SECEditController Class

class SECEditController: public MvcController, public ISECEditPresentationState, public ISECEditFindReplaceNotify

The SECEditController class manages the  SECEdit data model, and also communicates with the  SECEditViewport-derived viewport. The controller class listens for user driven events, and manipulates the model and viewport accordingly. All user events are processed through handlers in the controller, which is plugged into the viewport window.

Defined in: SECEditController.h

Class Members

Creation / Initialization

 SECEditController()

Constructs an SECEditController object.

virtual BOOL  Create(CWnd* pWnd, sfl::MvcVisualComponent* pComp)

Creates the controller on the specified visual component.

virtual void  Init()

Initializes the controller object.

virtual ~SECEditController()

Default Destructor

ISECEditPresentationState Implementation

virtual BOOL  GetColumnSelect() const

Queries whether the current selection, if any, is a column selection.

virtual BOOL  GetSelection(SECEditLineColPair& lcpSel, BOOL bAllowVWS = FALSE) const

Retrieves the line/column coordinates for the current selection.

virtual BOOL  GetSelection(int& nStartLine, int& nStartCol, int& nEndLine, int& nEndCol, BOOL bAllowVWS = FALSE) const

Retrieves the starting and ending positions of the current selection.

virtual SECEditSelectionType  GetSelectionType() const

Returns the type of the current selection.

virtual BOOL  IsSelecting() const

Queries whether text is currently selected.

virtual BOOL  GetColumnSelectInProgress(CRect& rcSelect) const

Returns the rect in logical coordinates of the column select in progress

virtual BOOL  GetShowSelAlways() const

Does this view show selection always instead of only when its view has focus

virtual BOOL  GetSelectColumns(int nLine, int& nStartCol, int &ampnEndCol) const

Retrieves the starting and ending columns of the current selection.

virtual _SEC_FIND_REPLACE_STATE*  GetFindReplaceState() const

Retrieves the global find/replace state information.

virtual int  GetGutterWidth() const

Returns the width of the gutter on the left side of the viewport.

virtual void  SetGutterWidth(int nWidth)

Sets the Width for Gutter (only the mark section)

virtual int  GetGutterIndexWidth() const

Returns the Width of the Index Section

virtual void  SetGutterIndexWidth(int nWidth = -1)

Sets the Width of the Index Section, -1 forces it to be calculated automaticlly

virtual UINT  GetGutterAlignment() const

Returns the Alignment for Gutter area

virtual void  SetGutterAlignment(UINT nAlign)

Sets the Alignment for Gutter area

virtual int  GetGutterMarkWidth() const

Returns the Width for Mark Area

virtual int  GetGutterIndexDigits() const

Returns amount of index digits to be displayed

virtual void  SetGutterIndexDigits(int nDigits = -1)

Sets amount of index digits, -1 cause it to be calculated automaticlly

inline virtual COLORREF GetGutterIndexColor()

Returns the color used in Index

inline virtual void SetGutterIndexColor(COLORREF rgb)

Sets the Color for Gutter Index

inline virtual SECEditFontInfo* GetGutterIndexFont() const

Returns the font info for Index text

virtual void  UpdateGutterIndexFont()

Called after m_pGutterIndexFont is modified

virtual CString  GetGutterIndexText(int nLine) const

Returns the string to be displayed as index

virtual CPoint  LineColToPoint(SECEditLineCol& lc, CDC* pDC) const

Converts the given line and column coordinates into a logical point.

virtual CPoint  LineColToPoint(SECEditLineCol& lc) const

Converts the given line and column coordinates into a logical point.

virtual SECEditLineCol  PointToLineCol(CPoint& pt, CDC* pDC, BOOL bPreceedTab = TRUE) const

Converts a logical point to a line and column coordinate.

virtual SECEditLineCol  PointToLineCol(CPoint& pt, BOOL bPreceedTab = TRUE) const

Converts a logical point to a line and column coordinate.

Caret Navigation Operations

BOOL  BackTab()

Moves the caret back one tab.

void  CharLeft()

Moves the cursor one character to the left.

void  CharLeftExtend()

Extends the selection one character to the left.

void  CharRight()

Moves the cursor one character to the right.

void  CharRightExtend()

Extends the selection one character to the right.

void  DocumentStart()

Moves to the beginning of the document.

void  DocumentStartExtend()

Extends the selection to the beginning of the document.

void  DocumentEnd()

Moves to the end of the document.

void  DocumentEndExtend()

Extends the selection to the end of the document.

void  Home()

Moves to the start of the line, or to the first character on the line.

void  HomeExtend()

Extends the selection to the start of the line, or the first character on the line.

void  WordLeft()

Moves back one word.

void  WordLeftExtend()

Extends the selection back one word.

void  WordRight()

Moves forward one word.

void  WordRightExtend()

Extends the selection forward one word.

void  LineDown()

Moves down one line.

void  LineDownExtend()

Extends the selection down one line.

void  LineEnd()

Moves to the end of the current line.

void  LineEndExtend()

Extends the selection to the end of the current line.

void  LineUp()

Moves up one line.

void  LineUpExtend()

Extends the selection up one line.

void  PageDown()

Moves down one page.

void  PageDownExtend()

Extends the selection down one page.

void  PageUp()

Moves up one page.

void  PageUpExtend()

Extends the selection up one page.

Internal Caret Navigation

SECEditLineCol  GetLCLineUp(const SECEditLineCol& lc) const

Returns the character coordinates above lc

SECEditLineCol  GetLCLineDown(const SECEditLineCol& lc) const

Returns the character coordinates below lc

SECEditLineCol  GetLCCharLeft(const SECEditLineCol& lc) const

Returns the coordinates of the character immediately left of lc

SECEditLineCol  GetLCCharRight(const SECEditLineCol& lc) const

Returns the coordinates of the character immediately right of lc

SECEditLineCol  GetLCWordLeft(const SECEditLineCol& lc, BOOL bExtraSpace = FALSE) const

Returns the coordinates of the start of the word immediately left of lc

SECEditLineCol  GetLCWordRight(const SECEditLineCol& lc, BOOL bExtraSpace = FALSE) const

Returns the coordinates of the start of the word immediately right of lc

void  CaretUp()

Moves the caret up one line.

void  CaretDown()

Moves the caret down one line.

void  CaretLeft()

Moves the caret one character to the left.

void  CaretRight()

Moves the caret one character to the right.

void  CaretHome()

Moves the caret to the start of the current line or to the first character on that line.

void  CaretEnd()

Moves the caret to either the end of the current line.

void  CaretPageUp()

Moves the caret one page up.

void  CaretPageDown()

Moves the caret one page down.

void  CaretDocHome()

Moves the caret to the beginning of the document.

void  CaretDocEnd()

Moves the caret to the end of the document.

virtual void  InvokeCaret(BOOL bSolid = TRUE)

Creates a caret for the viewport

virtual void  RevokeCaret()

Destroys the caret.

virtual void  MoveCaret(int nLine, int nCol, BOOL bVirtual = FALSE)

Moves the caret to a logical screen point.

virtual void  MoveCaret(CPoint pt, BOOL bVirtual = FALSE)

Moves the caret to the line and column position given.

virtual void  MakeCaretVisible()

Helper method for making the caret visible.

virtual BOOL  UpdateCaretPosFromCmd(SECEditCommand* pCmd)

Updates the current caret position based on the given command.

Text Searching

void  FindNextWord()

Finds the next occurance of the selected text.

void  FindNext()

Finds the next occurance of the specified text.

void  FindPrevWord()

Finds the previous occurrance of the selected text.

void  FindPrev()

Finds the previous occurrance of the specified text.

Find/Replace

virtual BOOL  NeedFindForReplace(_SEC_FIND_REPLACE_STATE* pState)

Queries whether a find opeation needs to take place before a replace operation can occur.

virtual BOOL  SECEditFindReplaceNotifyMsg(SECEditFindReplaceDlg* pFindReplaceDlg)

Called to communicate that an action needs to be peformed.

virtual void  ShowFindReplaceDlg(BOOL bFindDialogOnly)

Displays the find/replace dialog.

Drag/Drop methods

virtual DROPEFFECT  DoDragDrop()

Performs a drag drop operation.

virtual DROPEFFECT  OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)

Called when the cursor first enters the window.

virtual void  OnDragLeave()

Called when the cursor is dragged out of the window.

virtual DROPEFFECT  OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)

Called repeatedly when the cursor is dragged over the window.

virtual BOOL  OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point)

Called when data is dropped into the window.

virtual BOOL  GetOleText(COleDataObject* pDataObject, CString& strText, BOOL& bColumnar)

Retrieves the text from an OLE data source object.

virtual COleDataSource*  GetNewCOleDataSource()

Creates a new COleDataSource object.

CEdit Compatibility Methods

BOOL  CanUndo() const

Determines whether an operation can be undone.

int  CharFromPos(CPoint pt) const

Retrieves the line and character indices for the character closest to a specified position.

int  GetFirstVisibleLine() const

Determines the top visible line number.

int  GetLastVisibleLine() const

Determines the bottom visible line number.

BOOL IsLineVisible(int nLine) const

Determines if a line is visible

int  GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const

Retrieves a line of text.

int  GetLineCount() const

Retrieves the number of text lines.

BOOL  GetModify() const

Determines whether the contents have been modified.

void  SetModify(BOOL bModified = TRUE)

Sets or clears the modification flag.

void  GetSel(int& nStartChar, int& nEndChar) const

Gets the starting and ending character positions of the current selection.

DWORD  GetSel() const

Gets the starting and ending character positions of the current selection.

int  GetWindowText(LPTSTR lpszStringBuf, int nMaxCount) const

Returns the window text.

void  GetWindowText(CString& rString) const

Returns the window text.

CPoint  PosFromChar(UINT nChar) const

Retrieves the coordinates of the upper-left corner of a specified character index.

CEdit Compatibility Methods: Operations

void  EmptyUndoBuffer()

Resets (clears) the undo flag.

int  LineFromChar(int nIndex = -1, int* pCol = NULL) const

Retrieves the line number of the line that contains the specified character index.

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

Retrieves the character index of a line.

int  LineLength(int nCharIndex = -1) const

Retrieves the length of a line.

void  LineScroll(int nLines, int nChars = 0)

Scrolls the text.

void  MoveToLine(int nLine)

Sets nLine as the top visible line.

void  ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)

Replaces the current selection with the specified text.

void  SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE)

Selects a range of characters.

void  SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE)

Selects a range of characters.

BOOL  SetReadOnly(BOOL bReadOnly = TRUE)

Sets the read-only state.

void  SetWindowText(LPCTSTR lpszString)

Sets the window text.

CEdit compatibility methods: Clipboard operations

void  Clear()

Deletes (clears) the current selection (if any).

void  Copy()

Copies the current selection (if any) to the clipboard.

void  Cut()

Deletes (cuts) the current selection (if any) and copies to the clipboard.

void  Paste()

Inserts the data from the clipboard at the current cursor position.

BOOL  Undo()

Reverses the last operation.

Accessors

SECEditLineCol  GetCaretPos() const

Returns the caret location

virtual BOOL  GetSyntaxColoring() const

Does this controller's viewport want syntax coloring

virtual SECEditFontInfo*  GetFontInfo() const

Gets the Font and Coloring information for this viewport to use

virtual ISECEditLangConfig*  GetLangPtr() const

Retrieves a pointer to a configuration manager object.

virtual SECEdit*  GetEditModel() const

Gets a pointer to the data model.

virtual SECEditViewport*  GetSECEditViewport() const

Gets a pointer to the viewport.

void  GetLine(int nLine, int nCol, LPCTSTR& lpszLine, CString& strLine)

Retrieves a line of text from the edit buffer.

virtual BOOL  GetWordBound(CString& strWord, int nLine = -1, int nCol = -1, BOOL bForward = TRUE, int* pLine = NULL, int* pCol = NULL) const

Retrieves the next or previous word from the given position.

virtual CString  GetCurrentWord(int* pStartCol = NULL, int* pEndCol = NULL) const

Retrieves the word at current caret position.

virtual CString  GetWord(int nLine, int nCol, int* pStartCol = NULL, int* pEndCol = NULL) const

Retrieves the word at the given position.

virtual BOOL  GetWordStart(CString& strLeft, int& nLine, int& nCol) const

Retrieves the beginning portion of a word and its starting position.

virtual BOOL  GetWordEnd(CString& strRight, int& nLine, int& nCol) const

Retrieves the ending portion of a word and its ending position.

virtual BOOL  MouseDown() const

Queries the status of the mouse button.

virtual BOOL  IsReadOnly() const

Queries the read-only status of the data model.

BOOL  CaretVirtual() const

Queries whether the caret is currently positioned in virtual white space.

General Operations

void  CenterLine(int nLine = -1)

Moves the given line as close to the center of the viewport as possible

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

Inserts text at a specific position.

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

Inserts text at a specific position.

void  LineCut()

Cuts the selected or current line to the clipboard.

void  LineDelete()

Deletes the selected or current line to the clipboard.

BOOL  Delete()

Deletes the selection or the character to the right of the cursor.

BOOL  DeleteBack()

Deletes the selection or the character to the left of the cursor.

void  EditCut()

Cuts the selected text to the clipboard.

void  EditCopy()

Copies the selected text to the clipboard.

BOOL  EditPaste()

Pastes the text from the clipboard.

BOOL  EditRedo()

Performs a redo operation of the last undo command.

BOOL  EditUndo()

Performs an undo of the last executed command.

void  Tab()

Inserts one tab.

void  SelectionLowercase()

Converts the current selection to lowercase.

void  SelectionUppercase()

Converts the current selection to uppercase.

BOOL  ToggleViewWhitespace()

Toggles the visibility of white space in the text.

void  WindowScroll(int nLines, int nChars = 0)

Scrolls the window vertically and/or horizontally.

void  WindowScrollDown()

Scrolls the window down one line.

void  WindowScrollUp()

Scrolls the window up one line.

void  WordDeleteToEnd()

Deletes a word to the right.

void  WordDeleteToStart()

Deletes a word to the left.

Overridables

virtual BOOL  ExtendContextMenu(CMenu& top, CMenu& popup)

Builds the default context menu

virtual void  UpdateContextMenu(CMenu& popup)

Calls the Update Handlers for items ont he context menu

virtual BOOL  OnCaretLineChanged(int nPreviousLine, BOOL bLineChanged)

Called when the caret changes lines.

Selection Methods

BOOL  ClearSelection(BOOL bInvalidate = TRUE)

Clears the current selection.

CString  GetSelText() const

Retrieves the selected text.

BOOL  HasSelection() const

Queries the selection state.

BOOL  HasWritableSelection() const

Queries the presence of modifiable selected text.

BOOL  IsLineColInSel(const SECEditLineCol& lc) const

Determines if the given coordinates are within a selected text region.

void  ReplaceSelection(LPCTSTR lpszNewText = NULL, BOOL bColumnar = FALSE)

Replaces the text currently selected.

void  SelectAll()

Selects all text in the document.

void  SelectLineRange()

Selects a range of lines.

void  SelectLineRange(int nStartLine, int nEndLine = -1)

Selects a range of lines.

BOOL  UpdateSelectionFromCmd(SECEditCommand* pCmd)

Updates the current selection based on the given command.

void  InvalidateSelection() const

Invalidates the selectiond

void  InvalidateLines(int nStartLine, int nEndLine = -1) const

Invalidates the given range of lines

void  ExtendSelection(const SECEditLineCol& lc, BOOL bInvalidate = TRUE)

Extends the selection from the caret to the given point

void  ExtendSelection(int nLine, int nCol, BOOL bInvalidate = TRUE)

Extends the selection from the caret to the given point

void  SetShowSelAlways(BOOL bShowSel)

Sets the value for shoing the selection always

void  SetSelection(int nStartLine, int nStartCol, int nEndLine, int nEndCol, SECEditSelectionType seltype = secST_StreamSelect)

Sets the selection

void  SetSelection(const SECEditLineColPair& lcpSel, SECEditSelectionType seltype = secST_StreamSelect)

Sets the selection

void  SelectLine(int nStartLine)

Sets the selection for one line

void OnHighlight()

Toggle highlight at current line

virtual void ToggleHighlight(int nLine)

Toggle highlight at a specified line

BOOL GetHighlight(int nLine) const

Check if the nLine is highlighted

Protected methods

void  AdjustCaretFromPoint()

Converts the logical point location of the caret to line and column coordinates.

void  AdjustCaretLastCol()

Adjusts the caret after vertical caret movement.

void  AdjustLastCol()

Stores the horizontal caret logical point ordinate as the last known screen column.

void  AdjustPointFromCaret()

Converts the current line and column caret location to a logical point.

virtual COleDataSource*  CacheSelText(BOOL bClipboard = TRUE)

Creates a new COleDataSource with the selected text.

virtual SECEditLineCol  DeleteSelection()

Deletes any selected text.

virtual BOOL  DoCmd(sfl::MvcCommand* pCmd)

Executes a command.

virtual void  DoInsertChar(const CString& strChar)

Inserts the given character at the current location.

CString  GetSingleLineSel()

Retrieves the text in the current selection.

BOOL  GetVirtualWhitespace() const

Queries whether virtual white space is enabled.

BOOL  InsertColumnText(SECEditLineCol lcInsert, LPCTSTR lpszText)

Inserts text as a column of text.

void  PadToCaret()

Appends spaces to a line until to pad the line to the currrent caret location.

Protected Data Members

BOOL  m_bModalFindDlg

Controls whether the find/replace dialog is modal or modeless

BOOL  m_bTempVirtualWhitespace

Set to true for transient operations that require virtual whitespace to be enabled

BOOL  m_bShowSelAlways

Does this controller show selection always?

BOOL  m_bLostFocusToSplitter

TRUE if the view has lost focus to a splitter window containing this view

SECEditCommand*  m_pLastCmd

Holds a pointer to the last typing command to group undo operations

unsigned int  m_n1stChar

Contains the first part of a multibyte character entry in OnChar

UINT  m_nScrollTimer

Timer ID for Drag/Scrolling

BOOL  m_bCaretHidden

Visible status of the caret

BOOL  m_bInUpdateCaretPosMsg

TRUE if the current message being handled in a custom caret message

int  m_nPreviousLine

Caches the previous line location of the caret when the caret switches lines

HACCEL  m_hAccelTable

The handle the accelerator table that maps keystrokes to edit commands

HCURSOR  m_hGutterCursor

The handle the the cursor used when the mouse is over the gutter area

int  m_nGutterWidth

The width of the gutter area in logical units

BOOL  m_bCanDrop

During a Drag/Drop operation, signals if the view will accept a drop of the data

BOOL  m_bDropCaretCanShow

During a Drag/Drop oepration, singals if the view should show a caret indicating the location for the drop

BOOL  m_bMouseDown

Tracks whether the primary mouse button is down

BOOL  m_bMakeCaretVisible

Flag indicating if the caret should be scrolled into view if it moves outside the window

int  m_nMakeCaretVisible

A count used when setting the status of the caret visibility

SECEditLineCol  m_lcCaret

The location of the caret in this controller's viewport

CPoint  m_ptCaretPos

The position of the caret in logical units

CPoint  m_ptCaretPrev

The previous position of the caret in logicial units

CPoint  m_ptSelAnchor

The anchor position of a column selection

int  m_nLastScreenCol

Caches the previous caret offset into the line in device units. Used when navigating up or down through lines

BOOL  m_bUseLastCol

TRUE if caret column position caching is enabled

BOOL  m_bHaveCaret

TRUE if this controller's window has the caret

BOOL  m_bCaretVirtual

TRUE if the caret is currently in virtual whitespace

SECEditSelection  m_sel

Holds the current selection if any

BOOL  m_bLastMatch

Internal flag used when determining the last match in a search operation

CString  m_strLastMatch

Internal variable used when determining the last match in a search operation

int  m_nIndicatorOffset

Offset added to the zero based line and column indicators

mutable BOOL  m_bIgnoreGutter

Flag that tells the line conversion routines to ignore the gutter when converting

int m_nGutterAlignment

Format style for gutter area

int m_nGutterIndexWidth

Width of the gutter Index area

int m_nGutterIndexDigits

Amount of digits to be displayed in the gutter

SECEditFontInfo* m_pGutterIndexFont

Font Info used in Gutter (Index) Area

COLORREF m_rgbGutterIndexColor

Color used for Gutter (Index) Font