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 inline void IncRef(void) { m_refcount
++; }
103 inline void DecRef(void) { m_refcount
--; if(m_refcount
== 0) delete this;}
104 inline void SetLabel(const wxString
&l
) { m_label
= l
; }
105 inline const wxString
& GetLabel(void) const { return m_label
; }
110 virtual ~UserData() { wxASSERT(m_refcount
== 0); }
111 /// prevents gcc from generating stupid warnings
112 friend class dummy_UserData
;
115 /// return the type of this object
116 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; }
117 /** Calculates the size of an object.
118 @param dc the wxDC to draw on
119 @param llist the wxLayoutList
121 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
) = 0;
124 @param dc the wxDC to draw on
125 @param coords where to draw the baseline of the object.
126 @param wxllist pointer to wxLayoutList
127 @param begin if !=-1, from which position on to highlight it
128 @param end if begin !=-1, how many positions to highlight it
130 virtual void Draw(wxDC
& /* dc */,
131 wxPoint
const & /* coords */,
132 class wxLayoutList
*wxllist
,
133 CoordType begin
= -1,
134 CoordType end
= -1) { }
136 /** Calculates and returns the size of the object.
137 @param top where to store height above baseline
138 @param bottom where to store height below baseline
139 @return the size of the object's box in pixels
141 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const
142 { *top
= 0; *bottom
= 0; return wxPoint(0,0); }
144 /// Return just the width of the object on the screen.
145 virtual CoordType
GetWidth(void) const { return 0; }
146 /// returns the number of cursor positions occupied by this object
147 virtual CoordType
GetLength(void) const { return 1; }
148 /** Returns the cursor offset relating to the screen x position
149 relative to begin of object.
150 @param dc the wxDC to use for calculations
151 @param xpos relative x position from head of object
152 @return cursor coordinate offset
154 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const { return 0; }
157 wxLayoutObject() { m_UserData
= NULL
; }
158 /// delete the user data
159 virtual ~wxLayoutObject() { if(m_UserData
) m_UserData
->DecRef(); }
161 #ifdef WXLAYOUT_DEBUG
162 virtual void Debug(void);
165 /** Tells the object about some user data. This data is associated
166 with the object and will be deleted at destruction time.
167 It is reference counted.
169 void SetUserData(UserData
*data
)
172 m_UserData
->DecRef();
175 m_UserData
->IncRef();
178 /** Return the user data.
179 Increments the object's reference count. When no longer needed,
180 caller must call DecRef() on the pointer returned.
182 UserData
* GetUserData(void) const { if(m_UserData
) m_UserData
->IncRef(); return m_UserData
; }
184 /** Makes a copy of this object.
186 virtual wxLayoutObject
*Copy(void) = 0;
188 /** Clipboard support function. Read and write objects to
191 /// Writes the object to the string.
192 virtual void Write(wxString
&ostr
) = 0;
194 @param str stream to read from, will bee changed
195 @return true on success
197 static wxLayoutObject
*Read(wxString
&istr
);
200 /// optional data for application's use
201 UserData
*m_UserData
;
204 /// Define a list type of wxLayoutObject pointers.
205 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObject
);
207 /// An illegal iterator to save typing.
208 #define NULLIT (wxLayoutObjectList::iterator(NULL))
209 /// The iterator type.
210 #define wxLOiterator wxLayoutObjectList::iterator
212 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
216 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
217 /** This class implements a wxLayoutObject holding plain text.
219 class wxLayoutObjectText
: public wxLayoutObject
222 wxLayoutObjectText(const wxString
&txt
= "");
224 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
225 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
);
226 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
227 class wxLayoutList
*wxllist
,
228 CoordType begin
= -1,
230 /** Calculates and returns the size of the object.
231 @param top where to store height above baseline
232 @param bottom where to store height below baseline
233 @return the size of the object's box in pixels
235 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
236 /// Return just the width of the object on the screen.
237 virtual CoordType
GetWidth(void) const { return m_Width
; }
238 /** Returns the cursor offset relating to the screen x position
239 relative to begin of object.
240 @param dc the wxDC to use for calculations
241 @param xpos relative x position from head of object
242 @return cursor coordinate offset
244 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const;
246 virtual void Write(wxString
&ostr
);
247 static wxLayoutObjectText
*Read(wxString
&istr
);
249 #ifdef WXLAYOUT_DEBUG
250 virtual void Debug(void);
253 virtual CoordType
GetLength(void) const { return strlen(m_Text
.c_str()); }
256 wxString
& GetText(void) { return m_Text
; }
257 void SetText(wxString
const &text
) { m_Text
= text
; }
258 /** Makes a copy of this object.
260 virtual wxLayoutObject
*Copy(void);
263 /// size of the box containing text
264 long m_Width
, m_Height
;
265 /// Height above baseline.
267 /// Height below baseline.
271 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
275 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
276 /** This class implements a wxLayoutObject holding a graphic.
278 class wxLayoutObjectIcon
: public wxLayoutObject
281 wxLayoutObjectIcon(wxBitmap
*icon
= NULL
);
282 wxLayoutObjectIcon(wxBitmap
const &icon
);
284 ~wxLayoutObjectIcon() { if(m_Icon
) delete m_Icon
; }
286 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
287 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
);
288 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
289 class wxLayoutList
*wxllist
,
290 CoordType begin
= -1,
293 /** Calculates and returns the size of the object.
294 @param top where to store height above baseline
295 @param bottom where to store height below baseline
296 @return the size of the object's box in pixels
298 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
299 /// Return just the width of the object on the screen.
300 virtual CoordType
GetWidth(void) const { return m_Icon
->GetWidth(); }
301 // return a pointer to the icon
302 wxBitmap
*GetIcon(void) const { return m_Icon
; }
303 /** Makes a copy of this object.
305 virtual wxLayoutObject
*Copy(void);
306 virtual void Write(wxString
&ostr
);
307 static wxLayoutObjectIcon
*Read(wxString
&istr
);
312 /** This structure holds all formatting information. Members which are
313 undefined (for a CmdObject this means: no change), are set to -1.
315 struct wxLayoutStyleInfo
317 wxLayoutStyleInfo(int ifamily
= -1,
323 wxColour
*bg
= NULL
);
324 wxColour
& GetBGColour()
328 wxLayoutStyleInfo
& operator=(const wxLayoutStyleInfo
&right
);
329 /// Font change parameters.
330 int size
, family
, style
, weight
, underline
;
333 int m_fg_valid
, m_bg_valid
; // bool, but must be int!
337 class wxFontCacheEntry
340 wxFontCacheEntry(int family
, int size
, int style
, int weight
,
343 m_Family
= family
; m_Size
= size
; m_Style
= style
;
344 m_Weight
= weight
; m_Underline
= underline
;
345 m_Font
= new wxFont(m_Size
, m_Family
,
346 m_Style
, m_Weight
, m_Underline
);
348 bool Matches(int family
, int size
, int style
, int weight
,
349 bool underline
) const
351 return size
== m_Size
&& family
== m_Family
352 && style
== m_Style
&& weight
== m_Weight
353 && underline
== m_Underline
;
355 wxFont
& GetFont(void) { return *m_Font
; }
362 int m_Family
, m_Size
, m_Style
, m_Weight
;
366 KBLIST_DEFINE(wxFCEList
, wxFontCacheEntry
);
371 wxFont
& GetFont(int family
, int size
, int style
, int weight
,
373 wxFont
& GetFont(wxLayoutStyleInfo
const &si
)
375 return GetFont(si
.family
, si
.size
, si
.style
, si
.weight
, si
.underline
);
378 wxFCEList m_FontList
;
381 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
385 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
386 /** This class implements a wxLayoutObject holding style change commands.
388 class wxLayoutObjectCmd
: public wxLayoutObject
391 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
392 virtual void Layout(wxDC
&dc
, class wxLayoutList
*llist
);
393 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
394 class wxLayoutList
*wxllist
,
395 CoordType begin
= -1,
397 wxLayoutObjectCmd(int family
= -1,
403 wxColour
*bg
= NULL
);
404 ~wxLayoutObjectCmd();
405 /** Stores the current style in the styleinfo structure */
406 wxLayoutStyleInfo
* GetStyle(void) const;
407 /** Makes a copy of this object.
409 virtual wxLayoutObject
*Copy(void);
410 virtual void Write(wxString
&ostr
);
411 static wxLayoutObjectCmd
*Read(wxString
&istr
);
413 wxLayoutStyleInfo
*m_StyleInfo
;
416 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
418 The wxLayoutLine object
420 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
422 /// forward declaration
425 /** This class represents a single line of objects to be displayed.
426 It knows its height and total size and whether it needs to be
428 It has pointers to its first and next line so it can automatically
429 update them as needed.
435 @param prev pointer to previous line or NULL
436 @param next pointer to following line or NULL
437 @param llist pointer to layout list
439 wxLayoutLine(wxLayoutLine
*prev
, wxLayoutList
*llist
);
440 /** This function inserts a new object at cursor position xpos.
441 @param xpos where to insert new object
442 @param obj the object to insert
443 @return true if that xpos existed and the object was inserted
445 bool Insert(CoordType xpos
, wxLayoutObject
*obj
);
447 /** This function inserts text at cursor position xpos.
448 @param xpos where to insert
449 @param text the text to insert
450 @return true if that xpos existed and the object was inserted
452 bool Insert(CoordType xpos
, wxString text
);
454 /** This function appends an object to the line.
455 @param obj the object to insert
457 void Append(wxLayoutObject
* obj
)
460 m_ObjectList
.push_back(obj
);
461 m_Length
+= obj
->GetLength();
464 /** This function appens the next line to this, i.e. joins the two
467 void MergeNextLine(wxLayoutList
*llist
);
469 /** This function deletes npos cursor positions from position xpos.
470 @param xpos where to delete
471 @param npos how many positions
472 @return number of positions still to be deleted
474 CoordType
Delete(CoordType xpos
, CoordType npos
);
476 /** This function breaks the line at a given cursor position.
477 @param xpos where to break it
478 @return pointer to the new line object replacing the old one
480 wxLayoutLine
*Break(CoordType xpos
, wxLayoutList
*llist
);
482 /** Deletes the next word from this position, including leading
484 This function does not delete over font changes, i.e. a word
485 with formatting instructions in the middle of it is treated as
486 two (three actually!) words. In fact, if the cursor is on a non-text object, that
487 one is treated as a word.
488 @param xpos from where to delete
489 @return true if a word was deleted
491 bool DeleteWord(CoordType npos
);
493 /** Finds a suitable position left to the given column to break the
495 @param column we want to break the line to the left of this
496 @return column for breaking line or -1 if no suitable location found
498 CoordType
GetWrapPosition(CoordType column
);
500 /** Finds the object which covers the cursor position xpos in this
502 @param xpos the column number
503 @param offset where to store the difference between xpos and
505 @return iterator to the object or NULLIT
507 wxLayoutObjectList::iterator
FindObject(CoordType xpos
, CoordType
510 /** Finds the object which covers the screen position xpos in this
512 @param dc the wxDC to use for calculations
513 @param xpos the screen x coordinate
514 @param offset where to store the difference between xpos and
516 @return iterator to the object or NULLIT
518 wxLayoutObjectList::iterator
FindObjectScreen(wxDC
&dc
,
521 bool *found
= NULL
) const ;
523 /** Finds text in this line.
524 @param needle the text to find
525 @param xpos the position where to start the search
526 @return the cursoor coord where it was found or -1
528 CoordType
FindText(const wxString
&needle
, CoordType xpos
= 0) const;
530 /** Get the first object in the list. This is used by the wxlparser
531 functions to export the list.
532 @return iterator to the first object
534 wxLayoutObjectList::iterator
GetFirstObject(void)
536 return m_ObjectList
.begin();
539 /** Deletes this line, returns pointer to next line.
540 @param update If true, update all following lines.
542 wxLayoutLine
*DeleteLine(bool update
, wxLayoutList
*llist
);
544 /**@name Cursor Management */
546 /** Return the line number of this line.
547 @return the line number
549 inline CoordType
GetLineNumber(void) const { return m_LineNumber
; }
550 /** Return the length of the line.
551 @return line lenght in cursor positions
553 inline CoordType
GetLength(void) const { return m_Length
; }
556 /**@name Drawing and Layout */
558 /** Draws the line on a wxDC.
559 @param dc the wxDC to draw on
560 @param llist the wxLayoutList
561 @param offset an optional offset to shift printout
565 const wxPoint
&offset
= wxPoint(0,0)) const;
567 /** Recalculates the positions of objects and the height of the
569 @param dc the wxDC to draw on
570 @param llist th e wxLayoutList
571 @param cursorPos if not NULL, set cursor screen position in there
572 @param cursorSize if not cursorPos != NULL, set cursor size in there
573 @param cx if cursorPos != NULL, the cursor x position
575 void Layout(wxDC
&dc
,
577 wxPoint
*cursorPos
= NULL
,
578 wxPoint
*cursorSize
= NULL
,
580 /** This function finds an object belonging to a given cursor
581 position. It assumes that Layout() has been called before.
582 @param dc the wxDC to use for calculations
583 @param xpos screen x position
584 @param found if non-NULL set to false if we return the last
585 object before the cursor, to true if we really have an object
587 @return pointer to the object
589 wxLayoutObject
* FindObjectScreen(wxDC
&dc
, CoordType xpos
, bool
594 /**@name List traversal */
596 /// Returns pointer to next line.
597 wxLayoutLine
*GetNextLine(void) const { return m_Next
; }
598 /// Returns pointer to previous line.
599 wxLayoutLine
*GetPreviousLine(void) const { return m_Previous
; }
600 /// Sets the link to the next line.
601 void SetNext(wxLayoutLine
*next
)
602 { m_Next
= next
; if(next
) next
->m_Previous
= this; }
603 /// Sets the link to the previous line.
604 void SetPrevious(wxLayoutLine
*previous
)
605 { m_Previous
= previous
; if(previous
) previous
->m_Next
= this; }
608 /// Returns the position of this line on the canvas.
609 wxPoint
GetPosition(void) const { return m_Position
; }
610 /// Returns the height of this line.
611 CoordType
GetHeight(void) const { return m_Height
; }
612 /// Returns the width of this line.
613 CoordType
GetWidth(void) const { return m_Width
; }
614 /** This will recalculate the position and size of this line.
615 If called recursively it will abort if the position of an
616 object is unchanged, assuming that none of the following
617 objects need to move.
618 @param recurse if greater 0 then it will be used as the
619 minimum(!) recursion level, continue with all lines till the end of
620 the list or until the coordinates no longer changed.
622 void RecalculatePositions(int recurse
, wxLayoutList
*llist
);
623 /// Recalculates the position of this line on the canvas.
624 wxPoint
RecalculatePosition(wxLayoutList
*llist
);
626 /** Copies the contents of this line to another wxLayoutList
627 @param llist the wxLayoutList destination
628 @param from x cursor coordinate where to start
629 @param to x cursor coordinate where to stop, -1 for end of line
631 void Copy(wxLayoutList
*llist
,
635 #ifdef WXLAYOUT_DEBUG
638 wxLayoutStyleInfo
&GetStyleInfo() { return m_StyleInfo
; }
640 /// Returns dirty state
641 bool IsDirty(void) const { return m_Dirty
; }
642 /// Marks line as diry.
643 void MarkDirty(void) { m_Dirty
= true; }
645 /// Destructor is private. Use DeleteLine() to remove it.
648 /**@name Functions to let the lines synchronise with each other. */
650 /** Sets the height of this line. Will mark following lines as
652 @param height new height
654 void SetHeight(CoordType height
, wxLayoutList
*llist
)
655 { m_Height
= height
; RecalculatePositions(true, llist
); }
657 /** Moves the linenumbers one on, because a line has been inserted
659 @param delta either +1 or -1
661 void MoveLines(int delta
)
663 m_LineNumber
+= delta
;
664 if(m_Next
) m_Next
->MoveLines(delta
);
669 CoordType m_LineNumber
;
670 /// The line length in cursor positions.
672 /// The total height of the line.
674 /// The total width of the line on screen.
676 /// The baseline for drawing objects
677 CoordType m_BaseLine
;
678 /// The position on the canvas.
680 /// The list of objects
681 wxLayoutObjectList m_ObjectList
;
682 /// Have we been changed since the last layout?
684 /// Pointer to previous line if it exists.
685 wxLayoutLine
*m_Previous
;
686 /// Pointer to next line if it exists.
687 wxLayoutLine
*m_Next
;
688 /// A StyleInfo structure, holding the current settings.
689 wxLayoutStyleInfo m_StyleInfo
;
690 /// Just to suppress gcc compiler warnings.
693 wxLayoutLine(const wxLayoutLine
&);
697 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
699 The wxLayoutList object
701 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
702 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
703 higher level of abstraction for the text and can generally be considered
704 as representing "the text".
715 void Clear(int family
= wxROMAN
,
716 int size
=WXLO_DEFAULTFONTSIZE
,
722 /// Empty: clear the list but leave font settings.
725 /**@name Cursor Management */
727 /** Set new cursor position.
728 @param p new position
729 @return bool if it could be set
731 bool MoveCursorTo(wxPoint
const &p
);
732 /** Move cursor up or down.
734 @return bool if it could be moved
736 bool MoveCursorVertically(int n
);
737 /** Move cursor left or right.
739 @return bool if it could be moved
741 bool MoveCursorHorizontally(int n
);
743 /// Move cursor to end of line.
744 void MoveCursorToEndOfLine(void)
746 wxASSERT(m_CursorLine
);
747 MoveCursorHorizontally(m_CursorLine
->GetLength()-m_CursorPos
.x
);
750 /// Move cursor to begin of line.
751 void MoveCursorToBeginOfLine(void)
752 { MoveCursorHorizontally(-m_CursorPos
.x
); }
754 /// Returns current cursor position.
755 const wxPoint
&GetCursorPos(wxDC
&dc
) const { return m_CursorPos
; }
756 const wxPoint
&GetCursorPos() const { return m_CursorPos
; }
760 /**@name Editing functions.
761 All of these functions return true on success and false on
764 /// Insert text at current cursor position.
765 bool Insert(wxString
const &text
);
766 /// Insert some other object at current cursor position.
767 bool Insert(wxLayoutObject
*obj
);
768 /// Inserts objects at current cursor positions
769 bool Insert(wxLayoutList
*llist
);
771 /// Inserts a linebreak at current cursor position.
772 bool LineBreak(void);
773 /** Wraps the current line. Searches to the left of the cursor to
774 break the line. Does nothing if the cursor position is before
775 the break position parameter.
776 @param column the break position for the line, maximum length
777 @return true if line got broken
779 bool WrapLine(CoordType column
);
780 /** This function deletes npos cursor positions.
781 @param npos how many positions
782 @return true if everything got deleted
784 bool Delete(CoordType npos
);
786 /** Delete the next n lines.
787 @param n how many lines to delete
788 @return how many it could not delete
790 int DeleteLines(int n
);
792 /// Delete to end of line.
793 void DeleteToEndOfLine(void)
795 wxASSERT(m_CursorLine
);
796 Delete(m_CursorLine
->GetLength()-m_CursorPos
.x
);
798 /// Delete to begin of line.
799 void DeleteToBeginOfLine(void)
801 wxASSERT(m_CursorLine
);
802 CoordType n
= m_CursorPos
.x
;
803 #ifdef WXLAYOUT_DEBUG
804 wxASSERT(MoveCursorHorizontally(-n
));
806 MoveCursorHorizontally(-n
);
811 /** Delete the next word.
813 void DeleteWord(void)
815 wxASSERT(m_CursorLine
);
816 m_CursorLine
->DeleteWord(m_CursorPos
.x
);
821 /** Finds text in this list.
822 @param needle the text to find
823 @param cpos the position where to start the search
824 @return the cursoor coord where it was found or (-1,-1)
826 wxPoint
FindText(const wxString
&needle
, const wxPoint
&cpos
= wxPoint(0,0)) const;
828 /**@name Formatting options */
830 /// sets font parameters
831 void SetFont(int family
, int size
, int style
,
832 int weight
, int underline
,
835 /// sets font parameters, colours by name
836 void SetFont(int family
=-1, int size
= -1, int style
=-1,
837 int weight
=-1, int underline
= -1,
838 char const *fg
= NULL
,
839 char const *bg
= NULL
);
840 /// changes to the next larger font size
841 inline void SetFontLarger(void)
842 { SetFont(-1,(12*m_CurrentSetting
.size
)/10); }
843 /// changes to the next smaller font size
844 inline void SetFontSmaller(void)
845 { SetFont(-1,(10*m_CurrentSetting
.size
)/12); }
848 inline void SetFontFamily(int family
) { SetFont(family
); }
850 inline void SetFontSize(int size
) { SetFont(-1,size
); }
852 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
854 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
855 /// toggle underline flag
856 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
857 /// set font colours by name
858 inline void SetFontColour(char const *fg
, char const *bg
= NULL
)
859 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
860 /// set font colours by colour
861 inline void SetFontColour(wxColour
*fg
, wxColour
*bg
= NULL
)
862 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
866 Returns a pointer to the default settings.
867 This is only valid temporarily and should not be stored
869 @return the default settings of the list
871 wxLayoutStyleInfo
*GetDefaults(void) { return &m_DefaultSetting
; }
872 wxLayoutStyleInfo
*GetStyleInfo(void) { return &m_CurrentSetting
; }
877 /** Draws the complete list on a wxDC.
878 @param dc the wxDC to draw on
879 @param offset an optional offset to shift printout
880 @param top optional y coordinate where to start drawing
881 @param bottom optional y coordinate where to stop drawing
884 const wxPoint
&offset
= wxPoint(0,0),
885 CoordType top
= -1, CoordType bottom
= -1);
887 /** Calculates new layout for the list, like Draw() but does not
889 @param dc the wxDC to draw on
890 @param bottom optional y coordinate where to stop calculating
891 @param forceAll force re-layout of all lines
893 void Layout(wxDC
&dc
, CoordType bottom
= -1, bool forceAll
= false);
895 /** Calculates new sizes for everything in the list, like Layout()
896 but this is needed after the list got changed.
897 @param dc the wxDC to draw on
898 @param bottom optional y coordinate where to stop calculating
900 void Recalculate(wxDC
&dc
, CoordType bottom
= -1);
902 /** Returns the size of the list in screen coordinates.
903 The return value only makes sense after the list has been
905 @return a wxPoint holding the maximal x/y coordinates used for
908 wxPoint
GetSize(void) const;
910 /** Returns the cursor position on the screen.
911 @return cursor position in pixels
913 wxPoint
GetCursorScreenPos(wxDC
&dc
);
915 /** Draws the cursor.
916 @param active If true, draw a bold cursor to mark window as
918 @param translate optional translation of cursor coords on screen
920 void DrawCursor(wxDC
&dc
,
922 const wxPoint
& translate
= wxPoint(0,0));
924 /** This function finds an object belonging to a given screen
925 position. It assumes that Layout() has been called before.
926 @param pos screen position
927 @param cursorPos if non NULL, store cursor position in there
928 @param found if used, set this to true if we really found an
929 object, to false if we had to take the object near to it
930 @return pointer to the object
932 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
934 wxPoint
*cursorPos
= NULL
,
937 /** Called by the objects to update the update rectangle.
938 @param x horizontal coordinate to include in rectangle
939 @param y vertical coordinate to include in rectangle
941 void SetUpdateRect(CoordType x
, CoordType y
);
942 /** Called by the objects to update the update rectangle.
943 @param p a point to include in it
945 inline void SetUpdateRect(const wxPoint
&p
)
946 { SetUpdateRect(p
.x
,p
.y
); }
947 /// Invalidates the update rectangle.
948 void InvalidateUpdateRect(void) { m_UpdateRectValid
= false; }
949 /// Returns the update rectangle.
950 const wxRect
*GetUpdateRect(void) const { return &m_UpdateRect
; }
953 /**@name For exporting one object after another. */
955 /** Returns a pointer to the first line in the list. */
956 wxLayoutLine
*GetFirstLine(void)
958 wxASSERT(m_FirstLine
);
963 /// Begin selecting text.
964 void StartSelection(wxPoint cpos
= wxPoint(-1,-1));
965 // Continue selecting text
966 void ContinueSelection(wxPoint cpos
= wxPoint(-1,-1));
967 /// End selecting text.
968 void EndSelection(wxPoint cpos
= wxPoint(-1,-1));
969 /// Are we still selecting text?
970 bool IsSelecting(void);
971 bool IsSelected(const wxPoint
&cursor
);
973 /** Return the selection as a wxLayoutList.
974 @param invalidate if true, the selection will be invalidated after this and can no longer be used.
975 @return Another layout list object holding the selection, must be freed by caller
977 wxLayoutList
*GetSelection(class wxLayoutDataObject
*wxldo
= NULL
, bool invalidate
= TRUE
);
978 /// Delete selected bit
979 void DeleteSelection(void);
981 wxLayoutList
*Copy(const wxPoint
&from
= wxPoint(0,0),
982 const wxPoint
&to
= wxPoint(-1,-1));
984 /// starts highlighting of text for selections
985 void StartHighlighting(wxDC
&dc
);
986 /// ends highlighting of text for selections
987 void EndHighlighting(wxDC
&dc
);
989 /** Tests whether this layout line is selected and needs
991 @param line to test for
992 @param from set to first cursorpos to be highlighted (for returncode == -1)
993 @param to set to last cursorpos to be highlighted (for returncode == -1)
994 @return 0 = not selected, 1 = fully selected, -1 = partially
998 int IsSelected(const wxLayoutLine
*line
, CoordType
*from
, CoordType
*to
);
1000 void ApplyStyle(wxLayoutStyleInfo
*si
, wxDC
&dc
);
1001 #ifdef WXLAYOUT_DEBUG
1006 void InternalClear(void);
1007 /** Calculates the cursor position on the screen.
1009 void UpdateCursorScreenPos(wxDC
&dc
);
1011 /// The list of lines.
1012 wxLayoutLine
*m_FirstLine
;
1013 /// The update rectangle which needs to be refreshed:
1014 wxRect m_UpdateRect
;
1015 /// Is the update rectangle valid?
1016 bool m_UpdateRectValid
;
1017 /**@name Cursor Management */
1019 /// Where the text cursor (column,line) is.
1020 wxPoint m_CursorPos
;
1021 /// The size of the cursor.
1022 wxPoint m_CursorSize
;
1023 /// Where the cursor should be drawn.
1024 wxPoint m_CursorScreenPos
;
1025 /// The line where the cursor is.
1026 wxLayoutLine
*m_CursorLine
;
1029 /// A structure for the selection.
1032 Selection() { m_valid
= false; m_selecting
= false; }
1035 wxPoint m_CursorA
, m_CursorB
;
1037 /** @name Font parameters. */
1039 /// this object manages the fonts for us
1040 wxFontCache m_FontCache
;
1041 /// the default setting:
1042 wxLayoutStyleInfo m_DefaultSetting
;
1043 /// the current setting:
1044 wxLayoutStyleInfo m_CurrentSetting
;
1049 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1051 The wxLayoutDataObject for exporting data to the clipboard in our
1054 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1055 class wxLayoutDataObject
: public wxPrivateDataObject
1058 wxLayoutDataObject(void)
1060 SetId("application/wxlayoutlist");
1061 //m_format.SetAtom((GdkAtom) 222222);
1065 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1067 The wxLayoutPrintout object for printing within the wxWindows print
1070 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1071 /** This class implements a wxPrintout for printing a wxLayoutList within
1072 the wxWindows printing framework.
1074 class wxLayoutPrintout
: public wxPrintout
1078 @param llist pointer to the wxLayoutList to be printed
1079 @param title title for PS file or windows
1081 wxLayoutPrintout(wxLayoutList
*llist
,
1082 wxString
const & title
=
1083 "wxLayout Printout");
1085 ~wxLayoutPrintout();
1087 /** Function which prints the n-th page.
1088 @param page the page number to print
1089 @return bool true if we are not at end of document yet
1091 bool OnPrintPage(int page
);
1092 /** Checks whether page exists in document.
1093 @param page number of page
1094 @return true if page exists
1096 bool HasPage(int page
);
1098 /** Gets called from wxWindows to find out which pages are existing.
1099 I'm not totally sure about the parameters though.
1100 @param minPage the first page in the document
1101 @param maxPage the last page in the document
1102 @param selPageFrom the first page to be printed
1103 @param selPageTo the last page to be printed
1105 void GetPageInfo(int *minPage
, int *maxPage
,
1106 int *selPageFrom
, int *selPageTo
);
1108 /** This little function scales the DC so that the printout has
1109 roughly the same size as the output on screen.
1110 @param dc the wxDC to scale
1111 @return the scale that was applied
1113 float ScaleDC(wxDC
*dc
);
1116 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1119 /// The list to print.
1120 wxLayoutList
*m_llist
;
1121 /// Title for PS file or window.
1123 /// The real paper size.
1124 int m_PageHeight
, m_PageWidth
;
1125 /// How much we actually print per page.
1126 int m_PrintoutHeight
;
1127 /// How many pages we need to print.
1129 /// Top left corner where we start printing.