home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 34.6 KB | 1,165 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawPart.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWDEF_H
- #include "DrawDef.h"
- #endif
-
- #ifndef CONSTANT_H
- #include "Constant.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef DRAWSEL_H
- #include "DrawSel.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef TOOLFRM_H
- #include "ToolFrm.h"
- #endif
-
- #ifndef PALFRAME_H
- #include "PalFrame.h"
- #endif
-
- #ifndef PATFRAME_H
- #include "PatFrame.h"
- #endif
-
- #ifndef DRAWCMDS_H
- #include "DrawCmds.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- #ifndef SOM_ODFExamples_ODFDrawEmbeddedFramesIterator_xh
- #include "SOMIter.xh"
- #endif
-
- //#ifndef ALGNOBFR_H
- //#include "AlgnObFr.h"
- //#endif
-
- // ----- Part Layer -----
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWFLOWIN_H
- #include "FWFloWin.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw
- #endif
-
- //========================================================================================
- // Globals
- //========================================================================================
-
- const ODValueType CDrawPart::kPartKind = kODFDrawKind;
- const ODValueType CDrawPart::kPartUserName = kODFDrawEditorUserString;
-
- //========================================================================================
- // class CDrawPart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::CDrawPart
- //----------------------------------------------------------------------------------------
-
- CDrawPart::CDrawPart(ODPart* odPart) :
- FW_CEmbeddingPart(odPart, CDrawPart::kPartKind, CDrawPart::kPartUserName, FW_gInstance, kPartIconID)
- {
- fNbEmbedded = 0;
-
- fShapeList = NULL;
- fCurrentPenSize = FW_IntToFixed(1);
- fRenderVerb = kFillFrame;
-
- fPaletteWindow = NULL;
- fPatternWindow = NULL;
- fToolsWindow = NULL;
-
- fToolFrame = NULL;
- fPaletteFrame = NULL;
- fPatternFrame = NULL;
-
- fPalettePresentation = NULL;
- fPatternPresentation = NULL;
- fToolPresentation = NULL;
- fMainPresentation = NULL;
- fAlignObjectsPresentation = NULL;
-
- fTool = kSelectTool;
-
- fFillColor = FW_kRGBWhite;
- fFrameColor = FW_kRGBBlack;
-
- fAutoGrid = TRUE;
-
- fUnit = cInchUnit;
- fArcUnit = cDegreesUnit;
-
- fPostCreated = FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::~CDrawPart
- //----------------------------------------------------------------------------------------
-
- CDrawPart::~CDrawPart()
- {
- if (fShapeList)
- {
- CBaseShape* shape;
- while ((shape = (CBaseShape*)fShapeList->First()) != NULL)
- {
- fShapeList->Remove(shape);
- delete shape;
- }
- }
-
- delete fShapeList;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::Initialize(Environment *ev)
- {
- // ----- Call Inherited Initialize -----
- FW_CEmbeddingPart::Initialize(ev);
-
- FW_InitializeArchiving(FW_gInstance);
-
- fShapeList = new FW_CPrivOrderedCollection;
- fDrawingSize.Set(FW_IntToFixed(1024 * 5), FW_IntToFixed(1024 * 5));
-
- InitializeMenuBar(ev, GetMenuBar(ev));
-
- // ----- Tokenize -----
- fDrawSelection = new CDrawSelection(ev, this); // Attention I don't own the selection the presentation will
-
- fToolPresentation = RegisterPresentation(ev, kToolPresentation, FALSE);
- fPalettePresentation = RegisterPresentation(ev, kPalettePresentation, FALSE);
- fPatternPresentation = RegisterPresentation(ev, kPatternPresentation, FALSE);
- fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, fDrawSelection);
- fAlignObjectsPresentation = RegisterPresentation(ev, kAlignObjectsPresentation, FALSE);
-
- // ----- Pattern Table -----
- fPatternTable[0] = FW_kBlackPat;
- fPatternTable[1] = FW_kWhitePat;
- fPatternTable[2] = FW_kGrayPat;
- fPatternTable[3] = FW_kLightGrayPat;
- fPatternTable[4] = FW_kDarkGrayPat;
- fPatternTable[5] = FW_kHorizontalPat;
- fPatternTable[6] = FW_kVerticalPat;
- fPatternTable[7] = FW_kFDiagonalPat;
- fPatternTable[8] = FW_kBDiagonalPat;
- fPatternTable[9] = FW_kCrossPat;
- fPatternTable[10] = FW_kDiagCrossPat;
- fPatternTable[11] = FW_kAntPat;
-
- fFillPatIndex = 0;
- fFramePatIndex = 0;
-
- SupportFramePaging(ev, TRUE);
- }
-
- //------------------------------------------------------------------------------
- // CDrawPart::InitializeMenuBar
- //------------------------------------------------------------------------------
-
- void CDrawPart::InitializeMenuBar(Environment *ev, FW_CMenuBar *menuBar)
- {
- FW_CSharedLibraryResourceFile resFile; // Open the resource file of this shared library
-
- #ifdef FW_BUILD_WIN
- // [HLX] Temporary embed menu for windows
- WinAddEmbedMenu(ev, menuBar);
- #endif
-
- // ----- Arrange Menu -----
- FW_CPullDownMenu* pullDownMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kArrangeStr);
-
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kMoveForwardStr, cMoveForward, 'F');
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kMoveToFrontStr, cMoveToFront);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kMoveBackwardStr, cMoveBackward, 'B');
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kMoveToBackStr, cMoveToBack);
- pullDownMenu->AppendSeparator(ev);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kAlignToGridStr, cAlignToGrid);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kAlignObjectsStr, cAlignObjects);
- pullDownMenu->AppendSeparator(ev);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kRotateStr, cRotate);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kFlipHorizontalStr, cFlipH);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kFlipVerticalStr, cFlipV);
- pullDownMenu->AppendSeparator(ev);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kGroupStr, cGroup);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kUngroupStr, cUngroup);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kLockStr, cLock);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kUnlockStr, cUnlock);
- menuBar->AdoptMenuLast(ev, pullDownMenu);
-
- // ----- Size Menu -----
- pullDownMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kSizeStr);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, k1PixelStr, cPen1);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, k2PixelsStr, cPen2);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, k3PixelsStr, cPen3);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, k4PixelsStr, cPen4);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, k5PixelsStr, cPen5);
- menuBar->AdoptMenuLast(ev, pullDownMenu);
-
- // ----- Options Menu -----
- pullDownMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kOptionsStr);
- pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kHideRulersStr, kShowRulersStr, cRulers);
- pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kHideGraphicsGridStr, kShowGraphicsGridStr, cGraphicsGrid);
- pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kTurnAutoGridOnStr, kTurnAutoGridOffStr, cAutoGrid);
- pullDownMenu->AppendSeparator(ev);
- // ----- Unit sub-menu -----
- FW_CPullDownMenu* subMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kUnitsStr);
- subMenu->AppendTextItem(ev, resFile, kMenuStrings, kInchStr, cInchUnit);
- subMenu->AppendTextItem(ev, resFile, kMenuStrings, kCmStr, cCmUnit);
- subMenu->AppendTextItem(ev, resFile, kMenuStrings, kPixelStr, cPixelUnit);
- subMenu->AppendTextItem(ev, resFile, kMenuStrings, kPicaStr, cPicaUnit);
- subMenu->AppendSeparator(ev);
- subMenu->AppendTextItem(ev, resFile, kMenuStrings, kDegreesStr, cDegreesUnit);
- subMenu->AppendTextItem(ev, resFile, kMenuStrings, kRadiansStr, cRadiansUnit);
- pullDownMenu->AppendSubMenu(ev, subMenu);
- pullDownMenu->AppendSeparator(ev);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kScaleSelectionStr, cScaleSelection);
- pullDownMenu->AppendTextItem(ev, resFile, kMenuStrings, kRoundCornersStr, cRoundCorners);
-
- menuBar->AdoptMenuLast(ev, pullDownMenu);
-
- // ----- Windows Menu -----
- pullDownMenu = new FW_CPullDownMenu(ev, resFile, kMenuStrings, kWindowsStr);
- pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kShowPaletteStr, kHidePaletteStr, cHideShowPalette);
- pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kShowPatternsStr, kHidePatternsStr, cHideShowPattern);
- pullDownMenu->AppendToggleItem(ev, resFile, kMenuStrings, kShowToolsStr, kHideToolsStr, cHideShowTools);
- menuBar->AdoptMenuLast(ev, pullDownMenu);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::InternalizeContent
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::InternalizeContent(Environment *ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- // ----- Create an Archive for our shapes -----
- FW_CStorageUnitSink sink(storageUnit, kODPropContents, this->GetPartKind(ev));
- CDrawReadableStream archive(ev, this, &sink, cloneInfo);
-
- // ----- Read number of shapes -----
- unsigned long count;
- archive >> count;
-
- // ----- Read top left offset -----
- FW_CFixed xTopLeft, yTopLeft;
- archive >> xTopLeft;
- archive >> yTopLeft;
-
- for (short i = 0; i<count; i++)
- {
- CBaseShape* theShape = NULL;
- FW_READ_DYNAMIC_OBJECT(archive, &theShape, CBaseShape);
- FW_ASSERT(theShape);
-
- // ----- Add the shape to the shape list -----
- fShapeList->AddLast(theShape);
-
- if (xTopLeft || yTopLeft)
- {
- theShape->OffsetShape(ev, -xTopLeft, -yTopLeft);
- }
- theShape->SetExternalizationIndex(i); // so links can find their shapes
- }
-
- // ----- Read links -----
- CDrawLinkManager* linkMgr = (CDrawLinkManager*) this->GetLinkManager(ev);
- linkMgr->InternalizeLinks(ev, storageUnit);
-
- // ----- Now we have read everything in we can call the facet clipper -----
- CDrawFacetClipper facetClipper(ev, this);
- facetClipper.Clip(ev, fMainPresentation, NULL);
-
- // ----- Read general information -----
- if (storageUnit->Exists(ev, kContentAnnotationProp, (ODValueType)kContentAnnotationValue, 0))
- {
- FW_CStorageUnitSink sink(storageUnit, kContentAnnotationProp, kContentAnnotationValue);
- FW_CReadableStream stream(&sink);
- stream >> fTool;
- stream >> fCurrentPenSize;
- stream >> fRenderVerb;
- stream >> fAutoGrid;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::ExternalizeContent
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::ExternalizeContent(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- ODValueType contentPropertyValueType = this->GetPartKind(ev);
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, contentPropertyValueType, 0, kODPosUndefined);
- storageUnit->Remove(ev);
- storageUnit->AddValue(ev, contentPropertyValueType);
-
- // ----- Create an archive for our shapes -----
- FW_CStorageUnitSink sink(storageUnit, kODPropContents, contentPropertyValueType);
- CDrawWritableStream archive(ev, &sink, cloneInfo);
-
- // ----- Write number of shapes -----
- unsigned long count = fShapeList->Count();
- archive << count;
-
- // ----- Write top left offset -----
- FW_CFixed offset = FW_IntToFixed(0);
- archive << offset;
- archive << offset;
-
- // ----- Write shapes -----
- short extIndex = 0; // externalization index, used by links to identify shapes
- FW_COrderedCollectionIterator ite(fShapeList);
- for (CBaseShape* theShape = (CBaseShape*)ite.First(); ite.IsNotComplete(); theShape = (CBaseShape*)ite.Next())
- {
- FW_WRITE_DYNAMIC_OBJECT(archive, theShape, CBaseShape);
- theShape->SetExternalizationIndex(extIndex++); // so links can write their shapes' indices
- }
-
- // ----- Write links -----
- CDrawLinkManager* linkMgr = (CDrawLinkManager*) this->GetLinkManager(ev);
- linkMgr->ExternalizeLinks(ev, storageUnit, cloneInfo);
-
- // ----- Write general information -----
- // FW_SUAddPropValue correctly test if the property and value exist before
- // trying to create them
- FW_SUAddPropValue(ev, storageUnit, kContentAnnotationProp, kContentAnnotationValue);
-
- FW_CStorageUnitSink sink2(storageUnit, kContentAnnotationProp, kContentAnnotationValue);
- FW_CWritableStream stream(&sink2);
- stream << fTool;
- stream << fCurrentPenSize;
- stream << fRenderVerb;
- stream << fAutoGrid;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewShape
- //----------------------------------------------------------------------------------------
-
- CBaseShape* CDrawPart::NewShape(Environment* ev, unsigned short shapeType)
- {
- CBaseShape *theShape = NULL;
-
- FW_ASSERT(shapeType != kProxyShape); // We should never create a proxyShape this way
-
- switch (shapeType)
- {
- case kLineShape:
- theShape = new CLineShape();
- break;
-
- case kTextShape:
- theShape = new CTextShape();
- break;
-
- case kRectShape:
- theShape = new CRectShape();
- break;
-
- case kOvalShape:
- theShape = new COvalShape();
- break;
-
- case kRRectShape:
- theShape = new CRoundRectShape();
- break;
- }
-
- return theShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewLinkManager
- //----------------------------------------------------------------------------------------
- FW_CLinkManager* CDrawPart::NewLinkManager(Environment *ev)
- {
- CDrawLinkManager* linkMgr = FW_NEW(CDrawLinkManager, (ev, this));
- return linkMgr;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::RemoveShape
- //----------------------------------------------------------------------------------------
- void CDrawPart::RemoveShape(Environment* ev, CBaseShape* shape)
- {
- fShapeList->Remove(shape);
- shape->Removed(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DeleteShape
- //----------------------------------------------------------------------------------------
- void CDrawPart::DeleteShape(Environment* ev, CBaseShape* shape)
- {
- fShapeList->Remove(shape);
- shape->Deleted(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::AddShape
- //----------------------------------------------------------------------------------------
- void CDrawPart::AddShape(Environment* ev, CBaseShape* shape)
- {
- fShapeList->AddLast(shape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::AddShapeAfter
- //----------------------------------------------------------------------------------------
- void CDrawPart::AddShapeAfter(Environment* ev, CBaseShape* after, CBaseShape* shape)
- {
- fShapeList->AddAfter(after, shape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_CString32 name("ODFDraw");
- FW_CString32 sorry("Sorry, not yet implemented!");
-
- FW_Boolean result = TRUE;
- ODCommandID commandID = theMenuEvent.GetCommandID(ev);
-
- if (cPen1 <= commandID && commandID <= cPen5)
- {
- FW_CFixed penSize = FW_IntToFixed(commandID - cPen1 + 1);
- if (!fDrawSelection->IsEmpty(ev))
- fDrawSelection->ChangeSelectionPenSize(ev, penSize);
- else
- fCurrentPenSize = penSize;
- }
- else
- {
- switch (commandID)
- {
- #ifdef FW_BUILD_MAC
- case kODCommandAbout:
- ::FW_About(FW_gInstance);
- break;
- #endif
- case cHideShowPattern:
- if (fPatternWindow == NULL)
- {
- FW_CPoint position(FW_IntToFixed(100), FW_IntToFixed(100));
- fPatternWindow = new FW_CFloatingWindow(ev, GetODPart(ev), fPatternPresentation->GetPresentationType(ev), FW_CString32(""), FW_kZeroPoint, position, TRUE);
- }
- fPatternWindow->ShowHide(ev, !fPatternWindow->IsShown(ev));
- break;
-
- case cHideShowPalette:
- if (fPaletteWindow == NULL)
- {
- FW_CPoint position(FW_IntToFixed(100), FW_IntToFixed(100));
- fPaletteWindow = new FW_CFloatingWindow(ev, GetODPart(ev), fPalettePresentation->GetPresentationType(ev), FW_CString32(""), FW_kZeroPoint, position, TRUE);
- }
- fPaletteWindow->ShowHide(ev, !fPaletteWindow->IsShown(ev));
- break;
-
- case cHideShowTools:
- if (fToolsWindow == NULL)
- {
- FW_CPoint position(FW_IntToFixed(100), FW_IntToFixed(100));
- FW_CPoint windowSize(FW_IntToFixed(kToolsWindowWidth), FW_IntToFixed(kToolsWindowHeight));
- fToolsWindow = new FW_CFloatingWindow(ev, GetODPart(ev), fToolPresentation->GetPresentationType(ev), FW_CString32(""), windowSize, position, TRUE);
- }
- fToolsWindow->ShowHide(ev, !fToolsWindow->IsShown(ev));
- break;
-
- case cMoveForward:
- MoveForward(ev);
- this->Changed(ev);
- break;
- case cMoveToFront:
- MoveToFront(ev);
- this->Changed(ev);
- break;
- case cMoveBackward:
- MoveBackward(ev);
- this->Changed(ev);
- break;
- case cMoveToBack:
- MoveToBack(ev);
- this->Changed(ev);
- break;
-
- case cAutoGrid:
- fAutoGrid = !fAutoGrid;
- break;
-
- case cAlignObjects:
- #ifdef FW_DIALOGS_WIP
- LaunchDialog(ev, fAlignObjectsPresentation, kModalDialog,
- FW_CPoint(ff(100), ff(100)), FW_CPoint(ff(360), ff(220)));
- #endif
- // break;
-
- case cAlignToGrid:
- case cRotate:
- case cFlipH:
- case cFlipV:
- case cGroup:
- case cUngroup:
- case cLock:
- case cUnlock:
- case cScaleSelection:
- case cRoundCorners:
- FW_CAlert::DoNote(name, sorry);
- break;
-
- case cInchUnit:
- case cCmUnit:
- case cPixelUnit:
- case cPicaUnit:
- fUnit = commandID;
- break;
-
- case cDegreesUnit:
- case cRadiansUnit:
- fArcUnit = commandID;
- break;
-
- default:
- result = FALSE;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetTool
- //----------------------------------------------------------------------------------------
- void CDrawPart::SetTool(Environment* ev, unsigned short newTool)
- {
- if (fTool != newTool)
- {
- if (fTool == kSelectTool && !fDrawSelection->IsEmpty(ev))
- fDrawSelection->CloseSelection(ev);
-
- CheckTool(ev, fTool, newTool);
- fTool = newTool;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetRenderVerb
- //----------------------------------------------------------------------------------------
- void CDrawPart::SetRenderVerb(Environment* ev, unsigned short renderVerb)
- {
- if (fRenderVerb != renderVerb)
- {
- if (!fDrawSelection->IsEmpty(ev))
- {
- CChangeRenderVerbCommand* cmd = FW_NEW(CChangeRenderVerbCommand,
- (ev, this, this->GetActiveFrame(ev), fDrawSelection, renderVerb));
- this->ExecuteCommand(ev, cmd);
- }
-
- unsigned short oldRenderVerb = fRenderVerb;
- fRenderVerb = renderVerb;
- CheckRenderVerb(ev, oldRenderVerb, fRenderVerb);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::NewFrame
- //----------------------------------------------------------------------------------------
- FW_CFrame* CDrawPart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage)
- {
- if (presentation == fPalettePresentation)
- {
- FW_ASSERT(fPaletteFrame == NULL);
- return (fPaletteFrame = new CPaletteFrame(ev, odFrame, presentation, this));
- }
- else if (presentation == fPatternPresentation)
- {
- FW_ASSERT(fPatternFrame == NULL);
- return (fPatternFrame = new CPatternFrame(ev, odFrame, presentation, this));
- }
- else if (presentation == fToolPresentation)
- {
- FW_ASSERT(fToolFrame == NULL);
- return (fToolFrame = new CToolFrame(ev, odFrame, presentation, this));
- }
- // else if (presentation == fAlignObjectsPresentation)
- // {
- // return FW_NEW(CAlignObjectsFrame, (ev, odFrame, this));
- // }
-
- return new CDrawFrame(ev, odFrame, presentation, this);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- if (!hasMenuFocus)
- return FALSE;
-
- ODCommandID command;
- FW_Boolean hasSelection = fDrawSelection->Count() > 0;
-
- // ----- Edit Menu -----
- menuBar->EnableCommand(ev, kODCommandSelectAll, fShapeList->Count() > 0);
- menuBar->SetItemString(ev, kODCommandAbout, FW_CString32("About ODFDraw...")); // [HLX] Should go into a resource
-
- // ----- PenSize Menu -----
- FW_CFixed penSize = fCurrentPenSize;
- if (fDrawSelection->Count() >= 1)
- {
- if (!fDrawSelection->GetSelectionPenSize(ev, penSize))
- {
- penSize = FW_kFixed0;
- }
- }
- command = penSize.AsInt() + cPen1 - 1;
-
- for (ODCommandID p = cPen1; p <= cPen5; p++)
- menuBar->EnableAndCheckCommand(ev, p, TRUE, p == command);
-
- FW_Boolean readWrite = !IsReadOnly(ev);
-
- // ----- Arrange Menu -----
- menuBar->EnableCommand(ev, cMoveForward, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cMoveToFront, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cMoveBackward, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cMoveToBack, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cAlignToGrid, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cAlignObjects, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cRotate, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cFlipH, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cFlipV, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cGroup, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cUngroup, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cLock, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cUnlock, readWrite && hasSelection);
-
- // ----- Options Menu -----
- menuBar->EnableAndToggleCommand(ev, cAutoGrid, TRUE, !fAutoGrid);
- menuBar->EnableCommand(ev, cScaleSelection, readWrite && hasSelection);
- menuBar->EnableCommand(ev, cRoundCorners, TRUE);
-
- // ----- Units Menu -----
- menuBar->EnableAndCheckCommand(ev, cInchUnit, TRUE, fUnit == cInchUnit);
- menuBar->EnableAndCheckCommand(ev, cCmUnit, TRUE, fUnit == cCmUnit);
- menuBar->EnableAndCheckCommand(ev, cPixelUnit, TRUE, fUnit == cPixelUnit);
- menuBar->EnableAndCheckCommand(ev, cPicaUnit, TRUE, fUnit == cPicaUnit);
- menuBar->EnableAndCheckCommand(ev, cDegreesUnit, TRUE, fArcUnit == cDegreesUnit);
- menuBar->EnableAndCheckCommand(ev, cRadiansUnit, TRUE, fArcUnit == cRadiansUnit);
-
- // ----- Window Menu -----
- menuBar->EnableAndToggleCommand(ev, cHideShowTools, TRUE, fToolsWindow == NULL || !fToolsWindow->IsShown(ev));
- menuBar->EnableAndToggleCommand(ev, cHideShowPalette, TRUE, fPaletteWindow == NULL || !fPaletteWindow->IsShown(ev));
- menuBar->EnableAndToggleCommand(ev, cHideShowPattern, TRUE, fPatternWindow == NULL || !fPatternWindow->IsShown(ev));
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::CheckTool
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::CheckTool(Environment* ev, unsigned short oldTool, unsigned short newTool)
- {
- if (fToolFrame != NULL)
- fToolFrame->CheckTool(ev, oldTool, newTool);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::CheckRenderVerb
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::CheckRenderVerb(Environment* ev, unsigned short oldRenderVerb, unsigned short newRenderVerb)
- {
- if (fToolFrame != NULL)
- fToolFrame->CheckRenderVerb(ev, oldRenderVerb, newRenderVerb);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::UpdateAfterMove
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::UpdateAfterMove(Environment* ev)
- {
- CDrawFacetClipper facetClipper(ev, this);
- facetClipper.Clip(ev, fMainPresentation, fDrawSelection->GetUpdateShape());
-
- fMainPresentation->Invalidate(ev, fDrawSelection->GetUpdateShape());
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::MoveBackward
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::MoveBackward(Environment* ev)
- {
- FW_Boolean didIt = FALSE;
-
- CBaseShape* shape = (CBaseShape*)fShapeList->First();
- CBaseShape* previous = NULL;
- while (shape != NULL)
- {
- if (shape->IsSelectedShape() && previous != NULL && !previous->IsSelectedShape())
- {
- fShapeList->Remove(shape);
- fShapeList->AddBefore(previous, shape);
- shape->MovedBefore(ev, previous);
- shape = previous;
- didIt = TRUE;
- }
- else
- previous = shape;
-
- shape = (CBaseShape*)fShapeList->After(shape);
- }
-
- if (didIt)
- UpdateAfterMove(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::MoveForward
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::MoveForward(Environment* ev)
- {
- FW_Boolean didIt = FALSE;
-
- CBaseShape* shape = (CBaseShape*)fShapeList->Last();
- CBaseShape* next = NULL;
- while (shape != NULL)
- {
- if (shape->IsSelectedShape() && next != NULL && !next->IsSelectedShape())
- {
- fShapeList->Remove(shape);
- fShapeList->AddAfter(next, shape);
- shape->MovedAfter(ev, next);
- shape = next;
- didIt = TRUE;
- }
- else
- next = shape;
-
- shape = (CBaseShape*)fShapeList->Before(shape);
- }
-
- if (didIt)
- UpdateAfterMove(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::MoveToBack
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::MoveToBack(Environment* ev)
- {
- FW_CPrivOrderedCollection* extract = ExtractSelection(ev);
-
- FW_TRY
- {
- FW_COrderedCollectionIterator ite(extract);
- for (CBaseShape* shape = (CBaseShape*)ite.Last(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Previous())
- {
- fShapeList->AddFirst(shape);
- shape->MovedFirst(ev);
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete extract; // calls RemoveAll
-
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- delete extract; // calls RemoveAll
-
- UpdateAfterMove(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::MoveToFront
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::MoveToFront(Environment* ev)
- {
- FW_CPrivOrderedCollection* extract = ExtractSelection(ev);
-
- FW_TRY
- {
- FW_COrderedCollectionIterator ite(extract);
- for (CBaseShape* shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- fShapeList->AddLast(shape);
- shape->MovedLast(ev);
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete extract; // calls RemoveAll
-
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- delete extract; // calls RemoveAll
-
- UpdateAfterMove(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::ExtractSelection
- //----------------------------------------------------------------------------------------
-
- FW_CPrivOrderedCollection* CDrawPart::ExtractSelection(Environment* ev)
- {
- FW_CPrivOrderedCollection* extract = new FW_CPrivOrderedCollection;
-
- // ----- Create the extract list -----
- FW_COrderedCollectionIterator ite(fShapeList);
- CBaseShape* shape;
- for (shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->IsSelectedShape())
- extract->AddLast(shape);
- }
-
- // ----- Remove then from the shape list -----
- FW_COrderedCollectionIterator ite2(extract);
- for (shape = (CBaseShape*)ite2.First(); ite2.IsNotComplete(); shape = (CBaseShape*)ite2.Next())
- {
- fShapeList->Remove(shape);
- }
-
- return extract;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::UpdateAllToolFacets
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::UpdateAllToolFacets(Environment *ev)
- {
- if (fToolFrame != NULL)
- fToolFrame->UpdateColors(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetFillColor
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetFillColor(Environment *ev, const FW_CColor& color)
- {
- if (fDrawSelection->IsEmpty(ev))
- {
- fFillColor = color;
- UpdateAllToolFacets(ev);
- }
- else if (!fDrawSelection->IsOKtoEdit(ev))
- {
- FW_Beep();
- }
- else
- {
- CChangeColorCommand* cmd = FW_NEW(CChangeColorCommand,
- (ev, cChangeFillColor, this, this->GetActiveFrame(ev), fDrawSelection, color));
- this->ExecuteCommand(ev, cmd);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetFrameColor
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetFrameColor(Environment *ev, const FW_CColor& color)
- {
- if (fDrawSelection->IsEmpty(ev))
- {
- fFrameColor = color;
- UpdateAllToolFacets(ev);
- }
- else if (!fDrawSelection->IsOKtoEdit(ev))
- {
- FW_Beep();
- }
- else
- {
- CChangeColorCommand* cmd = FW_NEW(CChangeColorCommand,
- (ev, cChangeFrameColor, this, this->GetActiveFrame(ev), fDrawSelection, color));
- this->ExecuteCommand(ev, cmd);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetFillPattern
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetFillPattern(Environment *ev, short newFillPatIndex)
- {
- if (fDrawSelection->IsEmpty(ev))
- {
- fFillPatIndex = newFillPatIndex;
- UpdateAllToolFacets(ev);
- }
- else if (!fDrawSelection->IsOKtoEdit(ev))
- {
- FW_Beep();
- }
- else
- {
- FW_PPattern pattern = GetPattern(newFillPatIndex)->Copy();
- CChangePatternCommand* cmd = FW_NEW(CChangePatternCommand,
- (ev, cChangeFillPattern, this, this->GetActiveFrame(ev), fDrawSelection, pattern));
- this->ExecuteCommand(ev, cmd);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::SetFramePattern
- //----------------------------------------------------------------------------------------
-
- void CDrawPart::SetFramePattern(Environment *ev, short newFramePatIndex)
- {
- if (fDrawSelection->IsEmpty(ev))
- {
- fFramePatIndex = newFramePatIndex;
- UpdateAllToolFacets(ev);
- }
- else if (!fDrawSelection->IsOKtoEdit(ev))
- {
- FW_Beep();
- }
- else
- {
- FW_PPattern pattern = GetPattern(newFramePatIndex)->Copy();
- CChangePatternCommand* cmd = FW_NEW(CChangePatternCommand,
- (ev, cChangeFramePattern, this, this->GetActiveFrame(ev), fDrawSelection, pattern));
- this->ExecuteCommand(ev, cmd);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::WhichShape
- //----------------------------------------------------------------------------------------
-
- CBaseShape* CDrawPart::WhichShape(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent, FW_Boolean hasToBeSelected) const
- {
- FW_COrderedCollectionIterator ite(fShapeList);
- for (CBaseShape* shape = (CBaseShape*)ite.Last(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Previous())
- {
- FW_Boolean test = (!hasToBeSelected) || (hasToBeSelected && shape->IsSelectedShape());
- if (test && shape->HitTest(ev, gc, theMouseEvent))
- return shape;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::FindShapeWithIndex
- //----------------------------------------------------------------------------------------
- CBaseShape* CDrawPart::FindShapeWithIndex(short extIndex)
- {
- // Search the shape list and return the shape with the specified externalization index
- FW_COrderedCollectionIterator ite(fShapeList);
- for (CBaseShape* shape = (CBaseShape*)ite.First(); ite.IsNotComplete(); shape = (CBaseShape*)ite.Next())
- {
- if (shape->GetExternalizationIndex() == extIndex)
- return shape;
- }
-
- // extIndex not found!?
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawPart::DoPostCreate
- //----------------------------------------------------------------------------------------
- void CDrawPart::DoPostCreate(Environment* ev)
- {
- // Perform "DoPostCreate"-type initialization.
- // In our case, we want to make sure that any subscribers that were just internalized
- // get registered for automatic updates.
-
- if (!fPostCreated) // do this only once!
- {
- CDrawLinkManager* linkMgr = (CDrawLinkManager*) this->GetLinkManager(ev);
- linkMgr->RegisterSubscribers(ev);
- fPostCreated = TRUE;
- }
- }
-