]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxllist.h
wxTextFile::Close() implemented
[wxWidgets.git] / user / wxLayout / wxllist.h
1 /*-*- c++ -*-********************************************************
2 * wxLayoutList.h - a formatted text rendering engine for wxWindows *
3 * *
4 * (C) 1999 by Karsten Ballüder (Ballueder@usa.net) *
5 * *
6 * $Id$
7 *******************************************************************/
8
9
10 #ifndef WXLLIST_H
11 #define WXLLIST_H
12
13 #ifdef __GNUG__
14 # pragma interface "wxllist.h"
15 #endif
16
17 #include "kbList.h"
18
19 #include "wx/wx.h"
20 #include "wx/print.h"
21 #include "wx/printdlg.h"
22 #include "wx/generic/printps.h"
23 #include "wx/generic/prntdlgg.h"
24
25 // skip the following defines if embedded in M application
26 #ifndef M_BASEDIR
27 # define WXMENU_LAYOUT_LCLICK 1111
28 # define WXMENU_LAYOUT_RCLICK 1112
29 # define WXMENU_LAYOUT_DBLCLICK 1113
30 #endif
31
32 #ifdef __WXDEBUG__
33 # define WXLAYOUT_DEBUG
34 #endif
35
36 #ifdef WXLAYOUT_DEBUG
37 # define WXLO_TRACE(x) wxLogDebug(x)
38 #else
39 # define WXLO_TRACE(x)
40 #endif
41
42
43
44 #ifndef WXLO_DEFAULTFONTSIZE
45 # define WXLO_DEFAULTFONTSIZE 12
46 #endif
47
48
49 /// Types of currently supported layout objects.
50 enum wxLayoutObjectType
51 {
52 /// illegal object type, should never appear
53 WXLO_TYPE_INVALID = 0,
54 /// text object, containing normal text
55 WXLO_TYPE_TEXT,
56 /// command object, containing font or colour changes
57 WXLO_TYPE_CMD,
58 /// icon object, any kind of image
59 WXLO_TYPE_ICON
60 };
61
62 /// Type used for coordinates in drawing. Must be signed.
63 typedef long CoordType;
64
65 // Forward declarations.
66 class wxLayoutList;
67 class wxLayoutObject;
68 class wxDC;
69 class wxColour;
70 class wxFont;
71
72
73 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
74
75 The wxLayout objects which make up the lines.
76
77 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
78
79 /** The base class defining the interface to each object which can be
80 part of the layout. Each object needs to draw itself and calculate
81 its size.
82 */
83 class wxLayoutObject
84 {
85 public:
86 /** This structure can be used to contain data associated with the
87 object.
88 It is refcounted, so the caller has to do a DecRef() on it
89 instead of a delete.
90 */
91 struct UserData
92 {
93 UserData() { m_refcount = 1; }
94 void IncRef(void) { m_refcount++; }
95 void DecRef(void) { m_refcount--; if(m_refcount == 0) delete this;}
96 private:
97 int m_refcount;
98 protected:
99 virtual ~UserData() { wxASSERT(m_refcount == 0); }
100 /// prevents gcc from generating stupid warnings
101 friend class dummy_UserData;
102 };
103
104 /// return the type of this object
105 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_INVALID; }
106 /** Calculates the size of an object.
107 @param dc the wxDC to draw on
108 */
109 virtual void Layout(wxDC &) = 0;
110
111 /** Draws an object.
112 @param dc the wxDC to draw on
113 @param coords where to draw the baseline of the object.
114 */
115 virtual void Draw(wxDC & /* dc */, wxPoint const & /* coords */) { }
116
117 /** Calculates and returns the size of the object.
118 @param top where to store height above baseline
119 @param bottom where to store height below baseline
120 @return the size of the object's box in pixels
121 */
122 virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const
123 { *top = 0; *bottom = 0; return wxPoint(0,0); }
124
125 /// Return just the width of the object on the screen.
126 virtual CoordType GetWidth(void) const { return 0; }
127 /// returns the number of cursor positions occupied by this object
128 virtual CoordType GetLength(void) const { return 1; }
129 /** Returns the cursor offset relating to the screen x position
130 relative to begin of object.
131 @param dc the wxDC to use for calculations
132 @param xpos relative x position from head of object
133 @return cursor coordinate offset
134 */
135 virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const { return 0; }
136
137 /// constructor
138 wxLayoutObject() { m_UserData = NULL; }
139 /// delete the user data
140 virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); }
141
142 #ifdef WXLAYOUT_DEBUG
143 virtual void Debug(void);
144 #endif
145
146 /** Tells the object about some user data. This data is associated
147 with the object and will be deleted at destruction time.
148 */
149 void SetUserData(UserData *data)
150 {
151 if(m_UserData)
152 m_UserData->DecRef();
153 m_UserData = data;
154 m_UserData->IncRef();
155 }
156
157 /** Return the user data. */
158 void * GetUserData(void) const { if(m_UserData) m_UserData->IncRef(); return m_UserData; }
159
160 /** Makes a copy of this object.
161 */
162 virtual wxLayoutObject *Copy(void) = 0;
163 private:
164 /// optional data for application's use
165 UserData *m_UserData;
166 };
167
168 /// Define a list type of wxLayoutObject pointers.
169 KBLIST_DEFINE(wxLayoutObjectList, wxLayoutObject);
170
171 /// An illegal iterator to save typing.
172 #define NULLIT (wxLayoutObjectList::iterator(NULL))
173 /// The iterator type.
174 #define wxLOiterator wxLayoutObjectList::iterator
175
176 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
177
178 wxLayoutObjectText
179
180 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
181 /** This class implements a wxLayoutObject holding plain text.
182 */
183 class wxLayoutObjectText : public wxLayoutObject
184 {
185 public:
186 wxLayoutObjectText(const wxString &txt);
187
188 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
189 virtual void Layout(wxDC &dc);
190 virtual void Draw(wxDC &dc, wxPoint const &coords);
191 /** Calculates and returns the size of the object.
192 @param top where to store height above baseline
193 @param bottom where to store height below baseline
194 @return the size of the object's box in pixels
195 */
196 virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
197 /// Return just the width of the object on the screen.
198 virtual CoordType GetWidth(void) const { return m_Width; }
199 /** Returns the cursor offset relating to the screen x position
200 relative to begin of object.
201 @param dc the wxDC to use for calculations
202 @param xpos relative x position from head of object
203 @return cursor coordinate offset
204 */
205 virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const;
206
207
208 #ifdef WXLAYOUT_DEBUG
209 virtual void Debug(void);
210 #endif
211
212 virtual CoordType GetLength(void) const { return strlen(m_Text.c_str()); }
213
214 // for editing:
215 wxString & GetText(void) { return m_Text; }
216 void SetText(wxString const &text) { m_Text = text; }
217 /** Makes a copy of this object.
218 */
219 virtual wxLayoutObject *Copy(void);
220 private:
221 wxString m_Text;
222 /// size of the box containing text
223 long m_Width, m_Height;
224 /// Height above baseline.
225 long m_Top;
226 /// Height below baseline.
227 long m_Bottom;
228 };
229
230 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
231
232 wxLayoutObjectIcon
233
234 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
235 /** This class implements a wxLayoutObject holding a graphic.
236 */
237 class wxLayoutObjectIcon : public wxLayoutObject
238 {
239 public:
240 wxLayoutObjectIcon(wxBitmap *icon);
241 wxLayoutObjectIcon(wxBitmap const &icon);
242
243 ~wxLayoutObjectIcon() { delete m_Icon; }
244
245 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
246 virtual void Layout(wxDC &dc);
247 virtual void Draw(wxDC &dc, wxPoint const &coords);
248
249 /** Calculates and returns the size of the object.
250 @param top where to store height above baseline
251 @param bottom where to store height below baseline
252 @return the size of the object's box in pixels
253 */
254 virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
255 /// Return just the width of the object on the screen.
256 virtual CoordType GetWidth(void) const { return m_Icon->GetWidth(); }
257 // return a pointer to the icon
258 wxBitmap *GetIcon(void) const { return m_Icon; }
259 /** Makes a copy of this object.
260 */
261 virtual wxLayoutObject *Copy(void);
262 private:
263 wxBitmap *m_Icon;
264 };
265
266 /// for export to html:
267 struct wxLayoutStyleInfo
268 {
269 wxLayoutStyleInfo()
270 {
271 family = -1; // this marks the styleinfo as uninitialised
272 }
273 int size, family, style, weight;
274 bool underline;
275 unsigned fg_red, fg_green, fg_blue;
276 unsigned bg_red, bg_green, bg_blue;
277 };
278
279 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
280
281 wxLayoutObjectCmd
282
283 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
284 /** This class implements a wxLayoutObject holding style change commands.
285 */
286 class wxLayoutObjectCmd : public wxLayoutObject
287 {
288 public:
289 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
290 virtual void Layout(wxDC &dc);
291 virtual void Draw(wxDC &dc, wxPoint const &coords);
292 wxLayoutObjectCmd(int size, int family, int style, int weight,
293 bool underline,
294 wxColour const *fg, wxColour const *bg);
295 ~wxLayoutObjectCmd();
296 /** Stores the current style in the styleinfo structure */
297 void GetStyle(wxLayoutStyleInfo *si) const;
298 /// return the background colour for setting colour of window
299 wxColour const *GetBGColour(void) const { return m_ColourBG; }
300 /** Makes a copy of this object.
301 */
302 virtual wxLayoutObject *Copy(void);
303 private:
304 /// the font to use
305 wxFont *m_font;
306 /// foreground colour
307 wxColour const *m_ColourFG;
308 /// background colour
309 wxColour const *m_ColourBG;
310 };
311
312 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
313
314 The wxLayoutLine object
315
316 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
317
318 /** This class represents a single line of objects to be displayed.
319 It knows its height and total size and whether it needs to be
320 redrawn or not.
321 It has pointers to its first and next line so it can automatically
322 update them as needed.
323 */
324 class wxLayoutLine
325 {
326 public:
327 /** Constructor.
328 @param prev pointer to previous line or NULL
329 @param next pointer to following line or NULL
330 */
331 wxLayoutLine(wxLayoutLine *prev);
332 /** This function inserts a new object at cursor position xpos.
333 @param xpos where to insert new object
334 @param obj the object to insert
335 @return true if that xpos existed and the object was inserted
336 */
337 bool Insert(CoordType xpos, wxLayoutObject *obj);
338
339 /** This function inserts text at cursor position xpos.
340 @param xpos where to insert
341 @param text the text to insert
342 @return true if that xpos existed and the object was inserted
343 */
344 bool Insert(CoordType xpos, wxString text);
345
346 /** This function appends an object to the line.
347 @param obj the object to insert
348 */
349 void Append(wxLayoutObject * obj)
350 {
351 wxASSERT(obj);
352 m_ObjectList.push_back(obj);
353 m_Length += obj->GetLength();
354 }
355
356 /** This function appens the next line to this, i.e. joins the two
357 lines into one.
358 */
359 void MergeNextLine(void);
360
361 /** This function deletes npos cursor positions from position xpos.
362 @param xpos where to delete
363 @param npos how many positions
364 @return number of positions still to be deleted
365 */
366 CoordType Delete(CoordType xpos, CoordType npos);
367
368 /** This function breaks the line at a given cursor position.
369 @param xpos where to break it
370 @return pointer to the new line object replacing the old one
371 */
372 wxLayoutLine *Break(CoordType xpos);
373
374 /** Deletes the next word from this position, including leading
375 whitespace.
376 This function does not delete over font changes, i.e. a word
377 with formatting instructions in the middle of it is treated as
378 two (three actually!) words. In fact, if the cursor is on a non-text object, that
379 one is treated as a word.
380 @param xpos from where to delete
381 @return true if a word was deleted
382 */
383 bool DeleteWord(CoordType npos);
384
385 /** Finds a suitable position left to the given column to break the
386 line.
387 @param column we want to break the line to the left of this
388 @return column for breaking line or -1 if no suitable location found
389 */
390 CoordType GetWrapPosition(CoordType column);
391
392 /** Finds the object which covers the cursor position xpos in this
393 line.
394 @param xpos the column number
395 @param offset where to store the difference between xpos and
396 the object's head
397 @return iterator to the object or NULLIT
398 */
399 wxLayoutObjectList::iterator FindObject(CoordType xpos, CoordType
400 *offset) const ;
401
402 /** Finds the object which covers the screen position xpos in this
403 line.
404 @param dc the wxDC to use for calculations
405 @param xpos the screen x coordinate
406 @param offset where to store the difference between xpos and
407 the object's head
408 @return iterator to the object or NULLIT
409 */
410 wxLayoutObjectList::iterator FindObjectScreen(wxDC &dc,
411 CoordType xpos,
412 CoordType *offset) const ;
413
414 /** Get the first object in the list. This is used by the wxlparser
415 functions to export the list.
416 @return iterator to the first object
417 */
418 wxLayoutObjectList::iterator GetFirstObject(void)
419 {
420 return m_ObjectList.begin();
421 }
422
423 /** Deletes this line, returns pointer to next line.
424 @param update If true, update all following lines.
425 */
426 wxLayoutLine *DeleteLine(bool update);
427
428 /**@name Cursor Management */
429 //@{
430 /** Return the line number of this line.
431 @return the line number
432 */
433 CoordType GetLineNumber(void) const { return m_LineNumber; }
434 /** Return the length of the line.
435 @return line lenght in cursor positions
436 */
437 CoordType GetLength(void) const { return m_Length; }
438 //@}
439
440 /**@name Drawing and Layout */
441 //@{
442 /** Draws the line on a wxDC.
443 @param dc the wxDC to draw on
444 @param offset an optional offset to shift printout
445 */
446 void Draw(wxDC &dc, const wxPoint &offset = wxPoint(0,0)) const;
447
448 /** Recalculates the positions of objects and the height of the
449 line.
450 @param dc the wxDC to draw on
451 @param cursorPos if not NULL, set cursor screen position in there
452 @param cursorSize if not cursorPos != NULL, set cursor size in there
453 @param cx if cursorPos != NULL, the cursor x position
454 */
455 void Layout(wxDC &dc,
456 wxPoint *cursorPos = NULL,
457 wxPoint *cursorSize = NULL,
458 int cx = 0);
459 /** This function finds an object belonging to a given cursor
460 position. It assumes that Layout() has been called before.
461 @param dc the wxDC to use for calculations
462 @param xpos screen x position
463 @return pointer to the object
464 */
465 wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos);
466 //@}
467
468 /**@name List traversal */
469 //@{
470 /// Returns pointer to next line.
471 wxLayoutLine *GetNextLine(void) const { return m_Next; }
472 /// Returns pointer to previous line.
473 wxLayoutLine *GetPreviousLine(void) const { return m_Previous; }
474 /// Sets the link to the next line.
475 void SetNext(wxLayoutLine *next)
476 { m_Next = next; if(next) next->m_Previous = this; }
477 /// Sets the link to the previous line.
478 void SetPrevious(wxLayoutLine *previous)
479 { m_Previous = previous; if(previous) previous->m_Next = this; }
480 //@}
481
482 /// Returns the position of this line on the canvas.
483 wxPoint GetPosition(void) const { return m_Position; }
484 /// Returns the height of this line.
485 CoordType GetHeight(void) const { return m_Height; }
486 /// Returns the width of this line.
487 CoordType GetWidth(void) const { return m_Width; }
488 /** This will recalculate the position and size of this line.
489 If called recursively it will abort if the position of an
490 object is unchanged, assuming that none of the following
491 objects need to move.
492 @param recurse if greater 0 then it will be used as the
493 minimum(!) recursion level, continue with all lines till the end of
494 the list or until the coordinates no longer changed.
495 */
496 void RecalculatePositions(int recurse = 0);
497 /// Recalculates the position of this line on the canvas.
498 wxPoint RecalculatePosition(void);
499 private:
500 /// Destructor is private. Use DeleteLine() to remove it.
501 ~wxLayoutLine();
502
503 /**@name Functions to let the lines synchronise with each other. */
504 //@{
505 /** Sets the height of this line. Will mark following lines as
506 dirty.
507 @param height new height
508 */
509 void SetHeight(CoordType height)
510 { m_Height = height; RecalculatePositions(true); }
511
512 /** Moves the linenumbers one on, because a line has been inserted
513 or deleted.
514 @param delta either +1 or -1
515 */
516 void MoveLines(int delta)
517 {
518 m_LineNumber += delta;
519 if(m_Next) m_Next->MoveLines(delta);
520 }
521 //@}
522 private:
523 /// The line number.
524 CoordType m_LineNumber;
525 /// The line length in cursor positions.
526 CoordType m_Length;
527 /// The total height of the line.
528 CoordType m_Height;
529 /// The total width of the line on screen.
530 CoordType m_Width;
531 /// The baseline for drawing objects
532 CoordType m_BaseLine;
533 /// The position on the canvas.
534 wxPoint m_Position;
535 /// The list of objects
536 wxLayoutObjectList m_ObjectList;
537 /// Have we been changed since the last layout?
538 bool m_Dirty;
539 /// Pointer to previous line if it exists.
540 wxLayoutLine *m_Previous;
541 /// Pointer to next line if it exists.
542 wxLayoutLine *m_Next;
543 /// Just to suppress gcc compiler warnings.
544 friend class dummy;
545 };
546
547
548 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
549
550 The wxLayoutList object
551
552 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
553 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
554 higher level of abstraction for the text and can generally be considered
555 as representing "the text".
556 */
557 class wxLayoutList
558 {
559 public:
560 /// Constructor.
561 wxLayoutList();
562 /// Destructor.
563 ~wxLayoutList();
564
565 /// Clear the list.
566 void Clear(int family = wxROMAN,
567 int size=WXLO_DEFAULTFONTSIZE,
568 int style=wxNORMAL,
569 int weight=wxNORMAL,
570 int underline=0,
571 char const *fg="black",
572 char const *bg="white");
573 /// Empty: clear the list but leave font settings.
574 void Empty(void);
575
576 /**@name Cursor Management */
577 //@{
578 /** Set new cursor position.
579 @param p new position
580 @return bool if it could be set
581 */
582 bool MoveCursorTo(wxPoint const &p);
583 /** Move cursor up or down.
584 @param n
585 @return bool if it could be moved
586 */
587 bool MoveCursorVertically(int n);
588 /** Move cursor left or right.
589 @param n
590 @return bool if it could be moved
591 */
592 bool MoveCursorHorizontally(int n);
593
594 /// Move cursor to end of line.
595 void MoveCursorToEndOfLine(void)
596 {
597 wxASSERT(m_CursorLine);
598 MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
599 }
600
601 /// Move cursor to begin of line.
602 void MoveCursorToBeginOfLine(void)
603 { MoveCursorHorizontally(-m_CursorPos.x); }
604
605 /// Returns current cursor position.
606 wxPoint GetCursorPos(void) const { return m_CursorPos; }
607 //@}
608
609 /**@name Editing functions.
610 All of these functions return true on success and false on
611 failure. */
612 //@{
613 /// Insert text at current cursor position.
614 bool Insert(wxString const &text);
615 /// Insert some other object at current cursor position.
616 bool Insert(wxLayoutObject *obj);
617 /// Inserts a linebreak at current cursor position.
618 bool LineBreak(void);
619 /** Wraps the current line. Searches to the left of the cursor to
620 break the line. Does nothing if the cursor position is before
621 the break position parameter.
622 @param column the break position for the line, maximum length
623 @return true if line got broken
624 */
625 bool WrapLine(CoordType column);
626 /** This function deletes npos cursor positions.
627 @param npos how many positions
628 @return true if everything got deleted
629 */
630 bool Delete(CoordType npos);
631
632 /** Delete the next n lines.
633 @param n how many lines to delete
634 @return how many it could not delete
635 */
636 int DeleteLines(int n);
637
638 /// Delete to end of line.
639 void DeleteToEndOfLine(void)
640 {
641 wxASSERT(m_CursorLine);
642 Delete(m_CursorLine->GetLength()-m_CursorPos.x);
643 }
644 /// Delete to begin of line.
645 void DeleteToBeginOfLine(void)
646 {
647 wxASSERT(m_CursorLine);
648 CoordType n = m_CursorPos.x;
649 #ifdef WXLAYOUT_DEBUG
650 wxASSERT(MoveCursorHorizontally(-n));
651 #else
652 MoveCursorHorizontally(-n);
653 #endif
654 Delete(n);
655 }
656
657 /** Delete the next word.
658 */
659 void DeleteWord(void)
660 {
661 wxASSERT(m_CursorLine);
662 m_CursorLine->DeleteWord(m_CursorPos.x);
663 }
664
665 //@}
666
667 /**@name Formatting options */
668 //@{
669 /// sets font parameters
670 void SetFont(int family, int size, int style,
671 int weight, int underline,
672 wxColour const *fg,
673 wxColour const *bg);
674 /// sets font parameters, colours by name
675 void SetFont(int family=-1, int size = -1, int style=-1,
676 int weight=-1, int underline = -1,
677 char const *fg = NULL,
678 char const *bg = NULL);
679 /// changes to the next larger font size
680 inline void SetFontLarger(void)
681 { SetFont(-1,(12*m_FontPtSize)/10); }
682 /// changes to the next smaller font size
683 inline void SetFontSmaller(void)
684 { SetFont(-1,(10*m_FontPtSize)/12); }
685
686 /// set font family
687 inline void SetFontFamily(int family) { SetFont(family); }
688 /// set font size
689 inline void SetFontSize(int size) { SetFont(-1,size); }
690 /// set font style
691 inline void SetFontStyle(int style) { SetFont(-1,-1,style); }
692 /// set font weight
693 inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); }
694 /// toggle underline flag
695 inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
696 /// set font colours by name
697 inline void SetFontColour(char const *fg, char const *bg = NULL) { SetFont(-1,-1,-1,-1,-1,fg,bg); }
698 /**
699 Returns a pointer to the default settings.
700 This is only valid temporarily and should not be stored
701 anywhere.
702 @return the default settings of the list
703 */
704 wxLayoutObjectCmd const *GetDefaults(void) const { return m_DefaultSetting ; }
705 //@}
706
707 /**@name Drawing */
708 //@{
709 /** Draws the complete list on a wxDC.
710 @param dc the wxDC to draw on
711 @param offset an optional offset to shift printout
712 @param top optional y coordinate where to start drawing
713 @param bottom optional y coordinate where to stop drawing
714 */
715 void Draw(wxDC &dc, const wxPoint &offset = wxPoint(0,0),
716 CoordType top = -1, CoordType bottom = -1) const;
717
718 /** Calculates new layout for the list, like Draw() but does not
719 actually draw it.
720 @param dc the wxDC to draw on
721 @param bottom optional y coordinate where to stop calculating
722 */
723 void Layout(wxDC &dc, CoordType bottom = -1) const;
724
725 /** Calculates new sizes for everything in the list, like Layout()
726 but this is needed after the list got changed.
727 @param dc the wxDC to draw on
728 @param bottom optional y coordinate where to stop calculating
729 */
730 void Recalculate(wxDC &dc, CoordType bottom = -1) const;
731
732 /** Returns the size of the list in screen coordinates.
733 The return value only makes sense after the list has been
734 drawn.
735 @return a wxPoint holding the maximal x/y coordinates used for
736 drawing
737 */
738 wxPoint GetSize(void) const;
739
740 /** Returns the cursor position on the screen.
741 @return cursor position in pixels
742 */
743 wxPoint GetCursorScreenPos(void) const
744 { return m_CursorScreenPos; }
745
746 /** Draws the cursor.
747 @param active If true, draw a bold cursor to mark window as
748 active.
749 @param translate optional translation of cursor coords on screen
750 */
751 void DrawCursor(wxDC &dc,
752 bool active = true,
753 const wxPoint & translate = wxPoint(0,0));
754
755 /** This function finds an object belonging to a given screen
756 position. It assumes that Layout() has been called before.
757 @param pos screen position
758 @param cursorPos if non NULL, store cursor position in there
759 @return pointer to the object
760 */
761 wxLayoutObject * FindObjectScreen(wxDC &dc,
762 wxPoint const pos,
763 wxPoint *cursorPos = NULL);
764
765 //@}
766
767 /**@name For exporting one object after another. */
768 //@{
769 /** Returns a pointer to the first line in the list. */
770 wxLayoutLine *GetFirstLine(void)
771 {
772 wxASSERT(m_FirstLine);
773 return m_FirstLine;
774 }
775 //@}
776 private:
777 /// Clear the list.
778 void InternalClear(void);
779
780 /// The list of lines.
781 wxLayoutLine *m_FirstLine;
782 /**@name Cursor Management */
783 //@{
784 /// Where the text cursor (column,line) is.
785 wxPoint m_CursorPos;
786 /// The size of the cursor.
787 wxPoint m_CursorSize;
788 /// Where the cursor should be drawn.
789 wxPoint m_CursorScreenPos;
790 /// The line where the cursor is.
791 wxLayoutLine *m_CursorLine;
792 //@}
793
794 /** @name Font parameters. */
795 //@{
796 int m_FontFamily, m_FontStyle, m_FontWeight;
797 int m_FontPtSize;
798 bool m_FontUnderline;
799 /// colours:
800 wxColour const * m_ColourFG;
801 wxColour const * m_ColourBG;
802 /// the default setting:
803 wxLayoutObjectCmd *m_DefaultSetting;
804 //@}
805 };
806
807
808
809
810 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
811
812 The wxLayoutPrintout object for printing within the wxWindows print
813 framework.
814
815 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
816 /** This class implements a wxPrintout for printing a wxLayoutList within
817 the wxWindows printing framework.
818 */
819 class wxLayoutPrintout: public wxPrintout
820 {
821 public:
822 /** Constructor.
823 @param llist pointer to the wxLayoutList to be printed
824 @param title title for PS file or windows
825 */
826 wxLayoutPrintout(wxLayoutList *llist,
827 wxString const & title =
828 "wxLayout Printout");
829 /** Function which prints the n-th page.
830 @param page the page number to print
831 @return bool true if we are not at end of document yet
832 */
833 bool OnPrintPage(int page);
834 /** Checks whether page exists in document.
835 @param page number of page
836 @return true if page exists
837 */
838 bool HasPage(int page);
839
840 /** Gets called from wxWindows to find out which pages are existing.
841 I'm not totally sure about the parameters though.
842 @param minPage the first page in the document
843 @param maxPage the last page in the document
844 @param selPageFrom the first page to be printed
845 @param selPageTo the last page to be printed
846 */
847 void GetPageInfo(int *minPage, int *maxPage,
848 int *selPageFrom, int *selPageTo);
849 protected:
850 /** This little function scales the DC so that the printout has
851 roughly the same size as the output on screen.
852 @param dc the wxDC to scale
853 @return the scale that was applied
854 */
855 float ScaleDC(wxDC *dc);
856
857 /* no longer used
858 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
859 */
860 private:
861 /// The list to print.
862 wxLayoutList *m_llist;
863 /// Title for PS file or window.
864 wxString m_title;
865 /// The real paper size.
866 int m_PageHeight, m_PageWidth;
867 /// How much we actually print per page.
868 int m_PrintoutHeight;
869 /// How many pages we need to print.
870 int m_NumOfPages;
871 /// Top left corner where we start printing.
872 wxPoint m_Offset;
873 };
874
875
876 #endif // WXLLIST_H