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 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 static const int SCROLL_MARGIN
= 4;
58 // ----------------------------------------------------------------------------
59 // global variables for this module
60 // ----------------------------------------------------------------------------
62 extern wxHashTable
*wxWidgetHashTable
;
63 static wxWindow
* g_captureWindow
= NULL
;
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
70 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
71 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
79 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
80 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
81 EVT_IDLE(wxWindowX11::OnIdle
)
84 // ============================================================================
86 // ============================================================================
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 void wxWindowX11::Init()
98 // generic initializations first
102 m_mainWidget
= (WXWindow
) 0;
104 m_winCaptured
= FALSE
;
107 m_isBeingDeleted
= 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
, "can't create wxWindow without parent" );
122 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
124 parent
->AddChild(this);
126 int w
= size
.GetWidth();
127 int h
= size
.GetHeight();
135 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
136 int xscreen
= DefaultScreen( xdisplay
);
137 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
139 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
140 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
143 m_foregroundColour
= *wxBLACK
;
144 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
147 Window parentWindow
= (Window
) parent
->GetMainWindow();
149 Window window
= XCreateSimpleWindow(
150 xdisplay
, parentWindow
,
152 m_backgroundColour
.GetPixel(),
153 m_backgroundColour
.GetPixel() );
155 m_mainWidget
= (WXWindow
) window
;
157 // Select event types wanted
158 XSelectInput(wxGlobalDisplay(), window
,
159 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
160 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
161 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
164 wxAddWindowToTable(window
, (wxWindow
*) this);
166 // Is a subwindow, so map immediately
168 XMapWindow(wxGlobalDisplay(), window
);
170 // Without this, the cursor may not be restored properly (e.g. in splitter
172 SetCursor(*wxSTANDARD_CURSOR
);
173 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
174 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
180 wxWindowX11::~wxWindowX11()
182 if (g_captureWindow
== this)
183 g_captureWindow
= NULL
;
185 m_isBeingDeleted
= TRUE
;
187 // X11-specific actions first
188 Window main
= (Window
) m_mainWidget
;
191 // Removes event handlers
192 //DetachWidget(main);
196 m_parent
->RemoveChild( this );
200 // Destroy the window
203 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
204 wxDeleteWindowFromTable( main
);
205 XDestroyWindow( wxGlobalDisplay(), main
);
210 // ---------------------------------------------------------------------------
212 // ---------------------------------------------------------------------------
214 void wxWindowX11::SetFocus()
216 Window wMain
= (Window
) GetMainWindow();
219 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
222 wmhints
.flags
= InputHint
;
223 wmhints
.input
= True
;
224 XSetWMHints(wxGlobalDisplay(), wMain
, &wmhints
);
228 // Get the window with the focus
229 wxWindow
*wxWindowBase::FindFocus()
231 Window wFocus
= (Window
) 0;
234 XGetInputFocus(wxGlobalDisplay(), & wFocus
, & revert
);
237 wxWindow
*win
= NULL
;
240 win
= wxGetWindowFromTable(wFocus
);
241 wFocus
= wxGetWindowParent(wFocus
);
242 } while (wFocus
&& !win
);
250 // Enabling/disabling handled by event loop, and not sending events
252 bool wxWindowX11::Enable(bool enable
)
254 if ( !wxWindowBase::Enable(enable
) )
260 bool wxWindowX11::Show(bool show
)
262 wxWindowBase::Show(show
);
264 Window xwin
= (Window
) GetXWindow();
265 Display
*xdisp
= (Display
*) GetXDisplay();
269 msg
.Printf("Mapping window of type %s", GetClassInfo()->GetClassName());
271 XMapWindow(xdisp
, xwin
);
277 msg
.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName());
279 XUnmapWindow(xdisp
, xwin
);
285 // Raise the window to the top of the Z order
286 void wxWindowX11::Raise()
289 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
292 // Lower the window to the bottom of the Z order
293 void wxWindowX11::Lower()
296 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
299 void wxWindowX11::DoCaptureMouse()
301 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
303 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
314 g_captureWindow
= (wxWindow
*) this;
318 int res
= XGrabPointer(wxGlobalDisplay(), (Window
) GetMainWindow(),
320 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
324 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
327 if (res
!= GrabSuccess
)
330 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
332 if (res
== GrabNotViewable
)
334 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
336 g_captureWindow
= NULL
;
339 wxLogDebug("Grabbed pointer");
342 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
343 (Window
) GetMainWindow(),
345 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
351 if (res
!= GrabSuccess
)
353 wxLogDebug("Failed to grab mouse buttons.");
354 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
360 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
362 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
370 if (res
!= GrabSuccess
)
372 wxLogDebug("Failed to grab keyboard.");
373 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
375 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
376 (Window
) GetMainWindow());
382 m_winCaptured
= TRUE
;
386 void wxWindowX11::DoReleaseMouse()
388 g_captureWindow
= NULL
;
389 if ( !m_winCaptured
)
392 Window wMain
= (Window
)GetMainWindow();
396 XUngrabPointer(wxGlobalDisplay(), wMain
);
398 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
400 XUngrabKeyboard(wxGlobalDisplay(), CurrentTime
);
403 wxLogDebug("Ungrabbed pointer");
405 m_winCaptured
= FALSE
;
408 bool wxWindowX11::SetFont(const wxFont
& font
)
410 if ( !wxWindowBase::SetFont(font
) )
419 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
421 if ( !wxWindowBase::SetCursor(cursor
) )
427 wxCursor
* cursor2
= NULL
;
429 cursor2
= & m_cursor
;
431 cursor2
= wxSTANDARD_CURSOR
;
433 WXDisplay
*dpy
= GetXDisplay();
434 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
436 Window win
= (Window
) GetMainWindow();
437 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
442 // Coordinates relative to the window
443 void wxWindowX11::WarpPointer (int x
, int y
)
446 XWarpPointer( wxGlobalDisplay(), None
, (Window
) m_mainWidget
, 0, 0, 0, 0, x
, y
);
449 // Does a physical scroll
450 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
456 // Use specified rectangle
457 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
461 // Use whole client area
463 GetClientSize(& w
, & h
);
466 wxNode
*cnode
= m_children
.First();
469 wxWindow
*child
= (wxWindow
*) cnode
->Data();
472 child
->GetSize( &sx
, &sy
);
473 wxPoint
pos( child
->GetPosition() );
474 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
475 cnode
= cnode
->Next();
478 int x1
= (dx
>= 0) ? x
: x
- dx
;
479 int y1
= (dy
>= 0) ? y
: y
- dy
;
480 int w1
= w
- abs(dx
);
481 int h1
= h
- abs(dy
);
482 int x2
= (dx
>= 0) ? x
+ dx
: x
;
483 int y2
= (dy
>= 0) ? y
+ dy
: y
;
485 wxClientDC
dc((wxWindow
*) this);
487 dc
.SetLogicalFunction (wxCOPY
);
489 Window window
= (Window
) GetMainWindow();
490 Display
* display
= wxGlobalDisplay();
492 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
493 x1
, y1
, w1
, h1
, x2
, y2
);
495 dc
.SetAutoSetting(TRUE
);
496 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
497 dc
.SetBrush(brush
); // FIXME: needed?
499 // We'll add rectangles to the list of update rectangles according to which
500 // bits we've exposed.
505 wxRect
*rect
= new wxRect
;
511 XFillRectangle(display
, window
,
512 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
516 rect
->width
= rect
->width
;
517 rect
->height
= rect
->height
;
519 updateRects
.Append((wxObject
*) rect
);
523 wxRect
*rect
= new wxRect
;
525 rect
->x
= x
+ w
+ dx
;
530 XFillRectangle(display
, window
,
531 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
536 rect
->width
= rect
->width
;
537 rect
->height
= rect
->height
;
539 updateRects
.Append((wxObject
*) rect
);
543 wxRect
*rect
= new wxRect
;
550 XFillRectangle(display
, window
,
551 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
555 rect
->width
= rect
->width
;
556 rect
->height
= rect
->height
;
558 updateRects
.Append((wxObject
*) rect
);
562 wxRect
*rect
= new wxRect
;
565 rect
->y
= y
+ h
+ dy
;
569 XFillRectangle(display
, window
,
570 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
574 rect
->width
= rect
->width
;
575 rect
->height
= rect
->height
;
577 updateRects
.Append((wxObject
*) rect
);
579 dc
.SetBrush(wxNullBrush
);
581 // Now send expose events
583 wxNode
* node
= updateRects
.First();
586 wxRect
* rect
= (wxRect
*) node
->Data();
590 event
.display
= display
;
591 event
.send_event
= True
;
592 event
.window
= window
;
596 event
.width
= rect
->width
;
597 event
.height
= rect
->height
;
601 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
607 // Delete the update rects
608 node
= updateRects
.First();
611 wxRect
* rect
= (wxRect
*) node
->Data();
618 // ---------------------------------------------------------------------------
620 // ---------------------------------------------------------------------------
622 #if wxUSE_DRAG_AND_DROP
624 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
631 // Old style file-manager drag&drop
632 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
637 // ----------------------------------------------------------------------------
639 // ----------------------------------------------------------------------------
643 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
648 #endif // wxUSE_TOOLTIPS
650 // ---------------------------------------------------------------------------
651 // moving and resizing
652 // ---------------------------------------------------------------------------
654 bool wxWindowX11::PreResize()
660 void wxWindowX11::DoGetSize(int *x
, int *y
) const
662 Window window
= (Window
) m_mainWidget
;
665 XWindowAttributes attr
;
666 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
671 *x
= attr
.width
/* + 2*m_borderSize */ ;
672 *y
= attr
.height
/* + 2*m_borderSize */ ;
677 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
679 Window window
= (Window
) m_mainWidget
;
682 XWindowAttributes attr
;
683 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
691 // We may be faking the client origin. So a window that's really at (0, 30)
692 // may appear (to wxWin apps) to be at (0, 0).
695 wxPoint
pt(GetParent()->GetClientAreaOrigin());
703 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
705 Display
*display
= wxGlobalDisplay();
706 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
707 Window thisWindow
= (Window
) m_mainWidget
;
712 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
715 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
717 Display
*display
= wxGlobalDisplay();
718 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
719 Window thisWindow
= (Window
) m_mainWidget
;
724 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
728 // Get size *available for subwindows* i.e. excluding menu bar etc.
729 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
731 Window window
= (Window
) m_mainWidget
;
735 XWindowAttributes attr
;
736 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
747 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
749 if (!GetMainWindow())
752 XWindowChanges windowChanges
;
755 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
758 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
762 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
765 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
769 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
771 windowChanges
.width
= width
/* - m_borderSize*2 */;
772 valueMask
|= CWWidth
;
774 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
776 windowChanges
.height
= height
/* -m_borderSize*2*/;
777 valueMask
|= CWHeight
;
780 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
781 valueMask
, & windowChanges
);
784 void wxWindowX11::DoSetClientSize(int width
, int height
)
786 if (!GetMainWindow())
789 XWindowChanges windowChanges
;
794 windowChanges
.width
= width
;
795 valueMask
|= CWWidth
;
799 windowChanges
.height
= height
;
800 valueMask
|= CWHeight
;
802 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
803 valueMask
, & windowChanges
);
806 // For implementation purposes - sometimes decorations make the client area
808 wxPoint
wxWindowX11::GetClientAreaOrigin() const
810 return wxPoint(0, 0);
813 // Makes an adjustment to the window position (for example, a frame that has
814 // a toolbar that it manages itself).
815 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
817 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
819 wxPoint
pt(GetParent()->GetClientAreaOrigin());
820 x
+= pt
.x
; y
+= pt
.y
;
824 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
831 XSizeHints sizeHints
;
834 if (minW
> -1 && minH
> -1)
836 sizeHints
.flags
|= PMinSize
;
837 sizeHints
.min_width
= minW
;
838 sizeHints
.min_height
= minH
;
840 if (maxW
> -1 && maxH
> -1)
842 sizeHints
.flags
|= PMaxSize
;
843 sizeHints
.max_width
= maxW
;
844 sizeHints
.max_height
= maxH
;
846 if (incW
> -1 && incH
> -1)
848 sizeHints
.flags
|= PResizeInc
;
849 sizeHints
.width_inc
= incW
;
850 sizeHints
.height_inc
= incH
;
853 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
856 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
858 DoSetSize(x
, y
, width
, height
);
861 // ---------------------------------------------------------------------------
863 // ---------------------------------------------------------------------------
865 int wxWindowX11::GetCharHeight() const
867 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
869 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
871 int direction
, ascent
, descent
;
873 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
876 // return (overall.ascent + overall.descent);
877 return (ascent
+ descent
);
880 int wxWindowX11::GetCharWidth() const
882 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
884 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
886 int direction
, ascent
, descent
;
888 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
891 return overall
.width
;
894 void wxWindowX11::GetTextExtent(const wxString
& string
,
896 int *descent
, int *externalLeading
,
897 const wxFont
*theFont
) const
899 wxFont
*fontToUse
= (wxFont
*)theFont
;
901 fontToUse
= (wxFont
*) & m_font
;
903 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
905 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
907 int direction
, ascent
, descent2
;
909 int slen
= string
.Len();
913 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
914 &ascent
, &descent2
, &overall
);
917 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
918 &direction
, &ascent
, &descent2
, &overall
);
921 *x
= (overall
.width
);
923 *y
= (ascent
+ descent2
);
927 *externalLeading
= 0;
931 // ----------------------------------------------------------------------------
933 // ----------------------------------------------------------------------------
935 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
941 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
942 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
947 GetSize( &width
, &height
);
949 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
950 m_clearRegion
.Clear();
951 m_clearRegion
.Union( 0, 0, width
, height
);
957 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
958 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
963 GetSize( &width
, &height
);
965 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
966 m_updateRegion
.Clear();
967 m_updateRegion
.Union( 0, 0, width
, height
);
970 // Actually don't schedule yet..
974 void wxWindowX11::Update()
976 if (!m_updateRegion
.IsEmpty())
978 X11SendPaintEvents();
982 void wxWindowX11::Clear()
984 wxClientDC
dc((wxWindow
*) this);
985 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
986 dc
.SetBackground(brush
);
990 void wxWindowX11::X11SendPaintEvents()
992 m_clipPaintRegion
= TRUE
;
994 // if (!m_clearRegion.IsEmpty())
996 wxWindowDC
dc( (wxWindow
*)this );
997 dc
.SetClippingRegion( m_clearRegion
);
999 wxEraseEvent
erase_event( GetId(), &dc
);
1000 erase_event
.SetEventObject( this );
1002 if (!GetEventHandler()->ProcessEvent(erase_event
))
1004 wxRegionIterator
upd( m_clearRegion
);
1007 XClearArea( wxGlobalDisplay(), (Window
) m_mainWidget
,
1008 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight(), False
);
1012 m_clearRegion
.Clear();
1015 wxNcPaintEvent
nc_paint_event( GetId() );
1016 nc_paint_event
.SetEventObject( this );
1017 GetEventHandler()->ProcessEvent( nc_paint_event
);
1019 wxPaintEvent
paint_event( GetId() );
1020 paint_event
.SetEventObject( this );
1021 GetEventHandler()->ProcessEvent( paint_event
);
1023 m_clipPaintRegion
= FALSE
;
1026 // ----------------------------------------------------------------------------
1028 // ----------------------------------------------------------------------------
1030 // Responds to colour changes: passes event on to children.
1031 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1033 wxWindowList::Node
*node
= GetChildren().GetFirst();
1036 // Only propagate to non-top-level windows
1037 wxWindow
*win
= node
->GetData();
1038 if ( win
->GetParent() )
1040 wxSysColourChangedEvent event2
;
1041 event
.m_eventObject
= win
;
1042 win
->GetEventHandler()->ProcessEvent(event2
);
1045 node
= node
->GetNext();
1049 void wxWindowX11::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1051 // This calls the UI-update mechanism (querying windows for
1052 // menu/toolbar/control state information)
1056 // ----------------------------------------------------------------------------
1057 // function which maintain the global hash table mapping Widgets to wxWindows
1058 // ----------------------------------------------------------------------------
1060 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1062 wxWindow
*oldItem
= NULL
;
1063 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1065 wxLogDebug("Widget table clash: new widget is %ld, %s",
1066 (long)w
, win
->GetClassInfo()->GetClassName());
1070 wxWidgetHashTable
->Put((long) w
, win
);
1072 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1073 w
, win
, win
->GetClassInfo()->GetClassName());
1078 wxWindow
*wxGetWindowFromTable(Window w
)
1080 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1083 void wxDeleteWindowFromTable(Window w
)
1085 wxWidgetHashTable
->Delete((long)w
);
1088 // ----------------------------------------------------------------------------
1089 // add/remove window from the table
1090 // ----------------------------------------------------------------------------
1092 // ----------------------------------------------------------------------------
1093 // X11-specific accessors
1094 // ----------------------------------------------------------------------------
1096 // Get the underlying X window
1097 WXWindow
wxWindowX11::GetXWindow() const
1099 return GetMainWindow();
1102 // Get the underlying X display
1103 WXDisplay
*wxWindowX11::GetXDisplay() const
1105 return wxGetDisplay();
1108 WXWindow
wxWindowX11::GetMainWindow() const
1110 return m_mainWidget
;
1113 // ----------------------------------------------------------------------------
1114 // TranslateXXXEvent() functions
1115 // ----------------------------------------------------------------------------
1117 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1119 switch (xevent
->xany
.type
)
1127 wxEventType eventType
= wxEVT_NULL
;
1129 if (xevent
->xany
.type
== EnterNotify
)
1131 //if (local_event.xcrossing.mode!=NotifyNormal)
1132 // return ; // Ignore grab events
1133 eventType
= wxEVT_ENTER_WINDOW
;
1134 // canvas->GetEventHandler()->OnSetFocus();
1136 else if (xevent
->xany
.type
== LeaveNotify
)
1138 //if (local_event.xcrossingr.mode!=NotifyNormal)
1139 // return ; // Ignore grab events
1140 eventType
= wxEVT_LEAVE_WINDOW
;
1141 // canvas->GetEventHandler()->OnKillFocus();
1143 else if (xevent
->xany
.type
== MotionNotify
)
1145 eventType
= wxEVT_MOTION
;
1147 else if (xevent
->xany
.type
== ButtonPress
)
1149 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1151 if (xevent
->xbutton
.button
== Button1
)
1153 eventType
= wxEVT_LEFT_DOWN
;
1156 else if (xevent
->xbutton
.button
== Button2
)
1158 eventType
= wxEVT_MIDDLE_DOWN
;
1161 else if (xevent
->xbutton
.button
== Button3
)
1163 eventType
= wxEVT_RIGHT_DOWN
;
1167 // check for a double click
1168 // TODO: where can we get this value from?
1169 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1170 long dclickTime
= 200;
1171 long ts
= wxevent
.GetTimestamp();
1173 int buttonLast
= win
->GetLastClickedButton();
1174 long lastTS
= win
->GetLastClickTime();
1175 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1178 win
->SetLastClick(0, ts
);
1179 if ( eventType
== wxEVT_LEFT_DOWN
)
1180 eventType
= wxEVT_LEFT_DCLICK
;
1181 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1182 eventType
= wxEVT_MIDDLE_DCLICK
;
1183 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1184 eventType
= wxEVT_RIGHT_DCLICK
;
1188 // not fast enough or different button
1189 win
->SetLastClick(button
, ts
);
1192 else if (xevent
->xany
.type
== ButtonRelease
)
1194 if (xevent
->xbutton
.button
== Button1
)
1196 eventType
= wxEVT_LEFT_UP
;
1198 else if (xevent
->xbutton
.button
== Button2
)
1200 eventType
= wxEVT_MIDDLE_UP
;
1202 else if (xevent
->xbutton
.button
== Button3
)
1204 eventType
= wxEVT_RIGHT_UP
;
1213 wxevent
.SetEventType(eventType
);
1215 wxevent
.m_x
= xevent
->xbutton
.x
;
1216 wxevent
.m_y
= xevent
->xbutton
.y
;
1218 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1219 || (event_left_is_down (xevent
)
1220 && (eventType
!= wxEVT_LEFT_UP
)));
1221 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1222 || (event_middle_is_down (xevent
)
1223 && (eventType
!= wxEVT_MIDDLE_UP
)));
1224 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1225 || (event_right_is_down (xevent
)
1226 && (eventType
!= wxEVT_RIGHT_UP
)));
1228 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1229 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1230 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1231 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1233 wxevent
.SetId(win
->GetId());
1234 wxevent
.SetEventObject(win
);
1242 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1244 switch (xevent
->xany
.type
)
1252 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1253 int id
= wxCharCodeXToWX (keySym
);
1255 if (xevent
->xkey
.state
& ShiftMask
)
1256 wxevent
.m_shiftDown
= TRUE
;
1257 if (xevent
->xkey
.state
& ControlMask
)
1258 wxevent
.m_controlDown
= TRUE
;
1259 if (xevent
->xkey
.state
& Mod3Mask
)
1260 wxevent
.m_altDown
= TRUE
;
1261 if (xevent
->xkey
.state
& Mod1Mask
)
1262 wxevent
.m_metaDown
= TRUE
;
1263 wxevent
.SetEventObject(win
);
1264 wxevent
.m_keyCode
= id
;
1265 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1267 wxevent
.m_x
= xevent
->xbutton
.x
;
1268 wxevent
.m_y
= xevent
->xbutton
.y
;
1282 // ----------------------------------------------------------------------------
1284 // ----------------------------------------------------------------------------
1288 #define YAllocColor XAllocColor
1289 XColor g_itemColors
[5];
1290 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1293 static XmColorProc colorProc
;
1295 result
= wxNO_COLORS
;
1299 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1300 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1301 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1302 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1303 if (colorProc
== (XmColorProc
) NULL
)
1305 // Get a ptr to the actual function
1306 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1307 // And set it back to motif.
1308 XmSetColorCalculation (colorProc
);
1310 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1311 &g_itemColors
[wxFORE_INDEX
],
1312 &g_itemColors
[wxSELE_INDEX
],
1313 &g_itemColors
[wxTOPS_INDEX
],
1314 &g_itemColors
[wxBOTS_INDEX
]);
1315 result
= wxBACK_COLORS
;
1319 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1320 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1321 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1322 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1323 if (result
== wxNO_COLORS
)
1324 result
= wxFORE_COLORS
;
1327 Display
*dpy
= display
;
1328 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1332 /* 5 Colours to allocate */
1333 for (int i
= 0; i
< 5; i
++)
1334 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1335 result
= wxNO_COLORS
;
1339 /* Only 1 colour to allocate */
1340 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1341 result
= wxNO_COLORS
;
1349 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1351 wxWindowBase::SetBackgroundColour(col
);
1353 if (!GetMainWindow())
1356 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1357 int xscreen
= DefaultScreen( xdisplay
);
1358 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1360 wxColour
colour( col
);
1361 colour
.CalcPixel( (WXColormap
) cm
);
1363 XSetWindowAttributes attrib
;
1364 attrib
.background_pixel
= colour
.GetPixel();
1366 XChangeWindowAttributes(wxGlobalDisplay(),
1367 (Window
) GetMainWindow(),
1374 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1376 if ( !wxWindowBase::SetForegroundColour(col
) )
1382 // ----------------------------------------------------------------------------
1384 // ----------------------------------------------------------------------------
1386 wxWindow
*wxGetActiveWindow()
1389 wxFAIL_MSG("Not implemented");
1394 wxWindow
*wxWindowBase::GetCapture()
1396 return (wxWindow
*)g_captureWindow
;
1400 // Find the wxWindow at the current mouse position, returning the mouse
1402 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1404 return wxFindWindowAtPoint(wxGetMousePosition());
1407 // Get the current mouse position.
1408 wxPoint
wxGetMousePosition()
1410 Display
*display
= wxGlobalDisplay();
1411 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1412 Window rootReturn
, childReturn
;
1413 int rootX
, rootY
, winX
, winY
;
1414 unsigned int maskReturn
;
1416 XQueryPointer (display
,
1420 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1421 return wxPoint(rootX
, rootY
);
1425 // ----------------------------------------------------------------------------
1426 // wxNoOptimize: switch off size optimization
1427 // ----------------------------------------------------------------------------
1429 int wxNoOptimize::ms_count
= 0;