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