X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8236a88ae2cbbfade17a8dc325546402ed28e2ab..8f7173abc4a901249df3ae13a91d3f19874ac269:/samples/richedit/wxllist.h?ds=sidebyside diff --git a/samples/richedit/wxllist.h b/samples/richedit/wxllist.h index 552c2551b0..071f490dbf 100644 --- a/samples/richedit/wxllist.h +++ b/samples/richedit/wxllist.h @@ -16,12 +16,12 @@ #include "kbList.h" -#include "wx/wx.h" -#include "wx/print.h" -#include "wx/printdlg.h" -#include "wx/generic/printps.h" -#include "wx/generic/prntdlgg.h" -#include "wx/dataobj.h" +#include +#include +#include +#include +#include +#include // skip the following defines if embedded in M application #ifndef M_BASEDIR @@ -32,8 +32,8 @@ // use the wxWindows caret class instead of home grown cursor whenever possible #ifdef __WXMSW__ - #undef WXLAYOUT_USE_CARET - #define WXLAYOUT_USE_CARET 1 +# undef WXLAYOUT_USE_CARET +# define WXLAYOUT_USE_CARET 1 #endif // __WXMSW__ // do not enable debug mode within Mahogany @@ -203,6 +203,10 @@ public: */ static wxLayoutObject *Read(wxString &istr); //@} + + /// returns TRUE if the object is shown on the screen (i.e. not cmd object) + bool IsVisibleObject() const { return GetType() != WXLO_TYPE_CMD; } + protected: /// optional data for application's use UserData *m_UserData; @@ -214,7 +218,7 @@ KBLIST_DEFINE(wxLayoutObjectList, wxLayoutObject); /// An illegal iterator to save typing. #define NULLIT (wxLayoutObjectList::iterator(NULL)) /// The iterator type. -#define wxLOiterator wxLayoutObjectList::iterator +typedef wxLayoutObjectList::iterator wxLOiterator; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -316,8 +320,7 @@ private: wxBitmap *m_Icon; }; -/** This structure holds all formatting information. Members which are - undefined (for a CmdObject this means: no change), are set to -1. +/** This structure holds all formatting information. */ struct wxLayoutStyleInfo { @@ -328,11 +331,10 @@ struct wxLayoutStyleInfo int iul = -1, wxColour *fg = NULL, wxColour *bg = NULL); - wxColour & GetBGColour() - { - return m_bg; - } wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right); + + wxColour & GetBGColour() { return m_bg; } + /// Font change parameters. int size, family, style, weight, underline; /// Colours @@ -340,7 +342,7 @@ struct wxLayoutStyleInfo int m_fg_valid, m_bg_valid; // bool, but must be int! }; - +/// a cached font class wxFontCacheEntry { public: @@ -366,6 +368,8 @@ public: } private: wxFont *m_Font; + + // VZ: I wonder why it doesn't use wxLayoutStyleInfo instead of those? int m_Family, m_Size, m_Style, m_Weight; bool m_Underline; }; @@ -516,12 +520,14 @@ public: /** Finds the object which covers the screen position xpos in this line. @param dc the wxDC to use for calculations + @param llist the layout list to which this line belongs @param xpos the screen x coordinate @param offset where to store the difference between xpos and the object's head @return iterator to the object or NULLIT */ wxLayoutObjectList::iterator FindObjectScreen(wxDC &dc, + wxLayoutList *llist, CoordType xpos, CoordType *offset, bool *found = NULL) const ; @@ -537,11 +543,18 @@ public: functions to export the list. @return iterator to the first object */ - wxLayoutObjectList::iterator GetFirstObject(void) + wxLayoutObjectList::iterator GetFirstObject(void) const { return m_ObjectList.begin(); } + /** Get the last object in the list. + */ + wxLayoutObjectList::iterator GetLastObject(void) const + { + return m_ObjectList.tail(); + } + /** Deletes this line, returns pointer to next line. @param update If true, update all following lines. */ @@ -576,6 +589,7 @@ public: @param llist th e wxLayoutList @param cursorPos if not NULL, set cursor screen position in there @param cursorSize if not cursorPos != NULL, set cursor size in there + @param cursorStyle if non NULL where to store styleinfo for cursor pos @param cx if cursorPos != NULL, the cursor x position @param suppressStyleUpdate FALSe normally, only to suppress updating of m_StyleInfo */ @@ -583,6 +597,7 @@ public: wxLayoutList *llist, wxPoint *cursorPos = NULL, wxPoint *cursorSize = NULL, + wxLayoutStyleInfo *cursorStyle = NULL, int cx = 0, bool suppressStyleUpdate = FALSE); /** This function finds an object belonging to a given cursor @@ -594,13 +609,14 @@ public: for that position @return pointer to the object */ - wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos, bool - *found = NULL); + wxLayoutObject * FindObjectScreen(wxDC &dc, + CoordType xpos, + bool *found = NULL); /** This sets the style info for the beginning of this line. @param si styleinfo structure */ void ApplyStyle(const wxLayoutStyleInfo &si) - { m_StyleInfo = si; } + { m_StyleInfo = si; } //@} @@ -779,9 +795,11 @@ public: bool MoveCursorHorizontally(int n); /** Move cursor to the left or right counting in words @param n = number of positions in words + @param untilNext: puts the cursor at the start of the next word if true, + leaves it at the end of the current one otherwise @return bool if it could be moved */ - bool MoveCursorWord(int n); + bool MoveCursorWord(int n, bool untilNext = true); /// Move cursor to end of line. void MoveCursorToEndOfLine(void) @@ -790,14 +808,24 @@ public: MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x); } - /// Move cursor to begin of line. + /// Move cursor to the start of line. void MoveCursorToBeginOfLine(void) { MoveCursorHorizontally(-m_CursorPos.x); } + /// get the number of lines in the list + size_t GetNumLines() const { return m_numLines; } + /// Returns current cursor position. const wxPoint &GetCursorPos(wxDC &dc) const { return m_CursorPos; } const wxPoint &GetCursorPos() const { return m_CursorPos; } + /// move cursor to the end of text + void MoveCursorToEnd(void) + { + MoveCursorTo(wxPoint(0, GetNumLines() - 1)); + MoveCursorToEndOfLine(); + } + //@} /**@name Editing functions. @@ -913,13 +941,14 @@ public: wxLayoutStyleInfo &GetDefaultStyleInfo(void) { return m_DefaultStyleInfo ; } wxLayoutStyleInfo &GetStyleInfo(void) { return m_CurrentStyleInfo ; } const wxLayoutStyleInfo &GetStyleInfo(void) const { return m_CurrentStyleInfo ; } + const wxLayoutStyleInfo &GetCursorStyleInfo(void) const { return m_CursorStyleInfo ; } /// is the current font underlined? - bool IsFontUnderlined() const { return GetStyleInfo().underline != 0; } + bool IsFontUnderlined() const { return GetCursorStyleInfo().underline != 0; } /// is the current font bold? - bool IsFontBold() const { return GetStyleInfo().weight == wxBOLD; } + bool IsFontBold() const { return GetCursorStyleInfo().weight == wxBOLD; } /// is the current font italic? - bool IsFontItalic() const { return GetStyleInfo().style == wxITALIC; } + bool IsFontItalic() const { return GetCursorStyleInfo().style == wxITALIC; } /// set underline if it was off, turn it off if it was on void ToggleFontUnderline() @@ -989,11 +1018,6 @@ public: */ wxPoint GetCursorScreenPos(wxDC &dc); - /** Calculates the cursor position on the screen. - @param dc the dc to use for cursor position calculations - */ - void UpdateCursorScreenPos(wxDC &dc); - /** Draws the cursor. @param active If true, draw a bold cursor to mark window as active. @@ -1029,11 +1053,11 @@ public: /// adds the cursor position to the update rectangle void AddCursorPosToUpdateRect() { - #ifndef WXLAYOUT_USE_CARET - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); +#ifndef WXLAYOUT_USE_CARET + SetUpdateRect(m_CursorScreenPos); + SetUpdateRect(m_CursorScreenPos+m_CursorSize); //#else - the caret will take care of refreshing itself - #endif // !WXLAYOUT_USE_CARET +#endif // !WXLAYOUT_USE_CARET } /// Invalidates the update rectangle. void InvalidateUpdateRect(void) { m_UpdateRectValid = false; } @@ -1066,9 +1090,9 @@ public: /// Discard the current selection void DiscardSelection(); /// Are we still selecting text? - bool IsSelecting(void); + bool IsSelecting(void) const; /// Is the given point (text coords) selected? - bool IsSelected(const wxPoint &cursor); + bool IsSelected(const wxPoint &cursor) const; /// Do we have a non null selection? bool HasSelection() const { return m_Selection.m_valid || m_Selection.m_selecting; } @@ -1105,16 +1129,44 @@ public: void Debug(void); #endif + // for wxLayoutLine usage only + void IncNumLines() { m_numLines++; } + void DecNumLines() { m_numLines--; } + + /// get the line by number + wxLayoutLine *GetLine(CoordType index) const + { + wxASSERT_MSG( (0 <= index) && (index < (CoordType)m_numLines), + "invalid index" ); + + wxLayoutLine *line; + CoordType n = index; + for ( line = m_FirstLine; line && n-- > 0; line = line->GetNextLine() ) + ; + + if ( line ) + { + // should be the right one + wxASSERT( line->GetLineNumber() == index ); + } + + return line; + } + private: /// Clear the list. void InternalClear(void); /// The list of lines. wxLayoutLine *m_FirstLine; + /// The number of lines in the list (store instead recalculating for speed) + size_t m_numLines; + /// The update rectangle which needs to be refreshed: wxRect m_UpdateRect; /// Is the update rectangle valid? bool m_UpdateRectValid; + /**@name Cursor Management */ //@{ /// Where the text cursor (column,line) is. @@ -1136,9 +1188,11 @@ private: /// selection.state and begin/end coordinates struct Selection { - Selection() { m_valid = false; m_selecting = false; } + Selection() { m_valid = m_selecting = m_discarded = false; } + bool m_valid; bool m_selecting; + bool m_discarded; // may be TRUE only until the next redraw // returns true if we already have the screen coordinates of the // selection start and end @@ -1159,6 +1213,8 @@ private: wxLayoutStyleInfo m_DefaultStyleInfo; /// the current setting: wxLayoutStyleInfo m_CurrentStyleInfo; + /// the current setting: + wxLayoutStyleInfo m_CursorStyleInfo; //@} };