X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/43e916c33ecf51aac840c1dd640069a2ac0329ab..41ca191f4b76957735a885b620d54c5f51524522:/user/wxLayout/wxllist.h diff --git a/user/wxLayout/wxllist.h b/user/wxLayout/wxllist.h index 2ae0e08129..75019427ef 100644 --- a/user/wxLayout/wxllist.h +++ b/user/wxLayout/wxllist.h @@ -33,10 +33,19 @@ # define WXLAYOUT_DEBUG #endif +#ifdef WXLAYOUT_DEBUG +# define WXLO_TRACE(x) wxLogDebug(x) +#else +# define WXLO_TRACE(x) +#endif + + + #ifndef WXLO_DEFAULTFONTSIZE # define WXLO_DEFAULTFONTSIZE 12 #endif + /// Types of currently supported layout objects. enum wxLayoutObjectType { @@ -74,10 +83,22 @@ 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 @@ -105,11 +126,18 @@ public: virtual CoordType GetWidth(void) const { return 0; } /// returns the number of cursor positions occupied by this object virtual CoordType GetLength(void) const { return 1; } + /** Returns the cursor offset relating to the screen x position + relative to begin of object. + @param dc the wxDC to use for calculations + @param xpos relative x position from head of object + @return cursor coordinate offset + */ + virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const { return 0; } /// 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); @@ -118,11 +146,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; }; @@ -158,6 +196,14 @@ 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_Width; } + /** Returns the cursor offset relating to the screen x position + relative to begin of object. + @param dc the wxDC to use for calculations + @param xpos relative x position from head of object + @return cursor coordinate offset + */ + virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const; + #ifdef WXLAYOUT_DEBUG virtual void Debug(void); @@ -168,7 +214,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 @@ -206,7 +254,11 @@ 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; }; @@ -239,19 +291,22 @@ public: 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); + wxColour &fg, wxColour &bg); ~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; } + wxColour &GetBGColour(void) { return m_ColourBG; } + /** Makes a copy of this object. + */ + virtual wxLayoutObject *Copy(void); private: /// the font to use wxFont *m_font; /// foreground colour - wxColour const *m_ColourFG; + wxColour m_ColourFG; /// background colour - wxColour const *m_ColourBG; + wxColour m_ColourBG; }; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -260,6 +315,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. @@ -272,8 +330,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 @@ -301,7 +360,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 @@ -314,7 +373,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. @@ -326,6 +385,13 @@ public: @return true if a word was deleted */ bool DeleteWord(CoordType npos); + + /** Finds a suitable position left to the given column to break the + line. + @param column we want to break the line to the left of this + @return column for breaking line or -1 if no suitable location found + */ + CoordType GetWrapPosition(CoordType column); /** Finds the object which covers the cursor position xpos in this line. @@ -337,6 +403,18 @@ public: wxLayoutObjectList::iterator FindObject(CoordType xpos, CoordType *offset) const ; + /** Finds the object which covers the screen position xpos in this + line. + @param dc the wxDC to use for calculations + @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, + CoordType xpos, + CoordType *offset) 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 @@ -349,7 +427,7 @@ 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 */ //@{ @@ -367,27 +445,33 @@ public: //@{ /** 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); /** This function finds an object belonging to a given cursor position. It assumes that Layout() has been called before. + @param dc the wxDC to use for calculations @param xpos screen x position @return pointer to the object */ - wxLayoutObject * FindObject(CoordType xpos); + wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos); //@} /**@name List traversal */ @@ -418,7 +502,9 @@ 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(wxLayoutList *llist); private: /// Destructor is private. Use DeleteLine() to remove it. ~wxLayoutLine(); @@ -429,10 +515,8 @@ private: dirty. @param height new height */ - void SetHeight(CoordType height) - { m_Height = height; RecalculatePositions(true); } - /// Recalculates the position of this line on the canvas. - wxPoint RecalculatePosition(void); + 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. @@ -467,6 +551,8 @@ private: wxLayoutLine *m_Next; /// Just to suppress gcc compiler warnings. friend class dummy; +private: + wxLayoutLine(const wxLayoutLine &); }; @@ -493,9 +579,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. @@ -526,7 +614,7 @@ public: { MoveCursorHorizontally(-m_CursorPos.x); } /// Returns current cursor position. - wxPoint GetCursorPos(void) const { return m_CursorPos; } + wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; } //@} /**@name Editing functions. @@ -539,6 +627,13 @@ public: bool Insert(wxLayoutObject *obj); /// Inserts a linebreak at current cursor position. bool LineBreak(void); + /** Wraps the current line. Searches to the left of the cursor to + break the line. Does nothing if the cursor position is before + the break position parameter. + @param column the break position for the line, maximum length + @return true if line got broken + */ + bool WrapLine(CoordType column); /** This function deletes npos cursor positions. @param npos how many positions @return true if everything got deleted @@ -585,8 +680,8 @@ public: /// 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, @@ -617,7 +712,7 @@ public: anywhere. @return the default settings of the list */ - wxLayoutObjectCmd const *GetDefaults(void) const { return m_DefaultSetting ; } + wxLayoutObjectCmd *GetDefaults(void) { return m_DefaultSetting ; } //@} /**@name Drawing */ @@ -629,14 +724,22 @@ public: @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; + 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 */ - void Layout(wxDC &dc, CoordType bottom = -1) const; + void Layout(wxDC &dc, CoordType bottom = -1); + + /** 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); + /** Returns the size of the list in screen coordinates. The return value only makes sense after the list has been drawn. @@ -648,8 +751,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 @@ -660,13 +762,24 @@ public: bool active = true, const wxPoint & translate = wxPoint(0,0)); - /** This function finds an object belonging to a given cursor + /** This function finds an object belonging to a given screen position. It assumes that Layout() has been called before. @param pos screen position + @param cursorPos if non NULL, store cursor position in there @return pointer to the object */ - wxLayoutObject * FindObject(wxPoint const pos); + wxLayoutObject * FindObjectScreen(wxDC &dc, + wxPoint const pos, + wxPoint *cursorPos = NULL); + /** Called by the objects to update the update rectangle. + @param p a point to include in it + */ + void SetUpdateRect(const wxPoint &p); + /// 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. */ @@ -678,12 +791,24 @@ public: return m_FirstLine; } //@} + + void StartSelection(void); + void EndSelection(void); + bool IsSelected(const wxPoint &cursor); + 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. @@ -696,14 +821,20 @@ private: wxLayoutLine *m_CursorLine; //@} + /// A structure for the selection. + struct Selection + { + bool m_valid; + 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; + wxColour m_ColourFG; + wxColour m_ColourBG; /// the default setting: wxLayoutObjectCmd *m_DefaultSetting; //@}