]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxllist.h
52c87053db3e94020bfb2ce1ea610cac2de1e5eb
[wxWidgets.git] / user / wxLayout / wxllist.h
1 /*-*- c++ -*-********************************************************
2 * wxLayoutList.h - a formatted text rendering engine for wxWindows *
3 * *
4 * (C) 1999 by Karsten Ballüder (Ballueder@usa.net) *
5 * *
6 * $Id$
7 *******************************************************************/
8
9
10 #ifndef WXLLIST_H
11 #define WXLLIST_H
12
13 #ifdef __GNUG__
14 # pragma interface "wxllist.h"
15 #endif
16
17 #include "kbList.h"
18
19 #include "wx/wx.h"
20 #include "wx/print.h"
21 #include "wx/printdlg.h"
22 #include "wx/generic/printps.h"
23 #include "wx/generic/prntdlgg.h"
24
25 // skip the following defines if embedded in M application
26 #ifndef M_BASEDIR
27 # define WXMENU_LAYOUT_LCLICK 1111
28 # define WXMENU_LAYOUT_RCLICK 1112
29 # define WXMENU_LAYOUT_DBLCLICK 1113
30 #endif
31
32 // do not enable debug mode within Mahogany
33 #if defined(__WXDEBUG__) && ! defined(M_BASEDIR)
34 # define WXLAYOUT_DEBUG
35 #endif
36
37 #ifdef WXLAYOUT_DEBUG
38 # define WXLO_TRACE(x) wxLogDebug(x)
39 #else
40 # define WXLO_TRACE(x)
41 #endif
42
43 #define WXLO_DEBUG_URECT 0
44
45 #ifndef WXLO_DEFAULTFONTSIZE
46 # define WXLO_DEFAULTFONTSIZE 12
47 #endif
48
49
50 /// Types of currently supported layout objects.
51 enum wxLayoutObjectType
52 {
53 /// illegal object type, should never appear
54 WXLO_TYPE_INVALID = 0,
55 /// text object, containing normal text
56 WXLO_TYPE_TEXT,
57 /// command object, containing font or colour changes
58 WXLO_TYPE_CMD,
59 /// icon object, any kind of image
60 WXLO_TYPE_ICON
61 };
62
63 /// Type used for coordinates in drawing. Must be signed.
64 typedef long CoordType;
65
66 // Forward declarations.
67 class wxLayoutList;
68 class wxLayoutObject;
69 class wxDC;
70 class wxColour;
71 class wxFont;
72
73
74 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
75
76 The wxLayout objects which make up the lines.
77
78 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
79
80 /** The base class defining the interface to each object which can be
81 part of the layout. Each object needs to draw itself and calculate
82 its size.
83 */
84 class wxLayoutObject
85 {
86 public:
87 /** This structure can be used to contain data associated with the
88 object.
89 It is refcounted, so the caller has to do a DecRef() on it
90 instead of a delete.
91 */
92 struct UserData
93 {
94 UserData() { m_refcount = 1; }
95 void IncRef(void) { m_refcount++; }
96 void DecRef(void) { m_refcount--; if(m_refcount == 0) delete this;}
97 private:
98 int m_refcount;
99 protected:
100 virtual ~UserData() { wxASSERT(m_refcount == 0); }
101 /// prevents gcc from generating stupid warnings
102 friend class dummy_UserData;
103 };
104
105 /// return the type of this object
106 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_INVALID; }
107 /** Calculates the size of an object.
108 @param dc the wxDC to draw on
109 @param llist the wxLayoutList
110 */
111 virtual void Layout(wxDC &dc, class wxLayoutList *llist) = 0;
112
113 /** Draws an object.
114 @param dc the wxDC to draw on
115 @param coords where to draw the baseline of the object.
116 @param wxllist pointer to wxLayoutList
117 @param begin if !=-1, from which position on to highlight it
118 @param end if begin !=-1, how many positions to highlight it
119 */
120 virtual void Draw(wxDC & /* dc */,
121 wxPoint const & /* coords */,
122 class wxLayoutList *wxllist,
123 CoordType begin = -1,
124 CoordType end = -1) { }
125
126 /** Calculates and returns the size of the object.
127 @param top where to store height above baseline
128 @param bottom where to store height below baseline
129 @return the size of the object's box in pixels
130 */
131 virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const
132 { *top = 0; *bottom = 0; return wxPoint(0,0); }
133
134 /// Return just the width of the object on the screen.
135 virtual CoordType GetWidth(void) const { return 0; }
136 /// returns the number of cursor positions occupied by this object
137 virtual CoordType GetLength(void) const { return 1; }
138 /** Returns the cursor offset relating to the screen x position
139 relative to begin of object.
140 @param dc the wxDC to use for calculations
141 @param xpos relative x position from head of object
142 @return cursor coordinate offset
143 */
144 virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const { return 0; }
145
146 /// constructor
147 wxLayoutObject() { m_UserData = NULL; }
148 /// delete the user data
149 virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); }
150
151 #ifdef WXLAYOUT_DEBUG
152 virtual void Debug(void);
153 #endif
154
155 /** Tells the object about some user data. This data is associated
156 with the object and will be deleted at destruction time.
157 */
158 void SetUserData(UserData *data)
159 {
160 if(m_UserData)
161 m_UserData->DecRef();
162 m_UserData = data;
163 m_UserData->IncRef();
164 }
165
166 /** Return the user data. */
167 void * GetUserData(void) const { if(m_UserData) m_UserData->IncRef(); return m_UserData; }
168
169 /** Makes a copy of this object.
170 */
171 virtual wxLayoutObject *Copy(void) = 0;
172 protected:
173 /// optional data for application's use
174 UserData *m_UserData;
175 };
176
177 /// Define a list type of wxLayoutObject pointers.
178 KBLIST_DEFINE(wxLayoutObjectList, wxLayoutObject);
179
180 /// An illegal iterator to save typing.
181 #define NULLIT (wxLayoutObjectList::iterator(NULL))
182 /// The iterator type.
183 #define wxLOiterator wxLayoutObjectList::iterator
184
185 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
186
187 wxLayoutObjectText
188
189 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
190 /** This class implements a wxLayoutObject holding plain text.
191 */
192 class wxLayoutObjectText : public wxLayoutObject
193 {
194 public:
195 wxLayoutObjectText(const wxString &txt);
196
197 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
198 virtual void Layout(wxDC &dc, class wxLayoutList *llist);
199 virtual void Draw(wxDC &dc, wxPoint const &coords,
200 class wxLayoutList *wxllist,
201 CoordType begin = -1,
202 CoordType end = -1);
203 /** Calculates and returns the size of the object.
204 @param top where to store height above baseline
205 @param bottom where to store height below baseline
206 @return the size of the object's box in pixels
207 */
208 virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
209 /// Return just the width of the object on the screen.
210 virtual CoordType GetWidth(void) const { return m_Width; }
211 /** Returns the cursor offset relating to the screen x position
212 relative to begin of object.
213 @param dc the wxDC to use for calculations
214 @param xpos relative x position from head of object
215 @return cursor coordinate offset
216 */
217 virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const;
218
219
220 #ifdef WXLAYOUT_DEBUG
221 virtual void Debug(void);
222 #endif
223
224 virtual CoordType GetLength(void) const { return strlen(m_Text.c_str()); }
225
226 // for editing:
227 wxString & GetText(void) { return m_Text; }
228 void SetText(wxString const &text) { m_Text = text; }
229 /** Makes a copy of this object.
230 */
231 virtual wxLayoutObject *Copy(void);
232 private:
233 wxString m_Text;
234 /// size of the box containing text
235 long m_Width, m_Height;
236 /// Height above baseline.
237 long m_Top;
238 /// Height below baseline.
239 long m_Bottom;
240 };
241
242 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
243
244 wxLayoutObjectIcon
245
246 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
247 /** This class implements a wxLayoutObject holding a graphic.
248 */
249 class wxLayoutObjectIcon : public wxLayoutObject
250 {
251 public:
252 wxLayoutObjectIcon(wxBitmap *icon);
253 wxLayoutObjectIcon(wxBitmap const &icon);
254
255 ~wxLayoutObjectIcon() { delete m_Icon; }
256
257 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
258 virtual void Layout(wxDC &dc, class wxLayoutList *llist);
259 virtual void Draw(wxDC &dc, wxPoint const &coords,
260 class wxLayoutList *wxllist,
261 CoordType begin = -1,
262 CoordType end = -1);
263
264 /** Calculates and returns the size of the object.
265 @param top where to store height above baseline
266 @param bottom where to store height below baseline
267 @return the size of the object's box in pixels
268 */
269 virtual wxPoint GetSize(CoordType * top, CoordType *bottom) const;
270 /// Return just the width of the object on the screen.
271 virtual CoordType GetWidth(void) const { return m_Icon->GetWidth(); }
272 // return a pointer to the icon
273 wxBitmap *GetIcon(void) const { return m_Icon; }
274 /** Makes a copy of this object.
275 */
276 virtual wxLayoutObject *Copy(void);
277 private:
278 wxBitmap *m_Icon;
279 };
280
281 /** This structure holds all formatting information. Members which are
282 undefined (for a CmdObject this means: no change), are set to -1.
283 */
284 struct wxLayoutStyleInfo
285 {
286 wxLayoutStyleInfo(int ifamily = -1,
287 int isize = -1,
288 int istyle = -1,
289 int iweight = -1,
290 int iul = -1,
291 wxColour *fg = NULL,
292 wxColour *bg = NULL);
293 wxColour & GetBGColour()
294 {
295 return m_bg;
296 }
297 wxLayoutStyleInfo & operator=(const wxLayoutStyleInfo &right);
298 /// Font change parameters.
299 int size, family, style, weight, underline;
300 /// Colours
301 wxColour m_bg, m_fg;
302 bool m_fg_valid, m_bg_valid;
303 };
304
305
306 class wxFontCacheEntry
307 {
308 public:
309 wxFontCacheEntry(int family, int size, int style, int weight,
310 bool underline)
311 {
312 m_Family = family; m_Size = size; m_Style = style;
313 m_Weight = weight; m_Underline = underline;
314 m_Font = new wxFont(m_Size, m_Family,
315 m_Style, m_Weight, m_Underline);
316 }
317 bool Matches(int family, int size, int style, int weight,
318 bool underline) const
319 {
320 return size == m_Size && family == m_Family
321 && style == m_Style && weight == m_Weight
322 && underline == m_Underline;
323 }
324 wxFont & GetFont(void) { return *m_Font; }
325 ~wxFontCacheEntry()
326 {
327 delete m_Font;
328 }
329 private:
330 wxFont *m_Font;
331 int m_Family, m_Size, m_Style, m_Weight;
332 bool m_Underline;
333 };
334
335 KBLIST_DEFINE(wxFCEList, wxFontCacheEntry);
336
337 class wxFontCache
338 {
339 public:
340 wxFont & GetFont(int family, int size, int style, int weight,
341 bool underline);
342 wxFont & GetFont(wxLayoutStyleInfo const &si)
343 {
344 return GetFont(si.family, si.size, si.style, si.weight, si.underline);
345 }
346 private:
347 wxFCEList m_FontList;
348 };
349
350 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
351
352 wxLayoutObjectCmd
353
354 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
355 /** This class implements a wxLayoutObject holding style change commands.
356 */
357 class wxLayoutObjectCmd : public wxLayoutObject
358 {
359 public:
360 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
361 virtual void Layout(wxDC &dc, class wxLayoutList *llist);
362 virtual void Draw(wxDC &dc, wxPoint const &coords,
363 class wxLayoutList *wxllist,
364 CoordType begin = -1,
365 CoordType end = -1);
366 wxLayoutObjectCmd(int family = -1,
367 int size = -1,
368 int style = -1,
369 int weight = -1,
370 int underline = -1,
371 wxColour *fg = NULL,
372 wxColour *bg = NULL);
373 ~wxLayoutObjectCmd();
374 /** Stores the current style in the styleinfo structure */
375 wxLayoutStyleInfo * GetStyle(void) const;
376 /** Makes a copy of this object.
377 */
378 virtual wxLayoutObject *Copy(void);
379 private:
380 wxLayoutStyleInfo *m_StyleInfo;
381 };
382
383 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
384
385 The wxLayoutLine object
386
387 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
388
389 /// forward declaration
390 class wxLayoutList;
391
392 /** This class represents a single line of objects to be displayed.
393 It knows its height and total size and whether it needs to be
394 redrawn or not.
395 It has pointers to its first and next line so it can automatically
396 update them as needed.
397 */
398 class wxLayoutLine
399 {
400 public:
401 /** Constructor.
402 @param prev pointer to previous line or NULL
403 @param next pointer to following line or NULL
404 @param llist pointer to layout list
405 */
406 wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist);
407 /** This function inserts a new object at cursor position xpos.
408 @param xpos where to insert new object
409 @param obj the object to insert
410 @return true if that xpos existed and the object was inserted
411 */
412 bool Insert(CoordType xpos, wxLayoutObject *obj);
413
414 /** This function inserts text at cursor position xpos.
415 @param xpos where to insert
416 @param text the text to insert
417 @return true if that xpos existed and the object was inserted
418 */
419 bool Insert(CoordType xpos, wxString text);
420
421 /** This function appends an object to the line.
422 @param obj the object to insert
423 */
424 void Append(wxLayoutObject * obj)
425 {
426 wxASSERT(obj);
427 m_ObjectList.push_back(obj);
428 m_Length += obj->GetLength();
429 }
430
431 /** This function appens the next line to this, i.e. joins the two
432 lines into one.
433 */
434 void MergeNextLine(wxLayoutList *llist);
435
436 /** This function deletes npos cursor positions from position xpos.
437 @param xpos where to delete
438 @param npos how many positions
439 @return number of positions still to be deleted
440 */
441 CoordType Delete(CoordType xpos, CoordType npos);
442
443 /** This function breaks the line at a given cursor position.
444 @param xpos where to break it
445 @return pointer to the new line object replacing the old one
446 */
447 wxLayoutLine *Break(CoordType xpos, wxLayoutList *llist);
448
449 /** Deletes the next word from this position, including leading
450 whitespace.
451 This function does not delete over font changes, i.e. a word
452 with formatting instructions in the middle of it is treated as
453 two (three actually!) words. In fact, if the cursor is on a non-text object, that
454 one is treated as a word.
455 @param xpos from where to delete
456 @return true if a word was deleted
457 */
458 bool DeleteWord(CoordType npos);
459
460 /** Finds a suitable position left to the given column to break the
461 line.
462 @param column we want to break the line to the left of this
463 @return column for breaking line or -1 if no suitable location found
464 */
465 CoordType GetWrapPosition(CoordType column);
466
467 /** Finds the object which covers the cursor position xpos in this
468 line.
469 @param xpos the column number
470 @param offset where to store the difference between xpos and
471 the object's head
472 @return iterator to the object or NULLIT
473 */
474 wxLayoutObjectList::iterator FindObject(CoordType xpos, CoordType
475 *offset) const ;
476
477 /** Finds the object which covers the screen position xpos in this
478 line.
479 @param dc the wxDC to use for calculations
480 @param xpos the screen x coordinate
481 @param offset where to store the difference between xpos and
482 the object's head
483 @return iterator to the object or NULLIT
484 */
485 wxLayoutObjectList::iterator FindObjectScreen(wxDC &dc,
486 CoordType xpos,
487 CoordType *offset,
488 bool *found = NULL) const ;
489
490 /** Finds text in this line.
491 @param needle the text to find
492 @param xpos the position where to start the search
493 @return the cursoor coord where it was found or -1
494 */
495 CoordType FindText(const wxString &needle, CoordType xpos = 0) const;
496
497 /** Get the first object in the list. This is used by the wxlparser
498 functions to export the list.
499 @return iterator to the first object
500 */
501 wxLayoutObjectList::iterator GetFirstObject(void)
502 {
503 return m_ObjectList.begin();
504 }
505
506 /** Deletes this line, returns pointer to next line.
507 @param update If true, update all following lines.
508 */
509 wxLayoutLine *DeleteLine(bool update, wxLayoutList *llist);
510
511 /**@name Cursor Management */
512 //@{
513 /** Return the line number of this line.
514 @return the line number
515 */
516 inline CoordType GetLineNumber(void) const { return m_LineNumber; }
517 /** Return the length of the line.
518 @return line lenght in cursor positions
519 */
520 inline CoordType GetLength(void) const { return m_Length; }
521 //@}
522
523 /**@name Drawing and Layout */
524 //@{
525 /** Draws the line on a wxDC.
526 @param dc the wxDC to draw on
527 @param llist the wxLayoutList
528 @param offset an optional offset to shift printout
529 */
530 void Draw(wxDC &dc,
531 wxLayoutList *llist,
532 const wxPoint &offset = wxPoint(0,0)) const;
533
534 /** Recalculates the positions of objects and the height of the
535 line.
536 @param dc the wxDC to draw on
537 @param llist th e wxLayoutList
538 @param cursorPos if not NULL, set cursor screen position in there
539 @param cursorSize if not cursorPos != NULL, set cursor size in there
540 @param cx if cursorPos != NULL, the cursor x position
541 */
542 void Layout(wxDC &dc,
543 wxLayoutList *llist,
544 wxPoint *cursorPos = NULL,
545 wxPoint *cursorSize = NULL,
546 int cx = 0);
547 /** This function finds an object belonging to a given cursor
548 position. It assumes that Layout() has been called before.
549 @param dc the wxDC to use for calculations
550 @param xpos screen x position
551 @param found if non-NULL set to false if we return the last
552 object before the cursor, to true if we really have an object
553 for that position
554 @return pointer to the object
555 */
556 wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos, bool
557 *found = NULL);
558
559 //@}
560
561 /**@name List traversal */
562 //@{
563 /// Returns pointer to next line.
564 wxLayoutLine *GetNextLine(void) const { return m_Next; }
565 /// Returns pointer to previous line.
566 wxLayoutLine *GetPreviousLine(void) const { return m_Previous; }
567 /// Sets the link to the next line.
568 void SetNext(wxLayoutLine *next)
569 { m_Next = next; if(next) next->m_Previous = this; }
570 /// Sets the link to the previous line.
571 void SetPrevious(wxLayoutLine *previous)
572 { m_Previous = previous; if(previous) previous->m_Next = this; }
573 //@}
574
575 /// Returns the position of this line on the canvas.
576 wxPoint GetPosition(void) const { return m_Position; }
577 /// Returns the height of this line.
578 CoordType GetHeight(void) const { return m_Height; }
579 /// Returns the width of this line.
580 CoordType GetWidth(void) const { return m_Width; }
581 /** This will recalculate the position and size of this line.
582 If called recursively it will abort if the position of an
583 object is unchanged, assuming that none of the following
584 objects need to move.
585 @param recurse if greater 0 then it will be used as the
586 minimum(!) recursion level, continue with all lines till the end of
587 the list or until the coordinates no longer changed.
588 */
589 void RecalculatePositions(int recurse, wxLayoutList *llist);
590 /// Recalculates the position of this line on the canvas.
591 wxPoint RecalculatePosition(wxLayoutList *llist);
592
593 /** Copies the contents of this line to another wxLayoutList
594 @param llist the wxLayoutList destination
595 @param from x cursor coordinate where to start
596 @param to x cursor coordinate where to stop, -1 for end of line
597 */
598 void Copy(wxLayoutList *llist,
599 CoordType from = 0,
600 CoordType to = -1);
601
602 #ifdef WXLAYOUT_DEBUG
603 void Debug(void);
604 #endif
605 wxLayoutStyleInfo &GetStyleInfo() { return m_StyleInfo; }
606
607 /// Returns dirty state
608 bool IsDirty(void) const { return m_Dirty; }
609 private:
610 /// Destructor is private. Use DeleteLine() to remove it.
611 ~wxLayoutLine();
612
613 /**@name Functions to let the lines synchronise with each other. */
614 //@{
615 /** Sets the height of this line. Will mark following lines as
616 dirty.
617 @param height new height
618 */
619 void SetHeight(CoordType height, wxLayoutList *llist)
620 { m_Height = height; RecalculatePositions(true, llist); }
621
622 /** Moves the linenumbers one on, because a line has been inserted
623 or deleted.
624 @param delta either +1 or -1
625 */
626 void MoveLines(int delta)
627 {
628 m_LineNumber += delta;
629 if(m_Next) m_Next->MoveLines(delta);
630 }
631 //@}
632 private:
633 /// The line number.
634 CoordType m_LineNumber;
635 /// The line length in cursor positions.
636 CoordType m_Length;
637 /// The total height of the line.
638 CoordType m_Height;
639 /// The total width of the line on screen.
640 CoordType m_Width;
641 /// The baseline for drawing objects
642 CoordType m_BaseLine;
643 /// The position on the canvas.
644 wxPoint m_Position;
645 /// The list of objects
646 wxLayoutObjectList m_ObjectList;
647 /// Have we been changed since the last layout?
648 bool m_Dirty;
649 /// Pointer to previous line if it exists.
650 wxLayoutLine *m_Previous;
651 /// Pointer to next line if it exists.
652 wxLayoutLine *m_Next;
653 /// A StyleInfo structure, holding the current settings.
654 wxLayoutStyleInfo m_StyleInfo;
655 /// Just to suppress gcc compiler warnings.
656 friend class dummy;
657 private:
658 wxLayoutLine(const wxLayoutLine &);
659 };
660
661
662 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
663
664 The wxLayoutList object
665
666 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
667 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
668 higher level of abstraction for the text and can generally be considered
669 as representing "the text".
670 */
671 class wxLayoutList
672 {
673 public:
674 /// Constructor.
675 wxLayoutList();
676 /// Destructor.
677 ~wxLayoutList();
678
679 /// Clear the list.
680 void Clear(int family = wxROMAN,
681 int size=WXLO_DEFAULTFONTSIZE,
682 int style=wxNORMAL,
683 int weight=wxNORMAL,
684 int underline=0,
685 wxColour *fg=NULL,
686 wxColour *bg=NULL);
687 /// Empty: clear the list but leave font settings.
688 void Empty(void);
689
690 /**@name Cursor Management */
691 //@{
692 /** Set new cursor position.
693 @param p new position
694 @return bool if it could be set
695 */
696 bool MoveCursorTo(wxPoint const &p);
697 /** Move cursor up or down.
698 @param n
699 @return bool if it could be moved
700 */
701 bool MoveCursorVertically(int n);
702 /** Move cursor left or right.
703 @param n
704 @return bool if it could be moved
705 */
706 bool MoveCursorHorizontally(int n);
707
708 /// Move cursor to end of line.
709 void MoveCursorToEndOfLine(void)
710 {
711 wxASSERT(m_CursorLine);
712 MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
713 }
714
715 /// Move cursor to begin of line.
716 void MoveCursorToBeginOfLine(void)
717 { MoveCursorHorizontally(-m_CursorPos.x); }
718
719 /// Returns current cursor position.
720 wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; }
721 wxPoint GetCursorPos() const { return m_CursorPos; }
722
723 //@}
724
725 /**@name Editing functions.
726 All of these functions return true on success and false on
727 failure. */
728 //@{
729 /// Insert text at current cursor position.
730 bool Insert(wxString const &text);
731 /// Insert some other object at current cursor position.
732 bool Insert(wxLayoutObject *obj);
733 /// Inserts a linebreak at current cursor position.
734 bool LineBreak(void);
735 /** Wraps the current line. Searches to the left of the cursor to
736 break the line. Does nothing if the cursor position is before
737 the break position parameter.
738 @param column the break position for the line, maximum length
739 @return true if line got broken
740 */
741 bool WrapLine(CoordType column);
742 /** This function deletes npos cursor positions.
743 @param npos how many positions
744 @return true if everything got deleted
745 */
746 bool Delete(CoordType npos);
747
748 /** Delete the next n lines.
749 @param n how many lines to delete
750 @return how many it could not delete
751 */
752 int DeleteLines(int n);
753
754 /// Delete to end of line.
755 void DeleteToEndOfLine(void)
756 {
757 wxASSERT(m_CursorLine);
758 Delete(m_CursorLine->GetLength()-m_CursorPos.x);
759 }
760 /// Delete to begin of line.
761 void DeleteToBeginOfLine(void)
762 {
763 wxASSERT(m_CursorLine);
764 CoordType n = m_CursorPos.x;
765 #ifdef WXLAYOUT_DEBUG
766 wxASSERT(MoveCursorHorizontally(-n));
767 #else
768 MoveCursorHorizontally(-n);
769 #endif
770 Delete(n);
771 }
772
773 /** Delete the next word.
774 */
775 void DeleteWord(void)
776 {
777 wxASSERT(m_CursorLine);
778 m_CursorLine->DeleteWord(m_CursorPos.x);
779 }
780
781 //@}
782
783 /** Finds text in this list.
784 @param needle the text to find
785 @param cpos the position where to start the search
786 @return the cursoor coord where it was found or (-1,-1)
787 */
788 wxPoint FindText(const wxString &needle, const wxPoint &cpos = wxPoint(0,0)) const;
789
790 /**@name Formatting options */
791 //@{
792 /// sets font parameters
793 void SetFont(int family, int size, int style,
794 int weight, int underline,
795 wxColour *fg,
796 wxColour *bg);
797 /// sets font parameters, colours by name
798 void SetFont(int family=-1, int size = -1, int style=-1,
799 int weight=-1, int underline = -1,
800 char const *fg = NULL,
801 char const *bg = NULL);
802 /// changes to the next larger font size
803 inline void SetFontLarger(void)
804 { SetFont(-1,(12*m_CurrentSetting.size)/10); }
805 /// changes to the next smaller font size
806 inline void SetFontSmaller(void)
807 { SetFont(-1,(10*m_CurrentSetting.size)/12); }
808
809 /// set font family
810 inline void SetFontFamily(int family) { SetFont(family); }
811 /// set font size
812 inline void SetFontSize(int size) { SetFont(-1,size); }
813 /// set font style
814 inline void SetFontStyle(int style) { SetFont(-1,-1,style); }
815 /// set font weight
816 inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); }
817 /// toggle underline flag
818 inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
819 /// set font colours by name
820 inline void SetFontColour(char const *fg, char const *bg = NULL)
821 { SetFont(-1,-1,-1,-1,-1,fg,bg); }
822 /// set font colours by colour
823 inline void SetFontColour(wxColour *fg, wxColour *bg = NULL)
824 { SetFont(-1,-1,-1,-1,-1,fg,bg); }
825
826
827 /**
828 Returns a pointer to the default settings.
829 This is only valid temporarily and should not be stored
830 anywhere.
831 @return the default settings of the list
832 */
833 wxLayoutStyleInfo *GetDefaults(void) { return &m_DefaultSetting ; }
834 wxLayoutStyleInfo *GetStyleInfo(void) { return &m_CurrentSetting ; }
835 //@}
836
837 /**@name Drawing */
838 //@{
839 /** Draws the complete list on a wxDC.
840 @param dc the wxDC to draw on
841 @param offset an optional offset to shift printout
842 @param top optional y coordinate where to start drawing
843 @param bottom optional y coordinate where to stop drawing
844 */
845 void Draw(wxDC &dc,
846 const wxPoint &offset = wxPoint(0,0),
847 CoordType top = -1, CoordType bottom = -1);
848
849 /** Calculates new layout for the list, like Draw() but does not
850 actually draw it.
851 @param dc the wxDC to draw on
852 @param bottom optional y coordinate where to stop calculating
853 @param forceAll force re-layout of all lines
854 */
855 void Layout(wxDC &dc, CoordType bottom = -1, bool forceAll = false);
856
857 /** Calculates new sizes for everything in the list, like Layout()
858 but this is needed after the list got changed.
859 @param dc the wxDC to draw on
860 @param bottom optional y coordinate where to stop calculating
861 */
862 void Recalculate(wxDC &dc, CoordType bottom = -1);
863
864 /** Returns the size of the list in screen coordinates.
865 The return value only makes sense after the list has been
866 drawn.
867 @return a wxPoint holding the maximal x/y coordinates used for
868 drawing
869 */
870 wxPoint GetSize(void) const;
871
872 /** Returns the cursor position on the screen.
873 @return cursor position in pixels
874 */
875 wxPoint GetCursorScreenPos(wxDC &dc);
876
877 /** Draws the cursor.
878 @param active If true, draw a bold cursor to mark window as
879 active.
880 @param translate optional translation of cursor coords on screen
881 */
882 void DrawCursor(wxDC &dc,
883 bool active = true,
884 const wxPoint & translate = wxPoint(0,0));
885
886 /** This function finds an object belonging to a given screen
887 position. It assumes that Layout() has been called before.
888 @param pos screen position
889 @param cursorPos if non NULL, store cursor position in there
890 @param found if used, set this to true if we really found an
891 object, to false if we had to take the object near to it
892 @return pointer to the object
893 */
894 wxLayoutObject * FindObjectScreen(wxDC &dc,
895 wxPoint const pos,
896 wxPoint *cursorPos = NULL,
897 bool *found = NULL);
898
899 /** Called by the objects to update the update rectangle.
900 @param x horizontal coordinate to include in rectangle
901 @param y vertical coordinate to include in rectangle
902 */
903 void SetUpdateRect(CoordType x, CoordType y);
904 /** Called by the objects to update the update rectangle.
905 @param p a point to include in it
906 */
907 inline void SetUpdateRect(const wxPoint &p)
908 { SetUpdateRect(p.x,p.y); }
909 /// Invalidates the update rectangle.
910 void InvalidateUpdateRect(void) { m_UpdateRectValid = false; }
911 /// Returns the update rectangle.
912 const wxRect *GetUpdateRect(void) const { return &m_UpdateRect; }
913 //@}
914
915 /**@name For exporting one object after another. */
916 //@{
917 /** Returns a pointer to the first line in the list. */
918 wxLayoutLine *GetFirstLine(void)
919 {
920 wxASSERT(m_FirstLine);
921 return m_FirstLine;
922 }
923 //@}
924
925 /// Begin selecting text.
926 void StartSelection(void);
927 // Continue selecting text
928 void ContinueSelection(void);
929 /// End selecting text.
930 void EndSelection(void);
931 /// Are we still selecting text?
932 bool IsSelecting(void);
933 bool IsSelected(const wxPoint &cursor);
934
935 /// Return the selection as a wxLayoutList:
936 wxLayoutList *GetSelection(void);
937 /// Delete selected bit
938 void DeleteSelection(void);
939
940 wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0),
941 const wxPoint &to = wxPoint(-1,-1));
942
943 /// starts highlighting of text for selections
944 void StartHighlighting(wxDC &dc);
945 /// ends highlighting of text for selections
946 void EndHighlighting(wxDC &dc);
947
948 /** Tests whether this layout line is selected and needs
949 highlighting.
950 @param line to test for
951 @param from set to first cursorpos to be highlighted (for returncode == -1)
952 @param to set to last cursorpos to be highlighted (for returncode == -1)
953 @return 0 = not selected, 1 = fully selected, -1 = partially
954 selected
955
956 */
957 int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
958
959 void ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc);
960 #ifdef WXLAYOUT_DEBUG
961 void Debug(void);
962 #endif
963 private:
964 /// Clear the list.
965 void InternalClear(void);
966 /** Calculates the cursor position on the screen.
967 */
968 void UpdateCursorScreenPos(wxDC &dc);
969
970 /// The list of lines.
971 wxLayoutLine *m_FirstLine;
972 /// The update rectangle which needs to be refreshed:
973 wxRect m_UpdateRect;
974 /// Is the update rectangle valid?
975 bool m_UpdateRectValid;
976 /**@name Cursor Management */
977 //@{
978 /// Where the text cursor (column,line) is.
979 wxPoint m_CursorPos;
980 /// The size of the cursor.
981 wxPoint m_CursorSize;
982 /// Where the cursor should be drawn.
983 wxPoint m_CursorScreenPos;
984 /// The line where the cursor is.
985 wxLayoutLine *m_CursorLine;
986 //@}
987
988 /// A structure for the selection.
989 struct Selection
990 {
991 Selection() { m_valid = false; m_selecting = false; }
992 bool m_valid;
993 bool m_selecting;
994 wxPoint m_CursorA, m_CursorB;
995 } m_Selection;
996 /** @name Font parameters. */
997 //@{
998 /// this object manages the fonts for us
999 wxFontCache m_FontCache;
1000 /// the default setting:
1001 wxLayoutStyleInfo m_DefaultSetting;
1002 /// the current setting:
1003 wxLayoutStyleInfo m_CurrentSetting;
1004 //@}
1005 };
1006
1007
1008
1009
1010 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1011
1012 The wxLayoutPrintout object for printing within the wxWindows print
1013 framework.
1014
1015 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1016 /** This class implements a wxPrintout for printing a wxLayoutList within
1017 the wxWindows printing framework.
1018 */
1019 class wxLayoutPrintout: public wxPrintout
1020 {
1021 public:
1022 /** Constructor.
1023 @param llist pointer to the wxLayoutList to be printed
1024 @param title title for PS file or windows
1025 */
1026 wxLayoutPrintout(wxLayoutList *llist,
1027 wxString const & title =
1028 "wxLayout Printout");
1029 /// Destructor.
1030 ~wxLayoutPrintout();
1031
1032 /** Function which prints the n-th page.
1033 @param page the page number to print
1034 @return bool true if we are not at end of document yet
1035 */
1036 bool OnPrintPage(int page);
1037 /** Checks whether page exists in document.
1038 @param page number of page
1039 @return true if page exists
1040 */
1041 bool HasPage(int page);
1042
1043 /** Gets called from wxWindows to find out which pages are existing.
1044 I'm not totally sure about the parameters though.
1045 @param minPage the first page in the document
1046 @param maxPage the last page in the document
1047 @param selPageFrom the first page to be printed
1048 @param selPageTo the last page to be printed
1049 */
1050 void GetPageInfo(int *minPage, int *maxPage,
1051 int *selPageFrom, int *selPageTo);
1052 protected:
1053 /** This little function scales the DC so that the printout has
1054 roughly the same size as the output on screen.
1055 @param dc the wxDC to scale
1056 @return the scale that was applied
1057 */
1058 float ScaleDC(wxDC *dc);
1059
1060 /* no longer used
1061 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1062 */
1063 private:
1064 /// The list to print.
1065 wxLayoutList *m_llist;
1066 /// Title for PS file or window.
1067 wxString m_title;
1068 /// The real paper size.
1069 int m_PageHeight, m_PageWidth;
1070 /// How much we actually print per page.
1071 int m_PrintoutHeight;
1072 /// How many pages we need to print.
1073 int m_NumOfPages;
1074 /// Top left corner where we start printing.
1075 wxPoint m_Offset;
1076 };
1077
1078
1079 #endif // WXLLIST_H