]>
git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxllist.h
06e077b0a10f70b9838e5243fdd39c86c07d8926
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 enum wxLayoutObjectType
{ WXLO_TYPE_INVALID
, WXLO_TYPE_TEXT
, WXLO_TYPE_CMD
, WXLO_TYPE_ICON
, WXLO_TYPE_LINEBREAK
};
37 typedef long CoordType
;
40 class wxLayoutObjectBase
;
42 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObjectBase
);
43 KBLIST_DEFINE(wxLayoutOLinesList
, wxLayoutObjectList::iterator
);
46 class wxLayoutObjectBase
49 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; } ;
51 @param dc the wxDC to draw on
52 @param position where to draw the top left corner
53 @param baseLine the baseline for alignment, from top of box
54 @draw if set to false, do not draw but just calculate sizes
56 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
59 virtual wxPoint
GetSize(CoordType
*baseLine
) const { return
61 /// returns the number of cursor positions occupied by this object
62 virtual CoordType
CountPositions(void) const { return 1; }
64 wxLayoutObjectBase() { m_UserData
= NULL
; }
65 virtual ~wxLayoutObjectBase() { if(m_UserData
) delete m_UserData
; }
67 virtual void Debug(void);
70 void SetUserData(void *data
) { m_UserData
= data
; }
71 void * GetUserData(void) const { return m_UserData
; }
73 /// optional data for application's use
77 /// object for text block
78 class wxLayoutObjectText
: public wxLayoutObjectBase
81 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
82 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
84 /** This returns the height and in baseLine the position of the
85 text's baseline within it's box. This is needed to properly
88 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
90 virtual void Debug(void);
93 wxLayoutObjectText(const String
&txt
);
94 virtual CoordType
CountPositions(void) const { return strlen(m_Text
.c_str()); }
97 String
& GetText(void) { return m_Text
; }
98 void SetText(String
const &text
) { m_Text
= text
; }
101 /// size of the box containing text
102 long m_Width
, m_Height
;
103 /// the position of the baseline counted from the top of the box
108 class wxLayoutObjectIcon
: public wxLayoutObjectBase
111 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
112 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
114 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
115 wxLayoutObjectIcon(wxIcon
*icon
);
120 /// for export to html:
121 struct wxLayoutStyleInfo
123 int size
, family
, style
, weight
;
125 unsigned fg_red
, fg_green
, fg_blue
;
126 unsigned bg_red
, bg_green
, bg_blue
;
129 /// pseudo-object executing a formatting command in Draw()
130 class wxLayoutObjectCmd
: public wxLayoutObjectBase
133 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
134 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
136 wxLayoutObjectCmd(int size
, int family
, int style
, int weight
,
138 wxColour
const *fg
, wxColour
const *bg
);
139 ~wxLayoutObjectCmd();
140 // caller must free pointer:
141 wxLayoutStyleInfo
*GetStyle(void) const ;
145 /// foreground colour
146 wxColour
const *m_ColourFG
;
147 /// background colour
148 wxColour
const *m_ColourBG
;
151 /// this object doesn't do anything at all
152 class wxLayoutObjectLineBreak
: public wxLayoutObjectBase
155 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_LINEBREAK
; }
160 This class provides a high level abstraction to the wxFText
162 It handles most of the character events with its own callback
163 functions, providing an editing ability. All events which cannot be
164 handled get passed to the parent window's handlers.
166 class wxLayoutList
: public wxLayoutObjectList
175 void AddObject(wxLayoutObjectBase
*obj
);
176 void AddText(String
const &txt
);
178 void LineBreak(void);
179 void SetFont(int family
, int size
, int style
,
180 int weight
, int underline
,
183 void SetFont(int family
=-1, int size
= -1, int style
=-1,
184 int weight
=-1, int underline
= -1,
185 char const *fg
= NULL
,
186 char const *bg
= NULL
);
187 inline void SetFontFamily(int family
) { SetFont(family
); }
188 inline void SetFontSize(int size
) { SetFont(-1,size
); }
189 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
190 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
191 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
192 inline void SetFontColour(char const *fg
, char const *bg
= NULL
) { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
195 /** Draw the list on a given DC.
196 @param findObject if true, return the object occupying the
197 position specified by coords
198 @param coords position where to find the object
199 @return if findObject == true, the object or NULL
201 wxLayoutObjectBase
*Draw(wxDC
&dc
, bool findObject
= false,
202 wxPoint
const &coords
= wxPoint(0,0));
204 #ifdef WXLAYOUT_DEBUG
209 /// for access by wxLayoutWindow:
210 void GetSize(CoordType
*max_x
, CoordType
*max_y
,
211 CoordType
*lineHeight
);
213 /**@name Functionality for editing */
215 /// set list editable or read only
216 void SetEditable(bool editable
= true) { m_Editable
= true; }
218 void MoveCursor(int dx
= 0, int dy
= 0);
219 void SetCursor(wxPoint
const &p
) { m_CursorPosition
= p
; }
220 /// delete one or more cursor positions
221 void Delete(CoordType count
= 1);
222 void Insert(String
const &text
);
223 void Insert(wxLayoutObjectBase
*obj
);
224 void Clear(int family
= wxROMAN
, int size
=12, int style
=wxNORMAL
, int weight
=wxNORMAL
,
225 int underline
=0, char const *fg
="black", char const *bg
="white");
230 int m_FontFamily
, m_FontStyle
, m_FontWeight
;
232 bool m_FontUnderline
;
234 wxColour
const * m_ColourFG
;
235 wxColour
const * m_ColourBG
;
236 /// the default setting:
237 wxLayoutObjectCmd
*m_DefaultSetting
;
239 /// needs recalculation?
242 // the currently updated line:
243 /// where do we draw next:
245 /// the height of the current line:
246 CoordType m_LineHeight
;
247 /// maximum drawn x position so far
249 /// maximum drawn y position:
252 //---- this is needed for editing:
253 /// where is the text cursor:
254 wxPoint m_CursorPosition
;
255 /// which is the last line
259 /// find the object to the cursor position and returns the offset
261 wxLayoutObjectList::iterator
FindObjectCursor(wxPoint
const &cpos
, CoordType
*offset
= NULL
);
262 wxLayoutObjectList::iterator
FindCurrentObject(CoordType
*offset
= NULL
);
263 // get the length of the line with the object pointed to by i
264 CoordType
GetLineLength(wxLayoutObjectList::iterator i
);