// $Revision: 1.13 $ // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. //======================================================================= // file MarsCanvas.h // // description An extremely simple model-based canvas. Mars makes // few changes to the way the view works. It adds // its own menu bar (frameworks really shouldn't do this // for applications you know, except for maybe stuff west // of the Edit menu). It also sets the initial current // cursor tool. // // Mars uses stock graphics, tools, commands and // interactors, etc. provided by GrafEdit. It simply // configures a menu layout to use these. Mars also // uses TStandardCanvasModel "out of the box." // // Now you might think, "hmm, does this framework do // too much?" Well, there are more abstract classes // if you don't want to store your graphics in a model, // don't want to be part of a document, or want to be // an individual for other reasons. It just happens that // TStandardCanvas... classes are concrete since many // developers will be able to go quite far just introducing // new graphics and commands, but sticking with my model // and selection, and just subclassing my view to organize // menus, etc. Especially the MIS types should appreciate // this approach. // // modifications rtw 12/15/93 new file // // // Copyright (C) 1994 Taligent, Inc. All rights reserved. //======================================================================== #ifndef Taligent_CURSORTOOLSELECTIONSTATE #include #endif #ifndef Taligent_STANDARDARROWTOOL #include #endif #ifndef Taligent_CANVASLINE #include #endif #ifndef Taligent_CANVASPOLYLINE #include #endif #ifndef Taligent_CANVASPOLYGON #include #endif #ifndef Taligent_CANVASCURVE #include #endif #ifndef Taligent_CANVASTEXT #include #endif #ifndef Taligent_BASICCANVASGRAPHIC #include #endif #ifndef Taligent_GRAPHICS #include #endif #ifndef Taligent_BUNDLES #include #endif #ifndef Taligent_GRAFATTRIBUTE #include #endif #ifndef Taligent_RGBCOLOR #include #endif #ifndef Taligent_VIEWROOT #include #endif #ifndef Taligent_REQUESTPROCESSOR #include #endif #ifndef Taligent_MENUCONTROLS #include #endif #ifndef Taligent_TRANSFORMS #include #endif #ifndef Taligent_LABEL #include #endif #ifndef Taligent_GRAFPENS #include #endif #ifndef Taligent_MARSPRESENTER #include "MarsPresenter.h" #endif #ifndef Taligent_STANDARDGRAFEDIT #include #endif #ifndef Taligent_SCROLLINGVIEW #include #endif #ifndef Taligent_CANVASTEXT #include #endif #ifndef Taligent_TEXTMENUS #include #endif TSubMenuItem *TMarsPresenter::gToolSubMenuItem = NIL; TSubMenuItem *TMarsPresenter::gColorSubMenuItem = NIL; TSubMenuItem *TMarsPresenter::gPenSubMenuItem = NIL; TSubMenuItem *TMarsPresenter::gTextSubMenuItem = NIL; VersionDefinitionsMacro (TMarsPresenter, kOriginalVersion); DynamicCastDefinitionsMacroOne (TMarsPresenter,TGUIPresenter); TMarsPresenter::TMarsPresenter (const TGUIBundle& bundle) : TGUIPresenter(bundle), fCanvasView(NIL) { } TMarsPresenter::~TMarsPresenter() { // don't delete fCanvasView (we were just hanging onto a reference) } void TMarsPresenter::SetCanvasView(TCanvasView* canvasView) { fCanvasView = canvasView; } TView* TMarsPresenter::HandleCreateMainView (TGUIBundle* theBundleToAlias) const { // Create and return a TStandardCanvasView on top of a TScrollingView TCanvasView *contentView = new TStandardCanvasView (theBundleToAlias); TCanvasFrontToBackFilter filter; TCanvasAreaFunnel funnel; contentView->EnumerateGraphics(filter,funnel); TGArea theViewArea = funnel.GetCanvasArea(); // Check to make sure that the view is at least the default size. If not, // make it the default size. TGRect viewRect = theViewArea.GetBounds(); TGRect scrollRect = theViewArea.GetBounds(); TGPoint bottomRight = viewRect.GetBottomRight(); bottomRight.fX = bottomRight.fX < 500. ? 500. : bottomRight.fX; bottomRight.fY = bottomRight.fY < 400. ? 400. : bottomRight.fY; viewRect.SetBottomRight(bottomRight); bottomRight = scrollRect.GetBottomRight(); bottomRight.fX = bottomRight.fX < 350. ? 350. : bottomRight.fX; bottomRight.fY = bottomRight.fY < 300. ? 300. : bottomRight.fY; scrollRect.SetBottomRight(bottomRight); // Okay, now that we've adjusted the view size to be at least the minimum // Let's Set its allocated area theViewArea = TGArea(viewRect); contentView->SetAllocatedArea(theViewArea); ::NonConst((TMarsPresenter*)this)->SetCanvasView(contentView); // put everything into a scrolling view TScrollingView* scrollingView = new TScrollingView(TScrollingView::kBothScrollbars); scrollingView->AdoptViewToScroll(contentView); theViewArea = TGArea(scrollRect); scrollingView->SetAllocatedArea (theViewArea); return scrollingView; } void TMarsPresenter::HandleMenuActivate (TMenu& theMainMenu) { TGUIPresenter::HandleMenuActivate(theMainMenu); TMomentaryMenuItem* popup; TDeleterFor theArchive = TArchive::CopyArchiveForSharedLibrary(); if (!TMarsPresenter::gToolSubMenuItem) { // Tools menu TMenu *toolsMenu = new TMenu (); toolsMenu->SetControlLayout(MControl::kTopToBottom); popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TStandardArrowTool())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Arrow")))); popup->SetSeparator (MMenuItem::kAfter); toolsMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasLineCreationTool())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Line")))); toolsMenu->AdoptLast (popup); TRGBColor black (0.,0.,0.), white (1.,1.,1.); TGrafBundle* bundle = new TGrafBundle ( new TColorPaint(white), new TColorPaint(black), TAttributeState::kFillAndFrame); bundle->AdoptFramePen ( new TSolidPen(1.) ); TPolygon rect (TGRect(0.,0.,1.,1.), ::Copy(*bundle) ); popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TBasicCanvasGraphicCreationTool(rect))); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Rectangle")))); toolsMenu->AdoptLast (popup); TEllipse ellipse (TGRect(0.,0.,1.,1.), bundle ); popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TBasicCanvasGraphicCreationTool(ellipse))); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Ellipse")))); toolsMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasPolylineCreationTool())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Polyline")))); toolsMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasPolygonCreationTool())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Polygon")))); toolsMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasCurveCreationTool())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Curve")))); toolsMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TCursorToolSelectionState(new TCanvasTextGraphicCreationTool())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Text")))); toolsMenu->AdoptLast (popup); TMarsPresenter::gToolSubMenuItem = new TSubMenuItem (toolsMenu, new TTextLabel(*TDeleterFor(CopyLocalizedText(theArchive, "Tools")))); } if (!TMarsPresenter::gColorSubMenuItem) { // Colors menu TMenu *colorsMenu = new TMenu (); colorsMenu->SetControlLayout(MControl::kTopToBottom); popup = new TMomentaryMenuItem (new TStandardCanvasFrameColorSelectionState(TRGBColor(1.,0.,0.), GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Red Frame")))); colorsMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TStandardCanvasFrameColorSelectionState(TRGBColor(0.,1.,0.), GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Green Frame")))); colorsMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TStandardCanvasFrameColorSelectionState(TRGBColor(0.,0.,1.), GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Blue Frame")))); popup->SetSeparator (MMenuItem::kAfter); colorsMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TStandardCanvasFillColorSelectionState(TRGBColor(1.,0.,0.), GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Red Fill")))); colorsMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TStandardCanvasFillColorSelectionState(TRGBColor(0.,1.,0.), GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Green Fill")))); colorsMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TStandardCanvasFillColorSelectionState(TRGBColor(0.,0.,1.), GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "Blue Fill")))); colorsMenu->AdoptLast (popup); TMarsPresenter::gColorSubMenuItem = new TSubMenuItem (colorsMenu, new TTextLabel(*TDeleterFor(CopyLocalizedText(theArchive, "Color")))); } if (!TMarsPresenter::gPenSubMenuItem) { // Lines menu TMenu *linesMenu = new TMenu (); linesMenu->SetControlLayout(MControl::kTopToBottom); popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(1., GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "1 point")))); linesMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(2., GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "2 point")))); linesMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(4., GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "4 point")))); linesMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(6., GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "6 point")))); linesMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(8., GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "8 point")))); linesMenu->AdoptLast (popup); popup = new TMomentaryMenuItem (new TStandardCanvasLineWidthSelectionState(10., GetSharedBundleConnection())); popup->AdoptLabel (new TTextLabel (*TDeleterFor(CopyLocalizedText(theArchive, "10 point")))); linesMenu->AdoptLast (popup); TMarsPresenter::gPenSubMenuItem = new TSubMenuItem (linesMenu, new TTextLabel(*TDeleterFor(CopyLocalizedText(theArchive, "Pen")))); } if (!TMarsPresenter::gTextSubMenuItem) { // Text menu TMenu* textMenu = new TMenu(); textMenu->SetControlLayout( MControl::kTopToBottom ); TTextMenu* textMenuCreator = new TTextMenu((TTextView*)fCanvasView->GetEditableTextView()); textMenuCreator->AddTextMenus(*textMenu); TMarsPresenter::gTextSubMenuItem = new TSubMenuItem (textMenu, new TTextLabel(*TDeleterFor(CopyLocalizedText(theArchive, "Text")))); } theMainMenu.AdoptLast (TMarsPresenter::gToolSubMenuItem); theMainMenu.AdoptLast (TMarsPresenter::gColorSubMenuItem); theMainMenu.AdoptLast (TMarsPresenter::gPenSubMenuItem); theMainMenu.AdoptLast (TMarsPresenter::gTextSubMenuItem); } void TMarsPresenter::HandleMenuDeactivate(TMenu& theMainMenu) { TMarsPresenter::gToolSubMenuItem->GetOwner()->Orphan(*TMarsPresenter::gToolSubMenuItem); TMarsPresenter::gColorSubMenuItem->GetOwner()->Orphan(*TMarsPresenter::gColorSubMenuItem); TMarsPresenter::gPenSubMenuItem->GetOwner()->Orphan(*TMarsPresenter::gPenSubMenuItem); TMarsPresenter::gTextSubMenuItem->GetOwner()->Orphan(*TMarsPresenter::gTextSubMenuItem); TGUIPresenter::HandleMenuDeactivate(theMainMenu); } TStandardText* TMarsPresenter::CopyLocalizedText(TArchive* theArchive, const TStandardText& theKey ) const { TArchiveEnvelope theEnvelope(theArchive, GetLocale()); return theEnvelope.CopyObject( theKey ); } // The Mars stationery static TGUIModelPresenterStationeryFor stationery;