]>
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 #include "wx/printdlg.h"
20 #include "wx/generic/printps.h"
21 #include "wx/generic/prntdlgg.h"
23 // skip the following defines if embedded in M application
26 //# define WXLAYOUT_DEBUG
30 # define WXLAYOUT_DEBUG
31 // The wxLayout classes can be compiled with std::string instead of wxString
32 //# define USE_STD_STRING
37 typedef std::string String
;
38 # define Str(str)(str.c_str())
40 typedef wxString String
;
44 /// Types of currently supported layout objects.
45 enum wxLayoutObjectType
46 { WXLO_TYPE_INVALID
= 0, WXLO_TYPE_TEXT
, WXLO_TYPE_CMD
, WXLO_TYPE_ICON
, WXLO_TYPE_LINEBREAK
};
48 /// Type used for coordinates in drawing.
49 typedef long CoordType
;
52 class wxLayoutObjectBase
;
58 /** The base class defining the interface to each object which can be
59 part of the layout. Each object needs to draw itself and calculate
62 class wxLayoutObjectBase
65 /// return the type of this object
66 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; } ;
68 @param dc the wxDC to draw on
69 @param position where to draw the top left corner
70 @param baseLine the baseline for alignment, from top of box
71 @draw if set to false, do not draw but just calculate sizes
73 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
76 /** Calculates and returns the size of the object. May need to be
78 @param baseLine pointer where to store the baseline position of
79 this object (i.e. the height from the top of the box to the
81 @return the size of the object's box in pixels
83 virtual wxPoint
GetSize(CoordType
*baseLine
) const { return
85 /// returns the number of cursor positions occupied by this object
86 virtual CoordType
CountPositions(void) const { return 1; }
89 wxLayoutObjectBase() { m_UserData
= NULL
; }
90 /// note: any user data will be freed at the time the object is deleted
91 virtual ~wxLayoutObjectBase() { if(m_UserData
) delete m_UserData
; }
93 virtual void Debug(void);
96 /** Tells the object about some user data. This data is associated
97 with the object and will be deleted at destruction time.
99 void SetUserData(void *data
) { m_UserData
= data
; }
100 /** Return the user data. */
101 void * GetUserData(void) const { return m_UserData
; }
103 /// optional data for application's use
107 /// Define a list type of wxLayoutObjectBase pointers.
108 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObjectBase
);
111 /// object for text block
112 class wxLayoutObjectText
: public wxLayoutObjectBase
115 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
116 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
118 /** This returns the height and in baseLine the position of the
119 text's baseline within it's box. This is needed to properly
122 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
123 #ifdef WXLAYOUT_DEBUG
124 virtual void Debug(void);
127 wxLayoutObjectText(const String
&txt
);
128 virtual CoordType
CountPositions(void) const { return strlen(m_Text
.c_str()); }
131 String
& GetText(void) { return m_Text
; }
132 void SetText(String
const &text
) { m_Text
= text
; }
135 /// size of the box containing text
136 long m_Width
, m_Height
;
137 /// the position of the baseline counted from the top of the box
142 class wxLayoutObjectIcon
: public wxLayoutObjectBase
145 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
146 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
148 virtual wxPoint
GetSize(CoordType
*baseLine
) const;
149 wxLayoutObjectIcon(wxIcon
*icon
);
155 /// for export to html:
156 struct wxLayoutStyleInfo
158 int size
, family
, style
, weight
;
160 unsigned fg_red
, fg_green
, fg_blue
;
161 unsigned bg_red
, bg_green
, bg_blue
;
164 /// pseudo-object executing a formatting command in Draw()
165 class wxLayoutObjectCmd
: public wxLayoutObjectBase
168 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
169 virtual void Draw(wxDC
&dc
, wxPoint position
, CoordType baseLine
,
171 wxLayoutObjectCmd(int size
, int family
, int style
, int weight
,
173 wxColour
const *fg
, wxColour
const *bg
);
174 ~wxLayoutObjectCmd();
175 /// caller must free pointer:
176 wxLayoutStyleInfo
*GetStyle(void) const ;
177 /// return the background colour for setting colour of window
178 wxColour
const *GetBGColour(void) const { return m_ColourBG
; }
182 /// foreground colour
183 wxColour
const *m_ColourFG
;
184 /// background colour
185 wxColour
const *m_ColourBG
;
188 /// this object doesn't do anything at all
189 class wxLayoutObjectLineBreak
: public wxLayoutObjectBase
192 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_LINEBREAK
; }
196 class wxLayoutPrintout
;
199 This class provides a high level abstraction to the wxFText
201 It handles most of the character events with its own callback
202 functions, providing an editing ability. All events which cannot be
203 handled get passed to the parent window's handlers.
205 class wxLayoutList
: public wxLayoutObjectList
214 void AddObject(wxLayoutObjectBase
*obj
);
215 void AddText(String
const &txt
);
217 void LineBreak(void);
218 void SetFont(int family
, int size
, int style
,
219 int weight
, int underline
,
222 void SetFont(int family
=-1, int size
= -1, int style
=-1,
223 int weight
=-1, int underline
= -1,
224 char const *fg
= (const char *) NULL
,
225 char const *bg
= (const char *) NULL
);
226 inline void SetFontFamily(int family
) { SetFont(family
); }
227 inline void SetFontSize(int size
) { SetFont(-1,size
); }
228 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
229 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
230 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
231 inline void SetFontColour(char const *fg
, char const *bg
= (const char *) NULL
) { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
234 /** Draw the list on a given DC.
235 @param findObject if true, return the object occupying the
236 position specified by coords
237 @param coords position where to find the object
238 @pageNo if > 0, print only that page of a document (for
240 @reallyDraw set this to false if you don't want to draw but just calculate the coordinates
241 @return if findObject == true, the object or NULL
243 wxLayoutObjectBase
*Draw(wxDC
&dc
, bool findObject
= false,
244 wxPoint
const &coords
= wxPoint(0,0),
245 int pageNo
= -1, bool reallyDraw
= true);
247 #ifdef WXLAYOUT_DEBUG
249 void ShowCurrentObject();
253 /// for access by wxLayoutWindow:
254 void GetSize(CoordType
*max_x
, CoordType
*max_y
,
255 CoordType
*lineHeight
);
258 /**@name Functionality for editing */
260 /// set list editable or read only
261 void SetEditable(bool editable
= true) { m_Editable
= editable
; }
262 /// return true if list is editable
263 bool IsEditable(void) const { return m_Editable
; }
264 /// move cursor, returns true if it could move to the desired position
265 bool MoveCursor(int dx
= 0, int dy
= 0);
266 void SetCursor(wxPoint
const &p
) { m_CursorPosition
= p
; }
267 wxPoint
GetCursor(void) const { return m_CursorPosition
; }
268 /// delete one or more cursor positions
269 void Delete(CoordType count
= 1);
270 void Insert(String
const &text
);
271 void Insert(wxLayoutObjectBase
*obj
);
272 void Clear(int family
= wxROMAN
, int size
=12, int style
=wxNORMAL
, int weight
=wxNORMAL
,
273 int underline
=0, char const *fg
="black", char const *bg
="white");
275 /// return a pointer to the default settings:
276 wxLayoutObjectCmd
const *GetDefaults(void) const { return m_DefaultSetting
; }
278 wxLayoutObjectList::iterator
FindCurrentObject(CoordType
*offset
= (CoordType
*) NULL
);
279 // get the length of the line with the object pointed to by i, offs
280 // only used to decide whether we are before or after linebreak
281 CoordType
GetLineLength(wxLayoutObjectList::iterator i
,
283 wxLayoutPrintout
*MakePrintout(wxString
const &name
);
288 int m_FontFamily
, m_FontStyle
, m_FontWeight
;
290 bool m_FontUnderline
;
292 wxColour
const * m_ColourFG
;
293 wxColour
const * m_ColourBG
;
294 /// the default setting:
295 wxLayoutObjectCmd
*m_DefaultSetting
;
297 /// needs recalculation?
300 // the currently updated line:
301 /// where do we draw next:
303 /// the height of the current line:
304 CoordType m_LineHeight
;
305 /// maximum drawn x position so far
307 /// maximum drawn y position:
310 //---- this is needed for editing:
311 /// where is the text cursor:
312 wxPoint m_CursorPosition
;
313 /// which is the last line
317 /// find the object to the cursor position and returns the offset
319 wxLayoutObjectList::iterator
FindObjectCursor(wxPoint
*cpos
, CoordType
*offset
= (CoordType
*) NULL
);
323 class wxLayoutPrintout
: public wxPrintout
326 wxLayoutPrintout(wxLayoutList
&llist
, wxString
const & title
= "My printout"):wxPrintout(title
)
327 { m_llist
= &llist
; m_maxPage
= 0; }
328 bool OnPrintPage(int page
);
329 bool HasPage(int page
);
330 bool OnBeginDocument(int startPage
, int endPage
);
331 void GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int
334 wxLayoutList
*m_llist
;