/* * Implementation of timeprefbrowse.h */ #include #include #include #include <441/include/paintlabel.h> #include "time_browser.h" #include "time_editor.h" TimeBrowser::TimeBrowser( int starttime, int endtime, int granularity) { /* * Make each editor 10-chars wide for now. This should probably be a parm. */ numcolumns = 8; /* * Insert a framed composition of text editors as the only element of this. * This is a sublcass of MonoScene, so exactly one interactor can be * inserted */ Insert(new Frame( ComposeEditors(starttime, endtime, granularity)) ); } HBox* TimeBrowser::ComposeEditors( int starttime, int endtime, int granularity) { int numrows; /* Value to be returned by ComposeLeftColumn, q.v. */ /* * Build the new hbox to hold all of the editors. */ columns = new HBox(); /* * Insert the left column, containing the hours of the day. * ComposeLeftColumn tells us how many rows there are. */ columns->Insert(ComposeLeftColumn( starttime, endtime, granularity, numrows)); /* * Stick in each of the five day columns, separated by a vetical line (a * VBorder) and some glue. */ columns->Insert(new VBorder); columns->Insert(new VGlue(round(0.25 * inch), 0, 0)); columns->Insert(ComposeColumn(" Mon", numrows, mon)); columns->Insert(new VBorder); columns->Insert(new VGlue(round(0.25 * inch), 0, 0)); columns->Insert(ComposeColumn(" Tue", numrows, tue)); columns->Insert(new VBorder); columns->Insert(new VGlue(round(0.25 * inch), 0, 0)); columns->Insert(ComposeColumn(" Wed", numrows, wed)); columns->Insert(new VBorder); columns->Insert(new VGlue(round(0.25 * inch), 0, 0)); columns->Insert(ComposeColumn(" Thu", numrows, thu)); columns->Insert(new VBorder); columns->Insert(new VGlue(round(0.25 * inch), 0, 0)); columns->Insert(ComposeColumn(" Fri", numrows, fri)); /* * Return the completed hbox. */ return columns; } VBox* TimeBrowser::ComposeLeftColumn( int starttime, int endtime, int granularity, int& numrows) { TimeEditor* ed; /* Local copy for filling up purposes. */ /* * Compute the number of rows. */ numrows = (endtime - starttime + 100)/100; /* Somewhat FAKE for now -- * should ask Time class. */ /* * Make a vbox holding the column heading ("Time") and the editor that will * hold the hours of the day. This clearly needs to be expanded to loop * through starttime to endtime and stick in the right numbers. */ VBox* vb = new VBox( new PaintLabel("Time", "times", "bold", "r", "14"), new HBorder, ed = new TimeEditor(numrows, numcolumns)); /* * Loop through the times and stick 'em in the editor. */ SetInitialTimes(ed, starttime, numrows); /* * Return the completed column. */ return vb; } void TimeBrowser::SetInitialTimes( TimeEditor* ed, int starttime, int numrows) { int i,t; char tstr[10]; for (i=1, t=starttime; i<=numrows; i++) { sprintf(tstr, "%d\n", t); ed->InsertText(tstr, strlen(tstr)); t += 100; /* Moderately fake, again call some time module */ } } VBox* TimeBrowser::ComposeColumn(char* label, int numrows, TimeEditor* te) { /* * Make a vbox holding the colunm label (a day of the week) and the column * data. This needs to be expanded to communicate with the model class to * get the actual time prefs data from the instructor database. */ te = new TimeEditor(numrows, numcolumns); VBox* vb = new VBox( new PaintLabel(label, "times", "bold", "r", "14"), new HBorder, te); /* * Return the completed column. */ return vb; }