]>
git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxllist.h
d4744a77ba58f479582cc6a6026d70f61c4f2d7e
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 ;
162 /// return the background colour for setting colour of window
163 wxColour
const *GetBGColour(void) const { return m_ColourBG
; }
167 /// foreground colour
168 wxColour
const *m_ColourFG
;
169 /// background colour
170 wxColour
const *m_ColourBG
;
173 /// this object doesn't do anything at all
174 class wxLayoutObjectLineBreak
: public wxLayoutObjectBase
177 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_LINEBREAK
; }
182 This class provides a high level abstraction to the wxFText
184 It handles most of the character events with its own callback
185 functions, providing an editing ability. All events which cannot be
186 handled get passed to the parent window's handlers.
188 class wxLayoutList
: public wxLayoutObjectList
197 void AddObject(wxLayoutObjectBase
*obj
);
198 void AddText(String
const &txt
);
200 void LineBreak(void);
201 void SetFont(int family
, int size
, int style
,
202 int weight
, int underline
,
205 void SetFont(int family
=-1, int size
= -1, int style
=-1,
206 int weight
=-1, int underline
= -1,
207 char const *fg
= NULL
,
208 char const *bg
= NULL
);
209 inline void SetFontFamily(int family
) { SetFont(family
); }
210 inline void SetFontSize(int size
) { SetFont(-1,size
); }
211 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
212 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
213 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
214 inline void SetFontColour(char const *fg
, char const *bg
= NULL
) { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
217 /** Draw the list on a given DC.
218 @param findObject if true, return the object occupying the
219 position specified by coords
220 @param coords position where to find the object
221 @return if findObject == true, the object or NULL
223 wxLayoutObjectBase
*Draw(wxDC
&dc
, bool findObject
= false,
224 wxPoint
const &coords
= wxPoint(0,0));
226 #ifdef WXLAYOUT_DEBUG
231 /// for access by wxLayoutWindow:
232 void GetSize(CoordType
*max_x
, CoordType
*max_y
,
233 CoordType
*lineHeight
);
235 /**@name Functionality for editing */
237 /// set list editable or read only
238 void SetEditable(bool editable
= true) { m_Editable
= true; }
240 void MoveCursor(int dx
= 0, int dy
= 0);
241 void SetCursor(wxPoint
const &p
) { m_CursorPosition
= p
; }
242 /// delete one or more cursor positions
243 void Delete(CoordType count
= 1);
244 void Insert(String
const &text
);
245 void Insert(wxLayoutObjectBase
*obj
);
246 void Clear(int family
= wxROMAN
, int size
=12, int style
=wxNORMAL
, int weight
=wxNORMAL
,
247 int underline
=0, char const *fg
="black", char const *bg
="white");
249 /// return a pointer to the default settings:
250 wxLayoutObjectCmd
const *GetDefaults(void) const { return m_DefaultSetting
; }
255 int m_FontFamily
, m_FontStyle
, m_FontWeight
;
257 bool m_FontUnderline
;
259 wxColour
const * m_ColourFG
;
260 wxColour
const * m_ColourBG
;
261 /// the default setting:
262 wxLayoutObjectCmd
*m_DefaultSetting
;
264 /// needs recalculation?
267 // the currently updated line:
268 /// where do we draw next:
270 /// the height of the current line:
271 CoordType m_LineHeight
;
272 /// maximum drawn x position so far
274 /// maximum drawn y position:
277 //---- this is needed for editing:
278 /// where is the text cursor:
279 wxPoint m_CursorPosition
;
280 /// which is the last line
284 /// find the object to the cursor position and returns the offset
286 wxLayoutObjectList::iterator
FindObjectCursor(wxPoint
const &cpos
, CoordType
*offset
= NULL
);
287 wxLayoutObjectList::iterator
FindCurrentObject(CoordType
*offset
= NULL
);
288 // get the length of the line with the object pointed to by i
289 CoordType
GetLineLength(wxLayoutObjectList::iterator i
);