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