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_DYNAMIC_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 // TODO: prune those that are no longer needed
103 m_needsRefresh
= TRUE
;
104 m_mainWidget
= (WXWindow
) 0;
106 m_winCaptured
= FALSE
;
109 m_isBeingDeleted
= FALSE
;
115 m_drawingArea
= (WXWindow
) 0;
125 m_canAddEventHandler
= FALSE
;
130 // real construction (Init() must have been called before!)
131 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
135 const wxString
& name
)
137 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
139 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
142 parent
->AddChild(this);
144 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
145 m_foregroundColour
= *wxBLACK
;
147 // TODO: How to create more interesting borders?
148 // Will presumably have to create multiple windows.
149 if (style
& wxSIMPLE_BORDER
)
152 } else if (style
& wxSUNKEN_BORDER
)
155 } else if (style
& wxRAISED_BORDER
)
160 int w
= size
.GetWidth();
161 int h
= size
.GetHeight();
169 int screen
= DefaultScreen(wxGlobalDisplay());
173 parentWindow
= (Window
) parent
->GetClientWindow();
175 parentWindow
= RootWindow(wxGlobalDisplay(), screen
);
177 Window window
= XCreateSimpleWindow(wxGlobalDisplay(), parentWindow
,
178 x
, y
, w
, h
, m_borderSize
,
179 m_backgroundColour
.AllocColour(wxGlobalDisplay()),
180 m_foregroundColour
.AllocColour(wxGlobalDisplay()));
182 // Select event types wanted
183 XSelectInput(wxGlobalDisplay(), window
,
184 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
185 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
186 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
189 wxAddWindowToTable(window
, (wxWindow
*) this);
191 // If a subwindow, show.
192 // if (parent && !parent->IsKindOf(CLASSINFO(wxTopLevelWindowX11)) && parent->IsShown())
195 XMapWindow(wxGlobalDisplay(), window
);
198 // Without this, the cursor may not be restored properly (e.g. in splitter
200 SetCursor(*wxSTANDARD_CURSOR
);
201 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
202 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
208 wxWindowX11::~wxWindowX11()
210 if (g_captureWindow
== this)
211 g_captureWindow
= NULL
;
213 m_isBeingDeleted
= TRUE
;
215 // X11-specific actions first
216 WXWindow wMain
= GetMainWindow();
219 // Removes event handlers
220 //DetachWidget(wMain);
224 m_parent
->RemoveChild( this );
229 // If m_drawingArea, we're a fully-fledged window with drawing area,
230 // scrollbars etc. (what wxCanvas used to be)
233 // Destroy children before destroying self
237 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
239 Widget w
= (Widget
) m_drawingArea
;
240 wxDeleteWindowFromTable(w
);
245 m_drawingArea
= (WXWidget
) 0;
248 // Only if we're _really_ a canvas (not a dialog box/panel)
249 if (m_scrolledWindow
)
251 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
256 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
257 XtUnmanageChild((Widget
) m_hScrollBar
);
261 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
262 XtUnmanageChild((Widget
) m_vScrollBar
);
266 XtDestroyWidget((Widget
) m_hScrollBar
);
268 XtDestroyWidget((Widget
) m_vScrollBar
);
270 UnmanageAndDestroy(m_scrolledWindow
);
274 XtDestroyWidget ((Widget
) m_borderWidget
);
275 m_borderWidget
= (WXWidget
) 0;
278 else // Why wasn't this here before? JACS 8/3/2000
283 // Destroy the window
286 XSelectInput(wxGlobalDisplay(), (Window
) GetMainWindow(),
288 wxDeleteWindowFromTable((Window
) GetMainWindow());
289 XDestroyWindow(wxGlobalDisplay(), (Window
) GetMainWindow());
290 SetMainWindow((WXWindow
) NULL
);
294 // ----------------------------------------------------------------------------
295 // scrollbar management
296 // ----------------------------------------------------------------------------
299 void wxWindowX11::CreateScrollbar(wxOrientation orientation
)
303 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
305 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
307 // Add scrollbars if required
308 if (orientation
== wxHORIZONTAL
)
310 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
311 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
312 XmNorientation
, XmHORIZONTAL
,
314 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
315 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
316 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
317 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
318 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
319 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
320 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
321 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
323 XtVaSetValues (hScrollBar
,
328 m_hScrollBar
= (WXWidget
) hScrollBar
;
330 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
331 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
333 XtRealizeWidget(hScrollBar
);
335 XtVaSetValues((Widget
) m_scrolledWindow
,
336 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
341 wxAddWindowToTable( hScrollBar
, this );
344 if (orientation
== wxVERTICAL
)
346 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
347 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
348 XmNorientation
, XmVERTICAL
,
350 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
351 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
352 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
353 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
354 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
355 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
356 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
357 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
359 XtVaSetValues (vScrollBar
,
364 m_vScrollBar
= (WXWidget
) vScrollBar
;
365 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
366 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
368 XtRealizeWidget(vScrollBar
);
370 XtVaSetValues((Widget
) m_scrolledWindow
,
371 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
376 wxAddWindowToTable( vScrollBar
, this );
379 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
383 void wxWindowX11::DestroyScrollbar(wxOrientation orientation
)
387 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
389 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
390 // Add scrollbars if required
391 if (orientation
== wxHORIZONTAL
)
395 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
396 XtDestroyWidget((Widget
) m_hScrollBar
);
398 m_hScrollBar
= (WXWidget
) 0;
401 XtVaSetValues((Widget
) m_scrolledWindow
,
402 XmNhorizontalScrollBar
, (Widget
) 0,
407 if (orientation
== wxVERTICAL
)
411 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
412 XtDestroyWidget((Widget
) m_vScrollBar
);
414 m_vScrollBar
= (WXWidget
) 0;
417 XtVaSetValues((Widget
) m_scrolledWindow
,
418 XmNverticalScrollBar
, (Widget
) 0,
422 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
426 // ---------------------------------------------------------------------------
428 // ---------------------------------------------------------------------------
430 void wxWindowX11::SetFocus()
433 Window wMain
= (Window
) GetMainWidget();
436 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
439 wmhints
.flags
= InputHint
;
440 wmhints
.input
= True
;
441 XSetWMHints(wxGlobalDisplay(), wMain
, &wmhints
)
446 // Get the window with the focus
447 wxWindow
*wxWindowBase::FindFocus()
449 Window wFocus
= (Window
) 0;
452 XGetInputFocus(wxGlobalDisplay(), & wFocus
, & revert
);
455 wxWindow
*win
= NULL
;
458 win
= wxGetWindowFromTable(wFocus
);
459 wFocus
= wxGetWindowParent(wFocus
);
460 } while (wFocus
&& !win
);
468 // Enabling/disabling handled by event loop, and not sending events
470 bool wxWindowX11::Enable(bool enable
)
472 if ( !wxWindowBase::Enable(enable
) )
478 bool wxWindowX11::Show(bool show
)
480 if ( !wxWindowBase::Show(show
) )
483 Window xwin
= (Window
) GetXWindow();
484 Display
*xdisp
= (Display
*) GetXDisplay();
487 XMapWindow(xdisp
, xwin
);
491 XUnmapWindow(xdisp
, xwin
);
497 // Raise the window to the top of the Z order
498 void wxWindowX11::Raise()
500 Window window
= (Window
) GetTopWindow();
502 XRaiseWindow(wxGlobalDisplay(), window
);
505 // Lower the window to the bottom of the Z order
506 void wxWindowX11::Lower()
508 Window window
= (Window
) GetTopWindow();
510 XLowerWindow(wxGlobalDisplay(), window
);
513 void wxWindowX11::DoCaptureMouse()
515 g_captureWindow
= (wxWindow
*) this;
519 // TODO: should we also call XGrabButton, XGrabKeyboard?
522 int res
= XGrabPointer(wxGlobalDisplay(), (Window
) GetMainWindow(),
524 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
528 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
531 if (res
== GrabSuccess
)
533 m_winCaptured
= TRUE
;
538 void wxWindowX11::DoReleaseMouse()
540 g_captureWindow
= NULL
;
541 if ( !m_winCaptured
)
544 Window wMain
= (Window
)GetMainWindow();
546 // TODO: should we also call XUngrabButton, XUngrabKeyboard?
548 XUngrabPointer(wxGlobalDisplay(), wMain
);
550 m_winCaptured
= FALSE
;
553 bool wxWindowX11::SetFont(const wxFont
& font
)
555 if ( !wxWindowBase::SetFont(font
) )
566 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
568 if ( !wxWindowBase::SetCursor(cursor
) )
574 wxCursor
* cursor2
= NULL
;
576 cursor2
= & m_cursor
;
578 cursor2
= wxSTANDARD_CURSOR
;
580 WXDisplay
*dpy
= GetXDisplay();
581 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
583 Window win
= (Window
) GetMainWindow();
584 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
589 // Coordinates relative to the window
590 void wxWindowX11::WarpPointer (int x
, int y
)
592 Window wClient
= (Window
) GetClientWindow();
594 XWarpPointer(wxGlobalDisplay(), None
, wClient
, 0, 0, 0, 0, x
, y
);
597 // ---------------------------------------------------------------------------
599 // ---------------------------------------------------------------------------
601 int wxWindowX11::GetScrollPos(int orient
) const
603 if (orient
== wxHORIZONTAL
)
609 // This now returns the whole range, not just the number of positions that we
611 int wxWindowX11::GetScrollRange(int WXUNUSED(orient
)) const
616 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
617 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
620 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
625 int wxWindowX11::GetScrollThumb(int orient
) const
631 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
632 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
635 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
640 void wxWindowX11::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
645 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
649 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
652 SetInternalScrollPos((wxOrientation
)orient
, pos
);
655 // New function that will replace some of the above.
656 void wxWindowX11::SetScrollbar(int WXUNUSED(orient
), int WXUNUSED(pos
), int WXUNUSED(thumbVisible
),
657 int WXUNUSED(range
), bool WXUNUSED(refresh
))
662 GetSize(& oldW
, & oldH
);
666 if (thumbVisible
== 0)
669 if (thumbVisible
> range
)
670 thumbVisible
= range
;
672 // Save the old state to see if it changed
673 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
675 if (orient
== wxHORIZONTAL
)
677 if (thumbVisible
== range
)
680 DestroyScrollbar(wxHORIZONTAL
);
685 CreateScrollbar(wxHORIZONTAL
);
688 if (orient
== wxVERTICAL
)
690 if (thumbVisible
== range
)
693 DestroyScrollbar(wxVERTICAL
);
698 CreateScrollbar(wxVERTICAL
);
701 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
703 if (oldScrollBar
!= newScrollBar
)
705 // This is important! Without it, scrollbars misbehave badly.
706 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
707 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
708 XtRealizeWidget((Widget
) m_scrolledWindow
);
709 XtManageChild((Widget
) m_scrolledWindow
);
714 XtVaSetValues((Widget
) newScrollBar
,
718 XmNsliderSize
, thumbVisible
,
722 SetInternalScrollPos((wxOrientation
)orient
, pos
);
725 GetSize(& newW
, & newH
);
727 // Adjusting scrollbars can resize the canvas accidentally
728 if (newW
!= oldW
|| newH
!= oldH
)
729 SetSize(-1, -1, oldW
, oldH
);
733 // Does a physical scroll
734 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
739 // Use specified rectangle
740 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
744 // Use whole client area
746 GetClientSize(& w
, & h
);
749 wxNode
*cnode
= m_children
.First();
752 wxWindow
*child
= (wxWindow
*) cnode
->Data();
755 child
->GetSize( &sx
, &sy
);
756 wxPoint
pos( child
->GetPosition() );
757 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
758 cnode
= cnode
->Next();
761 int x1
= (dx
>= 0) ? x
: x
- dx
;
762 int y1
= (dy
>= 0) ? y
: y
- dy
;
763 int w1
= w
- abs(dx
);
764 int h1
= h
- abs(dy
);
765 int x2
= (dx
>= 0) ? x
+ dx
: x
;
766 int y2
= (dy
>= 0) ? y
+ dy
: y
;
768 wxClientDC
dc((wxWindow
*) this);
770 dc
.SetLogicalFunction (wxCOPY
);
772 Window window
= (Window
) GetMainWindow();
773 Display
* display
= wxGlobalDisplay();
775 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
776 x1
, y1
, w1
, h1
, x2
, y2
);
778 dc
.SetAutoSetting(TRUE
);
779 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
780 dc
.SetBrush(brush
); // FIXME: needed?
782 // We'll add rectangles to the list of update rectangles according to which
783 // bits we've exposed.
788 wxRect
*rect
= new wxRect
;
794 XFillRectangle(display
, window
,
795 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
799 rect
->width
= rect
->width
;
800 rect
->height
= rect
->height
;
802 updateRects
.Append((wxObject
*) rect
);
806 wxRect
*rect
= new wxRect
;
808 rect
->x
= x
+ w
+ dx
;
813 XFillRectangle(display
, window
,
814 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
819 rect
->width
= rect
->width
;
820 rect
->height
= rect
->height
;
822 updateRects
.Append((wxObject
*) rect
);
826 wxRect
*rect
= new wxRect
;
833 XFillRectangle(display
, window
,
834 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
838 rect
->width
= rect
->width
;
839 rect
->height
= rect
->height
;
841 updateRects
.Append((wxObject
*) rect
);
845 wxRect
*rect
= new wxRect
;
848 rect
->y
= y
+ h
+ dy
;
852 XFillRectangle(display
, window
,
853 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
857 rect
->width
= rect
->width
;
858 rect
->height
= rect
->height
;
860 updateRects
.Append((wxObject
*) rect
);
862 dc
.SetBrush(wxNullBrush
);
864 // Now send expose events
866 wxNode
* node
= updateRects
.First();
869 wxRect
* rect
= (wxRect
*) node
->Data();
873 event
.display
= display
;
874 event
.send_event
= True
;
875 event
.window
= window
;
879 event
.width
= rect
->width
;
880 event
.height
= rect
->height
;
884 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
890 // Delete the update rects
891 node
= updateRects
.First();
894 wxRect
* rect
= (wxRect
*) node
->Data();
901 // XmUpdateDisplay((Widget) GetMainWidget());
904 // ---------------------------------------------------------------------------
906 // ---------------------------------------------------------------------------
908 #if wxUSE_DRAG_AND_DROP
910 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
917 // Old style file-manager drag&drop
918 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
923 // ----------------------------------------------------------------------------
925 // ----------------------------------------------------------------------------
929 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
934 #endif // wxUSE_TOOLTIPS
936 // ---------------------------------------------------------------------------
937 // moving and resizing
938 // ---------------------------------------------------------------------------
940 bool wxWindowX11::PreResize()
946 void wxWindowX11::DoGetSize(int *x
, int *y
) const
948 Window window
= (Window
) GetTopWindow();
951 XWindowAttributes attr
;
952 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
957 *x
= attr
.width
+ 2*m_borderSize
;
958 *y
= attr
.height
+ 2*m_borderSize
;
963 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
965 Window window
= (Window
) GetTopWindow();
968 XWindowAttributes attr
;
969 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
977 // We may be faking the client origin. So a window that's really at (0, 30)
978 // may appear (to wxWin apps) to be at (0, 0).
981 wxPoint
pt(GetParent()->GetClientAreaOrigin());
989 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
991 Display
*display
= wxGlobalDisplay();
992 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
993 Window thisWindow
= (Window
) GetClientWindow();
998 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1001 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
1003 Display
*display
= wxGlobalDisplay();
1004 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
1005 Window thisWindow
= (Window
) GetClientWindow();
1010 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1014 // Get size *available for subwindows* i.e. excluding menu bar etc.
1015 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
1017 Window window
= (Window
) GetClientWindow();
1021 XWindowAttributes attr
;
1022 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
1033 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1035 if (!GetMainWindow())
1038 XWindowChanges windowChanges
;
1041 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1043 windowChanges
.x
= x
;
1046 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1048 windowChanges
.y
= y
;
1051 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1053 windowChanges
.width
= width
- m_borderSize
*2;
1054 valueMask
|= CWWidth
;
1056 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1058 windowChanges
.height
= height
- m_borderSize
*2;
1059 valueMask
|= CWHeight
;
1061 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1063 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
1064 valueMask
, & windowChanges
);
1067 void wxWindowX11::DoSetClientSize(int width
, int height
)
1069 if (!GetMainWindow())
1072 XWindowChanges windowChanges
;
1077 windowChanges
.width
= width
;
1078 valueMask
|= CWWidth
;
1082 windowChanges
.height
= height
;
1083 valueMask
|= CWHeight
;
1085 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
1086 valueMask
, & windowChanges
);
1089 // For implementation purposes - sometimes decorations make the client area
1091 wxPoint
wxWindowX11::GetClientAreaOrigin() const
1093 return wxPoint(0, 0);
1096 // Makes an adjustment to the window position (for example, a frame that has
1097 // a toolbar that it manages itself).
1098 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
1100 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
1102 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1103 x
+= pt
.x
; y
+= pt
.y
;
1107 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1114 XSizeHints sizeHints
;
1115 sizeHints
.flags
= 0;
1117 if (minW
> -1 && minH
> -1)
1119 sizeHints
.flags
|= PMinSize
;
1120 sizeHints
.min_width
= minW
;
1121 sizeHints
.min_height
= minH
;
1123 if (maxW
> -1 && maxH
> -1)
1125 sizeHints
.flags
|= PMaxSize
;
1126 sizeHints
.max_width
= maxW
;
1127 sizeHints
.max_height
= maxH
;
1129 if (incW
> -1 && incH
> -1)
1131 sizeHints
.flags
|= PResizeInc
;
1132 sizeHints
.width_inc
= incW
;
1133 sizeHints
.height_inc
= incH
;
1136 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
1139 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
1141 DoSetSize(x
, y
, width
, height
);
1144 // ---------------------------------------------------------------------------
1146 // ---------------------------------------------------------------------------
1148 int wxWindowX11::GetCharHeight() const
1150 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1152 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1154 int direction
, ascent
, descent
;
1155 XCharStruct overall
;
1156 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1157 &descent
, &overall
);
1159 // return (overall.ascent + overall.descent);
1160 return (ascent
+ descent
);
1163 int wxWindowX11::GetCharWidth() const
1165 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1167 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1169 int direction
, ascent
, descent
;
1170 XCharStruct overall
;
1171 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1172 &descent
, &overall
);
1174 return overall
.width
;
1177 void wxWindowX11::GetTextExtent(const wxString
& string
,
1179 int *descent
, int *externalLeading
,
1180 const wxFont
*theFont
) const
1182 wxFont
*fontToUse
= (wxFont
*)theFont
;
1184 fontToUse
= (wxFont
*) & m_font
;
1186 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1188 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1190 int direction
, ascent
, descent2
;
1191 XCharStruct overall
;
1192 int slen
= string
.Len();
1196 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1197 &ascent
, &descent2
, &overall
);
1200 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1201 &direction
, &ascent
, &descent2
, &overall
);
1204 *x
= (overall
.width
);
1206 *y
= (ascent
+ descent2
);
1208 *descent
= descent2
;
1209 if (externalLeading
)
1210 *externalLeading
= 0;
1214 // ----------------------------------------------------------------------------
1216 // ----------------------------------------------------------------------------
1218 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1220 m_needsRefresh
= TRUE
;
1221 Display
*display
= wxGlobalDisplay();
1222 Window thisWindow
= (Window
) GetMainWindow();
1224 XExposeEvent dummyEvent
;
1226 GetSize(&width
, &height
);
1228 dummyEvent
.type
= Expose
;
1229 dummyEvent
.display
= display
;
1230 dummyEvent
.send_event
= True
;
1231 dummyEvent
.window
= thisWindow
;
1234 dummyEvent
.x
= rect
->x
;
1235 dummyEvent
.y
= rect
->y
;
1236 dummyEvent
.width
= rect
->width
;
1237 dummyEvent
.height
= rect
->height
;
1243 dummyEvent
.width
= width
;
1244 dummyEvent
.height
= height
;
1246 dummyEvent
.count
= 0;
1250 wxClientDC
dc((wxWindow
*) this);
1251 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1252 dc
.SetBackground(backgroundBrush
);
1259 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1262 void wxWindowX11::Clear()
1264 wxClientDC
dc((wxWindow
*) this);
1265 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1266 dc
.SetBackground(brush
);
1270 void wxWindowX11::X11SendPaintEvents()
1272 m_clipPaintRegion
= TRUE
;
1274 if (!m_clearRegion
.IsEmpty())
1276 wxWindowDC
dc( (wxWindow
*)this );
1277 dc
.SetClippingRegion( m_clearRegion
);
1279 wxEraseEvent
erase_event( GetId(), &dc
);
1280 erase_event
.SetEventObject( this );
1282 if (!GetEventHandler()->ProcessEvent(erase_event
))
1284 wxRegionIterator
upd( m_clearRegion
);
1287 // XClearArea( ... , upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
1291 m_clearRegion
.Clear();
1294 wxNcPaintEvent
nc_paint_event( GetId() );
1295 nc_paint_event
.SetEventObject( this );
1296 GetEventHandler()->ProcessEvent( nc_paint_event
);
1298 wxPaintEvent
paint_event( GetId() );
1299 paint_event
.SetEventObject( this );
1300 GetEventHandler()->ProcessEvent( paint_event
);
1302 m_clipPaintRegion
= FALSE
;
1305 // ----------------------------------------------------------------------------
1307 // ----------------------------------------------------------------------------
1309 // Responds to colour changes: passes event on to children.
1310 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1312 wxWindowList::Node
*node
= GetChildren().GetFirst();
1315 // Only propagate to non-top-level windows
1316 wxWindow
*win
= node
->GetData();
1317 if ( win
->GetParent() )
1319 wxSysColourChangedEvent event2
;
1320 event
.m_eventObject
= win
;
1321 win
->GetEventHandler()->ProcessEvent(event2
);
1324 node
= node
->GetNext();
1328 void wxWindowX11::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1330 // This calls the UI-update mechanism (querying windows for
1331 // menu/toolbar/control state information)
1335 // ----------------------------------------------------------------------------
1337 // ----------------------------------------------------------------------------
1339 bool wxWindowX11::ProcessAccelerator(wxKeyEvent
& event
)
1341 if (!m_acceleratorTable
.Ok())
1344 const wxAcceleratorEntry
* entry
= m_acceleratorTable
.GetEntry(event
);
1347 // Bingo, we have a match. Now find a control that matches the
1348 // entry command id.
1350 // Need to go up to the top of the window hierarchy, since it might
1351 // be e.g. a menu item
1352 wxWindow
* parent
= (wxWindow
*) this;
1353 while ( parent
&& !parent
->IsTopLevel() )
1354 parent
= parent
->GetParent();
1359 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1362 // Try for a menu command
1363 if (frame
->GetMenuBar())
1365 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1368 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1369 commandEvent
.SetEventObject(frame
);
1371 // If ProcessEvent returns TRUE (it was handled), then
1372 // the calling code will skip the event handling.
1373 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1378 // Find a child matching the command id
1379 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1385 // Now we process those kinds of windows that we can.
1386 // For now, only buttons.
1387 if ( wxDynamicCast(child
, wxButton
) )
1389 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1390 commandEvent
.SetEventObject(child
);
1391 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1398 // We didn't match the key event against an accelerator.
1402 // ============================================================================
1403 // X11-specific stuff from here on
1404 // ============================================================================
1406 // ----------------------------------------------------------------------------
1407 // function which maintain the global hash table mapping Widgets to wxWindows
1408 // ----------------------------------------------------------------------------
1410 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1412 wxWindow
*oldItem
= NULL
;
1413 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1415 wxLogDebug("Widget table clash: new widget is %ld, %s",
1416 (long)w
, win
->GetClassInfo()->GetClassName());
1420 wxWidgetHashTable
->Put((long) w
, win
);
1422 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1423 w
, win
, win
->GetClassInfo()->GetClassName());
1428 wxWindow
*wxGetWindowFromTable(Window w
)
1430 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1433 void wxDeleteWindowFromTable(Window w
)
1435 wxWidgetHashTable
->Delete((long)w
);
1438 // ----------------------------------------------------------------------------
1439 // add/remove window from the table
1440 // ----------------------------------------------------------------------------
1442 // ----------------------------------------------------------------------------
1443 // X11-specific accessors
1444 // ----------------------------------------------------------------------------
1446 // Get the underlying X window
1447 WXWindow
wxWindowX11::GetXWindow() const
1449 return GetMainWindow();
1452 // Get the underlying X display
1453 WXDisplay
*wxWindowX11::GetXDisplay() const
1455 return wxGetDisplay();
1458 WXWindow
wxWindowX11::GetMainWindow() const
1461 return m_drawingArea
;
1463 return m_mainWidget
;
1466 WXWindow
wxWindowX11::GetClientWindow() const
1468 if (m_drawingArea
!= (WXWindow
) 0)
1469 return m_drawingArea
;
1471 return GetMainWindow();
1474 WXWindow
wxWindowX11::GetTopWindow() const
1476 return GetMainWindow();
1479 WXWindow
wxWindowX11::GetLabelWindow() const
1481 return GetMainWindow();
1484 // ----------------------------------------------------------------------------
1486 // ----------------------------------------------------------------------------
1488 // TODO: implement wxWindow scrollbar, presumably using wxScrollBar
1490 static void wxScrollBarCallback(Widget scrollbar
,
1491 XtPointer clientData
,
1492 XmScrollBarCallbackStruct
*cbs
)
1494 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
1495 int orientation
= (int) clientData
;
1497 wxEventType eventType
= wxEVT_NULL
;
1498 switch (cbs
->reason
)
1500 case XmCR_INCREMENT
:
1502 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1505 case XmCR_DECREMENT
:
1507 eventType
= wxEVT_SCROLLWIN_LINEUP
;
1512 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1515 case XmCR_VALUE_CHANGED
:
1517 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
1520 case XmCR_PAGE_INCREMENT
:
1522 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1525 case XmCR_PAGE_DECREMENT
:
1527 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1532 eventType
= wxEVT_SCROLLWIN_TOP
;
1535 case XmCR_TO_BOTTOM
:
1537 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1542 // Should never get here
1543 wxFAIL_MSG("Unknown scroll event.");
1548 wxScrollWinEvent
event(eventType
,
1550 ((orientation
== XmHORIZONTAL
) ?
1551 wxHORIZONTAL
: wxVERTICAL
));
1552 event
.SetEventObject( win
);
1553 win
->GetEventHandler()->ProcessEvent(event
);
1557 // ----------------------------------------------------------------------------
1558 // TranslateXXXEvent() functions
1559 // ----------------------------------------------------------------------------
1561 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1563 switch (xevent
->xany
.type
)
1571 wxEventType eventType
= wxEVT_NULL
;
1573 if (xevent
->xany
.type
== EnterNotify
)
1575 //if (local_event.xcrossing.mode!=NotifyNormal)
1576 // return ; // Ignore grab events
1577 eventType
= wxEVT_ENTER_WINDOW
;
1578 // canvas->GetEventHandler()->OnSetFocus();
1580 else if (xevent
->xany
.type
== LeaveNotify
)
1582 //if (local_event.xcrossingr.mode!=NotifyNormal)
1583 // return ; // Ignore grab events
1584 eventType
= wxEVT_LEAVE_WINDOW
;
1585 // canvas->GetEventHandler()->OnKillFocus();
1587 else if (xevent
->xany
.type
== MotionNotify
)
1589 eventType
= wxEVT_MOTION
;
1591 else if (xevent
->xany
.type
== ButtonPress
)
1593 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1595 if (xevent
->xbutton
.button
== Button1
)
1597 eventType
= wxEVT_LEFT_DOWN
;
1600 else if (xevent
->xbutton
.button
== Button2
)
1602 eventType
= wxEVT_MIDDLE_DOWN
;
1605 else if (xevent
->xbutton
.button
== Button3
)
1607 eventType
= wxEVT_RIGHT_DOWN
;
1611 // check for a double click
1612 // TODO: where can we get this value from?
1613 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1614 long dclickTime
= 200;
1615 long ts
= wxevent
.GetTimestamp();
1617 int buttonLast
= win
->GetLastClickedButton();
1618 long lastTS
= win
->GetLastClickTime();
1619 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1622 win
->SetLastClick(0, ts
);
1623 if ( eventType
== wxEVT_LEFT_DOWN
)
1624 eventType
= wxEVT_LEFT_DCLICK
;
1625 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1626 eventType
= wxEVT_MIDDLE_DCLICK
;
1627 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1628 eventType
= wxEVT_RIGHT_DCLICK
;
1632 // not fast enough or different button
1633 win
->SetLastClick(button
, ts
);
1636 else if (xevent
->xany
.type
== ButtonRelease
)
1638 if (xevent
->xbutton
.button
== Button1
)
1640 eventType
= wxEVT_LEFT_UP
;
1642 else if (xevent
->xbutton
.button
== Button2
)
1644 eventType
= wxEVT_MIDDLE_UP
;
1646 else if (xevent
->xbutton
.button
== Button3
)
1648 eventType
= wxEVT_RIGHT_UP
;
1657 wxevent
.SetEventType(eventType
);
1659 wxevent
.m_x
= xevent
->xbutton
.x
;
1660 wxevent
.m_y
= xevent
->xbutton
.y
;
1662 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1663 || (event_left_is_down (xevent
)
1664 && (eventType
!= wxEVT_LEFT_UP
)));
1665 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1666 || (event_middle_is_down (xevent
)
1667 && (eventType
!= wxEVT_MIDDLE_UP
)));
1668 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1669 || (event_right_is_down (xevent
)
1670 && (eventType
!= wxEVT_RIGHT_UP
)));
1672 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1673 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1674 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1675 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1677 wxevent
.SetId(win
->GetId());
1678 wxevent
.SetEventObject(win
);
1686 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1688 switch (xevent
->xany
.type
)
1696 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1697 int id
= wxCharCodeXToWX (keySym
);
1699 if (xevent
->xkey
.state
& ShiftMask
)
1700 wxevent
.m_shiftDown
= TRUE
;
1701 if (xevent
->xkey
.state
& ControlMask
)
1702 wxevent
.m_controlDown
= TRUE
;
1703 if (xevent
->xkey
.state
& Mod3Mask
)
1704 wxevent
.m_altDown
= TRUE
;
1705 if (xevent
->xkey
.state
& Mod1Mask
)
1706 wxevent
.m_metaDown
= TRUE
;
1707 wxevent
.SetEventObject(win
);
1708 wxevent
.m_keyCode
= id
;
1709 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1711 wxevent
.m_x
= xevent
->xbutton
.x
;
1712 wxevent
.m_y
= xevent
->xbutton
.y
;
1726 // ----------------------------------------------------------------------------
1728 // ----------------------------------------------------------------------------
1732 #define YAllocColor XAllocColor
1733 XColor g_itemColors
[5];
1734 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1737 static XmColorProc colorProc
;
1739 result
= wxNO_COLORS
;
1743 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1744 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1745 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1746 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1747 if (colorProc
== (XmColorProc
) NULL
)
1749 // Get a ptr to the actual function
1750 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1751 // And set it back to motif.
1752 XmSetColorCalculation (colorProc
);
1754 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1755 &g_itemColors
[wxFORE_INDEX
],
1756 &g_itemColors
[wxSELE_INDEX
],
1757 &g_itemColors
[wxTOPS_INDEX
],
1758 &g_itemColors
[wxBOTS_INDEX
]);
1759 result
= wxBACK_COLORS
;
1763 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1764 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1765 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1766 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1767 if (result
== wxNO_COLORS
)
1768 result
= wxFORE_COLORS
;
1771 Display
*dpy
= display
;
1772 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1776 /* 5 Colours to allocate */
1777 for (int i
= 0; i
< 5; i
++)
1778 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1779 result
= wxNO_COLORS
;
1783 /* Only 1 colour to allocate */
1784 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1785 result
= wxNO_COLORS
;
1793 // Changes the foreground and background colours to be derived from the current
1794 // background colour. To change the foreground colour, you must call
1795 // SetForegroundColour explicitly.
1796 void wxWindowX11::ChangeBackgroundColour()
1800 WXWidget mainWidget
= GetMainWidget();
1802 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
1806 void wxWindowX11::ChangeForegroundColour()
1810 WXWidget mainWidget
= GetMainWidget();
1812 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
1813 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
1814 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
1818 // Change a widget's foreground and background colours.
1819 void wxWindowX11::DoChangeForegroundColour(WXWindow widget
, wxColour
& foregroundColour
)
1823 // When should we specify the foreground, if it's calculated
1824 // by wxComputeColours?
1825 // Solution: say we start with the default (computed) foreground colour.
1826 // If we call SetForegroundColour explicitly for a control or window,
1827 // then the foreground is changed.
1828 // Therefore SetBackgroundColour computes the foreground colour, and
1829 // SetForegroundColour changes the foreground colour. The ordering is
1832 Widget w
= (Widget
)widget
;
1835 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
1841 void wxWindowX11::DoChangeBackgroundColour(WXWindow widget
, wxColour
& backgroundColour
, bool changeArmColour
)
1845 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
1848 XtVaSetValues ((Widget
) widget
,
1849 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
1850 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
1851 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
1852 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
1855 if (changeArmColour
)
1856 XtVaSetValues ((Widget
) widget
,
1857 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
1862 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1864 if ( !wxWindowBase::SetBackgroundColour(col
) )
1867 ChangeBackgroundColour();
1872 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1874 if ( !wxWindowBase::SetForegroundColour(col
) )
1877 ChangeForegroundColour();
1882 void wxWindowX11::ChangeFont(bool keepOriginalSize
)
1886 // Note that this causes the widget to be resized back
1887 // to its original size! We therefore have to set the size
1888 // back again. TODO: a better way in Motif?
1889 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
1890 if (w
&& m_font
.Ok())
1892 int width
, height
, width1
, height1
;
1893 GetSize(& width
, & height
);
1895 // lesstif 0.87 hangs here
1896 #ifndef LESSTIF_VERSION
1898 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
1902 GetSize(& width1
, & height1
);
1903 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
1905 SetSize(-1, -1, width
, height
);
1911 // ----------------------------------------------------------------------------
1913 // ----------------------------------------------------------------------------
1915 wxWindow
*wxGetActiveWindow()
1918 wxFAIL_MSG("Not implemented");
1923 wxWindow
*wxWindowBase::GetCapture()
1925 return (wxWindow
*)g_captureWindow
;
1929 // Find the wxWindow at the current mouse position, returning the mouse
1931 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1933 return wxFindWindowAtPoint(wxGetMousePosition());
1936 // Get the current mouse position.
1937 wxPoint
wxGetMousePosition()
1939 Display
*display
= wxGlobalDisplay();
1940 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1941 Window rootReturn
, childReturn
;
1942 int rootX
, rootY
, winX
, winY
;
1943 unsigned int maskReturn
;
1945 XQueryPointer (display
,
1949 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1950 return wxPoint(rootX
, rootY
);
1954 // ----------------------------------------------------------------------------
1955 // wxNoOptimize: switch off size optimization
1956 // ----------------------------------------------------------------------------
1958 int wxNoOptimize::ms_count
= 0;