|
@@ -11,11 +11,157 @@
|
|
|
#define Uses_TStatusLine
|
|
#define Uses_TStatusLine
|
|
|
#define Uses_TStatusItem
|
|
#define Uses_TStatusItem
|
|
|
#define Uses_TStatusDef
|
|
#define Uses_TStatusDef
|
|
|
|
|
+#define Uses_TScroller
|
|
|
#define Uses_TDeskTop
|
|
#define Uses_TDeskTop
|
|
|
|
|
+#define Uses_TCollection
|
|
|
|
|
+#define Uses_TScroller
|
|
|
|
|
+#define Uses_TWindow
|
|
|
|
|
+#define Uses_ipstream
|
|
|
|
|
+#define Uses_opstream
|
|
|
|
|
+#define Uses_TStreamableClass
|
|
|
|
|
+
|
|
|
#include <string>
|
|
#include <string>
|
|
|
#include <tvision/tv.h>
|
|
#include <tvision/tv.h>
|
|
|
|
|
|
|
|
|
|
+class TItemCollection : public TCollection {
|
|
|
|
|
+
|
|
|
|
|
+public:
|
|
|
|
|
+ TItemCollection(short lim, short delta) : TCollection(lim, delta) {}
|
|
|
|
|
+ virtual void freeItem(void *p) { delete[](char *) p; }
|
|
|
|
|
+
|
|
|
|
|
+private:
|
|
|
|
|
+ virtual void *readItem(ipstream &) { return 0; }
|
|
|
|
|
+ virtual void writeItem(void *, opstream &) {}
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+class TItemViewer : public TScroller {
|
|
|
|
|
+
|
|
|
|
|
+public:
|
|
|
|
|
+ char *fileName;
|
|
|
|
|
+ TCollection *fileLines;
|
|
|
|
|
+ Boolean isValid;
|
|
|
|
|
+ TItemViewer(const TRect &bounds, TScrollBar *aHScrollBar,
|
|
|
|
|
+ TScrollBar *aVScrollBar, Boolean left);
|
|
|
|
|
+ ~TItemViewer();
|
|
|
|
|
+ TItemViewer(StreamableInit) : TScroller(streamableInit){};
|
|
|
|
|
+ void draw();
|
|
|
|
|
+ void setState(ushort aState, Boolean enable);
|
|
|
|
|
+ void scrollDraw();
|
|
|
|
|
+ Boolean valid(ushort command);
|
|
|
|
|
+
|
|
|
|
|
+private:
|
|
|
|
|
+ virtual const char *streamableName() const { return name; }
|
|
|
|
|
+
|
|
|
|
|
+protected:
|
|
|
|
|
+ virtual void write(opstream &);
|
|
|
|
|
+ virtual void *read(ipstream &);
|
|
|
|
|
+
|
|
|
|
|
+public:
|
|
|
|
|
+ static const char *const name;
|
|
|
|
|
+ static TStreamable *build();
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+class TItemWindow : public TWindow {
|
|
|
|
|
+
|
|
|
|
|
+public:
|
|
|
|
|
+ TItemWindow(const char *fileName);
|
|
|
|
|
+protected:
|
|
|
|
|
+ virtual void sizeLimits(TPoint& min, TPoint& max) override {
|
|
|
|
|
+ TWindow::sizeLimits(min, max);
|
|
|
|
|
+ min.x = size.x/2+10;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+const int maxLineLength = 256;
|
|
|
|
|
+
|
|
|
|
|
+const char *const TItemViewer::name = "TItemViewer";
|
|
|
|
|
+
|
|
|
|
|
+TItemViewer::TItemViewer(const TRect &bounds, TScrollBar *aHScrollBar,
|
|
|
|
|
+ TScrollBar *aVScrollBar, Boolean left)
|
|
|
|
|
+ : TScroller(bounds, aHScrollBar, aVScrollBar) {
|
|
|
|
|
+ if (left)
|
|
|
|
|
+ growMode = gfGrowHiY;
|
|
|
|
|
+ else
|
|
|
|
|
+ growMode = gfGrowHiX | gfGrowHiY;
|
|
|
|
|
+
|
|
|
|
|
+ isValid = True;
|
|
|
|
|
+ fileName = 0;
|
|
|
|
|
+ fileLines = new TItemCollection(5, 5);
|
|
|
|
|
+ fileLines->insert(newStr(left ? "Items" : "Categories"));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TItemViewer::~TItemViewer() { destroy(fileLines); }
|
|
|
|
|
+
|
|
|
|
|
+void TItemViewer::draw() {
|
|
|
|
|
+ char *p;
|
|
|
|
|
+
|
|
|
|
|
+ ushort c = getColor(0x0301);
|
|
|
|
|
+
|
|
|
|
|
+ for (short i = 0; i < size.y; i++) {
|
|
|
|
|
+ TDrawBuffer b;
|
|
|
|
|
+ b.moveChar(0, ' ', c, size.x);
|
|
|
|
|
+
|
|
|
|
|
+ if (delta.y + i < fileLines->getCount()) {
|
|
|
|
|
+ p = (char *)(fileLines->at(delta.y + i));
|
|
|
|
|
+ if (p)
|
|
|
|
|
+ b.moveStr(0, p, c, (short)size.x, (short)delta.x);
|
|
|
|
|
+ }
|
|
|
|
|
+ writeBuf(0, i, (short)size.x, 1, b);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void TItemViewer::scrollDraw() {
|
|
|
|
|
+ TScroller::scrollDraw();
|
|
|
|
|
+ draw();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void TItemViewer::setState(ushort aState, Boolean enable) {
|
|
|
|
|
+ TScroller::setState(aState, enable);
|
|
|
|
|
+ if (enable && (aState & sfExposed))
|
|
|
|
|
+ setLimit(limit.x, limit.y);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Boolean TItemViewer::valid(ushort) { return isValid; }
|
|
|
|
|
+
|
|
|
|
|
+void *TItemViewer::read(ipstream &is) {
|
|
|
|
|
+ char *fName;
|
|
|
|
|
+ TScroller::read(is);
|
|
|
|
|
+ delete fName;
|
|
|
|
|
+ return this;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void TItemViewer::write(opstream &os) {
|
|
|
|
|
+ TScroller::write(os);
|
|
|
|
|
+ os.writeString(fileName);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TStreamable *TItemViewer::build() { return new TItemViewer(streamableInit); }
|
|
|
|
|
+
|
|
|
|
|
+TStreamableClass RItemView(TItemViewer::name, TItemViewer::build,
|
|
|
|
|
+ __DELTA(TItemViewer));
|
|
|
|
|
+
|
|
|
|
|
+static short winNumber = 0;
|
|
|
|
|
+
|
|
|
|
|
+TItemWindow::TItemWindow(const char *fileName)
|
|
|
|
|
+ : TWindow(TProgram::deskTop->getExtent(), fileName, winNumber++),
|
|
|
|
|
+ TWindowInit(&TItemWindow::initFrame) {
|
|
|
|
|
+ options |= ofTileable;
|
|
|
|
|
+ auto bounds = getExtent();
|
|
|
|
|
+ TRect r(bounds.a.x, bounds.a.y, bounds.b.x / 2 + 1, bounds.b.y);
|
|
|
|
|
+ r.grow(-1, -1);
|
|
|
|
|
+ insert(new TItemViewer(r, standardScrollBar(sbHorizontal | sbHandleKeyboard),
|
|
|
|
|
+ standardScrollBar(sbVertical | sbHandleKeyboard),
|
|
|
|
|
+ True));
|
|
|
|
|
+ r = TRect(bounds.b.x / 2, bounds.a.y, bounds.b.x, bounds.b.y);
|
|
|
|
|
+ r.grow(-1, -1);
|
|
|
|
|
+ insert(new TItemViewer(r, standardScrollBar(sbHorizontal | sbHandleKeyboard),
|
|
|
|
|
+ standardScrollBar(sbVertical | sbHandleKeyboard),
|
|
|
|
|
+ False));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const int GreetThemCmd = 100;
|
|
const int GreetThemCmd = 100;
|
|
|
|
|
+const int CallListCmd = 101;
|
|
|
|
|
|
|
|
class THelloApp : public TApplication {
|
|
class THelloApp : public TApplication {
|
|
|
|
|
|
|
@@ -57,6 +203,11 @@ void THelloApp::handleEvent(TEvent &event) {
|
|
|
greetingBox();
|
|
greetingBox();
|
|
|
clearEvent(event);
|
|
clearEvent(event);
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case CallListCmd:
|
|
|
|
|
+ if (TView *w = validView(new TItemWindow("test")))
|
|
|
|
|
+ deskTop->insert(w);
|
|
|
|
|
+ clearEvent(event);
|
|
|
|
|
+ break;
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -69,7 +220,8 @@ TMenuBar *THelloApp::initMenuBar(TRect r) {
|
|
|
|
|
|
|
|
return new TMenuBar(
|
|
return new TMenuBar(
|
|
|
r, *new TSubMenu("~F~ile", kbAltH) +
|
|
r, *new TSubMenu("~F~ile", kbAltH) +
|
|
|
- *new TMenuItem("~G~reeting...", GreetThemCmd, kbAltG) + newLine() +
|
|
|
|
|
|
|
+ *new TMenuItem("~G~reeting...", GreetThemCmd, kbAltG) +
|
|
|
|
|
+ *new TMenuItem("~L~ist...", CallListCmd, kbAltL) + newLine() +
|
|
|
*new TMenuItem("E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X"));
|
|
*new TMenuItem("E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -81,7 +233,12 @@ TStatusLine *THelloApp::initStatusLine(TRect r) {
|
|
|
*new TStatusItem(0, kbF10, cmMenu));
|
|
*new TStatusItem(0, kbF10, cmMenu));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#ifndef BINARY
|
|
|
extern "C" int ui_main(char *hello_line) {
|
|
extern "C" int ui_main(char *hello_line) {
|
|
|
|
|
+#else
|
|
|
|
|
+int main() {
|
|
|
|
|
+ const char *hello_line = "test line";
|
|
|
|
|
+#endif
|
|
|
THelloApp helloWorld;
|
|
THelloApp helloWorld;
|
|
|
helloWorld.set_hello(hello_line);
|
|
helloWorld.set_hello(hello_line);
|
|
|
helloWorld.run();
|
|
helloWorld.run();
|