]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxllist.h
fd2d2807c674bc16b637dd6d0018ce6db72d8c3f
[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 @param wxllist pointer to wxLayoutList
115 @param begin if !=-1, from which position on to highlight it
116 @param end if begin !=-1, how many positions to highlight it
117 */
118 virtual void Draw(wxDC & /* dc */,
119 wxPoint const & /* coords */,
120 class wxLayoutList *wxllist,
121 CoordType begin = -1,
122 CoordType end = -1) { }
123
124 /** Calculates and returns the size of the object.
125 @param top where to store height above baseline
126 @param bottom where to store height below baseline
127 @return the size of the object's box in pixels
128 */
129 virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const
130 { *top = 0; *bottom = 0; return wxPoint(0,0); }
131
132 /// Return just the width of the object on the screen.
133 virtual CoordType GetWidth(void) const { return 0; }
134 /// returns the number of cursor positions occupied by this object
135 virtual CoordType GetLength(void) const { return 1; }
136 /** Returns the cursor offset relating to the screen x position
137 relative to begin of object.
138 @param dc the wxDC to use for calculations
139 @param xpos relative x position from head of object
140 @return cursor coordinate offset
141 */
142 virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const { return 0; }
143
144 /// constructor
145 wxLayoutObject() { m_UserData = NULL; }
146 /// delete the user data
147 virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); }
148
149 #ifdef WXLAYOUT_DEBUG
150 virtual void Debug(void);
151 #endif
152
153 /** Tells the object about some user data. This data is associated
154 with the object and will be deleted at destruction time.
155 */
156 void SetUserData(UserData *data)
157 {
158 if(m_UserData)
159 m_UserData->DecRef();
160 m_UserData = data;
161 m_UserData->IncRef();
162 }
163
164 /** Return the user data. */
165 void * GetUserData(void) const { if(m_UserData) m_UserData->IncRef(); return m_UserData; }
166
167 /** Makes a copy of this object.
168 */
169 virtual wxLayoutObject *Copy(void) = 0;
170 protected:
171 /// optional data for application's use
172 UserData *m_UserData;
173 };
174
175 /// Define a list type of wxLayoutObject pointers.
176 KBLIST_DEFINE(wxLayoutObjectList, wxLayoutObject);
177
178 /// An illegal iterator to save typing.
179 #define NULLIT (wxLayoutObjectList::iterator(NULL))
180 /// The iterator type.
181 #define wxLOiterator wxLayoutObjectList::iterator
182
183 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
184
185 wxLayoutObjectText
186
187 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
188 /** This class implements a wxLayoutObject holding plain text.
189 */
190 class wxLayoutObjectText : public wxLayoutObject
191 {
192 public:
193 wxLayoutObjectText(const wxString &txt);
194
195 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
196 virtual void Layout(wxDC &dc);
197 virtual void Draw(wxDC &dc, wxPoint const &coords,
198 class wxLayoutList *wxllist,
199 CoordType begin = -1,
200 CoordType end = -1);
201 /** Calculates and returns the size of the object.
202 @param top where to store height above baseline
203 @param bottom where to store height below baseline
204 @return the size of the object's box in pixels
205 */
206 virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
207 /// Return just the width of the object on the screen.
208 virtual CoordType GetWidth(void) const { return m_Width; }
209 /** Returns the cursor offset relating to the screen x position
210 relative to begin of object.
211 @param dc the wxDC to use for calculations
212 @param xpos relative x position from head of object
213 @return cursor coordinate offset
214 */
215 virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const;
216
217
218 #ifdef WXLAYOUT_DEBUG
219 virtual void Debug(void);
220 #endif
221
222 virtual CoordType GetLength(void) const { return strlen(m_Text.c_str()); }
223
224 // for editing:
225 wxString & GetText(void) { return m_Text; }
226 void SetText(wxString const &text) { m_Text = text; }
227 /** Makes a copy of this object.
228 */
229 virtual wxLayoutObject *Copy(void);
230 private:
231 wxString m_Text;
232 /// size of the box containing text
233 long m_Width, m_Height;
234 /// Height above baseline.
235 long m_Top;
236 /// Height below baseline.
237 long m_Bottom;
238 };
239
240 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
241
242 wxLayoutObjectIcon
243
244 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
245 /** This class implements a wxLayoutObject holding a graphic.
246 */
247 class wxLayoutObjectIcon : public wxLayoutObject
248 {
249 public:
250 wxLayoutObjectIcon(wxBitmap *icon);
251 wxLayoutObjectIcon(wxBitmap const &icon);
252
253 ~wxLayoutObjectIcon() { delete m_Icon; }
254
255 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
256 virtual void Layout(wxDC &dc);
257 virtual void Draw(wxDC &dc, wxPoint const &coords,
258 class wxLayoutList *wxllist,
259 CoordType begin = -1,
260 CoordType end = -1);
261
262 /** Calculates and returns the size of the object.
263 @param top where to store height above baseline
264 @param bottom where to store height below baseline
265 @return the size of the object's box in pixels
266 */
267 virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
268 /// Return just the width of the object on the screen.
269 virtual CoordType GetWidth(void) const { return m_Icon->GetWidth(); }
270 // return a pointer to the icon
271 wxBitmap *GetIcon(void) const { return m_Icon; }
272 /** Makes a copy of this object.
273 */
274 virtual wxLayoutObject *Copy(void);
275 private:
276 wxBitmap *m_Icon;
277 };
278
279 /// for export to html:
280 struct wxLayoutStyleInfo
281 {
282 wxLayoutStyleInfo()
283 {
284 family = -1; // this marks the styleinfo as uninitialised
285 }
286 int size, family, style, weight;
287 bool underline;
288 unsigned fg_red, fg_green, fg_blue;
289 unsigned bg_red, bg_green, bg_blue;
290 };
291
292 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
293
294 wxLayoutObjectCmd
295
296 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
297 /** This class implements a wxLayoutObject holding style change commands.
298 */
299 class wxLayoutObjectCmd : public wxLayoutObject
300 {
301 public:
302 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
303 virtual void Layout(wxDC &dc);
304 virtual void Draw(wxDC &dc, wxPoint const &coords,
305 class wxLayoutList *wxllist,
306 CoordType begin = -1,
307 CoordType end = -1);
308 wxLayoutObjectCmd(int size, int family, int style, int weight,
309 bool underline,
310 wxColour &fg, wxColour &bg);
311 ~wxLayoutObjectCmd();
312 /** Stores the current style in the styleinfo structure */
313 void GetStyle(wxLayoutStyleInfo *si) const;
314 /// return the background colour for setting colour of window
315 wxColour &GetBGColour(void) { return m_ColourBG; }
316 /** Makes a copy of this object.
317 */
318 virtual wxLayoutObject *Copy(void);
319 private:
320 /// the font to use
321 wxFont *m_font;
322 /// foreground colour
323 wxColour m_ColourFG;
324 /// background colour
325 wxColour m_ColourBG;
326 };
327
328 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
329
330 The wxLayoutLine object
331
332 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
333
334 /// forward declaration
335 class wxLayoutList;
336
337 /** This class represents a single line of objects to be displayed.
338 It knows its height and total size and whether it needs to be
339 redrawn or not.
340 It has pointers to its first and next line so it can automatically
341 update them as needed.
342 */
343 class wxLayoutLine
344 {
345 public:
346 /** Constructor.
347 @param prev pointer to previous line or NULL
348 @param next pointer to following line or NULL
349 @param llist pointer to layout list
350 */
351 wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist);
352 /** This function inserts a new object at cursor position xpos.
353 @param xpos where to insert new object
354 @param obj the object to insert
355 @return true if that xpos existed and the object was inserted
356 */
357 bool Insert(CoordType xpos, wxLayoutObject *obj);
358
359 /** This function inserts text at cursor position xpos.
360 @param xpos where to insert
361 @param text the text to insert
362 @return true if that xpos existed and the object was inserted
363 */
364 bool Insert(CoordType xpos, wxString text);
365
366 /** This function appends an object to the line.
367 @param obj the object to insert
368 */
369 void Append(wxLayoutObject * obj)
370 {
371 wxASSERT(obj);
372 m_ObjectList.push_back(obj);
373 m_Length += obj->GetLength();
374 }
375
376 /** This function appens the next line to this, i.e. joins the two
377 lines into one.
378 */
379 void MergeNextLine(wxLayoutList *llist);
380
381 /** This function deletes npos cursor positions from position xpos.
382 @param xpos where to delete
383 @param npos how many positions
384 @return number of positions still to be deleted
385 */
386 CoordType Delete(CoordType xpos, CoordType npos);
387
388 /** This function breaks the line at a given cursor position.
389 @param xpos where to break it
390 @return pointer to the new line object replacing the old one
391 */
392 wxLayoutLine *Break(CoordType xpos, wxLayoutList *llist);
393
394 /** Deletes the next word from this position, including leading
395 whitespace.
396 This function does not delete over font changes, i.e. a word
397 with formatting instructions in the middle of it is treated as
398 two (three actually!) words. In fact, if the cursor is on a non-text object, that
399 one is treated as a word.
400 @param xpos from where to delete
401 @return true if a word was deleted
402 */
403 bool DeleteWord(CoordType npos);
404
405 /** Finds a suitable position left to the given column to break the
406 line.
407 @param column we want to break the line to the left of this
408 @return column for breaking line or -1 if no suitable location found
409 */
410 CoordType GetWrapPosition(CoordType column);
411
412 /** Finds the object which covers the cursor position xpos in this
413 line.
414 @param xpos the column number
415 @param offset where to store the difference between xpos and
416 the object's head
417 @return iterator to the object or NULLIT
418 */
419 wxLayoutObjectList::iterator FindObject(CoordType xpos, CoordType
420 *offset) const ;
421
422 /** Finds the object which covers the screen position xpos in this
423 line.
424 @param dc the wxDC to use for calculations
425 @param xpos the screen x coordinate
426 @param offset where to store the difference between xpos and
427 the object's head
428 @return iterator to the object or NULLIT
429 */
430 wxLayoutObjectList::iterator FindObjectScreen(wxDC &dc,
431 CoordType xpos,
432 CoordType *offset,
433 bool *found = NULL) const ;
434
435 /** Get the first object in the list. This is used by the wxlparser
436 functions to export the list.
437 @return iterator to the first object
438 */
439 wxLayoutObjectList::iterator GetFirstObject(void)
440 {
441 return m_ObjectList.begin();
442 }
443
444 /** Deletes this line, returns pointer to next line.
445 @param update If true, update all following lines.
446 */
447 wxLayoutLine *DeleteLine(bool update, wxLayoutList *llist);
448
449 /**@name Cursor Management */
450 //@{
451 /** Return the line number of this line.
452 @return the line number
453 */
454 inline CoordType GetLineNumber(void) const { return m_LineNumber; }
455 /** Return the length of the line.
456 @return line lenght in cursor positions
457 */
458 inline CoordType GetLength(void) const { return m_Length; }
459 //@}
460
461 /**@name Drawing and Layout */
462 //@{
463 /** Draws the line on a wxDC.
464 @param dc the wxDC to draw on
465 @param llist the wxLayoutList
466 @param offset an optional offset to shift printout
467 */
468 void Draw(wxDC &dc,
469 wxLayoutList *llist,
470 const wxPoint &offset = wxPoint(0,0)) const;
471
472 /** Recalculates the positions of objects and the height of the
473 line.
474 @param dc the wxDC to draw on
475 @param llist th e wxLayoutList
476 @param cursorPos if not NULL, set cursor screen position in there
477 @param cursorSize if not cursorPos != NULL, set cursor size in there
478 @param cx if cursorPos != NULL, the cursor x position
479 */
480 void Layout(wxDC &dc,
481 wxLayoutList *llist,
482 wxPoint *cursorPos = NULL,
483 wxPoint *cursorSize = NULL,
484 int cx = 0);
485 /** This function finds an object belonging to a given cursor
486 position. It assumes that Layout() has been called before.
487 @param dc the wxDC to use for calculations
488 @param xpos screen x position
489 @param found if non-NULL set to false if we return the last
490 object before the cursor, to true if we really have an object
491 for that position
492 @return pointer to the object
493 */
494 wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos, bool
495 *found = NULL);
496 //@}
497
498 /**@name List traversal */
499 //@{
500 /// Returns pointer to next line.
501 wxLayoutLine *GetNextLine(void) const { return m_Next; }
502 /// Returns pointer to previous line.
503 wxLayoutLine *GetPreviousLine(void) const { return m_Previous; }
504 /// Sets the link to the next line.
505 void SetNext(wxLayoutLine *next)
506 { m_Next = next; if(next) next->m_Previous = this; }
507 /// Sets the link to the previous line.
508 void SetPrevious(wxLayoutLine *previous)
509 { m_Previous = previous; if(previous) previous->m_Next = this; }
510 //@}
511
512 /// Returns the position of this line on the canvas.
513 wxPoint GetPosition(void) const { return m_Position; }
514 /// Returns the height of this line.
515 CoordType GetHeight(void) const { return m_Height; }
516 /// Returns the width of this line.
517 CoordType GetWidth(void) const { return m_Width; }
518 /** This will recalculate the position and size of this line.
519 If called recursively it will abort if the position of an
520 object is unchanged, assuming that none of the following
521 objects need to move.
522 @param recurse if greater 0 then it will be used as the
523 minimum(!) recursion level, continue with all lines till the end of
524 the list or until the coordinates no longer changed.
525 */
526 void RecalculatePositions(int recurse, wxLayoutList *llist);
527 /// Recalculates the position of this line on the canvas.
528 wxPoint RecalculatePosition(wxLayoutList *llist);
529
530 #ifdef WXLAYOUT_DEBUG
531 void Debug(void);
532 #endif
533
534 private:
535 /// Destructor is private. Use DeleteLine() to remove it.
536 ~wxLayoutLine();
537
538 /**@name Functions to let the lines synchronise with each other. */
539 //@{
540 /** Sets the height of this line. Will mark following lines as
541 dirty.
542 @param height new height
543 */
544 void SetHeight(CoordType height, wxLayoutList *llist)
545 { m_Height = height; RecalculatePositions(true, llist); }
546
547 /** Moves the linenumbers one on, because a line has been inserted
548 or deleted.
549 @param delta either +1 or -1
550 */
551 void MoveLines(int delta)
552 {
553 m_LineNumber += delta;
554 if(m_Next) m_Next->MoveLines(delta);
555 }
556 //@}
557 private:
558 /// The line number.
559 CoordType m_LineNumber;
560 /// The line length in cursor positions.
561 CoordType m_Length;
562 /// The total height of the line.
563 CoordType m_Height;
564 /// The total width of the line on screen.
565 CoordType m_Width;
566 /// The baseline for drawing objects
567 CoordType m_BaseLine;
568 /// The position on the canvas.
569 wxPoint m_Position;
570 /// The list of objects
571 wxLayoutObjectList m_ObjectList;
572 /// Have we been changed since the last layout?
573 bool m_Dirty;
574 /// Pointer to previous line if it exists.
575 wxLayoutLine *m_Previous;
576 /// Pointer to next line if it exists.
577 wxLayoutLine *m_Next;
578 /// Just to suppress gcc compiler warnings.
579 friend class dummy;
580 private:
581 wxLayoutLine(const wxLayoutLine &);
582 };
583
584
585 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
586
587 The wxLayoutList object
588
589 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
590 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
591 higher level of abstraction for the text and can generally be considered
592 as representing "the text".
593 */
594 class wxLayoutList
595 {
596 public:
597 /// Constructor.
598 wxLayoutList();
599 /// Destructor.
600 ~wxLayoutList();
601
602 /// Clear the list.
603 void Clear(int family = wxROMAN,
604 int size=WXLO_DEFAULTFONTSIZE,
605 int style=wxNORMAL,
606 int weight=wxNORMAL,
607 int underline=0,
608 wxColour *fg=NULL,
609 wxColour *bg=NULL);
610 /// Empty: clear the list but leave font settings.
611 void Empty(void);
612
613 /**@name Cursor Management */
614 //@{
615 /** Set new cursor position.
616 @param p new position
617 @return bool if it could be set
618 */
619 bool MoveCursorTo(wxPoint const &p);
620 /** Move cursor up or down.
621 @param n
622 @return bool if it could be moved
623 */
624 bool MoveCursorVertically(int n);
625 /** Move cursor left or right.
626 @param n
627 @return bool if it could be moved
628 */
629 bool MoveCursorHorizontally(int n);
630
631 /// Move cursor to end of line.
632 void MoveCursorToEndOfLine(void)
633 {
634 wxASSERT(m_CursorLine);
635 MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
636 }
637
638 /// Move cursor to begin of line.
639 void MoveCursorToBeginOfLine(void)
640 { MoveCursorHorizontally(-m_CursorPos.x); }
641
642 /// Returns current cursor position.
643 wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; }
644 //@}
645
646 /**@name Editing functions.
647 All of these functions return true on success and false on
648 failure. */
649 //@{
650 /// Insert text at current cursor position.
651 bool Insert(wxString const &text);
652 /// Insert some other object at current cursor position.
653 bool Insert(wxLayoutObject *obj);
654 /// Inserts a linebreak at current cursor position.
655 bool LineBreak(void);
656 /** Wraps the current line. Searches to the left of the cursor to
657 break the line. Does nothing if the cursor position is before
658 the break position parameter.
659 @param column the break position for the line, maximum length
660 @return true if line got broken
661 */
662 bool WrapLine(CoordType column);
663 /** This function deletes npos cursor positions.
664 @param npos how many positions
665 @return true if everything got deleted
666 */
667 bool Delete(CoordType npos);
668
669 /** Delete the next n lines.
670 @param n how many lines to delete
671 @return how many it could not delete
672 */
673 int DeleteLines(int n);
674
675 /// Delete to end of line.
676 void DeleteToEndOfLine(void)
677 {
678 wxASSERT(m_CursorLine);
679 Delete(m_CursorLine->GetLength()-m_CursorPos.x);
680 }
681 /// Delete to begin of line.
682 void DeleteToBeginOfLine(void)
683 {
684 wxASSERT(m_CursorLine);
685 CoordType n = m_CursorPos.x;
686 #ifdef WXLAYOUT_DEBUG
687 wxASSERT(MoveCursorHorizontally(-n));
688 #else
689 MoveCursorHorizontally(-n);
690 #endif
691 Delete(n);
692 }
693
694 /** Delete the next word.
695 */
696 void DeleteWord(void)
697 {
698 wxASSERT(m_CursorLine);
699 m_CursorLine->DeleteWord(m_CursorPos.x);
700 }
701
702 //@}
703
704 /**@name Formatting options */
705 //@{
706 /// sets font parameters
707 void SetFont(int family, int size, int style,
708 int weight, int underline,
709 wxColour *fg,
710 wxColour *bg);
711 /// sets font parameters, colours by name
712 void SetFont(int family=-1, int size = -1, int style=-1,
713 int weight=-1, int underline = -1,
714 char const *fg = NULL,
715 char const *bg = NULL);
716 /// changes to the next larger font size
717 inline void SetFontLarger(void)
718 { SetFont(-1,(12*m_FontPtSize)/10); }
719 /// changes to the next smaller font size
720 inline void SetFontSmaller(void)
721 { SetFont(-1,(10*m_FontPtSize)/12); }
722
723 /// set font family
724 inline void SetFontFamily(int family) { SetFont(family); }
725 /// set font size
726 inline void SetFontSize(int size) { SetFont(-1,size); }
727 /// set font style
728 inline void SetFontStyle(int style) { SetFont(-1,-1,style); }
729 /// set font weight
730 inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); }
731 /// toggle underline flag
732 inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
733 /// set font colours by name
734 inline void SetFontColour(char const *fg, char const *bg = NULL) { SetFont(-1,-1,-1,-1,-1,fg,bg); }
735 /**
736 Returns a pointer to the default settings.
737 This is only valid temporarily and should not be stored
738 anywhere.
739 @return the default settings of the list
740 */
741 wxLayoutObjectCmd *GetDefaults(void) { return m_DefaultSetting ; }
742 //@}
743
744 /**@name Drawing */
745 //@{
746 /** Draws the complete list on a wxDC.
747 @param dc the wxDC to draw on
748 @param offset an optional offset to shift printout
749 @param top optional y coordinate where to start drawing
750 @param bottom optional y coordinate where to stop drawing
751 */
752 void Draw(wxDC &dc,
753 const wxPoint &offset = wxPoint(0,0),
754 CoordType top = -1, CoordType bottom = -1);
755
756 /** Calculates new layout for the list, like Draw() but does not
757 actually draw it.
758 @param dc the wxDC to draw on
759 @param bottom optional y coordinate where to stop calculating
760 */
761 void Layout(wxDC &dc, CoordType bottom = -1);
762
763 /** Calculates new sizes for everything in the list, like Layout()
764 but this is needed after the list got changed.
765 @param dc the wxDC to draw on
766 @param bottom optional y coordinate where to stop calculating
767 */
768 void Recalculate(wxDC &dc, CoordType bottom = -1);
769
770 /** Returns the size of the list in screen coordinates.
771 The return value only makes sense after the list has been
772 drawn.
773 @return a wxPoint holding the maximal x/y coordinates used for
774 drawing
775 */
776 wxPoint GetSize(void) const;
777
778 /** Returns the cursor position on the screen.
779 @return cursor position in pixels
780 */
781 wxPoint GetCursorScreenPos(wxDC &dc);
782
783 /** Draws the cursor.
784 @param active If true, draw a bold cursor to mark window as
785 active.
786 @param translate optional translation of cursor coords on screen
787 */
788 void DrawCursor(wxDC &dc,
789 bool active = true,
790 const wxPoint & translate = wxPoint(0,0));
791
792 /** This function finds an object belonging to a given screen
793 position. It assumes that Layout() has been called before.
794 @param pos screen position
795 @param cursorPos if non NULL, store cursor position in there
796 @param found if used, set this to true if we really found an
797 object, to false if we had to take the object near to it
798 @return pointer to the object
799 */
800 wxLayoutObject * FindObjectScreen(wxDC &dc,
801 wxPoint const pos,
802 wxPoint *cursorPos = NULL,
803 bool *found = NULL);
804
805 /** Called by the objects to update the update rectangle.
806 @param x horizontal coordinate to include in rectangle
807 @param y vertical coordinate to include in rectangle
808 */
809 void SetUpdateRect(CoordType x, CoordType y);
810 /** Called by the objects to update the update rectangle.
811 @param p a point to include in it
812 */
813 inline void SetUpdateRect(const wxPoint &p)
814 { SetUpdateRect(p.x,p.y); }
815 /// Invalidates the update rectangle.
816 void InvalidateUpdateRect(void) { m_UpdateRectValid = false; }
817 /// Returns the update rectangle.
818 const wxRect *GetUpdateRect(void) const { return &m_UpdateRect; }
819 //@}
820
821 /**@name For exporting one object after another. */
822 //@{
823 /** Returns a pointer to the first line in the list. */
824 wxLayoutLine *GetFirstLine(void)
825 {
826 wxASSERT(m_FirstLine);
827 return m_FirstLine;
828 }
829 //@}
830
831 /// Begin selecting text.
832 void StartSelection(void);
833 // Continue selecting text
834 void ContinueSelection(void);
835 /// End selecting text.
836 void EndSelection(void);
837 /// Are we still selecting text?
838 bool IsSelecting(void);
839 bool IsSelected(const wxPoint &cursor);
840
841 /// starts highlighting of text for selections
842 void StartHighlighting(wxDC &dc);
843 /// ends highlighting of text for selections
844 void EndHighlighting(wxDC &dc);
845
846 /** Tests whether this layout line is selected and needs
847 highlighting.
848 @param line to test for
849 @param from set to first cursorpos to be highlighted (for returncode == -1)
850 @param to set to last cursorpos to be highlighted (for returncode == -1)
851 @return 0 = not selected, 1 = fully selected, -1 = partially
852 selected
853
854 */
855 int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
856
857 #ifdef WXLAYOUT_DEBUG
858 void Debug(void);
859 #endif
860 private:
861 /// Clear the list.
862 void InternalClear(void);
863 /** Calculates the cursor position on the screen.
864 */
865 void UpdateCursorScreenPos(wxDC &dc);
866
867 /// The list of lines.
868 wxLayoutLine *m_FirstLine;
869 /// The update rectangle which needs to be refreshed:
870 wxRect m_UpdateRect;
871 /// Is the update rectangle valid?
872 bool m_UpdateRectValid;
873 /**@name Cursor Management */
874 //@{
875 /// Where the text cursor (column,line) is.
876 wxPoint m_CursorPos;
877 /// The size of the cursor.
878 wxPoint m_CursorSize;
879 /// Where the cursor should be drawn.
880 wxPoint m_CursorScreenPos;
881 /// The line where the cursor is.
882 wxLayoutLine *m_CursorLine;
883 //@}
884
885 /// A structure for the selection.
886 struct Selection
887 {
888 bool m_valid;
889 bool m_selecting;
890 wxPoint m_CursorA, m_CursorB;
891 Selection() { m_valid = false; m_selecting = true; }
892 } m_Selection;
893 /** @name Font parameters. */
894 //@{
895 int m_FontFamily, m_FontStyle, m_FontWeight;
896 int m_FontPtSize;
897 bool m_FontUnderline;
898 /// colours:
899 wxColour m_ColourFG;
900 wxColour m_ColourBG;
901 /// the default setting:
902 wxLayoutObjectCmd *m_DefaultSetting;
903 //@}
904 };
905
906
907
908
909 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
910
911 The wxLayoutPrintout object for printing within the wxWindows print
912 framework.
913
914 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
915 /** This class implements a wxPrintout for printing a wxLayoutList within
916 the wxWindows printing framework.
917 */
918 class wxLayoutPrintout: public wxPrintout
919 {
920 public:
921 /** Constructor.
922 @param llist pointer to the wxLayoutList to be printed
923 @param title title for PS file or windows
924 */
925 wxLayoutPrintout(wxLayoutList *llist,
926 wxString const & title =
927 "wxLayout Printout");
928 /// Destructor.
929 ~wxLayoutPrintout();
930
931 /** Function which prints the n-th page.
932 @param page the page number to print
933 @return bool true if we are not at end of document yet
934 */
935 bool OnPrintPage(int page);
936 /** Checks whether page exists in document.
937 @param page number of page
938 @return true if page exists
939 */
940 bool HasPage(int page);
941
942 /** Gets called from wxWindows to find out which pages are existing.
943 I'm not totally sure about the parameters though.
944 @param minPage the first page in the document
945 @param maxPage the last page in the document
946 @param selPageFrom the first page to be printed
947 @param selPageTo the last page to be printed
948 */
949 void GetPageInfo(int *minPage, int *maxPage,
950 int *selPageFrom, int *selPageTo);
951 protected:
952 /** This little function scales the DC so that the printout has
953 roughly the same size as the output on screen.
954 @param dc the wxDC to scale
955 @return the scale that was applied
956 */
957 float ScaleDC(wxDC *dc);
958
959 /* no longer used
960 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
961 */
962 private:
963 /// The list to print.
964 wxLayoutList *m_llist;
965 /// Title for PS file or window.
966 wxString m_title;
967 /// The real paper size.
968 int m_PageHeight, m_PageWidth;
969 /// How much we actually print per page.
970 int m_PrintoutHeight;
971 /// How many pages we need to print.
972 int m_NumOfPages;
973 /// Top left corner where we start printing.
974 wxPoint m_Offset;
975 };
976
977
978 #endif // WXLLIST_H