]> git.saurik.com Git - wxWidgets.git/blob - samples/richedit/wxlwindow.h
3bbaf90d4369c16981166a781b27b65668549af6
[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 1
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_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 /** Sets a background image, only used on screen, not on printouts.
71 @param bitmap a pointer to a wxBitmap or NULL to remove it
72 */
73 void SetBackgroundBitmap(wxBitmap *bitmap = NULL)
74 {
75 if(m_BGbitmap) delete m_BGbitmap;
76 m_BGbitmap = bitmap;
77 }
78 /// Enable or disable editing, i.e. processing of keystrokes.
79 void SetEditable(bool toggle) { m_Editable = toggle; }
80 /// Query whether list can be edited by user.
81 bool IsEditable(void) const { return m_Editable; }
82 /** Sets cursor visibility, visible=1, invisible=0,
83 visible-on-demand=-1, to hide it until moved.
84 @param visibility -1,0 or 1
85 @return the old visibility
86 */
87 inline int SetCursorVisibility(int visibility = -1)
88 { int v =m_CursorVisibility;
89 m_CursorVisibility = visibility; return v;}
90
91 /// Pastes text from clipboard.
92 void Paste(void);
93 /** Copies selection to clipboard.
94 @param invalidate used internally, see wxllist.h for details
95 */
96 bool Copy(bool invalidate = true);
97 /// Copies selection to clipboard and deletes it.
98 bool Cut(void);
99 //@}
100
101 bool Find(const wxString &needle,
102 wxPoint * fromWhere = NULL);
103
104 void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
105
106 /** Sets the wrap margin.
107 @param margin set this to 0 to disable it
108 */
109 void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
110
111 /** Redraws the window.
112 Internally, this stores the parameter and calls a refresh on
113 wxMSW, draws directly on wxGTK.
114 */
115 void DoPaint(const wxRect *updateRect = NULL);
116
117 /// if exact == false, assume 50% extra size for the future
118 void ResizeScrollbars(bool exact = false); // don't change this to true!
119
120 /// if the flag is true, we send events when user clicks on embedded objects
121 inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
122
123 /* Returns a pointer to the wxLayoutList object.
124 @return the list
125 */
126 wxLayoutList * GetLayoutList(void) { return m_llist; }
127
128 /**@name Callbacks */
129 //@{
130 void OnPaint(wxPaintEvent &event);
131 void OnChar(wxKeyEvent& event);
132 void OnKeyUp(wxKeyEvent& event);
133 void OnUpdateMenuUnderline(wxUpdateUIEvent& event);
134 void OnUpdateMenuBold(wxUpdateUIEvent& event);
135 void OnUpdateMenuItalic(wxUpdateUIEvent& event);
136 void OnMenu(wxCommandEvent& event);
137 void OnLeftMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LDOWN, event); }
138 void OnLeftMouseUp(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LUP, event); }
139 void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
140 void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
141 void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
142 void OnSetFocus(wxFocusEvent &ev);
143 void OnKillFocus(wxFocusEvent &ev);
144 //@}
145
146 /// Creates a wxMenu for use as a format popup.
147 static wxMenu * MakeFormatMenu(void);
148 /**@name Dirty flag handling for optimisations. */
149 //@{
150 /// Set dirty flag.
151 void SetDirty(void) { m_Dirty = true; }
152 /// Query whether window needs redrawing.
153 bool IsDirty(void) const { return m_Dirty; }
154 /// Reset dirty flag.
155 void ResetDirty(void) { m_Dirty = false; }
156 //@}
157 /// Redraws the window, used by DoPaint() or OnPaint().
158 void InternalPaint(const wxRect *updateRect);
159
160 /// Has list been modified/edited?
161 bool IsModified(void) const { return m_Modified; }
162 /// Mark list as modified or unchanged.
163 void SetModified(bool modified = true) { m_Modified = modified; }
164 /** Tell window to update a wxStatusBar with UserData labels and
165 cursor positions.
166 @param bar wxStatusBar pointer
167 @param labelfield field to use in statusbar for URLs/userdata labels, or -1 to disable
168 @param cursorfield field to use for cursor position, or -1 to disable
169 */
170 void SetStatusBar(class wxStatusBar *bar,
171 int labelfield = -1,
172 int cursorfield = -1)
173 {
174 m_StatusBar = bar; m_StatusFieldLabel = labelfield;
175 m_StatusFieldCursor = cursorfield;
176 }
177
178 protected:
179 /// generic function for mouse events processing
180 void OnMouse(int eventId, wxMouseEvent& event);
181 /// as the name says
182 void ScrollToCursor(void);
183 /// for sending events
184 wxWindow *m_Parent;
185 /// Shall we send events?
186 bool m_doSendEvents;
187 /// Where does the current view start?
188 int m_ViewStartX; int m_ViewStartY;
189 /// Do we currently have the focus?
190 bool m_HaveFocus;
191 /// do we handle clicks of the right mouse button?
192 bool m_DoPopupMenu;
193 /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
194 bool m_ScrollToCursor;
195 /// Do we currently have a non-standard cursor?
196 bool m_HandCursor;
197 /// the menu
198 wxMenu * m_PopupMenu;
199 /// for derived classes, set when mouse is clicked
200 wxPoint m_ClickPosition;
201 /// for scrollbar calculations:
202 int m_maxx;
203 int m_maxy;
204 int m_lineHeight;
205 /** Visibility parameter for cursor. 0/1 as expected, -1: visible
206 on demand.
207 */
208 int m_CursorVisibility;
209 private:
210 /// The layout list to be displayed.
211 wxLayoutList *m_llist;
212 /// Can user edit the window?
213 bool m_Editable;
214 /// Are we currently building a selection with the keyboard?
215 bool m_Selecting;
216 /// wrap margin
217 CoordType m_WrapMargin;
218 /// Is list dirty (for redraws, internal use)?
219 bool m_Dirty;
220 /// Has list been edited?
221 bool m_Modified;
222 wxMemoryDC *m_memDC;
223 wxBitmap *m_bitmap;
224 wxPoint m_bitmapSize;
225 /// A frame's statusbar to update
226 class wxStatusBar *m_StatusBar;
227 /// statusbar field for labels
228 int m_StatusFieldLabel;
229 /// statusbar field for cursor positions
230 int m_StatusFieldCursor;
231 /// a pointer to a bitmap for the background
232 wxBitmap *m_BGbitmap;
233 DECLARE_EVENT_TABLE()
234 };
235
236 #endif