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
;
191 m_drawingArea
= (WXWidget
) 0;
199 m_backingPixmap
= (WXPixmap
) 0;
208 m_canAddEventHandler
= FALSE
;
211 // real construction (Init() must have been called before!)
212 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
216 const wxString
& name
)
218 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
220 CreateBase(parent
, id
, pos
, size
, style
, name
);
222 parent
->AddChild(this);
224 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
225 m_foregroundColour
= *wxBLACK
;
227 //// TODO: we should probably optimize by only creating a
228 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
229 //// But for now, let's simplify things by always creating the
230 //// drawing area, since otherwise the translations are different.
232 // New translations for getting mouse motion feedback
233 static const String translations
=
234 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
235 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
236 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
237 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
238 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
239 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
240 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
241 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
242 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
243 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
244 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
245 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
246 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
247 <Key>: DrawingAreaInput()";
249 XtActionsRec actions
[1];
250 actions
[0].string
= "wxCanvasMotionEvent";
251 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
252 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
254 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
255 if (style
& wxBORDER
)
257 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
260 xmFrameWidgetClass
, parentWidget
,
261 XmNshadowType
, XmSHADOW_IN
,
266 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
269 xmScrolledWindowWidgetClass
,
270 m_borderWidget
? (Widget
) m_borderWidget
272 XmNresizePolicy
, XmRESIZE_NONE
,
274 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
275 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
279 XtTranslations ptr
= XtParseTranslationTable(translations
);
280 m_drawingArea
= (WXWidget
)XtVaCreateWidget
283 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
284 XmNunitType
, XmPIXELS
,
285 // XmNresizePolicy, XmRESIZE_ANY,
286 XmNresizePolicy
, XmRESIZE_NONE
,
289 XmNtranslations
, ptr
,
292 XtFree((char *) ptr
);
295 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
297 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
298 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
299 XtFree ((char *) ptr
);
303 wxAddWindowToTable((Widget
) m_drawingArea
, this);
304 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
306 // This order is very important in Motif 1.2.1
307 XtRealizeWidget ((Widget
) m_scrolledWindow
);
308 XtRealizeWidget ((Widget
) m_drawingArea
);
309 XtManageChild ((Widget
) m_drawingArea
);
311 ptr
= XtParseTranslationTable("<Configure>: resize()");
312 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
313 XtFree ((char *) ptr
);
315 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
316 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
320 display
= XtDisplay (scrolledWindow
);
321 xwindow
= XtWindow (drawingArea
);
325 (Widget
)m_drawingArea
,
326 PointerMotionHintMask
| EnterWindowMask
|
327 LeaveWindowMask
| FocusChangeMask
,
329 (XtEventHandler
) wxCanvasEnterLeave
,
333 // Scrolled widget needs to have its colour changed or we get a little blue
334 // square where the scrollbars abutt
335 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
336 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
337 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
339 XmScrolledWindowSetAreas(
340 (Widget
)m_scrolledWindow
,
341 (Widget
) 0, (Widget
) 0,
342 (Widget
) m_drawingArea
);
346 XtRealizeWidget ((Widget
) m_hScrollBar
);
348 XtRealizeWidget ((Widget
) m_vScrollBar
);
351 // Without this, the cursor may not be restored properly (e.g. in splitter
353 SetCursor(*wxSTANDARD_CURSOR
);
354 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
355 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
361 wxWindow::~wxWindow()
363 // Motif-specific actions first
364 WXWidget wMain
= GetMainWidget();
367 // Removes event handlers
374 m_parent
->RemoveChild( this );
376 // If m_drawingArea, we're a fully-fledged window with drawing area,
377 // scrollbars etc. (what wxCanvas used to be)
380 // Destroy children before destroying self
384 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
386 Widget w
= (Widget
) m_drawingArea
;
387 wxDeleteWindowFromTable(w
);
394 m_mainWidget
= (WXWidget
) 0;
396 // Only if we're _really_ a canvas (not a dialog box/panel)
397 if (m_scrolledWindow
)
399 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
402 UnmanageAndDestroy(m_hScrollBar
);
403 UnmanageAndDestroy(m_vScrollBar
);
404 UnmanageAndDestroy(m_scrolledWindow
);
408 XtDestroyWidget ((Widget
) m_borderWidget
);
409 m_borderWidget
= (WXWidget
) 0;
413 // Destroy the window
416 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
417 // Child widgets will get destroyed automatically when a frame
418 // or dialog is destroyed, but before that you may get some memory
419 // leaks and potential layout problems if you delete and then add
421 XtDestroyWidget((Widget
) GetMainWidget());
422 SetMainWidget((WXWidget
) NULL
);
426 // ----------------------------------------------------------------------------
427 // scrollbar management
428 // ----------------------------------------------------------------------------
431 void wxWindow::CreateScrollbar(wxOrientation orientation
)
433 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
435 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
437 // Add scrollbars if required
438 if (orientation
== wxHORIZONTAL
)
440 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
441 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
442 XmNorientation
, XmHORIZONTAL
,
444 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
445 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
446 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
447 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
448 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
449 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
450 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
451 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
453 XtVaSetValues (hScrollBar
,
458 m_hScrollBar
= (WXWidget
) hScrollBar
;
460 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
461 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
463 XtRealizeWidget(hScrollBar
);
465 XtVaSetValues((Widget
) m_scrolledWindow
,
466 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
472 if (orientation
== wxVERTICAL
)
474 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
475 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
476 XmNorientation
, XmVERTICAL
,
478 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
479 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
480 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
481 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
482 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
483 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
484 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
485 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
487 XtVaSetValues (vScrollBar
,
492 m_vScrollBar
= (WXWidget
) vScrollBar
;
493 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
494 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
496 XtRealizeWidget(vScrollBar
);
498 XtVaSetValues((Widget
) m_scrolledWindow
,
499 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
505 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
508 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
510 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
512 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
513 // Add scrollbars if required
514 if (orientation
== wxHORIZONTAL
)
518 XtDestroyWidget((Widget
) m_hScrollBar
);
520 m_hScrollBar
= (WXWidget
) 0;
523 XtVaSetValues((Widget
) m_scrolledWindow
,
524 XmNhorizontalScrollBar
, (Widget
) 0,
529 if (orientation
== wxVERTICAL
)
533 XtDestroyWidget((Widget
) m_vScrollBar
);
535 m_vScrollBar
= (WXWidget
) 0;
538 XtVaSetValues((Widget
) m_scrolledWindow
,
539 XmNverticalScrollBar
, (Widget
) 0,
543 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
546 // ---------------------------------------------------------------------------
548 // ---------------------------------------------------------------------------
550 void wxWindow::SetFocus()
552 Widget wMain
= (Widget
) GetMainWidget();
553 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
554 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
557 // Get the window with the focus
558 wxWindow
*wxWindowBase::FindFocus()
561 // (1) Can there be multiple focussed widgets in an application?
562 // In which case we need to find the top-level window that's
564 // (2) The widget with the focus may not be in the widget table
565 // depending on which widgets I put in the table
566 wxWindow
*winFocus
= (wxWindow
*)NULL
;
567 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
569 node
= node
->GetNext() )
571 wxWindow
*win
= node
->GetData();
573 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
575 if (w
!= (Widget
) NULL
)
577 winFocus
= wxGetWindowFromTable(w
);
586 bool wxWindow::Enable(bool enable
)
588 if ( !wxWindowBase::Enable(enable
) )
591 Widget wMain
= (Widget
)GetMainWidget();
594 XtSetSensitive(wMain
, enable
);
595 XmUpdateDisplay(wMain
);
601 bool wxWindow::Show(bool show
)
603 if ( !wxWindowBase::Show(show
) )
606 if (m_borderWidget
|| m_scrolledWindow
)
608 MapOrUnmap(m_drawingArea
, show
);
609 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
613 if ( !MapOrUnmap(GetTopWidget(), show
) )
614 MapOrUnmap(GetMainWidget(), show
);
618 Window xwin
= (Window
) GetXWindow();
619 Display
*xdisp
= (Display
*) GetXDisplay();
621 XMapWindow(xdisp
, xwin
);
623 XUnmapWindow(xdisp
, xwin
);
629 // Raise the window to the top of the Z order
630 void wxWindow::Raise()
632 Widget wTop
= (Widget
) GetTopWidget();
633 Window window
= XtWindow(wTop
);
634 XRaiseWindow(XtDisplay(wTop
), window
);
637 // Lower the window to the bottom of the Z order
638 void wxWindow::Lower()
640 Widget wTop
= (Widget
) GetTopWidget();
641 Window window
= XtWindow(wTop
);
642 XLowerWindow(XtDisplay(wTop
), window
);
645 void wxWindow::SetTitle(const wxString
& title
)
647 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
650 wxString
wxWindow::GetTitle() const
653 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
655 return wxString(title
);
658 void wxWindow::CaptureMouse()
663 Widget wMain
= (Widget
)GetMainWidget();
665 XtAddGrab(wMain
, TRUE
, FALSE
);
667 m_winCaptured
= TRUE
;
670 void wxWindow::ReleaseMouse()
672 if ( !m_winCaptured
)
675 Widget wMain
= (Widget
)GetMainWidget();
679 m_winCaptured
= FALSE
;
682 bool wxWindow::SetFont(const wxFont
& font
)
684 if ( !wxWindowBase::SetFont(font
) )
695 bool wxWindow::SetCursor(const wxCursor
& cursor
)
697 if ( !wxWindowBase::SetCursor(cursor
) )
703 wxASSERT_MSG( m_cursor
.Ok(),
704 _T("cursor must be valid after call to the base version"));
706 WXDisplay
*dpy
= GetXDisplay();
707 WXCursor x_cursor
= m_cursor
.GetXCursor(dpy
);
709 Widget w
= (Widget
) GetMainWidget();
710 Window win
= XtWindow(w
);
711 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
716 // Coordinates relative to the window
717 void wxWindow::WarpPointer (int x
, int y
)
719 Widget wClient
= (Widget
)GetClientWidget();
721 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
724 // ---------------------------------------------------------------------------
726 // ---------------------------------------------------------------------------
728 int wxWindow::GetScrollPos(int orient
) const
730 if (orient
== wxHORIZONTAL
)
736 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
740 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
748 // This now returns the whole range, not just the number of positions that we
750 int wxWindow::GetScrollRange(int orient
) const
752 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
753 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
756 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
760 int wxWindow::GetScrollThumb(int orient
) const
762 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
763 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
766 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
770 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
772 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
776 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
779 SetInternalScrollPos((wxOrientation
)orient
, pos
);
782 // New function that will replace some of the above.
783 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
784 int range
, bool WXUNUSED(refresh
))
787 GetSize(& oldW
, & oldH
);
791 if (thumbVisible
== 0)
794 if (thumbVisible
> range
)
795 thumbVisible
= range
;
797 // Save the old state to see if it changed
798 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
800 if (orient
== wxHORIZONTAL
)
802 if (thumbVisible
== range
)
805 DestroyScrollbar(wxHORIZONTAL
);
810 CreateScrollbar(wxHORIZONTAL
);
813 if (orient
== wxVERTICAL
)
815 if (thumbVisible
== range
)
818 DestroyScrollbar(wxVERTICAL
);
823 CreateScrollbar(wxVERTICAL
);
826 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
828 if (oldScrollBar
!= newScrollBar
)
830 // This is important! Without it, scrollbars misbehave badly.
831 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
832 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
833 XtRealizeWidget((Widget
) m_scrolledWindow
);
834 XtManageChild((Widget
) m_scrolledWindow
);
839 XtVaSetValues((Widget
) newScrollBar
,
843 XmNsliderSize
, thumbVisible
,
847 SetInternalScrollPos((wxOrientation
)orient
, pos
);
850 GetSize(& newW
, & newH
);
852 // Adjusting scrollbars can resize the canvas accidentally
853 if (newW
!= oldW
|| newH
!= oldH
)
854 SetSize(-1, -1, oldW
, oldH
);
857 // Does a physical scroll
858 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
863 // Use specified rectangle
864 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
868 // Use whole client area
870 GetClientSize(& w
, & h
);
873 int x1
= (dx
>= 0) ? x
: x
- dx
;
874 int y1
= (dy
>= 0) ? y
: y
- dy
;
875 int w1
= w
- abs(dx
);
876 int h1
= h
- abs(dy
);
877 int x2
= (dx
>= 0) ? x
+ dx
: x
;
878 int y2
= (dy
>= 0) ? y
+ dy
: y
;
882 dc
.SetLogicalFunction (wxCOPY
);
884 Widget widget
= (Widget
) GetMainWidget();
885 Window window
= XtWindow(widget
);
886 Display
* display
= XtDisplay(widget
);
888 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
889 x1
, y1
, w1
, h1
, x2
, y2
);
891 dc
.SetAutoSetting(TRUE
);
892 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
893 dc
.SetBrush(brush
); // FIXME: needed?
895 // We'll add rectangles to the list of update rectangles according to which
896 // bits we've exposed.
901 wxRect
*rect
= new wxRect
;
907 XFillRectangle(display
, window
,
908 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
912 rect
->width
= rect
->width
;
913 rect
->height
= rect
->height
;
915 updateRects
.Append((wxObject
*) rect
);
919 wxRect
*rect
= new wxRect
;
921 rect
->x
= x
+ w
+ dx
;
926 XFillRectangle(display
, window
,
927 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
932 rect
->width
= rect
->width
;
933 rect
->height
= rect
->height
;
935 updateRects
.Append((wxObject
*) rect
);
939 wxRect
*rect
= new wxRect
;
946 XFillRectangle(display
, window
,
947 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
951 rect
->width
= rect
->width
;
952 rect
->height
= rect
->height
;
954 updateRects
.Append((wxObject
*) rect
);
958 wxRect
*rect
= new wxRect
;
961 rect
->y
= y
+ h
+ dy
;
965 XFillRectangle(display
, window
,
966 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
970 rect
->width
= rect
->width
;
971 rect
->height
= rect
->height
;
973 updateRects
.Append((wxObject
*) rect
);
975 dc
.SetBrush(wxNullBrush
);
977 // Now send expose events
979 wxNode
* node
= updateRects
.First();
982 wxRect
* rect
= (wxRect
*) node
->Data();
986 event
.display
= display
;
987 event
.send_event
= True
;
988 event
.window
= window
;
992 event
.width
= rect
->width
;
993 event
.height
= rect
->height
;
997 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1003 // Delete the update rects
1004 node
= updateRects
.First();
1007 wxRect
* rect
= (wxRect
*) node
->Data();
1009 node
= node
->Next();
1012 XmUpdateDisplay((Widget
) GetMainWidget());
1015 // ---------------------------------------------------------------------------
1017 // ---------------------------------------------------------------------------
1019 #if wxUSE_DRAG_AND_DROP
1021 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1028 // Old style file-manager drag&drop
1029 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1034 // ----------------------------------------------------------------------------
1036 // ----------------------------------------------------------------------------
1040 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1045 #endif // wxUSE_TOOLTIPS
1047 // ----------------------------------------------------------------------------
1049 // ----------------------------------------------------------------------------
1051 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1053 Widget widget
= (Widget
) GetMainWidget();
1055 /* The menuId field seems to be usused, so we'll use it to
1056 indicate whether a menu is popped up or not:
1057 0: Not currently created as a popup
1058 -1: Created as a popup, but not active
1062 if (menu
->GetParent() && (menu
->GetId() != -1))
1065 if (menu
->GetMainWidget()) {
1066 menu
->DestroyMenu(TRUE
);
1069 menu
->SetId(1); /* Mark as popped-up */
1070 menu
->CreateMenu(NULL
, widget
, menu
);
1071 menu
->SetInvokingWindow(this);
1075 // menu->SetParent(parent);
1076 // parent->children->Append(menu); // Store menu for later deletion
1078 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1086 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1088 wxCanvas *canvas = (wxCanvas *) this;
1089 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1090 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1094 Display
*display
= XtDisplay (widget
);
1095 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1096 Window thisWindow
= XtWindow (widget
);
1098 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1099 &rootX
, &rootY
, &childWindow
);
1101 XButtonPressedEvent event
;
1102 event
.type
= ButtonPress
;
1108 event
.x_root
= rootX
;
1109 event
.y_root
= rootY
;
1111 XmMenuPosition (menuWidget
, &event
);
1112 XtManageChild (menuWidget
);
1117 // ---------------------------------------------------------------------------
1118 // moving and resizing
1119 // ---------------------------------------------------------------------------
1121 bool wxWindow::PreResize()
1127 void wxWindow::DoGetSize(int *x
, int *y
) const
1131 CanvasGetSize(x
, y
);
1135 Widget widget
= (Widget
) GetTopWidget();
1137 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1141 void wxWindow::DoGetPosition(int *x
, int *y
) const
1145 CanvasGetPosition(x
, y
);
1148 Widget widget
= (Widget
) GetTopWidget();
1150 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1152 // We may be faking the client origin. So a window that's really at (0, 30)
1153 // may appear (to wxWin apps) to be at (0, 0).
1156 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1164 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1166 Widget widget
= (Widget
) GetClientWidget();
1167 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1168 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1169 Window thisWindow
= XtWindow(widget
);
1174 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1177 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1179 Widget widget
= (Widget
) GetClientWidget();
1180 Display
*display
= XtDisplay(widget
);
1181 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1182 Window thisWindow
= XtWindow(widget
);
1187 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1191 // Get size *available for subwindows* i.e. excluding menu bar etc.
1192 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1194 Widget widget
= (Widget
) GetClientWidget();
1196 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1200 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1202 // A bit of optimization to help sort out the flickers.
1203 int oldX
, oldY
, oldW
, oldH
;
1204 GetSize(& oldW
, & oldH
);
1205 GetPosition(& oldX
, & oldY
);
1207 bool useOldPos
= FALSE
;
1208 bool useOldSize
= FALSE
;
1210 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
1212 else if (x
== oldX
&& y
== oldY
)
1215 if ((width
== -1) && (height
== -1))
1217 else if (width
== oldW
&& height
== oldH
)
1220 if (!wxNoOptimize::CanOptimize())
1222 useOldSize
= FALSE
; useOldPos
= FALSE
;
1225 if (useOldPos
&& useOldSize
)
1230 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
1233 Widget widget
= (Widget
) GetTopWidget();
1237 bool managed
= XtIsManaged( widget
);
1239 XtUnmanageChild(widget
);
1241 int xx
= x
; int yy
= y
;
1242 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1246 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1247 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
1248 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1249 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
1254 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1256 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1260 XtManageChild(widget
);
1262 // How about this bit. Maybe we don't need to generate size events
1263 // all the time -- they'll be generated when the window is sized anyway.
1265 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1266 sizeEvent
.SetEventObject(this);
1268 GetEventHandler()->ProcessEvent(sizeEvent
);
1272 void wxWindow::DoSetClientSize(int width
, int height
)
1276 CanvasSetClientSize(width
, height
);
1280 Widget widget
= (Widget
) GetTopWidget();
1283 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1285 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1287 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1288 sizeEvent
.SetEventObject(this);
1290 GetEventHandler()->ProcessEvent(sizeEvent
);
1293 // For implementation purposes - sometimes decorations make the client area
1295 wxPoint
wxWindow::GetClientAreaOrigin() const
1297 return wxPoint(0, 0);
1300 // Makes an adjustment to the window position (for example, a frame that has
1301 // a toolbar that it manages itself).
1302 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
1304 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
1306 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1307 x
+= pt
.x
; y
+= pt
.y
;
1311 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1318 wxFrame
*frame
= wxDynamicCast(this, wxFrame
);
1321 // TODO what about dialogs?
1325 Widget widget
= (Widget
) frame
->GetShellWidget();
1328 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1330 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1332 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1334 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1336 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1338 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1341 // ---------------------------------------------------------------------------
1343 // ---------------------------------------------------------------------------
1345 int wxWindow::GetCharHeight() const
1347 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1349 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1351 int direction
, ascent
, descent
;
1352 XCharStruct overall
;
1353 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1354 &descent
, &overall
);
1356 // return (overall.ascent + overall.descent);
1357 return (ascent
+ descent
);
1360 int wxWindow::GetCharWidth() const
1362 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1364 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1366 int direction
, ascent
, descent
;
1367 XCharStruct overall
;
1368 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1369 &descent
, &overall
);
1371 return overall
.width
;
1374 void wxWindow::GetTextExtent(const wxString
& string
,
1376 int *descent
, int *externalLeading
,
1377 const wxFont
*theFont
) const
1379 wxFont
*fontToUse
= (wxFont
*)theFont
;
1381 fontToUse
= (wxFont
*) & m_font
;
1383 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1385 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1387 int direction
, ascent
, descent2
;
1388 XCharStruct overall
;
1393 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1394 &ascent
, &descent2
, &overall
);
1397 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1398 &direction
, &ascent
, &descent2
, &overall
);
1401 *x
= (overall
.width
);
1403 *y
= (ascent
+ descent2
);
1405 *descent
= descent2
;
1406 if (externalLeading
)
1407 *externalLeading
= 0;
1410 // ----------------------------------------------------------------------------
1412 // ----------------------------------------------------------------------------
1414 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1416 m_needsRefresh
= TRUE
;
1417 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1418 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1420 XExposeEvent dummyEvent
;
1422 GetSize(&width
, &height
);
1424 dummyEvent
.type
= Expose
;
1425 dummyEvent
.display
= display
;
1426 dummyEvent
.send_event
= True
;
1427 dummyEvent
.window
= thisWindow
;
1430 dummyEvent
.x
= rect
->x
;
1431 dummyEvent
.y
= rect
->y
;
1432 dummyEvent
.width
= rect
->width
;
1433 dummyEvent
.height
= rect
->height
;
1439 dummyEvent
.width
= width
;
1440 dummyEvent
.height
= height
;
1442 dummyEvent
.count
= 0;
1446 wxClientDC
dc(this);
1447 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1448 dc
.SetBackground(backgroundBrush
);
1455 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1458 void wxWindow::Clear()
1460 wxClientDC
dc(this);
1461 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1462 dc
.SetBackground(brush
);
1466 void wxWindow::ClearUpdateRects()
1468 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1471 wxRect
* rect
= node
->GetData();
1473 node
= node
->GetNext();
1476 m_updateRects
.Clear();
1479 void wxWindow::DoPaint()
1481 //TODO : make a temporary gc so we can do the XCopyArea below
1482 if (m_backingPixmap
&& !m_needsRefresh
)
1486 GC tempGC
= (GC
) dc
.GetBackingGC();
1488 Widget widget
= (Widget
) GetMainWidget();
1493 // We have to test whether it's a wxScrolledWindow (hack!) because
1494 // otherwise we don't know how many pixels have been scrolled. We might
1495 // solve this in the future by defining virtual wxWindow functions to get
1496 // the scroll position in pixels. Or, each kind of scrolled window has to
1497 // implement backing stores itself, using generic wxWindows code.
1498 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1499 if ( scrolledWindow
)
1502 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1508 // TODO: This could be optimized further by only copying the areas in the
1509 // current update region.
1511 // Only blit the part visible in the client area. The backing pixmap
1512 // always starts at 0, 0 but we may be looking at only a portion of it.
1513 wxSize clientArea
= GetClientSize();
1514 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1515 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1517 // Copy whichever is samller, the amount of pixmap we have to copy,
1518 // or the size of the client area.
1519 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1520 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1522 // Make sure we're not negative
1523 toBlitX
= wxMax(0, toBlitX
);
1524 toBlitY
= wxMax(0, toBlitY
);
1529 (Pixmap
) m_backingPixmap
,
1532 scrollPosX
, scrollPosY
, // Start at the scroll position
1533 toBlitX
, toBlitY
, // How much of the pixmap to copy
1539 // Set an erase event first
1540 wxEraseEvent
eraseEvent(GetId());
1541 eraseEvent
.SetEventObject(this);
1542 GetEventHandler()->ProcessEvent(eraseEvent
);
1544 wxPaintEvent
event(GetId());
1545 event
.SetEventObject(this);
1546 GetEventHandler()->ProcessEvent(event
);
1548 m_needsRefresh
= FALSE
;
1552 // ----------------------------------------------------------------------------
1554 // ----------------------------------------------------------------------------
1556 // Responds to colour changes: passes event on to children.
1557 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1559 wxWindowList::Node
*node
= GetChildren().GetFirst();
1562 // Only propagate to non-top-level windows
1563 wxWindow
*win
= node
->GetData();
1564 if ( win
->GetParent() )
1566 wxSysColourChangedEvent event2
;
1567 event
.m_eventObject
= win
;
1568 win
->GetEventHandler()->ProcessEvent(event2
);
1571 node
= node
->GetNext();
1575 void wxWindow::OnIdle(wxIdleEvent
& event
)
1577 // This calls the UI-update mechanism (querying windows for
1578 // menu/toolbar/control state information)
1582 // ----------------------------------------------------------------------------
1584 // ----------------------------------------------------------------------------
1586 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1588 if (!m_acceleratorTable
.Ok())
1591 int count
= m_acceleratorTable
.GetCount();
1592 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1594 for (i
= 0; i
< count
; i
++)
1596 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1597 if (entry
->MatchesEvent(event
))
1599 // Bingo, we have a match. Now find a control that matches the entry
1602 // Need to go up to the top of the window hierarchy, since it might
1603 // be e.g. a menu item
1604 wxWindow
* parent
= this;
1605 while ( parent
&& !parent
->IsTopLevel() )
1606 parent
= parent
->GetParent();
1611 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1614 // Try for a menu command
1615 if (frame
->GetMenuBar())
1617 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
1620 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1621 commandEvent
.SetEventObject(frame
);
1623 // If ProcessEvent returns TRUE (it was handled), then
1624 // the calling code will skip the event handling.
1625 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1630 // Find a child matching the command id
1631 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1637 // Now we process those kinds of windows that we can.
1638 // For now, only buttons.
1639 if ( wxDynamicCast(child
, wxButton
) )
1641 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1642 commandEvent
.SetEventObject(child
);
1643 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1650 // We didn't match the key event against an accelerator.
1654 // ============================================================================
1655 // Motif-specific stuff from here on
1656 // ============================================================================
1658 // ----------------------------------------------------------------------------
1659 // function which maintain the global hash table mapping Widgets to wxWindows
1660 // ----------------------------------------------------------------------------
1662 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1664 wxWindow
*oldItem
= NULL
;
1665 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1667 wxLogDebug("Widget table clash: new widget is %ld, %s",
1668 (long)w
, win
->GetClassInfo()->GetClassName());
1672 wxWidgetHashTable
->Put((long) w
, win
);
1674 wxLogDebug("Widget 0x%08x <-> window %p (%s)",
1675 w
, win
, win
->GetClassInfo()->GetClassName());
1680 wxWindow
*wxGetWindowFromTable(Widget w
)
1682 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1685 void wxDeleteWindowFromTable(Widget w
)
1687 wxWidgetHashTable
->Delete((long)w
);
1690 // ----------------------------------------------------------------------------
1691 // add/remove window from the table
1692 // ----------------------------------------------------------------------------
1694 // Add to hash table, add event handler
1695 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
1696 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1698 wxAddWindowToTable((Widget
) mainWidget
, this);
1699 if (CanAddEventHandler())
1701 XtAddEventHandler((Widget
) mainWidget
,
1702 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1704 wxPanelItemEventHandler
,
1711 XtOverrideTranslations ((Widget
) mainWidget
,
1712 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1713 XtFree ((char *) ptr
);
1716 // Some widgets have a parent form widget, e.g. wxRadioBox
1719 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1723 XtOverrideTranslations ((Widget
) formWidget
,
1724 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1725 XtFree ((char *) ptr
);
1732 SetSize (x
, y
, width
, height
);
1737 // Remove event handler, remove from hash table
1738 bool wxWindow::DetachWidget(WXWidget widget
)
1740 if (CanAddEventHandler())
1742 XtRemoveEventHandler((Widget
) widget
,
1743 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1745 wxPanelItemEventHandler
,
1749 wxDeleteWindowFromTable((Widget
) widget
);
1753 // ----------------------------------------------------------------------------
1754 // Motif-specific accessors
1755 // ----------------------------------------------------------------------------
1757 // Get the underlying X window
1758 WXWindow
wxWindow::GetXWindow() const
1760 Widget wMain
= (Widget
)GetMainWidget();
1762 return (WXWindow
) XtWindow(wMain
);
1764 return (WXWindow
) 0;
1767 // Get the underlying X display
1768 WXDisplay
*wxWindow::GetXDisplay() const
1770 Widget wMain
= (Widget
)GetMainWidget();
1772 return (WXDisplay
*) XtDisplay(wMain
);
1774 return (WXDisplay
*) NULL
;
1777 WXWidget
wxWindow::GetMainWidget() const
1780 return m_drawingArea
;
1782 return m_mainWidget
;
1785 WXWidget
wxWindow::GetClientWidget() const
1787 if (m_drawingArea
!= (WXWidget
) 0)
1788 return m_drawingArea
;
1790 return GetMainWidget();
1793 WXWidget
wxWindow::GetTopWidget() const
1795 return GetMainWidget();
1798 WXWidget
wxWindow::GetLabelWidget() const
1800 return GetMainWidget();
1803 // ----------------------------------------------------------------------------
1805 // ----------------------------------------------------------------------------
1807 // All widgets should have this as their resize proc.
1808 // OnSize sent to wxWindow via client data.
1809 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
1811 wxWindow
*win
= wxGetWindowFromTable(w
);
1815 if (win
->PreResize())
1818 win
->GetSize(&width
, &height
);
1819 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1820 sizeEvent
.SetEventObject(win
);
1821 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1825 static void wxCanvasRepaintProc(Widget drawingArea
,
1826 XtPointer clientData
,
1827 XmDrawingAreaCallbackStruct
* cbs
)
1829 if (!wxGetWindowFromTable(drawingArea
))
1832 XEvent
* event
= cbs
->event
;
1833 wxWindow
* win
= (wxWindow
*) clientData
;
1835 switch (event
->type
)
1839 if (event
-> xexpose
.count
== 0)
1842 wxPaintEvent
event(win
->GetId());
1843 event
.SetEventObject(win
);
1844 win
->GetEventHandler()->ProcessEvent(event
);
1848 win
->ClearUpdateRects();
1852 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1853 event
->xexpose
.width
, event
->xexpose
.height
);
1860 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1861 static void wxCanvasEnterLeave(Widget drawingArea
,
1862 XtPointer clientData
,
1863 XCrossingEvent
* event
)
1865 XmDrawingAreaCallbackStruct cbs
;
1868 ((XCrossingEvent
&) ev
) = *event
;
1870 cbs
.reason
= XmCR_INPUT
;
1873 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1876 // Fix to make it work under Motif 1.0 (!)
1877 static void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
1879 #if XmVersion <= 1000
1880 XmDrawingAreaCallbackStruct cbs
;
1883 ev
= *((XEvent
*) event
);
1884 cbs
.reason
= XmCR_INPUT
;
1887 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1888 #endif // XmVersion <= 1000
1891 static void wxCanvasInputEvent(Widget drawingArea
,
1893 XmDrawingAreaCallbackStruct
* cbs
)
1895 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1901 if (cbs
->reason
!= XmCR_INPUT
)
1904 local_event
= *(cbs
->event
); // We must keep a copy!
1906 switch (local_event
.xany
.type
)
1914 wxEventType eventType
= wxEVT_NULL
;
1916 if (local_event
.xany
.type
== EnterNotify
)
1918 //if (local_event.xcrossing.mode!=NotifyNormal)
1919 // return ; // Ignore grab events
1920 eventType
= wxEVT_ENTER_WINDOW
;
1921 // canvas->GetEventHandler()->OnSetFocus();
1923 else if (local_event
.xany
.type
== LeaveNotify
)
1925 //if (local_event.xcrossing.mode!=NotifyNormal)
1926 // return ; // Ignore grab events
1927 eventType
= wxEVT_LEAVE_WINDOW
;
1928 // canvas->GetEventHandler()->OnKillFocus();
1930 else if (local_event
.xany
.type
== MotionNotify
)
1932 eventType
= wxEVT_MOTION
;
1933 if (local_event
.xmotion
.is_hint
== NotifyHint
)
1936 Display
*dpy
= XtDisplay (drawingArea
);
1938 XQueryPointer (dpy
, XtWindow (drawingArea
),
1940 &local_event
.xmotion
.x_root
,
1941 &local_event
.xmotion
.y_root
,
1942 &local_event
.xmotion
.x
,
1943 &local_event
.xmotion
.y
,
1944 &local_event
.xmotion
.state
);
1951 else if (local_event
.xany
.type
== ButtonPress
)
1953 if (local_event
.xbutton
.button
== Button1
)
1955 eventType
= wxEVT_LEFT_DOWN
;
1956 canvas
->SetButton1(TRUE
);
1958 else if (local_event
.xbutton
.button
== Button2
)
1960 eventType
= wxEVT_MIDDLE_DOWN
;
1961 canvas
->SetButton2(TRUE
);
1963 else if (local_event
.xbutton
.button
== Button3
)
1965 eventType
= wxEVT_RIGHT_DOWN
;
1966 canvas
->SetButton3(TRUE
);
1969 else if (local_event
.xany
.type
== ButtonRelease
)
1971 if (local_event
.xbutton
.button
== Button1
)
1973 eventType
= wxEVT_LEFT_UP
;
1974 canvas
->SetButton1(FALSE
);
1976 else if (local_event
.xbutton
.button
== Button2
)
1978 eventType
= wxEVT_MIDDLE_UP
;
1979 canvas
->SetButton2(FALSE
);
1981 else if (local_event
.xbutton
.button
== Button3
)
1983 eventType
= wxEVT_RIGHT_UP
;
1984 canvas
->SetButton3(FALSE
);
1988 wxMouseEvent
wxevent (eventType
);
1990 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1991 || (event_left_is_down (&local_event
)
1992 && (eventType
!= wxEVT_LEFT_UP
)));
1993 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1994 || (event_middle_is_down (&local_event
)
1995 && (eventType
!= wxEVT_MIDDLE_UP
)));
1996 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1997 || (event_right_is_down (&local_event
)
1998 && (eventType
!= wxEVT_RIGHT_UP
)));
2000 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2001 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2002 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2003 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2004 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2006 // Now check if we need to translate this event into a double click
2007 if (TRUE
) // canvas->doubleClickAllowed)
2009 if (wxevent
.ButtonDown())
2011 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2013 // get button and time-stamp
2015 if (wxevent
.LeftDown())
2017 else if (wxevent
.MiddleDown())
2019 else if (wxevent
.RightDown())
2021 long ts
= wxevent
.GetTimestamp();
2023 // check, if single or double click
2024 int buttonLast
= canvas
->GetLastClickedButton();
2025 long lastTS
= canvas
->GetLastClickTime();
2026 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2029 canvas
->SetLastClick(0, ts
);
2030 switch ( eventType
)
2032 case wxEVT_LEFT_DOWN
:
2033 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2035 case wxEVT_MIDDLE_DOWN
:
2036 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2038 case wxEVT_RIGHT_DOWN
:
2039 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2049 // not fast enough or different button
2050 canvas
->SetLastClick(button
, ts
);
2055 wxevent
.SetId(canvas
->GetId());
2056 wxevent
.SetEventObject(canvas
);
2057 wxevent
.m_x
= local_event
.xbutton
.x
;
2058 wxevent
.m_y
= local_event
.xbutton
.y
;
2059 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2061 if (eventType
== wxEVT_ENTER_WINDOW
||
2062 eventType
== wxEVT_LEAVE_WINDOW
||
2063 eventType
== wxEVT_MOTION
2073 XComposeStatus compose
;
2074 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, &compose
);
2077 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2078 int id
= wxCharCodeXToWX (keySym
);
2080 wxEventType eventType
= wxEVT_CHAR
;
2082 wxKeyEvent
event (eventType
);
2084 if (local_event
.xkey
.state
& ShiftMask
)
2085 event
.m_shiftDown
= TRUE
;
2086 if (local_event
.xkey
.state
& ControlMask
)
2087 event
.m_controlDown
= TRUE
;
2088 if (local_event
.xkey
.state
& Mod3Mask
)
2089 event
.m_altDown
= TRUE
;
2090 if (local_event
.xkey
.state
& Mod1Mask
)
2091 event
.m_metaDown
= TRUE
;
2092 event
.SetEventObject(canvas
);
2093 event
.m_keyCode
= id
;
2094 event
.SetTimestamp(local_event
.xkey
.time
);
2098 // Implement wxFrame::OnCharHook by checking ancestor.
2099 wxWindow
*parent
= canvas
->GetParent();
2100 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2101 parent
= parent
->GetParent();
2105 event
.SetEventType(wxEVT_CHAR_HOOK
);
2106 if (parent
->GetEventHandler()->ProcessEvent(event
))
2110 // For simplicity, OnKeyDown is the same as OnChar
2111 // TODO: filter modifier key presses from OnChar
2112 event
.SetEventType(wxEVT_KEY_DOWN
);
2114 // Only process OnChar if OnKeyDown didn't swallow it
2115 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2117 event
.SetEventType(wxEVT_CHAR
);
2118 canvas
->GetEventHandler()->ProcessEvent (event
);
2126 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2127 int id
= wxCharCodeXToWX (keySym
);
2129 wxKeyEvent
event (wxEVT_KEY_UP
);
2131 if (local_event
.xkey
.state
& ShiftMask
)
2132 event
.m_shiftDown
= TRUE
;
2133 if (local_event
.xkey
.state
& ControlMask
)
2134 event
.m_controlDown
= TRUE
;
2135 if (local_event
.xkey
.state
& Mod3Mask
)
2136 event
.m_altDown
= TRUE
;
2137 if (local_event
.xkey
.state
& Mod1Mask
)
2138 event
.m_metaDown
= TRUE
;
2139 event
.SetEventObject(canvas
);
2140 event
.m_keyCode
= id
;
2141 event
.SetTimestamp(local_event
.xkey
.time
);
2145 canvas
->GetEventHandler()->ProcessEvent (event
);
2151 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2153 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2154 event
.SetEventObject(canvas
);
2155 canvas
->GetEventHandler()->ProcessEvent(event
);
2161 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2163 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2164 event
.SetEventObject(canvas
);
2165 canvas
->GetEventHandler()->ProcessEvent(event
);
2174 static void wxPanelItemEventHandler(Widget wid
,
2175 XtPointer client_data
,
2177 Boolean
*continueToDispatch
)
2179 // Widget can be a label or the actual widget.
2181 wxWindow
*window
= wxGetWindowFromTable(wid
);
2184 wxMouseEvent
wxevent(0);
2185 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2187 window
->GetEventHandler()->ProcessEvent(wxevent
);
2191 // TODO: probably the key to allowing default behaviour to happen. Say we
2192 // set a m_doDefault flag to FALSE at the start of this function. Then in
2193 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2194 // TRUE, indicating that default processing can happen. Thus, behaviour can
2195 // appear to be overridden just by adding an event handler and not calling
2196 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2197 // way of handling drawing area events, to simplify things.
2198 *continueToDispatch
= True
;
2201 static void wxScrollBarCallback(Widget scrollbar
,
2202 XtPointer clientData
,
2203 XmScaleCallbackStruct
*cbs
)
2205 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2206 int orientation
= (int) clientData
;
2208 wxEventType eventType
= wxEVT_NULL
;
2209 switch (cbs
->reason
)
2211 case XmCR_INCREMENT
:
2213 eventType
= wxEVT_SCROLL_LINEDOWN
;
2216 case XmCR_DECREMENT
:
2218 eventType
= wxEVT_SCROLL_LINEUP
;
2223 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2226 case XmCR_VALUE_CHANGED
:
2228 // TODO: Should this be intercepted too, or will it cause
2229 // duplicate events?
2230 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2233 case XmCR_PAGE_INCREMENT
:
2235 eventType
= wxEVT_SCROLL_PAGEDOWN
;
2238 case XmCR_PAGE_DECREMENT
:
2240 eventType
= wxEVT_SCROLL_PAGEUP
;
2245 eventType
= wxEVT_SCROLL_TOP
;
2248 case XmCR_TO_BOTTOM
:
2250 eventType
= wxEVT_SCROLL_BOTTOM
;
2255 // Should never get here
2256 wxFAIL_MSG("Unknown scroll event.");
2261 wxScrollEvent
event(eventType
, win
->GetId());
2262 event
.SetEventObject(win
);
2263 event
.SetPosition(cbs
->value
);
2264 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
2266 win
->GetEventHandler()->ProcessEvent(event
);
2269 // For repainting arbitrary windows
2270 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2275 wxWindow
* win
= wxGetWindowFromTable(w
);
2279 switch(event
-> type
)
2283 window
= (Window
) win
-> GetXWindow();
2284 display
= (Display
*) win
-> GetXDisplay();
2286 if (event
-> xexpose
.count
== 0)
2290 win
->ClearUpdateRects();
2294 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2295 event
->xexpose
.width
, event
->xexpose
.height
);
2303 // ----------------------------------------------------------------------------
2304 // CanvaseXXXSize() functions
2305 // ----------------------------------------------------------------------------
2307 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2308 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2310 // A bit of optimization to help sort out the flickers.
2311 int oldX
, oldY
, oldW
, oldH
;
2312 GetSize(& oldW
, & oldH
);
2313 GetPosition(& oldX
, & oldY
);
2315 bool useOldPos
= FALSE
;
2316 bool useOldSize
= FALSE
;
2318 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2320 else if (x
== oldX
&& y
== oldY
)
2323 if ((w
== -1) && (h
== -1))
2325 else if (w
== oldW
&& h
== oldH
)
2328 if (!wxNoOptimize::CanOptimize())
2330 useOldSize
= FALSE
; useOldPos
= FALSE
;
2333 if (useOldPos
&& useOldSize
)
2336 Widget drawingArea
= (Widget
) m_drawingArea
;
2337 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2340 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2341 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2343 int xx
= x
; int yy
= y
;
2344 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2348 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2350 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2354 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2356 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2368 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2369 short thick
, margin
;
2370 XtVaGetValues ((Widget
) m_borderWidget
,
2371 XmNshadowThickness
, &thick
,
2372 XmNmarginWidth
, &margin
,
2374 w
-= 2 * (thick
+ margin
);
2377 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2381 XtVaGetValues ((Widget
) m_scrolledWindow
,
2382 XmNspacing
, &spacing
,
2383 XmNverticalScrollBar
, &sbar
,
2387 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2391 w
-= (spacing
+ wsbar
);
2394 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2401 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2402 short thick
, margin
;
2403 XtVaGetValues ((Widget
) m_borderWidget
,
2404 XmNshadowThickness
, &thick
,
2405 XmNmarginHeight
, &margin
,
2407 h
-= 2 * (thick
+ margin
);
2410 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2414 XtVaGetValues ((Widget
) m_scrolledWindow
,
2415 XmNspacing
, &spacing
,
2416 XmNhorizontalScrollBar
, &sbar
,
2420 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2424 h
-= (spacing
+ wsbar
);
2427 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2433 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2434 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2438 GetClientSize (&ww
, &hh
);
2439 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2440 sizeEvent
.SetEventObject(this);
2442 GetEventHandler()->ProcessEvent(sizeEvent
);
2446 void wxWindow::CanvasSetClientSize (int w
, int h
)
2448 Widget drawingArea
= (Widget
) m_drawingArea
;
2450 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2453 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2455 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2458 // TODO: is this necessary?
2459 allowRepainting
= FALSE
;
2461 XSync (XtDisplay (drawingArea
), FALSE
);
2463 while (XtAppPending (wxTheApp
->appContext
))
2465 XFlush (XtDisplay (drawingArea
));
2466 XtAppNextEvent (wxTheApp
->appContext
, &event
);
2467 XtDispatchEvent (&event
);
2471 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2474 allowRepainting
= TRUE
;
2477 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2478 sizeEvent
.SetEventObject(this);
2480 GetEventHandler()->ProcessEvent(sizeEvent
);
2484 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2486 // Must return the same thing that was set via SetClientSize
2488 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2493 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2496 if ((Widget
) m_borderWidget
)
2497 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2498 else if ((Widget
) m_scrolledWindow
)
2499 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2501 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2507 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2510 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2512 // We may be faking the client origin.
2513 // So a window that's really at (0, 30) may appear
2514 // (to wxWin apps) to be at (0, 0).
2517 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2526 // ----------------------------------------------------------------------------
2527 // TranslateXXXEvent() functions
2528 // ----------------------------------------------------------------------------
2530 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2532 switch (xevent
->xany
.type
)
2540 wxEventType eventType
= wxEVT_NULL
;
2542 if (xevent
->xany
.type
== LeaveNotify
)
2544 win
->SetButton1(FALSE
);
2545 win
->SetButton2(FALSE
);
2546 win
->SetButton3(FALSE
);
2549 else if (xevent
->xany
.type
== MotionNotify
)
2551 eventType
= wxEVT_MOTION
;
2553 else if (xevent
->xany
.type
== ButtonPress
)
2555 if (xevent
->xbutton
.button
== Button1
)
2557 eventType
= wxEVT_LEFT_DOWN
;
2558 win
->SetButton1(TRUE
);
2560 else if (xevent
->xbutton
.button
== Button2
)
2562 eventType
= wxEVT_MIDDLE_DOWN
;
2563 win
->SetButton2(TRUE
);
2565 else if (xevent
->xbutton
.button
== Button3
)
2567 eventType
= wxEVT_RIGHT_DOWN
;
2568 win
->SetButton3(TRUE
);
2571 else if (xevent
->xany
.type
== ButtonRelease
)
2573 if (xevent
->xbutton
.button
== Button1
)
2575 eventType
= wxEVT_LEFT_UP
;
2576 win
->SetButton1(FALSE
);
2578 else if (xevent
->xbutton
.button
== Button2
)
2580 eventType
= wxEVT_MIDDLE_UP
;
2581 win
->SetButton2(FALSE
);
2583 else if (xevent
->xbutton
.button
== Button3
)
2585 eventType
= wxEVT_RIGHT_UP
;
2586 win
->SetButton3(FALSE
);
2595 wxevent
.SetEventType(eventType
);
2598 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2601 win
->GetPosition(&x2
, &y2
);
2603 // The button x/y must be translated to wxWindows
2604 // window space - the widget might be a label or button,
2608 if (widget
!= (Widget
)win
->GetMainWidget())
2614 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2615 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2617 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2618 || (event_left_is_down (xevent
)
2619 && (eventType
!= wxEVT_LEFT_UP
)));
2620 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2621 || (event_middle_is_down (xevent
)
2622 && (eventType
!= wxEVT_MIDDLE_UP
)));
2623 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2624 || (event_right_is_down (xevent
)
2625 && (eventType
!= wxEVT_RIGHT_UP
)));
2627 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2628 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2635 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2637 switch (xevent
->xany
.type
)
2645 XComposeStatus compose
;
2646 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, &compose
);
2648 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2649 int id
= wxCharCodeXToWX (keySym
);
2651 if (xevent
->xkey
.state
& ShiftMask
)
2652 wxevent
.m_shiftDown
= TRUE
;
2653 if (xevent
->xkey
.state
& ControlMask
)
2654 wxevent
.m_controlDown
= TRUE
;
2655 if (xevent
->xkey
.state
& Mod3Mask
)
2656 wxevent
.m_altDown
= TRUE
;
2657 if (xevent
->xkey
.state
& Mod1Mask
)
2658 wxevent
.m_metaDown
= TRUE
;
2659 wxevent
.SetEventObject(win
);
2660 wxevent
.m_keyCode
= id
;
2661 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2663 wxevent
.m_x
= xevent
->xbutton
.x
;
2664 wxevent
.m_y
= xevent
->xbutton
.y
;
2678 // ----------------------------------------------------------------------------
2680 // ----------------------------------------------------------------------------
2682 #define YAllocColor XAllocColor
2683 XColor g_itemColors
[5];
2684 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2687 static XmColorProc colorProc
;
2689 result
= wxNO_COLORS
;
2693 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2694 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2695 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2696 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2697 if (colorProc
== (XmColorProc
) NULL
)
2699 // Get a ptr to the actual function
2700 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2701 // And set it back to motif.
2702 XmSetColorCalculation (colorProc
);
2704 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2705 &g_itemColors
[wxFORE_INDEX
],
2706 &g_itemColors
[wxSELE_INDEX
],
2707 &g_itemColors
[wxTOPS_INDEX
],
2708 &g_itemColors
[wxBOTS_INDEX
]);
2709 result
= wxBACK_COLORS
;
2713 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2714 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2715 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2716 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2717 if (result
== wxNO_COLORS
)
2718 result
= wxFORE_COLORS
;
2721 Display
*dpy
= display
;
2722 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2726 /* 5 Colours to allocate */
2727 for (int i
= 0; i
< 5; i
++)
2728 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2729 result
= wxNO_COLORS
;
2733 /* Only 1 colour to allocate */
2734 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2735 result
= wxNO_COLORS
;
2742 // Changes the foreground and background colours to be derived from the current
2743 // background colour. To change the foreground colour, you must call
2744 // SetForegroundColour explicitly.
2745 void wxWindow::ChangeBackgroundColour()
2747 WXWidget mainWidget
= GetMainWidget();
2749 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2751 // This not necessary
2754 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
2756 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
2757 // Have to set the scrollbar colours back since
2758 // the scrolled window seemed to change them
2759 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
2762 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
2764 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
2769 void wxWindow::ChangeForegroundColour()
2771 WXWidget mainWidget
= GetMainWidget();
2773 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2774 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2775 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2778 // Change a widget's foreground and background colours.
2779 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
2781 // When should we specify the foreground, if it's calculated
2782 // by wxComputeColours?
2783 // Solution: say we start with the default (computed) foreground colour.
2784 // If we call SetForegroundColour explicitly for a control or window,
2785 // then the foreground is changed.
2786 // Therefore SetBackgroundColour computes the foreground colour, and
2787 // SetForegroundColour changes the foreground colour. The ordering is
2790 Widget w
= (Widget
)widget
;
2793 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
2798 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
2800 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
2803 XtVaSetValues ((Widget
) widget
,
2804 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
2805 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
2806 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
2807 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
2810 if (changeArmColour
)
2811 XtVaSetValues ((Widget
) widget
,
2812 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
2816 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2818 if ( !wxWindowBase::SetBackgroundColour(col
) )
2821 ChangeBackgroundColour();
2826 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2828 if ( !wxWindowBase::SetForegroundColour(col
) )
2831 ChangeForegroundColour();
2836 void wxWindow::ChangeFont(bool keepOriginalSize
)
2838 // Note that this causes the widget to be resized back
2839 // to its original size! We therefore have to set the size
2840 // back again. TODO: a better way in Motif?
2841 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2842 if (w
&& m_font
.Ok())
2844 int width
, height
, width1
, height1
;
2845 GetSize(& width
, & height
);
2847 // lesstif 0.87 hangs here
2848 #ifndef LESSTIF_VERSION
2850 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
2854 GetSize(& width1
, & height1
);
2855 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2857 SetSize(-1, -1, width
, height
);
2862 // ----------------------------------------------------------------------------
2864 // ----------------------------------------------------------------------------
2866 wxWindow
*wxGetActiveWindow()
2872 // ----------------------------------------------------------------------------
2873 // wxNoOptimize: switch off size optimization
2874 // ----------------------------------------------------------------------------
2876 int wxNoOptimize::ms_count
= 0;