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