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"
30 #include "wx/dcclient.h"
31 #include "wx/button.h"
33 #include "wx/settings.h"
34 #include "wx/scrolwin.h"
35 #include "wx/layout.h"
36 #include "wx/menuitem.h"
37 #include "wx/module.h"
38 #include "wx/unix/utilsx11.h"
41 #include "wx/evtloop.h"
43 #if wxUSE_DRAG_AND_DROP
47 // DoSetSizeIntr and DoMoveWindowIntr
49 // under Motif composite controls (such as wxCalendarCtrl or generic wxSpinCtrl
50 // did not work and/or segfaulted because
51 // 1) wxWindow::Create calls SetSize,
52 // which results in a call to DoSetSize much earlier than in the other ports
53 // 2) if wxWindow::Create is called (wxControl::Create calls it)
54 // then DoSetSize is never called, causing layout problems in composite
58 // 1) don't call SetSize, DoSetSize, DoMoveWindow, DoGetPosition,
59 // DoSetPosition directly or indirectly from wxWindow::Create
60 // 2) call DoMoveWindow from DoSetSize, allowing controls to override it
63 #pragma message disable nosimpint
67 #include <Xm/DrawingA.h>
68 #include <Xm/ScrolledW.h>
69 #include <Xm/ScrollBar.h>
72 #include <Xm/RowColumn.h> // for XmMenuPosition
74 #pragma message enable nosimpint
77 #include "wx/motif/private.h"
78 #include "wx/motif/dcclient.h"
82 // ----------------------------------------------------------------------------
83 // global variables for this module
84 // ----------------------------------------------------------------------------
86 extern wxHashTable
*wxWidgetHashTable
;
87 static wxWindow
* g_captureWindow
= NULL
;
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
95 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
96 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
97 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
98 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
99 XmScrollBarCallbackStruct
*cbs
);
100 static void wxPanelItemEventHandler(Widget wid
,
101 XtPointer client_data
,
103 Boolean
*continueToDispatch
);
108 // Helper function for 16-bit fonts
109 static int str16len(const char *s
)
113 while (s
[0] && s
[1]) {
123 // ----------------------------------------------------------------------------
125 // ----------------------------------------------------------------------------
127 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
128 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
129 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
137 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
138 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
141 // ============================================================================
143 // ============================================================================
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
151 Widget w
= (Widget
)widget
;
159 bool wxWindow::MapOrUnmap(WXWidget widget
, bool domap
)
161 Widget w
= (Widget
)widget
;
165 // Rationale: a lot of common operations (including but not
166 // limited to moving, resizing and appending items to a listbox)
167 // unmamange the widget, do their work, then manage it again.
168 // This means that, for example adding an item to a listbox will show it,
169 // or that most controls are shown every time they are moved or resized!
170 XtSetMappedWhenManaged( w
, domap
);
172 // if the widget is not unmanaged, it still intercepts
173 // mouse events, even if it is not mapped (and hence invisible)
188 // ----------------------------------------------------------------------------
190 // ----------------------------------------------------------------------------
192 void wxWindow::Init()
195 m_needsRefresh
= true;
196 m_mainWidget
= (WXWidget
) 0;
198 m_winCaptured
= false;
206 m_drawingArea
= (WXWidget
) 0;
211 m_backingPixmap
= (WXPixmap
) 0;
222 // real construction (Init() must have been called before!)
223 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
227 const wxString
& name
)
229 // Get default border
230 wxBorder border
= GetBorder(style
);
231 style
&= ~wxBORDER_MASK
;
234 wxCHECK_MSG( parent
, false, "can't create wxWindow without parent" );
236 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
238 parent
->AddChild(this);
241 //// TODO: we should probably optimize by only creating a
242 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
243 //// But for now, let's simplify things by always creating the
244 //// drawing area, since otherwise the translations are different.
246 // New translations for getting mouse motion feedback
247 static const String translations
= wxMOTIF_STR(
248 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
249 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
250 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
251 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
252 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
253 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
254 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
255 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
256 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
257 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
258 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
259 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
260 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
261 <Key>: DrawingAreaInput()");
263 XtActionsRec actions
[1];
264 actions
[0].string
= wxMOTIF_STR("wxCanvasMotionEvent");
265 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
266 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
268 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
269 m_borderWidget
= wxCreateBorderWidget( (WXWidget
)parentWidget
, style
);
271 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
274 xmScrolledWindowWidgetClass
,
275 m_borderWidget
? (Widget
) m_borderWidget
277 XmNresizePolicy
, XmRESIZE_NONE
,
279 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
280 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
284 XtTranslations ptr
= XtParseTranslationTable(translations
);
285 m_drawingArea
= (WXWidget
)XtVaCreateWidget
288 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
289 XmNunitType
, XmPIXELS
,
290 // XmNresizePolicy, XmRESIZE_ANY,
291 XmNresizePolicy
, XmRESIZE_NONE
,
294 XmNtranslations
, ptr
,
297 XtFree((char *) ptr
);
300 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
302 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
303 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
304 XtFree ((char *) ptr
);
308 wxAddWindowToTable((Widget
) m_drawingArea
, this);
309 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
311 // This order is very important in Motif 1.2.1
312 XtRealizeWidget ((Widget
) m_scrolledWindow
);
313 XtRealizeWidget ((Widget
) m_drawingArea
);
314 XtManageChild ((Widget
) m_drawingArea
);
316 ptr
= XtParseTranslationTable("<Configure>: resize()");
317 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
318 XtFree ((char *) ptr
);
320 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
321 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
324 (Widget
)m_drawingArea
,
325 PointerMotionHintMask
| EnterWindowMask
|
326 LeaveWindowMask
| FocusChangeMask
,
328 (XtEventHandler
) wxCanvasEnterLeave
,
332 XmScrolledWindowSetAreas(
333 (Widget
)m_scrolledWindow
,
334 (Widget
) 0, (Widget
) 0,
335 (Widget
) m_drawingArea
);
339 // Without this, the cursor may not be restored properly (e.g. in splitter
341 SetCursor(*wxSTANDARD_CURSOR
);
342 DoSetSizeIntr(pos
.x
, pos
.y
, size
.x
,size
.y
, wxSIZE_AUTO
, true);
347 wxWindow::~wxWindow()
351 if (g_captureWindow
== this)
352 g_captureWindow
= NULL
;
354 // Motif-specific actions first
355 WXWidget wMain
= GetMainWidget();
358 // Removes event handlers
362 // If m_drawingArea, we're a fully-fledged window with drawing area,
363 // scrollbars etc. (what wxCanvas used to be)
366 // Destroy children before destroying self
370 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
372 Widget w
= (Widget
) m_drawingArea
;
373 wxDeleteWindowFromTable(w
);
378 m_drawingArea
= (WXWidget
) 0;
381 // Only if we're _really_ a canvas (not a dialog box/panel)
382 if (m_scrolledWindow
)
384 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
389 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
390 XtUnmanageChild((Widget
) m_hScrollBar
);
394 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
395 XtUnmanageChild((Widget
) m_vScrollBar
);
399 XtDestroyWidget((Widget
) m_hScrollBar
);
401 XtDestroyWidget((Widget
) m_vScrollBar
);
403 UnmanageAndDestroy(m_scrolledWindow
);
407 XtDestroyWidget ((Widget
) m_borderWidget
);
408 m_borderWidget
= (WXWidget
) 0;
411 else // Why wasn't this here before? JACS 8/3/2000
415 // Destroy the window
418 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
419 // Child widgets will get destroyed automatically when a frame
420 // or dialog is destroyed, but before that you may get some memory
421 // leaks and potential layout problems if you delete and then add
424 // GRG, Feb/2000: commented this out when adding support for
425 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
426 // that this call crashed wxMotif under OS/2, so it seems
427 // that leaving it out is the right thing to do.
428 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
429 XtDestroyWidget((Widget
) GetMainWidget());
430 SetMainWidget((WXWidget
) NULL
);
434 // ----------------------------------------------------------------------------
435 // scrollbar management
436 // ----------------------------------------------------------------------------
438 WXWidget
wxWindow::DoCreateScrollBar(WXWidget parent
,
439 wxOrientation orientation
,
442 int orient
= ( orientation
& wxHORIZONTAL
) ? XmHORIZONTAL
: XmVERTICAL
;
444 XtVaCreateManagedWidget( "scrollBarWidget",
445 xmScrollBarWidgetClass
, (Widget
)parent
,
446 XmNorientation
, orient
,
451 XtPointer o
= (XtPointer
)orientation
;
452 XtCallbackProc cb
= (XtCallbackProc
)callback
;
454 XtAddCallback( sb
, XmNvalueChangedCallback
, cb
, o
);
455 XtAddCallback( sb
, XmNdragCallback
, cb
, o
);
456 XtAddCallback( sb
, XmNincrementCallback
, cb
, o
);
457 XtAddCallback( sb
, XmNdecrementCallback
, cb
, o
);
458 XtAddCallback( sb
, XmNpageIncrementCallback
, cb
, o
);
459 XtAddCallback( sb
, XmNpageDecrementCallback
, cb
, o
);
460 XtAddCallback( sb
, XmNtoTopCallback
, cb
, o
);
461 XtAddCallback( sb
, XmNtoBottomCallback
, cb
, o
);
467 void wxWindow::CreateScrollbar(wxOrientation orientation
)
469 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
471 XtVaSetValues( (Widget
) m_scrolledWindow
,
472 XmNresizePolicy
, XmRESIZE_NONE
,
475 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
476 // Add scrollbars if required
477 if (orientation
== wxHORIZONTAL
)
479 m_hScrollBar
= DoCreateScrollBar( m_scrolledWindow
, wxHORIZONTAL
,
480 (void (*)())wxScrollBarCallback
);
482 wxDoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, true);
484 XtRealizeWidget( (Widget
)m_hScrollBar
);
486 XtVaSetValues((Widget
) m_scrolledWindow
,
487 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
490 wxAddWindowToTable( (Widget
)m_hScrollBar
, this );
492 else if (orientation
== wxVERTICAL
)
494 m_vScrollBar
= DoCreateScrollBar( m_scrolledWindow
, wxVERTICAL
,
495 (void (*)())wxScrollBarCallback
);
497 wxDoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, true);
499 XtRealizeWidget((Widget
)m_vScrollBar
);
501 XtVaSetValues((Widget
) m_scrolledWindow
,
502 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
505 wxAddWindowToTable( (Widget
)m_vScrollBar
, this );
508 XtVaSetValues( (Widget
) m_scrolledWindow
,
509 XmNresizePolicy
, XmRESIZE_ANY
,
513 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
515 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
517 XtVaSetValues((Widget
) m_scrolledWindow
,
518 XmNresizePolicy
, XmRESIZE_NONE
,
520 String stringSB
= orientation
== wxHORIZONTAL
?
521 XmNhorizontalScrollBar
: XmNverticalScrollBar
;
522 WXWidget
* widgetSB
= orientation
== wxHORIZONTAL
?
523 &m_hScrollBar
: &m_vScrollBar
;
527 wxDeleteWindowFromTable( (Widget
)*widgetSB
);
528 XtDestroyWidget( (Widget
)*widgetSB
);
529 *widgetSB
= (WXWidget
)NULL
;
532 XtVaSetValues( (Widget
)m_scrolledWindow
,
533 stringSB
, (Widget
) 0,
536 XtVaSetValues((Widget
) m_scrolledWindow
,
537 XmNresizePolicy
, XmRESIZE_ANY
,
541 // ---------------------------------------------------------------------------
543 // ---------------------------------------------------------------------------
545 void wxWindow::SetFocus()
547 Widget wMain
= (Widget
) GetMainWidget();
548 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
549 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
552 // Get the window with the focus
553 wxWindow
*wxWindowBase::DoFindFocus()
556 // (1) Can there be multiple focussed widgets in an application?
557 // In which case we need to find the top-level window that's
559 // (2) The widget with the focus may not be in the widget table
560 // depending on which widgets I put in the table
561 wxWindow
*winFocus
= NULL
;
562 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
564 node
= node
->GetNext() )
566 wxWindow
*win
= node
->GetData();
568 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
570 if (w
!= (Widget
) NULL
)
572 winFocus
= wxGetWindowFromTable(w
);
581 bool wxWindow::Enable(bool enable
)
583 if ( !wxWindowBase::Enable(enable
) )
586 Widget wMain
= (Widget
)GetMainWidget();
589 XtSetSensitive(wMain
, enable
);
590 XmUpdateDisplay(wMain
);
596 bool wxWindow::Show(bool show
)
598 if ( !wxWindowBase::Show(show
) )
601 if (m_borderWidget
|| m_scrolledWindow
)
603 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
604 // MapOrUnmap(m_drawingArea, show);
608 if ( !MapOrUnmap(GetTopWidget(), show
) )
609 MapOrUnmap(GetMainWidget(), show
);
615 // Raise the window to the top of the Z order
616 void wxWindow::Raise()
618 Widget wTop
= (Widget
) GetTopWidget();
619 Window window
= XtWindow(wTop
);
620 XRaiseWindow(XtDisplay(wTop
), window
);
623 // Lower the window to the bottom of the Z order
624 void wxWindow::Lower()
626 Widget wTop
= (Widget
) GetTopWidget();
627 Window window
= XtWindow(wTop
);
628 XLowerWindow(XtDisplay(wTop
), window
);
631 void wxWindow::SetLabel(const wxString
& label
)
633 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
,
634 (const char*)label
.mb_str(), NULL
);
637 wxString
wxWindow::GetLabel() const
640 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &label
, NULL
);
642 return wxString(label
);
645 void wxWindow::DoCaptureMouse()
647 g_captureWindow
= this;
651 Widget wMain
= (Widget
)GetMainWidget();
653 XtAddGrab(wMain
, True
, False
);
655 m_winCaptured
= true;
658 void wxWindow::DoReleaseMouse()
660 g_captureWindow
= NULL
;
661 if ( !m_winCaptured
)
664 Widget wMain
= (Widget
)GetMainWidget();
668 m_winCaptured
= false;
671 bool wxWindow::SetFont(const wxFont
& font
)
673 if ( !wxWindowBase::SetFont(font
) )
684 bool wxWindow::SetCursor(const wxCursor
& cursor
)
686 if ( !wxWindowBase::SetCursor(cursor
) )
692 // wxASSERT_MSG( m_cursor.Ok(),
693 // wxT("cursor must be valid after call to the base version"));
694 const wxCursor
* cursor2
= NULL
;
696 cursor2
= & m_cursor
;
698 cursor2
= wxSTANDARD_CURSOR
;
700 WXDisplay
*dpy
= GetXDisplay();
701 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
703 Widget w
= (Widget
) GetMainWidget();
704 Window win
= XtWindow(w
);
705 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
710 // Coordinates relative to the window
711 void wxWindow::WarpPointer (int x
, int y
)
713 Widget wClient
= (Widget
)GetClientWidget();
715 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
718 // ---------------------------------------------------------------------------
720 // ---------------------------------------------------------------------------
722 int wxWindow::GetScrollPos(int orient
) const
724 if (orient
== wxHORIZONTAL
)
730 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
734 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
742 // This now returns the whole range, not just the number of positions that we
744 int wxWindow::GetScrollRange(int orient
) const
746 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
747 // CE scintilla windows don't always have these scrollbars
748 // and it tends to pile up a whole bunch of asserts
749 //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
753 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
757 int wxWindow::GetScrollThumb(int orient
) const
759 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
760 //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
764 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
768 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
770 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
774 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
777 SetInternalScrollPos((wxOrientation
)orient
, pos
);
780 // New function that will replace some of the above.
781 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
782 int range
, bool WXUNUSED(refresh
))
785 GetSize(& oldW
, & oldH
);
789 if (thumbVisible
== 0)
792 if (thumbVisible
> range
)
793 thumbVisible
= range
;
795 // Save the old state to see if it changed
796 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
798 if (orient
== wxHORIZONTAL
)
800 if (thumbVisible
== range
)
803 DestroyScrollbar(wxHORIZONTAL
);
808 CreateScrollbar(wxHORIZONTAL
);
811 if (orient
== wxVERTICAL
)
813 if (thumbVisible
== range
)
816 DestroyScrollbar(wxVERTICAL
);
821 CreateScrollbar(wxVERTICAL
);
824 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
826 if (oldScrollBar
!= newScrollBar
)
828 // This is important! Without it, scrollbars misbehave badly.
829 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
830 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
831 XtRealizeWidget((Widget
) m_scrolledWindow
);
832 XtManageChild((Widget
) m_scrolledWindow
);
837 XtVaSetValues((Widget
) newScrollBar
,
841 XmNsliderSize
, thumbVisible
,
845 SetInternalScrollPos((wxOrientation
)orient
, pos
);
848 GetSize(& newW
, & newH
);
850 // Adjusting scrollbars can resize the canvas accidentally
851 if (newW
!= oldW
|| newH
!= oldH
)
852 SetSize(wxDefaultCoord
, wxDefaultCoord
, oldW
, oldH
);
855 // Does a physical scroll
856 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
861 // Use specified rectangle
862 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
866 // Use whole client area
868 GetClientSize(& w
, & h
);
871 int x1
= (dx
>= 0) ? x
: x
- dx
;
872 int y1
= (dy
>= 0) ? y
: y
- dy
;
873 int w1
= w
- abs(dx
);
874 int h1
= h
- abs(dy
);
875 int x2
= (dx
>= 0) ? x
+ dx
: x
;
876 int y2
= (dy
>= 0) ? y
+ dy
: y
;
879 wxClientDCImpl
* const
880 dcimpl
= static_cast<wxClientDCImpl
*>(dc
.GetImpl());
881 GC
const gc
= (GC
) dcimpl
->GetGC();
883 dc
.SetLogicalFunction (wxCOPY
);
885 Widget widget
= (Widget
) GetMainWidget();
886 Window window
= XtWindow(widget
);
887 Display
* display
= XtDisplay(widget
);
889 XCopyArea(display
, window
, window
, gc
, x1
, y1
, w1
, h1
, x2
, y2
);
891 dcimpl
->SetAutoSetting(true);
892 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
893 dc
.SetBrush(brush
); // FIXME: needed?
895 wxWindowList::compatibility_iterator cnode
= m_children
.GetFirst();
898 wxWindow
*child
= cnode
->GetData();
901 child
->GetSize( &sx
, &sy
);
902 wxPoint
pos( child
->GetPosition() );
903 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
904 cnode
= cnode
->GetNext();
907 // We'll add rectangles to the list of update rectangles according to which
908 // bits we've exposed.
913 wxRect
*rect
= new wxRect
;
919 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
923 rect
->width
= rect
->width
;
924 rect
->height
= rect
->height
;
926 updateRects
.Append((wxObject
*) rect
);
930 wxRect
*rect
= new wxRect
;
932 rect
->x
= x
+ w
+ dx
;
937 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
941 rect
->width
= rect
->width
;
942 rect
->height
= rect
->height
;
944 updateRects
.Append((wxObject
*) rect
);
948 wxRect
*rect
= new wxRect
;
955 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
959 rect
->width
= rect
->width
;
960 rect
->height
= rect
->height
;
962 updateRects
.Append((wxObject
*) rect
);
966 wxRect
*rect
= new wxRect
;
969 rect
->y
= y
+ h
+ dy
;
973 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
977 rect
->width
= rect
->width
;
978 rect
->height
= rect
->height
;
980 updateRects
.Append((wxObject
*) rect
);
982 dc
.SetBrush(wxNullBrush
);
984 // Now send expose events
986 wxList::compatibility_iterator node
= updateRects
.GetFirst();
989 wxRect
* rect
= (wxRect
*) node
->GetData();
993 event
.display
= display
;
994 event
.send_event
= True
;
995 event
.window
= window
;
999 event
.width
= rect
->width
;
1000 event
.height
= rect
->height
;
1004 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1006 node
= node
->GetNext();
1010 // Delete the update rects
1011 node
= updateRects
.GetFirst();
1014 wxRect
* rect
= (wxRect
*) node
->GetData();
1016 node
= node
->GetNext();
1019 XmUpdateDisplay((Widget
) GetMainWidget());
1022 // ---------------------------------------------------------------------------
1024 // ---------------------------------------------------------------------------
1026 #if wxUSE_DRAG_AND_DROP
1028 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1035 // Old style file-manager drag&drop
1036 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1041 // ----------------------------------------------------------------------------
1043 // ----------------------------------------------------------------------------
1047 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1052 #endif // wxUSE_TOOLTIPS
1054 // ----------------------------------------------------------------------------
1056 // ----------------------------------------------------------------------------
1060 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1062 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1064 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
1065 x
= mouse
.x
; y
= mouse
.y
;
1068 Widget widget
= (Widget
) GetMainWidget();
1070 /* The menuId field seems to be usused, so we'll use it to
1071 indicate whether a menu is popped up or not:
1072 0: Not currently created as a popup
1073 -1: Created as a popup, but not active
1077 if (menu
->GetParent() && (menu
->GetId() != -1))
1080 if (menu
->GetMainWidget())
1082 menu
->DestroyMenu(true);
1085 menu
->SetId(1); /* Mark as popped-up */
1086 menu
->CreateMenu(NULL
, widget
, menu
, 0);
1090 // menu->SetParent(parent);
1091 // parent->children->Append(menu); // Store menu for later deletion
1093 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1101 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1103 wxCanvas *canvas = (wxCanvas *) this;
1104 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1105 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1109 Display
*display
= XtDisplay (widget
);
1110 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1111 Window thisWindow
= XtWindow (widget
);
1113 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1114 &rootX
, &rootY
, &childWindow
);
1116 XButtonPressedEvent event
;
1117 event
.type
= ButtonPress
;
1123 event
.x_root
= rootX
;
1124 event
.y_root
= rootY
;
1126 XmMenuPosition (menuWidget
, &event
);
1127 XtManageChild (menuWidget
);
1129 // The ID of a pop-up menu is 1 when active, and is set to 0 by the
1130 // idle-time destroy routine.
1131 // Waiting until this ID changes causes this function to block until
1132 // the menu has been dismissed and the widgets cleaned up.
1133 // In other words, once this routine returns, it is safe to delete
1135 // Ian Brown <ian.brown@printsoft.de>
1137 wxEventLoop evtLoop
;
1139 while (menu
->GetId() == 1)
1141 wxDoEventLoopIteration( evtLoop
);
1149 // ---------------------------------------------------------------------------
1150 // moving and resizing
1151 // ---------------------------------------------------------------------------
1153 bool wxWindow::PreResize()
1159 void wxWindow::DoGetSize(int *x
, int *y
) const
1161 Widget widget
= (Widget
)( !m_drawingArea
? GetTopWidget() :
1162 ( m_borderWidget
? m_borderWidget
:
1163 m_scrolledWindow
? m_scrolledWindow
:
1168 XtVaGetValues( widget
,
1172 if(x
) *x
= widget
? xx
: -1;
1173 if(y
) *y
= widget
? yy
: -1;
1176 void wxWindow::DoGetPosition(int *x
, int *y
) const
1178 Widget widget
= (Widget
)
1180 ( m_borderWidget
? m_borderWidget
: m_scrolledWindow
) :
1184 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1186 // We may be faking the client origin. So a window that's really at (0, 30)
1187 // may appear (to wxWin apps) to be at (0, 0).
1190 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1191 xx
= (Position
)(xx
- pt
.x
);
1192 yy
= (Position
)(yy
- pt
.y
);
1199 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1201 Widget widget
= (Widget
) GetClientWidget();
1202 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1203 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1204 Window thisWindow
= XtWindow(widget
);
1207 int xx
= x
? *x
: 0;
1208 int yy
= y
? *y
: 0;
1209 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
1210 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
1214 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1216 Widget widget
= (Widget
) GetClientWidget();
1217 Display
*display
= XtDisplay(widget
);
1218 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1219 Window thisWindow
= XtWindow(widget
);
1222 int xx
= x
? *x
: 0;
1223 int yy
= y
? *y
: 0;
1224 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
1225 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
1230 // Get size *available for subwindows* i.e. excluding menu bar etc.
1231 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1233 Widget widget
= (Widget
) GetClientWidget();
1235 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1236 if(x
) *x
= xx
; if(y
) *y
= yy
;
1239 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1241 DoSetSizeIntr(x
, y
, width
, height
, sizeFlags
, false);
1244 void wxWindow::DoSetSizeIntr(int x
, int y
, int width
, int height
,
1245 int sizeFlags
, bool fromCtor
)
1247 // A bit of optimization to help sort out the flickers.
1248 int oldX
= -1, oldY
= -1, oldW
= -1, oldH
= -1;
1252 GetSize(& oldW
, & oldH
);
1253 GetPosition(& oldX
, & oldY
);
1261 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1269 wxSize
size(wxDefaultSize
);
1272 if ( ( sizeFlags
& wxSIZE_AUTO_WIDTH
) && !fromCtor
)
1274 size
= DoGetBestSize();
1285 if( ( sizeFlags
& wxSIZE_AUTO_HEIGHT
) && !fromCtor
)
1287 if( size
.x
== -1 ) size
= DoGetBestSize();
1296 if ( x
!= oldX
|| y
!= oldY
|| width
!= oldW
|| height
!= oldH
1297 || !wxNoOptimize::CanOptimize() )
1310 flags
|= wxMOVE_WIDTH
;
1313 flags
|= wxMOVE_HEIGHT
;
1315 int xx
= x
; int yy
= y
;
1316 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1318 DoMoveWindow( xx
, yy
, width
, height
);
1320 DoMoveWindowIntr( xx
, yy
, width
, height
, flags
);
1325 Widget widget
= (Widget
) GetTopWidget();
1329 bool managed
= XtIsManaged( widget
);
1331 XtUnmanageChild(widget
);
1335 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1337 DoMoveWindow(xx
, yy
, width
, height
);
1340 XtManageChild(widget
);
1344 void wxWindow::DoSetClientSize(int width
, int height
)
1348 Widget drawingArea
= (Widget
) m_drawingArea
;
1350 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1353 XtVaSetValues(drawingArea
, XmNwidth
, width
, NULL
);
1355 XtVaSetValues(drawingArea
, XmNheight
, height
, NULL
);
1357 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1361 Widget widget
= (Widget
) GetTopWidget();
1364 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1366 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1369 void wxWindow::DoMoveWindowIntr(int xx
, int yy
, int w
, int h
,
1374 Widget drawingArea
= (Widget
) m_drawingArea
;
1375 Widget borderOrScrolled
= m_borderWidget
?
1376 (Widget
) m_borderWidget
:
1377 (Widget
) m_scrolledWindow
;
1379 bool managed
= XtIsManaged(borderOrScrolled
);
1381 XtUnmanageChild (borderOrScrolled
);
1382 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1384 if (flags
& wxMOVE_X
)
1385 XtVaSetValues (borderOrScrolled
,
1388 if (flags
& wxMOVE_Y
)
1389 XtVaSetValues (borderOrScrolled
,
1393 if (flags
& wxMOVE_WIDTH
)
1397 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
1398 short thick
, margin
;
1399 XtVaGetValues ((Widget
) m_borderWidget
,
1400 XmNshadowThickness
, &thick
,
1401 XmNmarginWidth
, &margin
,
1403 w
-= 2 * (thick
+ margin
);
1407 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
1410 if (flags
& wxMOVE_HEIGHT
)
1414 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
1415 short thick
, margin
;
1416 XtVaGetValues ((Widget
) m_borderWidget
,
1417 XmNshadowThickness
, &thick
,
1418 XmNmarginHeight
, &margin
,
1420 h
-= 2 * (thick
+ margin
);
1424 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
1428 XtManageChild (borderOrScrolled
);
1429 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1436 XtVaSetValues((Widget
)GetTopWidget(),
1445 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1447 DoMoveWindowIntr (x
, y
, width
, height
,
1448 wxMOVE_X
|wxMOVE_Y
|wxMOVE_WIDTH
|wxMOVE_HEIGHT
);
1451 // ---------------------------------------------------------------------------
1453 // ---------------------------------------------------------------------------
1455 int wxWindow::GetCharHeight() const
1460 wxGetTextExtent (GetXDisplay(), m_font
, 1.0,
1461 "x", NULL
, &height
, NULL
, NULL
);
1463 wxGetTextExtent (this, "x", NULL
, &height
, NULL
, NULL
);
1468 int wxWindow::GetCharWidth() const
1473 wxGetTextExtent (GetXDisplay(), m_font
, 1.0,
1474 "x", &width
, NULL
, NULL
, NULL
);
1476 wxGetTextExtent (this, "x", &width
, NULL
, NULL
, NULL
);
1481 void wxWindow::DoGetTextExtent(const wxString
& string
,
1484 int *externalLeading
,
1485 const wxFont
*theFont
) const
1487 const wxFont
*fontToUse
= theFont
? theFont
: &m_font
;
1489 if (externalLeading
)
1490 *externalLeading
= 0;
1491 if (fontToUse
->Ok())
1492 wxGetTextExtent (GetXDisplay(), *fontToUse
, 1.0,
1493 string
, x
, y
, NULL
, descent
);
1495 wxGetTextExtent (this, string
, x
, y
, NULL
, descent
);
1498 // ----------------------------------------------------------------------------
1500 // ----------------------------------------------------------------------------
1502 void wxWindow::AddUpdateRect(int x
, int y
, int w
, int h
)
1504 m_updateRegion
.Union( x
, y
, w
, h
);
1507 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1509 Widget widget
= (Widget
) GetMainWidget();
1512 m_needsRefresh
= true;
1513 Display
*display
= XtDisplay(widget
);
1514 Window thisWindow
= XtWindow(widget
);
1516 XExposeEvent dummyEvent
;
1518 GetSize(&width
, &height
);
1520 dummyEvent
.type
= Expose
;
1521 dummyEvent
.display
= display
;
1522 dummyEvent
.send_event
= True
;
1523 dummyEvent
.window
= thisWindow
;
1526 dummyEvent
.x
= rect
->x
;
1527 dummyEvent
.y
= rect
->y
;
1528 dummyEvent
.width
= rect
->width
;
1529 dummyEvent
.height
= rect
->height
;
1535 dummyEvent
.width
= width
;
1536 dummyEvent
.height
= height
;
1538 dummyEvent
.count
= 0;
1542 wxClientDC
dc(this);
1543 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1544 dc
.SetBackground(backgroundBrush
);
1546 wxClientDCImpl
* const
1547 dcimpl
= static_cast<wxClientDCImpl
*>(dc
.GetImpl());
1549 dcimpl
->Clear(*rect
);
1554 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1557 void wxWindow::DoPaint()
1559 //TODO : make a temporary gc so we can do the XCopyArea below
1560 if (m_backingPixmap
&& !m_needsRefresh
)
1564 wxPaintDCImpl
* const
1565 dcimpl
= static_cast<wxPaintDCImpl
*>(dc
.GetImpl());
1567 GC tempGC
= (GC
) dcimpl
->GetBackingGC();
1569 Widget widget
= (Widget
) GetMainWidget();
1574 // We have to test whether it's a wxScrolledWindow (hack!) because
1575 // otherwise we don't know how many pixels have been scrolled. We might
1576 // solve this in the future by defining virtual wxWindow functions to get
1577 // the scroll position in pixels. Or, each kind of scrolled window has to
1578 // implement backing stores itself, using generic wxWidgets code.
1579 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1580 if ( scrolledWindow
)
1583 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1589 // TODO: This could be optimized further by only copying the areas in the
1590 // current update region.
1592 // Only blit the part visible in the client area. The backing pixmap
1593 // always starts at 0, 0 but we may be looking at only a portion of it.
1594 wxSize clientArea
= GetClientSize();
1595 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1596 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1598 // Copy whichever is samller, the amount of pixmap we have to copy,
1599 // or the size of the client area.
1600 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1601 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1603 // Make sure we're not negative
1604 toBlitX
= wxMax(0, toBlitX
);
1605 toBlitY
= wxMax(0, toBlitY
);
1610 (Pixmap
) m_backingPixmap
,
1613 scrollPosX
, scrollPosY
, // Start at the scroll position
1614 toBlitX
, toBlitY
, // How much of the pixmap to copy
1620 wxWindowDC
dc(this);
1621 // Set an erase event first
1622 wxEraseEvent
eraseEvent(GetId(), &dc
);
1623 eraseEvent
.SetEventObject(this);
1624 HandleWindowEvent(eraseEvent
);
1626 wxPaintEvent
event(GetId());
1627 event
.SetEventObject(this);
1628 HandleWindowEvent(event
);
1630 m_needsRefresh
= false;
1634 // ----------------------------------------------------------------------------
1636 // ----------------------------------------------------------------------------
1638 // Responds to colour changes: passes event on to children.
1639 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1641 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1644 // Only propagate to non-top-level windows
1645 wxWindow
*win
= node
->GetData();
1646 if ( win
->GetParent() )
1648 wxSysColourChangedEvent event2
;
1649 event
.SetEventObject(win
);
1650 win
->HandleWindowEvent(event2
);
1653 node
= node
->GetNext();
1657 void wxWindow::OnInternalIdle()
1659 // This calls the UI-update mechanism (querying windows for
1660 // menu/toolbar/control state information)
1661 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1662 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1665 // ----------------------------------------------------------------------------
1667 // ----------------------------------------------------------------------------
1669 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1672 if (!m_acceleratorTable
.Ok())
1675 int count
= m_acceleratorTable
.GetCount();
1676 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1678 for (i
= 0; i
< count
; i
++)
1680 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1681 if (entry
->MatchesEvent(event
))
1683 // Bingo, we have a match. Now find a control that matches the
1684 // entry command id.
1686 // Need to go up to the top of the window hierarchy, since it might
1687 // be e.g. a menu item
1688 wxWindow
* parent
= this;
1689 while ( parent
&& !parent
->IsTopLevel() )
1690 parent
= parent
->GetParent();
1695 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1699 // Try for a menu command
1700 if (frame
->GetMenuBar())
1702 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1705 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1706 commandEvent
.SetEventObject(frame
);
1708 // If ProcessEvent returns true (it was handled), then
1709 // the calling code will skip the event handling.
1710 return frame
->HandleWindowEvent(commandEvent
);
1716 // Find a child matching the command id
1717 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1723 // Now we process those kinds of windows that we can.
1724 // For now, only buttons.
1725 if ( wxDynamicCast(child
, wxButton
) )
1727 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1728 commandEvent
.SetEventObject(child
);
1729 return child
->HandleWindowEvent(commandEvent
);
1737 // We didn't match the key event against an accelerator.
1741 // ============================================================================
1742 // Motif-specific stuff from here on
1743 // ============================================================================
1745 // ----------------------------------------------------------------------------
1746 // function which maintain the global hash table mapping Widgets to wxWidgets
1747 // ----------------------------------------------------------------------------
1749 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1751 const long key
= (long)w
;
1752 if ( wxWidgetHashTable
->Get(key
))
1754 wxLogDebug("Widget table clash: new widget is %ld, %s",
1755 key
, win
->GetClassInfo()->GetClassName());
1759 wxWidgetHashTable
->Put(key
, win
);
1761 wxLogTrace("widget", "Widget 0x%p <-> window %p (%s)",
1762 w
, win
, win
->GetClassInfo()->GetClassName());
1767 wxWindow
*wxGetWindowFromTable(Widget w
)
1769 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1772 void wxDeleteWindowFromTable(Widget w
)
1774 wxLogTrace("widget", "Widget 0x%p", (WXWidget
)w
);
1776 wxWidgetHashTable
->Delete((long)w
);
1779 // ----------------------------------------------------------------------------
1780 // add/remove window from the table
1781 // ----------------------------------------------------------------------------
1783 // Add to hash table, add event handler
1784 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1785 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1787 wxAddWindowToTable((Widget
) mainWidget
, this);
1788 XtAddEventHandler( (Widget
) mainWidget
,
1789 ButtonPressMask
| ButtonReleaseMask
1790 | PointerMotionMask
,
1792 wxPanelItemEventHandler
,
1798 XtOverrideTranslations ((Widget
) mainWidget
,
1799 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1800 XtFree ((char *) ptr
);
1803 // Some widgets have a parent form widget, e.g. wxRadioBox
1806 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1810 XtOverrideTranslations ((Widget
) formWidget
,
1811 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1812 XtFree ((char *) ptr
);
1819 DoSetSize (x
, y
, width
, height
, wxSIZE_USE_EXISTING
);
1824 // Remove event handler, remove from hash table
1825 bool wxWindow::DetachWidget(WXWidget widget
)
1827 XtRemoveEventHandler( (Widget
) widget
,
1828 ButtonPressMask
| ButtonReleaseMask
1829 | PointerMotionMask
,
1831 wxPanelItemEventHandler
,
1834 wxDeleteWindowFromTable((Widget
) widget
);
1838 // ----------------------------------------------------------------------------
1839 // Motif-specific accessors
1840 // ----------------------------------------------------------------------------
1842 WXWindow
wxWindow::GetClientXWindow() const
1844 Widget wMain
= (Widget
)GetClientWidget();
1846 return (WXWindow
) XtWindow(wMain
);
1848 return (WXWindow
) 0;
1851 // Get the underlying X window
1852 WXWindow
wxWindow::GetXWindow() const
1854 Widget wMain
= (Widget
)GetMainWidget();
1856 return (WXWindow
) XtWindow(wMain
);
1858 return (WXWindow
) 0;
1861 // Get the underlying X display
1862 WXDisplay
*wxWindow::GetXDisplay() const
1864 Widget wMain
= (Widget
)GetMainWidget();
1866 return (WXDisplay
*) XtDisplay(wMain
);
1871 WXWidget
wxWindow::GetMainWidget() const
1874 return m_drawingArea
;
1876 return m_mainWidget
;
1879 WXWidget
wxWindow::GetClientWidget() const
1881 if (m_drawingArea
!= (WXWidget
) 0)
1882 return m_drawingArea
;
1884 return GetMainWidget();
1887 WXWidget
wxWindow::GetTopWidget() const
1889 return GetMainWidget();
1892 WXWidget
wxWindow::GetLabelWidget() const
1894 return GetMainWidget();
1897 // ----------------------------------------------------------------------------
1899 // ----------------------------------------------------------------------------
1901 // All widgets should have this as their resize proc.
1902 // OnSize sent to wxWindow via client data.
1903 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
),
1904 String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1906 wxWindow
*win
= wxGetWindowFromTable(w
);
1910 if (win
->PreResize())
1912 wxSize
newSize(win
->GetSize());
1913 wxSizeEvent
sizeEvent(newSize
, win
->GetId());
1914 sizeEvent
.SetEventObject(win
);
1915 win
->HandleWindowEvent(sizeEvent
);
1919 static void wxCanvasRepaintProc(Widget drawingArea
,
1920 XtPointer clientData
,
1921 XmDrawingAreaCallbackStruct
* cbs
)
1923 if (!wxGetWindowFromTable(drawingArea
))
1926 XEvent
* event
= cbs
->event
;
1927 wxWindow
* win
= (wxWindow
*) clientData
;
1929 switch (event
->type
)
1933 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1934 event
->xexpose
.width
, event
->xexpose
.height
);
1936 if (event
-> xexpose
.count
== 0)
1945 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1946 static void wxCanvasEnterLeave(Widget drawingArea
,
1947 XtPointer
WXUNUSED(clientData
),
1948 XCrossingEvent
* event
)
1950 XmDrawingAreaCallbackStruct cbs
;
1953 ((XCrossingEvent
&) ev
) = *event
;
1955 cbs
.reason
= XmCR_INPUT
;
1958 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1961 // Fix to make it work under Motif 1.0 (!)
1962 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
),
1963 XButtonEvent
*WXUNUSED(event
))
1965 #if XmVersion <= 1000
1966 XmDrawingAreaCallbackStruct cbs
;
1969 ev
= *((XEvent
*) event
);
1970 cbs
.reason
= XmCR_INPUT
;
1973 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1974 #endif // XmVersion <= 1000
1977 static void wxCanvasInputEvent(Widget drawingArea
,
1978 XtPointer
WXUNUSED(data
),
1979 XmDrawingAreaCallbackStruct
* cbs
)
1981 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1982 XEvent
* xevent
= cbs
->event
;
1987 if (cbs
->reason
!= XmCR_INPUT
)
1990 switch (xevent
->xany
.type
)
1998 wxMouseEvent
wxevent(0);
1999 if (wxTranslateMouseEvent(wxevent
, canvas
, drawingArea
, xevent
))
2001 canvas
->HandleWindowEvent(wxevent
);
2007 wxKeyEvent
event (wxEVT_CHAR
);
2008 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, xevent
))
2010 // Implement wxFrame::OnCharHook by checking ancestor.
2011 wxWindow
*parent
= canvas
;
2012 while (parent
&& !parent
->IsTopLevel())
2013 parent
= parent
->GetParent();
2017 event
.SetEventType(wxEVT_CHAR_HOOK
);
2018 if (parent
->HandleWindowEvent(event
))
2022 // For simplicity, OnKeyDown is the same as OnChar
2023 // TODO: filter modifier key presses from OnChar
2024 event
.SetEventType(wxEVT_KEY_DOWN
);
2026 // Only process OnChar if OnKeyDown didn't swallow it
2027 if (!canvas
->HandleWindowEvent (event
))
2029 event
.SetEventType(wxEVT_CHAR
);
2030 canvas
->HandleWindowEvent (event
);
2037 wxKeyEvent
event (wxEVT_KEY_UP
);
2038 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, xevent
))
2040 canvas
->HandleWindowEvent (event
);
2046 if (xevent
->xfocus
.detail
!= NotifyPointer
)
2048 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2049 event
.SetEventObject(canvas
);
2050 canvas
->HandleWindowEvent(event
);
2056 if (xevent
->xfocus
.detail
!= NotifyPointer
)
2058 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2059 event
.SetEventObject(canvas
);
2060 canvas
->HandleWindowEvent(event
);
2069 static void wxPanelItemEventHandler(Widget wid
,
2070 XtPointer
WXUNUSED(client_data
),
2072 Boolean
*continueToDispatch
)
2074 // Widget can be a label or the actual widget.
2076 wxWindow
*window
= wxGetWindowFromTable(wid
);
2079 wxMouseEvent
wxevent(0);
2080 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2082 window
->HandleWindowEvent(wxevent
);
2086 // TODO: probably the key to allowing default behaviour to happen. Say we
2087 // set a m_doDefault flag to false at the start of this function. Then in
2088 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2089 // true, indicating that default processing can happen. Thus, behaviour can
2090 // appear to be overridden just by adding an event handler and not calling
2091 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2092 // way of handling drawing area events, to simplify things.
2093 *continueToDispatch
= True
;
2096 static void wxScrollBarCallback(Widget scrollbar
,
2097 XtPointer clientData
,
2098 XmScrollBarCallbackStruct
*cbs
)
2100 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2101 wxCHECK_RET( win
, wxT("invalid widget in scrollbar callback") );
2103 wxOrientation orientation
= (wxOrientation
)wxPtrToUInt(clientData
);
2105 wxEventType eventType
= wxEVT_NULL
;
2106 switch (cbs
->reason
)
2108 case XmCR_INCREMENT
:
2110 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2113 case XmCR_DECREMENT
:
2115 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2120 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2123 case XmCR_VALUE_CHANGED
:
2125 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2128 case XmCR_PAGE_INCREMENT
:
2130 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2133 case XmCR_PAGE_DECREMENT
:
2135 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2140 eventType
= wxEVT_SCROLLWIN_TOP
;
2143 case XmCR_TO_BOTTOM
:
2145 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2150 // Should never get here
2151 wxFAIL_MSG("Unknown scroll event.");
2156 wxScrollWinEvent
event(eventType
,
2159 event
.SetEventObject( win
);
2160 win
->HandleWindowEvent(event
);
2163 // For repainting arbitrary windows
2164 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2166 wxWindow
* win
= wxGetWindowFromTable(w
);
2170 switch ( event
->type
)
2174 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2175 event
->xexpose
.width
, event
->xexpose
.height
);
2177 if ( event
->xexpose
.count
== 0 )
2187 // ----------------------------------------------------------------------------
2188 // TranslateXXXEvent() functions
2189 // ----------------------------------------------------------------------------
2191 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
,
2192 Widget widget
, const XEvent
*xevent
)
2194 switch (xevent
->xany
.type
)
2199 fprintf(stderr
, "Widget 0x%p <-> window %p (%s), %s\n",
2200 (WXWidget
)widget
, win
, win
->GetClassInfo()->GetClassName(),
2201 (xevent
->xany
.type
== EnterNotify
? "ENTER" : "LEAVE"));
2207 int eventx
= xevent
->xbutton
.x
, eventy
= xevent
->xbutton
.y
;
2209 wxEventType eventType
= wxEVT_NULL
;
2211 if (xevent
->xany
.type
== LeaveNotify
)
2213 eventType
= wxEVT_LEAVE_WINDOW
;
2215 if (xevent
->xany
.type
== EnterNotify
)
2217 eventType
= wxEVT_ENTER_WINDOW
;
2219 else if (xevent
->xany
.type
== MotionNotify
)
2221 eventType
= wxEVT_MOTION
;
2223 if (xevent
->xmotion
.is_hint
== NotifyHint
)
2228 Display
*dpy
= XtDisplay (widget
);
2230 XQueryPointer (dpy
, XtWindow (widget
),
2232 &x_root
, &y_root
, &eventx
, &eventy
, &state
);
2235 else if (xevent
->xany
.type
== ButtonPress
)
2237 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2239 if (xevent
->xbutton
.button
== Button1
)
2241 eventType
= wxEVT_LEFT_DOWN
;
2244 else if (xevent
->xbutton
.button
== Button2
)
2246 eventType
= wxEVT_MIDDLE_DOWN
;
2249 else if (xevent
->xbutton
.button
== Button3
)
2251 eventType
= wxEVT_RIGHT_DOWN
;
2255 // check for a double click
2257 long dclickTime
= XtGetMultiClickTime(xevent
->xany
.display
);
2258 long ts
= wxevent
.GetTimestamp();
2260 int buttonLast
= win
->GetLastClickedButton();
2261 long lastTS
= win
->GetLastClickTime();
2262 if ( buttonLast
&& buttonLast
== button
&&
2263 (ts
- lastTS
) < dclickTime
)
2266 win
->SetLastClick(0, ts
);
2267 if ( eventType
== wxEVT_LEFT_DOWN
)
2268 eventType
= wxEVT_LEFT_DCLICK
;
2269 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2270 eventType
= wxEVT_MIDDLE_DCLICK
;
2271 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2272 eventType
= wxEVT_RIGHT_DCLICK
;
2276 // not fast enough or different button
2277 win
->SetLastClick(button
, ts
);
2280 else if (xevent
->xany
.type
== ButtonRelease
)
2282 if (xevent
->xbutton
.button
== Button1
)
2284 eventType
= wxEVT_LEFT_UP
;
2286 else if (xevent
->xbutton
.button
== Button2
)
2288 eventType
= wxEVT_MIDDLE_UP
;
2290 else if (xevent
->xbutton
.button
== Button3
)
2292 eventType
= wxEVT_RIGHT_UP
;
2302 wxevent
.SetEventType(eventType
);
2305 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2308 win
->GetPosition(&x2
, &y2
);
2310 // The button x/y must be translated to wxWidgets
2311 // window space - the widget might be a label or button,
2315 if (widget
!= (Widget
)win
->GetMainWidget())
2321 wxevent
.m_x
= eventx
+ dx
;
2322 wxevent
.m_y
= eventy
+ dy
;
2324 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2325 || (event_left_is_down (xevent
)
2326 && (eventType
!= wxEVT_LEFT_UP
)));
2327 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2328 || (event_middle_is_down (xevent
)
2329 && (eventType
!= wxEVT_MIDDLE_UP
)));
2330 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2331 || (event_right_is_down (xevent
)
2332 && (eventType
!= wxEVT_RIGHT_UP
)));
2334 wxevent
.m_shiftDown
= (xevent
->xbutton
.state
& ShiftMask
) == ShiftMask
;
2335 wxevent
.m_controlDown
= (xevent
->xbutton
.state
& ControlMask
) == ControlMask
;
2336 wxevent
.m_altDown
= (xevent
->xbutton
.state
& Mod3Mask
) == Mod3Mask
;
2337 wxevent
.m_metaDown
= (xevent
->xbutton
.state
& Mod1Mask
) == Mod1Mask
;
2339 wxevent
.SetId(win
->GetId());
2340 wxevent
.SetEventObject(win
);
2348 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
,
2349 Widget
WXUNUSED(widget
), const XEvent
*xevent
)
2351 switch (xevent
->xany
.type
)
2359 (void) XLookupString((XKeyEvent
*)xevent
, buf
, 20, &keySym
, NULL
);
2360 int id
= wxCharCodeXToWX (keySym
);
2361 // id may be WXK_xxx code - these are outside ASCII range, so we
2362 // can't just use toupper() on id
2363 if (id
>= 'a' && id
<= 'z')
2366 if (xevent
->xkey
.state
& ShiftMask
)
2367 wxevent
.m_shiftDown
= true;
2368 if (xevent
->xkey
.state
& ControlMask
)
2369 wxevent
.m_controlDown
= true;
2370 if (xevent
->xkey
.state
& Mod3Mask
)
2371 wxevent
.m_altDown
= true;
2372 if (xevent
->xkey
.state
& Mod1Mask
)
2373 wxevent
.m_metaDown
= true;
2374 wxevent
.SetEventObject(win
);
2375 wxevent
.m_keyCode
= id
;
2376 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2378 wxevent
.m_x
= xevent
->xbutton
.x
;
2379 wxevent
.m_y
= xevent
->xbutton
.y
;
2392 // ----------------------------------------------------------------------------
2394 // ----------------------------------------------------------------------------
2396 #define YAllocColor XAllocColor
2397 XColor g_itemColors
[5];
2398 int wxComputeColours (Display
*display
, const wxColour
* back
, const wxColour
* fore
)
2401 static XmColorProc colorProc
;
2403 result
= wxNO_COLORS
;
2407 g_itemColors
[0].red
= (unsigned short)(((long) back
->Red ()) << 8);
2408 g_itemColors
[0].green
= (unsigned short)(((long) back
->Green ()) << 8);
2409 g_itemColors
[0].blue
= (unsigned short)(((long) back
->Blue ()) << 8);
2410 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2411 if (colorProc
== (XmColorProc
) NULL
)
2413 // Get a ptr to the actual function
2414 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2415 // And set it back to motif.
2416 XmSetColorCalculation (colorProc
);
2418 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2419 &g_itemColors
[wxFORE_INDEX
],
2420 &g_itemColors
[wxSELE_INDEX
],
2421 &g_itemColors
[wxTOPS_INDEX
],
2422 &g_itemColors
[wxBOTS_INDEX
]);
2423 result
= wxBACK_COLORS
;
2427 g_itemColors
[wxFORE_INDEX
].red
= (unsigned short)(((long) fore
->Red ()) << 8);
2428 g_itemColors
[wxFORE_INDEX
].green
= (unsigned short)(((long) fore
->Green ()) << 8);
2429 g_itemColors
[wxFORE_INDEX
].blue
= (unsigned short)(((long) fore
->Blue ()) << 8);
2430 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2431 if (result
== wxNO_COLORS
)
2432 result
= wxFORE_COLORS
;
2435 Display
*dpy
= display
;
2436 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2440 /* 5 Colours to allocate */
2441 for (int i
= 0; i
< 5; i
++)
2442 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2443 result
= wxNO_COLORS
;
2447 /* Only 1 colour to allocate */
2448 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2449 result
= wxNO_COLORS
;
2455 // Changes the foreground and background colours to be derived from the current
2456 // background colour. To change the foreground colour, you must call
2457 // SetForegroundColour explicitly.
2458 void wxWindow::ChangeBackgroundColour()
2460 WXWidget mainWidget
= GetMainWidget();
2462 wxDoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2463 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2464 wxDoChangeForegroundColour(m_scrolledWindow
, m_backgroundColour
);
2467 void wxWindow::ChangeForegroundColour()
2469 WXWidget mainWidget
= GetMainWidget();
2471 wxDoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2472 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2473 wxDoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2476 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2478 if ( !wxWindowBase::SetBackgroundColour(col
) )
2481 ChangeBackgroundColour();
2486 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2488 if ( !wxWindowBase::SetForegroundColour(col
) )
2491 ChangeForegroundColour();
2496 void wxWindow::ChangeFont(bool keepOriginalSize
)
2498 // Note that this causes the widget to be resized back
2499 // to its original size! We therefore have to set the size
2500 // back again. TODO: a better way in Motif?
2501 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2502 if (w
&& m_font
.Ok())
2504 int width
, height
, width1
, height1
;
2505 GetSize(& width
, & height
);
2507 wxDoChangeFont( w
, m_font
);
2509 GetSize(& width1
, & height1
);
2510 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2512 SetSize(wxDefaultCoord
, wxDefaultCoord
, width
, height
);
2518 void wxWindow::PostCreation()
2521 ChangeForegroundColour();
2522 ChangeBackgroundColour();
2526 void wxWindow::PreCreation()
2528 InheritAttributes();
2531 // ----------------------------------------------------------------------------
2533 // ----------------------------------------------------------------------------
2535 wxWindow
*wxGetActiveWindow()
2538 wxFAIL_MSG("Not implemented");
2543 wxWindow
*wxWindowBase::GetCapture()
2545 return (wxWindow
*)g_captureWindow
;
2549 // Find the wxWindow at the current mouse position, returning the mouse
2551 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2553 pt
= wxGetMousePosition();
2554 return wxFindWindowAtPoint(pt
);
2557 void wxGetMouseState(int& rootX
, int& rootY
, unsigned& maskReturn
)
2559 Display
*display
= wxGlobalDisplay();
2560 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2561 Window rootReturn
, childReturn
;
2564 XQueryPointer (display
,
2568 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
2571 // Get the current mouse position.
2572 wxPoint
wxGetMousePosition()
2577 wxGetMouseState(x
, y
, mask
);
2578 return wxPoint(x
, y
);
2581 wxMouseState
wxGetMouseState()
2587 wxGetMouseState(x
, y
, mask
);
2592 ms
.SetLeftDown(mask
& Button1Mask
);
2593 ms
.SetMiddleDown(mask
& Button2Mask
);
2594 ms
.SetRightDown(mask
& Button3Mask
);
2596 ms
.SetControlDown(mask
& ControlMask
);
2597 ms
.SetShiftDown(mask
& ShiftMask
);
2598 ms
.SetAltDown(mask
& Mod3Mask
);
2599 ms
.SetMetaDown(mask
& Mod1Mask
);
2605 #if wxMOTIF_NEW_FONT_HANDLING
2609 void wxGetTextExtent(const wxWindow
* window
, const wxString
& str
,
2610 int* width
, int* height
, int* ascent
, int* descent
)
2614 XmRendition rendition
= NULL
;
2615 XmRenderTable table
= NULL
;
2616 Widget w
= (Widget
) window
->GetLabelWidget();
2618 XtVaGetValues( w
, XmNrenderTable
, &table
, NULL
);
2620 table
= XmeGetDefaultRenderTable(w
, XmTEXT_RENDER_TABLE
);
2622 rendition
= XmRenderTableGetRendition( table
, "" );
2623 XtSetArg( args
[count
], XmNfont
, 0 ); ++count
;
2624 XtSetArg( args
[count
], XmNfontType
, 0 ); ++count
;
2625 XmRenditionRetrieve( rendition
, args
, count
);
2627 if (args
[1].value
== XmFONT_IS_FONTSET
)
2629 XRectangle ink
, logical
;
2630 WXFontSet fset
= (WXFontSet
) args
[0].value
;
2632 XmbTextExtents( (XFontSet
)fset
, str
.c_str(), str
.length(),
2635 if( width
) *width
= logical
.width
;
2636 if( height
) *height
= logical
.height
;
2637 if( ascent
) *ascent
= -logical
.y
;
2638 if( descent
) *descent
= logical
.height
+ logical
.y
;
2642 int direction
, ascent2
, descent2
;
2643 XCharStruct overall
;
2644 XFontStruct
* fontStruct
;
2646 XmeRenderTableGetDefaultFont( table
, &fontStruct
);
2647 XTextExtents(fontStruct
, (const char*)str
.c_str(), str
.length(),
2648 &direction
, &ascent2
, &descent2
, &overall
);
2650 if ( width
) *width
= overall
.width
;
2651 if ( height
) *height
= ascent2
+ descent2
;
2652 if ( descent
) *descent
= descent2
;
2653 if ( ascent
) *ascent
= ascent2
;
2657 #else // if !wxMOTIF_NEW_FONT_HANDLING
2659 void wxGetTextExtent(const wxWindow
* window
, const wxString
& str
,
2660 int* width
, int* height
, int* ascent
, int* descent
)
2662 XmFontList list
= NULL
;
2665 Widget w
= (Widget
) window
->GetLabelWidget();
2667 XtVaGetValues( w
, XmNfontList
, &list
, NULL
);
2668 XmFontListInitFontContext( &cxt
, list
);
2670 XmFontListEntry entry
= XmFontListNextEntry( cxt
);
2671 XmFontListFreeFontContext( cxt
);
2672 XtPointer thing
= XmFontListEntryGetFont( entry
, &type
);
2674 if (type
== XmFONT_IS_FONTSET
)
2676 XRectangle ink
, logical
;
2678 XmbTextExtents( (XFontSet
)thing
, str
.c_str(), str
.length(),
2681 if( width
) *width
= logical
.width
;
2682 if( height
) *height
= logical
.height
;
2683 if( ascent
) *ascent
= -logical
.y
;
2684 if( descent
) *descent
= logical
.height
+ logical
.y
;
2688 int direction
, ascent2
, descent2
;
2689 XCharStruct overall
;
2691 XTextExtents( (XFontStruct
*)thing
, (char*)(const char*)str
.c_str(), str
.length(),
2692 &direction
, &ascent2
, &descent2
, &overall
);
2694 if ( width
) *width
= overall
.width
;
2695 if ( height
) *height
= ascent2
+ descent2
;
2696 if ( descent
) *descent
= descent2
;
2697 if ( ascent
) *ascent
= ascent2
;
2701 #endif // !wxMOTIF_NEW_FONT_HANDLING
2703 // ----------------------------------------------------------------------------
2704 // wxNoOptimize: switch off size optimization
2705 // ----------------------------------------------------------------------------
2707 int wxNoOptimize::ms_count
= 0;