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;
108 m_button3Pressed
= FALSE
;
110 m_winCaptured
= FALSE
;
113 m_isBeingDeleted
= FALSE
;
119 m_drawingArea
= (WXWindow
) 0;
127 m_backingPixmap
= (WXPixmap
) 0;
136 m_canAddEventHandler
= FALSE
;
141 // real construction (Init() must have been called before!)
142 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
146 const wxString
& name
)
148 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
150 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
153 parent
->AddChild(this);
155 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
156 m_foregroundColour
= *wxBLACK
;
158 // TODO: How to create more interesting borders?
159 // Will presumably have to create multiple windows.
160 if (style
& wxSIMPLE_BORDER
)
163 } else if (style
& wxSUNKEN_BORDER
)
166 } else if (style
& wxRAISED_BORDER
)
171 int w
= size
.GetWidth();
172 int h
= size
.GetHeight();
175 int h
= size
.GetHeight();
181 int innerWidth
= w
- 2*m_borderSize
;
182 int innerHeight
= h
- 2*m_borderSize
;
184 int screen
= DefaultScreen(wxGlobalDisplay());
188 parentWindow
= (Window
) parent
->GetClientWindow();
190 parentWindow
= RootWindow(wxGlobalDisplay(), screen
);
192 Widget window
= XCreateSimpleWindow(wxGlobalDisplay(),
193 x
, y
, innerWidth
, innerHeight
, borderWidth
,
194 m_backgroundColour
.AllocColour(wxGlobalDisplay()),
195 m_foregroundColour
.AllocColour(wxGlobalDisplay()));
197 // Select event types wanted
198 XSelectInput(wxGlobalDisplay(), window
,
199 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
200 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
201 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
204 m_mainWindow
= (WXWindow
) window
;
206 wxAddWindowToTable(window
, (wxWindow
*) this);
208 // If a subwindow, show.
209 if (parent
&& !parent
->IsKindOf(CLASSINFO(wxTopLevelWindowX11
)) && parent
->IsShown())
212 XMapWindow(wxGlobalDisplay(), window
);
215 // Without this, the cursor may not be restored properly (e.g. in splitter
217 SetCursor(*wxSTANDARD_CURSOR
);
218 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
219 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
225 wxWindowX11::~wxWindowX11()
227 if (g_captureWindow
== this)
228 g_captureWindow
= NULL
;
230 m_isBeingDeleted
= TRUE
;
232 // X11-specific actions first
233 WXWindow wMain
= GetMainWindow();
236 // Removes event handlers
237 //DetachWidget(wMain);
243 m_parent
->RemoveChild( this );
248 // If m_drawingArea, we're a fully-fledged window with drawing area,
249 // scrollbars etc. (what wxCanvas used to be)
252 // Destroy children before destroying self
256 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
258 Widget w
= (Widget
) m_drawingArea
;
259 wxDeleteWindowFromTable(w
);
264 m_drawingArea
= (WXWidget
) 0;
267 // Only if we're _really_ a canvas (not a dialog box/panel)
268 if (m_scrolledWindow
)
270 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
275 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
276 XtUnmanageChild((Widget
) m_hScrollBar
);
280 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
281 XtUnmanageChild((Widget
) m_vScrollBar
);
285 XtDestroyWidget((Widget
) m_hScrollBar
);
287 XtDestroyWidget((Widget
) m_vScrollBar
);
289 UnmanageAndDestroy(m_scrolledWindow
);
293 XtDestroyWidget ((Widget
) m_borderWidget
);
294 m_borderWidget
= (WXWidget
) 0;
297 else // Why wasn't this here before? JACS 8/3/2000
302 // Destroy the window
305 XSelectInput(wxGlobalDisplay(), (Window
) GetMainWindow(),
307 wxDeleteWindowFromTable((Window
) GetMainWindow());
308 XDestroyWindow((Window
) GetMainWindow());
309 SetMainWindow((WXWindow
) NULL
);
313 // ----------------------------------------------------------------------------
314 // scrollbar management
315 // ----------------------------------------------------------------------------
318 void wxWindowX11::CreateScrollbar(wxOrientation orientation
)
322 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
324 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
326 // Add scrollbars if required
327 if (orientation
== wxHORIZONTAL
)
329 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
330 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
331 XmNorientation
, XmHORIZONTAL
,
333 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
334 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
335 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
336 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
337 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
338 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
339 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
340 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
342 XtVaSetValues (hScrollBar
,
347 m_hScrollBar
= (WXWidget
) hScrollBar
;
349 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
350 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
352 XtRealizeWidget(hScrollBar
);
354 XtVaSetValues((Widget
) m_scrolledWindow
,
355 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
360 wxAddWindowToTable( hScrollBar
, this );
363 if (orientation
== wxVERTICAL
)
365 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
366 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
367 XmNorientation
, XmVERTICAL
,
369 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
370 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
371 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
372 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
373 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
374 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
375 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
376 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
378 XtVaSetValues (vScrollBar
,
383 m_vScrollBar
= (WXWidget
) vScrollBar
;
384 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
385 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
387 XtRealizeWidget(vScrollBar
);
389 XtVaSetValues((Widget
) m_scrolledWindow
,
390 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
395 wxAddWindowToTable( vScrollBar
, this );
398 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
402 void wxWindowX11::DestroyScrollbar(wxOrientation orientation
)
406 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
408 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
409 // Add scrollbars if required
410 if (orientation
== wxHORIZONTAL
)
414 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
415 XtDestroyWidget((Widget
) m_hScrollBar
);
417 m_hScrollBar
= (WXWidget
) 0;
420 XtVaSetValues((Widget
) m_scrolledWindow
,
421 XmNhorizontalScrollBar
, (Widget
) 0,
426 if (orientation
== wxVERTICAL
)
430 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
431 XtDestroyWidget((Widget
) m_vScrollBar
);
433 m_vScrollBar
= (WXWidget
) 0;
436 XtVaSetValues((Widget
) m_scrolledWindow
,
437 XmNverticalScrollBar
, (Widget
) 0,
441 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
445 // ---------------------------------------------------------------------------
447 // ---------------------------------------------------------------------------
449 void wxWindowX11::SetFocus()
451 Window wMain
= (Window
) GetMainWidget();
454 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
457 wmhints
.flags
= InputHint
;
458 wmhints
.input
= True
;
459 XSetWMHints(wxGlobalDisplay(), wMain
, &wmhints
)
463 // Get the window with the focus
464 wxWindow
*wxWindowBase::FindFocus()
466 Window wFocus
= (Window
) 0;
469 XGetInputFocus(wxGlobalDisplay(), & wFocus
, & revert
);
472 wxWindow
*win
= NULL
;
475 win
= wxGetWindowFromTable(wFocus
);
476 wFocus
= wxGetWindowParent(wFocus
);
477 } while (wFocus
&& !win
);
485 // Enabling/disabling handled by event loop, and not sending events
487 bool wxWindowX11::Enable(bool enable
)
489 if ( !wxWindowBase::Enable(enable
) )
495 bool wxWindowX11::Show(bool show
)
497 if ( !wxWindowBase::Show(show
) )
500 Window xwin
= (Window
) GetXWindow();
501 Display
*xdisp
= (Display
*) GetXDisplay();
504 XMapWindow(xdisp
, xwin
);
508 XUnmapWindow(xdisp
, xwin
);
514 // Raise the window to the top of the Z order
515 void wxWindowX11::Raise()
517 Window window
= (Window
) GetTopWindow();
519 XRaiseWindow(wxGlobalDisplay(), window
);
522 // Lower the window to the bottom of the Z order
523 void wxWindowX11::Lower()
525 Window window
= (Window
) GetTopWindow();
527 XLowerWindow(wxGlobalDisplay(), window
);
530 void wxWindowX11::DoCaptureMouse()
532 g_captureWindow
= (wxWindow
*) this;
536 // TODO: should we also call XGrabButton, XGrabKeyboard?
539 int res
= XGrabPointer(wxGlobalDisplay(), (Window
) GetMainWindow(),
541 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
545 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
548 if (res
== GrabSuccess
)
550 m_winCaptured
= TRUE
;
555 void wxWindowX11::DoReleaseMouse()
557 g_captureWindow
= NULL
;
558 if ( !m_winCaptured
)
561 Widget wMain
= (Widget
)GetMainWidget();
563 // TODO: should we also call XUngrabButton, XUngrabKeyboard?
565 XUngrabPointer(wxGlobalDisplay(), wMain
);
567 m_winCaptured
= FALSE
;
570 bool wxWindowX11::SetFont(const wxFont
& font
)
572 if ( !wxWindowBase::SetFont(font
) )
583 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
585 if ( !wxWindowBase::SetCursor(cursor
) )
591 wxCursor
* cursor2
= NULL
;
593 cursor2
= & m_cursor
;
595 cursor2
= wxSTANDARD_CURSOR
;
597 WXDisplay
*dpy
= GetXDisplay();
598 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
600 Window win
= (Window
) GetMainWindow();
601 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
606 // Coordinates relative to the window
607 void wxWindowX11::WarpPointer (int x
, int y
)
609 Window wClient
= (Window
) GetClientWindow();
611 XWarpPointer(wxGlobalDisplay(), None
, wClient
, 0, 0, 0, 0, x
, y
);
614 // ---------------------------------------------------------------------------
616 // ---------------------------------------------------------------------------
618 int wxWindowX11::GetScrollPos(int orient
) const
620 if (orient
== wxHORIZONTAL
)
626 // This now returns the whole range, not just the number of positions that we
628 int wxWindowX11::GetScrollRange(int WXUNUSED(orient
)) const
633 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
634 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
637 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
642 int wxWindowX11::GetScrollThumb(int orient
) const
648 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
649 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
652 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
657 void wxWindowX11::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
662 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
666 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
669 SetInternalScrollPos((wxOrientation
)orient
, pos
);
672 // New function that will replace some of the above.
673 void wxWindowX11::SetScrollbar(int WXUNUSED(orient
), int WXUNUSED(pos
), int WXUNUSED(thumbVisible
),
674 int WXUNUSED(range
), bool WXUNUSED(refresh
))
679 GetSize(& oldW
, & oldH
);
683 if (thumbVisible
== 0)
686 if (thumbVisible
> range
)
687 thumbVisible
= range
;
689 // Save the old state to see if it changed
690 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
692 if (orient
== wxHORIZONTAL
)
694 if (thumbVisible
== range
)
697 DestroyScrollbar(wxHORIZONTAL
);
702 CreateScrollbar(wxHORIZONTAL
);
705 if (orient
== wxVERTICAL
)
707 if (thumbVisible
== range
)
710 DestroyScrollbar(wxVERTICAL
);
715 CreateScrollbar(wxVERTICAL
);
718 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
720 if (oldScrollBar
!= newScrollBar
)
722 // This is important! Without it, scrollbars misbehave badly.
723 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
724 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
725 XtRealizeWidget((Widget
) m_scrolledWindow
);
726 XtManageChild((Widget
) m_scrolledWindow
);
731 XtVaSetValues((Widget
) newScrollBar
,
735 XmNsliderSize
, thumbVisible
,
739 SetInternalScrollPos((wxOrientation
)orient
, pos
);
742 GetSize(& newW
, & newH
);
744 // Adjusting scrollbars can resize the canvas accidentally
745 if (newW
!= oldW
|| newH
!= oldH
)
746 SetSize(-1, -1, oldW
, oldH
);
750 // Does a physical scroll
751 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
756 // Use specified rectangle
757 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
761 // Use whole client area
763 GetClientSize(& w
, & h
);
766 wxNode
*cnode
= m_children
.First();
769 wxWindow
*child
= (wxWindow
*) cnode
->Data();
772 child
->GetSize( &sx
, &sy
);
773 wxPoint
pos( child
->GetPosition() );
774 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
775 cnode
= cnode
->Next();
778 int x1
= (dx
>= 0) ? x
: x
- dx
;
779 int y1
= (dy
>= 0) ? y
: y
- dy
;
780 int w1
= w
- abs(dx
);
781 int h1
= h
- abs(dy
);
782 int x2
= (dx
>= 0) ? x
+ dx
: x
;
783 int y2
= (dy
>= 0) ? y
+ dy
: y
;
785 wxClientDC
dc((wxWindow
*) this);
787 dc
.SetLogicalFunction (wxCOPY
);
789 Window window
= (Window
) GetMainWindow();
790 Display
* display
= wxGlobalDisplay();
792 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
793 x1
, y1
, w1
, h1
, x2
, y2
);
795 dc
.SetAutoSetting(TRUE
);
796 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
797 dc
.SetBrush(brush
); // FIXME: needed?
799 // We'll add rectangles to the list of update rectangles according to which
800 // bits we've exposed.
805 wxRect
*rect
= new wxRect
;
811 XFillRectangle(display
, window
,
812 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
816 rect
->width
= rect
->width
;
817 rect
->height
= rect
->height
;
819 updateRects
.Append((wxObject
*) rect
);
823 wxRect
*rect
= new wxRect
;
825 rect
->x
= x
+ w
+ dx
;
830 XFillRectangle(display
, window
,
831 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
836 rect
->width
= rect
->width
;
837 rect
->height
= rect
->height
;
839 updateRects
.Append((wxObject
*) rect
);
843 wxRect
*rect
= new wxRect
;
850 XFillRectangle(display
, window
,
851 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
855 rect
->width
= rect
->width
;
856 rect
->height
= rect
->height
;
858 updateRects
.Append((wxObject
*) rect
);
862 wxRect
*rect
= new wxRect
;
865 rect
->y
= y
+ h
+ dy
;
869 XFillRectangle(display
, window
,
870 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
874 rect
->width
= rect
->width
;
875 rect
->height
= rect
->height
;
877 updateRects
.Append((wxObject
*) rect
);
879 dc
.SetBrush(wxNullBrush
);
881 // Now send expose events
883 wxNode
* node
= updateRects
.First();
886 wxRect
* rect
= (wxRect
*) node
->Data();
890 event
.display
= display
;
891 event
.send_event
= True
;
892 event
.window
= window
;
896 event
.width
= rect
->width
;
897 event
.height
= rect
->height
;
901 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
907 // Delete the update rects
908 node
= updateRects
.First();
911 wxRect
* rect
= (wxRect
*) node
->Data();
918 // XmUpdateDisplay((Widget) GetMainWidget());
921 // ---------------------------------------------------------------------------
923 // ---------------------------------------------------------------------------
925 #if wxUSE_DRAG_AND_DROP
927 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
934 // Old style file-manager drag&drop
935 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
940 // ----------------------------------------------------------------------------
942 // ----------------------------------------------------------------------------
946 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
951 #endif // wxUSE_TOOLTIPS
953 // ---------------------------------------------------------------------------
954 // moving and resizing
955 // ---------------------------------------------------------------------------
957 bool wxWindowX11::PreResize()
963 void wxWindowX11::DoGetSize(int *x
, int *y
) const
965 Window window
= (Window
) GetTopWindow();
968 XWindowAttributes attr
;
969 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
974 *x
= attr
.width
+ 2*m_borderSize
;
975 *y
= attr
.height
+ 2*m_borderSize
;
980 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
982 Window window
= (Window
) GetTopWindow();
985 XWindowAttributes attr
;
986 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
994 // We may be faking the client origin. So a window that's really at (0, 30)
995 // may appear (to wxWin apps) to be at (0, 0).
998 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1006 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
1008 Display
*display
= wxGlobalDisplay();
1009 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
1010 Window thisWindow
= (Window
) GetClientWindow();
1015 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1018 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
1020 Display
*display
= wxGlobalDisplay();
1021 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
1022 Window thisWindow
= (Window
) GetClientWindow();
1027 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1031 // Get size *available for subwindows* i.e. excluding menu bar etc.
1032 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
1034 Window window
= (Window
) GetClientWindow();
1038 XWindowAttributes attr
;
1039 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
1050 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1052 if (!GetMainWindow())
1055 XWindowChanges windowChanges
;
1058 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1060 windowChanges
.x
= x
;
1063 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1065 windowChanges
.y
= y
;
1068 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1070 windowChanges
.width
= width
- m_borderSize
*2;
1071 valueMask
|= CWWidth
;
1073 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1075 windowChanges
.height
= height
- m_borderSize
*2;
1076 valueMask
|= CWHeight
;
1078 AdjustForParentClientOrigin(valueMask
.x
, valueMask
.y
, sizeFlags
);
1080 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
1081 valueMask
, & windowChanges
);
1084 void wxWindowX11::DoSetClientSize(int width
, int height
)
1086 if (!GetMainWindow())
1089 XWindowChanges windowChanges
;
1094 windowChanges
.width
= width
;
1095 valueMask
|= CWWidth
;
1099 windowChanges
.height
= height
;
1100 valueMask
|= CWHeight
;
1102 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
1103 valueMask
, & windowChanges
);
1106 // For implementation purposes - sometimes decorations make the client area
1108 wxPoint
wxWindowX11::GetClientAreaOrigin() const
1110 return wxPoint(0, 0);
1113 // Makes an adjustment to the window position (for example, a frame that has
1114 // a toolbar that it manages itself).
1115 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
1117 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
1119 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1120 x
+= pt
.x
; y
+= pt
.y
;
1124 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1131 XSizeHints sizeHints
;
1132 sizeHints
.flags
= 0;
1134 if (minW
> -1 && minH
> -1)
1136 sizeHints
.flags
|= PMinSize
;
1137 sizeHints
.min_width
= minW
;
1138 sizeHints
.min_height
= minH
;
1140 if (maxW
> -1 && maxH
> -1)
1142 sizeHints
.flags
|= PMaxSize
;
1143 sizeHints
.max_width
= maxW
;
1144 sizeHints
.max_height
= maxH
;
1146 if (incW
> -1 && incH
> -1)
1148 sizeHints
.flags
|= PResizeInc
;
1149 sizeHints
.width_inc
= incW
;
1150 sizeHints
.height_inc
= incH
;
1153 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
)
1156 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
1158 DoSetSize(x
, y
, width
, height
);
1161 // ---------------------------------------------------------------------------
1163 // ---------------------------------------------------------------------------
1165 int wxWindowX11::GetCharHeight() const
1167 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1169 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1171 int direction
, ascent
, descent
;
1172 XCharStruct overall
;
1173 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1174 &descent
, &overall
);
1176 // return (overall.ascent + overall.descent);
1177 return (ascent
+ descent
);
1180 int wxWindowX11::GetCharWidth() const
1182 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1184 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1186 int direction
, ascent
, descent
;
1187 XCharStruct overall
;
1188 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1189 &descent
, &overall
);
1191 return overall
.width
;
1194 void wxWindowX11::GetTextExtent(const wxString
& string
,
1196 int *descent
, int *externalLeading
,
1197 const wxFont
*theFont
) const
1199 wxFont
*fontToUse
= (wxFont
*)theFont
;
1201 fontToUse
= (wxFont
*) & m_font
;
1203 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1205 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1207 int direction
, ascent
, descent2
;
1208 XCharStruct overall
;
1209 int slen
= string
.Len();
1213 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1214 &ascent
, &descent2
, &overall
);
1217 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1218 &direction
, &ascent
, &descent2
, &overall
);
1221 *x
= (overall
.width
);
1223 *y
= (ascent
+ descent2
);
1225 *descent
= descent2
;
1226 if (externalLeading
)
1227 *externalLeading
= 0;
1231 // ----------------------------------------------------------------------------
1233 // ----------------------------------------------------------------------------
1235 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1237 m_needsRefresh
= TRUE
;
1238 Display
*display
= wxGlobalDisplay();
1239 Window thisWindow
= (Window
) GetMainWindow();
1241 XExposeEvent dummyEvent
;
1243 GetSize(&width
, &height
);
1245 dummyEvent
.type
= Expose
;
1246 dummyEvent
.display
= display
;
1247 dummyEvent
.send_event
= True
;
1248 dummyEvent
.window
= thisWindow
;
1251 dummyEvent
.x
= rect
->x
;
1252 dummyEvent
.y
= rect
->y
;
1253 dummyEvent
.width
= rect
->width
;
1254 dummyEvent
.height
= rect
->height
;
1260 dummyEvent
.width
= width
;
1261 dummyEvent
.height
= height
;
1263 dummyEvent
.count
= 0;
1267 wxClientDC
dc((wxWindow
*) this);
1268 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1269 dc
.SetBackground(backgroundBrush
);
1276 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1279 void wxWindowX11::Clear()
1281 wxClientDC
dc((wxWindow
*) this);
1282 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1283 dc
.SetBackground(brush
);
1287 void wxWindowX11::ClearUpdateRects()
1289 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1292 wxRect
* rect
= node
->GetData();
1294 node
= node
->GetNext();
1297 m_updateRects
.Clear();
1300 void wxWindowX11::DoPaint()
1302 // Set an erase event first
1303 wxEraseEvent
eraseEvent(GetId());
1304 eraseEvent
.SetEventObject(this);
1305 GetEventHandler()->ProcessEvent(eraseEvent
);
1307 wxPaintEvent
event(GetId());
1308 event
.SetEventObject(this);
1309 GetEventHandler()->ProcessEvent(event
);
1311 m_needsRefresh
= FALSE
;
1314 // ----------------------------------------------------------------------------
1316 // ----------------------------------------------------------------------------
1318 // Responds to colour changes: passes event on to children.
1319 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1321 wxWindowList::Node
*node
= GetChildren().GetFirst();
1324 // Only propagate to non-top-level windows
1325 wxWindow
*win
= node
->GetData();
1326 if ( win
->GetParent() )
1328 wxSysColourChangedEvent event2
;
1329 event
.m_eventObject
= win
;
1330 win
->GetEventHandler()->ProcessEvent(event2
);
1333 node
= node
->GetNext();
1337 void wxWindowX11::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1339 // This calls the UI-update mechanism (querying windows for
1340 // menu/toolbar/control state information)
1344 // ----------------------------------------------------------------------------
1346 // ----------------------------------------------------------------------------
1348 bool wxWindowX11::ProcessAccelerator(wxKeyEvent
& event
)
1350 if (!m_acceleratorTable
.Ok())
1353 const wxAcceleratorEntry
* entry
= m_acceleratorTable
.GetEntry(event
);
1356 // Bingo, we have a match. Now find a control that matches the
1357 // entry command id.
1359 // Need to go up to the top of the window hierarchy, since it might
1360 // be e.g. a menu item
1361 wxWindow
* parent
= (wxWindow
*) this;
1362 while ( parent
&& !parent
->IsTopLevel() )
1363 parent
= parent
->GetParent();
1368 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1371 // Try for a menu command
1372 if (frame
->GetMenuBar())
1374 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1377 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1378 commandEvent
.SetEventObject(frame
);
1380 // If ProcessEvent returns TRUE (it was handled), then
1381 // the calling code will skip the event handling.
1382 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1387 // Find a child matching the command id
1388 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1394 // Now we process those kinds of windows that we can.
1395 // For now, only buttons.
1396 if ( wxDynamicCast(child
, wxButton
) )
1398 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1399 commandEvent
.SetEventObject(child
);
1400 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1407 // We didn't match the key event against an accelerator.
1411 // ============================================================================
1412 // X11-specific stuff from here on
1413 // ============================================================================
1415 // ----------------------------------------------------------------------------
1416 // function which maintain the global hash table mapping Widgets to wxWindows
1417 // ----------------------------------------------------------------------------
1419 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1421 wxWindow
*oldItem
= NULL
;
1422 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1424 wxLogDebug("Widget table clash: new widget is %ld, %s",
1425 (long)w
, win
->GetClassInfo()->GetClassName());
1429 wxWidgetHashTable
->Put((long) w
, win
);
1431 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1432 w
, win
, win
->GetClassInfo()->GetClassName());
1437 wxWindow
*wxGetWindowFromTable(Window w
)
1439 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1442 void wxDeleteWindowFromTable(Window w
)
1444 wxWidgetHashTable
->Delete((long)w
);
1447 // ----------------------------------------------------------------------------
1448 // add/remove window from the table
1449 // ----------------------------------------------------------------------------
1451 // ----------------------------------------------------------------------------
1452 // X11-specific accessors
1453 // ----------------------------------------------------------------------------
1455 // Get the underlying X window
1456 WXWindow
wxWindowX11::GetXWindow() const
1458 return GetMainWindow();
1461 // Get the underlying X display
1462 WXDisplay
*wxWindowX11::GetXDisplay() const
1464 return wxGetDisplay();
1467 WXWindow
wxWindowX11::GetMainWindow() const
1470 return m_drawingArea
;
1472 return m_mainWidget
;
1475 WXWindow
wxWindowX11::GetClientWindow() const
1477 if (m_drawingArea
!= (WXWindow
) 0)
1478 return m_drawingArea
;
1480 return GetMainWindow();
1483 WXWindow
wxWindowX11::GetTopWindow() const
1485 return GetMainWindow();
1488 WXWindow
wxWindowX11::GetLabelWindow() const
1490 return GetMainWindow();
1493 // ----------------------------------------------------------------------------
1495 // ----------------------------------------------------------------------------
1497 // TODO: implement wxWindow scrollbar, presumably using wxScrollBar
1499 static void wxScrollBarCallback(Widget scrollbar
,
1500 XtPointer clientData
,
1501 XmScrollBarCallbackStruct
*cbs
)
1503 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
1504 int orientation
= (int) clientData
;
1506 wxEventType eventType
= wxEVT_NULL
;
1507 switch (cbs
->reason
)
1509 case XmCR_INCREMENT
:
1511 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1514 case XmCR_DECREMENT
:
1516 eventType
= wxEVT_SCROLLWIN_LINEUP
;
1521 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1524 case XmCR_VALUE_CHANGED
:
1526 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
1529 case XmCR_PAGE_INCREMENT
:
1531 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1534 case XmCR_PAGE_DECREMENT
:
1536 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1541 eventType
= wxEVT_SCROLLWIN_TOP
;
1544 case XmCR_TO_BOTTOM
:
1546 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1551 // Should never get here
1552 wxFAIL_MSG("Unknown scroll event.");
1557 wxScrollWinEvent
event(eventType
,
1559 ((orientation
== XmHORIZONTAL
) ?
1560 wxHORIZONTAL
: wxVERTICAL
));
1561 event
.SetEventObject( win
);
1562 win
->GetEventHandler()->ProcessEvent(event
);
1566 // ----------------------------------------------------------------------------
1567 // TranslateXXXEvent() functions
1568 // ----------------------------------------------------------------------------
1570 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1572 switch (xevent
->xany
.type
)
1580 wxEventType eventType
= wxEVT_NULL
;
1582 if (xevent
->xany
.type
== EnterNotify
)
1584 //if (local_event.xcrossing.mode!=NotifyNormal)
1585 // return ; // Ignore grab events
1586 eventType
= wxEVT_ENTER_WINDOW
;
1587 // canvas->GetEventHandler()->OnSetFocus();
1589 else if (xevent
->xany
.type
== LeaveNotify
)
1591 //if (local_event.xcrossingr.mode!=NotifyNormal)
1592 // return ; // Ignore grab events
1593 eventType
= wxEVT_LEAVE_WINDOW
;
1594 // canvas->GetEventHandler()->OnKillFocus();
1596 else if (xevent
->xany
.type
== MotionNotify
)
1598 eventType
= wxEVT_MOTION
;
1600 else if (xevent
->xany
.type
== ButtonPress
)
1602 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1604 if (xevent
->xbutton
.button
== Button1
)
1606 eventType
= wxEVT_LEFT_DOWN
;
1607 win
->SetButton1(TRUE
);
1610 else if (xevent
->xbutton
.button
== Button2
)
1612 eventType
= wxEVT_MIDDLE_DOWN
;
1613 win
->SetButton2(TRUE
);
1616 else if (xevent
->xbutton
.button
== Button3
)
1618 eventType
= wxEVT_RIGHT_DOWN
;
1619 win
->SetButton3(TRUE
);
1623 // check for a double click
1624 // TODO: where can we get this value from?
1625 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1626 long dclickTime
= 200;
1627 long ts
= wxevent
.GetTimestamp();
1629 int buttonLast
= win
->GetLastClickedButton();
1630 long lastTS
= win
->GetLastClickTime();
1631 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1634 win
->SetLastClick(0, ts
);
1635 if ( eventType
== wxEVT_LEFT_DOWN
)
1636 eventType
= wxEVT_LEFT_DCLICK
;
1637 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1638 eventType
= wxEVT_MIDDLE_DCLICK
;
1639 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1640 eventType
= wxEVT_RIGHT_DCLICK
;
1644 // not fast enough or different button
1645 win
->SetLastClick(button
, ts
);
1648 else if (xevent
->xany
.type
== ButtonRelease
)
1650 if (xevent
->xbutton
.button
== Button1
)
1652 eventType
= wxEVT_LEFT_UP
;
1653 win
->SetButton1(FALSE
);
1655 else if (xevent
->xbutton
.button
== Button2
)
1657 eventType
= wxEVT_MIDDLE_UP
;
1658 win
->SetButton2(FALSE
);
1660 else if (xevent
->xbutton
.button
== Button3
)
1662 eventType
= wxEVT_RIGHT_UP
;
1663 win
->SetButton3(FALSE
);
1672 wxevent
.SetEventType(eventType
);
1674 wxevent
.m_x
= xevent
->xbutton
.x
;
1675 wxevent
.m_y
= xevent
->xbutton
.y
;
1677 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1678 || (event_left_is_down (xevent
)
1679 && (eventType
!= wxEVT_LEFT_UP
)));
1680 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1681 || (event_middle_is_down (xevent
)
1682 && (eventType
!= wxEVT_MIDDLE_UP
)));
1683 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1684 || (event_right_is_down (xevent
)
1685 && (eventType
!= wxEVT_RIGHT_UP
)));
1687 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1688 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1689 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1690 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1692 wxevent
.SetId(win
->GetId());
1693 wxevent
.SetEventObject(win
);
1701 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1703 switch (xevent
->xany
.type
)
1711 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1712 int id
= wxCharCodeXToWX (keySym
);
1714 if (xevent
->xkey
.state
& ShiftMask
)
1715 wxevent
.m_shiftDown
= TRUE
;
1716 if (xevent
->xkey
.state
& ControlMask
)
1717 wxevent
.m_controlDown
= TRUE
;
1718 if (xevent
->xkey
.state
& Mod3Mask
)
1719 wxevent
.m_altDown
= TRUE
;
1720 if (xevent
->xkey
.state
& Mod1Mask
)
1721 wxevent
.m_metaDown
= TRUE
;
1722 wxevent
.SetEventObject(win
);
1723 wxevent
.m_keyCode
= id
;
1724 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1726 wxevent
.m_x
= xevent
->xbutton
.x
;
1727 wxevent
.m_y
= xevent
->xbutton
.y
;
1741 // ----------------------------------------------------------------------------
1743 // ----------------------------------------------------------------------------
1747 #define YAllocColor XAllocColor
1748 XColor g_itemColors
[5];
1749 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1752 static XmColorProc colorProc
;
1754 result
= wxNO_COLORS
;
1758 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1759 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1760 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1761 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1762 if (colorProc
== (XmColorProc
) NULL
)
1764 // Get a ptr to the actual function
1765 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1766 // And set it back to motif.
1767 XmSetColorCalculation (colorProc
);
1769 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1770 &g_itemColors
[wxFORE_INDEX
],
1771 &g_itemColors
[wxSELE_INDEX
],
1772 &g_itemColors
[wxTOPS_INDEX
],
1773 &g_itemColors
[wxBOTS_INDEX
]);
1774 result
= wxBACK_COLORS
;
1778 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1779 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1780 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1781 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1782 if (result
== wxNO_COLORS
)
1783 result
= wxFORE_COLORS
;
1786 Display
*dpy
= display
;
1787 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1791 /* 5 Colours to allocate */
1792 for (int i
= 0; i
< 5; i
++)
1793 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1794 result
= wxNO_COLORS
;
1798 /* Only 1 colour to allocate */
1799 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1800 result
= wxNO_COLORS
;
1808 // Changes the foreground and background colours to be derived from the current
1809 // background colour. To change the foreground colour, you must call
1810 // SetForegroundColour explicitly.
1811 void wxWindowX11::ChangeBackgroundColour()
1815 WXWidget mainWidget
= GetMainWidget();
1817 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
1821 void wxWindowX11::ChangeForegroundColour()
1825 WXWidget mainWidget
= GetMainWidget();
1827 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
1828 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
1829 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
1833 // Change a widget's foreground and background colours.
1834 void wxWindowX11::DoChangeForegroundColour(WXWindow widget
, wxColour
& foregroundColour
)
1838 // When should we specify the foreground, if it's calculated
1839 // by wxComputeColours?
1840 // Solution: say we start with the default (computed) foreground colour.
1841 // If we call SetForegroundColour explicitly for a control or window,
1842 // then the foreground is changed.
1843 // Therefore SetBackgroundColour computes the foreground colour, and
1844 // SetForegroundColour changes the foreground colour. The ordering is
1847 Widget w
= (Widget
)widget
;
1850 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
1856 void wxWindowX11::DoChangeBackgroundColour(WXWindow widget
, wxColour
& backgroundColour
, bool changeArmColour
)
1860 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
1863 XtVaSetValues ((Widget
) widget
,
1864 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
1865 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
1866 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
1867 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
1870 if (changeArmColour
)
1871 XtVaSetValues ((Widget
) widget
,
1872 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
1877 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1879 if ( !wxWindowBase::SetBackgroundColour(col
) )
1882 ChangeBackgroundColour();
1887 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1889 if ( !wxWindowBase::SetForegroundColour(col
) )
1892 ChangeForegroundColour();
1897 void wxWindowX11::ChangeFont(bool keepOriginalSize
)
1901 // Note that this causes the widget to be resized back
1902 // to its original size! We therefore have to set the size
1903 // back again. TODO: a better way in Motif?
1904 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
1905 if (w
&& m_font
.Ok())
1907 int width
, height
, width1
, height1
;
1908 GetSize(& width
, & height
);
1910 // lesstif 0.87 hangs here
1911 #ifndef LESSTIF_VERSION
1913 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
1917 GetSize(& width1
, & height1
);
1918 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
1920 SetSize(-1, -1, width
, height
);
1926 // ----------------------------------------------------------------------------
1928 // ----------------------------------------------------------------------------
1930 wxWindow
*wxGetActiveWindow()
1933 wxFAIL_MSG("Not implemented");
1938 wxWindow
*wxWindowBase::GetCapture()
1940 return (wxWindow
*)g_captureWindow
;
1944 // Find the wxWindow at the current mouse position, returning the mouse
1946 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1948 return wxFindWindowAtPoint(wxGetMousePosition());
1951 // Get the current mouse position.
1952 wxPoint
wxGetMousePosition()
1954 Display
*display
= wxGlobalDisplay();
1955 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1956 Window rootReturn
, childReturn
;
1957 int rootX
, rootY
, winX
, winY
;
1958 unsigned int maskReturn
;
1960 XQueryPointer (display
,
1964 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1965 return wxPoint(rootX
, rootY
);
1969 // ----------------------------------------------------------------------------
1970 // wxNoOptimize: switch off size optimization
1971 // ----------------------------------------------------------------------------
1973 int wxNoOptimize::ms_count
= 0;