1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  21     #pragma implementation "window.h" 
  27 #include "wx/dcclient.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" 
  38 #include "wx/scrolwin.h" 
  39 #include "wx/scrolbar.h" 
  40 #include "wx/module.h" 
  41 #include "wx/menuitem.h" 
  43 #include "wx/fontutil.h" 
  44 #include "wx/univ/renderer.h" 
  47 #if  wxUSE_DRAG_AND_DROP 
  51 #include "wx/x11/private.h" 
  52 #include "X11/Xutil.h" 
  55 // For wxGetLocalTime, used by XButtonEventGetTime 
  61 // ---------------------------------------------------------------------------- 
  62 // global variables for this module 
  63 // ---------------------------------------------------------------------------- 
  65 static wxWindow
* g_captureWindow 
= NULL
; 
  68 // ---------------------------------------------------------------------------- 
  70 // ---------------------------------------------------------------------------- 
  72 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask) 
  73 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask) 
  74 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask) 
  76 // ---------------------------------------------------------------------------- 
  78 // ---------------------------------------------------------------------------- 
  80 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
) 
  82 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
) 
  83     EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
) 
  86 // ============================================================================ 
  88 // ============================================================================ 
  90 // ---------------------------------------------------------------------------- 
  92 // ---------------------------------------------------------------------------- 
  94 // ---------------------------------------------------------------------------- 
  96 // ---------------------------------------------------------------------------- 
  98 void wxWindowX11::Init() 
 101     m_mainWindow 
= (WXWindow
) 0; 
 102     m_clientWindow 
= (WXWindow
) 0; 
 103     m_insertIntoMain 
= FALSE
; 
 104     m_updateNcArea 
= FALSE
; 
 106     m_winCaptured 
= FALSE
; 
 107     m_needsInputFocus 
= FALSE
; 
 113 // real construction (Init() must have been called before!) 
 114 bool wxWindowX11::Create(wxWindow 
*parent
, wxWindowID id
, 
 118                       const wxString
& name
) 
 120     wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") ); 
 122     CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
); 
 124     parent
->AddChild(this); 
 126     Display 
*xdisplay 
= (Display
*) wxGlobalDisplay(); 
 127     int xscreen 
= DefaultScreen( xdisplay 
); 
 128     Visual 
*xvisual 
= DefaultVisual( xdisplay
, xscreen 
); 
 129     Colormap cm 
= DefaultColormap( xdisplay
, xscreen 
); 
 131     m_backgroundColour 
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
); 
 132     m_backgroundColour
.CalcPixel( (WXColormap
) cm 
); 
 134     m_foregroundColour 
= *wxBLACK
; 
 135     m_foregroundColour
.CalcPixel( (WXColormap
) cm 
); 
 137     Window xparent 
= (Window
) parent
->GetClientAreaWindow(); 
 139     // Add window's own scrollbars to main window, not to client window 
 140     if (parent
->GetInsertIntoMain()) 
 142         // wxLogDebug( "Inserted into main: %s", GetName().c_str() ); 
 143         xparent 
= (Window
) parent
->GetMainWindow(); 
 146     // Size (not including the border) must be nonzero (or a Value error results)! 
 147     // Note: The Xlib manual doesn't mention this restriction of XCreateWindow. 
 160 #if wxUSE_TWO_WINDOWS 
 161     bool need_two_windows 
= 
 162         ((( wxSUNKEN_BORDER 
| wxRAISED_BORDER 
| wxSIMPLE_BORDER 
| wxHSCROLL 
| wxVSCROLL 
) & m_windowStyle
) != 0); 
 164     bool need_two_windows 
= FALSE
; 
 168     long xattributes 
= 0; 
 170     XSetWindowAttributes xattributes
; 
 171     long xattributes_mask 
= 0; 
 173     xattributes_mask 
|= CWBackPixel
; 
 174     xattributes
.background_pixel 
= m_backgroundColour
.GetPixel(); 
 176     xattributes_mask 
|= CWBorderPixel
; 
 177     xattributes
.border_pixel 
= BlackPixel( xdisplay
, xscreen 
); 
 179     xattributes_mask 
|= CWEventMask
; 
 182     if (need_two_windows
) 
 185         long backColor
, foreColor
; 
 186         backColor 
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue()); 
 187         foreColor 
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue()); 
 189         Window xwindow 
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 
 190                                     0, 0, InputOutput
, xvisual
, backColor
, foreColor
); 
 191         XSelectInput( xdisplay
, xwindow
, 
 192           GR_EVENT_MASK_CLOSE_REQ 
| ExposureMask 
| KeyPressMask 
| KeyReleaseMask 
| ButtonPressMask 
| ButtonReleaseMask 
| 
 193           ButtonMotionMask 
| EnterWindowMask 
| LeaveWindowMask 
| PointerMotionMask 
| 
 194           KeymapStateMask 
| FocusChangeMask 
| ColormapChangeMask 
| StructureNotifyMask 
| 
 195                       PropertyChangeMask 
); 
 199         xattributes
.event_mask 
= 
 200             ExposureMask 
| StructureNotifyMask 
| ColormapChangeMask
; 
 202         Window xwindow 
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 
 203             0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes 
); 
 207         XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None 
); 
 209         m_mainWindow 
= (WXWindow
) xwindow
; 
 210         wxAddWindowToTable( xwindow
, (wxWindow
*) this ); 
 212         XMapWindow( xdisplay
, xwindow 
); 
 215         xattributes
.event_mask 
= 
 216             ExposureMask 
| KeyPressMask 
| KeyReleaseMask 
| ButtonPressMask 
| ButtonReleaseMask 
| 
 217             ButtonMotionMask 
| EnterWindowMask 
| LeaveWindowMask 
| PointerMotionMask 
| 
 218             KeymapStateMask 
| FocusChangeMask 
| ColormapChangeMask 
| StructureNotifyMask 
| 
 219             PropertyChangeMask 
| VisibilityChangeMask 
; 
 221         if (!HasFlag( wxFULL_REPAINT_ON_RESIZE 
)) 
 223             xattributes_mask 
|= CWBitGravity
; 
 224             xattributes
.bit_gravity 
= StaticGravity
; 
 228         if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
)) 
 235         else if (HasFlag( wxSIMPLE_BORDER 
)) 
 248         // Make again sure the size is nonzero. 
 255         backColor 
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue()); 
 256         foreColor 
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue()); 
 258         xwindow 
= XCreateWindowWithColor( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 
 259                                     0, 0, InputOutput
, xvisual
, backColor
, foreColor
); 
 260         XSelectInput( xdisplay
, xwindow
, 
 261           GR_EVENT_MASK_CLOSE_REQ 
| ExposureMask 
| KeyPressMask 
| KeyReleaseMask 
| ButtonPressMask 
| ButtonReleaseMask 
| 
 262           ButtonMotionMask 
| EnterWindowMask 
| LeaveWindowMask 
| PointerMotionMask 
| 
 263           KeymapStateMask 
| FocusChangeMask 
| ColormapChangeMask 
| StructureNotifyMask 
| 
 264                       PropertyChangeMask 
); 
 267         xwindow 
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 
 268             0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes 
); 
 271         XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None 
); 
 273         m_clientWindow 
= (WXWindow
) xwindow
; 
 274         wxAddClientWindowToTable( xwindow
, (wxWindow
*) this ); 
 276         XMapWindow( xdisplay
, xwindow 
); 
 280         // wxLogDebug( "No two windows needed %s", GetName().c_str() ); 
 282         long backColor
, foreColor
; 
 283         backColor 
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue()); 
 284         foreColor 
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue()); 
 286         Window xwindow 
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 
 287                                     0, 0, InputOutput
, xvisual
, backColor
, foreColor
); 
 288         XSelectInput( xdisplay
, xwindow
, 
 289           GR_EVENT_MASK_CLOSE_REQ 
| ExposureMask 
| KeyPressMask 
| KeyReleaseMask 
| ButtonPressMask 
| ButtonReleaseMask 
| 
 290           ButtonMotionMask 
| EnterWindowMask 
| LeaveWindowMask 
| PointerMotionMask 
| 
 291           KeymapStateMask 
| FocusChangeMask 
| ColormapChangeMask 
| StructureNotifyMask 
| 
 292                       PropertyChangeMask 
); 
 295         xattributes
.event_mask 
= 
 296             ExposureMask 
| KeyPressMask 
| KeyReleaseMask 
| ButtonPressMask 
| ButtonReleaseMask 
| 
 297             ButtonMotionMask 
| EnterWindowMask 
| LeaveWindowMask 
| PointerMotionMask 
| 
 298             KeymapStateMask 
| FocusChangeMask 
| ColormapChangeMask 
| StructureNotifyMask 
| 
 299             PropertyChangeMask 
| VisibilityChangeMask 
; 
 301         if (!HasFlag( wxFULL_REPAINT_ON_RESIZE 
)) 
 303             xattributes_mask 
|= CWBitGravity
; 
 304             xattributes
.bit_gravity 
= NorthWestGravity
; 
 307         Window xwindow 
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 
 308             0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes 
); 
 311         XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None 
); 
 313         m_mainWindow 
= (WXWindow
) xwindow
; 
 314         m_clientWindow 
= m_mainWindow
; 
 315         wxAddWindowToTable( xwindow
, (wxWindow
*) this ); 
 317         XMapWindow( xdisplay
, xwindow 
); 
 320     // Is a subwindow, so map immediately 
 323     // Without this, the cursor may not be restored properly (e.g. in splitter 
 325     SetCursor(*wxSTANDARD_CURSOR
); 
 326     SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
)); 
 328     // Don't call this, it can have nasty repercussions for composite controls, 
 330     //    SetSize(pos.x, pos.y, size.x, size.y); 
 336 wxWindowX11::~wxWindowX11() 
 340     if (g_captureWindow 
== this) 
 341         g_captureWindow 
= NULL
; 
 343     m_isBeingDeleted 
= TRUE
; 
 347     if (m_clientWindow 
!= m_mainWindow
) 
 349         // Destroy the cleint window 
 350         Window xwindow 
= (Window
) m_clientWindow
; 
 351         wxDeleteClientWindowFromTable( xwindow 
); 
 352         XDestroyWindow( wxGlobalDisplay(), xwindow 
); 
 353         m_clientWindow 
= NULL
; 
 356     // Destroy the window 
 357     Window xwindow 
= (Window
) m_mainWindow
; 
 358     wxDeleteWindowFromTable( xwindow 
); 
 359     XDestroyWindow( wxGlobalDisplay(), xwindow 
); 
 363 // --------------------------------------------------------------------------- 
 365 // --------------------------------------------------------------------------- 
 367 void wxWindowX11::SetFocus() 
 369     Window xwindow 
= (Window
) m_clientWindow
; 
 371     wxCHECK_RET( xwindow
, wxT("invalid window") ); 
 373     wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") ); 
 376     if (GetName() == "scrollBar") 
 383     if (wxWindowIsVisible(xwindow
)) 
 385         wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName()); 
 386         //        XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime ); 
 387         XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToNone
, CurrentTime 
); 
 388         m_needsInputFocus 
= FALSE
; 
 392         m_needsInputFocus 
= TRUE
; 
 396 // Get the window with the focus 
 397 wxWindow 
*wxWindowBase::DoFindFocus() 
 399     Window xfocus 
= (Window
) 0; 
 402     XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
); 
 405         wxWindow 
*win 
= wxGetWindowFromTable( xfocus 
); 
 408             win 
= wxGetClientWindowFromTable( xfocus 
); 
 417 // Enabling/disabling handled by event loop, and not sending events 
 419 bool wxWindowX11::Enable(bool enable
) 
 421     if ( !wxWindowBase::Enable(enable
) ) 
 427 bool wxWindowX11::Show(bool show
) 
 429     wxWindowBase::Show(show
); 
 431     Window xwindow 
= (Window
) m_mainWindow
; 
 432     Display 
*xdisp 
= wxGlobalDisplay(); 
 435         // wxLogDebug( "Mapping window of type %s", GetName().c_str() ); 
 436         XMapWindow(xdisp
, xwindow
); 
 440         // wxLogDebug( "Unmapping window of type %s", GetName().c_str() ); 
 441         XUnmapWindow(xdisp
, xwindow
); 
 447 // Raise the window to the top of the Z order 
 448 void wxWindowX11::Raise() 
 451         XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow 
); 
 454 // Lower the window to the bottom of the Z order 
 455 void wxWindowX11::Lower() 
 458         XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow 
); 
 461 void wxWindowX11::DoCaptureMouse() 
 463     if ((g_captureWindow 
!= NULL
) && (g_captureWindow 
!= this)) 
 465         wxASSERT_MSG(FALSE
, wxT("Trying to capture before mouse released.")); 
 476     Window xwindow 
= (Window
) m_clientWindow
; 
 478     wxCHECK_RET( xwindow
, wxT("invalid window") ); 
 480     g_captureWindow 
= (wxWindow
*) this; 
 484         int res 
= XGrabPointer(wxGlobalDisplay(), xwindow
, 
 486             ButtonPressMask 
| ButtonReleaseMask 
| ButtonMotionMask 
| EnterWindowMask 
| LeaveWindowMask 
| PointerMotionMask
, 
 490             None
, /* cursor */ // TODO: This may need to be set to the cursor of this window 
 493         if (res 
!= GrabSuccess
) 
 496             msg
.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName()); 
 498             if (res 
== GrabNotViewable
) 
 499                 wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") ); 
 501             g_captureWindow 
= NULL
; 
 505         m_winCaptured 
= TRUE
; 
 509 void wxWindowX11::DoReleaseMouse() 
 511     g_captureWindow 
= NULL
; 
 513     if ( !m_winCaptured 
) 
 516     Window xwindow 
= (Window
) m_clientWindow
; 
 520         XUngrabPointer( wxGlobalDisplay(), CurrentTime 
); 
 523     // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() ); 
 525     m_winCaptured 
= FALSE
; 
 528 bool wxWindowX11::SetFont(const wxFont
& font
) 
 530     if ( !wxWindowBase::SetFont(font
) ) 
 539 bool wxWindowX11::SetCursor(const wxCursor
& cursor
) 
 541     if ( !wxWindowBase::SetCursor(cursor
) ) 
 547     Window xwindow 
= (Window
) m_clientWindow
; 
 549     wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") ); 
 551     wxCursor cursorToUse
; 
 553         cursorToUse 
= m_cursor
; 
 555         cursorToUse 
= *wxSTANDARD_CURSOR
; 
 557     Cursor xcursor 
= (Cursor
) cursorToUse
.GetCursor(); 
 559     XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor 
); 
 564 // Coordinates relative to the window 
 565 void wxWindowX11::WarpPointer (int x
, int y
) 
 567     Window xwindow 
= (Window
) m_clientWindow
; 
 569     wxCHECK_RET( xwindow
, wxT("invalid window") ); 
 571     XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
); 
 574 // Does a physical scroll 
 575 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect 
*rect
) 
 577     // No scrolling requested. 
 578     if ((dx 
== 0) && (dy 
== 0)) return; 
 580     if (!m_updateRegion
.IsEmpty()) 
 582         m_updateRegion
.Offset( dx
, dy 
); 
 586         GetSize( &cw
, &ch 
);  // GetClientSize() ?? 
 587         m_updateRegion
.Intersect( 0, 0, cw
, ch 
); 
 590     if (!m_clearRegion
.IsEmpty()) 
 592         m_clearRegion
.Offset( dx
, dy 
); 
 596         GetSize( &cw
, &ch 
);  // GetClientSize() ?? 
 597         m_clearRegion
.Intersect( 0, 0, cw
, ch 
); 
 600     Window xwindow 
= (Window
) GetClientAreaWindow(); 
 602     wxCHECK_RET( xwindow
, wxT("invalid window") ); 
 604     Display 
*xdisplay 
= wxGlobalDisplay(); 
 606     GC xgc 
= XCreateGC( xdisplay
, xwindow
, 0, NULL 
); 
 607     XSetGraphicsExposures( xdisplay
, xgc
, True 
); 
 625         GetClientSize( &cw
, &ch 
); 
 628 #if wxUSE_TWO_WINDOWS 
 629     wxPoint 
offset( 0,0 ); 
 631     wxPoint offset 
= GetClientAreaOrigin(); 
 636     int w 
= cw 
- abs(dx
); 
 637     int h 
= ch 
- abs(dy
); 
 639     if ((h 
< 0) || (w 
< 0)) 
 646         if (dx 
< 0) rect
.x 
= cw
+dx 
+ offset
.x
; else rect
.x 
= s_x
; 
 647         if (dy 
< 0) rect
.y 
= ch
+dy 
+ offset
.y
; else rect
.y 
= s_y
; 
 648         if (dy 
!= 0) rect
.width 
= cw
; else rect
.width 
= abs(dx
); 
 649         if (dx 
!= 0) rect
.height 
= ch
; else rect
.height 
= abs(dy
); 
 654         if (dx 
< 0) s_x 
+= -dx
; 
 655         if (dy 
< 0) s_y 
+= -dy
; 
 656         if (dx 
> 0) d_x 
= dx 
+ offset
.x
; 
 657         if (dy 
> 0) d_y 
= dy 
+ offset
.y
; 
 659         XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y 
); 
 661         // wxLogDebug( "Copy: s_x %d s_y %d w %d h %d d_x %d d_y %d", s_x, s_y, w, h, d_x, d_y ); 
 663         // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height ); 
 665         m_updateRegion
.Union( rect 
); 
 666         m_clearRegion
.Union( rect 
); 
 669     XFreeGC( xdisplay
, xgc 
); 
 672 // --------------------------------------------------------------------------- 
 674 // --------------------------------------------------------------------------- 
 676 #if wxUSE_DRAG_AND_DROP 
 678 void wxWindowX11::SetDropTarget(wxDropTarget 
* WXUNUSED(pDropTarget
)) 
 685 // Old style file-manager drag&drop 
 686 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
)) 
 691 // ---------------------------------------------------------------------------- 
 693 // ---------------------------------------------------------------------------- 
 697 void wxWindowX11::DoSetToolTip(wxToolTip 
* WXUNUSED(tooltip
)) 
 702 #endif // wxUSE_TOOLTIPS 
 704 // --------------------------------------------------------------------------- 
 705 // moving and resizing 
 706 // --------------------------------------------------------------------------- 
 708 bool wxWindowX11::PreResize() 
 714 void wxWindowX11::DoGetSize(int *x
, int *y
) const 
 716     Window xwindow 
= (Window
) m_mainWindow
; 
 718     wxCHECK_RET( xwindow
, wxT("invalid window") ); 
 720     //XSync(wxGlobalDisplay(), False); 
 722     XWindowAttributes attr
; 
 723     Status status 
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr 
); 
 728         *x 
= attr
.width 
/* + 2*m_borderSize */ ; 
 729         *y 
= attr
.height 
/* + 2*m_borderSize */ ; 
 733 void wxWindowX11::DoGetPosition(int *x
, int *y
) const 
 735     Window window 
= (Window
) m_mainWindow
; 
 738         //XSync(wxGlobalDisplay(), False); 
 739         XWindowAttributes attr
; 
 740         Status status 
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
); 
 748             // We may be faking the client origin. So a window that's really at (0, 30) 
 749             // may appear (to wxWin apps) to be at (0, 0). 
 752                 wxPoint 
pt(GetParent()->GetClientAreaOrigin()); 
 760 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const 
 762     Display 
*display 
= wxGlobalDisplay(); 
 763     Window rootWindow 
= RootWindowOfScreen(DefaultScreenOfDisplay(display
)); 
 764     Window thisWindow 
= (Window
) m_clientWindow
; 
 769     XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
); 
 772 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const 
 774     Display 
*display 
= wxGlobalDisplay(); 
 775     Window rootWindow 
= RootWindowOfScreen(DefaultScreenOfDisplay(display
)); 
 776     Window thisWindow 
= (Window
) m_clientWindow
; 
 781     XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
); 
 785 // Get size *available for subwindows* i.e. excluding menu bar etc. 
 786 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const 
 788     Window window 
= (Window
) m_mainWindow
; 
 792         XWindowAttributes attr
; 
 793         Status status 
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr 
); 
 804 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
) 
 806     //    wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height); 
 808     Window xwindow 
= (Window
) m_mainWindow
; 
 810     wxCHECK_RET( xwindow
, wxT("invalid window") ); 
 812     XWindowAttributes attr
; 
 813     Status status 
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr 
); 
 814     wxCHECK_RET( status
, wxT("invalid window attributes") ); 
 818     int new_w 
= attr
.width
; 
 819     int new_h 
= attr
.height
; 
 821     if (x 
!= -1 || (sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
)) 
 824         AdjustForParentClientOrigin( x
, yy
, sizeFlags
); 
 827     if (y 
!= -1 || (sizeFlags 
& wxSIZE_ALLOW_MINUS_ONE
)) 
 830         AdjustForParentClientOrigin( xx
, y
, sizeFlags
); 
 846     DoMoveWindow( new_x
, new_y
, new_w
, new_h 
); 
 849 void wxWindowX11::DoSetClientSize(int width
, int height
) 
 851     //    wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height); 
 853     Window xwindow 
= (Window
) m_mainWindow
; 
 855     wxCHECK_RET( xwindow
, wxT("invalid window") ); 
 857     XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height 
); 
 859     if (m_mainWindow 
!= m_clientWindow
) 
 861         xwindow 
= (Window
) m_clientWindow
; 
 863         wxWindow 
*window 
= (wxWindow
*) this; 
 864         wxRenderer 
*renderer 
= window
->GetRenderer(); 
 867             wxRect border 
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle 
& wxBORDER_MASK
) ); 
 868             width 
-= border
.x 
+ border
.width
; 
 869             height 
-= border
.y 
+ border
.height
; 
 872         XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height 
); 
 876 // For implementation purposes - sometimes decorations make the client area 
 878 wxPoint 
wxWindowX11::GetClientAreaOrigin() const 
 880     return wxPoint(0, 0); 
 883 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
) 
 885     Window xwindow 
= (Window
) m_mainWindow
; 
 887     wxCHECK_RET( xwindow
, wxT("invalid window") ); 
 891     XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height 
); 
 892     if (m_mainWindow 
!= m_clientWindow
) 
 894         xwindow 
= (Window
) m_clientWindow
; 
 896         wxWindow 
*window 
= (wxWindow
*) this; 
 897         wxRenderer 
*renderer 
= window
->GetRenderer(); 
 900             wxRect border 
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle 
& wxBORDER_MASK
) ); 
 903             width 
-= border
.x 
+ border
.width
; 
 904             height 
-= border
.y 
+ border
.height
; 
 912         wxScrollBar 
*sb 
= window
->GetScrollbar( wxHORIZONTAL 
); 
 913         if (sb 
&& sb
->IsShown()) 
 915             wxSize size 
= sb
->GetSize(); 
 918         sb 
= window
->GetScrollbar( wxVERTICAL 
); 
 919         if (sb 
&& sb
->IsShown()) 
 921             wxSize size 
= sb
->GetSize(); 
 925         XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) ); 
 930     XWindowChanges windowChanges
; 
 933     windowChanges
.width 
= width
; 
 934     windowChanges
.height 
= height
; 
 935     windowChanges
.stack_mode 
= 0; 
 936     int valueMask 
= CWX 
| CWY 
| CWWidth 
| CWHeight
; 
 938     XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges 
); 
 943 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
) 
 951     XSizeHints sizeHints
; 
 954     if (minW 
> -1 && minH 
> -1) 
 956         sizeHints
.flags 
|= PMinSize
; 
 957         sizeHints
.min_width 
= minW
; 
 958         sizeHints
.min_height 
= minH
; 
 960     if (maxW 
> -1 && maxH 
> -1) 
 962         sizeHints
.flags 
|= PMaxSize
; 
 963         sizeHints
.max_width 
= maxW
; 
 964         sizeHints
.max_height 
= maxH
; 
 966     if (incW 
> -1 && incH 
> -1) 
 968         sizeHints
.flags 
|= PResizeInc
; 
 969         sizeHints
.width_inc 
= incW
; 
 970         sizeHints
.height_inc 
= incH
; 
 973     XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints 
); 
 977 // --------------------------------------------------------------------------- 
 979 // --------------------------------------------------------------------------- 
 981 int wxWindowX11::GetCharHeight() const 
 983     wxCHECK_MSG( m_font
.Ok(), 0, wxT("valid window font needed") ); 
 986     // There should be an easier way. 
 987     PangoLayout 
*layout 
= pango_layout_new( wxTheApp
->GetPangoContext() ); 
 988     pango_layout_set_font_description( layout
, GetFont().GetNativeFontInfo()->description 
); 
 989     pango_layout_set_text(layout
, "H", 1 ); 
 991     pango_layout_get_pixel_size(layout
, &w
, &h
); 
 992     g_object_unref( G_OBJECT( layout 
) ); 
 996     WXFontStructPtr pFontStruct 
= m_font
.GetFontStruct(1.0, wxGlobalDisplay()); 
 998     int direction
, ascent
, descent
; 
1000     XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
, 
1001         &descent
, &overall
); 
1003     //  return (overall.ascent + overall.descent); 
1004     return (ascent 
+ descent
); 
1008 int wxWindowX11::GetCharWidth() const 
1010     wxCHECK_MSG( m_font
.Ok(), 0, wxT("valid window font needed") ); 
1013     // There should be an easier way. 
1014     PangoLayout 
*layout 
= pango_layout_new( wxTheApp
->GetPangoContext() ); 
1015     pango_layout_set_font_description( layout
, GetFont().GetNativeFontInfo()->description 
); 
1016     pango_layout_set_text(layout
, "H", 1 ); 
1018     pango_layout_get_pixel_size(layout
, &w
, &h
); 
1019     g_object_unref( G_OBJECT( layout 
) ); 
1023     WXFontStructPtr pFontStruct 
= m_font
.GetFontStruct(1.0, wxGlobalDisplay()); 
1025     int direction
, ascent
, descent
; 
1026     XCharStruct overall
; 
1027     XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
, 
1028         &descent
, &overall
); 
1030     return overall
.width
; 
1034 void wxWindowX11::GetTextExtent(const wxString
& string
, 
1036                              int *descent
, int *externalLeading
, 
1037                              const wxFont 
*theFont
) const 
1039     wxFont fontToUse 
= m_font
; 
1040     if (theFont
) fontToUse 
= *theFont
; 
1042     wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") ); 
1044     if (string
.IsEmpty()) 
1052     PangoLayout 
*layout 
= pango_layout_new( wxTheApp
->GetPangoContext() ); 
1054     PangoFontDescription 
*desc 
= fontToUse
.GetNativeFontInfo()->description
; 
1055     pango_layout_set_font_description(layout
, desc
); 
1057     const wxCharBuffer data 
= wxConvUTF8
.cWC2MB( string 
); 
1058     pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data 
)); 
1060     PangoLayoutLine 
*line 
= (PangoLayoutLine 
*)pango_layout_get_lines(layout
)->data
; 
1063     PangoRectangle rect
; 
1064     pango_layout_line_get_extents(line
, NULL
, &rect
); 
1066     if (x
) (*x
) = (wxCoord
) (rect
.width 
/ PANGO_SCALE
); 
1067     if (y
) (*y
) = (wxCoord
) (rect
.height 
/ PANGO_SCALE
); 
1070         // Do something about metrics here 
1073     if (externalLeading
) (*externalLeading
) = 0;  // ?? 
1075     g_object_unref( G_OBJECT( layout 
) ); 
1077     WXFontStructPtr pFontStruct 
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay()); 
1079     int direction
, ascent
, descent2
; 
1080     XCharStruct overall
; 
1081     int slen 
= string
.Len(); 
1083     XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
, 
1084                  &direction
, &ascent
, &descent2
, &overall
); 
1087         *x 
= (overall
.width
); 
1089         *y 
= (ascent 
+ descent2
); 
1091         *descent 
= descent2
; 
1092     if (externalLeading
) 
1093         *externalLeading 
= 0; 
1097 // ---------------------------------------------------------------------------- 
1099 // ---------------------------------------------------------------------------- 
1101 void wxWindowX11::Refresh(bool eraseBack
, const wxRect 
*rect
) 
1107             // Schedule for later Updating in ::Update() or ::OnInternalIdle(). 
1108             m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height 
); 
1113             GetSize( &width
, &height 
); 
1115             // Schedule for later Updating in ::Update() or ::OnInternalIdle(). 
1116             m_clearRegion
.Clear(); 
1117             m_clearRegion
.Union( 0, 0, width
, height 
); 
1123          // Schedule for later Updating in ::Update() or ::OnInternalIdle(). 
1124          m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height 
); 
1129         GetSize( &width
, &height 
); 
1131         // Schedule for later Updating in ::Update() or ::OnInternalIdle(). 
1132         m_updateRegion
.Clear(); 
1133         m_updateRegion
.Union( 0, 0, width
, height 
); 
1137 void wxWindowX11::Update() 
1141         // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName()); 
1142         // Send nc paint events. 
1143         SendNcPaintEvents(); 
1146     if (!m_updateRegion
.IsEmpty()) 
1148         // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName()); 
1149         // Actually send erase events. 
1152         // Actually send paint events. 
1157 void wxWindowX11::SendEraseEvents() 
1159     if (m_clearRegion
.IsEmpty()) return; 
1161     wxClientDC 
dc( (wxWindow
*)this ); 
1162     dc
.SetClippingRegion( m_clearRegion 
); 
1164     wxEraseEvent 
erase_event( GetId(), &dc 
); 
1165     erase_event
.SetEventObject( this ); 
1167     if (!GetEventHandler()->ProcessEvent(erase_event
) ) 
1169         Display 
*xdisplay 
= wxGlobalDisplay(); 
1170         Window xwindow 
= (Window
) GetClientAreaWindow(); 
1171         XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() ); 
1173         wxRegionIterator 
upd( m_clearRegion 
); 
1176             XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, 
1177                             upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() ); 
1182     m_clearRegion
.Clear(); 
1185 void wxWindowX11::SendPaintEvents() 
1187     //    wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId()); 
1189     m_clipPaintRegion 
= TRUE
; 
1191     wxPaintEvent 
paint_event( GetId() ); 
1192     paint_event
.SetEventObject( this ); 
1193     GetEventHandler()->ProcessEvent( paint_event 
); 
1195     m_updateRegion
.Clear(); 
1197     m_clipPaintRegion 
= FALSE
; 
1200 void wxWindowX11::SendNcPaintEvents() 
1202     wxWindow 
*window 
= (wxWindow
*) this; 
1204     // All this for drawing the small square between the scrollbars. 
1209     wxScrollBar 
*sb 
= window
->GetScrollbar( wxHORIZONTAL 
); 
1210     if (sb 
&& sb
->IsShown()) 
1212         height 
= sb
->GetSize().y
; 
1213         y 
= sb
->GetPosition().y
; 
1215         sb 
= window
->GetScrollbar( wxVERTICAL 
); 
1216         if (sb 
&& sb
->IsShown()) 
1218             width 
= sb
->GetSize().x
; 
1219             x 
= sb
->GetPosition().x
; 
1221             Display 
*xdisplay 
= wxGlobalDisplay(); 
1222             Window xwindow 
= (Window
) GetMainWindow(); 
1223             Colormap cm 
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() ); 
1224             wxColour colour 
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
); 
1225             colour
.CalcPixel( (WXColormap
) cm 
); 
1227             XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() ); 
1229             XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height 
); 
1233     wxNcPaintEvent 
nc_paint_event( GetId() ); 
1234     nc_paint_event
.SetEventObject( this ); 
1235     GetEventHandler()->ProcessEvent( nc_paint_event 
); 
1237     m_updateNcArea 
= FALSE
; 
1240 // ---------------------------------------------------------------------------- 
1242 // ---------------------------------------------------------------------------- 
1244 // Responds to colour changes: passes event on to children. 
1245 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
) 
1247     wxWindowList::compatibility_iterator node 
= GetChildren().GetFirst(); 
1250         // Only propagate to non-top-level windows 
1251         wxWindow 
*win 
= node
->GetData(); 
1252         if ( win
->GetParent() ) 
1254             wxSysColourChangedEvent event2
; 
1255             event
.m_eventObject 
= win
; 
1256             win
->GetEventHandler()->ProcessEvent(event2
); 
1259         node 
= node
->GetNext(); 
1263 // See handler for InFocus case in app.cpp for details. 
1264 wxWindow
* g_GettingFocus 
= NULL
; 
1266 void wxWindowX11::OnInternalIdle() 
1268     // Update invalidated regions. 
1271     // This calls the UI-update mechanism (querying windows for 
1272     // menu/toolbar/control state information) 
1273     if (wxUpdateUIEvent::CanUpdate((wxWindow
*) this)) 
1274         UpdateWindowUI(wxUPDATE_UI_FROMIDLE
); 
1276     // Set the input focus if couldn't do it before 
1277     if (m_needsInputFocus
) 
1281         msg
.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName()); 
1282         printf(msg
.c_str()); 
1286         // If it couldn't set the focus now, there's 
1287         // no point in trying again. 
1288         m_needsInputFocus 
= FALSE
; 
1290     g_GettingFocus 
= NULL
; 
1293 // ---------------------------------------------------------------------------- 
1294 // function which maintain the global hash table mapping Widgets to wxWidgets 
1295 // ---------------------------------------------------------------------------- 
1297 static bool DoAddWindowToTable(wxWindowHash 
*hash
, Window w
, wxWindow 
*win
) 
1299     if ( !hash
->insert(wxWindowHash::value_type(w
, win
)).second 
) 
1301         wxLogDebug( wxT("Widget table clash: new widget is 0x%08x, %s"), 
1302                     (unsigned int)w
, win
->GetClassInfo()->GetClassName()); 
1306     wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"), 
1307                 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName()); 
1312 static inline wxWindow 
*DoGetWindowFromTable(wxWindowHash 
*hash
, Window w
) 
1314     wxWindowHash::iterator i 
= hash
->find(w
); 
1315     return i 
== hash
->end() ? NULL 
: i
->second
; 
1318 static inline void DoDeleteWindowFromTable(wxWindowHash 
*hash
, Window w
) 
1320     wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x deleted"), (unsigned int) w
); 
1325 // ---------------------------------------------------------------------------- 
1327 // ---------------------------------------------------------------------------- 
1329 bool wxAddWindowToTable(Window w
, wxWindow 
*win
) 
1331     return DoAddWindowToTable(wxWidgetHashTable
, w
, win
); 
1334 wxWindow 
*wxGetWindowFromTable(Window w
) 
1336     return DoGetWindowFromTable(wxWidgetHashTable
, w
); 
1339 void wxDeleteWindowFromTable(Window w
) 
1341     DoDeleteWindowFromTable(wxWidgetHashTable
, w
); 
1344 bool wxAddClientWindowToTable(Window w
, wxWindow 
*win
) 
1346     return DoAddWindowToTable(wxClientWidgetHashTable
, w
, win
); 
1349 wxWindow 
*wxGetClientWindowFromTable(Window w
) 
1351     return DoGetWindowFromTable(wxClientWidgetHashTable
, w
); 
1354 void wxDeleteClientWindowFromTable(Window w
) 
1356     DoDeleteWindowFromTable(wxClientWidgetHashTable
, w
); 
1359 // ---------------------------------------------------------------------------- 
1360 // X11-specific accessors 
1361 // ---------------------------------------------------------------------------- 
1363 WXWindow 
wxWindowX11::GetMainWindow() const 
1365     return m_mainWindow
; 
1368 WXWindow 
wxWindowX11::GetClientAreaWindow() const 
1370     return m_clientWindow
; 
1373 // ---------------------------------------------------------------------------- 
1374 // TranslateXXXEvent() functions 
1375 // ---------------------------------------------------------------------------- 
1377 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow 
*win
, Window window
, XEvent 
*xevent
) 
1379     switch (XEventGetType(xevent
)) 
1387             wxEventType eventType 
= wxEVT_NULL
; 
1389             if (XEventGetType(xevent
) == EnterNotify
) 
1391                 //if (local_event.xcrossing.mode!=NotifyNormal) 
1392                 //  return ; // Ignore grab events 
1393                 eventType 
= wxEVT_ENTER_WINDOW
; 
1394                 //            canvas->GetEventHandler()->OnSetFocus(); 
1396             else if (XEventGetType(xevent
) == LeaveNotify
) 
1398                 //if (local_event.xcrossingr.mode!=NotifyNormal) 
1399                 //  return ; // Ignore grab events 
1400                 eventType 
= wxEVT_LEAVE_WINDOW
; 
1401                 //            canvas->GetEventHandler()->OnKillFocus(); 
1403             else if (XEventGetType(xevent
) == MotionNotify
) 
1405                 eventType 
= wxEVT_MOTION
; 
1407             else if (XEventGetType(xevent
) == ButtonPress
) 
1409                 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
)); 
1411                 if (XButtonEventLChanged(xevent
)) 
1413                     eventType 
= wxEVT_LEFT_DOWN
; 
1416                 else if (XButtonEventMChanged(xevent
)) 
1418                     eventType 
= wxEVT_MIDDLE_DOWN
; 
1421                 else if (XButtonEventRChanged(xevent
)) 
1423                     eventType 
= wxEVT_RIGHT_DOWN
; 
1427                 // check for a double click 
1428                 // TODO: where can we get this value from? 
1429                 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay()); 
1430                 long dclickTime 
= 200; 
1431                 long ts 
= wxevent
.GetTimestamp(); 
1433                 int buttonLast 
= win
->GetLastClickedButton(); 
1434                 long lastTS 
= win
->GetLastClickTime(); 
1435                 if ( buttonLast 
&& buttonLast 
== button 
&& (ts 
- lastTS
) < dclickTime 
) 
1438                     win
->SetLastClick(0, ts
); 
1439                     if ( eventType 
== wxEVT_LEFT_DOWN 
) 
1440                         eventType 
= wxEVT_LEFT_DCLICK
; 
1441                     else if ( eventType 
== wxEVT_MIDDLE_DOWN 
) 
1442                         eventType 
= wxEVT_MIDDLE_DCLICK
; 
1443                     else if ( eventType 
== wxEVT_RIGHT_DOWN 
) 
1444                         eventType 
= wxEVT_RIGHT_DCLICK
; 
1448                     // not fast enough or different button 
1449                     win
->SetLastClick(button
, ts
); 
1452             else if (XEventGetType(xevent
) == ButtonRelease
) 
1454                 if (XButtonEventLChanged(xevent
)) 
1456                     eventType 
= wxEVT_LEFT_UP
; 
1458                 else if (XButtonEventMChanged(xevent
)) 
1460                     eventType 
= wxEVT_MIDDLE_UP
; 
1462                 else if (XButtonEventRChanged(xevent
)) 
1464                     eventType 
= wxEVT_RIGHT_UP
; 
1473             wxevent
.SetEventType(eventType
); 
1475             wxevent
.m_x 
= XButtonEventGetX(xevent
); 
1476             wxevent
.m_y 
= XButtonEventGetY(xevent
); 
1478             wxevent
.m_leftDown 
= ((eventType 
== wxEVT_LEFT_DOWN
) 
1479                 || (XButtonEventLIsDown(xevent
) 
1480                 && (eventType 
!= wxEVT_LEFT_UP
))); 
1481             wxevent
.m_middleDown 
= ((eventType 
== wxEVT_MIDDLE_DOWN
) 
1482                 || (XButtonEventMIsDown(xevent
) 
1483                 && (eventType 
!= wxEVT_MIDDLE_UP
))); 
1484             wxevent
.m_rightDown 
= ((eventType 
== wxEVT_RIGHT_DOWN
) 
1485                 || (XButtonEventRIsDown (xevent
) 
1486                 && (eventType 
!= wxEVT_RIGHT_UP
))); 
1488             wxevent
.m_shiftDown 
= XButtonEventShiftIsDown(xevent
); 
1489             wxevent
.m_controlDown 
= XButtonEventCtrlIsDown(xevent
); 
1490             wxevent
.m_altDown 
= XButtonEventAltIsDown(xevent
); 
1491             wxevent
.m_metaDown 
= XButtonEventMetaIsDown(xevent
); 
1493             wxevent
.SetId(win
->GetId()); 
1494             wxevent
.SetEventObject(win
); 
1502 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow 
*win
, Window 
WXUNUSED(win
), XEvent 
*xevent
, bool isAscii
) 
1504     switch (XEventGetType(xevent
)) 
1512             (void) XLookupString ((XKeyEvent 
*) xevent
, buf
, 20, &keySym
, NULL
); 
1513             int id 
= wxCharCodeXToWX (keySym
); 
1514             // id may be WXK_xxx code - these are outside ASCII range, so we 
1515             // can't just use toupper() on id. 
1516             // Only change this if we want the raw key that was pressed, 
1517             // and don't change it if we want an ASCII value. 
1518             if (!isAscii 
&& (id 
>= 'a' && id 
<= 'z')) 
1520                 id 
= id 
+ 'A' - 'a'; 
1523             wxevent
.m_shiftDown 
= XKeyEventShiftIsDown(xevent
); 
1524             wxevent
.m_controlDown 
= XKeyEventCtrlIsDown(xevent
); 
1525             wxevent
.m_altDown 
= XKeyEventAltIsDown(xevent
); 
1526             wxevent
.m_metaDown 
= XKeyEventMetaIsDown(xevent
); 
1527             wxevent
.SetEventObject(win
); 
1528             wxevent
.m_keyCode 
= id
; 
1529             wxevent
.SetTimestamp(XKeyEventGetTime(xevent
)); 
1531             wxevent
.m_x 
= XKeyEventGetX(xevent
); 
1532             wxevent
.m_y 
= XKeyEventGetY(xevent
); 
1542 // ---------------------------------------------------------------------------- 
1544 // ---------------------------------------------------------------------------- 
1546 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
) 
1548     wxWindowBase::SetBackgroundColour(col
); 
1550     Display 
*xdisplay 
= (Display
*) wxGlobalDisplay(); 
1551     int xscreen 
= DefaultScreen( xdisplay 
); 
1552     Colormap cm 
= DefaultColormap( xdisplay
, xscreen 
); 
1554     m_backgroundColour
.CalcPixel( (WXColormap
) cm 
); 
1556     // We don't set the background colour as we paint 
1557     // the background ourselves. 
1558     // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() ); 
1563 bool wxWindowX11::SetForegroundColour(const wxColour
& col
) 
1565     if ( !wxWindowBase::SetForegroundColour(col
) ) 
1571 // ---------------------------------------------------------------------------- 
1573 // ---------------------------------------------------------------------------- 
1575 wxWindow 
*wxGetActiveWindow() 
1578     wxFAIL_MSG(wxT("Not implemented")); 
1583 wxWindow 
*wxWindowBase::GetCapture() 
1585     return (wxWindow 
*)g_captureWindow
; 
1589 // Find the wxWindow at the current mouse position, returning the mouse 
1591 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
) 
1593     return wxFindWindowAtPoint(wxGetMousePosition()); 
1596 // Get the current mouse position. 
1597 wxPoint 
wxGetMousePosition() 
1601     return wxPoint(0, 0); 
1603     Display 
*display 
= wxGlobalDisplay(); 
1604     Window rootWindow 
= RootWindowOfScreen (DefaultScreenOfDisplay(display
)); 
1605     Window rootReturn
, childReturn
; 
1606     int rootX
, rootY
, winX
, winY
; 
1607     unsigned int maskReturn
; 
1609     XQueryPointer (display
, 
1613                    &rootX
, &rootY
, &winX
, &winY
, &maskReturn
); 
1614     return wxPoint(rootX
, rootY
); 
1619 // ---------------------------------------------------------------------------- 
1620 // wxNoOptimize: switch off size optimization 
1621 // ---------------------------------------------------------------------------- 
1623 int wxNoOptimize::ms_count 
= 0; 
1626 // ---------------------------------------------------------------------------- 
1628 // ---------------------------------------------------------------------------- 
1630 class wxWinModule 
: public wxModule
 
1637     DECLARE_DYNAMIC_CLASS(wxWinModule
) 
1640 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
) 
1642 bool wxWinModule::OnInit() 
1644     Display 
*xdisplay 
= wxGlobalDisplay(); 
1645     int xscreen 
= DefaultScreen( xdisplay 
); 
1646     Window xroot 
= RootWindow( xdisplay
, xscreen 
); 
1647     g_eraseGC 
= XCreateGC( xdisplay
, xroot
, 0, NULL 
); 
1648     XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid 
); 
1653 void wxWinModule::OnExit() 
1655     Display 
*xdisplay 
= wxGlobalDisplay(); 
1656     XFreeGC( xdisplay
, g_eraseGC 
);