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 #include "wx/listimpl.cpp"
45 #if wxUSE_DRAG_AND_DROP
51 #include <Xm/DrawingA.h>
52 #include <Xm/ScrolledW.h>
53 #include <Xm/ScrollBar.h>
56 #include <Xm/RowColumn.h> // for XmMenuPosition
58 #include "wx/motif/private.h"
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 static const int SCROLL_MARGIN
= 4;
68 // ----------------------------------------------------------------------------
69 // global variables for this module
70 // ----------------------------------------------------------------------------
72 extern wxHashTable
*wxWidgetHashTable
;
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
79 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
80 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
81 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
82 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
83 XmScaleCallbackStruct
*cbs
);
84 static void wxPanelItemEventHandler(Widget wid
,
85 XtPointer client_data
,
87 Boolean
*continueToDispatch
);
92 // Helper function for 16-bit fonts
93 static int str16len(const char *s
)
97 while (s
[0] && s
[1]) {
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
112 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
113 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 #if !USE_SHARED_LIBRARY
120 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
122 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
123 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
124 EVT_IDLE(wxWindow::OnIdle
)
126 #endif // USE_SHARED_LIBRARY
128 // ============================================================================
130 // ============================================================================
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 WX_DEFINE_LIST(wxRectList
);
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
144 Widget w
= (Widget
)widget
;
152 bool wxWindow::MapOrUnmap(WXWidget widget
, bool map
)
154 Widget w
= (Widget
)widget
;
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 void wxWindow::Init()
172 // generic initializations first
176 m_needsRefresh
= TRUE
;
177 m_mainWidget
= (WXWidget
) 0;
181 m_button3Pressed
= FALSE
;
183 m_winCaptured
= FALSE
;
186 m_isBeingDeleted
= FALSE
;
192 m_drawingArea
= (WXWidget
) 0;
200 m_backingPixmap
= (WXPixmap
) 0;
209 m_canAddEventHandler
= FALSE
;
212 // real construction (Init() must have been called before!)
213 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
217 const wxString
& name
)
219 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
221 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
223 parent
->AddChild(this);
225 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
226 m_foregroundColour
= *wxBLACK
;
228 //// TODO: we should probably optimize by only creating a
229 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
230 //// But for now, let's simplify things by always creating the
231 //// drawing area, since otherwise the translations are different.
233 // New translations for getting mouse motion feedback
234 static const String translations
=
235 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
236 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
237 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
238 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
239 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
240 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
241 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
242 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
243 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
244 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
245 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
246 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
247 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
248 <Key>: DrawingAreaInput()";
250 XtActionsRec actions
[1];
251 actions
[0].string
= "wxCanvasMotionEvent";
252 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
253 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
255 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
256 if (style
& wxBORDER
)
258 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
261 xmFrameWidgetClass
, parentWidget
,
262 XmNshadowType
, XmSHADOW_IN
,
267 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
270 xmScrolledWindowWidgetClass
,
271 m_borderWidget
? (Widget
) m_borderWidget
273 XmNresizePolicy
, XmRESIZE_NONE
,
275 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
276 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
280 XtTranslations ptr
= XtParseTranslationTable(translations
);
281 m_drawingArea
= (WXWidget
)XtVaCreateWidget
284 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
285 XmNunitType
, XmPIXELS
,
286 // XmNresizePolicy, XmRESIZE_ANY,
287 XmNresizePolicy
, XmRESIZE_NONE
,
290 XmNtranslations
, ptr
,
293 XtFree((char *) ptr
);
296 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
298 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
299 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
300 XtFree ((char *) ptr
);
304 wxAddWindowToTable((Widget
) m_drawingArea
, this);
305 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
307 // This order is very important in Motif 1.2.1
308 XtRealizeWidget ((Widget
) m_scrolledWindow
);
309 XtRealizeWidget ((Widget
) m_drawingArea
);
310 XtManageChild ((Widget
) m_drawingArea
);
312 ptr
= XtParseTranslationTable("<Configure>: resize()");
313 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
314 XtFree ((char *) ptr
);
316 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
317 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
321 display
= XtDisplay (scrolledWindow
);
322 xwindow
= XtWindow (drawingArea
);
326 (Widget
)m_drawingArea
,
327 PointerMotionHintMask
| EnterWindowMask
|
328 LeaveWindowMask
| FocusChangeMask
,
330 (XtEventHandler
) wxCanvasEnterLeave
,
334 // Scrolled widget needs to have its colour changed or we get a little blue
335 // square where the scrollbars abutt
336 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
337 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
338 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
340 XmScrolledWindowSetAreas(
341 (Widget
)m_scrolledWindow
,
342 (Widget
) 0, (Widget
) 0,
343 (Widget
) m_drawingArea
);
347 XtRealizeWidget ((Widget
) m_hScrollBar
);
349 XtRealizeWidget ((Widget
) m_vScrollBar
);
352 // Without this, the cursor may not be restored properly (e.g. in splitter
354 SetCursor(*wxSTANDARD_CURSOR
);
355 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
356 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
362 wxWindow::~wxWindow()
364 m_isBeingDeleted
= TRUE
;
366 // Motif-specific actions first
367 WXWidget wMain
= GetMainWidget();
370 // Removes event handlers
377 m_parent
->RemoveChild( this );
379 // If m_drawingArea, we're a fully-fledged window with drawing area,
380 // scrollbars etc. (what wxCanvas used to be)
383 // Destroy children before destroying self
387 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
389 Widget w
= (Widget
) m_drawingArea
;
390 wxDeleteWindowFromTable(w
);
397 m_mainWidget
= (WXWidget
) 0;
399 // Only if we're _really_ a canvas (not a dialog box/panel)
400 if (m_scrolledWindow
)
402 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
405 UnmanageAndDestroy(m_hScrollBar
);
406 UnmanageAndDestroy(m_vScrollBar
);
407 UnmanageAndDestroy(m_scrolledWindow
);
411 XtDestroyWidget ((Widget
) m_borderWidget
);
412 m_borderWidget
= (WXWidget
) 0;
416 // Destroy the window
419 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
420 // Child widgets will get destroyed automatically when a frame
421 // or dialog is destroyed, but before that you may get some memory
422 // leaks and potential layout problems if you delete and then add
424 XtDestroyWidget((Widget
) GetMainWidget());
425 SetMainWidget((WXWidget
) NULL
);
429 // ----------------------------------------------------------------------------
430 // scrollbar management
431 // ----------------------------------------------------------------------------
434 void wxWindow::CreateScrollbar(wxOrientation orientation
)
436 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
438 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
440 // Add scrollbars if required
441 if (orientation
== wxHORIZONTAL
)
443 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
444 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
445 XmNorientation
, XmHORIZONTAL
,
447 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
448 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
449 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
450 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
451 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
452 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
453 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
454 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
456 XtVaSetValues (hScrollBar
,
461 m_hScrollBar
= (WXWidget
) hScrollBar
;
463 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
464 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
466 XtRealizeWidget(hScrollBar
);
468 XtVaSetValues((Widget
) m_scrolledWindow
,
469 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
475 if (orientation
== wxVERTICAL
)
477 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
478 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
479 XmNorientation
, XmVERTICAL
,
481 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
482 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
483 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
484 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
485 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
486 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
487 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
488 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
490 XtVaSetValues (vScrollBar
,
495 m_vScrollBar
= (WXWidget
) vScrollBar
;
496 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
497 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
499 XtRealizeWidget(vScrollBar
);
501 XtVaSetValues((Widget
) m_scrolledWindow
,
502 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
508 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
511 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
513 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
515 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
516 // Add scrollbars if required
517 if (orientation
== wxHORIZONTAL
)
521 XtDestroyWidget((Widget
) m_hScrollBar
);
523 m_hScrollBar
= (WXWidget
) 0;
526 XtVaSetValues((Widget
) m_scrolledWindow
,
527 XmNhorizontalScrollBar
, (Widget
) 0,
532 if (orientation
== wxVERTICAL
)
536 XtDestroyWidget((Widget
) m_vScrollBar
);
538 m_vScrollBar
= (WXWidget
) 0;
541 XtVaSetValues((Widget
) m_scrolledWindow
,
542 XmNverticalScrollBar
, (Widget
) 0,
546 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
549 // ---------------------------------------------------------------------------
551 // ---------------------------------------------------------------------------
553 void wxWindow::SetFocus()
555 Widget wMain
= (Widget
) GetMainWidget();
556 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
557 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
560 // Get the window with the focus
561 wxWindow
*wxWindowBase::FindFocus()
564 // (1) Can there be multiple focussed widgets in an application?
565 // In which case we need to find the top-level window that's
567 // (2) The widget with the focus may not be in the widget table
568 // depending on which widgets I put in the table
569 wxWindow
*winFocus
= (wxWindow
*)NULL
;
570 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
572 node
= node
->GetNext() )
574 wxWindow
*win
= node
->GetData();
576 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
578 if (w
!= (Widget
) NULL
)
580 winFocus
= wxGetWindowFromTable(w
);
589 bool wxWindow::Enable(bool enable
)
591 if ( !wxWindowBase::Enable(enable
) )
594 Widget wMain
= (Widget
)GetMainWidget();
597 XtSetSensitive(wMain
, enable
);
598 XmUpdateDisplay(wMain
);
604 bool wxWindow::Show(bool show
)
606 if ( !wxWindowBase::Show(show
) )
609 if (m_borderWidget
|| m_scrolledWindow
)
611 MapOrUnmap(m_drawingArea
, show
);
612 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
616 if ( !MapOrUnmap(GetTopWidget(), show
) )
617 MapOrUnmap(GetMainWidget(), show
);
621 Window xwin
= (Window
) GetXWindow();
622 Display
*xdisp
= (Display
*) GetXDisplay();
624 XMapWindow(xdisp
, xwin
);
626 XUnmapWindow(xdisp
, xwin
);
632 // Raise the window to the top of the Z order
633 void wxWindow::Raise()
635 Widget wTop
= (Widget
) GetTopWidget();
636 Window window
= XtWindow(wTop
);
637 XRaiseWindow(XtDisplay(wTop
), window
);
640 // Lower the window to the bottom of the Z order
641 void wxWindow::Lower()
643 Widget wTop
= (Widget
) GetTopWidget();
644 Window window
= XtWindow(wTop
);
645 XLowerWindow(XtDisplay(wTop
), window
);
648 void wxWindow::SetTitle(const wxString
& title
)
650 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
653 wxString
wxWindow::GetTitle() const
656 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
658 return wxString(title
);
661 void wxWindow::CaptureMouse()
666 Widget wMain
= (Widget
)GetMainWidget();
668 XtAddGrab(wMain
, TRUE
, FALSE
);
670 m_winCaptured
= TRUE
;
673 void wxWindow::ReleaseMouse()
675 if ( !m_winCaptured
)
678 Widget wMain
= (Widget
)GetMainWidget();
682 m_winCaptured
= FALSE
;
685 bool wxWindow::SetFont(const wxFont
& font
)
687 if ( !wxWindowBase::SetFont(font
) )
698 bool wxWindow::SetCursor(const wxCursor
& cursor
)
700 if ( !wxWindowBase::SetCursor(cursor
) )
706 wxASSERT_MSG( m_cursor
.Ok(),
707 _T("cursor must be valid after call to the base version"));
709 WXDisplay
*dpy
= GetXDisplay();
710 WXCursor x_cursor
= m_cursor
.GetXCursor(dpy
);
712 Widget w
= (Widget
) GetMainWidget();
713 Window win
= XtWindow(w
);
714 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
719 // Coordinates relative to the window
720 void wxWindow::WarpPointer (int x
, int y
)
722 Widget wClient
= (Widget
)GetClientWidget();
724 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
727 // ---------------------------------------------------------------------------
729 // ---------------------------------------------------------------------------
731 int wxWindow::GetScrollPos(int orient
) const
733 if (orient
== wxHORIZONTAL
)
739 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
743 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
751 // This now returns the whole range, not just the number of positions that we
753 int wxWindow::GetScrollRange(int orient
) const
755 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
756 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
759 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
763 int wxWindow::GetScrollThumb(int orient
) const
765 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
766 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
769 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
773 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
775 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
779 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
782 SetInternalScrollPos((wxOrientation
)orient
, pos
);
785 // New function that will replace some of the above.
786 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
787 int range
, bool WXUNUSED(refresh
))
790 GetSize(& oldW
, & oldH
);
794 if (thumbVisible
== 0)
797 if (thumbVisible
> range
)
798 thumbVisible
= range
;
800 // Save the old state to see if it changed
801 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
803 if (orient
== wxHORIZONTAL
)
805 if (thumbVisible
== range
)
808 DestroyScrollbar(wxHORIZONTAL
);
813 CreateScrollbar(wxHORIZONTAL
);
816 if (orient
== wxVERTICAL
)
818 if (thumbVisible
== range
)
821 DestroyScrollbar(wxVERTICAL
);
826 CreateScrollbar(wxVERTICAL
);
829 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
831 if (oldScrollBar
!= newScrollBar
)
833 // This is important! Without it, scrollbars misbehave badly.
834 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
835 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
836 XtRealizeWidget((Widget
) m_scrolledWindow
);
837 XtManageChild((Widget
) m_scrolledWindow
);
842 XtVaSetValues((Widget
) newScrollBar
,
846 XmNsliderSize
, thumbVisible
,
850 SetInternalScrollPos((wxOrientation
)orient
, pos
);
853 GetSize(& newW
, & newH
);
855 // Adjusting scrollbars can resize the canvas accidentally
856 if (newW
!= oldW
|| newH
!= oldH
)
857 SetSize(-1, -1, oldW
, oldH
);
860 // Does a physical scroll
861 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
866 // Use specified rectangle
867 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
871 // Use whole client area
873 GetClientSize(& w
, & h
);
876 int x1
= (dx
>= 0) ? x
: x
- dx
;
877 int y1
= (dy
>= 0) ? y
: y
- dy
;
878 int w1
= w
- abs(dx
);
879 int h1
= h
- abs(dy
);
880 int x2
= (dx
>= 0) ? x
+ dx
: x
;
881 int y2
= (dy
>= 0) ? y
+ dy
: y
;
885 dc
.SetLogicalFunction (wxCOPY
);
887 Widget widget
= (Widget
) GetMainWidget();
888 Window window
= XtWindow(widget
);
889 Display
* display
= XtDisplay(widget
);
891 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
892 x1
, y1
, w1
, h1
, x2
, y2
);
894 dc
.SetAutoSetting(TRUE
);
895 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
896 dc
.SetBrush(brush
); // FIXME: needed?
898 // We'll add rectangles to the list of update rectangles according to which
899 // bits we've exposed.
904 wxRect
*rect
= new wxRect
;
910 XFillRectangle(display
, window
,
911 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
915 rect
->width
= rect
->width
;
916 rect
->height
= rect
->height
;
918 updateRects
.Append((wxObject
*) rect
);
922 wxRect
*rect
= new wxRect
;
924 rect
->x
= x
+ w
+ dx
;
929 XFillRectangle(display
, window
,
930 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
935 rect
->width
= rect
->width
;
936 rect
->height
= rect
->height
;
938 updateRects
.Append((wxObject
*) rect
);
942 wxRect
*rect
= new wxRect
;
949 XFillRectangle(display
, window
,
950 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
954 rect
->width
= rect
->width
;
955 rect
->height
= rect
->height
;
957 updateRects
.Append((wxObject
*) rect
);
961 wxRect
*rect
= new wxRect
;
964 rect
->y
= y
+ h
+ dy
;
968 XFillRectangle(display
, window
,
969 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
973 rect
->width
= rect
->width
;
974 rect
->height
= rect
->height
;
976 updateRects
.Append((wxObject
*) rect
);
978 dc
.SetBrush(wxNullBrush
);
980 // Now send expose events
982 wxNode
* node
= updateRects
.First();
985 wxRect
* rect
= (wxRect
*) node
->Data();
989 event
.display
= display
;
990 event
.send_event
= True
;
991 event
.window
= window
;
995 event
.width
= rect
->width
;
996 event
.height
= rect
->height
;
1000 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1002 node
= node
->Next();
1006 // Delete the update rects
1007 node
= updateRects
.First();
1010 wxRect
* rect
= (wxRect
*) node
->Data();
1012 node
= node
->Next();
1015 XmUpdateDisplay((Widget
) GetMainWidget());
1018 // ---------------------------------------------------------------------------
1020 // ---------------------------------------------------------------------------
1022 #if wxUSE_DRAG_AND_DROP
1024 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1031 // Old style file-manager drag&drop
1032 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1037 // ----------------------------------------------------------------------------
1039 // ----------------------------------------------------------------------------
1043 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1048 #endif // wxUSE_TOOLTIPS
1050 // ----------------------------------------------------------------------------
1052 // ----------------------------------------------------------------------------
1054 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1056 Widget widget
= (Widget
) GetMainWidget();
1058 /* The menuId field seems to be usused, so we'll use it to
1059 indicate whether a menu is popped up or not:
1060 0: Not currently created as a popup
1061 -1: Created as a popup, but not active
1065 if (menu
->GetParent() && (menu
->GetId() != -1))
1068 if (menu
->GetMainWidget()) {
1069 menu
->DestroyMenu(TRUE
);
1072 menu
->SetId(1); /* Mark as popped-up */
1073 menu
->CreateMenu(NULL
, widget
, menu
);
1074 menu
->SetInvokingWindow(this);
1078 // menu->SetParent(parent);
1079 // parent->children->Append(menu); // Store menu for later deletion
1081 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1089 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1091 wxCanvas *canvas = (wxCanvas *) this;
1092 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1093 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1097 Display
*display
= XtDisplay (widget
);
1098 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1099 Window thisWindow
= XtWindow (widget
);
1101 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1102 &rootX
, &rootY
, &childWindow
);
1104 XButtonPressedEvent event
;
1105 event
.type
= ButtonPress
;
1111 event
.x_root
= rootX
;
1112 event
.y_root
= rootY
;
1114 XmMenuPosition (menuWidget
, &event
);
1115 XtManageChild (menuWidget
);
1120 // ---------------------------------------------------------------------------
1121 // moving and resizing
1122 // ---------------------------------------------------------------------------
1124 bool wxWindow::PreResize()
1130 void wxWindow::DoGetSize(int *x
, int *y
) const
1134 CanvasGetSize(x
, y
);
1138 Widget widget
= (Widget
) GetTopWidget();
1140 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1144 void wxWindow::DoGetPosition(int *x
, int *y
) const
1148 CanvasGetPosition(x
, y
);
1151 Widget widget
= (Widget
) GetTopWidget();
1153 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1155 // We may be faking the client origin. So a window that's really at (0, 30)
1156 // may appear (to wxWin apps) to be at (0, 0).
1159 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1167 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1169 Widget widget
= (Widget
) GetClientWidget();
1170 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1171 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1172 Window thisWindow
= XtWindow(widget
);
1177 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1180 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1182 Widget widget
= (Widget
) GetClientWidget();
1183 Display
*display
= XtDisplay(widget
);
1184 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1185 Window thisWindow
= XtWindow(widget
);
1190 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1194 // Get size *available for subwindows* i.e. excluding menu bar etc.
1195 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1197 Widget widget
= (Widget
) GetClientWidget();
1199 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1203 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1205 // A bit of optimization to help sort out the flickers.
1206 int oldX
, oldY
, oldW
, oldH
;
1207 GetSize(& oldW
, & oldH
);
1208 GetPosition(& oldX
, & oldY
);
1210 bool useOldPos
= FALSE
;
1211 bool useOldSize
= FALSE
;
1213 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
1215 else if (x
== oldX
&& y
== oldY
)
1218 if ((width
== -1) && (height
== -1))
1220 else if (width
== oldW
&& height
== oldH
)
1223 if (!wxNoOptimize::CanOptimize())
1225 useOldSize
= FALSE
; useOldPos
= FALSE
;
1228 if (useOldPos
&& useOldSize
)
1233 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
1236 Widget widget
= (Widget
) GetTopWidget();
1240 bool managed
= XtIsManaged( widget
);
1242 XtUnmanageChild(widget
);
1244 int xx
= x
; int yy
= y
;
1245 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1249 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1250 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
1251 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1252 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
1257 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1259 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1263 XtManageChild(widget
);
1265 // How about this bit. Maybe we don't need to generate size events
1266 // all the time -- they'll be generated when the window is sized anyway.
1268 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1269 sizeEvent
.SetEventObject(this);
1271 GetEventHandler()->ProcessEvent(sizeEvent
);
1275 void wxWindow::DoSetClientSize(int width
, int height
)
1279 CanvasSetClientSize(width
, height
);
1283 Widget widget
= (Widget
) GetTopWidget();
1286 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1288 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1290 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1291 sizeEvent
.SetEventObject(this);
1293 GetEventHandler()->ProcessEvent(sizeEvent
);
1296 // For implementation purposes - sometimes decorations make the client area
1298 wxPoint
wxWindow::GetClientAreaOrigin() const
1300 return wxPoint(0, 0);
1303 // Makes an adjustment to the window position (for example, a frame that has
1304 // a toolbar that it manages itself).
1305 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
1307 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
1309 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1310 x
+= pt
.x
; y
+= pt
.y
;
1314 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1321 wxFrame
*frame
= wxDynamicCast(this, wxFrame
);
1324 // TODO what about dialogs?
1328 Widget widget
= (Widget
) frame
->GetShellWidget();
1331 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1333 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1335 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1337 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1339 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1341 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1344 // ---------------------------------------------------------------------------
1346 // ---------------------------------------------------------------------------
1348 int wxWindow::GetCharHeight() const
1350 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1352 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1354 int direction
, ascent
, descent
;
1355 XCharStruct overall
;
1356 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1357 &descent
, &overall
);
1359 // return (overall.ascent + overall.descent);
1360 return (ascent
+ descent
);
1363 int wxWindow::GetCharWidth() const
1365 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1367 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1369 int direction
, ascent
, descent
;
1370 XCharStruct overall
;
1371 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1372 &descent
, &overall
);
1374 return overall
.width
;
1377 void wxWindow::GetTextExtent(const wxString
& string
,
1379 int *descent
, int *externalLeading
,
1380 const wxFont
*theFont
) const
1382 wxFont
*fontToUse
= (wxFont
*)theFont
;
1384 fontToUse
= (wxFont
*) & m_font
;
1386 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1388 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1390 int direction
, ascent
, descent2
;
1391 XCharStruct overall
;
1396 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1397 &ascent
, &descent2
, &overall
);
1400 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1401 &direction
, &ascent
, &descent2
, &overall
);
1404 *x
= (overall
.width
);
1406 *y
= (ascent
+ descent2
);
1408 *descent
= descent2
;
1409 if (externalLeading
)
1410 *externalLeading
= 0;
1413 // ----------------------------------------------------------------------------
1415 // ----------------------------------------------------------------------------
1417 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1419 m_needsRefresh
= TRUE
;
1420 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1421 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1423 XExposeEvent dummyEvent
;
1425 GetSize(&width
, &height
);
1427 dummyEvent
.type
= Expose
;
1428 dummyEvent
.display
= display
;
1429 dummyEvent
.send_event
= True
;
1430 dummyEvent
.window
= thisWindow
;
1433 dummyEvent
.x
= rect
->x
;
1434 dummyEvent
.y
= rect
->y
;
1435 dummyEvent
.width
= rect
->width
;
1436 dummyEvent
.height
= rect
->height
;
1442 dummyEvent
.width
= width
;
1443 dummyEvent
.height
= height
;
1445 dummyEvent
.count
= 0;
1449 wxClientDC
dc(this);
1450 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1451 dc
.SetBackground(backgroundBrush
);
1458 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1461 void wxWindow::Clear()
1463 wxClientDC
dc(this);
1464 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1465 dc
.SetBackground(brush
);
1469 void wxWindow::ClearUpdateRects()
1471 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1474 wxRect
* rect
= node
->GetData();
1476 node
= node
->GetNext();
1479 m_updateRects
.Clear();
1482 void wxWindow::DoPaint()
1484 //TODO : make a temporary gc so we can do the XCopyArea below
1485 if (m_backingPixmap
&& !m_needsRefresh
)
1489 GC tempGC
= (GC
) dc
.GetBackingGC();
1491 Widget widget
= (Widget
) GetMainWidget();
1496 // We have to test whether it's a wxScrolledWindow (hack!) because
1497 // otherwise we don't know how many pixels have been scrolled. We might
1498 // solve this in the future by defining virtual wxWindow functions to get
1499 // the scroll position in pixels. Or, each kind of scrolled window has to
1500 // implement backing stores itself, using generic wxWindows code.
1501 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1502 if ( scrolledWindow
)
1505 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1511 // TODO: This could be optimized further by only copying the areas in the
1512 // current update region.
1514 // Only blit the part visible in the client area. The backing pixmap
1515 // always starts at 0, 0 but we may be looking at only a portion of it.
1516 wxSize clientArea
= GetClientSize();
1517 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1518 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1520 // Copy whichever is samller, the amount of pixmap we have to copy,
1521 // or the size of the client area.
1522 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1523 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1525 // Make sure we're not negative
1526 toBlitX
= wxMax(0, toBlitX
);
1527 toBlitY
= wxMax(0, toBlitY
);
1532 (Pixmap
) m_backingPixmap
,
1535 scrollPosX
, scrollPosY
, // Start at the scroll position
1536 toBlitX
, toBlitY
, // How much of the pixmap to copy
1542 // Set an erase event first
1543 wxEraseEvent
eraseEvent(GetId());
1544 eraseEvent
.SetEventObject(this);
1545 GetEventHandler()->ProcessEvent(eraseEvent
);
1547 wxPaintEvent
event(GetId());
1548 event
.SetEventObject(this);
1549 GetEventHandler()->ProcessEvent(event
);
1551 m_needsRefresh
= FALSE
;
1555 // ----------------------------------------------------------------------------
1557 // ----------------------------------------------------------------------------
1559 // Responds to colour changes: passes event on to children.
1560 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1562 wxWindowList::Node
*node
= GetChildren().GetFirst();
1565 // Only propagate to non-top-level windows
1566 wxWindow
*win
= node
->GetData();
1567 if ( win
->GetParent() )
1569 wxSysColourChangedEvent event2
;
1570 event
.m_eventObject
= win
;
1571 win
->GetEventHandler()->ProcessEvent(event2
);
1574 node
= node
->GetNext();
1578 void wxWindow::OnIdle(wxIdleEvent
& event
)
1580 // This calls the UI-update mechanism (querying windows for
1581 // menu/toolbar/control state information)
1585 // ----------------------------------------------------------------------------
1587 // ----------------------------------------------------------------------------
1589 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1591 if (!m_acceleratorTable
.Ok())
1594 int count
= m_acceleratorTable
.GetCount();
1595 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1597 for (i
= 0; i
< count
; i
++)
1599 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1600 if (entry
->MatchesEvent(event
))
1602 // Bingo, we have a match. Now find a control that matches the entry
1605 // Need to go up to the top of the window hierarchy, since it might
1606 // be e.g. a menu item
1607 wxWindow
* parent
= this;
1608 while ( parent
&& !parent
->IsTopLevel() )
1609 parent
= parent
->GetParent();
1614 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1617 // Try for a menu command
1618 if (frame
->GetMenuBar())
1620 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
1623 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1624 commandEvent
.SetEventObject(frame
);
1626 // If ProcessEvent returns TRUE (it was handled), then
1627 // the calling code will skip the event handling.
1628 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1633 // Find a child matching the command id
1634 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1640 // Now we process those kinds of windows that we can.
1641 // For now, only buttons.
1642 if ( wxDynamicCast(child
, wxButton
) )
1644 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1645 commandEvent
.SetEventObject(child
);
1646 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1653 // We didn't match the key event against an accelerator.
1657 // ============================================================================
1658 // Motif-specific stuff from here on
1659 // ============================================================================
1661 // ----------------------------------------------------------------------------
1662 // function which maintain the global hash table mapping Widgets to wxWindows
1663 // ----------------------------------------------------------------------------
1665 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1667 wxWindow
*oldItem
= NULL
;
1668 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1670 wxLogDebug("Widget table clash: new widget is %ld, %s",
1671 (long)w
, win
->GetClassInfo()->GetClassName());
1675 wxWidgetHashTable
->Put((long) w
, win
);
1677 wxLogDebug("Widget 0x%08x <-> window %p (%s)",
1678 w
, win
, win
->GetClassInfo()->GetClassName());
1683 wxWindow
*wxGetWindowFromTable(Widget w
)
1685 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1688 void wxDeleteWindowFromTable(Widget w
)
1690 wxWidgetHashTable
->Delete((long)w
);
1693 // ----------------------------------------------------------------------------
1694 // add/remove window from the table
1695 // ----------------------------------------------------------------------------
1697 // Add to hash table, add event handler
1698 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
1699 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1701 wxAddWindowToTable((Widget
) mainWidget
, this);
1702 if (CanAddEventHandler())
1704 XtAddEventHandler((Widget
) mainWidget
,
1705 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1707 wxPanelItemEventHandler
,
1714 XtOverrideTranslations ((Widget
) mainWidget
,
1715 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1716 XtFree ((char *) ptr
);
1719 // Some widgets have a parent form widget, e.g. wxRadioBox
1722 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1726 XtOverrideTranslations ((Widget
) formWidget
,
1727 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1728 XtFree ((char *) ptr
);
1735 SetSize (x
, y
, width
, height
);
1740 // Remove event handler, remove from hash table
1741 bool wxWindow::DetachWidget(WXWidget widget
)
1743 if (CanAddEventHandler())
1745 XtRemoveEventHandler((Widget
) widget
,
1746 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1748 wxPanelItemEventHandler
,
1752 wxDeleteWindowFromTable((Widget
) widget
);
1756 // ----------------------------------------------------------------------------
1757 // Motif-specific accessors
1758 // ----------------------------------------------------------------------------
1760 // Get the underlying X window
1761 WXWindow
wxWindow::GetXWindow() const
1763 Widget wMain
= (Widget
)GetMainWidget();
1765 return (WXWindow
) XtWindow(wMain
);
1767 return (WXWindow
) 0;
1770 // Get the underlying X display
1771 WXDisplay
*wxWindow::GetXDisplay() const
1773 Widget wMain
= (Widget
)GetMainWidget();
1775 return (WXDisplay
*) XtDisplay(wMain
);
1777 return (WXDisplay
*) NULL
;
1780 WXWidget
wxWindow::GetMainWidget() const
1783 return m_drawingArea
;
1785 return m_mainWidget
;
1788 WXWidget
wxWindow::GetClientWidget() const
1790 if (m_drawingArea
!= (WXWidget
) 0)
1791 return m_drawingArea
;
1793 return GetMainWidget();
1796 WXWidget
wxWindow::GetTopWidget() const
1798 return GetMainWidget();
1801 WXWidget
wxWindow::GetLabelWidget() const
1803 return GetMainWidget();
1806 // ----------------------------------------------------------------------------
1808 // ----------------------------------------------------------------------------
1810 // All widgets should have this as their resize proc.
1811 // OnSize sent to wxWindow via client data.
1812 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
1814 wxWindow
*win
= wxGetWindowFromTable(w
);
1818 if (win
->PreResize())
1821 win
->GetSize(&width
, &height
);
1822 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1823 sizeEvent
.SetEventObject(win
);
1824 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1828 static void wxCanvasRepaintProc(Widget drawingArea
,
1829 XtPointer clientData
,
1830 XmDrawingAreaCallbackStruct
* cbs
)
1832 if (!wxGetWindowFromTable(drawingArea
))
1835 XEvent
* event
= cbs
->event
;
1836 wxWindow
* win
= (wxWindow
*) clientData
;
1838 switch (event
->type
)
1842 if (event
-> xexpose
.count
== 0)
1845 wxPaintEvent
event(win
->GetId());
1846 event
.SetEventObject(win
);
1847 win
->GetEventHandler()->ProcessEvent(event
);
1851 win
->ClearUpdateRects();
1855 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1856 event
->xexpose
.width
, event
->xexpose
.height
);
1863 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1864 static void wxCanvasEnterLeave(Widget drawingArea
,
1865 XtPointer clientData
,
1866 XCrossingEvent
* event
)
1868 XmDrawingAreaCallbackStruct cbs
;
1871 ((XCrossingEvent
&) ev
) = *event
;
1873 cbs
.reason
= XmCR_INPUT
;
1876 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1879 // Fix to make it work under Motif 1.0 (!)
1880 static void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
1882 #if XmVersion <= 1000
1883 XmDrawingAreaCallbackStruct cbs
;
1886 ev
= *((XEvent
*) event
);
1887 cbs
.reason
= XmCR_INPUT
;
1890 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1891 #endif // XmVersion <= 1000
1894 static void wxCanvasInputEvent(Widget drawingArea
,
1896 XmDrawingAreaCallbackStruct
* cbs
)
1898 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1904 if (cbs
->reason
!= XmCR_INPUT
)
1907 local_event
= *(cbs
->event
); // We must keep a copy!
1909 switch (local_event
.xany
.type
)
1917 wxEventType eventType
= wxEVT_NULL
;
1919 if (local_event
.xany
.type
== EnterNotify
)
1921 //if (local_event.xcrossing.mode!=NotifyNormal)
1922 // return ; // Ignore grab events
1923 eventType
= wxEVT_ENTER_WINDOW
;
1924 // canvas->GetEventHandler()->OnSetFocus();
1926 else if (local_event
.xany
.type
== LeaveNotify
)
1928 //if (local_event.xcrossing.mode!=NotifyNormal)
1929 // return ; // Ignore grab events
1930 eventType
= wxEVT_LEAVE_WINDOW
;
1931 // canvas->GetEventHandler()->OnKillFocus();
1933 else if (local_event
.xany
.type
== MotionNotify
)
1935 eventType
= wxEVT_MOTION
;
1936 if (local_event
.xmotion
.is_hint
== NotifyHint
)
1939 Display
*dpy
= XtDisplay (drawingArea
);
1941 XQueryPointer (dpy
, XtWindow (drawingArea
),
1943 &local_event
.xmotion
.x_root
,
1944 &local_event
.xmotion
.y_root
,
1945 &local_event
.xmotion
.x
,
1946 &local_event
.xmotion
.y
,
1947 &local_event
.xmotion
.state
);
1954 else if (local_event
.xany
.type
== ButtonPress
)
1956 if (local_event
.xbutton
.button
== Button1
)
1958 eventType
= wxEVT_LEFT_DOWN
;
1959 canvas
->SetButton1(TRUE
);
1961 else if (local_event
.xbutton
.button
== Button2
)
1963 eventType
= wxEVT_MIDDLE_DOWN
;
1964 canvas
->SetButton2(TRUE
);
1966 else if (local_event
.xbutton
.button
== Button3
)
1968 eventType
= wxEVT_RIGHT_DOWN
;
1969 canvas
->SetButton3(TRUE
);
1972 else if (local_event
.xany
.type
== ButtonRelease
)
1974 if (local_event
.xbutton
.button
== Button1
)
1976 eventType
= wxEVT_LEFT_UP
;
1977 canvas
->SetButton1(FALSE
);
1979 else if (local_event
.xbutton
.button
== Button2
)
1981 eventType
= wxEVT_MIDDLE_UP
;
1982 canvas
->SetButton2(FALSE
);
1984 else if (local_event
.xbutton
.button
== Button3
)
1986 eventType
= wxEVT_RIGHT_UP
;
1987 canvas
->SetButton3(FALSE
);
1991 wxMouseEvent
wxevent (eventType
);
1993 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1994 || (event_left_is_down (&local_event
)
1995 && (eventType
!= wxEVT_LEFT_UP
)));
1996 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1997 || (event_middle_is_down (&local_event
)
1998 && (eventType
!= wxEVT_MIDDLE_UP
)));
1999 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2000 || (event_right_is_down (&local_event
)
2001 && (eventType
!= wxEVT_RIGHT_UP
)));
2003 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2004 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2005 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2006 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2007 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2009 // Now check if we need to translate this event into a double click
2010 if (TRUE
) // canvas->doubleClickAllowed)
2012 if (wxevent
.ButtonDown())
2014 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2016 // get button and time-stamp
2018 if (wxevent
.LeftDown())
2020 else if (wxevent
.MiddleDown())
2022 else if (wxevent
.RightDown())
2024 long ts
= wxevent
.GetTimestamp();
2026 // check, if single or double click
2027 int buttonLast
= canvas
->GetLastClickedButton();
2028 long lastTS
= canvas
->GetLastClickTime();
2029 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2032 canvas
->SetLastClick(0, ts
);
2033 switch ( eventType
)
2035 case wxEVT_LEFT_DOWN
:
2036 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2038 case wxEVT_MIDDLE_DOWN
:
2039 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2041 case wxEVT_RIGHT_DOWN
:
2042 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2052 // not fast enough or different button
2053 canvas
->SetLastClick(button
, ts
);
2058 wxevent
.SetId(canvas
->GetId());
2059 wxevent
.SetEventObject(canvas
);
2060 wxevent
.m_x
= local_event
.xbutton
.x
;
2061 wxevent
.m_y
= local_event
.xbutton
.y
;
2062 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2064 if (eventType
== wxEVT_ENTER_WINDOW
||
2065 eventType
== wxEVT_LEAVE_WINDOW
||
2066 eventType
== wxEVT_MOTION
2076 XComposeStatus compose
;
2077 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, &compose
);
2080 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2081 int id
= wxCharCodeXToWX (keySym
);
2083 wxEventType eventType
= wxEVT_CHAR
;
2085 wxKeyEvent
event (eventType
);
2087 if (local_event
.xkey
.state
& ShiftMask
)
2088 event
.m_shiftDown
= TRUE
;
2089 if (local_event
.xkey
.state
& ControlMask
)
2090 event
.m_controlDown
= TRUE
;
2091 if (local_event
.xkey
.state
& Mod3Mask
)
2092 event
.m_altDown
= TRUE
;
2093 if (local_event
.xkey
.state
& Mod1Mask
)
2094 event
.m_metaDown
= TRUE
;
2095 event
.SetEventObject(canvas
);
2096 event
.m_keyCode
= id
;
2097 event
.SetTimestamp(local_event
.xkey
.time
);
2101 // Implement wxFrame::OnCharHook by checking ancestor.
2102 wxWindow
*parent
= canvas
->GetParent();
2103 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2104 parent
= parent
->GetParent();
2108 event
.SetEventType(wxEVT_CHAR_HOOK
);
2109 if (parent
->GetEventHandler()->ProcessEvent(event
))
2113 // For simplicity, OnKeyDown is the same as OnChar
2114 // TODO: filter modifier key presses from OnChar
2115 event
.SetEventType(wxEVT_KEY_DOWN
);
2117 // Only process OnChar if OnKeyDown didn't swallow it
2118 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2120 event
.SetEventType(wxEVT_CHAR
);
2121 canvas
->GetEventHandler()->ProcessEvent (event
);
2129 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2130 int id
= wxCharCodeXToWX (keySym
);
2132 wxKeyEvent
event (wxEVT_KEY_UP
);
2134 if (local_event
.xkey
.state
& ShiftMask
)
2135 event
.m_shiftDown
= TRUE
;
2136 if (local_event
.xkey
.state
& ControlMask
)
2137 event
.m_controlDown
= TRUE
;
2138 if (local_event
.xkey
.state
& Mod3Mask
)
2139 event
.m_altDown
= TRUE
;
2140 if (local_event
.xkey
.state
& Mod1Mask
)
2141 event
.m_metaDown
= TRUE
;
2142 event
.SetEventObject(canvas
);
2143 event
.m_keyCode
= id
;
2144 event
.SetTimestamp(local_event
.xkey
.time
);
2148 canvas
->GetEventHandler()->ProcessEvent (event
);
2154 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2156 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2157 event
.SetEventObject(canvas
);
2158 canvas
->GetEventHandler()->ProcessEvent(event
);
2164 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2166 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2167 event
.SetEventObject(canvas
);
2168 canvas
->GetEventHandler()->ProcessEvent(event
);
2177 static void wxPanelItemEventHandler(Widget wid
,
2178 XtPointer client_data
,
2180 Boolean
*continueToDispatch
)
2182 // Widget can be a label or the actual widget.
2184 wxWindow
*window
= wxGetWindowFromTable(wid
);
2187 wxMouseEvent
wxevent(0);
2188 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2190 window
->GetEventHandler()->ProcessEvent(wxevent
);
2194 // TODO: probably the key to allowing default behaviour to happen. Say we
2195 // set a m_doDefault flag to FALSE at the start of this function. Then in
2196 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2197 // TRUE, indicating that default processing can happen. Thus, behaviour can
2198 // appear to be overridden just by adding an event handler and not calling
2199 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2200 // way of handling drawing area events, to simplify things.
2201 *continueToDispatch
= True
;
2204 static void wxScrollBarCallback(Widget scrollbar
,
2205 XtPointer clientData
,
2206 XmScaleCallbackStruct
*cbs
)
2208 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2209 int orientation
= (int) clientData
;
2211 wxEventType eventType
= wxEVT_NULL
;
2212 switch (cbs
->reason
)
2214 case XmCR_INCREMENT
:
2216 eventType
= wxEVT_SCROLL_LINEDOWN
;
2219 case XmCR_DECREMENT
:
2221 eventType
= wxEVT_SCROLL_LINEUP
;
2226 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2229 case XmCR_VALUE_CHANGED
:
2231 // TODO: Should this be intercepted too, or will it cause
2232 // duplicate events?
2233 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2236 case XmCR_PAGE_INCREMENT
:
2238 eventType
= wxEVT_SCROLL_PAGEDOWN
;
2241 case XmCR_PAGE_DECREMENT
:
2243 eventType
= wxEVT_SCROLL_PAGEUP
;
2248 eventType
= wxEVT_SCROLL_TOP
;
2251 case XmCR_TO_BOTTOM
:
2253 eventType
= wxEVT_SCROLL_BOTTOM
;
2258 // Should never get here
2259 wxFAIL_MSG("Unknown scroll event.");
2264 wxScrollEvent
event(eventType
, win
->GetId());
2265 event
.SetEventObject(win
);
2266 event
.SetPosition(cbs
->value
);
2267 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
2269 win
->GetEventHandler()->ProcessEvent(event
);
2272 // For repainting arbitrary windows
2273 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2278 wxWindow
* win
= wxGetWindowFromTable(w
);
2282 switch(event
-> type
)
2286 window
= (Window
) win
-> GetXWindow();
2287 display
= (Display
*) win
-> GetXDisplay();
2289 if (event
-> xexpose
.count
== 0)
2293 win
->ClearUpdateRects();
2297 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2298 event
->xexpose
.width
, event
->xexpose
.height
);
2306 // ----------------------------------------------------------------------------
2307 // CanvaseXXXSize() functions
2308 // ----------------------------------------------------------------------------
2310 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2311 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2313 // A bit of optimization to help sort out the flickers.
2314 int oldX
, oldY
, oldW
, oldH
;
2315 GetSize(& oldW
, & oldH
);
2316 GetPosition(& oldX
, & oldY
);
2318 bool useOldPos
= FALSE
;
2319 bool useOldSize
= FALSE
;
2321 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2323 else if (x
== oldX
&& y
== oldY
)
2326 if ((w
== -1) && (h
== -1))
2328 else if (w
== oldW
&& h
== oldH
)
2331 if (!wxNoOptimize::CanOptimize())
2333 useOldSize
= FALSE
; useOldPos
= FALSE
;
2336 if (useOldPos
&& useOldSize
)
2339 Widget drawingArea
= (Widget
) m_drawingArea
;
2340 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2343 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2344 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2346 int xx
= x
; int yy
= y
;
2347 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2351 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2353 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2357 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2359 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2371 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2372 short thick
, margin
;
2373 XtVaGetValues ((Widget
) m_borderWidget
,
2374 XmNshadowThickness
, &thick
,
2375 XmNmarginWidth
, &margin
,
2377 w
-= 2 * (thick
+ margin
);
2380 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2384 XtVaGetValues ((Widget
) m_scrolledWindow
,
2385 XmNspacing
, &spacing
,
2386 XmNverticalScrollBar
, &sbar
,
2390 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2394 w
-= (spacing
+ wsbar
);
2397 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2404 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2405 short thick
, margin
;
2406 XtVaGetValues ((Widget
) m_borderWidget
,
2407 XmNshadowThickness
, &thick
,
2408 XmNmarginHeight
, &margin
,
2410 h
-= 2 * (thick
+ margin
);
2413 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2417 XtVaGetValues ((Widget
) m_scrolledWindow
,
2418 XmNspacing
, &spacing
,
2419 XmNhorizontalScrollBar
, &sbar
,
2423 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2427 h
-= (spacing
+ wsbar
);
2430 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2436 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2437 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2441 GetClientSize (&ww
, &hh
);
2442 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2443 sizeEvent
.SetEventObject(this);
2445 GetEventHandler()->ProcessEvent(sizeEvent
);
2449 void wxWindow::CanvasSetClientSize (int w
, int h
)
2451 Widget drawingArea
= (Widget
) m_drawingArea
;
2453 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2456 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2458 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2461 // TODO: is this necessary?
2462 allowRepainting
= FALSE
;
2464 XSync (XtDisplay (drawingArea
), FALSE
);
2466 while (XtAppPending (wxTheApp
->appContext
))
2468 XFlush (XtDisplay (drawingArea
));
2469 XtAppNextEvent (wxTheApp
->appContext
, &event
);
2470 XtDispatchEvent (&event
);
2474 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2477 allowRepainting
= TRUE
;
2480 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2481 sizeEvent
.SetEventObject(this);
2483 GetEventHandler()->ProcessEvent(sizeEvent
);
2487 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2489 // Must return the same thing that was set via SetClientSize
2491 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2496 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2499 if ((Widget
) m_borderWidget
)
2500 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2501 else if ((Widget
) m_scrolledWindow
)
2502 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2504 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2510 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2513 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2515 // We may be faking the client origin.
2516 // So a window that's really at (0, 30) may appear
2517 // (to wxWin apps) to be at (0, 0).
2520 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2529 // ----------------------------------------------------------------------------
2530 // TranslateXXXEvent() functions
2531 // ----------------------------------------------------------------------------
2533 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2535 switch (xevent
->xany
.type
)
2543 wxEventType eventType
= wxEVT_NULL
;
2545 if (xevent
->xany
.type
== LeaveNotify
)
2547 win
->SetButton1(FALSE
);
2548 win
->SetButton2(FALSE
);
2549 win
->SetButton3(FALSE
);
2552 else if (xevent
->xany
.type
== MotionNotify
)
2554 eventType
= wxEVT_MOTION
;
2556 else if (xevent
->xany
.type
== ButtonPress
)
2558 if (xevent
->xbutton
.button
== Button1
)
2560 eventType
= wxEVT_LEFT_DOWN
;
2561 win
->SetButton1(TRUE
);
2563 else if (xevent
->xbutton
.button
== Button2
)
2565 eventType
= wxEVT_MIDDLE_DOWN
;
2566 win
->SetButton2(TRUE
);
2568 else if (xevent
->xbutton
.button
== Button3
)
2570 eventType
= wxEVT_RIGHT_DOWN
;
2571 win
->SetButton3(TRUE
);
2574 else if (xevent
->xany
.type
== ButtonRelease
)
2576 if (xevent
->xbutton
.button
== Button1
)
2578 eventType
= wxEVT_LEFT_UP
;
2579 win
->SetButton1(FALSE
);
2581 else if (xevent
->xbutton
.button
== Button2
)
2583 eventType
= wxEVT_MIDDLE_UP
;
2584 win
->SetButton2(FALSE
);
2586 else if (xevent
->xbutton
.button
== Button3
)
2588 eventType
= wxEVT_RIGHT_UP
;
2589 win
->SetButton3(FALSE
);
2598 wxevent
.SetEventType(eventType
);
2601 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2604 win
->GetPosition(&x2
, &y2
);
2606 // The button x/y must be translated to wxWindows
2607 // window space - the widget might be a label or button,
2611 if (widget
!= (Widget
)win
->GetMainWidget())
2617 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2618 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2620 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2621 || (event_left_is_down (xevent
)
2622 && (eventType
!= wxEVT_LEFT_UP
)));
2623 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2624 || (event_middle_is_down (xevent
)
2625 && (eventType
!= wxEVT_MIDDLE_UP
)));
2626 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2627 || (event_right_is_down (xevent
)
2628 && (eventType
!= wxEVT_RIGHT_UP
)));
2630 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2631 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2638 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2640 switch (xevent
->xany
.type
)
2649 XComposeStatus compose
;
2650 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, &compose
);
2652 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2653 int id
= wxCharCodeXToWX (keySym
);
2655 if (xevent
->xkey
.state
& ShiftMask
)
2656 wxevent
.m_shiftDown
= TRUE
;
2657 if (xevent
->xkey
.state
& ControlMask
)
2658 wxevent
.m_controlDown
= TRUE
;
2659 if (xevent
->xkey
.state
& Mod3Mask
)
2660 wxevent
.m_altDown
= TRUE
;
2661 if (xevent
->xkey
.state
& Mod1Mask
)
2662 wxevent
.m_metaDown
= TRUE
;
2663 wxevent
.SetEventObject(win
);
2664 wxevent
.m_keyCode
= id
;
2665 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2667 wxevent
.m_x
= xevent
->xbutton
.x
;
2668 wxevent
.m_y
= xevent
->xbutton
.y
;
2682 // ----------------------------------------------------------------------------
2684 // ----------------------------------------------------------------------------
2686 #define YAllocColor XAllocColor
2687 XColor g_itemColors
[5];
2688 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2691 static XmColorProc colorProc
;
2693 result
= wxNO_COLORS
;
2697 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2698 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2699 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2700 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2701 if (colorProc
== (XmColorProc
) NULL
)
2703 // Get a ptr to the actual function
2704 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2705 // And set it back to motif.
2706 XmSetColorCalculation (colorProc
);
2708 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2709 &g_itemColors
[wxFORE_INDEX
],
2710 &g_itemColors
[wxSELE_INDEX
],
2711 &g_itemColors
[wxTOPS_INDEX
],
2712 &g_itemColors
[wxBOTS_INDEX
]);
2713 result
= wxBACK_COLORS
;
2717 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2718 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2719 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2720 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2721 if (result
== wxNO_COLORS
)
2722 result
= wxFORE_COLORS
;
2725 Display
*dpy
= display
;
2726 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2730 /* 5 Colours to allocate */
2731 for (int i
= 0; i
< 5; i
++)
2732 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2733 result
= wxNO_COLORS
;
2737 /* Only 1 colour to allocate */
2738 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2739 result
= wxNO_COLORS
;
2746 // Changes the foreground and background colours to be derived from the current
2747 // background colour. To change the foreground colour, you must call
2748 // SetForegroundColour explicitly.
2749 void wxWindow::ChangeBackgroundColour()
2751 WXWidget mainWidget
= GetMainWidget();
2753 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2755 // This not necessary
2758 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
2760 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
2761 // Have to set the scrollbar colours back since
2762 // the scrolled window seemed to change them
2763 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
2766 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
2768 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
2773 void wxWindow::ChangeForegroundColour()
2775 WXWidget mainWidget
= GetMainWidget();
2777 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2778 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2779 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2782 // Change a widget's foreground and background colours.
2783 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
2785 // When should we specify the foreground, if it's calculated
2786 // by wxComputeColours?
2787 // Solution: say we start with the default (computed) foreground colour.
2788 // If we call SetForegroundColour explicitly for a control or window,
2789 // then the foreground is changed.
2790 // Therefore SetBackgroundColour computes the foreground colour, and
2791 // SetForegroundColour changes the foreground colour. The ordering is
2794 Widget w
= (Widget
)widget
;
2797 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
2802 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
2804 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
2807 XtVaSetValues ((Widget
) widget
,
2808 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
2809 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
2810 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
2811 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
2814 if (changeArmColour
)
2815 XtVaSetValues ((Widget
) widget
,
2816 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
2820 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2822 if ( !wxWindowBase::SetBackgroundColour(col
) )
2825 ChangeBackgroundColour();
2830 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2832 if ( !wxWindowBase::SetForegroundColour(col
) )
2835 ChangeForegroundColour();
2840 void wxWindow::ChangeFont(bool keepOriginalSize
)
2842 // Note that this causes the widget to be resized back
2843 // to its original size! We therefore have to set the size
2844 // back again. TODO: a better way in Motif?
2845 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2846 if (w
&& m_font
.Ok())
2848 int width
, height
, width1
, height1
;
2849 GetSize(& width
, & height
);
2851 // lesstif 0.87 hangs here
2852 #ifndef LESSTIF_VERSION
2854 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
2858 GetSize(& width1
, & height1
);
2859 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2861 SetSize(-1, -1, width
, height
);
2866 // ----------------------------------------------------------------------------
2868 // ----------------------------------------------------------------------------
2870 wxWindow
*wxGetActiveWindow()
2876 // ----------------------------------------------------------------------------
2877 // wxNoOptimize: switch off size optimization
2878 // ----------------------------------------------------------------------------
2880 int wxNoOptimize::ms_count
= 0;