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