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