]> git.saurik.com Git - wxWidgets.git/blob - samples/richedit/wxlwindow.h
Corrected link error for missing wxRegTipProvider::GetTip by giving it
[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_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 bool Find(const wxString &needle,
110 wxPoint * fromWhere = NULL);
111
112 void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
113
114 /** Sets the wrap margin.
115 @param margin set this to 0 to disable it
116 */
117 void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
118
119 /** Redraws the window.
120 Internally, this stores the parameter and calls a refresh on
121 wxMSW, draws directly on wxGTK.
122 */
123 void DoPaint(const wxRect *updateRect = NULL);
124
125 /// if exact == false, assume 50% extra size for the future
126 void ResizeScrollbars(bool exact = false); // don't change this to true!
127
128 /// if the flag is true, we send events when user clicks on embedded objects
129 inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
130
131 /* Returns a pointer to the wxLayoutList object.
132 @return the list
133 */
134 wxLayoutList * GetLayoutList(void) { return m_llist; }
135
136 /**@name Callbacks */
137 //@{
138 void OnSize(wxSizeEvent &event);
139 void OnPaint(wxPaintEvent &event);
140 void OnChar(wxKeyEvent& event);
141 void OnKeyUp(wxKeyEvent& event);
142 void OnUpdateMenuUnderline(wxUpdateUIEvent& event);
143 void OnUpdateMenuBold(wxUpdateUIEvent& event);
144 void OnUpdateMenuItalic(wxUpdateUIEvent& event);
145 void OnMenu(wxCommandEvent& event);
146 void OnLeftMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LDOWN, event); }
147 void OnLeftMouseUp(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LUP, event); }
148 void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
149 void OnMiddleMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_MDOWN, event); }
150 void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
151 void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
152 void OnSetFocus(wxFocusEvent &ev);
153 void OnKillFocus(wxFocusEvent &ev);
154 //@}
155
156 /// Creates a wxMenu for use as a format popup.
157 static wxMenu * MakeFormatMenu(void);
158 /**@name Dirty flag handling for optimisations. */
159 //@{
160 /// Set dirty flag.
161 void SetDirty(void) { m_Dirty = true; }
162 /// Query whether window needs redrawing.
163 bool IsDirty(void) const { return m_Dirty; }
164 /// Reset dirty flag.
165 void ResetDirty(void) { m_Dirty = false; }
166 //@}
167 /// Redraws the window, used by DoPaint() or OnPaint().
168 void InternalPaint(const wxRect *updateRect);
169
170 /// Has list been modified/edited?
171 bool IsModified(void) const { return m_Modified; }
172 /// Mark list as modified or unchanged.
173 void SetModified(bool modified = true) { m_Modified = modified; }
174 /** Tell window to update a wxStatusBar with UserData labels and
175 cursor positions.
176 @param bar wxStatusBar pointer
177 @param labelfield field to use in statusbar for URLs/userdata labels, or -1 to disable
178 @param cursorfield field to use for cursor position, or -1 to disable
179 */
180 void SetStatusBar(class wxStatusBar *bar,
181 int labelfield = -1,
182 int cursorfield = -1)
183 {
184 m_StatusBar = bar; m_StatusFieldLabel = labelfield;
185 m_StatusFieldCursor = cursorfield;
186 }
187
188 protected:
189 /// generic function for mouse events processing
190 void OnMouse(int eventId, wxMouseEvent& event);
191 /// as the name says
192 void ScrollToCursor(void);
193 /// for sending events
194 wxWindow *m_Parent;
195 /// Shall we send events?
196 bool m_doSendEvents;
197 /// Where does the current view start?
198 int m_ViewStartX; int m_ViewStartY;
199 /// Do we currently have the focus?
200 bool m_HaveFocus;
201 /// do we handle clicks of the right mouse button?
202 bool m_DoPopupMenu;
203 /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
204 bool m_ScrollToCursor;
205 /// Do we currently have a non-standard cursor?
206 bool m_HandCursor;
207 /// the menu
208 wxMenu * m_PopupMenu;
209 /// for derived classes, set when mouse is clicked
210 wxPoint m_ClickPosition;
211 /// for scrollbar calculations:
212 int m_maxx;
213 int m_maxy;
214 int m_lineHeight;
215
216 /// do we have the corresponding scrollbar?
217 bool m_hasHScrollbar,
218 m_hasVScrollbar;
219
220 /** Visibility parameter for cursor. 0/1 as expected, -1: visible
221 on demand.
222 */
223 int m_CursorVisibility;
224
225 bool SetAutoDeleteSelection(bool enable = TRUE)
226 {
227 bool old = m_AutoDeleteSelection;
228 m_AutoDeleteSelection = enable;
229 return old;
230 }
231 private:
232 /// The layout list to be displayed.
233 wxLayoutList *m_llist;
234 /// Can user edit the window?
235 bool m_Editable;
236 /// Are we currently building a selection with the keyboard?
237 bool m_Selecting;
238 /// wrap margin
239 CoordType m_WrapMargin;
240 /// Is list dirty (for redraws, internal use)?
241 bool m_Dirty;
242 /// Has list been edited?
243 bool m_Modified;
244 wxMemoryDC *m_memDC;
245 wxBitmap *m_bitmap;
246 wxPoint m_bitmapSize;
247 /// A frame's statusbar to update
248 class wxStatusBar *m_StatusBar;
249 /// statusbar field for labels
250 int m_StatusFieldLabel;
251 /// statusbar field for cursor positions
252 int m_StatusFieldCursor;
253 /// a pointer to a bitmap for the background
254 wxBitmap *m_BGbitmap;
255 /**@name Some configuration options */
256 //@{
257 /// Do we want to auto-replace the selection with new text?
258 bool m_AutoDeleteSelection;
259 //@}
260 DECLARE_EVENT_TABLE()
261 };
262
263 #endif