1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/window.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
24 #define XtDisplay XTDISPLAY
25 #define XtWindow XTWINDOW
26 #define XtScreen XTSCREEN
36 #include "wx/dcclient.h"
37 #include "wx/button.h"
39 #include "wx/settings.h"
40 #include "wx/scrolwin.h"
41 #include "wx/layout.h"
42 #include "wx/menuitem.h"
43 #include "wx/module.h"
46 #include "wx/evtloop.h"
48 #if wxUSE_DRAG_AND_DROP
52 // DoSetSizeIntr and DoMoveWindowIntr
54 // under Motif composite controls (such as wxCalendarCtrl or generic wxSpinCtrl
55 // did not work and/or segfaulted because
56 // 1) wxWindow::Create calls SetSize,
57 // which results in a call to DoSetSize much earlier than in the other ports
58 // 2) if wxWindow::Create is called (wxControl::Create calls it)
59 // then DoSetSize is never called, causing layout problems in composite
63 // 1) don't call SetSize, DoSetSize, DoMoveWindow, DoGetPosition,
64 // DoSetPosition directly or indirectly from wxWindow::Create
65 // 2) call DoMoveWindow from DoSetSize, allowing controls to override it
68 #pragma message disable nosimpint
72 #include <Xm/DrawingA.h>
73 #include <Xm/ScrolledW.h>
74 #include <Xm/ScrollBar.h>
77 #include <Xm/RowColumn.h> // for XmMenuPosition
79 #pragma message enable nosimpint
82 #include "wx/motif/private.h"
86 // ----------------------------------------------------------------------------
87 // global variables for this module
88 // ----------------------------------------------------------------------------
90 extern wxHashTable
*wxWidgetHashTable
;
91 static wxWindow
* g_captureWindow
= NULL
;
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
99 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
100 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
101 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
102 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
103 XmScrollBarCallbackStruct
*cbs
);
104 static void wxPanelItemEventHandler(Widget wid
,
105 XtPointer client_data
,
107 Boolean
*continueToDispatch
);
112 // Helper function for 16-bit fonts
113 static int str16len(const char *s
)
117 while (s
[0] && s
[1]) {
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
132 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
133 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
141 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
142 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
145 // ============================================================================
147 // ============================================================================
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
153 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
155 Widget w
= (Widget
)widget
;
163 bool wxWindow::MapOrUnmap(WXWidget widget
, bool domap
)
165 Widget w
= (Widget
)widget
;
169 // Rationale: a lot of common operations (including but not
170 // limited to moving, resizing and appending items to a listbox)
171 // unmamange the widget, do their work, then manage it again.
172 // This means that, for example adding an item to a listbox will show it,
173 // or that most controls are shown every time they are moved or resized!
174 XtSetMappedWhenManaged( w
, domap
);
176 // if the widget is not unmanaged, it still intercepts
177 // mouse events, even if it is not mapped (and hence invisible)
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
196 void wxWindow::Init()
199 m_needsRefresh
= true;
200 m_mainWidget
= (WXWidget
) 0;
202 m_winCaptured
= false;
210 m_drawingArea
= (WXWidget
) 0;
215 m_backingPixmap
= (WXPixmap
) 0;
226 // real construction (Init() must have been called before!)
227 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
231 const wxString
& name
)
233 // Get default border
234 wxBorder border
= GetBorder(style
);
235 style
&= ~wxBORDER_MASK
;
238 wxCHECK_MSG( parent
, false, "can't create wxWindow without parent" );
240 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
242 parent
->AddChild(this);
245 //// TODO: we should probably optimize by only creating a
246 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
247 //// But for now, let's simplify things by always creating the
248 //// drawing area, since otherwise the translations are different.
250 // New translations for getting mouse motion feedback
251 static const String translations
= wxMOTIF_STR(
252 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
253 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
254 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
255 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
256 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
257 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
258 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
259 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
260 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
261 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
262 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
263 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
264 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
265 <Key>: DrawingAreaInput()");
267 XtActionsRec actions
[1];
268 actions
[0].string
= wxMOTIF_STR("wxCanvasMotionEvent");
269 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
270 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
272 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
273 m_borderWidget
= wxCreateBorderWidget( (WXWidget
)parentWidget
, style
);
275 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
278 xmScrolledWindowWidgetClass
,
279 m_borderWidget
? (Widget
) m_borderWidget
281 XmNresizePolicy
, XmRESIZE_NONE
,
283 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
284 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
288 XtTranslations ptr
= XtParseTranslationTable(translations
);
289 m_drawingArea
= (WXWidget
)XtVaCreateWidget
292 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
293 XmNunitType
, XmPIXELS
,
294 // XmNresizePolicy, XmRESIZE_ANY,
295 XmNresizePolicy
, XmRESIZE_NONE
,
298 XmNtranslations
, ptr
,
301 XtFree((char *) ptr
);
304 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
306 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
307 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
308 XtFree ((char *) ptr
);
312 wxAddWindowToTable((Widget
) m_drawingArea
, this);
313 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
315 // This order is very important in Motif 1.2.1
316 XtRealizeWidget ((Widget
) m_scrolledWindow
);
317 XtRealizeWidget ((Widget
) m_drawingArea
);
318 XtManageChild ((Widget
) m_drawingArea
);
320 ptr
= XtParseTranslationTable("<Configure>: resize()");
321 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
322 XtFree ((char *) ptr
);
324 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
325 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
328 (Widget
)m_drawingArea
,
329 PointerMotionHintMask
| EnterWindowMask
|
330 LeaveWindowMask
| FocusChangeMask
,
332 (XtEventHandler
) wxCanvasEnterLeave
,
336 XmScrolledWindowSetAreas(
337 (Widget
)m_scrolledWindow
,
338 (Widget
) 0, (Widget
) 0,
339 (Widget
) m_drawingArea
);
343 // Without this, the cursor may not be restored properly (e.g. in splitter
345 SetCursor(*wxSTANDARD_CURSOR
);
346 DoSetSizeIntr(pos
.x
, pos
.y
, size
.x
,size
.y
, wxSIZE_AUTO
, true);
351 wxWindow::~wxWindow()
353 if (g_captureWindow
== this)
354 g_captureWindow
= NULL
;
356 m_isBeingDeleted
= true;
358 // Motif-specific actions first
359 WXWidget wMain
= GetMainWidget();
362 // Removes event handlers
366 // If m_drawingArea, we're a fully-fledged window with drawing area,
367 // scrollbars etc. (what wxCanvas used to be)
370 // Destroy children before destroying self
374 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
376 Widget w
= (Widget
) m_drawingArea
;
377 wxDeleteWindowFromTable(w
);
382 m_drawingArea
= (WXWidget
) 0;
385 // Only if we're _really_ a canvas (not a dialog box/panel)
386 if (m_scrolledWindow
)
388 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
393 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
394 XtUnmanageChild((Widget
) m_hScrollBar
);
398 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
399 XtUnmanageChild((Widget
) m_vScrollBar
);
403 XtDestroyWidget((Widget
) m_hScrollBar
);
405 XtDestroyWidget((Widget
) m_vScrollBar
);
407 UnmanageAndDestroy(m_scrolledWindow
);
411 XtDestroyWidget ((Widget
) m_borderWidget
);
412 m_borderWidget
= (WXWidget
) 0;
415 else // Why wasn't this here before? JACS 8/3/2000
419 // Destroy the window
422 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
423 // Child widgets will get destroyed automatically when a frame
424 // or dialog is destroyed, but before that you may get some memory
425 // leaks and potential layout problems if you delete and then add
428 // GRG, Feb/2000: commented this out when adding support for
429 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
430 // that this call crashed wxMotif under OS/2, so it seems
431 // that leaving it out is the right thing to do.
432 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
433 XtDestroyWidget((Widget
) GetMainWidget());
434 SetMainWidget((WXWidget
) NULL
);
438 // ----------------------------------------------------------------------------
439 // scrollbar management
440 // ----------------------------------------------------------------------------
442 WXWidget
wxWindow::DoCreateScrollBar(WXWidget parent
,
443 wxOrientation orientation
,
446 int orient
= ( orientation
& wxHORIZONTAL
) ? XmHORIZONTAL
: XmVERTICAL
;
448 XtVaCreateManagedWidget( "scrollBarWidget",
449 xmScrollBarWidgetClass
, (Widget
)parent
,
450 XmNorientation
, orient
,
455 XtPointer o
= (XtPointer
)orientation
;
456 XtCallbackProc cb
= (XtCallbackProc
)callback
;
458 XtAddCallback( sb
, XmNvalueChangedCallback
, cb
, o
);
459 XtAddCallback( sb
, XmNdragCallback
, cb
, o
);
460 XtAddCallback( sb
, XmNincrementCallback
, cb
, o
);
461 XtAddCallback( sb
, XmNdecrementCallback
, cb
, o
);
462 XtAddCallback( sb
, XmNpageIncrementCallback
, cb
, o
);
463 XtAddCallback( sb
, XmNpageDecrementCallback
, cb
, o
);
464 XtAddCallback( sb
, XmNtoTopCallback
, cb
, o
);
465 XtAddCallback( sb
, XmNtoBottomCallback
, cb
, o
);
471 void wxWindow::CreateScrollbar(wxOrientation orientation
)
473 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
475 XtVaSetValues( (Widget
) m_scrolledWindow
,
476 XmNresizePolicy
, XmRESIZE_NONE
,
479 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
480 // Add scrollbars if required
481 if (orientation
== wxHORIZONTAL
)
483 m_hScrollBar
= DoCreateScrollBar( m_scrolledWindow
, wxHORIZONTAL
,
484 (void (*)())wxScrollBarCallback
);
486 wxDoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, true);
488 XtRealizeWidget( (Widget
)m_hScrollBar
);
490 XtVaSetValues((Widget
) m_scrolledWindow
,
491 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
494 wxAddWindowToTable( (Widget
)m_hScrollBar
, this );
496 else if (orientation
== wxVERTICAL
)
498 m_vScrollBar
= DoCreateScrollBar( m_scrolledWindow
, wxVERTICAL
,
499 (void (*)())wxScrollBarCallback
);
501 wxDoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, true);
503 XtRealizeWidget((Widget
)m_vScrollBar
);
505 XtVaSetValues((Widget
) m_scrolledWindow
,
506 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
509 wxAddWindowToTable( (Widget
)m_vScrollBar
, this );
512 XtVaSetValues( (Widget
) m_scrolledWindow
,
513 XmNresizePolicy
, XmRESIZE_ANY
,
517 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
519 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
521 XtVaSetValues((Widget
) m_scrolledWindow
,
522 XmNresizePolicy
, XmRESIZE_NONE
,
524 String stringSB
= orientation
== wxHORIZONTAL
?
525 XmNhorizontalScrollBar
: XmNverticalScrollBar
;
526 WXWidget
* widgetSB
= orientation
== wxHORIZONTAL
?
527 &m_hScrollBar
: &m_vScrollBar
;
531 wxDeleteWindowFromTable( (Widget
)*widgetSB
);
532 XtDestroyWidget( (Widget
)*widgetSB
);
533 *widgetSB
= (WXWidget
)NULL
;
536 XtVaSetValues( (Widget
)m_scrolledWindow
,
537 stringSB
, (Widget
) 0,
540 XtVaSetValues((Widget
) m_scrolledWindow
,
541 XmNresizePolicy
, XmRESIZE_ANY
,
545 // ---------------------------------------------------------------------------
547 // ---------------------------------------------------------------------------
549 void wxWindow::SetFocus()
551 Widget wMain
= (Widget
) GetMainWidget();
552 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
553 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
556 // Get the window with the focus
557 wxWindow
*wxWindowBase::DoFindFocus()
560 // (1) Can there be multiple focussed widgets in an application?
561 // In which case we need to find the top-level window that's
563 // (2) The widget with the focus may not be in the widget table
564 // depending on which widgets I put in the table
565 wxWindow
*winFocus
= (wxWindow
*)NULL
;
566 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
568 node
= node
->GetNext() )
570 wxWindow
*win
= node
->GetData();
572 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
574 if (w
!= (Widget
) NULL
)
576 winFocus
= wxGetWindowFromTable(w
);
585 bool wxWindow::Enable(bool enable
)
587 if ( !wxWindowBase::Enable(enable
) )
590 Widget wMain
= (Widget
)GetMainWidget();
593 XtSetSensitive(wMain
, enable
);
594 XmUpdateDisplay(wMain
);
600 bool wxWindow::Show(bool show
)
602 if ( !wxWindowBase::Show(show
) )
605 if (m_borderWidget
|| m_scrolledWindow
)
607 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
608 // MapOrUnmap(m_drawingArea, show);
612 if ( !MapOrUnmap(GetTopWidget(), show
) )
613 MapOrUnmap(GetMainWidget(), show
);
619 // Raise the window to the top of the Z order
620 void wxWindow::Raise()
622 Widget wTop
= (Widget
) GetTopWidget();
623 Window window
= XtWindow(wTop
);
624 XRaiseWindow(XtDisplay(wTop
), window
);
627 // Lower the window to the bottom of the Z order
628 void wxWindow::Lower()
630 Widget wTop
= (Widget
) GetTopWidget();
631 Window window
= XtWindow(wTop
);
632 XLowerWindow(XtDisplay(wTop
), window
);
635 void wxWindow::SetLabel(const wxString
& label
)
637 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
,
638 (const char*)label
.mb_str(), NULL
);
641 wxString
wxWindow::GetLabel() const
644 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &label
, NULL
);
646 return wxString(label
);
649 void wxWindow::DoCaptureMouse()
651 g_captureWindow
= this;
655 Widget wMain
= (Widget
)GetMainWidget();
657 XtAddGrab(wMain
, True
, False
);
659 m_winCaptured
= true;
662 void wxWindow::DoReleaseMouse()
664 g_captureWindow
= NULL
;
665 if ( !m_winCaptured
)
668 Widget wMain
= (Widget
)GetMainWidget();
672 m_winCaptured
= false;
675 bool wxWindow::SetFont(const wxFont
& font
)
677 if ( !wxWindowBase::SetFont(font
) )
688 bool wxWindow::SetCursor(const wxCursor
& cursor
)
690 if ( !wxWindowBase::SetCursor(cursor
) )
696 // wxASSERT_MSG( m_cursor.Ok(),
697 // wxT("cursor must be valid after call to the base version"));
698 const wxCursor
* cursor2
= NULL
;
700 cursor2
= & m_cursor
;
702 cursor2
= wxSTANDARD_CURSOR
;
704 WXDisplay
*dpy
= GetXDisplay();
705 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
707 Widget w
= (Widget
) GetMainWidget();
708 Window win
= XtWindow(w
);
709 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
714 // Coordinates relative to the window
715 void wxWindow::WarpPointer (int x
, int y
)
717 Widget wClient
= (Widget
)GetClientWidget();
719 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
722 // ---------------------------------------------------------------------------
724 // ---------------------------------------------------------------------------
726 int wxWindow::GetScrollPos(int orient
) const
728 if (orient
== wxHORIZONTAL
)
734 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
738 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
746 // This now returns the whole range, not just the number of positions that we
748 int wxWindow::GetScrollRange(int orient
) const
750 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
751 // CE scintilla windows don't always have these scrollbars
752 // and it tends to pile up a whole bunch of asserts
753 //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
757 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
761 int wxWindow::GetScrollThumb(int orient
) const
763 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
764 //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
768 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
772 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
774 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
778 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
781 SetInternalScrollPos((wxOrientation
)orient
, pos
);
784 // New function that will replace some of the above.
785 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
786 int range
, bool WXUNUSED(refresh
))
789 GetSize(& oldW
, & oldH
);
793 if (thumbVisible
== 0)
796 if (thumbVisible
> range
)
797 thumbVisible
= range
;
799 // Save the old state to see if it changed
800 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
802 if (orient
== wxHORIZONTAL
)
804 if (thumbVisible
== range
)
807 DestroyScrollbar(wxHORIZONTAL
);
812 CreateScrollbar(wxHORIZONTAL
);
815 if (orient
== wxVERTICAL
)
817 if (thumbVisible
== range
)
820 DestroyScrollbar(wxVERTICAL
);
825 CreateScrollbar(wxVERTICAL
);
828 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
830 if (oldScrollBar
!= newScrollBar
)
832 // This is important! Without it, scrollbars misbehave badly.
833 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
834 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
835 XtRealizeWidget((Widget
) m_scrolledWindow
);
836 XtManageChild((Widget
) m_scrolledWindow
);
841 XtVaSetValues((Widget
) newScrollBar
,
845 XmNsliderSize
, thumbVisible
,
849 SetInternalScrollPos((wxOrientation
)orient
, pos
);
852 GetSize(& newW
, & newH
);
854 // Adjusting scrollbars can resize the canvas accidentally
855 if (newW
!= oldW
|| newH
!= oldH
)
856 SetSize(wxDefaultCoord
, wxDefaultCoord
, oldW
, oldH
);
859 // Does a physical scroll
860 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
865 // Use specified rectangle
866 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
870 // Use whole client area
872 GetClientSize(& w
, & h
);
875 int x1
= (dx
>= 0) ? x
: x
- dx
;
876 int y1
= (dy
>= 0) ? y
: y
- dy
;
877 int w1
= w
- abs(dx
);
878 int h1
= h
- abs(dy
);
879 int x2
= (dx
>= 0) ? x
+ dx
: x
;
880 int y2
= (dy
>= 0) ? y
+ dy
: y
;
884 dc
.SetLogicalFunction (wxCOPY
);
886 Widget widget
= (Widget
) GetMainWidget();
887 Window window
= XtWindow(widget
);
888 Display
* display
= XtDisplay(widget
);
890 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
891 x1
, y1
, w1
, h1
, x2
, y2
);
893 dc
.SetAutoSetting(true);
894 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
895 dc
.SetBrush(brush
); // FIXME: needed?
897 wxWindowList::compatibility_iterator cnode
= m_children
.GetFirst();
900 wxWindow
*child
= cnode
->GetData();
903 child
->GetSize( &sx
, &sy
);
904 wxPoint
pos( child
->GetPosition() );
905 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
906 cnode
= cnode
->GetNext();
909 // We'll add rectangles to the list of update rectangles according to which
910 // bits we've exposed.
915 wxRect
*rect
= new wxRect
;
921 XFillRectangle(display
, window
,
922 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
926 rect
->width
= rect
->width
;
927 rect
->height
= rect
->height
;
929 updateRects
.Append((wxObject
*) rect
);
933 wxRect
*rect
= new wxRect
;
935 rect
->x
= x
+ w
+ dx
;
940 XFillRectangle(display
, window
,
941 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
946 rect
->width
= rect
->width
;
947 rect
->height
= rect
->height
;
949 updateRects
.Append((wxObject
*) rect
);
953 wxRect
*rect
= new wxRect
;
960 XFillRectangle(display
, window
,
961 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
965 rect
->width
= rect
->width
;
966 rect
->height
= rect
->height
;
968 updateRects
.Append((wxObject
*) rect
);
972 wxRect
*rect
= new wxRect
;
975 rect
->y
= y
+ h
+ dy
;
979 XFillRectangle(display
, window
,
980 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
984 rect
->width
= rect
->width
;
985 rect
->height
= rect
->height
;
987 updateRects
.Append((wxObject
*) rect
);
989 dc
.SetBrush(wxNullBrush
);
991 // Now send expose events
993 wxList::compatibility_iterator node
= updateRects
.GetFirst();
996 wxRect
* rect
= (wxRect
*) node
->GetData();
1000 event
.display
= display
;
1001 event
.send_event
= True
;
1002 event
.window
= window
;
1006 event
.width
= rect
->width
;
1007 event
.height
= rect
->height
;
1011 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1013 node
= node
->GetNext();
1017 // Delete the update rects
1018 node
= updateRects
.GetFirst();
1021 wxRect
* rect
= (wxRect
*) node
->GetData();
1023 node
= node
->GetNext();
1026 XmUpdateDisplay((Widget
) GetMainWidget());
1029 // ---------------------------------------------------------------------------
1031 // ---------------------------------------------------------------------------
1033 #if wxUSE_DRAG_AND_DROP
1035 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1042 // Old style file-manager drag&drop
1043 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1048 // ----------------------------------------------------------------------------
1050 // ----------------------------------------------------------------------------
1054 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1059 #endif // wxUSE_TOOLTIPS
1061 // ----------------------------------------------------------------------------
1063 // ----------------------------------------------------------------------------
1067 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1069 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1071 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
1072 x
= mouse
.x
; y
= mouse
.y
;
1075 Widget widget
= (Widget
) GetMainWidget();
1077 /* The menuId field seems to be usused, so we'll use it to
1078 indicate whether a menu is popped up or not:
1079 0: Not currently created as a popup
1080 -1: Created as a popup, but not active
1084 if (menu
->GetParent() && (menu
->GetId() != -1))
1087 if (menu
->GetMainWidget())
1089 menu
->DestroyMenu(true);
1092 menu
->SetId(1); /* Mark as popped-up */
1093 menu
->CreateMenu(NULL
, widget
, menu
, 0);
1094 menu
->SetInvokingWindow(this);
1098 // menu->SetParent(parent);
1099 // parent->children->Append(menu); // Store menu for later deletion
1101 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1109 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1111 wxCanvas *canvas = (wxCanvas *) this;
1112 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1113 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1117 Display
*display
= XtDisplay (widget
);
1118 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1119 Window thisWindow
= XtWindow (widget
);
1121 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1122 &rootX
, &rootY
, &childWindow
);
1124 XButtonPressedEvent event
;
1125 event
.type
= ButtonPress
;
1131 event
.x_root
= rootX
;
1132 event
.y_root
= rootY
;
1134 XmMenuPosition (menuWidget
, &event
);
1135 XtManageChild (menuWidget
);
1137 // The ID of a pop-up menu is 1 when active, and is set to 0 by the
1138 // idle-time destroy routine.
1139 // Waiting until this ID changes causes this function to block until
1140 // the menu has been dismissed and the widgets cleaned up.
1141 // In other words, once this routine returns, it is safe to delete
1143 // Ian Brown <ian.brown@printsoft.de>
1145 wxEventLoop evtLoop
;
1147 while (menu
->GetId() == 1)
1149 wxDoEventLoopIteration( evtLoop
);
1157 // ---------------------------------------------------------------------------
1158 // moving and resizing
1159 // ---------------------------------------------------------------------------
1161 bool wxWindow::PreResize()
1167 void wxWindow::DoGetSize(int *x
, int *y
) const
1169 Widget widget
= (Widget
)( !m_drawingArea
? GetTopWidget() :
1170 ( m_borderWidget
? m_borderWidget
:
1171 m_scrolledWindow
? m_scrolledWindow
:
1176 XtVaGetValues( widget
,
1180 if(x
) *x
= widget
? xx
: -1;
1181 if(y
) *y
= widget
? yy
: -1;
1184 void wxWindow::DoGetPosition(int *x
, int *y
) const
1186 Widget widget
= (Widget
)
1188 ( m_borderWidget
? m_borderWidget
: m_scrolledWindow
) :
1192 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1194 // We may be faking the client origin. So a window that's really at (0, 30)
1195 // may appear (to wxWin apps) to be at (0, 0).
1198 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1199 xx
= (Position
)(xx
- pt
.x
);
1200 yy
= (Position
)(yy
- pt
.y
);
1207 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1209 Widget widget
= (Widget
) GetClientWidget();
1210 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1211 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1212 Window thisWindow
= XtWindow(widget
);
1215 int xx
= x
? *x
: 0;
1216 int yy
= y
? *y
: 0;
1217 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
1218 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
1222 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1224 Widget widget
= (Widget
) GetClientWidget();
1225 Display
*display
= XtDisplay(widget
);
1226 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1227 Window thisWindow
= XtWindow(widget
);
1230 int xx
= x
? *x
: 0;
1231 int yy
= y
? *y
: 0;
1232 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
1233 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
1238 // Get size *available for subwindows* i.e. excluding menu bar etc.
1239 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1241 Widget widget
= (Widget
) GetClientWidget();
1243 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1244 if(x
) *x
= xx
; if(y
) *y
= yy
;
1247 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1249 DoSetSizeIntr(x
, y
, width
, height
, sizeFlags
, false);
1252 void wxWindow::DoSetSizeIntr(int x
, int y
, int width
, int height
,
1253 int sizeFlags
, bool fromCtor
)
1255 // A bit of optimization to help sort out the flickers.
1256 int oldX
= -1, oldY
= -1, oldW
= -1, oldH
= -1;
1260 GetSize(& oldW
, & oldH
);
1261 GetPosition(& oldX
, & oldY
);
1269 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1277 wxSize
size(wxDefaultSize
);
1280 if ( ( sizeFlags
& wxSIZE_AUTO_WIDTH
) && !fromCtor
)
1282 size
= DoGetBestSize();
1293 if( ( sizeFlags
& wxSIZE_AUTO_HEIGHT
) && !fromCtor
)
1295 if( size
.x
== -1 ) size
= DoGetBestSize();
1304 if ( x
!= oldX
|| y
!= oldY
|| width
!= oldW
|| height
!= oldH
1305 || !wxNoOptimize::CanOptimize() )
1318 flags
|= wxMOVE_WIDTH
;
1321 flags
|= wxMOVE_HEIGHT
;
1323 int xx
= x
; int yy
= y
;
1324 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1326 DoMoveWindow( xx
, yy
, width
, height
);
1328 DoMoveWindowIntr( xx
, yy
, width
, height
, flags
);
1333 Widget widget
= (Widget
) GetTopWidget();
1337 bool managed
= XtIsManaged( widget
);
1339 XtUnmanageChild(widget
);
1343 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1345 DoMoveWindow(xx
, yy
, width
, height
);
1348 XtManageChild(widget
);
1352 void wxWindow::DoSetClientSize(int width
, int height
)
1356 Widget drawingArea
= (Widget
) m_drawingArea
;
1358 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1361 XtVaSetValues(drawingArea
, XmNwidth
, width
, NULL
);
1363 XtVaSetValues(drawingArea
, XmNheight
, height
, NULL
);
1365 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1369 Widget widget
= (Widget
) GetTopWidget();
1372 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1374 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1377 void wxWindow::DoMoveWindowIntr(int xx
, int yy
, int w
, int h
,
1382 Widget drawingArea
= (Widget
) m_drawingArea
;
1383 Widget borderOrScrolled
= m_borderWidget
?
1384 (Widget
) m_borderWidget
:
1385 (Widget
) m_scrolledWindow
;
1387 bool managed
= XtIsManaged(borderOrScrolled
);
1389 XtUnmanageChild (borderOrScrolled
);
1390 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1392 if (flags
& wxMOVE_X
)
1393 XtVaSetValues (borderOrScrolled
,
1396 if (flags
& wxMOVE_Y
)
1397 XtVaSetValues (borderOrScrolled
,
1401 if (flags
& wxMOVE_WIDTH
)
1405 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
1406 short thick
, margin
;
1407 XtVaGetValues ((Widget
) m_borderWidget
,
1408 XmNshadowThickness
, &thick
,
1409 XmNmarginWidth
, &margin
,
1411 w
-= 2 * (thick
+ margin
);
1415 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
1418 if (flags
& wxMOVE_HEIGHT
)
1422 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
1423 short thick
, margin
;
1424 XtVaGetValues ((Widget
) m_borderWidget
,
1425 XmNshadowThickness
, &thick
,
1426 XmNmarginHeight
, &margin
,
1428 h
-= 2 * (thick
+ margin
);
1432 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
1436 XtManageChild (borderOrScrolled
);
1437 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1444 XtVaSetValues((Widget
)GetTopWidget(),
1453 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1455 DoMoveWindowIntr (x
, y
, width
, height
,
1456 wxMOVE_X
|wxMOVE_Y
|wxMOVE_WIDTH
|wxMOVE_HEIGHT
);
1459 // ---------------------------------------------------------------------------
1461 // ---------------------------------------------------------------------------
1463 int wxWindow::GetCharHeight() const
1468 wxGetTextExtent (GetXDisplay(), m_font
, 1.0,
1469 "x", NULL
, &height
, NULL
, NULL
);
1471 wxGetTextExtent (this, "x", NULL
, &height
, NULL
, NULL
);
1476 int wxWindow::GetCharWidth() const
1481 wxGetTextExtent (GetXDisplay(), m_font
, 1.0,
1482 "x", &width
, NULL
, NULL
, NULL
);
1484 wxGetTextExtent (this, "x", &width
, NULL
, NULL
, NULL
);
1489 void wxWindow::GetTextExtent(const wxString
& string
,
1491 int *descent
, int *externalLeading
,
1492 const wxFont
*theFont
) const
1494 const wxFont
*fontToUse
= theFont
? theFont
: &m_font
;
1496 if (externalLeading
)
1497 *externalLeading
= 0;
1498 if (fontToUse
->Ok())
1499 wxGetTextExtent (GetXDisplay(), *fontToUse
, 1.0,
1500 string
, x
, y
, NULL
, descent
);
1502 wxGetTextExtent (this, string
, x
, y
, NULL
, descent
);
1505 // ----------------------------------------------------------------------------
1507 // ----------------------------------------------------------------------------
1509 void wxWindow::AddUpdateRect(int x
, int y
, int w
, int h
)
1511 m_updateRegion
.Union( x
, y
, w
, h
);
1514 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1516 Widget widget
= (Widget
) GetMainWidget();
1519 m_needsRefresh
= true;
1520 Display
*display
= XtDisplay(widget
);
1521 Window thisWindow
= XtWindow(widget
);
1523 XExposeEvent dummyEvent
;
1525 GetSize(&width
, &height
);
1527 dummyEvent
.type
= Expose
;
1528 dummyEvent
.display
= display
;
1529 dummyEvent
.send_event
= True
;
1530 dummyEvent
.window
= thisWindow
;
1533 dummyEvent
.x
= rect
->x
;
1534 dummyEvent
.y
= rect
->y
;
1535 dummyEvent
.width
= rect
->width
;
1536 dummyEvent
.height
= rect
->height
;
1542 dummyEvent
.width
= width
;
1543 dummyEvent
.height
= height
;
1545 dummyEvent
.count
= 0;
1549 wxClientDC
dc(this);
1550 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1551 dc
.SetBackground(backgroundBrush
);
1558 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1561 void wxWindow::DoPaint()
1563 //TODO : make a temporary gc so we can do the XCopyArea below
1564 if (m_backingPixmap
&& !m_needsRefresh
)
1568 GC tempGC
= (GC
) dc
.GetBackingGC();
1570 Widget widget
= (Widget
) GetMainWidget();
1575 // We have to test whether it's a wxScrolledWindow (hack!) because
1576 // otherwise we don't know how many pixels have been scrolled. We might
1577 // solve this in the future by defining virtual wxWindow functions to get
1578 // the scroll position in pixels. Or, each kind of scrolled window has to
1579 // implement backing stores itself, using generic wxWidgets code.
1580 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1581 if ( scrolledWindow
)
1584 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1590 // TODO: This could be optimized further by only copying the areas in the
1591 // current update region.
1593 // Only blit the part visible in the client area. The backing pixmap
1594 // always starts at 0, 0 but we may be looking at only a portion of it.
1595 wxSize clientArea
= GetClientSize();
1596 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1597 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1599 // Copy whichever is samller, the amount of pixmap we have to copy,
1600 // or the size of the client area.
1601 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1602 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1604 // Make sure we're not negative
1605 toBlitX
= wxMax(0, toBlitX
);
1606 toBlitY
= wxMax(0, toBlitY
);
1611 (Pixmap
) m_backingPixmap
,
1614 scrollPosX
, scrollPosY
, // Start at the scroll position
1615 toBlitX
, toBlitY
, // How much of the pixmap to copy
1621 wxWindowDC
dc(this);
1622 // Set an erase event first
1623 wxEraseEvent
eraseEvent(GetId(), &dc
);
1624 eraseEvent
.SetEventObject(this);
1625 GetEventHandler()->ProcessEvent(eraseEvent
);
1627 wxPaintEvent
event(GetId());
1628 event
.SetEventObject(this);
1629 GetEventHandler()->ProcessEvent(event
);
1631 m_needsRefresh
= false;
1635 // ----------------------------------------------------------------------------
1637 // ----------------------------------------------------------------------------
1639 // Responds to colour changes: passes event on to children.
1640 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1642 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1645 // Only propagate to non-top-level windows
1646 wxWindow
*win
= node
->GetData();
1647 if ( win
->GetParent() )
1649 wxSysColourChangedEvent event2
;
1650 event
.SetEventObject(win
);
1651 win
->GetEventHandler()->ProcessEvent(event2
);
1654 node
= node
->GetNext();
1658 void wxWindow::OnInternalIdle()
1660 // This calls the UI-update mechanism (querying windows for
1661 // menu/toolbar/control state information)
1662 if (wxUpdateUIEvent::CanUpdate(this) && IsShown())
1663 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1666 // ----------------------------------------------------------------------------
1668 // ----------------------------------------------------------------------------
1670 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1673 if (!m_acceleratorTable
.Ok())
1676 int count
= m_acceleratorTable
.GetCount();
1677 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1679 for (i
= 0; i
< count
; i
++)
1681 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1682 if (entry
->MatchesEvent(event
))
1684 // Bingo, we have a match. Now find a control that matches the
1685 // entry command id.
1687 // Need to go up to the top of the window hierarchy, since it might
1688 // be e.g. a menu item
1689 wxWindow
* parent
= this;
1690 while ( parent
&& !parent
->IsTopLevel() )
1691 parent
= parent
->GetParent();
1696 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1700 // Try for a menu command
1701 if (frame
->GetMenuBar())
1703 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1706 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1707 commandEvent
.SetEventObject(frame
);
1709 // If ProcessEvent returns true (it was handled), then
1710 // the calling code will skip the event handling.
1711 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1717 // Find a child matching the command id
1718 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1724 // Now we process those kinds of windows that we can.
1725 // For now, only buttons.
1726 if ( wxDynamicCast(child
, wxButton
) )
1728 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1729 commandEvent
.SetEventObject(child
);
1730 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1738 // We didn't match the key event against an accelerator.
1742 // ============================================================================
1743 // Motif-specific stuff from here on
1744 // ============================================================================
1746 // ----------------------------------------------------------------------------
1747 // function which maintain the global hash table mapping Widgets to wxWidgets
1748 // ----------------------------------------------------------------------------
1750 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1752 const long key
= (long)w
;
1753 if ( wxWidgetHashTable
->Get(key
))
1755 wxLogDebug("Widget table clash: new widget is %ld, %s",
1756 key
, win
->GetClassInfo()->GetClassName());
1760 wxWidgetHashTable
->Put(key
, win
);
1762 wxLogTrace("widget", "Widget 0x%p <-> window %p (%s)",
1763 w
, win
, win
->GetClassInfo()->GetClassName());
1768 wxWindow
*wxGetWindowFromTable(Widget w
)
1770 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1773 void wxDeleteWindowFromTable(Widget w
)
1775 wxLogTrace("widget", "Widget 0x%p", (WXWidget
)w
);
1777 wxWidgetHashTable
->Delete((long)w
);
1780 // ----------------------------------------------------------------------------
1781 // add/remove window from the table
1782 // ----------------------------------------------------------------------------
1784 // Add to hash table, add event handler
1785 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1786 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1788 wxAddWindowToTable((Widget
) mainWidget
, this);
1789 XtAddEventHandler( (Widget
) mainWidget
,
1790 ButtonPressMask
| ButtonReleaseMask
1791 | PointerMotionMask
,
1793 wxPanelItemEventHandler
,
1799 XtOverrideTranslations ((Widget
) mainWidget
,
1800 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1801 XtFree ((char *) ptr
);
1804 // Some widgets have a parent form widget, e.g. wxRadioBox
1807 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1811 XtOverrideTranslations ((Widget
) formWidget
,
1812 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1813 XtFree ((char *) ptr
);
1820 DoSetSize (x
, y
, width
, height
, wxSIZE_USE_EXISTING
);
1825 // Remove event handler, remove from hash table
1826 bool wxWindow::DetachWidget(WXWidget widget
)
1828 XtRemoveEventHandler( (Widget
) widget
,
1829 ButtonPressMask
| ButtonReleaseMask
1830 | PointerMotionMask
,
1832 wxPanelItemEventHandler
,
1835 wxDeleteWindowFromTable((Widget
) widget
);
1839 // ----------------------------------------------------------------------------
1840 // Motif-specific accessors
1841 // ----------------------------------------------------------------------------
1843 WXWindow
wxWindow::GetClientXWindow() const
1845 Widget wMain
= (Widget
)GetClientWidget();
1847 return (WXWindow
) XtWindow(wMain
);
1849 return (WXWindow
) 0;
1852 // Get the underlying X window
1853 WXWindow
wxWindow::GetXWindow() const
1855 Widget wMain
= (Widget
)GetMainWidget();
1857 return (WXWindow
) XtWindow(wMain
);
1859 return (WXWindow
) 0;
1862 // Get the underlying X display
1863 WXDisplay
*wxWindow::GetXDisplay() const
1865 Widget wMain
= (Widget
)GetMainWidget();
1867 return (WXDisplay
*) XtDisplay(wMain
);
1869 return (WXDisplay
*) NULL
;
1872 WXWidget
wxWindow::GetMainWidget() const
1875 return m_drawingArea
;
1877 return m_mainWidget
;
1880 WXWidget
wxWindow::GetClientWidget() const
1882 if (m_drawingArea
!= (WXWidget
) 0)
1883 return m_drawingArea
;
1885 return GetMainWidget();
1888 WXWidget
wxWindow::GetTopWidget() const
1890 return GetMainWidget();
1893 WXWidget
wxWindow::GetLabelWidget() const
1895 return GetMainWidget();
1898 // ----------------------------------------------------------------------------
1900 // ----------------------------------------------------------------------------
1902 // All widgets should have this as their resize proc.
1903 // OnSize sent to wxWindow via client data.
1904 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
),
1905 String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1907 wxWindow
*win
= wxGetWindowFromTable(w
);
1911 if (win
->PreResize())
1913 wxSize
newSize(win
->GetSize());
1914 wxSizeEvent
sizeEvent(newSize
, win
->GetId());
1915 sizeEvent
.SetEventObject(win
);
1916 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1920 static void wxCanvasRepaintProc(Widget drawingArea
,
1921 XtPointer clientData
,
1922 XmDrawingAreaCallbackStruct
* cbs
)
1924 if (!wxGetWindowFromTable(drawingArea
))
1927 XEvent
* event
= cbs
->event
;
1928 wxWindow
* win
= (wxWindow
*) clientData
;
1930 switch (event
->type
)
1934 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1935 event
->xexpose
.width
, event
->xexpose
.height
);
1937 if (event
-> xexpose
.count
== 0)
1946 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1947 static void wxCanvasEnterLeave(Widget drawingArea
,
1948 XtPointer
WXUNUSED(clientData
),
1949 XCrossingEvent
* event
)
1951 XmDrawingAreaCallbackStruct cbs
;
1954 ((XCrossingEvent
&) ev
) = *event
;
1956 cbs
.reason
= XmCR_INPUT
;
1959 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1962 // Fix to make it work under Motif 1.0 (!)
1963 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
),
1964 XButtonEvent
*WXUNUSED(event
))
1966 #if XmVersion <= 1000
1967 XmDrawingAreaCallbackStruct cbs
;
1970 ev
= *((XEvent
*) event
);
1971 cbs
.reason
= XmCR_INPUT
;
1974 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1975 #endif // XmVersion <= 1000
1978 static void wxCanvasInputEvent(Widget drawingArea
,
1979 XtPointer
WXUNUSED(data
),
1980 XmDrawingAreaCallbackStruct
* cbs
)
1982 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1983 XEvent
* xevent
= cbs
->event
;
1988 if (cbs
->reason
!= XmCR_INPUT
)
1991 switch (xevent
->xany
.type
)
1999 wxMouseEvent
wxevent(0);
2000 if (wxTranslateMouseEvent(wxevent
, canvas
, drawingArea
, xevent
))
2002 canvas
->GetEventHandler()->ProcessEvent(wxevent
);
2008 wxKeyEvent
event (wxEVT_CHAR
);
2009 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, xevent
))
2011 // Implement wxFrame::OnCharHook by checking ancestor.
2012 wxWindow
*parent
= canvas
;
2013 while (parent
&& !parent
->IsTopLevel())
2014 parent
= parent
->GetParent();
2018 event
.SetEventType(wxEVT_CHAR_HOOK
);
2019 if (parent
->GetEventHandler()->ProcessEvent(event
))
2023 // For simplicity, OnKeyDown is the same as OnChar
2024 // TODO: filter modifier key presses from OnChar
2025 event
.SetEventType(wxEVT_KEY_DOWN
);
2027 // Only process OnChar if OnKeyDown didn't swallow it
2028 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2030 event
.SetEventType(wxEVT_CHAR
);
2031 canvas
->GetEventHandler()->ProcessEvent (event
);
2038 wxKeyEvent
event (wxEVT_KEY_UP
);
2039 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, xevent
))
2041 canvas
->GetEventHandler()->ProcessEvent (event
);
2047 if (xevent
->xfocus
.detail
!= NotifyPointer
)
2049 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2050 event
.SetEventObject(canvas
);
2051 canvas
->GetEventHandler()->ProcessEvent(event
);
2057 if (xevent
->xfocus
.detail
!= NotifyPointer
)
2059 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2060 event
.SetEventObject(canvas
);
2061 canvas
->GetEventHandler()->ProcessEvent(event
);
2070 static void wxPanelItemEventHandler(Widget wid
,
2071 XtPointer
WXUNUSED(client_data
),
2073 Boolean
*continueToDispatch
)
2075 // Widget can be a label or the actual widget.
2077 wxWindow
*window
= wxGetWindowFromTable(wid
);
2080 wxMouseEvent
wxevent(0);
2081 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2083 window
->GetEventHandler()->ProcessEvent(wxevent
);
2087 // TODO: probably the key to allowing default behaviour to happen. Say we
2088 // set a m_doDefault flag to false at the start of this function. Then in
2089 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2090 // true, indicating that default processing can happen. Thus, behaviour can
2091 // appear to be overridden just by adding an event handler and not calling
2092 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2093 // way of handling drawing area events, to simplify things.
2094 *continueToDispatch
= True
;
2097 static void wxScrollBarCallback(Widget scrollbar
,
2098 XtPointer clientData
,
2099 XmScrollBarCallbackStruct
*cbs
)
2101 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2102 wxCHECK_RET( win
, _T("invalid widget in scrollbar callback") );
2104 wxOrientation orientation
= (wxOrientation
)wxPtrToUInt(clientData
);
2106 wxEventType eventType
= wxEVT_NULL
;
2107 switch (cbs
->reason
)
2109 case XmCR_INCREMENT
:
2111 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2114 case XmCR_DECREMENT
:
2116 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2121 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2124 case XmCR_VALUE_CHANGED
:
2126 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2129 case XmCR_PAGE_INCREMENT
:
2131 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2134 case XmCR_PAGE_DECREMENT
:
2136 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2141 eventType
= wxEVT_SCROLLWIN_TOP
;
2144 case XmCR_TO_BOTTOM
:
2146 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2151 // Should never get here
2152 wxFAIL_MSG("Unknown scroll event.");
2157 wxScrollWinEvent
event(eventType
,
2160 event
.SetEventObject( win
);
2161 win
->GetEventHandler()->ProcessEvent(event
);
2164 // For repainting arbitrary windows
2165 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2167 wxWindow
* win
= wxGetWindowFromTable(w
);
2171 switch ( event
->type
)
2175 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2176 event
->xexpose
.width
, event
->xexpose
.height
);
2178 if ( event
->xexpose
.count
== 0 )
2188 // ----------------------------------------------------------------------------
2189 // TranslateXXXEvent() functions
2190 // ----------------------------------------------------------------------------
2192 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
,
2193 Widget widget
, const XEvent
*xevent
)
2195 switch (xevent
->xany
.type
)
2200 fprintf(stderr
, "Widget 0x%p <-> window %p (%s), %s\n",
2201 (WXWidget
)widget
, win
, win
->GetClassInfo()->GetClassName(),
2202 (xevent
->xany
.type
== EnterNotify
? "ENTER" : "LEAVE"));
2208 int eventx
= xevent
->xbutton
.x
, eventy
= xevent
->xbutton
.y
;
2210 wxEventType eventType
= wxEVT_NULL
;
2212 if (xevent
->xany
.type
== LeaveNotify
)
2214 eventType
= wxEVT_LEAVE_WINDOW
;
2216 if (xevent
->xany
.type
== EnterNotify
)
2218 eventType
= wxEVT_ENTER_WINDOW
;
2220 else if (xevent
->xany
.type
== MotionNotify
)
2222 eventType
= wxEVT_MOTION
;
2224 if (xevent
->xmotion
.is_hint
== NotifyHint
)
2229 Display
*dpy
= XtDisplay (widget
);
2231 XQueryPointer (dpy
, XtWindow (widget
),
2233 &x_root
, &y_root
, &eventx
, &eventy
, &state
);
2236 else if (xevent
->xany
.type
== ButtonPress
)
2238 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2240 if (xevent
->xbutton
.button
== Button1
)
2242 eventType
= wxEVT_LEFT_DOWN
;
2245 else if (xevent
->xbutton
.button
== Button2
)
2247 eventType
= wxEVT_MIDDLE_DOWN
;
2250 else if (xevent
->xbutton
.button
== Button3
)
2252 eventType
= wxEVT_RIGHT_DOWN
;
2256 // check for a double click
2258 long dclickTime
= XtGetMultiClickTime(xevent
->xany
.display
);
2259 long ts
= wxevent
.GetTimestamp();
2261 int buttonLast
= win
->GetLastClickedButton();
2262 long lastTS
= win
->GetLastClickTime();
2263 if ( buttonLast
&& buttonLast
== button
&&
2264 (ts
- lastTS
) < dclickTime
)
2267 win
->SetLastClick(0, ts
);
2268 if ( eventType
== wxEVT_LEFT_DOWN
)
2269 eventType
= wxEVT_LEFT_DCLICK
;
2270 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2271 eventType
= wxEVT_MIDDLE_DCLICK
;
2272 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2273 eventType
= wxEVT_RIGHT_DCLICK
;
2277 // not fast enough or different button
2278 win
->SetLastClick(button
, ts
);
2281 else if (xevent
->xany
.type
== ButtonRelease
)
2283 if (xevent
->xbutton
.button
== Button1
)
2285 eventType
= wxEVT_LEFT_UP
;
2287 else if (xevent
->xbutton
.button
== Button2
)
2289 eventType
= wxEVT_MIDDLE_UP
;
2291 else if (xevent
->xbutton
.button
== Button3
)
2293 eventType
= wxEVT_RIGHT_UP
;
2303 wxevent
.SetEventType(eventType
);
2306 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2309 win
->GetPosition(&x2
, &y2
);
2311 // The button x/y must be translated to wxWidgets
2312 // window space - the widget might be a label or button,
2316 if (widget
!= (Widget
)win
->GetMainWidget())
2322 wxevent
.m_x
= eventx
+ dx
;
2323 wxevent
.m_y
= eventy
+ dy
;
2325 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2326 || (event_left_is_down (xevent
)
2327 && (eventType
!= wxEVT_LEFT_UP
)));
2328 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2329 || (event_middle_is_down (xevent
)
2330 && (eventType
!= wxEVT_MIDDLE_UP
)));
2331 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2332 || (event_right_is_down (xevent
)
2333 && (eventType
!= wxEVT_RIGHT_UP
)));
2335 wxevent
.m_shiftDown
= (xevent
->xbutton
.state
& ShiftMask
) == ShiftMask
;
2336 wxevent
.m_controlDown
= (xevent
->xbutton
.state
& ControlMask
) == ControlMask
;
2337 wxevent
.m_altDown
= (xevent
->xbutton
.state
& Mod3Mask
) == Mod3Mask
;
2338 wxevent
.m_metaDown
= (xevent
->xbutton
.state
& Mod1Mask
) == Mod1Mask
;
2340 wxevent
.SetId(win
->GetId());
2341 wxevent
.SetEventObject(win
);
2349 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
,
2350 Widget
WXUNUSED(widget
), const XEvent
*xevent
)
2352 switch (xevent
->xany
.type
)
2360 (void) XLookupString((XKeyEvent
*)xevent
, buf
, 20, &keySym
, NULL
);
2361 int id
= wxCharCodeXToWX (keySym
);
2362 // id may be WXK_xxx code - these are outside ASCII range, so we
2363 // can't just use toupper() on id
2364 if (id
>= 'a' && id
<= 'z')
2367 if (xevent
->xkey
.state
& ShiftMask
)
2368 wxevent
.m_shiftDown
= true;
2369 if (xevent
->xkey
.state
& ControlMask
)
2370 wxevent
.m_controlDown
= true;
2371 if (xevent
->xkey
.state
& Mod3Mask
)
2372 wxevent
.m_altDown
= true;
2373 if (xevent
->xkey
.state
& Mod1Mask
)
2374 wxevent
.m_metaDown
= true;
2375 wxevent
.SetEventObject(win
);
2376 wxevent
.m_keyCode
= id
;
2377 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2379 wxevent
.m_x
= xevent
->xbutton
.x
;
2380 wxevent
.m_y
= xevent
->xbutton
.y
;
2393 // ----------------------------------------------------------------------------
2395 // ----------------------------------------------------------------------------
2397 #define YAllocColor XAllocColor
2398 XColor g_itemColors
[5];
2399 int wxComputeColours (Display
*display
, const wxColour
* back
, const wxColour
* fore
)
2402 static XmColorProc colorProc
;
2404 result
= wxNO_COLORS
;
2408 g_itemColors
[0].red
= (unsigned short)(((long) back
->Red ()) << 8);
2409 g_itemColors
[0].green
= (unsigned short)(((long) back
->Green ()) << 8);
2410 g_itemColors
[0].blue
= (unsigned short)(((long) back
->Blue ()) << 8);
2411 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2412 if (colorProc
== (XmColorProc
) NULL
)
2414 // Get a ptr to the actual function
2415 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2416 // And set it back to motif.
2417 XmSetColorCalculation (colorProc
);
2419 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2420 &g_itemColors
[wxFORE_INDEX
],
2421 &g_itemColors
[wxSELE_INDEX
],
2422 &g_itemColors
[wxTOPS_INDEX
],
2423 &g_itemColors
[wxBOTS_INDEX
]);
2424 result
= wxBACK_COLORS
;
2428 g_itemColors
[wxFORE_INDEX
].red
= (unsigned short)(((long) fore
->Red ()) << 8);
2429 g_itemColors
[wxFORE_INDEX
].green
= (unsigned short)(((long) fore
->Green ()) << 8);
2430 g_itemColors
[wxFORE_INDEX
].blue
= (unsigned short)(((long) fore
->Blue ()) << 8);
2431 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2432 if (result
== wxNO_COLORS
)
2433 result
= wxFORE_COLORS
;
2436 Display
*dpy
= display
;
2437 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2441 /* 5 Colours to allocate */
2442 for (int i
= 0; i
< 5; i
++)
2443 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2444 result
= wxNO_COLORS
;
2448 /* Only 1 colour to allocate */
2449 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2450 result
= wxNO_COLORS
;
2456 // Changes the foreground and background colours to be derived from the current
2457 // background colour. To change the foreground colour, you must call
2458 // SetForegroundColour explicitly.
2459 void wxWindow::ChangeBackgroundColour()
2461 WXWidget mainWidget
= GetMainWidget();
2463 wxDoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2464 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2465 wxDoChangeForegroundColour(m_scrolledWindow
, m_backgroundColour
);
2468 void wxWindow::ChangeForegroundColour()
2470 WXWidget mainWidget
= GetMainWidget();
2472 wxDoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2473 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2474 wxDoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2477 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2479 if ( !wxWindowBase::SetBackgroundColour(col
) )
2482 ChangeBackgroundColour();
2487 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2489 if ( !wxWindowBase::SetForegroundColour(col
) )
2492 ChangeForegroundColour();
2497 void wxWindow::ChangeFont(bool keepOriginalSize
)
2499 // Note that this causes the widget to be resized back
2500 // to its original size! We therefore have to set the size
2501 // back again. TODO: a better way in Motif?
2502 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2503 if (w
&& m_font
.Ok())
2505 int width
, height
, width1
, height1
;
2506 GetSize(& width
, & height
);
2508 wxDoChangeFont( w
, m_font
);
2510 GetSize(& width1
, & height1
);
2511 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2513 SetSize(wxDefaultCoord
, wxDefaultCoord
, width
, height
);
2519 void wxWindow::PostCreation()
2522 ChangeForegroundColour();
2523 ChangeBackgroundColour();
2527 void wxWindow::PreCreation()
2529 InheritAttributes();
2532 // ----------------------------------------------------------------------------
2534 // ----------------------------------------------------------------------------
2536 wxWindow
*wxGetActiveWindow()
2539 wxFAIL_MSG("Not implemented");
2544 wxWindow
*wxWindowBase::GetCapture()
2546 return (wxWindow
*)g_captureWindow
;
2550 // Find the wxWindow at the current mouse position, returning the mouse
2552 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2554 pt
= wxGetMousePosition();
2555 return wxFindWindowAtPoint(pt
);
2558 void wxGetMouseState(int& rootX
, int& rootY
, unsigned& maskReturn
)
2560 Display
*display
= wxGlobalDisplay();
2561 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2562 Window rootReturn
, childReturn
;
2565 XQueryPointer (display
,
2569 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
2572 // Get the current mouse position.
2573 wxPoint
wxGetMousePosition()
2578 wxGetMouseState(x
, y
, mask
);
2579 return wxPoint(x
, y
);
2582 wxMouseState
wxGetMouseState()
2588 wxGetMouseState(x
, y
, mask
);
2593 ms
.SetLeftDown(mask
& Button1Mask
);
2594 ms
.SetMiddleDown(mask
& Button2Mask
);
2595 ms
.SetRightDown(mask
& Button3Mask
);
2597 ms
.SetControlDown(mask
& ControlMask
);
2598 ms
.SetShiftDown(mask
& ShiftMask
);
2599 ms
.SetAltDown(mask
& Mod3Mask
);
2600 ms
.SetMetaDown(mask
& Mod1Mask
);
2606 #if wxMOTIF_NEW_FONT_HANDLING
2610 void wxGetTextExtent(const wxWindow
* window
, const wxString
& str
,
2611 int* width
, int* height
, int* ascent
, int* descent
)
2615 XmRendition rendition
= NULL
;
2616 XmRenderTable table
= NULL
;
2617 Widget w
= (Widget
) window
->GetLabelWidget();
2619 XtVaGetValues( w
, XmNrenderTable
, &table
, NULL
);
2621 table
= XmeGetDefaultRenderTable(w
, XmTEXT_RENDER_TABLE
);
2623 rendition
= XmRenderTableGetRendition( table
, "" );
2624 XtSetArg( args
[count
], XmNfont
, 0 ); ++count
;
2625 XtSetArg( args
[count
], XmNfontType
, 0 ); ++count
;
2626 XmRenditionRetrieve( rendition
, args
, count
);
2628 if (args
[1].value
== XmFONT_IS_FONTSET
)
2630 XRectangle ink
, logical
;
2631 WXFontSet fset
= (WXFontSet
) args
[0].value
;
2633 XmbTextExtents( (XFontSet
)fset
, str
.c_str(), str
.length(),
2636 if( width
) *width
= logical
.width
;
2637 if( height
) *height
= logical
.height
;
2638 if( ascent
) *ascent
= -logical
.y
;
2639 if( descent
) *descent
= logical
.height
+ logical
.y
;
2643 int direction
, ascent2
, descent2
;
2644 XCharStruct overall
;
2645 XFontStruct
* fontStruct
;
2647 XmeRenderTableGetDefaultFont( table
, &fontStruct
);
2648 XTextExtents(fontStruct
, (const char*)str
.c_str(), str
.length(),
2649 &direction
, &ascent2
, &descent2
, &overall
);
2651 if ( width
) *width
= overall
.width
;
2652 if ( height
) *height
= ascent2
+ descent2
;
2653 if ( descent
) *descent
= descent2
;
2654 if ( ascent
) *ascent
= ascent2
;
2658 #else // if !wxMOTIF_NEW_FONT_HANDLING
2660 void wxGetTextExtent(const wxWindow
* window
, const wxString
& str
,
2661 int* width
, int* height
, int* ascent
, int* descent
)
2663 XmFontList list
= NULL
;
2666 Widget w
= (Widget
) window
->GetLabelWidget();
2668 XtVaGetValues( w
, XmNfontList
, &list
, NULL
);
2669 XmFontListInitFontContext( &cxt
, list
);
2671 XmFontListEntry entry
= XmFontListNextEntry( cxt
);
2672 XmFontListFreeFontContext( cxt
);
2673 XtPointer thing
= XmFontListEntryGetFont( entry
, &type
);
2675 if (type
== XmFONT_IS_FONTSET
)
2677 XRectangle ink
, logical
;
2679 XmbTextExtents( (XFontSet
)thing
, str
.c_str(), str
.length(),
2682 if( width
) *width
= logical
.width
;
2683 if( height
) *height
= logical
.height
;
2684 if( ascent
) *ascent
= -logical
.y
;
2685 if( descent
) *descent
= logical
.height
+ logical
.y
;
2689 int direction
, ascent2
, descent2
;
2690 XCharStruct overall
;
2692 XTextExtents( (XFontStruct
*)thing
, (char*)(const char*)str
.c_str(), str
.length(),
2693 &direction
, &ascent2
, &descent2
, &overall
);
2695 if ( width
) *width
= overall
.width
;
2696 if ( height
) *height
= ascent2
+ descent2
;
2697 if ( descent
) *descent
= descent2
;
2698 if ( ascent
) *ascent
= ascent2
;
2702 #endif // !wxMOTIF_NEW_FONT_HANDLING
2704 // ----------------------------------------------------------------------------
2705 // wxNoOptimize: switch off size optimization
2706 // ----------------------------------------------------------------------------
2708 int wxNoOptimize::ms_count
= 0;