1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
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/module.h"
40 #include "wx/menuitem.h"
43 #if wxUSE_DRAG_AND_DROP
47 #include "wx/x11/private.h"
48 #include "X11/Xutil.h"
52 // ----------------------------------------------------------------------------
53 // global variables for this module
54 // ----------------------------------------------------------------------------
56 extern wxHashTable
*wxWidgetHashTable
;
57 static wxWindow
* g_captureWindow
= NULL
;
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
64 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
65 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
73 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
74 EVT_SYS_COLOUR_CHANGED(wxWindowX11
::OnSysColourChanged
)
77 // ============================================================================
79 // ============================================================================
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 void wxWindowX11
::Init()
91 // generic initializations first
95 m_mainWidget
= (WXWindow
) 0;
96 m_winCaptured
= FALSE
;
97 m_needsInputFocus
= FALSE
;
99 m_isBeingDeleted
= FALSE
;
104 // real construction (Init() must have been called before!)
105 bool wxWindowX11
::Create(wxWindow
*parent
, wxWindowID id
,
109 const wxString
& name
)
111 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
113 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
115 parent
->AddChild(this);
117 int w
= size
.GetWidth();
118 int h
= size
.GetHeight();
126 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
127 int xscreen
= DefaultScreen( xdisplay
);
128 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
130 m_backgroundColour
= wxSystemSettings
::GetColour(wxSYS_COLOUR_3DFACE
);
131 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
133 m_foregroundColour
= *wxBLACK
;
134 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
136 Window parentWindow
= (Window
) parent
->GetMainWindow();
150 Window xwindow
= XCreateSimpleWindow(
151 xdisplay
, parentWindow
,
152 pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 0,
153 m_backgroundColour
.GetPixel(),
154 m_backgroundColour
.GetPixel() );
156 m_mainWidget
= (WXWindow
) xwindow
;
158 // Select event types wanted
159 XSelectInput( xdisplay
, xwindow
,
160 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
161 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
162 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
165 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
167 // Is a subwindow, so map immediately
169 XMapWindow( xdisplay
, xwindow
);
171 // Without this, the cursor may not be restored properly (e.g. in splitter
173 SetCursor(*wxSTANDARD_CURSOR
);
174 SetFont(wxSystemSettings
::GetFont(wxSYS_DEFAULT_GUI_FONT
));
176 // Set background to None which will prevent X11 from clearing the
177 // background comletely.
178 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
180 // Don't call this, it can have nasty repercussions for composite controls,
182 // SetSize(pos.x, pos.y, size.x, size.y);
188 wxWindowX11
::~wxWindowX11()
190 if (g_captureWindow
== this)
191 g_captureWindow
= NULL
;
193 m_isBeingDeleted
= TRUE
;
195 // X11-specific actions first
196 Window main
= (Window
) m_mainWidget
;
199 // Removes event handlers
200 //DetachWidget(main);
204 m_parent
->RemoveChild( this );
208 // Destroy the window
211 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
212 wxDeleteWindowFromTable( main
);
213 XDestroyWindow( wxGlobalDisplay(), main
);
218 // ---------------------------------------------------------------------------
220 // ---------------------------------------------------------------------------
222 void wxWindowX11
::SetFocus()
224 Window xwindow
= (Window
) GetMainWindow();
226 wxCHECK_RET( xwindow
, wxT("invalid window") );
228 if (wxWindowIsVisible(xwindow
))
230 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
231 m_needsInputFocus
= FALSE
;
235 m_needsInputFocus
= TRUE
;
239 // Get the window with the focus
240 wxWindow
*wxWindowBase
::FindFocus()
242 Window xfocus
= (Window
) 0;
245 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
248 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
256 // Enabling/disabling handled by event loop, and not sending events
258 bool wxWindowX11
::Enable(bool enable
)
260 if ( !wxWindowBase
::Enable(enable
) )
266 bool wxWindowX11
::Show(bool show
)
268 wxWindowBase
::Show(show
);
270 Window xwin
= (Window
) GetXWindow();
271 Display
*xdisp
= (Display
*) GetXDisplay();
275 msg
.Printf("Mapping window of type %s", GetClassInfo()->GetClassName());
277 XMapWindow(xdisp
, xwin
);
283 msg
.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName());
285 XUnmapWindow(xdisp
, xwin
);
291 // Raise the window to the top of the Z order
292 void wxWindowX11
::Raise()
295 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
298 // Lower the window to the bottom of the Z order
299 void wxWindowX11
::Lower()
302 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
305 void wxWindowX11
::DoCaptureMouse()
307 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
309 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
320 Window xwindow
= (Window
) GetMainWindow();
322 wxCHECK_RET( xwindow
, wxT("invalid window") );
324 g_captureWindow
= (wxWindow
*) this;
328 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
330 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
334 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
337 if (res
!= GrabSuccess
)
340 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
342 if (res
== GrabNotViewable
)
344 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
346 g_captureWindow
= NULL
;
350 wxLogDebug("Grabbed pointer");
353 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
354 (Window
) GetMainWindow(),
356 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
362 if (res
!= GrabSuccess
)
364 wxLogDebug("Failed to grab mouse buttons.");
365 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
371 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
372 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
378 if (res
!= GrabSuccess
)
380 wxLogDebug("Failed to grab keyboard.");
381 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
382 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
383 (Window
) GetMainWindow());
388 m_winCaptured
= TRUE
;
392 void wxWindowX11
::DoReleaseMouse()
394 g_captureWindow
= NULL
;
396 if ( !m_winCaptured
)
399 Window xwindow
= (Window
) GetMainWindow();
403 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
405 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
406 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
409 wxLogDebug("Ungrabbed pointer");
411 m_winCaptured
= FALSE
;
414 bool wxWindowX11
::SetFont(const wxFont
& font
)
416 if ( !wxWindowBase
::SetFont(font
) )
425 bool wxWindowX11
::SetCursor(const wxCursor
& cursor
)
427 if ( !wxWindowBase
::SetCursor(cursor
) )
433 Window xwindow
= (Window
) GetMainWindow();
435 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
437 wxCursor cursorToUse
;
439 cursorToUse
= m_cursor
;
441 cursorToUse
= *wxSTANDARD_CURSOR
;
443 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
445 XDefineCursor( (Display
*) wxGlobalDisplay(), xwindow
, xcursor
);
450 // Coordinates relative to the window
451 void wxWindowX11
::WarpPointer (int x
, int y
)
453 Window xwindow
= (Window
) GetMainWindow();
455 wxCHECK_RET( xwindow
, wxT("invalid window") );
457 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
460 // Does a physical scroll
461 void wxWindowX11
::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
467 // Use specified rectangle
468 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
472 // Use whole client area
474 GetClientSize(& w
, & h
);
477 wxNode
*cnode
= m_children
.First();
480 wxWindow
*child
= (wxWindow
*) cnode
->Data();
483 child
->GetSize( &sx
, &sy
);
484 wxPoint
pos( child
->GetPosition() );
485 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
486 cnode
= cnode
->Next();
489 int x1
= (dx
>= 0) ? x
: x
- dx
;
490 int y1
= (dy
>= 0) ? y
: y
- dy
;
491 int w1
= w
- abs(dx
);
492 int h1
= h
- abs(dy
);
493 int x2
= (dx
>= 0) ? x
+ dx
: x
;
494 int y2
= (dy
>= 0) ? y
+ dy
: y
;
496 wxClientDC
dc((wxWindow
*) this);
498 dc
.SetLogicalFunction (wxCOPY
);
500 Window window
= (Window
) GetMainWindow();
501 Display
* display
= wxGlobalDisplay();
503 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
504 x1
, y1
, w1
, h1
, x2
, y2
);
506 dc
.SetAutoSetting(TRUE
);
507 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
508 dc
.SetBrush(brush
); // FIXME: needed?
510 // We'll add rectangles to the list of update rectangles according to which
511 // bits we've exposed.
516 wxRect
*rect
= new wxRect
;
522 XFillRectangle(display
, window
,
523 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
527 rect
->width
= rect
->width
;
528 rect
->height
= rect
->height
;
530 updateRects
.Append((wxObject
*) rect
);
534 wxRect
*rect
= new wxRect
;
536 rect
->x
= x
+ w
+ dx
;
541 XFillRectangle(display
, window
,
542 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
547 rect
->width
= rect
->width
;
548 rect
->height
= rect
->height
;
550 updateRects
.Append((wxObject
*) rect
);
554 wxRect
*rect
= new wxRect
;
561 XFillRectangle(display
, window
,
562 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
566 rect
->width
= rect
->width
;
567 rect
->height
= rect
->height
;
569 updateRects
.Append((wxObject
*) rect
);
573 wxRect
*rect
= new wxRect
;
576 rect
->y
= y
+ h
+ dy
;
580 XFillRectangle(display
, window
,
581 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
585 rect
->width
= rect
->width
;
586 rect
->height
= rect
->height
;
588 updateRects
.Append((wxObject
*) rect
);
590 dc
.SetBrush(wxNullBrush
);
592 // Now send expose events
594 wxNode
* node
= updateRects
.First();
597 wxRect
* rect
= (wxRect
*) node
->Data();
601 event
.display
= display
;
602 event
.send_event
= True
;
603 event
.window
= window
;
607 event
.width
= rect
->width
;
608 event
.height
= rect
->height
;
612 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
618 // Delete the update rects
619 node
= updateRects
.First();
622 wxRect
* rect
= (wxRect
*) node
->Data();
629 // ---------------------------------------------------------------------------
631 // ---------------------------------------------------------------------------
633 #if wxUSE_DRAG_AND_DROP
635 void wxWindowX11
::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
642 // Old style file-manager drag&drop
643 void wxWindowX11
::DragAcceptFiles(bool WXUNUSED(accept
))
648 // ----------------------------------------------------------------------------
650 // ----------------------------------------------------------------------------
654 void wxWindowX11
::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
659 #endif // wxUSE_TOOLTIPS
661 // ---------------------------------------------------------------------------
662 // moving and resizing
663 // ---------------------------------------------------------------------------
665 bool wxWindowX11
::PreResize()
671 void wxWindowX11
::DoGetSize(int *x
, int *y
) const
673 Window xwindow
= (Window
) GetMainWindow();
675 wxCHECK_RET( xwindow
, wxT("invalid window") );
677 XSync(wxGlobalDisplay(), False
);
678 XWindowAttributes attr
;
679 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
684 *x
= attr
.width
/* + 2*m_borderSize */ ;
685 *y
= attr
.height
/* + 2*m_borderSize */ ;
689 void wxWindowX11
::DoGetPosition(int *x
, int *y
) const
691 Window window
= (Window
) m_mainWidget
;
694 XSync(wxGlobalDisplay(), False
);
695 XWindowAttributes attr
;
696 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
704 // We may be faking the client origin. So a window that's really at (0, 30)
705 // may appear (to wxWin apps) to be at (0, 0).
708 wxPoint
pt(GetParent()->GetClientAreaOrigin());
716 void wxWindowX11
::DoScreenToClient(int *x
, int *y
) const
718 Display
*display
= wxGlobalDisplay();
719 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
720 Window thisWindow
= (Window
) m_mainWidget
;
725 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
728 void wxWindowX11
::DoClientToScreen(int *x
, int *y
) const
730 Display
*display
= wxGlobalDisplay();
731 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
732 Window thisWindow
= (Window
) m_mainWidget
;
737 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
741 // Get size *available for subwindows* i.e. excluding menu bar etc.
742 void wxWindowX11
::DoGetClientSize(int *x
, int *y
) const
744 Window window
= (Window
) m_mainWidget
;
748 XSync(wxGlobalDisplay(), False
);
749 XWindowAttributes attr
;
750 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
761 void wxWindowX11
::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
763 if (!GetMainWindow())
766 XWindowChanges windowChanges
;
769 windowChanges
.width
= 0;
770 windowChanges
.height
= 0;
771 windowChanges
.stack_mode
= 0;
774 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
777 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
781 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
784 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
788 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
790 windowChanges
.width
= width
/* - m_borderSize*2 */;
791 if (windowChanges
.width
== 0)
792 windowChanges
.width
= 1;
793 valueMask
|= CWWidth
;
795 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
797 windowChanges
.height
= height
/* -m_borderSize*2*/;
798 if (windowChanges
.height
== 0)
799 windowChanges
.height
= 1;
800 valueMask
|= CWHeight
;
803 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
804 valueMask
, & windowChanges
);
805 XSync(wxGlobalDisplay(), False
);
808 void wxWindowX11
::DoSetClientSize(int width
, int height
)
810 if (!GetMainWindow())
813 XWindowChanges windowChanges
;
818 windowChanges
.width
= width
;
819 valueMask
|= CWWidth
;
823 windowChanges
.height
= height
;
824 valueMask
|= CWHeight
;
826 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
827 valueMask
, & windowChanges
);
828 XSync(wxGlobalDisplay(), False
);
831 // For implementation purposes - sometimes decorations make the client area
833 wxPoint wxWindowX11
::GetClientAreaOrigin() const
835 return wxPoint(0, 0);
838 // Makes an adjustment to the window position (for example, a frame that has
839 // a toolbar that it manages itself).
840 void wxWindowX11
::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
842 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
844 wxPoint
pt(GetParent()->GetClientAreaOrigin());
845 x
+= pt
.x
; y
+= pt
.y
;
849 void wxWindowX11
::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
856 XSizeHints sizeHints
;
859 if (minW
> -1 && minH
> -1)
861 sizeHints
.flags
|= PMinSize
;
862 sizeHints
.min_width
= minW
;
863 sizeHints
.min_height
= minH
;
865 if (maxW
> -1 && maxH
> -1)
867 sizeHints
.flags
|= PMaxSize
;
868 sizeHints
.max_width
= maxW
;
869 sizeHints
.max_height
= maxH
;
871 if (incW
> -1 && incH
> -1)
873 sizeHints
.flags
|= PResizeInc
;
874 sizeHints
.width_inc
= incW
;
875 sizeHints
.height_inc
= incH
;
878 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
881 void wxWindowX11
::DoMoveWindow(int x
, int y
, int width
, int height
)
883 DoSetSize(x
, y
, width
, height
);
886 // ---------------------------------------------------------------------------
888 // ---------------------------------------------------------------------------
890 int wxWindowX11
::GetCharHeight() const
892 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
894 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
896 int direction
, ascent
, descent
;
898 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
901 // return (overall.ascent + overall.descent);
902 return (ascent
+ descent
);
905 int wxWindowX11
::GetCharWidth() const
907 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
909 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
911 int direction
, ascent
, descent
;
913 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
916 return overall
.width
;
919 void wxWindowX11
::GetTextExtent(const wxString
& string
,
921 int *descent
, int *externalLeading
,
922 const wxFont
*theFont
) const
924 wxFont fontToUse
= m_font
;
925 if (theFont
) fontToUse
= *theFont
;
927 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
929 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
931 int direction
, ascent
, descent2
;
933 int slen
= string
.Len();
937 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
938 &ascent
, &descent2
, &overall
);
941 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
942 &direction
, &ascent
, &descent2
, &overall
);
945 *x
= (overall
.width
);
947 *y
= (ascent
+ descent2
);
951 *externalLeading
= 0;
955 // ----------------------------------------------------------------------------
957 // ----------------------------------------------------------------------------
959 void wxWindowX11
::Refresh(bool eraseBack
, const wxRect
*rect
)
965 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
966 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
971 GetSize( &width
, &height
);
973 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
974 m_clearRegion
.Clear();
975 m_clearRegion
.Union( 0, 0, width
, height
);
981 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
982 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
987 GetSize( &width
, &height
);
989 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
990 m_updateRegion
.Clear();
991 m_updateRegion
.Union( 0, 0, width
, height
);
995 void wxWindowX11
::Update()
997 if (!m_updateRegion
.IsEmpty())
999 // Actually send erase and paint events.
1000 X11SendPaintEvents();
1004 void wxWindowX11
::Clear()
1006 wxClientDC
dc((wxWindow
*) this);
1007 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1008 dc
.SetBackground(brush
);
1012 void wxWindowX11
::X11SendPaintEvents()
1014 m_clipPaintRegion
= TRUE
;
1016 if (!m_clearRegion
.IsEmpty())
1018 wxWindowDC
dc( (wxWindow
*)this );
1019 dc
.SetClippingRegion( m_clearRegion
);
1021 wxEraseEvent
erase_event( GetId(), &dc
);
1022 erase_event
.SetEventObject( this );
1024 if (!GetEventHandler()->ProcessEvent(erase_event
))
1026 printf( "Hallo!\n" );
1027 Window xwindow
= (Window
) GetMainWindow();
1028 Display
*xdisplay
= wxGlobalDisplay();
1029 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
1030 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
1031 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
1032 wxRegionIterator
upd( m_clearRegion
);
1035 XFillRectangle( xdisplay
, xwindow
, xgc
,
1036 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1040 m_clearRegion
.Clear();
1043 wxNcPaintEvent
nc_paint_event( GetId() );
1044 nc_paint_event
.SetEventObject( this );
1045 GetEventHandler()->ProcessEvent( nc_paint_event
);
1047 wxPaintEvent
paint_event( GetId() );
1048 paint_event
.SetEventObject( this );
1049 GetEventHandler()->ProcessEvent( paint_event
);
1051 m_updateRegion
.Clear();
1053 m_clipPaintRegion
= FALSE
;
1056 // ----------------------------------------------------------------------------
1058 // ----------------------------------------------------------------------------
1060 // Responds to colour changes: passes event on to children.
1061 void wxWindowX11
::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1063 wxWindowList
::Node
*node
= GetChildren().GetFirst();
1066 // Only propagate to non-top-level windows
1067 wxWindow
*win
= node
->GetData();
1068 if ( win
->GetParent() )
1070 wxSysColourChangedEvent event2
;
1071 event
.m_eventObject
= win
;
1072 win
->GetEventHandler()->ProcessEvent(event2
);
1075 node
= node
->GetNext();
1079 void wxWindowX11
::OnInternalIdle()
1081 // Update invalidated regions.
1084 // This calls the UI-update mechanism (querying windows for
1085 // menu/toolbar/control state information)
1088 // Set the input focus if couldn't do it before
1089 if (m_needsInputFocus
)
1093 // ----------------------------------------------------------------------------
1094 // function which maintain the global hash table mapping Widgets to wxWindows
1095 // ----------------------------------------------------------------------------
1097 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1099 wxWindow
*oldItem
= NULL
;
1100 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1102 wxLogDebug("Widget table clash: new widget is %ld, %s",
1103 (long)w
, win
->GetClassInfo()->GetClassName());
1107 wxWidgetHashTable
->Put((long) w
, win
);
1109 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1110 w
, win
, win
->GetClassInfo()->GetClassName());
1115 wxWindow
*wxGetWindowFromTable(Window w
)
1117 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1120 void wxDeleteWindowFromTable(Window w
)
1122 wxWidgetHashTable
->Delete((long)w
);
1125 // ----------------------------------------------------------------------------
1126 // add/remove window from the table
1127 // ----------------------------------------------------------------------------
1129 // ----------------------------------------------------------------------------
1130 // X11-specific accessors
1131 // ----------------------------------------------------------------------------
1133 // Get the underlying X window
1134 WXWindow wxWindowX11
::GetXWindow() const
1136 return GetMainWindow();
1139 // Get the underlying X display
1140 WXDisplay
*wxWindowX11
::GetXDisplay() const
1142 return wxGetDisplay();
1145 WXWindow wxWindowX11
::GetMainWindow() const
1147 return m_mainWidget
;
1150 // ----------------------------------------------------------------------------
1151 // TranslateXXXEvent() functions
1152 // ----------------------------------------------------------------------------
1154 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1156 switch (xevent
->xany
.type
)
1164 wxEventType eventType
= wxEVT_NULL
;
1166 if (xevent
->xany
.type
== EnterNotify
)
1168 //if (local_event.xcrossing.mode!=NotifyNormal)
1169 // return ; // Ignore grab events
1170 eventType
= wxEVT_ENTER_WINDOW
;
1171 // canvas->GetEventHandler()->OnSetFocus();
1173 else if (xevent
->xany
.type
== LeaveNotify
)
1175 //if (local_event.xcrossingr.mode!=NotifyNormal)
1176 // return ; // Ignore grab events
1177 eventType
= wxEVT_LEAVE_WINDOW
;
1178 // canvas->GetEventHandler()->OnKillFocus();
1180 else if (xevent
->xany
.type
== MotionNotify
)
1182 eventType
= wxEVT_MOTION
;
1184 else if (xevent
->xany
.type
== ButtonPress
)
1186 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1188 if (xevent
->xbutton
.button
== Button1
)
1190 eventType
= wxEVT_LEFT_DOWN
;
1193 else if (xevent
->xbutton
.button
== Button2
)
1195 eventType
= wxEVT_MIDDLE_DOWN
;
1198 else if (xevent
->xbutton
.button
== Button3
)
1200 eventType
= wxEVT_RIGHT_DOWN
;
1204 // check for a double click
1205 // TODO: where can we get this value from?
1206 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1207 long dclickTime
= 200;
1208 long ts
= wxevent
.GetTimestamp();
1210 int buttonLast
= win
->GetLastClickedButton();
1211 long lastTS
= win
->GetLastClickTime();
1212 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1215 win
->SetLastClick(0, ts
);
1216 if ( eventType
== wxEVT_LEFT_DOWN
)
1217 eventType
= wxEVT_LEFT_DCLICK
;
1218 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1219 eventType
= wxEVT_MIDDLE_DCLICK
;
1220 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1221 eventType
= wxEVT_RIGHT_DCLICK
;
1225 // not fast enough or different button
1226 win
->SetLastClick(button
, ts
);
1229 else if (xevent
->xany
.type
== ButtonRelease
)
1231 if (xevent
->xbutton
.button
== Button1
)
1233 eventType
= wxEVT_LEFT_UP
;
1235 else if (xevent
->xbutton
.button
== Button2
)
1237 eventType
= wxEVT_MIDDLE_UP
;
1239 else if (xevent
->xbutton
.button
== Button3
)
1241 eventType
= wxEVT_RIGHT_UP
;
1250 wxevent
.SetEventType(eventType
);
1252 wxevent
.m_x
= xevent
->xbutton
.x
;
1253 wxevent
.m_y
= xevent
->xbutton
.y
;
1255 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1256 || (event_left_is_down (xevent
)
1257 && (eventType
!= wxEVT_LEFT_UP
)));
1258 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1259 || (event_middle_is_down (xevent
)
1260 && (eventType
!= wxEVT_MIDDLE_UP
)));
1261 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1262 || (event_right_is_down (xevent
)
1263 && (eventType
!= wxEVT_RIGHT_UP
)));
1265 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1266 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1267 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1268 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1270 wxevent
.SetId(win
->GetId());
1271 wxevent
.SetEventObject(win
);
1279 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1281 switch (xevent
->xany
.type
)
1289 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1290 int id
= wxCharCodeXToWX (keySym
);
1292 if (xevent
->xkey
.state
& ShiftMask
)
1293 wxevent
.m_shiftDown
= TRUE
;
1294 if (xevent
->xkey
.state
& ControlMask
)
1295 wxevent
.m_controlDown
= TRUE
;
1296 if (xevent
->xkey
.state
& Mod3Mask
)
1297 wxevent
.m_altDown
= TRUE
;
1298 if (xevent
->xkey
.state
& Mod1Mask
)
1299 wxevent
.m_metaDown
= TRUE
;
1300 wxevent
.SetEventObject(win
);
1301 wxevent
.m_keyCode
= id
;
1302 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1304 wxevent
.m_x
= xevent
->xbutton
.x
;
1305 wxevent
.m_y
= xevent
->xbutton
.y
;
1319 // ----------------------------------------------------------------------------
1321 // ----------------------------------------------------------------------------
1323 bool wxWindowX11
::SetBackgroundColour(const wxColour
& col
)
1325 wxWindowBase
::SetBackgroundColour(col
);
1327 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1328 int xscreen
= DefaultScreen( xdisplay
);
1329 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1331 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1333 if (!GetMainWindow())
1337 XSetWindowAttributes attrib;
1338 attrib.background_pixel = colour.GetPixel();
1340 XChangeWindowAttributes(wxGlobalDisplay(),
1341 (Window) GetMainWindow(),
1349 bool wxWindowX11
::SetForegroundColour(const wxColour
& col
)
1351 if ( !wxWindowBase
::SetForegroundColour(col
) )
1357 // ----------------------------------------------------------------------------
1359 // ----------------------------------------------------------------------------
1361 wxWindow
*wxGetActiveWindow()
1364 wxFAIL_MSG("Not implemented");
1369 wxWindow
*wxWindowBase
::GetCapture()
1371 return (wxWindow
*)g_captureWindow
;
1375 // Find the wxWindow at the current mouse position, returning the mouse
1377 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1379 return wxFindWindowAtPoint(wxGetMousePosition());
1382 // Get the current mouse position.
1383 wxPoint
wxGetMousePosition()
1385 Display
*display
= wxGlobalDisplay();
1386 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1387 Window rootReturn
, childReturn
;
1388 int rootX
, rootY
, winX
, winY
;
1389 unsigned int maskReturn
;
1391 XQueryPointer (display
,
1395 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1396 return wxPoint(rootX
, rootY
);
1400 // ----------------------------------------------------------------------------
1401 // wxNoOptimize: switch off size optimization
1402 // ----------------------------------------------------------------------------
1404 int wxNoOptimize
::ms_count
= 0;