]>
Commit | Line | Data |
---|---|---|
83df96d6 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: windows.cpp | |
3 | // Purpose: wxWindow | |
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 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "window.h" | |
22 | #endif | |
23 | ||
83df96d6 JS |
24 | #include "wx/setup.h" |
25 | #include "wx/menu.h" | |
26 | #include "wx/dc.h" | |
27 | #include "wx/dcclient.h" | |
28 | #include "wx/utils.h" | |
29 | #include "wx/app.h" | |
30 | #include "wx/panel.h" | |
31 | #include "wx/layout.h" | |
32 | #include "wx/dialog.h" | |
33 | #include "wx/listbox.h" | |
34 | #include "wx/button.h" | |
35 | #include "wx/settings.h" | |
36 | #include "wx/msgdlg.h" | |
37 | #include "wx/frame.h" | |
38 | #include "wx/scrolwin.h" | |
39 | #include "wx/module.h" | |
40 | #include "wx/menuitem.h" | |
41 | #include "wx/log.h" | |
42 | ||
43 | #if wxUSE_DRAG_AND_DROP | |
44 | #include "wx/dnd.h" | |
45 | #endif | |
46 | ||
bc797f4c | 47 | #include "wx/x11/private.h" |
7266b672 | 48 | #include "X11/Xutil.h" |
83df96d6 | 49 | |
461e93f9 JS |
50 | #if wxUSE_NANOX |
51 | // For wxGetLocalTime, used by XButtonEventGetTime | |
52 | #include "wx/timer.h" | |
53 | #endif | |
54 | ||
83df96d6 JS |
55 | #include <string.h> |
56 | ||
83df96d6 JS |
57 | // ---------------------------------------------------------------------------- |
58 | // global variables for this module | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
61 | extern wxHashTable *wxWidgetHashTable; | |
62 | static wxWindow* g_captureWindow = NULL; | |
63 | ||
83df96d6 JS |
64 | // ---------------------------------------------------------------------------- |
65 | // macros | |
66 | // ---------------------------------------------------------------------------- | |
67 | ||
68 | #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask) | |
69 | #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask) | |
70 | #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask) | |
71 | ||
72 | // ---------------------------------------------------------------------------- | |
73 | // event tables | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
8354aa92 | 76 | IMPLEMENT_ABSTRACT_CLASS(wxWindowX11, wxWindowBase) |
83df96d6 | 77 | |
bc797f4c JS |
78 | BEGIN_EVENT_TABLE(wxWindowX11, wxWindowBase) |
79 | EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged) | |
bc797f4c | 80 | END_EVENT_TABLE() |
83df96d6 JS |
81 | |
82 | // ============================================================================ | |
83 | // implementation | |
84 | // ============================================================================ | |
85 | ||
86 | // ---------------------------------------------------------------------------- | |
87 | // helper functions | |
88 | // ---------------------------------------------------------------------------- | |
89 | ||
83df96d6 JS |
90 | // ---------------------------------------------------------------------------- |
91 | // constructors | |
92 | // ---------------------------------------------------------------------------- | |
93 | ||
bc797f4c | 94 | void wxWindowX11::Init() |
83df96d6 JS |
95 | { |
96 | // generic initializations first | |
97 | InitBase(); | |
98 | ||
7266b672 | 99 | // X11-specific |
7266b672 | 100 | m_mainWidget = (WXWindow) 0; |
83df96d6 | 101 | m_winCaptured = FALSE; |
3a0b23eb | 102 | m_needsInputFocus = FALSE; |
83df96d6 JS |
103 | m_isShown = TRUE; |
104 | m_isBeingDeleted = FALSE; | |
83df96d6 JS |
105 | m_lastTS = 0; |
106 | m_lastButton = 0; | |
83df96d6 JS |
107 | } |
108 | ||
109 | // real construction (Init() must have been called before!) | |
bc797f4c | 110 | bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, |
83df96d6 JS |
111 | const wxPoint& pos, |
112 | const wxSize& size, | |
113 | long style, | |
114 | const wxString& name) | |
115 | { | |
116 | wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" ); | |
117 | ||
118 | CreateBase(parent, id, pos, size, style, wxDefaultValidator, name); | |
119 | ||
3cd0b8c5 | 120 | parent->AddChild(this); |
83df96d6 | 121 | |
b513212d JS |
122 | int w = size.GetWidth(); |
123 | int h = size.GetHeight(); | |
124 | int x = size.GetX(); | |
125 | int y = size.GetY(); | |
178572bb RR |
126 | if (w == -1) w = 20; |
127 | if (h == -1) h = 20; | |
b513212d JS |
128 | if (x == -1) x = 0; |
129 | if (y == -1) y = 0; | |
83df96d6 | 130 | |
3cd0b8c5 RR |
131 | Display *xdisplay = (Display*) wxGlobalDisplay(); |
132 | int xscreen = DefaultScreen( xdisplay ); | |
7e4501ee | 133 | Visual *xvisual = DefaultVisual( xdisplay, xscreen ); |
3cd0b8c5 | 134 | Colormap cm = DefaultColormap( xdisplay, xscreen ); |
b513212d | 135 | |
3cd0b8c5 RR |
136 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
137 | m_backgroundColour.CalcPixel( (WXColormap) cm ); | |
138 | ||
139 | m_foregroundColour = *wxBLACK; | |
140 | m_foregroundColour.CalcPixel( (WXColormap) cm ); | |
3cd0b8c5 | 141 | |
7e4501ee | 142 | Window xparent = (Window) parent->GetMainWindow(); |
b513212d | 143 | |
461e93f9 | 144 | #if !wxUSE_NANOX |
7e4501ee RR |
145 | XSetWindowAttributes xattributes; |
146 | ||
147 | long xattributes_mask = | |
148 | CWEventMask | | |
149 | CWBorderPixel | CWBackPixel; | |
150 | ||
151 | xattributes.background_pixel = m_backgroundColour.GetPixel(); | |
152 | xattributes.border_pixel = BlackPixel( xdisplay, xscreen ); | |
153 | ||
154 | xattributes.event_mask = | |
155 | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
156 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
157 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
158 | PropertyChangeMask; | |
461e93f9 | 159 | #endif |
7e4501ee | 160 | |
15c69343 JS |
161 | wxSize size2(size); |
162 | if (size2.x == -1) | |
7e4501ee | 163 | size2.x = 20; |
15c69343 | 164 | if (size2.y == -1) |
7e4501ee | 165 | size2.y = 20; |
15c69343 JS |
166 | |
167 | wxPoint pos2(pos); | |
168 | if (pos2.x == -1) | |
7e4501ee | 169 | pos2.x = 0; |
15c69343 | 170 | if (pos2.y == -1) |
7e4501ee | 171 | pos2.y = 0; |
15c69343 | 172 | |
461e93f9 JS |
173 | #if wxUSE_NANOX |
174 | int extraFlags = GR_EVENT_MASK_CLOSE_REQ; | |
175 | ||
176 | long backColor, foreColor; | |
177 | backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()); | |
178 | foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue()); | |
179 | ||
180 | Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, | |
181 | 0, 0, InputOutput, xvisual, backColor, foreColor); | |
182 | XSelectInput( xdisplay, xwindow, | |
183 | extraFlags | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | | |
184 | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | | |
185 | KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | | |
186 | PropertyChangeMask ); | |
187 | ||
188 | #else | |
189 | ||
7e4501ee RR |
190 | Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, |
191 | 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); | |
461e93f9 JS |
192 | |
193 | #endif | |
194 | ||
ba696cfa | 195 | m_mainWidget = (WXWindow) xwindow; |
b513212d | 196 | |
ba696cfa | 197 | wxAddWindowToTable( xwindow, (wxWindow*) this ); |
b513212d | 198 | |
b28d3abf JS |
199 | // Is a subwindow, so map immediately |
200 | m_isShown = TRUE; | |
ba696cfa | 201 | XMapWindow( xdisplay, xwindow ); |
83df96d6 JS |
202 | |
203 | // Without this, the cursor may not be restored properly (e.g. in splitter | |
204 | // sample). | |
205 | SetCursor(*wxSTANDARD_CURSOR); | |
206 | SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
ba696cfa RR |
207 | |
208 | // Set background to None which will prevent X11 from clearing the | |
209 | // background comletely. | |
210 | XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); | |
15c69343 JS |
211 | |
212 | // Don't call this, it can have nasty repercussions for composite controls, | |
213 | // for example | |
214 | // SetSize(pos.x, pos.y, size.x, size.y); | |
83df96d6 JS |
215 | |
216 | return TRUE; | |
217 | } | |
218 | ||
219 | // Destructor | |
7266b672 | 220 | wxWindowX11::~wxWindowX11() |
83df96d6 JS |
221 | { |
222 | if (g_captureWindow == this) | |
223 | g_captureWindow = NULL; | |
224 | ||
225 | m_isBeingDeleted = TRUE; | |
226 | ||
7266b672 | 227 | // X11-specific actions first |
7e4501ee | 228 | Window xwindow = (Window) m_mainWidget; |
83df96d6 | 229 | |
d02cb44e | 230 | if (m_parent) |
83df96d6 JS |
231 | m_parent->RemoveChild( this ); |
232 | ||
d02cb44e | 233 | DestroyChildren(); |
83df96d6 JS |
234 | |
235 | // Destroy the window | |
7e4501ee | 236 | if (xwindow) |
83df96d6 | 237 | { |
7e4501ee RR |
238 | XSelectInput( wxGlobalDisplay(), xwindow, NoEventMask); |
239 | wxDeleteWindowFromTable( xwindow ); | |
240 | XDestroyWindow( wxGlobalDisplay(), xwindow ); | |
d02cb44e | 241 | m_mainWidget = NULL; |
83df96d6 | 242 | } |
83df96d6 JS |
243 | } |
244 | ||
245 | // --------------------------------------------------------------------------- | |
246 | // basic operations | |
247 | // --------------------------------------------------------------------------- | |
248 | ||
bc797f4c | 249 | void wxWindowX11::SetFocus() |
83df96d6 | 250 | { |
86fd8bda RR |
251 | Window xwindow = (Window) GetMainWindow(); |
252 | ||
253 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
9b8270da RR |
254 | |
255 | wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") ); | |
256 | ||
257 | #if 0 | |
258 | if (GetName() == "scrollBar") | |
259 | { | |
260 | char *crash = NULL; | |
261 | *crash = 0; | |
262 | } | |
263 | #endif | |
264 | ||
3a0b23eb JS |
265 | if (wxWindowIsVisible(xwindow)) |
266 | { | |
79ad56d0 | 267 | XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime ); |
ba696cfa | 268 | m_needsInputFocus = FALSE; |
3a0b23eb JS |
269 | } |
270 | else | |
271 | { | |
ba696cfa | 272 | m_needsInputFocus = TRUE; |
3a0b23eb | 273 | } |
83df96d6 JS |
274 | } |
275 | ||
276 | // Get the window with the focus | |
277 | wxWindow *wxWindowBase::FindFocus() | |
278 | { | |
86fd8bda | 279 | Window xfocus = (Window) 0; |
b513212d | 280 | int revert = 0; |
bc797f4c | 281 | |
86fd8bda RR |
282 | XGetInputFocus( wxGlobalDisplay(), &xfocus, &revert); |
283 | if (xfocus) | |
83df96d6 | 284 | { |
86fd8bda | 285 | wxWindow *win = wxGetWindowFromTable( xfocus ); |
b513212d JS |
286 | |
287 | return win; | |
83df96d6 JS |
288 | } |
289 | ||
b513212d | 290 | return NULL; |
83df96d6 JS |
291 | } |
292 | ||
fc9be1cf RR |
293 | wxWindow *wxWindowX11::GetFocusWidget() |
294 | { | |
295 | wxWindow *win = (wxWindow*) this; | |
296 | while (!win->IsTopLevel()) | |
297 | { | |
298 | win = win->GetParent(); | |
299 | if (!win) | |
300 | return (wxWindow*) NULL; | |
301 | } | |
302 | ||
303 | return win; | |
304 | } | |
305 | ||
b513212d JS |
306 | // Enabling/disabling handled by event loop, and not sending events |
307 | // if disabled. | |
bc797f4c | 308 | bool wxWindowX11::Enable(bool enable) |
83df96d6 JS |
309 | { |
310 | if ( !wxWindowBase::Enable(enable) ) | |
311 | return FALSE; | |
b513212d | 312 | |
83df96d6 JS |
313 | return TRUE; |
314 | } | |
315 | ||
bc797f4c | 316 | bool wxWindowX11::Show(bool show) |
83df96d6 | 317 | { |
7edcafa4 | 318 | wxWindowBase::Show(show); |
83df96d6 | 319 | |
83df96d6 JS |
320 | Window xwin = (Window) GetXWindow(); |
321 | Display *xdisp = (Display*) GetXDisplay(); | |
322 | if (show) | |
b513212d | 323 | { |
7e4501ee | 324 | // wxLogDebug( "Mapping window of type %s", GetName().c_str() ); |
83df96d6 | 325 | XMapWindow(xdisp, xwin); |
256d631a | 326 | XSync(xdisp, False); |
b513212d | 327 | } |
83df96d6 | 328 | else |
b513212d | 329 | { |
7e4501ee | 330 | // wxLogDebug( "Unmapping window of type %s", GetName().c_str() ); |
83df96d6 | 331 | XUnmapWindow(xdisp, xwin); |
b513212d | 332 | } |
83df96d6 JS |
333 | |
334 | return TRUE; | |
335 | } | |
336 | ||
337 | // Raise the window to the top of the Z order | |
bc797f4c | 338 | void wxWindowX11::Raise() |
83df96d6 | 339 | { |
d02cb44e RR |
340 | if (m_mainWidget) |
341 | XRaiseWindow( wxGlobalDisplay(), (Window) m_mainWidget ); | |
83df96d6 JS |
342 | } |
343 | ||
344 | // Lower the window to the bottom of the Z order | |
bc797f4c | 345 | void wxWindowX11::Lower() |
83df96d6 | 346 | { |
d02cb44e RR |
347 | if (m_mainWidget) |
348 | XLowerWindow( wxGlobalDisplay(), (Window) m_mainWidget ); | |
83df96d6 JS |
349 | } |
350 | ||
bc797f4c | 351 | void wxWindowX11::DoCaptureMouse() |
83df96d6 | 352 | { |
7edcafa4 JS |
353 | if ((g_captureWindow != NULL) && (g_captureWindow != this)) |
354 | { | |
346d4fcd | 355 | wxASSERT_MSG(FALSE, "Trying to capture before mouse released."); |
7edcafa4 | 356 | |
346d4fcd RR |
357 | // Core dump now |
358 | int *tmp = NULL; | |
359 | (*tmp) = 1; | |
360 | return; | |
7edcafa4 JS |
361 | } |
362 | ||
346d4fcd | 363 | if (m_winCaptured) |
83df96d6 JS |
364 | return; |
365 | ||
346d4fcd RR |
366 | Window xwindow = (Window) GetMainWindow(); |
367 | ||
86fd8bda RR |
368 | wxCHECK_RET( xwindow, wxT("invalid window") ); |
369 | ||
7edcafa4 JS |
370 | g_captureWindow = (wxWindow*) this; |
371 | ||
346d4fcd | 372 | if (xwindow) |
b513212d | 373 | { |
346d4fcd | 374 | int res = XGrabPointer(wxGlobalDisplay(), xwindow, |
b513212d JS |
375 | FALSE, |
376 | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, | |
377 | GrabModeAsync, | |
378 | GrabModeAsync, | |
379 | None, | |
380 | None, /* cursor */ // TODO: This may need to be set to the cursor of this window | |
346d4fcd | 381 | CurrentTime ); |
b513212d | 382 | |
b28d3abf | 383 | if (res != GrabSuccess) |
b513212d | 384 | { |
346d4fcd RR |
385 | wxString msg; |
386 | msg.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName()); | |
387 | wxLogDebug(msg); | |
388 | if (res == GrabNotViewable) | |
389 | { | |
390 | wxLogDebug("This is not a viewable window - perhaps not shown yet?"); | |
391 | } | |
392 | g_captureWindow = NULL; | |
b28d3abf | 393 | return; |
b513212d | 394 | } |
346d4fcd | 395 | |
9691c806 | 396 | // wxLogDebug("Grabbed pointer in %s", GetName().c_str() ); |
b28d3abf | 397 | |
7edcafa4 | 398 | #if 0 |
b28d3abf JS |
399 | res = XGrabButton(wxGlobalDisplay(), AnyButton, AnyModifier, |
400 | (Window) GetMainWindow(), | |
401 | FALSE, | |
402 | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, | |
403 | GrabModeAsync, | |
404 | GrabModeAsync, | |
405 | None, | |
406 | None); | |
7edcafa4 | 407 | |
b28d3abf JS |
408 | if (res != GrabSuccess) |
409 | { | |
410 | wxLogDebug("Failed to grab mouse buttons."); | |
411 | XUngrabPointer(wxGlobalDisplay(), CurrentTime); | |
412 | return; | |
413 | } | |
7edcafa4 | 414 | #endif |
b28d3abf | 415 | |
7edcafa4 | 416 | #if 0 |
b28d3abf | 417 | res = XGrabKeyboard(wxGlobalDisplay(), (Window) GetMainWindow(), |
1b0b798d | 418 | ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask, |
b28d3abf | 419 | FALSE, |
b28d3abf JS |
420 | GrabModeAsync, |
421 | GrabModeAsync, | |
422 | CurrentTime); | |
423 | ||
424 | if (res != GrabSuccess) | |
425 | { | |
426 | wxLogDebug("Failed to grab keyboard."); | |
427 | XUngrabPointer(wxGlobalDisplay(), CurrentTime); | |
428 | XUngrabButton(wxGlobalDisplay(), AnyButton, AnyModifier, | |
429 | (Window) GetMainWindow()); | |
430 | return; | |
431 | } | |
7edcafa4 JS |
432 | #endif |
433 | ||
b28d3abf | 434 | m_winCaptured = TRUE; |
b513212d | 435 | } |
83df96d6 JS |
436 | } |
437 | ||
bc797f4c | 438 | void wxWindowX11::DoReleaseMouse() |
83df96d6 JS |
439 | { |
440 | g_captureWindow = NULL; | |
346d4fcd | 441 | |
83df96d6 JS |
442 | if ( !m_winCaptured ) |
443 | return; | |
444 | ||
346d4fcd | 445 | Window xwindow = (Window) GetMainWindow(); |
b513212d | 446 | |
346d4fcd | 447 | if (xwindow) |
b28d3abf | 448 | { |
346d4fcd | 449 | XUngrabPointer( wxGlobalDisplay(), CurrentTime ); |
7edcafa4 | 450 | #if 0 |
346d4fcd RR |
451 | XUngrabButton( wxGlobalDisplay(), AnyButton, AnyModifier, xwindow); |
452 | XUngrabKeyboard( wxGlobalDisplay(), CurrentTime ); | |
7edcafa4 | 453 | #endif |
b28d3abf | 454 | } |
887dd52f | 455 | |
9691c806 | 456 | // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() ); |
83df96d6 JS |
457 | |
458 | m_winCaptured = FALSE; | |
459 | } | |
460 | ||
bc797f4c | 461 | bool wxWindowX11::SetFont(const wxFont& font) |
83df96d6 JS |
462 | { |
463 | if ( !wxWindowBase::SetFont(font) ) | |
464 | { | |
465 | // nothing to do | |
466 | return FALSE; | |
467 | } | |
468 | ||
83df96d6 JS |
469 | return TRUE; |
470 | } | |
471 | ||
bc797f4c | 472 | bool wxWindowX11::SetCursor(const wxCursor& cursor) |
83df96d6 JS |
473 | { |
474 | if ( !wxWindowBase::SetCursor(cursor) ) | |
475 | { | |
476 | // no change | |
477 | return FALSE; | |
478 | } | |
479 | ||
86fd8bda RR |
480 | Window xwindow = (Window) GetMainWindow(); |
481 | ||
482 | wxCHECK_MSG( xwindow, FALSE, wxT("invalid window") ); | |
483 | ||
484 | wxCursor cursorToUse; | |
83df96d6 | 485 | if (m_cursor.Ok()) |
86fd8bda | 486 | cursorToUse = m_cursor; |
83df96d6 | 487 | else |
86fd8bda | 488 | cursorToUse = *wxSTANDARD_CURSOR; |
83df96d6 | 489 | |
86fd8bda | 490 | Cursor xcursor = (Cursor) cursorToUse.GetCursor(); |
83df96d6 | 491 | |
e88be8c9 | 492 | XDefineCursor( wxGlobalDisplay(), xwindow, xcursor ); |
83df96d6 JS |
493 | |
494 | return TRUE; | |
495 | } | |
496 | ||
497 | // Coordinates relative to the window | |
bc797f4c | 498 | void wxWindowX11::WarpPointer (int x, int y) |
83df96d6 | 499 | { |
86fd8bda RR |
500 | Window xwindow = (Window) GetMainWindow(); |
501 | ||
502 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
503 | ||
504 | XWarpPointer( wxGlobalDisplay(), None, xwindow, 0, 0, 0, 0, x, y); | |
83df96d6 JS |
505 | } |
506 | ||
83df96d6 | 507 | // Does a physical scroll |
bc797f4c | 508 | void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) |
83df96d6 | 509 | { |
fc9be1cf RR |
510 | // No scrolling requested. |
511 | if ((dx == 0) && (dy == 0)) return; | |
512 | ||
513 | if (!m_updateRegion.IsEmpty()) | |
514 | { | |
515 | m_updateRegion.Offset( dx, dy ); | |
516 | ||
517 | int cw = 0; | |
518 | int ch = 0; | |
519 | GetSize( &cw, &ch ); // GetClientSize() ?? | |
520 | m_updateRegion.Intersect( 0, 0, cw, ch ); | |
521 | } | |
522 | ||
523 | if (!m_clearRegion.IsEmpty()) | |
524 | { | |
525 | m_clearRegion.Offset( dx, dy ); | |
526 | ||
527 | int cw = 0; | |
528 | int ch = 0; | |
529 | GetSize( &cw, &ch ); // GetClientSize() ?? | |
530 | m_clearRegion.Intersect( 0, 0, cw, ch ); | |
531 | } | |
532 | ||
7e085304 RR |
533 | Window xwindow = (Window) GetMainWindow(); |
534 | ||
535 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
536 | ||
537 | Display *xdisplay = wxGlobalDisplay(); | |
538 | ||
539 | GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL ); | |
540 | XSetGraphicsExposures( xdisplay, xgc, True ); | |
541 | ||
e88be8c9 RR |
542 | int s_x = 0; |
543 | int s_y = 0; | |
4125131b RR |
544 | int cw; |
545 | int ch; | |
546 | if (rect) | |
547 | { | |
548 | s_x = rect->x; | |
549 | s_y = rect->y; | |
e88be8c9 | 550 | |
4125131b RR |
551 | cw = rect->width; |
552 | ch = rect->height; | |
553 | } | |
554 | else | |
555 | { | |
556 | s_x = 0; | |
557 | s_y = 0; | |
558 | GetClientSize( &cw, &ch ); | |
559 | } | |
560 | ||
561 | wxPoint offset = GetClientAreaOrigin(); | |
562 | s_x += offset.x; | |
563 | s_y += offset.y; | |
e88be8c9 | 564 | |
7e085304 RR |
565 | int w = cw - abs(dx); |
566 | int h = ch - abs(dy); | |
4125131b | 567 | |
7e085304 | 568 | if ((h < 0) || (w < 0)) |
83df96d6 | 569 | { |
7e085304 | 570 | Refresh(); |
83df96d6 JS |
571 | } |
572 | else | |
573 | { | |
4125131b | 574 | wxRect rect; |
f809133f RR |
575 | if (dx < 0) rect.x = cw+dx + offset.x; else rect.x = s_x; |
576 | if (dy < 0) rect.y = ch+dy + offset.y; else rect.y = s_y; | |
4125131b RR |
577 | if (dy != 0) rect.width = cw; else rect.width = abs(dx); |
578 | if (dx != 0) rect.height = ch; else rect.height = abs(dy); | |
579 | ||
580 | int d_x = s_x; | |
581 | int d_y = s_y; | |
e88be8c9 | 582 | |
4125131b RR |
583 | if (dx < 0) s_x += -dx; |
584 | if (dy < 0) s_y += -dy; | |
e88be8c9 RR |
585 | if (dx > 0) d_x = dx + offset.x; |
586 | if (dy > 0) d_y = dy + offset.y; | |
7e085304 RR |
587 | |
588 | XCopyArea( xdisplay, xwindow, xwindow, xgc, s_x, s_y, w, h, d_x, d_y ); | |
4125131b | 589 | |
e88be8c9 | 590 | // 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 | 591 | |
e88be8c9 | 592 | // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height ); |
7e085304 RR |
593 | |
594 | m_updateRegion.Union( rect ); | |
595 | m_clearRegion.Union( rect ); | |
83df96d6 | 596 | } |
bc797f4c | 597 | |
7e085304 | 598 | XFreeGC( xdisplay, xgc ); |
83df96d6 JS |
599 | } |
600 | ||
601 | // --------------------------------------------------------------------------- | |
602 | // drag and drop | |
603 | // --------------------------------------------------------------------------- | |
604 | ||
605 | #if wxUSE_DRAG_AND_DROP | |
606 | ||
bc797f4c | 607 | void wxWindowX11::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget)) |
83df96d6 JS |
608 | { |
609 | // TODO | |
610 | } | |
611 | ||
612 | #endif | |
613 | ||
614 | // Old style file-manager drag&drop | |
bc797f4c | 615 | void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept)) |
83df96d6 JS |
616 | { |
617 | // TODO | |
618 | } | |
619 | ||
620 | // ---------------------------------------------------------------------------- | |
621 | // tooltips | |
622 | // ---------------------------------------------------------------------------- | |
623 | ||
624 | #if wxUSE_TOOLTIPS | |
625 | ||
bc797f4c | 626 | void wxWindowX11::DoSetToolTip(wxToolTip * WXUNUSED(tooltip)) |
83df96d6 JS |
627 | { |
628 | // TODO | |
629 | } | |
630 | ||
631 | #endif // wxUSE_TOOLTIPS | |
632 | ||
83df96d6 JS |
633 | // --------------------------------------------------------------------------- |
634 | // moving and resizing | |
635 | // --------------------------------------------------------------------------- | |
636 | ||
bc797f4c | 637 | bool wxWindowX11::PreResize() |
83df96d6 JS |
638 | { |
639 | return TRUE; | |
640 | } | |
641 | ||
642 | // Get total size | |
bc797f4c | 643 | void wxWindowX11::DoGetSize(int *x, int *y) const |
83df96d6 | 644 | { |
86fd8bda RR |
645 | Window xwindow = (Window) GetMainWindow(); |
646 | ||
647 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
648 | ||
9d2cef1c | 649 | // XSync(wxGlobalDisplay(), False); |
e941874b | 650 | |
86fd8bda RR |
651 | XWindowAttributes attr; |
652 | Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); | |
653 | wxASSERT(status); | |
b513212d | 654 | |
86fd8bda RR |
655 | if (status) |
656 | { | |
657 | *x = attr.width /* + 2*m_borderSize */ ; | |
658 | *y = attr.height /* + 2*m_borderSize */ ; | |
83df96d6 | 659 | } |
83df96d6 JS |
660 | } |
661 | ||
bc797f4c | 662 | void wxWindowX11::DoGetPosition(int *x, int *y) const |
83df96d6 | 663 | { |
d02cb44e | 664 | Window window = (Window) m_mainWidget; |
b513212d | 665 | if (window) |
83df96d6 | 666 | { |
9d2cef1c | 667 | // XSync(wxGlobalDisplay(), False); |
b513212d JS |
668 | XWindowAttributes attr; |
669 | Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); | |
670 | wxASSERT(status); | |
671 | ||
672 | if (status) | |
673 | { | |
674 | *x = attr.x; | |
675 | *y = attr.y; | |
676 | ||
677 | // We may be faking the client origin. So a window that's really at (0, 30) | |
678 | // may appear (to wxWin apps) to be at (0, 0). | |
679 | if (GetParent()) | |
680 | { | |
681 | wxPoint pt(GetParent()->GetClientAreaOrigin()); | |
682 | *x -= pt.x; | |
683 | *y -= pt.y; | |
684 | } | |
685 | } | |
83df96d6 | 686 | } |
83df96d6 JS |
687 | } |
688 | ||
bc797f4c | 689 | void wxWindowX11::DoScreenToClient(int *x, int *y) const |
83df96d6 | 690 | { |
b513212d | 691 | Display *display = wxGlobalDisplay(); |
bc797f4c | 692 | Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); |
d02cb44e | 693 | Window thisWindow = (Window) m_mainWidget; |
83df96d6 JS |
694 | |
695 | Window childWindow; | |
696 | int xx = *x; | |
697 | int yy = *y; | |
698 | XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow); | |
699 | } | |
700 | ||
bc797f4c | 701 | void wxWindowX11::DoClientToScreen(int *x, int *y) const |
83df96d6 | 702 | { |
b513212d | 703 | Display *display = wxGlobalDisplay(); |
bc797f4c | 704 | Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display)); |
d02cb44e | 705 | Window thisWindow = (Window) m_mainWidget; |
83df96d6 JS |
706 | |
707 | Window childWindow; | |
708 | int xx = *x; | |
709 | int yy = *y; | |
710 | XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow); | |
711 | } | |
712 | ||
713 | ||
714 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
bc797f4c | 715 | void wxWindowX11::DoGetClientSize(int *x, int *y) const |
83df96d6 | 716 | { |
d02cb44e | 717 | Window window = (Window) m_mainWidget; |
b513212d JS |
718 | |
719 | if (window) | |
720 | { | |
9d2cef1c | 721 | // XSync(wxGlobalDisplay(), False); // Is this really a good idea? |
b513212d | 722 | XWindowAttributes attr; |
3cd0b8c5 | 723 | Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr ); |
b513212d JS |
724 | wxASSERT(status); |
725 | ||
726 | if (status) | |
727 | { | |
728 | *x = attr.width ; | |
729 | *y = attr.height ; | |
730 | } | |
731 | } | |
83df96d6 JS |
732 | } |
733 | ||
bc797f4c | 734 | void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
83df96d6 | 735 | { |
27398643 | 736 | Window xwindow = (Window) GetMainWindow(); |
83df96d6 | 737 | |
27398643 RR |
738 | wxCHECK_RET( xwindow, wxT("invalid window") ); |
739 | ||
740 | XWindowAttributes attr; | |
741 | Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); | |
742 | wxCHECK_RET( status, wxT("invalid window attributes") ); | |
743 | ||
744 | int new_x = attr.x; | |
745 | int new_y = attr.y; | |
746 | int new_w = attr.width; | |
747 | int new_h = attr.height; | |
748 | ||
b513212d JS |
749 | |
750 | if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) | |
83df96d6 | 751 | { |
27398643 | 752 | int yy = 0; |
e5053ade | 753 | AdjustForParentClientOrigin( x, yy, sizeFlags); |
27398643 | 754 | new_x = x; |
83df96d6 | 755 | } |
b513212d | 756 | if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
83df96d6 | 757 | { |
27398643 | 758 | int xx = 0; |
e5053ade | 759 | AdjustForParentClientOrigin( xx, y, sizeFlags); |
27398643 | 760 | new_y = y; |
83df96d6 | 761 | } |
27398643 | 762 | if (width != -1) |
83df96d6 | 763 | { |
27398643 RR |
764 | new_w = width; |
765 | if (new_w <= 0) | |
766 | new_w = 20; | |
83df96d6 | 767 | } |
27398643 | 768 | if (height != -1) |
b513212d | 769 | { |
27398643 RR |
770 | new_h = height; |
771 | if (new_h <= 0) | |
772 | new_h = 20; | |
b513212d | 773 | } |
27398643 RR |
774 | |
775 | DoMoveWindow( new_x, new_y, new_w, new_h ); | |
83df96d6 JS |
776 | } |
777 | ||
bc797f4c | 778 | void wxWindowX11::DoSetClientSize(int width, int height) |
83df96d6 | 779 | { |
27398643 | 780 | Window xwindow = (Window) GetMainWindow(); |
83df96d6 | 781 | |
27398643 | 782 | wxCHECK_RET( xwindow, wxT("invalid window") ); |
83df96d6 | 783 | |
27398643 RR |
784 | XWindowAttributes attr; |
785 | Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); | |
786 | wxCHECK_RET( status, wxT("invalid window attributes") ); | |
787 | ||
788 | int new_x = attr.x; | |
789 | int new_y = attr.y; | |
790 | int new_w = attr.width; | |
791 | int new_h = attr.height; | |
792 | ||
b513212d | 793 | if (width != -1) |
27398643 RR |
794 | new_w = width; |
795 | ||
b513212d | 796 | if (height != -1) |
27398643 RR |
797 | new_h = height; |
798 | ||
799 | DoMoveWindow( new_x, new_y, new_w, new_h ); | |
83df96d6 JS |
800 | } |
801 | ||
802 | // For implementation purposes - sometimes decorations make the client area | |
803 | // smaller | |
bc797f4c | 804 | wxPoint wxWindowX11::GetClientAreaOrigin() const |
83df96d6 JS |
805 | { |
806 | return wxPoint(0, 0); | |
807 | } | |
808 | ||
bc797f4c | 809 | void wxWindowX11::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH) |
83df96d6 JS |
810 | { |
811 | m_minWidth = minW; | |
812 | m_minHeight = minH; | |
813 | m_maxWidth = maxW; | |
814 | m_maxHeight = maxH; | |
815 | ||
461e93f9 | 816 | #if !wxUSE_NANOX |
b513212d JS |
817 | XSizeHints sizeHints; |
818 | sizeHints.flags = 0; | |
819 | ||
820 | if (minW > -1 && minH > -1) | |
83df96d6 | 821 | { |
b513212d JS |
822 | sizeHints.flags |= PMinSize; |
823 | sizeHints.min_width = minW; | |
824 | sizeHints.min_height = minH; | |
825 | } | |
826 | if (maxW > -1 && maxH > -1) | |
827 | { | |
828 | sizeHints.flags |= PMaxSize; | |
829 | sizeHints.max_width = maxW; | |
830 | sizeHints.max_height = maxH; | |
831 | } | |
832 | if (incW > -1 && incH > -1) | |
833 | { | |
834 | sizeHints.flags |= PResizeInc; | |
835 | sizeHints.width_inc = incW; | |
836 | sizeHints.height_inc = incH; | |
83df96d6 JS |
837 | } |
838 | ||
178572bb | 839 | XSetWMNormalHints(wxGlobalDisplay(), (Window) GetMainWindow(), & sizeHints); |
461e93f9 | 840 | #endif |
83df96d6 JS |
841 | } |
842 | ||
bc797f4c | 843 | void wxWindowX11::DoMoveWindow(int x, int y, int width, int height) |
83df96d6 | 844 | { |
27398643 RR |
845 | Window xwindow = (Window) GetMainWindow(); |
846 | ||
847 | wxCHECK_RET( xwindow, wxT("invalid window") ); | |
848 | ||
849 | XWindowChanges windowChanges; | |
850 | windowChanges.x = x; | |
851 | windowChanges.y = y; | |
852 | windowChanges.width = width; | |
853 | windowChanges.height = height; | |
854 | windowChanges.stack_mode = 0; | |
855 | int valueMask = CWX | CWY | CWWidth | CWHeight; | |
856 | ||
857 | XConfigureWindow( wxGlobalDisplay(), xwindow, valueMask, &windowChanges ); | |
83df96d6 JS |
858 | } |
859 | ||
860 | // --------------------------------------------------------------------------- | |
861 | // text metrics | |
862 | // --------------------------------------------------------------------------- | |
863 | ||
bc797f4c | 864 | int wxWindowX11::GetCharHeight() const |
83df96d6 JS |
865 | { |
866 | wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); | |
867 | ||
868 | WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay()); | |
869 | ||
870 | int direction, ascent, descent; | |
871 | XCharStruct overall; | |
872 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
873 | &descent, &overall); | |
874 | ||
875 | // return (overall.ascent + overall.descent); | |
876 | return (ascent + descent); | |
877 | } | |
878 | ||
bc797f4c | 879 | int wxWindowX11::GetCharWidth() const |
83df96d6 JS |
880 | { |
881 | wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); | |
882 | ||
883 | WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay()); | |
884 | ||
885 | int direction, ascent, descent; | |
886 | XCharStruct overall; | |
887 | XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent, | |
888 | &descent, &overall); | |
889 | ||
890 | return overall.width; | |
891 | } | |
892 | ||
bc797f4c | 893 | void wxWindowX11::GetTextExtent(const wxString& string, |
83df96d6 JS |
894 | int *x, int *y, |
895 | int *descent, int *externalLeading, | |
896 | const wxFont *theFont) const | |
897 | { | |
0d1dff01 RR |
898 | wxFont fontToUse = m_font; |
899 | if (theFont) fontToUse = *theFont; | |
83df96d6 | 900 | |
0d1dff01 RR |
901 | wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") ); |
902 | ||
903 | WXFontStructPtr pFontStruct = fontToUse.GetFontStruct(1.0, GetXDisplay()); | |
83df96d6 JS |
904 | |
905 | int direction, ascent, descent2; | |
906 | XCharStruct overall; | |
907 | int slen = string.Len(); | |
908 | ||
909 | #if 0 | |
910 | if (use16) | |
911 | XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction, | |
912 | &ascent, &descent2, &overall); | |
913 | #endif | |
914 | ||
461e93f9 | 915 | XTextExtents((XFontStruct*) pFontStruct, (char*) string.c_str(), slen, |
83df96d6 JS |
916 | &direction, &ascent, &descent2, &overall); |
917 | ||
918 | if ( x ) | |
919 | *x = (overall.width); | |
920 | if ( y ) | |
921 | *y = (ascent + descent2); | |
922 | if (descent) | |
923 | *descent = descent2; | |
924 | if (externalLeading) | |
925 | *externalLeading = 0; | |
926 | ||
927 | } | |
928 | ||
929 | // ---------------------------------------------------------------------------- | |
930 | // painting | |
931 | // ---------------------------------------------------------------------------- | |
932 | ||
bc797f4c | 933 | void wxWindowX11::Refresh(bool eraseBack, const wxRect *rect) |
83df96d6 | 934 | { |
d02cb44e RR |
935 | if (eraseBack) |
936 | { | |
937 | if (rect) | |
938 | { | |
939 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
940 | m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height ); | |
941 | } | |
942 | else | |
943 | { | |
944 | int height,width; | |
945 | GetSize( &width, &height ); | |
946 | ||
947 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
948 | m_clearRegion.Clear(); | |
949 | m_clearRegion.Union( 0, 0, width, height ); | |
950 | } | |
951 | } | |
83df96d6 | 952 | |
83df96d6 JS |
953 | if (rect) |
954 | { | |
d02cb44e RR |
955 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). |
956 | m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height ); | |
83df96d6 JS |
957 | } |
958 | else | |
959 | { | |
0d1dff01 RR |
960 | int height,width; |
961 | GetSize( &width, &height ); | |
d02cb44e RR |
962 | |
963 | // Schedule for later Updating in ::Update() or ::OnInternalIdle(). | |
964 | m_updateRegion.Clear(); | |
965 | m_updateRegion.Union( 0, 0, width, height ); | |
83df96d6 | 966 | } |
d02cb44e | 967 | } |
83df96d6 | 968 | |
d02cb44e RR |
969 | void wxWindowX11::Update() |
970 | { | |
971 | if (!m_updateRegion.IsEmpty()) | |
83df96d6 | 972 | { |
0b5c0e1a | 973 | // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName()); |
887dd52f RR |
974 | // Actually send erase events. |
975 | SendEraseEvents(); | |
976 | ||
977 | // Actually send paint events. | |
978 | SendPaintEvents(); | |
83df96d6 | 979 | } |
83df96d6 JS |
980 | } |
981 | ||
bc797f4c | 982 | void wxWindowX11::Clear() |
83df96d6 | 983 | { |
7266b672 | 984 | wxClientDC dc((wxWindow*) this); |
83df96d6 JS |
985 | wxBrush brush(GetBackgroundColour(), wxSOLID); |
986 | dc.SetBackground(brush); | |
987 | dc.Clear(); | |
988 | } | |
989 | ||
887dd52f | 990 | void wxWindowX11::SendEraseEvents() |
83df96d6 | 991 | { |
ba696cfa | 992 | if (!m_clearRegion.IsEmpty()) |
83df96d6 | 993 | { |
887dd52f RR |
994 | m_clipPaintRegion = TRUE; |
995 | ||
1934d291 RR |
996 | wxWindowDC dc( (wxWindow*)this ); |
997 | dc.SetClippingRegion( m_clearRegion ); | |
998 | ||
999 | wxEraseEvent erase_event( GetId(), &dc ); | |
1000 | erase_event.SetEventObject( this ); | |
0b5c0e1a | 1001 | |
1934d291 RR |
1002 | if (!GetEventHandler()->ProcessEvent(erase_event)) |
1003 | { | |
ba696cfa RR |
1004 | Window xwindow = (Window) GetMainWindow(); |
1005 | Display *xdisplay = wxGlobalDisplay(); | |
1006 | GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL ); | |
1007 | XSetFillStyle( xdisplay, xgc, FillSolid ); | |
1008 | XSetForeground( xdisplay, xgc, m_backgroundColour.GetPixel() ); | |
1934d291 RR |
1009 | wxRegionIterator upd( m_clearRegion ); |
1010 | while (upd) | |
1011 | { | |
ba696cfa RR |
1012 | XFillRectangle( xdisplay, xwindow, xgc, |
1013 | upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() ); | |
1934d291 RR |
1014 | upd ++; |
1015 | } | |
8ac7c509 | 1016 | XFreeGC( xdisplay, xgc ); |
1934d291 RR |
1017 | } |
1018 | m_clearRegion.Clear(); | |
887dd52f RR |
1019 | |
1020 | m_clipPaintRegion = FALSE; | |
83df96d6 | 1021 | } |
887dd52f RR |
1022 | } |
1023 | ||
1024 | ||
1025 | void wxWindowX11::SendPaintEvents() | |
1026 | { | |
1027 | m_clipPaintRegion = TRUE; | |
83df96d6 | 1028 | |
1180fb81 RR |
1029 | wxNcPaintEvent nc_paint_event( GetId() ); |
1030 | nc_paint_event.SetEventObject( this ); | |
1031 | GetEventHandler()->ProcessEvent( nc_paint_event ); | |
83df96d6 | 1032 | |
1934d291 RR |
1033 | wxPaintEvent paint_event( GetId() ); |
1034 | paint_event.SetEventObject( this ); | |
1035 | GetEventHandler()->ProcessEvent( paint_event ); | |
0d1dff01 | 1036 | |
0b5c0e1a | 1037 | m_updateRegion.Clear(); |
1934d291 | 1038 | m_clipPaintRegion = FALSE; |
83df96d6 JS |
1039 | } |
1040 | ||
1041 | // ---------------------------------------------------------------------------- | |
1042 | // event handlers | |
1043 | // ---------------------------------------------------------------------------- | |
1044 | ||
1045 | // Responds to colour changes: passes event on to children. | |
bc797f4c | 1046 | void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event) |
83df96d6 JS |
1047 | { |
1048 | wxWindowList::Node *node = GetChildren().GetFirst(); | |
1049 | while ( node ) | |
1050 | { | |
1051 | // Only propagate to non-top-level windows | |
1052 | wxWindow *win = node->GetData(); | |
1053 | if ( win->GetParent() ) | |
1054 | { | |
1055 | wxSysColourChangedEvent event2; | |
1056 | event.m_eventObject = win; | |
1057 | win->GetEventHandler()->ProcessEvent(event2); | |
1058 | } | |
1059 | ||
1060 | node = node->GetNext(); | |
1061 | } | |
1062 | } | |
1063 | ||
0d1dff01 | 1064 | void wxWindowX11::OnInternalIdle() |
83df96d6 | 1065 | { |
0d1dff01 RR |
1066 | // Update invalidated regions. |
1067 | Update(); | |
1068 | ||
83df96d6 JS |
1069 | // This calls the UI-update mechanism (querying windows for |
1070 | // menu/toolbar/control state information) | |
1071 | UpdateWindowUI(); | |
3a0b23eb JS |
1072 | |
1073 | // Set the input focus if couldn't do it before | |
1074 | if (m_needsInputFocus) | |
ff6b424a | 1075 | { |
3a0b23eb | 1076 | SetFocus(); |
ff6b424a | 1077 | } |
83df96d6 JS |
1078 | } |
1079 | ||
83df96d6 JS |
1080 | // ---------------------------------------------------------------------------- |
1081 | // function which maintain the global hash table mapping Widgets to wxWindows | |
1082 | // ---------------------------------------------------------------------------- | |
1083 | ||
bc797f4c | 1084 | bool wxAddWindowToTable(Window w, wxWindow *win) |
83df96d6 JS |
1085 | { |
1086 | wxWindow *oldItem = NULL; | |
1087 | if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w))) | |
1088 | { | |
1089 | wxLogDebug("Widget table clash: new widget is %ld, %s", | |
1090 | (long)w, win->GetClassInfo()->GetClassName()); | |
1091 | return FALSE; | |
1092 | } | |
1093 | ||
1094 | wxWidgetHashTable->Put((long) w, win); | |
1095 | ||
bc797f4c | 1096 | wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)", |
83df96d6 JS |
1097 | w, win, win->GetClassInfo()->GetClassName()); |
1098 | ||
1099 | return TRUE; | |
1100 | } | |
1101 | ||
bc797f4c | 1102 | wxWindow *wxGetWindowFromTable(Window w) |
83df96d6 JS |
1103 | { |
1104 | return (wxWindow *)wxWidgetHashTable->Get((long) w); | |
1105 | } | |
1106 | ||
bc797f4c | 1107 | void wxDeleteWindowFromTable(Window w) |
83df96d6 JS |
1108 | { |
1109 | wxWidgetHashTable->Delete((long)w); | |
1110 | } | |
1111 | ||
1112 | // ---------------------------------------------------------------------------- | |
1113 | // add/remove window from the table | |
1114 | // ---------------------------------------------------------------------------- | |
1115 | ||
83df96d6 | 1116 | // ---------------------------------------------------------------------------- |
bc797f4c | 1117 | // X11-specific accessors |
83df96d6 JS |
1118 | // ---------------------------------------------------------------------------- |
1119 | ||
1120 | // Get the underlying X window | |
bc797f4c | 1121 | WXWindow wxWindowX11::GetXWindow() const |
83df96d6 | 1122 | { |
bc797f4c | 1123 | return GetMainWindow(); |
83df96d6 JS |
1124 | } |
1125 | ||
1126 | // Get the underlying X display | |
bc797f4c | 1127 | WXDisplay *wxWindowX11::GetXDisplay() const |
83df96d6 | 1128 | { |
bc797f4c | 1129 | return wxGetDisplay(); |
83df96d6 JS |
1130 | } |
1131 | ||
bc797f4c | 1132 | WXWindow wxWindowX11::GetMainWindow() const |
83df96d6 | 1133 | { |
d02cb44e | 1134 | return m_mainWidget; |
83df96d6 JS |
1135 | } |
1136 | ||
83df96d6 JS |
1137 | // ---------------------------------------------------------------------------- |
1138 | // TranslateXXXEvent() functions | |
1139 | // ---------------------------------------------------------------------------- | |
1140 | ||
1b0fb34b | 1141 | bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window, XEvent *xevent) |
83df96d6 | 1142 | { |
461e93f9 | 1143 | switch (XEventGetType(xevent)) |
83df96d6 | 1144 | { |
1b0fb34b JS |
1145 | case EnterNotify: |
1146 | case LeaveNotify: | |
83df96d6 JS |
1147 | case ButtonPress: |
1148 | case ButtonRelease: | |
1149 | case MotionNotify: | |
1150 | { | |
1151 | wxEventType eventType = wxEVT_NULL; | |
1152 | ||
461e93f9 | 1153 | if (XEventGetType(xevent) == EnterNotify) |
83df96d6 | 1154 | { |
1b0fb34b JS |
1155 | //if (local_event.xcrossing.mode!=NotifyNormal) |
1156 | // return ; // Ignore grab events | |
1157 | eventType = wxEVT_ENTER_WINDOW; | |
1158 | // canvas->GetEventHandler()->OnSetFocus(); | |
1159 | } | |
461e93f9 | 1160 | else if (XEventGetType(xevent) == LeaveNotify) |
1b0fb34b JS |
1161 | { |
1162 | //if (local_event.xcrossingr.mode!=NotifyNormal) | |
1163 | // return ; // Ignore grab events | |
1164 | eventType = wxEVT_LEAVE_WINDOW; | |
1165 | // canvas->GetEventHandler()->OnKillFocus(); | |
83df96d6 | 1166 | } |
461e93f9 | 1167 | else if (XEventGetType(xevent) == MotionNotify) |
83df96d6 JS |
1168 | { |
1169 | eventType = wxEVT_MOTION; | |
1170 | } | |
461e93f9 | 1171 | else if (XEventGetType(xevent) == ButtonPress) |
83df96d6 | 1172 | { |
461e93f9 | 1173 | wxevent.SetTimestamp(XButtonEventGetTime(xevent)); |
83df96d6 | 1174 | int button = 0; |
461e93f9 | 1175 | if (XButtonEventLChanged(xevent)) |
83df96d6 JS |
1176 | { |
1177 | eventType = wxEVT_LEFT_DOWN; | |
83df96d6 JS |
1178 | button = 1; |
1179 | } | |
461e93f9 | 1180 | else if (XButtonEventMChanged(xevent)) |
83df96d6 JS |
1181 | { |
1182 | eventType = wxEVT_MIDDLE_DOWN; | |
83df96d6 JS |
1183 | button = 2; |
1184 | } | |
461e93f9 | 1185 | else if (XButtonEventRChanged(xevent)) |
83df96d6 JS |
1186 | { |
1187 | eventType = wxEVT_RIGHT_DOWN; | |
83df96d6 JS |
1188 | button = 3; |
1189 | } | |
1190 | ||
1191 | // check for a double click | |
1b0fb34b | 1192 | // TODO: where can we get this value from? |
b513212d | 1193 | //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay()); |
7266b672 | 1194 | long dclickTime = 200; |
83df96d6 JS |
1195 | long ts = wxevent.GetTimestamp(); |
1196 | ||
1197 | int buttonLast = win->GetLastClickedButton(); | |
1198 | long lastTS = win->GetLastClickTime(); | |
1199 | if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime ) | |
1200 | { | |
1201 | // I have a dclick | |
1202 | win->SetLastClick(0, ts); | |
1203 | if ( eventType == wxEVT_LEFT_DOWN ) | |
1204 | eventType = wxEVT_LEFT_DCLICK; | |
1205 | else if ( eventType == wxEVT_MIDDLE_DOWN ) | |
1206 | eventType = wxEVT_MIDDLE_DCLICK; | |
1207 | else if ( eventType == wxEVT_RIGHT_DOWN ) | |
1208 | eventType = wxEVT_RIGHT_DCLICK; | |
1209 | } | |
1210 | else | |
1211 | { | |
1212 | // not fast enough or different button | |
1213 | win->SetLastClick(button, ts); | |
1214 | } | |
1215 | } | |
461e93f9 | 1216 | else if (XEventGetType(xevent) == ButtonRelease) |
83df96d6 | 1217 | { |
461e93f9 | 1218 | if (XButtonEventLChanged(xevent)) |
83df96d6 JS |
1219 | { |
1220 | eventType = wxEVT_LEFT_UP; | |
83df96d6 | 1221 | } |
461e93f9 | 1222 | else if (XButtonEventMChanged(xevent)) |
83df96d6 JS |
1223 | { |
1224 | eventType = wxEVT_MIDDLE_UP; | |
83df96d6 | 1225 | } |
461e93f9 | 1226 | else if (XButtonEventRChanged(xevent)) |
83df96d6 JS |
1227 | { |
1228 | eventType = wxEVT_RIGHT_UP; | |
83df96d6 JS |
1229 | } |
1230 | else return FALSE; | |
1231 | } | |
1232 | else | |
1233 | { | |
1234 | return FALSE; | |
1235 | } | |
1236 | ||
1237 | wxevent.SetEventType(eventType); | |
1238 | ||
461e93f9 JS |
1239 | wxevent.m_x = XButtonEventGetX(xevent); |
1240 | wxevent.m_y = XButtonEventGetY(xevent); | |
83df96d6 JS |
1241 | |
1242 | wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN) | |
461e93f9 | 1243 | || (XButtonEventLIsDown(xevent) |
83df96d6 JS |
1244 | && (eventType != wxEVT_LEFT_UP))); |
1245 | wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN) | |
461e93f9 | 1246 | || (XButtonEventMIsDown(xevent) |
83df96d6 JS |
1247 | && (eventType != wxEVT_MIDDLE_UP))); |
1248 | wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN) | |
461e93f9 | 1249 | || (XButtonEventRIsDown (xevent) |
83df96d6 JS |
1250 | && (eventType != wxEVT_RIGHT_UP))); |
1251 | ||
461e93f9 JS |
1252 | wxevent.m_shiftDown = XButtonEventShiftIsDown(xevent); |
1253 | wxevent.m_controlDown = XButtonEventCtrlIsDown(xevent); | |
1254 | wxevent.m_altDown = XButtonEventAltIsDown(xevent); | |
1255 | wxevent.m_metaDown = XButtonEventMetaIsDown(xevent); | |
83df96d6 JS |
1256 | |
1257 | wxevent.SetId(win->GetId()); | |
1258 | wxevent.SetEventObject(win); | |
1259 | ||
1260 | return TRUE; | |
1261 | } | |
1262 | } | |
1263 | return FALSE; | |
1264 | } | |
1265 | ||
7eaac9f5 | 1266 | bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win), XEvent *xevent) |
83df96d6 | 1267 | { |
461e93f9 | 1268 | switch (XEventGetType(xevent)) |
83df96d6 JS |
1269 | { |
1270 | case KeyPress: | |
1271 | case KeyRelease: | |
1272 | { | |
1273 | char buf[20]; | |
1274 | ||
1275 | KeySym keySym; | |
83df96d6 JS |
1276 | (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL); |
1277 | int id = wxCharCodeXToWX (keySym); | |
1278 | ||
461e93f9 JS |
1279 | wxevent.m_shiftDown = XKeyEventShiftIsDown(xevent); |
1280 | wxevent.m_controlDown = XKeyEventCtrlIsDown(xevent); | |
1281 | wxevent.m_altDown = XKeyEventAltIsDown(xevent); | |
1282 | wxevent.m_metaDown = XKeyEventMetaIsDown(xevent); | |
83df96d6 JS |
1283 | wxevent.SetEventObject(win); |
1284 | wxevent.m_keyCode = id; | |
461e93f9 | 1285 | wxevent.SetTimestamp(XKeyEventGetTime(xevent)); |
83df96d6 | 1286 | |
461e93f9 JS |
1287 | wxevent.m_x = XKeyEventGetX(xevent); |
1288 | wxevent.m_y = XKeyEventGetY(xevent); | |
83df96d6 JS |
1289 | |
1290 | if (id > -1) | |
1291 | return TRUE; | |
1292 | else | |
1293 | return FALSE; | |
1294 | break; | |
1295 | } | |
1296 | default: | |
1297 | break; | |
1298 | } | |
1299 | return FALSE; | |
1300 | } | |
1301 | ||
1302 | // ---------------------------------------------------------------------------- | |
1303 | // Colour stuff | |
1304 | // ---------------------------------------------------------------------------- | |
1305 | ||
bc797f4c | 1306 | bool wxWindowX11::SetBackgroundColour(const wxColour& col) |
83df96d6 | 1307 | { |
56cb684a | 1308 | wxWindowBase::SetBackgroundColour(col); |
83df96d6 | 1309 | |
3cd0b8c5 RR |
1310 | Display *xdisplay = (Display*) wxGlobalDisplay(); |
1311 | int xscreen = DefaultScreen( xdisplay ); | |
1312 | Colormap cm = DefaultColormap( xdisplay, xscreen ); | |
1313 | ||
ba696cfa | 1314 | m_backgroundColour.CalcPixel( (WXColormap) cm ); |
3cd0b8c5 | 1315 | |
ba696cfa RR |
1316 | if (!GetMainWindow()) |
1317 | return FALSE; | |
1318 | ||
1319 | /* | |
b28d3abf | 1320 | XSetWindowAttributes attrib; |
3cd0b8c5 | 1321 | attrib.background_pixel = colour.GetPixel(); |
b28d3abf JS |
1322 | |
1323 | XChangeWindowAttributes(wxGlobalDisplay(), | |
1324 | (Window) GetMainWindow(), | |
1325 | CWBackPixel, | |
1326 | & attrib); | |
ba696cfa | 1327 | */ |
b28d3abf | 1328 | |
83df96d6 JS |
1329 | return TRUE; |
1330 | } | |
1331 | ||
bc797f4c | 1332 | bool wxWindowX11::SetForegroundColour(const wxColour& col) |
83df96d6 JS |
1333 | { |
1334 | if ( !wxWindowBase::SetForegroundColour(col) ) | |
1335 | return FALSE; | |
1336 | ||
83df96d6 JS |
1337 | return TRUE; |
1338 | } | |
1339 | ||
83df96d6 JS |
1340 | // ---------------------------------------------------------------------------- |
1341 | // global functions | |
1342 | // ---------------------------------------------------------------------------- | |
1343 | ||
1344 | wxWindow *wxGetActiveWindow() | |
1345 | { | |
1346 | // TODO | |
1347 | wxFAIL_MSG("Not implemented"); | |
1348 | return NULL; | |
1349 | } | |
1350 | ||
1351 | /* static */ | |
1352 | wxWindow *wxWindowBase::GetCapture() | |
1353 | { | |
1354 | return (wxWindow *)g_captureWindow; | |
1355 | } | |
1356 | ||
1357 | ||
1358 | // Find the wxWindow at the current mouse position, returning the mouse | |
1359 | // position. | |
1360 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) | |
1361 | { | |
1362 | return wxFindWindowAtPoint(wxGetMousePosition()); | |
1363 | } | |
1364 | ||
1365 | // Get the current mouse position. | |
1366 | wxPoint wxGetMousePosition() | |
1367 | { | |
461e93f9 JS |
1368 | #if wxUSE_NANOX |
1369 | /* TODO */ | |
1370 | return wxPoint(0, 0); | |
1371 | #else | |
b513212d | 1372 | Display *display = wxGlobalDisplay(); |
83df96d6 JS |
1373 | Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); |
1374 | Window rootReturn, childReturn; | |
1375 | int rootX, rootY, winX, winY; | |
1376 | unsigned int maskReturn; | |
1377 | ||
1378 | XQueryPointer (display, | |
1379 | rootWindow, | |
1380 | &rootReturn, | |
1381 | &childReturn, | |
1382 | &rootX, &rootY, &winX, &winY, &maskReturn); | |
1383 | return wxPoint(rootX, rootY); | |
461e93f9 | 1384 | #endif |
83df96d6 JS |
1385 | } |
1386 | ||
1387 | ||
1388 | // ---------------------------------------------------------------------------- | |
1389 | // wxNoOptimize: switch off size optimization | |
1390 | // ---------------------------------------------------------------------------- | |
1391 | ||
1392 | int wxNoOptimize::ms_count = 0; | |
1393 |