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
; }
609 /// Marks line as diry.
610 void MarkDirty(void) { m_Dirty
= true; }
612 /// Destructor is private. Use DeleteLine() to remove it.
615 /**@name Functions to let the lines synchronise with each other. */
617 /** Sets the height of this line. Will mark following lines as
619 @param height new height
621 void SetHeight(CoordType height
, wxLayoutList
*llist
)
622 { m_Height
= height
; RecalculatePositions(true, llist
); }
624 /** Moves the linenumbers one on, because a line has been inserted
626 @param delta either +1 or -1
628 void MoveLines(int delta
)
630 m_LineNumber
+= delta
;
631 if(m_Next
) m_Next
->MoveLines(delta
);
636 CoordType m_LineNumber
;
637 /// The line length in cursor positions.
639 /// The total height of the line.
641 /// The total width of the line on screen.
643 /// The baseline for drawing objects
644 CoordType m_BaseLine
;
645 /// The position on the canvas.
647 /// The list of objects
648 wxLayoutObjectList m_ObjectList
;
649 /// Have we been changed since the last layout?
651 /// Pointer to previous line if it exists.
652 wxLayoutLine
*m_Previous
;
653 /// Pointer to next line if it exists.
654 wxLayoutLine
*m_Next
;
655 /// A StyleInfo structure, holding the current settings.
656 wxLayoutStyleInfo m_StyleInfo
;
657 /// Just to suppress gcc compiler warnings.
660 wxLayoutLine(const wxLayoutLine
&);
664 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
666 The wxLayoutList object
668 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
669 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
670 higher level of abstraction for the text and can generally be considered
671 as representing "the text".
682 void Clear(int family
= wxROMAN
,
683 int size
=WXLO_DEFAULTFONTSIZE
,
689 /// Empty: clear the list but leave font settings.
692 /**@name Cursor Management */
694 /** Set new cursor position.
695 @param p new position
696 @return bool if it could be set
698 bool MoveCursorTo(wxPoint
const &p
);
699 /** Move cursor up or down.
701 @return bool if it could be moved
703 bool MoveCursorVertically(int n
);
704 /** Move cursor left or right.
706 @return bool if it could be moved
708 bool MoveCursorHorizontally(int n
);
710 /// Move cursor to end of line.
711 void MoveCursorToEndOfLine(void)
713 wxASSERT(m_CursorLine
);
714 MoveCursorHorizontally(m_CursorLine
->GetLength()-m_CursorPos
.x
);
717 /// Move cursor to begin of line.
718 void MoveCursorToBeginOfLine(void)
719 { MoveCursorHorizontally(-m_CursorPos
.x
); }
721 /// Returns current cursor position.
722 wxPoint
GetCursorPos(wxDC
&dc
) const { return m_CursorPos
; }
723 wxPoint
GetCursorPos() const { return m_CursorPos
; }
727 /**@name Editing functions.
728 All of these functions return true on success and false on
731 /// Insert text at current cursor position.
732 bool Insert(wxString
const &text
);
733 /// Insert some other object at current cursor position.
734 bool Insert(wxLayoutObject
*obj
);
735 /// Inserts a linebreak at current cursor position.
736 bool LineBreak(void);
737 /** Wraps the current line. Searches to the left of the cursor to
738 break the line. Does nothing if the cursor position is before
739 the break position parameter.
740 @param column the break position for the line, maximum length
741 @return true if line got broken
743 bool WrapLine(CoordType column
);
744 /** This function deletes npos cursor positions.
745 @param npos how many positions
746 @return true if everything got deleted
748 bool Delete(CoordType npos
);
750 /** Delete the next n lines.
751 @param n how many lines to delete
752 @return how many it could not delete
754 int DeleteLines(int n
);
756 /// Delete to end of line.
757 void DeleteToEndOfLine(void)
759 wxASSERT(m_CursorLine
);
760 Delete(m_CursorLine
->GetLength()-m_CursorPos
.x
);
762 /// Delete to begin of line.
763 void DeleteToBeginOfLine(void)
765 wxASSERT(m_CursorLine
);
766 CoordType n
= m_CursorPos
.x
;
767 #ifdef WXLAYOUT_DEBUG
768 wxASSERT(MoveCursorHorizontally(-n
));
770 MoveCursorHorizontally(-n
);
775 /** Delete the next word.
777 void DeleteWord(void)
779 wxASSERT(m_CursorLine
);
780 m_CursorLine
->DeleteWord(m_CursorPos
.x
);
785 /** Finds text in this list.
786 @param needle the text to find
787 @param cpos the position where to start the search
788 @return the cursoor coord where it was found or (-1,-1)
790 wxPoint
FindText(const wxString
&needle
, const wxPoint
&cpos
= wxPoint(0,0)) const;
792 /**@name Formatting options */
794 /// sets font parameters
795 void SetFont(int family
, int size
, int style
,
796 int weight
, int underline
,
799 /// sets font parameters, colours by name
800 void SetFont(int family
=-1, int size
= -1, int style
=-1,
801 int weight
=-1, int underline
= -1,
802 char const *fg
= NULL
,
803 char const *bg
= NULL
);
804 /// changes to the next larger font size
805 inline void SetFontLarger(void)
806 { SetFont(-1,(12*m_CurrentSetting
.size
)/10); }
807 /// changes to the next smaller font size
808 inline void SetFontSmaller(void)
809 { SetFont(-1,(10*m_CurrentSetting
.size
)/12); }
812 inline void SetFontFamily(int family
) { SetFont(family
); }
814 inline void SetFontSize(int size
) { SetFont(-1,size
); }
816 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
818 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
819 /// toggle underline flag
820 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
821 /// set font colours by name
822 inline void SetFontColour(char const *fg
, char const *bg
= NULL
)
823 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
824 /// set font colours by colour
825 inline void SetFontColour(wxColour
*fg
, wxColour
*bg
= NULL
)
826 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
830 Returns a pointer to the default settings.
831 This is only valid temporarily and should not be stored
833 @return the default settings of the list
835 wxLayoutStyleInfo
*GetDefaults(void) { return &m_DefaultSetting
; }
836 wxLayoutStyleInfo
*GetStyleInfo(void) { return &m_CurrentSetting
; }
841 /** Draws the complete list on a wxDC.
842 @param dc the wxDC to draw on
843 @param offset an optional offset to shift printout
844 @param top optional y coordinate where to start drawing
845 @param bottom optional y coordinate where to stop drawing
848 const wxPoint
&offset
= wxPoint(0,0),
849 CoordType top
= -1, CoordType bottom
= -1);
851 /** Calculates new layout for the list, like Draw() but does not
853 @param dc the wxDC to draw on
854 @param bottom optional y coordinate where to stop calculating
855 @param forceAll force re-layout of all lines
857 void Layout(wxDC
&dc
, CoordType bottom
= -1, bool forceAll
= false);
859 /** Calculates new sizes for everything in the list, like Layout()
860 but this is needed after the list got changed.
861 @param dc the wxDC to draw on
862 @param bottom optional y coordinate where to stop calculating
864 void Recalculate(wxDC
&dc
, CoordType bottom
= -1);
866 /** Returns the size of the list in screen coordinates.
867 The return value only makes sense after the list has been
869 @return a wxPoint holding the maximal x/y coordinates used for
872 wxPoint
GetSize(void) const;
874 /** Returns the cursor position on the screen.
875 @return cursor position in pixels
877 wxPoint
GetCursorScreenPos(wxDC
&dc
);
879 /** Draws the cursor.
880 @param active If true, draw a bold cursor to mark window as
882 @param translate optional translation of cursor coords on screen
884 void DrawCursor(wxDC
&dc
,
886 const wxPoint
& translate
= wxPoint(0,0));
888 /** This function finds an object belonging to a given screen
889 position. It assumes that Layout() has been called before.
890 @param pos screen position
891 @param cursorPos if non NULL, store cursor position in there
892 @param found if used, set this to true if we really found an
893 object, to false if we had to take the object near to it
894 @return pointer to the object
896 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
898 wxPoint
*cursorPos
= NULL
,
901 /** Called by the objects to update the update rectangle.
902 @param x horizontal coordinate to include in rectangle
903 @param y vertical coordinate to include in rectangle
905 void SetUpdateRect(CoordType x
, CoordType y
);
906 /** Called by the objects to update the update rectangle.
907 @param p a point to include in it
909 inline void SetUpdateRect(const wxPoint
&p
)
910 { SetUpdateRect(p
.x
,p
.y
); }
911 /// Invalidates the update rectangle.
912 void InvalidateUpdateRect(void) { m_UpdateRectValid
= false; }
913 /// Returns the update rectangle.
914 const wxRect
*GetUpdateRect(void) const { return &m_UpdateRect
; }
917 /**@name For exporting one object after another. */
919 /** Returns a pointer to the first line in the list. */
920 wxLayoutLine
*GetFirstLine(void)
922 wxASSERT(m_FirstLine
);
927 /// Begin selecting text.
928 void StartSelection(void);
929 // Continue selecting text
930 void ContinueSelection(void);
931 /// End selecting text.
932 void EndSelection(void);
933 /// Are we still selecting text?
934 bool IsSelecting(void);
935 bool IsSelected(const wxPoint
&cursor
);
937 /// Return the selection as a wxLayoutList:
938 wxLayoutList
*GetSelection(void);
939 /// Delete selected bit
940 void DeleteSelection(void);
942 wxLayoutList
*Copy(const wxPoint
&from
= wxPoint(0,0),
943 const wxPoint
&to
= wxPoint(-1,-1));
945 /// starts highlighting of text for selections
946 void StartHighlighting(wxDC
&dc
);
947 /// ends highlighting of text for selections
948 void EndHighlighting(wxDC
&dc
);
950 /** Tests whether this layout line is selected and needs
952 @param line to test for
953 @param from set to first cursorpos to be highlighted (for returncode == -1)
954 @param to set to last cursorpos to be highlighted (for returncode == -1)
955 @return 0 = not selected, 1 = fully selected, -1 = partially
959 int IsSelected(const wxLayoutLine
*line
, CoordType
*from
, CoordType
*to
);
961 void ApplyStyle(wxLayoutStyleInfo
*si
, wxDC
&dc
);
962 #ifdef WXLAYOUT_DEBUG
967 void InternalClear(void);
968 /** Calculates the cursor position on the screen.
970 void UpdateCursorScreenPos(wxDC
&dc
);
972 /// The list of lines.
973 wxLayoutLine
*m_FirstLine
;
974 /// The update rectangle which needs to be refreshed:
976 /// Is the update rectangle valid?
977 bool m_UpdateRectValid
;
978 /**@name Cursor Management */
980 /// Where the text cursor (column,line) is.
982 /// The size of the cursor.
983 wxPoint m_CursorSize
;
984 /// Where the cursor should be drawn.
985 wxPoint m_CursorScreenPos
;
986 /// The line where the cursor is.
987 wxLayoutLine
*m_CursorLine
;
990 /// A structure for the selection.
993 Selection() { m_valid
= false; m_selecting
= false; }
996 wxPoint m_CursorA
, m_CursorB
;
998 /** @name Font parameters. */
1000 /// this object manages the fonts for us
1001 wxFontCache m_FontCache
;
1002 /// the default setting:
1003 wxLayoutStyleInfo m_DefaultSetting
;
1004 /// the current setting:
1005 wxLayoutStyleInfo m_CurrentSetting
;
1012 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1014 The wxLayoutPrintout object for printing within the wxWindows print
1017 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1018 /** This class implements a wxPrintout for printing a wxLayoutList within
1019 the wxWindows printing framework.
1021 class wxLayoutPrintout
: public wxPrintout
1025 @param llist pointer to the wxLayoutList to be printed
1026 @param title title for PS file or windows
1028 wxLayoutPrintout(wxLayoutList
*llist
,
1029 wxString
const & title
=
1030 "wxLayout Printout");
1032 ~wxLayoutPrintout();
1034 /** Function which prints the n-th page.
1035 @param page the page number to print
1036 @return bool true if we are not at end of document yet
1038 bool OnPrintPage(int page
);
1039 /** Checks whether page exists in document.
1040 @param page number of page
1041 @return true if page exists
1043 bool HasPage(int page
);
1045 /** Gets called from wxWindows to find out which pages are existing.
1046 I'm not totally sure about the parameters though.
1047 @param minPage the first page in the document
1048 @param maxPage the last page in the document
1049 @param selPageFrom the first page to be printed
1050 @param selPageTo the last page to be printed
1052 void GetPageInfo(int *minPage
, int *maxPage
,
1053 int *selPageFrom
, int *selPageTo
);
1055 /** This little function scales the DC so that the printout has
1056 roughly the same size as the output on screen.
1057 @param dc the wxDC to scale
1058 @return the scale that was applied
1060 float ScaleDC(wxDC
*dc
);
1063 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1066 /// The list to print.
1067 wxLayoutList
*m_llist
;
1068 /// Title for PS file or window.
1070 /// The real paper size.
1071 int m_PageHeight
, m_PageWidth
;
1072 /// How much we actually print per page.
1073 int m_PrintoutHeight
;
1074 /// How many pages we need to print.
1076 /// Top left corner where we start printing.