]>
git.saurik.com Git - wxWidgets.git/blob - samples/richedit/wxlwindow.h
8733d7a6cac3dab033b67271273dc54f73dbe15d
1 /*-*- c++ -*-********************************************************
2 * wxLwindow.h : a scrolled Window for displaying/entering rich text*
4 * (C) 1998-2000 by Karsten Ballüder (ballueder@gmx.net) *
7 *******************************************************************/
12 # pragma interface "wxlwindow.h"
21 #ifndef WXLOWIN_MENU_FIRST
22 # define WXLOWIN_MENU_FIRST 12000
28 WXLOWIN_MENU_LARGER
= WXLOWIN_MENU_FIRST
,
30 WXLOWIN_MENU_UNDERLINE
,
34 WXLOWIN_MENU_TYPEWRITER
,
35 WXLOWIN_MENU_SANSSERIF
,
37 WXLOWIN_MENU_DBLCLICK
,
40 WXLOWIN_MENU_LCLICK
= WXLOWIN_MENU_LDOWN
,
42 WXLOWIN_MENU_MOUSEMOVE
,
43 WXLOWIN_MENU_LAST
= WXLOWIN_MENU_MOUSEMOVE
47 This class is a rich text editing widget.
49 class wxLayoutWindow
: public wxScrolledWindow
53 @param parent parent window to display this panel in
55 wxLayoutWindow(wxWindow
*parent
);
58 virtual ~wxLayoutWindow();
60 /**@name Editing functionality */
62 /// Clears the window and sets default parameters.
63 void Clear(int family
= wxROMAN
,
66 int weight
= wxNORMAL
,
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
);
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
78 void SetBackgroundBitmap(wxBitmap
*bitmap
= NULL
)
80 if(m_BGbitmap
) delete m_BGbitmap
;
84 /// Enable or disable editing, i.e. processing of keystrokes.
85 void SetEditable(bool toggle
)
88 SetCursorVisibility(toggle
);
91 /// Query whether list can be edited by user.
92 bool IsEditable() const { return m_Editable
; }
94 /** Sets cursor visibility, visible=1, invisible=0,
95 visible-on-demand=-1, to hide it until moved.
96 @param visibility -1,0 or 1
97 @return the old visibility
99 inline int SetCursorVisibility(int visibility
= -1)
101 int v
=m_CursorVisibility
;
102 m_CursorVisibility
= visibility
; return v
;
105 /// Pastes text from clipboard.
106 void Paste(bool privateFormat
= false, bool usePrimarySelection
= false);
108 /** Copies selection to clipboard.
109 @param invalidate used internally, see wxllist.h for details
111 bool Copy(bool invalidate
= true, bool privateFormat
= false, bool primary
= false);
113 /// Copies selection to clipboard and deletes it.
114 bool Cut(bool privateFormat
= false, bool usePrimary
= false);
117 /// find string in buffer
118 bool Find(const wxString
&needle
,
119 wxPoint
* fromWhere
= NULL
,
120 const wxString
&configPath
= _T("MsgViewFindString"));
122 /// find the same string again
125 void EnablePopup(bool enable
= true) { m_DoPopupMenu
= enable
; }
127 /** Sets the wrap margin.
128 @param margin set this to 0 to disable it
130 void SetWrapMargin(CoordType margin
) { m_WrapMargin
= margin
; }
132 /** Toggle wordwrap as we type.
133 @param on true to activate word wrap
135 void SetWordWrap(bool on
= true) { m_DoWordWrap
= on
; }
137 /** Redraws the window.
138 Internally, this stores the parameter and calls a refresh on
139 wxMSW, draws directly on wxGTK.
141 void RequestUpdate(const wxRect
*updateRect
= NULL
);
143 /// if exact == false, assume 50% extra size for the future
144 void ResizeScrollbars(bool exact
= false); // don't change this to true!
146 /// if the flag is true, we send events when user clicks on embedded objects
147 inline void SetMouseTracking(bool doIt
= true) { m_doSendEvents
= doIt
; }
149 /** Returns a pointer to the wxLayoutList object.
152 wxLayoutList
* GetLayoutList() { return m_llist
; }
154 /**@name Callbacks */
156 void OnSize(wxSizeEvent
&event
);
157 void OnPaint(wxPaintEvent
&event
);
158 void OnChar(wxKeyEvent
& event
);
159 void OnKeyUp(wxKeyEvent
& event
);
160 void OnUpdateMenuUnderline(wxUpdateUIEvent
& event
);
161 void OnUpdateMenuBold(wxUpdateUIEvent
& event
);
162 void OnUpdateMenuItalic(wxUpdateUIEvent
& event
);
163 void OnMenu(wxCommandEvent
& event
);
164 void OnLeftMouseDown(wxMouseEvent
& event
) { OnMouse(WXLOWIN_MENU_LDOWN
, event
); }
165 void OnLeftMouseUp(wxMouseEvent
& event
) { OnMouse(WXLOWIN_MENU_LUP
, event
); }
166 void OnRightMouseClick(wxMouseEvent
& event
) { OnMouse(WXLOWIN_MENU_RCLICK
, event
); }
167 void OnMiddleMouseDown(wxMouseEvent
& event
) { OnMouse(WXLOWIN_MENU_MDOWN
, event
); }
168 void OnMouseDblClick(wxMouseEvent
& event
) { OnMouse(WXLOWIN_MENU_DBLCLICK
, event
); }
169 void OnMouseMove(wxMouseEvent
&event
) { OnMouse(WXLOWIN_MENU_MOUSEMOVE
, event
) ; }
170 void OnSetFocus(wxFocusEvent
&ev
);
171 void OnKillFocus(wxFocusEvent
&ev
);
174 /// Creates a wxMenu for use as a format popup.
175 static wxMenu
* MakeFormatMenu();
177 /// Redraws the window, used by RequestUpdate() or OnPaint().
178 void InternalPaint(const wxRect
*updateRect
);
180 /** Tell window to update a wxStatusBar with UserData labels and
182 @param bar wxStatusBar pointer
183 @param labelfield field to use in statusbar for URLs/userdata labels, or -1 to disable
184 @param cursorfield field to use for cursor position, or -1 to disable
186 void SetStatusBar(class wxStatusBar
*bar
,
188 int cursorfield
= -1)
190 m_StatusBar
= bar
; m_StatusFieldLabel
= labelfield
;
191 m_StatusFieldCursor
= cursorfield
;
195 /// Enable or disable focus follow mode under non-MSW
196 void SetFocusFollowMode(bool enable
= true)
198 m_FocusFollowMode
= enable
;
202 /** @name Modified flag handling, will not get reset by list unless
206 void SetModified(bool modified
= true) { m_Modified
= modified
; }
208 /// Query whether window needs redrawing.
209 bool IsModified() const { return m_Modified
; }
213 @name Dirty flag handling for optimisations.
214 Normally one should only need to call SetDirty(), e.g. when
215 manipulating the wxLayoutList directly, so the window will update
216 itself. ResetDirty() and IsDirty() should only be used
220 void SetDirty() { m_Dirty
= true; m_Modified
= true; }
222 /// Query whether window needs redrawing.
223 bool IsDirty() const { return m_Dirty
; }
225 /// Reset dirty flag.
226 void ResetDirty() { m_Dirty
= false; }
231 /// generic function for mouse events processing
232 void OnMouse(int eventId
, wxMouseEvent
& event
);
235 void ScrollToCursor();
237 /// for sending events
240 /// Shall we send events?
243 /// Where does the current view start?
244 int m_ViewStartX
; int m_ViewStartY
;
246 /// Do we currently have the focus?
249 /// do we handle clicks of the right mouse button?
252 /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
253 bool m_ScrollToCursor
;
255 /// Do we currently have a non-standard cursor?
259 wxMenu
* m_PopupMenu
;
261 /// for derived classes, set when mouse is clicked
262 wxPoint m_ClickPosition
;
264 /// for scrollbar calculations:
269 /// do we want automatic word wrap?
273 CoordType m_WrapMargin
;
275 /// do we have the corresponding scrollbar?
276 bool m_hasHScrollbar
,
279 /** Visibility parameter for cursor. 0/1 as expected, -1: visible
282 int m_CursorVisibility
;
284 bool SetAutoDeleteSelection(bool enable
= true)
286 bool old
= m_AutoDeleteSelection
;
287 m_AutoDeleteSelection
= enable
;
291 /// The layout list to be displayed.
292 wxLayoutList
*m_llist
;
294 /// Can user edit the window?
297 /// Are we currently building a selection with the keyboard?
300 /// Has list changed since last redraw, e.g. in size?
303 /// Has the list ever been modified?
308 wxPoint m_bitmapSize
;
310 /// A frame's statusbar to update
311 class wxStatusBar
*m_StatusBar
;
313 /// statusbar field for labels
314 int m_StatusFieldLabel
;
316 /// statusbar field for cursor positions
317 int m_StatusFieldCursor
;
319 /// a pointer to a bitmap for the background
320 wxBitmap
*m_BGbitmap
;
322 /**@name Some configuration options */
324 /// Do we want to auto-replace the selection with new text?
325 bool m_AutoDeleteSelection
;
328 /// Do we want the focus to follow the mouse?
329 bool m_FocusFollowMode
;
331 /// For finding text and finding it again:
332 wxString m_FindString
;
335 DECLARE_EVENT_TABLE()