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 // use the wxWindows caret class instead of home grown cursor whenever possible
35 # undef WXLAYOUT_USE_CARET
36 # define WXLAYOUT_USE_CARET 1
39 // do not enable debug mode within Mahogany
40 #if defined(__WXDEBUG__) && ! defined(M_BASEDIR)
41 # define WXLAYOUT_DEBUG
45 # define WXLO_TRACE(x) wxLogDebug(x)
47 # define WXLO_TRACE(x)
50 #define WXLO_DEBUG_URECT 0
52 #ifndef WXLO_DEFAULTFONTSIZE
53 # define WXLO_DEFAULTFONTSIZE 12
57 # define WXLO_BITMAP_FORMAT wxBITMAP_TYPE_BMP
59 # define WXLO_BITMAP_FORMAT wxBITMAP_TYPE_PNG
62 /// Types of currently supported layout objects.
63 enum wxLayoutObjectType
65 /// illegal object type, should never appear
66 WXLO_TYPE_INVALID
= 0,
67 /// text object, containing normal text
69 /// command object, containing font or colour changes
71 /// icon object, any kind of image
75 /// Type used for coordinates in drawing. Must be signed.
76 typedef long CoordType
;
78 // Forward declarations.
83 class WXDLLEXPORT wxCaret
;
84 class WXDLLEXPORT wxColour
;
85 class WXDLLEXPORT wxDC
;
86 class WXDLLEXPORT wxFont
;
88 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
90 The wxLayout objects which make up the lines.
92 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
94 /** The base class defining the interface to each object which can be
95 part of the layout. Each object needs to draw itself and calculate
101 /** This structure can be used to contain data associated with the
103 It is refcounted, so the caller has to do a DecRef() on it
108 UserData() { m_refcount
= 1; }
109 inline void IncRef(void) { m_refcount
++; }
110 inline void DecRef(void) { m_refcount
--; if(m_refcount
== 0) delete this;}
111 inline void SetLabel(const wxString
&l
) { m_label
= l
; }
112 inline const wxString
& GetLabel(void) const { return m_label
; }
117 virtual ~UserData() { wxASSERT(m_refcount
== 0); }
118 /// prevents gcc from generating stupid warnings
119 friend class dummy_UserData
;
122 /// return the type of this object
123 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; }
124 /** Calculates the size of an object.
125 @param dc the wxDC to draw on
126 @param llist the wxLayoutList
128 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
) = 0;
131 @param dc the wxDC to draw on
132 @param coords where to draw the baseline of the object.
133 @param wxllist pointer to wxLayoutList
134 @param begin if !=-1, from which position on to highlight it
135 @param end if begin !=-1, how many positions to highlight it
137 virtual void Draw(wxDC
& /* dc */,
138 wxPoint
const & /* coords */,
139 wxLayoutList
*wxllist
,
140 CoordType begin
= -1,
141 CoordType end
= -1) { }
143 /** Calculates and returns the size of the object.
144 @param top where to store height above baseline
145 @param bottom where to store height below baseline
146 @return the size of the object's box in pixels
148 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const
149 { *top
= 0; *bottom
= 0; return wxPoint(0,0); }
151 /// Return just the width of the object on the screen.
152 virtual CoordType
GetWidth(void) const { return 0; }
153 /// returns the number of cursor positions occupied by this object
154 virtual CoordType
GetLength(void) const { return 1; }
155 /** Returns the cursor offset relating to the screen x position
156 relative to begin of object.
157 @param dc the wxDC to use for calculations
158 @param xpos relative x position from head of object
159 @return cursor coordinate offset
161 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const { return 0; }
164 wxLayoutObject() { m_UserData
= NULL
; }
165 /// delete the user data
166 virtual ~wxLayoutObject() { if(m_UserData
) m_UserData
->DecRef(); }
168 #ifdef WXLAYOUT_DEBUG
169 virtual void Debug(void);
172 /** Tells the object about some user data. This data is associated
173 with the object and will be deleted at destruction time.
174 It is reference counted.
176 void SetUserData(UserData
*data
)
179 m_UserData
->DecRef();
182 m_UserData
->IncRef();
185 /** Return the user data.
186 Increments the object's reference count. When no longer needed,
187 caller must call DecRef() on the pointer returned.
189 UserData
* GetUserData(void) const { if(m_UserData
) m_UserData
->IncRef(); return m_UserData
; }
191 /** Makes a copy of this object.
193 virtual wxLayoutObject
*Copy(void) = 0;
195 /** Clipboard support function. Read and write objects to
198 /// Writes the object to the string.
199 virtual void Write(wxString
&ostr
) = 0;
201 @param str stream to read from, will bee changed
202 @return true on success
204 static wxLayoutObject
*Read(wxString
&istr
);
207 /// returns TRUE if the object is shown on the screen (i.e. not cmd object)
208 bool IsVisibleObject() const { return GetType() != WXLO_TYPE_CMD
; }
211 /// optional data for application's use
212 UserData
*m_UserData
;
215 /// Define a list type of wxLayoutObject pointers.
216 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObject
);
218 /// An illegal iterator to save typing.
219 #define NULLIT (wxLayoutObjectList::iterator(NULL))
220 /// The iterator type.
221 typedef wxLayoutObjectList::iterator wxLOiterator
;
223 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
227 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
228 /** This class implements a wxLayoutObject holding plain text.
230 class wxLayoutObjectText
: public wxLayoutObject
233 wxLayoutObjectText(const wxString
&txt
= "");
235 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
236 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
237 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
238 wxLayoutList
*wxllist
,
239 CoordType begin
= -1,
241 /** Calculates and returns the size of the object.
242 @param top where to store height above baseline
243 @param bottom where to store height below baseline
244 @return the size of the object's box in pixels
246 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
247 /// Return just the width of the object on the screen.
248 virtual CoordType
GetWidth(void) const { return m_Width
; }
249 /** Returns the cursor offset relating to the screen x position
250 relative to begin of object.
251 @param dc the wxDC to use for calculations
252 @param xpos relative x position from head of object
253 @return cursor coordinate offset
255 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const;
257 virtual void Write(wxString
&ostr
);
258 static wxLayoutObjectText
*Read(wxString
&istr
);
260 #ifdef WXLAYOUT_DEBUG
261 virtual void Debug(void);
264 virtual CoordType
GetLength(void) const { return strlen(m_Text
.c_str()); }
267 wxString
& GetText(void) { return m_Text
; }
268 void SetText(wxString
const &text
) { m_Text
= text
; }
269 /** Makes a copy of this object.
271 virtual wxLayoutObject
*Copy(void);
274 /// size of the box containing text
275 long m_Width
, m_Height
;
276 /// Height above baseline.
278 /// Height below baseline.
282 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
286 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
287 /** This class implements a wxLayoutObject holding a graphic.
289 class wxLayoutObjectIcon
: public wxLayoutObject
292 wxLayoutObjectIcon(wxBitmap
*icon
= NULL
);
293 wxLayoutObjectIcon(wxBitmap
const &icon
);
295 ~wxLayoutObjectIcon() { if(m_Icon
) delete m_Icon
; }
297 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
298 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
299 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
300 wxLayoutList
*wxllist
,
301 CoordType begin
= -1,
304 /** Calculates and returns the size of the object.
305 @param top where to store height above baseline
306 @param bottom where to store height below baseline
307 @return the size of the object's box in pixels
309 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
310 /// Return just the width of the object on the screen.
311 virtual CoordType
GetWidth(void) const { return m_Icon
->GetWidth(); }
312 // return a pointer to the icon
313 wxBitmap
*GetIcon(void) const { return m_Icon
; }
314 /** Makes a copy of this object.
316 virtual wxLayoutObject
*Copy(void);
317 virtual void Write(wxString
&ostr
);
318 static wxLayoutObjectIcon
*Read(wxString
&istr
);
323 /** This structure holds all formatting information.
325 struct wxLayoutStyleInfo
327 wxLayoutStyleInfo(int ifamily
= -1,
333 wxColour
*bg
= NULL
);
334 wxLayoutStyleInfo
& operator=(const wxLayoutStyleInfo
&right
);
336 wxColour
& GetBGColour() { return m_bg
; }
338 /// Font change parameters.
339 int size
, family
, style
, weight
, underline
;
342 int m_fg_valid
, m_bg_valid
; // bool, but must be int!
346 class wxFontCacheEntry
349 wxFontCacheEntry(int family
, int size
, int style
, int weight
,
352 m_Family
= family
; m_Size
= size
; m_Style
= style
;
353 m_Weight
= weight
; m_Underline
= underline
;
354 m_Font
= new wxFont(m_Size
, m_Family
,
355 m_Style
, m_Weight
, m_Underline
);
357 bool Matches(int family
, int size
, int style
, int weight
,
358 bool underline
) const
360 return size
== m_Size
&& family
== m_Family
361 && style
== m_Style
&& weight
== m_Weight
362 && underline
== m_Underline
;
364 wxFont
& GetFont(void) { return *m_Font
; }
372 // VZ: I wonder why it doesn't use wxLayoutStyleInfo instead of those?
373 int m_Family
, m_Size
, m_Style
, m_Weight
;
377 KBLIST_DEFINE(wxFCEList
, wxFontCacheEntry
);
382 wxFont
& GetFont(int family
, int size
, int style
, int weight
,
384 wxFont
& GetFont(wxLayoutStyleInfo
const &si
)
386 return GetFont(si
.family
, si
.size
, si
.style
, si
.weight
,
390 wxFCEList m_FontList
;
393 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
397 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
398 /** This class implements a wxLayoutObject holding style change commands.
400 class wxLayoutObjectCmd
: public wxLayoutObject
403 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
404 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
405 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
406 wxLayoutList
*wxllist
,
407 CoordType begin
= -1,
409 wxLayoutObjectCmd(int family
= -1,
415 wxColour
*bg
= NULL
);
416 ~wxLayoutObjectCmd();
417 /** Stores the current style in the styleinfo structure */
418 wxLayoutStyleInfo
* GetStyle(void) const;
419 /** Makes a copy of this object.
421 virtual wxLayoutObject
*Copy(void);
422 virtual void Write(wxString
&ostr
);
423 static wxLayoutObjectCmd
*Read(wxString
&istr
);
425 wxLayoutStyleInfo
*m_StyleInfo
;
428 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
430 The wxLayoutLine object
432 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
434 /** This class represents a single line of objects to be displayed.
435 It knows its height and total size and whether it needs to be
437 It has pointers to its first and next line so it can automatically
438 update them as needed.
444 @param prev pointer to previous line or NULL
445 @param next pointer to following line or NULL
446 @param llist pointer to layout list
448 wxLayoutLine(wxLayoutLine
*prev
, wxLayoutList
*llist
);
449 /** This function inserts a new object at cursor position xpos.
450 @param xpos where to insert new object
451 @param obj the object to insert
452 @return true if that xpos existed and the object was inserted
454 bool Insert(CoordType xpos
, wxLayoutObject
*obj
);
456 /** This function inserts text at cursor position xpos.
457 @param xpos where to insert
458 @param text the text to insert
459 @return true if that xpos existed and the object was inserted
461 bool Insert(CoordType xpos
, const wxString
& text
);
463 /** This function appends an object to the line.
464 @param obj the object to insert
466 void Append(wxLayoutObject
* obj
)
470 m_ObjectList
.push_back(obj
);
471 m_Length
+= obj
->GetLength();
474 /** This function appens the next line to this, i.e. joins the two
477 void MergeNextLine(wxLayoutList
*llist
);
479 /** This function deletes npos cursor positions from position xpos.
480 @param xpos where to delete
481 @param npos how many positions
482 @return number of positions still to be deleted
484 CoordType
Delete(CoordType xpos
, CoordType npos
);
486 /** This function breaks the line at a given cursor position.
487 @param xpos where to break it
488 @return pointer to the new line object replacing the old one
490 wxLayoutLine
*Break(CoordType xpos
, wxLayoutList
*llist
);
492 /** Deletes the next word from this position, including leading
494 This function does not delete over font changes, i.e. a word
495 with formatting instructions in the middle of it is treated as
496 two (three actually!) words. In fact, if the cursor is on a non-text object, that
497 one is treated as a word.
498 @param xpos from where to delete
499 @return true if a word was deleted
501 bool DeleteWord(CoordType npos
);
503 /** Finds a suitable position left to the given column to break the
505 @param column we want to break the line to the left of this
506 @return column for breaking line or -1 if no suitable location found
508 CoordType
GetWrapPosition(CoordType column
);
510 /** Finds the object which covers the cursor position xpos in this
512 @param xpos the column number
513 @param offset where to store the difference between xpos and
515 @return iterator to the object or NULLIT
517 wxLayoutObjectList::iterator
FindObject(CoordType xpos
, CoordType
520 /** Finds the object which covers the screen position xpos in this
522 @param dc the wxDC to use for calculations
523 @param llist the layout list to which this line belongs
524 @param xpos the screen x coordinate
525 @param offset where to store the difference between xpos and
527 @return iterator to the object or NULLIT
529 wxLayoutObjectList::iterator
FindObjectScreen(wxDC
&dc
,
533 bool *found
= NULL
) const ;
535 /** Finds text in this line.
536 @param needle the text to find
537 @param xpos the position where to start the search
538 @return the cursoor coord where it was found or -1
540 CoordType
FindText(const wxString
&needle
, CoordType xpos
= 0) const;
542 /** Get the first object in the list. This is used by the wxlparser
543 functions to export the list.
544 @return iterator to the first object
546 wxLayoutObjectList::iterator
GetFirstObject(void) const
548 return m_ObjectList
.begin();
551 /** Get the last object in the list.
553 wxLayoutObjectList::iterator
GetLastObject(void) const
555 return m_ObjectList
.tail();
558 /** Deletes this line, returns pointer to next line.
559 @param update If true, update all following lines.
561 wxLayoutLine
*DeleteLine(bool update
, wxLayoutList
*llist
);
563 /**@name Cursor Management */
565 /** Return the line number of this line.
566 @return the line number
568 inline CoordType
GetLineNumber(void) const { return m_LineNumber
; }
569 /** Return the length of the line.
570 @return line lenght in cursor positions
572 inline CoordType
GetLength(void) const { return m_Length
; }
575 /**@name Drawing and Layout */
577 /** Draws the line on a wxDC.
578 @param dc the wxDC to draw on
579 @param llist the wxLayoutList
580 @param offset an optional offset to shift printout
584 const wxPoint
&offset
= wxPoint(0,0)) const;
586 /** Recalculates the positions of objects and the height of the
588 @param dc the wxDC to draw on
589 @param llist th e wxLayoutList
590 @param cursorPos if not NULL, set cursor screen position in there
591 @param cursorSize if not cursorPos != NULL, set cursor size in there
592 @param cursorStyle if non NULL where to store styleinfo for cursor pos
593 @param cx if cursorPos != NULL, the cursor x position
594 @param suppressStyleUpdate FALSe normally, only to suppress updating of m_StyleInfo
596 void Layout(wxDC
&dc
,
598 wxPoint
*cursorPos
= NULL
,
599 wxPoint
*cursorSize
= NULL
,
600 wxLayoutStyleInfo
*cursorStyle
= NULL
,
602 bool suppressStyleUpdate
= FALSE
);
603 /** This function finds an object belonging to a given cursor
604 position. It assumes that Layout() has been called before.
605 @param dc the wxDC to use for calculations
606 @param xpos screen x position
607 @param found if non-NULL set to false if we return the last
608 object before the cursor, to true if we really have an object
610 @return pointer to the object
612 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
615 /** This sets the style info for the beginning of this line.
616 @param si styleinfo structure
618 void ApplyStyle(const wxLayoutStyleInfo
&si
)
619 { m_StyleInfo
= si
; }
623 /**@name List traversal */
625 /// Returns pointer to next line.
626 wxLayoutLine
*GetNextLine(void) const { return m_Next
; }
627 /// Returns pointer to previous line.
628 wxLayoutLine
*GetPreviousLine(void) const { return m_Previous
; }
629 /// Sets the link to the next line.
630 void SetNext(wxLayoutLine
*next
)
631 { m_Next
= next
; if(next
) next
->m_Previous
= this; }
632 /// Sets the link to the previous line.
633 void SetPrevious(wxLayoutLine
*previous
)
634 { m_Previous
= previous
; if(previous
) previous
->m_Next
= this; }
637 /// Returns the position of this line on the canvas.
638 wxPoint
GetPosition(void) const { return m_Position
; }
639 /// Returns the height of this line.
640 CoordType
GetHeight(void) const { return m_Height
; }
641 /// Returns the width of this line.
642 CoordType
GetWidth(void) const { return m_Width
; }
643 /** This will recalculate the position and size of this line.
644 If called recursively it will abort if the position of an
645 object is unchanged, assuming that none of the following
646 objects need to move.
647 @param recurse if greater 0 then it will be used as the
648 minimum(!) recursion level, continue with all lines till the end of
649 the list or until the coordinates no longer changed.
651 void RecalculatePositions(int recurse
, wxLayoutList
*llist
);
652 /// Recalculates the position of this line on the canvas.
653 wxPoint
RecalculatePosition(wxLayoutList
*llist
);
655 /** Copies the contents of this line to another wxLayoutList
656 @param llist the wxLayoutList destination
657 @param from x cursor coordinate where to start
658 @param to x cursor coordinate where to stop, -1 for end of line
660 void Copy(wxLayoutList
*llist
,
664 #ifdef WXLAYOUT_DEBUG
667 wxLayoutStyleInfo
const & GetStyleInfo() const { return m_StyleInfo
; }
669 /// Returns dirty state
670 bool IsDirty(void) const { return m_Dirty
; }
671 /** Marks this line as diry.
672 @param left xpos from where it is dirty or -1 for all
674 void MarkDirty(CoordType left
= -1)
678 if ( m_updateLeft
== -1 || left
< m_updateLeft
)
684 /** Marks the following lines as dirty.
685 @param recurse if -1 recurse to end of list, otherwise depth of recursion.
687 void MarkNextDirty(int recurse
= 0);
688 /// Reset the dirty flag
689 void MarkClean() { m_Dirty
= false; m_updateLeft
= -1; }
692 /// Destructor is private. Use DeleteLine() to remove it.
695 /**@name Functions to let the lines synchronise with each other. */
697 /** Sets the height of this line. Will mark following lines as
699 @param height new height
701 void SetHeight(CoordType height
, wxLayoutList
*llist
)
702 { m_Height
= height
; RecalculatePositions(true, llist
); }
704 /** Moves the linenumbers one on, because a line has been inserted
706 @param delta either +1 or -1
708 void MoveLines(int delta
)
710 m_LineNumber
+= delta
;
711 if(m_Next
) m_Next
->MoveLines(delta
);
716 CoordType m_LineNumber
;
717 /// The line length in cursor positions.
719 /// The total height of the line.
721 /// The total width of the line on screen.
723 /// The baseline for drawing objects
724 CoordType m_BaseLine
;
725 /// The position on the canvas.
727 /// The list of objects
728 wxLayoutObjectList m_ObjectList
;
729 /// Have we been changed since the last layout?
731 /// The coordinate of the left boundary of the update rectangle (if m_Dirty)
732 CoordType m_updateLeft
;
733 /// Pointer to previous line if it exists.
734 wxLayoutLine
*m_Previous
;
735 /// Pointer to next line if it exists.
736 wxLayoutLine
*m_Next
;
737 /// A StyleInfo structure, holding the current settings.
738 wxLayoutStyleInfo m_StyleInfo
;
739 /// Just to suppress gcc compiler warnings.
742 wxLayoutLine(const wxLayoutLine
&);
746 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
748 The wxLayoutList object
750 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
751 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
752 higher level of abstraction for the text and can generally be considered
753 as representing "the text".
763 #ifdef WXLAYOUT_USE_CARET
764 /// give us the pointer to the caret to use
765 void SetCaret(wxCaret
*caret
) { m_caret
= caret
; }
766 #endif // WXLAYOUT_USE_CARET
769 void Clear(int family
= wxROMAN
,
770 int size
=WXLO_DEFAULTFONTSIZE
,
776 /// Empty: clear the list but leave font settings.
779 /**@name Cursor Management */
781 /** Set new cursor position.
782 @param p new position
783 @return bool if it could be set
785 bool MoveCursorTo(wxPoint
const &p
);
786 /** Move cursor up or down.
788 @return bool if it could be moved
790 bool MoveCursorVertically(int n
);
791 /** Move cursor left or right.
792 @param n = number of positions to move
793 @return bool if it could be moved
795 bool MoveCursorHorizontally(int n
);
796 /** Move cursor to the left or right counting in words
797 @param n = number of positions in words
798 @param untilNext: puts the cursor at the start of the next word if true,
799 leaves it at the end of the current one otherwise
800 @return bool if it could be moved
802 bool MoveCursorWord(int n
, bool untilNext
= true);
804 /// Move cursor to end of line.
805 void MoveCursorToEndOfLine(void)
807 wxASSERT(m_CursorLine
);
808 MoveCursorHorizontally(m_CursorLine
->GetLength()-m_CursorPos
.x
);
811 /// Move cursor to the start of line.
812 void MoveCursorToBeginOfLine(void)
813 { MoveCursorHorizontally(-m_CursorPos
.x
); }
815 /// get the number of lines in the list
816 size_t GetNumLines() const { return m_numLines
; }
818 /// Returns current cursor position.
819 const wxPoint
&GetCursorPos(wxDC
&dc
) const { return m_CursorPos
; }
820 const wxPoint
&GetCursorPos() const { return m_CursorPos
; }
822 /// move cursor to the end of text
823 void MoveCursorToEnd(void)
825 MoveCursorTo(wxPoint(0, GetNumLines() - 1));
826 MoveCursorToEndOfLine();
831 /**@name Editing functions.
832 All of these functions return true on success and false on
835 /// Insert text at current cursor position.
836 bool Insert(wxString
const &text
);
837 /// Insert some other object at current cursor position.
838 bool Insert(wxLayoutObject
*obj
);
839 /// Inserts objects at current cursor positions
840 bool Insert(wxLayoutList
*llist
);
842 /// Inserts a linebreak at current cursor position.
843 bool LineBreak(void);
844 /** Wraps the current line. Searches to the left of the cursor to
845 break the line. Does nothing if the cursor position is before
846 the break position parameter.
847 @param column the break position for the line, maximum length
848 @return true if line got broken
850 bool WrapLine(CoordType column
);
851 /** This function deletes npos cursor positions.
852 @param npos how many positions
853 @return true if everything got deleted
855 bool Delete(CoordType npos
);
857 /** Delete the next n lines.
858 @param n how many lines to delete
859 @return how many it could not delete
861 int DeleteLines(int n
);
863 /// Delete to end of line.
864 void DeleteToEndOfLine(void)
866 wxASSERT(m_CursorLine
);
867 Delete(m_CursorLine
->GetLength()-m_CursorPos
.x
);
869 /// Delete to begin of line.
870 void DeleteToBeginOfLine(void)
872 wxASSERT(m_CursorLine
);
873 CoordType n
= m_CursorPos
.x
;
874 #ifdef WXLAYOUT_DEBUG
875 wxASSERT(MoveCursorHorizontally(-n
));
877 MoveCursorHorizontally(-n
);
882 /** Delete the next word.
884 void DeleteWord(void)
886 wxASSERT(m_CursorLine
);
887 m_CursorLine
->DeleteWord(m_CursorPos
.x
);
892 /** Finds text in this list.
893 @param needle the text to find
894 @param cpos the position where to start the search
895 @return the cursor coord where it was found or (-1,-1)
897 wxPoint
FindText(const wxString
&needle
, const wxPoint
&cpos
= wxPoint(0,0)) const;
899 /**@name Formatting options */
901 /// sets font parameters
902 void SetFont(int family
, int size
, int style
,
903 int weight
, int underline
,
906 /// sets font parameters, colours by name
907 void SetFont(int family
=-1, int size
= -1, int style
=-1,
908 int weight
=-1, int underline
= -1,
909 char const *fg
= NULL
,
910 char const *bg
= NULL
);
911 /// changes to the next larger font size
912 inline void SetFontLarger(void)
913 { SetFont(-1,(12*m_CurrentStyleInfo
.size
)/10); }
914 /// changes to the next smaller font size
915 inline void SetFontSmaller(void)
916 { SetFont(-1,(10*m_CurrentStyleInfo
.size
)/12); }
919 inline void SetFontFamily(int family
) { SetFont(family
); }
921 inline void SetFontSize(int size
) { SetFont(-1,size
); }
923 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
925 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
926 /// toggle underline flag
927 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
928 /// set font colours by name
929 inline void SetFontColour(char const *fg
, char const *bg
= NULL
)
930 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
931 /// set font colours by colour
932 inline void SetFontColour(wxColour
*fg
, wxColour
*bg
= NULL
)
933 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
936 Returns a pointer to the default settings.
937 This is only valid temporarily and should not be stored
939 @return the default settings of the list
941 wxLayoutStyleInfo
&GetDefaultStyleInfo(void) { return m_DefaultStyleInfo
; }
942 wxLayoutStyleInfo
&GetStyleInfo(void) { return m_CurrentStyleInfo
; }
943 const wxLayoutStyleInfo
&GetStyleInfo(void) const { return m_CurrentStyleInfo
; }
944 const wxLayoutStyleInfo
&GetCursorStyleInfo(void) const { return m_CursorStyleInfo
; }
946 /// is the current font underlined?
947 bool IsFontUnderlined() const { return GetCursorStyleInfo().underline
!= 0; }
948 /// is the current font bold?
949 bool IsFontBold() const { return GetCursorStyleInfo().weight
== wxBOLD
; }
950 /// is the current font italic?
951 bool IsFontItalic() const { return GetCursorStyleInfo().style
== wxITALIC
; }
953 /// set underline if it was off, turn it off if it was on
954 void ToggleFontUnderline()
955 { SetFontUnderline(!IsFontUnderlined()); }
957 /// make font bold if it was normal or make it normal if it was bold
958 void ToggleFontWeight()
959 { SetFontWeight(IsFontBold() ? wxNORMAL
: wxBOLD
); }
961 /// make font italic if it was normal or make it normal if it was italic
962 void ToggleFontItalics()
963 { SetFontStyle(IsFontItalic() ? wxNORMAL
: wxITALIC
); }
969 /** Draws the complete list on a wxDC.
970 @param dc the wxDC to draw on
971 @param offset an optional offset to shift printout
972 @param top optional y coordinate where to start drawing
973 @param bottom optional y coordinate where to stop drawing
976 const wxPoint
&offset
= wxPoint(0,0),
977 CoordType top
= -1, CoordType bottom
= -1);
979 /** Calculates new layout for the list, like Draw() but does not
981 @param dc the wxDC to draw on
982 @param bottom optional y coordinate where to stop calculating
983 @param forceAll force re-layout of all lines
984 @param cpos Can hold a cursorposition, and will be overwritten
985 with the corresponding DC position.
986 @param csize Will hold the cursor size relating to cpos.
988 void Layout(wxDC
&dc
, CoordType bottom
= -1, bool forceAll
= false,
989 wxPoint
*cpos
= NULL
,
990 wxPoint
*csize
= NULL
);
992 /** Returns the screen coordinates relating to a given cursor
993 position and the size of the cursor at that position.
994 @param dc for which to calculate it
995 @param cpos Cursor position to look for.
996 @param csize If non-NULL, will be set to the cursor size.
997 @return The cursor position on the DC.
999 wxPoint
GetScreenPos(wxDC
&dc
, const wxPoint
&cpos
, wxPoint
*csize
= NULL
);
1001 /** Calculates new sizes for everything in the list, like Layout()
1002 but this is needed after the list got changed.
1003 @param dc the wxDC to draw on
1004 @param bottom optional y coordinate where to stop calculating
1006 void Recalculate(wxDC
&dc
, CoordType bottom
= -1);
1008 /** Returns the size of the list in screen coordinates.
1009 The return value only makes sense after the list has been
1011 @return a wxPoint holding the maximal x/y coordinates used for
1014 wxPoint
GetSize(void) const;
1016 /** Returns the cursor position on the screen.
1017 @return cursor position in pixels
1019 wxPoint
GetCursorScreenPos(wxDC
&dc
);
1021 /** Draws the cursor.
1022 @param active If true, draw a bold cursor to mark window as
1024 @param translate optional translation of cursor coords on screen
1026 void DrawCursor(wxDC
&dc
,
1028 const wxPoint
& translate
= wxPoint(0,0));
1030 /** This function finds an object belonging to a given screen
1031 position. It assumes that Layout() has been called before.
1032 @param pos screen position
1033 @param cursorPos if non NULL, store cursor position in there
1034 @param found if used, set this to true if we really found an
1035 object, to false if we had to take the object near to it
1036 @return pointer to the object
1038 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
1040 wxPoint
*cursorPos
= NULL
,
1041 bool *found
= NULL
);
1043 /** Called by the objects to update the update rectangle.
1044 @param x horizontal coordinate to include in rectangle
1045 @param y vertical coordinate to include in rectangle
1047 void SetUpdateRect(CoordType x
, CoordType y
);
1048 /** Called by the objects to update the update rectangle.
1049 @param p a point to include in it
1051 void SetUpdateRect(const wxPoint
&p
)
1052 { SetUpdateRect(p
.x
,p
.y
); }
1053 /// adds the cursor position to the update rectangle
1054 void AddCursorPosToUpdateRect()
1056 #ifndef WXLAYOUT_USE_CARET
1057 SetUpdateRect(m_CursorScreenPos
);
1058 SetUpdateRect(m_CursorScreenPos
+m_CursorSize
);
1059 //#else - the caret will take care of refreshing itself
1060 #endif // !WXLAYOUT_USE_CARET
1062 /// Invalidates the update rectangle.
1063 void InvalidateUpdateRect(void) { m_UpdateRectValid
= false; }
1064 /// Returns the update rectangle.
1065 const wxRect
*GetUpdateRect(void) const { return &m_UpdateRect
; }
1068 /// get the current cursor size
1069 const wxPoint
& GetCursorSize() const { return m_CursorSize
; }
1071 /**@name For exporting one object after another. */
1073 /** Returns a pointer to the first line in the list. */
1074 wxLayoutLine
*GetFirstLine(void)
1076 wxASSERT(m_FirstLine
);
1081 /// Begin selecting text
1082 void StartSelection(const wxPoint
& cpos
= wxPoint(-1,-1),
1083 const wxPoint
& spos
= wxPoint(-1,-1));
1084 // Continue selecting text
1085 void ContinueSelection(const wxPoint
& cpos
= wxPoint(-1,-1),
1086 const wxPoint
& spos
= wxPoint(-1,-1));
1087 /// End selecting text.
1088 void EndSelection(const wxPoint
& cpos
= wxPoint(-1,-1),
1089 const wxPoint
& spos
= wxPoint(-1,-1));
1090 /// Discard the current selection
1091 void DiscardSelection();
1092 /// Are we still selecting text?
1093 bool IsSelecting(void) const;
1094 /// Is the given point (text coords) selected?
1095 bool IsSelected(const wxPoint
&cursor
) const;
1096 /// Do we have a non null selection?
1097 bool HasSelection() const
1098 { return m_Selection
.m_valid
|| m_Selection
.m_selecting
; }
1100 /** Return the selection as a wxLayoutList.
1101 @param invalidate if true, the selection will be invalidated after this and can no longer be used.
1102 @return Another layout list object holding the selection, must be freed by caller
1104 wxLayoutList
*GetSelection(class wxLayoutDataObject
*wxldo
= NULL
, bool invalidate
= TRUE
);
1105 /// Delete selected bit
1106 void DeleteSelection(void);
1108 wxLayoutList
*Copy(const wxPoint
&from
= wxPoint(0,0),
1109 const wxPoint
&to
= wxPoint(-1,-1));
1111 /// starts highlighting of text for selections
1112 void StartHighlighting(wxDC
&dc
);
1113 /// ends highlighting of text for selections
1114 void EndHighlighting(wxDC
&dc
);
1116 /** Tests whether this layout line is selected and needs
1118 @param line to test for
1119 @param from set to first cursorpos to be highlighted (for returncode == -1)
1120 @param to set to last cursorpos to be highlighted (for returncode == -1)
1121 @return 0 = not selected, 1 = fully selected, -1 = partially
1125 int IsSelected(const wxLayoutLine
*line
, CoordType
*from
, CoordType
*to
);
1127 void ApplyStyle(wxLayoutStyleInfo
const &si
, wxDC
&dc
);
1128 #ifdef WXLAYOUT_DEBUG
1132 // for wxLayoutLine usage only
1133 void IncNumLines() { m_numLines
++; }
1134 void DecNumLines() { m_numLines
--; }
1136 /// get the line by number
1137 wxLayoutLine
*GetLine(CoordType index
) const
1139 wxASSERT_MSG( (0 <= index
) && (index
< (CoordType
)m_numLines
),
1143 CoordType n
= index
;
1144 for ( line
= m_FirstLine
; line
&& n
-- > 0; line
= line
->GetNextLine() )
1149 // should be the right one
1150 wxASSERT( line
->GetLineNumber() == index
);
1158 void InternalClear(void);
1160 /// The list of lines.
1161 wxLayoutLine
*m_FirstLine
;
1162 /// The number of lines in the list (store instead recalculating for speed)
1165 /// The update rectangle which needs to be refreshed:
1166 wxRect m_UpdateRect
;
1167 /// Is the update rectangle valid?
1168 bool m_UpdateRectValid
;
1170 /**@name Cursor Management */
1172 /// Where the text cursor (column,line) is.
1173 wxPoint m_CursorPos
;
1174 /// Where the cursor should be drawn.
1175 wxPoint m_CursorScreenPos
;
1176 /// The line where the cursor is.
1177 wxLayoutLine
*m_CursorLine
;
1178 /// The size of the cursor.
1179 wxPoint m_CursorSize
;
1180 /// Has the cursor moved (is m_CursorScreenPos up to date)?
1182 #ifdef WXLAYOUT_USE_CARET
1185 #endif // WXLAYOUT_USE_CARET
1188 /// selection.state and begin/end coordinates
1191 Selection() { m_valid
= m_selecting
= m_discarded
= false; }
1195 bool m_discarded
; // may be TRUE only until the next redraw
1197 // returns true if we already have the screen coordinates of the
1198 // selection start and end
1199 bool HasValidScreenCoords() const
1200 { return m_ScreenA
.x
!= -1 && m_ScreenB
.x
!= -1; }
1202 // the start and end of the selection coordinates in pixels
1203 wxPoint m_ScreenA
, m_ScreenB
;
1205 // these coordinates are in text positions, not in pixels
1206 wxPoint m_CursorA
, m_CursorB
;
1208 /** @name Font parameters. */
1210 /// this object manages the fonts for us
1211 wxFontCache m_FontCache
;
1212 /// the default setting:
1213 wxLayoutStyleInfo m_DefaultStyleInfo
;
1214 /// the current setting:
1215 wxLayoutStyleInfo m_CurrentStyleInfo
;
1216 /// the current setting:
1217 wxLayoutStyleInfo m_CursorStyleInfo
;
1221 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1223 The wxLayoutDataObject for exporting data to the clipboard in our
1226 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1227 class wxLayoutDataObject
: public wxPrivateDataObject
1230 wxLayoutDataObject(void)
1232 SetId("application/wxlayoutlist");
1233 //m_format.SetAtom((GdkAtom) 222222);
1237 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1239 The wxLayoutPrintout object for printing within the wxWindows print
1242 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1243 /** This class implements a wxPrintout for printing a wxLayoutList within
1244 the wxWindows printing framework.
1246 class wxLayoutPrintout
: public wxPrintout
1250 @param llist pointer to the wxLayoutList to be printed
1251 @param title title for PS file or windows
1253 wxLayoutPrintout(wxLayoutList
*llist
,
1254 wxString
const & title
=
1255 "wxLayout Printout");
1257 ~wxLayoutPrintout();
1259 /** Function which prints the n-th page.
1260 @param page the page number to print
1261 @return bool true if we are not at end of document yet
1263 bool OnPrintPage(int page
);
1264 /** Checks whether page exists in document.
1265 @param page number of page
1266 @return true if page exists
1268 bool HasPage(int page
);
1270 /** Gets called from wxWindows to find out which pages are existing.
1271 I'm not totally sure about the parameters though.
1272 @param minPage the first page in the document
1273 @param maxPage the last page in the document
1274 @param selPageFrom the first page to be printed
1275 @param selPageTo the last page to be printed
1277 void GetPageInfo(int *minPage
, int *maxPage
,
1278 int *selPageFrom
, int *selPageTo
);
1280 /** This little function scales the DC so that the printout has
1281 roughly the same size as the output on screen.
1282 @param dc the wxDC to scale
1283 @return the scale that was applied
1285 float ScaleDC(wxDC
*dc
);
1288 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1291 /// The list to print.
1292 wxLayoutList
*m_llist
;
1293 /// Title for PS file or window.
1295 /// The real paper size.
1296 int m_PageHeight
, m_PageWidth
;
1297 /// How much we actually print per page.
1298 int m_PrintoutHeight
;
1299 /// How many pages we need to print.
1301 /// Top left corner where we start printing.