/* * This file illustrates a simple monthly calendar view, built with Frames, * Messages, TextEditors, HBoxes, and VBoxes. In addition to the month view, * there is a separate pulldown command window. */ #include #include #include #include #include #include #include #include #include #include #include class CaretModifiableTextEditor; /* * A DayCellView is a Frame containing a VBox containing a 15-char message and * 5x15 text editor. Its Handle function should be specialized to allow double * clicking to bring up a day view expansion. */ class DayCellView : public Frame { public: DayCellView(char* date); InsertText(char* text); protected: CaretModifiableTextEditor* ed; }; /* * A CaretModifiableTextEditor is simply a standard InterViews TextEditor with * a new public function that allows the caret style of the underlying * TextDisplay to be changed. */ class CaretModifiableTextEditor : public TextEditor { public: CaretModifiableTextEditor(int rows, int cols, int tabsize, int highlight); void CaretStyle(int style); }; DayCellView::DayCellView(char* date) { Insert(new VBox( new Message(date), ed = new CaretModifiableTextEditor(5, 15, 8, Reversed))); ed->Edit(new TextBuffer(new char[5*15], 0, 5*15)); ed->CaretStyle(NoCaret); } DayCellView::InsertText(char* text) { ed->InsertText(text, strlen(text)+1); } CaretModifiableTextEditor::CaretModifiableTextEditor( int rows, int cols, int tabsize, int highlight) : TextEditor(rows, cols, tabsize, highlight) {} void CaretModifiableTextEditor::CaretStyle(int style) { display->CaretStyle(style); } /* * Class NewWorld implements a correct version of GetRelative, which appears to * be seriously brain damaged in the library. */ class NewWorld : public World { public: void GetRelative(int& x, int&y, Interactor* i); /* * Set x and y to the position of the given interactor, relative to this. */ }; void NewWorld::GetRelative(int& x, int&y, Interactor* i) { // x = i->left; // y = i->bottom; } int x,y; main () { World* w = new World; MenuBar* menubar; PulldownMenu *fmenu, *vmenu, *bmenu, *smenu; DayCellView* days[32]; int d,height; char dstr[3]; /* * Create a real simple pulldown menu, as a separate X window. */ menubar = new MenuBar; fmenu = new PulldownMenu(" Files "); vmenu = new PulldownMenu(" View "); bmenu = new PulldownMenu(" Browse "); smenu = new PulldownMenu(" Schedule "); menubar->Include(fmenu); menubar->Include(vmenu); menubar->Include(bmenu); menubar->Include(smenu); /* * Create all the cells and stick 'em in a calendar view. */ for (d=1; d<=31; d++) { sprintf(dstr, "%d", d); days[d] = new DayCellView(dstr); } HBox* week1 = new HBox(new HGlue(), days[1], days[2]); week1->Align(Right); HBox* week2 = new HBox( days[3], days[4], days[5], days[6], days[7], days[8], days[9]); HBox* week3 = new HBox( days[10], days[11], days[12], days[13], days[14], days[15], days[16]); HBox* week4 = new HBox( days[17], days[18], days[19], days[20], days[21], days[22], days[23]); HBox* week5 = new HBox( days[24], days[25], days[26], days[27], days[28], days[29], days[30]); HBox* week6 = new HBox(days[31]); week6->Align(Left); days[8]->InsertText("Snr Project"); w->InsertApplication(menubar); x = 0; y = 0; menubar->GetRelative(x,y); Interactor* guts = new Tray( new HBox( new VBox( week1, week2, week3, week4, week5, week6 ) ) ); /* * The following four lines are not necessary if we use a TopLeft * alignment. */ //w->InsertIcon(guts, x, y); //height = guts->GetShape()->height; //w->Remove(guts); //system("sleep 1"); w->InsertApplication(guts, x, y-menubar->GetShape()->height, TopLeft); w->Run(); }