Color and Pen menus

In the Mars program, the Color and Pen menu items work on the current selection. When the end user selects a menu item from the Color or Pen menu, the Presentation framework instantiates a momentary control state that knows the control state for the menu item and the command that corresponds to that control state. The momentary control state instance calls the AdoptAndDo interactor function, which creates the correct command and binds that command to the current selection so the command can act on the current selection.

The control state classes derive from TSimpleMomentaryControlStateOn, which, in GrafEdit, is a template that takes MCanvasSelection (the current selection) as a parameter. The control state classes used in the Mars program are the following:

    TStandardCanvasFillColorState
    TStandardCanvasFrameColorState
The control command classes derive from
TCommandOn, which is a template that in GrafEdit takes MCanvasSelection (the current selection) as a parameter. The corresponding commands used in the Mars program are created as follows:

    TSetCanvasGraphicFrameColorCmd
    TSetCanvasGraphicFillColorCmd

Color menu

The Color menu
appears to the right of the Tool menu. The following code creates the Colors menu and specifies kTopBottom which means the items will be listed from top to bottom on the menu. Each menu item is added with AdoptLast to put it after the last item on the menu.

      // Copyright (C) 1995 Taligent, Inc. All rights reserved.
          TMenu *colorsMenu = new TMenu ();
          colorsMenu->SetControlLayout(MControl::kTopToBottom);
The menu is created by specifying the menu item text, and a standard control state for the frame or fill color, as appropriate. The Document framework supplies the appropriate commands and interactors.

Red frame

              popup = new TMomentaryMenuItem (new TStandardCanvasFrameColorSelectionState(TRGBColor(1.,0.,0.), GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Red Frame"))));
              colorsMenu->AdoptLast (popup);

Green frame

              popup = new TMomentaryMenuItem (new TStandardCanvasFrameColorSelectionState(TRGBColor(0.,1.,0.), GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Green Frame"))));
              colorsMenu->AdoptLast (popup);

Blue frame with separator line below

              popup = new TMomentaryMenuItem (new TStandardCanvasFrameColorSelectionState(TRGBColor(0.,0.,1.), GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Blue Frame"))));
              popup->SetSeparator (MMenuItem::kAfter);
              colorsMenu->AdoptLast (popup);

Red fill

              popup = new TMomentaryMenuItem (new TStandardCanvasFillColorSelectionState(TRGBColor(1.,0.,0.), GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Red Fill"))));
              colorsMenu->AdoptLast (popup);

Green fill

              popup = new TMomentaryMenuItem (new TStandardCanvasFillColorSelectionState(TRGBColor(0.,1.,0.), GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Green Fill"))));
              colorsMenu->AdoptLast (popup);

Blue fill

              popup = new TMomentaryMenuItem (new TStandardCanvasFillColorSelectionState(TRGBColor(0.,0.,1.), GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Blue Fill"))));
              colorsMenu->AdoptLast (popup);
    

Labelling the menu

    TMarsPresenter::gColorSubMenuItem = new TSubMenuItem (colorsMenu, new TTextLabel(*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Color"))));

Pen menu

The Pen menu appears
to the right of the Tool menu. The following code creates the Pen menu and specifies kTopBottom which means the items will be listed from top to bottom on the menu. Each menu item is added with AdoptLast to put it after the last item on the menu.

      // Copyright (C) 1995 Taligent, Inc. All rights reserved.
              if (!TMarsPresenter::gPenSubMenuItem) {
              // Lines menu
              
              TMenu *linesMenu = new TMenu ();
              linesMenu->SetControlLayout(MControl::kTopToBottom);
The menu is created by specifying the menu item text, and the standard line width control state. The Document framework supplies the appropriate command and interactor.

1world-coordinate unit

          popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(1., GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "1 point"))));
              linesMenu->AdoptLast (popup);

2 world-coordinate units

              popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(2., GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "2 point"))));
              linesMenu->AdoptLast (popup);

4 world-coordinate units

              popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(4., GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "4 point"))));
              linesMenu->AdoptLast (popup);

6 world-coordinate units

              popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(6., GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "6 point"))));
              linesMenu->AdoptLast (popup);

8 world-coordinate units

              popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(8., GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "8 point"))));
              linesMenu->AdoptLast (popup);

10 world-coordinate units

              popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(10., GetSharedBundleConnection()));
              popup->AdoptLabel (new TTextLabel (*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "10 point"))));
              linesMenu->AdoptLast (popup);

Labelling the menu

              TMarsPresenter::gPenSubMenuItem = new TSubMenuItem (linesMenu, 
                              new TTextLabel(*TDeleterFor<TStandardText>(CopyLocalizedText(theArchive, "Pen"))));

[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