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();
180 int screen
= DefaultScreen(wxGlobalDisplay());
184 parentWindow
= (Window
) parent
->GetClientWindow();
186 parentWindow
= RootWindow(wxGlobalDisplay(), screen
);
188 Window window
= XCreateSimpleWindow(wxGlobalDisplay(), parentWindow
,
189 x
, y
, w
, h
, m_borderSize
,
190 m_backgroundColour
.AllocColour(wxGlobalDisplay()),
191 m_foregroundColour
.AllocColour(wxGlobalDisplay()));
193 // Select event types wanted
194 XSelectInput(wxGlobalDisplay(), window
,
195 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
196 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
197 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
200 wxAddWindowToTable(window
, (wxWindow
*) this);
202 // If a subwindow, show.
203 // if (parent && !parent->IsKindOf(CLASSINFO(wxTopLevelWindowX11)) && parent->IsShown())
206 XMapWindow(wxGlobalDisplay(), window
);
209 // Without this, the cursor may not be restored properly (e.g. in splitter
211 SetCursor(*wxSTANDARD_CURSOR
);
212 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
213 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
219 wxWindowX11::~wxWindowX11()
221 if (g_captureWindow
== this)
222 g_captureWindow
= NULL
;
224 m_isBeingDeleted
= TRUE
;
226 // X11-specific actions first
227 WXWindow wMain
= GetMainWindow();
230 // Removes event handlers
231 //DetachWidget(wMain);
237 m_parent
->RemoveChild( this );
242 // If m_drawingArea, we're a fully-fledged window with drawing area,
243 // scrollbars etc. (what wxCanvas used to be)
246 // Destroy children before destroying self
250 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
252 Widget w
= (Widget
) m_drawingArea
;
253 wxDeleteWindowFromTable(w
);
258 m_drawingArea
= (WXWidget
) 0;
261 // Only if we're _really_ a canvas (not a dialog box/panel)
262 if (m_scrolledWindow
)
264 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
269 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
270 XtUnmanageChild((Widget
) m_hScrollBar
);
274 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
275 XtUnmanageChild((Widget
) m_vScrollBar
);
279 XtDestroyWidget((Widget
) m_hScrollBar
);
281 XtDestroyWidget((Widget
) m_vScrollBar
);
283 UnmanageAndDestroy(m_scrolledWindow
);
287 XtDestroyWidget ((Widget
) m_borderWidget
);
288 m_borderWidget
= (WXWidget
) 0;
291 else // Why wasn't this here before? JACS 8/3/2000
296 // Destroy the window
299 XSelectInput(wxGlobalDisplay(), (Window
) GetMainWindow(),
301 wxDeleteWindowFromTable((Window
) GetMainWindow());
302 XDestroyWindow(wxGlobalDisplay(), (Window
) GetMainWindow());
303 SetMainWindow((WXWindow
) NULL
);
307 // ----------------------------------------------------------------------------
308 // scrollbar management
309 // ----------------------------------------------------------------------------
312 void wxWindowX11::CreateScrollbar(wxOrientation orientation
)
316 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
318 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
320 // Add scrollbars if required
321 if (orientation
== wxHORIZONTAL
)
323 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
324 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
325 XmNorientation
, XmHORIZONTAL
,
327 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
328 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
329 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
330 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
331 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
332 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
333 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
334 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
336 XtVaSetValues (hScrollBar
,
341 m_hScrollBar
= (WXWidget
) hScrollBar
;
343 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
344 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
346 XtRealizeWidget(hScrollBar
);
348 XtVaSetValues((Widget
) m_scrolledWindow
,
349 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
354 wxAddWindowToTable( hScrollBar
, this );
357 if (orientation
== wxVERTICAL
)
359 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
360 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
361 XmNorientation
, XmVERTICAL
,
363 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
364 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
365 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
366 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
367 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
368 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
369 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
370 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
372 XtVaSetValues (vScrollBar
,
377 m_vScrollBar
= (WXWidget
) vScrollBar
;
378 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
379 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
381 XtRealizeWidget(vScrollBar
);
383 XtVaSetValues((Widget
) m_scrolledWindow
,
384 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
389 wxAddWindowToTable( vScrollBar
, this );
392 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
396 void wxWindowX11::DestroyScrollbar(wxOrientation orientation
)
400 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
402 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
403 // Add scrollbars if required
404 if (orientation
== wxHORIZONTAL
)
408 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
409 XtDestroyWidget((Widget
) m_hScrollBar
);
411 m_hScrollBar
= (WXWidget
) 0;
414 XtVaSetValues((Widget
) m_scrolledWindow
,
415 XmNhorizontalScrollBar
, (Widget
) 0,
420 if (orientation
== wxVERTICAL
)
424 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
425 XtDestroyWidget((Widget
) m_vScrollBar
);
427 m_vScrollBar
= (WXWidget
) 0;
430 XtVaSetValues((Widget
) m_scrolledWindow
,
431 XmNverticalScrollBar
, (Widget
) 0,
435 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
439 // ---------------------------------------------------------------------------
441 // ---------------------------------------------------------------------------
443 void wxWindowX11::SetFocus()
446 Window wMain
= (Window
) GetMainWidget();
449 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
452 wmhints
.flags
= InputHint
;
453 wmhints
.input
= True
;
454 XSetWMHints(wxGlobalDisplay(), wMain
, &wmhints
)
459 // Get the window with the focus
460 wxWindow
*wxWindowBase::FindFocus()
462 Window wFocus
= (Window
) 0;
465 XGetInputFocus(wxGlobalDisplay(), & wFocus
, & revert
);
468 wxWindow
*win
= NULL
;
471 win
= wxGetWindowFromTable(wFocus
);
472 wFocus
= wxGetWindowParent(wFocus
);
473 } while (wFocus
&& !win
);
481 // Enabling/disabling handled by event loop, and not sending events
483 bool wxWindowX11::Enable(bool enable
)
485 if ( !wxWindowBase::Enable(enable
) )
491 bool wxWindowX11::Show(bool show
)
493 if ( !wxWindowBase::Show(show
) )
496 Window xwin
= (Window
) GetXWindow();
497 Display
*xdisp
= (Display
*) GetXDisplay();
500 XMapWindow(xdisp
, xwin
);
504 XUnmapWindow(xdisp
, xwin
);
510 // Raise the window to the top of the Z order
511 void wxWindowX11::Raise()
513 Window window
= (Window
) GetTopWindow();
515 XRaiseWindow(wxGlobalDisplay(), window
);
518 // Lower the window to the bottom of the Z order
519 void wxWindowX11::Lower()
521 Window window
= (Window
) GetTopWindow();
523 XLowerWindow(wxGlobalDisplay(), window
);
526 void wxWindowX11::DoCaptureMouse()
528 g_captureWindow
= (wxWindow
*) this;
532 // TODO: should we also call XGrabButton, XGrabKeyboard?
535 int res
= XGrabPointer(wxGlobalDisplay(), (Window
) GetMainWindow(),
537 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
541 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
544 if (res
== GrabSuccess
)
546 m_winCaptured
= TRUE
;
551 void wxWindowX11::DoReleaseMouse()
553 g_captureWindow
= NULL
;
554 if ( !m_winCaptured
)
557 Window wMain
= (Window
)GetMainWindow();
559 // TODO: should we also call XUngrabButton, XUngrabKeyboard?
561 XUngrabPointer(wxGlobalDisplay(), wMain
);
563 m_winCaptured
= FALSE
;
566 bool wxWindowX11::SetFont(const wxFont
& font
)
568 if ( !wxWindowBase::SetFont(font
) )
579 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
581 if ( !wxWindowBase::SetCursor(cursor
) )
587 wxCursor
* cursor2
= NULL
;
589 cursor2
= & m_cursor
;
591 cursor2
= wxSTANDARD_CURSOR
;
593 WXDisplay
*dpy
= GetXDisplay();
594 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
596 Window win
= (Window
) GetMainWindow();
597 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
602 // Coordinates relative to the window
603 void wxWindowX11::WarpPointer (int x
, int y
)
605 Window wClient
= (Window
) GetClientWindow();
607 XWarpPointer(wxGlobalDisplay(), None
, wClient
, 0, 0, 0, 0, x
, y
);
610 // ---------------------------------------------------------------------------
612 // ---------------------------------------------------------------------------
614 int wxWindowX11::GetScrollPos(int orient
) const
616 if (orient
== wxHORIZONTAL
)
622 // This now returns the whole range, not just the number of positions that we
624 int wxWindowX11::GetScrollRange(int WXUNUSED(orient
)) const
629 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
630 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
633 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
638 int wxWindowX11::GetScrollThumb(int orient
) const
644 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
645 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
648 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
653 void wxWindowX11::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
658 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
662 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
665 SetInternalScrollPos((wxOrientation
)orient
, pos
);
668 // New function that will replace some of the above.
669 void wxWindowX11::SetScrollbar(int WXUNUSED(orient
), int WXUNUSED(pos
), int WXUNUSED(thumbVisible
),
670 int WXUNUSED(range
), bool WXUNUSED(refresh
))
675 GetSize(& oldW
, & oldH
);
679 if (thumbVisible
== 0)
682 if (thumbVisible
> range
)
683 thumbVisible
= range
;
685 // Save the old state to see if it changed
686 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
688 if (orient
== wxHORIZONTAL
)
690 if (thumbVisible
== range
)
693 DestroyScrollbar(wxHORIZONTAL
);
698 CreateScrollbar(wxHORIZONTAL
);
701 if (orient
== wxVERTICAL
)
703 if (thumbVisible
== range
)
706 DestroyScrollbar(wxVERTICAL
);
711 CreateScrollbar(wxVERTICAL
);
714 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
716 if (oldScrollBar
!= newScrollBar
)
718 // This is important! Without it, scrollbars misbehave badly.
719 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
720 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
721 XtRealizeWidget((Widget
) m_scrolledWindow
);
722 XtManageChild((Widget
) m_scrolledWindow
);
727 XtVaSetValues((Widget
) newScrollBar
,
731 XmNsliderSize
, thumbVisible
,
735 SetInternalScrollPos((wxOrientation
)orient
, pos
);
738 GetSize(& newW
, & newH
);
740 // Adjusting scrollbars can resize the canvas accidentally
741 if (newW
!= oldW
|| newH
!= oldH
)
742 SetSize(-1, -1, oldW
, oldH
);
746 // Does a physical scroll
747 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
752 // Use specified rectangle
753 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
757 // Use whole client area
759 GetClientSize(& w
, & h
);
762 wxNode
*cnode
= m_children
.First();
765 wxWindow
*child
= (wxWindow
*) cnode
->Data();
768 child
->GetSize( &sx
, &sy
);
769 wxPoint
pos( child
->GetPosition() );
770 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
771 cnode
= cnode
->Next();
774 int x1
= (dx
>= 0) ? x
: x
- dx
;
775 int y1
= (dy
>= 0) ? y
: y
- dy
;
776 int w1
= w
- abs(dx
);
777 int h1
= h
- abs(dy
);
778 int x2
= (dx
>= 0) ? x
+ dx
: x
;
779 int y2
= (dy
>= 0) ? y
+ dy
: y
;
781 wxClientDC
dc((wxWindow
*) this);
783 dc
.SetLogicalFunction (wxCOPY
);
785 Window window
= (Window
) GetMainWindow();
786 Display
* display
= wxGlobalDisplay();
788 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
789 x1
, y1
, w1
, h1
, x2
, y2
);
791 dc
.SetAutoSetting(TRUE
);
792 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
793 dc
.SetBrush(brush
); // FIXME: needed?
795 // We'll add rectangles to the list of update rectangles according to which
796 // bits we've exposed.
801 wxRect
*rect
= new wxRect
;
807 XFillRectangle(display
, window
,
808 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
812 rect
->width
= rect
->width
;
813 rect
->height
= rect
->height
;
815 updateRects
.Append((wxObject
*) rect
);
819 wxRect
*rect
= new wxRect
;
821 rect
->x
= x
+ w
+ dx
;
826 XFillRectangle(display
, window
,
827 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
832 rect
->width
= rect
->width
;
833 rect
->height
= rect
->height
;
835 updateRects
.Append((wxObject
*) rect
);
839 wxRect
*rect
= new wxRect
;
846 XFillRectangle(display
, window
,
847 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
851 rect
->width
= rect
->width
;
852 rect
->height
= rect
->height
;
854 updateRects
.Append((wxObject
*) rect
);
858 wxRect
*rect
= new wxRect
;
861 rect
->y
= y
+ h
+ dy
;
865 XFillRectangle(display
, window
,
866 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
870 rect
->width
= rect
->width
;
871 rect
->height
= rect
->height
;
873 updateRects
.Append((wxObject
*) rect
);
875 dc
.SetBrush(wxNullBrush
);
877 // Now send expose events
879 wxNode
* node
= updateRects
.First();
882 wxRect
* rect
= (wxRect
*) node
->Data();
886 event
.display
= display
;
887 event
.send_event
= True
;
888 event
.window
= window
;
892 event
.width
= rect
->width
;
893 event
.height
= rect
->height
;
897 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
903 // Delete the update rects
904 node
= updateRects
.First();
907 wxRect
* rect
= (wxRect
*) node
->Data();
914 // XmUpdateDisplay((Widget) GetMainWidget());
917 // ---------------------------------------------------------------------------
919 // ---------------------------------------------------------------------------
921 #if wxUSE_DRAG_AND_DROP
923 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
930 // Old style file-manager drag&drop
931 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
936 // ----------------------------------------------------------------------------
938 // ----------------------------------------------------------------------------
942 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
947 #endif // wxUSE_TOOLTIPS
949 // ---------------------------------------------------------------------------
950 // moving and resizing
951 // ---------------------------------------------------------------------------
953 bool wxWindowX11::PreResize()
959 void wxWindowX11::DoGetSize(int *x
, int *y
) const
961 Window window
= (Window
) GetTopWindow();
964 XWindowAttributes attr
;
965 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
970 *x
= attr
.width
+ 2*m_borderSize
;
971 *y
= attr
.height
+ 2*m_borderSize
;
976 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
978 Window window
= (Window
) GetTopWindow();
981 XWindowAttributes attr
;
982 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
990 // We may be faking the client origin. So a window that's really at (0, 30)
991 // may appear (to wxWin apps) to be at (0, 0).
994 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1002 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
1004 Display
*display
= wxGlobalDisplay();
1005 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
1006 Window thisWindow
= (Window
) GetClientWindow();
1011 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1014 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
1016 Display
*display
= wxGlobalDisplay();
1017 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
1018 Window thisWindow
= (Window
) GetClientWindow();
1023 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1027 // Get size *available for subwindows* i.e. excluding menu bar etc.
1028 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
1030 Window window
= (Window
) GetClientWindow();
1034 XWindowAttributes attr
;
1035 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
1046 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1048 if (!GetMainWindow())
1051 XWindowChanges windowChanges
;
1054 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1056 windowChanges
.x
= x
;
1059 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1061 windowChanges
.y
= y
;
1064 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1066 windowChanges
.width
= width
- m_borderSize
*2;
1067 valueMask
|= CWWidth
;
1069 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1071 windowChanges
.height
= height
- m_borderSize
*2;
1072 valueMask
|= CWHeight
;
1074 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
1076 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
1077 valueMask
, & windowChanges
);
1080 void wxWindowX11::DoSetClientSize(int width
, int height
)
1082 if (!GetMainWindow())
1085 XWindowChanges windowChanges
;
1090 windowChanges
.width
= width
;
1091 valueMask
|= CWWidth
;
1095 windowChanges
.height
= height
;
1096 valueMask
|= CWHeight
;
1098 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
1099 valueMask
, & windowChanges
);
1102 // For implementation purposes - sometimes decorations make the client area
1104 wxPoint
wxWindowX11::GetClientAreaOrigin() const
1106 return wxPoint(0, 0);
1109 // Makes an adjustment to the window position (for example, a frame that has
1110 // a toolbar that it manages itself).
1111 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
1113 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
1115 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1116 x
+= pt
.x
; y
+= pt
.y
;
1120 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1127 XSizeHints sizeHints
;
1128 sizeHints
.flags
= 0;
1130 if (minW
> -1 && minH
> -1)
1132 sizeHints
.flags
|= PMinSize
;
1133 sizeHints
.min_width
= minW
;
1134 sizeHints
.min_height
= minH
;
1136 if (maxW
> -1 && maxH
> -1)
1138 sizeHints
.flags
|= PMaxSize
;
1139 sizeHints
.max_width
= maxW
;
1140 sizeHints
.max_height
= maxH
;
1142 if (incW
> -1 && incH
> -1)
1144 sizeHints
.flags
|= PResizeInc
;
1145 sizeHints
.width_inc
= incW
;
1146 sizeHints
.height_inc
= incH
;
1149 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
1152 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
1154 DoSetSize(x
, y
, width
, height
);
1157 // ---------------------------------------------------------------------------
1159 // ---------------------------------------------------------------------------
1161 int wxWindowX11::GetCharHeight() const
1163 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1165 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1167 int direction
, ascent
, descent
;
1168 XCharStruct overall
;
1169 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1170 &descent
, &overall
);
1172 // return (overall.ascent + overall.descent);
1173 return (ascent
+ descent
);
1176 int wxWindowX11::GetCharWidth() const
1178 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1180 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1182 int direction
, ascent
, descent
;
1183 XCharStruct overall
;
1184 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1185 &descent
, &overall
);
1187 return overall
.width
;
1190 void wxWindowX11::GetTextExtent(const wxString
& string
,
1192 int *descent
, int *externalLeading
,
1193 const wxFont
*theFont
) const
1195 wxFont
*fontToUse
= (wxFont
*)theFont
;
1197 fontToUse
= (wxFont
*) & m_font
;
1199 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1201 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1203 int direction
, ascent
, descent2
;
1204 XCharStruct overall
;
1205 int slen
= string
.Len();
1209 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1210 &ascent
, &descent2
, &overall
);
1213 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1214 &direction
, &ascent
, &descent2
, &overall
);
1217 *x
= (overall
.width
);
1219 *y
= (ascent
+ descent2
);
1221 *descent
= descent2
;
1222 if (externalLeading
)
1223 *externalLeading
= 0;
1227 // ----------------------------------------------------------------------------
1229 // ----------------------------------------------------------------------------
1231 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1233 m_needsRefresh
= TRUE
;
1234 Display
*display
= wxGlobalDisplay();
1235 Window thisWindow
= (Window
) GetMainWindow();
1237 XExposeEvent dummyEvent
;
1239 GetSize(&width
, &height
);
1241 dummyEvent
.type
= Expose
;
1242 dummyEvent
.display
= display
;
1243 dummyEvent
.send_event
= True
;
1244 dummyEvent
.window
= thisWindow
;
1247 dummyEvent
.x
= rect
->x
;
1248 dummyEvent
.y
= rect
->y
;
1249 dummyEvent
.width
= rect
->width
;
1250 dummyEvent
.height
= rect
->height
;
1256 dummyEvent
.width
= width
;
1257 dummyEvent
.height
= height
;
1259 dummyEvent
.count
= 0;
1263 wxClientDC
dc((wxWindow
*) this);
1264 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1265 dc
.SetBackground(backgroundBrush
);
1272 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1275 void wxWindowX11::Clear()
1277 wxClientDC
dc((wxWindow
*) this);
1278 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1279 dc
.SetBackground(brush
);
1283 void wxWindowX11::ClearUpdateRects()
1285 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1288 wxRect
* rect
= node
->GetData();
1290 node
= node
->GetNext();
1293 m_updateRects
.Clear();
1296 void wxWindowX11::DoPaint()
1298 // Set an erase event first
1299 wxEraseEvent
eraseEvent(GetId());
1300 eraseEvent
.SetEventObject(this);
1301 GetEventHandler()->ProcessEvent(eraseEvent
);
1303 wxPaintEvent
event(GetId());
1304 event
.SetEventObject(this);
1305 GetEventHandler()->ProcessEvent(event
);
1307 m_needsRefresh
= FALSE
;
1310 // ----------------------------------------------------------------------------
1312 // ----------------------------------------------------------------------------
1314 // Responds to colour changes: passes event on to children.
1315 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1317 wxWindowList::Node
*node
= GetChildren().GetFirst();
1320 // Only propagate to non-top-level windows
1321 wxWindow
*win
= node
->GetData();
1322 if ( win
->GetParent() )
1324 wxSysColourChangedEvent event2
;
1325 event
.m_eventObject
= win
;
1326 win
->GetEventHandler()->ProcessEvent(event2
);
1329 node
= node
->GetNext();
1333 void wxWindowX11::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1335 // This calls the UI-update mechanism (querying windows for
1336 // menu/toolbar/control state information)
1340 // ----------------------------------------------------------------------------
1342 // ----------------------------------------------------------------------------
1344 bool wxWindowX11::ProcessAccelerator(wxKeyEvent
& event
)
1346 if (!m_acceleratorTable
.Ok())
1349 const wxAcceleratorEntry
* entry
= m_acceleratorTable
.GetEntry(event
);
1352 // Bingo, we have a match. Now find a control that matches the
1353 // entry command id.
1355 // Need to go up to the top of the window hierarchy, since it might
1356 // be e.g. a menu item
1357 wxWindow
* parent
= (wxWindow
*) this;
1358 while ( parent
&& !parent
->IsTopLevel() )
1359 parent
= parent
->GetParent();
1364 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1367 // Try for a menu command
1368 if (frame
->GetMenuBar())
1370 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1373 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1374 commandEvent
.SetEventObject(frame
);
1376 // If ProcessEvent returns TRUE (it was handled), then
1377 // the calling code will skip the event handling.
1378 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1383 // Find a child matching the command id
1384 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1390 // Now we process those kinds of windows that we can.
1391 // For now, only buttons.
1392 if ( wxDynamicCast(child
, wxButton
) )
1394 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1395 commandEvent
.SetEventObject(child
);
1396 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1403 // We didn't match the key event against an accelerator.
1407 // ============================================================================
1408 // X11-specific stuff from here on
1409 // ============================================================================
1411 // ----------------------------------------------------------------------------
1412 // function which maintain the global hash table mapping Widgets to wxWindows
1413 // ----------------------------------------------------------------------------
1415 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1417 wxWindow
*oldItem
= NULL
;
1418 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1420 wxLogDebug("Widget table clash: new widget is %ld, %s",
1421 (long)w
, win
->GetClassInfo()->GetClassName());
1425 wxWidgetHashTable
->Put((long) w
, win
);
1427 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1428 w
, win
, win
->GetClassInfo()->GetClassName());
1433 wxWindow
*wxGetWindowFromTable(Window w
)
1435 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1438 void wxDeleteWindowFromTable(Window w
)
1440 wxWidgetHashTable
->Delete((long)w
);
1443 // ----------------------------------------------------------------------------
1444 // add/remove window from the table
1445 // ----------------------------------------------------------------------------
1447 // ----------------------------------------------------------------------------
1448 // X11-specific accessors
1449 // ----------------------------------------------------------------------------
1451 // Get the underlying X window
1452 WXWindow
wxWindowX11::GetXWindow() const
1454 return GetMainWindow();
1457 // Get the underlying X display
1458 WXDisplay
*wxWindowX11::GetXDisplay() const
1460 return wxGetDisplay();
1463 WXWindow
wxWindowX11::GetMainWindow() const
1466 return m_drawingArea
;
1468 return m_mainWidget
;
1471 WXWindow
wxWindowX11::GetClientWindow() const
1473 if (m_drawingArea
!= (WXWindow
) 0)
1474 return m_drawingArea
;
1476 return GetMainWindow();
1479 WXWindow
wxWindowX11::GetTopWindow() const
1481 return GetMainWindow();
1484 WXWindow
wxWindowX11::GetLabelWindow() const
1486 return GetMainWindow();
1489 // ----------------------------------------------------------------------------
1491 // ----------------------------------------------------------------------------
1493 // TODO: implement wxWindow scrollbar, presumably using wxScrollBar
1495 static void wxScrollBarCallback(Widget scrollbar
,
1496 XtPointer clientData
,
1497 XmScrollBarCallbackStruct
*cbs
)
1499 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
1500 int orientation
= (int) clientData
;
1502 wxEventType eventType
= wxEVT_NULL
;
1503 switch (cbs
->reason
)
1505 case XmCR_INCREMENT
:
1507 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1510 case XmCR_DECREMENT
:
1512 eventType
= wxEVT_SCROLLWIN_LINEUP
;
1517 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1520 case XmCR_VALUE_CHANGED
:
1522 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
1525 case XmCR_PAGE_INCREMENT
:
1527 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1530 case XmCR_PAGE_DECREMENT
:
1532 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1537 eventType
= wxEVT_SCROLLWIN_TOP
;
1540 case XmCR_TO_BOTTOM
:
1542 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1547 // Should never get here
1548 wxFAIL_MSG("Unknown scroll event.");
1553 wxScrollWinEvent
event(eventType
,
1555 ((orientation
== XmHORIZONTAL
) ?
1556 wxHORIZONTAL
: wxVERTICAL
));
1557 event
.SetEventObject( win
);
1558 win
->GetEventHandler()->ProcessEvent(event
);
1562 // ----------------------------------------------------------------------------
1563 // TranslateXXXEvent() functions
1564 // ----------------------------------------------------------------------------
1566 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1568 switch (xevent
->xany
.type
)
1576 wxEventType eventType
= wxEVT_NULL
;
1578 if (xevent
->xany
.type
== EnterNotify
)
1580 //if (local_event.xcrossing.mode!=NotifyNormal)
1581 // return ; // Ignore grab events
1582 eventType
= wxEVT_ENTER_WINDOW
;
1583 // canvas->GetEventHandler()->OnSetFocus();
1585 else if (xevent
->xany
.type
== LeaveNotify
)
1587 //if (local_event.xcrossingr.mode!=NotifyNormal)
1588 // return ; // Ignore grab events
1589 eventType
= wxEVT_LEAVE_WINDOW
;
1590 // canvas->GetEventHandler()->OnKillFocus();
1592 else if (xevent
->xany
.type
== MotionNotify
)
1594 eventType
= wxEVT_MOTION
;
1596 else if (xevent
->xany
.type
== ButtonPress
)
1598 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1600 if (xevent
->xbutton
.button
== Button1
)
1602 eventType
= wxEVT_LEFT_DOWN
;
1603 win
->SetButton1(TRUE
);
1606 else if (xevent
->xbutton
.button
== Button2
)
1608 eventType
= wxEVT_MIDDLE_DOWN
;
1609 win
->SetButton2(TRUE
);
1612 else if (xevent
->xbutton
.button
== Button3
)
1614 eventType
= wxEVT_RIGHT_DOWN
;
1615 win
->SetButton3(TRUE
);
1619 // check for a double click
1620 // TODO: where can we get this value from?
1621 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1622 long dclickTime
= 200;
1623 long ts
= wxevent
.GetTimestamp();
1625 int buttonLast
= win
->GetLastClickedButton();
1626 long lastTS
= win
->GetLastClickTime();
1627 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1630 win
->SetLastClick(0, ts
);
1631 if ( eventType
== wxEVT_LEFT_DOWN
)
1632 eventType
= wxEVT_LEFT_DCLICK
;
1633 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1634 eventType
= wxEVT_MIDDLE_DCLICK
;
1635 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1636 eventType
= wxEVT_RIGHT_DCLICK
;
1640 // not fast enough or different button
1641 win
->SetLastClick(button
, ts
);
1644 else if (xevent
->xany
.type
== ButtonRelease
)
1646 if (xevent
->xbutton
.button
== Button1
)
1648 eventType
= wxEVT_LEFT_UP
;
1649 win
->SetButton1(FALSE
);
1651 else if (xevent
->xbutton
.button
== Button2
)
1653 eventType
= wxEVT_MIDDLE_UP
;
1654 win
->SetButton2(FALSE
);
1656 else if (xevent
->xbutton
.button
== Button3
)
1658 eventType
= wxEVT_RIGHT_UP
;
1659 win
->SetButton3(FALSE
);
1668 wxevent
.SetEventType(eventType
);
1670 wxevent
.m_x
= xevent
->xbutton
.x
;
1671 wxevent
.m_y
= xevent
->xbutton
.y
;
1673 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1674 || (event_left_is_down (xevent
)
1675 && (eventType
!= wxEVT_LEFT_UP
)));
1676 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1677 || (event_middle_is_down (xevent
)
1678 && (eventType
!= wxEVT_MIDDLE_UP
)));
1679 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1680 || (event_right_is_down (xevent
)
1681 && (eventType
!= wxEVT_RIGHT_UP
)));
1683 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1684 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1685 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1686 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1688 wxevent
.SetId(win
->GetId());
1689 wxevent
.SetEventObject(win
);
1697 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1699 switch (xevent
->xany
.type
)
1707 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1708 int id
= wxCharCodeXToWX (keySym
);
1710 if (xevent
->xkey
.state
& ShiftMask
)
1711 wxevent
.m_shiftDown
= TRUE
;
1712 if (xevent
->xkey
.state
& ControlMask
)
1713 wxevent
.m_controlDown
= TRUE
;
1714 if (xevent
->xkey
.state
& Mod3Mask
)
1715 wxevent
.m_altDown
= TRUE
;
1716 if (xevent
->xkey
.state
& Mod1Mask
)
1717 wxevent
.m_metaDown
= TRUE
;
1718 wxevent
.SetEventObject(win
);
1719 wxevent
.m_keyCode
= id
;
1720 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1722 wxevent
.m_x
= xevent
->xbutton
.x
;
1723 wxevent
.m_y
= xevent
->xbutton
.y
;
1737 // ----------------------------------------------------------------------------
1739 // ----------------------------------------------------------------------------
1743 #define YAllocColor XAllocColor
1744 XColor g_itemColors
[5];
1745 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1748 static XmColorProc colorProc
;
1750 result
= wxNO_COLORS
;
1754 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1755 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1756 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1757 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1758 if (colorProc
== (XmColorProc
) NULL
)
1760 // Get a ptr to the actual function
1761 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1762 // And set it back to motif.
1763 XmSetColorCalculation (colorProc
);
1765 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1766 &g_itemColors
[wxFORE_INDEX
],
1767 &g_itemColors
[wxSELE_INDEX
],
1768 &g_itemColors
[wxTOPS_INDEX
],
1769 &g_itemColors
[wxBOTS_INDEX
]);
1770 result
= wxBACK_COLORS
;
1774 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1775 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1776 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1777 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1778 if (result
== wxNO_COLORS
)
1779 result
= wxFORE_COLORS
;
1782 Display
*dpy
= display
;
1783 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1787 /* 5 Colours to allocate */
1788 for (int i
= 0; i
< 5; i
++)
1789 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1790 result
= wxNO_COLORS
;
1794 /* Only 1 colour to allocate */
1795 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1796 result
= wxNO_COLORS
;
1804 // Changes the foreground and background colours to be derived from the current
1805 // background colour. To change the foreground colour, you must call
1806 // SetForegroundColour explicitly.
1807 void wxWindowX11::ChangeBackgroundColour()
1811 WXWidget mainWidget
= GetMainWidget();
1813 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
1817 void wxWindowX11::ChangeForegroundColour()
1821 WXWidget mainWidget
= GetMainWidget();
1823 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
1824 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
1825 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
1829 // Change a widget's foreground and background colours.
1830 void wxWindowX11::DoChangeForegroundColour(WXWindow widget
, wxColour
& foregroundColour
)
1834 // When should we specify the foreground, if it's calculated
1835 // by wxComputeColours?
1836 // Solution: say we start with the default (computed) foreground colour.
1837 // If we call SetForegroundColour explicitly for a control or window,
1838 // then the foreground is changed.
1839 // Therefore SetBackgroundColour computes the foreground colour, and
1840 // SetForegroundColour changes the foreground colour. The ordering is
1843 Widget w
= (Widget
)widget
;
1846 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
1852 void wxWindowX11::DoChangeBackgroundColour(WXWindow widget
, wxColour
& backgroundColour
, bool changeArmColour
)
1856 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
1859 XtVaSetValues ((Widget
) widget
,
1860 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
1861 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
1862 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
1863 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
1866 if (changeArmColour
)
1867 XtVaSetValues ((Widget
) widget
,
1868 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
1873 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1875 if ( !wxWindowBase::SetBackgroundColour(col
) )
1878 ChangeBackgroundColour();
1883 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1885 if ( !wxWindowBase::SetForegroundColour(col
) )
1888 ChangeForegroundColour();
1893 void wxWindowX11::ChangeFont(bool keepOriginalSize
)
1897 // Note that this causes the widget to be resized back
1898 // to its original size! We therefore have to set the size
1899 // back again. TODO: a better way in Motif?
1900 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
1901 if (w
&& m_font
.Ok())
1903 int width
, height
, width1
, height1
;
1904 GetSize(& width
, & height
);
1906 // lesstif 0.87 hangs here
1907 #ifndef LESSTIF_VERSION
1909 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
1913 GetSize(& width1
, & height1
);
1914 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
1916 SetSize(-1, -1, width
, height
);
1922 // ----------------------------------------------------------------------------
1924 // ----------------------------------------------------------------------------
1926 wxWindow
*wxGetActiveWindow()
1929 wxFAIL_MSG("Not implemented");
1934 wxWindow
*wxWindowBase::GetCapture()
1936 return (wxWindow
*)g_captureWindow
;
1940 // Find the wxWindow at the current mouse position, returning the mouse
1942 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1944 return wxFindWindowAtPoint(wxGetMousePosition());
1947 // Get the current mouse position.
1948 wxPoint
wxGetMousePosition()
1950 Display
*display
= wxGlobalDisplay();
1951 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1952 Window rootReturn
, childReturn
;
1953 int rootX
, rootY
, winX
, winY
;
1954 unsigned int maskReturn
;
1956 XQueryPointer (display
,
1960 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1961 return wxPoint(rootX
, rootY
);
1965 // ----------------------------------------------------------------------------
1966 // wxNoOptimize: switch off size optimization
1967 // ----------------------------------------------------------------------------
1969 int wxNoOptimize::ms_count
= 0;