X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77c630ca853a557a42408d6ca2ee2ff658ff4708..ed07b20b506d54a9dfcc177c22f7224c3e09ebec:/user/wxLayout/wxllist.h diff --git a/user/wxLayout/wxllist.h b/user/wxLayout/wxllist.h index fab769d6f9..a9cf311850 100644 --- a/user/wxLayout/wxllist.h +++ b/user/wxLayout/wxllist.h @@ -29,7 +29,8 @@ # define WXMENU_LAYOUT_DBLCLICK 1113 #endif -#ifdef __WXDEBUG__ +// do not enable debug mode within Mahogany +#if defined(__WXDEBUG__) && ! defined(M_BASEDIR) # define WXLAYOUT_DEBUG #endif @@ -39,7 +40,7 @@ # define WXLO_TRACE(x) #endif - +#define WXLO_DEBUG_URECT 0 #ifndef WXLO_DEFAULTFONTSIZE # define WXLO_DEFAULTFONTSIZE 12 @@ -83,24 +84,44 @@ class wxFont; class wxLayoutObject { public: - /// This structure can be used to contain data associated with the object. + /** This structure can be used to contain data associated with the + object. + It is refcounted, so the caller has to do a DecRef() on it + instead of a delete. + */ struct UserData { - virtual ~UserData() { } + UserData() { m_refcount = 1; } + void IncRef(void) { m_refcount++; } + void DecRef(void) { m_refcount--; if(m_refcount == 0) delete this;} + private: + int m_refcount; + protected: + virtual ~UserData() { wxASSERT(m_refcount == 0); } + /// prevents gcc from generating stupid warnings + friend class dummy_UserData; }; /// return the type of this object virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_INVALID; } /** Calculates the size of an object. @param dc the wxDC to draw on + @param llist the wxLayoutList */ - virtual void Layout(wxDC &) = 0; + virtual void Layout(wxDC &dc, class wxLayoutList *llist) = 0; /** Draws an object. @param dc the wxDC to draw on @param coords where to draw the baseline of the object. + @param wxllist pointer to wxLayoutList + @param begin if !=-1, from which position on to highlight it + @param end if begin !=-1, how many positions to highlight it */ - virtual void Draw(wxDC & /* dc */, wxPoint const & /* coords */) { } + virtual void Draw(wxDC & /* dc */, + wxPoint const & /* coords */, + class wxLayoutList *wxllist, + CoordType begin = -1, + CoordType end = -1) { } /** Calculates and returns the size of the object. @param top where to store height above baseline @@ -125,7 +146,7 @@ public: /// constructor wxLayoutObject() { m_UserData = NULL; } /// delete the user data - virtual ~wxLayoutObject() { if(m_UserData) delete m_UserData; } + virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); } #ifdef WXLAYOUT_DEBUG virtual void Debug(void); @@ -134,11 +155,21 @@ public: /** Tells the object about some user data. This data is associated with the object and will be deleted at destruction time. */ - void SetUserData(UserData *data) { m_UserData = data; } - /** Return the user data. */ - void * GetUserData(void) const { return m_UserData; } + void SetUserData(UserData *data) + { + if(m_UserData) + m_UserData->DecRef(); + m_UserData = data; + m_UserData->IncRef(); + } -private: + /** Return the user data. */ + void * GetUserData(void) const { if(m_UserData) m_UserData->IncRef(); return m_UserData; } + + /** Makes a copy of this object. + */ + virtual wxLayoutObject *Copy(void) = 0; +protected: /// optional data for application's use UserData *m_UserData; }; @@ -164,8 +195,11 @@ public: wxLayoutObjectText(const wxString &txt); virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; } - virtual void Layout(wxDC &dc); - virtual void Draw(wxDC &dc, wxPoint const &coords); + virtual void Layout(wxDC &dc, class wxLayoutList *llist); + virtual void Draw(wxDC &dc, wxPoint const &coords, + class wxLayoutList *wxllist, + CoordType begin = -1, + CoordType end = -1); /** Calculates and returns the size of the object. @param top where to store height above baseline @param bottom where to store height below baseline @@ -192,7 +226,9 @@ public: // for editing: wxString & GetText(void) { return m_Text; } void SetText(wxString const &text) { m_Text = text; } - + /** Makes a copy of this object. + */ + virtual wxLayoutObject *Copy(void); private: wxString m_Text; /// size of the box containing text @@ -219,8 +255,11 @@ public: ~wxLayoutObjectIcon() { delete m_Icon; } virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; } - virtual void Layout(wxDC &dc); - virtual void Draw(wxDC &dc, wxPoint const &coords); + virtual void Layout(wxDC &dc, class wxLayoutList *llist); + virtual void Draw(wxDC &dc, wxPoint const &coords, + class wxLayoutList *wxllist, + CoordType begin = -1, + CoordType end = -1); /** Calculates and returns the size of the object. @param top where to store height above baseline @@ -230,22 +269,82 @@ public: virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const; /// Return just the width of the object on the screen. virtual CoordType GetWidth(void) const { return m_Icon->GetWidth(); } - + // return a pointer to the icon + wxBitmap *GetIcon(void) const { return m_Icon; } + /** Makes a copy of this object. + */ + virtual wxLayoutObject *Copy(void); private: wxBitmap *m_Icon; }; -/// for export to html: +/** This structure holds all formatting information. Members which are + undefined (for a CmdObject this means: no change), are set to -1. +*/ struct wxLayoutStyleInfo { - wxLayoutStyleInfo() + wxLayoutStyleInfo(int ifamily = -1, + int isize = -1, + int istyle = -1, + int iweight = -1, + int iul = -1, + wxColour *fg = NULL, + wxColour *bg = NULL); + wxColour & GetBGColour() { - family = -1; // this marks the styleinfo as uninitialised + return m_bg; } - int size, family, style, weight; - bool underline; - unsigned fg_red, fg_green, fg_blue; - unsigned bg_red, bg_green, bg_blue; + wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right); + /// Font change parameters. + int size, family, style, weight, underline; + /// Colours + wxColour m_bg, m_fg; + bool m_fg_valid, m_bg_valid; +}; + + +class wxFontCacheEntry +{ +public: + wxFontCacheEntry(int family, int size, int style, int weight, + bool underline) + { + m_Family = family; m_Size = size; m_Style = style; + m_Weight = weight; m_Underline = underline; + m_Font = new wxFont(m_Size, m_Family, + m_Style, m_Weight, m_Underline); + } + bool Matches(int family, int size, int style, int weight, + bool underline) const + { + return size == m_Size && family == m_Family + && style == m_Style && weight == m_Weight + && underline == m_Underline; + } + wxFont & GetFont(void) { return *m_Font; } + ~wxFontCacheEntry() + { + delete m_Font; + } +private: + wxFont *m_Font; + int m_Family, m_Size, m_Style, m_Weight; + bool m_Underline; +}; + +KBLIST_DEFINE(wxFCEList, wxFontCacheEntry); + +class wxFontCache +{ +public: + wxFont & GetFont(int family, int size, int style, int weight, + bool underline); + wxFont & GetFont(wxLayoutStyleInfo const &si) + { + return GetFont(si.family, si.size, si.style, si.weight, si.underline); + } +private: + wxFCEList m_FontList; }; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -259,23 +358,26 @@ class wxLayoutObjectCmd : public wxLayoutObject { public: virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; } - virtual void Layout(wxDC &dc); - virtual void Draw(wxDC &dc, wxPoint const &coords); - wxLayoutObjectCmd(int size, int family, int style, int weight, - bool underline, - wxColour const *fg, wxColour const *bg); + virtual void Layout(wxDC &dc, class wxLayoutList *llist); + virtual void Draw(wxDC &dc, wxPoint const &coords, + class wxLayoutList *wxllist, + CoordType begin = -1, + CoordType end = -1); + wxLayoutObjectCmd(int family = -1, + int size = -1, + int style = -1, + int weight = -1, + int underline = -1, + wxColour *fg = NULL, + wxColour *bg = NULL); ~wxLayoutObjectCmd(); /** Stores the current style in the styleinfo structure */ - void GetStyle(wxLayoutStyleInfo *si) const; - /// return the background colour for setting colour of window - wxColour const *GetBGColour(void) const { return m_ColourBG; } + wxLayoutStyleInfo * GetStyle(void) const; + /** Makes a copy of this object. + */ + virtual wxLayoutObject *Copy(void); private: - /// the font to use - wxFont *m_font; - /// foreground colour - wxColour const *m_ColourFG; - /// background colour - wxColour const *m_ColourBG; + wxLayoutStyleInfo *m_StyleInfo; }; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -284,6 +386,9 @@ private: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/// forward declaration +class wxLayoutList; + /** This class represents a single line of objects to be displayed. It knows its height and total size and whether it needs to be redrawn or not. @@ -296,8 +401,9 @@ public: /** Constructor. @param prev pointer to previous line or NULL @param next pointer to following line or NULL + @param llist pointer to layout list */ - wxLayoutLine(wxLayoutLine *prev); + wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist); /** This function inserts a new object at cursor position xpos. @param xpos where to insert new object @param obj the object to insert @@ -325,7 +431,7 @@ public: /** This function appens the next line to this, i.e. joins the two lines into one. */ - void MergeNextLine(void); + void MergeNextLine(wxLayoutList *llist); /** This function deletes npos cursor positions from position xpos. @param xpos where to delete @@ -338,7 +444,7 @@ public: @param xpos where to break it @return pointer to the new line object replacing the old one */ - wxLayoutLine *Break(CoordType xpos); + wxLayoutLine *Break(CoordType xpos, wxLayoutList *llist); /** Deletes the next word from this position, including leading whitespace. @@ -378,8 +484,16 @@ public: */ wxLayoutObjectList::iterator FindObjectScreen(wxDC &dc, CoordType xpos, - CoordType *offset) const ; + CoordType *offset, + bool *found = NULL) const ; + /** Finds text in this line. + @param needle the text to find + @param xpos the position where to start the search + @return the cursoor coord where it was found or -1 + */ + CoordType FindText(const wxString &needle, CoordType xpos = 0) const; + /** Get the first object in the list. This is used by the wxlparser functions to export the list. @return iterator to the first object @@ -392,36 +506,41 @@ public: /** Deletes this line, returns pointer to next line. @param update If true, update all following lines. */ - wxLayoutLine *DeleteLine(bool update); + wxLayoutLine *DeleteLine(bool update, wxLayoutList *llist); /**@name Cursor Management */ //@{ /** Return the line number of this line. @return the line number */ - CoordType GetLineNumber(void) const { return m_LineNumber; } + inline CoordType GetLineNumber(void) const { return m_LineNumber; } /** Return the length of the line. @return line lenght in cursor positions */ - CoordType GetLength(void) const { return m_Length; } + inline CoordType GetLength(void) const { return m_Length; } //@} /**@name Drawing and Layout */ //@{ /** Draws the line on a wxDC. @param dc the wxDC to draw on + @param llist the wxLayoutList @param offset an optional offset to shift printout */ - void Draw(wxDC &dc, const wxPoint &offset = wxPoint(0,0)) const; + void Draw(wxDC &dc, + wxLayoutList *llist, + const wxPoint &offset = wxPoint(0,0)) const; /** Recalculates the positions of objects and the height of the line. @param dc the wxDC to draw on + @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 cx if cursorPos != NULL, the cursor x position */ void Layout(wxDC &dc, + wxLayoutList *llist, wxPoint *cursorPos = NULL, wxPoint *cursorSize = NULL, int cx = 0); @@ -429,9 +548,14 @@ public: position. It assumes that Layout() has been called before. @param dc the wxDC to use for calculations @param xpos screen x position + @param found if non-NULL set to false if we return the last + object before the cursor, to true if we really have an object + for that position @return pointer to the object */ - wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos); + wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos, bool + *found = NULL); + //@} /**@name List traversal */ @@ -462,9 +586,28 @@ public: minimum(!) recursion level, continue with all lines till the end of the list or until the coordinates no longer changed. */ - void RecalculatePositions(int recurse = 0); + void RecalculatePositions(int recurse, wxLayoutList *llist); /// Recalculates the position of this line on the canvas. - wxPoint RecalculatePosition(void); + wxPoint RecalculatePosition(wxLayoutList *llist); + + /** Copies the contents of this line to another wxLayoutList + @param llist the wxLayoutList destination + @param from x cursor coordinate where to start + @param to x cursor coordinate where to stop, -1 for end of line + */ + void Copy(wxLayoutList *llist, + CoordType from = 0, + CoordType to = -1); + +#ifdef WXLAYOUT_DEBUG + void Debug(void); +#endif + wxLayoutStyleInfo &GetStyleInfo() { return m_StyleInfo; } + + /// Returns dirty state + bool IsDirty(void) const { return m_Dirty; } + /// Marks line as diry. + void MarkDirty(void) { m_Dirty = true; } private: /// Destructor is private. Use DeleteLine() to remove it. ~wxLayoutLine(); @@ -475,8 +618,8 @@ private: dirty. @param height new height */ - void SetHeight(CoordType height) - { m_Height = height; RecalculatePositions(true); } + void SetHeight(CoordType height, wxLayoutList *llist) + { m_Height = height; RecalculatePositions(true, llist); } /** Moves the linenumbers one on, because a line has been inserted or deleted. @@ -509,8 +652,12 @@ private: wxLayoutLine *m_Previous; /// Pointer to next line if it exists. wxLayoutLine *m_Next; + /// A StyleInfo structure, holding the current settings. + wxLayoutStyleInfo m_StyleInfo; /// Just to suppress gcc compiler warnings. friend class dummy; +private: + wxLayoutLine(const wxLayoutLine &); }; @@ -537,9 +684,11 @@ public: int style=wxNORMAL, int weight=wxNORMAL, int underline=0, - char const *fg="black", - char const *bg="white"); - + wxColour *fg=NULL, + wxColour *bg=NULL); + /// Empty: clear the list but leave font settings. + void Empty(void); + /**@name Cursor Management */ //@{ /** Set new cursor position. @@ -570,7 +719,9 @@ public: { MoveCursorHorizontally(-m_CursorPos.x); } /// Returns current cursor position. - wxPoint GetCursorPos(void) const { return m_CursorPos; } + wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; } + wxPoint GetCursorPos() const { return m_CursorPos; } + //@} /**@name Editing functions. @@ -631,13 +782,20 @@ public: //@} + /** Finds text in this list. + @param needle the text to find + @param cpos the position where to start the search + @return the cursoor coord where it was found or (-1,-1) + */ + wxPoint FindText(const wxString &needle, const wxPoint &cpos = wxPoint(0,0)) const; + /**@name Formatting options */ //@{ /// sets font parameters void SetFont(int family, int size, int style, int weight, int underline, - wxColour const *fg, - wxColour const *bg); + wxColour *fg, + wxColour *bg); /// sets font parameters, colours by name void SetFont(int family=-1, int size = -1, int style=-1, int weight=-1, int underline = -1, @@ -645,10 +803,10 @@ public: char const *bg = NULL); /// changes to the next larger font size inline void SetFontLarger(void) - { SetFont(-1,(12*m_FontPtSize)/10); } + { SetFont(-1,(12*m_CurrentSetting.size)/10); } /// changes to the next smaller font size inline void SetFontSmaller(void) - { SetFont(-1,(10*m_FontPtSize)/12); } + { SetFont(-1,(10*m_CurrentSetting.size)/12); } /// set font family inline void SetFontFamily(int family) { SetFont(family); } @@ -661,14 +819,21 @@ public: /// toggle underline flag inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); } /// set font colours by name - inline void SetFontColour(char const *fg, char const *bg = NULL) { SetFont(-1,-1,-1,-1,-1,fg,bg); } + inline void SetFontColour(char const *fg, char const *bg = NULL) + { SetFont(-1,-1,-1,-1,-1,fg,bg); } + /// set font colours by colour + inline void SetFontColour(wxColour *fg, wxColour *bg = NULL) + { SetFont(-1,-1,-1,-1,-1,fg,bg); } + + /** Returns a pointer to the default settings. This is only valid temporarily and should not be stored anywhere. @return the default settings of the list */ - wxLayoutObjectCmd const *GetDefaults(void) const { return m_DefaultSetting ; } + wxLayoutStyleInfo *GetDefaults(void) { return &m_DefaultSetting ; } + wxLayoutStyleInfo *GetStyleInfo(void) { return &m_CurrentSetting ; } //@} /**@name Drawing */ @@ -679,22 +844,24 @@ public: @param top optional y coordinate where to start drawing @param bottom optional y coordinate where to stop drawing */ - void Draw(wxDC &dc, const wxPoint &offset = wxPoint(0,0), - CoordType top = -1, CoordType bottom = -1) const; + void Draw(wxDC &dc, + const wxPoint &offset = wxPoint(0,0), + CoordType top = -1, CoordType bottom = -1); /** Calculates new layout for the list, like Draw() but does not actually draw it. @param dc the wxDC to draw on @param bottom optional y coordinate where to stop calculating + @param forceAll force re-layout of all lines */ - void Layout(wxDC &dc, CoordType bottom = -1) const; + void Layout(wxDC &dc, CoordType bottom = -1, bool forceAll = false); /** Calculates new sizes for everything in the list, like Layout() but this is needed after the list got changed. @param dc the wxDC to draw on @param bottom optional y coordinate where to stop calculating */ - void Recalculate(wxDC &dc, CoordType bottom = -1) const; + void Recalculate(wxDC &dc, CoordType bottom = -1); /** Returns the size of the list in screen coordinates. The return value only makes sense after the list has been @@ -707,8 +874,7 @@ public: /** Returns the cursor position on the screen. @return cursor position in pixels */ - wxPoint GetCursorScreenPos(void) const - { return m_CursorScreenPos; } + wxPoint GetCursorScreenPos(wxDC &dc); /** Draws the cursor. @param active If true, draw a bold cursor to mark window as @@ -723,12 +889,29 @@ public: position. It assumes that Layout() has been called before. @param pos screen position @param cursorPos if non NULL, store cursor position in there + @param found if used, set this to true if we really found an + object, to false if we had to take the object near to it @return pointer to the object */ wxLayoutObject * FindObjectScreen(wxDC &dc, wxPoint const pos, - wxPoint *cursorPos = NULL); + wxPoint *cursorPos = NULL, + bool *found = NULL); + /** Called by the objects to update the update rectangle. + @param x horizontal coordinate to include in rectangle + @param y vertical coordinate to include in rectangle + */ + void SetUpdateRect(CoordType x, CoordType y); + /** Called by the objects to update the update rectangle. + @param p a point to include in it + */ + inline void SetUpdateRect(const wxPoint &p) + { SetUpdateRect(p.x,p.y); } + /// Invalidates the update rectangle. + void InvalidateUpdateRect(void) { m_UpdateRectValid = false; } + /// Returns the update rectangle. + const wxRect *GetUpdateRect(void) const { return &m_UpdateRect; } //@} /**@name For exporting one object after another. */ @@ -740,12 +923,58 @@ public: return m_FirstLine; } //@} + + /// Begin selecting text. + void StartSelection(void); + // Continue selecting text + void ContinueSelection(void); + /// End selecting text. + void EndSelection(void); + /// Are we still selecting text? + bool IsSelecting(void); + bool IsSelected(const wxPoint &cursor); + + /// Return the selection as a wxLayoutList: + wxLayoutList *GetSelection(void); + /// Delete selected bit + void DeleteSelection(void); + + wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0), + const wxPoint &to = wxPoint(-1,-1)); + + /// starts highlighting of text for selections + void StartHighlighting(wxDC &dc); + /// ends highlighting of text for selections + void EndHighlighting(wxDC &dc); + + /** Tests whether this layout line is selected and needs + highlighting. + @param line to test for + @param from set to first cursorpos to be highlighted (for returncode == -1) + @param to set to last cursorpos to be highlighted (for returncode == -1) + @return 0 = not selected, 1 = fully selected, -1 = partially + selected + + */ + int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to); + + void ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc); +#ifdef WXLAYOUT_DEBUG + void Debug(void); +#endif private: /// Clear the list. void InternalClear(void); + /** Calculates the cursor position on the screen. + */ + void UpdateCursorScreenPos(wxDC &dc); /// The list of lines. wxLayoutLine *m_FirstLine; + /// 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. @@ -758,16 +987,22 @@ private: wxLayoutLine *m_CursorLine; //@} + /// A structure for the selection. + struct Selection + { + Selection() { m_valid = false; m_selecting = false; } + bool m_valid; + bool m_selecting; + wxPoint m_CursorA, m_CursorB; + } m_Selection; /** @name Font parameters. */ //@{ - int m_FontFamily, m_FontStyle, m_FontWeight; - int m_FontPtSize; - bool m_FontUnderline; - /// colours: - wxColour const * m_ColourFG; - wxColour const * m_ColourBG; + /// this object manages the fonts for us + wxFontCache m_FontCache; /// the default setting: - wxLayoutObjectCmd *m_DefaultSetting; + wxLayoutStyleInfo m_DefaultSetting; + /// the current setting: + wxLayoutStyleInfo m_CurrentSetting; //@} }; @@ -793,6 +1028,9 @@ public: wxLayoutPrintout(wxLayoutList *llist, wxString const & title = "wxLayout Printout"); + /// Destructor. + ~wxLayoutPrintout(); + /** Function which prints the n-th page. @param page the page number to print @return bool true if we are not at end of document yet