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 /// optional data for application's use
208 UserData
*m_UserData
;
211 /// Define a list type of wxLayoutObject pointers.
212 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObject
);
214 /// An illegal iterator to save typing.
215 #define NULLIT (wxLayoutObjectList::iterator(NULL))
216 /// The iterator type.
217 #define wxLOiterator wxLayoutObjectList::iterator
219 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
223 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
224 /** This class implements a wxLayoutObject holding plain text.
226 class wxLayoutObjectText
: public wxLayoutObject
229 wxLayoutObjectText(const wxString
&txt
= "");
231 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
232 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
233 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
234 wxLayoutList
*wxllist
,
235 CoordType begin
= -1,
237 /** Calculates and returns the size of the object.
238 @param top where to store height above baseline
239 @param bottom where to store height below baseline
240 @return the size of the object's box in pixels
242 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
243 /// Return just the width of the object on the screen.
244 virtual CoordType
GetWidth(void) const { return m_Width
; }
245 /** Returns the cursor offset relating to the screen x position
246 relative to begin of object.
247 @param dc the wxDC to use for calculations
248 @param xpos relative x position from head of object
249 @return cursor coordinate offset
251 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const;
253 virtual void Write(wxString
&ostr
);
254 static wxLayoutObjectText
*Read(wxString
&istr
);
256 #ifdef WXLAYOUT_DEBUG
257 virtual void Debug(void);
260 virtual CoordType
GetLength(void) const { return strlen(m_Text
.c_str()); }
263 wxString
& GetText(void) { return m_Text
; }
264 void SetText(wxString
const &text
) { m_Text
= text
; }
265 /** Makes a copy of this object.
267 virtual wxLayoutObject
*Copy(void);
270 /// size of the box containing text
271 long m_Width
, m_Height
;
272 /// Height above baseline.
274 /// Height below baseline.
278 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
282 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
283 /** This class implements a wxLayoutObject holding a graphic.
285 class wxLayoutObjectIcon
: public wxLayoutObject
288 wxLayoutObjectIcon(wxBitmap
*icon
= NULL
);
289 wxLayoutObjectIcon(wxBitmap
const &icon
);
291 ~wxLayoutObjectIcon() { if(m_Icon
) delete m_Icon
; }
293 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
294 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
295 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
296 wxLayoutList
*wxllist
,
297 CoordType begin
= -1,
300 /** Calculates and returns the size of the object.
301 @param top where to store height above baseline
302 @param bottom where to store height below baseline
303 @return the size of the object's box in pixels
305 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
306 /// Return just the width of the object on the screen.
307 virtual CoordType
GetWidth(void) const { return m_Icon
->GetWidth(); }
308 // return a pointer to the icon
309 wxBitmap
*GetIcon(void) const { return m_Icon
; }
310 /** Makes a copy of this object.
312 virtual wxLayoutObject
*Copy(void);
313 virtual void Write(wxString
&ostr
);
314 static wxLayoutObjectIcon
*Read(wxString
&istr
);
319 /** This structure holds all formatting information. Members which are
320 undefined (for a CmdObject this means: no change), are set to -1.
322 struct wxLayoutStyleInfo
324 wxLayoutStyleInfo(int ifamily
= -1,
330 wxColour
*bg
= NULL
);
331 wxColour
& GetBGColour()
335 wxLayoutStyleInfo
& operator=(const wxLayoutStyleInfo
&right
);
336 /// Font change parameters.
337 int size
, family
, style
, weight
, underline
;
340 int m_fg_valid
, m_bg_valid
; // bool, but must be int!
344 class wxFontCacheEntry
347 wxFontCacheEntry(int family
, int size
, int style
, int weight
,
350 m_Family
= family
; m_Size
= size
; m_Style
= style
;
351 m_Weight
= weight
; m_Underline
= underline
;
352 m_Font
= new wxFont(m_Size
, m_Family
,
353 m_Style
, m_Weight
, m_Underline
);
355 bool Matches(int family
, int size
, int style
, int weight
,
356 bool underline
) const
358 return size
== m_Size
&& family
== m_Family
359 && style
== m_Style
&& weight
== m_Weight
360 && underline
== m_Underline
;
362 wxFont
& GetFont(void) { return *m_Font
; }
369 int m_Family
, m_Size
, m_Style
, m_Weight
;
373 KBLIST_DEFINE(wxFCEList
, wxFontCacheEntry
);
378 wxFont
& GetFont(int family
, int size
, int style
, int weight
,
380 wxFont
& GetFont(wxLayoutStyleInfo
const &si
)
382 return GetFont(si
.family
, si
.size
, si
.style
, si
.weight
,
386 wxFCEList m_FontList
;
389 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
393 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
394 /** This class implements a wxLayoutObject holding style change commands.
396 class wxLayoutObjectCmd
: public wxLayoutObject
399 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
400 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
401 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
402 wxLayoutList
*wxllist
,
403 CoordType begin
= -1,
405 wxLayoutObjectCmd(int family
= -1,
411 wxColour
*bg
= NULL
);
412 ~wxLayoutObjectCmd();
413 /** Stores the current style in the styleinfo structure */
414 wxLayoutStyleInfo
* GetStyle(void) const;
415 /** Makes a copy of this object.
417 virtual wxLayoutObject
*Copy(void);
418 virtual void Write(wxString
&ostr
);
419 static wxLayoutObjectCmd
*Read(wxString
&istr
);
421 wxLayoutStyleInfo
*m_StyleInfo
;
424 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
426 The wxLayoutLine object
428 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
430 /** This class represents a single line of objects to be displayed.
431 It knows its height and total size and whether it needs to be
433 It has pointers to its first and next line so it can automatically
434 update them as needed.
440 @param prev pointer to previous line or NULL
441 @param next pointer to following line or NULL
442 @param llist pointer to layout list
444 wxLayoutLine(wxLayoutLine
*prev
, wxLayoutList
*llist
);
445 /** This function inserts a new object at cursor position xpos.
446 @param xpos where to insert new object
447 @param obj the object to insert
448 @return true if that xpos existed and the object was inserted
450 bool Insert(CoordType xpos
, wxLayoutObject
*obj
);
452 /** This function inserts text at cursor position xpos.
453 @param xpos where to insert
454 @param text the text to insert
455 @return true if that xpos existed and the object was inserted
457 bool Insert(CoordType xpos
, const wxString
& text
);
459 /** This function appends an object to the line.
460 @param obj the object to insert
462 void Append(wxLayoutObject
* obj
)
466 m_ObjectList
.push_back(obj
);
467 m_Length
+= obj
->GetLength();
470 /** This function appens the next line to this, i.e. joins the two
473 void MergeNextLine(wxLayoutList
*llist
);
475 /** This function deletes npos cursor positions from position xpos.
476 @param xpos where to delete
477 @param npos how many positions
478 @return number of positions still to be deleted
480 CoordType
Delete(CoordType xpos
, CoordType npos
);
482 /** This function breaks the line at a given cursor position.
483 @param xpos where to break it
484 @return pointer to the new line object replacing the old one
486 wxLayoutLine
*Break(CoordType xpos
, wxLayoutList
*llist
);
488 /** Deletes the next word from this position, including leading
490 This function does not delete over font changes, i.e. a word
491 with formatting instructions in the middle of it is treated as
492 two (three actually!) words. In fact, if the cursor is on a non-text object, that
493 one is treated as a word.
494 @param xpos from where to delete
495 @return true if a word was deleted
497 bool DeleteWord(CoordType npos
);
499 /** Finds a suitable position left to the given column to break the
501 @param column we want to break the line to the left of this
502 @return column for breaking line or -1 if no suitable location found
504 CoordType
GetWrapPosition(CoordType column
);
506 /** Finds the object which covers the cursor position xpos in this
508 @param xpos the column number
509 @param offset where to store the difference between xpos and
511 @return iterator to the object or NULLIT
513 wxLayoutObjectList::iterator
FindObject(CoordType xpos
, CoordType
516 /** Finds the object which covers the screen position xpos in this
518 @param dc the wxDC to use for calculations
519 @param xpos the screen x coordinate
520 @param offset where to store the difference between xpos and
522 @return iterator to the object or NULLIT
524 wxLayoutObjectList::iterator
FindObjectScreen(wxDC
&dc
,
527 bool *found
= NULL
) const ;
529 /** Finds text in this line.
530 @param needle the text to find
531 @param xpos the position where to start the search
532 @return the cursoor coord where it was found or -1
534 CoordType
FindText(const wxString
&needle
, CoordType xpos
= 0) const;
536 /** Get the first object in the list. This is used by the wxlparser
537 functions to export the list.
538 @return iterator to the first object
540 wxLayoutObjectList::iterator
GetFirstObject(void)
542 return m_ObjectList
.begin();
545 /** Deletes this line, returns pointer to next line.
546 @param update If true, update all following lines.
548 wxLayoutLine
*DeleteLine(bool update
, wxLayoutList
*llist
);
550 /**@name Cursor Management */
552 /** Return the line number of this line.
553 @return the line number
555 inline CoordType
GetLineNumber(void) const { return m_LineNumber
; }
556 /** Return the length of the line.
557 @return line lenght in cursor positions
559 inline CoordType
GetLength(void) const { return m_Length
; }
562 /**@name Drawing and Layout */
564 /** Draws the line on a wxDC.
565 @param dc the wxDC to draw on
566 @param llist the wxLayoutList
567 @param offset an optional offset to shift printout
571 const wxPoint
&offset
= wxPoint(0,0)) const;
573 /** Recalculates the positions of objects and the height of the
575 @param dc the wxDC to draw on
576 @param llist th e wxLayoutList
577 @param cursorPos if not NULL, set cursor screen position in there
578 @param cursorSize if not cursorPos != NULL, set cursor size in there
579 @param cx if cursorPos != NULL, the cursor x position
580 @param suppressStyleUpdate FALSe normally, only to suppress updating of m_StyleInfo
582 void Layout(wxDC
&dc
,
584 wxPoint
*cursorPos
= NULL
,
585 wxPoint
*cursorSize
= NULL
,
587 bool suppressStyleUpdate
= FALSE
);
588 /** This function finds an object belonging to a given cursor
589 position. It assumes that Layout() has been called before.
590 @param dc the wxDC to use for calculations
591 @param xpos screen x position
592 @param found if non-NULL set to false if we return the last
593 object before the cursor, to true if we really have an object
595 @return pointer to the object
597 wxLayoutObject
* FindObjectScreen(wxDC
&dc
, CoordType xpos
, bool
599 /** This sets the style info for the beginning of this line.
600 @param si styleinfo structure
602 void ApplyStyle(const wxLayoutStyleInfo
&si
)
603 { m_StyleInfo
= si
; }
607 /**@name List traversal */
609 /// Returns pointer to next line.
610 wxLayoutLine
*GetNextLine(void) const { return m_Next
; }
611 /// Returns pointer to previous line.
612 wxLayoutLine
*GetPreviousLine(void) const { return m_Previous
; }
613 /// Sets the link to the next line.
614 void SetNext(wxLayoutLine
*next
)
615 { m_Next
= next
; if(next
) next
->m_Previous
= this; }
616 /// Sets the link to the previous line.
617 void SetPrevious(wxLayoutLine
*previous
)
618 { m_Previous
= previous
; if(previous
) previous
->m_Next
= this; }
621 /// Returns the position of this line on the canvas.
622 wxPoint
GetPosition(void) const { return m_Position
; }
623 /// Returns the height of this line.
624 CoordType
GetHeight(void) const { return m_Height
; }
625 /// Returns the width of this line.
626 CoordType
GetWidth(void) const { return m_Width
; }
627 /** This will recalculate the position and size of this line.
628 If called recursively it will abort if the position of an
629 object is unchanged, assuming that none of the following
630 objects need to move.
631 @param recurse if greater 0 then it will be used as the
632 minimum(!) recursion level, continue with all lines till the end of
633 the list or until the coordinates no longer changed.
635 void RecalculatePositions(int recurse
, wxLayoutList
*llist
);
636 /// Recalculates the position of this line on the canvas.
637 wxPoint
RecalculatePosition(wxLayoutList
*llist
);
639 /** Copies the contents of this line to another wxLayoutList
640 @param llist the wxLayoutList destination
641 @param from x cursor coordinate where to start
642 @param to x cursor coordinate where to stop, -1 for end of line
644 void Copy(wxLayoutList
*llist
,
648 #ifdef WXLAYOUT_DEBUG
651 wxLayoutStyleInfo
const & GetStyleInfo() const { return m_StyleInfo
; }
653 /// Returns dirty state
654 bool IsDirty(void) const { return m_Dirty
; }
655 /** Marks this line as diry.
656 @param left xpos from where it is dirty or -1 for all
658 void MarkDirty(CoordType left
= -1)
662 if ( m_updateLeft
== -1 || left
< m_updateLeft
)
668 /** Marks the following lines as dirty.
669 @param recurse if -1 recurse to end of list, otherwise depth of recursion.
671 void MarkNextDirty(int recurse
= 0);
672 /// Reset the dirty flag
673 void MarkClean() { m_Dirty
= false; m_updateLeft
= -1; }
676 /// Destructor is private. Use DeleteLine() to remove it.
679 /**@name Functions to let the lines synchronise with each other. */
681 /** Sets the height of this line. Will mark following lines as
683 @param height new height
685 void SetHeight(CoordType height
, wxLayoutList
*llist
)
686 { m_Height
= height
; RecalculatePositions(true, llist
); }
688 /** Moves the linenumbers one on, because a line has been inserted
690 @param delta either +1 or -1
692 void MoveLines(int delta
)
694 m_LineNumber
+= delta
;
695 if(m_Next
) m_Next
->MoveLines(delta
);
700 CoordType m_LineNumber
;
701 /// The line length in cursor positions.
703 /// The total height of the line.
705 /// The total width of the line on screen.
707 /// The baseline for drawing objects
708 CoordType m_BaseLine
;
709 /// The position on the canvas.
711 /// The list of objects
712 wxLayoutObjectList m_ObjectList
;
713 /// Have we been changed since the last layout?
715 /// The coordinate of the left boundary of the update rectangle (if m_Dirty)
716 CoordType m_updateLeft
;
717 /// Pointer to previous line if it exists.
718 wxLayoutLine
*m_Previous
;
719 /// Pointer to next line if it exists.
720 wxLayoutLine
*m_Next
;
721 /// A StyleInfo structure, holding the current settings.
722 wxLayoutStyleInfo m_StyleInfo
;
723 /// Just to suppress gcc compiler warnings.
726 wxLayoutLine(const wxLayoutLine
&);
730 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
732 The wxLayoutList object
734 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
735 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
736 higher level of abstraction for the text and can generally be considered
737 as representing "the text".
747 #ifdef WXLAYOUT_USE_CARET
748 /// give us the pointer to the caret to use
749 void SetCaret(wxCaret
*caret
) { m_caret
= caret
; }
750 #endif // WXLAYOUT_USE_CARET
753 void Clear(int family
= wxROMAN
,
754 int size
=WXLO_DEFAULTFONTSIZE
,
760 /// Empty: clear the list but leave font settings.
763 /**@name Cursor Management */
765 /** Set new cursor position.
766 @param p new position
767 @return bool if it could be set
769 bool MoveCursorTo(wxPoint
const &p
);
770 /** Move cursor up or down.
772 @return bool if it could be moved
774 bool MoveCursorVertically(int n
);
775 /** Move cursor left or right.
776 @param n = number of positions to move
777 @return bool if it could be moved
779 bool MoveCursorHorizontally(int n
);
780 /** Move cursor to the left or right counting in words
781 @param n = number of positions in words
782 @return bool if it could be moved
784 bool MoveCursorWord(int n
);
786 /// Move cursor to end of line.
787 void MoveCursorToEndOfLine(void)
789 wxASSERT(m_CursorLine
);
790 MoveCursorHorizontally(m_CursorLine
->GetLength()-m_CursorPos
.x
);
793 /// Move cursor to begin of line.
794 void MoveCursorToBeginOfLine(void)
795 { MoveCursorHorizontally(-m_CursorPos
.x
); }
797 /// Returns current cursor position.
798 const wxPoint
&GetCursorPos(wxDC
&dc
) const { return m_CursorPos
; }
799 const wxPoint
&GetCursorPos() const { return m_CursorPos
; }
803 /**@name Editing functions.
804 All of these functions return true on success and false on
807 /// Insert text at current cursor position.
808 bool Insert(wxString
const &text
);
809 /// Insert some other object at current cursor position.
810 bool Insert(wxLayoutObject
*obj
);
811 /// Inserts objects at current cursor positions
812 bool Insert(wxLayoutList
*llist
);
814 /// Inserts a linebreak at current cursor position.
815 bool LineBreak(void);
816 /** Wraps the current line. Searches to the left of the cursor to
817 break the line. Does nothing if the cursor position is before
818 the break position parameter.
819 @param column the break position for the line, maximum length
820 @return true if line got broken
822 bool WrapLine(CoordType column
);
823 /** This function deletes npos cursor positions.
824 @param npos how many positions
825 @return true if everything got deleted
827 bool Delete(CoordType npos
);
829 /** Delete the next n lines.
830 @param n how many lines to delete
831 @return how many it could not delete
833 int DeleteLines(int n
);
835 /// Delete to end of line.
836 void DeleteToEndOfLine(void)
838 wxASSERT(m_CursorLine
);
839 Delete(m_CursorLine
->GetLength()-m_CursorPos
.x
);
841 /// Delete to begin of line.
842 void DeleteToBeginOfLine(void)
844 wxASSERT(m_CursorLine
);
845 CoordType n
= m_CursorPos
.x
;
846 #ifdef WXLAYOUT_DEBUG
847 wxASSERT(MoveCursorHorizontally(-n
));
849 MoveCursorHorizontally(-n
);
854 /** Delete the next word.
856 void DeleteWord(void)
858 wxASSERT(m_CursorLine
);
859 m_CursorLine
->DeleteWord(m_CursorPos
.x
);
864 /** Finds text in this list.
865 @param needle the text to find
866 @param cpos the position where to start the search
867 @return the cursor coord where it was found or (-1,-1)
869 wxPoint
FindText(const wxString
&needle
, const wxPoint
&cpos
= wxPoint(0,0)) const;
871 /**@name Formatting options */
873 /// sets font parameters
874 void SetFont(int family
, int size
, int style
,
875 int weight
, int underline
,
878 /// sets font parameters, colours by name
879 void SetFont(int family
=-1, int size
= -1, int style
=-1,
880 int weight
=-1, int underline
= -1,
881 char const *fg
= NULL
,
882 char const *bg
= NULL
);
883 /// changes to the next larger font size
884 inline void SetFontLarger(void)
885 { SetFont(-1,(12*m_CurrentStyleInfo
.size
)/10); }
886 /// changes to the next smaller font size
887 inline void SetFontSmaller(void)
888 { SetFont(-1,(10*m_CurrentStyleInfo
.size
)/12); }
891 inline void SetFontFamily(int family
) { SetFont(family
); }
893 inline void SetFontSize(int size
) { SetFont(-1,size
); }
895 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
897 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
898 /// toggle underline flag
899 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
900 /// set font colours by name
901 inline void SetFontColour(char const *fg
, char const *bg
= NULL
)
902 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
903 /// set font colours by colour
904 inline void SetFontColour(wxColour
*fg
, wxColour
*bg
= NULL
)
905 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
909 Returns a pointer to the default settings.
910 This is only valid temporarily and should not be stored
912 @return the default settings of the list
914 wxLayoutStyleInfo
&GetDefaultStyleInfo(void) { return m_DefaultStyleInfo
; }
915 wxLayoutStyleInfo
&GetStyleInfo(void) { return m_CurrentStyleInfo
; }
920 /** Draws the complete list on a wxDC.
921 @param dc the wxDC to draw on
922 @param offset an optional offset to shift printout
923 @param top optional y coordinate where to start drawing
924 @param bottom optional y coordinate where to stop drawing
927 const wxPoint
&offset
= wxPoint(0,0),
928 CoordType top
= -1, CoordType bottom
= -1);
930 /** Calculates new layout for the list, like Draw() but does not
932 @param dc the wxDC to draw on
933 @param bottom optional y coordinate where to stop calculating
934 @param forceAll force re-layout of all lines
936 void Layout(wxDC
&dc
, CoordType bottom
= -1, bool forceAll
= false);
938 /** Calculates new sizes for everything in the list, like Layout()
939 but this is needed after the list got changed.
940 @param dc the wxDC to draw on
941 @param bottom optional y coordinate where to stop calculating
943 void Recalculate(wxDC
&dc
, CoordType bottom
= -1);
945 /** Returns the size of the list in screen coordinates.
946 The return value only makes sense after the list has been
948 @return a wxPoint holding the maximal x/y coordinates used for
951 wxPoint
GetSize(void) const;
953 /** Returns the cursor position on the screen.
954 @return cursor position in pixels
956 wxPoint
GetCursorScreenPos(wxDC
&dc
);
957 /** Calculates the cursor position on the screen.
958 @param dc the dc to use for cursor position calculations
959 @param resetCursorMovedFlag: if true, reset "cursor moved" flag
960 @param translate optional translation of cursor coords on screen
963 void UpdateCursorScreenPos(wxDC
&dc
,
964 bool resetCursorMovedFlag
= true,
965 const wxPoint
& translate
= wxPoint(0,
968 /** Draws the cursor.
969 @param active If true, draw a bold cursor to mark window as
971 @param translate optional translation of cursor coords on screen
973 void DrawCursor(wxDC
&dc
,
975 const wxPoint
& translate
= wxPoint(0,0));
977 /** This function finds an object belonging to a given screen
978 position. It assumes that Layout() has been called before.
979 @param pos screen position
980 @param cursorPos if non NULL, store cursor position in there
981 @param found if used, set this to true if we really found an
982 object, to false if we had to take the object near to it
983 @return pointer to the object
985 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
987 wxPoint
*cursorPos
= NULL
,
990 /** Called by the objects to update the update rectangle.
991 @param x horizontal coordinate to include in rectangle
992 @param y vertical coordinate to include in rectangle
994 void SetUpdateRect(CoordType x
, CoordType y
);
995 /** Called by the objects to update the update rectangle.
996 @param p a point to include in it
998 void SetUpdateRect(const wxPoint
&p
)
999 { SetUpdateRect(p
.x
,p
.y
); }
1000 /// adds the cursor position to the update rectangle
1001 void AddCursorPosToUpdateRect()
1003 #ifndef WXLAYOUT_USE_CARET
1004 SetUpdateRect(m_CursorScreenPos
);
1005 SetUpdateRect(m_CursorScreenPos
+m_CursorSize
);
1006 //#else - the caret will take care of refreshing itself
1007 #endif // !WXLAYOUT_USE_CARET
1009 /// Invalidates the update rectangle.
1010 void InvalidateUpdateRect(void) { m_UpdateRectValid
= false; }
1011 /// Returns the update rectangle.
1012 const wxRect
*GetUpdateRect(void) const { return &m_UpdateRect
; }
1015 /// get the current cursor size
1016 const wxPoint
& GetCursorSize() const { return m_CursorSize
; }
1018 /**@name For exporting one object after another. */
1020 /** Returns a pointer to the first line in the list. */
1021 wxLayoutLine
*GetFirstLine(void)
1023 wxASSERT(m_FirstLine
);
1028 /// Begin selecting text
1029 void StartSelection(const wxPoint
& cpos
= wxPoint(-1,-1),
1030 const wxPoint
& spos
= wxPoint(-1,-1));
1031 // Continue selecting text
1032 void ContinueSelection(const wxPoint
& cpos
= wxPoint(-1,-1),
1033 const wxPoint
& spos
= wxPoint(-1,-1));
1034 /// End selecting text.
1035 void EndSelection(const wxPoint
& cpos
= wxPoint(-1,-1),
1036 const wxPoint
& spos
= wxPoint(-1,-1));
1037 /// Discard the current selection
1038 void DiscardSelection();
1039 /// Are we still selecting text?
1040 bool IsSelecting(void);
1041 /// Is the given point (text coords) selected?
1042 bool IsSelected(const wxPoint
&cursor
);
1043 /// Do we have a non null selection?
1044 bool HasSelection() const
1045 { return m_Selection
.m_valid
|| m_Selection
.m_selecting
; }
1047 /** Return the selection as a wxLayoutList.
1048 @param invalidate if true, the selection will be invalidated after this and can no longer be used.
1049 @return Another layout list object holding the selection, must be freed by caller
1051 wxLayoutList
*GetSelection(class wxLayoutDataObject
*wxldo
= NULL
, bool invalidate
= TRUE
);
1052 /// Delete selected bit
1053 void DeleteSelection(void);
1055 wxLayoutList
*Copy(const wxPoint
&from
= wxPoint(0,0),
1056 const wxPoint
&to
= wxPoint(-1,-1));
1058 /// starts highlighting of text for selections
1059 void StartHighlighting(wxDC
&dc
);
1060 /// ends highlighting of text for selections
1061 void EndHighlighting(wxDC
&dc
);
1063 /** Tests whether this layout line is selected and needs
1065 @param line to test for
1066 @param from set to first cursorpos to be highlighted (for returncode == -1)
1067 @param to set to last cursorpos to be highlighted (for returncode == -1)
1068 @return 0 = not selected, 1 = fully selected, -1 = partially
1072 int IsSelected(const wxLayoutLine
*line
, CoordType
*from
, CoordType
*to
);
1074 void ApplyStyle(wxLayoutStyleInfo
const &si
, wxDC
&dc
);
1075 #ifdef WXLAYOUT_DEBUG
1081 void InternalClear(void);
1083 /// The list of lines.
1084 wxLayoutLine
*m_FirstLine
;
1085 /// The update rectangle which needs to be refreshed:
1086 wxRect m_UpdateRect
;
1087 /// Is the update rectangle valid?
1088 bool m_UpdateRectValid
;
1089 /**@name Cursor Management */
1091 /// Where the text cursor (column,line) is.
1092 wxPoint m_CursorPos
;
1093 /// Where the cursor should be drawn.
1094 wxPoint m_CursorScreenPos
;
1095 /// The line where the cursor is.
1096 wxLayoutLine
*m_CursorLine
;
1097 /// The size of the cursor.
1098 wxPoint m_CursorSize
;
1099 /// Has the cursor moved (is m_CursorScreenPos up to date)?
1101 #ifdef WXLAYOUT_USE_CARET
1104 #endif // WXLAYOUT_USE_CARET
1107 /// selection.state and begin/end coordinates
1110 Selection() { m_valid
= false; m_selecting
= false; }
1114 // returns true if we already have the screen coordinates of the
1115 // selection start and end
1116 bool HasValidScreenCoords() const
1117 { return m_ScreenA
.x
!= -1 && m_ScreenB
.x
!= -1; }
1119 // the start and end of the selection coordinates in pixels
1120 wxPoint m_ScreenA
, m_ScreenB
;
1122 // these coordinates are in text positions, not in pixels
1123 wxPoint m_CursorA
, m_CursorB
;
1125 /** @name Font parameters. */
1127 /// this object manages the fonts for us
1128 wxFontCache m_FontCache
;
1129 /// the default setting:
1130 wxLayoutStyleInfo m_DefaultStyleInfo
;
1131 /// the current setting:
1132 wxLayoutStyleInfo m_CurrentStyleInfo
;
1136 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1138 The wxLayoutDataObject for exporting data to the clipboard in our
1141 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1142 class wxLayoutDataObject
: public wxPrivateDataObject
1145 wxLayoutDataObject(void)
1147 SetId("application/wxlayoutlist");
1148 //m_format.SetAtom((GdkAtom) 222222);
1152 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1154 The wxLayoutPrintout object for printing within the wxWindows print
1157 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1158 /** This class implements a wxPrintout for printing a wxLayoutList within
1159 the wxWindows printing framework.
1161 class wxLayoutPrintout
: public wxPrintout
1165 @param llist pointer to the wxLayoutList to be printed
1166 @param title title for PS file or windows
1168 wxLayoutPrintout(wxLayoutList
*llist
,
1169 wxString
const & title
=
1170 "wxLayout Printout");
1172 ~wxLayoutPrintout();
1174 /** Function which prints the n-th page.
1175 @param page the page number to print
1176 @return bool true if we are not at end of document yet
1178 bool OnPrintPage(int page
);
1179 /** Checks whether page exists in document.
1180 @param page number of page
1181 @return true if page exists
1183 bool HasPage(int page
);
1185 /** Gets called from wxWindows to find out which pages are existing.
1186 I'm not totally sure about the parameters though.
1187 @param minPage the first page in the document
1188 @param maxPage the last page in the document
1189 @param selPageFrom the first page to be printed
1190 @param selPageTo the last page to be printed
1192 void GetPageInfo(int *minPage
, int *maxPage
,
1193 int *selPageFrom
, int *selPageTo
);
1195 /** This little function scales the DC so that the printout has
1196 roughly the same size as the output on screen.
1197 @param dc the wxDC to scale
1198 @return the scale that was applied
1200 float ScaleDC(wxDC
*dc
);
1203 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1206 /// The list to print.
1207 wxLayoutList
*m_llist
;
1208 /// Title for PS file or window.
1210 /// The real paper size.
1211 int m_PageHeight
, m_PageWidth
;
1212 /// How much we actually print per page.
1213 int m_PrintoutHeight
;
1214 /// How many pages we need to print.
1216 /// Top left corner where we start printing.