wxX11:
[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 void SetLastClick(int button, long timestamp)
127 { m_lastButton = button; m_lastTS = timestamp; }
128
129 int GetLastClickedButton() const { return m_lastButton; }
130 long GetLastClickTime() const { return m_lastTS; }
131
132 // Gives window a chance to do something in response to a size message, e.g.
133 // arrange status bar, toolbar etc.
134 virtual bool PreResize();
135
136 // Generates paint events
137 void X11SendPaintEvents();
138
139 // sets the fore/background colour for the given widget
140 static void DoChangeForegroundColour(WXWindow widget, wxColour& foregroundColour);
141 static void DoChangeBackgroundColour(WXWindow widget, wxColour& backgroundColour, bool changeArmColour = FALSE);
142
143 // For implementation purposes - sometimes decorations make the client area
144 // smaller
145 virtual wxPoint GetClientAreaOrigin() const;
146
147 protected:
148 // event handlers (not virtual by design)
149 void OnIdle(wxIdleEvent& event);
150
151 // Makes an adjustment to the window position (for example, a frame that has
152 // a toolbar that it manages itself).
153 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
154
155 wxWindow *GetChild(int number) const
156 { return GetChildren().Item(number)->GetData(); }
157
158 // Responds to colour changes: passes event on to children.
159 void OnSysColourChanged(wxSysColourChangedEvent& event);
160
161 void SetMainWindow(WXWindow w) { m_mainWidget = w; }
162
163 bool CanAddEventHandler() const { return m_canAddEventHandler; }
164 void SetCanAddEventHandler(bool flag) { m_canAddEventHandler = flag; }
165
166 public:
167 // Change properties
168 virtual void ChangeFont(bool keepOriginalSize = TRUE); // Change to the current font (often overridden)
169
170 // Change background and foreground colour using current background colour
171 // setting (Motif generates foreground based on background)
172 virtual void ChangeBackgroundColour();
173 // Change foreground colour using current foreground colour setting
174 virtual void ChangeForegroundColour();
175
176 protected:
177 // How to implement accelerators. If we find a key event, translate to
178 // wxWindows wxKeyEvent form. Find a widget for the window. Now find a
179 // wxWindow for the widget. If there isn't one, go up the widget hierarchy
180 // trying to find one. Once one is found, call ProcessAccelerator for the
181 // window. If it returns TRUE (processed the event), skip the X event,
182 // otherwise carry on up the wxWindows window hierarchy calling
183 // ProcessAccelerator. If all return FALSE, process the X event as normal.
184 // Eventually we can implement OnCharHook the same way, but concentrate on
185 // accelerators for now. ProcessAccelerator must look at the current
186 // accelerator table, and try to find what menu id or window (beneath it)
187 // has this ID. Then construct an appropriate command
188 // event and send it.
189 public:
190 virtual bool ProcessAccelerator(wxKeyEvent& event);
191
192 protected:
193 // scrolling stuff
194 // ---------------
195
196 // create/destroy window scrollbars
197 void CreateScrollbar(wxOrientation orientation);
198 void DestroyScrollbar(wxOrientation orientation);
199
200 // get either hor or vert scrollbar widget
201 WXWindow GetScrollbar(wxOrientation orient) const
202 { return orient == wxHORIZONTAL ? m_hScrollBar : m_vScrollBar; }
203
204 // set the scroll pos
205 void SetInternalScrollPos(wxOrientation orient, int pos)
206 {
207 if ( orient == wxHORIZONTAL )
208 m_scrollPosX = pos;
209 else
210 m_scrollPosY = pos;
211 }
212
213 // Motif-specific flags
214 // --------------------
215
216 bool m_needsRefresh:1; // repaint backing store?
217 bool m_canAddEventHandler:1; // ???
218
219 // For double-click detection
220 long m_lastTS; // last timestamp
221 int m_lastButton; // last pressed button
222
223 protected:
224 WXWindow m_mainWidget;
225
226 wxRegion m_clearRegion;
227 bool m_clipPaintRegion;
228
229 WXWindow m_hScrollBar;
230 WXWindow m_vScrollBar;
231 WXWindow m_borderWidget;
232 WXWindow m_scrolledWindow;
233 WXWindow m_drawingArea;
234 bool m_winCaptured;
235 bool m_hScroll;
236 bool m_vScroll;
237
238 // Store the last scroll pos, since in wxWin the pos isn't set automatically
239 // by system
240 int m_scrollPosX;
241 int m_scrollPosY;
242
243 // Window border size
244 int m_borderSize;
245
246 // implement the base class pure virtuals
247 virtual void DoClientToScreen( int *x, int *y ) const;
248 virtual void DoScreenToClient( int *x, int *y ) const;
249 virtual void DoGetPosition( int *x, int *y ) const;
250 virtual void DoGetSize( int *width, int *height ) const;
251 virtual void DoGetClientSize( int *width, int *height ) const;
252 virtual void DoSetSize(int x, int y,
253 int width, int height,
254 int sizeFlags = wxSIZE_AUTO);
255 virtual void DoSetClientSize(int width, int height);
256 virtual void DoMoveWindow(int x, int y, int width, int height);
257 virtual bool DoPopupMenu(wxMenu *menu, int x, int y);
258
259 virtual void DoCaptureMouse();
260 virtual void DoReleaseMouse();
261
262 #if wxUSE_TOOLTIPS
263 virtual void DoSetToolTip( wxToolTip *tip );
264 #endif // wxUSE_TOOLTIPS
265
266 private:
267 // common part of all ctors
268 void Init();
269
270 DECLARE_DYNAMIC_CLASS(wxWindowX11)
271 DECLARE_NO_COPY_CLASS(wxWindowX11)
272 DECLARE_EVENT_TABLE()
273 };
274
275 // ----------------------------------------------------------------------------
276 // A little class to switch off `size optimization' while an instance of the
277 // object exists: this may be useful to temporarily disable the optimisation
278 // which consists to do nothing when the new size is equal to the old size -
279 // although quite useful usually to avoid flicker, sometimes it leads to
280 // undesired effects.
281 //
282 // Usage: create an instance of this class on the stack to disable the size
283 // optimisation, it will be reenabled as soon as the object goes out from scope.
284 // ----------------------------------------------------------------------------
285
286 class WXDLLEXPORT wxNoOptimize
287 {
288 public:
289 wxNoOptimize() { ms_count++; }
290 ~wxNoOptimize() { ms_count--; }
291
292 static bool CanOptimize() { return ms_count == 0; }
293
294 protected:
295 static int ms_count;
296 };
297
298 #endif
299 // _WX_WINDOW_H_