More X11 code
[wxWidgets.git] / include / wx / x11 / window.h
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_
13 #define _WX_WINDOW_H_
14
15 #ifdef __GNUG__
16 #pragma interface "window.h"
17 #endif
18
19 #include "wx/region.h"
20
21 // ----------------------------------------------------------------------------
22 // wxWindow class for Motif - see also wxWindowBase
23 // ----------------------------------------------------------------------------
24
25 class wxWindowX11 : public wxWindowBase
26 {
27 friend class WXDLLEXPORT wxDC;
28 friend class WXDLLEXPORT wxWindowDC;
29
30 public:
31 wxWindowX11() { Init(); }
32
33 wxWindowX11(wxWindow *parent,
34 wxWindowID id,
35 const wxPoint& pos = wxDefaultPosition,
36 const wxSize& size = wxDefaultSize,
37 long style = 0,
38 const wxString& name = wxPanelNameStr)
39 {
40 Init();
41 Create(parent, id, pos, size, style, name);
42 }
43
44 virtual ~wxWindowX11();
45
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);
52
53 virtual void Raise();
54 virtual void Lower();
55
56 virtual bool Show( bool show = TRUE );
57 virtual bool Enable( bool enable = TRUE );
58
59 virtual void SetFocus();
60
61 virtual void WarpPointer(int x, int y);
62
63 virtual void Refresh( bool eraseBackground = TRUE,
64 const wxRect *rect = (const wxRect *) NULL );
65 virtual void Clear();
66
67 virtual bool SetBackgroundColour( const wxColour &colour );
68 virtual bool SetForegroundColour( const wxColour &colour );
69
70 virtual bool SetCursor( const wxCursor &cursor );
71 virtual bool SetFont( const wxFont &font );
72
73 virtual int GetCharHeight() const;
74 virtual int GetCharWidth() const;
75 virtual void GetTextExtent(const wxString& string,
76 int *x, int *y,
77 int *descent = (int *) NULL,
78 int *externalLeading = (int *) NULL,
79 const wxFont *theFont = (const wxFont *) NULL)
80 const;
81
82 virtual void SetScrollbar( int orient, int pos, int thumbVisible,
83 int range, bool refresh = TRUE );
84 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
85 virtual int GetScrollPos( int orient ) const;
86 virtual int GetScrollThumb( int orient ) const;
87 virtual int GetScrollRange( int orient ) const;
88 virtual void ScrollWindow( int dx, int dy,
89 const wxRect* rect = (wxRect *) NULL );
90
91 virtual void SetSizeHints(int minW, int minH,
92 int maxW = -1, int maxH = -1,
93 int incW = -1, int incH = -1);
94 #if wxUSE_DRAG_AND_DROP
95 virtual void SetDropTarget( wxDropTarget *dropTarget );
96 #endif // wxUSE_DRAG_AND_DROP
97
98 // Accept files for dragging
99 virtual void DragAcceptFiles(bool accept);
100
101 // Get the unique identifier of a window
102 virtual WXWindow GetHandle() const { return GetMainWindow(); }
103
104 // implementation from now on
105 // --------------------------
106
107 // accessors
108 // ---------
109
110 // Get main widget for this window, e.g. a text widget
111 virtual WXWindow GetMainWindow() const;
112 // Get the widget that corresponds to the label (for font setting, label setting etc.)
113 virtual WXWindow GetLabelWindow() const;
114 // Get the client widget for this window (something we can create other
115 // windows on)
116 virtual WXWindow GetClientWindow() const;
117 // Get the top widget for this window, e.g. the scrolled widget parent of a
118 // multi-line text widget. Top means, top in the window hierarchy that
119 // implements this window.
120 virtual WXWindow GetTopWindow() const;
121
122 // Get the underlying X window and display
123 WXWindow GetXWindow() const;
124 WXDisplay *GetXDisplay() const;
125
126 // called from Motif callbacks - and should only be called from there
127
128 void SetButton1(bool pressed) { m_button1Pressed = pressed; }
129 void SetButton2(bool pressed) { m_button2Pressed = pressed; }
130 void SetButton3(bool pressed) { m_button3Pressed = pressed; }
131
132 void SetLastClick(int button, long timestamp)
133 { m_lastButton = button; m_lastTS = timestamp; }
134
135 int GetLastClickedButton() const { return m_lastButton; }
136 long GetLastClickTime() const { return m_lastTS; }
137
138 // Gives window a chance to do something in response to a size message, e.g.
139 // arrange status bar, toolbar etc.
140 virtual bool PreResize();
141
142 // Generates a paint event
143 virtual void DoPaint();
144
145 // update rectangle/region manipulation
146 // (for wxWindowDC and Motif callbacks only)
147 // -----------------------------------------
148
149 // read/write access to the update rect list
150 const wxRectList& GetUpdateRects() const { return m_updateRects; }
151
152 // Adds a recangle to the updates list
153 void AddUpdateRect(int x, int y, int w, int h)
154 { m_updateRects.Append(new wxRect(x, y, w, h)); }
155
156 // Empties the m_updateRects list
157 void ClearUpdateRects();
158
159 void ClearUpdateRegion() { m_updateRegion.Clear(); }
160 void SetUpdateRegion(const wxRegion& region) { m_updateRegion = region; }
161
162 // sets the fore/background colour for the given widget
163 static void DoChangeForegroundColour(WXWindow widget, wxColour& foregroundColour);
164 static void DoChangeBackgroundColour(WXWindow widget, wxColour& backgroundColour, bool changeArmColour = FALSE);
165
166 // For implementation purposes - sometimes decorations make the client area
167 // smaller
168 virtual wxPoint GetClientAreaOrigin() const;
169
170 protected:
171 // event handlers (not virtual by design)
172 void OnIdle(wxIdleEvent& event);
173
174 // Makes an adjustment to the window position (for example, a frame that has
175 // a toolbar that it manages itself).
176 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
177
178 wxWindow *GetChild(int number) const
179 { return GetChildren().Item(number)->GetData(); }
180
181 // Responds to colour changes: passes event on to children.
182 void OnSysColourChanged(wxSysColourChangedEvent& event);
183
184 void SetMainWindow(WXWindow w) { m_mainWidget = w; }
185
186 bool CanAddEventHandler() const { return m_canAddEventHandler; }
187 void SetCanAddEventHandler(bool flag) { m_canAddEventHandler = flag; }
188
189 public:
190 WXPixmap GetBackingPixmap() const { return m_backingPixmap; }
191 void SetBackingPixmap(WXPixmap pixmap) { m_backingPixmap = pixmap; }
192 int GetPixmapWidth() const { return m_pixmapWidth; }
193 int GetPixmapHeight() const { return m_pixmapHeight; }
194 void SetPixmapWidth(int w) { m_pixmapWidth = w; }
195 void SetPixmapHeight(int h) { m_pixmapHeight = h; }
196
197 // Change properties
198 virtual void ChangeFont(bool keepOriginalSize = TRUE); // Change to the current font (often overridden)
199
200 // Change background and foreground colour using current background colour
201 // setting (Motif generates foreground based on background)
202 virtual void ChangeBackgroundColour();
203 // Change foreground colour using current foreground colour setting
204 virtual void ChangeForegroundColour();
205
206 protected:
207 // How to implement accelerators. If we find a key event, translate to
208 // wxWindows wxKeyEvent form. Find a widget for the window. Now find a
209 // wxWindow for the widget. If there isn't one, go up the widget hierarchy
210 // trying to find one. Once one is found, call ProcessAccelerator for the
211 // window. If it returns TRUE (processed the event), skip the X event,
212 // otherwise carry on up the wxWindows window hierarchy calling
213 // ProcessAccelerator. If all return FALSE, process the X event as normal.
214 // Eventually we can implement OnCharHook the same way, but concentrate on
215 // accelerators for now. ProcessAccelerator must look at the current
216 // accelerator table, and try to find what menu id or window (beneath it)
217 // has this ID. Then construct an appropriate command
218 // event and send it.
219 public:
220 virtual bool ProcessAccelerator(wxKeyEvent& event);
221
222 protected:
223 // scrolling stuff
224 // ---------------
225
226 // create/destroy window scrollbars
227 void CreateScrollbar(wxOrientation orientation);
228 void DestroyScrollbar(wxOrientation orientation);
229
230 // get either hor or vert scrollbar widget
231 WXWindow GetScrollbar(wxOrientation orient) const
232 { return orient == wxHORIZONTAL ? m_hScrollBar : m_vScrollBar; }
233
234 // set the scroll pos
235 void SetInternalScrollPos(wxOrientation orient, int pos)
236 {
237 if ( orient == wxHORIZONTAL )
238 m_scrollPosX = pos;
239 else
240 m_scrollPosY = pos;
241 }
242
243 // Motif-specific flags
244 // --------------------
245
246 bool m_needsRefresh:1; // repaint backing store?
247 bool m_canAddEventHandler:1; // ???
248 bool m_button1Pressed:1;
249 bool m_button2Pressed:1;
250 bool m_button3Pressed:1;
251
252 // For double-click detection
253 long m_lastTS; // last timestamp
254 int m_lastButton; // last pressed button
255
256 // List of wxRects representing damaged region
257 wxRectList m_updateRects;
258
259 protected:
260 WXWindow m_mainWidget;
261 WXWindow m_hScrollBar;
262 WXWindow m_vScrollBar;
263 WXWindow m_borderWidget;
264 WXWindow m_scrolledWindow;
265 WXWindow m_drawingArea;
266 bool m_winCaptured;
267 bool m_hScroll;
268 bool m_vScroll;
269 WXPixmap m_backingPixmap;
270 int m_pixmapWidth;
271 int m_pixmapHeight;
272 int m_pixmapOffsetX;
273 int m_pixmapOffsetY;
274
275 // Store the last scroll pos, since in wxWin the pos isn't set automatically
276 // by system
277 int m_scrollPosX;
278 int m_scrollPosY;
279
280 // Window border size
281 int m_borderSize;
282
283 // implement the base class pure virtuals
284 virtual void DoClientToScreen( int *x, int *y ) const;
285 virtual void DoScreenToClient( int *x, int *y ) const;
286 virtual void DoGetPosition( int *x, int *y ) const;
287 virtual void DoGetSize( int *width, int *height ) const;
288 virtual void DoGetClientSize( int *width, int *height ) const;
289 virtual void DoSetSize(int x, int y,
290 int width, int height,
291 int sizeFlags = wxSIZE_AUTO);
292 virtual void DoSetClientSize(int width, int height);
293 virtual void DoMoveWindow(int x, int y, int width, int height);
294 virtual bool DoPopupMenu(wxMenu *menu, int x, int y);
295
296 virtual void DoCaptureMouse();
297 virtual void DoReleaseMouse();
298
299 #if wxUSE_TOOLTIPS
300 virtual void DoSetToolTip( wxToolTip *tip );
301 #endif // wxUSE_TOOLTIPS
302
303 private:
304 // common part of all ctors
305 void Init();
306
307 DECLARE_DYNAMIC_CLASS(wxWindowX11)
308 DECLARE_NO_COPY_CLASS(wxWindowX11)
309 DECLARE_EVENT_TABLE()
310 };
311
312 // ----------------------------------------------------------------------------
313 // A little class to switch off `size optimization' while an instance of the
314 // object exists: this may be useful to temporarily disable the optimisation
315 // which consists to do nothing when the new size is equal to the old size -
316 // although quite useful usually to avoid flicker, sometimes it leads to
317 // undesired effects.
318 //
319 // Usage: create an instance of this class on the stack to disable the size
320 // optimisation, it will be reenabled as soon as the object goes out from scope.
321 // ----------------------------------------------------------------------------
322
323 class WXDLLEXPORT wxNoOptimize
324 {
325 public:
326 wxNoOptimize() { ms_count++; }
327 ~wxNoOptimize() { ms_count--; }
328
329 static bool CanOptimize() { return ms_count == 0; }
330
331 protected:
332 static int ms_count;
333 };
334
335 #endif
336 // _WX_WINDOW_H_