]> git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlwindow.h
89d709a7286784b4fa0b6dc62476c9cfb8495158
[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 SetDirty();
72 DoPaint();
73 }
74
75 /// Enable or disable editing, i.e. processing of keystrokes.
76 void SetEditable(bool toggle) { m_Editable = toggle; }
77 /// Query whether list can be edited by user.
78 bool IsEditable(void) const { return m_Editable; }
79
80 //@}
81
82 void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }
83
84 /** Sets the wrap margin.
85 @param margin set this to 0 to disable it
86 */
87 void SetWrapMargin(CoordType margin) { m_WrapMargin = margin; }
88
89 /** Redraws the window.
90 @param scrollToCursor if true, scroll the window so that the
91 cursor becomes visible
92 */
93 void DoPaint(bool scrollToCursor = false);
94
95 #ifdef __WXMSW__
96 virtual long MSWGetDlgCode();
97 #endif //MSW
98
99 /// if exact == false, assume 50% extra size for the future
100 void ResizeScrollbars(bool exact = false); // don't change this to true!
101
102 /// if the flag is true, we send events when user clicks on embedded objects
103 inline void SetMouseTracking(bool doIt = true) { m_doSendEvents = doIt; }
104
105 /* Returns a pointer to the wxLayoutList object.
106 @return the list
107 */
108 wxLayoutList * GetLayoutList(void) { return m_llist; }
109
110 /**@name Callbacks */
111 //@{
112 void OnPaint(wxPaintEvent &event);
113 void OnChar(wxKeyEvent& event);
114 void OnMenu(wxCommandEvent& event);
115 void OnLeftMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_LCLICK, event); }
116 void OnRightMouseClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_RCLICK, event); }
117 void OnMouseDblClick(wxMouseEvent& event) { OnMouse(WXLOWIN_MENU_DBLCLICK, event); }
118 void OnSetFocus(wxFocusEvent &ev);
119 void OnKillFocus(wxFocusEvent &ev);
120 //@}
121
122 /// Creates a wxMenu for use as a format popup.
123 static wxMenu * MakeFormatMenu(void);
124 /// Set dirty flag.
125 void SetDirty(void) { m_Dirty = true; }
126 protected:
127 /**@name Dirty flag handling for optimisations. */
128 //@{
129 /// Query whether window needs redrawing.
130 bool IsDirty(void) const { return m_Dirty; }
131 /// Reset dirty flag.
132 void ResetDirty(void) { m_Dirty = false; }
133 //@}
134 protected:
135 /// generic function for mouse events processing
136 void OnMouse(int eventId, wxMouseEvent& event);
137
138 /// for sending events
139 wxWindow *m_Parent;
140 /// Shall we send events?
141 bool m_doSendEvents;
142 /// Where does the current view start?
143 int m_ViewStartX; int m_ViewStartY;
144 /// Do we currently have the focus?
145 bool m_HaveFocus;
146 /// do we handle clicks of the right mouse button?
147 bool m_DoPopupMenu;
148 /// the menu
149 wxMenu * m_PopupMenu;
150 /// for derived classes, set when mouse is clicked
151 wxPoint m_ClickPosition;
152 /// for scrollbar calculations:
153 int m_maxx;
154 int m_maxy;
155 int m_lineHeight;
156 private:
157 /// The layout list to be displayed.
158 wxLayoutList *m_llist;
159
160 /// Can user edit the window?
161 bool m_Editable;
162 /// wrap margin
163 CoordType m_WrapMargin;
164 /// Is list dirty?
165 bool m_Dirty;
166 wxMemoryDC *m_memDC;
167 wxBitmap *m_bitmap;
168 wxPoint m_bitmapSize;
169
170 DECLARE_EVENT_TABLE()
171 };
172
173 #endif