]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlwindow.h
Added imaggif.h, imaggif.cpp (wxImage GIF-reading support); candidate
[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 char const *fg="black",
67 char const *bg="white")
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 DoPaint();
75 }
76 /** Sets a background image, only used on screen, not on printouts.
77 @param bitmap a pointer to a wxBitmap or NULL to remove it
78 */
79 void SetBackgroundBitmap(wxBitmap *bitmap = NULL)
80 {
81 if(m_BGbitmap) delete m_BGbitmap;
82 m_BGbitmap = bitmap;
83 }
84 /// Enable or disable editing, i.e. processing of keystrokes.
85 void SetEditable(bool toggle) { m_Editable = toggle; }
86 /// Query whether list can be edited by user.
87 bool IsEditable(void) const { return m_Editable; }
88 /// Pastes text from clipboard.
89 void Paste(void);
90
91 //@}
92
93 void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
94
95 /** Sets the wrap margin.
96 @param margin set this to 0 to disable it
97 */
98 void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
99
100 /** Redraws the window.
101 Internally, this stores the parameter and calls a refresh on
102 wxMSW, draws directly on wxGTK.
103 @param scrollToCursor if true, scroll the window so that the
104 cursor becomes visible
105 */
106 void DoPaint(bool scrollToCursor = false);
107
108 #ifdef __WXMSW__
109 virtual long MSWGetDlgCode();
110 #endif //MSW
111
112 /// if exact == false, assume 50% extra size for the future
113 void ResizeScrollbars(bool exact = false); // don't change this to true!
114
115 /// if the flag is true, we send events when user clicks on embedded objects
116 inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
117
118 /* Returns a pointer to the wxLayoutList object.
119 @return the list
120 */
121 wxLayoutList * GetLayoutList(void) { return m_llist; }
122
123 /**@name Callbacks */
124 //@{
125 void OnPaint(wxPaintEvent &event);
126 void OnChar(wxKeyEvent& event);
127 void OnMenu(wxCommandEvent& event);
128 void OnLeftMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LCLICK, event); }
129 void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
130 void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
131 void OnSetFocus(wxFocusEvent &ev);
132 void OnKillFocus(wxFocusEvent &ev);
133 //@}
134
135 /// Creates a wxMenu for use as a format popup.
136 static wxMenu * MakeFormatMenu(void);
137 /**@name Dirty flag handling for optimisations. */
138 //@{
139 /// Set dirty flag.
140 void SetDirty(void) { m_Dirty = true; }
141 /// Query whether window needs redrawing.
142 bool IsDirty(void) const { return m_Dirty; }
143 /// Reset dirty flag.
144 void ResetDirty(void) { m_Dirty = false; }
145 //@}
146 /// Redraws the window, used by DoPaint() or OnPaint().
147 void InternalPaint(void);
148
149 /// Has list been modified/edited?
150 bool IsModified(void) const { return m_Modified; }
151 /// Mark list as modified or unchanged.
152 void SetModified(bool modified = true) { m_Modified = modified; }
153
154 protected:
155 /// generic function for mouse events processing
156 void OnMouse(int eventId, wxMouseEvent& event);
157
158 /// for sending events
159 wxWindow *m_Parent;
160 /// Shall we send events?
161 bool m_doSendEvents;
162 /// Where does the current view start?
163 int m_ViewStartX; int m_ViewStartY;
164 /// Do we currently have the focus?
165 bool m_HaveFocus;
166 /// do we handle clicks of the right mouse button?
167 bool m_DoPopupMenu;
168 /// Should InternalPaint() scroll to cursor.
169 bool m_ScrollToCursor;
170 /// the menu
171 wxMenu * m_PopupMenu;
172 /// for derived classes, set when mouse is clicked
173 wxPoint m_ClickPosition;
174 /// for scrollbar calculations:
175 int m_maxx;
176 int m_maxy;
177 int m_lineHeight;
178 private:
179 /// The layout list to be displayed.
180 wxLayoutList *m_llist;
181 /// Can user edit the window?
182 bool m_Editable;
183 /// wrap margin
184 CoordType m_WrapMargin;
185 /// Is list dirty (for redraws, internal use)?
186 bool m_Dirty;
187 /// Has list been edited?
188 bool m_Modified;
189 wxMemoryDC *m_memDC;
190 wxBitmap *m_bitmap;
191 wxPoint m_bitmapSize;
192 /// a pointer to a bitmap for the background
193 wxBitmap *m_BGbitmap;
194 DECLARE_EVENT_TABLE()
195 };
196
197 #endif