1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "window.h"
25 #define XtDisplay XTDISPLAY
26 #define XtWindow XTWINDOW
27 #define XtScreen XTSCREEN
33 #include "wx/dcclient.h"
36 #include "wx/layout.h"
37 #include "wx/button.h"
38 #include "wx/settings.h"
40 #include "wx/scrolwin.h"
41 #include "wx/module.h"
42 #include "wx/menuitem.h"
44 #include "wx/evtloop.h"
47 #if wxUSE_DRAG_AND_DROP
51 // DoSetSizeIntr and DoMoveWindowIntr
53 // under Motif composite controls (such as wxCalendarCtrl or generic wxSpinCtrl
54 // did nott work and/or segfaulted because
55 // 1) wxWindow::Create calls SetSize,
56 // which results in a call to DoSetSize much earlier than in the other ports
57 // 2) if wxWindow::Create is called (wxControl::Create calls it)
58 // then DoSetSize is never called, causing layout problems in composite
62 // 1) don't call SetSize, DoSetSize, DoMoveWindow, DoGetPosition,
63 // DoSetPosition directly or indirectly from wxWindow::Create
64 // 2) call DoMoveWindow from DoSetSize, allowing controls to override it
67 #pragma message disable nosimpint
71 #include <Xm/DrawingA.h>
72 #include <Xm/ScrolledW.h>
73 #include <Xm/ScrollBar.h>
76 #include <Xm/RowColumn.h> // for XmMenuPosition
78 #pragma message enable nosimpint
81 #include "wx/motif/private.h"
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 static const int SCROLL_MARGIN
= 4;
91 // ----------------------------------------------------------------------------
92 // global variables for this module
93 // ----------------------------------------------------------------------------
95 extern wxHashTable
*wxWidgetHashTable
;
96 static wxWindow
* g_captureWindow
= NULL
;
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
104 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
105 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
106 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
107 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
108 XmScrollBarCallbackStruct
*cbs
);
109 static void wxPanelItemEventHandler(Widget wid
,
110 XtPointer client_data
,
112 Boolean
*continueToDispatch
);
117 // Helper function for 16-bit fonts
118 static int str16len(const char *s
)
122 while (s
[0] && s
[1]) {
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
137 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
138 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
144 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
146 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
147 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
148 EVT_IDLE(wxWindow::OnIdle
)
151 // ============================================================================
153 // ============================================================================
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
161 Widget w
= (Widget
)widget
;
169 bool wxWindow::MapOrUnmap(WXWidget widget
, bool domap
)
171 Widget w
= (Widget
)widget
;
180 // Rationale: a lot of common operations (including but not
181 // limited to moving, resizing and appending items to a listbox)
182 // unmamange the widget, do their work, then manage it again.
183 // This means that, for example adding an item to a listbox will show it,
184 // or that most controls are shown every time they are moved or resized!
185 XtSetMappedWhenManaged( w
, domap
);
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 void wxWindow::Init()
196 // generic initializations first
200 m_needsRefresh
= TRUE
;
201 m_mainWidget
= (WXWidget
) 0;
205 m_button3Pressed
= FALSE
;
207 m_winCaptured
= FALSE
;
210 m_isBeingDeleted
= FALSE
;
216 m_drawingArea
= (WXWidget
) 0;
224 m_backingPixmap
= (WXPixmap
) 0;
233 m_canAddEventHandler
= FALSE
;
236 // real construction (Init() must have been called before!)
237 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
241 const wxString
& name
)
243 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
245 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
247 parent
->AddChild(this);
249 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
250 m_foregroundColour
= *wxBLACK
;
252 //// TODO: we should probably optimize by only creating a
253 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
254 //// But for now, let's simplify things by always creating the
255 //// drawing area, since otherwise the translations are different.
257 // New translations for getting mouse motion feedback
258 static const String translations
=
259 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
260 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
261 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
262 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
263 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
264 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
265 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
266 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
267 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
268 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
269 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
270 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
271 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
272 <Key>: DrawingAreaInput()";
274 XtActionsRec actions
[1];
275 actions
[0].string
= "wxCanvasMotionEvent";
276 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
277 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
279 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
281 if (style
& wxSIMPLE_BORDER
)
283 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
286 xmFrameWidgetClass
, parentWidget
,
287 XmNshadowType
, XmSHADOW_IN
,
288 XmNshadowThickness
, 1,
291 } else if (style
& wxSUNKEN_BORDER
)
293 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
296 xmFrameWidgetClass
, parentWidget
,
297 XmNshadowType
, XmSHADOW_IN
,
300 } else if (style
& wxRAISED_BORDER
)
302 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
305 xmFrameWidgetClass
, parentWidget
,
306 XmNshadowType
, XmSHADOW_OUT
,
311 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
314 xmScrolledWindowWidgetClass
,
315 m_borderWidget
? (Widget
) m_borderWidget
317 XmNresizePolicy
, XmRESIZE_NONE
,
319 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
320 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
324 XtTranslations ptr
= XtParseTranslationTable(translations
);
325 m_drawingArea
= (WXWidget
)XtVaCreateWidget
328 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
329 XmNunitType
, XmPIXELS
,
330 // XmNresizePolicy, XmRESIZE_ANY,
331 XmNresizePolicy
, XmRESIZE_NONE
,
334 XmNtranslations
, ptr
,
337 XtFree((char *) ptr
);
340 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
342 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
343 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
344 XtFree ((char *) ptr
);
348 wxAddWindowToTable((Widget
) m_drawingArea
, this);
349 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
351 // This order is very important in Motif 1.2.1
352 XtRealizeWidget ((Widget
) m_scrolledWindow
);
353 XtRealizeWidget ((Widget
) m_drawingArea
);
354 XtManageChild ((Widget
) m_drawingArea
);
356 ptr
= XtParseTranslationTable("<Configure>: resize()");
357 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
358 XtFree ((char *) ptr
);
360 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
361 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
365 display
= XtDisplay (scrolledWindow
);
366 xwindow
= XtWindow (drawingArea
);
370 (Widget
)m_drawingArea
,
371 PointerMotionHintMask
| EnterWindowMask
|
372 LeaveWindowMask
| FocusChangeMask
,
374 (XtEventHandler
) wxCanvasEnterLeave
,
378 // Scrolled widget needs to have its colour changed or we get a little blue
379 // square where the scrollbars abutt
380 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
381 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
382 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
384 XmScrolledWindowSetAreas(
385 (Widget
)m_scrolledWindow
,
386 (Widget
) 0, (Widget
) 0,
387 (Widget
) m_drawingArea
);
391 XtRealizeWidget ((Widget
) m_hScrollBar
);
393 XtRealizeWidget ((Widget
) m_vScrollBar
);
396 // Without this, the cursor may not be restored properly (e.g. in splitter
398 SetCursor(*wxSTANDARD_CURSOR
);
399 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
400 DoSetSizeIntr(pos
.x
, pos
.y
, size
.x
,size
.y
, wxSIZE_AUTO
, TRUE
);
405 wxWindow::~wxWindow()
407 if (g_captureWindow
== this)
408 g_captureWindow
= NULL
;
410 m_isBeingDeleted
= TRUE
;
412 // Motif-specific actions first
413 WXWidget wMain
= GetMainWidget();
416 // Removes event handlers
423 m_parent
->RemoveChild( this );
425 // If m_drawingArea, we're a fully-fledged window with drawing area,
426 // scrollbars etc. (what wxCanvas used to be)
429 // Destroy children before destroying self
433 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
435 Widget w
= (Widget
) m_drawingArea
;
436 wxDeleteWindowFromTable(w
);
441 m_drawingArea
= (WXWidget
) 0;
444 // Only if we're _really_ a canvas (not a dialog box/panel)
445 if (m_scrolledWindow
)
447 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
452 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
453 XtUnmanageChild((Widget
) m_hScrollBar
);
457 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
458 XtUnmanageChild((Widget
) m_vScrollBar
);
462 XtDestroyWidget((Widget
) m_hScrollBar
);
464 XtDestroyWidget((Widget
) m_vScrollBar
);
466 UnmanageAndDestroy(m_scrolledWindow
);
470 XtDestroyWidget ((Widget
) m_borderWidget
);
471 m_borderWidget
= (WXWidget
) 0;
474 else // Why wasn't this here before? JACS 8/3/2000
478 // Destroy the window
481 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
482 // Child widgets will get destroyed automatically when a frame
483 // or dialog is destroyed, but before that you may get some memory
484 // leaks and potential layout problems if you delete and then add
487 // GRG, Feb/2000: commented this out when adding support for
488 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
489 // that this call crashed wxMotif under OS/2, so it seems
490 // that leaving it out is the right thing to do.
491 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
492 XtDestroyWidget((Widget
) GetMainWidget());
493 SetMainWidget((WXWidget
) NULL
);
497 // ----------------------------------------------------------------------------
498 // scrollbar management
499 // ----------------------------------------------------------------------------
502 void wxWindow::CreateScrollbar(wxOrientation orientation
)
504 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
506 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
508 // Add scrollbars if required
509 if (orientation
== wxHORIZONTAL
)
511 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
512 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
513 XmNorientation
, XmHORIZONTAL
,
515 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
516 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
517 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
518 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
519 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
520 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
521 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
522 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
524 XtVaSetValues (hScrollBar
,
529 m_hScrollBar
= (WXWidget
) hScrollBar
;
531 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
532 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
534 XtRealizeWidget(hScrollBar
);
536 XtVaSetValues((Widget
) m_scrolledWindow
,
537 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
542 wxAddWindowToTable( hScrollBar
, this );
545 if (orientation
== wxVERTICAL
)
547 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
548 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
549 XmNorientation
, XmVERTICAL
,
551 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
552 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
553 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
554 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
555 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
556 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
557 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
558 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
560 XtVaSetValues (vScrollBar
,
565 m_vScrollBar
= (WXWidget
) vScrollBar
;
566 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
567 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
569 XtRealizeWidget(vScrollBar
);
571 XtVaSetValues((Widget
) m_scrolledWindow
,
572 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
577 wxAddWindowToTable( vScrollBar
, this );
580 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
583 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
585 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
587 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
588 // Add scrollbars if required
589 if (orientation
== wxHORIZONTAL
)
593 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
594 XtDestroyWidget((Widget
) m_hScrollBar
);
596 m_hScrollBar
= (WXWidget
) 0;
599 XtVaSetValues((Widget
) m_scrolledWindow
,
600 XmNhorizontalScrollBar
, (Widget
) 0,
605 if (orientation
== wxVERTICAL
)
609 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
610 XtDestroyWidget((Widget
) m_vScrollBar
);
612 m_vScrollBar
= (WXWidget
) 0;
615 XtVaSetValues((Widget
) m_scrolledWindow
,
616 XmNverticalScrollBar
, (Widget
) 0,
620 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
623 // ---------------------------------------------------------------------------
625 // ---------------------------------------------------------------------------
627 void wxWindow::SetFocus()
629 Widget wMain
= (Widget
) GetMainWidget();
630 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
631 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
634 // Get the window with the focus
635 wxWindow
*wxWindowBase::FindFocus()
638 // (1) Can there be multiple focussed widgets in an application?
639 // In which case we need to find the top-level window that's
641 // (2) The widget with the focus may not be in the widget table
642 // depending on which widgets I put in the table
643 wxWindow
*winFocus
= (wxWindow
*)NULL
;
644 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
646 node
= node
->GetNext() )
648 wxWindow
*win
= node
->GetData();
650 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
652 if (w
!= (Widget
) NULL
)
654 winFocus
= wxGetWindowFromTable(w
);
663 bool wxWindow::Enable(bool enable
)
665 if ( !wxWindowBase::Enable(enable
) )
668 Widget wMain
= (Widget
)GetMainWidget();
671 XtSetSensitive(wMain
, enable
);
672 XmUpdateDisplay(wMain
);
678 bool wxWindow::Show(bool show
)
680 if ( !wxWindowBase::Show(show
) )
683 if (m_borderWidget
|| m_scrolledWindow
)
685 MapOrUnmap(m_drawingArea
, show
);
686 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
690 if ( !MapOrUnmap(GetTopWidget(), show
) )
691 MapOrUnmap(GetMainWidget(), show
);
697 // Raise the window to the top of the Z order
698 void wxWindow::Raise()
700 Widget wTop
= (Widget
) GetTopWidget();
701 Window window
= XtWindow(wTop
);
702 XRaiseWindow(XtDisplay(wTop
), window
);
705 // Lower the window to the bottom of the Z order
706 void wxWindow::Lower()
708 Widget wTop
= (Widget
) GetTopWidget();
709 Window window
= XtWindow(wTop
);
710 XLowerWindow(XtDisplay(wTop
), window
);
713 void wxWindow::SetTitle(const wxString
& title
)
715 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
718 wxString
wxWindow::GetTitle() const
721 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
723 return wxString(title
);
726 void wxWindow::DoCaptureMouse()
728 g_captureWindow
= this;
732 Widget wMain
= (Widget
)GetMainWidget();
734 XtAddGrab(wMain
, TRUE
, FALSE
);
736 m_winCaptured
= TRUE
;
739 void wxWindow::DoReleaseMouse()
741 g_captureWindow
= NULL
;
742 if ( !m_winCaptured
)
745 Widget wMain
= (Widget
)GetMainWidget();
749 m_winCaptured
= FALSE
;
752 bool wxWindow::SetFont(const wxFont
& font
)
754 if ( !wxWindowBase::SetFont(font
) )
765 bool wxWindow::SetCursor(const wxCursor
& cursor
)
767 if ( !wxWindowBase::SetCursor(cursor
) )
773 // wxASSERT_MSG( m_cursor.Ok(),
774 // wxT("cursor must be valid after call to the base version"));
775 wxCursor
* cursor2
= NULL
;
777 cursor2
= & m_cursor
;
779 cursor2
= wxSTANDARD_CURSOR
;
781 WXDisplay
*dpy
= GetXDisplay();
782 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
784 Widget w
= (Widget
) GetMainWidget();
785 Window win
= XtWindow(w
);
786 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
791 // Coordinates relative to the window
792 void wxWindow::WarpPointer (int x
, int y
)
794 Widget wClient
= (Widget
)GetClientWidget();
796 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
799 // ---------------------------------------------------------------------------
801 // ---------------------------------------------------------------------------
803 int wxWindow::GetScrollPos(int orient
) const
805 if (orient
== wxHORIZONTAL
)
811 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
815 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
823 // This now returns the whole range, not just the number of positions that we
825 int wxWindow::GetScrollRange(int orient
) const
827 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
828 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
832 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
836 int wxWindow::GetScrollThumb(int orient
) const
838 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
839 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
842 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
846 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
848 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
852 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
855 SetInternalScrollPos((wxOrientation
)orient
, pos
);
858 // New function that will replace some of the above.
859 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
860 int range
, bool WXUNUSED(refresh
))
863 GetSize(& oldW
, & oldH
);
867 if (thumbVisible
== 0)
870 if (thumbVisible
> range
)
871 thumbVisible
= range
;
873 // Save the old state to see if it changed
874 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
876 if (orient
== wxHORIZONTAL
)
878 if (thumbVisible
== range
)
881 DestroyScrollbar(wxHORIZONTAL
);
886 CreateScrollbar(wxHORIZONTAL
);
889 if (orient
== wxVERTICAL
)
891 if (thumbVisible
== range
)
894 DestroyScrollbar(wxVERTICAL
);
899 CreateScrollbar(wxVERTICAL
);
902 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
904 if (oldScrollBar
!= newScrollBar
)
906 // This is important! Without it, scrollbars misbehave badly.
907 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
908 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
909 XtRealizeWidget((Widget
) m_scrolledWindow
);
910 XtManageChild((Widget
) m_scrolledWindow
);
915 XtVaSetValues((Widget
) newScrollBar
,
919 XmNsliderSize
, thumbVisible
,
923 SetInternalScrollPos((wxOrientation
)orient
, pos
);
926 GetSize(& newW
, & newH
);
928 // Adjusting scrollbars can resize the canvas accidentally
929 if (newW
!= oldW
|| newH
!= oldH
)
930 SetSize(-1, -1, oldW
, oldH
);
933 // Does a physical scroll
934 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
939 // Use specified rectangle
940 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
944 // Use whole client area
946 GetClientSize(& w
, & h
);
949 int x1
= (dx
>= 0) ? x
: x
- dx
;
950 int y1
= (dy
>= 0) ? y
: y
- dy
;
951 int w1
= w
- abs(dx
);
952 int h1
= h
- abs(dy
);
953 int x2
= (dx
>= 0) ? x
+ dx
: x
;
954 int y2
= (dy
>= 0) ? y
+ dy
: y
;
958 dc
.SetLogicalFunction (wxCOPY
);
960 Widget widget
= (Widget
) GetMainWidget();
961 Window window
= XtWindow(widget
);
962 Display
* display
= XtDisplay(widget
);
964 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
965 x1
, y1
, w1
, h1
, x2
, y2
);
967 dc
.SetAutoSetting(TRUE
);
968 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
969 dc
.SetBrush(brush
); // FIXME: needed?
971 wxWindowList::Node
*cnode
= m_children
.GetFirst();
974 wxWindow
*child
= cnode
->GetData();
977 child
->GetSize( &sx
, &sy
);
978 wxPoint
pos( child
->GetPosition() );
979 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
980 cnode
= cnode
->GetNext();
983 // We'll add rectangles to the list of update rectangles according to which
984 // bits we've exposed.
989 wxRect
*rect
= new wxRect
;
995 XFillRectangle(display
, window
,
996 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1000 rect
->width
= rect
->width
;
1001 rect
->height
= rect
->height
;
1003 updateRects
.Append((wxObject
*) rect
);
1007 wxRect
*rect
= new wxRect
;
1009 rect
->x
= x
+ w
+ dx
;
1014 XFillRectangle(display
, window
,
1015 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1020 rect
->width
= rect
->width
;
1021 rect
->height
= rect
->height
;
1023 updateRects
.Append((wxObject
*) rect
);
1027 wxRect
*rect
= new wxRect
;
1034 XFillRectangle(display
, window
,
1035 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1039 rect
->width
= rect
->width
;
1040 rect
->height
= rect
->height
;
1042 updateRects
.Append((wxObject
*) rect
);
1046 wxRect
*rect
= new wxRect
;
1049 rect
->y
= y
+ h
+ dy
;
1053 XFillRectangle(display
, window
,
1054 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1058 rect
->width
= rect
->width
;
1059 rect
->height
= rect
->height
;
1061 updateRects
.Append((wxObject
*) rect
);
1063 dc
.SetBrush(wxNullBrush
);
1065 // Now send expose events
1067 wxList::Node
* node
= updateRects
.GetFirst();
1070 wxRect
* rect
= (wxRect
*) node
->GetData();
1073 event
.type
= Expose
;
1074 event
.display
= display
;
1075 event
.send_event
= True
;
1076 event
.window
= window
;
1080 event
.width
= rect
->width
;
1081 event
.height
= rect
->height
;
1085 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1087 node
= node
->GetNext();
1091 // Delete the update rects
1092 node
= updateRects
.GetFirst();
1095 wxRect
* rect
= (wxRect
*) node
->GetData();
1097 node
= node
->GetNext();
1100 XmUpdateDisplay((Widget
) GetMainWidget());
1103 // ---------------------------------------------------------------------------
1105 // ---------------------------------------------------------------------------
1107 #if wxUSE_DRAG_AND_DROP
1109 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1116 // Old style file-manager drag&drop
1117 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1122 // ----------------------------------------------------------------------------
1124 // ----------------------------------------------------------------------------
1128 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1133 #endif // wxUSE_TOOLTIPS
1135 // ----------------------------------------------------------------------------
1137 // ----------------------------------------------------------------------------
1141 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1143 Widget widget
= (Widget
) GetMainWidget();
1145 /* The menuId field seems to be usused, so we'll use it to
1146 indicate whether a menu is popped up or not:
1147 0: Not currently created as a popup
1148 -1: Created as a popup, but not active
1152 if (menu
->GetParent() && (menu
->GetId() != -1))
1155 if (menu
->GetMainWidget())
1157 menu
->DestroyMenu(TRUE
);
1160 menu
->SetId(1); /* Mark as popped-up */
1161 menu
->CreateMenu(NULL
, widget
, menu
);
1162 menu
->SetInvokingWindow(this);
1166 // menu->SetParent(parent);
1167 // parent->children->Append(menu); // Store menu for later deletion
1169 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1177 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1179 wxCanvas *canvas = (wxCanvas *) this;
1180 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1181 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1185 Display
*display
= XtDisplay (widget
);
1186 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1187 Window thisWindow
= XtWindow (widget
);
1189 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1190 &rootX
, &rootY
, &childWindow
);
1192 XButtonPressedEvent event
;
1193 event
.type
= ButtonPress
;
1199 event
.x_root
= rootX
;
1200 event
.y_root
= rootY
;
1202 XmMenuPosition (menuWidget
, &event
);
1203 XtManageChild (menuWidget
);
1205 // The ID of a pop-up menu is 1 when active, and is set to 0 by the
1206 // idle-time destroy routine.
1207 // Waiting until this ID changes causes this function to block until
1208 // the menu has been dismissed and the widgets cleaned up.
1209 // In other words, once this routine returns, it is safe to delete
1211 // Ian Brown <ian.brown@printsoft.de>
1213 wxEventLoop evtLoop
;
1215 while (menu
->GetId() == 1)
1217 wxDoEventLoopIteration( evtLoop
);
1225 // ---------------------------------------------------------------------------
1226 // moving and resizing
1227 // ---------------------------------------------------------------------------
1229 bool wxWindow::PreResize()
1235 void wxWindow::DoGetSize(int *x
, int *y
) const
1237 Widget widget
= (Widget
)( !m_drawingArea
? GetTopWidget() :
1238 ( m_borderWidget
? m_borderWidget
:
1239 m_scrolledWindow
? m_scrolledWindow
:
1243 XtVaGetValues( widget
,
1251 void wxWindow::DoGetPosition(int *x
, int *y
) const
1253 Widget widget
= (Widget
)
1255 ( m_borderWidget
? m_borderWidget
: m_scrolledWindow
) :
1259 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1261 // We may be faking the client origin. So a window that's really at (0, 30)
1262 // may appear (to wxWin apps) to be at (0, 0).
1265 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1274 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1276 Widget widget
= (Widget
) GetClientWidget();
1277 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1278 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1279 Window thisWindow
= XtWindow(widget
);
1284 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1287 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1289 Widget widget
= (Widget
) GetClientWidget();
1290 Display
*display
= XtDisplay(widget
);
1291 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1292 Window thisWindow
= XtWindow(widget
);
1297 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1301 // Get size *available for subwindows* i.e. excluding menu bar etc.
1302 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1304 Widget widget
= (Widget
) GetClientWidget();
1306 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1307 if(x
) *x
= xx
; if(y
) *y
= yy
;
1310 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1312 DoSetSizeIntr(x
, y
, width
, height
, sizeFlags
, FALSE
);
1315 void wxWindow::DoSetSizeIntr(int x
, int y
, int width
, int height
,
1316 int sizeFlags
, bool fromCtor
)
1318 // A bit of optimization to help sort out the flickers.
1319 int oldX
= -1, oldY
= -1, oldW
= -1, oldH
= -1;
1322 GetSize(& oldW
, & oldH
);
1323 GetPosition(& oldX
, & oldY
);
1326 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1334 wxSize
size(-1, -1);
1337 if ( ( sizeFlags
& wxSIZE_AUTO_WIDTH
) && !fromCtor
)
1339 size
= DoGetBestSize();
1350 if( ( sizeFlags
& wxSIZE_AUTO_HEIGHT
) && !fromCtor
)
1352 if( size
.x
== -1 ) size
= DoGetBestSize();
1361 if ( x
!= oldX
|| y
!= oldY
|| width
!= oldW
|| height
!= oldH
1362 || !wxNoOptimize::CanOptimize() )
1368 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1371 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1375 flags
|= wxMOVE_WIDTH
;
1378 flags
|= wxMOVE_HEIGHT
;
1380 int xx
= x
; int yy
= y
;
1381 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1383 DoMoveWindow( xx
, yy
, width
, height
);
1385 DoMoveWindowIntr( xx
, yy
, width
, height
, flags
);
1390 Widget widget
= (Widget
) GetTopWidget();
1394 bool managed
= XtIsManaged( widget
);
1396 XtUnmanageChild(widget
);
1400 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1402 DoMoveWindow(xx
, yy
, width
, height
);
1405 XtManageChild(widget
);
1409 void wxWindow::DoSetClientSize(int width
, int height
)
1413 Widget drawingArea
= (Widget
) m_drawingArea
;
1415 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1418 XtVaSetValues(drawingArea
, XmNwidth
, width
, NULL
);
1420 XtVaSetValues(drawingArea
, XmNheight
, height
, NULL
);
1422 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1426 Widget widget
= (Widget
) GetTopWidget();
1429 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1431 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1434 // For implementation purposes - sometimes decorations make the client area
1436 wxPoint
wxWindow::GetClientAreaOrigin() const
1438 return wxPoint(0, 0);
1441 void wxWindow::DoMoveWindowIntr(int xx
, int yy
, int w
, int h
,
1446 Widget drawingArea
= (Widget
) m_drawingArea
;
1447 Widget borderOrScrolled
= m_borderWidget
?
1448 (Widget
) m_borderWidget
:
1449 (Widget
) m_scrolledWindow
;
1451 bool managed
= XtIsManaged(borderOrScrolled
);
1453 XtUnmanageChild (borderOrScrolled
);
1454 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1456 if (flags
& wxMOVE_X
)
1457 XtVaSetValues (borderOrScrolled
,
1460 if (flags
& wxMOVE_Y
)
1461 XtVaSetValues (borderOrScrolled
,
1465 if (flags
& wxMOVE_WIDTH
)
1469 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
1470 short thick
, margin
;
1471 XtVaGetValues ((Widget
) m_borderWidget
,
1472 XmNshadowThickness
, &thick
,
1473 XmNmarginWidth
, &margin
,
1475 w
-= 2 * (thick
+ margin
);
1478 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
1481 if (flags
& wxMOVE_HEIGHT
)
1485 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
1486 short thick
, margin
;
1487 XtVaGetValues ((Widget
) m_borderWidget
,
1488 XmNshadowThickness
, &thick
,
1489 XmNmarginHeight
, &margin
,
1491 h
-= 2 * (thick
+ margin
);
1494 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
1498 XtManageChild (borderOrScrolled
);
1499 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1506 XtVaSetValues((Widget
)GetTopWidget(),
1515 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1517 DoMoveWindowIntr (x
, y
, width
, height
,
1518 wxMOVE_X
|wxMOVE_Y
|wxMOVE_WIDTH
|wxMOVE_HEIGHT
);
1521 // ---------------------------------------------------------------------------
1523 // ---------------------------------------------------------------------------
1525 int wxWindow::GetCharHeight() const
1527 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1529 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1531 int direction
, ascent
, descent
;
1532 XCharStruct overall
;
1533 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1534 &descent
, &overall
);
1536 // return (overall.ascent + overall.descent);
1537 return (ascent
+ descent
);
1540 int wxWindow::GetCharWidth() const
1542 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1544 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1546 int direction
, ascent
, descent
;
1547 XCharStruct overall
;
1548 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1549 &descent
, &overall
);
1551 return overall
.width
;
1554 void wxWindow::GetTextExtent(const wxString
& string
,
1556 int *descent
, int *externalLeading
,
1557 const wxFont
*theFont
) const
1559 wxFont
*fontToUse
= (wxFont
*)theFont
;
1561 fontToUse
= (wxFont
*) & m_font
;
1563 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1565 WXFontStructPtr pFontStruct
= fontToUse
->GetFontStruct(1.0, GetXDisplay());
1567 int direction
, ascent
, descent2
;
1568 XCharStruct overall
;
1569 int slen
= string
.Len();
1573 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1574 &ascent
, &descent2
, &overall
);
1577 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1578 &direction
, &ascent
, &descent2
, &overall
);
1581 *x
= (overall
.width
);
1583 *y
= (ascent
+ descent2
);
1585 *descent
= descent2
;
1586 if (externalLeading
)
1587 *externalLeading
= 0;
1591 // ----------------------------------------------------------------------------
1593 // ----------------------------------------------------------------------------
1595 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1597 m_needsRefresh
= TRUE
;
1598 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1599 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1601 XExposeEvent dummyEvent
;
1603 GetSize(&width
, &height
);
1605 dummyEvent
.type
= Expose
;
1606 dummyEvent
.display
= display
;
1607 dummyEvent
.send_event
= True
;
1608 dummyEvent
.window
= thisWindow
;
1611 dummyEvent
.x
= rect
->x
;
1612 dummyEvent
.y
= rect
->y
;
1613 dummyEvent
.width
= rect
->width
;
1614 dummyEvent
.height
= rect
->height
;
1620 dummyEvent
.width
= width
;
1621 dummyEvent
.height
= height
;
1623 dummyEvent
.count
= 0;
1627 wxClientDC
dc(this);
1628 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1629 dc
.SetBackground(backgroundBrush
);
1636 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1639 void wxWindow::Clear()
1641 wxClientDC
dc(this);
1642 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1643 dc
.SetBackground(brush
);
1647 void wxWindow::ClearUpdateRects()
1649 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1652 wxRect
* rect
= node
->GetData();
1654 node
= node
->GetNext();
1657 m_updateRects
.Clear();
1660 void wxWindow::DoPaint()
1662 //TODO : make a temporary gc so we can do the XCopyArea below
1663 if (m_backingPixmap
&& !m_needsRefresh
)
1667 GC tempGC
= (GC
) dc
.GetBackingGC();
1669 Widget widget
= (Widget
) GetMainWidget();
1674 // We have to test whether it's a wxScrolledWindow (hack!) because
1675 // otherwise we don't know how many pixels have been scrolled. We might
1676 // solve this in the future by defining virtual wxWindow functions to get
1677 // the scroll position in pixels. Or, each kind of scrolled window has to
1678 // implement backing stores itself, using generic wxWindows code.
1679 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1680 if ( scrolledWindow
)
1683 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1689 // TODO: This could be optimized further by only copying the areas in the
1690 // current update region.
1692 // Only blit the part visible in the client area. The backing pixmap
1693 // always starts at 0, 0 but we may be looking at only a portion of it.
1694 wxSize clientArea
= GetClientSize();
1695 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1696 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1698 // Copy whichever is samller, the amount of pixmap we have to copy,
1699 // or the size of the client area.
1700 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1701 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1703 // Make sure we're not negative
1704 toBlitX
= wxMax(0, toBlitX
);
1705 toBlitY
= wxMax(0, toBlitY
);
1710 (Pixmap
) m_backingPixmap
,
1713 scrollPosX
, scrollPosY
, // Start at the scroll position
1714 toBlitX
, toBlitY
, // How much of the pixmap to copy
1720 wxWindowDC
dc(this);
1721 // Set an erase event first
1722 wxEraseEvent
eraseEvent(GetId(), &dc
);
1723 eraseEvent
.SetEventObject(this);
1724 GetEventHandler()->ProcessEvent(eraseEvent
);
1726 wxPaintEvent
event(GetId());
1727 event
.SetEventObject(this);
1728 GetEventHandler()->ProcessEvent(event
);
1730 m_needsRefresh
= FALSE
;
1734 // ----------------------------------------------------------------------------
1736 // ----------------------------------------------------------------------------
1738 // Responds to colour changes: passes event on to children.
1739 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1741 wxWindowList::Node
*node
= GetChildren().GetFirst();
1744 // Only propagate to non-top-level windows
1745 wxWindow
*win
= node
->GetData();
1746 if ( win
->GetParent() )
1748 wxSysColourChangedEvent event2
;
1749 event
.m_eventObject
= win
;
1750 win
->GetEventHandler()->ProcessEvent(event2
);
1753 node
= node
->GetNext();
1757 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1759 // This calls the UI-update mechanism (querying windows for
1760 // menu/toolbar/control state information)
1764 // ----------------------------------------------------------------------------
1766 // ----------------------------------------------------------------------------
1768 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1771 if (!m_acceleratorTable
.Ok())
1774 int count
= m_acceleratorTable
.GetCount();
1775 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1777 for (i
= 0; i
< count
; i
++)
1779 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1780 if (entry
->MatchesEvent(event
))
1782 // Bingo, we have a match. Now find a control that matches the
1783 // entry command id.
1785 // Need to go up to the top of the window hierarchy, since it might
1786 // be e.g. a menu item
1787 wxWindow
* parent
= this;
1788 while ( parent
&& !parent
->IsTopLevel() )
1789 parent
= parent
->GetParent();
1794 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1798 // Try for a menu command
1799 if (frame
->GetMenuBar())
1801 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1804 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1805 commandEvent
.SetEventObject(frame
);
1807 // If ProcessEvent returns TRUE (it was handled), then
1808 // the calling code will skip the event handling.
1809 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1815 // Find a child matching the command id
1816 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1822 // Now we process those kinds of windows that we can.
1823 // For now, only buttons.
1824 if ( wxDynamicCast(child
, wxButton
) )
1826 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1827 commandEvent
.SetEventObject(child
);
1828 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1836 // We didn't match the key event against an accelerator.
1840 // ============================================================================
1841 // Motif-specific stuff from here on
1842 // ============================================================================
1844 // ----------------------------------------------------------------------------
1845 // function which maintain the global hash table mapping Widgets to wxWindows
1846 // ----------------------------------------------------------------------------
1848 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1850 wxWindow
*oldItem
= NULL
;
1851 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1853 wxLogDebug("Widget table clash: new widget is %ld, %s",
1854 (long)w
, win
->GetClassInfo()->GetClassName());
1858 wxWidgetHashTable
->Put((long) w
, win
);
1860 wxLogTrace("widget", "Widget 0x%p <-> window %p (%s)",
1861 (WXWidget
)w
, win
, win
->GetClassInfo()->GetClassName());
1866 wxWindow
*wxGetWindowFromTable(Widget w
)
1868 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1871 void wxDeleteWindowFromTable(Widget w
)
1873 wxLogTrace("widget", "Widget 0x%p", (WXWidget
)w
);
1875 wxWidgetHashTable
->Delete((long)w
);
1878 // ----------------------------------------------------------------------------
1879 // add/remove window from the table
1880 // ----------------------------------------------------------------------------
1882 // Add to hash table, add event handler
1883 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1884 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1886 wxAddWindowToTable((Widget
) mainWidget
, this);
1887 if (CanAddEventHandler())
1889 XtAddEventHandler((Widget
) mainWidget
,
1890 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1892 wxPanelItemEventHandler
,
1899 XtOverrideTranslations ((Widget
) mainWidget
,
1900 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1901 XtFree ((char *) ptr
);
1904 // Some widgets have a parent form widget, e.g. wxRadioBox
1907 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1911 XtOverrideTranslations ((Widget
) formWidget
,
1912 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1913 XtFree ((char *) ptr
);
1920 SetSize (x
, y
, width
, height
);
1925 // Remove event handler, remove from hash table
1926 bool wxWindow::DetachWidget(WXWidget widget
)
1928 if (CanAddEventHandler())
1930 XtRemoveEventHandler((Widget
) widget
,
1931 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1933 wxPanelItemEventHandler
,
1937 wxDeleteWindowFromTable((Widget
) widget
);
1941 // ----------------------------------------------------------------------------
1942 // Motif-specific accessors
1943 // ----------------------------------------------------------------------------
1945 // Get the underlying X window
1946 WXWindow
wxWindow::GetXWindow() const
1948 Widget wMain
= (Widget
)GetMainWidget();
1950 return (WXWindow
) XtWindow(wMain
);
1952 return (WXWindow
) 0;
1955 // Get the underlying X display
1956 WXDisplay
*wxWindow::GetXDisplay() const
1958 Widget wMain
= (Widget
)GetMainWidget();
1960 return (WXDisplay
*) XtDisplay(wMain
);
1962 return (WXDisplay
*) NULL
;
1965 WXWidget
wxWindow::GetMainWidget() const
1968 return m_drawingArea
;
1970 return m_mainWidget
;
1973 WXWidget
wxWindow::GetClientWidget() const
1975 if (m_drawingArea
!= (WXWidget
) 0)
1976 return m_drawingArea
;
1978 return GetMainWidget();
1981 WXWidget
wxWindow::GetTopWidget() const
1983 return GetMainWidget();
1986 WXWidget
wxWindow::GetLabelWidget() const
1988 return GetMainWidget();
1991 // ----------------------------------------------------------------------------
1993 // ----------------------------------------------------------------------------
1995 // All widgets should have this as their resize proc.
1996 // OnSize sent to wxWindow via client data.
1997 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
),
1998 String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
2000 wxWindow
*win
= wxGetWindowFromTable(w
);
2004 if (win
->PreResize())
2007 win
->GetSize(&width
, &height
);
2008 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2009 sizeEvent
.SetEventObject(win
);
2010 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2014 static void wxCanvasRepaintProc(Widget drawingArea
,
2015 XtPointer clientData
,
2016 XmDrawingAreaCallbackStruct
* cbs
)
2018 if (!wxGetWindowFromTable(drawingArea
))
2021 XEvent
* event
= cbs
->event
;
2022 wxWindow
* win
= (wxWindow
*) clientData
;
2024 switch (event
->type
)
2028 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2029 event
->xexpose
.width
, event
->xexpose
.height
);
2031 if (event
-> xexpose
.count
== 0)
2034 win
->ClearUpdateRects();
2041 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2042 static void wxCanvasEnterLeave(Widget drawingArea
,
2043 XtPointer
WXUNUSED(clientData
),
2044 XCrossingEvent
* event
)
2046 XmDrawingAreaCallbackStruct cbs
;
2049 ((XCrossingEvent
&) ev
) = *event
;
2051 cbs
.reason
= XmCR_INPUT
;
2054 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
2057 // Fix to make it work under Motif 1.0 (!)
2058 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
),
2059 XButtonEvent
*WXUNUSED(event
))
2061 #if XmVersion <= 1000
2062 XmDrawingAreaCallbackStruct cbs
;
2065 ev
= *((XEvent
*) event
);
2066 cbs
.reason
= XmCR_INPUT
;
2069 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2070 #endif // XmVersion <= 1000
2073 static void wxCanvasInputEvent(Widget drawingArea
,
2074 XtPointer
WXUNUSED(data
),
2075 XmDrawingAreaCallbackStruct
* cbs
)
2077 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
2083 if (cbs
->reason
!= XmCR_INPUT
)
2086 local_event
= *(cbs
->event
); // We must keep a copy!
2088 switch (local_event
.xany
.type
)
2096 // FIXME: most of this mouse event code is more or less
2097 // duplicated in wxTranslateMouseEvent
2099 wxEventType eventType
= wxEVT_NULL
;
2101 if (local_event
.xany
.type
== EnterNotify
)
2103 //if (local_event.xcrossing.mode!=NotifyNormal)
2104 // return ; // Ignore grab events
2105 eventType
= wxEVT_ENTER_WINDOW
;
2106 // canvas->GetEventHandler()->OnSetFocus();
2108 else if (local_event
.xany
.type
== LeaveNotify
)
2110 //if (local_event.xcrossingr.mode!=NotifyNormal)
2111 // return ; // Ignore grab events
2112 eventType
= wxEVT_LEAVE_WINDOW
;
2113 // canvas->GetEventHandler()->OnKillFocus();
2115 else if (local_event
.xany
.type
== MotionNotify
)
2117 eventType
= wxEVT_MOTION
;
2120 else if (local_event
.xany
.type
== ButtonPress
)
2122 if (local_event
.xbutton
.button
== Button1
)
2124 eventType
= wxEVT_LEFT_DOWN
;
2125 canvas
->SetButton1(TRUE
);
2127 else if (local_event
.xbutton
.button
== Button2
)
2129 eventType
= wxEVT_MIDDLE_DOWN
;
2130 canvas
->SetButton2(TRUE
);
2132 else if (local_event
.xbutton
.button
== Button3
)
2134 eventType
= wxEVT_RIGHT_DOWN
;
2135 canvas
->SetButton3(TRUE
);
2138 else if (local_event
.xany
.type
== ButtonRelease
)
2140 if (local_event
.xbutton
.button
== Button1
)
2142 eventType
= wxEVT_LEFT_UP
;
2143 canvas
->SetButton1(FALSE
);
2145 else if (local_event
.xbutton
.button
== Button2
)
2147 eventType
= wxEVT_MIDDLE_UP
;
2148 canvas
->SetButton2(FALSE
);
2150 else if (local_event
.xbutton
.button
== Button3
)
2152 eventType
= wxEVT_RIGHT_UP
;
2153 canvas
->SetButton3(FALSE
);
2157 wxMouseEvent
wxevent (eventType
);
2159 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2160 || (event_left_is_down (&local_event
)
2161 && (eventType
!= wxEVT_LEFT_UP
)));
2162 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2163 || (event_middle_is_down (&local_event
)
2164 && (eventType
!= wxEVT_MIDDLE_UP
)));
2165 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2166 || (event_right_is_down (&local_event
)
2167 && (eventType
!= wxEVT_RIGHT_UP
)));
2169 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2170 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2171 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2172 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2173 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2175 if ( eventType
== wxEVT_MOTION
)
2177 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2180 Display
*dpy
= XtDisplay (drawingArea
);
2182 XQueryPointer (dpy
, XtWindow (drawingArea
),
2184 &local_event
.xmotion
.x_root
,
2185 &local_event
.xmotion
.y_root
,
2186 &local_event
.xmotion
.x
,
2187 &local_event
.xmotion
.y
,
2188 &local_event
.xmotion
.state
);
2195 // Now check if we need to translate this event into a double click
2196 if (TRUE
) // canvas->doubleClickAllowed)
2198 if (wxevent
.ButtonDown())
2200 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2202 // get button and time-stamp
2204 if (wxevent
.LeftDown())
2206 else if (wxevent
.MiddleDown())
2208 else if (wxevent
.RightDown())
2210 long ts
= wxevent
.GetTimestamp();
2212 // check, if single or double click
2213 int buttonLast
= canvas
->GetLastClickedButton();
2214 long lastTS
= canvas
->GetLastClickTime();
2215 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2218 canvas
->SetLastClick(0, ts
);
2220 wxEventType typeDouble
;
2221 if ( eventType
== wxEVT_LEFT_DOWN
)
2222 typeDouble
= wxEVT_LEFT_DCLICK
;
2223 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2224 typeDouble
= wxEVT_MIDDLE_DCLICK
;
2225 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2226 typeDouble
= wxEVT_RIGHT_DCLICK
;
2228 typeDouble
= wxEVT_NULL
;
2230 if ( typeDouble
!= wxEVT_NULL
)
2232 wxevent
.SetEventType(typeDouble
);
2237 // not fast enough or different button
2238 canvas
->SetLastClick(button
, ts
);
2243 wxevent
.SetId(canvas
->GetId());
2244 wxevent
.SetEventObject(canvas
);
2245 wxevent
.m_x
= local_event
.xbutton
.x
;
2246 wxevent
.m_y
= local_event
.xbutton
.y
;
2247 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2249 if (eventType
== wxEVT_ENTER_WINDOW
||
2250 eventType
== wxEVT_LEAVE_WINDOW
||
2251 eventType
== wxEVT_MOTION
2259 wxKeyEvent
event (wxEVT_CHAR
);
2260 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, &local_event
))
2262 // Implement wxFrame::OnCharHook by checking ancestor.
2263 wxWindow
*parent
= canvas
;
2264 while (parent
&& !parent
->IsTopLevel())
2265 parent
= parent
->GetParent();
2269 event
.SetEventType(wxEVT_CHAR_HOOK
);
2270 if (parent
->GetEventHandler()->ProcessEvent(event
))
2274 // For simplicity, OnKeyDown is the same as OnChar
2275 // TODO: filter modifier key presses from OnChar
2276 event
.SetEventType(wxEVT_KEY_DOWN
);
2278 // Only process OnChar if OnKeyDown didn't swallow it
2279 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2281 event
.SetEventType(wxEVT_CHAR
);
2282 canvas
->GetEventHandler()->ProcessEvent (event
);
2289 wxKeyEvent
event (wxEVT_KEY_UP
);
2290 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, &local_event
))
2292 canvas
->GetEventHandler()->ProcessEvent (event
);
2298 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2300 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2301 event
.SetEventObject(canvas
);
2302 canvas
->GetEventHandler()->ProcessEvent(event
);
2308 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2310 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2311 event
.SetEventObject(canvas
);
2312 canvas
->GetEventHandler()->ProcessEvent(event
);
2321 static void wxPanelItemEventHandler(Widget wid
,
2322 XtPointer
WXUNUSED(client_data
),
2324 Boolean
*continueToDispatch
)
2326 // Widget can be a label or the actual widget.
2328 wxWindow
*window
= wxGetWindowFromTable(wid
);
2331 wxMouseEvent
wxevent(0);
2332 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2334 window
->GetEventHandler()->ProcessEvent(wxevent
);
2338 // TODO: probably the key to allowing default behaviour to happen. Say we
2339 // set a m_doDefault flag to FALSE at the start of this function. Then in
2340 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2341 // TRUE, indicating that default processing can happen. Thus, behaviour can
2342 // appear to be overridden just by adding an event handler and not calling
2343 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2344 // way of handling drawing area events, to simplify things.
2345 *continueToDispatch
= True
;
2348 static void wxScrollBarCallback(Widget scrollbar
,
2349 XtPointer clientData
,
2350 XmScrollBarCallbackStruct
*cbs
)
2352 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2353 int orientation
= (int) clientData
;
2355 wxEventType eventType
= wxEVT_NULL
;
2356 switch (cbs
->reason
)
2358 case XmCR_INCREMENT
:
2360 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2363 case XmCR_DECREMENT
:
2365 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2370 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2373 case XmCR_VALUE_CHANGED
:
2375 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2378 case XmCR_PAGE_INCREMENT
:
2380 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2383 case XmCR_PAGE_DECREMENT
:
2385 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2390 eventType
= wxEVT_SCROLLWIN_TOP
;
2393 case XmCR_TO_BOTTOM
:
2395 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2400 // Should never get here
2401 wxFAIL_MSG("Unknown scroll event.");
2406 wxScrollWinEvent
event(eventType
,
2408 ((orientation
== XmHORIZONTAL
) ?
2409 wxHORIZONTAL
: wxVERTICAL
));
2410 event
.SetEventObject( win
);
2411 win
->GetEventHandler()->ProcessEvent(event
);
2414 // For repainting arbitrary windows
2415 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2420 wxWindow
* win
= wxGetWindowFromTable(w
);
2424 switch(event
-> type
)
2428 window
= (Window
) win
-> GetXWindow();
2429 display
= (Display
*) win
-> GetXDisplay();
2431 if (event
-> xexpose
.count
== 0)
2435 win
->ClearUpdateRects();
2439 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2440 event
->xexpose
.width
, event
->xexpose
.height
);
2448 // ----------------------------------------------------------------------------
2449 // TranslateXXXEvent() functions
2450 // ----------------------------------------------------------------------------
2452 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2454 switch (xevent
->xany
.type
)
2456 case EnterNotify
: // never received here - yes ? MB
2457 case LeaveNotify
: // never received here - yes ? MB
2462 wxEventType eventType
= wxEVT_NULL
;
2464 // FIXME: this is never true I think - MB
2466 if (xevent
->xany
.type
== LeaveNotify
)
2468 win
->SetButton1(FALSE
);
2469 win
->SetButton2(FALSE
);
2470 win
->SetButton3(FALSE
);
2473 else if (xevent
->xany
.type
== MotionNotify
)
2475 eventType
= wxEVT_MOTION
;
2477 else if (xevent
->xany
.type
== ButtonPress
)
2479 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2481 if (xevent
->xbutton
.button
== Button1
)
2483 eventType
= wxEVT_LEFT_DOWN
;
2484 win
->SetButton1(TRUE
);
2487 else if (xevent
->xbutton
.button
== Button2
)
2489 eventType
= wxEVT_MIDDLE_DOWN
;
2490 win
->SetButton2(TRUE
);
2493 else if (xevent
->xbutton
.button
== Button3
)
2495 eventType
= wxEVT_RIGHT_DOWN
;
2496 win
->SetButton3(TRUE
);
2500 // check for a double click
2502 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2503 long ts
= wxevent
.GetTimestamp();
2505 int buttonLast
= win
->GetLastClickedButton();
2506 long lastTS
= win
->GetLastClickTime();
2507 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2510 win
->SetLastClick(0, ts
);
2511 if ( eventType
== wxEVT_LEFT_DOWN
)
2512 eventType
= wxEVT_LEFT_DCLICK
;
2513 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2514 eventType
= wxEVT_MIDDLE_DCLICK
;
2515 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2516 eventType
= wxEVT_RIGHT_DCLICK
;
2520 // not fast enough or different button
2521 win
->SetLastClick(button
, ts
);
2524 else if (xevent
->xany
.type
== ButtonRelease
)
2526 if (xevent
->xbutton
.button
== Button1
)
2528 eventType
= wxEVT_LEFT_UP
;
2529 win
->SetButton1(FALSE
);
2531 else if (xevent
->xbutton
.button
== Button2
)
2533 eventType
= wxEVT_MIDDLE_UP
;
2534 win
->SetButton2(FALSE
);
2536 else if (xevent
->xbutton
.button
== Button3
)
2538 eventType
= wxEVT_RIGHT_UP
;
2539 win
->SetButton3(FALSE
);
2548 wxevent
.SetEventType(eventType
);
2551 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2554 win
->GetPosition(&x2
, &y2
);
2556 // The button x/y must be translated to wxWindows
2557 // window space - the widget might be a label or button,
2561 if (widget
!= (Widget
)win
->GetMainWidget())
2567 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2568 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2570 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2571 || (event_left_is_down (xevent
)
2572 && (eventType
!= wxEVT_LEFT_UP
)));
2573 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2574 || (event_middle_is_down (xevent
)
2575 && (eventType
!= wxEVT_MIDDLE_UP
)));
2576 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2577 || (event_right_is_down (xevent
)
2578 && (eventType
!= wxEVT_RIGHT_UP
)));
2580 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2581 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2582 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
2583 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
2585 wxevent
.SetId(win
->GetId());
2586 wxevent
.SetEventObject(win
);
2594 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
,
2595 Widget
WXUNUSED(widget
), XEvent
*xevent
)
2597 switch (xevent
->xany
.type
)
2605 (void) XLookupString((XKeyEvent
*)xevent
, buf
, 20, &keySym
, NULL
);
2606 int id
= wxCharCodeXToWX (keySym
);
2607 // id may be WXK_xxx code - these are outside ASCII range, so we
2608 // can't just use toupper() on id
2609 if (id
>= 'a' && id
<= 'z')
2612 if (xevent
->xkey
.state
& ShiftMask
)
2613 wxevent
.m_shiftDown
= TRUE
;
2614 if (xevent
->xkey
.state
& ControlMask
)
2615 wxevent
.m_controlDown
= TRUE
;
2616 if (xevent
->xkey
.state
& Mod3Mask
)
2617 wxevent
.m_altDown
= TRUE
;
2618 if (xevent
->xkey
.state
& Mod1Mask
)
2619 wxevent
.m_metaDown
= TRUE
;
2620 wxevent
.SetEventObject(win
);
2621 wxevent
.m_keyCode
= id
;
2622 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2624 wxevent
.m_x
= xevent
->xbutton
.x
;
2625 wxevent
.m_y
= xevent
->xbutton
.y
;
2639 // ----------------------------------------------------------------------------
2641 // ----------------------------------------------------------------------------
2643 #define YAllocColor XAllocColor
2644 XColor g_itemColors
[5];
2645 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2648 static XmColorProc colorProc
;
2650 result
= wxNO_COLORS
;
2654 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2655 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2656 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2657 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2658 if (colorProc
== (XmColorProc
) NULL
)
2660 // Get a ptr to the actual function
2661 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2662 // And set it back to motif.
2663 XmSetColorCalculation (colorProc
);
2665 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2666 &g_itemColors
[wxFORE_INDEX
],
2667 &g_itemColors
[wxSELE_INDEX
],
2668 &g_itemColors
[wxTOPS_INDEX
],
2669 &g_itemColors
[wxBOTS_INDEX
]);
2670 result
= wxBACK_COLORS
;
2674 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2675 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2676 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2677 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2678 if (result
== wxNO_COLORS
)
2679 result
= wxFORE_COLORS
;
2682 Display
*dpy
= display
;
2683 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2687 /* 5 Colours to allocate */
2688 for (int i
= 0; i
< 5; i
++)
2689 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2690 result
= wxNO_COLORS
;
2694 /* Only 1 colour to allocate */
2695 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2696 result
= wxNO_COLORS
;
2702 // Changes the foreground and background colours to be derived from the current
2703 // background colour. To change the foreground colour, you must call
2704 // SetForegroundColour explicitly.
2705 void wxWindow::ChangeBackgroundColour()
2707 WXWidget mainWidget
= GetMainWidget();
2709 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2712 void wxWindow::ChangeForegroundColour()
2714 WXWidget mainWidget
= GetMainWidget();
2716 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2717 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2718 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2721 // Change a widget's foreground and background colours.
2722 void wxWindow::DoChangeForegroundColour(WXWidget widget
,
2723 wxColour
& foregroundColour
)
2725 wxDoChangeForegroundColour( widget
, foregroundColour
);
2728 void wxWindow::DoChangeBackgroundColour(WXWidget widget
,
2729 wxColour
& backgroundColour
,
2730 bool changeArmColour
)
2732 wxDoChangeBackgroundColour( widget
, backgroundColour
, changeArmColour
);
2735 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2737 if ( !wxWindowBase::SetBackgroundColour(col
) )
2740 ChangeBackgroundColour();
2745 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2747 if ( !wxWindowBase::SetForegroundColour(col
) )
2750 ChangeForegroundColour();
2755 void wxWindow::ChangeFont(bool keepOriginalSize
)
2757 // Note that this causes the widget to be resized back
2758 // to its original size! We therefore have to set the size
2759 // back again. TODO: a better way in Motif?
2760 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2761 if (w
&& m_font
.Ok())
2763 int width
, height
, width1
, height1
;
2764 GetSize(& width
, & height
);
2766 wxDoChangeFont( GetLabelWidget(), m_font
);
2768 GetSize(& width1
, & height1
);
2769 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2771 SetSize(-1, -1, width
, height
);
2776 // ----------------------------------------------------------------------------
2778 // ----------------------------------------------------------------------------
2780 wxWindow
*wxGetActiveWindow()
2783 wxFAIL_MSG("Not implemented");
2788 wxWindow
*wxWindowBase::GetCapture()
2790 return (wxWindow
*)g_captureWindow
;
2794 // Find the wxWindow at the current mouse position, returning the mouse
2796 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2798 return wxFindWindowAtPoint(wxGetMousePosition());
2801 // Get the current mouse position.
2802 wxPoint
wxGetMousePosition()
2804 Display
*display
= (Display
*) wxGetDisplay();
2805 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2806 Window rootReturn
, childReturn
;
2807 int rootX
, rootY
, winX
, winY
;
2808 unsigned int maskReturn
;
2810 XQueryPointer (display
,
2814 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
2815 return wxPoint(rootX
, rootY
);
2819 // ----------------------------------------------------------------------------
2820 // wxNoOptimize: switch off size optimization
2821 // ----------------------------------------------------------------------------
2823 int wxNoOptimize::ms_count
= 0;