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
;
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
89 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
90 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
91 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
92 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
93 XmScrollBarCallbackStruct
*cbs
);
94 static void wxPanelItemEventHandler(Widget wid
,
95 XtPointer client_data
,
97 Boolean
*continueToDispatch
);
102 // Helper function for 16-bit fonts
103 static int str16len(const char *s
)
107 while (s
[0] && s
[1]) {
117 // ----------------------------------------------------------------------------
119 // ----------------------------------------------------------------------------
121 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
122 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
123 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
129 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
131 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
132 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
133 EVT_IDLE(wxWindow::OnIdle
)
136 // ============================================================================
138 // ============================================================================
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
144 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
146 Widget w
= (Widget
)widget
;
154 bool wxWindow::MapOrUnmap(WXWidget widget
, bool map
)
156 Widget w
= (Widget
)widget
;
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
172 void wxWindow::Init()
174 // generic initializations first
178 m_needsRefresh
= TRUE
;
179 m_mainWidget
= (WXWidget
) 0;
183 m_button3Pressed
= FALSE
;
185 m_winCaptured
= FALSE
;
188 m_isBeingDeleted
= FALSE
;
194 m_drawingArea
= (WXWidget
) 0;
202 m_backingPixmap
= (WXPixmap
) 0;
211 m_canAddEventHandler
= FALSE
;
214 // real construction (Init() must have been called before!)
215 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
219 const wxString
& name
)
221 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
223 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
225 parent
->AddChild(this);
227 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
228 m_foregroundColour
= *wxBLACK
;
230 //// TODO: we should probably optimize by only creating a
231 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
232 //// But for now, let's simplify things by always creating the
233 //// drawing area, since otherwise the translations are different.
235 // New translations for getting mouse motion feedback
236 static const String translations
=
237 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
238 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
239 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
240 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
241 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
242 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
243 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
244 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
245 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
246 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
247 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
248 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
249 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
250 <Key>: DrawingAreaInput()";
252 XtActionsRec actions
[1];
253 actions
[0].string
= "wxCanvasMotionEvent";
254 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
255 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
257 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
259 if (style
& wxSIMPLE_BORDER
)
261 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
264 xmFrameWidgetClass
, parentWidget
,
265 XmNshadowType
, XmSHADOW_IN
,
266 XmNshadowThickness
, 1,
269 } else if (style
& wxSUNKEN_BORDER
)
271 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
274 xmFrameWidgetClass
, parentWidget
,
275 XmNshadowType
, XmSHADOW_IN
,
278 } else if (style
& wxRAISED_BORDER
)
280 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
283 xmFrameWidgetClass
, parentWidget
,
284 XmNshadowType
, XmSHADOW_OUT
,
289 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
292 xmScrolledWindowWidgetClass
,
293 m_borderWidget
? (Widget
) m_borderWidget
295 XmNresizePolicy
, XmRESIZE_NONE
,
297 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
298 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
302 XtTranslations ptr
= XtParseTranslationTable(translations
);
303 m_drawingArea
= (WXWidget
)XtVaCreateWidget
306 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
307 XmNunitType
, XmPIXELS
,
308 // XmNresizePolicy, XmRESIZE_ANY,
309 XmNresizePolicy
, XmRESIZE_NONE
,
312 XmNtranslations
, ptr
,
315 XtFree((char *) ptr
);
318 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
320 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
321 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
322 XtFree ((char *) ptr
);
326 wxAddWindowToTable((Widget
) m_drawingArea
, this);
327 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
329 // This order is very important in Motif 1.2.1
330 XtRealizeWidget ((Widget
) m_scrolledWindow
);
331 XtRealizeWidget ((Widget
) m_drawingArea
);
332 XtManageChild ((Widget
) m_drawingArea
);
334 ptr
= XtParseTranslationTable("<Configure>: resize()");
335 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
336 XtFree ((char *) ptr
);
338 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
339 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
343 display
= XtDisplay (scrolledWindow
);
344 xwindow
= XtWindow (drawingArea
);
348 (Widget
)m_drawingArea
,
349 PointerMotionHintMask
| EnterWindowMask
|
350 LeaveWindowMask
| FocusChangeMask
,
352 (XtEventHandler
) wxCanvasEnterLeave
,
356 // Scrolled widget needs to have its colour changed or we get a little blue
357 // square where the scrollbars abutt
358 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
359 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
360 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
362 XmScrolledWindowSetAreas(
363 (Widget
)m_scrolledWindow
,
364 (Widget
) 0, (Widget
) 0,
365 (Widget
) m_drawingArea
);
369 XtRealizeWidget ((Widget
) m_hScrollBar
);
371 XtRealizeWidget ((Widget
) m_vScrollBar
);
374 // Without this, the cursor may not be restored properly (e.g. in splitter
376 SetCursor(*wxSTANDARD_CURSOR
);
377 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
378 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
384 wxWindow::~wxWindow()
386 m_isBeingDeleted
= TRUE
;
388 // Motif-specific actions first
389 WXWidget wMain
= GetMainWidget();
392 // Removes event handlers
399 m_parent
->RemoveChild( this );
401 // If m_drawingArea, we're a fully-fledged window with drawing area,
402 // scrollbars etc. (what wxCanvas used to be)
405 // Destroy children before destroying self
409 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
411 Widget w
= (Widget
) m_drawingArea
;
412 wxDeleteWindowFromTable(w
);
417 m_drawingArea
= (WXWidget
) 0;
420 // Only if we're _really_ a canvas (not a dialog box/panel)
421 if (m_scrolledWindow
)
423 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
428 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
429 XtUnmanageChild((Widget
) m_hScrollBar
);
433 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
434 XtUnmanageChild((Widget
) m_vScrollBar
);
438 XtDestroyWidget((Widget
) m_hScrollBar
);
440 XtDestroyWidget((Widget
) m_vScrollBar
);
442 UnmanageAndDestroy(m_scrolledWindow
);
446 XtDestroyWidget ((Widget
) m_borderWidget
);
447 m_borderWidget
= (WXWidget
) 0;
450 else // Why wasn't this here before? JACS 8/3/2000
454 // Destroy the window
457 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
458 // Child widgets will get destroyed automatically when a frame
459 // or dialog is destroyed, but before that you may get some memory
460 // leaks and potential layout problems if you delete and then add
463 // GRG, Feb/2000: commented this out when adding support for
464 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
465 // that this call crashed wxMotif under OS/2, so it seems
466 // that leaving it out is the right thing to do.
467 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
468 XtDestroyWidget((Widget
) GetMainWidget());
469 SetMainWidget((WXWidget
) NULL
);
473 // ----------------------------------------------------------------------------
474 // scrollbar management
475 // ----------------------------------------------------------------------------
478 void wxWindow::CreateScrollbar(wxOrientation orientation
)
480 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
482 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
484 // Add scrollbars if required
485 if (orientation
== wxHORIZONTAL
)
487 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
488 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
489 XmNorientation
, XmHORIZONTAL
,
491 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
492 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
493 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
494 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
495 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
496 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
497 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
498 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
500 XtVaSetValues (hScrollBar
,
505 m_hScrollBar
= (WXWidget
) hScrollBar
;
507 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
508 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
510 XtRealizeWidget(hScrollBar
);
512 XtVaSetValues((Widget
) m_scrolledWindow
,
513 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
518 wxAddWindowToTable( hScrollBar
, this );
521 if (orientation
== wxVERTICAL
)
523 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
524 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
525 XmNorientation
, XmVERTICAL
,
527 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
528 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
529 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
530 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
531 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
532 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
533 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
534 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
536 XtVaSetValues (vScrollBar
,
541 m_vScrollBar
= (WXWidget
) vScrollBar
;
542 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
543 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
545 XtRealizeWidget(vScrollBar
);
547 XtVaSetValues((Widget
) m_scrolledWindow
,
548 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
553 wxAddWindowToTable( vScrollBar
, this );
556 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
559 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
561 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
563 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
564 // Add scrollbars if required
565 if (orientation
== wxHORIZONTAL
)
569 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
570 XtDestroyWidget((Widget
) m_hScrollBar
);
572 m_hScrollBar
= (WXWidget
) 0;
575 XtVaSetValues((Widget
) m_scrolledWindow
,
576 XmNhorizontalScrollBar
, (Widget
) 0,
581 if (orientation
== wxVERTICAL
)
585 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
586 XtDestroyWidget((Widget
) m_vScrollBar
);
588 m_vScrollBar
= (WXWidget
) 0;
591 XtVaSetValues((Widget
) m_scrolledWindow
,
592 XmNverticalScrollBar
, (Widget
) 0,
596 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
599 // ---------------------------------------------------------------------------
601 // ---------------------------------------------------------------------------
603 void wxWindow::SetFocus()
605 Widget wMain
= (Widget
) GetMainWidget();
606 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
607 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
610 // Get the window with the focus
611 wxWindow
*wxWindowBase::FindFocus()
614 // (1) Can there be multiple focussed widgets in an application?
615 // In which case we need to find the top-level window that's
617 // (2) The widget with the focus may not be in the widget table
618 // depending on which widgets I put in the table
619 wxWindow
*winFocus
= (wxWindow
*)NULL
;
620 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
622 node
= node
->GetNext() )
624 wxWindow
*win
= node
->GetData();
626 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
628 if (w
!= (Widget
) NULL
)
630 winFocus
= wxGetWindowFromTable(w
);
639 bool wxWindow::Enable(bool enable
)
641 if ( !wxWindowBase::Enable(enable
) )
644 Widget wMain
= (Widget
)GetMainWidget();
647 XtSetSensitive(wMain
, enable
);
648 XmUpdateDisplay(wMain
);
654 bool wxWindow::Show(bool show
)
656 if ( !wxWindowBase::Show(show
) )
659 if (m_borderWidget
|| m_scrolledWindow
)
661 MapOrUnmap(m_drawingArea
, show
);
662 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
666 if ( !MapOrUnmap(GetTopWidget(), show
) )
667 MapOrUnmap(GetMainWidget(), show
);
671 Window xwin
= (Window
) GetXWindow();
672 Display
*xdisp
= (Display
*) GetXDisplay();
674 XMapWindow(xdisp
, xwin
);
676 XUnmapWindow(xdisp
, xwin
);
682 // Raise the window to the top of the Z order
683 void wxWindow::Raise()
685 Widget wTop
= (Widget
) GetTopWidget();
686 Window window
= XtWindow(wTop
);
687 XRaiseWindow(XtDisplay(wTop
), window
);
690 // Lower the window to the bottom of the Z order
691 void wxWindow::Lower()
693 Widget wTop
= (Widget
) GetTopWidget();
694 Window window
= XtWindow(wTop
);
695 XLowerWindow(XtDisplay(wTop
), window
);
698 void wxWindow::SetTitle(const wxString
& title
)
700 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
703 wxString
wxWindow::GetTitle() const
706 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
708 return wxString(title
);
711 void wxWindow::CaptureMouse()
716 Widget wMain
= (Widget
)GetMainWidget();
718 XtAddGrab(wMain
, TRUE
, FALSE
);
720 m_winCaptured
= TRUE
;
723 void wxWindow::ReleaseMouse()
725 if ( !m_winCaptured
)
728 Widget wMain
= (Widget
)GetMainWidget();
732 m_winCaptured
= FALSE
;
735 bool wxWindow::SetFont(const wxFont
& font
)
737 if ( !wxWindowBase::SetFont(font
) )
748 bool wxWindow::SetCursor(const wxCursor
& cursor
)
750 if ( !wxWindowBase::SetCursor(cursor
) )
756 // wxASSERT_MSG( m_cursor.Ok(),
757 // wxT("cursor must be valid after call to the base version"));
758 wxCursor
* cursor2
= NULL
;
760 cursor2
= & m_cursor
;
762 cursor2
= wxSTANDARD_CURSOR
;
764 WXDisplay
*dpy
= GetXDisplay();
765 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
767 Widget w
= (Widget
) GetMainWidget();
768 Window win
= XtWindow(w
);
769 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
774 // Coordinates relative to the window
775 void wxWindow::WarpPointer (int x
, int y
)
777 Widget wClient
= (Widget
)GetClientWidget();
779 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
782 // ---------------------------------------------------------------------------
784 // ---------------------------------------------------------------------------
786 int wxWindow::GetScrollPos(int orient
) const
788 if (orient
== wxHORIZONTAL
)
794 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
798 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
806 // This now returns the whole range, not just the number of positions that we
808 int wxWindow::GetScrollRange(int orient
) const
810 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
811 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
814 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
818 int wxWindow::GetScrollThumb(int orient
) const
820 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
821 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
824 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
828 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
830 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
834 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
837 SetInternalScrollPos((wxOrientation
)orient
, pos
);
840 // New function that will replace some of the above.
841 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
842 int range
, bool WXUNUSED(refresh
))
845 GetSize(& oldW
, & oldH
);
849 if (thumbVisible
== 0)
852 if (thumbVisible
> range
)
853 thumbVisible
= range
;
855 // Save the old state to see if it changed
856 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
858 if (orient
== wxHORIZONTAL
)
860 if (thumbVisible
== range
)
863 DestroyScrollbar(wxHORIZONTAL
);
868 CreateScrollbar(wxHORIZONTAL
);
871 if (orient
== wxVERTICAL
)
873 if (thumbVisible
== range
)
876 DestroyScrollbar(wxVERTICAL
);
881 CreateScrollbar(wxVERTICAL
);
884 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
886 if (oldScrollBar
!= newScrollBar
)
888 // This is important! Without it, scrollbars misbehave badly.
889 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
890 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
891 XtRealizeWidget((Widget
) m_scrolledWindow
);
892 XtManageChild((Widget
) m_scrolledWindow
);
897 XtVaSetValues((Widget
) newScrollBar
,
901 XmNsliderSize
, thumbVisible
,
905 SetInternalScrollPos((wxOrientation
)orient
, pos
);
908 GetSize(& newW
, & newH
);
910 // Adjusting scrollbars can resize the canvas accidentally
911 if (newW
!= oldW
|| newH
!= oldH
)
912 SetSize(-1, -1, oldW
, oldH
);
915 // Does a physical scroll
916 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
921 // Use specified rectangle
922 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
926 // Use whole client area
928 GetClientSize(& w
, & h
);
931 wxNode
*cnode
= m_children
.First();
934 wxWindow
*child
= (wxWindow
*) cnode
->Data();
937 child
->GetSize( &sx
, &sy
);
938 wxPoint
pos( child
->GetPosition() );
939 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
940 cnode
= cnode
->Next();
943 int x1
= (dx
>= 0) ? x
: x
- dx
;
944 int y1
= (dy
>= 0) ? y
: y
- dy
;
945 int w1
= w
- abs(dx
);
946 int h1
= h
- abs(dy
);
947 int x2
= (dx
>= 0) ? x
+ dx
: x
;
948 int y2
= (dy
>= 0) ? y
+ dy
: y
;
952 dc
.SetLogicalFunction (wxCOPY
);
954 Widget widget
= (Widget
) GetMainWidget();
955 Window window
= XtWindow(widget
);
956 Display
* display
= XtDisplay(widget
);
958 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
959 x1
, y1
, w1
, h1
, x2
, y2
);
961 dc
.SetAutoSetting(TRUE
);
962 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
963 dc
.SetBrush(brush
); // FIXME: needed?
965 // We'll add rectangles to the list of update rectangles according to which
966 // bits we've exposed.
971 wxRect
*rect
= new wxRect
;
977 XFillRectangle(display
, window
,
978 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
982 rect
->width
= rect
->width
;
983 rect
->height
= rect
->height
;
985 updateRects
.Append((wxObject
*) rect
);
989 wxRect
*rect
= new wxRect
;
991 rect
->x
= x
+ w
+ dx
;
996 XFillRectangle(display
, window
,
997 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1002 rect
->width
= rect
->width
;
1003 rect
->height
= rect
->height
;
1005 updateRects
.Append((wxObject
*) rect
);
1009 wxRect
*rect
= new wxRect
;
1016 XFillRectangle(display
, window
,
1017 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1021 rect
->width
= rect
->width
;
1022 rect
->height
= rect
->height
;
1024 updateRects
.Append((wxObject
*) rect
);
1028 wxRect
*rect
= new wxRect
;
1031 rect
->y
= y
+ h
+ dy
;
1035 XFillRectangle(display
, window
,
1036 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1040 rect
->width
= rect
->width
;
1041 rect
->height
= rect
->height
;
1043 updateRects
.Append((wxObject
*) rect
);
1045 dc
.SetBrush(wxNullBrush
);
1047 // Now send expose events
1049 wxNode
* node
= updateRects
.First();
1052 wxRect
* rect
= (wxRect
*) node
->Data();
1055 event
.type
= Expose
;
1056 event
.display
= display
;
1057 event
.send_event
= True
;
1058 event
.window
= window
;
1062 event
.width
= rect
->width
;
1063 event
.height
= rect
->height
;
1067 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1069 node
= node
->Next();
1073 // Delete the update rects
1074 node
= updateRects
.First();
1077 wxRect
* rect
= (wxRect
*) node
->Data();
1079 node
= node
->Next();
1082 XmUpdateDisplay((Widget
) GetMainWidget());
1085 // ---------------------------------------------------------------------------
1087 // ---------------------------------------------------------------------------
1089 #if wxUSE_DRAG_AND_DROP
1091 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1098 // Old style file-manager drag&drop
1099 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1104 // ----------------------------------------------------------------------------
1106 // ----------------------------------------------------------------------------
1110 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1115 #endif // wxUSE_TOOLTIPS
1117 // ----------------------------------------------------------------------------
1119 // ----------------------------------------------------------------------------
1121 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1123 Widget widget
= (Widget
) GetMainWidget();
1125 /* The menuId field seems to be usused, so we'll use it to
1126 indicate whether a menu is popped up or not:
1127 0: Not currently created as a popup
1128 -1: Created as a popup, but not active
1132 if (menu
->GetParent() && (menu
->GetId() != -1))
1135 if (menu
->GetMainWidget()) {
1136 menu
->DestroyMenu(TRUE
);
1139 menu
->SetId(1); /* Mark as popped-up */
1140 menu
->CreateMenu(NULL
, widget
, menu
);
1141 menu
->SetInvokingWindow(this);
1145 // menu->SetParent(parent);
1146 // parent->children->Append(menu); // Store menu for later deletion
1148 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1156 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1158 wxCanvas *canvas = (wxCanvas *) this;
1159 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1160 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1164 Display
*display
= XtDisplay (widget
);
1165 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1166 Window thisWindow
= XtWindow (widget
);
1168 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1169 &rootX
, &rootY
, &childWindow
);
1171 XButtonPressedEvent event
;
1172 event
.type
= ButtonPress
;
1178 event
.x_root
= rootX
;
1179 event
.y_root
= rootY
;
1181 XmMenuPosition (menuWidget
, &event
);
1182 XtManageChild (menuWidget
);
1187 // ---------------------------------------------------------------------------
1188 // moving and resizing
1189 // ---------------------------------------------------------------------------
1191 bool wxWindow::PreResize()
1197 void wxWindow::DoGetSize(int *x
, int *y
) const
1201 CanvasGetSize(x
, y
);
1205 Widget widget
= (Widget
) GetTopWidget();
1207 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1208 if(x
) *x
= xx
; if(y
) *y
= yy
;
1211 void wxWindow::DoGetPosition(int *x
, int *y
) const
1215 CanvasGetPosition(x
, y
);
1218 Widget widget
= (Widget
) GetTopWidget();
1220 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1222 // We may be faking the client origin. So a window that's really at (0, 30)
1223 // may appear (to wxWin apps) to be at (0, 0).
1226 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1231 if(x
) *x
= xx
; if(y
) *y
= yy
;
1234 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1236 Widget widget
= (Widget
) GetClientWidget();
1237 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1238 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1239 Window thisWindow
= XtWindow(widget
);
1244 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1247 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1249 Widget widget
= (Widget
) GetClientWidget();
1250 Display
*display
= XtDisplay(widget
);
1251 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1252 Window thisWindow
= XtWindow(widget
);
1257 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1261 // Get size *available for subwindows* i.e. excluding menu bar etc.
1262 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1264 Widget widget
= (Widget
) GetClientWidget();
1266 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1267 if(x
) *x
= xx
; if(y
) *y
= yy
;
1270 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1272 // A bit of optimization to help sort out the flickers.
1273 int oldX
, oldY
, oldW
, oldH
;
1274 GetSize(& oldW
, & oldH
);
1275 GetPosition(& oldX
, & oldY
);
1277 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1290 bool nothingChanged
= (x
== oldX
) && (y
== oldY
) &&
1291 (width
== oldW
) && (height
== oldH
);
1293 if (!wxNoOptimize::CanOptimize())
1295 nothingChanged
= FALSE
;
1298 if ( !nothingChanged
)
1302 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
1306 Widget widget
= (Widget
) GetTopWidget();
1310 bool managed
= XtIsManaged( widget
);
1312 XtUnmanageChild(widget
);
1316 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1318 DoMoveWindow(xx
, yy
, width
, height
);
1321 XtManageChild(widget
);
1323 // How about this bit. Maybe we don't need to generate size events
1324 // all the time -- they'll be generated when the window is sized anyway.
1326 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1327 sizeEvent
.SetEventObject(this);
1329 GetEventHandler()->ProcessEvent(sizeEvent
);
1334 void wxWindow::DoSetClientSize(int width
, int height
)
1338 CanvasSetClientSize(width
, height
);
1342 Widget widget
= (Widget
) GetTopWidget();
1345 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1347 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1349 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1350 sizeEvent
.SetEventObject(this);
1352 GetEventHandler()->ProcessEvent(sizeEvent
);
1355 // For implementation purposes - sometimes decorations make the client area
1357 wxPoint
wxWindow::GetClientAreaOrigin() const
1359 return wxPoint(0, 0);
1362 // Makes an adjustment to the window position (for example, a frame that has
1363 // a toolbar that it manages itself).
1364 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
1366 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
1368 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1369 x
+= pt
.x
; y
+= pt
.y
;
1373 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1380 wxFrame
*frame
= wxDynamicCast(this, wxFrame
);
1383 // TODO what about dialogs?
1387 Widget widget
= (Widget
) frame
->GetShellWidget();
1390 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1392 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1394 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1396 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1398 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1400 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1403 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1405 XtVaSetValues((Widget
)GetTopWidget(),
1413 // ---------------------------------------------------------------------------
1415 // ---------------------------------------------------------------------------
1417 int wxWindow::GetCharHeight() const
1419 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1421 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1423 int direction
, ascent
, descent
;
1424 XCharStruct overall
;
1425 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1426 &descent
, &overall
);
1428 // return (overall.ascent + overall.descent);
1429 return (ascent
+ descent
);
1432 int wxWindow::GetCharWidth() const
1434 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1436 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1438 int direction
, ascent
, descent
;
1439 XCharStruct overall
;
1440 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1441 &descent
, &overall
);
1443 return overall
.width
;
1446 void wxWindow::GetTextExtent(const wxString
& string
,
1448 int *descent
, int *externalLeading
,
1449 const wxFont
*theFont
) const
1451 wxFont
*fontToUse
= (wxFont
*)theFont
;
1453 fontToUse
= (wxFont
*) & m_font
;
1455 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1457 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1459 int direction
, ascent
, descent2
;
1460 XCharStruct overall
;
1461 int slen
= string
.Len();
1465 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1466 &ascent
, &descent2
, &overall
);
1469 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1470 &direction
, &ascent
, &descent2
, &overall
);
1473 *x
= (overall
.width
);
1475 *y
= (ascent
+ descent2
);
1477 *descent
= descent2
;
1478 if (externalLeading
)
1479 *externalLeading
= 0;
1483 // ----------------------------------------------------------------------------
1485 // ----------------------------------------------------------------------------
1487 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1489 m_needsRefresh
= TRUE
;
1490 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1491 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1493 XExposeEvent dummyEvent
;
1495 GetSize(&width
, &height
);
1497 dummyEvent
.type
= Expose
;
1498 dummyEvent
.display
= display
;
1499 dummyEvent
.send_event
= True
;
1500 dummyEvent
.window
= thisWindow
;
1503 dummyEvent
.x
= rect
->x
;
1504 dummyEvent
.y
= rect
->y
;
1505 dummyEvent
.width
= rect
->width
;
1506 dummyEvent
.height
= rect
->height
;
1512 dummyEvent
.width
= width
;
1513 dummyEvent
.height
= height
;
1515 dummyEvent
.count
= 0;
1519 wxClientDC
dc(this);
1520 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1521 dc
.SetBackground(backgroundBrush
);
1528 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1531 void wxWindow::Clear()
1533 wxClientDC
dc(this);
1534 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1535 dc
.SetBackground(brush
);
1539 void wxWindow::ClearUpdateRects()
1541 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1544 wxRect
* rect
= node
->GetData();
1546 node
= node
->GetNext();
1549 m_updateRects
.Clear();
1552 void wxWindow::DoPaint()
1554 //TODO : make a temporary gc so we can do the XCopyArea below
1555 if (m_backingPixmap
&& !m_needsRefresh
)
1559 GC tempGC
= (GC
) dc
.GetBackingGC();
1561 Widget widget
= (Widget
) GetMainWidget();
1566 // We have to test whether it's a wxScrolledWindow (hack!) because
1567 // otherwise we don't know how many pixels have been scrolled. We might
1568 // solve this in the future by defining virtual wxWindow functions to get
1569 // the scroll position in pixels. Or, each kind of scrolled window has to
1570 // implement backing stores itself, using generic wxWindows code.
1571 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1572 if ( scrolledWindow
)
1575 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1581 // TODO: This could be optimized further by only copying the areas in the
1582 // current update region.
1584 // Only blit the part visible in the client area. The backing pixmap
1585 // always starts at 0, 0 but we may be looking at only a portion of it.
1586 wxSize clientArea
= GetClientSize();
1587 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1588 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1590 // Copy whichever is samller, the amount of pixmap we have to copy,
1591 // or the size of the client area.
1592 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1593 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1595 // Make sure we're not negative
1596 toBlitX
= wxMax(0, toBlitX
);
1597 toBlitY
= wxMax(0, toBlitY
);
1602 (Pixmap
) m_backingPixmap
,
1605 scrollPosX
, scrollPosY
, // Start at the scroll position
1606 toBlitX
, toBlitY
, // How much of the pixmap to copy
1612 // Set an erase event first
1613 wxEraseEvent
eraseEvent(GetId());
1614 eraseEvent
.SetEventObject(this);
1615 GetEventHandler()->ProcessEvent(eraseEvent
);
1617 wxPaintEvent
event(GetId());
1618 event
.SetEventObject(this);
1619 GetEventHandler()->ProcessEvent(event
);
1621 m_needsRefresh
= FALSE
;
1625 // ----------------------------------------------------------------------------
1627 // ----------------------------------------------------------------------------
1629 // Responds to colour changes: passes event on to children.
1630 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1632 wxWindowList::Node
*node
= GetChildren().GetFirst();
1635 // Only propagate to non-top-level windows
1636 wxWindow
*win
= node
->GetData();
1637 if ( win
->GetParent() )
1639 wxSysColourChangedEvent event2
;
1640 event
.m_eventObject
= win
;
1641 win
->GetEventHandler()->ProcessEvent(event2
);
1644 node
= node
->GetNext();
1648 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1650 // This calls the UI-update mechanism (querying windows for
1651 // menu/toolbar/control state information)
1655 // ----------------------------------------------------------------------------
1657 // ----------------------------------------------------------------------------
1659 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1661 if (!m_acceleratorTable
.Ok())
1664 int count
= m_acceleratorTable
.GetCount();
1665 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1667 for (i
= 0; i
< count
; i
++)
1669 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1670 if (entry
->MatchesEvent(event
))
1672 // Bingo, we have a match. Now find a control that matches the entry
1675 // Need to go up to the top of the window hierarchy, since it might
1676 // be e.g. a menu item
1677 wxWindow
* parent
= this;
1678 while ( parent
&& !parent
->IsTopLevel() )
1679 parent
= parent
->GetParent();
1684 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1687 // Try for a menu command
1688 if (frame
->GetMenuBar())
1690 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1693 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1694 commandEvent
.SetEventObject(frame
);
1696 // If ProcessEvent returns TRUE (it was handled), then
1697 // the calling code will skip the event handling.
1698 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1703 // Find a child matching the command id
1704 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1710 // Now we process those kinds of windows that we can.
1711 // For now, only buttons.
1712 if ( wxDynamicCast(child
, wxButton
) )
1714 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1715 commandEvent
.SetEventObject(child
);
1716 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1723 // We didn't match the key event against an accelerator.
1727 // ============================================================================
1728 // Motif-specific stuff from here on
1729 // ============================================================================
1731 // ----------------------------------------------------------------------------
1732 // function which maintain the global hash table mapping Widgets to wxWindows
1733 // ----------------------------------------------------------------------------
1735 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1737 wxWindow
*oldItem
= NULL
;
1738 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1740 wxLogDebug("Widget table clash: new widget is %ld, %s",
1741 (long)w
, win
->GetClassInfo()->GetClassName());
1745 wxWidgetHashTable
->Put((long) w
, win
);
1747 wxLogTrace("widget", "Widget 0x%08x <-> window %p (%s)",
1748 w
, win
, win
->GetClassInfo()->GetClassName());
1753 wxWindow
*wxGetWindowFromTable(Widget w
)
1755 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1758 void wxDeleteWindowFromTable(Widget w
)
1760 wxWidgetHashTable
->Delete((long)w
);
1763 // ----------------------------------------------------------------------------
1764 // add/remove window from the table
1765 // ----------------------------------------------------------------------------
1767 // Add to hash table, add event handler
1768 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1769 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1771 wxAddWindowToTable((Widget
) mainWidget
, this);
1772 if (CanAddEventHandler())
1774 XtAddEventHandler((Widget
) mainWidget
,
1775 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1777 wxPanelItemEventHandler
,
1784 XtOverrideTranslations ((Widget
) mainWidget
,
1785 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1786 XtFree ((char *) ptr
);
1789 // Some widgets have a parent form widget, e.g. wxRadioBox
1792 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1796 XtOverrideTranslations ((Widget
) formWidget
,
1797 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1798 XtFree ((char *) ptr
);
1805 SetSize (x
, y
, width
, height
);
1810 // Remove event handler, remove from hash table
1811 bool wxWindow::DetachWidget(WXWidget widget
)
1813 if (CanAddEventHandler())
1815 XtRemoveEventHandler((Widget
) widget
,
1816 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1818 wxPanelItemEventHandler
,
1822 wxDeleteWindowFromTable((Widget
) widget
);
1826 // ----------------------------------------------------------------------------
1827 // Motif-specific accessors
1828 // ----------------------------------------------------------------------------
1830 // Get the underlying X window
1831 WXWindow
wxWindow::GetXWindow() const
1833 Widget wMain
= (Widget
)GetMainWidget();
1835 return (WXWindow
) XtWindow(wMain
);
1837 return (WXWindow
) 0;
1840 // Get the underlying X display
1841 WXDisplay
*wxWindow::GetXDisplay() const
1843 Widget wMain
= (Widget
)GetMainWidget();
1845 return (WXDisplay
*) XtDisplay(wMain
);
1847 return (WXDisplay
*) NULL
;
1850 WXWidget
wxWindow::GetMainWidget() const
1853 return m_drawingArea
;
1855 return m_mainWidget
;
1858 WXWidget
wxWindow::GetClientWidget() const
1860 if (m_drawingArea
!= (WXWidget
) 0)
1861 return m_drawingArea
;
1863 return GetMainWidget();
1866 WXWidget
wxWindow::GetTopWidget() const
1868 return GetMainWidget();
1871 WXWidget
wxWindow::GetLabelWidget() const
1873 return GetMainWidget();
1876 // ----------------------------------------------------------------------------
1878 // ----------------------------------------------------------------------------
1880 // All widgets should have this as their resize proc.
1881 // OnSize sent to wxWindow via client data.
1882 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
), String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1884 wxWindow
*win
= wxGetWindowFromTable(w
);
1888 if (win
->PreResize())
1891 win
->GetSize(&width
, &height
);
1892 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1893 sizeEvent
.SetEventObject(win
);
1894 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1898 static void wxCanvasRepaintProc(Widget drawingArea
,
1899 XtPointer clientData
,
1900 XmDrawingAreaCallbackStruct
* cbs
)
1902 if (!wxGetWindowFromTable(drawingArea
))
1905 XEvent
* event
= cbs
->event
;
1906 wxWindow
* win
= (wxWindow
*) clientData
;
1908 switch (event
->type
)
1912 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1913 event
->xexpose
.width
, event
->xexpose
.height
);
1915 if (event
-> xexpose
.count
== 0)
1918 win
->ClearUpdateRects();
1925 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1926 static void wxCanvasEnterLeave(Widget drawingArea
,
1927 XtPointer
WXUNUSED(clientData
),
1928 XCrossingEvent
* event
)
1930 XmDrawingAreaCallbackStruct cbs
;
1933 ((XCrossingEvent
&) ev
) = *event
;
1935 cbs
.reason
= XmCR_INPUT
;
1938 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1941 // Fix to make it work under Motif 1.0 (!)
1942 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
), XButtonEvent
* WXUNUSED(event
))
1944 #if XmVersion <= 1000
1945 XmDrawingAreaCallbackStruct cbs
;
1948 ev
= *((XEvent
*) event
);
1949 cbs
.reason
= XmCR_INPUT
;
1952 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1953 #endif // XmVersion <= 1000
1956 static void wxCanvasInputEvent(Widget drawingArea
,
1957 XtPointer
WXUNUSED(data
),
1958 XmDrawingAreaCallbackStruct
* cbs
)
1960 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1966 if (cbs
->reason
!= XmCR_INPUT
)
1969 local_event
= *(cbs
->event
); // We must keep a copy!
1971 switch (local_event
.xany
.type
)
1979 // FIXME: most of this mouse event code is more or less
1980 // duplicated in wxTranslateMouseEvent
1982 wxEventType eventType
= wxEVT_NULL
;
1984 if (local_event
.xany
.type
== EnterNotify
)
1986 //if (local_event.xcrossing.mode!=NotifyNormal)
1987 // return ; // Ignore grab events
1988 eventType
= wxEVT_ENTER_WINDOW
;
1989 // canvas->GetEventHandler()->OnSetFocus();
1991 else if (local_event
.xany
.type
== LeaveNotify
)
1993 //if (local_event.xcrossingr.mode!=NotifyNormal)
1994 // return ; // Ignore grab events
1995 eventType
= wxEVT_LEAVE_WINDOW
;
1996 // canvas->GetEventHandler()->OnKillFocus();
1998 else if (local_event
.xany
.type
== MotionNotify
)
2000 eventType
= wxEVT_MOTION
;
2003 else if (local_event
.xany
.type
== ButtonPress
)
2005 if (local_event
.xbutton
.button
== Button1
)
2007 eventType
= wxEVT_LEFT_DOWN
;
2008 canvas
->SetButton1(TRUE
);
2010 else if (local_event
.xbutton
.button
== Button2
)
2012 eventType
= wxEVT_MIDDLE_DOWN
;
2013 canvas
->SetButton2(TRUE
);
2015 else if (local_event
.xbutton
.button
== Button3
)
2017 eventType
= wxEVT_RIGHT_DOWN
;
2018 canvas
->SetButton3(TRUE
);
2021 else if (local_event
.xany
.type
== ButtonRelease
)
2023 if (local_event
.xbutton
.button
== Button1
)
2025 eventType
= wxEVT_LEFT_UP
;
2026 canvas
->SetButton1(FALSE
);
2028 else if (local_event
.xbutton
.button
== Button2
)
2030 eventType
= wxEVT_MIDDLE_UP
;
2031 canvas
->SetButton2(FALSE
);
2033 else if (local_event
.xbutton
.button
== Button3
)
2035 eventType
= wxEVT_RIGHT_UP
;
2036 canvas
->SetButton3(FALSE
);
2040 wxMouseEvent
wxevent (eventType
);
2042 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2043 || (event_left_is_down (&local_event
)
2044 && (eventType
!= wxEVT_LEFT_UP
)));
2045 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2046 || (event_middle_is_down (&local_event
)
2047 && (eventType
!= wxEVT_MIDDLE_UP
)));
2048 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2049 || (event_right_is_down (&local_event
)
2050 && (eventType
!= wxEVT_RIGHT_UP
)));
2052 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2053 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2054 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2055 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2056 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2058 if ( eventType
== wxEVT_MOTION
)
2060 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2063 Display
*dpy
= XtDisplay (drawingArea
);
2065 XQueryPointer (dpy
, XtWindow (drawingArea
),
2067 &local_event
.xmotion
.x_root
,
2068 &local_event
.xmotion
.y_root
,
2069 &local_event
.xmotion
.x
,
2070 &local_event
.xmotion
.y
,
2071 &local_event
.xmotion
.state
);
2078 // Now check if we need to translate this event into a double click
2079 if (TRUE
) // canvas->doubleClickAllowed)
2081 if (wxevent
.ButtonDown())
2083 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2085 // get button and time-stamp
2087 if (wxevent
.LeftDown())
2089 else if (wxevent
.MiddleDown())
2091 else if (wxevent
.RightDown())
2093 long ts
= wxevent
.GetTimestamp();
2095 // check, if single or double click
2096 int buttonLast
= canvas
->GetLastClickedButton();
2097 long lastTS
= canvas
->GetLastClickTime();
2098 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2101 canvas
->SetLastClick(0, ts
);
2103 wxEventType typeDouble
;
2104 if ( eventType
== wxEVT_LEFT_DOWN
)
2105 typeDouble
= wxEVT_LEFT_DCLICK
;
2106 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2107 typeDouble
= wxEVT_MIDDLE_DCLICK
;
2108 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2109 typeDouble
= wxEVT_RIGHT_DCLICK
;
2111 typeDouble
= wxEVT_NULL
;
2113 if ( typeDouble
!= wxEVT_NULL
)
2115 wxevent
.SetEventType(typeDouble
);
2120 // not fast enough or different button
2121 canvas
->SetLastClick(button
, ts
);
2126 wxevent
.SetId(canvas
->GetId());
2127 wxevent
.SetEventObject(canvas
);
2128 wxevent
.m_x
= local_event
.xbutton
.x
;
2129 wxevent
.m_y
= local_event
.xbutton
.y
;
2130 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2132 if (eventType
== wxEVT_ENTER_WINDOW
||
2133 eventType
== wxEVT_LEAVE_WINDOW
||
2134 eventType
== wxEVT_MOTION
2144 XComposeStatus compose
;
2145 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, &compose
);
2148 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2149 int id
= wxCharCodeXToWX (keySym
);
2151 wxEventType eventType
= wxEVT_CHAR
;
2153 wxKeyEvent
event (eventType
);
2155 if (local_event
.xkey
.state
& ShiftMask
)
2156 event
.m_shiftDown
= TRUE
;
2157 if (local_event
.xkey
.state
& ControlMask
)
2158 event
.m_controlDown
= TRUE
;
2159 if (local_event
.xkey
.state
& Mod3Mask
)
2160 event
.m_altDown
= TRUE
;
2161 if (local_event
.xkey
.state
& Mod1Mask
)
2162 event
.m_metaDown
= TRUE
;
2163 event
.SetEventObject(canvas
);
2164 event
.m_keyCode
= id
;
2165 event
.SetTimestamp(local_event
.xkey
.time
);
2169 // Implement wxFrame::OnCharHook by checking ancestor.
2170 wxWindow
*parent
= canvas
->GetParent();
2171 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2172 parent
= parent
->GetParent();
2176 event
.SetEventType(wxEVT_CHAR_HOOK
);
2177 if (parent
->GetEventHandler()->ProcessEvent(event
))
2181 // For simplicity, OnKeyDown is the same as OnChar
2182 // TODO: filter modifier key presses from OnChar
2183 event
.SetEventType(wxEVT_KEY_DOWN
);
2185 // Only process OnChar if OnKeyDown didn't swallow it
2186 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2188 event
.SetEventType(wxEVT_CHAR
);
2189 canvas
->GetEventHandler()->ProcessEvent (event
);
2197 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2198 int id
= wxCharCodeXToWX (keySym
);
2200 wxKeyEvent
event (wxEVT_KEY_UP
);
2202 if (local_event
.xkey
.state
& ShiftMask
)
2203 event
.m_shiftDown
= TRUE
;
2204 if (local_event
.xkey
.state
& ControlMask
)
2205 event
.m_controlDown
= TRUE
;
2206 if (local_event
.xkey
.state
& Mod3Mask
)
2207 event
.m_altDown
= TRUE
;
2208 if (local_event
.xkey
.state
& Mod1Mask
)
2209 event
.m_metaDown
= TRUE
;
2210 event
.SetEventObject(canvas
);
2211 event
.m_keyCode
= id
;
2212 event
.SetTimestamp(local_event
.xkey
.time
);
2216 canvas
->GetEventHandler()->ProcessEvent (event
);
2222 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2224 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2225 event
.SetEventObject(canvas
);
2226 canvas
->GetEventHandler()->ProcessEvent(event
);
2232 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2234 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2235 event
.SetEventObject(canvas
);
2236 canvas
->GetEventHandler()->ProcessEvent(event
);
2245 static void wxPanelItemEventHandler(Widget wid
,
2246 XtPointer
WXUNUSED(client_data
),
2248 Boolean
*continueToDispatch
)
2250 // Widget can be a label or the actual widget.
2252 wxWindow
*window
= wxGetWindowFromTable(wid
);
2255 wxMouseEvent
wxevent(0);
2256 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2258 window
->GetEventHandler()->ProcessEvent(wxevent
);
2262 // TODO: probably the key to allowing default behaviour to happen. Say we
2263 // set a m_doDefault flag to FALSE at the start of this function. Then in
2264 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2265 // TRUE, indicating that default processing can happen. Thus, behaviour can
2266 // appear to be overridden just by adding an event handler and not calling
2267 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2268 // way of handling drawing area events, to simplify things.
2269 *continueToDispatch
= True
;
2272 static void wxScrollBarCallback(Widget scrollbar
,
2273 XtPointer clientData
,
2274 XmScrollBarCallbackStruct
*cbs
)
2276 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2277 int orientation
= (int) clientData
;
2279 wxEventType eventType
= wxEVT_NULL
;
2280 switch (cbs
->reason
)
2282 case XmCR_INCREMENT
:
2284 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2287 case XmCR_DECREMENT
:
2289 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2294 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2297 case XmCR_VALUE_CHANGED
:
2299 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2302 case XmCR_PAGE_INCREMENT
:
2304 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2307 case XmCR_PAGE_DECREMENT
:
2309 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2314 eventType
= wxEVT_SCROLLWIN_TOP
;
2317 case XmCR_TO_BOTTOM
:
2319 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2324 // Should never get here
2325 wxFAIL_MSG("Unknown scroll event.");
2330 wxScrollWinEvent
event(eventType
,
2332 ((orientation
== XmHORIZONTAL
) ?
2333 wxHORIZONTAL
: wxVERTICAL
));
2334 event
.SetEventObject( win
);
2335 win
->GetEventHandler()->ProcessEvent(event
);
2338 // For repainting arbitrary windows
2339 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2344 wxWindow
* win
= wxGetWindowFromTable(w
);
2348 switch(event
-> type
)
2352 window
= (Window
) win
-> GetXWindow();
2353 display
= (Display
*) win
-> GetXDisplay();
2355 if (event
-> xexpose
.count
== 0)
2359 win
->ClearUpdateRects();
2363 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2364 event
->xexpose
.width
, event
->xexpose
.height
);
2372 // ----------------------------------------------------------------------------
2373 // CanvaseXXXSize() functions
2374 // ----------------------------------------------------------------------------
2376 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2377 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2379 // A bit of optimization to help sort out the flickers.
2380 int oldX
, oldY
, oldW
, oldH
;
2381 GetSize(& oldW
, & oldH
);
2382 GetPosition(& oldX
, & oldY
);
2384 bool useOldPos
= FALSE
;
2385 bool useOldSize
= FALSE
;
2387 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2389 else if (x
== oldX
&& y
== oldY
)
2392 if ((w
== -1) && (h
== -1))
2394 else if (w
== oldW
&& h
== oldH
)
2397 if (!wxNoOptimize::CanOptimize())
2399 useOldSize
= FALSE
; useOldPos
= FALSE
;
2402 if (useOldPos
&& useOldSize
)
2405 Widget drawingArea
= (Widget
) m_drawingArea
;
2406 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2409 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2410 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2412 int xx
= x
; int yy
= y
;
2413 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2417 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2419 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2423 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2425 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2437 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2438 short thick
, margin
;
2439 XtVaGetValues ((Widget
) m_borderWidget
,
2440 XmNshadowThickness
, &thick
,
2441 XmNmarginWidth
, &margin
,
2443 w
-= 2 * (thick
+ margin
);
2446 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2450 XtVaGetValues ((Widget
) m_scrolledWindow
,
2451 XmNspacing
, &spacing
,
2452 XmNverticalScrollBar
, &sbar
,
2456 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2460 w
-= (spacing
+ wsbar
);
2463 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2470 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2471 short thick
, margin
;
2472 XtVaGetValues ((Widget
) m_borderWidget
,
2473 XmNshadowThickness
, &thick
,
2474 XmNmarginHeight
, &margin
,
2476 h
-= 2 * (thick
+ margin
);
2479 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2483 XtVaGetValues ((Widget
) m_scrolledWindow
,
2484 XmNspacing
, &spacing
,
2485 XmNhorizontalScrollBar
, &sbar
,
2489 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2493 h
-= (spacing
+ wsbar
);
2496 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2502 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2503 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2507 GetClientSize (&ww
, &hh
);
2508 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2509 sizeEvent
.SetEventObject(this);
2511 GetEventHandler()->ProcessEvent(sizeEvent
);
2515 void wxWindow::CanvasSetClientSize (int w
, int h
)
2517 Widget drawingArea
= (Widget
) m_drawingArea
;
2519 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2522 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2524 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2527 // TODO: is this necessary?
2528 allowRepainting
= FALSE
;
2530 XSync (XtDisplay (drawingArea
), FALSE
);
2532 while (XtAppPending (wxTheApp
->appContext
))
2534 XFlush (XtDisplay (drawingArea
));
2535 XtAppNextEvent (wxTheApp
->appContext
, &event
);
2536 XtDispatchEvent (&event
);
2540 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2543 allowRepainting
= TRUE
;
2546 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2547 sizeEvent
.SetEventObject(this);
2549 GetEventHandler()->ProcessEvent(sizeEvent
);
2553 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2555 // Must return the same thing that was set via SetClientSize
2557 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2562 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2565 if ((Widget
) m_borderWidget
)
2566 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2567 else if ((Widget
) m_scrolledWindow
)
2568 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2570 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2576 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2579 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2581 // We may be faking the client origin.
2582 // So a window that's really at (0, 30) may appear
2583 // (to wxWin apps) to be at (0, 0).
2586 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2595 // ----------------------------------------------------------------------------
2596 // TranslateXXXEvent() functions
2597 // ----------------------------------------------------------------------------
2599 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2601 switch (xevent
->xany
.type
)
2603 case EnterNotify
: // never received here - yes ? MB
2604 case LeaveNotify
: // never received here - yes ? MB
2609 wxEventType eventType
= wxEVT_NULL
;
2611 // FIXME: this is never true I think - MB
2613 if (xevent
->xany
.type
== LeaveNotify
)
2615 win
->SetButton1(FALSE
);
2616 win
->SetButton2(FALSE
);
2617 win
->SetButton3(FALSE
);
2620 else if (xevent
->xany
.type
== MotionNotify
)
2622 eventType
= wxEVT_MOTION
;
2624 else if (xevent
->xany
.type
== ButtonPress
)
2626 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2628 if (xevent
->xbutton
.button
== Button1
)
2630 eventType
= wxEVT_LEFT_DOWN
;
2631 win
->SetButton1(TRUE
);
2634 else if (xevent
->xbutton
.button
== Button2
)
2636 eventType
= wxEVT_MIDDLE_DOWN
;
2637 win
->SetButton2(TRUE
);
2640 else if (xevent
->xbutton
.button
== Button3
)
2642 eventType
= wxEVT_RIGHT_DOWN
;
2643 win
->SetButton3(TRUE
);
2647 // check for a double click
2649 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2650 long ts
= wxevent
.GetTimestamp();
2652 int buttonLast
= win
->GetLastClickedButton();
2653 long lastTS
= win
->GetLastClickTime();
2654 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2657 win
->SetLastClick(0, ts
);
2658 if ( eventType
== wxEVT_LEFT_DOWN
)
2659 eventType
= wxEVT_LEFT_DCLICK
;
2660 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2661 eventType
= wxEVT_MIDDLE_DCLICK
;
2662 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2663 eventType
= wxEVT_RIGHT_DCLICK
;
2667 // not fast enough or different button
2668 win
->SetLastClick(button
, ts
);
2671 else if (xevent
->xany
.type
== ButtonRelease
)
2673 if (xevent
->xbutton
.button
== Button1
)
2675 eventType
= wxEVT_LEFT_UP
;
2676 win
->SetButton1(FALSE
);
2678 else if (xevent
->xbutton
.button
== Button2
)
2680 eventType
= wxEVT_MIDDLE_UP
;
2681 win
->SetButton2(FALSE
);
2683 else if (xevent
->xbutton
.button
== Button3
)
2685 eventType
= wxEVT_RIGHT_UP
;
2686 win
->SetButton3(FALSE
);
2695 wxevent
.SetEventType(eventType
);
2698 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2701 win
->GetPosition(&x2
, &y2
);
2703 // The button x/y must be translated to wxWindows
2704 // window space - the widget might be a label or button,
2708 if (widget
!= (Widget
)win
->GetMainWidget())
2714 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2715 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2717 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2718 || (event_left_is_down (xevent
)
2719 && (eventType
!= wxEVT_LEFT_UP
)));
2720 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2721 || (event_middle_is_down (xevent
)
2722 && (eventType
!= wxEVT_MIDDLE_UP
)));
2723 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2724 || (event_right_is_down (xevent
)
2725 && (eventType
!= wxEVT_RIGHT_UP
)));
2727 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2728 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2729 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
2730 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
2732 wxevent
.SetId(win
->GetId());
2733 wxevent
.SetEventObject(win
);
2741 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget
WXUNUSED(widget
), XEvent
*xevent
)
2743 switch (xevent
->xany
.type
)
2752 XComposeStatus compose
;
2753 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, &compose
);
2755 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2756 int id
= wxCharCodeXToWX (keySym
);
2758 if (xevent
->xkey
.state
& ShiftMask
)
2759 wxevent
.m_shiftDown
= TRUE
;
2760 if (xevent
->xkey
.state
& ControlMask
)
2761 wxevent
.m_controlDown
= TRUE
;
2762 if (xevent
->xkey
.state
& Mod3Mask
)
2763 wxevent
.m_altDown
= TRUE
;
2764 if (xevent
->xkey
.state
& Mod1Mask
)
2765 wxevent
.m_metaDown
= TRUE
;
2766 wxevent
.SetEventObject(win
);
2767 wxevent
.m_keyCode
= id
;
2768 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2770 wxevent
.m_x
= xevent
->xbutton
.x
;
2771 wxevent
.m_y
= xevent
->xbutton
.y
;
2785 // ----------------------------------------------------------------------------
2787 // ----------------------------------------------------------------------------
2789 #define YAllocColor XAllocColor
2790 XColor g_itemColors
[5];
2791 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2794 static XmColorProc colorProc
;
2796 result
= wxNO_COLORS
;
2800 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2801 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2802 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2803 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2804 if (colorProc
== (XmColorProc
) NULL
)
2806 // Get a ptr to the actual function
2807 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2808 // And set it back to motif.
2809 XmSetColorCalculation (colorProc
);
2811 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2812 &g_itemColors
[wxFORE_INDEX
],
2813 &g_itemColors
[wxSELE_INDEX
],
2814 &g_itemColors
[wxTOPS_INDEX
],
2815 &g_itemColors
[wxBOTS_INDEX
]);
2816 result
= wxBACK_COLORS
;
2820 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2821 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2822 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2823 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2824 if (result
== wxNO_COLORS
)
2825 result
= wxFORE_COLORS
;
2828 Display
*dpy
= display
;
2829 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2833 /* 5 Colours to allocate */
2834 for (int i
= 0; i
< 5; i
++)
2835 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2836 result
= wxNO_COLORS
;
2840 /* Only 1 colour to allocate */
2841 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2842 result
= wxNO_COLORS
;
2849 // Changes the foreground and background colours to be derived from the current
2850 // background colour. To change the foreground colour, you must call
2851 // SetForegroundColour explicitly.
2852 void wxWindow::ChangeBackgroundColour()
2854 WXWidget mainWidget
= GetMainWidget();
2856 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2858 // This not necessary
2861 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
2863 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
2864 // Have to set the scrollbar colours back since
2865 // the scrolled window seemed to change them
2866 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
2869 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
2871 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
2876 void wxWindow::ChangeForegroundColour()
2878 WXWidget mainWidget
= GetMainWidget();
2880 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2881 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2882 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2885 // Change a widget's foreground and background colours.
2886 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
2888 // When should we specify the foreground, if it's calculated
2889 // by wxComputeColours?
2890 // Solution: say we start with the default (computed) foreground colour.
2891 // If we call SetForegroundColour explicitly for a control or window,
2892 // then the foreground is changed.
2893 // Therefore SetBackgroundColour computes the foreground colour, and
2894 // SetForegroundColour changes the foreground colour. The ordering is
2897 Widget w
= (Widget
)widget
;
2900 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
2905 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
2907 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
2910 XtVaSetValues ((Widget
) widget
,
2911 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
2912 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
2913 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
2914 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
2917 if (changeArmColour
)
2918 XtVaSetValues ((Widget
) widget
,
2919 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
2923 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2925 if ( !wxWindowBase::SetBackgroundColour(col
) )
2928 ChangeBackgroundColour();
2933 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2935 if ( !wxWindowBase::SetForegroundColour(col
) )
2938 ChangeForegroundColour();
2943 void wxWindow::ChangeFont(bool keepOriginalSize
)
2945 // Note that this causes the widget to be resized back
2946 // to its original size! We therefore have to set the size
2947 // back again. TODO: a better way in Motif?
2948 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2949 if (w
&& m_font
.Ok())
2951 int width
, height
, width1
, height1
;
2952 GetSize(& width
, & height
);
2954 // lesstif 0.87 hangs here
2955 #ifndef LESSTIF_VERSION
2957 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
2961 GetSize(& width1
, & height1
);
2962 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2964 SetSize(-1, -1, width
, height
);
2969 // ----------------------------------------------------------------------------
2971 // ----------------------------------------------------------------------------
2973 wxWindow
*wxGetActiveWindow()
2976 wxFAIL_MSG("Not implemented");
2980 // Find the wxWindow at the current mouse position, returning the mouse
2982 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2984 return wxFindWindowAtPoint(wxGetMousePosition());
2987 // Get the current mouse position.
2988 wxPoint
wxGetMousePosition()
2990 Display
*display
= (Display
*) wxGetDisplay();
2991 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2992 Window rootReturn
, childReturn
;
2993 int rootX
, rootY
, winX
, winY
;
2994 unsigned int maskReturn
;
2996 XQueryPointer (display
,
3000 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
3001 return wxPoint(rootX
, rootY
);
3004 // ----------------------------------------------------------------------------
3005 // wxNoOptimize: switch off size optimization
3006 // ----------------------------------------------------------------------------
3008 int wxNoOptimize::ms_count
= 0;