]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxllist.h
find position bug fixed
[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() const
294 {
295 return fg_valid ? new
296 wxColour(bg_red,bg_green,bg_blue)
297 : wxWHITE;
298 }
299 wxFont *GetFont(wxLayoutStyleInfo *);
300 /// Font change parameters.
301 int size, family, style, weight, underline;
302 /// Is foreground colour valid to bet set?
303 bool fg_valid;
304 /// Is background colour valid to bet set?
305 bool bg_valid;
306 /// Foreground colour RGB values.
307 unsigned fg_red, fg_green, fg_blue;
308 /// Background colour RGB values.
309 unsigned bg_red, bg_green, bg_blue;
310 };
311
312 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
313
314 wxLayoutObjectCmd
315
316 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
317 /** This class implements a wxLayoutObject holding style change commands.
318 */
319 class wxLayoutObjectCmd : public wxLayoutObject
320 {
321 public:
322 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
323 virtual void Layout(wxDC &dc, class wxLayoutList *llist);
324 virtual void Draw(wxDC &dc, wxPoint const &coords,
325 class wxLayoutList *wxllist,
326 CoordType begin = -1,
327 CoordType end = -1);
328 wxLayoutObjectCmd(int size = -1,
329 int family = -1,
330 int style = -1,
331 int weight = -1,
332 int underline = -1,
333 wxColour *fg = NULL,
334 wxColour *bg = NULL);
335 ~wxLayoutObjectCmd();
336 /** Stores the current style in the styleinfo structure */
337 wxLayoutStyleInfo * GetStyle(void) const;
338 /** Makes a copy of this object.
339 */
340 virtual wxLayoutObject *Copy(void);
341 private:
342 /// the font to use
343 wxFont *m_font;
344 wxLayoutStyleInfo *m_StyleInfo;
345 };
346
347 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
348
349 The wxLayoutLine object
350
351 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
352
353 /// forward declaration
354 class wxLayoutList;
355
356 /** This class represents a single line of objects to be displayed.
357 It knows its height and total size and whether it needs to be
358 redrawn or not.
359 It has pointers to its first and next line so it can automatically
360 update them as needed.
361 */
362 class wxLayoutLine
363 {
364 public:
365 /** Constructor.
366 @param prev pointer to previous line or NULL
367 @param next pointer to following line or NULL
368 @param llist pointer to layout list
369 */
370 wxLayoutLine(wxLayoutLine *prev, wxLayoutList *llist);
371 /** This function inserts a new object at cursor position xpos.
372 @param xpos where to insert new object
373 @param obj the object to insert
374 @return true if that xpos existed and the object was inserted
375 */
376 bool Insert(CoordType xpos, wxLayoutObject *obj);
377
378 /** This function inserts text at cursor position xpos.
379 @param xpos where to insert
380 @param text the text to insert
381 @return true if that xpos existed and the object was inserted
382 */
383 bool Insert(CoordType xpos, wxString text);
384
385 /** This function appends an object to the line.
386 @param obj the object to insert
387 */
388 void Append(wxLayoutObject * obj)
389 {
390 wxASSERT(obj);
391 m_ObjectList.push_back(obj);
392 m_Length += obj->GetLength();
393 }
394
395 /** This function appens the next line to this, i.e. joins the two
396 lines into one.
397 */
398 void MergeNextLine(wxLayoutList *llist);
399
400 /** This function deletes npos cursor positions from position xpos.
401 @param xpos where to delete
402 @param npos how many positions
403 @return number of positions still to be deleted
404 */
405 CoordType Delete(CoordType xpos, CoordType npos);
406
407 /** This function breaks the line at a given cursor position.
408 @param xpos where to break it
409 @return pointer to the new line object replacing the old one
410 */
411 wxLayoutLine *Break(CoordType xpos, wxLayoutList *llist);
412
413 /** Deletes the next word from this position, including leading
414 whitespace.
415 This function does not delete over font changes, i.e. a word
416 with formatting instructions in the middle of it is treated as
417 two (three actually!) words. In fact, if the cursor is on a non-text object, that
418 one is treated as a word.
419 @param xpos from where to delete
420 @return true if a word was deleted
421 */
422 bool DeleteWord(CoordType npos);
423
424 /** Finds a suitable position left to the given column to break the
425 line.
426 @param column we want to break the line to the left of this
427 @return column for breaking line or -1 if no suitable location found
428 */
429 CoordType GetWrapPosition(CoordType column);
430
431 /** Finds the object which covers the cursor position xpos in this
432 line.
433 @param xpos the column number
434 @param offset where to store the difference between xpos and
435 the object's head
436 @return iterator to the object or NULLIT
437 */
438 wxLayoutObjectList::iterator FindObject(CoordType xpos, CoordType
439 *offset) const ;
440
441 /** Finds the object which covers the screen position xpos in this
442 line.
443 @param dc the wxDC to use for calculations
444 @param xpos the screen x coordinate
445 @param offset where to store the difference between xpos and
446 the object's head
447 @return iterator to the object or NULLIT
448 */
449 wxLayoutObjectList::iterator FindObjectScreen(wxDC &dc,
450 CoordType xpos,
451 CoordType *offset,
452 bool *found = NULL) const ;
453
454 /** Finds text in this line.
455 @param needle the text to find
456 @param xpos the position where to start the search
457 @return the cursoor coord where it was found or -1
458 */
459 CoordType FindText(const wxString &needle, CoordType xpos = 0) const;
460
461 /** Get the first object in the list. This is used by the wxlparser
462 functions to export the list.
463 @return iterator to the first object
464 */
465 wxLayoutObjectList::iterator GetFirstObject(void)
466 {
467 return m_ObjectList.begin();
468 }
469
470 /** Deletes this line, returns pointer to next line.
471 @param update If true, update all following lines.
472 */
473 wxLayoutLine *DeleteLine(bool update, wxLayoutList *llist);
474
475 /**@name Cursor Management */
476 //@{
477 /** Return the line number of this line.
478 @return the line number
479 */
480 inline CoordType GetLineNumber(void) const { return m_LineNumber; }
481 /** Return the length of the line.
482 @return line lenght in cursor positions
483 */
484 inline CoordType GetLength(void) const { return m_Length; }
485 //@}
486
487 /**@name Drawing and Layout */
488 //@{
489 /** Draws the line on a wxDC.
490 @param dc the wxDC to draw on
491 @param llist the wxLayoutList
492 @param offset an optional offset to shift printout
493 */
494 void Draw(wxDC &dc,
495 wxLayoutList *llist,
496 const wxPoint &offset = wxPoint(0,0)) const;
497
498 /** Recalculates the positions of objects and the height of the
499 line.
500 @param dc the wxDC to draw on
501 @param llist th e wxLayoutList
502 @param cursorPos if not NULL, set cursor screen position in there
503 @param cursorSize if not cursorPos != NULL, set cursor size in there
504 @param cx if cursorPos != NULL, the cursor x position
505 */
506 void Layout(wxDC &dc,
507 wxLayoutList *llist,
508 wxPoint *cursorPos = NULL,
509 wxPoint *cursorSize = NULL,
510 int cx = 0);
511 /** This function finds an object belonging to a given cursor
512 position. It assumes that Layout() has been called before.
513 @param dc the wxDC to use for calculations
514 @param xpos screen x position
515 @param found if non-NULL set to false if we return the last
516 object before the cursor, to true if we really have an object
517 for that position
518 @return pointer to the object
519 */
520 wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos, bool
521 *found = NULL);
522
523 //@}
524
525 /**@name List traversal */
526 //@{
527 /// Returns pointer to next line.
528 wxLayoutLine *GetNextLine(void) const { return m_Next; }
529 /// Returns pointer to previous line.
530 wxLayoutLine *GetPreviousLine(void) const { return m_Previous; }
531 /// Sets the link to the next line.
532 void SetNext(wxLayoutLine *next)
533 { m_Next = next; if(next) next->m_Previous = this; }
534 /// Sets the link to the previous line.
535 void SetPrevious(wxLayoutLine *previous)
536 { m_Previous = previous; if(previous) previous->m_Next = this; }
537 //@}
538
539 /// Returns the position of this line on the canvas.
540 wxPoint GetPosition(void) const { return m_Position; }
541 /// Returns the height of this line.
542 CoordType GetHeight(void) const { return m_Height; }
543 /// Returns the width of this line.
544 CoordType GetWidth(void) const { return m_Width; }
545 /** This will recalculate the position and size of this line.
546 If called recursively it will abort if the position of an
547 object is unchanged, assuming that none of the following
548 objects need to move.
549 @param recurse if greater 0 then it will be used as the
550 minimum(!) recursion level, continue with all lines till the end of
551 the list or until the coordinates no longer changed.
552 */
553 void RecalculatePositions(int recurse, wxLayoutList *llist);
554 /// Recalculates the position of this line on the canvas.
555 wxPoint RecalculatePosition(wxLayoutList *llist);
556
557 /** Copies the contents of this line to another wxLayoutList
558 @param llist the wxLayoutList destination
559 @param from x cursor coordinate where to start
560 @param to x cursor coordinate where to stop, -1 for end of line
561 */
562 void Copy(wxLayoutList *llist,
563 CoordType from = 0,
564 CoordType to = -1);
565
566 #ifdef WXLAYOUT_DEBUG
567 void Debug(void);
568 #endif
569
570 private:
571 /// Destructor is private. Use DeleteLine() to remove it.
572 ~wxLayoutLine();
573
574 /**@name Functions to let the lines synchronise with each other. */
575 //@{
576 /** Sets the height of this line. Will mark following lines as
577 dirty.
578 @param height new height
579 */
580 void SetHeight(CoordType height, wxLayoutList *llist)
581 { m_Height = height; RecalculatePositions(true, llist); }
582
583 /** Moves the linenumbers one on, because a line has been inserted
584 or deleted.
585 @param delta either +1 or -1
586 */
587 void MoveLines(int delta)
588 {
589 m_LineNumber += delta;
590 if(m_Next) m_Next->MoveLines(delta);
591 }
592 //@}
593 private:
594 /// The line number.
595 CoordType m_LineNumber;
596 /// The line length in cursor positions.
597 CoordType m_Length;
598 /// The total height of the line.
599 CoordType m_Height;
600 /// The total width of the line on screen.
601 CoordType m_Width;
602 /// The baseline for drawing objects
603 CoordType m_BaseLine;
604 /// The position on the canvas.
605 wxPoint m_Position;
606 /// The list of objects
607 wxLayoutObjectList m_ObjectList;
608 /// Have we been changed since the last layout?
609 bool m_Dirty;
610 /// Pointer to previous line if it exists.
611 wxLayoutLine *m_Previous;
612 /// Pointer to next line if it exists.
613 wxLayoutLine *m_Next;
614 /// Just to suppress gcc compiler warnings.
615 friend class dummy;
616 private:
617 wxLayoutLine(const wxLayoutLine &);
618 };
619
620
621 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
622
623 The wxLayoutList object
624
625 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
626 /** The wxLayoutList is a list of wxLayoutLine objects. It provides a
627 higher level of abstraction for the text and can generally be considered
628 as representing "the text".
629 */
630 class wxLayoutList
631 {
632 public:
633 /// Constructor.
634 wxLayoutList();
635 /// Destructor.
636 ~wxLayoutList();
637
638 /// Clear the list.
639 void Clear(int family = wxROMAN,
640 int size=WXLO_DEFAULTFONTSIZE,
641 int style=wxNORMAL,
642 int weight=wxNORMAL,
643 int underline=0,
644 wxColour *fg=NULL,
645 wxColour *bg=NULL);
646 /// Empty: clear the list but leave font settings.
647 void Empty(void);
648
649 /**@name Cursor Management */
650 //@{
651 /** Set new cursor position.
652 @param p new position
653 @return bool if it could be set
654 */
655 bool MoveCursorTo(wxPoint const &p);
656 /** Move cursor up or down.
657 @param n
658 @return bool if it could be moved
659 */
660 bool MoveCursorVertically(int n);
661 /** Move cursor left or right.
662 @param n
663 @return bool if it could be moved
664 */
665 bool MoveCursorHorizontally(int n);
666
667 /// Move cursor to end of line.
668 void MoveCursorToEndOfLine(void)
669 {
670 wxASSERT(m_CursorLine);
671 MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x);
672 }
673
674 /// Move cursor to begin of line.
675 void MoveCursorToBeginOfLine(void)
676 { MoveCursorHorizontally(-m_CursorPos.x); }
677
678 /// Returns current cursor position.
679 wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; }
680 wxPoint GetCursorPos() const { return m_CursorPos; }
681
682 //@}
683
684 /**@name Editing functions.
685 All of these functions return true on success and false on
686 failure. */
687 //@{
688 /// Insert text at current cursor position.
689 bool Insert(wxString const &text);
690 /// Insert some other object at current cursor position.
691 bool Insert(wxLayoutObject *obj);
692 /// Inserts a linebreak at current cursor position.
693 bool LineBreak(void);
694 /** Wraps the current line. Searches to the left of the cursor to
695 break the line. Does nothing if the cursor position is before
696 the break position parameter.
697 @param column the break position for the line, maximum length
698 @return true if line got broken
699 */
700 bool WrapLine(CoordType column);
701 /** This function deletes npos cursor positions.
702 @param npos how many positions
703 @return true if everything got deleted
704 */
705 bool Delete(CoordType npos);
706
707 /** Delete the next n lines.
708 @param n how many lines to delete
709 @return how many it could not delete
710 */
711 int DeleteLines(int n);
712
713 /// Delete to end of line.
714 void DeleteToEndOfLine(void)
715 {
716 wxASSERT(m_CursorLine);
717 Delete(m_CursorLine->GetLength()-m_CursorPos.x);
718 }
719 /// Delete to begin of line.
720 void DeleteToBeginOfLine(void)
721 {
722 wxASSERT(m_CursorLine);
723 CoordType n = m_CursorPos.x;
724 #ifdef WXLAYOUT_DEBUG
725 wxASSERT(MoveCursorHorizontally(-n));
726 #else
727 MoveCursorHorizontally(-n);
728 #endif
729 Delete(n);
730 }
731
732 /** Delete the next word.
733 */
734 void DeleteWord(void)
735 {
736 wxASSERT(m_CursorLine);
737 m_CursorLine->DeleteWord(m_CursorPos.x);
738 }
739
740 //@}
741
742 /** Finds text in this list.
743 @param needle the text to find
744 @param cpos the position where to start the search
745 @return the cursoor coord where it was found or (-1,-1)
746 */
747 wxPoint FindText(const wxString &needle, const wxPoint &cpos = wxPoint(0,0)) const;
748
749 /**@name Formatting options */
750 //@{
751 /// sets font parameters
752 void SetFont(int family, int size, int style,
753 int weight, int underline,
754 wxColour *fg,
755 wxColour *bg);
756 /// sets font parameters, colours by name
757 void SetFont(int family=-1, int size = -1, int style=-1,
758 int weight=-1, int underline = -1,
759 char const *fg = NULL,
760 char const *bg = NULL);
761 /// changes to the next larger font size
762 inline void SetFontLarger(void)
763 { SetFont(-1,(12*m_FontPtSize)/10); }
764 /// changes to the next smaller font size
765 inline void SetFontSmaller(void)
766 { SetFont(-1,(10*m_FontPtSize)/12); }
767
768 /// set font family
769 inline void SetFontFamily(int family) { SetFont(family); }
770 /// set font size
771 inline void SetFontSize(int size) { SetFont(-1,size); }
772 /// set font style
773 inline void SetFontStyle(int style) { SetFont(-1,-1,style); }
774 /// set font weight
775 inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); }
776 /// toggle underline flag
777 inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
778 /// set font colours by name
779 inline void SetFontColour(char const *fg, char const *bg = NULL)
780 { SetFont(-1,-1,-1,-1,-1,fg,bg); }
781 /// set font colours by colour
782 inline void SetFontColour(wxColour *fg, wxColour *bg = NULL)
783 { SetFont(-1,-1,-1,-1,-1,fg,bg); }
784
785
786 /**
787 Returns a pointer to the default settings.
788 This is only valid temporarily and should not be stored
789 anywhere.
790 @return the default settings of the list
791 */
792 wxLayoutStyleInfo *GetDefaults(void) { return m_DefaultSetting ; }
793 //@}
794
795 /**@name Drawing */
796 //@{
797 /** Draws the complete list on a wxDC.
798 @param dc the wxDC to draw on
799 @param offset an optional offset to shift printout
800 @param top optional y coordinate where to start drawing
801 @param bottom optional y coordinate where to stop drawing
802 */
803 void Draw(wxDC &dc,
804 const wxPoint &offset = wxPoint(0,0),
805 CoordType top = -1, CoordType bottom = -1);
806
807 /** Calculates new layout for the list, like Draw() but does not
808 actually draw it.
809 @param dc the wxDC to draw on
810 @param bottom optional y coordinate where to stop calculating
811 */
812 void Layout(wxDC &dc, CoordType bottom = -1);
813
814 /** Calculates new sizes for everything in the list, like Layout()
815 but this is needed after the list got changed.
816 @param dc the wxDC to draw on
817 @param bottom optional y coordinate where to stop calculating
818 */
819 void Recalculate(wxDC &dc, CoordType bottom = -1);
820
821 /** Returns the size of the list in screen coordinates.
822 The return value only makes sense after the list has been
823 drawn.
824 @return a wxPoint holding the maximal x/y coordinates used for
825 drawing
826 */
827 wxPoint GetSize(void) const;
828
829 /** Returns the cursor position on the screen.
830 @return cursor position in pixels
831 */
832 wxPoint GetCursorScreenPos(wxDC &dc);
833
834 /** Draws the cursor.
835 @param active If true, draw a bold cursor to mark window as
836 active.
837 @param translate optional translation of cursor coords on screen
838 */
839 void DrawCursor(wxDC &dc,
840 bool active = true,
841 const wxPoint & translate = wxPoint(0,0));
842
843 /** This function finds an object belonging to a given screen
844 position. It assumes that Layout() has been called before.
845 @param pos screen position
846 @param cursorPos if non NULL, store cursor position in there
847 @param found if used, set this to true if we really found an
848 object, to false if we had to take the object near to it
849 @return pointer to the object
850 */
851 wxLayoutObject * FindObjectScreen(wxDC &dc,
852 wxPoint const pos,
853 wxPoint *cursorPos = NULL,
854 bool *found = NULL);
855
856 /** Called by the objects to update the update rectangle.
857 @param x horizontal coordinate to include in rectangle
858 @param y vertical coordinate to include in rectangle
859 */
860 void SetUpdateRect(CoordType x, CoordType y);
861 /** Called by the objects to update the update rectangle.
862 @param p a point to include in it
863 */
864 inline void SetUpdateRect(const wxPoint &p)
865 { SetUpdateRect(p.x,p.y); }
866 /// Invalidates the update rectangle.
867 void InvalidateUpdateRect(void) { m_UpdateRectValid = false; }
868 /// Returns the update rectangle.
869 const wxRect *GetUpdateRect(void) const { return &m_UpdateRect; }
870 //@}
871
872 /**@name For exporting one object after another. */
873 //@{
874 /** Returns a pointer to the first line in the list. */
875 wxLayoutLine *GetFirstLine(void)
876 {
877 wxASSERT(m_FirstLine);
878 return m_FirstLine;
879 }
880 //@}
881
882 /// Begin selecting text.
883 void StartSelection(void);
884 // Continue selecting text
885 void ContinueSelection(void);
886 /// End selecting text.
887 void EndSelection(void);
888 /// Are we still selecting text?
889 bool IsSelecting(void);
890 bool IsSelected(const wxPoint &cursor);
891
892 /// Return the selection as a wxLayoutList:
893 wxLayoutList *GetSelection(void);
894 /// Delete selected bit
895 void DeleteSelection(void);
896
897 wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0),
898 const wxPoint &to = wxPoint(-1,-1));
899
900 /// starts highlighting of text for selections
901 void StartHighlighting(wxDC &dc);
902 /// ends highlighting of text for selections
903 void EndHighlighting(wxDC &dc);
904
905 /** Tests whether this layout line is selected and needs
906 highlighting.
907 @param line to test for
908 @param from set to first cursorpos to be highlighted (for returncode == -1)
909 @param to set to last cursorpos to be highlighted (for returncode == -1)
910 @return 0 = not selected, 1 = fully selected, -1 = partially
911 selected
912
913 */
914 int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to);
915
916
917 void ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc);
918 #ifdef WXLAYOUT_DEBUG
919 void Debug(void);
920 #endif
921 private:
922 /// Clear the list.
923 void InternalClear(void);
924 /** Calculates the cursor position on the screen.
925 */
926 void UpdateCursorScreenPos(wxDC &dc);
927
928 /// The list of lines.
929 wxLayoutLine *m_FirstLine;
930 /// The update rectangle which needs to be refreshed:
931 wxRect m_UpdateRect;
932 /// Is the update rectangle valid?
933 bool m_UpdateRectValid;
934 /**@name Cursor Management */
935 //@{
936 /// Where the text cursor (column,line) is.
937 wxPoint m_CursorPos;
938 /// The size of the cursor.
939 wxPoint m_CursorSize;
940 /// Where the cursor should be drawn.
941 wxPoint m_CursorScreenPos;
942 /// The line where the cursor is.
943 wxLayoutLine *m_CursorLine;
944 //@}
945
946 /// A structure for the selection.
947 struct Selection
948 {
949 Selection() { m_valid = false; m_selecting = false; }
950 bool m_valid;
951 bool m_selecting;
952 wxPoint m_CursorA, m_CursorB;
953 } m_Selection;
954 /** @name Font parameters. */
955 //@{
956 int m_FontFamily, m_FontStyle, m_FontWeight;
957 int m_FontPtSize;
958 bool m_FontUnderline;
959 /// colours:
960 wxColour m_ColourFG;
961 wxColour m_ColourBG;
962 /// the default setting:
963 wxLayoutStyleInfo *m_DefaultSetting;
964 /// the current setting:
965 wxLayoutStyleInfo m_CurrentSetting;
966 //@}
967 };
968
969
970
971
972 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
973
974 The wxLayoutPrintout object for printing within the wxWindows print
975 framework.
976
977 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
978 /** This class implements a wxPrintout for printing a wxLayoutList within
979 the wxWindows printing framework.
980 */
981 class wxLayoutPrintout: public wxPrintout
982 {
983 public:
984 /** Constructor.
985 @param llist pointer to the wxLayoutList to be printed
986 @param title title for PS file or windows
987 */
988 wxLayoutPrintout(wxLayoutList *llist,
989 wxString const & title =
990 "wxLayout Printout");
991 /// Destructor.
992 ~wxLayoutPrintout();
993
994 /** Function which prints the n-th page.
995 @param page the page number to print
996 @return bool true if we are not at end of document yet
997 */
998 bool OnPrintPage(int page);
999 /** Checks whether page exists in document.
1000 @param page number of page
1001 @return true if page exists
1002 */
1003 bool HasPage(int page);
1004
1005 /** Gets called from wxWindows to find out which pages are existing.
1006 I'm not totally sure about the parameters though.
1007 @param minPage the first page in the document
1008 @param maxPage the last page in the document
1009 @param selPageFrom the first page to be printed
1010 @param selPageTo the last page to be printed
1011 */
1012 void GetPageInfo(int *minPage, int *maxPage,
1013 int *selPageFrom, int *selPageTo);
1014 protected:
1015 /** This little function scales the DC so that the printout has
1016 roughly the same size as the output on screen.
1017 @param dc the wxDC to scale
1018 @return the scale that was applied
1019 */
1020 float ScaleDC(wxDC *dc);
1021
1022 /* no longer used
1023 virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno);
1024 */
1025 private:
1026 /// The list to print.
1027 wxLayoutList *m_llist;
1028 /// Title for PS file or window.
1029 wxString m_title;
1030 /// The real paper size.
1031 int m_PageHeight, m_PageWidth;
1032 /// How much we actually print per page.
1033 int m_PrintoutHeight;
1034 /// How many pages we need to print.
1035 int m_NumOfPages;
1036 /// Top left corner where we start printing.
1037 wxPoint m_Offset;
1038 };
1039
1040
1041 #endif // WXLLIST_H