// $Revision: 1.3 $ // Copyright (C) 1994-1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_TEXTTOOLSAMPLE #define TaligentSamples_TEXTTOOLSAMPLE #ifndef Taligent_MOUSECURSORTOOLS #include #endif #ifndef Taligent_PRIMITIVECLASSES #include #endif #ifndef Taligent_TEXTSELECTION #include #endif #ifndef Taligent_TEXTTYPES #include #endif #ifndef Taligent_STANDARDARROWTOOL #include #endif #ifndef Taligent_RGBCOLOR #include #endif #ifndef Taligent_TEXTTOOLS #include #endif // TSampleTextTool applies the command to the selection established during interaction. // The cursor graphic, palette graphic, and palette text may be customized by adopting // these objects. // You can only customize the interactor by subclassing CreateInteractor. Since you // must know the MToolHandler before creating a TToolInteractor, we can't pass a prototype // and customize it later. To get around this, the tool is passed the command it will // use when it later instantiates the interactor. // !!! It might be worthwhile to rewrite this using TInstanceOf<> to handle some of // the pointer management. class TSampleTextTool : public TSimpleMouseTool { public: MCollectibleDeclarationsMacro (TSampleTextTool); TSampleTextTool(TCommandOn* commandToAdopt, MGraphic* cursorGraphicToAdopt = NIL, MGraphic* paletteGraphicToAdopt = NIL, TText* paletteTextToAdopt = NIL); TSampleTextTool(const TSampleTextTool&); virtual ~TSampleTextTool(); TSampleTextTool& operator=(const TSampleTextTool&); virtual void GetPaletteText(TText&) const; virtual MGraphic* CreatePaletteGraphic() const; virtual MGraphic* CreateCursorGraphic() const; virtual TToolInteractor* CreateInteractor(MToolTarget* adoptTarget) const; virtual TStream& operator>>=(TStream&) const; virtual TStream& operator<<=(TStream&); static MGraphic* CreateHighlighterGraphic(const TRGBColor& fillColor); static MGraphic* CreateEraserGraphic(const TRGBColor& fillColor); protected: TSampleTextTool(); private: void InternalDelete(); void InternalCopy(const TSampleTextTool&); TCommandOn* fCommand; MGraphic* fCursorGraphic; MGraphic* fPaletteGraphic; TText* fPaletteText; enum EVersion { kOriginalVersion }; }; // Track the mouse while down, and execute the command against the selection in the // target on mouse up. Selection is left as an insertion point at the mouse up // location. class TSampleTextToolInteractor : public TToolInteractor, public MMouseEventHandler { public: VersionDeclarationsMacro(TSampleTextToolInteractor); TSampleTextToolInteractor(MToolHandler* handlerAlias, TTextToolInteractionTarget* targetToAdopt, TCommandOn* commandToAdopt); TSampleTextToolInteractor(const TSampleTextToolInteractor&); virtual ~TSampleTextToolInteractor(); virtual bool MouseDown(TMouseDownEvent&); virtual bool MouseMoved(TMouseMovedEvent&); virtual bool MouseUp(TMouseUpEvent&); private: TTextToolInteractionTarget* fTarget; TCommandOn* fCommand; MTextSelection* fSelection; TTextOffset fAnchor; }; #endif // TaligentSamples_TEXTTOOLSAMPLE