1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "window.h"
25 #define XtDisplay XTDISPLAY
26 #define XtWindow XTWINDOW
27 #define XtScreen XTSCREEN
33 #include "wx/dcclient.h"
37 #include "wx/layout.h"
38 #include "wx/dialog.h"
39 #include "wx/listbox.h"
40 #include "wx/button.h"
41 #include "wx/settings.h"
42 #include "wx/msgdlg.h"
44 #include "wx/scrolwin.h"
45 #include "wx/module.h"
46 #include "wx/menuitem.h"
49 #if wxUSE_DRAG_AND_DROP
54 #pragma message disable nosimpint
58 #include <Xm/DrawingA.h>
59 #include <Xm/ScrolledW.h>
60 #include <Xm/ScrollBar.h>
63 #include <Xm/RowColumn.h> // for XmMenuPosition
65 #pragma message enable nosimpint
68 #include "wx/motif/private.h"
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 static const int SCROLL_MARGIN
= 4;
78 // ----------------------------------------------------------------------------
79 // global variables for this module
80 // ----------------------------------------------------------------------------
82 extern wxHashTable
*wxWidgetHashTable
;
83 static wxWindow
* g_captureWindow
= NULL
;
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
91 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
92 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
93 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
94 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
95 XmScrollBarCallbackStruct
*cbs
);
96 static void wxPanelItemEventHandler(Widget wid
,
97 XtPointer client_data
,
99 Boolean
*continueToDispatch
);
104 // Helper function for 16-bit fonts
105 static int str16len(const char *s
)
109 while (s
[0] && s
[1]) {
119 // ----------------------------------------------------------------------------
121 // ----------------------------------------------------------------------------
123 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
124 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
125 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
133 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
134 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
135 EVT_IDLE(wxWindow::OnIdle
)
138 // ============================================================================
140 // ============================================================================
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
148 Widget w
= (Widget
)widget
;
156 bool wxWindow::MapOrUnmap(WXWidget widget
, bool map
)
158 Widget w
= (Widget
)widget
;
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 void wxWindow::Init()
176 // generic initializations first
180 m_needsRefresh
= TRUE
;
181 m_mainWidget
= (WXWidget
) 0;
185 m_button3Pressed
= FALSE
;
187 m_winCaptured
= FALSE
;
190 m_isBeingDeleted
= FALSE
;
196 m_drawingArea
= (WXWidget
) 0;
204 m_backingPixmap
= (WXPixmap
) 0;
213 m_canAddEventHandler
= FALSE
;
216 // real construction (Init() must have been called before!)
217 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
221 const wxString
& name
)
223 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
225 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
227 parent
->AddChild(this);
229 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
230 m_foregroundColour
= *wxBLACK
;
232 //// TODO: we should probably optimize by only creating a
233 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
234 //// But for now, let's simplify things by always creating the
235 //// drawing area, since otherwise the translations are different.
237 // New translations for getting mouse motion feedback
238 static const String translations
=
239 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
240 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
241 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
242 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
243 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
244 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
245 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
246 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
247 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
248 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
249 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
250 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
251 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
252 <Key>: DrawingAreaInput()";
254 XtActionsRec actions
[1];
255 actions
[0].string
= "wxCanvasMotionEvent";
256 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
257 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
259 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
261 if (style
& wxSIMPLE_BORDER
)
263 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
266 xmFrameWidgetClass
, parentWidget
,
267 XmNshadowType
, XmSHADOW_IN
,
268 XmNshadowThickness
, 1,
271 } else if (style
& wxSUNKEN_BORDER
)
273 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
276 xmFrameWidgetClass
, parentWidget
,
277 XmNshadowType
, XmSHADOW_IN
,
280 } else if (style
& wxRAISED_BORDER
)
282 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
285 xmFrameWidgetClass
, parentWidget
,
286 XmNshadowType
, XmSHADOW_OUT
,
291 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
294 xmScrolledWindowWidgetClass
,
295 m_borderWidget
? (Widget
) m_borderWidget
297 XmNresizePolicy
, XmRESIZE_NONE
,
299 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
300 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
304 XtTranslations ptr
= XtParseTranslationTable(translations
);
305 m_drawingArea
= (WXWidget
)XtVaCreateWidget
308 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
309 XmNunitType
, XmPIXELS
,
310 // XmNresizePolicy, XmRESIZE_ANY,
311 XmNresizePolicy
, XmRESIZE_NONE
,
314 XmNtranslations
, ptr
,
317 XtFree((char *) ptr
);
320 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
322 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
323 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
324 XtFree ((char *) ptr
);
328 wxAddWindowToTable((Widget
) m_drawingArea
, this);
329 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
331 // This order is very important in Motif 1.2.1
332 XtRealizeWidget ((Widget
) m_scrolledWindow
);
333 XtRealizeWidget ((Widget
) m_drawingArea
);
334 XtManageChild ((Widget
) m_drawingArea
);
336 ptr
= XtParseTranslationTable("<Configure>: resize()");
337 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
338 XtFree ((char *) ptr
);
340 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
341 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
345 display
= XtDisplay (scrolledWindow
);
346 xwindow
= XtWindow (drawingArea
);
350 (Widget
)m_drawingArea
,
351 PointerMotionHintMask
| EnterWindowMask
|
352 LeaveWindowMask
| FocusChangeMask
,
354 (XtEventHandler
) wxCanvasEnterLeave
,
358 // Scrolled widget needs to have its colour changed or we get a little blue
359 // square where the scrollbars abutt
360 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
361 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
362 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
364 XmScrolledWindowSetAreas(
365 (Widget
)m_scrolledWindow
,
366 (Widget
) 0, (Widget
) 0,
367 (Widget
) m_drawingArea
);
371 XtRealizeWidget ((Widget
) m_hScrollBar
);
373 XtRealizeWidget ((Widget
) m_vScrollBar
);
376 // Without this, the cursor may not be restored properly (e.g. in splitter
378 SetCursor(*wxSTANDARD_CURSOR
);
379 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
380 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
386 wxWindow::~wxWindow()
388 if (g_captureWindow
== this)
389 g_captureWindow
= NULL
;
391 m_isBeingDeleted
= TRUE
;
393 // Motif-specific actions first
394 WXWidget wMain
= GetMainWidget();
397 // Removes event handlers
404 m_parent
->RemoveChild( this );
406 // If m_drawingArea, we're a fully-fledged window with drawing area,
407 // scrollbars etc. (what wxCanvas used to be)
410 // Destroy children before destroying self
414 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
416 Widget w
= (Widget
) m_drawingArea
;
417 wxDeleteWindowFromTable(w
);
422 m_drawingArea
= (WXWidget
) 0;
425 // Only if we're _really_ a canvas (not a dialog box/panel)
426 if (m_scrolledWindow
)
428 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
433 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
434 XtUnmanageChild((Widget
) m_hScrollBar
);
438 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
439 XtUnmanageChild((Widget
) m_vScrollBar
);
443 XtDestroyWidget((Widget
) m_hScrollBar
);
445 XtDestroyWidget((Widget
) m_vScrollBar
);
447 UnmanageAndDestroy(m_scrolledWindow
);
451 XtDestroyWidget ((Widget
) m_borderWidget
);
452 m_borderWidget
= (WXWidget
) 0;
455 else // Why wasn't this here before? JACS 8/3/2000
459 // Destroy the window
462 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
463 // Child widgets will get destroyed automatically when a frame
464 // or dialog is destroyed, but before that you may get some memory
465 // leaks and potential layout problems if you delete and then add
468 // GRG, Feb/2000: commented this out when adding support for
469 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
470 // that this call crashed wxMotif under OS/2, so it seems
471 // that leaving it out is the right thing to do.
472 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
473 XtDestroyWidget((Widget
) GetMainWidget());
474 SetMainWidget((WXWidget
) NULL
);
478 // ----------------------------------------------------------------------------
479 // scrollbar management
480 // ----------------------------------------------------------------------------
483 void wxWindow::CreateScrollbar(wxOrientation orientation
)
485 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
487 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
489 // Add scrollbars if required
490 if (orientation
== wxHORIZONTAL
)
492 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
493 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
494 XmNorientation
, XmHORIZONTAL
,
496 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
497 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
498 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
499 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
500 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
501 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
502 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
503 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
505 XtVaSetValues (hScrollBar
,
510 m_hScrollBar
= (WXWidget
) hScrollBar
;
512 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
513 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
515 XtRealizeWidget(hScrollBar
);
517 XtVaSetValues((Widget
) m_scrolledWindow
,
518 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
523 wxAddWindowToTable( hScrollBar
, this );
526 if (orientation
== wxVERTICAL
)
528 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
529 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
530 XmNorientation
, XmVERTICAL
,
532 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
533 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
534 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
535 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
536 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
537 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
538 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
539 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
541 XtVaSetValues (vScrollBar
,
546 m_vScrollBar
= (WXWidget
) vScrollBar
;
547 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
548 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
550 XtRealizeWidget(vScrollBar
);
552 XtVaSetValues((Widget
) m_scrolledWindow
,
553 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
558 wxAddWindowToTable( vScrollBar
, this );
561 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
564 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
566 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
568 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
569 // Add scrollbars if required
570 if (orientation
== wxHORIZONTAL
)
574 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
575 XtDestroyWidget((Widget
) m_hScrollBar
);
577 m_hScrollBar
= (WXWidget
) 0;
580 XtVaSetValues((Widget
) m_scrolledWindow
,
581 XmNhorizontalScrollBar
, (Widget
) 0,
586 if (orientation
== wxVERTICAL
)
590 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
591 XtDestroyWidget((Widget
) m_vScrollBar
);
593 m_vScrollBar
= (WXWidget
) 0;
596 XtVaSetValues((Widget
) m_scrolledWindow
,
597 XmNverticalScrollBar
, (Widget
) 0,
601 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
604 // ---------------------------------------------------------------------------
606 // ---------------------------------------------------------------------------
608 void wxWindow::SetFocus()
610 Widget wMain
= (Widget
) GetMainWidget();
611 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
612 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
615 // Get the window with the focus
616 wxWindow
*wxWindowBase::FindFocus()
619 // (1) Can there be multiple focussed widgets in an application?
620 // In which case we need to find the top-level window that's
622 // (2) The widget with the focus may not be in the widget table
623 // depending on which widgets I put in the table
624 wxWindow
*winFocus
= (wxWindow
*)NULL
;
625 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
627 node
= node
->GetNext() )
629 wxWindow
*win
= node
->GetData();
631 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
633 if (w
!= (Widget
) NULL
)
635 winFocus
= wxGetWindowFromTable(w
);
644 bool wxWindow::Enable(bool enable
)
646 if ( !wxWindowBase::Enable(enable
) )
649 Widget wMain
= (Widget
)GetMainWidget();
652 XtSetSensitive(wMain
, enable
);
653 XmUpdateDisplay(wMain
);
659 bool wxWindow::Show(bool show
)
661 if ( !wxWindowBase::Show(show
) )
664 if (m_borderWidget
|| m_scrolledWindow
)
666 MapOrUnmap(m_drawingArea
, show
);
667 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
671 if ( !MapOrUnmap(GetTopWidget(), show
) )
672 MapOrUnmap(GetMainWidget(), show
);
676 Window xwin
= (Window
) GetXWindow();
677 Display
*xdisp
= (Display
*) GetXDisplay();
679 XMapWindow(xdisp
, xwin
);
681 XUnmapWindow(xdisp
, xwin
);
687 // Raise the window to the top of the Z order
688 void wxWindow::Raise()
690 Widget wTop
= (Widget
) GetTopWidget();
691 Window window
= XtWindow(wTop
);
692 XRaiseWindow(XtDisplay(wTop
), window
);
695 // Lower the window to the bottom of the Z order
696 void wxWindow::Lower()
698 Widget wTop
= (Widget
) GetTopWidget();
699 Window window
= XtWindow(wTop
);
700 XLowerWindow(XtDisplay(wTop
), window
);
703 void wxWindow::SetTitle(const wxString
& title
)
705 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
708 wxString
wxWindow::GetTitle() const
711 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
713 return wxString(title
);
716 void wxWindow::DoCaptureMouse()
718 g_captureWindow
= this;
722 Widget wMain
= (Widget
)GetMainWidget();
724 XtAddGrab(wMain
, TRUE
, FALSE
);
726 m_winCaptured
= TRUE
;
729 void wxWindow::DoReleaseMouse()
731 g_captureWindow
= NULL
;
732 if ( !m_winCaptured
)
735 Widget wMain
= (Widget
)GetMainWidget();
739 m_winCaptured
= FALSE
;
742 bool wxWindow::SetFont(const wxFont
& font
)
744 if ( !wxWindowBase::SetFont(font
) )
755 bool wxWindow::SetCursor(const wxCursor
& cursor
)
757 if ( !wxWindowBase::SetCursor(cursor
) )
763 // wxASSERT_MSG( m_cursor.Ok(),
764 // wxT("cursor must be valid after call to the base version"));
765 wxCursor
* cursor2
= NULL
;
767 cursor2
= & m_cursor
;
769 cursor2
= wxSTANDARD_CURSOR
;
771 WXDisplay
*dpy
= GetXDisplay();
772 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
774 Widget w
= (Widget
) GetMainWidget();
775 Window win
= XtWindow(w
);
776 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
781 // Coordinates relative to the window
782 void wxWindow::WarpPointer (int x
, int y
)
784 Widget wClient
= (Widget
)GetClientWidget();
786 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
789 // ---------------------------------------------------------------------------
791 // ---------------------------------------------------------------------------
793 int wxWindow::GetScrollPos(int orient
) const
795 if (orient
== wxHORIZONTAL
)
801 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
805 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
813 // This now returns the whole range, not just the number of positions that we
815 int wxWindow::GetScrollRange(int orient
) const
817 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
818 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
822 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
826 int wxWindow::GetScrollThumb(int orient
) const
828 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
829 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
832 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
836 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
838 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
842 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
845 SetInternalScrollPos((wxOrientation
)orient
, pos
);
848 // New function that will replace some of the above.
849 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
850 int range
, bool WXUNUSED(refresh
))
853 GetSize(& oldW
, & oldH
);
857 if (thumbVisible
== 0)
860 if (thumbVisible
> range
)
861 thumbVisible
= range
;
863 // Save the old state to see if it changed
864 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
866 if (orient
== wxHORIZONTAL
)
868 if (thumbVisible
== range
)
871 DestroyScrollbar(wxHORIZONTAL
);
876 CreateScrollbar(wxHORIZONTAL
);
879 if (orient
== wxVERTICAL
)
881 if (thumbVisible
== range
)
884 DestroyScrollbar(wxVERTICAL
);
889 CreateScrollbar(wxVERTICAL
);
892 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
894 if (oldScrollBar
!= newScrollBar
)
896 // This is important! Without it, scrollbars misbehave badly.
897 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
898 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
899 XtRealizeWidget((Widget
) m_scrolledWindow
);
900 XtManageChild((Widget
) m_scrolledWindow
);
905 XtVaSetValues((Widget
) newScrollBar
,
909 XmNsliderSize
, thumbVisible
,
913 SetInternalScrollPos((wxOrientation
)orient
, pos
);
916 GetSize(& newW
, & newH
);
918 // Adjusting scrollbars can resize the canvas accidentally
919 if (newW
!= oldW
|| newH
!= oldH
)
920 SetSize(-1, -1, oldW
, oldH
);
923 // Does a physical scroll
924 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
929 // Use specified rectangle
930 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
934 // Use whole client area
936 GetClientSize(& w
, & h
);
939 wxNode
*cnode
= m_children
.First();
942 wxWindow
*child
= (wxWindow
*) cnode
->Data();
945 child
->GetSize( &sx
, &sy
);
946 wxPoint
pos( child
->GetPosition() );
947 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
948 cnode
= cnode
->Next();
951 int x1
= (dx
>= 0) ? x
: x
- dx
;
952 int y1
= (dy
>= 0) ? y
: y
- dy
;
953 int w1
= w
- abs(dx
);
954 int h1
= h
- abs(dy
);
955 int x2
= (dx
>= 0) ? x
+ dx
: x
;
956 int y2
= (dy
>= 0) ? y
+ dy
: y
;
960 dc
.SetLogicalFunction (wxCOPY
);
962 Widget widget
= (Widget
) GetMainWidget();
963 Window window
= XtWindow(widget
);
964 Display
* display
= XtDisplay(widget
);
966 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
967 x1
, y1
, w1
, h1
, x2
, y2
);
969 dc
.SetAutoSetting(TRUE
);
970 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
971 dc
.SetBrush(brush
); // FIXME: needed?
973 // We'll add rectangles to the list of update rectangles according to which
974 // bits we've exposed.
979 wxRect
*rect
= new wxRect
;
985 XFillRectangle(display
, window
,
986 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
990 rect
->width
= rect
->width
;
991 rect
->height
= rect
->height
;
993 updateRects
.Append((wxObject
*) rect
);
997 wxRect
*rect
= new wxRect
;
999 rect
->x
= x
+ w
+ dx
;
1004 XFillRectangle(display
, window
,
1005 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1010 rect
->width
= rect
->width
;
1011 rect
->height
= rect
->height
;
1013 updateRects
.Append((wxObject
*) rect
);
1017 wxRect
*rect
= new wxRect
;
1024 XFillRectangle(display
, window
,
1025 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1029 rect
->width
= rect
->width
;
1030 rect
->height
= rect
->height
;
1032 updateRects
.Append((wxObject
*) rect
);
1036 wxRect
*rect
= new wxRect
;
1039 rect
->y
= y
+ h
+ dy
;
1043 XFillRectangle(display
, window
,
1044 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1048 rect
->width
= rect
->width
;
1049 rect
->height
= rect
->height
;
1051 updateRects
.Append((wxObject
*) rect
);
1053 dc
.SetBrush(wxNullBrush
);
1055 // Now send expose events
1057 wxNode
* node
= updateRects
.First();
1060 wxRect
* rect
= (wxRect
*) node
->Data();
1063 event
.type
= Expose
;
1064 event
.display
= display
;
1065 event
.send_event
= True
;
1066 event
.window
= window
;
1070 event
.width
= rect
->width
;
1071 event
.height
= rect
->height
;
1075 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1077 node
= node
->Next();
1081 // Delete the update rects
1082 node
= updateRects
.First();
1085 wxRect
* rect
= (wxRect
*) node
->Data();
1087 node
= node
->Next();
1090 XmUpdateDisplay((Widget
) GetMainWidget());
1093 // ---------------------------------------------------------------------------
1095 // ---------------------------------------------------------------------------
1097 #if wxUSE_DRAG_AND_DROP
1099 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1106 // Old style file-manager drag&drop
1107 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1112 // ----------------------------------------------------------------------------
1114 // ----------------------------------------------------------------------------
1118 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1123 #endif // wxUSE_TOOLTIPS
1125 // ----------------------------------------------------------------------------
1127 // ----------------------------------------------------------------------------
1129 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1131 Widget widget
= (Widget
) GetMainWidget();
1133 /* The menuId field seems to be usused, so we'll use it to
1134 indicate whether a menu is popped up or not:
1135 0: Not currently created as a popup
1136 -1: Created as a popup, but not active
1140 if (menu
->GetParent() && (menu
->GetId() != -1))
1143 if (menu
->GetMainWidget()) {
1144 menu
->DestroyMenu(TRUE
);
1147 menu
->SetId(1); /* Mark as popped-up */
1148 menu
->CreateMenu(NULL
, widget
, menu
);
1149 menu
->SetInvokingWindow(this);
1153 // menu->SetParent(parent);
1154 // parent->children->Append(menu); // Store menu for later deletion
1156 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1164 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1166 wxCanvas *canvas = (wxCanvas *) this;
1167 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1168 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1172 Display
*display
= XtDisplay (widget
);
1173 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1174 Window thisWindow
= XtWindow (widget
);
1176 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1177 &rootX
, &rootY
, &childWindow
);
1179 XButtonPressedEvent event
;
1180 event
.type
= ButtonPress
;
1186 event
.x_root
= rootX
;
1187 event
.y_root
= rootY
;
1189 XmMenuPosition (menuWidget
, &event
);
1190 XtManageChild (menuWidget
);
1195 // ---------------------------------------------------------------------------
1196 // moving and resizing
1197 // ---------------------------------------------------------------------------
1199 bool wxWindow::PreResize()
1205 void wxWindow::DoGetSize(int *x
, int *y
) const
1209 CanvasGetSize(x
, y
);
1213 Widget widget
= (Widget
) GetTopWidget();
1215 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1216 if(x
) *x
= xx
; if(y
) *y
= yy
;
1219 void wxWindow::DoGetPosition(int *x
, int *y
) const
1223 CanvasGetPosition(x
, y
);
1226 Widget widget
= (Widget
) GetTopWidget();
1228 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1230 // We may be faking the client origin. So a window that's really at (0, 30)
1231 // may appear (to wxWin apps) to be at (0, 0).
1234 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1239 if(x
) *x
= xx
; if(y
) *y
= yy
;
1242 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1244 Widget widget
= (Widget
) GetClientWidget();
1245 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1246 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1247 Window thisWindow
= XtWindow(widget
);
1252 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1255 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1257 Widget widget
= (Widget
) GetClientWidget();
1258 Display
*display
= XtDisplay(widget
);
1259 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1260 Window thisWindow
= XtWindow(widget
);
1265 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1269 // Get size *available for subwindows* i.e. excluding menu bar etc.
1270 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1272 Widget widget
= (Widget
) GetClientWidget();
1274 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1275 if(x
) *x
= xx
; if(y
) *y
= yy
;
1278 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1280 // A bit of optimization to help sort out the flickers.
1281 int oldX
, oldY
, oldW
, oldH
;
1282 GetSize(& oldW
, & oldH
);
1283 GetPosition(& oldX
, & oldY
);
1285 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1298 bool nothingChanged
= (x
== oldX
) && (y
== oldY
) &&
1299 (width
== oldW
) && (height
== oldH
);
1301 if (!wxNoOptimize::CanOptimize())
1303 nothingChanged
= FALSE
;
1306 if ( !nothingChanged
)
1310 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
1314 Widget widget
= (Widget
) GetTopWidget();
1318 bool managed
= XtIsManaged( widget
);
1320 XtUnmanageChild(widget
);
1324 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1326 DoMoveWindow(xx
, yy
, width
, height
);
1329 XtManageChild(widget
);
1331 // How about this bit. Maybe we don't need to generate size events
1332 // all the time -- they'll be generated when the window is sized anyway.
1334 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1335 sizeEvent
.SetEventObject(this);
1337 GetEventHandler()->ProcessEvent(sizeEvent
);
1342 void wxWindow::DoSetClientSize(int width
, int height
)
1346 CanvasSetClientSize(width
, height
);
1350 Widget widget
= (Widget
) GetTopWidget();
1353 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1355 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1357 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1358 sizeEvent
.SetEventObject(this);
1360 GetEventHandler()->ProcessEvent(sizeEvent
);
1363 // For implementation purposes - sometimes decorations make the client area
1365 wxPoint
wxWindow::GetClientAreaOrigin() const
1367 return wxPoint(0, 0);
1370 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1377 wxFrame
*frame
= wxDynamicCast(this, wxFrame
);
1380 // TODO what about dialogs?
1384 Widget widget
= (Widget
) frame
->GetShellWidget();
1387 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1389 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1391 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1393 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1395 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1397 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1400 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1402 XtVaSetValues((Widget
)GetTopWidget(),
1410 // ---------------------------------------------------------------------------
1412 // ---------------------------------------------------------------------------
1414 int wxWindow::GetCharHeight() const
1416 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1418 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1420 int direction
, ascent
, descent
;
1421 XCharStruct overall
;
1422 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1423 &descent
, &overall
);
1425 // return (overall.ascent + overall.descent);
1426 return (ascent
+ descent
);
1429 int wxWindow::GetCharWidth() const
1431 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1433 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1435 int direction
, ascent
, descent
;
1436 XCharStruct overall
;
1437 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1438 &descent
, &overall
);
1440 return overall
.width
;
1443 void wxWindow::GetTextExtent(const wxString
& string
,
1445 int *descent
, int *externalLeading
,
1446 const wxFont
*theFont
) const
1448 wxFont
*fontToUse
= (wxFont
*)theFont
;
1450 fontToUse
= (wxFont
*) & m_font
;
1452 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1454 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1456 int direction
, ascent
, descent2
;
1457 XCharStruct overall
;
1458 int slen
= string
.Len();
1462 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1463 &ascent
, &descent2
, &overall
);
1466 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1467 &direction
, &ascent
, &descent2
, &overall
);
1470 *x
= (overall
.width
);
1472 *y
= (ascent
+ descent2
);
1474 *descent
= descent2
;
1475 if (externalLeading
)
1476 *externalLeading
= 0;
1480 // ----------------------------------------------------------------------------
1482 // ----------------------------------------------------------------------------
1484 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1486 m_needsRefresh
= TRUE
;
1487 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1488 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1490 XExposeEvent dummyEvent
;
1492 GetSize(&width
, &height
);
1494 dummyEvent
.type
= Expose
;
1495 dummyEvent
.display
= display
;
1496 dummyEvent
.send_event
= True
;
1497 dummyEvent
.window
= thisWindow
;
1500 dummyEvent
.x
= rect
->x
;
1501 dummyEvent
.y
= rect
->y
;
1502 dummyEvent
.width
= rect
->width
;
1503 dummyEvent
.height
= rect
->height
;
1509 dummyEvent
.width
= width
;
1510 dummyEvent
.height
= height
;
1512 dummyEvent
.count
= 0;
1516 wxClientDC
dc(this);
1517 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1518 dc
.SetBackground(backgroundBrush
);
1525 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1528 void wxWindow::Clear()
1530 wxClientDC
dc(this);
1531 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1532 dc
.SetBackground(brush
);
1536 void wxWindow::ClearUpdateRects()
1538 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1541 wxRect
* rect
= node
->GetData();
1543 node
= node
->GetNext();
1546 m_updateRects
.Clear();
1549 void wxWindow::DoPaint()
1551 //TODO : make a temporary gc so we can do the XCopyArea below
1552 if (m_backingPixmap
&& !m_needsRefresh
)
1556 GC tempGC
= (GC
) dc
.GetBackingGC();
1558 Widget widget
= (Widget
) GetMainWidget();
1563 // We have to test whether it's a wxScrolledWindow (hack!) because
1564 // otherwise we don't know how many pixels have been scrolled. We might
1565 // solve this in the future by defining virtual wxWindow functions to get
1566 // the scroll position in pixels. Or, each kind of scrolled window has to
1567 // implement backing stores itself, using generic wxWindows code.
1568 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1569 if ( scrolledWindow
)
1572 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1578 // TODO: This could be optimized further by only copying the areas in the
1579 // current update region.
1581 // Only blit the part visible in the client area. The backing pixmap
1582 // always starts at 0, 0 but we may be looking at only a portion of it.
1583 wxSize clientArea
= GetClientSize();
1584 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1585 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1587 // Copy whichever is samller, the amount of pixmap we have to copy,
1588 // or the size of the client area.
1589 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1590 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1592 // Make sure we're not negative
1593 toBlitX
= wxMax(0, toBlitX
);
1594 toBlitY
= wxMax(0, toBlitY
);
1599 (Pixmap
) m_backingPixmap
,
1602 scrollPosX
, scrollPosY
, // Start at the scroll position
1603 toBlitX
, toBlitY
, // How much of the pixmap to copy
1609 // Set an erase event first
1610 wxEraseEvent
eraseEvent(GetId());
1611 eraseEvent
.SetEventObject(this);
1612 GetEventHandler()->ProcessEvent(eraseEvent
);
1614 wxPaintEvent
event(GetId());
1615 event
.SetEventObject(this);
1616 GetEventHandler()->ProcessEvent(event
);
1618 m_needsRefresh
= FALSE
;
1622 // ----------------------------------------------------------------------------
1624 // ----------------------------------------------------------------------------
1626 // Responds to colour changes: passes event on to children.
1627 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1629 wxWindowList::Node
*node
= GetChildren().GetFirst();
1632 // Only propagate to non-top-level windows
1633 wxWindow
*win
= node
->GetData();
1634 if ( win
->GetParent() )
1636 wxSysColourChangedEvent event2
;
1637 event
.m_eventObject
= win
;
1638 win
->GetEventHandler()->ProcessEvent(event2
);
1641 node
= node
->GetNext();
1645 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1647 // This calls the UI-update mechanism (querying windows for
1648 // menu/toolbar/control state information)
1652 // ----------------------------------------------------------------------------
1654 // ----------------------------------------------------------------------------
1656 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1658 if (!m_acceleratorTable
.Ok())
1661 int count
= m_acceleratorTable
.GetCount();
1662 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1664 for (i
= 0; i
< count
; i
++)
1666 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1667 if (entry
->MatchesEvent(event
))
1669 // Bingo, we have a match. Now find a control that matches the
1670 // entry command id.
1672 // Need to go up to the top of the window hierarchy, since it might
1673 // be e.g. a menu item
1674 wxWindow
* parent
= this;
1675 while ( parent
&& !parent
->IsTopLevel() )
1676 parent
= parent
->GetParent();
1681 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1684 // Try for a menu command
1685 if (frame
->GetMenuBar())
1687 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1690 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1691 commandEvent
.SetEventObject(frame
);
1693 // If ProcessEvent returns TRUE (it was handled), then
1694 // the calling code will skip the event handling.
1695 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1700 // Find a child matching the command id
1701 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1707 // Now we process those kinds of windows that we can.
1708 // For now, only buttons.
1709 if ( wxDynamicCast(child
, wxButton
) )
1711 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1712 commandEvent
.SetEventObject(child
);
1713 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1720 // We didn't match the key event against an accelerator.
1724 // ============================================================================
1725 // Motif-specific stuff from here on
1726 // ============================================================================
1728 // ----------------------------------------------------------------------------
1729 // function which maintain the global hash table mapping Widgets to wxWindows
1730 // ----------------------------------------------------------------------------
1732 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1734 wxWindow
*oldItem
= NULL
;
1735 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1737 wxLogDebug("Widget table clash: new widget is %ld, %s",
1738 (long)w
, win
->GetClassInfo()->GetClassName());
1742 wxWidgetHashTable
->Put((long) w
, win
);
1744 wxLogTrace("widget", "Widget 0x%08x <-> window %p (%s)",
1745 w
, win
, win
->GetClassInfo()->GetClassName());
1750 wxWindow
*wxGetWindowFromTable(Widget w
)
1752 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1755 void wxDeleteWindowFromTable(Widget w
)
1757 wxWidgetHashTable
->Delete((long)w
);
1760 // ----------------------------------------------------------------------------
1761 // add/remove window from the table
1762 // ----------------------------------------------------------------------------
1764 // Add to hash table, add event handler
1765 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1766 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1768 wxAddWindowToTable((Widget
) mainWidget
, this);
1769 if (CanAddEventHandler())
1771 XtAddEventHandler((Widget
) mainWidget
,
1772 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1774 wxPanelItemEventHandler
,
1781 XtOverrideTranslations ((Widget
) mainWidget
,
1782 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1783 XtFree ((char *) ptr
);
1786 // Some widgets have a parent form widget, e.g. wxRadioBox
1789 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1793 XtOverrideTranslations ((Widget
) formWidget
,
1794 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1795 XtFree ((char *) ptr
);
1802 SetSize (x
, y
, width
, height
);
1807 // Remove event handler, remove from hash table
1808 bool wxWindow::DetachWidget(WXWidget widget
)
1810 if (CanAddEventHandler())
1812 XtRemoveEventHandler((Widget
) widget
,
1813 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1815 wxPanelItemEventHandler
,
1819 wxDeleteWindowFromTable((Widget
) widget
);
1823 // ----------------------------------------------------------------------------
1824 // Motif-specific accessors
1825 // ----------------------------------------------------------------------------
1827 // Get the underlying X window
1828 WXWindow
wxWindow::GetXWindow() const
1830 Widget wMain
= (Widget
)GetMainWidget();
1832 return (WXWindow
) XtWindow(wMain
);
1834 return (WXWindow
) 0;
1837 // Get the underlying X display
1838 WXDisplay
*wxWindow::GetXDisplay() const
1840 Widget wMain
= (Widget
)GetMainWidget();
1842 return (WXDisplay
*) XtDisplay(wMain
);
1844 return (WXDisplay
*) NULL
;
1847 WXWidget
wxWindow::GetMainWidget() const
1850 return m_drawingArea
;
1852 return m_mainWidget
;
1855 WXWidget
wxWindow::GetClientWidget() const
1857 if (m_drawingArea
!= (WXWidget
) 0)
1858 return m_drawingArea
;
1860 return GetMainWidget();
1863 WXWidget
wxWindow::GetTopWidget() const
1865 return GetMainWidget();
1868 WXWidget
wxWindow::GetLabelWidget() const
1870 return GetMainWidget();
1873 // ----------------------------------------------------------------------------
1875 // ----------------------------------------------------------------------------
1877 // All widgets should have this as their resize proc.
1878 // OnSize sent to wxWindow via client data.
1879 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
), String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1881 wxWindow
*win
= wxGetWindowFromTable(w
);
1885 if (win
->PreResize())
1888 win
->GetSize(&width
, &height
);
1889 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1890 sizeEvent
.SetEventObject(win
);
1891 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1895 static void wxCanvasRepaintProc(Widget drawingArea
,
1896 XtPointer clientData
,
1897 XmDrawingAreaCallbackStruct
* cbs
)
1899 if (!wxGetWindowFromTable(drawingArea
))
1902 XEvent
* event
= cbs
->event
;
1903 wxWindow
* win
= (wxWindow
*) clientData
;
1905 switch (event
->type
)
1909 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1910 event
->xexpose
.width
, event
->xexpose
.height
);
1912 if (event
-> xexpose
.count
== 0)
1915 win
->ClearUpdateRects();
1922 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1923 static void wxCanvasEnterLeave(Widget drawingArea
,
1924 XtPointer
WXUNUSED(clientData
),
1925 XCrossingEvent
* event
)
1927 XmDrawingAreaCallbackStruct cbs
;
1930 ((XCrossingEvent
&) ev
) = *event
;
1932 cbs
.reason
= XmCR_INPUT
;
1935 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1938 // Fix to make it work under Motif 1.0 (!)
1939 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
), XButtonEvent
* WXUNUSED(event
))
1941 #if XmVersion <= 1000
1942 XmDrawingAreaCallbackStruct cbs
;
1945 ev
= *((XEvent
*) event
);
1946 cbs
.reason
= XmCR_INPUT
;
1949 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1950 #endif // XmVersion <= 1000
1953 static void wxCanvasInputEvent(Widget drawingArea
,
1954 XtPointer
WXUNUSED(data
),
1955 XmDrawingAreaCallbackStruct
* cbs
)
1957 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1963 if (cbs
->reason
!= XmCR_INPUT
)
1966 local_event
= *(cbs
->event
); // We must keep a copy!
1968 switch (local_event
.xany
.type
)
1976 // FIXME: most of this mouse event code is more or less
1977 // duplicated in wxTranslateMouseEvent
1979 wxEventType eventType
= wxEVT_NULL
;
1981 if (local_event
.xany
.type
== EnterNotify
)
1983 //if (local_event.xcrossing.mode!=NotifyNormal)
1984 // return ; // Ignore grab events
1985 eventType
= wxEVT_ENTER_WINDOW
;
1986 // canvas->GetEventHandler()->OnSetFocus();
1988 else if (local_event
.xany
.type
== LeaveNotify
)
1990 //if (local_event.xcrossingr.mode!=NotifyNormal)
1991 // return ; // Ignore grab events
1992 eventType
= wxEVT_LEAVE_WINDOW
;
1993 // canvas->GetEventHandler()->OnKillFocus();
1995 else if (local_event
.xany
.type
== MotionNotify
)
1997 eventType
= wxEVT_MOTION
;
2000 else if (local_event
.xany
.type
== ButtonPress
)
2002 if (local_event
.xbutton
.button
== Button1
)
2004 eventType
= wxEVT_LEFT_DOWN
;
2005 canvas
->SetButton1(TRUE
);
2007 else if (local_event
.xbutton
.button
== Button2
)
2009 eventType
= wxEVT_MIDDLE_DOWN
;
2010 canvas
->SetButton2(TRUE
);
2012 else if (local_event
.xbutton
.button
== Button3
)
2014 eventType
= wxEVT_RIGHT_DOWN
;
2015 canvas
->SetButton3(TRUE
);
2018 else if (local_event
.xany
.type
== ButtonRelease
)
2020 if (local_event
.xbutton
.button
== Button1
)
2022 eventType
= wxEVT_LEFT_UP
;
2023 canvas
->SetButton1(FALSE
);
2025 else if (local_event
.xbutton
.button
== Button2
)
2027 eventType
= wxEVT_MIDDLE_UP
;
2028 canvas
->SetButton2(FALSE
);
2030 else if (local_event
.xbutton
.button
== Button3
)
2032 eventType
= wxEVT_RIGHT_UP
;
2033 canvas
->SetButton3(FALSE
);
2037 wxMouseEvent
wxevent (eventType
);
2039 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2040 || (event_left_is_down (&local_event
)
2041 && (eventType
!= wxEVT_LEFT_UP
)));
2042 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2043 || (event_middle_is_down (&local_event
)
2044 && (eventType
!= wxEVT_MIDDLE_UP
)));
2045 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2046 || (event_right_is_down (&local_event
)
2047 && (eventType
!= wxEVT_RIGHT_UP
)));
2049 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2050 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2051 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2052 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2053 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2055 if ( eventType
== wxEVT_MOTION
)
2057 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2060 Display
*dpy
= XtDisplay (drawingArea
);
2062 XQueryPointer (dpy
, XtWindow (drawingArea
),
2064 &local_event
.xmotion
.x_root
,
2065 &local_event
.xmotion
.y_root
,
2066 &local_event
.xmotion
.x
,
2067 &local_event
.xmotion
.y
,
2068 &local_event
.xmotion
.state
);
2075 // Now check if we need to translate this event into a double click
2076 if (TRUE
) // canvas->doubleClickAllowed)
2078 if (wxevent
.ButtonDown())
2080 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2082 // get button and time-stamp
2084 if (wxevent
.LeftDown())
2086 else if (wxevent
.MiddleDown())
2088 else if (wxevent
.RightDown())
2090 long ts
= wxevent
.GetTimestamp();
2092 // check, if single or double click
2093 int buttonLast
= canvas
->GetLastClickedButton();
2094 long lastTS
= canvas
->GetLastClickTime();
2095 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2098 canvas
->SetLastClick(0, ts
);
2100 wxEventType typeDouble
;
2101 if ( eventType
== wxEVT_LEFT_DOWN
)
2102 typeDouble
= wxEVT_LEFT_DCLICK
;
2103 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2104 typeDouble
= wxEVT_MIDDLE_DCLICK
;
2105 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2106 typeDouble
= wxEVT_RIGHT_DCLICK
;
2108 typeDouble
= wxEVT_NULL
;
2110 if ( typeDouble
!= wxEVT_NULL
)
2112 wxevent
.SetEventType(typeDouble
);
2117 // not fast enough or different button
2118 canvas
->SetLastClick(button
, ts
);
2123 wxevent
.SetId(canvas
->GetId());
2124 wxevent
.SetEventObject(canvas
);
2125 wxevent
.m_x
= local_event
.xbutton
.x
;
2126 wxevent
.m_y
= local_event
.xbutton
.y
;
2127 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2129 if (eventType
== wxEVT_ENTER_WINDOW
||
2130 eventType
== wxEVT_LEAVE_WINDOW
||
2131 eventType
== wxEVT_MOTION
2140 static char buf
[100];
2142 XComposeStatus compose
;
2143 (void) XLookupString ((XKeyEvent
*) & local_event
, buf
, 20, &keySym
, &compose
);
2146 (void) XLookupString ((XKeyEvent
*) & local_event
, buf
, 20, &keySym
, NULL
);
2147 int id
= wxCharCodeXToWX (keySym
);
2149 wxEventType eventType
= wxEVT_CHAR
;
2151 wxKeyEvent
event (eventType
);
2153 if (local_event
.xkey
.state
& ShiftMask
)
2154 event
.m_shiftDown
= TRUE
;
2155 if (local_event
.xkey
.state
& ControlMask
)
2156 event
.m_controlDown
= TRUE
;
2157 if (local_event
.xkey
.state
& Mod3Mask
)
2158 event
.m_altDown
= TRUE
;
2159 if (local_event
.xkey
.state
& Mod1Mask
)
2160 event
.m_metaDown
= TRUE
;
2161 event
.SetEventObject(canvas
);
2162 event
.m_keyCode
= id
;
2163 event
.SetTimestamp(local_event
.xkey
.time
);
2167 // Implement wxFrame::OnCharHook by checking ancestor.
2168 wxWindow
*parent
= canvas
->GetParent();
2169 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2170 parent
= parent
->GetParent();
2174 event
.SetEventType(wxEVT_CHAR_HOOK
);
2175 if (parent
->GetEventHandler()->ProcessEvent(event
))
2179 // For simplicity, OnKeyDown is the same as OnChar
2180 // TODO: filter modifier key presses from OnChar
2181 event
.SetEventType(wxEVT_KEY_DOWN
);
2183 // Only process OnChar if OnKeyDown didn't swallow it
2184 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2186 event
.SetEventType(wxEVT_CHAR
);
2187 canvas
->GetEventHandler()->ProcessEvent (event
);
2194 static char buf
[100];
2196 (void) XLookupString ((XKeyEvent
*) & local_event
, buf
, 20, &keySym
, NULL
);
2197 int id
= wxCharCodeXToWX (keySym
);
2199 wxKeyEvent
event (wxEVT_KEY_UP
);
2201 if (local_event
.xkey
.state
& ShiftMask
)
2202 event
.m_shiftDown
= TRUE
;
2203 if (local_event
.xkey
.state
& ControlMask
)
2204 event
.m_controlDown
= TRUE
;
2205 if (local_event
.xkey
.state
& Mod3Mask
)
2206 event
.m_altDown
= TRUE
;
2207 if (local_event
.xkey
.state
& Mod1Mask
)
2208 event
.m_metaDown
= TRUE
;
2209 event
.SetEventObject(canvas
);
2210 event
.m_keyCode
= id
;
2211 event
.SetTimestamp(local_event
.xkey
.time
);
2215 canvas
->GetEventHandler()->ProcessEvent (event
);
2221 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2223 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2224 event
.SetEventObject(canvas
);
2225 canvas
->GetEventHandler()->ProcessEvent(event
);
2231 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2233 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2234 event
.SetEventObject(canvas
);
2235 canvas
->GetEventHandler()->ProcessEvent(event
);
2244 static void wxPanelItemEventHandler(Widget wid
,
2245 XtPointer
WXUNUSED(client_data
),
2247 Boolean
*continueToDispatch
)
2249 // Widget can be a label or the actual widget.
2251 wxWindow
*window
= wxGetWindowFromTable(wid
);
2254 wxMouseEvent
wxevent(0);
2255 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2257 window
->GetEventHandler()->ProcessEvent(wxevent
);
2261 // TODO: probably the key to allowing default behaviour to happen. Say we
2262 // set a m_doDefault flag to FALSE at the start of this function. Then in
2263 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2264 // TRUE, indicating that default processing can happen. Thus, behaviour can
2265 // appear to be overridden just by adding an event handler and not calling
2266 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2267 // way of handling drawing area events, to simplify things.
2268 *continueToDispatch
= True
;
2271 static void wxScrollBarCallback(Widget scrollbar
,
2272 XtPointer clientData
,
2273 XmScrollBarCallbackStruct
*cbs
)
2275 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2276 int orientation
= (int) clientData
;
2278 wxEventType eventType
= wxEVT_NULL
;
2279 switch (cbs
->reason
)
2281 case XmCR_INCREMENT
:
2283 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2286 case XmCR_DECREMENT
:
2288 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2293 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2296 case XmCR_VALUE_CHANGED
:
2298 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2301 case XmCR_PAGE_INCREMENT
:
2303 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2306 case XmCR_PAGE_DECREMENT
:
2308 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2313 eventType
= wxEVT_SCROLLWIN_TOP
;
2316 case XmCR_TO_BOTTOM
:
2318 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2323 // Should never get here
2324 wxFAIL_MSG("Unknown scroll event.");
2329 wxScrollWinEvent
event(eventType
,
2331 ((orientation
== XmHORIZONTAL
) ?
2332 wxHORIZONTAL
: wxVERTICAL
));
2333 event
.SetEventObject( win
);
2334 win
->GetEventHandler()->ProcessEvent(event
);
2337 // For repainting arbitrary windows
2338 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2343 wxWindow
* win
= wxGetWindowFromTable(w
);
2347 switch(event
-> type
)
2351 window
= (Window
) win
-> GetXWindow();
2352 display
= (Display
*) win
-> GetXDisplay();
2354 if (event
-> xexpose
.count
== 0)
2358 win
->ClearUpdateRects();
2362 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2363 event
->xexpose
.width
, event
->xexpose
.height
);
2371 // ----------------------------------------------------------------------------
2372 // CanvaseXXXSize() functions
2373 // ----------------------------------------------------------------------------
2375 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2376 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2378 // A bit of optimization to help sort out the flickers.
2379 int oldX
, oldY
, oldW
, oldH
;
2380 GetSize(& oldW
, & oldH
);
2381 GetPosition(& oldX
, & oldY
);
2383 bool useOldPos
= FALSE
;
2384 bool useOldSize
= FALSE
;
2386 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2388 else if (x
== oldX
&& y
== oldY
)
2391 if ((w
== -1) && (h
== -1))
2393 else if (w
== oldW
&& h
== oldH
)
2396 if (!wxNoOptimize::CanOptimize())
2398 useOldSize
= FALSE
; useOldPos
= FALSE
;
2401 if (useOldPos
&& useOldSize
)
2404 Widget drawingArea
= (Widget
) m_drawingArea
;
2405 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2408 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2409 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2411 int xx
= x
; int yy
= y
;
2412 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2416 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2418 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2422 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2424 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2436 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2437 short thick
, margin
;
2438 XtVaGetValues ((Widget
) m_borderWidget
,
2439 XmNshadowThickness
, &thick
,
2440 XmNmarginWidth
, &margin
,
2442 w
-= 2 * (thick
+ margin
);
2445 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2449 XtVaGetValues ((Widget
) m_scrolledWindow
,
2450 XmNspacing
, &spacing
,
2451 XmNverticalScrollBar
, &sbar
,
2455 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2459 w
-= (spacing
+ wsbar
);
2462 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2469 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2470 short thick
, margin
;
2471 XtVaGetValues ((Widget
) m_borderWidget
,
2472 XmNshadowThickness
, &thick
,
2473 XmNmarginHeight
, &margin
,
2475 h
-= 2 * (thick
+ margin
);
2478 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2482 XtVaGetValues ((Widget
) m_scrolledWindow
,
2483 XmNspacing
, &spacing
,
2484 XmNhorizontalScrollBar
, &sbar
,
2488 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2492 h
-= (spacing
+ wsbar
);
2495 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2501 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2502 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2506 GetClientSize (&ww
, &hh
);
2507 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2508 sizeEvent
.SetEventObject(this);
2510 GetEventHandler()->ProcessEvent(sizeEvent
);
2514 void wxWindow::CanvasSetClientSize (int w
, int h
)
2516 Widget drawingArea
= (Widget
) m_drawingArea
;
2518 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2521 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2523 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2526 // TODO: is this necessary?
2527 allowRepainting
= FALSE
;
2529 XSync (XtDisplay (drawingArea
), FALSE
);
2531 while (XtAppPending (wxTheApp
->appContext
))
2533 XFlush (XtDisplay (drawingArea
));
2534 XtAppNextEvent (wxTheApp
->appContext
, &event
);
2535 XtDispatchEvent (&event
);
2539 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2542 allowRepainting
= TRUE
;
2545 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2546 sizeEvent
.SetEventObject(this);
2548 GetEventHandler()->ProcessEvent(sizeEvent
);
2552 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2554 // Must return the same thing that was set via SetClientSize
2556 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2561 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2564 if ((Widget
) m_borderWidget
)
2565 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2566 else if ((Widget
) m_scrolledWindow
)
2567 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2569 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2575 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2578 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2580 // We may be faking the client origin.
2581 // So a window that's really at (0, 30) may appear
2582 // (to wxWin apps) to be at (0, 0).
2585 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2594 // ----------------------------------------------------------------------------
2595 // TranslateXXXEvent() functions
2596 // ----------------------------------------------------------------------------
2598 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2600 switch (xevent
->xany
.type
)
2602 case EnterNotify
: // never received here - yes ? MB
2603 case LeaveNotify
: // never received here - yes ? MB
2608 wxEventType eventType
= wxEVT_NULL
;
2610 // FIXME: this is never true I think - MB
2612 if (xevent
->xany
.type
== LeaveNotify
)
2614 win
->SetButton1(FALSE
);
2615 win
->SetButton2(FALSE
);
2616 win
->SetButton3(FALSE
);
2619 else if (xevent
->xany
.type
== MotionNotify
)
2621 eventType
= wxEVT_MOTION
;
2623 else if (xevent
->xany
.type
== ButtonPress
)
2625 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2627 if (xevent
->xbutton
.button
== Button1
)
2629 eventType
= wxEVT_LEFT_DOWN
;
2630 win
->SetButton1(TRUE
);
2633 else if (xevent
->xbutton
.button
== Button2
)
2635 eventType
= wxEVT_MIDDLE_DOWN
;
2636 win
->SetButton2(TRUE
);
2639 else if (xevent
->xbutton
.button
== Button3
)
2641 eventType
= wxEVT_RIGHT_DOWN
;
2642 win
->SetButton3(TRUE
);
2646 // check for a double click
2648 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2649 long ts
= wxevent
.GetTimestamp();
2651 int buttonLast
= win
->GetLastClickedButton();
2652 long lastTS
= win
->GetLastClickTime();
2653 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2656 win
->SetLastClick(0, ts
);
2657 if ( eventType
== wxEVT_LEFT_DOWN
)
2658 eventType
= wxEVT_LEFT_DCLICK
;
2659 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2660 eventType
= wxEVT_MIDDLE_DCLICK
;
2661 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2662 eventType
= wxEVT_RIGHT_DCLICK
;
2666 // not fast enough or different button
2667 win
->SetLastClick(button
, ts
);
2670 else if (xevent
->xany
.type
== ButtonRelease
)
2672 if (xevent
->xbutton
.button
== Button1
)
2674 eventType
= wxEVT_LEFT_UP
;
2675 win
->SetButton1(FALSE
);
2677 else if (xevent
->xbutton
.button
== Button2
)
2679 eventType
= wxEVT_MIDDLE_UP
;
2680 win
->SetButton2(FALSE
);
2682 else if (xevent
->xbutton
.button
== Button3
)
2684 eventType
= wxEVT_RIGHT_UP
;
2685 win
->SetButton3(FALSE
);
2694 wxevent
.SetEventType(eventType
);
2697 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2700 win
->GetPosition(&x2
, &y2
);
2702 // The button x/y must be translated to wxWindows
2703 // window space - the widget might be a label or button,
2707 if (widget
!= (Widget
)win
->GetMainWidget())
2713 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2714 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2716 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2717 || (event_left_is_down (xevent
)
2718 && (eventType
!= wxEVT_LEFT_UP
)));
2719 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2720 || (event_middle_is_down (xevent
)
2721 && (eventType
!= wxEVT_MIDDLE_UP
)));
2722 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2723 || (event_right_is_down (xevent
)
2724 && (eventType
!= wxEVT_RIGHT_UP
)));
2726 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2727 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2728 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
2729 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
2731 wxevent
.SetId(win
->GetId());
2732 wxevent
.SetEventObject(win
);
2740 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget
WXUNUSED(widget
), XEvent
*xevent
)
2742 switch (xevent
->xany
.type
)
2751 XComposeStatus compose
;
2752 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, &compose
);
2754 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2755 int id
= wxCharCodeXToWX (keySym
);
2757 if (xevent
->xkey
.state
& ShiftMask
)
2758 wxevent
.m_shiftDown
= TRUE
;
2759 if (xevent
->xkey
.state
& ControlMask
)
2760 wxevent
.m_controlDown
= TRUE
;
2761 if (xevent
->xkey
.state
& Mod3Mask
)
2762 wxevent
.m_altDown
= TRUE
;
2763 if (xevent
->xkey
.state
& Mod1Mask
)
2764 wxevent
.m_metaDown
= TRUE
;
2765 wxevent
.SetEventObject(win
);
2766 wxevent
.m_keyCode
= id
;
2767 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2769 wxevent
.m_x
= xevent
->xbutton
.x
;
2770 wxevent
.m_y
= xevent
->xbutton
.y
;
2784 // ----------------------------------------------------------------------------
2786 // ----------------------------------------------------------------------------
2788 #define YAllocColor XAllocColor
2789 XColor g_itemColors
[5];
2790 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2793 static XmColorProc colorProc
;
2795 result
= wxNO_COLORS
;
2799 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2800 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2801 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2802 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2803 if (colorProc
== (XmColorProc
) NULL
)
2805 // Get a ptr to the actual function
2806 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2807 // And set it back to motif.
2808 XmSetColorCalculation (colorProc
);
2810 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2811 &g_itemColors
[wxFORE_INDEX
],
2812 &g_itemColors
[wxSELE_INDEX
],
2813 &g_itemColors
[wxTOPS_INDEX
],
2814 &g_itemColors
[wxBOTS_INDEX
]);
2815 result
= wxBACK_COLORS
;
2819 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2820 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2821 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2822 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2823 if (result
== wxNO_COLORS
)
2824 result
= wxFORE_COLORS
;
2827 Display
*dpy
= display
;
2828 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2832 /* 5 Colours to allocate */
2833 for (int i
= 0; i
< 5; i
++)
2834 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2835 result
= wxNO_COLORS
;
2839 /* Only 1 colour to allocate */
2840 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2841 result
= wxNO_COLORS
;
2848 // Changes the foreground and background colours to be derived from the current
2849 // background colour. To change the foreground colour, you must call
2850 // SetForegroundColour explicitly.
2851 void wxWindow::ChangeBackgroundColour()
2853 WXWidget mainWidget
= GetMainWidget();
2855 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2857 // This not necessary
2860 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
2862 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
2863 // Have to set the scrollbar colours back since
2864 // the scrolled window seemed to change them
2865 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
2868 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
2870 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
2875 void wxWindow::ChangeForegroundColour()
2877 WXWidget mainWidget
= GetMainWidget();
2879 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2880 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2881 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2884 // Change a widget's foreground and background colours.
2885 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
2887 // When should we specify the foreground, if it's calculated
2888 // by wxComputeColours?
2889 // Solution: say we start with the default (computed) foreground colour.
2890 // If we call SetForegroundColour explicitly for a control or window,
2891 // then the foreground is changed.
2892 // Therefore SetBackgroundColour computes the foreground colour, and
2893 // SetForegroundColour changes the foreground colour. The ordering is
2896 Widget w
= (Widget
)widget
;
2899 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
2904 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
2906 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
2909 XtVaSetValues ((Widget
) widget
,
2910 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
2911 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
2912 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
2913 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
2916 if (changeArmColour
)
2917 XtVaSetValues ((Widget
) widget
,
2918 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
2922 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2924 if ( !wxWindowBase::SetBackgroundColour(col
) )
2927 ChangeBackgroundColour();
2932 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2934 if ( !wxWindowBase::SetForegroundColour(col
) )
2937 ChangeForegroundColour();
2942 void wxWindow::ChangeFont(bool keepOriginalSize
)
2944 // Note that this causes the widget to be resized back
2945 // to its original size! We therefore have to set the size
2946 // back again. TODO: a better way in Motif?
2947 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2948 if (w
&& m_font
.Ok())
2950 int width
, height
, width1
, height1
;
2951 GetSize(& width
, & height
);
2953 // lesstif 0.87 hangs here
2954 #ifndef LESSTIF_VERSION
2956 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
2960 GetSize(& width1
, & height1
);
2961 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2963 SetSize(-1, -1, width
, height
);
2968 // ----------------------------------------------------------------------------
2970 // ----------------------------------------------------------------------------
2972 wxWindow
*wxGetActiveWindow()
2975 wxFAIL_MSG("Not implemented");
2980 wxWindow
*wxWindowBase::GetCapture()
2982 return (wxWindow
*)g_captureWindow
;
2986 // Find the wxWindow at the current mouse position, returning the mouse
2988 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2990 return wxFindWindowAtPoint(wxGetMousePosition());
2993 // Get the current mouse position.
2994 wxPoint
wxGetMousePosition()
2996 Display
*display
= (Display
*) wxGetDisplay();
2997 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2998 Window rootReturn
, childReturn
;
2999 int rootX
, rootY
, winX
, winY
;
3000 unsigned int maskReturn
;
3002 XQueryPointer (display
,
3006 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
3007 return wxPoint(rootX
, rootY
);
3011 // ----------------------------------------------------------------------------
3012 // wxNoOptimize: switch off size optimization
3013 // ----------------------------------------------------------------------------
3015 int wxNoOptimize::ms_count
= 0;