]> git.saurik.com Git - wxWidgets.git/blob - samples/richedit/wxlwindow.h
e0ddabd6276a1ea5d491f5a219b2cdb5b4456350
[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 OnSize(wxSizeEvent &event);
131 void OnPaint(wxPaintEvent &event);
132 void OnChar(wxKeyEvent& event);
133 void OnKeyUp(wxKeyEvent& event);
134 void OnUpdateMenuUnderline(wxUpdateUIEvent& event);
135 void OnUpdateMenuBold(wxUpdateUIEvent& event);
136 void OnUpdateMenuItalic(wxUpdateUIEvent& event);
137 void OnMenu(wxCommandEvent& event);
138 void OnLeftMouseDown(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LDOWN, event); }
139 void OnLeftMouseUp(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LUP, event); }
140 void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
141 void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
142 void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
143 void OnSetFocus(wxFocusEvent &ev);
144 void OnKillFocus(wxFocusEvent &ev);
145 //@}
146
147 /// Creates a wxMenu for use as a format popup.
148 static wxMenu * MakeFormatMenu(void);
149 /**@name Dirty flag handling for optimisations. */
150 //@{
151 /// Set dirty flag.
152 void SetDirty(void) { m_Dirty = true; }
153 /// Query whether window needs redrawing.
154 bool IsDirty(void) const { return m_Dirty; }
155 /// Reset dirty flag.
156 void ResetDirty(void) { m_Dirty = false; }
157 //@}
158 /// Redraws the window, used by DoPaint() or OnPaint().
159 void InternalPaint(const wxRect *updateRect);
160
161 /// Has list been modified/edited?
162 bool IsModified(void) const { return m_Modified; }
163 /// Mark list as modified or unchanged.
164 void SetModified(bool modified = true) { m_Modified = modified; }
165 /** Tell window to update a wxStatusBar with UserData labels and
166 cursor positions.
167 @param bar wxStatusBar pointer
168 @param labelfield field to use in statusbar for URLs/userdata labels, or -1 to disable
169 @param cursorfield field to use for cursor position, or -1 to disable
170 */
171 void SetStatusBar(class wxStatusBar *bar,
172 int labelfield = -1,
173 int cursorfield = -1)
174 {
175 m_StatusBar = bar; m_StatusFieldLabel = labelfield;
176 m_StatusFieldCursor = cursorfield;
177 }
178
179 protected:
180 /// generic function for mouse events processing
181 void OnMouse(int eventId, wxMouseEvent& event);
182 /// as the name says
183 void ScrollToCursor(void);
184 /// for sending events
185 wxWindow *m_Parent;
186 /// Shall we send events?
187 bool m_doSendEvents;
188 /// Where does the current view start?
189 int m_ViewStartX; int m_ViewStartY;
190 /// Do we currently have the focus?
191 bool m_HaveFocus;
192 /// do we handle clicks of the right mouse button?
193 bool m_DoPopupMenu;
194 /// Should InternalPaint() scroll to cursor (VZ: seems unused any more)
195 bool m_ScrollToCursor;
196 /// Do we currently have a non-standard cursor?
197 bool m_HandCursor;
198 /// the menu
199 wxMenu * m_PopupMenu;
200 /// for derived classes, set when mouse is clicked
201 wxPoint m_ClickPosition;
202 /// for scrollbar calculations:
203 int m_maxx;
204 int m_maxy;
205 int m_lineHeight;
206
207 /// do we have the corresponding scrollbar?
208 bool m_hasHScrollbar,
209 m_hasVScrollbar;
210
211 /** Visibility parameter for cursor. 0/1 as expected, -1: visible
212 on demand.
213 */
214 int m_CursorVisibility;
215 private:
216 /// The layout list to be displayed.
217 wxLayoutList *m_llist;
218 /// Can user edit the window?
219 bool m_Editable;
220 /// Are we currently building a selection with the keyboard?
221 bool m_Selecting;
222 /// wrap margin
223 CoordType m_WrapMargin;
224 /// Is list dirty (for redraws, internal use)?
225 bool m_Dirty;
226 /// Has list been edited?
227 bool m_Modified;
228 wxMemoryDC *m_memDC;
229 wxBitmap *m_bitmap;
230 wxPoint m_bitmapSize;
231 /// A frame's statusbar to update
232 class wxStatusBar *m_StatusBar;
233 /// statusbar field for labels
234 int m_StatusFieldLabel;
235 /// statusbar field for cursor positions
236 int m_StatusFieldCursor;
237 /// a pointer to a bitmap for the background
238 wxBitmap *m_BGbitmap;
239 DECLARE_EVENT_TABLE()
240 };
241
242 #endif