Creating the presenter

The following code calls the VersionDefinitionsMacro to provide meta class information for versioning. The constructor passes the TGUIBundle to the parent constructor.

      // Copyright (C) 1995 Taligent, Inc. All rights reserved.
      TSubMenuItem    *TDeimosPresenter::gToolSubMenuItem = NIL;
      
      VersionDefinitionsMacro (TDeimosPresenter, kOriginalVersion);
      DynamicCastDefinitionsMacroOne (TDeimosPresenter,TGUIPresenter);
      
      TDeimosPresenter::TDeimosPresenter (const TGUIBundle& bundle)
          : TGUIPresenter(bundle)
      {
      }
      
      TDeimosPresenter::~TDeimosPresenter()
      { 
      }

Creating the view

The following code creates a TStandardCanvas view and puts it into a scrolling view. TStandardCanvas view is constructed with a
TGUIBundle pointer. The bundle is aliased, not owned.

      TView* TDeimosPresenter::HandleCreateMainView (TGUIBundle* theBundleToAlias) const
      {
          // Create and return a TStandardCanvasView on top of a TScrollingView
          TCanvasView *contentView = new TStandardCanvasView (theBundleToAlias);
          contentView->SetAllocatedArea (TGArea(TGRect(0.,0.,500.,400.)));
          
          // put everything into a scrolling view
          TScrollingView* scrollingView = new TScrollingView(TScrollingView::kBothScrollbars);
          scrollingView->AdoptViewToScroll(contentView);
          scrollingView->SetAllocatedArea (TGArea(TGRect(0.,0.,350.,300.)));
          
          return scrollingView;
      }

Adding a menu palette with commands

The following code creates a menu palette with one menu that contains two menu items. When chosen, each menu item sets the current tool for working in the view. The first menu item sets the tool to draw a curve, and the second menu item sets the arrow tool for selecting and manipulating curves.

      void TDeimosPresenter::HandleMenuActivate (TMenu& theMainMenu)
      {
          TGUIPresenter::HandleMenuActivate(theMainMenu);
          TMomentaryMenuItem* popup;
      
          if (!TDeimosPresenter::gToolSubMenuItem) {
              // Tools menu
          
              TMenu *toolsMenu = new TMenu ();
              toolsMenu->SetControlLayout(MControl::kTopToBottom);
          
              popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TStandardArrowTool()));
              popup->AdoptLabel (new TTextLabel (TStandardText("Arrow")));
              popup->SetSeparator (MMenuItem::kAfter);
              toolsMenu->AdoptLast (popup);
                          
              popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasCurveCreationTool()));
              popup->AdoptLabel (new TTextLabel (TStandardText("Curve")));
              toolsMenu->AdoptLast (popup);
      
              TDeimosPresenter::gToolSubMenuItem = new TSubMenuItem (toolsMenu, 
                              new TTextLabel(TStandardText("Tools")));
          }
      
          theMainMenu.AdoptLast (TDeimosPresenter::gToolSubMenuItem);
      }

Deactivating the menu pallet

This member function orphans the submenu.

      void TDeimosPresenter::HandleMenuDeactivate(TMenu& theMainMenu)
      {   
          TDeimosPresenter::gToolSubMenuItem->GetOwner()->Orphan(*TDeimosPresenter::gToolSubMenuItem);
          TGUIPresenter::HandleMenuDeactivate(theMainMenu);
      }

Creating the stationery

To work with the Presentation framework, this GrafEdit application uses a stationery class. A template stationary class is both declared and instantiated at the end of each presenter source file. The template class is instantiated from the model and presenter classes used. The following creates the
Deimos stationery:

    static TGUIModelPresenterStationeryFor<TStandardCanvasModel,TDeimosPresenter> stationery;

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker