]>
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"
19 // skip the following defines if embedded in M application
22 //# define WXLAYOUT_DEBUG
26 # define WXLAYOUT_DEBUG
27 // The wxLayout classes can be compiled with std::string instead of wxString
28 //# define USE_STD_STRING
33 typedef std::string String
;
34 # define Str(str)(str.c_str())
36 typedef wxString String
;
40 /// Types of currently supported layout objects.
41 enum wxLayoutObjectType
42 { WXLO_TYPE_INVALID
, WXLO_TYPE_TEXT
, WXLO_TYPE_CMD
, WXLO_TYPE_ICON
, WXLO_TYPE_LINEBREAK
};
44 /// Type used for coordinates in drawing.
45 typedef long CoordType
;
48 class wxLayoutObjectBase
;
50 /// Define a list type of wxLayoutObjectBase pointers.
51 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObjectBase
);
53 /** The base class defining the interface to each object which can be
54 part of the layout. Each object needs to draw itself and calculate
57 class wxLayoutObjectBase
60 /// return the type of this object
61 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; } ;
63 @param dc the wxDC to draw on
64 @param position where to draw the top left corner
65 @param baseLine the baseline for alignment, from top of box
66 @draw if set to false, do not draw but just calculate sizes
68 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
71 /** Calculates and returns the size of the object. May need to be
73 @param baseLine pointer where to store the baseline position of
74 this object (i.e. the height from the top of the box to the
76 @return the size of the object's box in pixels
78 virtual wxPoint
GetSize(CoordType
*baseLine
) const { return
80 /// returns the number of cursor positions occupied by this object
81 virtual CoordType
CountPositions(void) const { return 1; }
84 wxLayoutObjectBase() { m_UserData
= NULL
; }
85 /// note: any user data will be freed at the time the object is deleted
86 virtual ~wxLayoutObjectBase() { if(m_UserData
) delete m_UserData
; }
88 virtual void Debug(void);
91 /** Tells the object about some user data. This data is associated
92 with the object and will be deleted at destruction time.
94 void SetUserData(void *data
) { m_UserData
= data
; }
95 /** Return the user data. */
96 void * GetUserData(void) const { return m_UserData
; }
98 /// optional data for application's use
102 /// object for text block
103 class wxLayoutObjectText
: public wxLayoutObjectBase
106 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
107 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
109 /** This returns the height and in baseLine the position of the
110 text's baseline within it's box. This is needed to properly
113 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
114 #ifdef WXLAYOUT_DEBUG
115 virtual void Debug(void);
118 wxLayoutObjectText(const String
&txt
);
119 virtual CoordType
CountPositions(void) const { return strlen(m_Text
.c_str()); }
122 String
& GetText(void) { return m_Text
; }
123 void SetText(String
const &text
) { m_Text
= text
; }
126 /// size of the box containing text
127 long m_Width
, m_Height
;
128 /// the position of the baseline counted from the top of the box
133 class wxLayoutObjectIcon
: public wxLayoutObjectBase
136 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
137 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
139 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
140 wxLayoutObjectIcon(wxIcon
*icon
);
145 /// for export to html:
146 struct wxLayoutStyleInfo
148 int size
, family
, style
, weight
;
150 unsigned fg_red
, fg_green
, fg_blue
;
151 unsigned bg_red
, bg_green
, bg_blue
;
154 /// pseudo-object executing a formatting command in Draw()
155 class wxLayoutObjectCmd
: public wxLayoutObjectBase
158 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
159 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
161 wxLayoutObjectCmd(int size
, int family
, int style
, int weight
,
163 wxColour
const *fg
, wxColour
const *bg
);
164 ~wxLayoutObjectCmd();
165 /// caller must free pointer:
166 wxLayoutStyleInfo
*GetStyle(void) const ;
167 /// return the background colour for setting colour of window
168 wxColour
const *GetBGColour(void) const { return m_ColourBG
; }
172 /// foreground colour
173 wxColour
const *m_ColourFG
;
174 /// background colour
175 wxColour
const *m_ColourBG
;
178 /// this object doesn't do anything at all
179 class wxLayoutObjectLineBreak
: public wxLayoutObjectBase
182 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_LINEBREAK
; }
187 This class provides a high level abstraction to the wxFText
189 It handles most of the character events with its own callback
190 functions, providing an editing ability. All events which cannot be
191 handled get passed to the parent window's handlers.
193 class wxLayoutList
: public wxLayoutObjectList
202 void AddObject(wxLayoutObjectBase
*obj
);
203 void AddText(String
const &txt
);
205 void LineBreak(void);
206 void SetFont(int family
, int size
, int style
,
207 int weight
, int underline
,
210 void SetFont(int family
=-1, int size
= -1, int style
=-1,
211 int weight
=-1, int underline
= -1,
212 char const *fg
= NULL
,
213 char const *bg
= NULL
);
214 inline void SetFontFamily(int family
) { SetFont(family
); }
215 inline void SetFontSize(int size
) { SetFont(-1,size
); }
216 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
217 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
218 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
219 inline void SetFontColour(char const *fg
, char const *bg
= NULL
) { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
222 /** Draw the list on a given DC.
223 @param findObject if true, return the object occupying the
224 position specified by coords
225 @param coords position where to find the object
226 @return if findObject == true, the object or NULL
228 wxLayoutObjectBase
*Draw(wxDC
&dc
, bool findObject
= false,
229 wxPoint
const &coords
= wxPoint(0,0));
231 #ifdef WXLAYOUT_DEBUG
236 /// for access by wxLayoutWindow:
237 void GetSize(CoordType
*max_x
, CoordType
*max_y
,
238 CoordType
*lineHeight
);
240 /**@name Functionality for editing */
242 /// set list editable or read only
243 void SetEditable(bool editable
= true) { m_Editable
= editable
; }
244 /// return true if list is editable
245 bool IsEditable(void) const { return m_Editable
; }
247 void MoveCursor(int dx
= 0, int dy
= 0);
248 void SetCursor(wxPoint
const &p
) { m_CursorPosition
= p
; }
249 wxPoint
GetCursor(void) const { return m_CursorPosition
; }
250 /// delete one or more cursor positions
251 void Delete(CoordType count
= 1);
252 void Insert(String
const &text
);
253 void Insert(wxLayoutObjectBase
*obj
);
254 void Clear(int family
= wxROMAN
, int size
=12, int style
=wxNORMAL
, int weight
=wxNORMAL
,
255 int underline
=0, char const *fg
="black", char const *bg
="white");
257 /// return a pointer to the default settings:
258 wxLayoutObjectCmd
const *GetDefaults(void) const { return m_DefaultSetting
; }
260 wxLayoutObjectList::iterator
FindCurrentObject(CoordType
*offset
= NULL
);
261 // get the length of the line with the object pointed to by i
262 CoordType
GetLineLength(wxLayoutObjectList::iterator i
);
266 int m_FontFamily
, m_FontStyle
, m_FontWeight
;
268 bool m_FontUnderline
;
270 wxColour
const * m_ColourFG
;
271 wxColour
const * m_ColourBG
;
272 /// the default setting:
273 wxLayoutObjectCmd
*m_DefaultSetting
;
275 /// needs recalculation?
278 // the currently updated line:
279 /// where do we draw next:
281 /// the height of the current line:
282 CoordType m_LineHeight
;
283 /// maximum drawn x position so far
285 /// maximum drawn y position:
288 //---- this is needed for editing:
289 /// where is the text cursor:
290 wxPoint m_CursorPosition
;
291 /// which is the last line
295 /// find the object to the cursor position and returns the offset
297 wxLayoutObjectList::iterator
FindObjectCursor(wxPoint
const &cpos
, CoordType
*offset
= NULL
);