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