home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TextensionCommand.h
-
- Contains: xxx put contents here xxx
-
- Written by: Essam Zaky
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 1/4/94 EZ clean up
- <1> 1/4/94 EZ first checked in
-
- */
-
- #ifndef _TextensionCommand_
- #define _TextensionCommand_
-
- #ifndef _Textension_
- #include "Textension.h"
- #endif
-
- #ifndef _TSMTextension_
- #include "TSMTextension.h"
- #endif
-
- #ifndef _Frames_
- #include "Frames.h"
- #endif
-
- #ifndef _TextensionIOSuite_
- #include "TextensionIOSuite.h"
- #endif
-
- #ifndef _Streams_
- #include "Streams.h"
- #endif
-
- #ifndef _AttrObject_
- #include "AttrObject.h"
- #endif
-
- #ifdef txtnRulers
- #ifndef _RulerObject_
- #include "RulerObject.h"
- #endif
- #endif
-
- //**************************************************************************************************
-
-
- //constants for command state (returned from "GetCommandState")
- const char kDoCommandState = 0;
- const char kUndoCommandState = 1;
- const char kRedoCommandState = 2;
-
- const char kErrorCommandState = 4;
-
- //**************************************************************************************************
-
- const short kNoTextensionCommand = 0;
- //initializes the variables to nil, so that a Free will not release theme
-
- //••constants for CTextensionEditCommand command ids
-
- const short kTextensionKeyCommand = 1;
- const short kTextensionCutCommand = 1 << 1;
- const short kTextensionPasteCommand = 1 << 2;
- const short kTextensionClearCommand = 1 << 3;
-
-
- const short kTextensionRunCommand = 1 << 4; //face, font, color, ...
-
- #ifdef txtnRulers
- const short kTextensionRulerCommand = 1 << 5; //add tab, delete tab, just, line spacing, ...
- #endif
-
- #ifdef txtnAdvRulers
- const short kTextensionPasteRulerCommand = 1 << 6;
- const short kTextensionModifyTabCommand = 1 << 7;
- #endif
-
- const short kTextensionTextModifCommandMask = kTextensionKeyCommand + kTextensionCutCommand + kTextensionPasteCommand + kTextensionClearCommand;
- const short kTextensionRunsModifCommandMask = kTextensionRunCommand;
-
- #ifdef txtnRulers
- #ifdef txtnAdvRulers
- const short kTextensionRulersModifCommandMask = kTextensionRulerCommand+kTextensionPasteRulerCommand+kTextensionModifyTabCommand;
- #else
- const short kTextensionRulersModifCommandMask = kTextensionRulerCommand;
- #endif
- #endif
-
- //•descendents should not use command numbers 1..5000
-
-
- //*************************************************************************************************
-
-
- #ifdef txtnAdvRulers
- /*when calling ITextensionEditCommand, the modifier.fAttr should be kTabAttr, fAttrValue should
- point to a "TModifyTabCommandData" struct, fMessage is not used */
-
- struct TModifyTabCommandData {
- short oldValue;
- Ttab newTab;
- };
- typedef TModifyTabCommandData* TModifyTabCommandDataPtr;
- #endif
-
- //**************************************************************************************************
-
- //•"KeyCommandResult" defs
- typedef unsigned char KeyCommandResult;
-
- const KeyCommandResult kSameKeyCommand = 0;
- const KeyCommandResult kEndKeyCommand = 1 << 0;
- const KeyCommandResult kStartNewKeyCommand = 1 << 1;
-
- //**************************************************************************************************
-
- class CTextensionCommand : public HandleObject {
- public:
- //-----
- CTextensionCommand();
-
- virtual void Free();
-
- OSErr Execute(short* userAction = nil);
- //userAction has the same meaning as the value returned from CTextension::DisplayChanged
-
- inline short GetCommandId() const {return fCmdId;}
- inline char GetCommandState() const {return fState;}
-
- inline char CanUndo() {return fCanUndo;}
-
- inline CTextension* GetTextension() const {return fTextension;}
-
- protected:
- //--------
- CTextension* fTextension;
-
- short fCmdId;
-
- char fCanUndo;
- char fState;
-
- void ITextensionCommand(CTextension* textension, short theCmd);
-
- //userAction has the same meaning as the value returned from CTextension::DisplayChanged
- virtual OSErr DoIt(short* userAction) = 0;
- virtual OSErr UndoIt(short* userAction) = 0;
- virtual OSErr RedoIt(short* userAction) = 0;
-
- private:
- //------
- };
- //**************************************************************************************************
-
- class CTextensionEditCommand : public CTextensionCommand {
- public:
- //-----
- CTextensionEditCommand();
-
- OSErr ITextensionEditCommand(CTextension* textension, short theCmd
- , Boolean* noMemForUndo
- , const TAttrObjModifier* modifier =nil);
- /*modifier->fObj if not nil should be valid during the life of this object and will be deleted when the command is freed.
- Even if an error occur Free should be called.*/
-
- //•overide
- virtual void Free();
-
- protected:
- //--------
- TAttrObjModifier fAttrObjModifier;
-
- TOffsetRange fOldSelRange;
-
- #ifdef txtnRulers
- TOffsetRange fRulersRange;
- #endif
-
- TOffset fNewSelEnd;
-
- CTextensionIOSuite* fOldIOSuite;
- char fNoOldIOSuiteData; //used to distinguish between fOldIOSuite is nil beacuse of memory error or because old sel range was empty
-
- CTextensionIOSuite* fNewIOSuite; //used for Redo paste
-
- #ifdef txtnNever
- long fCmdContextId;
- #endif
-
- //•overide
- virtual OSErr DoIt(short* userAction);
- virtual OSErr UndoIt(short* userAction);
- virtual OSErr RedoIt(short* userAction);
-
- //•own
- virtual OSErr SaveOldSelRangeIOSuite();
- OSErr SaveNewSelRangeIOSuite();
-
- virtual void GetUndoSelectionRange(TOffsetRange* selRange);
- virtual void GetRedoSelectionRange(TOffsetRange* selRange);
-
- private:
- //------
- CTextensionIOSuite* SaveIOSuite(TOffsetRange* range, TIOFlags flags);
-
- #ifdef txtnAdvRulers
- void ModifyTab();
- #endif
- };
- //*************************************************************************************************
-
-
- class CTextensionKeyCommand : public CTextensionEditCommand {
- public:
- //-----
- CTextensionKeyCommand();
-
- OSErr ITextensionKeyCommand(CTextension* textension, TKeyDownParams* keyParams, Boolean* noMemForUndo);
-
- //•override
-
- //•own
- KeyCommandResult NewKey(EventRecord* event, TKeyDownParams* keyParams);
-
- protected:
- //--------
- //•override
- virtual OSErr SaveOldSelRangeIOSuite();
-
- virtual OSErr DoIt(short* userAction);
- virtual OSErr UndoIt(short* userAction);
-
- virtual void GetUndoSelectionRange(TOffsetRange* selRange);
- virtual void GetRedoSelectionRange(TOffsetRange* selRange);
-
- //•own
- virtual Boolean AcceptKey(const TKeyDownParams* keyParams);
- virtual Boolean AddKey(EventRecord* event, TKeyDownParams* keyParams);
-
- private:
- //------
- char fFirstKey;
- char fCantAcceptOtherKeys;
- TOffset fMinBackSpaceOffset;
- };
- //***************************************************************************************************
-
- class CTSMTextensionKeyCommand : public CTextensionKeyCommand {
- public:
- //-----
- CTSMTextensionKeyCommand();
-
- OSErr ITSMTextensionKeyCommand(CTextension* textension, TKeyDownParams* keyParams, Boolean* noMemForUndo);
-
- //•override
-
- //•own
-
- protected:
- //--------
- //•override
- virtual Boolean AcceptKey(const TKeyDownParams* keyParams);
- virtual Boolean AddKey(EventRecord* event, TKeyDownParams* keyParams);
-
- virtual OSErr UndoIt(short* userAction);
-
- private:
- //------
- CTSMTextension* fTSMTextension;
- long fInlineAreaStart;
- long fOldCountChars;
-
- void TerminateInline();
- };
- //***************************************************************************************************
-
-
- #endif
-