Small changes to 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 Update();
66
67 virtual void Clear();
68
69 virtual bool SetBackgroundColour( const wxColour &colour );
70 virtual bool SetForegroundColour( const wxColour &colour );
71
72 virtual bool SetCursor( const wxCursor &cursor );
73 virtual bool SetFont( const wxFont &font );
74
75 virtual int GetCharHeight() const;
76 virtual int GetCharWidth() const;
77 virtual void GetTextExtent(const wxString& string,
78 int *x, int *y,
79 int *descent = (int *) NULL,
80 int *externalLeading = (int *) NULL,
81 const wxFont *theFont = (const wxFont *) NULL)
82 const;
83
84 virtual void ScrollWindow( int dx, int dy,
85 const wxRect* rect = (wxRect *) NULL );
86
87 virtual void SetSizeHints(int minW, int minH,
88 int maxW = -1, int maxH = -1,
89 int incW = -1, int incH = -1);
90 #if wxUSE_DRAG_AND_DROP
91 virtual void SetDropTarget( wxDropTarget *dropTarget );
92 #endif // wxUSE_DRAG_AND_DROP
93
94 // Accept files for dragging
95 virtual void DragAcceptFiles(bool accept);
96
97 // Get the unique identifier of a window
98 virtual WXWindow GetHandle() const { return GetMainWindow(); }
99
100 // implementation from now on
101 // --------------------------
102
103 // accessors
104 // ---------
105
106 // Get main widget for this window, e.g. a text widget
107 virtual WXWindow GetMainWindow() const;
108
109 // Get the underlying X window and display
110 WXWindow GetXWindow() const;
111 WXDisplay *GetXDisplay() const;
112
113 void SetLastClick(int button, long timestamp)
114 { m_lastButton = button; m_lastTS = timestamp; }
115
116 int GetLastClickedButton() const { return m_lastButton; }
117 long GetLastClickTime() const { return m_lastTS; }
118
119 // Gives window a chance to do something in response to a size message, e.g.
120 // arrange status bar, toolbar etc.
121 virtual bool PreResize();
122
123 // Generates paint events
124 void X11SendPaintEvents();
125
126 // sets the fore/background colour for the given widget
127 static void DoChangeForegroundColour(WXWindow widget, wxColour& foregroundColour);
128 static void DoChangeBackgroundColour(WXWindow widget, wxColour& backgroundColour, bool changeArmColour = FALSE);
129
130 // For implementation purposes - sometimes decorations make the client area
131 // smaller
132 virtual wxPoint GetClientAreaOrigin() const;
133
134 protected:
135 // event handlers (not virtual by design)
136 void OnIdle(wxIdleEvent& event);
137
138 // Makes an adjustment to the window position (for example, a frame that has
139 // a toolbar that it manages itself).
140 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
141
142 // Responds to colour changes: passes event on to children.
143 void OnSysColourChanged(wxSysColourChangedEvent& event);
144
145 // For double-click detection
146 long m_lastTS; // last timestamp
147 int m_lastButton; // last pressed button
148
149 protected:
150 WXWindow m_mainWidget;
151
152 wxRegion m_clearRegion;
153 bool m_clipPaintRegion;
154
155 bool m_winCaptured; // ????
156
157 // implement the base class pure virtuals
158 virtual void DoClientToScreen( int *x, int *y ) const;
159 virtual void DoScreenToClient( int *x, int *y ) const;
160 virtual void DoGetPosition( int *x, int *y ) const;
161 virtual void DoGetSize( int *width, int *height ) const;
162 virtual void DoGetClientSize( int *width, int *height ) const;
163 virtual void DoSetSize(int x, int y,
164 int width, int height,
165 int sizeFlags = wxSIZE_AUTO);
166 virtual void DoSetClientSize(int width, int height);
167 virtual void DoMoveWindow(int x, int y, int width, int height);
168
169 virtual void DoCaptureMouse();
170 virtual void DoReleaseMouse();
171
172 #if wxUSE_TOOLTIPS
173 virtual void DoSetToolTip( wxToolTip *tip );
174 #endif // wxUSE_TOOLTIPS
175
176 private:
177 // common part of all ctors
178 void Init();
179
180 DECLARE_DYNAMIC_CLASS(wxWindowX11)
181 DECLARE_NO_COPY_CLASS(wxWindowX11)
182 DECLARE_EVENT_TABLE()
183 };
184
185 // ----------------------------------------------------------------------------
186 // A little class to switch off `size optimization' while an instance of the
187 // object exists: this may be useful to temporarily disable the optimisation
188 // which consists to do nothing when the new size is equal to the old size -
189 // although quite useful usually to avoid flicker, sometimes it leads to
190 // undesired effects.
191 //
192 // Usage: create an instance of this class on the stack to disable the size
193 // optimisation, it will be reenabled as soon as the object goes out from scope.
194 // ----------------------------------------------------------------------------
195
196 class WXDLLEXPORT wxNoOptimize
197 {
198 public:
199 wxNoOptimize() { ms_count++; }
200 ~wxNoOptimize() { ms_count--; }
201
202 static bool CanOptimize() { return ms_count == 0; }
203
204 protected:
205 static int ms_count;
206 };
207
208 #endif
209 // _WX_WINDOW_H_