]> git.saurik.com Git - wxWidgets.git/blob - samples/richedit/wxlwindow.h
rtf cut&paste works now, html export fixed
[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 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 /// Enable or disable editing, i.e. processing of keystrokes.
84 void SetEditable(bool toggle)
85 { m_Editable = toggle; SetCursorVisibility(toggle); }
86 /// Query whether list can be edited by user.
87 bool IsEditable(void) const { return m_Editable; }
88 /** Sets cursor visibility, visible=1, invisible=0,
89 visible-on-demand=-1, to hide it until moved.
90 @param visibility -1,0 or 1
91 @return the old visibility
92 */
93 inline int SetCursorVisibility(int visibility = -1)
94 { int v =m_CursorVisibility;
95 m_CursorVisibility = visibility; return v;}
96
97 /// Pastes text from clipboard.
98 void Paste(bool privateFormat = FALSE, bool usePrimarySelection = FALSE);
99 /** Copies selection to clipboard.
100 @param invalidate used internally, see wxllist.h for details
101 */
102 bool Copy(bool invalidate = true, bool privateFormat = FALSE, bool primary = FALSE);
103 /// Copies selection to clipboard and deletes it.
104 bool Cut(bool privateFormat = FALSE, bool usePrimary = FALSE);
105 //@}
106
107 /// find string in buffer
108 bool Find(const wxString &needle,
109 wxPoint * fromWhere = NULL,
110 const wxString &configPath = "MsgViewFindString");
111 /// find the same string again
112 bool FindAgain(void);
113
114 void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
115
116 /** Sets the wrap margin.
117 @param margin set this to 0 to disable it
118 */
119 void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
120
121 /** Redraws the window.
122 Internally, this stores the parameter and calls a refresh on
123 wxMSW, draws directly on wxGTK.
124 */
125 void RequestUpdate(const wxRect *updateRect = NULL);
126
127 /// if exact == false, assume 50% extra size for the future
128 void ResizeScrollbars(bool exact = false); // don't change this to true!
129
130 /// if the flag is true, we send events when user clicks on embedded objects
131 inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
132
133 /* Returns a pointer to the wxLayoutList object.
134 @return the list
135 */
136 wxLayoutList * GetLayoutList(void) { return m_llist; }
137
138 /**@name Callbacks */
139 //@{
140 void OnSize(wxSizeEvent &event);
141 void OnPaint(wxPaintEvent &event);
142 void OnChar(wxKeyEvent& event);
143 void OnKeyUp(wxKeyEvent& event);
144 void OnUpdateMenuUnderline(wxUpdateUIEvent& event);
145 void OnUpdateMenuBold(wxUpdateUIEvent& event);
146 void OnUpdateMenuItalic(wxUpdateUIEvent& event);
147 void OnMenu(wxCommandEvent& event);
148 void OnLeftMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LDOWN, event); }
149 void OnLeftMouseUp(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LUP, event); }
150 void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
151 void OnMiddleMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_MDOWN, event); }
152 void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
153 void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
154 void OnSetFocus(wxFocusEvent &ev);
155 void OnKillFocus(wxFocusEvent &ev);
156 //@}
157
158 /// Creates a wxMenu for use as a format popup.
159 static wxMenu * MakeFormatMenu(void);
160 /// Redraws the window, used by RequestUpdate() or OnPaint().
161 void InternalPaint(const wxRect *updateRect);
162
163 /** Tell window to update a wxStatusBar with UserData labels and
164 cursor positions.
165 @param bar wxStatusBar pointer
166 @param labelfield field to use in statusbar for URLs/userdata labels, or -1 to disable
167 @param cursorfield field to use for cursor position, or -1 to disable
168 */
169 void SetStatusBar(class wxStatusBar *bar,
170 int labelfield = -1,
171 int cursorfield = -1)
172 {
173 m_StatusBar = bar; m_StatusFieldLabel = labelfield;
174 m_StatusFieldCursor = cursorfield;
175 }
176 #ifndef __WXMSW__
177 /// Enable or disable focus follow mode under non-MSW
178 void SetFocusFollowMode(bool enable = TRUE)
179 { m_FocusFollowMode = enable; }
180 #endif
181
182 /**@name Modified flag handling, will not get reset by list unless
183 in Clear() */
184 //@{
185 /// Set dirty flag.
186 void SetModified(bool modified = TRUE) { m_Modified = modified; }
187 /// Query whether window needs redrawing.
188 bool IsModified(void) const { return m_Modified; }
189 //@}
190
191 /**@name Dirty flag handling for optimisations.
192 Normally one should only need to call SetDirty(), e.g. when
193 manipulating the wxLayoutList directly, so the window will update
194 itself. ResetDirty() and IsDirty() should only be used
195 internally. */
196 //@{
197 /// Set dirty flag.
198 void SetDirty(void) { m_Dirty = true; m_Modified = true; }
199 /// Query whether window needs redrawing.
200 bool IsDirty(void) const { return m_Dirty; }
201 /// Reset dirty flag.
202 void ResetDirty(void) { m_Dirty = false; }
203 //@}
204
205
206 protected:
207 /// generic function for mouse events processing
208 void OnMouse(int eventId, wxMouseEvent& event);
209 /// as the name says
210 void ScrollToCursor(void);
211 /// for sending events
212 wxWindow *m_Parent;
213 /// Shall we send events?
214 bool m_doSendEvents;
215 /// Where does the current view start?
216 int m_ViewStartX; int m_ViewStartY;
217 /// Do we currently have the focus?
218 bool m_HaveFocus;
219 /// do we handle clicks of the right mouse button?
220 bool m_DoPopupMenu;
221 /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
222 bool m_ScrollToCursor;
223 /// Do we currently have a non-standard cursor?
224 bool m_HandCursor;
225 /// the menu
226 wxMenu * m_PopupMenu;
227 /// for derived classes, set when mouse is clicked
228 wxPoint m_ClickPosition;
229 /// for scrollbar calculations:
230 int m_maxx;
231 int m_maxy;
232 int m_lineHeight;
233
234 /// do we have the corresponding scrollbar?
235 bool m_hasHScrollbar,
236 m_hasVScrollbar;
237
238 /** Visibility parameter for cursor. 0/1 as expected, -1: visible
239 on demand.
240 */
241 int m_CursorVisibility;
242
243 bool SetAutoDeleteSelection(bool enable = TRUE)
244 {
245 bool old = m_AutoDeleteSelection;
246 m_AutoDeleteSelection = enable;
247 return old;
248 }
249 private:
250 /// The layout list to be displayed.
251 wxLayoutList *m_llist;
252 /// Can user edit the window?
253 bool m_Editable;
254 /// Are we currently building a selection with the keyboard?
255 bool m_Selecting;
256 /// wrap margin
257 CoordType m_WrapMargin;
258 /// Has list changed since last redraw, e.g. in size?
259 bool m_Dirty;
260 /// Has the list ever been modified?
261 bool m_Modified;
262 wxMemoryDC *m_memDC;
263 wxBitmap *m_bitmap;
264 wxPoint m_bitmapSize;
265 /// A frame's statusbar to update
266 class wxStatusBar *m_StatusBar;
267 /// statusbar field for labels
268 int m_StatusFieldLabel;
269 /// statusbar field for cursor positions
270 int m_StatusFieldCursor;
271 /// a pointer to a bitmap for the background
272 wxBitmap *m_BGbitmap;
273 /**@name Some configuration options */
274 //@{
275 /// Do we want to auto-replace the selection with new text?
276 bool m_AutoDeleteSelection;
277 #ifndef __WXMSW__
278 /// Do we want the focus to follow the mouse?
279 bool m_FocusFollowMode;
280 #endif
281 /// For finding text and finding it again:
282 wxString m_FindString;
283 //@}
284 DECLARE_EVENT_TABLE()
285 };
286
287 #endif