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