]>
Commit | Line | Data |
---|---|---|
83df96d6 | 1 | ///////////////////////////////////////////////////////////////////////////// |
9eddec69 | 2 | // Name: src/x11/window.cpp |
83df96d6 JS |
3 | // Purpose: wxWindow |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
65571936 | 9 | // Licence: wxWindows licence |
83df96d6 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
521bf4ff WS |
12 | // for compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #if defined(__BORLANDC__) | |
32d4c30a WS |
16 | #pragma hdrstop |
17 | #endif | |
18 | ||
83df96d6 JS |
19 | // ============================================================================ |
20 | // declarations | |
21 | // ============================================================================ | |
22 | ||
23 | // ---------------------------------------------------------------------------- | |
24 | // headers | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
e4db172a WS |
27 | #include "wx/window.h" |
28 | ||
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/hash.h" | |
31 | #include "wx/log.h" | |
670f9935 | 32 | #include "wx/app.h" |
de6185e2 | 33 | #include "wx/utils.h" |
8e609c82 | 34 | #include "wx/panel.h" |
76b49cf4 | 35 | #include "wx/frame.h" |
da80ae71 | 36 | #include "wx/dc.h" |
ed4b0fdc | 37 | #include "wx/dcclient.h" |
f1e01716 | 38 | #include "wx/button.h" |
3b3dc801 | 39 | #include "wx/menu.h" |
fdf565fe | 40 | #include "wx/dialog.h" |
c0badb70 | 41 | #include "wx/timer.h" |
9eddec69 | 42 | #include "wx/settings.h" |
246c5004 | 43 | #include "wx/msgdlg.h" |
851dee09 | 44 | #include "wx/scrolbar.h" |
2a673eb1 | 45 | #include "wx/listbox.h" |
1ab440bc | 46 | #include "wx/scrolwin.h" |
ed2fbeb8 | 47 | #include "wx/layout.h" |
25466131 | 48 | #include "wx/menuitem.h" |
02761f6c | 49 | #include "wx/module.h" |
be82fa69 | 50 | #include "wx/unix/utilsx11.h" |
e4db172a WS |
51 | #endif |
52 | ||
2b5f62a0 | 53 | #include "wx/fontutil.h" |
a17a79ba | 54 | #include "wx/univ/renderer.h" |
83df96d6 JS |
55 | |
56 | #if wxUSE_DRAG_AND_DROP | |
57 | #include "wx/dnd.h" | |
58 | #endif | |
59 | ||
bc797f4c | 60 | #include "wx/x11/private.h" |
7266b672 | 61 | #include "X11/Xutil.h" |
83df96d6 JS |
62 | |
63 | #include <string.h> | |
64 | ||
83df96d6 JS |
65 | // ---------------------------------------------------------------------------- |
66 | // global variables for this module | |
67 | // ---------------------------------------------------------------------------- | |
68 | ||
83df96d6 | 69 | static wxWindow* g_captureWindow = NULL; |
c2c0dabf | 70 | static GC g_eraseGC; |
83df96d6 | 71 | |
83df96d6 JS |
72 | // ---------------------------------------------------------------------------- |
73 | // macros | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
76 | #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask) | |
77 | #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask) | |
78 | #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask) | |
79 | ||
80 | // ---------------------------------------------------------------------------- | |
81 | // event tables | |
82 | // ---------------------------------------------------------------------------- | |
83 | ||
8354aa92 | 84 | IMPLEMENT_ABSTRACT_CLASS(wxWindowX11, wxWindowBase) |
83df96d6 | 85 | |
bc797f4c JS |
86 | BEGIN_EVENT_TABLE(wxWindowX11, wxWindowBase) |
87 | EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged) | |
bc797f4c | 88 | END_EVENT_TABLE() |
83df96d6 JS |
89 | |
90 | // ============================================================================ | |
91 | // implementation | |
92 | // ============================================================================ | |
93 | ||
94 | // ---------------------------------------------------------------------------- | |
95 | // helper functions | |
96 | // ---------------------------------------------------------------------------- | |
97 | ||
83df96d6 JS |
98 | // ---------------------------------------------------------------------------- |
99 | // constructors | |
100 | // ---------------------------------------------------------------------------- | |
101 | ||
bc797f4c | 102 | void wxWindowX11::Init() |
83df96d6 | 103 | { |
7266b672 | 104 | // X11-specific |
ab6b6b15 RR |
105 | m_mainWindow = (WXWindow) 0; |
106 | m_clientWindow = (WXWindow) 0; | |
ffd84c94 WS |
107 | m_insertIntoMain = false; |
108 | m_updateNcArea = false; | |
7de59551 | 109 | |
ffd84c94 WS |
110 | m_winCaptured = false; |
111 | m_needsInputFocus = false; | |
112 | m_isShown = true; | |
83df96d6 JS |
113 | m_lastTS = 0; |
114 | m_lastButton = 0; | |
83df96d6 JS |
115 | } |
116 | ||
117 | // real construction (Init() must have been called before!) | |
bc797f4c | 118 | bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, |
ffd84c94 WS |
119 | const wxPoint& pos, |
120 | const wxSize& size, | |
121 | long style, | |
122 | const wxString& name) | |
83df96d6 | 123 | { |
ffd84c94 | 124 | wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") ); |
83df96d6 | 125 | |
cce69fec JS |
126 | // Get default border |
127 | wxBorder border = GetBorder(style); | |
128 | style &= ~wxBORDER_MASK; | |
129 | style |= border; | |
130 | ||
83df96d6 JS |
131 | CreateBase(parent, id, pos, size, style, wxDefaultValidator, name); |
132 | ||
3cd0b8c5 | 133 | parent->AddChild(this); |
83df96d6 | 134 | |
3cd0b8c5 RR |
135 | Display *xdisplay = (Display*) wxGlobalDisplay(); |
136 | int xscreen = DefaultScreen( xdisplay ); | |
7e4501ee | 137 | Visual *xvisual = DefaultVisual( xdisplay, xscreen ); |
3cd0b8c5 | 138 | Colormap cm = DefaultColormap( xdisplay, xscreen ); |
b513212d | 139 | |
3cd0b8c5 | 140 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
7de59551 RD |
141 | m_backgroundColour.CalcPixel( (WXColormap) cm ); |
142 | ||
3cd0b8c5 | 143 | m_foregroundColour = *wxBLACK; |
7de59551 | 144 | m_foregroundColour.CalcPixel( (WXColormap) cm ); |
3cd0b8c5 | 145 | |
f41bc3e3 | 146 | Window xparent = (Window) parent->GetClientAreaWindow(); |
7de59551 | 147 | |
ab6b6b15 RR |
148 | // Add window's own scrollbars to main window, not to client window |
149 | if (parent->GetInsertIntoMain()) | |
150 | { | |
151 | // wxLogDebug( "Inserted into main: %s", GetName().c_str() ); | |
679918f9 | 152 | xparent = (Window) parent->X11GetMainWindow(); |
ab6b6b15 | 153 | } |
7de59551 | 154 | |
1cfb7d2c RR |
155 | // Size (not including the border) must be nonzero (or a Value error results)! |
156 | // Note: The Xlib manual doesn't mention this restriction of XCreateWindow. | |
2f12683e | 157 | wxSize size2(size); |
1cfb7d2c | 158 | if (size2.x <= 0) |
2b5f62a0 | 159 | size2.x = 20; |
1cfb7d2c | 160 | if (size2.y <= 0) |
2b5f62a0 | 161 | size2.y = 20; |
b513212d | 162 | |
2f12683e | 163 | wxPoint pos2(pos); |
ffd84c94 | 164 | if (pos2.x == wxDefaultCoord) |
2b5f62a0 | 165 | pos2.x = 0; |
ffd84c94 | 166 | if (pos2.y == wxDefaultCoord) |
2b5f62a0 | 167 | pos2.y = 0; |
7de59551 | 168 | |
43c05cf8 VZ |
169 | AdjustForParentClientOrigin(pos2.x, pos2.y); |
170 | ||
ab6b6b15 | 171 | #if wxUSE_TWO_WINDOWS |
2b5f62a0 | 172 | bool need_two_windows = |
cce69fec | 173 | ((( wxSUNKEN_BORDER | wxBORDER_THEME | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0); |
ab6b6b15 | 174 | #else |
ffd84c94 | 175 | bool need_two_windows = false; |
ab6b6b15 RR |
176 | #endif |
177 | ||
8601b2e1 JS |
178 | #if wxUSE_NANOX |
179 | long xattributes = 0; | |
180 | #else | |
7e4501ee | 181 | XSetWindowAttributes xattributes; |
ab6b6b15 | 182 | long xattributes_mask = 0; |
7de59551 | 183 | |
ab6b6b15 | 184 | xattributes_mask |= CWBackPixel; |
7e4501ee | 185 | xattributes.background_pixel = m_backgroundColour.GetPixel(); |
7de59551 | 186 | |
ab6b6b15 | 187 | xattributes_mask |= CWBorderPixel; |
7e4501ee | 188 | xattributes.border_pixel = BlackPixel( xdisplay, xscreen ); |
7de59551 | 189 | |
2f12683e | 190 | xattributes_mask |= CWEventMask; |
8601b2e1 | 191 | #endif |
7de59551 | 192 | |
ab6b6b15 | 193 | if (need_two_windows) |
2f12683e | 194 | { |
8601b2e1 JS |
195 | #if wxUSE_NANOX |
196 | long backColor, foreColor; | |
197 | backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()); | |
198 | foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue()); | |
7de59551 RD |
199 | |
200 | Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, | |
8601b2e1 JS |
201 | 0, 0, InputOutput, xvisual, backColor, foreColor); |
202 | XSelectInput( xdisplay, xwindow, | |
203 | GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
204 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
205 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
206 | PropertyChangeMask ); | |
7de59551 | 207 | |
8601b2e1 JS |
208 | #else |
209 | // Normal X11 | |
7de59551 | 210 | xattributes.event_mask = |
ab6b6b15 RR |
211 | ExposureMask | StructureNotifyMask | ColormapChangeMask; |
212 | ||
7de59551 | 213 | Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, |
ab6b6b15 | 214 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); |
8601b2e1 JS |
215 | |
216 | #endif | |
7de59551 | 217 | |
ab6b6b15 | 218 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); |
7de59551 | 219 | |
ab6b6b15 RR |
220 | m_mainWindow = (WXWindow) xwindow; |
221 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
7de59551 | 222 | |
ab6b6b15 | 223 | XMapWindow( xdisplay, xwindow ); |
8601b2e1 | 224 | |
7de59551 RD |
225 | #if !wxUSE_NANOX |
226 | xattributes.event_mask = | |
ab6b6b15 RR |
227 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
228 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
229 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
230 | PropertyChangeMask | VisibilityChangeMask ; | |
231 | ||
e441e1f4 | 232 | if (!HasFlag( wxFULL_REPAINT_ON_RESIZE )) |
ab6b6b15 RR |
233 | { |
234 | xattributes_mask |= CWBitGravity; | |
235 | xattributes.bit_gravity = StaticGravity; | |
236 | } | |
8601b2e1 | 237 | #endif |
7de59551 | 238 | |
cce69fec | 239 | if (HasFlag(wxSUNKEN_BORDER) || HasFlag(wxRAISED_BORDER) || HasFlag(wxBORDER_THEME)) |
065722d7 RR |
240 | { |
241 | pos2.x = 2; | |
242 | pos2.y = 2; | |
243 | size2.x -= 4; | |
244 | size2.y -= 4; | |
7de59551 | 245 | } |
1cfb7d2c | 246 | else if (HasFlag( wxSIMPLE_BORDER )) |
065722d7 RR |
247 | { |
248 | pos2.x = 1; | |
249 | pos2.y = 1; | |
250 | size2.x -= 2; | |
251 | size2.y -= 2; | |
7de59551 | 252 | } |
1cfb7d2c | 253 | else |
065722d7 RR |
254 | { |
255 | pos2.x = 0; | |
256 | pos2.y = 0; | |
257 | } | |
1cfb7d2c RR |
258 | |
259 | // Make again sure the size is nonzero. | |
260 | if (size2.x <= 0) | |
261 | size2.x = 1; | |
262 | if (size2.y <= 0) | |
263 | size2.y = 1; | |
264 | ||
7de59551 | 265 | #if wxUSE_NANOX |
8601b2e1 JS |
266 | backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()); |
267 | foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue()); | |
7de59551 RD |
268 | |
269 | xwindow = XCreateWindowWithColor( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y, | |
8601b2e1 JS |
270 | 0, 0, InputOutput, xvisual, backColor, foreColor); |
271 | XSelectInput( xdisplay, xwindow, | |
272 | GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
273 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
274 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
275 | PropertyChangeMask ); | |
7de59551 | 276 | |
8601b2e1 | 277 | #else |
7de59551 | 278 | xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y, |
ab6b6b15 | 279 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); |
8601b2e1 | 280 | #endif |
7de59551 | 281 | |
ab6b6b15 | 282 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); |
7de59551 | 283 | |
ab6b6b15 RR |
284 | m_clientWindow = (WXWindow) xwindow; |
285 | wxAddClientWindowToTable( xwindow, (wxWindow*) this ); | |
7de59551 | 286 | |
ab6b6b15 | 287 | XMapWindow( xdisplay, xwindow ); |
2f12683e | 288 | } |
ab6b6b15 RR |
289 | else |
290 | { | |
291 | // wxLogDebug( "No two windows needed %s", GetName().c_str() ); | |
8601b2e1 JS |
292 | #if wxUSE_NANOX |
293 | long backColor, foreColor; | |
294 | backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()); | |
295 | foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue()); | |
7de59551 RD |
296 | |
297 | Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, | |
8601b2e1 JS |
298 | 0, 0, InputOutput, xvisual, backColor, foreColor); |
299 | XSelectInput( xdisplay, xwindow, | |
300 | GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
301 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
302 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
303 | PropertyChangeMask ); | |
7de59551 | 304 | |
8601b2e1 | 305 | #else |
7de59551 | 306 | xattributes.event_mask = |
ab6b6b15 RR |
307 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | |
308 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
309 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
310 | PropertyChangeMask | VisibilityChangeMask ; | |
2f12683e | 311 | |
e441e1f4 | 312 | if (!HasFlag( wxFULL_REPAINT_ON_RESIZE )) |
ab6b6b15 RR |
313 | { |
314 | xattributes_mask |= CWBitGravity; | |
065722d7 | 315 | xattributes.bit_gravity = NorthWestGravity; |
ab6b6b15 | 316 | } |
7de59551 RD |
317 | |
318 | Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, | |
ab6b6b15 | 319 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); |
8601b2e1 | 320 | #endif |
7de59551 | 321 | |
ab6b6b15 | 322 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); |
7de59551 | 323 | |
ab6b6b15 RR |
324 | m_mainWindow = (WXWindow) xwindow; |
325 | m_clientWindow = m_mainWindow; | |
326 | wxAddWindowToTable( xwindow, (wxWindow*) this ); | |
7de59551 | 327 | |
ab6b6b15 RR |
328 | XMapWindow( xdisplay, xwindow ); |
329 | } | |
b513212d | 330 | |
b28d3abf | 331 | // Is a subwindow, so map immediately |
ffd84c94 | 332 | m_isShown = true; |
83df96d6 JS |
333 | |
334 | // Without this, the cursor may not be restored properly (e.g. in splitter | |
335 | // sample). | |
336 | SetCursor(*wxSTANDARD_CURSOR); | |
337 | SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
15c69343 JS |
338 | |
339 | // Don't call this, it can have nasty repercussions for composite controls, | |
340 | // for example | |
341 | // SetSize(pos.x, pos.y, size.x, size.y); | |
83df96d6 | 342 | |
ffd84c94 | 343 | return true; |
83df96d6 JS |
344 | } |
345 | ||
346 | // Destructor | |
7266b672 | 347 | wxWindowX11::~wxWindowX11() |
83df96d6 | 348 | { |
7de59551 RD |
349 | SendDestroyEvent(); |
350 | ||
83df96d6 | 351 | if (g_captureWindow == this) |
2b5f62a0 | 352 | g_captureWindow = NULL; |
7de59551 | 353 | |
d02cb44e | 354 | DestroyChildren(); |
83df96d6 | 355 | |
ab6b6b15 | 356 | if (m_clientWindow != m_mainWindow) |
83df96d6 | 357 | { |
ab6b6b15 RR |
358 | // Destroy the cleint window |
359 | Window xwindow = (Window) m_clientWindow; | |
360 | wxDeleteClientWindowFromTable( xwindow ); | |
7e4501ee | 361 | XDestroyWindow( wxGlobalDisplay(), xwindow ); |
ab6b6b15 | 362 | m_clientWindow = NULL; |
83df96d6 | 363 | } |
7de59551 | 364 | |
ab6b6b15 | 365 | // Destroy the window |
3aba082d VZ |
366 | if ( m_mainWindow ) |
367 | { | |
368 | Window xwindow = (Window) m_mainWindow; | |
369 | wxDeleteWindowFromTable( xwindow ); | |
370 | XDestroyWindow( wxGlobalDisplay(), xwindow ); | |
371 | m_mainWindow = NULL; | |
372 | } | |
83df96d6 JS |
373 | } |
374 | ||
375 | // --------------------------------------------------------------------------- | |
376 | // basic operations | |
377 | // --------------------------------------------------------------------------- | |
378 | ||
bc797f4c | 379 | void wxWindowX11::SetFocus() |
83df96d6 | 380 | { |
ab6b6b15 | 381 | Window xwindow = (Window) m_clientWindow; |
7de59551 | 382 | |
86fd8bda | 383 | wxCHECK_RET( xwindow, wxT("invalid window") ); |
7de59551 | 384 | |
10e0e1be JS |
385 | // Don't assert; we might be trying to set the focus for a panel |
386 | // with only static controls, so the panel returns false from AcceptsFocus. | |
387 | // The app should be not be expected to deal with this. | |
388 | if (!AcceptsFocus()) | |
389 | return; | |
7de59551 | 390 | |
9b8270da RR |
391 | #if 0 |
392 | if (GetName() == "scrollBar") | |
393 | { | |
394 | char *crash = NULL; | |
395 | *crash = 0; | |
396 | } | |
397 | #endif | |
7de59551 | 398 | |
3a0b23eb JS |
399 | if (wxWindowIsVisible(xwindow)) |
400 | { | |
9a83f860 | 401 | wxLogTrace( wxT("focus"), wxT("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName()); |
58ec2255 JS |
402 | // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime ); |
403 | XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToNone, CurrentTime ); | |
ffd84c94 | 404 | m_needsInputFocus = false; |
3a0b23eb JS |
405 | } |
406 | else | |
407 | { | |
ffd84c94 | 408 | m_needsInputFocus = true; |
3a0b23eb | 409 | } |
83df96d6 JS |
410 | } |
411 | ||
412 | // Get the window with the focus | |
0fe02759 | 413 | wxWindow *wxWindowBase::DoFindFocus() |
83df96d6 | 414 | { |
86fd8bda | 415 | Window xfocus = (Window) 0; |
b513212d | 416 | int revert = 0; |
bc797f4c | 417 | |
86fd8bda RR |
418 | XGetInputFocus( wxGlobalDisplay(), &xfocus, &revert); |
419 | if (xfocus) | |
83df96d6 | 420 | { |
86fd8bda | 421 | wxWindow *win = wxGetWindowFromTable( xfocus ); |
288efe84 JS |
422 | if (!win) |
423 | { | |
424 | win = wxGetClientWindowFromTable( xfocus ); | |
425 | } | |
b513212d JS |
426 | |
427 | return win; | |
83df96d6 JS |
428 | } |
429 | ||
b513212d | 430 | return NULL; |
83df96d6 JS |
431 | } |
432 | ||
b513212d JS |
433 | // Enabling/disabling handled by event loop, and not sending events |
434 | // if disabled. | |
bc797f4c | 435 | bool wxWindowX11::Enable(bool enable) |
83df96d6 JS |
436 | { |
437 | if ( !wxWindowBase::Enable(enable) ) | |
ffd84c94 | 438 | return false; |
7de59551 | 439 | |
ffd84c94 | 440 | return true; |
83df96d6 JS |
441 | } |
442 | ||
bc797f4c | 443 | bool wxWindowX11::Show(bool show) |
83df96d6 | 444 | { |
7edcafa4 | 445 | wxWindowBase::Show(show); |
83df96d6 | 446 | |
ab6b6b15 RR |
447 | Window xwindow = (Window) m_mainWindow; |
448 | Display *xdisp = wxGlobalDisplay(); | |
83df96d6 | 449 | if (show) |
b513212d | 450 | { |
7e4501ee | 451 | // wxLogDebug( "Mapping window of type %s", GetName().c_str() ); |
ab6b6b15 | 452 | XMapWindow(xdisp, xwindow); |
b513212d | 453 | } |
83df96d6 | 454 | else |
b513212d | 455 | { |
7e4501ee | 456 | // wxLogDebug( "Unmapping window of type %s", GetName().c_str() ); |
ab6b6b15 | 457 | XUnmapWindow(xdisp, xwindow); |
b513212d | 458 | } |
83df96d6 | 459 | |
ffd84c94 | 460 | return true; |
83df96d6 JS |
461 | } |
462 | ||
463 | // Raise the window to the top of the Z order | |
bc797f4c | 464 | void wxWindowX11::Raise() |
83df96d6 | 465 | { |
ab6b6b15 RR |
466 | if (m_mainWindow) |
467 | XRaiseWindow( wxGlobalDisplay(), (Window) m_mainWindow ); | |
83df96d6 JS |
468 | } |
469 | ||
470 | // Lower the window to the bottom of the Z order | |
bc797f4c | 471 | void wxWindowX11::Lower() |
83df96d6 | 472 | { |
ab6b6b15 RR |
473 | if (m_mainWindow) |
474 | XLowerWindow( wxGlobalDisplay(), (Window) m_mainWindow ); | |
83df96d6 JS |
475 | } |
476 | ||
ffd84c94 WS |
477 | void wxWindowX11::SetLabel(const wxString& WXUNUSED(label)) |
478 | { | |
479 | // TODO | |
480 | } | |
481 | ||
482 | wxString wxWindowX11::GetLabel() const | |
483 | { | |
484 | // TODO | |
485 | return wxEmptyString; | |
486 | } | |
487 | ||
bc797f4c | 488 | void wxWindowX11::DoCaptureMouse() |
83df96d6 | 489 | { |
7edcafa4 JS |
490 | if ((g_captureWindow != NULL) && (g_captureWindow != this)) |
491 | { | |
4362c705 | 492 | wxFAIL_MSG(wxT("Trying to capture before mouse released.")); |
7edcafa4 | 493 | |
346d4fcd RR |
494 | // Core dump now |
495 | int *tmp = NULL; | |
496 | (*tmp) = 1; | |
497 | return; | |
7edcafa4 | 498 | } |
7de59551 | 499 | |
346d4fcd | 500 | if (m_winCaptured) |
83df96d6 JS |
501 | return; |
502 | ||
ab6b6b15 | 503 | Window xwindow = (Window) m_clientWindow; |
346d4fcd | 504 | |
86fd8bda | 505 | wxCHECK_RET( xwindow, wxT("invalid window") ); |
7de59551 | 506 | |
7edcafa4 JS |
507 | g_captureWindow = (wxWindow*) this; |
508 | ||
346d4fcd | 509 | if (xwindow) |
b513212d | 510 | { |
346d4fcd | 511 | int res = XGrabPointer(wxGlobalDisplay(), xwindow, |
b513212d JS |
512 | FALSE, |
513 | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, | |
514 | GrabModeAsync, | |
2b5f62a0 | 515 | GrabModeAsync, |
b513212d JS |
516 | None, |
517 | None, /* cursor */ // TODO: This may need to be set to the cursor of this window | |
346d4fcd | 518 | CurrentTime ); |
b513212d | 519 | |
b28d3abf | 520 | if (res != GrabSuccess) |
b513212d | 521 | { |
346d4fcd | 522 | wxString msg; |
2b5f62a0 | 523 | msg.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName()); |
346d4fcd RR |
524 | wxLogDebug(msg); |
525 | if (res == GrabNotViewable) | |
43b2d5e7 | 526 | { |
2b5f62a0 | 527 | wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") ); |
43b2d5e7 | 528 | } |
7de59551 | 529 | |
346d4fcd | 530 | g_captureWindow = NULL; |
b28d3abf | 531 | return; |
b513212d | 532 | } |
346d4fcd | 533 | |
ffd84c94 | 534 | m_winCaptured = true; |
b513212d | 535 | } |
83df96d6 JS |
536 | } |
537 | ||
bc797f4c | 538 | void wxWindowX11::DoReleaseMouse() |
83df96d6 JS |
539 | { |
540 | g_captureWindow = NULL; | |
7de59551 | 541 | |
83df96d6 JS |
542 | if ( !m_winCaptured ) |
543 | return; | |
544 | ||
ab6b6b15 | 545 | Window xwindow = (Window) m_clientWindow; |
b513212d | 546 | |
346d4fcd | 547 | if (xwindow) |
b28d3abf | 548 | { |
346d4fcd | 549 | XUngrabPointer( wxGlobalDisplay(), CurrentTime ); |
b28d3abf | 550 | } |
7de59551 | 551 | |
9691c806 | 552 | // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() ); |
83df96d6 | 553 | |
ffd84c94 | 554 | m_winCaptured = false; |
83df96d6 JS |
555 | } |
556 | ||
bc797f4c | 557 | bool wxWindowX11::SetFont(const wxFont& font) |
83df96d6 JS |
558 | { |
559 | if ( !wxWindowBase::SetFont(font) ) | |
560 | { | |
561 | // nothing to do | |
ffd84c94 | 562 | return false; |
83df96d6 JS |
563 | } |
564 | ||
ffd84c94 | 565 | return true; |
83df96d6 JS |
566 | } |
567 | ||
bc797f4c | 568 | bool wxWindowX11::SetCursor(const wxCursor& cursor) |
83df96d6 JS |
569 | { |
570 | if ( !wxWindowBase::SetCursor(cursor) ) | |
571 | { | |
572 | // no change | |
ffd84c94 | 573 | return false; |
83df96d6 JS |
574 | } |
575 | ||
ab6b6b15 | 576 | Window xwindow = (Window) m_clientWindow; |
86fd8bda | 577 | |
ffd84c94 | 578 | wxCHECK_MSG( xwindow, false, wxT("invalid window") ); |
7de59551 | 579 | |
86fd8bda | 580 | wxCursor cursorToUse; |
83df96d6 | 581 | if (m_cursor.Ok()) |
86fd8bda | 582 | cursorToUse = m_cursor; |
83df96d6 | 583 | else |
86fd8bda | 584 | cursorToUse = *wxSTANDARD_CURSOR; |
83df96d6 | 585 | |
86fd8bda | 586 | Cursor xcursor = (Cursor) cursorToUse.GetCursor(); |
83df96d6 | 587 | |
e88be8c9 | 588 | XDefineCursor( wxGlobalDisplay(), xwindow, xcursor ); |
83df96d6 | 589 | |
ffd84c94 | 590 | return true; |
83df96d6 JS |
591 | } |
592 | ||
593 | // Coordinates relative to the window | |
bc797f4c | 594 | void wxWindowX11::WarpPointer (int x, int y) |
83df96d6 | 595 | { |
ab6b6b15 | 596 | Window xwindow = (Window) m_clientWindow; |
86fd8bda RR |
597 | |
598 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
7de59551 | 599 | |
86fd8bda | 600 | XWarpPointer( wxGlobalDisplay(), None, xwindow, 0, 0, 0, 0, x, y); |
83df96d6 JS |
601 | } |
602 | ||
83df96d6 | 603 | // Does a physical scroll |
bc797f4c | 604 | void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) |
83df96d6 | 605 | { |
fc9be1cf RR |
606 | // No scrolling requested. |
607 | if ((dx == 0) && (dy == 0)) return; | |
7de59551 | 608 | |
fc9be1cf RR |
609 | if (!m_updateRegion.IsEmpty()) |
610 | { | |
611 | m_updateRegion.Offset( dx, dy ); | |
7de59551 | 612 | |
fc9be1cf RR |
613 | int cw = 0; |
614 | int ch = 0; | |
615 | GetSize( &cw, &ch ); // GetClientSize() ?? | |
616 | m_updateRegion.Intersect( 0, 0, cw, ch ); | |
617 | } | |
7de59551 | 618 | |
fc9be1cf RR |
619 | if (!m_clearRegion.IsEmpty()) |
620 | { | |
621 | m_clearRegion.Offset( dx, dy ); | |
7de59551 | 622 | |
fc9be1cf RR |
623 | int cw = 0; |
624 | int ch = 0; | |
625 | GetSize( &cw, &ch ); // GetClientSize() ?? | |
626 | m_clearRegion.Intersect( 0, 0, cw, ch ); | |
627 | } | |
7de59551 | 628 | |
f41bc3e3 | 629 | Window xwindow = (Window) GetClientAreaWindow(); |
7e085304 RR |
630 | |
631 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
632 | ||
633 | Display *xdisplay = wxGlobalDisplay(); | |
634 | ||
635 | GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL ); | |
636 | XSetGraphicsExposures( xdisplay, xgc, True ); | |
637 | ||
e88be8c9 RR |
638 | int s_x = 0; |
639 | int s_y = 0; | |
4125131b RR |
640 | int cw; |
641 | int ch; | |
642 | if (rect) | |
643 | { | |
644 | s_x = rect->x; | |
645 | s_y = rect->y; | |
7de59551 | 646 | |
4125131b RR |
647 | cw = rect->width; |
648 | ch = rect->height; | |
649 | } | |
650 | else | |
651 | { | |
652 | s_x = 0; | |
653 | s_y = 0; | |
654 | GetClientSize( &cw, &ch ); | |
655 | } | |
7de59551 | 656 | |
ab6b6b15 RR |
657 | #if wxUSE_TWO_WINDOWS |
658 | wxPoint offset( 0,0 ); | |
659 | #else | |
4125131b RR |
660 | wxPoint offset = GetClientAreaOrigin(); |
661 | s_x += offset.x; | |
662 | s_y += offset.y; | |
ab6b6b15 | 663 | #endif |
7de59551 | 664 | |
7e085304 RR |
665 | int w = cw - abs(dx); |
666 | int h = ch - abs(dy); | |
7de59551 | 667 | |
7e085304 | 668 | if ((h < 0) || (w < 0)) |
83df96d6 | 669 | { |
7e085304 | 670 | Refresh(); |
83df96d6 JS |
671 | } |
672 | else | |
673 | { | |
4125131b | 674 | wxRect rect; |
f809133f RR |
675 | if (dx < 0) rect.x = cw+dx + offset.x; else rect.x = s_x; |
676 | if (dy < 0) rect.y = ch+dy + offset.y; else rect.y = s_y; | |
4125131b RR |
677 | if (dy != 0) rect.width = cw; else rect.width = abs(dx); |
678 | if (dx != 0) rect.height = ch; else rect.height = abs(dy); | |
7de59551 | 679 | |
4125131b RR |
680 | int d_x = s_x; |
681 | int d_y = s_y; | |
7de59551 | 682 | |
4125131b RR |
683 | if (dx < 0) s_x += -dx; |
684 | if (dy < 0) s_y += -dy; | |
ca86035f VZ |
685 | if (dx > 0) d_x += dx + offset.x; |
686 | if (dy > 0) d_y += dy + offset.y; | |
7e085304 RR |
687 | |
688 | XCopyArea( xdisplay, xwindow, xwindow, xgc, s_x, s_y, w, h, d_x, d_y ); | |
7de59551 | 689 | |
e88be8c9 | 690 | // wxLogDebug( "Copy: s_x %d s_y %d w %d h %d d_x %d d_y %d", s_x, s_y, w, h, d_x, d_y ); |
7e085304 | 691 | |
e88be8c9 | 692 | // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height ); |
7e085304 RR |
693 | |
694 | m_updateRegion.Union( rect ); | |
695 | m_clearRegion.Union( rect ); | |
83df96d6 | 696 | } |
7de59551 | 697 | |
7e085304 | 698 | XFreeGC( xdisplay, xgc ); |
271f05f7 JS |
699 | |
700 | // Move Clients, but not the scrollbars | |
701 | // FIXME: There may be a better method to move a lot of Windows within X11 | |
702 | wxScrollBar *sbH = ((wxWindow *) this)->GetScrollbar( wxHORIZONTAL ); | |
703 | wxScrollBar *sbV = ((wxWindow *) this)->GetScrollbar( wxVERTICAL ); | |
704 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
705 | while ( node ) | |
706 | { | |
707 | // Only propagate to non-top-level windows | |
708 | wxWindow *win = node->GetData(); | |
709 | if ( win->GetParent() && win != sbH && win != sbV ) | |
710 | { | |
711 | wxPoint pos = win->GetPosition(); | |
712 | // Add the delta to the old Position | |
713 | pos.x += dx; | |
714 | pos.y += dy; | |
715 | win->SetPosition(pos); | |
716 | } | |
717 | node = node->GetNext(); | |
718 | } | |
83df96d6 JS |
719 | } |
720 | ||
721 | // --------------------------------------------------------------------------- | |
722 | // drag and drop | |
723 | // --------------------------------------------------------------------------- | |
724 | ||
725 | #if wxUSE_DRAG_AND_DROP | |
726 | ||
bc797f4c | 727 | void wxWindowX11::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget)) |
83df96d6 JS |
728 | { |
729 | // TODO | |
730 | } | |
731 | ||
732 | #endif | |
733 | ||
734 | // Old style file-manager drag&drop | |
bc797f4c | 735 | void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept)) |
83df96d6 JS |
736 | { |
737 | // TODO | |
738 | } | |
739 | ||
740 | // ---------------------------------------------------------------------------- | |
741 | // tooltips | |
742 | // ---------------------------------------------------------------------------- | |
743 | ||
744 | #if wxUSE_TOOLTIPS | |
745 | ||
bc797f4c | 746 | void wxWindowX11::DoSetToolTip(wxToolTip * WXUNUSED(tooltip)) |
83df96d6 JS |
747 | { |
748 | // TODO | |
749 | } | |
750 | ||
751 | #endif // wxUSE_TOOLTIPS | |
752 | ||
83df96d6 JS |
753 | // --------------------------------------------------------------------------- |
754 | // moving and resizing | |
755 | // --------------------------------------------------------------------------- | |
756 | ||
bc797f4c | 757 | bool wxWindowX11::PreResize() |
83df96d6 | 758 | { |
ffd84c94 | 759 | return true; |
83df96d6 JS |
760 | } |
761 | ||
762 | // Get total size | |
bc797f4c | 763 | void wxWindowX11::DoGetSize(int *x, int *y) const |
83df96d6 | 764 | { |
ab6b6b15 | 765 | Window xwindow = (Window) m_mainWindow; |
86fd8bda RR |
766 | |
767 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
7de59551 | 768 | |
59db9cfa | 769 | //XSync(wxGlobalDisplay(), False); |
e941874b | 770 | |
86fd8bda RR |
771 | XWindowAttributes attr; |
772 | Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); | |
773 | wxASSERT(status); | |
7de59551 | 774 | |
86fd8bda RR |
775 | if (status) |
776 | { | |
777 | *x = attr.width /* + 2*m_borderSize */ ; | |
778 | *y = attr.height /* + 2*m_borderSize */ ; | |
83df96d6 | 779 | } |
83df96d6 JS |
780 | } |
781 | ||
bc797f4c | 782 | void wxWindowX11::DoGetPosition(int *x, int *y) const |
83df96d6 | 783 | { |
ab6b6b15 | 784 | Window window = (Window) m_mainWindow; |
b513212d | 785 | if (window) |
83df96d6 | 786 | { |
59db9cfa | 787 | //XSync(wxGlobalDisplay(), False); |
b513212d JS |
788 | XWindowAttributes attr; |
789 | Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); | |
790 | wxASSERT(status); | |
7de59551 | 791 | |
b513212d JS |
792 | if (status) |
793 | { | |
794 | *x = attr.x; | |
795 | *y = attr.y; | |
7de59551 | 796 | |
b513212d JS |
797 | // We may be faking the client origin. So a window that's really at (0, 30) |
798 | // may appear (to wxWin apps) to be at (0, 0). | |
799 | if (GetParent()) | |
800 | { | |
801 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
802 | *x -= pt.x; | |
803 | *y -= pt.y; | |
804 | } | |
805 | } | |
83df96d6 | 806 | } |
83df96d6 JS |
807 | } |
808 | ||
bc797f4c | 809 | void wxWindowX11::DoScreenToClient(int *x, int *y) const |
83df96d6 | 810 | { |
b513212d | 811 | Display *display = wxGlobalDisplay(); |
bc797f4c | 812 | Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); |
ab6b6b15 | 813 | Window thisWindow = (Window) m_clientWindow; |
83df96d6 JS |
814 | |
815 | Window childWindow; | |
c5c01214 VZ |
816 | int xx = x ? *x : 0; |
817 | int yy = y ? *y : 0; | |
818 | XTranslateCoordinates(display, rootWindow, thisWindow, | |
819 | xx, yy, x ? x : &xx, y ? y : &yy, | |
820 | &childWindow); | |
83df96d6 JS |
821 | } |
822 | ||
bc797f4c | 823 | void wxWindowX11::DoClientToScreen(int *x, int *y) const |
83df96d6 | 824 | { |
b513212d | 825 | Display *display = wxGlobalDisplay(); |
bc797f4c | 826 | Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); |
ab6b6b15 | 827 | Window thisWindow = (Window) m_clientWindow; |
83df96d6 | 828 | |
9d529fa0 | 829 | Window childWindow; |
c5c01214 VZ |
830 | int xx = x ? *x : 0; |
831 | int yy = y ? *y : 0; | |
832 | XTranslateCoordinates(display, thisWindow, rootWindow, | |
833 | xx, yy, x ? x : &xx, y ? y : &yy, | |
834 | &childWindow); | |
83df96d6 JS |
835 | } |
836 | ||
837 | ||
838 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
bc797f4c | 839 | void wxWindowX11::DoGetClientSize(int *x, int *y) const |
83df96d6 | 840 | { |
ab6b6b15 | 841 | Window window = (Window) m_mainWindow; |
b513212d JS |
842 | |
843 | if (window) | |
844 | { | |
845 | XWindowAttributes attr; | |
3cd0b8c5 | 846 | Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr ); |
b513212d | 847 | wxASSERT(status); |
7de59551 | 848 | |
b513212d JS |
849 | if (status) |
850 | { | |
851 | *x = attr.width ; | |
852 | *y = attr.height ; | |
853 | } | |
854 | } | |
83df96d6 JS |
855 | } |
856 | ||
bc797f4c | 857 | void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
83df96d6 | 858 | { |
df0e1b64 | 859 | // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height); |
7de59551 | 860 | |
ab6b6b15 | 861 | Window xwindow = (Window) m_mainWindow; |
83df96d6 | 862 | |
27398643 RR |
863 | wxCHECK_RET( xwindow, wxT("invalid window") ); |
864 | ||
865 | XWindowAttributes attr; | |
866 | Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); | |
867 | wxCHECK_RET( status, wxT("invalid window attributes") ); | |
7de59551 | 868 | |
27398643 RR |
869 | int new_x = attr.x; |
870 | int new_y = attr.y; | |
871 | int new_w = attr.width; | |
872 | int new_h = attr.height; | |
7de59551 | 873 | |
ffd84c94 | 874 | if (x != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
83df96d6 | 875 | { |
27398643 | 876 | int yy = 0; |
e5053ade | 877 | AdjustForParentClientOrigin( x, yy, sizeFlags); |
27398643 | 878 | new_x = x; |
83df96d6 | 879 | } |
ffd84c94 | 880 | if (y != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
83df96d6 | 881 | { |
27398643 | 882 | int xx = 0; |
e5053ade | 883 | AdjustForParentClientOrigin( xx, y, sizeFlags); |
27398643 | 884 | new_y = y; |
83df96d6 | 885 | } |
ffd84c94 | 886 | if (width != wxDefaultCoord) |
83df96d6 | 887 | { |
27398643 RR |
888 | new_w = width; |
889 | if (new_w <= 0) | |
890 | new_w = 20; | |
83df96d6 | 891 | } |
ffd84c94 | 892 | if (height != wxDefaultCoord) |
b513212d | 893 | { |
27398643 RR |
894 | new_h = height; |
895 | if (new_h <= 0) | |
896 | new_h = 20; | |
b513212d | 897 | } |
7de59551 | 898 | |
27398643 | 899 | DoMoveWindow( new_x, new_y, new_w, new_h ); |
83df96d6 JS |
900 | } |
901 | ||
bc797f4c | 902 | void wxWindowX11::DoSetClientSize(int width, int height) |
83df96d6 | 903 | { |
df0e1b64 | 904 | // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height); |
7de59551 | 905 | |
ab6b6b15 | 906 | Window xwindow = (Window) m_mainWindow; |
83df96d6 | 907 | |
27398643 | 908 | wxCHECK_RET( xwindow, wxT("invalid window") ); |
83df96d6 | 909 | |
2f12683e | 910 | XResizeWindow( wxGlobalDisplay(), xwindow, width, height ); |
7de59551 | 911 | |
ab6b6b15 RR |
912 | if (m_mainWindow != m_clientWindow) |
913 | { | |
914 | xwindow = (Window) m_clientWindow; | |
7de59551 | 915 | |
a17a79ba RR |
916 | wxWindow *window = (wxWindow*) this; |
917 | wxRenderer *renderer = window->GetRenderer(); | |
918 | if (renderer) | |
ab6b6b15 | 919 | { |
a17a79ba RR |
920 | wxRect border = renderer->GetBorderDimensions( (wxBorder)(m_windowStyle & wxBORDER_MASK) ); |
921 | width -= border.x + border.width; | |
922 | height -= border.y + border.height; | |
ab6b6b15 | 923 | } |
7de59551 | 924 | |
ab6b6b15 RR |
925 | XResizeWindow( wxGlobalDisplay(), xwindow, width, height ); |
926 | } | |
83df96d6 JS |
927 | } |
928 | ||
ab6b6b15 RR |
929 | void wxWindowX11::DoMoveWindow(int x, int y, int width, int height) |
930 | { | |
931 | Window xwindow = (Window) m_mainWindow; | |
932 | ||
933 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
934 | ||
935 | #if !wxUSE_NANOX | |
936 | ||
937 | XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, width, height ); | |
938 | if (m_mainWindow != m_clientWindow) | |
939 | { | |
940 | xwindow = (Window) m_clientWindow; | |
7de59551 | 941 | |
a17a79ba RR |
942 | wxWindow *window = (wxWindow*) this; |
943 | wxRenderer *renderer = window->GetRenderer(); | |
944 | if (renderer) | |
ab6b6b15 | 945 | { |
a17a79ba RR |
946 | wxRect border = renderer->GetBorderDimensions( (wxBorder)(m_windowStyle & wxBORDER_MASK) ); |
947 | x = border.x; | |
948 | y = border.y; | |
949 | width -= border.x + border.width; | |
950 | height -= border.y + border.height; | |
951 | } | |
952 | else | |
ab6b6b15 RR |
953 | { |
954 | x = 0; | |
955 | y = 0; | |
956 | } | |
7de59551 | 957 | |
ab6b6b15 RR |
958 | wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL ); |
959 | if (sb && sb->IsShown()) | |
960 | { | |
961 | wxSize size = sb->GetSize(); | |
962 | height -= size.y; | |
963 | } | |
964 | sb = window->GetScrollbar( wxVERTICAL ); | |
965 | if (sb && sb->IsShown()) | |
966 | { | |
967 | wxSize size = sb->GetSize(); | |
968 | width -= size.x; | |
969 | } | |
7de59551 | 970 | |
288efe84 | 971 | XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, wxMax(1, width), wxMax(1, height) ); |
ab6b6b15 | 972 | } |
7de59551 RD |
973 | |
974 | #else | |
ab6b6b15 RR |
975 | |
976 | XWindowChanges windowChanges; | |
977 | windowChanges.x = x; | |
978 | windowChanges.y = y; | |
979 | windowChanges.width = width; | |
980 | windowChanges.height = height; | |
981 | windowChanges.stack_mode = 0; | |
982 | int valueMask = CWX | CWY | CWWidth | CWHeight; | |
983 | ||
984 | XConfigureWindow( wxGlobalDisplay(), xwindow, valueMask, &windowChanges ); | |
7de59551 | 985 | |
ab6b6b15 RR |
986 | #endif |
987 | } | |
988 | ||
024f89f9 | 989 | void wxWindowX11::DoSetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH) |
83df96d6 JS |
990 | { |
991 | m_minWidth = minW; | |
992 | m_minHeight = minH; | |
993 | m_maxWidth = maxW; | |
994 | m_maxHeight = maxH; | |
995 | ||
461e93f9 | 996 | #if !wxUSE_NANOX |
b513212d JS |
997 | XSizeHints sizeHints; |
998 | sizeHints.flags = 0; | |
7de59551 | 999 | |
b513212d | 1000 | if (minW > -1 && minH > -1) |
83df96d6 | 1001 | { |
b513212d JS |
1002 | sizeHints.flags |= PMinSize; |
1003 | sizeHints.min_width = minW; | |
1004 | sizeHints.min_height = minH; | |
1005 | } | |
1006 | if (maxW > -1 && maxH > -1) | |
1007 | { | |
1008 | sizeHints.flags |= PMaxSize; | |
1009 | sizeHints.max_width = maxW; | |
1010 | sizeHints.max_height = maxH; | |
1011 | } | |
1012 | if (incW > -1 && incH > -1) | |
1013 | { | |
1014 | sizeHints.flags |= PResizeInc; | |
1015 | sizeHints.width_inc = incW; | |
1016 | sizeHints.height_inc = incH; | |
83df96d6 JS |
1017 | } |
1018 | ||
ab6b6b15 | 1019 | XSetWMNormalHints(wxGlobalDisplay(), (Window) m_mainWindow, &sizeHints ); |
2f12683e | 1020 | #endif |
83df96d6 JS |
1021 | } |
1022 | ||
1023 | // --------------------------------------------------------------------------- | |
1024 | // text metrics | |
1025 | // --------------------------------------------------------------------------- | |
1026 | ||
bc797f4c | 1027 | int wxWindowX11::GetCharHeight() const |
83df96d6 | 1028 | { |
4837b89e JS |
1029 | wxFont font(GetFont()); |
1030 | wxCHECK_MSG( font.Ok(), 0, wxT("valid window font needed") ); | |
83df96d6 | 1031 | |
2b5f62a0 VZ |
1032 | #if wxUSE_UNICODE |
1033 | // There should be an easier way. | |
1034 | PangoLayout *layout = pango_layout_new( wxTheApp->GetPangoContext() ); | |
4837b89e | 1035 | pango_layout_set_font_description( layout, font.GetNativeFontInfo()->description ); |
2b5f62a0 VZ |
1036 | pango_layout_set_text(layout, "H", 1 ); |
1037 | int w,h; | |
1038 | pango_layout_get_pixel_size(layout, &w, &h); | |
1039 | g_object_unref( G_OBJECT( layout ) ); | |
7de59551 | 1040 | |
2b5f62a0 VZ |
1041 | return h; |
1042 | #else | |
4837b89e | 1043 | WXFontStructPtr pFontStruct = font.GetFontStruct(1.0, wxGlobalDisplay()); |
83df96d6 JS |
1044 | |
1045 | int direction, ascent, descent; | |
1046 | XCharStruct overall; | |
1047 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
1048 | &descent, &overall); | |
1049 | ||
1050 | // return (overall.ascent + overall.descent); | |
1051 | return (ascent + descent); | |
2b5f62a0 | 1052 | #endif |
83df96d6 JS |
1053 | } |
1054 | ||
bc797f4c | 1055 | int wxWindowX11::GetCharWidth() const |
83df96d6 | 1056 | { |
4837b89e JS |
1057 | wxFont font(GetFont()); |
1058 | wxCHECK_MSG( font.Ok(), 0, wxT("valid window font needed") ); | |
83df96d6 | 1059 | |
2b5f62a0 VZ |
1060 | #if wxUSE_UNICODE |
1061 | // There should be an easier way. | |
1062 | PangoLayout *layout = pango_layout_new( wxTheApp->GetPangoContext() ); | |
4837b89e | 1063 | pango_layout_set_font_description( layout, font.GetNativeFontInfo()->description ); |
2b5f62a0 VZ |
1064 | pango_layout_set_text(layout, "H", 1 ); |
1065 | int w,h; | |
1066 | pango_layout_get_pixel_size(layout, &w, &h); | |
1067 | g_object_unref( G_OBJECT( layout ) ); | |
7de59551 | 1068 | |
2b5f62a0 VZ |
1069 | return w; |
1070 | #else | |
4837b89e | 1071 | WXFontStructPtr pFontStruct = font.GetFontStruct(1.0, wxGlobalDisplay()); |
83df96d6 JS |
1072 | |
1073 | int direction, ascent, descent; | |
1074 | XCharStruct overall; | |
1075 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
1076 | &descent, &overall); | |
1077 | ||
1078 | return overall.width; | |
2b5f62a0 | 1079 | #endif |
83df96d6 JS |
1080 | } |
1081 | ||
6de70470 VZ |
1082 | void wxWindowX11::DoGetTextExtent(const wxString& string, |
1083 | int *x, int *y, | |
1084 | int *descent, | |
1085 | int *externalLeading, | |
1086 | const wxFont *theFont) const | |
83df96d6 | 1087 | { |
4837b89e | 1088 | wxFont fontToUse = GetFont(); |
0d1dff01 | 1089 | if (theFont) fontToUse = *theFont; |
83df96d6 | 1090 | |
0d1dff01 RR |
1091 | wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") ); |
1092 | ||
ffd84c94 | 1093 | if (string.empty()) |
2b5f62a0 VZ |
1094 | { |
1095 | if (x) (*x) = 0; | |
1096 | if (y) (*y) = 0; | |
1097 | return; | |
1098 | } | |
1099 | ||
1100 | #if wxUSE_UNICODE | |
1101 | PangoLayout *layout = pango_layout_new( wxTheApp->GetPangoContext() ); | |
7de59551 | 1102 | |
2b5f62a0 VZ |
1103 | PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description; |
1104 | pango_layout_set_font_description(layout, desc); | |
7de59551 | 1105 | |
2b5f62a0 VZ |
1106 | const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); |
1107 | pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); | |
7de59551 | 1108 | |
2b5f62a0 VZ |
1109 | PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data; |
1110 | ||
7de59551 | 1111 | |
2b5f62a0 VZ |
1112 | PangoRectangle rect; |
1113 | pango_layout_line_get_extents(line, NULL, &rect); | |
7de59551 | 1114 | |
2b5f62a0 VZ |
1115 | if (x) (*x) = (wxCoord) (rect.width / PANGO_SCALE); |
1116 | if (y) (*y) = (wxCoord) (rect.height / PANGO_SCALE); | |
1117 | if (descent) | |
1118 | { | |
1119 | // Do something about metrics here | |
1120 | (*descent) = 0; | |
1121 | } | |
1122 | if (externalLeading) (*externalLeading) = 0; // ?? | |
1123 | ||
1124 | g_object_unref( G_OBJECT( layout ) ); | |
1125 | #else | |
ab6b6b15 | 1126 | WXFontStructPtr pFontStruct = fontToUse.GetFontStruct(1.0, wxGlobalDisplay()); |
83df96d6 JS |
1127 | |
1128 | int direction, ascent, descent2; | |
1129 | XCharStruct overall; | |
851dee09 | 1130 | int slen = string.length(); |
83df96d6 | 1131 | |
3ad2d972 | 1132 | XTextExtents((XFontStruct*) pFontStruct, (const char*) string.c_str(), slen, |
83df96d6 JS |
1133 | &direction, &ascent, &descent2, &overall); |
1134 | ||
1135 | if ( x ) | |
1136 | *x = (overall.width); | |
1137 | if ( y ) | |
1138 | *y = (ascent + descent2); | |
1139 | if (descent) | |
1140 | *descent = descent2; | |
1141 | if (externalLeading) | |
1142 | *externalLeading = 0; | |
2b5f62a0 | 1143 | #endif |
83df96d6 JS |
1144 | } |
1145 | ||
1146 | // ---------------------------------------------------------------------------- | |
1147 | // painting | |
1148 | // ---------------------------------------------------------------------------- | |
1149 | ||
bc797f4c | 1150 | void wxWindowX11::Refresh(bool eraseBack, const wxRect *rect) |
83df96d6 | 1151 | { |
d02cb44e RR |
1152 | if (eraseBack) |
1153 | { | |
1154 | if (rect) | |
1155 | { | |
1156 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
1157 | m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height ); | |
1158 | } | |
1159 | else | |
1160 | { | |
1161 | int height,width; | |
1162 | GetSize( &width, &height ); | |
7de59551 | 1163 | |
d02cb44e RR |
1164 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). |
1165 | m_clearRegion.Clear(); | |
1166 | m_clearRegion.Union( 0, 0, width, height ); | |
1167 | } | |
1168 | } | |
83df96d6 | 1169 | |
83df96d6 JS |
1170 | if (rect) |
1171 | { | |
d02cb44e RR |
1172 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). |
1173 | m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height ); | |
83df96d6 JS |
1174 | } |
1175 | else | |
1176 | { | |
0d1dff01 RR |
1177 | int height,width; |
1178 | GetSize( &width, &height ); | |
7de59551 | 1179 | |
d02cb44e RR |
1180 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). |
1181 | m_updateRegion.Clear(); | |
1182 | m_updateRegion.Union( 0, 0, width, height ); | |
83df96d6 | 1183 | } |
d02cb44e | 1184 | } |
83df96d6 | 1185 | |
d02cb44e RR |
1186 | void wxWindowX11::Update() |
1187 | { | |
ab6b6b15 RR |
1188 | if (m_updateNcArea) |
1189 | { | |
065722d7 | 1190 | // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName()); |
ab6b6b15 RR |
1191 | // Send nc paint events. |
1192 | SendNcPaintEvents(); | |
1193 | } | |
7de59551 | 1194 | |
d02cb44e | 1195 | if (!m_updateRegion.IsEmpty()) |
83df96d6 | 1196 | { |
ab6b6b15 | 1197 | // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName()); |
887dd52f RR |
1198 | // Actually send erase events. |
1199 | SendEraseEvents(); | |
7de59551 | 1200 | |
887dd52f RR |
1201 | // Actually send paint events. |
1202 | SendPaintEvents(); | |
83df96d6 | 1203 | } |
83df96d6 JS |
1204 | } |
1205 | ||
887dd52f | 1206 | void wxWindowX11::SendEraseEvents() |
83df96d6 | 1207 | { |
2f12683e | 1208 | if (m_clearRegion.IsEmpty()) return; |
7de59551 | 1209 | |
ab6b6b15 | 1210 | wxClientDC dc( (wxWindow*)this ); |
f84fb4ad | 1211 | dc.SetDeviceClippingRegion( m_clearRegion ); |
7de59551 | 1212 | |
2f12683e RR |
1213 | wxEraseEvent erase_event( GetId(), &dc ); |
1214 | erase_event.SetEventObject( this ); | |
0b5c0e1a | 1215 | |
937013e0 | 1216 | if (!HandleWindowEvent(erase_event) ) |
2f12683e | 1217 | { |
2f12683e | 1218 | Display *xdisplay = wxGlobalDisplay(); |
f41bc3e3 | 1219 | Window xwindow = (Window) GetClientAreaWindow(); |
c2c0dabf | 1220 | XSetForeground( xdisplay, g_eraseGC, m_backgroundColour.GetPixel() ); |
7de59551 | 1221 | |
2f12683e RR |
1222 | wxRegionIterator upd( m_clearRegion ); |
1223 | while (upd) | |
1934d291 | 1224 | { |
c2c0dabf | 1225 | XFillRectangle( xdisplay, xwindow, g_eraseGC, |
2f12683e RR |
1226 | upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() ); |
1227 | upd ++; | |
1934d291 | 1228 | } |
83df96d6 | 1229 | } |
7de59551 | 1230 | |
2f12683e | 1231 | m_clearRegion.Clear(); |
887dd52f RR |
1232 | } |
1233 | ||
887dd52f RR |
1234 | void wxWindowX11::SendPaintEvents() |
1235 | { | |
df0e1b64 JS |
1236 | // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId()); |
1237 | ||
ffd84c94 | 1238 | m_clipPaintRegion = true; |
7de59551 | 1239 | |
1934d291 RR |
1240 | wxPaintEvent paint_event( GetId() ); |
1241 | paint_event.SetEventObject( this ); | |
937013e0 | 1242 | HandleWindowEvent( paint_event ); |
7de59551 | 1243 | |
0b5c0e1a | 1244 | m_updateRegion.Clear(); |
7de59551 | 1245 | |
ffd84c94 | 1246 | m_clipPaintRegion = false; |
83df96d6 JS |
1247 | } |
1248 | ||
ab6b6b15 RR |
1249 | void wxWindowX11::SendNcPaintEvents() |
1250 | { | |
a17a79ba RR |
1251 | wxWindow *window = (wxWindow*) this; |
1252 | ||
1253 | // All this for drawing the small square between the scrollbars. | |
1254 | int width = 0; | |
1255 | int height = 0; | |
1256 | int x = 0; | |
1257 | int y = 0; | |
1258 | wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL ); | |
1259 | if (sb && sb->IsShown()) | |
1260 | { | |
1261 | height = sb->GetSize().y; | |
1262 | y = sb->GetPosition().y; | |
7de59551 | 1263 | |
a17a79ba RR |
1264 | sb = window->GetScrollbar( wxVERTICAL ); |
1265 | if (sb && sb->IsShown()) | |
1266 | { | |
1267 | width = sb->GetSize().x; | |
1268 | x = sb->GetPosition().x; | |
1269 | ||
1270 | Display *xdisplay = wxGlobalDisplay(); | |
679918f9 | 1271 | Window xwindow = (Window) X11GetMainWindow(); |
a17a79ba RR |
1272 | Colormap cm = (Colormap) wxTheApp->GetMainColormap( wxGetDisplay() ); |
1273 | wxColour colour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); | |
1274 | colour.CalcPixel( (WXColormap) cm ); | |
7de59551 | 1275 | |
a17a79ba | 1276 | XSetForeground( xdisplay, g_eraseGC, colour.GetPixel() ); |
7de59551 | 1277 | |
a17a79ba RR |
1278 | XFillRectangle( xdisplay, xwindow, g_eraseGC, x, y, width, height ); |
1279 | } | |
1280 | } | |
7de59551 | 1281 | |
ab6b6b15 RR |
1282 | wxNcPaintEvent nc_paint_event( GetId() ); |
1283 | nc_paint_event.SetEventObject( this ); | |
937013e0 | 1284 | HandleWindowEvent( nc_paint_event ); |
7de59551 | 1285 | |
ffd84c94 | 1286 | m_updateNcArea = false; |
ab6b6b15 RR |
1287 | } |
1288 | ||
83df96d6 JS |
1289 | // ---------------------------------------------------------------------------- |
1290 | // event handlers | |
1291 | // ---------------------------------------------------------------------------- | |
1292 | ||
1293 | // Responds to colour changes: passes event on to children. | |
bc797f4c | 1294 | void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event) |
83df96d6 | 1295 | { |
ac32ba44 | 1296 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
83df96d6 JS |
1297 | while ( node ) |
1298 | { | |
1299 | // Only propagate to non-top-level windows | |
1300 | wxWindow *win = node->GetData(); | |
1301 | if ( win->GetParent() ) | |
1302 | { | |
1303 | wxSysColourChangedEvent event2; | |
687706f5 | 1304 | event.SetEventObject(win); |
937013e0 | 1305 | win->HandleWindowEvent(event2); |
83df96d6 JS |
1306 | } |
1307 | ||
1308 | node = node->GetNext(); | |
1309 | } | |
1310 | } | |
1311 | ||
58ec2255 JS |
1312 | // See handler for InFocus case in app.cpp for details. |
1313 | wxWindow* g_GettingFocus = NULL; | |
1314 | ||
0d1dff01 | 1315 | void wxWindowX11::OnInternalIdle() |
83df96d6 | 1316 | { |
0d1dff01 RR |
1317 | // Update invalidated regions. |
1318 | Update(); | |
7de59551 | 1319 | |
83df96d6 JS |
1320 | // This calls the UI-update mechanism (querying windows for |
1321 | // menu/toolbar/control state information) | |
df707c27 | 1322 | if (wxUpdateUIEvent::CanUpdate((wxWindow*) this) && IsShownOnScreen()) |
e39af974 | 1323 | UpdateWindowUI(wxUPDATE_UI_FROMIDLE); |
3a0b23eb JS |
1324 | |
1325 | // Set the input focus if couldn't do it before | |
1326 | if (m_needsInputFocus) | |
ff6b424a | 1327 | { |
4cae9a20 JS |
1328 | #if 0 |
1329 | wxString msg; | |
1330 | msg.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName()); | |
1331 | printf(msg.c_str()); | |
2b5f62a0 VZ |
1332 | #endif |
1333 | SetFocus(); | |
7de59551 | 1334 | |
4cae9a20 JS |
1335 | // If it couldn't set the focus now, there's |
1336 | // no point in trying again. | |
ffd84c94 | 1337 | m_needsInputFocus = false; |
ff6b424a | 1338 | } |
58ec2255 | 1339 | g_GettingFocus = NULL; |
83df96d6 JS |
1340 | } |
1341 | ||
83df96d6 | 1342 | // ---------------------------------------------------------------------------- |
77ffb593 | 1343 | // function which maintain the global hash table mapping Widgets to wxWidgets |
83df96d6 JS |
1344 | // ---------------------------------------------------------------------------- |
1345 | ||
b8033a5d | 1346 | static bool DoAddWindowToTable(wxWindowHash *hash, Window w, wxWindow *win) |
83df96d6 | 1347 | { |
b8033a5d | 1348 | if ( !hash->insert(wxWindowHash::value_type(w, win)).second ) |
83df96d6 | 1349 | { |
b8033a5d VZ |
1350 | wxLogDebug( wxT("Widget table clash: new widget is 0x%08x, %s"), |
1351 | (unsigned int)w, win->GetClassInfo()->GetClassName()); | |
ffd84c94 | 1352 | return false; |
83df96d6 JS |
1353 | } |
1354 | ||
2b5f62a0 VZ |
1355 | wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"), |
1356 | (unsigned int) w, win, win->GetClassInfo()->GetClassName()); | |
83df96d6 | 1357 | |
ffd84c94 | 1358 | return true; |
83df96d6 JS |
1359 | } |
1360 | ||
b8033a5d | 1361 | static inline wxWindow *DoGetWindowFromTable(wxWindowHash *hash, Window w) |
83df96d6 | 1362 | { |
b8033a5d VZ |
1363 | wxWindowHash::iterator i = hash->find(w); |
1364 | return i == hash->end() ? NULL : i->second; | |
83df96d6 JS |
1365 | } |
1366 | ||
b8033a5d | 1367 | static inline void DoDeleteWindowFromTable(wxWindowHash *hash, Window w) |
83df96d6 | 1368 | { |
b8033a5d VZ |
1369 | wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x deleted"), (unsigned int) w); |
1370 | ||
1371 | hash->erase(w); | |
83df96d6 JS |
1372 | } |
1373 | ||
1374 | // ---------------------------------------------------------------------------- | |
b8033a5d | 1375 | // public wrappers |
83df96d6 JS |
1376 | // ---------------------------------------------------------------------------- |
1377 | ||
b8033a5d | 1378 | bool wxAddWindowToTable(Window w, wxWindow *win) |
ab6b6b15 | 1379 | { |
b8033a5d VZ |
1380 | return DoAddWindowToTable(wxWidgetHashTable, w, win); |
1381 | } | |
ab6b6b15 | 1382 | |
b8033a5d VZ |
1383 | wxWindow *wxGetWindowFromTable(Window w) |
1384 | { | |
1385 | return DoGetWindowFromTable(wxWidgetHashTable, w); | |
1386 | } | |
ab6b6b15 | 1387 | |
b8033a5d VZ |
1388 | void wxDeleteWindowFromTable(Window w) |
1389 | { | |
1390 | DoDeleteWindowFromTable(wxWidgetHashTable, w); | |
1391 | } | |
83df96d6 | 1392 | |
b8033a5d VZ |
1393 | bool wxAddClientWindowToTable(Window w, wxWindow *win) |
1394 | { | |
1395 | return DoAddWindowToTable(wxClientWidgetHashTable, w, win); | |
ab6b6b15 RR |
1396 | } |
1397 | ||
1398 | wxWindow *wxGetClientWindowFromTable(Window w) | |
83df96d6 | 1399 | { |
b8033a5d | 1400 | return DoGetWindowFromTable(wxClientWidgetHashTable, w); |
83df96d6 JS |
1401 | } |
1402 | ||
ab6b6b15 | 1403 | void wxDeleteClientWindowFromTable(Window w) |
83df96d6 | 1404 | { |
b8033a5d | 1405 | DoDeleteWindowFromTable(wxClientWidgetHashTable, w); |
83df96d6 JS |
1406 | } |
1407 | ||
ab6b6b15 RR |
1408 | // ---------------------------------------------------------------------------- |
1409 | // X11-specific accessors | |
1410 | // ---------------------------------------------------------------------------- | |
1411 | ||
679918f9 | 1412 | WXWindow wxWindowX11::X11GetMainWindow() const |
83df96d6 | 1413 | { |
ab6b6b15 RR |
1414 | return m_mainWindow; |
1415 | } | |
1416 | ||
f41bc3e3 | 1417 | WXWindow wxWindowX11::GetClientAreaWindow() const |
ab6b6b15 RR |
1418 | { |
1419 | return m_clientWindow; | |
83df96d6 JS |
1420 | } |
1421 | ||
83df96d6 JS |
1422 | // ---------------------------------------------------------------------------- |
1423 | // TranslateXXXEvent() functions | |
1424 | // ---------------------------------------------------------------------------- | |
1425 | ||
89954433 VZ |
1426 | bool wxTranslateMouseEvent(wxMouseEvent& wxevent, |
1427 | wxWindow *win, | |
1428 | Window WXUNUSED(window), | |
1429 | XEvent *xevent) | |
83df96d6 | 1430 | { |
461e93f9 | 1431 | switch (XEventGetType(xevent)) |
83df96d6 | 1432 | { |
1b0fb34b JS |
1433 | case EnterNotify: |
1434 | case LeaveNotify: | |
83df96d6 JS |
1435 | case ButtonPress: |
1436 | case ButtonRelease: | |
1437 | case MotionNotify: | |
1438 | { | |
1439 | wxEventType eventType = wxEVT_NULL; | |
1440 | ||
461e93f9 | 1441 | if (XEventGetType(xevent) == EnterNotify) |
83df96d6 | 1442 | { |
1b0fb34b JS |
1443 | //if (local_event.xcrossing.mode!=NotifyNormal) |
1444 | // return ; // Ignore grab events | |
1445 | eventType = wxEVT_ENTER_WINDOW; | |
1446 | // canvas->GetEventHandler()->OnSetFocus(); | |
1447 | } | |
461e93f9 | 1448 | else if (XEventGetType(xevent) == LeaveNotify) |
1b0fb34b JS |
1449 | { |
1450 | //if (local_event.xcrossingr.mode!=NotifyNormal) | |
1451 | // return ; // Ignore grab events | |
1452 | eventType = wxEVT_LEAVE_WINDOW; | |
1453 | // canvas->GetEventHandler()->OnKillFocus(); | |
83df96d6 | 1454 | } |
461e93f9 | 1455 | else if (XEventGetType(xevent) == MotionNotify) |
83df96d6 JS |
1456 | { |
1457 | eventType = wxEVT_MOTION; | |
1458 | } | |
461e93f9 | 1459 | else if (XEventGetType(xevent) == ButtonPress) |
83df96d6 | 1460 | { |
461e93f9 | 1461 | wxevent.SetTimestamp(XButtonEventGetTime(xevent)); |
83df96d6 | 1462 | int button = 0; |
461e93f9 | 1463 | if (XButtonEventLChanged(xevent)) |
83df96d6 JS |
1464 | { |
1465 | eventType = wxEVT_LEFT_DOWN; | |
83df96d6 JS |
1466 | button = 1; |
1467 | } | |
461e93f9 | 1468 | else if (XButtonEventMChanged(xevent)) |
83df96d6 JS |
1469 | { |
1470 | eventType = wxEVT_MIDDLE_DOWN; | |
83df96d6 JS |
1471 | button = 2; |
1472 | } | |
461e93f9 | 1473 | else if (XButtonEventRChanged(xevent)) |
83df96d6 JS |
1474 | { |
1475 | eventType = wxEVT_RIGHT_DOWN; | |
83df96d6 JS |
1476 | button = 3; |
1477 | } | |
2cdb6fdb VZ |
1478 | else if ( xevent->xbutton.button == Button4 || |
1479 | xevent->xbutton.button == Button5 ) | |
1480 | { | |
1481 | // this is the same value as used under wxMSW | |
1482 | static const int WHEEL_DELTA = 120; | |
1483 | ||
1484 | eventType = wxEVT_MOUSEWHEEL; | |
1485 | button = xevent->xbutton.button; | |
1486 | ||
1487 | wxevent.m_linesPerAction = 3; | |
1488 | wxevent.m_wheelDelta = WHEEL_DELTA; | |
1489 | ||
1490 | // Button 4 means mousewheel up, 5 means down | |
1491 | wxevent.m_wheelRotation = button == Button4 ? WHEEL_DELTA | |
1492 | : -WHEEL_DELTA; | |
1493 | } | |
83df96d6 JS |
1494 | |
1495 | // check for a double click | |
1b0fb34b | 1496 | // TODO: where can we get this value from? |
b513212d | 1497 | //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay()); |
7266b672 | 1498 | long dclickTime = 200; |
83df96d6 JS |
1499 | long ts = wxevent.GetTimestamp(); |
1500 | ||
1501 | int buttonLast = win->GetLastClickedButton(); | |
1502 | long lastTS = win->GetLastClickTime(); | |
1503 | if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime ) | |
1504 | { | |
1505 | // I have a dclick | |
1506 | win->SetLastClick(0, ts); | |
1507 | if ( eventType == wxEVT_LEFT_DOWN ) | |
1508 | eventType = wxEVT_LEFT_DCLICK; | |
1509 | else if ( eventType == wxEVT_MIDDLE_DOWN ) | |
1510 | eventType = wxEVT_MIDDLE_DCLICK; | |
1511 | else if ( eventType == wxEVT_RIGHT_DOWN ) | |
1512 | eventType = wxEVT_RIGHT_DCLICK; | |
1513 | } | |
1514 | else | |
1515 | { | |
1516 | // not fast enough or different button | |
1517 | win->SetLastClick(button, ts); | |
1518 | } | |
1519 | } | |
461e93f9 | 1520 | else if (XEventGetType(xevent) == ButtonRelease) |
83df96d6 | 1521 | { |
461e93f9 | 1522 | if (XButtonEventLChanged(xevent)) |
83df96d6 JS |
1523 | { |
1524 | eventType = wxEVT_LEFT_UP; | |
83df96d6 | 1525 | } |
461e93f9 | 1526 | else if (XButtonEventMChanged(xevent)) |
83df96d6 JS |
1527 | { |
1528 | eventType = wxEVT_MIDDLE_UP; | |
83df96d6 | 1529 | } |
461e93f9 | 1530 | else if (XButtonEventRChanged(xevent)) |
83df96d6 JS |
1531 | { |
1532 | eventType = wxEVT_RIGHT_UP; | |
83df96d6 | 1533 | } |
ffd84c94 | 1534 | else return false; |
83df96d6 JS |
1535 | } |
1536 | else | |
1537 | { | |
ffd84c94 | 1538 | return false; |
83df96d6 JS |
1539 | } |
1540 | ||
1541 | wxevent.SetEventType(eventType); | |
1542 | ||
461e93f9 JS |
1543 | wxevent.m_x = XButtonEventGetX(xevent); |
1544 | wxevent.m_y = XButtonEventGetY(xevent); | |
83df96d6 JS |
1545 | |
1546 | wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN) | |
461e93f9 | 1547 | || (XButtonEventLIsDown(xevent) |
83df96d6 JS |
1548 | && (eventType != wxEVT_LEFT_UP))); |
1549 | wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN) | |
461e93f9 | 1550 | || (XButtonEventMIsDown(xevent) |
83df96d6 JS |
1551 | && (eventType != wxEVT_MIDDLE_UP))); |
1552 | wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN) | |
461e93f9 | 1553 | || (XButtonEventRIsDown (xevent) |
83df96d6 JS |
1554 | && (eventType != wxEVT_RIGHT_UP))); |
1555 | ||
461e93f9 JS |
1556 | wxevent.m_shiftDown = XButtonEventShiftIsDown(xevent); |
1557 | wxevent.m_controlDown = XButtonEventCtrlIsDown(xevent); | |
1558 | wxevent.m_altDown = XButtonEventAltIsDown(xevent); | |
1559 | wxevent.m_metaDown = XButtonEventMetaIsDown(xevent); | |
83df96d6 JS |
1560 | |
1561 | wxevent.SetId(win->GetId()); | |
1562 | wxevent.SetEventObject(win); | |
1563 | ||
ffd84c94 | 1564 | return true; |
83df96d6 JS |
1565 | } |
1566 | } | |
ffd84c94 | 1567 | return false; |
83df96d6 JS |
1568 | } |
1569 | ||
2b5f62a0 | 1570 | bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win), XEvent *xevent, bool isAscii) |
83df96d6 | 1571 | { |
461e93f9 | 1572 | switch (XEventGetType(xevent)) |
83df96d6 JS |
1573 | { |
1574 | case KeyPress: | |
1575 | case KeyRelease: | |
1576 | { | |
1577 | char buf[20]; | |
1578 | ||
1579 | KeySym keySym; | |
83df96d6 JS |
1580 | (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL); |
1581 | int id = wxCharCodeXToWX (keySym); | |
2b5f62a0 VZ |
1582 | // id may be WXK_xxx code - these are outside ASCII range, so we |
1583 | // can't just use toupper() on id. | |
1584 | // Only change this if we want the raw key that was pressed, | |
1585 | // and don't change it if we want an ASCII value. | |
1586 | if (!isAscii && (id >= 'a' && id <= 'z')) | |
1587 | { | |
1588 | id = id + 'A' - 'a'; | |
1589 | } | |
83df96d6 | 1590 | |
461e93f9 JS |
1591 | wxevent.m_shiftDown = XKeyEventShiftIsDown(xevent); |
1592 | wxevent.m_controlDown = XKeyEventCtrlIsDown(xevent); | |
1593 | wxevent.m_altDown = XKeyEventAltIsDown(xevent); | |
1594 | wxevent.m_metaDown = XKeyEventMetaIsDown(xevent); | |
83df96d6 | 1595 | wxevent.SetEventObject(win); |
2b5f62a0 | 1596 | wxevent.m_keyCode = id; |
461e93f9 | 1597 | wxevent.SetTimestamp(XKeyEventGetTime(xevent)); |
83df96d6 | 1598 | |
461e93f9 JS |
1599 | wxevent.m_x = XKeyEventGetX(xevent); |
1600 | wxevent.m_y = XKeyEventGetY(xevent); | |
83df96d6 | 1601 | |
2b5f62a0 | 1602 | return id > -1; |
83df96d6 JS |
1603 | } |
1604 | default: | |
1605 | break; | |
1606 | } | |
ffd84c94 | 1607 | return false; |
83df96d6 JS |
1608 | } |
1609 | ||
1610 | // ---------------------------------------------------------------------------- | |
1611 | // Colour stuff | |
1612 | // ---------------------------------------------------------------------------- | |
1613 | ||
bc797f4c | 1614 | bool wxWindowX11::SetBackgroundColour(const wxColour& col) |
83df96d6 | 1615 | { |
56cb684a | 1616 | wxWindowBase::SetBackgroundColour(col); |
83df96d6 | 1617 | |
3cd0b8c5 RR |
1618 | Display *xdisplay = (Display*) wxGlobalDisplay(); |
1619 | int xscreen = DefaultScreen( xdisplay ); | |
1620 | Colormap cm = DefaultColormap( xdisplay, xscreen ); | |
1621 | ||
ba696cfa | 1622 | m_backgroundColour.CalcPixel( (WXColormap) cm ); |
7de59551 | 1623 | |
c2c0dabf RR |
1624 | // We don't set the background colour as we paint |
1625 | // the background ourselves. | |
1626 | // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() ); | |
7de59551 | 1627 | |
ffd84c94 | 1628 | return true; |
83df96d6 JS |
1629 | } |
1630 | ||
bc797f4c | 1631 | bool wxWindowX11::SetForegroundColour(const wxColour& col) |
83df96d6 JS |
1632 | { |
1633 | if ( !wxWindowBase::SetForegroundColour(col) ) | |
ffd84c94 | 1634 | return false; |
83df96d6 | 1635 | |
ffd84c94 | 1636 | return true; |
83df96d6 JS |
1637 | } |
1638 | ||
83df96d6 JS |
1639 | // ---------------------------------------------------------------------------- |
1640 | // global functions | |
1641 | // ---------------------------------------------------------------------------- | |
1642 | ||
1643 | wxWindow *wxGetActiveWindow() | |
1644 | { | |
2344c32b | 1645 | return wxGetTopLevelParent(wxWindow::FindFocus()); |
83df96d6 JS |
1646 | } |
1647 | ||
1648 | /* static */ | |
1649 | wxWindow *wxWindowBase::GetCapture() | |
1650 | { | |
1651 | return (wxWindow *)g_captureWindow; | |
1652 | } | |
1653 | ||
1654 | ||
1655 | // Find the wxWindow at the current mouse position, returning the mouse | |
1656 | // position. | |
1657 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) | |
1658 | { | |
89954433 VZ |
1659 | pt = wxGetMousePosition(); |
1660 | return wxFindWindowAtPoint(pt); | |
83df96d6 JS |
1661 | } |
1662 | ||
0cbc5287 | 1663 | void wxGetMouseState(int& rootX, int& rootY, unsigned& maskReturn) |
83df96d6 | 1664 | { |
461e93f9 JS |
1665 | #if wxUSE_NANOX |
1666 | /* TODO */ | |
0cbc5287 MW |
1667 | rootX = rootY = 0; |
1668 | maskReturn = 0; | |
461e93f9 | 1669 | #else |
b513212d | 1670 | Display *display = wxGlobalDisplay(); |
83df96d6 JS |
1671 | Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); |
1672 | Window rootReturn, childReturn; | |
0cbc5287 | 1673 | int winX, winY; |
83df96d6 JS |
1674 | |
1675 | XQueryPointer (display, | |
2b5f62a0 VZ |
1676 | rootWindow, |
1677 | &rootReturn, | |
83df96d6 JS |
1678 | &childReturn, |
1679 | &rootX, &rootY, &winX, &winY, &maskReturn); | |
461e93f9 | 1680 | #endif |
83df96d6 JS |
1681 | } |
1682 | ||
0cbc5287 MW |
1683 | // Get the current mouse position. |
1684 | wxPoint wxGetMousePosition() | |
1685 | { | |
1686 | int x, y; | |
1687 | unsigned mask; | |
1688 | ||
1689 | wxGetMouseState(x, y, mask); | |
1690 | return wxPoint(x, y); | |
1691 | } | |
1692 | ||
1693 | wxMouseState wxGetMouseState() | |
1694 | { | |
1695 | wxMouseState ms; | |
1696 | int x, y; | |
1697 | unsigned mask; | |
1698 | ||
1699 | wxGetMouseState(x, y, mask); | |
1700 | ||
1701 | ms.SetX(x); | |
1702 | ms.SetY(y); | |
1703 | ||
1704 | ms.SetLeftDown(mask & Button1Mask); | |
1705 | ms.SetMiddleDown(mask & Button2Mask); | |
1706 | ms.SetRightDown(mask & Button3Mask); | |
1707 | ||
1708 | ms.SetControlDown(mask & ControlMask); | |
1709 | ms.SetShiftDown(mask & ShiftMask); | |
af1a6227 MW |
1710 | ms.SetAltDown(mask & Mod3Mask); |
1711 | ms.SetMetaDown(mask & Mod1Mask); | |
0cbc5287 MW |
1712 | |
1713 | return ms; | |
1714 | } | |
1715 | ||
83df96d6 JS |
1716 | |
1717 | // ---------------------------------------------------------------------------- | |
1718 | // wxNoOptimize: switch off size optimization | |
1719 | // ---------------------------------------------------------------------------- | |
1720 | ||
1721 | int wxNoOptimize::ms_count = 0; | |
1722 | ||
c2c0dabf RR |
1723 | |
1724 | // ---------------------------------------------------------------------------- | |
1725 | // wxDCModule | |
1726 | // ---------------------------------------------------------------------------- | |
1727 | ||
1728 | class wxWinModule : public wxModule | |
1729 | { | |
1730 | public: | |
b886fae6 VZ |
1731 | wxWinModule() |
1732 | { | |
1733 | // we must be cleaned up before the display is closed | |
9a83f860 | 1734 | AddDependency(wxClassInfo::FindClass(wxT("wxX11DisplayModule"))); |
b886fae6 VZ |
1735 | } |
1736 | ||
1737 | virtual bool OnInit(); | |
1738 | virtual void OnExit(); | |
c2c0dabf RR |
1739 | |
1740 | private: | |
1741 | DECLARE_DYNAMIC_CLASS(wxWinModule) | |
1742 | }; | |
1743 | ||
1744 | IMPLEMENT_DYNAMIC_CLASS(wxWinModule, wxModule) | |
1745 | ||
1746 | bool wxWinModule::OnInit() | |
1747 | { | |
1748 | Display *xdisplay = wxGlobalDisplay(); | |
1749 | int xscreen = DefaultScreen( xdisplay ); | |
1750 | Window xroot = RootWindow( xdisplay, xscreen ); | |
1751 | g_eraseGC = XCreateGC( xdisplay, xroot, 0, NULL ); | |
1752 | XSetFillStyle( xdisplay, g_eraseGC, FillSolid ); | |
7de59551 | 1753 | |
ffd84c94 | 1754 | return true; |
c2c0dabf RR |
1755 | } |
1756 | ||
1757 | void wxWinModule::OnExit() | |
1758 | { | |
1759 | Display *xdisplay = wxGlobalDisplay(); | |
1760 | XFreeGC( xdisplay, g_eraseGC ); | |
1761 | } |