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