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