]>
git.saurik.com Git - wxWidgets.git/blob - samples/richedit/wxlwindow.h
8958e62fab72b712c575a929d6e2e3c87a50a8af
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
,
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
;
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
93 inline int SetCursorVisibility(int visibility
= -1)
94 { int v
=m_CursorVisibility
;
95 m_CursorVisibility
= visibility
; return v
;}
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
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
);
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);
114 void EnablePopup(bool enable
= true) { m_DoPopupMenu
= enable
; }
116 /** Sets the wrap margin.
117 @param margin set this to 0 to disable it
119 void SetWrapMargin(CoordType margin
) { m_WrapMargin
= margin
; }
121 /** Toggle wordwrap as we type.
122 @param on true to activate word wrap
124 void SetWordWrap(bool on
= true) { m_DoWordWrap
= on
; }
126 /** Redraws the window.
127 Internally, this stores the parameter and calls a refresh on
128 wxMSW, draws directly on wxGTK.
130 void RequestUpdate(const wxRect
*updateRect
= NULL
);
132 /// if exact == false, assume 50% extra size for the future
133 void ResizeScrollbars(bool exact
= false); // don't change this to true!
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
; }
138 /* Returns a pointer to the wxLayoutList object.
141 wxLayoutList
* GetLayoutList(void) { return m_llist
; }
143 /**@name Callbacks */
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
);
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
);
168 /** Tell window to update a wxStatusBar with UserData labels and
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
174 void SetStatusBar(class wxStatusBar
*bar
,
176 int cursorfield
= -1)
178 m_StatusBar
= bar
; m_StatusFieldLabel
= labelfield
;
179 m_StatusFieldCursor
= cursorfield
;
182 /// Enable or disable focus follow mode under non-MSW
183 void SetFocusFollowMode(bool enable
= TRUE
)
184 { m_FocusFollowMode
= enable
; }
187 /**@name Modified flag handling, will not get reset by list unless
191 void SetModified(bool modified
= TRUE
) { m_Modified
= modified
; }
192 /// Query whether window needs redrawing.
193 bool IsModified(void) const { return m_Modified
; }
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
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; }
212 /// generic function for mouse events processing
213 void OnMouse(int eventId
, wxMouseEvent
& event
);
215 void ScrollToCursor(void);
216 /// for sending events
218 /// Shall we send events?
220 /// Where does the current view start?
221 int m_ViewStartX
; int m_ViewStartY
;
222 /// Do we currently have the focus?
224 /// do we handle clicks of the right mouse button?
226 /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
227 bool m_ScrollToCursor
;
228 /// Do we currently have a non-standard cursor?
231 wxMenu
* m_PopupMenu
;
232 /// for derived classes, set when mouse is clicked
233 wxPoint m_ClickPosition
;
234 /// for scrollbar calculations:
238 /// do we want automatic word wrap?
241 CoordType m_WrapMargin
;
243 /// do we have the corresponding scrollbar?
244 bool m_hasHScrollbar
,
247 /** Visibility parameter for cursor. 0/1 as expected, -1: visible
250 int m_CursorVisibility
;
252 bool SetAutoDeleteSelection(bool enable
= TRUE
)
254 bool old
= m_AutoDeleteSelection
;
255 m_AutoDeleteSelection
= enable
;
259 /// The layout list to be displayed.
260 wxLayoutList
*m_llist
;
261 /// Can user edit the window?
263 /// Are we currently building a selection with the keyboard?
265 /// Has list changed since last redraw, e.g. in size?
267 /// Has the list ever been modified?
271 wxPoint m_bitmapSize
;
272 /// A frame's statusbar to update
273 class wxStatusBar
*m_StatusBar
;
274 /// statusbar field for labels
275 int m_StatusFieldLabel
;
276 /// statusbar field for cursor positions
277 int m_StatusFieldCursor
;
278 /// a pointer to a bitmap for the background
279 wxBitmap
*m_BGbitmap
;
280 /**@name Some configuration options */
282 /// Do we want to auto-replace the selection with new text?
283 bool m_AutoDeleteSelection
;
285 /// Do we want the focus to follow the mouse?
286 bool m_FocusFollowMode
;
288 /// For finding text and finding it again:
289 wxString m_FindString
;
291 DECLARE_EVENT_TABLE()