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"
24 #include "wx/dataobj.h"
26 // skip the following defines if embedded in M application
28 # define WXMENU_LAYOUT_LCLICK 1111
29 # define WXMENU_LAYOUT_RCLICK 1112
30 # define WXMENU_LAYOUT_DBLCLICK 1113
33 // do not enable debug mode within Mahogany
34 #if defined(__WXDEBUG__) && ! defined(M_BASEDIR)
35 # define WXLAYOUT_DEBUG
39 # define WXLO_TRACE(x) wxLogDebug(x)
41 # define WXLO_TRACE(x)
44 #define WXLO_DEBUG_URECT 0
46 #ifndef WXLO_DEFAULTFONTSIZE
47 # define WXLO_DEFAULTFONTSIZE 12
51 # define WXLO_BITMAP_FORMAT wxBITMAP_TYPE_BMP
53 # define WXLO_BITMAP_FORMAT wxBITMAP_TYPE_PNG
57 /// Types of currently supported layout objects.
58 enum wxLayoutObjectType
60 /// illegal object type, should never appear
61 WXLO_TYPE_INVALID
= 0,
62 /// text object, containing normal text
64 /// command object, containing font or colour changes
66 /// icon object, any kind of image
70 /// Type used for coordinates in drawing. Must be signed.
71 typedef long CoordType
;
73 // Forward declarations.
81 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
83 The wxLayout objects which make up the lines.
85 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
87 /** The base class defining the interface to each object which can be
88 part of the layout. Each object needs to draw itself and calculate
94 /** This structure can be used to contain data associated with the
96 It is refcounted, so the caller has to do a DecRef() on it
101 UserData() { m_refcount
= 1; }
102 void IncRef(void) { m_refcount
++; }
103 void DecRef(void) { m_refcount
--; if(m_refcount
== 0) delete this;}
107 virtual ~UserData() { wxASSERT(m_refcount
== 0); }
108 /// prevents gcc from generating stupid warnings
109 friend class dummy_UserData
;
112 /// return the type of this object
113 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; }
114 /** Calculates the size of an object.
115 @param dc the wxDC to draw on
116 @param llist the wxLayoutList
118 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
) = 0;
121 @param dc the wxDC to draw on
122 @param coords where to draw the baseline of the object.
123 @param wxllist pointer to wxLayoutList
124 @param begin if !=-1, from which position on to highlight it
125 @param end if begin !=-1, how many positions to highlight it
127 virtual void Draw(wxDC
& /* dc */,
128 wxPoint
const & /* coords */,
129 class wxLayoutList
*wxllist
,
130 CoordType begin
= -1,
131 CoordType end
= -1) { }
133 /** Calculates and returns the size of the object.
134 @param top where to store height above baseline
135 @param bottom where to store height below baseline
136 @return the size of the object's box in pixels
138 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const
139 { *top
= 0; *bottom
= 0; return wxPoint(0,0); }
141 /// Return just the width of the object on the screen.
142 virtual CoordType
GetWidth(void) const { return 0; }
143 /// returns the number of cursor positions occupied by this object
144 virtual CoordType
GetLength(void) const { return 1; }
145 /** Returns the cursor offset relating to the screen x position
146 relative to begin of object.
147 @param dc the wxDC to use for calculations
148 @param xpos relative x position from head of object
149 @return cursor coordinate offset
151 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const { return 0; }
154 wxLayoutObject() { m_UserData
= NULL
; }
155 /// delete the user data
156 virtual ~wxLayoutObject() { if(m_UserData
) m_UserData
->DecRef(); }
158 #ifdef WXLAYOUT_DEBUG
159 virtual void Debug(void);
162 /** Tells the object about some user data. This data is associated
163 with the object and will be deleted at destruction time.
165 void SetUserData(UserData
*data
)
168 m_UserData
->DecRef();
171 m_UserData
->IncRef();
174 /** Return the user data. */
175 void * GetUserData(void) const { if(m_UserData
) m_UserData
->IncRef(); return m_UserData
; }
177 /** Makes a copy of this object.
179 virtual wxLayoutObject
*Copy(void) = 0;
181 /** Clipboard support function. Read and write objects to
184 /// Writes the object to the string.
185 virtual void Write(wxString
&ostr
) = 0;
187 @param str stream to read from, will bee changed
188 @return true on success
190 static wxLayoutObject
*Read(wxString
&istr
);
193 /// optional data for application's use
194 UserData
*m_UserData
;
197 /// Define a list type of wxLayoutObject pointers.
198 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObject
);
200 /// An illegal iterator to save typing.
201 #define NULLIT (wxLayoutObjectList::iterator(NULL))
202 /// The iterator type.
203 #define wxLOiterator wxLayoutObjectList::iterator
205 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
209 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
210 /** This class implements a wxLayoutObject holding plain text.
212 class wxLayoutObjectText
: public wxLayoutObject
215 wxLayoutObjectText(const wxString
&txt
= "");
217 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
218 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
);
219 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
220 class wxLayoutList
*wxllist
,
221 CoordType begin
= -1,
223 /** Calculates and returns the size of the object.
224 @param top where to store height above baseline
225 @param bottom where to store height below baseline
226 @return the size of the object's box in pixels
228 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
229 /// Return just the width of the object on the screen.
230 virtual CoordType
GetWidth(void) const { return m_Width
; }
231 /** Returns the cursor offset relating to the screen x position
232 relative to begin of object.
233 @param dc the wxDC to use for calculations
234 @param xpos relative x position from head of object
235 @return cursor coordinate offset
237 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const;
239 virtual void Write(wxString
&ostr
);
240 static wxLayoutObjectText
*Read(wxString
&istr
);
242 #ifdef WXLAYOUT_DEBUG
243 virtual void Debug(void);
246 virtual CoordType
GetLength(void) const { return strlen(m_Text
.c_str()); }
249 wxString
& GetText(void) { return m_Text
; }
250 void SetText(wxString
const &text
) { m_Text
= text
; }
251 /** Makes a copy of this object.
253 virtual wxLayoutObject
*Copy(void);
256 /// size of the box containing text
257 long m_Width
, m_Height
;
258 /// Height above baseline.
260 /// Height below baseline.
264 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
268 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
269 /** This class implements a wxLayoutObject holding a graphic.
271 class wxLayoutObjectIcon
: public wxLayoutObject
274 wxLayoutObjectIcon(wxBitmap
*icon
= NULL
);
275 wxLayoutObjectIcon(wxBitmap
const &icon
);
277 ~wxLayoutObjectIcon() { if(m_Icon
) delete m_Icon
; }
279 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
280 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
);
281 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
282 class wxLayoutList
*wxllist
,
283 CoordType begin
= -1,
286 /** Calculates and returns the size of the object.
287 @param top where to store height above baseline
288 @param bottom where to store height below baseline
289 @return the size of the object's box in pixels
291 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
292 /// Return just the width of the object on the screen.
293 virtual CoordType
GetWidth(void) const { return m_Icon
->GetWidth(); }
294 // return a pointer to the icon
295 wxBitmap
*GetIcon(void) const { return m_Icon
; }
296 /** Makes a copy of this object.
298 virtual wxLayoutObject
*Copy(void);
299 virtual void Write(wxString
&ostr
);
300 static wxLayoutObjectIcon
*Read(wxString
&istr
);
305 /** This structure holds all formatting information. Members which are
306 undefined (for a CmdObject this means: no change), are set to -1.
308 struct wxLayoutStyleInfo
310 wxLayoutStyleInfo(int ifamily
= -1,
316 wxColour
*bg
= NULL
);
317 wxColour
& GetBGColour()
321 wxLayoutStyleInfo
& operator=(const wxLayoutStyleInfo
&right
);
322 /// Font change parameters.
323 int size
, family
, style
, weight
, underline
;
326 int m_fg_valid
, m_bg_valid
; // bool, but must be int!
330 class wxFontCacheEntry
333 wxFontCacheEntry(int family
, int size
, int style
, int weight
,
336 m_Family
= family
; m_Size
= size
; m_Style
= style
;
337 m_Weight
= weight
; m_Underline
= underline
;
338 m_Font
= new wxFont(m_Size
, m_Family
,
339 m_Style
, m_Weight
, m_Underline
);
341 bool Matches(int family
, int size
, int style
, int weight
,
342 bool underline
) const
344 return size
== m_Size
&& family
== m_Family
345 && style
== m_Style
&& weight
== m_Weight
346 && underline
== m_Underline
;
348 wxFont
& GetFont(void) { return *m_Font
; }
355 int m_Family
, m_Size
, m_Style
, m_Weight
;
359 KBLIST_DEFINE(wxFCEList
, wxFontCacheEntry
);
364 wxFont
& GetFont(int family
, int size
, int style
, int weight
,
366 wxFont
& GetFont(wxLayoutStyleInfo
const &si
)
368 return GetFont(si
.family
, si
.size
, si
.style
, si
.weight
, si
.underline
);
371 wxFCEList m_FontList
;
374 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
378 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
379 /** This class implements a wxLayoutObject holding style change commands.
381 class wxLayoutObjectCmd
: public wxLayoutObject
384 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
385 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
);
386 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
387 class wxLayoutList
*wxllist
,
388 CoordType begin
= -1,
390 wxLayoutObjectCmd(int family
= -1,
396 wxColour
*bg
= NULL
);
397 ~wxLayoutObjectCmd();
398 /** Stores the current style in the styleinfo structure */
399 wxLayoutStyleInfo
* GetStyle(void) const;
400 /** Makes a copy of this object.
402 virtual wxLayoutObject
*Copy(void);
403 virtual void Write(wxString
&ostr
);
404 static wxLayoutObjectCmd
*Read(wxString
&istr
);
406 wxLayoutStyleInfo
*m_StyleInfo
;
409 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
411 The wxLayoutLine object
413 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
415 /// forward declaration
418 /** This class represents a single line of objects to be displayed.
419 It knows its height and total size and whether it needs to be
421 It has pointers to its first and next line so it can automatically
422 update them as needed.
428 @param prev pointer to previous line or NULL
429 @param next pointer to following line or NULL
430 @param llist pointer to layout list
432 wxLayoutLine(wxLayoutLine
*prev
, wxLayoutList
*llist
);
433 /** This function inserts a new object at cursor position xpos.
434 @param xpos where to insert new object
435 @param obj the object to insert
436 @return true if that xpos existed and the object was inserted
438 bool Insert(CoordType xpos
, wxLayoutObject
*obj
);
440 /** This function inserts text at cursor position xpos.
441 @param xpos where to insert
442 @param text the text to insert
443 @return true if that xpos existed and the object was inserted
445 bool Insert(CoordType xpos
, wxString text
);
447 /** This function appends an object to the line.
448 @param obj the object to insert
450 void Append(wxLayoutObject
* obj
)
453 m_ObjectList
.push_back(obj
);
454 m_Length
+= obj
->GetLength();
457 /** This function appens the next line to this, i.e. joins the two
460 void MergeNextLine(wxLayoutList
*llist
);
462 /** This function deletes npos cursor positions from position xpos.
463 @param xpos where to delete
464 @param npos how many positions
465 @return number of positions still to be deleted
467 CoordType
Delete(CoordType xpos
, CoordType npos
);
469 /** This function breaks the line at a given cursor position.
470 @param xpos where to break it
471 @return pointer to the new line object replacing the old one
473 wxLayoutLine
*Break(CoordType xpos
, wxLayoutList
*llist
);
475 /** Deletes the next word from this position, including leading
477 This function does not delete over font changes, i.e. a word
478 with formatting instructions in the middle of it is treated as
479 two (three actually!) words. In fact, if the cursor is on a non-text object, that
480 one is treated as a word.
481 @param xpos from where to delete
482 @return true if a word was deleted
484 bool DeleteWord(CoordType npos
);
486 /** Finds a suitable position left to the given column to break the
488 @param column we want to break the line to the left of this
489 @return column for breaking line or -1 if no suitable location found
491 CoordType
GetWrapPosition(CoordType column
);
493 /** Finds the object which covers the cursor position xpos in this
495 @param xpos the column number
496 @param offset where to store the difference between xpos and
498 @return iterator to the object or NULLIT
500 wxLayoutObjectList::iterator
FindObject(CoordType xpos
, CoordType
503 /** Finds the object which covers the screen position xpos in this
505 @param dc the wxDC to use for calculations
506 @param xpos the screen x coordinate
507 @param offset where to store the difference between xpos and
509 @return iterator to the object or NULLIT
511 wxLayoutObjectList::iterator
FindObjectScreen(wxDC
&dc
,
514 bool *found
= NULL
) const ;
516 /** Finds text in this line.
517 @param needle the text to find
518 @param xpos the position where to start the search
519 @return the cursoor coord where it was found or -1
521 CoordType
FindText(const wxString
&needle
, CoordType xpos
= 0) const;
523 /** Get the first object in the list. This is used by the wxlparser
524 functions to export the list.
525 @return iterator to the first object
527 wxLayoutObjectList::iterator
GetFirstObject(void)
529 return m_ObjectList
.begin();
532 /** Deletes this line, returns pointer to next line.
533 @param update If true, update all following lines.
535 wxLayoutLine
*DeleteLine(bool update
, wxLayoutList
*llist
);
537 /**@name Cursor Management */
539 /** Return the line number of this line.
540 @return the line number
542 inline CoordType
GetLineNumber(void) const { return m_LineNumber
; }
543 /** Return the length of the line.
544 @return line lenght in cursor positions
546 inline CoordType
GetLength(void) const { return m_Length
; }
549 /**@name Drawing and Layout */
551 /** Draws the line on a wxDC.
552 @param dc the wxDC to draw on
553 @param llist the wxLayoutList
554 @param offset an optional offset to shift printout
558 const wxPoint
&offset
= wxPoint(0,0)) const;
560 /** Recalculates the positions of objects and the height of the
562 @param dc the wxDC to draw on
563 @param llist th e wxLayoutList
564 @param cursorPos if not NULL, set cursor screen position in there
565 @param cursorSize if not cursorPos != NULL, set cursor size in there
566 @param cx if cursorPos != NULL, the cursor x position
568 void Layout(wxDC
&dc
,
570 wxPoint
*cursorPos
= NULL
,
571 wxPoint
*cursorSize
= NULL
,
573 /** This function finds an object belonging to a given cursor
574 position. It assumes that Layout() has been called before.
575 @param dc the wxDC to use for calculations
576 @param xpos screen x position
577 @param found if non-NULL set to false if we return the last
578 object before the cursor, to true if we really have an object
580 @return pointer to the object
582 wxLayoutObject
* FindObjectScreen(wxDC
&dc
, CoordType xpos
, bool
587 /**@name List traversal */
589 /// Returns pointer to next line.
590 wxLayoutLine
*GetNextLine(void) const { return m_Next
; }
591 /// Returns pointer to previous line.
592 wxLayoutLine
*GetPreviousLine(void) const { return m_Previous
; }
593 /// Sets the link to the next line.
594 void SetNext(wxLayoutLine
*next
)
595 { m_Next
= next
; if(next
) next
->m_Previous
= this; }
596 /// Sets the link to the previous line.
597 void SetPrevious(wxLayoutLine
*previous
)
598 { m_Previous
= previous
; if(previous
) previous
->m_Next
= this; }
601 /// Returns the position of this line on the canvas.
602 wxPoint
GetPosition(void) const { return m_Position
; }
603 /// Returns the height of this line.
604 CoordType
GetHeight(void) const { return m_Height
; }
605 /// Returns the width of this line.
606 CoordType
GetWidth(void) const { return m_Width
; }
607 /** This will recalculate the position and size of this line.
608 If called recursively it will abort if the position of an
609 object is unchanged, assuming that none of the following
610 objects need to move.
611 @param recurse if greater 0 then it will be used as the
612 minimum(!) recursion level, continue with all lines till the end of
613 the list or until the coordinates no longer changed.
615 void RecalculatePositions(int recurse
, wxLayoutList
*llist
);
616 /// Recalculates the position of this line on the canvas.
617 wxPoint
RecalculatePosition(wxLayoutList
*llist
);
619 /** Copies the contents of this line to another wxLayoutList
620 @param llist the wxLayoutList destination
621 @param from x cursor coordinate where to start
622 @param to x cursor coordinate where to stop, -1 for end of line
624 void Copy(wxLayoutList
*llist
,
628 #ifdef WXLAYOUT_DEBUG
631 wxLayoutStyleInfo
&GetStyleInfo() { return m_StyleInfo
; }
633 /// Returns dirty state
634 bool IsDirty(void) const { return m_Dirty
; }
635 /// Marks line as diry.
636 void MarkDirty(void) { m_Dirty
= true; }
638 /// Destructor is private. Use DeleteLine() to remove it.
641 /**@name Functions to let the lines synchronise with each other. */
643 /** Sets the height of this line. Will mark following lines as
645 @param height new height
647 void SetHeight(CoordType height
, wxLayoutList
*llist
)
648 { m_Height
= height
; RecalculatePositions(true, llist
); }
650 /** Moves the linenumbers one on, because a line has been inserted
652 @param delta either +1 or -1
654 void MoveLines(int delta
)
656 m_LineNumber
+= delta
;
657 if(m_Next
) m_Next
->MoveLines(delta
);
662 CoordType m_LineNumber
;
663 /// The line length in cursor positions.
665 /// The total height of the line.
667 /// The total width of the line on screen.
669 /// The baseline for drawing objects
670 CoordType m_BaseLine
;
671 /// The position on the canvas.
673 /// The list of objects
674 wxLayoutObjectList m_ObjectList
;
675 /// Have we been changed since the last layout?
677 /// Pointer to previous line if it exists.
678 wxLayoutLine
*m_Previous
;
679 /// Pointer to next line if it exists.
680 wxLayoutLine
*m_Next
;
681 /// A StyleInfo structure, holding the current settings.
682 wxLayoutStyleInfo m_StyleInfo
;
683 /// Just to suppress gcc compiler warnings.
686 wxLayoutLine(const wxLayoutLine
&);
690 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
692 The wxLayoutList object
694 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
695 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
696 higher level of abstraction for the text and can generally be considered
697 as representing "the text".
708 void Clear(int family
= wxROMAN
,
709 int size
=WXLO_DEFAULTFONTSIZE
,
715 /// Empty: clear the list but leave font settings.
718 /**@name Cursor Management */
720 /** Set new cursor position.
721 @param p new position
722 @return bool if it could be set
724 bool MoveCursorTo(wxPoint
const &p
);
725 /** Move cursor up or down.
727 @return bool if it could be moved
729 bool MoveCursorVertically(int n
);
730 /** Move cursor left or right.
732 @return bool if it could be moved
734 bool MoveCursorHorizontally(int n
);
736 /// Move cursor to end of line.
737 void MoveCursorToEndOfLine(void)
739 wxASSERT(m_CursorLine
);
740 MoveCursorHorizontally(m_CursorLine
->GetLength()-m_CursorPos
.x
);
743 /// Move cursor to begin of line.
744 void MoveCursorToBeginOfLine(void)
745 { MoveCursorHorizontally(-m_CursorPos
.x
); }
747 /// Returns current cursor position.
748 wxPoint
GetCursorPos(wxDC
&dc
) const { return m_CursorPos
; }
749 wxPoint
GetCursorPos() const { return m_CursorPos
; }
753 /**@name Editing functions.
754 All of these functions return true on success and false on
757 /// Insert text at current cursor position.
758 bool Insert(wxString
const &text
);
759 /// Insert some other object at current cursor position.
760 bool Insert(wxLayoutObject
*obj
);
761 /// Inserts objects at current cursor positions
762 bool Insert(wxLayoutList
*llist
);
764 /// Inserts a linebreak at current cursor position.
765 bool LineBreak(void);
766 /** Wraps the current line. Searches to the left of the cursor to
767 break the line. Does nothing if the cursor position is before
768 the break position parameter.
769 @param column the break position for the line, maximum length
770 @return true if line got broken
772 bool WrapLine(CoordType column
);
773 /** This function deletes npos cursor positions.
774 @param npos how many positions
775 @return true if everything got deleted
777 bool Delete(CoordType npos
);
779 /** Delete the next n lines.
780 @param n how many lines to delete
781 @return how many it could not delete
783 int DeleteLines(int n
);
785 /// Delete to end of line.
786 void DeleteToEndOfLine(void)
788 wxASSERT(m_CursorLine
);
789 Delete(m_CursorLine
->GetLength()-m_CursorPos
.x
);
791 /// Delete to begin of line.
792 void DeleteToBeginOfLine(void)
794 wxASSERT(m_CursorLine
);
795 CoordType n
= m_CursorPos
.x
;
796 #ifdef WXLAYOUT_DEBUG
797 wxASSERT(MoveCursorHorizontally(-n
));
799 MoveCursorHorizontally(-n
);
804 /** Delete the next word.
806 void DeleteWord(void)
808 wxASSERT(m_CursorLine
);
809 m_CursorLine
->DeleteWord(m_CursorPos
.x
);
814 /** Finds text in this list.
815 @param needle the text to find
816 @param cpos the position where to start the search
817 @return the cursoor coord where it was found or (-1,-1)
819 wxPoint
FindText(const wxString
&needle
, const wxPoint
&cpos
= wxPoint(0,0)) const;
821 /**@name Formatting options */
823 /// sets font parameters
824 void SetFont(int family
, int size
, int style
,
825 int weight
, int underline
,
828 /// sets font parameters, colours by name
829 void SetFont(int family
=-1, int size
= -1, int style
=-1,
830 int weight
=-1, int underline
= -1,
831 char const *fg
= NULL
,
832 char const *bg
= NULL
);
833 /// changes to the next larger font size
834 inline void SetFontLarger(void)
835 { SetFont(-1,(12*m_CurrentSetting
.size
)/10); }
836 /// changes to the next smaller font size
837 inline void SetFontSmaller(void)
838 { SetFont(-1,(10*m_CurrentSetting
.size
)/12); }
841 inline void SetFontFamily(int family
) { SetFont(family
); }
843 inline void SetFontSize(int size
) { SetFont(-1,size
); }
845 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
847 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
848 /// toggle underline flag
849 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
850 /// set font colours by name
851 inline void SetFontColour(char const *fg
, char const *bg
= NULL
)
852 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
853 /// set font colours by colour
854 inline void SetFontColour(wxColour
*fg
, wxColour
*bg
= NULL
)
855 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
859 Returns a pointer to the default settings.
860 This is only valid temporarily and should not be stored
862 @return the default settings of the list
864 wxLayoutStyleInfo
*GetDefaults(void) { return &m_DefaultSetting
; }
865 wxLayoutStyleInfo
*GetStyleInfo(void) { return &m_CurrentSetting
; }
870 /** Draws the complete list on a wxDC.
871 @param dc the wxDC to draw on
872 @param offset an optional offset to shift printout
873 @param top optional y coordinate where to start drawing
874 @param bottom optional y coordinate where to stop drawing
877 const wxPoint
&offset
= wxPoint(0,0),
878 CoordType top
= -1, CoordType bottom
= -1);
880 /** Calculates new layout for the list, like Draw() but does not
882 @param dc the wxDC to draw on
883 @param bottom optional y coordinate where to stop calculating
884 @param forceAll force re-layout of all lines
886 void Layout(wxDC
&dc
, CoordType bottom
= -1, bool forceAll
= false);
888 /** Calculates new sizes for everything in the list, like Layout()
889 but this is needed after the list got changed.
890 @param dc the wxDC to draw on
891 @param bottom optional y coordinate where to stop calculating
893 void Recalculate(wxDC
&dc
, CoordType bottom
= -1);
895 /** Returns the size of the list in screen coordinates.
896 The return value only makes sense after the list has been
898 @return a wxPoint holding the maximal x/y coordinates used for
901 wxPoint
GetSize(void) const;
903 /** Returns the cursor position on the screen.
904 @return cursor position in pixels
906 wxPoint
GetCursorScreenPos(wxDC
&dc
);
908 /** Draws the cursor.
909 @param active If true, draw a bold cursor to mark window as
911 @param translate optional translation of cursor coords on screen
913 void DrawCursor(wxDC
&dc
,
915 const wxPoint
& translate
= wxPoint(0,0));
917 /** This function finds an object belonging to a given screen
918 position. It assumes that Layout() has been called before.
919 @param pos screen position
920 @param cursorPos if non NULL, store cursor position in there
921 @param found if used, set this to true if we really found an
922 object, to false if we had to take the object near to it
923 @return pointer to the object
925 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
927 wxPoint
*cursorPos
= NULL
,
930 /** Called by the objects to update the update rectangle.
931 @param x horizontal coordinate to include in rectangle
932 @param y vertical coordinate to include in rectangle
934 void SetUpdateRect(CoordType x
, CoordType y
);
935 /** Called by the objects to update the update rectangle.
936 @param p a point to include in it
938 inline void SetUpdateRect(const wxPoint
&p
)
939 { SetUpdateRect(p
.x
,p
.y
); }
940 /// Invalidates the update rectangle.
941 void InvalidateUpdateRect(void) { m_UpdateRectValid
= false; }
942 /// Returns the update rectangle.
943 const wxRect
*GetUpdateRect(void) const { return &m_UpdateRect
; }
946 /**@name For exporting one object after another. */
948 /** Returns a pointer to the first line in the list. */
949 wxLayoutLine
*GetFirstLine(void)
951 wxASSERT(m_FirstLine
);
956 /// Begin selecting text.
957 void StartSelection(wxPoint cpos
= wxPoint(-1,-1));
958 // Continue selecting text
959 void ContinueSelection(wxPoint cpos
= wxPoint(-1,-1));
960 /// End selecting text.
961 void EndSelection(wxPoint cpos
= wxPoint(-1,-1));
962 /// Are we still selecting text?
963 bool IsSelecting(void);
964 bool IsSelected(const wxPoint
&cursor
);
966 /** Return the selection as a wxLayoutList.
967 @param invalidate if true, the selection will be invalidated after this and can no longer be used.
968 @return Another layout list object holding the selection, must be freed by caller
970 wxLayoutList
*GetSelection(class wxLayoutDataObject
*wxldo
= NULL
, bool invalidate
= TRUE
);
971 /// Delete selected bit
972 void DeleteSelection(void);
974 wxLayoutList
*Copy(const wxPoint
&from
= wxPoint(0,0),
975 const wxPoint
&to
= wxPoint(-1,-1));
977 /// starts highlighting of text for selections
978 void StartHighlighting(wxDC
&dc
);
979 /// ends highlighting of text for selections
980 void EndHighlighting(wxDC
&dc
);
982 /** Tests whether this layout line is selected and needs
984 @param line to test for
985 @param from set to first cursorpos to be highlighted (for returncode == -1)
986 @param to set to last cursorpos to be highlighted (for returncode == -1)
987 @return 0 = not selected, 1 = fully selected, -1 = partially
991 int IsSelected(const wxLayoutLine
*line
, CoordType
*from
, CoordType
*to
);
993 void ApplyStyle(wxLayoutStyleInfo
*si
, wxDC
&dc
);
994 #ifdef WXLAYOUT_DEBUG
999 void InternalClear(void);
1000 /** Calculates the cursor position on the screen.
1002 void UpdateCursorScreenPos(wxDC
&dc
);
1004 /// The list of lines.
1005 wxLayoutLine
*m_FirstLine
;
1006 /// The update rectangle which needs to be refreshed:
1007 wxRect m_UpdateRect
;
1008 /// Is the update rectangle valid?
1009 bool m_UpdateRectValid
;
1010 /**@name Cursor Management */
1012 /// Where the text cursor (column,line) is.
1013 wxPoint m_CursorPos
;
1014 /// The size of the cursor.
1015 wxPoint m_CursorSize
;
1016 /// Where the cursor should be drawn.
1017 wxPoint m_CursorScreenPos
;
1018 /// The line where the cursor is.
1019 wxLayoutLine
*m_CursorLine
;
1022 /// A structure for the selection.
1025 Selection() { m_valid
= false; m_selecting
= false; }
1028 wxPoint m_CursorA
, m_CursorB
;
1030 /** @name Font parameters. */
1032 /// this object manages the fonts for us
1033 wxFontCache m_FontCache
;
1034 /// the default setting:
1035 wxLayoutStyleInfo m_DefaultSetting
;
1036 /// the current setting:
1037 wxLayoutStyleInfo m_CurrentSetting
;
1042 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1044 The wxLayoutDataObject for exporting data to the clipboard in our
1047 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1048 class wxLayoutDataObject
: public wxPrivateDataObject
1051 wxLayoutDataObject(void)
1053 SetId("application/wxlayoutlist");
1054 m_format
.SetAtom((GdkAtom
) 222222);
1058 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1060 The wxLayoutPrintout object for printing within the wxWindows print
1063 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1064 /** This class implements a wxPrintout for printing a wxLayoutList within
1065 the wxWindows printing framework.
1067 class wxLayoutPrintout
: public wxPrintout
1071 @param llist pointer to the wxLayoutList to be printed
1072 @param title title for PS file or windows
1074 wxLayoutPrintout(wxLayoutList
*llist
,
1075 wxString
const & title
=
1076 "wxLayout Printout");
1078 ~wxLayoutPrintout();
1080 /** Function which prints the n-th page.
1081 @param page the page number to print
1082 @return bool true if we are not at end of document yet
1084 bool OnPrintPage(int page
);
1085 /** Checks whether page exists in document.
1086 @param page number of page
1087 @return true if page exists
1089 bool HasPage(int page
);
1091 /** Gets called from wxWindows to find out which pages are existing.
1092 I'm not totally sure about the parameters though.
1093 @param minPage the first page in the document
1094 @param maxPage the last page in the document
1095 @param selPageFrom the first page to be printed
1096 @param selPageTo the last page to be printed
1098 void GetPageInfo(int *minPage
, int *maxPage
,
1099 int *selPageFrom
, int *selPageTo
);
1101 /** This little function scales the DC so that the printout has
1102 roughly the same size as the output on screen.
1103 @param dc the wxDC to scale
1104 @return the scale that was applied
1106 float ScaleDC(wxDC
*dc
);
1109 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1112 /// The list to print.
1113 wxLayoutList
*m_llist
;
1114 /// Title for PS file or window.
1116 /// The real paper size.
1117 int m_PageHeight
, m_PageWidth
;
1118 /// How much we actually print per page.
1119 int m_PrintoutHeight
;
1120 /// How many pages we need to print.
1122 /// Top left corner where we start printing.