]>
Commit | Line | Data |
---|---|---|
9b6dbb09 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: window.h | |
3 | // Purpose: wxWindow class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
34636400 | 9 | // Licence: wxWindows licence |
9b6dbb09 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_WINDOW_H_ | |
13 | #define _WX_WINDOW_H_ | |
14 | ||
15 | #ifdef __GNUG__ | |
34636400 | 16 | #pragma interface "window.h" |
9b6dbb09 JS |
17 | #endif |
18 | ||
34636400 VZ |
19 | // ---------------------------------------------------------------------------- |
20 | // wxWindow class for Motif - see also wxWindowBase | |
21 | // ---------------------------------------------------------------------------- | |
9b6dbb09 | 22 | |
34636400 | 23 | class wxWindow : public wxWindowBase |
9b6dbb09 | 24 | { |
34636400 | 25 | DECLARE_DYNAMIC_CLASS(wxWindow) |
9b6dbb09 | 26 | |
34636400 VZ |
27 | friend class WXDLLEXPORT wxDC; |
28 | friend class WXDLLEXPORT wxWindowDC; | |
9b6dbb09 JS |
29 | |
30 | public: | |
34636400 VZ |
31 | wxWindow() { Init(); } |
32 | ||
33 | wxWindow(wxWindow *parent, | |
34 | wxWindowID id, | |
35 | const wxPoint& pos = wxDefaultPosition, | |
36 | const wxSize& size = wxDefaultSize, | |
37 | long style = 0, | |
38 | const wxString& name = wxPanelNameStr) | |
bfc6fde4 | 39 | { |
34636400 | 40 | Init(); |
bfc6fde4 VZ |
41 | Create(parent, id, pos, size, style, name); |
42 | } | |
43 | ||
44 | virtual ~wxWindow(); | |
45 | ||
34636400 VZ |
46 | bool Create(wxWindow *parent, |
47 | wxWindowID id, | |
48 | const wxPoint& pos = wxDefaultPosition, | |
49 | const wxSize& size = wxDefaultSize, | |
50 | long style = 0, | |
51 | const wxString& name = wxPanelNameStr); | |
bfc6fde4 | 52 | |
34636400 VZ |
53 | // implement base class pure virtuals |
54 | virtual void SetTitle( const wxString& title); | |
55 | virtual wxString GetTitle() const; | |
bfc6fde4 | 56 | |
bfc6fde4 | 57 | virtual void Raise(); |
bfc6fde4 VZ |
58 | virtual void Lower(); |
59 | ||
34636400 VZ |
60 | virtual bool Show( bool show = TRUE ); |
61 | virtual bool Enable( bool enable = TRUE ); | |
bfc6fde4 | 62 | |
34636400 | 63 | virtual void SetFocus(); |
bfc6fde4 | 64 | |
34636400 VZ |
65 | virtual void WarpPointer(int x, int y); |
66 | virtual void CaptureMouse(); | |
67 | virtual void ReleaseMouse(); | |
bfc6fde4 | 68 | |
34636400 VZ |
69 | virtual void Refresh( bool eraseBackground = TRUE, |
70 | const wxRect *rect = (const wxRect *) NULL ); | |
71 | virtual void Clear(); | |
bfc6fde4 | 72 | |
34636400 VZ |
73 | virtual bool SetCursor( const wxCursor &cursor ); |
74 | virtual bool SetFont( const wxFont &font ); | |
bfc6fde4 | 75 | |
bfc6fde4 VZ |
76 | virtual int GetCharHeight() const; |
77 | virtual int GetCharWidth() const; | |
34636400 VZ |
78 | virtual void GetTextExtent(const wxString& string, |
79 | int *x, int *y, | |
80 | int *descent = (int *) NULL, | |
81 | int *externalLeading = (int *) NULL, | |
82 | const wxFont *theFont = (const wxFont *) NULL) | |
83 | const; | |
84 | ||
85 | virtual bool PopupMenu( wxMenu *menu, int x, int y ); | |
86 | ||
87 | virtual void SetScrollbar( int orient, int pos, int thumbVisible, | |
88 | int range, bool refresh = TRUE ); | |
89 | virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE ); | |
90 | virtual int GetScrollPos( int orient ) const; | |
91 | virtual int GetScrollThumb( int orient ) const; | |
92 | virtual int GetScrollRange( int orient ) const; | |
93 | virtual void ScrollWindow( int dx, int dy, | |
94 | const wxRect* rect = (wxRect *) NULL ); | |
9b6dbb09 | 95 | |
47d67540 | 96 | #if wxUSE_DRAG_AND_DROP |
34636400 VZ |
97 | virtual void SetDropTarget( wxDropTarget *dropTarget ); |
98 | #endif // wxUSE_DRAG_AND_DROP | |
9b6dbb09 | 99 | |
bfc6fde4 VZ |
100 | // Accept files for dragging |
101 | virtual void DragAcceptFiles(bool accept); | |
9b6dbb09 | 102 | |
34636400 VZ |
103 | protected: |
104 | // event handlers (not virtual by design) | |
bfc6fde4 | 105 | void OnIdle(wxIdleEvent& event); |
9b6dbb09 | 106 | |
bfc6fde4 VZ |
107 | // For implementation purposes - sometimes decorations make the client area |
108 | // smaller | |
109 | virtual wxPoint GetClientAreaOrigin() const; | |
110 | ||
111 | // Makes an adjustment to the window position (for example, a frame that has | |
112 | // a toolbar that it manages itself). | |
113 | virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags); | |
114 | ||
bfc6fde4 VZ |
115 | virtual void AddChild(wxWindow *child); // Adds reference to the child object |
116 | virtual void RemoveChild(wxWindow *child); // Removes reference to child | |
bfc6fde4 VZ |
117 | virtual void DestroyChildren(); // Removes and destroys all children |
118 | ||
34636400 VZ |
119 | wxWindow *GetChild(int number) const |
120 | { return GetChildren().Item(number)->GetData(); } | |
bfc6fde4 VZ |
121 | |
122 | // Responds to colour changes: passes event on to children. | |
123 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
124 | ||
34636400 | 125 | // Motif-specific |
bfc6fde4 | 126 | |
34636400 | 127 | // empties the m_updateRects list |
bfc6fde4 | 128 | void ClearUpdateRects(); |
34636400 VZ |
129 | |
130 | // CanvasXXXSiize functions | |
bfc6fde4 VZ |
131 | void CanvasGetSize(int* width, int* height) const; // If have drawing area |
132 | void CanvasGetClientSize(int *width, int *height) const; | |
133 | void CanvasGetPosition(int *x, int *y) const; // If have drawing area | |
134 | void CanvasSetClientSize(int width, int size); | |
135 | void CanvasSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); | |
136 | ||
34636400 VZ |
137 | // Gives window a chance to do something in response to a size message, e.g. |
138 | // arrange status bar, toolbar etc. | |
bfc6fde4 VZ |
139 | virtual bool PreResize() { return TRUE; } |
140 | ||
34636400 VZ |
141 | // accessors |
142 | // --------- | |
143 | ||
bfc6fde4 VZ |
144 | // Get main widget for this window, e.g. a text widget |
145 | virtual WXWidget GetMainWidget() const; | |
146 | // Get the widget that corresponds to the label (for font setting, label setting etc.) | |
34636400 VZ |
147 | virtual WXWidget GetLabelWidget() const; |
148 | // Get the client widget for this window (something we can create other | |
149 | // windows on) | |
bfc6fde4 | 150 | virtual WXWidget GetClientWidget() const; |
34636400 VZ |
151 | // Get the top widget for this window, e.g. the scrolled widget parent of a |
152 | // multi-line text widget. Top means, top in the window hierarchy that | |
153 | // implements this window. | |
bfc6fde4 | 154 | virtual WXWidget GetTopWidget() const; |
34636400 VZ |
155 | |
156 | // base class pure virtual | |
157 | virtual WXWidget GetHandle() const { return GetMainWidget(); } | |
158 | ||
159 | void SetMainWidget(WXWidget w) { m_mainWidget = w; } | |
160 | ||
bfc6fde4 VZ |
161 | bool CanAddEventHandler() const { return m_canAddEventHandler; } |
162 | void SetCanAddEventHandler(bool flag) { m_canAddEventHandler = flag; } | |
163 | ||
164 | // Get the underlying X window and display | |
34636400 VZ |
165 | WXWindow GetXWindow() const; |
166 | WXDisplay *GetXDisplay() const; | |
bfc6fde4 | 167 | |
34636400 | 168 | WXPixmap GetBackingPixmap() const { return m_backingPixmap; } |
bfc6fde4 VZ |
169 | int GetPixmapWidth() const { return m_pixmapWidth; } |
170 | int GetPixmapHeight() const { return m_pixmapHeight; } | |
171 | ||
172 | // Change properties | |
173 | virtual void ChangeFont(bool keepOriginalSize = TRUE); // Change to the current font (often overridden) | |
174 | virtual void DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour); | |
175 | virtual void DoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour = FALSE); | |
34636400 VZ |
176 | |
177 | // Change background and foreground colour using current background colour | |
178 | // setting (Motif generates foreground based on background) | |
179 | virtual void ChangeBackgroundColour(); | |
180 | // Change foreground colour using current foreground colour setting | |
181 | virtual void ChangeForegroundColour(); | |
bfc6fde4 VZ |
182 | |
183 | // Adds the widget to the hash table and adds event handlers. | |
34636400 VZ |
184 | bool AttachWidget(wxWindow* parent, WXWidget mainWidget, |
185 | WXWidget formWidget, int x, int y, int width, int height); | |
bfc6fde4 VZ |
186 | bool DetachWidget(WXWidget widget); |
187 | ||
188 | // Generates a paint event | |
189 | virtual void DoPaint(); | |
190 | ||
34636400 VZ |
191 | // How to implement accelerators. If we find a key event, translate to |
192 | // wxWindows wxKeyEvent form. Find a widget for the window. Now find a | |
193 | // wxWindow for the widget. If there isn't one, go up the widget hierarchy | |
bfc6fde4 VZ |
194 | // trying to find one. Once one is found, call ProcessAccelerator for the |
195 | // window. If it returns TRUE (processed the event), skip the X event, | |
34636400 VZ |
196 | // otherwise carry on up the wxWindows window hierarchy calling |
197 | // ProcessAccelerator. If all return FALSE, process the X event as normal. | |
198 | // Eventually we can implement OnCharHook the same way, but concentrate on | |
199 | // accelerators for now. ProcessAccelerator must look at the current | |
200 | // accelerator table, and try to find what menu id or window (beneath it) | |
201 | // has this ID. Then construct an appropriate command | |
bfc6fde4 VZ |
202 | // event and send it. |
203 | virtual bool ProcessAccelerator(wxKeyEvent& event); | |
204 | ||
9b6dbb09 | 205 | protected: |
34636400 VZ |
206 | // unmanage and destroy an X widget f it's !NULL (passing NULL is ok) |
207 | void UnmanageAndDestroy(WXWidget widget); | |
9b6dbb09 | 208 | |
34636400 VZ |
209 | // map or unmap an X widget (passing NULL is ok), returns TRUE if widget was |
210 | // mapped/unmapped | |
211 | bool MapOrUnmap(WXWidget widget, bool map); | |
9b6dbb09 | 212 | |
34636400 VZ |
213 | // get either hor or vert scrollbar widget |
214 | WXWidget GetScrollbar(wxOrientation orient) const | |
215 | { return orient == wxHORIZONTAL ? m_hScrollBar : m_vScrollBar; } | |
216 | ||
217 | // set the scroll pos | |
218 | void SetInternalScrollPos(wxOrientation orient, int pos) | |
219 | { | |
220 | if ( orient == wxHORIZONTAL ) | |
221 | m_scrollPosX = pos; | |
222 | else | |
223 | m_scrollPosY = pos; | |
224 | } | |
225 | ||
226 | // Motif-specific flags | |
227 | bool m_needsRefresh:1; // repaint backing store? | |
228 | bool m_canAddEventHandler:1; // ??? | |
229 | bool m_button1Pressed:1; | |
230 | bool m_button2Pressed:1; | |
231 | bool m_button3Pressed:1; | |
9b6dbb09 | 232 | |
bfc6fde4 | 233 | // For double-click detection |
34636400 VZ |
234 | long m_lastTS; // last timestamp |
235 | int m_lastButton; // last pressed button | |
236 | wxList m_updateRects; // List of wxRects representing damaged region | |
237 | ||
9b6dbb09 | 238 | protected: |
bfc6fde4 VZ |
239 | WXWidget m_mainWidget; |
240 | WXWidget m_hScrollBar; | |
241 | WXWidget m_vScrollBar; | |
242 | WXWidget m_borderWidget; | |
243 | WXWidget m_scrolledWindow; | |
244 | WXWidget m_drawingArea; | |
245 | bool m_winCaptured; | |
246 | bool m_hScroll; | |
247 | bool m_vScroll; | |
248 | WXPixmap m_backingPixmap; | |
249 | int m_pixmapWidth; | |
250 | int m_pixmapHeight; | |
251 | int m_pixmapOffsetX; | |
252 | int m_pixmapOffsetY; | |
bfc6fde4 | 253 | |
34636400 VZ |
254 | // Store the last scroll pos, since in wxWin the pos isn't set automatically |
255 | // by system | |
256 | int m_scrollPosX; | |
257 | int m_scrollPosY; | |
258 | ||
259 | // implement the base class pure virtuals | |
260 | virtual void DoClientToScreen( int *x, int *y ) const; | |
261 | virtual void DoScreenToClient( int *x, int *y ) const; | |
262 | virtual void DoGetPosition( int *x, int *y ) const; | |
263 | virtual void DoGetSize( int *width, int *height ) const; | |
264 | virtual void DoGetClientSize( int *width, int *height ) const; | |
bfc6fde4 VZ |
265 | virtual void DoSetSize(int x, int y, |
266 | int width, int height, | |
267 | int sizeFlags = wxSIZE_AUTO); | |
bfc6fde4 VZ |
268 | virtual void DoSetClientSize(int width, int height); |
269 | ||
34636400 VZ |
270 | #if wxUSE_TOOLTIPS |
271 | virtual void DoSetToolTip( wxToolTip *tip ); | |
272 | #endif // wxUSE_TOOLTIPS | |
273 | ||
bfc6fde4 | 274 | private: |
34636400 VZ |
275 | // common part of all ctors |
276 | void Init(); | |
277 | ||
278 | DECLARE_NO_COPY_CLASS(wxWindow); | |
bfc6fde4 | 279 | DECLARE_EVENT_TABLE() |
9b6dbb09 JS |
280 | }; |
281 | ||
34636400 | 282 | // ---------------------------------------------------------------------------- |
88150e60 JS |
283 | // A little class to switch off size optimization while an instance of the object |
284 | // exists | |
34636400 VZ |
285 | // |
286 | // TODO what is it for?? | |
287 | // ---------------------------------------------------------------------------- | |
88150e60 JS |
288 | class WXDLLEXPORT wxNoOptimize: public wxObject |
289 | { | |
290 | public: | |
291 | wxNoOptimize(); | |
292 | ~wxNoOptimize(); | |
293 | ||
294 | static bool CanOptimize(); | |
295 | ||
296 | protected: | |
297 | static int m_count; | |
298 | }; | |
299 | ||
9b6dbb09 JS |
300 | #endif |
301 | // _WX_WINDOW_H_ |