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