]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxllist.h
Various documentation changes, makefile fixes
[wxWidgets.git] / user / wxLayout / wxllist.h
1 /*-*- c++ -*-********************************************************
2 * wxLayoutList.h - a formatted text rendering engine for wxWindows *
3 * *
4 * (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
5 * *
6 * $Id$
7 *******************************************************************/
8 #ifndef WXLLIST_H
9 #define WXLLIST_H
10
11 #ifdef __GNUG__
12 # pragma interface "wxllist.h"
13 #endif
14
15 #include "kbList.h"
16
17 #include <wx/wx.h>
18
19 #ifndef DEBUG
20 # define DEBUG
21 #endif
22
23
24 enum wxLayoutObjectType { WXLO_TYPE_INVALID, WXLO_TYPE_TEXT, WXLO_TYPE_CMD, WXLO_TYPE_ICON, WXLO_TYPE_LINEBREAK };
25
26 typedef long CoordType;
27
28 class wxLayoutList;
29 class wxLayoutObjectBase;
30
31 KBLIST_DEFINE(wxLayoutObjectList, wxLayoutObjectBase);
32 KBLIST_DEFINE(wxLayoutOLinesList, wxLayoutObjectList::iterator);
33
34
35 class wxLayoutObjectBase
36 {
37 public:
38 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_INVALID; } ;
39 /** Draws an object.
40 @param dc the wxDC to draw on
41 @param position where to draw the top left corner
42 @param baseLine the baseline for alignment, from top of box
43 @draw if set to false, do not draw but just calculate sizes
44 */
45 virtual void Draw(wxDC &dc, wxPoint position, CoordType baseLine,
46 bool draw = true) {};
47
48 virtual wxPoint GetSize(CoordType *baseLine) const { return
49 wxPoint(0,0); };
50 /// returns the number of cursor positions occupied by this object
51 virtual CoordType CountPositions(void) const { return 1; }
52
53 wxLayoutObjectBase() { m_UserData = NULL; }
54 virtual ~wxLayoutObjectBase() {}
55 #ifdef DEBUG
56 virtual void Debug(void);
57 #endif
58
59 void SetUserData(void *data) { m_UserData = data; }
60 void * GetUserData(void) const { return m_UserData; }
61 private:
62 /// optional data for application's use
63 void * m_UserData;
64 };
65
66 /// object for text block
67 class wxLayoutObjectText : public wxLayoutObjectBase
68 {
69 public:
70 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
71 virtual void Draw(wxDC &dc, wxPoint position, CoordType baseLine,
72 bool draw = true);
73 /** This returns the height and in baseLine the position of the
74 text's baseline within it's box. This is needed to properly
75 align text objects.
76 */
77 virtual wxPoint GetSize(CoordType *baseLine) const;
78 #ifdef DEBUG
79 virtual void Debug(void);
80 #endif
81
82 wxLayoutObjectText(const wxString &txt);
83 virtual CoordType CountPositions(void) const { return strlen(m_Text.c_str()); }
84
85 // for editing:
86 wxString & GetText(void) { return m_Text; }
87 void SetText(wxString const &text) { m_Text = text; }
88 private:
89 wxString m_Text;
90 /// size of the box containing text
91 long m_Width, m_Height;
92 /// the position of the baseline counted from the top of the box
93 long m_BaseLine;
94 };
95
96 /// icon/pictures:
97 class wxLayoutObjectIcon : public wxLayoutObjectBase
98 {
99 public:
100 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
101 virtual void Draw(wxDC &dc, wxPoint position, CoordType baseLine,
102 bool draw = true);
103 virtual wxPoint GetSize(CoordType *baseLine) const;
104 wxLayoutObjectIcon(wxIcon *icon);
105 private:
106 wxIcon * m_Icon;
107 };
108
109 /// for export to html:
110 struct wxLayoutStyleInfo
111 {
112 int size, family, style, weight;
113 bool underline;
114 unsigned fg_red, fg_green, fg_blue;
115 unsigned bg_red, bg_green, bg_blue;
116 };
117
118 /// pseudo-object executing a formatting command in Draw()
119 class wxLayoutObjectCmd : public wxLayoutObjectBase
120 {
121 public:
122 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
123 virtual void Draw(wxDC &dc, wxPoint position, CoordType baseLine,
124 bool draw = true);
125 wxLayoutObjectCmd(int size, int family, int style, int weight,
126 bool underline,
127 wxColour const *fg, wxColour const *bg);
128 ~wxLayoutObjectCmd();
129 // caller must free pointer:
130 wxLayoutStyleInfo *GetStyle(void) const ;
131 private:
132 /// the font to use
133 wxFont *m_font;
134 /// foreground colour
135 wxColour const *m_ColourFG;
136 /// background colour
137 wxColour const *m_ColourBG;
138 };
139
140 /// this object doesn't do anything at all
141 class wxLayoutObjectLineBreak : public wxLayoutObjectBase
142 {
143 public:
144 virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_LINEBREAK; }
145 };
146
147
148 /**
149 This class provides a high level abstraction to the wxFText
150 classes.
151 It handles most of the character events with its own callback
152 functions, providing an editing ability. All events which cannot be
153 handled get passed to the parent window's handlers.
154 */
155 class wxLayoutList : public wxLayoutObjectList
156 {
157 public:
158 wxLayoutList();
159
160 /// Destructor.
161 ~wxLayoutList();
162
163 /// adds an object:
164 void AddObject(wxLayoutObjectBase *obj);
165 void AddText(wxString const &txt);
166
167 void LineBreak(void);
168 void SetFont(int family, int size, int style,
169 int weight, int underline,
170 wxColour const *fg,
171 wxColour const *bg);
172 void SetFont(int family=-1, int size = -1, int style=-1,
173 int weight=-1, int underline = -1,
174 char const *fg = NULL,
175 char const *bg = NULL);
176 /** Draw the list on a given DC.
177 @param findObject if true, return the object occupying the
178 position specified by coords
179 @param coords position where to find the object
180 @return if findObject == true, the object or NULL
181 */
182 wxLayoutObjectBase *Draw(wxDC &dc, bool findObject = false,
183 wxPoint const &coords = wxPoint(0,0));
184
185 #ifdef DEBUG
186 void Debug(void);
187 #endif
188
189
190 /// for access by wxLayoutWindow:
191 void GetSize(CoordType *max_x, CoordType *max_y,
192 CoordType *lineHeight);
193
194 /**@name Functionality for editing */
195 //@{
196 /// set list editable or read only
197 void SetEditable(bool editable = true) { m_Editable = true; }
198 /// move cursor
199 void MoveCursor(int dx = 0, int dy = 0);
200 void SetCursor(wxPoint const &p) { m_CursorPosition = p; }
201 /// delete one or more cursor positions
202 void Delete(CoordType count = 1);
203 void Insert(wxString const &text);
204 void Insert(wxLayoutObjectBase *obj);
205 void Clear(void);
206
207 //@}
208 protected:
209 /// font parameters:
210 int m_FontFamily, m_FontStyle, m_FontWeight;
211 int m_FontPtSize;
212 bool m_FontUnderline;
213 /// colours:
214 wxColour const * m_ColourFG;
215 wxColour const * m_ColourBG;
216
217 /// needs recalculation?
218 bool m_dirty;
219
220 // the currently updated line:
221 /// where do we draw next:
222 wxPoint m_Position;
223 /// the height of the current line:
224 CoordType m_LineHeight;
225 /// maximum drawn x position so far
226 CoordType m_MaxX;
227 /// maximum drawn y position:
228 CoordType m_MaxY;
229
230 //---- this is needed for editing:
231 /// where is the text cursor:
232 wxPoint m_CursorPosition;
233 /// which is the last line
234 CoordType m_MaxLine;
235 /// can we edit it?
236 bool m_Editable;
237 /// find the object to the cursor position and returns the offset
238 /// in there
239 wxLayoutObjectList::iterator FindObjectCursor(wxPoint const &cpos, CoordType *offset = NULL);
240 wxLayoutObjectList::iterator FindCurrentObject(CoordType *offset = NULL);
241 // get the length of the line with the object pointed to by i
242 CoordType GetLineLength(wxLayoutObjectList::iterator i);
243
244 };
245
246 #endif // WXLLIST_H