SECEdit Class

class SECEdit: public MvcTransactionModel, public CObject

The SECEdit class represents the data model which is manipulated by the controller class (SECEditController) and observed by the viewport class (SECEditViewport, a parent class of both SECEditCtrl and SECEditView). Because this class derives from MvcTransactionModel, it is capable of undo and redo operations.

Actually, the text itself is not stored in the SECEdit model, but is stored in SECEditBuffer, which implements the ISECEditBuffer interface.

SECEditCtrl objects contain a SECEdit model, whereas SECEditView objects simply reference a SECEdit model through a pointer (since multiple views may refer to the same model).

Defined in: SECEdit.h

See Also

SECEditController  SECEditBlockBuffer  SECEditViewport  SECEditCtrl  SECEditView

Class Members

Creation/Initialization

 SECEdit()

Default Constructor.

virtual BOOL  Init()

Initializes the SECEdit model.

virtual BOOL  Init(LPCTSTR lpszLanguage)

Initializes the SECEdit model.

virtual  ~SECEdit()

Default Destructor

Syntax Coloring and Language

virtual BOOL  Configure()

Invokes the language configuration dialog for the current language.

virtual ISECEditLangConfig*  GetLangPtr() const

Get the language pointer for this model

virtual void  SetLangPtr(ISECEditLangConfig* pILangConfig)

Explicitly set the language for this model

CString  GetLangId() const

Returns a string with the language this model is using

virtual BOOL  SetLanguage(LPCTSTR lpszLanguage)

Set the language by name for this model

BOOL  GetSyntaxColoring() const

Indicates if syntax coloring is enabled for this model

void  SetSyntaxColoring(BOOL bEnabled)

Sets the status of syntax coloring for this model

virtual SECEditFontInfo*  GetFontInfo()

Retrieves the font info manager object.

virtual void  SetFontInfo(SECEditFontInfo* pFontInfo)

Sets the font info manager object.

virtual SECEditLineColor*  GetLineColor(int nLine)

Retrieves the color of the text on the given line.

virtual SECEditLineColor*  SetLineColor(int nLine, int nStartCol = 0)

Sets the line color for the given line.

virtual SECEditFontInfo*  GetNewFontInfo()

Creates the font info manager object.

virtual int  ColorToken(int nLine, LPCTSTR lpszLine, LPCTSTR lpszToken, int nTokenLength, int nLength, unsigned short& nWhiteLength, SECEditLineColor* pLineColor)

Sets the syntax coloring for the token given

virtual int  ColorKeyword(int nLine, LPCTSTR lpszLine, LPCTSTR lpszToken, int nTokenLength, int nLength, unsigned short& nWhiteLength, SECEditLineColor* pLineColor)

Sets the syntax coloring for the keyword given

virtual int  ColorTokenKw(int nLine, LPCTSTR lpszLine, LPCTSTR lpszToken, int nTokenLength, int nLength, unsigned short& nWhiteLength, SECEditLineColor* pLineColor)

Sets the syntax coloring for the token keyword given

virtual int  ColorOperatorKw(int nLine, LPCTSTR lpszLine, LPCTSTR lpszToken, int nTokenLength, int nLength, unsigned short& nWhiteLength, SECEditLineColor* pLineColor)

Sets the syntax coloring for the operator given

virtual SECEditKeywordInfo*  IsTokenKw(int nLine, LPCTSTR lpszLine, LPCTSTR lpszToken, int nTokenLength, int nLength, SECEditKeywordType keytype/* = secKT_All */) const

Determines of the token passed begins a token keyword

virtual int  ColorTokenKwML(int nLine, LPCTSTR lpszLine, LPCTSTR lpszToken, int nLength, SECEditLineColor* pLineColor, SECEditKeywordInfo* pInfo)

Sets the syntax coloring for the multiline token keyword passed

virtual int  ColorTokenKwSL(int nLine, LPCTSTR lpszLine, LPCTSTR lpszToken, int nLength, SECEditLineColor* pLineColor, SECEditKeywordInfo* pInfo)

Sets the syntax coloring for the single line token keyword passed

virtual void  FillWhiteLength(SECEditLineColor* pLineColor, unsigned short& nWhiteLength)

Sets the syntax coloring for the block of non colored text prior to a colored block

virtual SECEditLineCol  FindTokenKwEnd(SECEditLineCol lcStart, SECEditKeywordInfo* pInfo) const

Finds the end of the token keyword passed

void  ResetKeywordColoringCache()

Clears the syntax coloring cache and causes visible lines to be recolored

LPCTSTR  EndKeyword(LPCTSTR lpszText, int nLength) const

Parses for the end of a keyword.

virtual int  IsKeyword(LPCTSTR lpszKeyword, int nKeywordLength, unsigned short& nOffset) const

Compares given string to the list of keywords.

virtual BOOL  FindSLComment(int nLine, int& nStartCol, int& nEndCol) const

Searches for the given single line keyword (e.g., comments, quotes, and operators).

virtual BOOL  IsLineColInSLComment(const SECEditLineCol& lc, int* pStartCol = NULL, int* pEndCol = NULL) const

Tests whether the given text position is located in a single line comment.

BOOL  ColorMLComments(const SECEditLineColPair& lcpBlock)

Colors all Multiline keywords in lcpBlock.

Text Document

virtual ISECEditBuffer*  GetNewEditBuffer()

Creates the edit buffer containing the text for the model.

BOOL  IsModified() const

Tests the model for the modified state.

virtual void  SetModified(BOOL bModified = TRUE)

Sets the modified state of the model.

BOOL  GetOverStrike() const

Tests the overstrike state.

void  SetOverStrike(BOOL bOverStrike)

Sets or clears the overstrike state.

virtual BOOL  GetReadOnly() const

Tests the read-only state.

void  SetReadOnly(BOOL bReadOnly = TRUE)

Sets the read-only state.

unsigned char  GetDefaultCharset() const

Returns the default character set in use by this model

SECEditLineCol  GetDocEnd() const

Returns a SECEditLineCol just after the last character in the document

CString  GetLineBreakChar() const

Retrieves the linebreak character if one exists.

virtual TCHAR  GetWhitespaceChar(BOOL bTabChar = FALSE) const

Retrieves a visible character that represents white space.

BOOL  m_bForceLineLengthValid

Set to TRUE for transient operations in which line length validation should not be performed

virtual void  Serialize(CArchive& ar)

Serializes the Text and the Language name of this SECEdit

virtual void  SerializeText(CArchive& ar)

Serializes the text only of this SECEdit

virtual void  SerializeLang(CArchive& ar)

Serializes the Language Name only of this SECEdit

void  GetEditText(CString& strEditText) const

Places a copy of all of the text of this SECEdit into the CString reference parameter

void  SetEditText(LPCTSTR lpszText, int nLength = -1)

Sets the text of this SECEdit to the given text and clears the undo buffers

virtual BOOL  ReadFile(LPCTSTR lpszPathName)

Reads in text from a file.

virtual void  ReadFileFail()

CWang005 Error Handler for ReadFile

virtual BOOL  SaveFile(LPCTSTR lpszPathName)

Saves the current text to a file.

BOOL  AppendFileData(LPSTR lpszText, UINT nBytes, int& nLine, int& nCol)

Helper method for loading data from a file.

int  GetTabStops(SECEditFontInfo* pFontInfo) const

Retrieves the width of an expanded tab stop in logical units.

virtual BOOL  Insert(int nLine, int nCol, LPCTSTR lpszText, int nLength = -1)

Inserts text into the the text buffer at the specified position.

virtual BOOL  Insert(SECEditLineColPair& lcpInsertBlock, LPCTSTR lpszText, int nLength = -1)

Inserts text into the the text buffer at the specified position.

virtual int  ConvertColumn(int nCol, BOOL bConversionType, LPCTSTR lpszLine, int *pScreenCol = NULL) const

Converts the given column offset on a line to an actual offset.

virtual int  ConvertColumn(int nCol, BOOL bConversionType, int nLine, int *pScreenCol = NULL) const

Converts the given column offset on a line to an actual offset.

virtual CString  PadSpaces(int nSpaces, SECEditLineCol lcSpace = SECEditLineCol(0, 0), BOOL bUseDefault = TRUE) const

Return a string that would fill the requestd amount of whitespace

virtual int  GetTabSpaces(SECEditLineCol lc) const

Return the number of spaces a tab stop at this location would require

virtual BOOL  ClearTextBlock(int nStartLine, int nStartCol, int nEndLine, int nEndCol)

Clears the block of text specified by the given positions.

virtual int  GetTextBlock(LPCTSTR& lpszBlock, int nStartLine, int nStartCol = 0, int nEndLine = -1, int nEndCol = -1) const

Retrieves the block of text between by two positions.

virtual BOOL  GetTextBlock(CString& strBlock, int nStartLine, int nStartCol = 0, int nEndLine = -1, int nEndCol = -1) const

Retrieves the block of text between by two positions.

virtual void  UpdateModifiedFlag()

Sets the modified flag.

virtual int  FindText(int nLine, int nCol, int& nResultLine, int& nResultCol, LPCTSTR lpszText, BOOL bDown, BOOL bWrapAround, BOOL bMatchCase, BOOL bMatchWholeWord, BOOL bRegularExpression, int nStopLine = -1, int nStopCol = -1) const

Locates text in the text buffer.

LPCTSTR  FindNextChar(LPCTSTR lpszText, TCHAR chFind, int nLength = -1) const

Find a character in a string.

LPCTSTR  FindNextString(LPCTSTR lpszText, LPCTSTR lpszFind, int nLength = -1, BOOL bMatchCase = TRUE) const

Find a string in a string.

SECEditCharType  GetCharType(unsigned int nChar, BOOL bReturnWhitespace = FALSE) const

Return the type of the given character

void  FreeUndoBuffers()

Clears the undo state of the transaction model.

virtual void  InitFontInfo()

Initializes the font info for the model.

virtual BOOL  InsertTab(int nLine, int nCol)

Inserts a tab or spaces to the text data.

BOOL  LineColFromChar(int nIndex, int& nLine, int& nCol) const

Converts an index position into line and column.

int  LineIndex(int nLine, int nCol = 0) const

Converts a line and column position into a virtual text index.

virtual BOOL  EnforceLineLengths(BOOL bEnforce = TRUE, int nStartLine = 0, int nEndLine = -1)

Validates the lengths and optionally breaks any lines that are too long in the given range

virtual sfl::MvcCommand*  ProcessInsert(SECEditLineColPair& lcpInsertBlock)

Creates a command objects for insert commands.

BOOL  EnforceMaxLineLength(SECEditLineColPair& lcpBlock, SECEditCompositeCommand* pCmd, int nFirstLineInsert = -1)

Scans lines in the given block to enforce the max length rule

void  UpdateCmds(SECEditCommand* pCmd)

Updates the state of the model to accomodate the effect of the given command

sfl::MvcCommand*  m_pCurrentCommand

Points to the current command.

sfl::MvcController*  m_pDragSelf

Indicates a self-source copy to the controller.

Undo/Redo

virtual sfl::MvcCommand*  Undo()

Performs an undo operation on the last command.

virtual sfl::MvcCommand*  Redo()

Performs a redo on a command that has been undone.

BOOL  GetUndoGroup() const

Test the command grouping state.

virtual void  SetUndoGroup(BOOL bGroupCommands)

Groups commands as they are executed so they can be undone as a singleton.

sfl::MvcCommand*  RemoveTopUndoCmd()

Removes the top command from the undo stack.

virtual void  MergeUndoCommand(SECEditCommand* pCmd, BOOL bNewCmdFirst)

Merges the given command with the top command on the undo stack.

virtual BOOL  Log(sfl::MvcCommand* pCmd)

Logs the given command.

Line

virtual int  GetLine(int nLine, CString& strLine, LPCTSTR& lpszLine) const

Retrieves the text on a given line.

int  GetLineLength(int nLine) const

Retrieves the length of a given line.

virtual int  GetLineVisibleLength(int nLine) const

Retrieves the number of visible characters on a given line.

virtual BOOL  IsLineColValid(int nLine, int nCol, BOOL bVirtualSpace = FALSE) const

Tests the validity of a given line and column pair.

virtual int  DoesSplitMBCS(int nLine, int nCol, BOOL bVirtualSpace = FALSE) const

Tests whether a byte splits a multibyte character.

int  GetLineCount() const

Retrieves the number of lines in the text.

int  GetLastLine() const

Gets the zero-based line number of the last text line.

CString  GetLineEnd() const

Returns the character that signals the end of a line.

virtual int  GetMaxWidth() const

Retrieves the maximum possible width of a line.

virtual BOOL  IsLineWhiteSpace(int nLine) const

Tests the line for the presence of exclusively white space.

int  FirstNonWhiteChar(int nLine) const

Retrieves the index of the first non-whitespace character.

Line ItemData

virtual BOOL  GetItemDataFlag(int nLine, unsigned int nFlag) const

Retrieves an indexed bit flag for a given line.

void  SetItemDataFlag(int nLine, unsigned int nFlag, BOOL bAdd)

Sets or clears an indexed bit flag for a given line.

virtual void  ToggleItemDataFlag(int nLine, unsigned int nFlag)

Toggles the state of a bit flag for a given line.

virtual void  DeleteAllItemDataFlag(unsigned int nFlag)

Clears all lines of a given bit flag.

virtual int  GetNextFlag(int nLine, unsigned int nFlag, BOOL bForward) const

Retrieves the next line number that has a given bit flag set.

virtual int  CountItemDataFlag(unsigned int nFlag) const

Counts the number of lines with a given flag set.

virtual SEC_DWORD  GetItemData(int nLine) const

Retrieves user data associated with the given line.

virtual SEC_DWORD  SetItemData(int nLine, SEC_DWORD dwItemData)

Sets user data associated with the given line.

virtual SECEditItemData*  GetItemDataPtr(int nLine)

Retrieves the item data structure associated with a line.

virtual void  DeleteItemDataPtr(int nLine)

Deletes the item data associated with a line.

virtual void  InsertItemDataLines(int nNewLine, int nNumLines, BOOL bMoveDown)

Helper function to manage the item data array.

virtual void  RemoveItemDataLines(int nStartLine, int nEndLine)

Deletes the item data objects from the specified lines.

virtual void  OnDeleteLineData(SECEditItemData* pData, int nLine)

Called when any line data is deleted

Objective Edit 1.x compatibility methods

void  ClearEdit()

Initializes the SECEdit model object.

void  InitEdit()

Initializes the SECEdit model object.

BOOL  GetModified() const

Tests the model for the modified state.

BOOL  WriteFile(LPCTSTR lpszFileName)

Saves the current text to a file.

void  SetFileMappingKey(LPCTSTR lpszKey = NULL)

Sets the keyword coloring key.

virtual void  OnUpdate(sfl::ISubject* pSubject, sfl::IMessage* pMsg)

Handle notifications of change for this SECEdit

Protected Data Members

BOOL m_bUnicodeFile

Ansi/Unicode file flag

BOOL  m_bSyntaxColoringEnabled

Flag indicating if Syntax Coloring is enabled for this model

BOOL m_bItemDataFlags

Flag indicating if ItemDataFlags are set in UpdateCmds - do not set for large insert

ISECEditBuffer*  m_pEditBuffer

Points to the buffer containing the text.

SECEditMLCommentArray  m_MLCommentArray

Maintains multiline comment starting and ending positions.

CTypedPtrArray&ltCPtrArray, SECEditLineColor*>  m_LineColorArray

RArray of syntax coloring information for each line

CTypedPtrArray&ltCPtrArray, SECEditItemData*>  m_ItemDataArray

Array of SECEditItemData objects associated with each line.

CTypedPtrMap&ltCMapPtrToPtr, SECEditItemData*, void*>  m_ItemDataMap

Map of SECEditItemData objects associated with each line.

BOOL  m_bModified

Stores the modified state of this text

BOOL  m_bReadOnly

Flag indicating if this text is read only

BOOL  m_bOverStrike

Flag indicating of overstrike mode is enabled

BOOL  m_bGroupCommands

Flag indicating if command grouping is enabled

int  m_nMaxWidth

MAximum amount of characters permitted on a line

int  m_nInvalidIndex

Tracks the lines that have been scanned for multiline keyword types

SECEditCompositeCommand*  m_pGroupCommand

Pointer to the current group command

sfl::MvcCommand*  m_pSaveCommand

Pointer the the command on the undo stack when this text was saved

SECEditFontInfo*  m_pFontInfo

Pointer to the font information for this text

ISECEditLangConfig*  m_pLanguage

Pointer to the language this model observes

BOOL m_bInsertDeleteDownUp

CWang002: An Indicator for Insert and Delete In case Insert, true if the entire start line will be moved down In case Delete, true if the start line will be completely replaced