]> git.saurik.com Git - wxWidgets.git/blob - samples/richedit/wxlwindow.h
Assert correction.
[wxWidgets.git] / samples / richedit / wxlwindow.h
1 /*-*- c++ -*-********************************************************
2 * wxLwindow.h : a scrolled Window for displaying/entering rich text*
3 * *
4 * (C) 1998-2000 by Karsten Ballüder (ballueder@gmx.net) *
5 * *
6 * $Id$
7 *******************************************************************/
8 #ifndef WXLWINDOW_H
9 #define WXLWINDOW_H
10
11 #ifdef __GNUG__
12 # pragma interface "wxlwindow.h"
13 #endif
14
15 #ifndef USE_PCH
16 # include "wx/wx.h"
17 #endif
18
19 #include "wxllist.h"
20
21 #ifndef WXLOWIN_MENU_FIRST
22 # define WXLOWIN_MENU_FIRST 12000
23 #endif
24
25
26 enum
27 {
28 WXLOWIN_MENU_LARGER = WXLOWIN_MENU_FIRST,
29 WXLOWIN_MENU_SMALLER,
30 WXLOWIN_MENU_UNDERLINE,
31 WXLOWIN_MENU_BOLD,
32 WXLOWIN_MENU_ITALICS,
33 WXLOWIN_MENU_ROMAN,
34 WXLOWIN_MENU_TYPEWRITER,
35 WXLOWIN_MENU_SANSSERIF,
36 WXLOWIN_MENU_RCLICK,
37 WXLOWIN_MENU_DBLCLICK,
38 WXLOWIN_MENU_MDOWN,
39 WXLOWIN_MENU_LDOWN,
40 WXLOWIN_MENU_LCLICK = WXLOWIN_MENU_LDOWN,
41 WXLOWIN_MENU_LUP,
42 WXLOWIN_MENU_MOUSEMOVE,
43 WXLOWIN_MENU_LAST = WXLOWIN_MENU_MOUSEMOVE
44 };
45
46 /**
47 This class is a rich text editing widget.
48 */
49 class wxLayoutWindow : public wxScrolledWindow
50 {
51 public:
52 /** Constructor.
53 @param parent parent window to display this panel in
54 */
55 wxLayoutWindow(wxWindow *parent);
56
57 /// Destructor.
58 virtual ~wxLayoutWindow();
59
60 /**@name Editing functionality */
61 //@{
62 /// Clears the window and sets default parameters.
63 void Clear(int family = wxROMAN,
64 int size = 12,
65 int style = wxNORMAL,
66 int weight = wxNORMAL,
67 int underline = 0,
68 wxColour *fg = NULL,
69 wxColour *bg = NULL);
70
71 /// override base class virtual to also refresh the scrollbar position
72 virtual void Refresh(bool eraseBackground = true,
73 const wxRect *rect = (const wxRect *)NULL);
74
75 /** Sets a background image, only used on screen, not on printouts.
76 @param bitmap a pointer to a wxBitmap or NULL to remove it
77 */
78 void SetBackgroundBitmap(wxBitmap *bitmap = NULL)
79 {
80 if(m_BGbitmap) delete m_BGbitmap;
81 m_BGbitmap = bitmap;
82 }
83
84 /// Enable or disable editing, i.e. processing of keystrokes.
85 void SetEditable(bool toggle)
86 {
87 m_Editable = toggle;
88 SetCursorVisibility(toggle);
89 }
90
91 /// Query whether list can be edited by user.
92 bool IsEditable() const { return m_Editable; }
93
94 /** Sets cursor visibility, visible=1, invisible=0,
95 visible-on-demand=-1, to hide it until moved.
96 @param visibility -1,0 or 1
97 @return the old visibility
98 */
99 inline int SetCursorVisibility(int visibility = -1)
100 {
101 int v =m_CursorVisibility;
102 m_CursorVisibility = visibility; return v;
103 }
104
105 /// Pastes text from clipboard.
106 void Paste(bool privateFormat = false, bool usePrimarySelection = false);
107
108 /** Copies selection to clipboard.
109 @param invalidate used internally, see wxllist.h for details
110 */
111 bool Copy(bool invalidate = true, bool privateFormat = false, bool primary = false);
112
113 /// Copies selection to clipboard and deletes it.
114 bool Cut(bool privateFormat = false, bool usePrimary = false);
115 //@}
116
117 /// find string in buffer
118 bool Find(const wxString &needle,
119 wxPoint * fromWhere = NULL,
120 const wxString &configPath = _T("MsgViewFindString"));
121
122 /// find the same string again
123 bool FindAgain();
124
125 void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
126
127 /** Sets the wrap margin.
128 @param margin set this to 0 to disable it
129 */
130 void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
131
132 /** Toggle wordwrap as we type.
133 @param on true to activate word wrap
134 */
135 void SetWordWrap(bool on = true) { m_DoWordWrap = on; }
136
137 /** Redraws the window.
138 Internally, this stores the parameter and calls a refresh on
139 wxMSW, draws directly on wxGTK.
140 */
141 void RequestUpdate(const wxRect *updateRect = NULL);
142
143 /// if exact == false, assume 50% extra size for the future
144 void ResizeScrollbars(bool exact = false); // don't change this to true!
145
146 /// if the flag is true, we send events when user clicks on embedded objects
147 inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
148
149 /** Returns a pointer to the wxLayoutList object.
150 @return the list
151 */
152 wxLayoutList * GetLayoutList() { return m_llist; }
153
154 /**@name Callbacks */
155 //@{
156 void OnSize(wxSizeEvent &event);
157 void OnPaint(wxPaintEvent &event);
158 void OnChar(wxKeyEvent& event);
159 void OnKeyUp(wxKeyEvent& event);
160 void OnUpdateMenuUnderline(wxUpdateUIEvent& event);
161 void OnUpdateMenuBold(wxUpdateUIEvent& event);
162 void OnUpdateMenuItalic(wxUpdateUIEvent& event);
163 void OnMenu(wxCommandEvent& event);
164 void OnLeftMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LDOWN, event); }
165 void OnLeftMouseUp(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LUP, event); }
166 void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
167 void OnMiddleMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_MDOWN, event); }
168 void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
169 void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
170 void OnSetFocus(wxFocusEvent &ev);
171 void OnKillFocus(wxFocusEvent &ev);
172 //@}
173
174 /// Creates a wxMenu for use as a format popup.
175 static wxMenu * MakeFormatMenu();
176
177 /// Redraws the window, used by RequestUpdate() or OnPaint().
178 void InternalPaint(const wxRect *updateRect);
179
180 #if wxUSE_STATUSBAR
181 /** Tell window to update a wxStatusBar with UserData labels and
182 cursor positions.
183 @param bar wxStatusBar pointer
184 @param labelfield field to use in statusbar for URLs/userdata labels, or -1 to disable
185 @param cursorfield field to use for cursor position, or -1 to disable
186 */
187 void SetStatusBar(class wxStatusBar *bar,
188 int labelfield = -1,
189 int cursorfield = -1)
190 {
191 m_StatusBar = bar; m_StatusFieldLabel = labelfield;
192 m_StatusFieldCursor = cursorfield;
193 }
194 #endif // wxUSE_STATUSBAR
195
196 #ifndef __WXMSW__
197 /// Enable or disable focus follow mode under non-MSW
198 void SetFocusFollowMode(bool enable = true)
199 {
200 m_FocusFollowMode = enable;
201 }
202 #endif
203
204 /** @name Modified flag handling, will not get reset by list unless
205 in Clear() */
206 //@{
207 /// Set dirty flag.
208 void SetModified(bool modified = true) { m_Modified = modified; }
209
210 /// Query whether window needs redrawing.
211 bool IsModified() const { return m_Modified; }
212 //@}
213
214 /**
215 @name Dirty flag handling for optimisations.
216 Normally one should only need to call SetDirty(), e.g. when
217 manipulating the wxLayoutList directly, so the window will update
218 itself. ResetDirty() and IsDirty() should only be used
219 internally. */
220 //@{
221 /// Set dirty flag.
222 void SetDirty() { m_Dirty = true; m_Modified = true; }
223
224 /// Query whether window needs redrawing.
225 bool IsDirty() const { return m_Dirty; }
226
227 /// Reset dirty flag.
228 void ResetDirty() { m_Dirty = false; }
229 //@}
230
231
232 protected:
233 /// generic function for mouse events processing
234 void OnMouse(int eventId, wxMouseEvent& event);
235
236 /// as the name says
237 void ScrollToCursor();
238
239 /// for sending events
240 wxWindow *m_Parent;
241
242 /// Shall we send events?
243 bool m_doSendEvents;
244
245 /// Where does the current view start?
246 int m_ViewStartX; int m_ViewStartY;
247
248 /// Do we currently have the focus?
249 bool m_HaveFocus;
250
251 /// do we handle clicks of the right mouse button?
252 bool m_DoPopupMenu;
253
254 /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
255 bool m_ScrollToCursor;
256
257 /// Do we currently have a non-standard cursor?
258 bool m_HandCursor;
259
260 /// the menu
261 wxMenu * m_PopupMenu;
262
263 /// for derived classes, set when mouse is clicked
264 wxPoint m_ClickPosition;
265
266 /// for scrollbar calculations:
267 int m_maxx;
268 int m_maxy;
269 int m_lineHeight;
270
271 /// do we want automatic word wrap?
272 bool m_DoWordWrap;
273
274 /// wrap margin
275 CoordType m_WrapMargin;
276
277 /// do we have the corresponding scrollbar?
278 bool m_hasHScrollbar,
279 m_hasVScrollbar;
280
281 /** Visibility parameter for cursor. 0/1 as expected, -1: visible
282 on demand.
283 */
284 int m_CursorVisibility;
285
286 bool SetAutoDeleteSelection(bool enable = true)
287 {
288 bool old = m_AutoDeleteSelection;
289 m_AutoDeleteSelection = enable;
290 return old;
291 }
292 private:
293 /// The layout list to be displayed.
294 wxLayoutList *m_llist;
295
296 /// Can user edit the window?
297 bool m_Editable;
298
299 /// Are we currently building a selection with the keyboard?
300 bool m_Selecting;
301
302 /// Has list changed since last redraw, e.g. in size?
303 bool m_Dirty;
304
305 /// Has the list ever been modified?
306 bool m_Modified;
307
308 wxMemoryDC *m_memDC;
309 wxBitmap *m_bitmap;
310 wxPoint m_bitmapSize;
311
312 #if wxUSE_STATUSBAR
313 /// A frame's statusbar to update
314 class wxStatusBar *m_StatusBar;
315 #endif // wxUSE_STATUSBAR
316
317 /// statusbar field for labels
318 int m_StatusFieldLabel;
319
320 /// statusbar field for cursor positions
321 int m_StatusFieldCursor;
322
323 /// a pointer to a bitmap for the background
324 wxBitmap *m_BGbitmap;
325
326 /**@name Some configuration options */
327 //@{
328 /// Do we want to auto-replace the selection with new text?
329 bool m_AutoDeleteSelection;
330
331 #ifndef __WXMSW__
332 /// Do we want the focus to follow the mouse?
333 bool m_FocusFollowMode;
334 #endif
335 /// For finding text and finding it again:
336 wxString m_FindString;
337 //@}
338
339 DECLARE_EVENT_TABLE()
340 };
341
342 #endif