]>
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
= 0, 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
;
54 /** The base class defining the interface to each object which can be
55 part of the layout. Each object needs to draw itself and calculate
58 class wxLayoutObjectBase
61 /// return the type of this object
62 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; } ;
64 @param dc the wxDC to draw on
65 @param position where to draw the top left corner
66 @param baseLine the baseline for alignment, from top of box
67 @draw if set to false, do not draw but just calculate sizes
69 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
72 /** Calculates and returns the size of the object. May need to be
74 @param baseLine pointer where to store the baseline position of
75 this object (i.e. the height from the top of the box to the
77 @return the size of the object's box in pixels
79 virtual wxPoint
GetSize(CoordType
*baseLine
) const { return
81 /// returns the number of cursor positions occupied by this object
82 virtual CoordType
CountPositions(void) const { return 1; }
85 wxLayoutObjectBase() { m_UserData
= NULL
; }
86 /// note: any user data will be freed at the time the object is deleted
87 virtual ~wxLayoutObjectBase() { if(m_UserData
) delete m_UserData
; }
89 virtual void Debug(void);
92 /** Tells the object about some user data. This data is associated
93 with the object and will be deleted at destruction time.
95 void SetUserData(void *data
) { m_UserData
= data
; }
96 /** Return the user data. */
97 void * GetUserData(void) const { return m_UserData
; }
99 /// optional data for application's use
103 /// Define a list type of wxLayoutObjectBase pointers.
104 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObjectBase
);
107 /// object for text block
108 class wxLayoutObjectText
: public wxLayoutObjectBase
111 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
112 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
114 /** This returns the height and in baseLine the position of the
115 text's baseline within it's box. This is needed to properly
118 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
119 #ifdef WXLAYOUT_DEBUG
120 virtual void Debug(void);
123 wxLayoutObjectText(const String
&txt
);
124 virtual CoordType
CountPositions(void) const { return strlen(m_Text
.c_str()); }
127 String
& GetText(void) { return m_Text
; }
128 void SetText(String
const &text
) { m_Text
= text
; }
131 /// size of the box containing text
132 long m_Width
, m_Height
;
133 /// the position of the baseline counted from the top of the box
138 class wxLayoutObjectIcon
: public wxLayoutObjectBase
141 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
142 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
144 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
145 wxLayoutObjectIcon(wxIcon
*icon
);
151 /// for export to html:
152 struct wxLayoutStyleInfo
154 int size
, family
, style
, weight
;
156 unsigned fg_red
, fg_green
, fg_blue
;
157 unsigned bg_red
, bg_green
, bg_blue
;
160 /// pseudo-object executing a formatting command in Draw()
161 class wxLayoutObjectCmd
: public wxLayoutObjectBase
164 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
165 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
167 wxLayoutObjectCmd(int size
, int family
, int style
, int weight
,
169 wxColour
const *fg
, wxColour
const *bg
);
170 ~wxLayoutObjectCmd();
171 /// caller must free pointer:
172 wxLayoutStyleInfo
*GetStyle(void) const ;
173 /// return the background colour for setting colour of window
174 wxColour
const *GetBGColour(void) const { return m_ColourBG
; }
178 /// foreground colour
179 wxColour
const *m_ColourFG
;
180 /// background colour
181 wxColour
const *m_ColourBG
;
184 /// this object doesn't do anything at all
185 class wxLayoutObjectLineBreak
: public wxLayoutObjectBase
188 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_LINEBREAK
; }
193 This class provides a high level abstraction to the wxFText
195 It handles most of the character events with its own callback
196 functions, providing an editing ability. All events which cannot be
197 handled get passed to the parent window's handlers.
199 class wxLayoutList
: public wxLayoutObjectList
208 void AddObject(wxLayoutObjectBase
*obj
);
209 void AddText(String
const &txt
);
211 void LineBreak(void);
212 void SetFont(int family
, int size
, int style
,
213 int weight
, int underline
,
216 void SetFont(int family
=-1, int size
= -1, int style
=-1,
217 int weight
=-1, int underline
= -1,
218 char const *fg
= NULL
,
219 char const *bg
= NULL
);
220 inline void SetFontFamily(int family
) { SetFont(family
); }
221 inline void SetFontSize(int size
) { SetFont(-1,size
); }
222 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
223 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
224 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
225 inline void SetFontColour(char const *fg
, char const *bg
= NULL
) { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
228 /** Draw the list on a given DC.
229 @param findObject if true, return the object occupying the
230 position specified by coords
231 @param coords position where to find the object
232 @return if findObject == true, the object or NULL
234 wxLayoutObjectBase
*Draw(wxDC
&dc
, bool findObject
= false,
235 wxPoint
const &coords
= wxPoint(0,0));
237 #ifdef WXLAYOUT_DEBUG
239 void ShowCurrentObject();
243 /// for access by wxLayoutWindow:
244 void GetSize(CoordType
*max_x
, CoordType
*max_y
,
245 CoordType
*lineHeight
);
247 /**@name Functionality for editing */
249 /// set list editable or read only
250 void SetEditable(bool editable
= true) { m_Editable
= editable
; }
251 /// return true if list is editable
252 bool IsEditable(void) const { return m_Editable
; }
253 /// move cursor, returns true if it could move to the desired position
254 bool MoveCursor(int dx
= 0, int dy
= 0);
255 void SetCursor(wxPoint
const &p
) { m_CursorPosition
= p
; }
256 wxPoint
GetCursor(void) const { return m_CursorPosition
; }
257 /// delete one or more cursor positions
258 void Delete(CoordType count
= 1);
259 void Insert(String
const &text
);
260 void Insert(wxLayoutObjectBase
*obj
);
261 void Clear(int family
= wxROMAN
, int size
=12, int style
=wxNORMAL
, int weight
=wxNORMAL
,
262 int underline
=0, char const *fg
="black", char const *bg
="white");
264 /// return a pointer to the default settings:
265 wxLayoutObjectCmd
const *GetDefaults(void) const { return m_DefaultSetting
; }
267 wxLayoutObjectList::iterator
FindCurrentObject(CoordType
*offset
= NULL
);
268 // get the length of the line with the object pointed to by i, offs
269 // only used to decide whether we are before or after linebreak
270 CoordType
GetLineLength(wxLayoutObjectList::iterator i
,
275 int m_FontFamily
, m_FontStyle
, m_FontWeight
;
277 bool m_FontUnderline
;
279 wxColour
const * m_ColourFG
;
280 wxColour
const * m_ColourBG
;
281 /// the default setting:
282 wxLayoutObjectCmd
*m_DefaultSetting
;
284 /// needs recalculation?
287 // the currently updated line:
288 /// where do we draw next:
290 /// the height of the current line:
291 CoordType m_LineHeight
;
292 /// maximum drawn x position so far
294 /// maximum drawn y position:
297 //---- this is needed for editing:
298 /// where is the text cursor:
299 wxPoint m_CursorPosition
;
300 /// which is the last line
304 /// find the object to the cursor position and returns the offset
306 wxLayoutObjectList::iterator
FindObjectCursor(wxPoint
*cpos
, CoordType
*offset
= NULL
);