1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/window.cpp
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/dcclient.h"
30 #include "wx/button.h"
32 #include "wx/settings.h"
33 #include "wx/scrolwin.h"
34 #include "wx/layout.h"
35 #include "wx/menuitem.h"
36 #include "wx/module.h"
39 #include "wx/evtloop.h"
40 #include "wx/unix/utilsx11.h"
42 #if wxUSE_DRAG_AND_DROP
46 // DoSetSizeIntr and DoMoveWindowIntr
48 // under Motif composite controls (such as wxCalendarCtrl or generic wxSpinCtrl
49 // did not work and/or segfaulted because
50 // 1) wxWindow::Create calls SetSize,
51 // which results in a call to DoSetSize much earlier than in the other ports
52 // 2) if wxWindow::Create is called (wxControl::Create calls it)
53 // then DoSetSize is never called, causing layout problems in composite
57 // 1) don't call SetSize, DoSetSize, DoMoveWindow, DoGetPosition,
58 // DoSetPosition directly or indirectly from wxWindow::Create
59 // 2) call DoMoveWindow from DoSetSize, allowing controls to override it
62 #pragma message disable nosimpint
66 #include <Xm/DrawingA.h>
67 #include <Xm/ScrolledW.h>
68 #include <Xm/ScrollBar.h>
71 #include <Xm/RowColumn.h> // for XmMenuPosition
73 #pragma message enable nosimpint
76 #include "wx/motif/private.h"
77 #include "wx/motif/dcclient.h"
81 // ----------------------------------------------------------------------------
82 // global variables for this module
83 // ----------------------------------------------------------------------------
85 extern wxHashTable
*wxWidgetHashTable
;
86 static wxWindow
* g_captureWindow
= NULL
;
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
94 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
95 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
96 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
97 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
98 XmScrollBarCallbackStruct
*cbs
);
99 static void wxPanelItemEventHandler(Widget wid
,
100 XtPointer client_data
,
102 Boolean
*continueToDispatch
);
107 // Helper function for 16-bit fonts
108 static int str16len(const char *s
)
112 while (s
[0] && s
[1]) {
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
127 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
128 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
134 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
135 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
138 // ============================================================================
140 // ============================================================================
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
148 Widget w
= (Widget
)widget
;
156 bool wxWindow::MapOrUnmap(WXWidget widget
, bool domap
)
158 Widget w
= (Widget
)widget
;
162 // Rationale: a lot of common operations (including but not
163 // limited to moving, resizing and appending items to a listbox)
164 // unmamange the widget, do their work, then manage it again.
165 // This means that, for example adding an item to a listbox will show it,
166 // or that most controls are shown every time they are moved or resized!
167 XtSetMappedWhenManaged( w
, domap
);
169 // if the widget is not unmanaged, it still intercepts
170 // mouse events, even if it is not mapped (and hence invisible)
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 void wxWindow::Init()
192 m_needsRefresh
= true;
193 m_mainWidget
= (WXWidget
) 0;
195 m_winCaptured
= false;
203 m_drawingArea
= (WXWidget
) 0;
208 m_backingPixmap
= (WXPixmap
) 0;
219 // real construction (Init() must have been called before!)
220 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
224 const wxString
& name
)
226 // Get default border
227 wxBorder border
= GetBorder(style
);
228 style
&= ~wxBORDER_MASK
;
231 wxCHECK_MSG( parent
, false, "can't create wxWindow without parent" );
233 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
235 parent
->AddChild(this);
238 //// TODO: we should probably optimize by only creating a
239 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
240 //// But for now, let's simplify things by always creating the
241 //// drawing area, since otherwise the translations are different.
243 // New translations for getting mouse motion feedback
244 static const String translations
= wxMOTIF_STR(
245 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
246 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
247 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
248 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
249 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
250 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
251 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
252 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
253 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
254 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
255 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
256 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
257 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
258 <Key>: DrawingAreaInput()");
260 XtActionsRec actions
[1];
261 actions
[0].string
= wxMOTIF_STR("wxCanvasMotionEvent");
262 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
263 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
265 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
266 m_borderWidget
= wxCreateBorderWidget( (WXWidget
)parentWidget
, style
);
268 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
271 xmScrolledWindowWidgetClass
,
272 m_borderWidget
? (Widget
) m_borderWidget
274 XmNresizePolicy
, XmRESIZE_NONE
,
276 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
277 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
281 XtTranslations ptr
= XtParseTranslationTable(translations
);
282 m_drawingArea
= (WXWidget
)XtVaCreateWidget
285 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
286 XmNunitType
, XmPIXELS
,
287 // XmNresizePolicy, XmRESIZE_ANY,
288 XmNresizePolicy
, XmRESIZE_NONE
,
291 XmNtranslations
, ptr
,
294 XtFree((char *) ptr
);
297 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
299 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
300 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
301 XtFree ((char *) ptr
);
305 wxAddWindowToTable((Widget
) m_drawingArea
, this);
306 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
308 // This order is very important in Motif 1.2.1
309 XtRealizeWidget ((Widget
) m_scrolledWindow
);
310 XtRealizeWidget ((Widget
) m_drawingArea
);
311 XtManageChild ((Widget
) m_drawingArea
);
313 ptr
= XtParseTranslationTable("<Configure>: resize()");
314 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
315 XtFree ((char *) ptr
);
317 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
318 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
321 (Widget
)m_drawingArea
,
322 PointerMotionHintMask
| EnterWindowMask
|
323 LeaveWindowMask
| FocusChangeMask
,
325 (XtEventHandler
) wxCanvasEnterLeave
,
329 XmScrolledWindowSetAreas(
330 (Widget
)m_scrolledWindow
,
331 (Widget
) 0, (Widget
) 0,
332 (Widget
) m_drawingArea
);
336 // Without this, the cursor may not be restored properly (e.g. in splitter
338 SetCursor(*wxSTANDARD_CURSOR
);
339 DoSetSizeIntr(pos
.x
, pos
.y
, size
.x
,size
.y
, wxSIZE_AUTO
, true);
344 wxWindow::~wxWindow()
348 if (g_captureWindow
== this)
349 g_captureWindow
= NULL
;
351 // Motif-specific actions first
352 WXWidget wMain
= GetMainWidget();
355 // Removes event handlers
359 // If m_drawingArea, we're a fully-fledged window with drawing area,
360 // scrollbars etc. (what wxCanvas used to be)
363 // Destroy children before destroying self
367 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
369 Widget w
= (Widget
) m_drawingArea
;
370 wxDeleteWindowFromTable(w
);
375 m_drawingArea
= (WXWidget
) 0;
378 // Only if we're _really_ a canvas (not a dialog box/panel)
379 if (m_scrolledWindow
)
381 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
386 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
387 XtUnmanageChild((Widget
) m_hScrollBar
);
391 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
392 XtUnmanageChild((Widget
) m_vScrollBar
);
396 XtDestroyWidget((Widget
) m_hScrollBar
);
398 XtDestroyWidget((Widget
) m_vScrollBar
);
400 UnmanageAndDestroy(m_scrolledWindow
);
404 XtDestroyWidget ((Widget
) m_borderWidget
);
405 m_borderWidget
= (WXWidget
) 0;
408 else // Why wasn't this here before? JACS 8/3/2000
412 // Destroy the window
415 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
416 // Child widgets will get destroyed automatically when a frame
417 // or dialog is destroyed, but before that you may get some memory
418 // leaks and potential layout problems if you delete and then add
421 // GRG, Feb/2000: commented this out when adding support for
422 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
423 // that this call crashed wxMotif under OS/2, so it seems
424 // that leaving it out is the right thing to do.
425 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
426 XtDestroyWidget((Widget
) GetMainWidget());
427 SetMainWidget((WXWidget
) NULL
);
431 // ----------------------------------------------------------------------------
432 // scrollbar management
433 // ----------------------------------------------------------------------------
435 WXWidget
wxWindow::DoCreateScrollBar(WXWidget parent
,
436 wxOrientation orientation
,
439 int orient
= ( orientation
& wxHORIZONTAL
) ? XmHORIZONTAL
: XmVERTICAL
;
441 XtVaCreateManagedWidget( "scrollBarWidget",
442 xmScrollBarWidgetClass
, (Widget
)parent
,
443 XmNorientation
, orient
,
448 XtPointer o
= (XtPointer
)orientation
;
449 XtCallbackProc cb
= (XtCallbackProc
)callback
;
451 XtAddCallback( sb
, XmNvalueChangedCallback
, cb
, o
);
452 XtAddCallback( sb
, XmNdragCallback
, cb
, o
);
453 XtAddCallback( sb
, XmNincrementCallback
, cb
, o
);
454 XtAddCallback( sb
, XmNdecrementCallback
, cb
, o
);
455 XtAddCallback( sb
, XmNpageIncrementCallback
, cb
, o
);
456 XtAddCallback( sb
, XmNpageDecrementCallback
, cb
, o
);
457 XtAddCallback( sb
, XmNtoTopCallback
, cb
, o
);
458 XtAddCallback( sb
, XmNtoBottomCallback
, cb
, o
);
464 void wxWindow::CreateScrollbar(wxOrientation orientation
)
466 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
468 XtVaSetValues( (Widget
) m_scrolledWindow
,
469 XmNresizePolicy
, XmRESIZE_NONE
,
472 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
473 // Add scrollbars if required
474 if (orientation
== wxHORIZONTAL
)
476 m_hScrollBar
= DoCreateScrollBar( m_scrolledWindow
, wxHORIZONTAL
,
477 (void (*)())wxScrollBarCallback
);
479 wxDoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, true);
481 XtRealizeWidget( (Widget
)m_hScrollBar
);
483 XtVaSetValues((Widget
) m_scrolledWindow
,
484 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
487 wxAddWindowToTable( (Widget
)m_hScrollBar
, this );
489 else if (orientation
== wxVERTICAL
)
491 m_vScrollBar
= DoCreateScrollBar( m_scrolledWindow
, wxVERTICAL
,
492 (void (*)())wxScrollBarCallback
);
494 wxDoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, true);
496 XtRealizeWidget((Widget
)m_vScrollBar
);
498 XtVaSetValues((Widget
) m_scrolledWindow
,
499 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
502 wxAddWindowToTable( (Widget
)m_vScrollBar
, this );
505 XtVaSetValues( (Widget
) m_scrolledWindow
,
506 XmNresizePolicy
, XmRESIZE_ANY
,
510 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
512 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
514 XtVaSetValues((Widget
) m_scrolledWindow
,
515 XmNresizePolicy
, XmRESIZE_NONE
,
517 String stringSB
= orientation
== wxHORIZONTAL
?
518 XmNhorizontalScrollBar
: XmNverticalScrollBar
;
519 WXWidget
* widgetSB
= orientation
== wxHORIZONTAL
?
520 &m_hScrollBar
: &m_vScrollBar
;
524 wxDeleteWindowFromTable( (Widget
)*widgetSB
);
525 XtDestroyWidget( (Widget
)*widgetSB
);
526 *widgetSB
= (WXWidget
)NULL
;
529 XtVaSetValues( (Widget
)m_scrolledWindow
,
530 stringSB
, (Widget
) 0,
533 XtVaSetValues((Widget
) m_scrolledWindow
,
534 XmNresizePolicy
, XmRESIZE_ANY
,
538 // ---------------------------------------------------------------------------
540 // ---------------------------------------------------------------------------
542 void wxWindow::SetFocus()
544 Widget wMain
= (Widget
) GetMainWidget();
545 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
546 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
549 // Get the window with the focus
550 wxWindow
*wxWindowBase::DoFindFocus()
553 // (1) Can there be multiple focussed widgets in an application?
554 // In which case we need to find the top-level window that's
556 // (2) The widget with the focus may not be in the widget table
557 // depending on which widgets I put in the table
558 wxWindow
*winFocus
= NULL
;
559 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
561 node
= node
->GetNext() )
563 wxWindow
*win
= node
->GetData();
565 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
567 if (w
!= (Widget
) NULL
)
569 winFocus
= wxGetWindowFromTable(w
);
578 bool wxWindow::Enable(bool enable
)
580 if ( !wxWindowBase::Enable(enable
) )
583 Widget wMain
= (Widget
)GetMainWidget();
586 XtSetSensitive(wMain
, enable
);
587 XmUpdateDisplay(wMain
);
593 bool wxWindow::Show(bool show
)
595 if ( !wxWindowBase::Show(show
) )
598 if (m_borderWidget
|| m_scrolledWindow
)
600 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
601 // MapOrUnmap(m_drawingArea, show);
605 if ( !MapOrUnmap(GetTopWidget(), show
) )
606 MapOrUnmap(GetMainWidget(), show
);
612 // Raise the window to the top of the Z order
613 void wxWindow::Raise()
615 Widget wTop
= (Widget
) GetTopWidget();
616 Window window
= XtWindow(wTop
);
617 XRaiseWindow(XtDisplay(wTop
), window
);
620 // Lower the window to the bottom of the Z order
621 void wxWindow::Lower()
623 Widget wTop
= (Widget
) GetTopWidget();
624 Window window
= XtWindow(wTop
);
625 XLowerWindow(XtDisplay(wTop
), window
);
628 void wxWindow::SetLabel(const wxString
& label
)
630 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
,
631 (const char*)label
.mb_str(), NULL
);
634 wxString
wxWindow::GetLabel() const
637 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &label
, NULL
);
639 return wxString(label
);
642 void wxWindow::DoCaptureMouse()
644 g_captureWindow
= this;
648 Widget wMain
= (Widget
)GetMainWidget();
650 XtAddGrab(wMain
, True
, False
);
652 m_winCaptured
= true;
655 void wxWindow::DoReleaseMouse()
657 g_captureWindow
= NULL
;
658 if ( !m_winCaptured
)
661 Widget wMain
= (Widget
)GetMainWidget();
665 m_winCaptured
= false;
668 bool wxWindow::SetFont(const wxFont
& font
)
670 if ( !wxWindowBase::SetFont(font
) )
681 bool wxWindow::SetCursor(const wxCursor
& cursor
)
683 if ( !wxWindowBase::SetCursor(cursor
) )
689 // wxASSERT_MSG( m_cursor.IsOk(),
690 // wxT("cursor must be valid after call to the base version"));
691 const wxCursor
* cursor2
= NULL
;
693 cursor2
= & m_cursor
;
695 cursor2
= wxSTANDARD_CURSOR
;
697 WXDisplay
*dpy
= GetXDisplay();
698 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
700 Widget w
= (Widget
) GetMainWidget();
701 Window win
= XtWindow(w
);
702 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
707 // Coordinates relative to the window
708 void wxWindow::WarpPointer (int x
, int y
)
710 Widget wClient
= (Widget
)GetClientWidget();
712 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
715 // ---------------------------------------------------------------------------
717 // ---------------------------------------------------------------------------
719 int wxWindow::GetScrollPos(int orient
) const
721 if (orient
== wxHORIZONTAL
)
727 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
731 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
739 // This now returns the whole range, not just the number of positions that we
741 int wxWindow::GetScrollRange(int orient
) const
743 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
744 // CE scintilla windows don't always have these scrollbars
745 // and it tends to pile up a whole bunch of asserts
746 //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
750 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
754 int wxWindow::GetScrollThumb(int orient
) const
756 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
757 //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
761 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
765 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
767 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
771 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
774 SetInternalScrollPos((wxOrientation
)orient
, pos
);
777 // New function that will replace some of the above.
778 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
779 int range
, bool WXUNUSED(refresh
))
782 GetSize(& oldW
, & oldH
);
786 if (thumbVisible
== 0)
789 if (thumbVisible
> range
)
790 thumbVisible
= range
;
792 // Save the old state to see if it changed
793 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
795 if (orient
== wxHORIZONTAL
)
797 if (thumbVisible
== range
)
800 DestroyScrollbar(wxHORIZONTAL
);
805 CreateScrollbar(wxHORIZONTAL
);
808 if (orient
== wxVERTICAL
)
810 if (thumbVisible
== range
)
813 DestroyScrollbar(wxVERTICAL
);
818 CreateScrollbar(wxVERTICAL
);
821 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
823 if (oldScrollBar
!= newScrollBar
)
825 // This is important! Without it, scrollbars misbehave badly.
826 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
827 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
828 XtRealizeWidget((Widget
) m_scrolledWindow
);
829 XtManageChild((Widget
) m_scrolledWindow
);
834 XtVaSetValues((Widget
) newScrollBar
,
838 XmNsliderSize
, thumbVisible
,
842 SetInternalScrollPos((wxOrientation
)orient
, pos
);
845 GetSize(& newW
, & newH
);
847 // Adjusting scrollbars can resize the canvas accidentally
848 if (newW
!= oldW
|| newH
!= oldH
)
849 SetSize(wxDefaultCoord
, wxDefaultCoord
, oldW
, oldH
);
852 // Does a physical scroll
853 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
858 // Use specified rectangle
859 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
863 // Use whole client area
865 GetClientSize(& w
, & h
);
868 int x1
= (dx
>= 0) ? x
: x
- dx
;
869 int y1
= (dy
>= 0) ? y
: y
- dy
;
870 int w1
= w
- abs(dx
);
871 int h1
= h
- abs(dy
);
872 int x2
= (dx
>= 0) ? x
+ dx
: x
;
873 int y2
= (dy
>= 0) ? y
+ dy
: y
;
876 wxClientDCImpl
* const
877 dcimpl
= static_cast<wxClientDCImpl
*>(dc
.GetImpl());
878 GC
const gc
= (GC
) dcimpl
->GetGC();
880 dc
.SetLogicalFunction (wxCOPY
);
882 Widget widget
= (Widget
) GetMainWidget();
883 Window window
= XtWindow(widget
);
884 Display
* display
= XtDisplay(widget
);
886 XCopyArea(display
, window
, window
, gc
, x1
, y1
, w1
, h1
, x2
, y2
);
888 dcimpl
->SetAutoSetting(true);
889 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
890 dc
.SetBrush(brush
); // FIXME: needed?
892 wxWindowList::compatibility_iterator cnode
= m_children
.GetFirst();
895 wxWindow
*child
= cnode
->GetData();
898 child
->GetSize( &sx
, &sy
);
899 wxPoint
pos( child
->GetPosition() );
900 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
901 cnode
= cnode
->GetNext();
904 // We'll add rectangles to the list of update rectangles according to which
905 // bits we've exposed.
910 wxRect
*rect
= new wxRect
;
916 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
920 rect
->width
= rect
->width
;
921 rect
->height
= rect
->height
;
923 updateRects
.Append((wxObject
*) rect
);
927 wxRect
*rect
= new wxRect
;
929 rect
->x
= x
+ w
+ dx
;
934 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
938 rect
->width
= rect
->width
;
939 rect
->height
= rect
->height
;
941 updateRects
.Append((wxObject
*) rect
);
945 wxRect
*rect
= new wxRect
;
952 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
956 rect
->width
= rect
->width
;
957 rect
->height
= rect
->height
;
959 updateRects
.Append((wxObject
*) rect
);
963 wxRect
*rect
= new wxRect
;
966 rect
->y
= y
+ h
+ dy
;
970 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
974 rect
->width
= rect
->width
;
975 rect
->height
= rect
->height
;
977 updateRects
.Append((wxObject
*) rect
);
979 dc
.SetBrush(wxNullBrush
);
981 // Now send expose events
983 wxList::compatibility_iterator node
= updateRects
.GetFirst();
986 wxRect
* rect
= (wxRect
*) node
->GetData();
990 event
.display
= display
;
991 event
.send_event
= True
;
992 event
.window
= window
;
996 event
.width
= rect
->width
;
997 event
.height
= rect
->height
;
1001 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1003 node
= node
->GetNext();
1007 // Delete the update rects
1008 node
= updateRects
.GetFirst();
1011 wxRect
* rect
= (wxRect
*) node
->GetData();
1013 node
= node
->GetNext();
1016 XmUpdateDisplay((Widget
) GetMainWidget());
1019 // ---------------------------------------------------------------------------
1021 // ---------------------------------------------------------------------------
1023 #if wxUSE_DRAG_AND_DROP
1025 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1032 // Old style file-manager drag&drop
1033 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1038 // ----------------------------------------------------------------------------
1040 // ----------------------------------------------------------------------------
1044 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1049 #endif // wxUSE_TOOLTIPS
1051 // ----------------------------------------------------------------------------
1053 // ----------------------------------------------------------------------------
1057 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1059 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1061 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
1062 x
= mouse
.x
; y
= mouse
.y
;
1065 Widget widget
= (Widget
) GetMainWidget();
1067 /* The menuId field seems to be usused, so we'll use it to
1068 indicate whether a menu is popped up or not:
1069 0: Not currently created as a popup
1070 -1: Created as a popup, but not active
1074 if (menu
->GetParent() && (menu
->GetId() != -1))
1077 if (menu
->GetMainWidget())
1079 menu
->DestroyMenu(true);
1082 menu
->SetId(1); /* Mark as popped-up */
1083 menu
->CreateMenu(NULL
, widget
, menu
, 0);
1087 // menu->SetParent(parent);
1088 // parent->children->Append(menu); // Store menu for later deletion
1090 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1098 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1100 wxCanvas *canvas = (wxCanvas *) this;
1101 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1102 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1106 Display
*display
= XtDisplay (widget
);
1107 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1108 Window thisWindow
= XtWindow (widget
);
1110 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1111 &rootX
, &rootY
, &childWindow
);
1113 XButtonPressedEvent event
;
1114 event
.type
= ButtonPress
;
1120 event
.x_root
= rootX
;
1121 event
.y_root
= rootY
;
1123 XmMenuPosition (menuWidget
, &event
);
1124 XtManageChild (menuWidget
);
1126 // The ID of a pop-up menu is 1 when active, and is set to 0 by the
1127 // idle-time destroy routine.
1128 // Waiting until this ID changes causes this function to block until
1129 // the menu has been dismissed and the widgets cleaned up.
1130 // In other words, once this routine returns, it is safe to delete
1132 // Ian Brown <ian.brown@printsoft.de>
1134 wxEventLoop evtLoop
;
1136 while (menu
->GetId() == 1)
1138 wxDoEventLoopIteration( evtLoop
);
1146 // ---------------------------------------------------------------------------
1147 // moving and resizing
1148 // ---------------------------------------------------------------------------
1150 bool wxWindow::PreResize()
1156 void wxWindow::DoGetSize(int *x
, int *y
) const
1158 Widget widget
= (Widget
)( !m_drawingArea
? GetTopWidget() :
1159 ( m_borderWidget
? m_borderWidget
:
1160 m_scrolledWindow
? m_scrolledWindow
:
1165 XtVaGetValues( widget
,
1169 if(x
) *x
= widget
? xx
: -1;
1170 if(y
) *y
= widget
? yy
: -1;
1173 void wxWindow::DoGetPosition(int *x
, int *y
) const
1175 Widget widget
= (Widget
)
1177 ( m_borderWidget
? m_borderWidget
: m_scrolledWindow
) :
1181 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1183 // We may be faking the client origin. So a window that's really at (0, 30)
1184 // may appear (to wxWin apps) to be at (0, 0).
1187 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1188 xx
= (Position
)(xx
- pt
.x
);
1189 yy
= (Position
)(yy
- pt
.y
);
1196 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1198 Widget widget
= (Widget
) GetClientWidget();
1199 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1200 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1201 Window thisWindow
= XtWindow(widget
);
1204 int xx
= x
? *x
: 0;
1205 int yy
= y
? *y
: 0;
1206 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
1207 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
1211 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1213 Widget widget
= (Widget
) GetClientWidget();
1214 Display
*display
= XtDisplay(widget
);
1215 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1216 Window thisWindow
= XtWindow(widget
);
1219 int xx
= x
? *x
: 0;
1220 int yy
= y
? *y
: 0;
1221 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
1222 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
1227 // Get size *available for subwindows* i.e. excluding menu bar etc.
1228 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1230 Widget widget
= (Widget
) GetClientWidget();
1232 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1233 if(x
) *x
= xx
; if(y
) *y
= yy
;
1236 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1238 DoSetSizeIntr(x
, y
, width
, height
, sizeFlags
, false);
1241 void wxWindow::DoSetSizeIntr(int x
, int y
, int width
, int height
,
1242 int sizeFlags
, bool fromCtor
)
1244 // A bit of optimization to help sort out the flickers.
1245 int oldX
= -1, oldY
= -1, oldW
= -1, oldH
= -1;
1249 GetSize(& oldW
, & oldH
);
1250 GetPosition(& oldX
, & oldY
);
1258 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1266 wxSize
size(wxDefaultSize
);
1269 if ( ( sizeFlags
& wxSIZE_AUTO_WIDTH
) && !fromCtor
)
1271 size
= DoGetBestSize();
1282 if( ( sizeFlags
& wxSIZE_AUTO_HEIGHT
) && !fromCtor
)
1284 if( size
.x
== -1 ) size
= DoGetBestSize();
1293 if ( x
!= oldX
|| y
!= oldY
|| width
!= oldW
|| height
!= oldH
1294 || !wxNoOptimize::CanOptimize() )
1307 flags
|= wxMOVE_WIDTH
;
1310 flags
|= wxMOVE_HEIGHT
;
1312 int xx
= x
; int yy
= y
;
1313 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1315 DoMoveWindow( xx
, yy
, width
, height
);
1317 DoMoveWindowIntr( xx
, yy
, width
, height
, flags
);
1322 Widget widget
= (Widget
) GetTopWidget();
1326 bool managed
= XtIsManaged( widget
);
1328 XtUnmanageChild(widget
);
1332 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1334 DoMoveWindow(xx
, yy
, width
, height
);
1337 XtManageChild(widget
);
1341 void wxWindow::DoSetClientSize(int width
, int height
)
1345 Widget drawingArea
= (Widget
) m_drawingArea
;
1347 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1350 XtVaSetValues(drawingArea
, XmNwidth
, width
, NULL
);
1352 XtVaSetValues(drawingArea
, XmNheight
, height
, NULL
);
1354 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1358 Widget widget
= (Widget
) GetTopWidget();
1361 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1363 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1366 void wxWindow::DoMoveWindowIntr(int xx
, int yy
, int w
, int h
,
1371 Widget drawingArea
= (Widget
) m_drawingArea
;
1372 Widget borderOrScrolled
= m_borderWidget
?
1373 (Widget
) m_borderWidget
:
1374 (Widget
) m_scrolledWindow
;
1376 bool managed
= XtIsManaged(borderOrScrolled
);
1378 XtUnmanageChild (borderOrScrolled
);
1379 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1381 if (flags
& wxMOVE_X
)
1382 XtVaSetValues (borderOrScrolled
,
1385 if (flags
& wxMOVE_Y
)
1386 XtVaSetValues (borderOrScrolled
,
1390 if (flags
& wxMOVE_WIDTH
)
1394 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
1395 short thick
, margin
;
1396 XtVaGetValues ((Widget
) m_borderWidget
,
1397 XmNshadowThickness
, &thick
,
1398 XmNmarginWidth
, &margin
,
1400 w
-= 2 * (thick
+ margin
);
1404 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
1407 if (flags
& wxMOVE_HEIGHT
)
1411 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
1412 short thick
, margin
;
1413 XtVaGetValues ((Widget
) m_borderWidget
,
1414 XmNshadowThickness
, &thick
,
1415 XmNmarginHeight
, &margin
,
1417 h
-= 2 * (thick
+ margin
);
1421 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
1425 XtManageChild (borderOrScrolled
);
1426 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1433 XtVaSetValues((Widget
)GetTopWidget(),
1442 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1444 DoMoveWindowIntr (x
, y
, width
, height
,
1445 wxMOVE_X
|wxMOVE_Y
|wxMOVE_WIDTH
|wxMOVE_HEIGHT
);
1448 // ---------------------------------------------------------------------------
1450 // ---------------------------------------------------------------------------
1452 int wxWindow::GetCharHeight() const
1457 wxGetTextExtent (GetXDisplay(), m_font
, 1.0,
1458 "x", NULL
, &height
, NULL
, NULL
);
1460 wxGetTextExtent (this, "x", NULL
, &height
, NULL
, NULL
);
1465 int wxWindow::GetCharWidth() const
1470 wxGetTextExtent (GetXDisplay(), m_font
, 1.0,
1471 "x", &width
, NULL
, NULL
, NULL
);
1473 wxGetTextExtent (this, "x", &width
, NULL
, NULL
, NULL
);
1478 void wxWindow::DoGetTextExtent(const wxString
& string
,
1481 int *externalLeading
,
1482 const wxFont
*theFont
) const
1484 const wxFont
*fontToUse
= theFont
? theFont
: &m_font
;
1486 if (externalLeading
)
1487 *externalLeading
= 0;
1488 if (fontToUse
->IsOk())
1489 wxGetTextExtent (GetXDisplay(), *fontToUse
, 1.0,
1490 string
, x
, y
, NULL
, descent
);
1492 wxGetTextExtent (this, string
, x
, y
, NULL
, descent
);
1495 // ----------------------------------------------------------------------------
1497 // ----------------------------------------------------------------------------
1499 void wxWindow::AddUpdateRect(int x
, int y
, int w
, int h
)
1501 m_updateRegion
.Union( x
, y
, w
, h
);
1504 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1506 Widget widget
= (Widget
) GetMainWidget();
1509 m_needsRefresh
= true;
1510 Display
*display
= XtDisplay(widget
);
1511 Window thisWindow
= XtWindow(widget
);
1513 XExposeEvent dummyEvent
;
1515 GetSize(&width
, &height
);
1517 dummyEvent
.type
= Expose
;
1518 dummyEvent
.display
= display
;
1519 dummyEvent
.send_event
= True
;
1520 dummyEvent
.window
= thisWindow
;
1523 dummyEvent
.x
= rect
->x
;
1524 dummyEvent
.y
= rect
->y
;
1525 dummyEvent
.width
= rect
->width
;
1526 dummyEvent
.height
= rect
->height
;
1532 dummyEvent
.width
= width
;
1533 dummyEvent
.height
= height
;
1535 dummyEvent
.count
= 0;
1539 wxClientDC
dc(this);
1540 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1541 dc
.SetBackground(backgroundBrush
);
1543 wxClientDCImpl
* const
1544 dcimpl
= static_cast<wxClientDCImpl
*>(dc
.GetImpl());
1546 dcimpl
->Clear(*rect
);
1551 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1554 void wxWindow::DoPaint()
1556 //TODO : make a temporary gc so we can do the XCopyArea below
1557 if (m_backingPixmap
&& !m_needsRefresh
)
1561 wxPaintDCImpl
* const
1562 dcimpl
= static_cast<wxPaintDCImpl
*>(dc
.GetImpl());
1564 GC tempGC
= (GC
) dcimpl
->GetBackingGC();
1566 Widget widget
= (Widget
) GetMainWidget();
1571 // We have to test whether it's a wxScrolledWindow (hack!) because
1572 // otherwise we don't know how many pixels have been scrolled. We might
1573 // solve this in the future by defining virtual wxWindow functions to get
1574 // the scroll position in pixels. Or, each kind of scrolled window has to
1575 // implement backing stores itself, using generic wxWidgets code.
1576 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1577 if ( scrolledWindow
)
1580 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1586 // TODO: This could be optimized further by only copying the areas in the
1587 // current update region.
1589 // Only blit the part visible in the client area. The backing pixmap
1590 // always starts at 0, 0 but we may be looking at only a portion of it.
1591 wxSize clientArea
= GetClientSize();
1592 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1593 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1595 // Copy whichever is samller, the amount of pixmap we have to copy,
1596 // or the size of the client area.
1597 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1598 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1600 // Make sure we're not negative
1601 toBlitX
= wxMax(0, toBlitX
);
1602 toBlitY
= wxMax(0, toBlitY
);
1607 (Pixmap
) m_backingPixmap
,
1610 scrollPosX
, scrollPosY
, // Start at the scroll position
1611 toBlitX
, toBlitY
, // How much of the pixmap to copy
1617 wxWindowDC
dc(this);
1618 // Set an erase event first
1619 wxEraseEvent
eraseEvent(GetId(), &dc
);
1620 eraseEvent
.SetEventObject(this);
1621 HandleWindowEvent(eraseEvent
);
1623 wxPaintEvent
event(GetId());
1624 event
.SetEventObject(this);
1625 HandleWindowEvent(event
);
1627 m_needsRefresh
= false;
1631 // ----------------------------------------------------------------------------
1633 // ----------------------------------------------------------------------------
1635 // Responds to colour changes: passes event on to children.
1636 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1638 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1641 // Only propagate to non-top-level windows
1642 wxWindow
*win
= node
->GetData();
1643 if ( win
->GetParent() )
1645 wxSysColourChangedEvent event2
;
1646 event
.SetEventObject(win
);
1647 win
->HandleWindowEvent(event2
);
1650 node
= node
->GetNext();
1654 // ----------------------------------------------------------------------------
1656 // ----------------------------------------------------------------------------
1658 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1661 if (!m_acceleratorTable
.IsOk())
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
1673 // entry command id.
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
);
1688 // Try for a menu command
1689 if (frame
->GetMenuBar())
1691 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1694 wxCommandEvent
commandEvent(wxEVT_MENU
, entry
->GetCommand());
1695 commandEvent
.SetEventObject(frame
);
1697 // If ProcessEvent returns true (it was handled), then
1698 // the calling code will skip the event handling.
1699 return frame
->HandleWindowEvent(commandEvent
);
1705 // Find a child matching the command id
1706 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1712 // Now we process those kinds of windows that we can.
1713 // For now, only buttons.
1714 if ( wxDynamicCast(child
, wxButton
) )
1716 wxCommandEvent
commandEvent (wxEVT_BUTTON
, child
->GetId());
1717 commandEvent
.SetEventObject(child
);
1718 return child
->HandleWindowEvent(commandEvent
);
1726 // We didn't match the key event against an accelerator.
1730 // ============================================================================
1731 // Motif-specific stuff from here on
1732 // ============================================================================
1734 // ----------------------------------------------------------------------------
1735 // function which maintain the global hash table mapping Widgets to wxWidgets
1736 // ----------------------------------------------------------------------------
1738 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1740 const long key
= (long)w
;
1741 if ( wxWidgetHashTable
->Get(key
))
1743 wxLogDebug("Widget table clash: new widget is %ld, %s",
1744 key
, win
->GetClassInfo()->GetClassName());
1748 wxWidgetHashTable
->Put(key
, win
);
1750 wxLogTrace("widget", "Widget 0x%p <-> window %p (%s)",
1751 w
, win
, win
->GetClassInfo()->GetClassName());
1756 wxWindow
*wxGetWindowFromTable(Widget w
)
1758 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1761 void wxDeleteWindowFromTable(Widget w
)
1763 wxLogTrace("widget", "Widget 0x%p", (WXWidget
)w
);
1765 wxWidgetHashTable
->Delete((long)w
);
1768 // ----------------------------------------------------------------------------
1769 // add/remove window from the table
1770 // ----------------------------------------------------------------------------
1772 // Add to hash table, add event handler
1773 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1774 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1776 wxAddWindowToTable((Widget
) mainWidget
, this);
1777 XtAddEventHandler( (Widget
) mainWidget
,
1778 ButtonPressMask
| ButtonReleaseMask
1779 | PointerMotionMask
,
1781 wxPanelItemEventHandler
,
1787 XtOverrideTranslations ((Widget
) mainWidget
,
1788 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1789 XtFree ((char *) ptr
);
1792 // Some widgets have a parent form widget, e.g. wxRadioBox
1795 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1799 XtOverrideTranslations ((Widget
) formWidget
,
1800 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1801 XtFree ((char *) ptr
);
1808 DoSetSize (x
, y
, width
, height
, wxSIZE_USE_EXISTING
);
1813 // Remove event handler, remove from hash table
1814 bool wxWindow::DetachWidget(WXWidget widget
)
1816 XtRemoveEventHandler( (Widget
) widget
,
1817 ButtonPressMask
| ButtonReleaseMask
1818 | PointerMotionMask
,
1820 wxPanelItemEventHandler
,
1823 wxDeleteWindowFromTable((Widget
) widget
);
1827 // ----------------------------------------------------------------------------
1828 // Motif-specific accessors
1829 // ----------------------------------------------------------------------------
1831 WXWindow
wxWindow::GetClientXWindow() const
1833 Widget wMain
= (Widget
)GetClientWidget();
1835 return (WXWindow
) XtWindow(wMain
);
1837 return (WXWindow
) 0;
1840 // Get the underlying X window
1841 WXWindow
wxWindow::GetXWindow() const
1843 Widget wMain
= (Widget
)GetMainWidget();
1845 return (WXWindow
) XtWindow(wMain
);
1847 return (WXWindow
) 0;
1850 // Get the underlying X display
1851 WXDisplay
*wxWindow::GetXDisplay() const
1853 Widget wMain
= (Widget
)GetMainWidget();
1855 return (WXDisplay
*) XtDisplay(wMain
);
1860 WXWidget
wxWindow::GetMainWidget() const
1863 return m_drawingArea
;
1865 return m_mainWidget
;
1868 WXWidget
wxWindow::GetClientWidget() const
1870 if (m_drawingArea
!= (WXWidget
) 0)
1871 return m_drawingArea
;
1873 return GetMainWidget();
1876 WXWidget
wxWindow::GetTopWidget() const
1878 return GetMainWidget();
1881 WXWidget
wxWindow::GetLabelWidget() const
1883 return GetMainWidget();
1886 // ----------------------------------------------------------------------------
1888 // ----------------------------------------------------------------------------
1890 // All widgets should have this as their resize proc.
1891 // OnSize sent to wxWindow via client data.
1892 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
),
1893 String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1895 wxWindow
*win
= wxGetWindowFromTable(w
);
1899 if (win
->PreResize())
1901 wxSize
newSize(win
->GetSize());
1902 wxSizeEvent
sizeEvent(newSize
, win
->GetId());
1903 sizeEvent
.SetEventObject(win
);
1904 win
->HandleWindowEvent(sizeEvent
);
1908 static void wxCanvasRepaintProc(Widget drawingArea
,
1909 XtPointer clientData
,
1910 XmDrawingAreaCallbackStruct
* cbs
)
1912 if (!wxGetWindowFromTable(drawingArea
))
1915 XEvent
* event
= cbs
->event
;
1916 wxWindow
* win
= (wxWindow
*) clientData
;
1918 switch (event
->type
)
1922 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1923 event
->xexpose
.width
, event
->xexpose
.height
);
1925 if (event
-> xexpose
.count
== 0)
1934 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1935 static void wxCanvasEnterLeave(Widget drawingArea
,
1936 XtPointer
WXUNUSED(clientData
),
1937 XCrossingEvent
* event
)
1939 XmDrawingAreaCallbackStruct cbs
;
1942 ((XCrossingEvent
&) ev
) = *event
;
1944 cbs
.reason
= XmCR_INPUT
;
1947 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1950 // Fix to make it work under Motif 1.0 (!)
1951 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
),
1952 XButtonEvent
*WXUNUSED(event
))
1954 #if XmVersion <= 1000
1955 XmDrawingAreaCallbackStruct cbs
;
1958 ev
= *((XEvent
*) event
);
1959 cbs
.reason
= XmCR_INPUT
;
1962 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1963 #endif // XmVersion <= 1000
1966 static void wxCanvasInputEvent(Widget drawingArea
,
1967 XtPointer
WXUNUSED(data
),
1968 XmDrawingAreaCallbackStruct
* cbs
)
1970 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1971 XEvent
* xevent
= cbs
->event
;
1976 if (cbs
->reason
!= XmCR_INPUT
)
1979 switch (xevent
->xany
.type
)
1987 wxMouseEvent
wxevent(0);
1988 if (wxTranslateMouseEvent(wxevent
, canvas
, drawingArea
, xevent
))
1990 canvas
->HandleWindowEvent(wxevent
);
1996 wxKeyEvent
event (wxEVT_CHAR
);
1997 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, xevent
))
1999 // Implement wxFrame::OnCharHook by checking ancestor.
2000 wxWindow
*parent
= canvas
;
2001 while (parent
&& !parent
->IsTopLevel())
2002 parent
= parent
->GetParent();
2006 event
.SetEventType(wxEVT_CHAR_HOOK
);
2007 if (parent
->HandleWindowEvent(event
))
2011 // For simplicity, OnKeyDown is the same as OnChar
2012 // TODO: filter modifier key presses from OnChar
2013 event
.SetEventType(wxEVT_KEY_DOWN
);
2015 // Only process OnChar if OnKeyDown didn't swallow it
2016 if (!canvas
->HandleWindowEvent (event
))
2018 event
.SetEventType(wxEVT_CHAR
);
2019 canvas
->HandleWindowEvent (event
);
2026 wxKeyEvent
event (wxEVT_KEY_UP
);
2027 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, xevent
))
2029 canvas
->HandleWindowEvent (event
);
2035 if (xevent
->xfocus
.detail
!= NotifyPointer
)
2037 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2038 event
.SetEventObject(canvas
);
2039 canvas
->HandleWindowEvent(event
);
2045 if (xevent
->xfocus
.detail
!= NotifyPointer
)
2047 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2048 event
.SetEventObject(canvas
);
2049 canvas
->HandleWindowEvent(event
);
2058 static void wxPanelItemEventHandler(Widget wid
,
2059 XtPointer
WXUNUSED(client_data
),
2061 Boolean
*continueToDispatch
)
2063 // Widget can be a label or the actual widget.
2065 wxWindow
*window
= wxGetWindowFromTable(wid
);
2068 wxMouseEvent
wxevent(0);
2069 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2071 window
->HandleWindowEvent(wxevent
);
2075 // TODO: probably the key to allowing default behaviour to happen. Say we
2076 // set a m_doDefault flag to false at the start of this function. Then in
2077 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2078 // true, indicating that default processing can happen. Thus, behaviour can
2079 // appear to be overridden just by adding an event handler and not calling
2080 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2081 // way of handling drawing area events, to simplify things.
2082 *continueToDispatch
= True
;
2085 static void wxScrollBarCallback(Widget scrollbar
,
2086 XtPointer clientData
,
2087 XmScrollBarCallbackStruct
*cbs
)
2089 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2090 wxCHECK_RET( win
, wxT("invalid widget in scrollbar callback") );
2092 wxOrientation orientation
= (wxOrientation
)wxPtrToUInt(clientData
);
2094 wxEventType eventType
= wxEVT_NULL
;
2095 switch (cbs
->reason
)
2097 case XmCR_INCREMENT
:
2099 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2102 case XmCR_DECREMENT
:
2104 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2109 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2112 case XmCR_VALUE_CHANGED
:
2114 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2117 case XmCR_PAGE_INCREMENT
:
2119 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2122 case XmCR_PAGE_DECREMENT
:
2124 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2129 eventType
= wxEVT_SCROLLWIN_TOP
;
2132 case XmCR_TO_BOTTOM
:
2134 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2139 // Should never get here
2140 wxFAIL_MSG("Unknown scroll event.");
2145 wxScrollWinEvent
event(eventType
,
2148 event
.SetEventObject( win
);
2149 win
->HandleWindowEvent(event
);
2152 // For repainting arbitrary windows
2153 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2155 wxWindow
* win
= wxGetWindowFromTable(w
);
2159 switch ( event
->type
)
2163 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2164 event
->xexpose
.width
, event
->xexpose
.height
);
2166 if ( event
->xexpose
.count
== 0 )
2176 // ----------------------------------------------------------------------------
2177 // TranslateXXXEvent() functions
2178 // ----------------------------------------------------------------------------
2180 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
,
2181 Widget widget
, const XEvent
*xevent
)
2183 switch (xevent
->xany
.type
)
2188 fprintf(stderr
, "Widget 0x%p <-> window %p (%s), %s\n",
2189 (WXWidget
)widget
, win
, win
->GetClassInfo()->GetClassName(),
2190 (xevent
->xany
.type
== EnterNotify
? "ENTER" : "LEAVE"));
2196 int eventx
= xevent
->xbutton
.x
, eventy
= xevent
->xbutton
.y
;
2198 wxEventType eventType
= wxEVT_NULL
;
2200 if (xevent
->xany
.type
== LeaveNotify
)
2202 eventType
= wxEVT_LEAVE_WINDOW
;
2204 if (xevent
->xany
.type
== EnterNotify
)
2206 eventType
= wxEVT_ENTER_WINDOW
;
2208 else if (xevent
->xany
.type
== MotionNotify
)
2210 eventType
= wxEVT_MOTION
;
2212 if (xevent
->xmotion
.is_hint
== NotifyHint
)
2217 Display
*dpy
= XtDisplay (widget
);
2219 XQueryPointer (dpy
, XtWindow (widget
),
2221 &x_root
, &y_root
, &eventx
, &eventy
, &state
);
2224 else if (xevent
->xany
.type
== ButtonPress
)
2226 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2228 if (xevent
->xbutton
.button
== Button1
)
2230 eventType
= wxEVT_LEFT_DOWN
;
2233 else if (xevent
->xbutton
.button
== Button2
)
2235 eventType
= wxEVT_MIDDLE_DOWN
;
2238 else if (xevent
->xbutton
.button
== Button3
)
2240 eventType
= wxEVT_RIGHT_DOWN
;
2244 // check for a double click
2246 long dclickTime
= XtGetMultiClickTime(xevent
->xany
.display
);
2247 long ts
= wxevent
.GetTimestamp();
2249 int buttonLast
= win
->GetLastClickedButton();
2250 long lastTS
= win
->GetLastClickTime();
2251 if ( buttonLast
&& buttonLast
== button
&&
2252 (ts
- lastTS
) < dclickTime
)
2255 win
->SetLastClick(0, ts
);
2256 if ( eventType
== wxEVT_LEFT_DOWN
)
2257 eventType
= wxEVT_LEFT_DCLICK
;
2258 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2259 eventType
= wxEVT_MIDDLE_DCLICK
;
2260 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2261 eventType
= wxEVT_RIGHT_DCLICK
;
2265 // not fast enough or different button
2266 win
->SetLastClick(button
, ts
);
2269 else if (xevent
->xany
.type
== ButtonRelease
)
2271 if (xevent
->xbutton
.button
== Button1
)
2273 eventType
= wxEVT_LEFT_UP
;
2275 else if (xevent
->xbutton
.button
== Button2
)
2277 eventType
= wxEVT_MIDDLE_UP
;
2279 else if (xevent
->xbutton
.button
== Button3
)
2281 eventType
= wxEVT_RIGHT_UP
;
2291 wxevent
.SetEventType(eventType
);
2294 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2297 win
->GetPosition(&x2
, &y2
);
2299 // The button x/y must be translated to wxWidgets
2300 // window space - the widget might be a label or button,
2304 if (widget
!= (Widget
)win
->GetMainWidget())
2310 wxevent
.m_x
= eventx
+ dx
;
2311 wxevent
.m_y
= eventy
+ dy
;
2313 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2314 || (event_left_is_down (xevent
)
2315 && (eventType
!= wxEVT_LEFT_UP
)));
2316 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2317 || (event_middle_is_down (xevent
)
2318 && (eventType
!= wxEVT_MIDDLE_UP
)));
2319 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2320 || (event_right_is_down (xevent
)
2321 && (eventType
!= wxEVT_RIGHT_UP
)));
2323 wxevent
.m_shiftDown
= (xevent
->xbutton
.state
& ShiftMask
) == ShiftMask
;
2324 wxevent
.m_controlDown
= (xevent
->xbutton
.state
& ControlMask
) == ControlMask
;
2325 wxevent
.m_altDown
= (xevent
->xbutton
.state
& Mod3Mask
) == Mod3Mask
;
2326 wxevent
.m_metaDown
= (xevent
->xbutton
.state
& Mod1Mask
) == Mod1Mask
;
2328 wxevent
.SetId(win
->GetId());
2329 wxevent
.SetEventObject(win
);
2337 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
,
2338 Widget
WXUNUSED(widget
), const XEvent
*xevent
)
2340 switch (xevent
->xany
.type
)
2348 (void) XLookupString((XKeyEvent
*)xevent
, buf
, 20, &keySym
, NULL
);
2349 int id
= wxCharCodeXToWX (keySym
);
2350 // id may be WXK_xxx code - these are outside ASCII range, so we
2351 // can't just use toupper() on id
2352 if (id
>= 'a' && id
<= 'z')
2355 if (xevent
->xkey
.state
& ShiftMask
)
2356 wxevent
.m_shiftDown
= true;
2357 if (xevent
->xkey
.state
& ControlMask
)
2358 wxevent
.m_controlDown
= true;
2359 if (xevent
->xkey
.state
& Mod3Mask
)
2360 wxevent
.m_altDown
= true;
2361 if (xevent
->xkey
.state
& Mod1Mask
)
2362 wxevent
.m_metaDown
= true;
2363 wxevent
.SetEventObject(win
);
2364 wxevent
.m_keyCode
= id
;
2365 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2367 wxevent
.m_x
= xevent
->xbutton
.x
;
2368 wxevent
.m_y
= xevent
->xbutton
.y
;
2381 // ----------------------------------------------------------------------------
2383 // ----------------------------------------------------------------------------
2385 #define YAllocColor XAllocColor
2386 XColor g_itemColors
[5];
2387 int wxComputeColours (Display
*display
, const wxColour
* back
, const wxColour
* fore
)
2390 static XmColorProc colorProc
;
2392 result
= wxNO_COLORS
;
2396 g_itemColors
[0].red
= (unsigned short)(((long) back
->Red ()) << 8);
2397 g_itemColors
[0].green
= (unsigned short)(((long) back
->Green ()) << 8);
2398 g_itemColors
[0].blue
= (unsigned short)(((long) back
->Blue ()) << 8);
2399 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2400 if (colorProc
== (XmColorProc
) NULL
)
2402 // Get a ptr to the actual function
2403 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2404 // And set it back to motif.
2405 XmSetColorCalculation (colorProc
);
2407 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2408 &g_itemColors
[wxFORE_INDEX
],
2409 &g_itemColors
[wxSELE_INDEX
],
2410 &g_itemColors
[wxTOPS_INDEX
],
2411 &g_itemColors
[wxBOTS_INDEX
]);
2412 result
= wxBACK_COLORS
;
2416 g_itemColors
[wxFORE_INDEX
].red
= (unsigned short)(((long) fore
->Red ()) << 8);
2417 g_itemColors
[wxFORE_INDEX
].green
= (unsigned short)(((long) fore
->Green ()) << 8);
2418 g_itemColors
[wxFORE_INDEX
].blue
= (unsigned short)(((long) fore
->Blue ()) << 8);
2419 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2420 if (result
== wxNO_COLORS
)
2421 result
= wxFORE_COLORS
;
2424 Display
*dpy
= display
;
2425 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2429 /* 5 Colours to allocate */
2430 for (int i
= 0; i
< 5; i
++)
2431 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2432 result
= wxNO_COLORS
;
2436 /* Only 1 colour to allocate */
2437 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2438 result
= wxNO_COLORS
;
2444 // Changes the foreground and background colours to be derived from the current
2445 // background colour. To change the foreground colour, you must call
2446 // SetForegroundColour explicitly.
2447 void wxWindow::ChangeBackgroundColour()
2449 WXWidget mainWidget
= GetMainWidget();
2451 wxDoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2452 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2453 wxDoChangeForegroundColour(m_scrolledWindow
, m_backgroundColour
);
2456 void wxWindow::ChangeForegroundColour()
2458 WXWidget mainWidget
= GetMainWidget();
2460 wxDoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2461 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2462 wxDoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2465 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2467 if ( !wxWindowBase::SetBackgroundColour(col
) )
2470 ChangeBackgroundColour();
2475 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2477 if ( !wxWindowBase::SetForegroundColour(col
) )
2480 ChangeForegroundColour();
2485 void wxWindow::ChangeFont(bool keepOriginalSize
)
2487 // Note that this causes the widget to be resized back
2488 // to its original size! We therefore have to set the size
2489 // back again. TODO: a better way in Motif?
2490 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2491 if (w
&& m_font
.IsOk())
2493 int width
, height
, width1
, height1
;
2494 GetSize(& width
, & height
);
2496 wxDoChangeFont( w
, m_font
);
2498 GetSize(& width1
, & height1
);
2499 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2501 SetSize(wxDefaultCoord
, wxDefaultCoord
, width
, height
);
2507 void wxWindow::PostCreation()
2510 ChangeForegroundColour();
2511 ChangeBackgroundColour();
2515 void wxWindow::PreCreation()
2517 InheritAttributes();
2520 // ----------------------------------------------------------------------------
2522 // ----------------------------------------------------------------------------
2524 wxWindow
*wxGetActiveWindow()
2527 wxFAIL_MSG("Not implemented");
2532 wxWindow
*wxWindowBase::GetCapture()
2534 return (wxWindow
*)g_captureWindow
;
2538 // Find the wxWindow at the current mouse position, returning the mouse
2540 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2542 pt
= wxGetMousePosition();
2543 return wxFindWindowAtPoint(pt
);
2546 void wxGetMouseState(int& rootX
, int& rootY
, unsigned& maskReturn
)
2548 Display
*display
= wxGlobalDisplay();
2549 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2550 Window rootReturn
, childReturn
;
2553 XQueryPointer (display
,
2557 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
2560 // Get the current mouse position.
2561 wxPoint
wxGetMousePosition()
2566 wxGetMouseState(x
, y
, mask
);
2567 return wxPoint(x
, y
);
2570 wxMouseState
wxGetMouseState()
2576 wxGetMouseState(x
, y
, mask
);
2581 ms
.SetLeftDown(mask
& Button1Mask
);
2582 ms
.SetMiddleDown(mask
& Button2Mask
);
2583 ms
.SetRightDown(mask
& Button3Mask
);
2585 ms
.SetControlDown(mask
& ControlMask
);
2586 ms
.SetShiftDown(mask
& ShiftMask
);
2587 ms
.SetAltDown(mask
& Mod3Mask
);
2588 ms
.SetMetaDown(mask
& Mod1Mask
);
2594 #if wxMOTIF_NEW_FONT_HANDLING
2598 void wxGetTextExtent(const wxWindow
* window
, const wxString
& str
,
2599 int* width
, int* height
, int* ascent
, int* descent
)
2603 XmRendition rendition
= NULL
;
2604 XmRenderTable table
= NULL
;
2605 Widget w
= (Widget
) window
->GetLabelWidget();
2607 XtVaGetValues( w
, XmNrenderTable
, &table
, NULL
);
2609 table
= XmeGetDefaultRenderTable(w
, XmTEXT_RENDER_TABLE
);
2611 rendition
= XmRenderTableGetRendition( table
, "" );
2612 XtSetArg( args
[count
], XmNfont
, 0 ); ++count
;
2613 XtSetArg( args
[count
], XmNfontType
, 0 ); ++count
;
2614 XmRenditionRetrieve( rendition
, args
, count
);
2616 if (args
[1].value
== XmFONT_IS_FONTSET
)
2618 XRectangle ink
, logical
;
2619 WXFontSet fset
= (WXFontSet
) args
[0].value
;
2621 XmbTextExtents( (XFontSet
)fset
, str
.c_str(), str
.length(),
2624 if( width
) *width
= logical
.width
;
2625 if( height
) *height
= logical
.height
;
2626 if( ascent
) *ascent
= -logical
.y
;
2627 if( descent
) *descent
= logical
.height
+ logical
.y
;
2631 int direction
, ascent2
, descent2
;
2632 XCharStruct overall
;
2633 XFontStruct
* fontStruct
;
2635 XmeRenderTableGetDefaultFont( table
, &fontStruct
);
2636 XTextExtents(fontStruct
, (const char*)str
.c_str(), str
.length(),
2637 &direction
, &ascent2
, &descent2
, &overall
);
2639 if ( width
) *width
= overall
.width
;
2640 if ( height
) *height
= ascent2
+ descent2
;
2641 if ( descent
) *descent
= descent2
;
2642 if ( ascent
) *ascent
= ascent2
;
2646 #else // if !wxMOTIF_NEW_FONT_HANDLING
2648 void wxGetTextExtent(const wxWindow
* window
, const wxString
& str
,
2649 int* width
, int* height
, int* ascent
, int* descent
)
2651 XmFontList list
= NULL
;
2654 Widget w
= (Widget
) window
->GetLabelWidget();
2656 XtVaGetValues( w
, XmNfontList
, &list
, NULL
);
2657 XmFontListInitFontContext( &cxt
, list
);
2659 XmFontListEntry entry
= XmFontListNextEntry( cxt
);
2660 XmFontListFreeFontContext( cxt
);
2661 XtPointer thing
= XmFontListEntryGetFont( entry
, &type
);
2663 if (type
== XmFONT_IS_FONTSET
)
2665 XRectangle ink
, logical
;
2667 XmbTextExtents( (XFontSet
)thing
, str
.c_str(), str
.length(),
2670 if( width
) *width
= logical
.width
;
2671 if( height
) *height
= logical
.height
;
2672 if( ascent
) *ascent
= -logical
.y
;
2673 if( descent
) *descent
= logical
.height
+ logical
.y
;
2677 int direction
, ascent2
, descent2
;
2678 XCharStruct overall
;
2680 XTextExtents( (XFontStruct
*)thing
, (char*)(const char*)str
.c_str(), str
.length(),
2681 &direction
, &ascent2
, &descent2
, &overall
);
2683 if ( width
) *width
= overall
.width
;
2684 if ( height
) *height
= ascent2
+ descent2
;
2685 if ( descent
) *descent
= descent2
;
2686 if ( ascent
) *ascent
= ascent2
;
2690 #endif // !wxMOTIF_NEW_FONT_HANDLING
2692 // ----------------------------------------------------------------------------
2693 // wxNoOptimize: switch off size optimization
2694 // ----------------------------------------------------------------------------
2696 int wxNoOptimize::ms_count
= 0;