/* * Simple illustration of the use of a Viewport. */ #include #include #include #include "funcbutton.h" #include #include #include #include #include #include #include #include #include #include void DoButton(void* v, Event *e); main () { World* w = new World; Tray* t = new Tray(); VBox* vb = new VBox; VBox* vb1 = new VBox; HBox* hb = new HBox; HBox* hb1; Viewport* vp; Shape* sh1, *sh2; char *bname1, *bname2;; int i; TextEditor* te = new TextEditor(10, 40, 8, 0); TextBuffer* text; const int size = 100000; char* buffer = new char[size]; char* b = buffer; /* * Make a vbox of 35 rows of hboxes, with each hbox containing a pair of * function buttons. */ for (i = 1; i <= 70; i+=2) { bname1 = new char[15]; bname2 = new char[15]; sprintf(bname1, "Button No. %d", i); sprintf(bname2, "Button No. %d", i+1); hb1 = new HBox( new FuncButton(DoButton, bname1, 0), new FuncButton(DoButton, bname2, 0)); hb1->Align(Center); vb1->Insert(hb1); /* * Stick a text editor in the middle of the buttons. */ if (i == 35) { text = new TextBuffer(buffer, b-buffer, size); te->Edit(text); vb1->Insert(new Frame(te)); te->InsertText("Now is the time for all good men to come to the aid of the party. The quick brown fox jumped over the lazy dogs.", strlen("Now is the time for all good men to come to the aid of the party. The quick brown fox jumped over the lazy dogs.")); } } /* * Stick the vbox in a viewport, slap a scroller on the viewport, an stick * the pair in a new outer hbox. Throw in a couple up and down movers * above and below the scroller. Note that the up and down movers will let * us move in the viewport beyond the normal range that the scroller will * let us move. This may or may not what is desired in all cases. */ hb->Insert(vp = new Viewport(vb1)); hb->Insert(new VBorder); hb->Insert( new VBox( new UpMover(vp,1), new HBorder, new VScroller(vp), new HBorder, new DownMover(vp,1) ) ); /* * Stick some other stuff around the outer hbox, to confirm that things get * reconfig'd nicely. */ vb->Insert(new Message("Message 1")); vb->Insert(new Message("Message 2")); vb->Insert(new Message("Message 3")); vb->Insert(new HBorder); vb->Insert(hb); vb->Insert(new HBorder); vb->Insert(new Message("Message 4")); vb->Insert(new Message("Message 5")); vb->Insert(new Message("Message 6")); vb->Align(Center); /* * Insert the outermost tray into the world. */ w->InsertApplication(new Tray(vb)); /* * Get the shape of the hbox and halve the height, so that only half of it * will appear initially in the viewport. Note that this happens after * InsertApplication, since Config is called from InsertApplication, and * Config tries its very hardest to "shrink wrap" things, independent of * whatever shapes they have before the Config. E.g., in this case, Config * will size everything to show all of the buttons, even if the box is * initially shaped to be smaller than is big enough to hold all of the * buttons. Once the initial call to Config is done, we can reshape and * reconfig all we want. */ sh1 = hb->GetShape(); sh1->height /= 2; hb->Reshape(*sh1); w->Reconfig(); w->Run(); delete w; } void DoButton(void* v, Event *e) { printf("In button.\n"); }