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() const
295 return fg_valid
? new
296 wxColour(bg_red
,bg_green
,bg_blue
)
299 wxFont
*GetFont(wxLayoutStyleInfo
*);
300 /// Font change parameters.
301 int size
, family
, style
, weight
, underline
;
302 /// Is foreground colour valid to bet set?
304 /// Is background colour valid to bet set?
306 /// Foreground colour RGB values.
307 unsigned fg_red
, fg_green
, fg_blue
;
308 /// Background colour RGB values.
309 unsigned bg_red
, bg_green
, bg_blue
;
312 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
316 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
317 /** This class implements a wxLayoutObject holding style change commands.
319 class wxLayoutObjectCmd
: public wxLayoutObject
322 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
323 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
);
324 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
325 class wxLayoutList
*wxllist
,
326 CoordType begin
= -1,
328 wxLayoutObjectCmd(int size
= -1,
334 wxColour
*bg
= NULL
);
335 ~wxLayoutObjectCmd();
336 /** Stores the current style in the styleinfo structure */
337 wxLayoutStyleInfo
* GetStyle(void) const;
338 /** Makes a copy of this object.
340 virtual wxLayoutObject
*Copy(void);
344 wxLayoutStyleInfo
*m_StyleInfo
;
347 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
349 The wxLayoutLine object
351 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
353 /// forward declaration
356 /** This class represents a single line of objects to be displayed.
357 It knows its height and total size and whether it needs to be
359 It has pointers to its first and next line so it can automatically
360 update them as needed.
366 @param prev pointer to previous line or NULL
367 @param next pointer to following line or NULL
368 @param llist pointer to layout list
370 wxLayoutLine(wxLayoutLine
*prev
, wxLayoutList
*llist
);
371 /** This function inserts a new object at cursor position xpos.
372 @param xpos where to insert new object
373 @param obj the object to insert
374 @return true if that xpos existed and the object was inserted
376 bool Insert(CoordType xpos
, wxLayoutObject
*obj
);
378 /** This function inserts text at cursor position xpos.
379 @param xpos where to insert
380 @param text the text to insert
381 @return true if that xpos existed and the object was inserted
383 bool Insert(CoordType xpos
, wxString text
);
385 /** This function appends an object to the line.
386 @param obj the object to insert
388 void Append(wxLayoutObject
* obj
)
391 m_ObjectList
.push_back(obj
);
392 m_Length
+= obj
->GetLength();
395 /** This function appens the next line to this, i.e. joins the two
398 void MergeNextLine(wxLayoutList
*llist
);
400 /** This function deletes npos cursor positions from position xpos.
401 @param xpos where to delete
402 @param npos how many positions
403 @return number of positions still to be deleted
405 CoordType
Delete(CoordType xpos
, CoordType npos
);
407 /** This function breaks the line at a given cursor position.
408 @param xpos where to break it
409 @return pointer to the new line object replacing the old one
411 wxLayoutLine
*Break(CoordType xpos
, wxLayoutList
*llist
);
413 /** Deletes the next word from this position, including leading
415 This function does not delete over font changes, i.e. a word
416 with formatting instructions in the middle of it is treated as
417 two (three actually!) words. In fact, if the cursor is on a non-text object, that
418 one is treated as a word.
419 @param xpos from where to delete
420 @return true if a word was deleted
422 bool DeleteWord(CoordType npos
);
424 /** Finds a suitable position left to the given column to break the
426 @param column we want to break the line to the left of this
427 @return column for breaking line or -1 if no suitable location found
429 CoordType
GetWrapPosition(CoordType column
);
431 /** Finds the object which covers the cursor position xpos in this
433 @param xpos the column number
434 @param offset where to store the difference between xpos and
436 @return iterator to the object or NULLIT
438 wxLayoutObjectList::iterator
FindObject(CoordType xpos
, CoordType
441 /** Finds the object which covers the screen position xpos in this
443 @param dc the wxDC to use for calculations
444 @param xpos the screen x coordinate
445 @param offset where to store the difference between xpos and
447 @return iterator to the object or NULLIT
449 wxLayoutObjectList::iterator
FindObjectScreen(wxDC
&dc
,
452 bool *found
= NULL
) const ;
454 /** Finds text in this line.
455 @param needle the text to find
456 @param xpos the position where to start the search
457 @return the cursoor coord where it was found or -1
459 CoordType
FindText(const wxString
&needle
, CoordType xpos
= 0) const;
461 /** Get the first object in the list. This is used by the wxlparser
462 functions to export the list.
463 @return iterator to the first object
465 wxLayoutObjectList::iterator
GetFirstObject(void)
467 return m_ObjectList
.begin();
470 /** Deletes this line, returns pointer to next line.
471 @param update If true, update all following lines.
473 wxLayoutLine
*DeleteLine(bool update
, wxLayoutList
*llist
);
475 /**@name Cursor Management */
477 /** Return the line number of this line.
478 @return the line number
480 inline CoordType
GetLineNumber(void) const { return m_LineNumber
; }
481 /** Return the length of the line.
482 @return line lenght in cursor positions
484 inline CoordType
GetLength(void) const { return m_Length
; }
487 /**@name Drawing and Layout */
489 /** Draws the line on a wxDC.
490 @param dc the wxDC to draw on
491 @param llist the wxLayoutList
492 @param offset an optional offset to shift printout
496 const wxPoint
&offset
= wxPoint(0,0)) const;
498 /** Recalculates the positions of objects and the height of the
500 @param dc the wxDC to draw on
501 @param llist th e wxLayoutList
502 @param cursorPos if not NULL, set cursor screen position in there
503 @param cursorSize if not cursorPos != NULL, set cursor size in there
504 @param cx if cursorPos != NULL, the cursor x position
506 void Layout(wxDC
&dc
,
508 wxPoint
*cursorPos
= NULL
,
509 wxPoint
*cursorSize
= NULL
,
511 /** This function finds an object belonging to a given cursor
512 position. It assumes that Layout() has been called before.
513 @param dc the wxDC to use for calculations
514 @param xpos screen x position
515 @param found if non-NULL set to false if we return the last
516 object before the cursor, to true if we really have an object
518 @return pointer to the object
520 wxLayoutObject
* FindObjectScreen(wxDC
&dc
, CoordType xpos
, bool
525 /**@name List traversal */
527 /// Returns pointer to next line.
528 wxLayoutLine
*GetNextLine(void) const { return m_Next
; }
529 /// Returns pointer to previous line.
530 wxLayoutLine
*GetPreviousLine(void) const { return m_Previous
; }
531 /// Sets the link to the next line.
532 void SetNext(wxLayoutLine
*next
)
533 { m_Next
= next
; if(next
) next
->m_Previous
= this; }
534 /// Sets the link to the previous line.
535 void SetPrevious(wxLayoutLine
*previous
)
536 { m_Previous
= previous
; if(previous
) previous
->m_Next
= this; }
539 /// Returns the position of this line on the canvas.
540 wxPoint
GetPosition(void) const { return m_Position
; }
541 /// Returns the height of this line.
542 CoordType
GetHeight(void) const { return m_Height
; }
543 /// Returns the width of this line.
544 CoordType
GetWidth(void) const { return m_Width
; }
545 /** This will recalculate the position and size of this line.
546 If called recursively it will abort if the position of an
547 object is unchanged, assuming that none of the following
548 objects need to move.
549 @param recurse if greater 0 then it will be used as the
550 minimum(!) recursion level, continue with all lines till the end of
551 the list or until the coordinates no longer changed.
553 void RecalculatePositions(int recurse
, wxLayoutList
*llist
);
554 /// Recalculates the position of this line on the canvas.
555 wxPoint
RecalculatePosition(wxLayoutList
*llist
);
557 /** Copies the contents of this line to another wxLayoutList
558 @param llist the wxLayoutList destination
559 @param from x cursor coordinate where to start
560 @param to x cursor coordinate where to stop, -1 for end of line
562 void Copy(wxLayoutList
*llist
,
566 #ifdef WXLAYOUT_DEBUG
571 /// Destructor is private. Use DeleteLine() to remove it.
574 /**@name Functions to let the lines synchronise with each other. */
576 /** Sets the height of this line. Will mark following lines as
578 @param height new height
580 void SetHeight(CoordType height
, wxLayoutList
*llist
)
581 { m_Height
= height
; RecalculatePositions(true, llist
); }
583 /** Moves the linenumbers one on, because a line has been inserted
585 @param delta either +1 or -1
587 void MoveLines(int delta
)
589 m_LineNumber
+= delta
;
590 if(m_Next
) m_Next
->MoveLines(delta
);
595 CoordType m_LineNumber
;
596 /// The line length in cursor positions.
598 /// The total height of the line.
600 /// The total width of the line on screen.
602 /// The baseline for drawing objects
603 CoordType m_BaseLine
;
604 /// The position on the canvas.
606 /// The list of objects
607 wxLayoutObjectList m_ObjectList
;
608 /// Have we been changed since the last layout?
610 /// Pointer to previous line if it exists.
611 wxLayoutLine
*m_Previous
;
612 /// Pointer to next line if it exists.
613 wxLayoutLine
*m_Next
;
614 /// Just to suppress gcc compiler warnings.
617 wxLayoutLine(const wxLayoutLine
&);
621 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
623 The wxLayoutList object
625 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
626 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
627 higher level of abstraction for the text and can generally be considered
628 as representing "the text".
639 void Clear(int family
= wxROMAN
,
640 int size
=WXLO_DEFAULTFONTSIZE
,
646 /// Empty: clear the list but leave font settings.
649 /**@name Cursor Management */
651 /** Set new cursor position.
652 @param p new position
653 @return bool if it could be set
655 bool MoveCursorTo(wxPoint
const &p
);
656 /** Move cursor up or down.
658 @return bool if it could be moved
660 bool MoveCursorVertically(int n
);
661 /** Move cursor left or right.
663 @return bool if it could be moved
665 bool MoveCursorHorizontally(int n
);
667 /// Move cursor to end of line.
668 void MoveCursorToEndOfLine(void)
670 wxASSERT(m_CursorLine
);
671 MoveCursorHorizontally(m_CursorLine
->GetLength()-m_CursorPos
.x
);
674 /// Move cursor to begin of line.
675 void MoveCursorToBeginOfLine(void)
676 { MoveCursorHorizontally(-m_CursorPos
.x
); }
678 /// Returns current cursor position.
679 wxPoint
GetCursorPos(wxDC
&dc
) const { return m_CursorPos
; }
680 wxPoint
GetCursorPos() const { return m_CursorPos
; }
684 /**@name Editing functions.
685 All of these functions return true on success and false on
688 /// Insert text at current cursor position.
689 bool Insert(wxString
const &text
);
690 /// Insert some other object at current cursor position.
691 bool Insert(wxLayoutObject
*obj
);
692 /// Inserts a linebreak at current cursor position.
693 bool LineBreak(void);
694 /** Wraps the current line. Searches to the left of the cursor to
695 break the line. Does nothing if the cursor position is before
696 the break position parameter.
697 @param column the break position for the line, maximum length
698 @return true if line got broken
700 bool WrapLine(CoordType column
);
701 /** This function deletes npos cursor positions.
702 @param npos how many positions
703 @return true if everything got deleted
705 bool Delete(CoordType npos
);
707 /** Delete the next n lines.
708 @param n how many lines to delete
709 @return how many it could not delete
711 int DeleteLines(int n
);
713 /// Delete to end of line.
714 void DeleteToEndOfLine(void)
716 wxASSERT(m_CursorLine
);
717 Delete(m_CursorLine
->GetLength()-m_CursorPos
.x
);
719 /// Delete to begin of line.
720 void DeleteToBeginOfLine(void)
722 wxASSERT(m_CursorLine
);
723 CoordType n
= m_CursorPos
.x
;
724 #ifdef WXLAYOUT_DEBUG
725 wxASSERT(MoveCursorHorizontally(-n
));
727 MoveCursorHorizontally(-n
);
732 /** Delete the next word.
734 void DeleteWord(void)
736 wxASSERT(m_CursorLine
);
737 m_CursorLine
->DeleteWord(m_CursorPos
.x
);
742 /** Finds text in this list.
743 @param needle the text to find
744 @param cpos the position where to start the search
745 @return the cursoor coord where it was found or (-1,-1)
747 wxPoint
FindText(const wxString
&needle
, const wxPoint
&cpos
= wxPoint(0,0)) const;
749 /**@name Formatting options */
751 /// sets font parameters
752 void SetFont(int family
, int size
, int style
,
753 int weight
, int underline
,
756 /// sets font parameters, colours by name
757 void SetFont(int family
=-1, int size
= -1, int style
=-1,
758 int weight
=-1, int underline
= -1,
759 char const *fg
= NULL
,
760 char const *bg
= NULL
);
761 /// changes to the next larger font size
762 inline void SetFontLarger(void)
763 { SetFont(-1,(12*m_FontPtSize
)/10); }
764 /// changes to the next smaller font size
765 inline void SetFontSmaller(void)
766 { SetFont(-1,(10*m_FontPtSize
)/12); }
769 inline void SetFontFamily(int family
) { SetFont(family
); }
771 inline void SetFontSize(int size
) { SetFont(-1,size
); }
773 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
775 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
776 /// toggle underline flag
777 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
778 /// set font colours by name
779 inline void SetFontColour(char const *fg
, char const *bg
= NULL
)
780 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
781 /// set font colours by colour
782 inline void SetFontColour(wxColour
*fg
, wxColour
*bg
= NULL
)
783 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
787 Returns a pointer to the default settings.
788 This is only valid temporarily and should not be stored
790 @return the default settings of the list
792 wxLayoutStyleInfo
*GetDefaults(void) { return m_DefaultSetting
; }
797 /** Draws the complete list on a wxDC.
798 @param dc the wxDC to draw on
799 @param offset an optional offset to shift printout
800 @param top optional y coordinate where to start drawing
801 @param bottom optional y coordinate where to stop drawing
804 const wxPoint
&offset
= wxPoint(0,0),
805 CoordType top
= -1, CoordType bottom
= -1);
807 /** Calculates new layout for the list, like Draw() but does not
809 @param dc the wxDC to draw on
810 @param bottom optional y coordinate where to stop calculating
812 void Layout(wxDC
&dc
, CoordType bottom
= -1);
814 /** Calculates new sizes for everything in the list, like Layout()
815 but this is needed after the list got changed.
816 @param dc the wxDC to draw on
817 @param bottom optional y coordinate where to stop calculating
819 void Recalculate(wxDC
&dc
, CoordType bottom
= -1);
821 /** Returns the size of the list in screen coordinates.
822 The return value only makes sense after the list has been
824 @return a wxPoint holding the maximal x/y coordinates used for
827 wxPoint
GetSize(void) const;
829 /** Returns the cursor position on the screen.
830 @return cursor position in pixels
832 wxPoint
GetCursorScreenPos(wxDC
&dc
);
834 /** Draws the cursor.
835 @param active If true, draw a bold cursor to mark window as
837 @param translate optional translation of cursor coords on screen
839 void DrawCursor(wxDC
&dc
,
841 const wxPoint
& translate
= wxPoint(0,0));
843 /** This function finds an object belonging to a given screen
844 position. It assumes that Layout() has been called before.
845 @param pos screen position
846 @param cursorPos if non NULL, store cursor position in there
847 @param found if used, set this to true if we really found an
848 object, to false if we had to take the object near to it
849 @return pointer to the object
851 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
853 wxPoint
*cursorPos
= NULL
,
856 /** Called by the objects to update the update rectangle.
857 @param x horizontal coordinate to include in rectangle
858 @param y vertical coordinate to include in rectangle
860 void SetUpdateRect(CoordType x
, CoordType y
);
861 /** Called by the objects to update the update rectangle.
862 @param p a point to include in it
864 inline void SetUpdateRect(const wxPoint
&p
)
865 { SetUpdateRect(p
.x
,p
.y
); }
866 /// Invalidates the update rectangle.
867 void InvalidateUpdateRect(void) { m_UpdateRectValid
= false; }
868 /// Returns the update rectangle.
869 const wxRect
*GetUpdateRect(void) const { return &m_UpdateRect
; }
872 /**@name For exporting one object after another. */
874 /** Returns a pointer to the first line in the list. */
875 wxLayoutLine
*GetFirstLine(void)
877 wxASSERT(m_FirstLine
);
882 /// Begin selecting text.
883 void StartSelection(void);
884 // Continue selecting text
885 void ContinueSelection(void);
886 /// End selecting text.
887 void EndSelection(void);
888 /// Are we still selecting text?
889 bool IsSelecting(void);
890 bool IsSelected(const wxPoint
&cursor
);
892 /// Return the selection as a wxLayoutList:
893 wxLayoutList
*GetSelection(void);
894 /// Delete selected bit
895 void DeleteSelection(void);
897 wxLayoutList
*Copy(const wxPoint
&from
= wxPoint(0,0),
898 const wxPoint
&to
= wxPoint(-1,-1));
900 /// starts highlighting of text for selections
901 void StartHighlighting(wxDC
&dc
);
902 /// ends highlighting of text for selections
903 void EndHighlighting(wxDC
&dc
);
905 /** Tests whether this layout line is selected and needs
907 @param line to test for
908 @param from set to first cursorpos to be highlighted (for returncode == -1)
909 @param to set to last cursorpos to be highlighted (for returncode == -1)
910 @return 0 = not selected, 1 = fully selected, -1 = partially
914 int IsSelected(const wxLayoutLine
*line
, CoordType
*from
, CoordType
*to
);
917 void ApplyStyle(wxLayoutStyleInfo
*si
, wxDC
&dc
);
918 #ifdef WXLAYOUT_DEBUG
923 void InternalClear(void);
924 /** Calculates the cursor position on the screen.
926 void UpdateCursorScreenPos(wxDC
&dc
);
928 /// The list of lines.
929 wxLayoutLine
*m_FirstLine
;
930 /// The update rectangle which needs to be refreshed:
932 /// Is the update rectangle valid?
933 bool m_UpdateRectValid
;
934 /**@name Cursor Management */
936 /// Where the text cursor (column,line) is.
938 /// The size of the cursor.
939 wxPoint m_CursorSize
;
940 /// Where the cursor should be drawn.
941 wxPoint m_CursorScreenPos
;
942 /// The line where the cursor is.
943 wxLayoutLine
*m_CursorLine
;
946 /// A structure for the selection.
949 Selection() { m_valid
= false; m_selecting
= false; }
952 wxPoint m_CursorA
, m_CursorB
;
954 /** @name Font parameters. */
956 int m_FontFamily
, m_FontStyle
, m_FontWeight
;
958 bool m_FontUnderline
;
962 /// the default setting:
963 wxLayoutStyleInfo
*m_DefaultSetting
;
964 /// the current setting:
965 wxLayoutStyleInfo m_CurrentSetting
;
972 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
974 The wxLayoutPrintout object for printing within the wxWindows print
977 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
978 /** This class implements a wxPrintout for printing a wxLayoutList within
979 the wxWindows printing framework.
981 class wxLayoutPrintout
: public wxPrintout
985 @param llist pointer to the wxLayoutList to be printed
986 @param title title for PS file or windows
988 wxLayoutPrintout(wxLayoutList
*llist
,
989 wxString
const & title
=
990 "wxLayout Printout");
994 /** Function which prints the n-th page.
995 @param page the page number to print
996 @return bool true if we are not at end of document yet
998 bool OnPrintPage(int page
);
999 /** Checks whether page exists in document.
1000 @param page number of page
1001 @return true if page exists
1003 bool HasPage(int page
);
1005 /** Gets called from wxWindows to find out which pages are existing.
1006 I'm not totally sure about the parameters though.
1007 @param minPage the first page in the document
1008 @param maxPage the last page in the document
1009 @param selPageFrom the first page to be printed
1010 @param selPageTo the last page to be printed
1012 void GetPageInfo(int *minPage
, int *maxPage
,
1013 int *selPageFrom
, int *selPageTo
);
1015 /** This little function scales the DC so that the printout has
1016 roughly the same size as the output on screen.
1017 @param dc the wxDC to scale
1018 @return the scale that was applied
1020 float ScaleDC(wxDC
*dc
);
1023 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1026 /// The list to print.
1027 wxLayoutList
*m_llist
;
1028 /// Title for PS file or window.
1030 /// The real paper size.
1031 int m_PageHeight
, m_PageWidth
;
1032 /// How much we actually print per page.
1033 int m_PrintoutHeight
;
1034 /// How many pages we need to print.
1036 /// Top left corner where we start printing.