]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlwindow.h
e8cb71b4d8c75fb8231537655386fbcb823507b3
[wxWidgets.git] / user / wxLayout / 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 enum
26 {
27 WXLOWIN_MENU_LARGER = WXLOWIN_MENU_FIRST,
28 WXLOWIN_MENU_SMALLER,
29 WXLOWIN_MENU_UNDERLINE_ON,
30 WXLOWIN_MENU_UNDERLINE_OFF,
31 WXLOWIN_MENU_BOLD_ON,
32 WXLOWIN_MENU_BOLD_OFF,
33 WXLOWIN_MENU_ITALICS_ON,
34 WXLOWIN_MENU_ITALICS_OFF,
35 WXLOWIN_MENU_ROMAN,
36 WXLOWIN_MENU_TYPEWRITER,
37 WXLOWIN_MENU_SANSSERIF,
38 WXLOWIN_MENU_RCLICK,
39 WXLOWIN_MENU_LCLICK,
40 WXLOWIN_MENU_DBLCLICK,
41 WXLOWIN_MENU_MOUSEMOVE,
42 WXLOWIN_MENU_LAST = WXLOWIN_MENU_MOUSEMOVE
43 };
44
45 /**
46 This class is a rich text editing widget.
47 */
48 class wxLayoutWindow : public wxScrolledWindow
49 {
50 public:
51 /** Constructor.
52 @param parent parent window to display this panel in
53 */
54 wxLayoutWindow(wxWindow *parent);
55
56 /// Destructor.
57 virtual ~wxLayoutWindow();
58
59 /**@name Editing functionality */
60 //@{
61 /// Clears the window and sets default parameters.
62 void Clear(int family = wxROMAN,
63 int size=12,
64 int style=wxNORMAL,
65 int weight=wxNORMAL,
66 int underline=0,
67 wxColour *fg=NULL,
68 wxColour *bg=NULL)
69 {
70 GetLayoutList()->Clear(family,size,style,weight,underline,fg,bg);
71 SetBackgroundColour(GetLayoutList()->GetDefaults()->GetBGColour());
72 ResizeScrollbars(true);
73 SetDirty();
74 SetModified(false);
75 wxRect r;
76 int w,h;
77 r.x = r.y = 0; GetSize(&w,&h);
78 r.width = w;
79 r.height = h;
80 DoPaint(&r);
81 }
82 /** Sets a background image, only used on screen, not on printouts.
83 @param bitmap a pointer to a wxBitmap or NULL to remove it
84 */
85 void SetBackgroundBitmap(wxBitmap *bitmap = NULL)
86 {
87 if(m_BGbitmap) delete m_BGbitmap;
88 m_BGbitmap = bitmap;
89 }
90 /// Enable or disable editing, i.e. processing of keystrokes.
91 void SetEditable(bool toggle) { m_Editable = toggle; }
92 /// Query whether list can be edited by user.
93 bool IsEditable(void) const { return m_Editable; }
94 /// Pastes text from clipboard.
95 void Paste(void);
96 /// Copies selection to clipboard.
97 bool Copy(void);
98
99 //@}
100
101 void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
102
103 /** Sets the wrap margin.
104 @param margin set this to 0 to disable it
105 */
106 void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
107
108 /** Redraws the window.
109 Internally, this stores the parameter and calls a refresh on
110 wxMSW, draws directly on wxGTK.
111 */
112 void DoPaint(const wxRect *updateRect);
113
114 #ifdef __WXMSW__
115 virtual long MSWGetDlgCode();
116 #endif //MSW
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 OnPaint(wxPaintEvent &event);
132 void OnChar(wxKeyEvent& event);
133 void OnKeyUp(wxKeyEvent& event);
134 void OnMenu(wxCommandEvent& event);
135 void OnLeftMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LCLICK, event); }
136 void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
137 void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
138 void OnMouseMove(wxMouseEvent &event) { OnMouse(WXLOWIN_MENU_MOUSEMOVE, event) ; }
139 void OnSetFocus(wxFocusEvent &ev);
140 void OnKillFocus(wxFocusEvent &ev);
141 //@}
142
143 /// Creates a wxMenu for use as a format popup.
144 static wxMenu * MakeFormatMenu(void);
145 /**@name Dirty flag handling for optimisations. */
146 //@{
147 /// Set dirty flag.
148 void SetDirty(void) { m_Dirty = true; }
149 /// Query whether window needs redrawing.
150 bool IsDirty(void) const { return m_Dirty; }
151 /// Reset dirty flag.
152 void ResetDirty(void) { m_Dirty = false; }
153 //@}
154 /// Redraws the window, used by DoPaint() or OnPaint().
155 void InternalPaint(const wxRect *updateRect);
156
157 /// Has list been modified/edited?
158 bool IsModified(void) const { return m_Modified; }
159 /// Mark list as modified or unchanged.
160 void SetModified(bool modified = true) { m_Modified = modified; }
161
162 protected:
163 /// generic function for mouse events processing
164 void OnMouse(int eventId, wxMouseEvent& event);
165 /// as the name says
166 void ScrollToCursor(void);
167 /// for sending events
168 wxWindow *m_Parent;
169 /// Shall we send events?
170 bool m_doSendEvents;
171 /// Where does the current view start?
172 int m_ViewStartX; int m_ViewStartY;
173 /// Do we currently have the focus?
174 bool m_HaveFocus;
175 /// do we handle clicks of the right mouse button?
176 bool m_DoPopupMenu;
177 /// Should InternalPaint() scroll to cursor.
178 bool m_ScrollToCursor;
179 /// Do we currently have a non-standard cursor?
180 bool m_HandCursor;
181 /// the menu
182 wxMenu * m_PopupMenu;
183 /// for derived classes, set when mouse is clicked
184 wxPoint m_ClickPosition;
185 /// for scrollbar calculations:
186 int m_maxx;
187 int m_maxy;
188 int m_lineHeight;
189 private:
190 /// The layout list to be displayed.
191 wxLayoutList *m_llist;
192 /// Can user edit the window?
193 bool m_Editable;
194 /// Are we currently building a selection with the keyboard?
195 bool m_Selecting;
196 /// wrap margin
197 CoordType m_WrapMargin;
198 /// Is list dirty (for redraws, internal use)?
199 bool m_Dirty;
200 /// Has list been edited?
201 bool m_Modified;
202 wxMemoryDC *m_memDC;
203 wxBitmap *m_bitmap;
204 wxPoint m_bitmapSize;
205 /// a pointer to a bitmap for the background
206 wxBitmap *m_BGbitmap;
207 DECLARE_EVENT_TABLE()
208 };
209
210 #endif