/**** * * Implementation of rolodex-menu-ui.h * */ #include "edit-menu.h" #include "file-menu.h" #include "rolodex-menu-ui.h" #include "rolodex-menu.h" #include "rolodex-tool.h" #include "white-background-tray.h" #include #include #include #include #include RolodexMenuUI::RolodexMenuUI(Screen* s, RolodexTool* rt) : RolodexUI(s, rt) { /* * Construct the file menu, passing its File model. */ fm = new FileMenu(new String("File"), rt->GetFile()); /* * Construct the edit menu, passing its Edit model. */ em = new EditMenu(new String("Edit"), rt->GetEdit()); /* * Construct the rolodex menu, passing its Rolodex model. */ rm = new RolodexMenu(new String("Rolodex"), rt->GetRolodex(), this); /* * For convenience, save a copy of the model as a downcast value. Hence, * this->m == this->rt, where the former is of type Model* and the latter * is of type RolodexTool*. */ this->rt = rt; } RolodexMenuUI::~RolodexMenuUI() { } void RolodexMenuUI::Compose() { /* * Make the window of this a WhiteBackgroundTray, which is a specialization * of an InterViews Tray. A Tray is a standard outermost interactor for a * top-level interface since it provides a opaque background. An HBox or * VBox by itself has a transparent background, which means that if it's * used as the outmost interactor, it will "absorb" whatever window * background is underneath it. Hence, it is standard practice to use a * Tray for the solid background. Trays have other useful purposes, but * here we're simply using one for its background. */ w = new WhiteBackgroundTray(vb = new VBox()); /* * Compose the menubar and insert it into this' window. The border * provides a visible separator under the menubar. By default a menubar * has no visible border. */ vb->Insert(ComposeMenuBar()); vb->Insert(new HBorder()); /* * Compose the data entry area and insert into the window. */ vb->Insert(ComposeDataArea()); /* * Make the start-up contents of the data entry empty. */ d->FlipTo(EMPTYPOSITION); /* * Set the name of the top-level interactor, which name will appear in the * titlebar of the window. */ w->SetName("Rolodex Tool"); /* * Create the icon that will be displayed when the top-level window is * iconified. It's the tool name, 3 pixels of whitespace margin, with an * outer frame border. See the InterViews documentation for the Frame * class for details. */ w->SetIconInteractor( new Frame(new MarginFrame(new Message("Rolodex Tool"), 3))); } MenuBar* RolodexMenuUI::ComposeMenuBar() { mb = new MenuBar(); /* * Compose the file menu view and insert its window into the bar. */ mb->Include((PulldownMenu*)ComposeFileMenu()->GetWindow()); /* * Stick some glue between the file and edit menus. */ mb->Insert(new HGlue( round(0.2*inch), round(0.15*inch), 0)); // ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ ^ Stretchibilty, // ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ // ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ Shrinkibility, i.e., minimum size // ^^^^^^^^^^^^^^^ // ^^^^^^^^^^^^^^^ Natural size, i.e., initial size /* * Compose the edit pulldown and insert it into the bar. */ mb->Include((PulldownMenu*)ComposeEditMenu()->GetWindow()); /* * Stick some glue between the edit and rolodex menus. */ mb->Insert(new HGlue(round(0.2*inch), round(0.15*inch), 0)); /* * Compose the rolodex pulldown and insert it into the bar. */ mb->Include((PulldownMenu*)ComposeRolodexMenu()->GetWindow()); /* * Stick some glue on the right edge of the menubar. */ mb->Insert(new HGlue(round(0.15*inch), 0, hfil)); return mb; } HBox* RolodexMenuUI::ComposeDataArea() { /* * Allocate a deck to hold the operation-specific dialogs. */ d = new Deck(); /* * Allocate and comppose each of the dialogs and insert each into the deck. * Note that the model for each of the dialogs is an appropriate components * of the rolodex tool workspace */ ComposeDialogs(); /* * Put the deck in an HBox with some glue on each end. This outer hbox * with its glue will allow horizontal stretchibility. Note here how the * HBox constructor can take more than one argument -- it can take up to 7 * arguments. */ return new HBox( new HGlue(round(0.2 * inch), 0, hfil), d, new HGlue(round(0.2 * inch), 0, hfil) ); } FileMenu* RolodexMenuUI::ComposeFileMenu() { /* * Compose the file menu, which entails inserting each of its items. */ fm->Compose(); /* * Return the composed menu. */ return fm; } EditMenu* RolodexMenuUI::ComposeEditMenu() { /* * Compose the edit menu, which entails inserting each of its items. */ em->Compose(); /* * Return the composed menu. */ return em; } RolodexMenu* RolodexMenuUI::ComposeRolodexMenu() { /* * Compose the rolodex menu, which entails inserting each of its items. */ rm->Compose(); /* * Return the composed menu. */ return rm; } void RolodexMenuUI::ComposeDialogs() { /* * Position 1 -- Add. */ acd = new AddCardDialog(rt->GetRolodex(), this); ComposeAndInsert(acd); /* * Position 2 -- Delete. */ dcd = new DeleteCardDialog(rt->GetRolodex(), this); ComposeAndInsert(dcd); /* * Position 3 -- Confirm Delete. */ cdd = new ConfirmDeleteDialog(rt->GetRolodex(), this); ComposeAndInsert(cdd); /* * Position 4 -- Change. */ ccd = new ChangeCardDialog(rt->GetRolodex(), this); ComposeAndInsert(ccd); /* * Position 5 -- Confirm Change. */ cncd = new ConfirmChangeDialog(rt->GetRolodex(), this); ComposeAndInsert(cncd); /* * Position 6 -- Found. (Note: this is seemingly done out of order since * FindCardDialog needs a pointer to FoundCardsDialog. But then the order * of the cards is really irrelevant anyway, except for organizational * clarity.) */ fcsd = new FoundCardsDialog(rt->GetRolodex(), this); ComposeAndInsert(fcsd); /* * Position 7 -- Find. */ fcd = new FindCardDialog(rt->GetRolodex(), this, fcsd); ComposeAndInsert(fcd); /* * Position 8 -- No Cards Found. */ nfcsd = new NoFoundCardsDialog(); ComposeAndInsert(nfcsd); /* * Position 9 -- Error. */ emd = new ErrorMessageDialog(); ComposeAndInsert(emd); /* * Position 10 -- Empty. */ d->Insert(new Tray()); } void RolodexMenuUI::ComposeAndInsert(View* v) { v->Compose(); d->Insert(v->GetWindow()); } void RolodexMenuUI::ShowAddCardDialog() { prevpos = curpos; d->FlipTo(curpos = ADDPOSITION); } void RolodexMenuUI::ShowDeleteCardDialog() { prevpos = curpos; d->FlipTo(curpos = DELPOSITION); } void RolodexMenuUI::ShowChangeCardDialog() { prevpos = curpos; d->FlipTo(curpos = CHANGEPOSITION); } void RolodexMenuUI::ShowFindCardDialog() { prevpos = curpos; d->FlipTo(curpos = FINDPOSITION); } void RolodexMenuUI::ShowFoundDialog() { prevpos = curpos; d->FlipTo(curpos = FOUNDPOSITION); } void RolodexMenuUI::ShowNoFoundDialog() { prevpos = curpos; d->FlipTo(curpos = NOFOUNDPOSITION); } void RolodexMenuUI::ShowErrorDialog(String* s) { emd->SetMessage(s); prevpos = curpos; d->FlipTo(ERRORPOSITION); } void RolodexMenuUI::ShowErrorDialog(StrList* sl) { emd->SetMessages(sl); prevpos = curpos; d->FlipTo(ERRORPOSITION); } void RolodexMenuUI::ShowEmptyDialog() { prevpos = curpos; d->FlipTo(curpos = EMPTYPOSITION); }