// $Revision: 1.2 $ // Copyright (C) 1994, 1995 Taligent, Inc. All rights reserved. // TilesView.h #ifndef TaligentSample_TILESVIEW #define TaligentSample_TILESVIEW // Include for embedder classes #ifndef Taligent_GUICOMPOUNDDOCUMENTEMBEDDER #include #endif // Include for Presentation Framework #ifndef Taligent_GUICOMPOUNDDOCUMENT #include #endif // Include for Presentation Framework commands #ifndef Taligent_GUICOMPOUNDDOCUMENTCOMMAND #include #endif // Include for drawing services, TGrafPort #ifndef Taligent_GRAFPORT #include #endif // Include for current selection support #ifndef TaligentSample_TILESSELECTIONS #include "TilesSelections.h" #endif // Include for drag and drop support #ifndef Taligent_MOUSEDRAGANDDROP #include #endif #ifndef Taligent_DROPACCEPTOR #include #endif #ifndef TaligentSample_TILESMODEL #include "TilesModel.h" #endif // The view is where all rendering will occur. TTilesView derives from TGUIEmbedderModelView // which provides for view capabilities (DrawContents), GUIBundle capabilities (GetModelReference, // GetPresenterStateReference, etc.) and full cut/copy/paste, embedding and embeddability support. // Embedded components are displayed as floating "Postit" type notes. TGUIEmbedderModelView already // mixes in MMouseEventHandler so it can handle mouse hit detection on embedded views. class TTilesView : public TGUIEmbedderModelView, public MDropAcceptor { public: // VersionDeclarationsMacro required because of inheritance from TGUIEmbedderModelView // and MDropAcceptor. VersionDeclarationsMacro (TTilesView); // All classes derived from TDocumentComponentView need to accept // a TGUIBundle* in their constructor,which they pass on to // TDocumentComponentView. The TGUIBundle "ties together" the elements // in a Presentation Framework document. TTilesView (TGUIBundle* b); virtual ~TTilesView (); // MouseDown() will figure out which tile is affected, create a command/ // selection pair and have the document AdoptAndDo() it. virtual bool MouseDown (TMouseDownEvent&); // MDropAcceptor overrides. ChoosePreferredType provides a list of available types that // the drag and drop event can provide. If an acceptable type is found (possibly determined // by the drop location), then chosenType is set to the type chosen and true is returned. virtual bool ChoosePreferredType(const TGPoint& whereDropped, const TSequenceOf& availableTypes, TTypeDescription& chosenType) const; // AcceptDrop will provide the type chosen in ChoosePreferredType through a scrap item. The // scarp item must be dynamically downcast to the expected scrap item containing the chosen type. virtual bool AcceptDrop( const TGPoint& whereDropped, const TTypeDescription& theType, const TScrapItem &theItem); // A convenience function which calls MGUIBundle's GetCurrentModelSelection and // safely downcasts the TModelSelection to a TTilesSelection*. The user should // always check for a 0 pointer after calling this function. const TTilesSelection* GetTilesSelection () const; protected: // HandleAfterConnectionToViewRoot is called by the Framework when the view is added // to the view hierachy. This usually happens just before the view is made // visible. Initialization routines are usually added here. virtual void HandleAfterConnectionToViewRoot (); // HandleBeforeDisconnectionFromViewRoot is called by the Framework when the view is removed // to the view hierachy. This usually happens just before the view is destroyed. // Cleanup routines are usually added here. virtual void HandleBeforeDisconnectionFromViewRoot (); // Draw contents renders the data from the model. This is the primary method // of a content view. The TGrafPort is already clipped to the region which needs // to be redrawn, so DrawContents should re-render the entire view and rely on // the port to do any necessary clipping. virtual void DrawContents (TGrafPort& port) const; // Draw an individual TTile into the port. Hilight the TTile if it is in the current selection. void DrawTile (TGrafPort& port, const TTile* tile, bool inCurrentSelection) const; // Build an array of MGraphics which maps the data in the model (rock, // paper, scissors) to drawable objects for use by DrawContents. void BuildTilesGraphicsMapToModel (); void DestroyTilesGraphicsMapToModel (); protected: TTilesView (); TTilesView (const TTilesView& copy); private: // Used in the VersionDefinitionsMacro enum {kOriginalVersion}; // Used to store the map of MGraphics used for rendering enum {kNumTilesGraphics=3}; MGraphic* fTilesGraphics[kNumTilesGraphics]; }; #endif // TaligentSample_TILESVIEW