]>
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
&WXUNUSED(dc
), wxPoint
WXUNUSED(position
),
64 CoordType
WXUNUSED(baseLine
), bool draw
= true) {};
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
*WXUNUSED(baseLine
) ) const
74 { return wxPoint(0,0); };
76 /// returns the number of cursor positions occupied by this object
77 virtual CoordType
CountPositions(void) const { return 1; }
80 wxLayoutObjectBase() { m_UserData
= NULL
; }
81 /// note: any user data will be freed at the time the object is deleted
82 virtual ~wxLayoutObjectBase() { if(m_UserData
) delete m_UserData
; }
84 virtual void Debug(void);
87 /** Tells the object about some user data. This data is associated
88 with the object and will be deleted at destruction time.
90 void SetUserData(void *data
) { m_UserData
= data
; }
91 /** Return the user data. */
92 void * GetUserData(void) const { return m_UserData
; }
94 /// optional data for application's use
98 /// object for text block
99 class wxLayoutObjectText
: public wxLayoutObjectBase
102 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
103 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
105 /** This returns the height and in baseLine the position of the
106 text's baseline within it's box. This is needed to properly
109 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
110 #ifdef WXLAYOUT_DEBUG
111 virtual void Debug(void);
114 wxLayoutObjectText(const String
&txt
);
115 virtual CoordType
CountPositions(void) const { return strlen(m_Text
.c_str()); }
118 String
& GetText(void) { return m_Text
; }
119 void SetText(String
const &text
) { m_Text
= text
; }
122 /// size of the box containing text
123 long m_Width
, m_Height
;
124 /// the position of the baseline counted from the top of the box
129 class wxLayoutObjectIcon
: public wxLayoutObjectBase
132 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
133 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
135 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
136 wxLayoutObjectIcon(wxIcon
*icon
);
141 /// for export to html:
142 struct wxLayoutStyleInfo
144 int size
, family
, style
, weight
;
146 unsigned fg_red
, fg_green
, fg_blue
;
147 unsigned bg_red
, bg_green
, bg_blue
;
150 /// pseudo-object executing a formatting command in Draw()
151 class wxLayoutObjectCmd
: public wxLayoutObjectBase
154 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
155 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
157 wxLayoutObjectCmd(int size
, int family
, int style
, int weight
,
159 wxColour
const *fg
, wxColour
const *bg
);
160 ~wxLayoutObjectCmd();
161 /// caller must free pointer:
162 wxLayoutStyleInfo
*GetStyle(void) const ;
163 /// return the background colour for setting colour of window
164 wxColour
const *GetBGColour(void) const { return m_ColourBG
; }
168 /// foreground colour
169 wxColour
const *m_ColourFG
;
170 /// background colour
171 wxColour
const *m_ColourBG
;
174 /// this object doesn't do anything at all
175 class wxLayoutObjectLineBreak
: public wxLayoutObjectBase
178 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_LINEBREAK
; }
183 This class provides a high level abstraction to the wxFText
185 It handles most of the character events with its own callback
186 functions, providing an editing ability. All events which cannot be
187 handled get passed to the parent window's handlers.
189 class wxLayoutList
: public wxLayoutObjectList
198 void AddObject(wxLayoutObjectBase
*obj
);
199 void AddText(String
const &txt
);
201 void LineBreak(void);
202 void SetFont(int family
, int size
, int style
,
203 int weight
, int underline
,
206 void SetFont(int family
=-1, int size
= -1, int style
=-1,
207 int weight
=-1, int underline
= -1,
208 char const *fg
= NULL
,
209 char const *bg
= NULL
);
210 inline void SetFontFamily(int family
) { SetFont(family
); }
211 inline void SetFontSize(int size
) { SetFont(-1,size
); }
212 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
213 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
214 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
215 inline void SetFontColour(char const *fg
, char const *bg
= NULL
) { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
218 /** Draw the list on a given DC.
219 @param findObject if true, return the object occupying the
220 position specified by coords
221 @param coords position where to find the object
222 @return if findObject == true, the object or NULL
224 wxLayoutObjectBase
*Draw(wxDC
&dc
, bool findObject
= false,
225 wxPoint
const &coords
= wxPoint(0,0));
227 #ifdef WXLAYOUT_DEBUG
232 /// for access by wxLayoutWindow:
233 void GetSize(CoordType
*max_x
, CoordType
*max_y
,
234 CoordType
*lineHeight
);
236 /**@name Functionality for editing */
238 /// set list editable or read only
239 void SetEditable(bool editable
= true) { m_Editable
= true; }
241 void MoveCursor(int dx
= 0, int dy
= 0);
242 void SetCursor(wxPoint
const &p
) { m_CursorPosition
= p
; }
243 /// delete one or more cursor positions
244 void Delete(CoordType count
= 1);
245 void Insert(String
const &text
);
246 void Insert(wxLayoutObjectBase
*obj
);
247 void Clear(int family
= wxROMAN
, int size
=12, int style
=wxNORMAL
, int weight
=wxNORMAL
,
248 int underline
=0, char const *fg
="black", char const *bg
="white");
250 /// return a pointer to the default settings:
251 wxLayoutObjectCmd
const *GetDefaults(void) const { return m_DefaultSetting
; }
256 int m_FontFamily
, m_FontStyle
, m_FontWeight
;
258 bool m_FontUnderline
;
260 wxColour
const * m_ColourFG
;
261 wxColour
const * m_ColourBG
;
262 /// the default setting:
263 wxLayoutObjectCmd
*m_DefaultSetting
;
265 /// needs recalculation?
268 // the currently updated line:
269 /// where do we draw next:
271 /// the height of the current line:
272 CoordType m_LineHeight
;
273 /// maximum drawn x position so far
275 /// maximum drawn y position:
278 //---- this is needed for editing:
279 /// where is the text cursor:
280 wxPoint m_CursorPosition
;
281 /// which is the last line
285 /// find the object to the cursor position and returns the offset
287 wxLayoutObjectList::iterator
FindObjectCursor(wxPoint
const &cpos
, CoordType
*offset
= NULL
);
288 wxLayoutObjectList::iterator
FindCurrentObject(CoordType
*offset
= NULL
);
289 // get the length of the line with the object pointed to by i
290 CoordType
GetLineLength(wxLayoutObjectList::iterator i
);