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