/* * Simple illustration of the use of a Viewport. */ #include #include #include #include #include #include #include #include #include #include #include class FixedHeightHBox : public HBox { public: FixedHeightHBox(int maxHeight); void ComputeShape(Shape*); protected: int maxHeight; }; FixedHeightHBox::FixedHeightHBox(int maxHeight) { this->maxHeight = maxHeight; } void FixedHeightHBox::ComputeShape(register Shape* box) { HBox::ComputeShape(box); if (box->height > maxHeight) box->height = maxHeight; } class FixedHeightVBox : public VBox { public: FixedHeightVBox(int maxHeight); void ComputeShape(Shape*); protected: int maxHeight; }; FixedHeightVBox::FixedHeightVBox(int maxHeight) { this->maxHeight = maxHeight; } void FixedHeightVBox::ComputeShape(register Shape* box) { VBox::ComputeShape(box); if (box->height > maxHeight) box->height = maxHeight; } void DoButton(void* v, Event *e); main () { World* w = new World; Tray* t = new Tray; VBox* vb = new VBox; VBox* vb1 = new VBox; VBox* vb2 = new VBox; FixedHeightVBox* vb3 = new FixedHeightVBox(50); FixedHeightHBox* hb = new FixedHeightHBox(50); HBox* hb1; Viewport* vp; Shape* sh1, *sh2; char *bname1, *bname2;; int i; /* * 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)); vb1->Insert(hb1); } /* * 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. */ vp = new Viewport(vb1); /*vb2->Insert(new UpMover(vp,1));*/ /*vb2->Insert(new HBorder);*/ vb2->Insert(new VScroller(vp)); /*vb2->Insert(new HBorder);*/ /*vb2->Insert(new DownMover(vp,1));*/ /* vb3->Insert(vb2); */ hb->Insert(vp); hb->Insert(new VBorder); hb->Insert(vb2); /* * 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); t->Insert(vb); /* * Insert the outermost tray into the world. */ w->InsertApplication(t); w->Run(); delete w; } void DoButton(void* v, Event *e) { printf("In button.\n"); }