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
63 /// Types of currently supported layout objects.
64 enum wxLayoutObjectType
66 /// illegal object type, should never appear
67 WXLO_TYPE_INVALID
= 0,
68 /// text object, containing normal text
70 /// command object, containing font or colour changes
72 /// icon object, any kind of image
76 /// Type used for coordinates in drawing. Must be signed.
77 typedef long CoordType
;
79 // Forward declarations.
84 class WXDLLEXPORT wxCaret
;
85 class WXDLLEXPORT wxColour
;
86 class WXDLLEXPORT wxDC
;
87 class WXDLLEXPORT wxFont
;
89 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
91 The wxLayout objects which make up the lines.
93 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
95 /** The base class defining the interface to each object which can be
96 part of the layout. Each object needs to draw itself and calculate
102 /** This structure can be used to contain data associated with the
104 It is refcounted, so the caller has to do a DecRef() on it
109 UserData() { m_refcount
= 1; }
110 inline void IncRef(void) { m_refcount
++; }
111 inline void DecRef(void) { m_refcount
--; if(m_refcount
== 0) delete this;}
112 inline void SetLabel(const wxString
&l
) { m_label
= l
; }
113 inline const wxString
& GetLabel(void) const { return m_label
; }
118 virtual ~UserData() { wxASSERT(m_refcount
== 0); }
119 /// prevents gcc from generating stupid warnings
120 friend class dummy_UserData
;
123 /// return the type of this object
124 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_INVALID
; }
125 /** Calculates the size of an object.
126 @param dc the wxDC to draw on
127 @param llist the wxLayoutList
129 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
) = 0;
132 @param dc the wxDC to draw on
133 @param coords where to draw the baseline of the object.
134 @param wxllist pointer to wxLayoutList
135 @param begin if !=-1, from which position on to highlight it
136 @param end if begin !=-1, how many positions to highlight it
138 virtual void Draw(wxDC
& /* dc */,
139 wxPoint
const & /* coords */,
140 wxLayoutList
*wxllist
,
141 CoordType begin
= -1,
142 CoordType end
= -1) { }
144 /** Calculates and returns the size of the object.
145 @param top where to store height above baseline
146 @param bottom where to store height below baseline
147 @return the size of the object's box in pixels
149 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const
150 { *top
= 0; *bottom
= 0; return wxPoint(0,0); }
152 /// Return just the width of the object on the screen.
153 virtual CoordType
GetWidth(void) const { return 0; }
154 /// returns the number of cursor positions occupied by this object
155 virtual CoordType
GetLength(void) const { return 1; }
156 /** Returns the cursor offset relating to the screen x position
157 relative to begin of object.
158 @param dc the wxDC to use for calculations
159 @param xpos relative x position from head of object
160 @return cursor coordinate offset
162 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const { return 0; }
165 wxLayoutObject() { m_UserData
= NULL
; }
166 /// delete the user data
167 virtual ~wxLayoutObject() { if(m_UserData
) m_UserData
->DecRef(); }
169 #ifdef WXLAYOUT_DEBUG
170 virtual void Debug(void);
173 /** Tells the object about some user data. This data is associated
174 with the object and will be deleted at destruction time.
175 It is reference counted.
177 void SetUserData(UserData
*data
)
180 m_UserData
->DecRef();
183 m_UserData
->IncRef();
186 /** Return the user data.
187 Increments the object's reference count. When no longer needed,
188 caller must call DecRef() on the pointer returned.
190 UserData
* GetUserData(void) const { if(m_UserData
) m_UserData
->IncRef(); return m_UserData
; }
192 /** Makes a copy of this object.
194 virtual wxLayoutObject
*Copy(void) = 0;
196 /** Clipboard support function. Read and write objects to
199 /// Writes the object to the string.
200 virtual void Write(wxString
&ostr
) = 0;
202 @param str stream to read from, will bee changed
203 @return true on success
205 static wxLayoutObject
*Read(wxString
&istr
);
208 /// optional data for application's use
209 UserData
*m_UserData
;
212 /// Define a list type of wxLayoutObject pointers.
213 KBLIST_DEFINE(wxLayoutObjectList
, wxLayoutObject
);
215 /// An illegal iterator to save typing.
216 #define NULLIT (wxLayoutObjectList::iterator(NULL))
217 /// The iterator type.
218 #define wxLOiterator wxLayoutObjectList::iterator
220 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
224 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
225 /** This class implements a wxLayoutObject holding plain text.
227 class wxLayoutObjectText
: public wxLayoutObject
230 wxLayoutObjectText(const wxString
&txt
= "");
232 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_TEXT
; }
233 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
234 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
235 wxLayoutList
*wxllist
,
236 CoordType begin
= -1,
238 /** Calculates and returns the size of the object.
239 @param top where to store height above baseline
240 @param bottom where to store height below baseline
241 @return the size of the object's box in pixels
243 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
244 /// Return just the width of the object on the screen.
245 virtual CoordType
GetWidth(void) const { return m_Width
; }
246 /** Returns the cursor offset relating to the screen x position
247 relative to begin of object.
248 @param dc the wxDC to use for calculations
249 @param xpos relative x position from head of object
250 @return cursor coordinate offset
252 virtual CoordType
GetOffsetScreen(wxDC
&dc
, CoordType xpos
) const;
254 virtual void Write(wxString
&ostr
);
255 static wxLayoutObjectText
*Read(wxString
&istr
);
257 #ifdef WXLAYOUT_DEBUG
258 virtual void Debug(void);
261 virtual CoordType
GetLength(void) const { return strlen(m_Text
.c_str()); }
264 wxString
& GetText(void) { return m_Text
; }
265 void SetText(wxString
const &text
) { m_Text
= text
; }
266 /** Makes a copy of this object.
268 virtual wxLayoutObject
*Copy(void);
271 /// size of the box containing text
272 long m_Width
, m_Height
;
273 /// Height above baseline.
275 /// Height below baseline.
279 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
283 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
284 /** This class implements a wxLayoutObject holding a graphic.
286 class wxLayoutObjectIcon
: public wxLayoutObject
289 wxLayoutObjectIcon(wxBitmap
*icon
= NULL
);
290 wxLayoutObjectIcon(wxBitmap
const &icon
);
292 ~wxLayoutObjectIcon() { if(m_Icon
) delete m_Icon
; }
294 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_ICON
; }
295 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
296 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
297 wxLayoutList
*wxllist
,
298 CoordType begin
= -1,
301 /** Calculates and returns the size of the object.
302 @param top where to store height above baseline
303 @param bottom where to store height below baseline
304 @return the size of the object's box in pixels
306 virtual wxPoint
GetSize(CoordType
* top
, CoordType
*bottom
) const;
307 /// Return just the width of the object on the screen.
308 virtual CoordType
GetWidth(void) const { return m_Icon
->GetWidth(); }
309 // return a pointer to the icon
310 wxBitmap
*GetIcon(void) const { return m_Icon
; }
311 /** Makes a copy of this object.
313 virtual wxLayoutObject
*Copy(void);
314 virtual void Write(wxString
&ostr
);
315 static wxLayoutObjectIcon
*Read(wxString
&istr
);
320 /** This structure holds all formatting information. Members which are
321 undefined (for a CmdObject this means: no change), are set to -1.
323 struct wxLayoutStyleInfo
325 wxLayoutStyleInfo(int ifamily
= -1,
331 wxColour
*bg
= NULL
);
332 wxColour
& GetBGColour()
336 wxLayoutStyleInfo
& operator=(const wxLayoutStyleInfo
&right
);
337 /// Font change parameters.
338 int size
, family
, style
, weight
, underline
;
341 int m_fg_valid
, m_bg_valid
; // bool, but must be int!
345 class wxFontCacheEntry
348 wxFontCacheEntry(int family
, int size
, int style
, int weight
,
351 m_Family
= family
; m_Size
= size
; m_Style
= style
;
352 m_Weight
= weight
; m_Underline
= underline
;
353 m_Font
= new wxFont(m_Size
, m_Family
,
354 m_Style
, m_Weight
, m_Underline
);
356 bool Matches(int family
, int size
, int style
, int weight
,
357 bool underline
) const
359 return size
== m_Size
&& family
== m_Family
360 && style
== m_Style
&& weight
== m_Weight
361 && underline
== m_Underline
;
363 wxFont
& GetFont(void) { return *m_Font
; }
370 int m_Family
, m_Size
, m_Style
, m_Weight
;
374 KBLIST_DEFINE(wxFCEList
, wxFontCacheEntry
);
379 wxFont
& GetFont(int family
, int size
, int style
, int weight
,
381 wxFont
& GetFont(wxLayoutStyleInfo
const &si
)
383 return GetFont(si
.family
, si
.size
, si
.style
, si
.weight
,
387 wxFCEList m_FontList
;
390 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
394 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
395 /** This class implements a wxLayoutObject holding style change commands.
397 class wxLayoutObjectCmd
: public wxLayoutObject
400 virtual wxLayoutObjectType
GetType(void) const { return WXLO_TYPE_CMD
; }
401 virtual void Layout(wxDC
&dc
, wxLayoutList
*llist
);
402 virtual void Draw(wxDC
&dc
, wxPoint
const &coords
,
403 wxLayoutList
*wxllist
,
404 CoordType begin
= -1,
406 wxLayoutObjectCmd(int family
= -1,
412 wxColour
*bg
= NULL
);
413 ~wxLayoutObjectCmd();
414 /** Stores the current style in the styleinfo structure */
415 wxLayoutStyleInfo
* GetStyle(void) const;
416 /** Makes a copy of this object.
418 virtual wxLayoutObject
*Copy(void);
419 virtual void Write(wxString
&ostr
);
420 static wxLayoutObjectCmd
*Read(wxString
&istr
);
422 wxLayoutStyleInfo
*m_StyleInfo
;
425 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
427 The wxLayoutLine object
429 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
431 /** This class represents a single line of objects to be displayed.
432 It knows its height and total size and whether it needs to be
434 It has pointers to its first and next line so it can automatically
435 update them as needed.
441 @param prev pointer to previous line or NULL
442 @param next pointer to following line or NULL
443 @param llist pointer to layout list
445 wxLayoutLine(wxLayoutLine
*prev
, wxLayoutList
*llist
);
446 /** This function inserts a new object at cursor position xpos.
447 @param xpos where to insert new object
448 @param obj the object to insert
449 @return true if that xpos existed and the object was inserted
451 bool Insert(CoordType xpos
, wxLayoutObject
*obj
);
453 /** This function inserts text at cursor position xpos.
454 @param xpos where to insert
455 @param text the text to insert
456 @return true if that xpos existed and the object was inserted
458 bool Insert(CoordType xpos
, const wxString
& text
);
460 /** This function appends an object to the line.
461 @param obj the object to insert
463 void Append(wxLayoutObject
* obj
)
467 m_ObjectList
.push_back(obj
);
468 m_Length
+= obj
->GetLength();
471 /** This function appens the next line to this, i.e. joins the two
474 void MergeNextLine(wxLayoutList
*llist
);
476 /** This function deletes npos cursor positions from position xpos.
477 @param xpos where to delete
478 @param npos how many positions
479 @return number of positions still to be deleted
481 CoordType
Delete(CoordType xpos
, CoordType npos
);
483 /** This function breaks the line at a given cursor position.
484 @param xpos where to break it
485 @return pointer to the new line object replacing the old one
487 wxLayoutLine
*Break(CoordType xpos
, wxLayoutList
*llist
);
489 /** Deletes the next word from this position, including leading
491 This function does not delete over font changes, i.e. a word
492 with formatting instructions in the middle of it is treated as
493 two (three actually!) words. In fact, if the cursor is on a non-text object, that
494 one is treated as a word.
495 @param xpos from where to delete
496 @return true if a word was deleted
498 bool DeleteWord(CoordType npos
);
500 /** Finds a suitable position left to the given column to break the
502 @param column we want to break the line to the left of this
503 @return column for breaking line or -1 if no suitable location found
505 CoordType
GetWrapPosition(CoordType column
);
507 /** Finds the object which covers the cursor position xpos in this
509 @param xpos the column number
510 @param offset where to store the difference between xpos and
512 @return iterator to the object or NULLIT
514 wxLayoutObjectList::iterator
FindObject(CoordType xpos
, CoordType
517 /** Finds the object which covers the screen position xpos in this
519 @param dc the wxDC to use for calculations
520 @param xpos the screen x coordinate
521 @param offset where to store the difference between xpos and
523 @return iterator to the object or NULLIT
525 wxLayoutObjectList::iterator
FindObjectScreen(wxDC
&dc
,
528 bool *found
= NULL
) const ;
530 /** Finds text in this line.
531 @param needle the text to find
532 @param xpos the position where to start the search
533 @return the cursoor coord where it was found or -1
535 CoordType
FindText(const wxString
&needle
, CoordType xpos
= 0) const;
537 /** Get the first object in the list. This is used by the wxlparser
538 functions to export the list.
539 @return iterator to the first object
541 wxLayoutObjectList::iterator
GetFirstObject(void)
543 return m_ObjectList
.begin();
546 /** Deletes this line, returns pointer to next line.
547 @param update If true, update all following lines.
549 wxLayoutLine
*DeleteLine(bool update
, wxLayoutList
*llist
);
551 /**@name Cursor Management */
553 /** Return the line number of this line.
554 @return the line number
556 inline CoordType
GetLineNumber(void) const { return m_LineNumber
; }
557 /** Return the length of the line.
558 @return line lenght in cursor positions
560 inline CoordType
GetLength(void) const { return m_Length
; }
563 /**@name Drawing and Layout */
565 /** Draws the line on a wxDC.
566 @param dc the wxDC to draw on
567 @param llist the wxLayoutList
568 @param offset an optional offset to shift printout
572 const wxPoint
&offset
= wxPoint(0,0)) const;
574 /** Recalculates the positions of objects and the height of the
576 @param dc the wxDC to draw on
577 @param llist th e wxLayoutList
578 @param cursorPos if not NULL, set cursor screen position in there
579 @param cursorSize if not cursorPos != NULL, set cursor size in there
580 @param cx if cursorPos != NULL, the cursor x position
582 void Layout(wxDC
&dc
,
584 wxPoint
*cursorPos
= NULL
,
585 wxPoint
*cursorSize
= NULL
,
587 /** This function finds an object belonging to a given cursor
588 position. It assumes that Layout() has been called before.
589 @param dc the wxDC to use for calculations
590 @param xpos screen x position
591 @param found if non-NULL set to false if we return the last
592 object before the cursor, to true if we really have an object
594 @return pointer to the object
596 wxLayoutObject
* FindObjectScreen(wxDC
&dc
, CoordType xpos
, bool
601 /**@name List traversal */
603 /// Returns pointer to next line.
604 wxLayoutLine
*GetNextLine(void) const { return m_Next
; }
605 /// Returns pointer to previous line.
606 wxLayoutLine
*GetPreviousLine(void) const { return m_Previous
; }
607 /// Sets the link to the next line.
608 void SetNext(wxLayoutLine
*next
)
609 { m_Next
= next
; if(next
) next
->m_Previous
= this; }
610 /// Sets the link to the previous line.
611 void SetPrevious(wxLayoutLine
*previous
)
612 { m_Previous
= previous
; if(previous
) previous
->m_Next
= this; }
615 /// Returns the position of this line on the canvas.
616 wxPoint
GetPosition(void) const { return m_Position
; }
617 /// Returns the height of this line.
618 CoordType
GetHeight(void) const { return m_Height
; }
619 /// Returns the width of this line.
620 CoordType
GetWidth(void) const { return m_Width
; }
621 /** This will recalculate the position and size of this line.
622 If called recursively it will abort if the position of an
623 object is unchanged, assuming that none of the following
624 objects need to move.
625 @param recurse if greater 0 then it will be used as the
626 minimum(!) recursion level, continue with all lines till the end of
627 the list or until the coordinates no longer changed.
629 void RecalculatePositions(int recurse
, wxLayoutList
*llist
);
630 /// Recalculates the position of this line on the canvas.
631 wxPoint
RecalculatePosition(wxLayoutList
*llist
);
633 /** Copies the contents of this line to another wxLayoutList
634 @param llist the wxLayoutList destination
635 @param from x cursor coordinate where to start
636 @param to x cursor coordinate where to stop, -1 for end of line
638 void Copy(wxLayoutList
*llist
,
642 #ifdef WXLAYOUT_DEBUG
645 wxLayoutStyleInfo
&GetStyleInfo() { return m_StyleInfo
; }
647 /// Returns dirty state
648 bool IsDirty(void) const { return m_Dirty
; }
649 /// Marks line as diry.
650 void MarkDirty(CoordType left
= -1)
654 if ( m_updateLeft
== -1 || left
< m_updateLeft
)
660 /// Reset the dirty flag
661 void MarkClean() { m_Dirty
= false; m_updateLeft
= -1; }
664 /// Destructor is private. Use DeleteLine() to remove it.
667 /**@name Functions to let the lines synchronise with each other. */
669 /** Sets the height of this line. Will mark following lines as
671 @param height new height
673 void SetHeight(CoordType height
, wxLayoutList
*llist
)
674 { m_Height
= height
; RecalculatePositions(true, llist
); }
676 /** Moves the linenumbers one on, because a line has been inserted
678 @param delta either +1 or -1
680 void MoveLines(int delta
)
682 m_LineNumber
+= delta
;
683 if(m_Next
) m_Next
->MoveLines(delta
);
688 CoordType m_LineNumber
;
689 /// The line length in cursor positions.
691 /// The total height of the line.
693 /// The total width of the line on screen.
695 /// The baseline for drawing objects
696 CoordType m_BaseLine
;
697 /// The position on the canvas.
699 /// The list of objects
700 wxLayoutObjectList m_ObjectList
;
701 /// Have we been changed since the last layout?
703 /// The coordinate of the left boundary of the update rectangle (if m_Dirty)
704 CoordType m_updateLeft
;
705 /// Pointer to previous line if it exists.
706 wxLayoutLine
*m_Previous
;
707 /// Pointer to next line if it exists.
708 wxLayoutLine
*m_Next
;
709 /// A StyleInfo structure, holding the current settings.
710 wxLayoutStyleInfo m_StyleInfo
;
711 /// Just to suppress gcc compiler warnings.
714 wxLayoutLine(const wxLayoutLine
&);
718 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
720 The wxLayoutList object
722 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
723 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
724 higher level of abstraction for the text and can generally be considered
725 as representing "the text".
735 #ifdef WXLAYOUT_USE_CARET
736 /// give us the pointer to the caret to use
737 void SetCaret(wxCaret
*caret
) { m_caret
= caret
; }
738 #endif // WXLAYOUT_USE_CARET
741 void Clear(int family
= wxROMAN
,
742 int size
=WXLO_DEFAULTFONTSIZE
,
748 /// Empty: clear the list but leave font settings.
751 /**@name Cursor Management */
753 /** Set new cursor position.
754 @param p new position
755 @return bool if it could be set
757 bool MoveCursorTo(wxPoint
const &p
);
758 /** Move cursor up or down.
760 @return bool if it could be moved
762 bool MoveCursorVertically(int n
);
763 /** Move cursor left or right.
765 @return bool if it could be moved
767 bool MoveCursorHorizontally(int n
);
769 /// Move cursor to end of line.
770 void MoveCursorToEndOfLine(void)
772 wxASSERT(m_CursorLine
);
773 MoveCursorHorizontally(m_CursorLine
->GetLength()-m_CursorPos
.x
);
776 /// Move cursor to begin of line.
777 void MoveCursorToBeginOfLine(void)
778 { MoveCursorHorizontally(-m_CursorPos
.x
); }
780 /// Returns current cursor position.
781 const wxPoint
&GetCursorPos(wxDC
&dc
) const { return m_CursorPos
; }
782 const wxPoint
&GetCursorPos() const { return m_CursorPos
; }
786 /**@name Editing functions.
787 All of these functions return true on success and false on
790 /// Insert text at current cursor position.
791 bool Insert(wxString
const &text
);
792 /// Insert some other object at current cursor position.
793 bool Insert(wxLayoutObject
*obj
);
794 /// Inserts objects at current cursor positions
795 bool Insert(wxLayoutList
*llist
);
797 /// Inserts a linebreak at current cursor position.
798 bool LineBreak(void);
799 /** Wraps the current line. Searches to the left of the cursor to
800 break the line. Does nothing if the cursor position is before
801 the break position parameter.
802 @param column the break position for the line, maximum length
803 @return true if line got broken
805 bool WrapLine(CoordType column
);
806 /** This function deletes npos cursor positions.
807 @param npos how many positions
808 @return true if everything got deleted
810 bool Delete(CoordType npos
);
812 /** Delete the next n lines.
813 @param n how many lines to delete
814 @return how many it could not delete
816 int DeleteLines(int n
);
818 /// Delete to end of line.
819 void DeleteToEndOfLine(void)
821 wxASSERT(m_CursorLine
);
822 Delete(m_CursorLine
->GetLength()-m_CursorPos
.x
);
824 /// Delete to begin of line.
825 void DeleteToBeginOfLine(void)
827 wxASSERT(m_CursorLine
);
828 CoordType n
= m_CursorPos
.x
;
829 #ifdef WXLAYOUT_DEBUG
830 wxASSERT(MoveCursorHorizontally(-n
));
832 MoveCursorHorizontally(-n
);
837 /** Delete the next word.
839 void DeleteWord(void)
841 wxASSERT(m_CursorLine
);
842 m_CursorLine
->DeleteWord(m_CursorPos
.x
);
847 /** Finds text in this list.
848 @param needle the text to find
849 @param cpos the position where to start the search
850 @return the cursoor coord where it was found or (-1,-1)
852 wxPoint
FindText(const wxString
&needle
, const wxPoint
&cpos
= wxPoint(0,0)) const;
854 /**@name Formatting options */
856 /// sets font parameters
857 void SetFont(int family
, int size
, int style
,
858 int weight
, int underline
,
861 /// sets font parameters, colours by name
862 void SetFont(int family
=-1, int size
= -1, int style
=-1,
863 int weight
=-1, int underline
= -1,
864 char const *fg
= NULL
,
865 char const *bg
= NULL
);
866 /// changes to the next larger font size
867 inline void SetFontLarger(void)
868 { SetFont(-1,(12*m_CurrentSetting
.size
)/10); }
869 /// changes to the next smaller font size
870 inline void SetFontSmaller(void)
871 { SetFont(-1,(10*m_CurrentSetting
.size
)/12); }
874 inline void SetFontFamily(int family
) { SetFont(family
); }
876 inline void SetFontSize(int size
) { SetFont(-1,size
); }
878 inline void SetFontStyle(int style
) { SetFont(-1,-1,style
); }
880 inline void SetFontWeight(int weight
) { SetFont(-1,-1,-1,weight
); }
881 /// toggle underline flag
882 inline void SetFontUnderline(bool ul
) { SetFont(-1,-1,-1,-1,(int)ul
); }
883 /// set font colours by name
884 inline void SetFontColour(char const *fg
, char const *bg
= NULL
)
885 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
886 /// set font colours by colour
887 inline void SetFontColour(wxColour
*fg
, wxColour
*bg
= NULL
)
888 { SetFont(-1,-1,-1,-1,-1,fg
,bg
); }
892 Returns a pointer to the default settings.
893 This is only valid temporarily and should not be stored
895 @return the default settings of the list
897 wxLayoutStyleInfo
*GetDefaults(void) { return &m_DefaultSetting
; }
898 wxLayoutStyleInfo
*GetStyleInfo(void) { return &m_CurrentSetting
; }
903 /** Draws the complete list on a wxDC.
904 @param dc the wxDC to draw on
905 @param offset an optional offset to shift printout
906 @param top optional y coordinate where to start drawing
907 @param bottom optional y coordinate where to stop drawing
910 const wxPoint
&offset
= wxPoint(0,0),
911 CoordType top
= -1, CoordType bottom
= -1);
913 /** Calculates new layout for the list, like Draw() but does not
915 @param dc the wxDC to draw on
916 @param bottom optional y coordinate where to stop calculating
917 @param forceAll force re-layout of all lines
919 void Layout(wxDC
&dc
, CoordType bottom
= -1, bool forceAll
= false);
921 /** Calculates new sizes for everything in the list, like Layout()
922 but this is needed after the list got changed.
923 @param dc the wxDC to draw on
924 @param bottom optional y coordinate where to stop calculating
926 void Recalculate(wxDC
&dc
, CoordType bottom
= -1);
928 /** Returns the size of the list in screen coordinates.
929 The return value only makes sense after the list has been
931 @return a wxPoint holding the maximal x/y coordinates used for
934 wxPoint
GetSize(void) const;
936 /** Returns the cursor position on the screen.
937 @return cursor position in pixels
939 wxPoint
GetCursorScreenPos(wxDC
&dc
);
941 /** Draws the cursor.
942 @param active If true, draw a bold cursor to mark window as
944 @param translate optional translation of cursor coords on screen
946 void DrawCursor(wxDC
&dc
,
948 const wxPoint
& translate
= wxPoint(0,0));
950 /** This function finds an object belonging to a given screen
951 position. It assumes that Layout() has been called before.
952 @param pos screen position
953 @param cursorPos if non NULL, store cursor position in there
954 @param found if used, set this to true if we really found an
955 object, to false if we had to take the object near to it
956 @return pointer to the object
958 wxLayoutObject
* FindObjectScreen(wxDC
&dc
,
960 wxPoint
*cursorPos
= NULL
,
963 /** Called by the objects to update the update rectangle.
964 @param x horizontal coordinate to include in rectangle
965 @param y vertical coordinate to include in rectangle
967 void SetUpdateRect(CoordType x
, CoordType y
);
968 /** Called by the objects to update the update rectangle.
969 @param p a point to include in it
971 inline void SetUpdateRect(const wxPoint
&p
)
972 { SetUpdateRect(p
.x
,p
.y
); }
973 /// adds the cursor position to the update rectangle
974 void AddCursorPosToUpdateRect()
976 #ifndef WXLAYOUT_USE_CARET
977 SetUpdateRect(m_CursorScreenPos
);
978 SetUpdateRect(m_CursorScreenPos
+m_CursorSize
);
979 //#else - the caret will take care of refreshing itself
980 #endif // !WXLAYOUT_USE_CARET
982 /// Invalidates the update rectangle.
983 void InvalidateUpdateRect(void) { m_UpdateRectValid
= false; }
984 /// Returns the update rectangle.
985 const wxRect
*GetUpdateRect(void) const { return &m_UpdateRect
; }
988 /**@name For exporting one object after another. */
990 /** Returns a pointer to the first line in the list. */
991 wxLayoutLine
*GetFirstLine(void)
993 wxASSERT(m_FirstLine
);
998 /// Begin selecting text.
999 void StartSelection(wxPoint cpos
= wxPoint(-1,-1));
1000 // Continue selecting text
1001 void ContinueSelection(wxPoint cpos
= wxPoint(-1,-1));
1002 /// End selecting text.
1003 void EndSelection(wxPoint cpos
= wxPoint(-1,-1));
1004 /// Are we still selecting text?
1005 bool IsSelecting(void);
1006 bool IsSelected(const wxPoint
&cursor
);
1008 /** Return the selection as a wxLayoutList.
1009 @param invalidate if true, the selection will be invalidated after this and can no longer be used.
1010 @return Another layout list object holding the selection, must be freed by caller
1012 wxLayoutList
*GetSelection(class wxLayoutDataObject
*wxldo
= NULL
, bool invalidate
= TRUE
);
1013 /// Delete selected bit
1014 void DeleteSelection(void);
1016 wxLayoutList
*Copy(const wxPoint
&from
= wxPoint(0,0),
1017 const wxPoint
&to
= wxPoint(-1,-1));
1019 /// starts highlighting of text for selections
1020 void StartHighlighting(wxDC
&dc
);
1021 /// ends highlighting of text for selections
1022 void EndHighlighting(wxDC
&dc
);
1024 /** Tests whether this layout line is selected and needs
1026 @param line to test for
1027 @param from set to first cursorpos to be highlighted (for returncode == -1)
1028 @param to set to last cursorpos to be highlighted (for returncode == -1)
1029 @return 0 = not selected, 1 = fully selected, -1 = partially
1033 int IsSelected(const wxLayoutLine
*line
, CoordType
*from
, CoordType
*to
);
1035 void ApplyStyle(wxLayoutStyleInfo
*si
, wxDC
&dc
);
1036 #ifdef WXLAYOUT_DEBUG
1041 void InternalClear(void);
1042 /** Calculates the cursor position on the screen.
1044 void UpdateCursorScreenPos(wxDC
&dc
);
1046 /// The list of lines.
1047 wxLayoutLine
*m_FirstLine
;
1048 /// The update rectangle which needs to be refreshed:
1049 wxRect m_UpdateRect
;
1050 /// Is the update rectangle valid?
1051 bool m_UpdateRectValid
;
1052 /**@name Cursor Management */
1054 /// Where the text cursor (column,line) is.
1055 wxPoint m_CursorPos
;
1056 /// Where the cursor should be drawn.
1057 wxPoint m_CursorScreenPos
;
1058 /// The line where the cursor is.
1059 wxLayoutLine
*m_CursorLine
;
1060 /// The size of the cursor.
1061 wxPoint m_CursorSize
;
1062 #ifdef WXLAYOUT_USE_CARET
1065 #endif // WXLAYOUT_USE_CARET
1068 /// A structure for the selection.
1071 Selection() { m_valid
= false; m_selecting
= false; }
1074 wxPoint m_CursorA
, m_CursorB
;
1076 /** @name Font parameters. */
1078 /// this object manages the fonts for us
1079 wxFontCache m_FontCache
;
1080 /// the default setting:
1081 wxLayoutStyleInfo m_DefaultSetting
;
1082 /// the current setting:
1083 wxLayoutStyleInfo m_CurrentSetting
;
1087 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1089 The wxLayoutDataObject for exporting data to the clipboard in our
1092 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1093 class wxLayoutDataObject
: public wxPrivateDataObject
1096 wxLayoutDataObject(void)
1098 SetId("application/wxlayoutlist");
1099 //m_format.SetAtom((GdkAtom) 222222);
1103 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1105 The wxLayoutPrintout object for printing within the wxWindows print
1108 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1109 /** This class implements a wxPrintout for printing a wxLayoutList within
1110 the wxWindows printing framework.
1112 class wxLayoutPrintout
: public wxPrintout
1116 @param llist pointer to the wxLayoutList to be printed
1117 @param title title for PS file or windows
1119 wxLayoutPrintout(wxLayoutList
*llist
,
1120 wxString
const & title
=
1121 "wxLayout Printout");
1123 ~wxLayoutPrintout();
1125 /** Function which prints the n-th page.
1126 @param page the page number to print
1127 @return bool true if we are not at end of document yet
1129 bool OnPrintPage(int page
);
1130 /** Checks whether page exists in document.
1131 @param page number of page
1132 @return true if page exists
1134 bool HasPage(int page
);
1136 /** Gets called from wxWindows to find out which pages are existing.
1137 I'm not totally sure about the parameters though.
1138 @param minPage the first page in the document
1139 @param maxPage the last page in the document
1140 @param selPageFrom the first page to be printed
1141 @param selPageTo the last page to be printed
1143 void GetPageInfo(int *minPage
, int *maxPage
,
1144 int *selPageFrom
, int *selPageTo
);
1146 /** This little function scales the DC so that the printout has
1147 roughly the same size as the output on screen.
1148 @param dc the wxDC to scale
1149 @return the scale that was applied
1151 float ScaleDC(wxDC
*dc
);
1154 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1157 /// The list to print.
1158 wxLayoutList
*m_llist
;
1159 /// Title for PS file or window.
1161 /// The real paper size.
1162 int m_PageHeight
, m_PageWidth
;
1163 /// How much we actually print per page.
1164 int m_PrintoutHeight
;
1165 /// How many pages we need to print.
1167 /// Top left corner where we start printing.