]>
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
23 //# define USE_STD_STRING
28 typedef std::string String
;
29 # define Str(str)(str.c_str())
31 typedef wxString String
;
35 /// Types of currently supported layout objects.
36 enum wxLayoutObjectType
37 { WXLO_TYPE_INVALID
, WXLO_TYPE_TEXT
, WXLO_TYPE_CMD
, WXLO_TYPE_ICON
, WXLO_TYPE_LINEBREAK
};
39 /// Type used for coordinates in drawing.
40 typedef long CoordType
;
43 class wxLayoutObjectBase
;
45 /// Define a list type of wxLayoutObjectBase pointers.
46 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObjectBase
);
48 /** The base class defining the interface to each object which can be
49 part of the layout. Each object needs to draw itself and calculate
52 class wxLayoutObjectBase
55 /// return the type of this object
56 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; } ;
58 @param dc the wxDC to draw on
59 @param position where to draw the top left corner
60 @param baseLine the baseline for alignment, from top of box
61 @draw if set to false, do not draw but just calculate sizes
63 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
66 /** Calculates and returns the size of the object. May need to be
68 @param baseLine pointer where to store the baseline position of
69 this object (i.e. the height from the top of the box to the
71 @return the size of the object's box in pixels
73 virtual wxPoint
GetSize(CoordType
*baseLine
) const { return
75 /// returns the number of cursor positions occupied by this object
76 virtual CoordType
CountPositions(void) const { return 1; }
79 wxLayoutObjectBase() { m_UserData
= NULL
; }
80 /// note: any user data will be freed at the time the object is deleted
81 virtual ~wxLayoutObjectBase() { if(m_UserData
) delete m_UserData
; }
83 virtual void Debug(void);
86 /** Tells the object about some user data. This data is associated
87 with the object and will be deleted at destruction time.
89 void SetUserData(void *data
) { m_UserData
= data
; }
90 /** Return the user data. */
91 void * GetUserData(void) const { return m_UserData
; }
93 /// optional data for application's use
97 /// object for text block
98 class wxLayoutObjectText
: public wxLayoutObjectBase
101 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
102 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
104 /** This returns the height and in baseLine the position of the
105 text's baseline within it's box. This is needed to properly
108 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
109 #ifdef WXLAYOUT_DEBUG
110 virtual void Debug(void);
113 wxLayoutObjectText(const String
&txt
);
114 virtual CoordType
CountPositions(void) const { return strlen(m_Text
.c_str()); }
117 String
& GetText(void) { return m_Text
; }
118 void SetText(String
const &text
) { m_Text
= text
; }
121 /// size of the box containing text
122 long m_Width
, m_Height
;
123 /// the position of the baseline counted from the top of the box
128 class wxLayoutObjectIcon
: public wxLayoutObjectBase
131 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
132 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
134 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
135 wxLayoutObjectIcon(wxIcon
*icon
);
140 /// for export to html:
141 struct wxLayoutStyleInfo
143 int size
, family
, style
, weight
;
145 unsigned fg_red
, fg_green
, fg_blue
;
146 unsigned bg_red
, bg_green
, bg_blue
;
149 /// pseudo-object executing a formatting command in Draw()
150 class wxLayoutObjectCmd
: public wxLayoutObjectBase
153 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
154 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
156 wxLayoutObjectCmd(int size
, int family
, int style
, int weight
,
158 wxColour
const *fg
, wxColour
const *bg
);
159 ~wxLayoutObjectCmd();
160 // caller must free pointer:
161 wxLayoutStyleInfo
*GetStyle(void) const ;
165 /// foreground colour
166 wxColour
const *m_ColourFG
;
167 /// background colour
168 wxColour
const *m_ColourBG
;
171 /// this object doesn't do anything at all
172 class wxLayoutObjectLineBreak
: public wxLayoutObjectBase
175 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_LINEBREAK
; }
180 This class provides a high level abstraction to the wxFText
182 It handles most of the character events with its own callback
183 functions, providing an editing ability. All events which cannot be
184 handled get passed to the parent window's handlers.
186 class wxLayoutList
: public wxLayoutObjectList
195 void AddObject(wxLayoutObjectBase
*obj
);
196 void AddText(String
const &txt
);
198 void LineBreak(void);
199 void SetFont(int family
, int size
, int style
,
200 int weight
, int underline
,
203 void SetFont(int family
=-1, int size
= -1, int style
=-1,
204 int weight
=-1, int underline
= -1,
205 char const *fg
= NULL
,
206 char const *bg
= NULL
);
207 inline void SetFontFamily(int family
) { SetFont(family
); }
208 inline void SetFontSize(int size
) { SetFont(-1,size
); }
209 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
210 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
211 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
212 inline void SetFontColour(char const *fg
, char const *bg
= NULL
) { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
215 /** Draw the list on a given DC.
216 @param findObject if true, return the object occupying the
217 position specified by coords
218 @param coords position where to find the object
219 @return if findObject == true, the object or NULL
221 wxLayoutObjectBase
*Draw(wxDC
&dc
, bool findObject
= false,
222 wxPoint
const &coords
= wxPoint(0,0));
224 #ifdef WXLAYOUT_DEBUG
229 /// for access by wxLayoutWindow:
230 void GetSize(CoordType
*max_x
, CoordType
*max_y
,
231 CoordType
*lineHeight
);
233 /**@name Functionality for editing */
235 /// set list editable or read only
236 void SetEditable(bool editable
= true) { m_Editable
= true; }
238 void MoveCursor(int dx
= 0, int dy
= 0);
239 void SetCursor(wxPoint
const &p
) { m_CursorPosition
= p
; }
240 /// delete one or more cursor positions
241 void Delete(CoordType count
= 1);
242 void Insert(String
const &text
);
243 void Insert(wxLayoutObjectBase
*obj
);
244 void Clear(int family
= wxROMAN
, int size
=12, int style
=wxNORMAL
, int weight
=wxNORMAL
,
245 int underline
=0, char const *fg
="black", char const *bg
="white");
250 int m_FontFamily
, m_FontStyle
, m_FontWeight
;
252 bool m_FontUnderline
;
254 wxColour
const * m_ColourFG
;
255 wxColour
const * m_ColourBG
;
256 /// the default setting:
257 wxLayoutObjectCmd
*m_DefaultSetting
;
259 /// needs recalculation?
262 // the currently updated line:
263 /// where do we draw next:
265 /// the height of the current line:
266 CoordType m_LineHeight
;
267 /// maximum drawn x position so far
269 /// maximum drawn y position:
272 //---- this is needed for editing:
273 /// where is the text cursor:
274 wxPoint m_CursorPosition
;
275 /// which is the last line
279 /// find the object to the cursor position and returns the offset
281 wxLayoutObjectList::iterator
FindObjectCursor(wxPoint
const &cpos
, CoordType
*offset
= NULL
);
282 wxLayoutObjectList::iterator
FindCurrentObject(CoordType
*offset
= NULL
);
283 // get the length of the line with the object pointed to by i
284 CoordType
GetLineLength(wxLayoutObjectList::iterator i
);