]> git.saurik.com Git - wxWidgets.git/blob - samples/richedit/wxlwindow.h
Added missing initialisation of m_AutoDeleteSelection.
[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 (Ballueder@usa.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 #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_LUP,
43 WXLOWIN_MENU_MOUSEMOVE,
44 WXLOWIN_MENU_LAST = WXLOWIN_MENU_MOUSEMOVE
45 };
46
47 /**
48 This class is a rich text editing widget.
49 */
50 class wxLayoutWindow : public wxScrolledWindow
51 {
52 public:
53 /** Constructor.
54 @param parent parent window to display this panel in
55 */
56 wxLayoutWindow(wxWindow *parent);
57
58 /// Destructor.
59 virtual ~wxLayoutWindow();
60
61 /**@name Editing functionality */
62 //@{
63 /// Clears the window and sets default parameters.
64 void Clear(int family = wxROMAN,
65 int size=12,
66 int style=wxNORMAL,
67 int weight=wxNORMAL,
68 int underline=0,
69 wxColour *fg=NULL,
70 wxColour *bg=NULL);
71
72 /// override base class virtual to also refresh the scrollbar position
73 virtual void Refresh(bool eraseBackground = TRUE,
74 const wxRect *rect = (const wxRect *)NULL);
75
76 /** Sets a background image, only used on screen, not on printouts.
77 @param bitmap a pointer to a wxBitmap or NULL to remove it
78 */
79 void SetBackgroundBitmap(wxBitmap *bitmap = NULL)
80 {
81 if(m_BGbitmap) delete m_BGbitmap;
82 m_BGbitmap = bitmap;
83 }
84 /// Enable or disable editing, i.e. processing of keystrokes.
85 void SetEditable(bool toggle) { m_Editable = 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 usePrimarySelection = FALSE);
99 /** Copies selection to clipboard.
100 @param invalidate used internally, see wxllist.h for details
101 */
102 bool Copy(bool invalidate = true);
103 /// Copies selection to clipboard and deletes it.
104 bool Cut(void);
105 //@}
106
107 bool Find(const wxString &needle,
108 wxPoint * fromWhere = NULL);
109
110 void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
111
112 /** Sets the wrap margin.
113 @param margin set this to 0 to disable it
114 */
115 void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
116
117 /** Redraws the window.
118 Internally, this stores the parameter and calls a refresh on
119 wxMSW, draws directly on wxGTK.
120 */
121 void DoPaint(const wxRect *updateRect = NULL);
122
123 /// if exact == false, assume 50% extra size for the future
124 void ResizeScrollbars(bool exact = false); // don't change this to true!
125
126 /// if the flag is true, we send events when user clicks on embedded objects
127 inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
128
129 /* Returns a pointer to the wxLayoutList object.
130 @return the list
131 */
132 wxLayoutList * GetLayoutList(void) { return m_llist; }
133
134 /**@name Callbacks */
135 //@{
136 void OnSize(wxSizeEvent &event);
137 void OnPaint(wxPaintEvent &event);
138 void OnChar(wxKeyEvent& event);
139 void OnKeyUp(wxKeyEvent& event);
140 void OnUpdateMenuUnderline(wxUpdateUIEvent& event);
141 void OnUpdateMenuBold(wxUpdateUIEvent& event);
142 void OnUpdateMenuItalic(wxUpdateUIEvent& event);
143 void OnMenu(wxCommandEvent& event);
144 void OnLeftMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LDOWN, event); }
145 void OnLeftMouseUp(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LUP, event); }
146 void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
147 void OnMiddleMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_MDOWN, event); }
148 void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
149 void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
150 void OnSetFocus(wxFocusEvent &ev);
151 void OnKillFocus(wxFocusEvent &ev);
152 //@}
153
154 /// Creates a wxMenu for use as a format popup.
155 static wxMenu * MakeFormatMenu(void);
156 /**@name Dirty flag handling for optimisations. */
157 //@{
158 /// Set dirty flag.
159 void SetDirty(void) { m_Dirty = true; }
160 /// Query whether window needs redrawing.
161 bool IsDirty(void) const { return m_Dirty; }
162 /// Reset dirty flag.
163 void ResetDirty(void) { m_Dirty = false; }
164 //@}
165 /// Redraws the window, used by DoPaint() or OnPaint().
166 void InternalPaint(const wxRect *updateRect);
167
168 /// Has list been modified/edited?
169 bool IsModified(void) const { return m_Modified; }
170 /// Mark list as modified or unchanged.
171 void SetModified(bool modified = true) { m_Modified = modified; }
172 /** Tell window to update a wxStatusBar with UserData labels and
173 cursor positions.
174 @param bar wxStatusBar pointer
175 @param labelfield field to use in statusbar for URLs/userdata labels, or -1 to disable
176 @param cursorfield field to use for cursor position, or -1 to disable
177 */
178 void SetStatusBar(class wxStatusBar *bar,
179 int labelfield = -1,
180 int cursorfield = -1)
181 {
182 m_StatusBar = bar; m_StatusFieldLabel = labelfield;
183 m_StatusFieldCursor = cursorfield;
184 }
185
186 protected:
187 /// generic function for mouse events processing
188 void OnMouse(int eventId, wxMouseEvent& event);
189 /// as the name says
190 void ScrollToCursor(void);
191 /// for sending events
192 wxWindow *m_Parent;
193 /// Shall we send events?
194 bool m_doSendEvents;
195 /// Where does the current view start?
196 int m_ViewStartX; int m_ViewStartY;
197 /// Do we currently have the focus?
198 bool m_HaveFocus;
199 /// do we handle clicks of the right mouse button?
200 bool m_DoPopupMenu;
201 /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
202 bool m_ScrollToCursor;
203 /// Do we currently have a non-standard cursor?
204 bool m_HandCursor;
205 /// the menu
206 wxMenu * m_PopupMenu;
207 /// for derived classes, set when mouse is clicked
208 wxPoint m_ClickPosition;
209 /// for scrollbar calculations:
210 int m_maxx;
211 int m_maxy;
212 int m_lineHeight;
213
214 /// do we have the corresponding scrollbar?
215 bool m_hasHScrollbar,
216 m_hasVScrollbar;
217
218 /** Visibility parameter for cursor. 0/1 as expected, -1: visible
219 on demand.
220 */
221 int m_CursorVisibility;
222
223 bool SetAutoDeleteSelection(bool enable = TRUE)
224 {
225 bool old = m_AutoDeleteSelection;
226 m_AutoDeleteSelection = enable;
227 return old;
228 }
229 private:
230 /// The layout list to be displayed.
231 wxLayoutList *m_llist;
232 /// Can user edit the window?
233 bool m_Editable;
234 /// Are we currently building a selection with the keyboard?
235 bool m_Selecting;
236 /// wrap margin
237 CoordType m_WrapMargin;
238 /// Is list dirty (for redraws, internal use)?
239 bool m_Dirty;
240 /// Has list been edited?
241 bool m_Modified;
242 wxMemoryDC *m_memDC;
243 wxBitmap *m_bitmap;
244 wxPoint m_bitmapSize;
245 /// A frame's statusbar to update
246 class wxStatusBar *m_StatusBar;
247 /// statusbar field for labels
248 int m_StatusFieldLabel;
249 /// statusbar field for cursor positions
250 int m_StatusFieldCursor;
251 /// a pointer to a bitmap for the background
252 wxBitmap *m_BGbitmap;
253 /**@name Some configuration options */
254 //@{
255 /// Do we want to auto-replace the selection with new text?
256 bool m_AutoDeleteSelection;
257 //@}
258 DECLARE_EVENT_TABLE()
259 };
260
261 #endif