1 /*-*- c++ -*-********************************************************
2 * wxLayoutList.h - a formatted text rendering engine for wxWindows *
4 * (C) 1999 by Karsten Ballüder (Ballueder@usa.net) *
7 *******************************************************************/
14 # pragma interface "wxllist.h"
21 #include "wx/printdlg.h"
22 #include "wx/generic/printps.h"
23 #include "wx/generic/prntdlgg.h"
25 // skip the following defines if embedded in M application
27 # define WXMENU_LAYOUT_LCLICK 1111
28 # define WXMENU_LAYOUT_RCLICK 1112
29 # define WXMENU_LAYOUT_DBLCLICK 1113
32 // do not enable debug mode within Mahogany
33 #if defined(__WXDEBUG__) && ! defined(M_BASEDIR)
34 # define WXLAYOUT_DEBUG
38 # define WXLO_TRACE(x) wxLogDebug(x)
40 # define WXLO_TRACE(x)
43 #define WXLO_DEBUG_URECT 0
45 #ifndef WXLO_DEFAULTFONTSIZE
46 # define WXLO_DEFAULTFONTSIZE 12
50 /// Types of currently supported layout objects.
51 enum wxLayoutObjectType
53 /// illegal object type, should never appear
54 WXLO_TYPE_INVALID
= 0,
55 /// text object, containing normal text
57 /// command object, containing font or colour changes
59 /// icon object, any kind of image
63 /// Type used for coordinates in drawing. Must be signed.
64 typedef long CoordType
;
66 // Forward declarations.
74 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
76 The wxLayout objects which make up the lines.
78 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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
87 /** This structure can be used to contain data associated with the
89 It is refcounted, so the caller has to do a DecRef() on it
94 UserData() { m_refcount
= 1; }
95 void IncRef(void) { m_refcount
++; }
96 void DecRef(void) { m_refcount
--; if(m_refcount
== 0) delete this;}
100 virtual ~UserData() { wxASSERT(m_refcount
== 0); }
101 /// prevents gcc from generating stupid warnings
102 friend class dummy_UserData
;
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 @param llist the wxLayoutList
111 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
) = 0;
114 @param dc the wxDC to draw on
115 @param coords where to draw the baseline of the object.
116 @param wxllist pointer to wxLayoutList
117 @param begin if !=-1, from which position on to highlight it
118 @param end if begin !=-1, how many positions to highlight it
120 virtual void Draw(wxDC
& /* dc */,
121 wxPoint
const & /* coords */,
122 class wxLayoutList
*wxllist
,
123 CoordType begin
= -1,
124 CoordType end
= -1) { }
126 /** Calculates and returns the size of the object.
127 @param top where to store height above baseline
128 @param bottom where to store height below baseline
129 @return the size of the object's box in pixels
131 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const
132 { *top
= 0; *bottom
= 0; return wxPoint(0,0); }
134 /// Return just the width of the object on the screen.
135 virtual CoordType
GetWidth(void) const { return 0; }
136 /// returns the number of cursor positions occupied by this object
137 virtual CoordType
GetLength(void) const { return 1; }
138 /** Returns the cursor offset relating to the screen x position
139 relative to begin of object.
140 @param dc the wxDC to use for calculations
141 @param xpos relative x position from head of object
142 @return cursor coordinate offset
144 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const { return 0; }
147 wxLayoutObject() { m_UserData
= NULL
; }
148 /// delete the user data
149 virtual ~wxLayoutObject() { if(m_UserData
) m_UserData
->DecRef(); }
151 #ifdef WXLAYOUT_DEBUG
152 virtual void Debug(void);
155 /** Tells the object about some user data. This data is associated
156 with the object and will be deleted at destruction time.
158 void SetUserData(UserData
*data
)
161 m_UserData
->DecRef();
163 m_UserData
->IncRef();
166 /** Return the user data. */
167 void * GetUserData(void) const { if(m_UserData
) m_UserData
->IncRef(); return m_UserData
; }
169 /** Makes a copy of this object.
171 virtual wxLayoutObject
*Copy(void) = 0;
173 /// optional data for application's use
174 UserData
*m_UserData
;
177 /// Define a list type of wxLayoutObject pointers.
178 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObject
);
180 /// An illegal iterator to save typing.
181 #define NULLIT (wxLayoutObjectList::iterator(NULL))
182 /// The iterator type.
183 #define wxLOiterator wxLayoutObjectList::iterator
185 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
189 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
190 /** This class implements a wxLayoutObject holding plain text.
192 class wxLayoutObjectText
: public wxLayoutObject
195 wxLayoutObjectText(const wxString
&txt
);
197 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
198 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
);
199 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
200 class wxLayoutList
*wxllist
,
201 CoordType begin
= -1,
203 /** Calculates and returns the size of the object.
204 @param top where to store height above baseline
205 @param bottom where to store height below baseline
206 @return the size of the object's box in pixels
208 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
209 /// Return just the width of the object on the screen.
210 virtual CoordType
GetWidth(void) const { return m_Width
; }
211 /** Returns the cursor offset relating to the screen x position
212 relative to begin of object.
213 @param dc the wxDC to use for calculations
214 @param xpos relative x position from head of object
215 @return cursor coordinate offset
217 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const;
220 #ifdef WXLAYOUT_DEBUG
221 virtual void Debug(void);
224 virtual CoordType
GetLength(void) const { return strlen(m_Text
.c_str()); }
227 wxString
& GetText(void) { return m_Text
; }
228 void SetText(wxString
const &text
) { m_Text
= text
; }
229 /** Makes a copy of this object.
231 virtual wxLayoutObject
*Copy(void);
234 /// size of the box containing text
235 long m_Width
, m_Height
;
236 /// Height above baseline.
238 /// Height below baseline.
242 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
246 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
247 /** This class implements a wxLayoutObject holding a graphic.
249 class wxLayoutObjectIcon
: public wxLayoutObject
252 wxLayoutObjectIcon(wxBitmap
*icon
);
253 wxLayoutObjectIcon(wxBitmap
const &icon
);
255 ~wxLayoutObjectIcon() { delete m_Icon
; }
257 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
258 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
);
259 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
260 class wxLayoutList
*wxllist
,
261 CoordType begin
= -1,
264 /** Calculates and returns the size of the object.
265 @param top where to store height above baseline
266 @param bottom where to store height below baseline
267 @return the size of the object's box in pixels
269 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
270 /// Return just the width of the object on the screen.
271 virtual CoordType
GetWidth(void) const { return m_Icon
->GetWidth(); }
272 // return a pointer to the icon
273 wxBitmap
*GetIcon(void) const { return m_Icon
; }
274 /** Makes a copy of this object.
276 virtual wxLayoutObject
*Copy(void);
281 /** This structure holds all formatting information. Members which are
282 undefined (for a CmdObject this means: no change), are set to -1.
284 struct wxLayoutStyleInfo
286 wxLayoutStyleInfo(int ifamily
= -1,
292 wxColour
*bg
= NULL
);
293 wxColour
& GetBGColour()
297 wxLayoutStyleInfo
& operator=(const wxLayoutStyleInfo
&right
);
298 /// Font change parameters.
299 int size
, family
, style
, weight
, underline
;
302 bool m_fg_valid
, m_bg_valid
;
306 class wxFontCacheEntry
309 wxFontCacheEntry(int family
, int size
, int style
, int weight
,
312 m_Family
= family
; m_Size
= size
; m_Style
= style
;
313 m_Weight
= weight
; m_Underline
= underline
;
314 m_Font
= new wxFont(m_Size
, m_Family
,
315 m_Style
, m_Weight
, m_Underline
);
317 bool Matches(int family
, int size
, int style
, int weight
,
318 bool underline
) const
320 return size
== m_Size
&& family
== m_Family
321 && style
== m_Style
&& weight
== m_Weight
322 && underline
== m_Underline
;
324 wxFont
& GetFont(void) { return *m_Font
; }
331 int m_Family
, m_Size
, m_Style
, m_Weight
;
335 KBLIST_DEFINE(wxFCEList
, wxFontCacheEntry
);
340 wxFont
& GetFont(int family
, int size
, int style
, int weight
,
342 wxFont
& GetFont(wxLayoutStyleInfo
const &si
)
344 return GetFont(si
.family
, si
.size
, si
.style
, si
.weight
, si
.underline
);
347 wxFCEList m_FontList
;
350 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
354 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
355 /** This class implements a wxLayoutObject holding style change commands.
357 class wxLayoutObjectCmd
: public wxLayoutObject
360 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
361 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
);
362 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
363 class wxLayoutList
*wxllist
,
364 CoordType begin
= -1,
366 wxLayoutObjectCmd(int family
= -1,
372 wxColour
*bg
= NULL
);
373 ~wxLayoutObjectCmd();
374 /** Stores the current style in the styleinfo structure */
375 wxLayoutStyleInfo
* GetStyle(void) const;
376 /** Makes a copy of this object.
378 virtual wxLayoutObject
*Copy(void);
380 wxLayoutStyleInfo
*m_StyleInfo
;
383 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
385 The wxLayoutLine object
387 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
389 /// forward declaration
392 /** This class represents a single line of objects to be displayed.
393 It knows its height and total size and whether it needs to be
395 It has pointers to its first and next line so it can automatically
396 update them as needed.
402 @param prev pointer to previous line or NULL
403 @param next pointer to following line or NULL
404 @param llist pointer to layout list
406 wxLayoutLine(wxLayoutLine
*prev
, wxLayoutList
*llist
);
407 /** This function inserts a new object at cursor position xpos.
408 @param xpos where to insert new object
409 @param obj the object to insert
410 @return true if that xpos existed and the object was inserted
412 bool Insert(CoordType xpos
, wxLayoutObject
*obj
);
414 /** This function inserts text at cursor position xpos.
415 @param xpos where to insert
416 @param text the text to insert
417 @return true if that xpos existed and the object was inserted
419 bool Insert(CoordType xpos
, wxString text
);
421 /** This function appends an object to the line.
422 @param obj the object to insert
424 void Append(wxLayoutObject
* obj
)
427 m_ObjectList
.push_back(obj
);
428 m_Length
+= obj
->GetLength();
431 /** This function appens the next line to this, i.e. joins the two
434 void MergeNextLine(wxLayoutList
*llist
);
436 /** This function deletes npos cursor positions from position xpos.
437 @param xpos where to delete
438 @param npos how many positions
439 @return number of positions still to be deleted
441 CoordType
Delete(CoordType xpos
, CoordType npos
);
443 /** This function breaks the line at a given cursor position.
444 @param xpos where to break it
445 @return pointer to the new line object replacing the old one
447 wxLayoutLine
*Break(CoordType xpos
, wxLayoutList
*llist
);
449 /** Deletes the next word from this position, including leading
451 This function does not delete over font changes, i.e. a word
452 with formatting instructions in the middle of it is treated as
453 two (three actually!) words. In fact, if the cursor is on a non-text object, that
454 one is treated as a word.
455 @param xpos from where to delete
456 @return true if a word was deleted
458 bool DeleteWord(CoordType npos
);
460 /** Finds a suitable position left to the given column to break the
462 @param column we want to break the line to the left of this
463 @return column for breaking line or -1 if no suitable location found
465 CoordType
GetWrapPosition(CoordType column
);
467 /** Finds the object which covers the cursor position xpos in this
469 @param xpos the column number
470 @param offset where to store the difference between xpos and
472 @return iterator to the object or NULLIT
474 wxLayoutObjectList::iterator
FindObject(CoordType xpos
, CoordType
477 /** Finds the object which covers the screen position xpos in this
479 @param dc the wxDC to use for calculations
480 @param xpos the screen x coordinate
481 @param offset where to store the difference between xpos and
483 @return iterator to the object or NULLIT
485 wxLayoutObjectList::iterator
FindObjectScreen(wxDC
&dc
,
488 bool *found
= NULL
) const ;
490 /** Finds text in this line.
491 @param needle the text to find
492 @param xpos the position where to start the search
493 @return the cursoor coord where it was found or -1
495 CoordType
FindText(const wxString
&needle
, CoordType xpos
= 0) const;
497 /** Get the first object in the list. This is used by the wxlparser
498 functions to export the list.
499 @return iterator to the first object
501 wxLayoutObjectList::iterator
GetFirstObject(void)
503 return m_ObjectList
.begin();
506 /** Deletes this line, returns pointer to next line.
507 @param update If true, update all following lines.
509 wxLayoutLine
*DeleteLine(bool update
, wxLayoutList
*llist
);
511 /**@name Cursor Management */
513 /** Return the line number of this line.
514 @return the line number
516 inline CoordType
GetLineNumber(void) const { return m_LineNumber
; }
517 /** Return the length of the line.
518 @return line lenght in cursor positions
520 inline CoordType
GetLength(void) const { return m_Length
; }
523 /**@name Drawing and Layout */
525 /** Draws the line on a wxDC.
526 @param dc the wxDC to draw on
527 @param llist the wxLayoutList
528 @param offset an optional offset to shift printout
532 const wxPoint
&offset
= wxPoint(0,0)) const;
534 /** Recalculates the positions of objects and the height of the
536 @param dc the wxDC to draw on
537 @param llist th e wxLayoutList
538 @param cursorPos if not NULL, set cursor screen position in there
539 @param cursorSize if not cursorPos != NULL, set cursor size in there
540 @param cx if cursorPos != NULL, the cursor x position
542 void Layout(wxDC
&dc
,
544 wxPoint
*cursorPos
= NULL
,
545 wxPoint
*cursorSize
= NULL
,
547 /** This function finds an object belonging to a given cursor
548 position. It assumes that Layout() has been called before.
549 @param dc the wxDC to use for calculations
550 @param xpos screen x position
551 @param found if non-NULL set to false if we return the last
552 object before the cursor, to true if we really have an object
554 @return pointer to the object
556 wxLayoutObject
* FindObjectScreen(wxDC
&dc
, CoordType xpos
, bool
561 /**@name List traversal */
563 /// Returns pointer to next line.
564 wxLayoutLine
*GetNextLine(void) const { return m_Next
; }
565 /// Returns pointer to previous line.
566 wxLayoutLine
*GetPreviousLine(void) const { return m_Previous
; }
567 /// Sets the link to the next line.
568 void SetNext(wxLayoutLine
*next
)
569 { m_Next
= next
; if(next
) next
->m_Previous
= this; }
570 /// Sets the link to the previous line.
571 void SetPrevious(wxLayoutLine
*previous
)
572 { m_Previous
= previous
; if(previous
) previous
->m_Next
= this; }
575 /// Returns the position of this line on the canvas.
576 wxPoint
GetPosition(void) const { return m_Position
; }
577 /// Returns the height of this line.
578 CoordType
GetHeight(void) const { return m_Height
; }
579 /// Returns the width of this line.
580 CoordType
GetWidth(void) const { return m_Width
; }
581 /** This will recalculate the position and size of this line.
582 If called recursively it will abort if the position of an
583 object is unchanged, assuming that none of the following
584 objects need to move.
585 @param recurse if greater 0 then it will be used as the
586 minimum(!) recursion level, continue with all lines till the end of
587 the list or until the coordinates no longer changed.
589 void RecalculatePositions(int recurse
, wxLayoutList
*llist
);
590 /// Recalculates the position of this line on the canvas.
591 wxPoint
RecalculatePosition(wxLayoutList
*llist
);
593 /** Copies the contents of this line to another wxLayoutList
594 @param llist the wxLayoutList destination
595 @param from x cursor coordinate where to start
596 @param to x cursor coordinate where to stop, -1 for end of line
598 void Copy(wxLayoutList
*llist
,
602 #ifdef WXLAYOUT_DEBUG
605 wxLayoutStyleInfo
&GetStyleInfo() { return m_StyleInfo
; }
607 /// Returns dirty state
608 bool IsDirty(void) const { return m_Dirty
; }
610 /// Destructor is private. Use DeleteLine() to remove it.
613 /**@name Functions to let the lines synchronise with each other. */
615 /** Sets the height of this line. Will mark following lines as
617 @param height new height
619 void SetHeight(CoordType height
, wxLayoutList
*llist
)
620 { m_Height
= height
; RecalculatePositions(true, llist
); }
622 /** Moves the linenumbers one on, because a line has been inserted
624 @param delta either +1 or -1
626 void MoveLines(int delta
)
628 m_LineNumber
+= delta
;
629 if(m_Next
) m_Next
->MoveLines(delta
);
634 CoordType m_LineNumber
;
635 /// The line length in cursor positions.
637 /// The total height of the line.
639 /// The total width of the line on screen.
641 /// The baseline for drawing objects
642 CoordType m_BaseLine
;
643 /// The position on the canvas.
645 /// The list of objects
646 wxLayoutObjectList m_ObjectList
;
647 /// Have we been changed since the last layout?
649 /// Pointer to previous line if it exists.
650 wxLayoutLine
*m_Previous
;
651 /// Pointer to next line if it exists.
652 wxLayoutLine
*m_Next
;
653 /// A StyleInfo structure, holding the current settings.
654 wxLayoutStyleInfo m_StyleInfo
;
655 /// Just to suppress gcc compiler warnings.
658 wxLayoutLine(const wxLayoutLine
&);
662 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
664 The wxLayoutList object
666 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
667 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
668 higher level of abstraction for the text and can generally be considered
669 as representing "the text".
680 void Clear(int family
= wxROMAN
,
681 int size
=WXLO_DEFAULTFONTSIZE
,
687 /// Empty: clear the list but leave font settings.
690 /**@name Cursor Management */
692 /** Set new cursor position.
693 @param p new position
694 @return bool if it could be set
696 bool MoveCursorTo(wxPoint
const &p
);
697 /** Move cursor up or down.
699 @return bool if it could be moved
701 bool MoveCursorVertically(int n
);
702 /** Move cursor left or right.
704 @return bool if it could be moved
706 bool MoveCursorHorizontally(int n
);
708 /// Move cursor to end of line.
709 void MoveCursorToEndOfLine(void)
711 wxASSERT(m_CursorLine
);
712 MoveCursorHorizontally(m_CursorLine
->GetLength()-m_CursorPos
.x
);
715 /// Move cursor to begin of line.
716 void MoveCursorToBeginOfLine(void)
717 { MoveCursorHorizontally(-m_CursorPos
.x
); }
719 /// Returns current cursor position.
720 wxPoint
GetCursorPos(wxDC
&dc
) const { return m_CursorPos
; }
721 wxPoint
GetCursorPos() const { return m_CursorPos
; }
725 /**@name Editing functions.
726 All of these functions return true on success and false on
729 /// Insert text at current cursor position.
730 bool Insert(wxString
const &text
);
731 /// Insert some other object at current cursor position.
732 bool Insert(wxLayoutObject
*obj
);
733 /// Inserts a linebreak at current cursor position.
734 bool LineBreak(void);
735 /** Wraps the current line. Searches to the left of the cursor to
736 break the line. Does nothing if the cursor position is before
737 the break position parameter.
738 @param column the break position for the line, maximum length
739 @return true if line got broken
741 bool WrapLine(CoordType column
);
742 /** This function deletes npos cursor positions.
743 @param npos how many positions
744 @return true if everything got deleted
746 bool Delete(CoordType npos
);
748 /** Delete the next n lines.
749 @param n how many lines to delete
750 @return how many it could not delete
752 int DeleteLines(int n
);
754 /// Delete to end of line.
755 void DeleteToEndOfLine(void)
757 wxASSERT(m_CursorLine
);
758 Delete(m_CursorLine
->GetLength()-m_CursorPos
.x
);
760 /// Delete to begin of line.
761 void DeleteToBeginOfLine(void)
763 wxASSERT(m_CursorLine
);
764 CoordType n
= m_CursorPos
.x
;
765 #ifdef WXLAYOUT_DEBUG
766 wxASSERT(MoveCursorHorizontally(-n
));
768 MoveCursorHorizontally(-n
);
773 /** Delete the next word.
775 void DeleteWord(void)
777 wxASSERT(m_CursorLine
);
778 m_CursorLine
->DeleteWord(m_CursorPos
.x
);
783 /** Finds text in this list.
784 @param needle the text to find
785 @param cpos the position where to start the search
786 @return the cursoor coord where it was found or (-1,-1)
788 wxPoint
FindText(const wxString
&needle
, const wxPoint
&cpos
= wxPoint(0,0)) const;
790 /**@name Formatting options */
792 /// sets font parameters
793 void SetFont(int family
, int size
, int style
,
794 int weight
, int underline
,
797 /// sets font parameters, colours by name
798 void SetFont(int family
=-1, int size
= -1, int style
=-1,
799 int weight
=-1, int underline
= -1,
800 char const *fg
= NULL
,
801 char const *bg
= NULL
);
802 /// changes to the next larger font size
803 inline void SetFontLarger(void)
804 { SetFont(-1,(12*m_CurrentSetting
.size
)/10); }
805 /// changes to the next smaller font size
806 inline void SetFontSmaller(void)
807 { SetFont(-1,(10*m_CurrentSetting
.size
)/12); }
810 inline void SetFontFamily(int family
) { SetFont(family
); }
812 inline void SetFontSize(int size
) { SetFont(-1,size
); }
814 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
816 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
817 /// toggle underline flag
818 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
819 /// set font colours by name
820 inline void SetFontColour(char const *fg
, char const *bg
= NULL
)
821 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
822 /// set font colours by colour
823 inline void SetFontColour(wxColour
*fg
, wxColour
*bg
= NULL
)
824 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
828 Returns a pointer to the default settings.
829 This is only valid temporarily and should not be stored
831 @return the default settings of the list
833 wxLayoutStyleInfo
*GetDefaults(void) { return &m_DefaultSetting
; }
834 wxLayoutStyleInfo
*GetStyleInfo(void) { return &m_CurrentSetting
; }
839 /** Draws the complete list on a wxDC.
840 @param dc the wxDC to draw on
841 @param offset an optional offset to shift printout
842 @param top optional y coordinate where to start drawing
843 @param bottom optional y coordinate where to stop drawing
846 const wxPoint
&offset
= wxPoint(0,0),
847 CoordType top
= -1, CoordType bottom
= -1);
849 /** Calculates new layout for the list, like Draw() but does not
851 @param dc the wxDC to draw on
852 @param bottom optional y coordinate where to stop calculating
853 @param forceAll force re-layout of all lines
855 void Layout(wxDC
&dc
, CoordType bottom
= -1, bool forceAll
= false);
857 /** Calculates new sizes for everything in the list, like Layout()
858 but this is needed after the list got changed.
859 @param dc the wxDC to draw on
860 @param bottom optional y coordinate where to stop calculating
862 void Recalculate(wxDC
&dc
, CoordType bottom
= -1);
864 /** Returns the size of the list in screen coordinates.
865 The return value only makes sense after the list has been
867 @return a wxPoint holding the maximal x/y coordinates used for
870 wxPoint
GetSize(void) const;
872 /** Returns the cursor position on the screen.
873 @return cursor position in pixels
875 wxPoint
GetCursorScreenPos(wxDC
&dc
);
877 /** Draws the cursor.
878 @param active If true, draw a bold cursor to mark window as
880 @param translate optional translation of cursor coords on screen
882 void DrawCursor(wxDC
&dc
,
884 const wxPoint
& translate
= wxPoint(0,0));
886 /** This function finds an object belonging to a given screen
887 position. It assumes that Layout() has been called before.
888 @param pos screen position
889 @param cursorPos if non NULL, store cursor position in there
890 @param found if used, set this to true if we really found an
891 object, to false if we had to take the object near to it
892 @return pointer to the object
894 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
896 wxPoint
*cursorPos
= NULL
,
899 /** Called by the objects to update the update rectangle.
900 @param x horizontal coordinate to include in rectangle
901 @param y vertical coordinate to include in rectangle
903 void SetUpdateRect(CoordType x
, CoordType y
);
904 /** Called by the objects to update the update rectangle.
905 @param p a point to include in it
907 inline void SetUpdateRect(const wxPoint
&p
)
908 { SetUpdateRect(p
.x
,p
.y
); }
909 /// Invalidates the update rectangle.
910 void InvalidateUpdateRect(void) { m_UpdateRectValid
= false; }
911 /// Returns the update rectangle.
912 const wxRect
*GetUpdateRect(void) const { return &m_UpdateRect
; }
915 /**@name For exporting one object after another. */
917 /** Returns a pointer to the first line in the list. */
918 wxLayoutLine
*GetFirstLine(void)
920 wxASSERT(m_FirstLine
);
925 /// Begin selecting text.
926 void StartSelection(void);
927 // Continue selecting text
928 void ContinueSelection(void);
929 /// End selecting text.
930 void EndSelection(void);
931 /// Are we still selecting text?
932 bool IsSelecting(void);
933 bool IsSelected(const wxPoint
&cursor
);
935 /// Return the selection as a wxLayoutList:
936 wxLayoutList
*GetSelection(void);
937 /// Delete selected bit
938 void DeleteSelection(void);
940 wxLayoutList
*Copy(const wxPoint
&from
= wxPoint(0,0),
941 const wxPoint
&to
= wxPoint(-1,-1));
943 /// starts highlighting of text for selections
944 void StartHighlighting(wxDC
&dc
);
945 /// ends highlighting of text for selections
946 void EndHighlighting(wxDC
&dc
);
948 /** Tests whether this layout line is selected and needs
950 @param line to test for
951 @param from set to first cursorpos to be highlighted (for returncode == -1)
952 @param to set to last cursorpos to be highlighted (for returncode == -1)
953 @return 0 = not selected, 1 = fully selected, -1 = partially
957 int IsSelected(const wxLayoutLine
*line
, CoordType
*from
, CoordType
*to
);
959 void ApplyStyle(wxLayoutStyleInfo
*si
, wxDC
&dc
);
960 #ifdef WXLAYOUT_DEBUG
965 void InternalClear(void);
966 /** Calculates the cursor position on the screen.
968 void UpdateCursorScreenPos(wxDC
&dc
);
970 /// The list of lines.
971 wxLayoutLine
*m_FirstLine
;
972 /// The update rectangle which needs to be refreshed:
974 /// Is the update rectangle valid?
975 bool m_UpdateRectValid
;
976 /**@name Cursor Management */
978 /// Where the text cursor (column,line) is.
980 /// The size of the cursor.
981 wxPoint m_CursorSize
;
982 /// Where the cursor should be drawn.
983 wxPoint m_CursorScreenPos
;
984 /// The line where the cursor is.
985 wxLayoutLine
*m_CursorLine
;
988 /// A structure for the selection.
991 Selection() { m_valid
= false; m_selecting
= false; }
994 wxPoint m_CursorA
, m_CursorB
;
996 /** @name Font parameters. */
998 /// this object manages the fonts for us
999 wxFontCache m_FontCache
;
1000 /// the default setting:
1001 wxLayoutStyleInfo m_DefaultSetting
;
1002 /// the current setting:
1003 wxLayoutStyleInfo m_CurrentSetting
;
1010 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1012 The wxLayoutPrintout object for printing within the wxWindows print
1015 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1016 /** This class implements a wxPrintout for printing a wxLayoutList within
1017 the wxWindows printing framework.
1019 class wxLayoutPrintout
: public wxPrintout
1023 @param llist pointer to the wxLayoutList to be printed
1024 @param title title for PS file or windows
1026 wxLayoutPrintout(wxLayoutList
*llist
,
1027 wxString
const & title
=
1028 "wxLayout Printout");
1030 ~wxLayoutPrintout();
1032 /** Function which prints the n-th page.
1033 @param page the page number to print
1034 @return bool true if we are not at end of document yet
1036 bool OnPrintPage(int page
);
1037 /** Checks whether page exists in document.
1038 @param page number of page
1039 @return true if page exists
1041 bool HasPage(int page
);
1043 /** Gets called from wxWindows to find out which pages are existing.
1044 I'm not totally sure about the parameters though.
1045 @param minPage the first page in the document
1046 @param maxPage the last page in the document
1047 @param selPageFrom the first page to be printed
1048 @param selPageTo the last page to be printed
1050 void GetPageInfo(int *minPage
, int *maxPage
,
1051 int *selPageFrom
, int *selPageTo
);
1053 /** This little function scales the DC so that the printout has
1054 roughly the same size as the output on screen.
1055 @param dc the wxDC to scale
1056 @return the scale that was applied
1058 float ScaleDC(wxDC
*dc
);
1061 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1064 /// The list to print.
1065 wxLayoutList
*m_llist
;
1066 /// Title for PS file or window.
1068 /// The real paper size.
1069 int m_PageHeight
, m_PageWidth
;
1070 /// How much we actually print per page.
1071 int m_PrintoutHeight
;
1072 /// How many pages we need to print.
1074 /// Top left corner where we start printing.