1 /*-*- c++ -*-********************************************************
2 * wxLayoutList.h - a formatted text rendering engine for wxWindows *
4 * (C) 1999 by Karsten Ballüder (ballueder@gmx.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
31 #else // for Mahogany only:
35 // use the wxWindows caret class instead of home grown cursor whenever possible
37 # undef WXLAYOUT_USE_CARET
38 # define WXLAYOUT_USE_CARET 1
41 // do not enable debug mode within Mahogany
42 #if defined(__WXDEBUG__) && ! defined(M_BASEDIR)
43 # define WXLAYOUT_DEBUG
47 # define WXLO_TRACE(x) wxLogDebug(x)
49 # define WXLO_TRACE(x)
52 #define WXLO_DEBUG_URECT 0
54 #ifndef WXLO_DEFAULTFONTSIZE
55 # define WXLO_DEFAULTFONTSIZE 12
59 # define WXLO_BITMAP_FORMAT wxBITMAP_TYPE_BMP
61 # define WXLO_BITMAP_FORMAT wxBITMAP_TYPE_PNG
64 /// Types of currently supported layout objects.
65 enum wxLayoutObjectType
67 /// illegal object type, should never appear
68 WXLO_TYPE_INVALID
= 0,
69 /// text object, containing normal text
71 /// command object, containing font or colour changes
73 /// icon object, any kind of image
77 /// Type used for coordinates in drawing. Must be signed.
78 typedef long CoordType
;
80 // Forward declarations.
85 class WXDLLEXPORT wxCaret
;
86 class WXDLLEXPORT wxColour
;
87 class WXDLLEXPORT wxDC
;
88 class WXDLLEXPORT wxFont
;
90 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
92 The wxLayout objects which make up the lines.
94 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
96 /** The base class defining the interface to each object which can be
97 part of the layout. Each object needs to draw itself and calculate
106 /** This structure can be used to contain data associated with the
108 It is refcounted, so the caller has to do a DecRef() on it
113 UserData() { m_refcount
= 1; }
114 inline void IncRef(void) { m_refcount
++; }
115 inline void DecRef(void) { m_refcount
--; if(m_refcount
== 0) delete this;}
116 inline void SetLabel(const wxString
&l
) { m_label
= l
; }
117 inline const wxString
& GetLabel(void) const { return m_label
; }
122 virtual ~UserData() { wxASSERT(m_refcount
== 0); }
123 /// prevents gcc from generating stupid warnings
124 friend class dummy_UserData
;
127 /// return the type of this object
128 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; }
129 /** Calculates the size of an object.
130 @param dc the wxDC to draw on
131 @param llist the wxLayoutList
133 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
) = 0;
136 @param dc the wxDC to draw on
137 @param coords where to draw the baseline of the object.
138 @param wxllist pointer to wxLayoutList
139 @param begin if !=-1, from which position on to highlight it
140 @param end if begin !=-1, how many positions to highlight it
142 virtual void Draw(wxDC
& /* dc */,
143 wxPoint
const & /* coords */,
144 wxLayoutList
*wxllist
,
145 CoordType begin
= -1,
146 CoordType end
= -1) { }
148 /** Calculates and returns the size of the object.
149 @param top where to store height above baseline
150 @param bottom where to store height below baseline
151 @return the size of the object's box in pixels
153 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const
154 { *top
= 0; *bottom
= 0; return wxPoint(0,0); }
156 /// Return just the width of the object on the screen.
157 virtual CoordType
GetWidth(void) const { return 0; }
158 /// returns the number of cursor positions occupied by this object
159 virtual CoordType
GetLength(void) const { return 1; }
160 /** Returns the cursor offset relating to the screen x position
161 relative to begin of object.
162 @param dc the wxDC to use for calculations
163 @param xpos relative x position from head of object
164 @return cursor coordinate offset
166 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const { return 0; }
169 wxLayoutObject() { m_UserData
= NULL
; }
170 /// delete the user data
171 virtual ~wxLayoutObject() { if(m_UserData
) m_UserData
->DecRef(); }
173 #ifdef WXLAYOUT_DEBUG
174 virtual void Debug(void);
177 /** Tells the object about some user data. This data is associated
178 with the object and will be deleted at destruction time.
179 It is reference counted.
181 void SetUserData(UserData
*data
)
184 m_UserData
->DecRef();
187 m_UserData
->IncRef();
190 /** Return the user data.
191 Increments the object's reference count. When no longer needed,
192 caller must call DecRef() on the pointer returned.
194 UserData
* GetUserData(void) const { if(m_UserData
) m_UserData
->IncRef(); return m_UserData
; }
196 /** Makes a copy of this object.
198 virtual wxLayoutObject
*Copy(void) = 0;
200 /** Clipboard support function. Read and write objects to
203 /// Writes the object to the string.
204 virtual void Write(wxString
&ostr
) = 0;
206 @param str stream to read from, will bee changed
207 @return true on success
209 static wxLayoutObject
*Read(wxString
&istr
);
212 /// returns TRUE if the object is shown on the screen (i.e. not cmd object)
213 bool IsVisibleObject() const { return GetType() != WXLO_TYPE_CMD
; }
216 /// optional data for application's use
217 UserData
*m_UserData
;
218 #if defined (M_BASEDIR) && defined (DEBUG)
219 MOBJECT_NAME(wxLayoutObject
)
223 /// Define a list type of wxLayoutObject pointers.
224 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObject
);
226 /// An illegal iterator to save typing.
227 #define NULLIT (wxLayoutObjectList::iterator(NULL))
228 /// The iterator type.
229 typedef wxLayoutObjectList::iterator wxLOiterator
;
231 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
235 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
236 /** This class implements a wxLayoutObject holding plain text.
238 class wxLayoutObjectText
: public wxLayoutObject
241 wxLayoutObjectText(const wxString
&txt
= "");
243 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
244 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
245 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
246 wxLayoutList
*wxllist
,
247 CoordType begin
= -1,
249 /** Calculates and returns the size of the object.
250 @param top where to store height above baseline
251 @param bottom where to store height below baseline
252 @return the size of the object's box in pixels
254 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
255 /// Return just the width of the object on the screen.
256 virtual CoordType
GetWidth(void) const { return m_Width
; }
257 /** Returns the cursor offset relating to the screen x position
258 relative to begin of object.
259 @param dc the wxDC to use for calculations
260 @param xpos relative x position from head of object
261 @return cursor coordinate offset
263 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const;
265 virtual void Write(wxString
&ostr
);
266 static wxLayoutObjectText
*Read(wxString
&istr
);
268 #ifdef WXLAYOUT_DEBUG
269 virtual void Debug(void);
272 virtual CoordType
GetLength(void) const { return strlen(m_Text
.c_str()); }
275 wxString
& GetText(void) { return m_Text
; }
276 void SetText(wxString
const &text
) { m_Text
= text
; }
277 /** Makes a copy of this object.
279 virtual wxLayoutObject
*Copy(void);
282 /// size of the box containing text
283 long m_Width
, m_Height
;
284 /// Height above baseline.
286 /// Height below baseline.
290 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
294 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
295 /** This class implements a wxLayoutObject holding a graphic.
297 class wxLayoutObjectIcon
: public wxLayoutObject
300 wxLayoutObjectIcon(wxBitmap
*icon
= NULL
);
301 wxLayoutObjectIcon(wxBitmap
const &icon
);
303 ~wxLayoutObjectIcon() { if(m_Icon
) delete m_Icon
; }
305 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
306 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
307 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
308 wxLayoutList
*wxllist
,
309 CoordType begin
= -1,
312 /** Calculates and returns the size of the object.
313 @param top where to store height above baseline
314 @param bottom where to store height below baseline
315 @return the size of the object's box in pixels
317 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
318 /// Return just the width of the object on the screen.
319 virtual CoordType
GetWidth(void) const { return m_Icon
->GetWidth(); }
320 // return a pointer to the icon
321 wxBitmap
*GetIcon(void) const { return m_Icon
; }
322 /** Makes a copy of this object.
324 virtual wxLayoutObject
*Copy(void);
325 virtual void Write(wxString
&ostr
);
326 static wxLayoutObjectIcon
*Read(wxString
&istr
);
331 /** This structure holds all formatting information.
333 struct wxLayoutStyleInfo
335 wxLayoutStyleInfo(int ifamily
= -1,
341 wxColour
*bg
= NULL
);
342 wxLayoutStyleInfo
& operator=(const wxLayoutStyleInfo
&right
);
344 wxColour
& GetBGColour() { return m_bg
; }
346 /// Font change parameters.
347 int size
, family
, style
, weight
, underline
;
350 int m_fg_valid
, m_bg_valid
; // bool, but must be int!
354 class wxFontCacheEntry
357 wxFontCacheEntry(int family
, int size
, int style
, int weight
,
360 m_Family
= family
; m_Size
= size
; m_Style
= style
;
361 m_Weight
= weight
; m_Underline
= underline
;
362 m_Font
= new wxFont(m_Size
, m_Family
,
363 m_Style
, m_Weight
, m_Underline
);
365 bool Matches(int family
, int size
, int style
, int weight
,
366 bool underline
) const
368 return size
== m_Size
&& family
== m_Family
369 && style
== m_Style
&& weight
== m_Weight
370 && underline
== m_Underline
;
372 wxFont
& GetFont(void) { return *m_Font
; }
380 // VZ: I wonder why it doesn't use wxLayoutStyleInfo instead of those?
381 int m_Family
, m_Size
, m_Style
, m_Weight
;
385 KBLIST_DEFINE(wxFCEList
, wxFontCacheEntry
);
390 wxFont
& GetFont(int family
, int size
, int style
, int weight
,
392 wxFont
& GetFont(wxLayoutStyleInfo
const &si
)
394 return GetFont(si
.family
, si
.size
, si
.style
, si
.weight
,
398 wxFCEList m_FontList
;
401 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
405 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
406 /** This class implements a wxLayoutObject holding style change commands.
408 class wxLayoutObjectCmd
: public wxLayoutObject
411 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
412 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
413 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
414 wxLayoutList
*wxllist
,
415 CoordType begin
= -1,
417 wxLayoutObjectCmd(int family
= -1,
423 wxColour
*bg
= NULL
);
424 ~wxLayoutObjectCmd();
425 /** Stores the current style in the styleinfo structure */
426 wxLayoutStyleInfo
* GetStyle(void) const;
427 /** Makes a copy of this object.
429 virtual wxLayoutObject
*Copy(void);
430 virtual void Write(wxString
&ostr
);
431 static wxLayoutObjectCmd
*Read(wxString
&istr
);
433 wxLayoutStyleInfo
*m_StyleInfo
;
436 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
438 The wxLayoutLine object
440 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
442 /** This class represents a single line of objects to be displayed.
443 It knows its height and total size and whether it needs to be
445 It has pointers to its first and next line so it can automatically
446 update them as needed.
452 @param prev pointer to previous line or NULL
453 @param next pointer to following line or NULL
454 @param llist pointer to layout list
456 wxLayoutLine(wxLayoutLine
*prev
, wxLayoutList
*llist
);
457 /** This function inserts a new object at cursor position xpos.
458 @param xpos where to insert new object
459 @param obj the object to insert
460 @return true if that xpos existed and the object was inserted
462 bool Insert(CoordType xpos
, wxLayoutObject
*obj
);
464 /** This function inserts text at cursor position xpos.
465 @param xpos where to insert
466 @param text the text to insert
467 @return true if that xpos existed and the object was inserted
469 bool Insert(CoordType xpos
, const wxString
& text
);
471 /** This function appends an object to the line.
472 @param obj the object to insert
474 void Append(wxLayoutObject
* obj
)
478 m_ObjectList
.push_back(obj
);
479 m_Length
+= obj
->GetLength();
482 /** This function appens the next line to this, i.e. joins the two
485 void MergeNextLine(wxLayoutList
*llist
);
487 /** This function deletes npos cursor positions from position xpos.
488 @param xpos where to delete
489 @param npos how many positions
490 @return number of positions still to be deleted
492 CoordType
Delete(CoordType xpos
, CoordType npos
);
494 /** This function breaks the line at a given cursor position.
495 @param xpos where to break it
496 @return pointer to the new line object replacing the old one
498 wxLayoutLine
*Break(CoordType xpos
, wxLayoutList
*llist
);
500 /** Deletes the next word from this position, including leading
502 This function does not delete over font changes, i.e. a word
503 with formatting instructions in the middle of it is treated as
504 two (three actually!) words. In fact, if the cursor is on a non-text object, that
505 one is treated as a word.
506 @param xpos from where to delete
507 @return true if a word was deleted
509 bool DeleteWord(CoordType npos
);
511 /** Finds a suitable position left to the given column to break the
513 @param column we want to break the line to the left of this
514 @return column for breaking line or -1 if no suitable location found
516 CoordType
GetWrapPosition(CoordType column
);
518 /** Finds the object which covers the cursor position xpos in this
520 @param xpos the column number
521 @param offset where to store the difference between xpos and
523 @return iterator to the object or NULLIT
525 wxLayoutObjectList::iterator
FindObject(CoordType xpos
, CoordType
528 /** Finds the object which covers the screen position xpos in this
530 @param dc the wxDC to use for calculations
531 @param llist the layout list to which this line belongs
532 @param xpos the screen x coordinate
533 @param offset where to store the difference between xpos and
535 @return iterator to the object or NULLIT
537 wxLayoutObjectList::iterator
FindObjectScreen(wxDC
&dc
,
541 bool *found
= NULL
) const ;
543 /** Finds text in this line.
544 @param needle the text to find
545 @param xpos the position where to start the search
546 @return the cursoor coord where it was found or -1
548 CoordType
FindText(const wxString
&needle
, CoordType xpos
= 0) const;
550 /** Get the first object in the list. This is used by the wxlparser
551 functions to export the list.
552 @return iterator to the first object
554 wxLayoutObjectList::iterator
GetFirstObject(void) const
556 return m_ObjectList
.begin();
559 /** Get the last object in the list.
561 wxLayoutObjectList::iterator
GetLastObject(void) const
563 return m_ObjectList
.tail();
566 /** Deletes this line, returns pointer to next line.
567 @param update If true, update all following lines.
569 wxLayoutLine
*DeleteLine(bool update
, wxLayoutList
*llist
);
571 /**@name Cursor Management */
573 /** Return the line number of this line.
574 @return the line number
576 inline CoordType
GetLineNumber(void) const { return m_LineNumber
; }
577 /** Return the length of the line.
578 @return line lenght in cursor positions
580 inline CoordType
GetLength(void) const { return m_Length
; }
583 /**@name Drawing and Layout */
585 /** Draws the line on a wxDC.
586 @param dc the wxDC to draw on
587 @param llist the wxLayoutList
588 @param offset an optional offset to shift printout
592 const wxPoint
&offset
= wxPoint(0,0)) const;
594 /** Recalculates the positions of objects and the height of the
596 @param dc the wxDC to draw on
597 @param llist th e wxLayoutList
598 @param cursorPos if not NULL, set cursor screen position in there
599 @param cursorSize if not cursorPos != NULL, set cursor size in there
600 @param cursorStyle if non NULL where to store styleinfo for cursor pos
601 @param cx if cursorPos != NULL, the cursor x position
602 @param suppressStyleUpdate FALSe normally, only to suppress updating of m_StyleInfo
604 void Layout(wxDC
&dc
,
606 wxPoint
*cursorPos
= NULL
,
607 wxPoint
*cursorSize
= NULL
,
608 wxLayoutStyleInfo
*cursorStyle
= NULL
,
610 bool suppressStyleUpdate
= FALSE
);
611 /** This function finds an object belonging to a given cursor
612 position. It assumes that Layout() has been called before.
613 @param dc the wxDC to use for calculations
614 @param xpos screen x position
615 @param found if non-NULL set to false if we return the last
616 object before the cursor, to true if we really have an object
618 @return pointer to the object
620 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
623 /** This sets the style info for the beginning of this line.
624 @param si styleinfo structure
626 void ApplyStyle(const wxLayoutStyleInfo
&si
)
627 { m_StyleInfo
= si
; }
631 /**@name List traversal */
633 /// Returns pointer to next line.
634 wxLayoutLine
*GetNextLine(void) const { return m_Next
; }
635 /// Returns pointer to previous line.
636 wxLayoutLine
*GetPreviousLine(void) const { return m_Previous
; }
637 /// Sets the link to the next line.
638 void SetNext(wxLayoutLine
*next
)
639 { m_Next
= next
; if(next
) next
->m_Previous
= this; }
640 /// Sets the link to the previous line.
641 void SetPrevious(wxLayoutLine
*previous
)
642 { m_Previous
= previous
; if(previous
) previous
->m_Next
= this; }
645 /// Returns the position of this line on the canvas.
646 wxPoint
GetPosition(void) const { return m_Position
; }
647 /// Returns the height of this line.
648 CoordType
GetHeight(void) const { return m_Height
; }
649 /// Returns the width of this line.
650 CoordType
GetWidth(void) const { return m_Width
; }
651 /// Recalculates the position of this line on the canvas.
652 wxPoint
RecalculatePosition(wxLayoutList
*llist
);
654 /** Copies the contents of this line to another wxLayoutList
655 @param llist the wxLayoutList destination
656 @param from x cursor coordinate where to start
657 @param to x cursor coordinate where to stop, -1 for end of line
659 void Copy(wxLayoutList
*llist
,
663 #ifdef WXLAYOUT_DEBUG
666 wxLayoutStyleInfo
const & GetStyleInfo() const { return m_StyleInfo
; }
668 /// Returns dirty state
669 bool IsDirty(void) const { return m_Dirty
; }
670 /** Marks this line as diry.
671 @param left xpos from where it is dirty or -1 for all
673 void MarkDirty(CoordType left
= -1)
677 if ( m_updateLeft
== -1 || left
< m_updateLeft
)
683 /// Reset the dirty flag
684 void MarkClean() { m_Dirty
= false; m_updateLeft
= -1; }
687 /// Destructor is private. Use DeleteLine() to remove it.
690 /**@name Functions to let the lines synchronise with each other. */
692 /** Sets the height of this line. Will mark following lines as
694 @param height new height
696 void SetHeight(CoordType height
, wxLayoutList
*llist
)
697 { m_Height
= height
; MarkDirty(); }
699 /** Updates the line numbers. */
704 CoordType m_LineNumber
;
705 /// The line length in cursor positions.
707 /// The total height of the line.
709 /// The total width of the line on screen.
711 /// The baseline for drawing objects
712 CoordType m_BaseLine
;
713 /// The position on the canvas.
715 /// The list of objects
716 wxLayoutObjectList m_ObjectList
;
717 /// Have we been changed since the last layout?
719 /// The coordinate of the left boundary of the update rectangle (if m_Dirty)
720 CoordType m_updateLeft
;
721 /// Pointer to previous line if it exists.
722 wxLayoutLine
*m_Previous
;
723 /// Pointer to next line if it exists.
724 wxLayoutLine
*m_Next
;
725 /// A StyleInfo structure, holding the current settings.
726 wxLayoutStyleInfo m_StyleInfo
;
727 /// Just to suppress gcc compiler warnings.
730 wxLayoutLine(const wxLayoutLine
&);
734 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
736 The wxLayoutList object
738 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
739 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
740 higher level of abstraction for the text and can generally be considered
741 as representing "the text".
751 #ifdef WXLAYOUT_USE_CARET
752 /// give us the pointer to the caret to use
753 void SetCaret(wxCaret
*caret
) { m_caret
= caret
; }
754 #endif // WXLAYOUT_USE_CARET
757 void Clear(int family
= wxROMAN
,
758 int size
=WXLO_DEFAULTFONTSIZE
,
764 /// Empty: clear the list but leave font settings.
767 /** Enable or disable auto-formatting. Normally, while editing this
768 should be enabled which is the default. While
769 inserting/deleting lots of text, it makes sense to temporarily
771 @param enable TRUE to enable, FALSE to disable
773 void SetAutoFormatting(bool enable
= TRUE
)
774 { m_AutoFormat
= enable
; }
775 /**@name Cursor Management */
777 /** Set new cursor position.
778 @param p new position
779 @return bool if it could be set
781 bool MoveCursorTo(wxPoint
const &p
);
782 /** Move cursor up or down.
784 @return bool if it could be moved
786 bool MoveCursorVertically(int n
);
787 /** Move cursor left or right.
788 @param n = number of positions to move
789 @return bool if it could be moved
791 bool MoveCursorHorizontally(int n
);
792 /** Move cursor to the left or right counting in words
793 @param n = number of positions in words
794 @param untilNext: puts the cursor at the start of the next word if true,
795 leaves it at the end of the current one otherwise
796 @return bool if it could be moved
798 bool MoveCursorWord(int n
, bool untilNext
= true);
800 /// Move cursor to end of line.
801 void MoveCursorToEndOfLine(void)
803 wxASSERT(m_CursorLine
);
804 MoveCursorHorizontally(m_CursorLine
->GetLength()-m_CursorPos
.x
);
807 /// Move cursor to the start of line.
808 void MoveCursorToBeginOfLine(void)
809 { MoveCursorHorizontally(-m_CursorPos
.x
); }
811 /// get the number of lines in the list
812 size_t GetNumLines() const { return m_numLines
; }
814 /// Returns current cursor position.
815 const wxPoint
&GetCursorPos(wxDC
&dc
) const { return m_CursorPos
; }
816 const wxPoint
&GetCursorPos() const { return m_CursorPos
; }
818 /// move cursor to the end of text
819 void MoveCursorToEnd(void)
821 MoveCursorTo(wxPoint(0, GetNumLines() - 1));
822 MoveCursorToEndOfLine();
827 /**@name Editing functions.
828 All of these functions return true on success and false on
831 /// Insert text at current cursor position.
832 bool Insert(wxString
const &text
);
833 /// Insert some other object at current cursor position.
834 bool Insert(wxLayoutObject
*obj
);
835 /// Inserts objects at current cursor positions
836 bool Insert(wxLayoutList
*llist
);
838 /// Inserts a linebreak at current cursor position.
839 bool LineBreak(void);
840 /** Wraps the current line. Searches to the left of the cursor to
841 break the line. Does nothing if the cursor position is before
842 the break position parameter.
843 @param column the break position for the line, maximum length
844 @return true if line got broken
846 bool WrapLine(CoordType column
);
847 /** This function deletes npos cursor positions.
848 @param npos how many positions
849 @return true if everything got deleted
851 bool Delete(CoordType npos
);
853 /** Delete the next n lines.
854 @param n how many lines to delete
855 @return how many it could not delete
857 int DeleteLines(int n
);
859 /// Delete to end of line.
860 void DeleteToEndOfLine(void)
862 wxASSERT(m_CursorLine
);
863 Delete(m_CursorLine
->GetLength()-m_CursorPos
.x
);
865 /// Delete to begin of line.
866 void DeleteToBeginOfLine(void)
868 wxASSERT(m_CursorLine
);
869 CoordType n
= m_CursorPos
.x
;
870 #ifdef WXLAYOUT_DEBUG
871 wxASSERT(MoveCursorHorizontally(-n
));
873 MoveCursorHorizontally(-n
);
878 /** Delete the next word.
880 void DeleteWord(void)
882 wxASSERT(m_CursorLine
);
883 m_CursorLine
->DeleteWord(m_CursorPos
.x
);
888 /** Finds text in this list.
889 @param needle the text to find
890 @param cpos the position where to start the search
891 @return the cursor coord where it was found or (-1,-1)
893 wxPoint
FindText(const wxString
&needle
, const wxPoint
&cpos
= wxPoint(0,0)) const;
895 /**@name Formatting options */
897 /// sets font parameters
898 void SetFont(int family
, int size
, int style
,
899 int weight
, int underline
,
902 /// sets font parameters, colours by name
903 void SetFont(int family
=-1, int size
= -1, int style
=-1,
904 int weight
=-1, int underline
= -1,
905 char const *fg
= NULL
,
906 char const *bg
= NULL
);
907 /// changes to the next larger font size
908 inline void SetFontLarger(void)
909 { SetFont(-1,(12*m_CurrentStyleInfo
.size
)/10); }
910 /// changes to the next smaller font size
911 inline void SetFontSmaller(void)
912 { SetFont(-1,(10*m_CurrentStyleInfo
.size
)/12); }
915 inline void SetFontFamily(int family
) { SetFont(family
); }
917 inline void SetFontSize(int size
) { SetFont(-1,size
); }
919 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
921 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
922 /// toggle underline flag
923 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
924 /// set font colours by name
925 inline void SetFontColour(char const *fg
, char const *bg
= NULL
)
926 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
927 /// set font colours by colour
928 inline void SetFontColour(wxColour
*fg
, wxColour
*bg
= NULL
)
929 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
932 Returns a pointer to the default settings.
933 This is only valid temporarily and should not be stored
935 @return the default settings of the list
937 wxLayoutStyleInfo
&GetDefaultStyleInfo(void) { return m_DefaultStyleInfo
; }
938 wxLayoutStyleInfo
&GetStyleInfo(void) { return m_CurrentStyleInfo
; }
939 const wxLayoutStyleInfo
&GetStyleInfo(void) const { return m_CurrentStyleInfo
; }
940 const wxLayoutStyleInfo
&GetCursorStyleInfo(void) const { return m_CursorStyleInfo
; }
942 /// is the current font underlined?
943 bool IsFontUnderlined() const { return GetCursorStyleInfo().underline
!= 0; }
944 /// is the current font bold?
945 bool IsFontBold() const { return GetCursorStyleInfo().weight
== wxBOLD
; }
946 /// is the current font italic?
947 bool IsFontItalic() const { return GetCursorStyleInfo().style
== wxITALIC
; }
949 /// set underline if it was off, turn it off if it was on
950 void ToggleFontUnderline()
951 { SetFontUnderline(!IsFontUnderlined()); }
953 /// make font bold if it was normal or make it normal if it was bold
954 void ToggleFontWeight()
955 { SetFontWeight(IsFontBold() ? wxNORMAL
: wxBOLD
); }
957 /// make font italic if it was normal or make it normal if it was italic
958 void ToggleFontItalics()
959 { SetFontStyle(IsFontItalic() ? wxNORMAL
: wxITALIC
); }
965 /** Draws the complete list on a wxDC.
966 @param dc the wxDC to draw on
967 @param offset an optional offset to shift printout
968 @param top optional y coordinate where to start drawing
969 @param bottom optional y coordinate where to stop drawing
970 @param clipStrictly if set, do not draw objects which reach
971 beyond "bottom". Set this when printing.
974 const wxPoint
&offset
= wxPoint(0,0),
975 CoordType top
= -1, CoordType bottom
= -1,
976 bool clipStrictly
= false);
978 /** Calculates new layout for the list, like Draw() but does not
980 @param dc the wxDC to draw on
981 @param bottom optional y coordinate where to stop calculating
982 @param forceAll force re-layout of all lines
983 @param cpos Can hold a cursorposition, and will be overwritten
984 with the corresponding DC position.
985 @param csize Will hold the cursor size relating to cpos.
987 void Layout(wxDC
&dc
, CoordType bottom
= -1, bool forceAll
= false,
988 wxPoint
*cpos
= NULL
,
989 wxPoint
*csize
= NULL
);
991 /** Ensure that the whole list will be recalculate on the next call
992 to Layout() or Draw().
993 @param redrawAll TRUE or FALSE to reset it
995 void ForceTotalLayout(bool redrawAll
= TRUE
)
996 { m_ReLayoutAll
= redrawAll
; }
998 /** Returns the screen coordinates relating to a given cursor
999 position and the size of the cursor at that position.
1000 @param dc for which to calculate it
1001 @param cpos Cursor position to look for.
1002 @param csize If non-NULL, will be set to the cursor size.
1003 @return The cursor position on the DC.
1005 wxPoint
GetScreenPos(wxDC
&dc
, const wxPoint
&cpos
, wxPoint
*csize
= NULL
);
1007 /** Calculates new sizes for everything in the list, like Layout()
1008 but this is needed after the list got changed.
1009 @param dc the wxDC to draw on
1010 @param bottom optional y coordinate where to stop calculating
1012 void Recalculate(wxDC
&dc
, CoordType bottom
= -1);
1014 /** Returns the size of the list in screen coordinates.
1015 The return value only makes sense after the list has been
1017 @return a wxPoint holding the maximal x/y coordinates used for
1020 wxPoint
GetSize(void) const;
1022 /** Returns the cursor position on the screen.
1024 wxPoint
GetCursorScreenPos(void) const;
1026 /** Draws the cursor.
1027 @param active If true, draw a bold cursor to mark window as
1029 @param translate optional translation of cursor coords on screen
1031 void DrawCursor(wxDC
&dc
,
1033 const wxPoint
& translate
= wxPoint(0,0));
1035 /** This function finds an object belonging to a given screen
1036 position. It assumes that Layout() has been called before.
1037 @param pos screen position
1038 @param cursorPos if non NULL, store cursor position in there
1039 @param found if used, set this to true if we really found an
1040 object, to false if we had to take the object near to it
1041 @return pointer to the object
1043 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
1045 wxPoint
*cursorPos
= NULL
,
1046 bool *found
= NULL
);
1048 /** Called by the objects to update the update rectangle.
1049 @param x horizontal coordinate to include in rectangle
1050 @param y vertical coordinate to include in rectangle
1052 void SetUpdateRect(CoordType x
, CoordType y
);
1053 /** Called by the objects to update the update rectangle.
1054 @param p a point to include in it
1056 void SetUpdateRect(const wxPoint
&p
)
1057 { SetUpdateRect(p
.x
,p
.y
); }
1058 /// adds the cursor position to the update rectangle
1059 void AddCursorPosToUpdateRect()
1061 #ifndef WXLAYOUT_USE_CARET
1062 SetUpdateRect(m_CursorScreenPos
);
1063 SetUpdateRect(m_CursorScreenPos
+m_CursorSize
);
1064 //#else - the caret will take care of refreshing itself
1065 #endif // !WXLAYOUT_USE_CARET
1067 /// Invalidates the update rectangle.
1068 void InvalidateUpdateRect(void) { m_UpdateRectValid
= false; }
1069 /// Returns the update rectangle.
1070 const wxRect
*GetUpdateRect(void) const { return &m_UpdateRect
; }
1073 /// get the current cursor size
1074 const wxPoint
& GetCursorSize() const { return m_CursorSize
; }
1076 /**@name For exporting one object after another. */
1078 /** Returns a pointer to the first line in the list. */
1079 wxLayoutLine
*GetFirstLine(void)
1081 wxASSERT(m_FirstLine
);
1086 /// Begin selecting text
1087 void StartSelection(const wxPoint
& cpos
= wxPoint(-1,-1),
1088 const wxPoint
& spos
= wxPoint(-1,-1));
1089 // Continue selecting text
1090 void ContinueSelection(const wxPoint
& cpos
= wxPoint(-1,-1),
1091 const wxPoint
& spos
= wxPoint(-1,-1));
1092 /// End selecting text.
1093 void EndSelection(const wxPoint
& cpos
= wxPoint(-1,-1),
1094 const wxPoint
& spos
= wxPoint(-1,-1));
1095 /// Discard the current selection
1096 void DiscardSelection();
1097 /// Are we still selecting text?
1098 bool IsSelecting(void) const;
1099 /// Is the given point (text coords) selected?
1100 bool IsSelected(const wxPoint
&cursor
) const;
1101 /// Do we have a non null selection?
1102 bool HasSelection() const
1103 { return m_Selection
.m_valid
|| m_Selection
.m_selecting
; }
1105 /** Return the selection as a wxLayoutList.
1106 @param invalidate if true, the selection will be invalidated after this and can no longer be used.
1107 @return Another layout list object holding the selection, must be freed by caller
1109 wxLayoutList
*GetSelection(class wxLayoutDataObject
*wxldo
= NULL
, bool invalidate
= TRUE
);
1110 /// Delete selected bit
1111 void DeleteSelection(void);
1113 wxLayoutList
*Copy(const wxPoint
&from
= wxPoint(0,0),
1114 const wxPoint
&to
= wxPoint(-1,-1));
1116 /// starts highlighting of text for selections
1117 void StartHighlighting(wxDC
&dc
);
1118 /// ends highlighting of text for selections
1119 void EndHighlighting(wxDC
&dc
);
1121 /** Tests whether this layout line is selected and needs
1123 @param line to test for
1124 @param from set to first cursorpos to be highlighted (for returncode == -1)
1125 @param to set to last cursorpos to be highlighted (for returncode == -1)
1126 @return 0 = not selected, 1 = fully selected, -1 = partially
1130 int IsSelected(const wxLayoutLine
*line
, CoordType
*from
, CoordType
*to
);
1132 void ApplyStyle(wxLayoutStyleInfo
const &si
, wxDC
&dc
);
1133 #ifdef WXLAYOUT_DEBUG
1137 // for wxLayoutLine usage only
1138 void IncNumLines() { m_numLines
++; }
1139 void DecNumLines() { m_numLines
--; }
1141 /// get the line by number
1142 wxLayoutLine
*GetLine(CoordType index
) const;
1145 void InternalClear(void);
1147 /// The list of lines.
1148 wxLayoutLine
*m_FirstLine
;
1149 /// The number of lines in the list (store instead recalculating for speed)
1152 /// The update rectangle which needs to be refreshed:
1153 wxRect m_UpdateRect
;
1154 /// Is the update rectangle valid?
1155 bool m_UpdateRectValid
;
1157 /// Shall we auto-format?
1159 /// Shall we re-layout everything?
1161 /**@name Cursor Management */
1163 /// Where the text cursor (column,line) is.
1164 wxPoint m_CursorPos
;
1165 /// Where the cursor should be drawn.
1166 wxPoint m_CursorScreenPos
;
1167 /// The line where the cursor is.
1168 wxLayoutLine
*m_CursorLine
;
1169 /// The size of the cursor.
1170 wxPoint m_CursorSize
;
1171 /// Has the cursor moved (is m_CursorScreenPos up to date)?
1173 #ifdef WXLAYOUT_USE_CARET
1176 #endif // WXLAYOUT_USE_CARET
1179 /// selection.state and begin/end coordinates
1182 Selection() { m_valid
= m_selecting
= m_discarded
= false; }
1186 bool m_discarded
; // may be TRUE only until the next redraw
1188 // returns true if we already have the screen coordinates of the
1189 // selection start and end
1190 bool HasValidScreenCoords() const
1191 { return m_ScreenA
.x
!= -1 && m_ScreenB
.x
!= -1; }
1193 // the start and end of the selection coordinates in pixels
1194 wxPoint m_ScreenA
, m_ScreenB
;
1196 // these coordinates are in text positions, not in pixels
1197 wxPoint m_CursorA
, m_CursorB
;
1199 /** @name Font parameters. */
1201 /// this object manages the fonts for us
1202 wxFontCache m_FontCache
;
1203 /// the default setting:
1204 wxLayoutStyleInfo m_DefaultStyleInfo
;
1205 /// the current setting:
1206 wxLayoutStyleInfo m_CurrentStyleInfo
;
1207 /// the current setting:
1208 wxLayoutStyleInfo m_CursorStyleInfo
;
1212 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1214 The wxLayoutDataObject for exporting data to the clipboard in our
1217 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1218 class wxLayoutDataObject
: public wxPrivateDataObject
1221 wxLayoutDataObject(void)
1223 SetId("application/wxlayoutlist");
1224 //m_format.SetAtom((GdkAtom) 222222);
1228 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1230 The wxLayoutPrintout object for printing within the wxWindows print
1233 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1234 /** This class implements a wxPrintout for printing a wxLayoutList within
1235 the wxWindows printing framework.
1237 class wxLayoutPrintout
: public wxPrintout
1241 @param llist pointer to the wxLayoutList to be printed
1242 @param title title for PS file or windows
1244 wxLayoutPrintout(wxLayoutList
*llist
,
1245 wxString
const & title
=
1246 "wxLayout Printout");
1248 ~wxLayoutPrintout();
1250 /** Function which prints the n-th page.
1251 @param page the page number to print
1252 @return bool true if we are not at end of document yet
1254 bool OnPrintPage(int page
);
1255 /** Checks whether page exists in document.
1256 @param page number of page
1257 @return true if page exists
1259 bool HasPage(int page
);
1261 /** Gets called from wxWindows to find out which pages are existing.
1262 I'm not totally sure about the parameters though.
1263 @param minPage the first page in the document
1264 @param maxPage the last page in the document
1265 @param selPageFrom the first page to be printed
1266 @param selPageTo the last page to be printed
1268 void GetPageInfo(int *minPage
, int *maxPage
,
1269 int *selPageFrom
, int *selPageTo
);
1271 /** This little function scales the DC so that the printout has
1272 roughly the same size as the output on screen.
1273 @param dc the wxDC to scale
1274 @return the scale that was applied
1276 float ScaleDC(wxDC
*dc
);
1279 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1282 /// The list to print.
1283 wxLayoutList
*m_llist
;
1284 /// Title for PS file or window.
1286 /// The real paper size.
1287 int m_PageHeight
, m_PageWidth
;
1288 /// How much we actually print per page.
1289 int m_PrintoutHeight
;
1290 /// How many pages we need to print.
1292 /// Top left corner where we start printing.