]>
git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxllist.h
1 /*-*- c++ -*-********************************************************
2 * wxLayoutList.h - a formatted text rendering engine for wxWindows *
4 * (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
7 *******************************************************************/
12 # pragma interface "wxllist.h"
24 enum wxLayoutObjectType
{ WXLO_TYPE_INVALID
, WXLO_TYPE_TEXT
, WXLO_TYPE_CMD
, WXLO_TYPE_ICON
, WXLO_TYPE_LINEBREAK
};
26 typedef long CoordType
;
29 class wxLayoutObjectBase
;
31 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObjectBase
);
32 KBLIST_DEFINE(wxLayoutOLinesList
, wxLayoutObjectList::iterator
);
35 class wxLayoutObjectBase
38 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; } ;
40 @param dc the wxDC to draw on
41 @param position where to draw the top left corner
42 @param baseLine the baseline for alignment, from top of box
43 @draw if set to false, do not draw but just calculate sizes
45 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
48 virtual wxPoint
GetSize(CoordType
*baseLine
) const { return
50 /// returns the number of cursor positions occupied by this object
51 virtual CoordType
CountPositions(void) const { return 1; }
53 wxLayoutObjectBase() { m_UserData
= NULL
; }
54 virtual ~wxLayoutObjectBase() {}
56 virtual void Debug(void);
59 void SetUserData(void *data
) { m_UserData
= data
; }
60 void * GetUserData(void) const { return m_UserData
; }
62 /// optional data for application's use
66 /// object for text block
67 class wxLayoutObjectText
: public wxLayoutObjectBase
70 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
71 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
73 /** This returns the height and in baseLine the position of the
74 text's baseline within it's box. This is needed to properly
77 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
79 virtual void Debug(void);
82 wxLayoutObjectText(const wxString
&txt
);
83 virtual CoordType
CountPositions(void) const { return strlen(m_Text
.c_str()); }
86 wxString
& GetText(void) { return m_Text
; }
87 void SetText(wxString
const &text
) { m_Text
= text
; }
90 /// size of the box containing text
91 long m_Width
, m_Height
;
92 /// the position of the baseline counted from the top of the box
97 class wxLayoutObjectIcon
: public wxLayoutObjectBase
100 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
101 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
103 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
104 wxLayoutObjectIcon(wxIcon
*icon
);
109 /// for export to html:
110 struct wxLayoutStyleInfo
112 int size
, family
, style
, weight
;
114 unsigned fg_red
, fg_green
, fg_blue
;
115 unsigned bg_red
, bg_green
, bg_blue
;
118 /// pseudo-object executing a formatting command in Draw()
119 class wxLayoutObjectCmd
: public wxLayoutObjectBase
122 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
123 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
125 wxLayoutObjectCmd(int size
, int family
, int style
, int weight
,
127 wxColour
const *fg
, wxColour
const *bg
);
128 ~wxLayoutObjectCmd();
129 // caller must free pointer:
130 wxLayoutStyleInfo
*GetStyle(void) const ;
134 /// foreground colour
135 wxColour
const *m_ColourFG
;
136 /// background colour
137 wxColour
const *m_ColourBG
;
140 /// this object doesn't do anything at all
141 class wxLayoutObjectLineBreak
: public wxLayoutObjectBase
144 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_LINEBREAK
; }
149 This class provides a high level abstraction to the wxFText
151 It handles most of the character events with its own callback
152 functions, providing an editing ability. All events which cannot be
153 handled get passed to the parent window's handlers.
155 class wxLayoutList
: public wxLayoutObjectList
164 void AddObject(wxLayoutObjectBase
*obj
);
165 void AddText(wxString
const &txt
);
167 void LineBreak(void);
168 void SetFont(int family
, int size
, int style
,
169 int weight
, int underline
,
172 void SetFont(int family
=-1, int size
= -1, int style
=-1,
173 int weight
=-1, int underline
= -1,
174 char const *fg
= NULL
,
175 char const *bg
= NULL
);
176 /** Draw the list on a given DC.
177 @param findObject if true, return the object occupying the
178 position specified by coords
179 @param coords position where to find the object
180 @return if findObject == true, the object or NULL
182 wxLayoutObjectBase
*Draw(wxDC
&dc
, bool findObject
= false,
183 wxPoint
const &coords
= wxPoint(0,0));
190 /// for access by wxLayoutWindow:
191 void GetSize(CoordType
*max_x
, CoordType
*max_y
,
192 CoordType
*lineHeight
);
194 /**@name Functionality for editing */
196 /// set list editable or read only
197 void SetEditable(bool editable
= true) { m_Editable
= true; }
199 void MoveCursor(int dx
= 0, int dy
= 0);
200 void SetCursor(wxPoint
const &p
) { m_CursorPosition
= p
; }
201 /// delete one or more cursor positions
202 void Delete(CoordType count
= 1);
203 void Insert(wxString
const &text
);
204 void Insert(wxLayoutObjectBase
*obj
);
210 int m_FontFamily
, m_FontStyle
, m_FontWeight
;
212 bool m_FontUnderline
;
214 wxColour
const * m_ColourFG
;
215 wxColour
const * m_ColourBG
;
217 /// needs recalculation?
220 // the currently updated line:
221 /// where do we draw next:
223 /// the height of the current line:
224 CoordType m_LineHeight
;
225 /// maximum drawn x position so far
227 /// maximum drawn y position:
230 //---- this is needed for editing:
231 /// where is the text cursor:
232 wxPoint m_CursorPosition
;
233 /// which is the last line
237 /// find the object to the cursor position and returns the offset
239 wxLayoutObjectList::iterator
FindObjectCursor(wxPoint
const &cpos
, CoordType
*offset
= NULL
);
240 wxLayoutObjectList::iterator
FindCurrentObject(CoordType
*offset
= NULL
);
241 // get the length of the line with the object pointed to by i
242 CoordType
GetLineLength(wxLayoutObjectList::iterator i
);