]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxllist.h
a9cf311850f7bd06edaad384f286f7ef62e28711
[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 /// Marks line as diry.
610 void MarkDirty(void) { m_Dirty = true; }
611 private:
612 /// Destructor is private. Use DeleteLine() to remove it.
613 ~wxLayoutLine();
614
615 /**@name Functions to let the lines synchronise with each other. */
616 //@{
617 /** Sets the height of this line. Will mark following lines as
618 dirty.
619 @param height new height
620 */
621 void SetHeight(CoordType height, wxLayoutList *llist)
622 { m_Height = height; RecalculatePositions(true, llist); }
623
624 /** Moves the linenumbers one on, because a line has been inserted
625 or deleted.
626 @param delta either +1 or -1
627 */
628 void MoveLines(int delta)
629 {
630 m_LineNumber += delta;
631 if(m_Next) m_Next->MoveLines(delta);
632 }
633 //@}
634 private:
635 /// The line number.
636 CoordType m_LineNumber;
637 /// The line length in cursor positions.
638 CoordType m_Length;
639 /// The total height of the line.
640 CoordType m_Height;
641 /// The total width of the line on screen.
642 CoordType m_Width;
643 /// The baseline for drawing objects
644 CoordType m_BaseLine;
645 /// The position on the canvas.
646 wxPoint m_Position;
647 /// The list of objects
648 wxLayoutObjectList m_ObjectList;
649 /// Have we been changed since the last layout?
650 bool m_Dirty;
651 /// Pointer to previous line if it exists.
652 wxLayoutLine *m_Previous;
653 /// Pointer to next line if it exists.
654 wxLayoutLine *m_Next;
655 /// A StyleInfo structure, holding the current settings.
656 wxLayoutStyleInfo m_StyleInfo;
657 /// Just to suppress gcc compiler warnings.
658 friend class dummy;
659 private:
660 wxLayoutLine(const wxLayoutLine &);
661 };
662
663
664 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
665
666 The wxLayoutList object
667
668 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
669 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
670 higher level of abstraction for the text and can generally be considered
671 as representing "the text".
672 */
673 class wxLayoutList
674 {
675 public:
676 /// Constructor.
677 wxLayoutList();
678 /// Destructor.
679 ~wxLayoutList();
680
681 /// Clear the list.
682 void Clear(int family = wxROMAN,
683 int size=WXLO_DEFAULTFONTSIZE,
684 int style=wxNORMAL,
685 int weight=wxNORMAL,
686 int underline=0,
687 wxColour *fg=NULL,
688 wxColour *bg=NULL);
689 /// Empty: clear the list but leave font settings.
690 void Empty(void);
691
692 /**@name Cursor Management */
693 //@{
694 /** Set new cursor position.
695 @param p new position
696 @return bool if it could be set
697 */
698 bool MoveCursorTo(wxPoint const &p);
699 /** Move cursor up or down.
700 @param n
701 @return bool if it could be moved
702 */
703 bool MoveCursorVertically(int n);
704 /** Move cursor left or right.
705 @param n
706 @return bool if it could be moved
707 */
708 bool MoveCursorHorizontally(int n);
709
710 /// Move cursor to end of line.
711 void MoveCursorToEndOfLine(void)
712 {
713 wxASSERT(m_CursorLine);
714 MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
715 }
716
717 /// Move cursor to begin of line.
718 void MoveCursorToBeginOfLine(void)
719 { MoveCursorHorizontally(-m_CursorPos.x); }
720
721 /// Returns current cursor position.
722 wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; }
723 wxPoint GetCursorPos() const { return m_CursorPos; }
724
725 //@}
726
727 /**@name Editing functions.
728 All of these functions return true on success and false on
729 failure. */
730 //@{
731 /// Insert text at current cursor position.
732 bool Insert(wxString const &text);
733 /// Insert some other object at current cursor position.
734 bool Insert(wxLayoutObject *obj);
735 /// Inserts a linebreak at current cursor position.
736 bool LineBreak(void);
737 /** Wraps the current line. Searches to the left of the cursor to
738 break the line. Does nothing if the cursor position is before
739 the break position parameter.
740 @param column the break position for the line, maximum length
741 @return true if line got broken
742 */
743 bool WrapLine(CoordType column);
744 /** This function deletes npos cursor positions.
745 @param npos how many positions
746 @return true if everything got deleted
747 */
748 bool Delete(CoordType npos);
749
750 /** Delete the next n lines.
751 @param n how many lines to delete
752 @return how many it could not delete
753 */
754 int DeleteLines(int n);
755
756 /// Delete to end of line.
757 void DeleteToEndOfLine(void)
758 {
759 wxASSERT(m_CursorLine);
760 Delete(m_CursorLine->GetLength()-m_CursorPos.x);
761 }
762 /// Delete to begin of line.
763 void DeleteToBeginOfLine(void)
764 {
765 wxASSERT(m_CursorLine);
766 CoordType n = m_CursorPos.x;
767 #ifdef WXLAYOUT_DEBUG
768 wxASSERT(MoveCursorHorizontally(-n));
769 #else
770 MoveCursorHorizontally(-n);
771 #endif
772 Delete(n);
773 }
774
775 /** Delete the next word.
776 */
777 void DeleteWord(void)
778 {
779 wxASSERT(m_CursorLine);
780 m_CursorLine->DeleteWord(m_CursorPos.x);
781 }
782
783 //@}
784
785 /** Finds text in this list.
786 @param needle the text to find
787 @param cpos the position where to start the search
788 @return the cursoor coord where it was found or (-1,-1)
789 */
790 wxPoint FindText(const wxString &needle, const wxPoint &cpos = wxPoint(0,0)) const;
791
792 /**@name Formatting options */
793 //@{
794 /// sets font parameters
795 void SetFont(int family, int size, int style,
796 int weight, int underline,
797 wxColour *fg,
798 wxColour *bg);
799 /// sets font parameters, colours by name
800 void SetFont(int family=-1, int size = -1, int style=-1,
801 int weight=-1, int underline = -1,
802 char const *fg = NULL,
803 char const *bg = NULL);
804 /// changes to the next larger font size
805 inline void SetFontLarger(void)
806 { SetFont(-1,(12*m_CurrentSetting.size)/10); }
807 /// changes to the next smaller font size
808 inline void SetFontSmaller(void)
809 { SetFont(-1,(10*m_CurrentSetting.size)/12); }
810
811 /// set font family
812 inline void SetFontFamily(int family) { SetFont(family); }
813 /// set font size
814 inline void SetFontSize(int size) { SetFont(-1,size); }
815 /// set font style
816 inline void SetFontStyle(int style) { SetFont(-1,-1,style); }
817 /// set font weight
818 inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); }
819 /// toggle underline flag
820 inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
821 /// set font colours by name
822 inline void SetFontColour(char const *fg, char const *bg = NULL)
823 { SetFont(-1,-1,-1,-1,-1,fg,bg); }
824 /// set font colours by colour
825 inline void SetFontColour(wxColour *fg, wxColour *bg = NULL)
826 { SetFont(-1,-1,-1,-1,-1,fg,bg); }
827
828
829 /**
830 Returns a pointer to the default settings.
831 This is only valid temporarily and should not be stored
832 anywhere.
833 @return the default settings of the list
834 */
835 wxLayoutStyleInfo *GetDefaults(void) { return &m_DefaultSetting ; }
836 wxLayoutStyleInfo *GetStyleInfo(void) { return &m_CurrentSetting ; }
837 //@}
838
839 /**@name Drawing */
840 //@{
841 /** Draws the complete list on a wxDC.
842 @param dc the wxDC to draw on
843 @param offset an optional offset to shift printout
844 @param top optional y coordinate where to start drawing
845 @param bottom optional y coordinate where to stop drawing
846 */
847 void Draw(wxDC &dc,
848 const wxPoint &offset = wxPoint(0,0),
849 CoordType top = -1, CoordType bottom = -1);
850
851 /** Calculates new layout for the list, like Draw() but does not
852 actually draw it.
853 @param dc the wxDC to draw on
854 @param bottom optional y coordinate where to stop calculating
855 @param forceAll force re-layout of all lines
856 */
857 void Layout(wxDC &dc, CoordType bottom = -1, bool forceAll = false);
858
859 /** Calculates new sizes for everything in the list, like Layout()
860 but this is needed after the list got changed.
861 @param dc the wxDC to draw on
862 @param bottom optional y coordinate where to stop calculating
863 */
864 void Recalculate(wxDC &dc, CoordType bottom = -1);
865
866 /** Returns the size of the list in screen coordinates.
867 The return value only makes sense after the list has been
868 drawn.
869 @return a wxPoint holding the maximal x/y coordinates used for
870 drawing
871 */
872 wxPoint GetSize(void) const;
873
874 /** Returns the cursor position on the screen.
875 @return cursor position in pixels
876 */
877 wxPoint GetCursorScreenPos(wxDC &dc);
878
879 /** Draws the cursor.
880 @param active If true, draw a bold cursor to mark window as
881 active.
882 @param translate optional translation of cursor coords on screen
883 */
884 void DrawCursor(wxDC &dc,
885 bool active = true,
886 const wxPoint & translate = wxPoint(0,0));
887
888 /** This function finds an object belonging to a given screen
889 position. It assumes that Layout() has been called before.
890 @param pos screen position
891 @param cursorPos if non NULL, store cursor position in there
892 @param found if used, set this to true if we really found an
893 object, to false if we had to take the object near to it
894 @return pointer to the object
895 */
896 wxLayoutObject * FindObjectScreen(wxDC &dc,
897 wxPoint const pos,
898 wxPoint *cursorPos = NULL,
899 bool *found = NULL);
900
901 /** Called by the objects to update the update rectangle.
902 @param x horizontal coordinate to include in rectangle
903 @param y vertical coordinate to include in rectangle
904 */
905 void SetUpdateRect(CoordType x, CoordType y);
906 /** Called by the objects to update the update rectangle.
907 @param p a point to include in it
908 */
909 inline void SetUpdateRect(const wxPoint &p)
910 { SetUpdateRect(p.x,p.y); }
911 /// Invalidates the update rectangle.
912 void InvalidateUpdateRect(void) { m_UpdateRectValid = false; }
913 /// Returns the update rectangle.
914 const wxRect *GetUpdateRect(void) const { return &m_UpdateRect; }
915 //@}
916
917 /**@name For exporting one object after another. */
918 //@{
919 /** Returns a pointer to the first line in the list. */
920 wxLayoutLine *GetFirstLine(void)
921 {
922 wxASSERT(m_FirstLine);
923 return m_FirstLine;
924 }
925 //@}
926
927 /// Begin selecting text.
928 void StartSelection(void);
929 // Continue selecting text
930 void ContinueSelection(void);
931 /// End selecting text.
932 void EndSelection(void);
933 /// Are we still selecting text?
934 bool IsSelecting(void);
935 bool IsSelected(const wxPoint &cursor);
936
937 /// Return the selection as a wxLayoutList:
938 wxLayoutList *GetSelection(void);
939 /// Delete selected bit
940 void DeleteSelection(void);
941
942 wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0),
943 const wxPoint &to = wxPoint(-1,-1));
944
945 /// starts highlighting of text for selections
946 void StartHighlighting(wxDC &dc);
947 /// ends highlighting of text for selections
948 void EndHighlighting(wxDC &dc);
949
950 /** Tests whether this layout line is selected and needs
951 highlighting.
952 @param line to test for
953 @param from set to first cursorpos to be highlighted (for returncode == -1)
954 @param to set to last cursorpos to be highlighted (for returncode == -1)
955 @return 0 = not selected, 1 = fully selected, -1 = partially
956 selected
957
958 */
959 int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
960
961 void ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc);
962 #ifdef WXLAYOUT_DEBUG
963 void Debug(void);
964 #endif
965 private:
966 /// Clear the list.
967 void InternalClear(void);
968 /** Calculates the cursor position on the screen.
969 */
970 void UpdateCursorScreenPos(wxDC &dc);
971
972 /// The list of lines.
973 wxLayoutLine *m_FirstLine;
974 /// The update rectangle which needs to be refreshed:
975 wxRect m_UpdateRect;
976 /// Is the update rectangle valid?
977 bool m_UpdateRectValid;
978 /**@name Cursor Management */
979 //@{
980 /// Where the text cursor (column,line) is.
981 wxPoint m_CursorPos;
982 /// The size of the cursor.
983 wxPoint m_CursorSize;
984 /// Where the cursor should be drawn.
985 wxPoint m_CursorScreenPos;
986 /// The line where the cursor is.
987 wxLayoutLine *m_CursorLine;
988 //@}
989
990 /// A structure for the selection.
991 struct Selection
992 {
993 Selection() { m_valid = false; m_selecting = false; }
994 bool m_valid;
995 bool m_selecting;
996 wxPoint m_CursorA, m_CursorB;
997 } m_Selection;
998 /** @name Font parameters. */
999 //@{
1000 /// this object manages the fonts for us
1001 wxFontCache m_FontCache;
1002 /// the default setting:
1003 wxLayoutStyleInfo m_DefaultSetting;
1004 /// the current setting:
1005 wxLayoutStyleInfo m_CurrentSetting;
1006 //@}
1007 };
1008
1009
1010
1011
1012 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1013
1014 The wxLayoutPrintout object for printing within the wxWindows print
1015 framework.
1016
1017 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1018 /** This class implements a wxPrintout for printing a wxLayoutList within
1019 the wxWindows printing framework.
1020 */
1021 class wxLayoutPrintout: public wxPrintout
1022 {
1023 public:
1024 /** Constructor.
1025 @param llist pointer to the wxLayoutList to be printed
1026 @param title title for PS file or windows
1027 */
1028 wxLayoutPrintout(wxLayoutList *llist,
1029 wxString const & title =
1030 "wxLayout Printout");
1031 /// Destructor.
1032 ~wxLayoutPrintout();
1033
1034 /** Function which prints the n-th page.
1035 @param page the page number to print
1036 @return bool true if we are not at end of document yet
1037 */
1038 bool OnPrintPage(int page);
1039 /** Checks whether page exists in document.
1040 @param page number of page
1041 @return true if page exists
1042 */
1043 bool HasPage(int page);
1044
1045 /** Gets called from wxWindows to find out which pages are existing.
1046 I'm not totally sure about the parameters though.
1047 @param minPage the first page in the document
1048 @param maxPage the last page in the document
1049 @param selPageFrom the first page to be printed
1050 @param selPageTo the last page to be printed
1051 */
1052 void GetPageInfo(int *minPage, int *maxPage,
1053 int *selPageFrom, int *selPageTo);
1054 protected:
1055 /** This little function scales the DC so that the printout has
1056 roughly the same size as the output on screen.
1057 @param dc the wxDC to scale
1058 @return the scale that was applied
1059 */
1060 float ScaleDC(wxDC *dc);
1061
1062 /* no longer used
1063 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1064 */
1065 private:
1066 /// The list to print.
1067 wxLayoutList *m_llist;
1068 /// Title for PS file or window.
1069 wxString m_title;
1070 /// The real paper size.
1071 int m_PageHeight, m_PageWidth;
1072 /// How much we actually print per page.
1073 int m_PrintoutHeight;
1074 /// How many pages we need to print.
1075 int m_NumOfPages;
1076 /// Top left corner where we start printing.
1077 wxPoint m_Offset;
1078 };
1079
1080
1081 #endif // WXLLIST_H