]>
Commit | Line | Data |
---|---|---|
9b6dbb09 | 1 | ///////////////////////////////////////////////////////////////////////////// |
34097680 | 2 | // Name: wx/motif/window.h |
9b6dbb09 JS |
3 | // Purpose: wxWindow class |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
9b6dbb09 | 7 | // Copyright: (c) Julian Smart |
65571936 | 8 | // Licence: wxWindows licence |
9b6dbb09 JS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifndef _WX_WINDOW_H_ | |
12 | #define _WX_WINDOW_H_ | |
13 | ||
25f47127 | 14 | #include "wx/region.h" |
af0bb3b1 | 15 | |
34636400 VZ |
16 | // ---------------------------------------------------------------------------- |
17 | // wxWindow class for Motif - see also wxWindowBase | |
18 | // ---------------------------------------------------------------------------- | |
9b6dbb09 | 19 | |
94c7b088 | 20 | class WXDLLIMPEXP_CORE wxWindow : public wxWindowBase |
9b6dbb09 | 21 | { |
b5dbe15d VS |
22 | friend class WXDLLIMPEXP_FWD_CORE wxDC; |
23 | friend class WXDLLIMPEXP_FWD_CORE wxWindowDC; | |
34097680 | 24 | |
9b6dbb09 | 25 | public: |
34636400 | 26 | wxWindow() { Init(); } |
34097680 | 27 | |
34636400 | 28 | wxWindow(wxWindow *parent, |
34097680 WS |
29 | wxWindowID id, |
30 | const wxPoint& pos = wxDefaultPosition, | |
31 | const wxSize& size = wxDefaultSize, | |
32 | long style = 0, | |
33 | const wxString& name = wxPanelNameStr) | |
bfc6fde4 | 34 | { |
34636400 | 35 | Init(); |
bfc6fde4 VZ |
36 | Create(parent, id, pos, size, style, name); |
37 | } | |
34097680 | 38 | |
bfc6fde4 | 39 | virtual ~wxWindow(); |
34097680 | 40 | |
34636400 | 41 | bool Create(wxWindow *parent, |
34097680 WS |
42 | wxWindowID id, |
43 | const wxPoint& pos = wxDefaultPosition, | |
44 | const wxSize& size = wxDefaultSize, | |
45 | long style = 0, | |
46 | const wxString& name = wxPanelNameStr); | |
47 | ||
34636400 | 48 | // implement base class pure virtuals |
34097680 WS |
49 | virtual void SetLabel(const wxString& label); |
50 | virtual wxString GetLabel() const; | |
51 | ||
bfc6fde4 | 52 | virtual void Raise(); |
bfc6fde4 | 53 | virtual void Lower(); |
34097680 | 54 | |
96be256b MB |
55 | virtual bool Show( bool show = true ); |
56 | virtual bool Enable( bool enable = true ); | |
34097680 | 57 | |
34636400 | 58 | virtual void SetFocus(); |
34097680 | 59 | |
34636400 | 60 | virtual void WarpPointer(int x, int y); |
34097680 | 61 | |
96be256b | 62 | virtual void Refresh( bool eraseBackground = true, |
83df96d6 | 63 | const wxRect *rect = (const wxRect *) NULL ); |
34097680 | 64 | |
af0bb3b1 VZ |
65 | virtual bool SetBackgroundColour( const wxColour &colour ); |
66 | virtual bool SetForegroundColour( const wxColour &colour ); | |
34097680 | 67 | |
34636400 VZ |
68 | virtual bool SetCursor( const wxCursor &cursor ); |
69 | virtual bool SetFont( const wxFont &font ); | |
34097680 | 70 | |
bfc6fde4 VZ |
71 | virtual int GetCharHeight() const; |
72 | virtual int GetCharWidth() const; | |
34097680 | 73 | |
34636400 | 74 | virtual void SetScrollbar( int orient, int pos, int thumbVisible, |
96be256b MB |
75 | int range, bool refresh = true ); |
76 | virtual void SetScrollPos( int orient, int pos, bool refresh = true ); | |
34636400 VZ |
77 | virtual int GetScrollPos( int orient ) const; |
78 | virtual int GetScrollThumb( int orient ) const; | |
79 | virtual int GetScrollRange( int orient ) const; | |
80 | virtual void ScrollWindow( int dx, int dy, | |
d3b9f782 | 81 | const wxRect* rect = NULL ); |
34097680 | 82 | |
47d67540 | 83 | #if wxUSE_DRAG_AND_DROP |
34636400 VZ |
84 | virtual void SetDropTarget( wxDropTarget *dropTarget ); |
85 | #endif // wxUSE_DRAG_AND_DROP | |
34097680 | 86 | |
bfc6fde4 VZ |
87 | // Accept files for dragging |
88 | virtual void DragAcceptFiles(bool accept); | |
53ce655c | 89 | |
af0bb3b1 VZ |
90 | // Get the unique identifier of a window |
91 | virtual WXWidget GetHandle() const { return GetMainWidget(); } | |
34097680 | 92 | |
af0bb3b1 VZ |
93 | // implementation from now on |
94 | // -------------------------- | |
34097680 | 95 | |
af0bb3b1 VZ |
96 | // accessors |
97 | // --------- | |
34097680 | 98 | |
af0bb3b1 VZ |
99 | // Get main widget for this window, e.g. a text widget |
100 | virtual WXWidget GetMainWidget() const; | |
a8680e3e MB |
101 | // Get the widget that corresponds to the label (for font setting, |
102 | // label setting etc.) | |
af0bb3b1 VZ |
103 | virtual WXWidget GetLabelWidget() const; |
104 | // Get the client widget for this window (something we can create other | |
105 | // windows on) | |
106 | virtual WXWidget GetClientWidget() const; | |
107 | // Get the top widget for this window, e.g. the scrolled widget parent of a | |
108 | // multi-line text widget. Top means, top in the window hierarchy that | |
109 | // implements this window. | |
110 | virtual WXWidget GetTopWidget() const; | |
34097680 | 111 | |
af0bb3b1 | 112 | // Get the underlying X window and display |
1807c27d | 113 | WXWindow GetClientXWindow() const; |
af0bb3b1 VZ |
114 | WXWindow GetXWindow() const; |
115 | WXDisplay *GetXDisplay() const; | |
34097680 | 116 | |
af0bb3b1 | 117 | void SetLastClick(int button, long timestamp) |
83df96d6 | 118 | { m_lastButton = button; m_lastTS = timestamp; } |
34097680 | 119 | |
af0bb3b1 VZ |
120 | int GetLastClickedButton() const { return m_lastButton; } |
121 | long GetLastClickTime() const { return m_lastTS; } | |
34097680 | 122 | |
a8680e3e MB |
123 | // Gives window a chance to do something in response to a size message, |
124 | // e.g. arrange status bar, toolbar etc. | |
af0bb3b1 | 125 | virtual bool PreResize(); |
34097680 | 126 | |
af0bb3b1 VZ |
127 | // Generates a paint event |
128 | virtual void DoPaint(); | |
34097680 | 129 | |
af0bb3b1 VZ |
130 | // update rectangle/region manipulation |
131 | // (for wxWindowDC and Motif callbacks only) | |
132 | // ----------------------------------------- | |
34097680 | 133 | |
af0bb3b1 | 134 | // Adds a recangle to the updates list |
148b44a1 | 135 | void AddUpdateRect(int x, int y, int w, int h); |
34097680 | 136 | |
af0bb3b1 VZ |
137 | void ClearUpdateRegion() { m_updateRegion.Clear(); } |
138 | void SetUpdateRegion(const wxRegion& region) { m_updateRegion = region; } | |
34097680 | 139 | |
105fbe1f MB |
140 | // post-creation activities |
141 | void PostCreation(); | |
142 | ||
143 | // pre-creation activities | |
144 | void PreCreation(); | |
145 | ||
d6eaea28 | 146 | protected: |
bfc6fde4 VZ |
147 | // Responds to colour changes: passes event on to children. |
148 | void OnSysColourChanged(wxSysColourChangedEvent& event); | |
34097680 | 149 | |
34636400 | 150 | // Motif-specific |
34097680 | 151 | |
34636400 | 152 | void SetMainWidget(WXWidget w) { m_mainWidget = w; } |
34097680 | 153 | |
37c997b4 MB |
154 | // See src/motif/window.cpp, near the top, for an explanation |
155 | // why this is necessary | |
156 | void CanvasSetSizeIntr(int x, int y, int width, int height, | |
157 | int sizeFlags, bool fromCtor); | |
158 | void DoSetSizeIntr(int x, int y, | |
159 | int width, int height, | |
160 | int sizeFlags, bool fromCtor); | |
fc7ca9b3 MB |
161 | |
162 | // for DoMoveWindowIntr flags | |
163 | enum | |
164 | { | |
165 | wxMOVE_X = 1, | |
166 | wxMOVE_Y = 2, | |
167 | wxMOVE_WIDTH = 4, | |
168 | wxMOVE_HEIGHT = 8 | |
169 | }; | |
170 | ||
171 | void DoMoveWindowIntr(int x, int y, int width, int height, | |
172 | int flags); | |
148b44a1 MB |
173 | |
174 | // helper function, to remove duplicate code, used in wxScrollBar | |
175 | WXWidget DoCreateScrollBar(WXWidget parent, wxOrientation orientation, | |
176 | void (*callback)()); | |
9806a47c | 177 | public: |
34636400 | 178 | WXPixmap GetBackingPixmap() const { return m_backingPixmap; } |
9806a47c | 179 | void SetBackingPixmap(WXPixmap pixmap) { m_backingPixmap = pixmap; } |
bfc6fde4 VZ |
180 | int GetPixmapWidth() const { return m_pixmapWidth; } |
181 | int GetPixmapHeight() const { return m_pixmapHeight; } | |
9806a47c JS |
182 | void SetPixmapWidth(int w) { m_pixmapWidth = w; } |
183 | void SetPixmapHeight(int h) { m_pixmapHeight = h; } | |
34097680 | 184 | |
bfc6fde4 | 185 | // Change properties |
a8680e3e | 186 | // Change to the current font (often overridden) |
96be256b | 187 | virtual void ChangeFont(bool keepOriginalSize = true); |
34097680 | 188 | |
34636400 VZ |
189 | // Change background and foreground colour using current background colour |
190 | // setting (Motif generates foreground based on background) | |
191 | virtual void ChangeBackgroundColour(); | |
192 | // Change foreground colour using current foreground colour setting | |
193 | virtual void ChangeForegroundColour(); | |
34097680 | 194 | |
da175b2c | 195 | protected: |
bfc6fde4 | 196 | // Adds the widget to the hash table and adds event handlers. |
34636400 | 197 | bool AttachWidget(wxWindow* parent, WXWidget mainWidget, |
83df96d6 | 198 | WXWidget formWidget, int x, int y, int width, int height); |
bfc6fde4 | 199 | bool DetachWidget(WXWidget widget); |
34097680 | 200 | |
34636400 | 201 | // How to implement accelerators. If we find a key event, translate to |
77ffb593 | 202 | // wxWidgets wxKeyEvent form. Find a widget for the window. Now find a |
34636400 | 203 | // wxWindow for the widget. If there isn't one, go up the widget hierarchy |
bfc6fde4 | 204 | // trying to find one. Once one is found, call ProcessAccelerator for the |
96be256b | 205 | // window. If it returns true (processed the event), skip the X event, |
77ffb593 | 206 | // otherwise carry on up the wxWidgets window hierarchy calling |
96be256b | 207 | // ProcessAccelerator. If all return false, process the X event as normal. |
34636400 VZ |
208 | // Eventually we can implement OnCharHook the same way, but concentrate on |
209 | // accelerators for now. ProcessAccelerator must look at the current | |
210 | // accelerator table, and try to find what menu id or window (beneath it) | |
211 | // has this ID. Then construct an appropriate command | |
bfc6fde4 | 212 | // event and send it. |
d75638f8 | 213 | public: |
bfc6fde4 | 214 | virtual bool ProcessAccelerator(wxKeyEvent& event); |
34097680 | 215 | |
d75638f8 | 216 | protected: |
34636400 VZ |
217 | // unmanage and destroy an X widget f it's !NULL (passing NULL is ok) |
218 | void UnmanageAndDestroy(WXWidget widget); | |
34097680 | 219 | |
a8680e3e | 220 | // map or unmap an X widget (passing NULL is ok), |
96be256b | 221 | // returns true if widget was mapped/unmapped |
34636400 | 222 | bool MapOrUnmap(WXWidget widget, bool map); |
34097680 | 223 | |
af0bb3b1 VZ |
224 | // scrolling stuff |
225 | // --------------- | |
34097680 | 226 | |
af0bb3b1 VZ |
227 | // create/destroy window scrollbars |
228 | void CreateScrollbar(wxOrientation orientation); | |
229 | void DestroyScrollbar(wxOrientation orientation); | |
34097680 | 230 | |
34636400 VZ |
231 | // get either hor or vert scrollbar widget |
232 | WXWidget GetScrollbar(wxOrientation orient) const | |
83df96d6 | 233 | { return orient == wxHORIZONTAL ? m_hScrollBar : m_vScrollBar; } |
34097680 | 234 | |
34636400 VZ |
235 | // set the scroll pos |
236 | void SetInternalScrollPos(wxOrientation orient, int pos) | |
237 | { | |
238 | if ( orient == wxHORIZONTAL ) | |
239 | m_scrollPosX = pos; | |
240 | else | |
241 | m_scrollPosY = pos; | |
242 | } | |
34097680 | 243 | |
34636400 | 244 | // Motif-specific flags |
af0bb3b1 | 245 | // -------------------- |
34097680 | 246 | |
34636400 | 247 | bool m_needsRefresh:1; // repaint backing store? |
34097680 | 248 | |
bfc6fde4 | 249 | // For double-click detection |
a8680e3e MB |
250 | long m_lastTS; // last timestamp |
251 | unsigned m_lastButton:2; // last pressed button | |
34097680 | 252 | |
9b6dbb09 | 253 | protected: |
bfc6fde4 VZ |
254 | WXWidget m_mainWidget; |
255 | WXWidget m_hScrollBar; | |
256 | WXWidget m_vScrollBar; | |
257 | WXWidget m_borderWidget; | |
258 | WXWidget m_scrolledWindow; | |
259 | WXWidget m_drawingArea; | |
a8680e3e | 260 | bool m_winCaptured:1; |
bfc6fde4 VZ |
261 | WXPixmap m_backingPixmap; |
262 | int m_pixmapWidth; | |
263 | int m_pixmapHeight; | |
264 | int m_pixmapOffsetX; | |
265 | int m_pixmapOffsetY; | |
34097680 | 266 | |
a8680e3e MB |
267 | // Store the last scroll pos, since in wxWin the pos isn't set |
268 | // automatically by system | |
34636400 VZ |
269 | int m_scrollPosX; |
270 | int m_scrollPosY; | |
34097680 | 271 | |
34636400 | 272 | // implement the base class pure virtuals |
6de70470 VZ |
273 | virtual void DoGetTextExtent(const wxString& string, |
274 | int *x, int *y, | |
275 | int *descent = NULL, | |
276 | int *externalLeading = NULL, | |
277 | const wxFont *font = NULL) const; | |
34636400 VZ |
278 | virtual void DoClientToScreen( int *x, int *y ) const; |
279 | virtual void DoScreenToClient( int *x, int *y ) const; | |
280 | virtual void DoGetPosition( int *x, int *y ) const; | |
281 | virtual void DoGetSize( int *width, int *height ) const; | |
282 | virtual void DoGetClientSize( int *width, int *height ) const; | |
bfc6fde4 | 283 | virtual void DoSetSize(int x, int y, |
83df96d6 JS |
284 | int width, int height, |
285 | int sizeFlags = wxSIZE_AUTO); | |
bfc6fde4 | 286 | virtual void DoSetClientSize(int width, int height); |
9d9b7755 | 287 | virtual void DoMoveWindow(int x, int y, int width, int height); |
ee31c392 | 288 | virtual bool DoPopupMenu(wxMenu *menu, int x, int y); |
4116c221 VZ |
289 | virtual void DoCaptureMouse(); |
290 | virtual void DoReleaseMouse(); | |
53ce655c | 291 | |
34636400 VZ |
292 | #if wxUSE_TOOLTIPS |
293 | virtual void DoSetToolTip( wxToolTip *tip ); | |
294 | #endif // wxUSE_TOOLTIPS | |
34097680 | 295 | |
bfc6fde4 | 296 | private: |
34636400 VZ |
297 | // common part of all ctors |
298 | void Init(); | |
34097680 | 299 | |
c4ea2971 | 300 | DECLARE_DYNAMIC_CLASS(wxWindow) |
c0c133e1 | 301 | wxDECLARE_NO_COPY_CLASS(wxWindow); |
bfc6fde4 | 302 | DECLARE_EVENT_TABLE() |
9b6dbb09 JS |
303 | }; |
304 | ||
34636400 | 305 | // ---------------------------------------------------------------------------- |
af0bb3b1 VZ |
306 | // A little class to switch off `size optimization' while an instance of the |
307 | // object exists: this may be useful to temporarily disable the optimisation | |
308 | // which consists to do nothing when the new size is equal to the old size - | |
309 | // although quite useful usually to avoid flicker, sometimes it leads to | |
310 | // undesired effects. | |
34636400 | 311 | // |
af0bb3b1 | 312 | // Usage: create an instance of this class on the stack to disable the size |
a8680e3e MB |
313 | // optimisation, it will be reenabled as soon as the object goes out |
314 | // from scope. | |
34636400 | 315 | // ---------------------------------------------------------------------------- |
af0bb3b1 | 316 | |
53a2db12 | 317 | class WXDLLIMPEXP_CORE wxNoOptimize |
88150e60 JS |
318 | { |
319 | public: | |
83df96d6 JS |
320 | wxNoOptimize() { ms_count++; } |
321 | ~wxNoOptimize() { ms_count--; } | |
34097680 | 322 | |
83df96d6 | 323 | static bool CanOptimize() { return ms_count == 0; } |
34097680 | 324 | |
88150e60 | 325 | protected: |
83df96d6 | 326 | static int ms_count; |
88150e60 JS |
327 | }; |
328 | ||
34097680 | 329 | #endif // _WX_WINDOW_H_ |