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 wxCHECK_MSG( parent
, false, "can't create wxWindow without parent" );
235 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
237 parent
->AddChild(this);
240 //// TODO: we should probably optimize by only creating a
241 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
242 //// But for now, let's simplify things by always creating the
243 //// drawing area, since otherwise the translations are different.
245 // New translations for getting mouse motion feedback
246 static const String translations
= wxMOTIF_STR(
247 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
248 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
249 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
250 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
251 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
252 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
253 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
254 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
255 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
256 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
257 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
258 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
259 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
260 <Key>: DrawingAreaInput()");
262 XtActionsRec actions
[1];
263 actions
[0].string
= wxMOTIF_STR("wxCanvasMotionEvent");
264 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
265 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
267 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
268 m_borderWidget
= wxCreateBorderWidget( (WXWidget
)parentWidget
, style
);
270 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
273 xmScrolledWindowWidgetClass
,
274 m_borderWidget
? (Widget
) m_borderWidget
276 XmNresizePolicy
, XmRESIZE_NONE
,
278 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
279 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
283 XtTranslations ptr
= XtParseTranslationTable(translations
);
284 m_drawingArea
= (WXWidget
)XtVaCreateWidget
287 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
288 XmNunitType
, XmPIXELS
,
289 // XmNresizePolicy, XmRESIZE_ANY,
290 XmNresizePolicy
, XmRESIZE_NONE
,
293 XmNtranslations
, ptr
,
296 XtFree((char *) ptr
);
299 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
301 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
302 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
303 XtFree ((char *) ptr
);
307 wxAddWindowToTable((Widget
) m_drawingArea
, this);
308 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
310 // This order is very important in Motif 1.2.1
311 XtRealizeWidget ((Widget
) m_scrolledWindow
);
312 XtRealizeWidget ((Widget
) m_drawingArea
);
313 XtManageChild ((Widget
) m_drawingArea
);
315 ptr
= XtParseTranslationTable("<Configure>: resize()");
316 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
317 XtFree ((char *) ptr
);
319 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
320 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
323 (Widget
)m_drawingArea
,
324 PointerMotionHintMask
| EnterWindowMask
|
325 LeaveWindowMask
| FocusChangeMask
,
327 (XtEventHandler
) wxCanvasEnterLeave
,
331 XmScrolledWindowSetAreas(
332 (Widget
)m_scrolledWindow
,
333 (Widget
) 0, (Widget
) 0,
334 (Widget
) m_drawingArea
);
338 // Without this, the cursor may not be restored properly (e.g. in splitter
340 SetCursor(*wxSTANDARD_CURSOR
);
341 DoSetSizeIntr(pos
.x
, pos
.y
, size
.x
,size
.y
, wxSIZE_AUTO
, true);
346 wxWindow::~wxWindow()
348 if (g_captureWindow
== this)
349 g_captureWindow
= NULL
;
351 m_isBeingDeleted
= true;
353 // Motif-specific actions first
354 WXWidget wMain
= GetMainWidget();
357 // Removes event handlers
361 // If m_drawingArea, we're a fully-fledged window with drawing area,
362 // scrollbars etc. (what wxCanvas used to be)
365 // Destroy children before destroying self
369 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
371 Widget w
= (Widget
) m_drawingArea
;
372 wxDeleteWindowFromTable(w
);
377 m_drawingArea
= (WXWidget
) 0;
380 // Only if we're _really_ a canvas (not a dialog box/panel)
381 if (m_scrolledWindow
)
383 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
388 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
389 XtUnmanageChild((Widget
) m_hScrollBar
);
393 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
394 XtUnmanageChild((Widget
) m_vScrollBar
);
398 XtDestroyWidget((Widget
) m_hScrollBar
);
400 XtDestroyWidget((Widget
) m_vScrollBar
);
402 UnmanageAndDestroy(m_scrolledWindow
);
406 XtDestroyWidget ((Widget
) m_borderWidget
);
407 m_borderWidget
= (WXWidget
) 0;
410 else // Why wasn't this here before? JACS 8/3/2000
414 // Destroy the window
417 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
418 // Child widgets will get destroyed automatically when a frame
419 // or dialog is destroyed, but before that you may get some memory
420 // leaks and potential layout problems if you delete and then add
423 // GRG, Feb/2000: commented this out when adding support for
424 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
425 // that this call crashed wxMotif under OS/2, so it seems
426 // that leaving it out is the right thing to do.
427 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
428 XtDestroyWidget((Widget
) GetMainWidget());
429 SetMainWidget((WXWidget
) NULL
);
433 // ----------------------------------------------------------------------------
434 // scrollbar management
435 // ----------------------------------------------------------------------------
437 WXWidget
wxWindow::DoCreateScrollBar(WXWidget parent
,
438 wxOrientation orientation
,
441 int orient
= ( orientation
& wxHORIZONTAL
) ? XmHORIZONTAL
: XmVERTICAL
;
443 XtVaCreateManagedWidget( "scrollBarWidget",
444 xmScrollBarWidgetClass
, (Widget
)parent
,
445 XmNorientation
, orient
,
450 XtPointer o
= (XtPointer
)orientation
;
451 XtCallbackProc cb
= (XtCallbackProc
)callback
;
453 XtAddCallback( sb
, XmNvalueChangedCallback
, cb
, o
);
454 XtAddCallback( sb
, XmNdragCallback
, cb
, o
);
455 XtAddCallback( sb
, XmNincrementCallback
, cb
, o
);
456 XtAddCallback( sb
, XmNdecrementCallback
, cb
, o
);
457 XtAddCallback( sb
, XmNpageIncrementCallback
, cb
, o
);
458 XtAddCallback( sb
, XmNpageDecrementCallback
, cb
, o
);
459 XtAddCallback( sb
, XmNtoTopCallback
, cb
, o
);
460 XtAddCallback( sb
, XmNtoBottomCallback
, cb
, o
);
466 void wxWindow::CreateScrollbar(wxOrientation orientation
)
468 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
470 XtVaSetValues( (Widget
) m_scrolledWindow
,
471 XmNresizePolicy
, XmRESIZE_NONE
,
474 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
475 // Add scrollbars if required
476 if (orientation
== wxHORIZONTAL
)
478 m_hScrollBar
= DoCreateScrollBar( m_scrolledWindow
, wxHORIZONTAL
,
479 (void (*)())wxScrollBarCallback
);
481 wxDoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, true);
483 XtRealizeWidget( (Widget
)m_hScrollBar
);
485 XtVaSetValues((Widget
) m_scrolledWindow
,
486 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
489 wxAddWindowToTable( (Widget
)m_hScrollBar
, this );
491 else if (orientation
== wxVERTICAL
)
493 m_vScrollBar
= DoCreateScrollBar( m_scrolledWindow
, wxVERTICAL
,
494 (void (*)())wxScrollBarCallback
);
496 wxDoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, true);
498 XtRealizeWidget((Widget
)m_vScrollBar
);
500 XtVaSetValues((Widget
) m_scrolledWindow
,
501 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
504 wxAddWindowToTable( (Widget
)m_vScrollBar
, this );
507 XtVaSetValues( (Widget
) m_scrolledWindow
,
508 XmNresizePolicy
, XmRESIZE_ANY
,
512 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
514 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
516 XtVaSetValues((Widget
) m_scrolledWindow
,
517 XmNresizePolicy
, XmRESIZE_NONE
,
519 String stringSB
= orientation
== wxHORIZONTAL
?
520 XmNhorizontalScrollBar
: XmNverticalScrollBar
;
521 WXWidget
* widgetSB
= orientation
== wxHORIZONTAL
?
522 &m_hScrollBar
: &m_vScrollBar
;
526 wxDeleteWindowFromTable( (Widget
)*widgetSB
);
527 XtDestroyWidget( (Widget
)*widgetSB
);
528 *widgetSB
= (WXWidget
)NULL
;
531 XtVaSetValues( (Widget
)m_scrolledWindow
,
532 stringSB
, (Widget
) 0,
535 XtVaSetValues((Widget
) m_scrolledWindow
,
536 XmNresizePolicy
, XmRESIZE_ANY
,
540 // ---------------------------------------------------------------------------
542 // ---------------------------------------------------------------------------
544 void wxWindow::SetFocus()
546 Widget wMain
= (Widget
) GetMainWidget();
547 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
548 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
551 // Get the window with the focus
552 wxWindow
*wxWindowBase::DoFindFocus()
555 // (1) Can there be multiple focussed widgets in an application?
556 // In which case we need to find the top-level window that's
558 // (2) The widget with the focus may not be in the widget table
559 // depending on which widgets I put in the table
560 wxWindow
*winFocus
= (wxWindow
*)NULL
;
561 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
563 node
= node
->GetNext() )
565 wxWindow
*win
= node
->GetData();
567 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
569 if (w
!= (Widget
) NULL
)
571 winFocus
= wxGetWindowFromTable(w
);
580 bool wxWindow::Enable(bool enable
)
582 if ( !wxWindowBase::Enable(enable
) )
585 Widget wMain
= (Widget
)GetMainWidget();
588 XtSetSensitive(wMain
, enable
);
589 XmUpdateDisplay(wMain
);
595 bool wxWindow::Show(bool show
)
597 if ( !wxWindowBase::Show(show
) )
600 if (m_borderWidget
|| m_scrolledWindow
)
602 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
603 // MapOrUnmap(m_drawingArea, show);
607 if ( !MapOrUnmap(GetTopWidget(), show
) )
608 MapOrUnmap(GetMainWidget(), show
);
614 // Raise the window to the top of the Z order
615 void wxWindow::Raise()
617 Widget wTop
= (Widget
) GetTopWidget();
618 Window window
= XtWindow(wTop
);
619 XRaiseWindow(XtDisplay(wTop
), window
);
622 // Lower the window to the bottom of the Z order
623 void wxWindow::Lower()
625 Widget wTop
= (Widget
) GetTopWidget();
626 Window window
= XtWindow(wTop
);
627 XLowerWindow(XtDisplay(wTop
), window
);
630 void wxWindow::SetLabel(const wxString
& label
)
632 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, label
.mb_str(), NULL
);
635 wxString
wxWindow::GetLabel() const
638 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &label
, NULL
);
640 return wxString(label
);
643 void wxWindow::DoCaptureMouse()
645 g_captureWindow
= this;
649 Widget wMain
= (Widget
)GetMainWidget();
651 XtAddGrab(wMain
, True
, False
);
653 m_winCaptured
= true;
656 void wxWindow::DoReleaseMouse()
658 g_captureWindow
= NULL
;
659 if ( !m_winCaptured
)
662 Widget wMain
= (Widget
)GetMainWidget();
666 m_winCaptured
= false;
669 bool wxWindow::SetFont(const wxFont
& font
)
671 if ( !wxWindowBase::SetFont(font
) )
682 bool wxWindow::SetCursor(const wxCursor
& cursor
)
684 if ( !wxWindowBase::SetCursor(cursor
) )
690 // wxASSERT_MSG( m_cursor.Ok(),
691 // wxT("cursor must be valid after call to the base version"));
692 const wxCursor
* cursor2
= NULL
;
694 cursor2
= & m_cursor
;
696 cursor2
= wxSTANDARD_CURSOR
;
698 WXDisplay
*dpy
= GetXDisplay();
699 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
701 Widget w
= (Widget
) GetMainWidget();
702 Window win
= XtWindow(w
);
703 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
708 // Coordinates relative to the window
709 void wxWindow::WarpPointer (int x
, int y
)
711 Widget wClient
= (Widget
)GetClientWidget();
713 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
716 // ---------------------------------------------------------------------------
718 // ---------------------------------------------------------------------------
720 int wxWindow::GetScrollPos(int orient
) const
722 if (orient
== wxHORIZONTAL
)
728 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
732 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
740 // This now returns the whole range, not just the number of positions that we
742 int wxWindow::GetScrollRange(int orient
) const
744 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
745 // CE scintilla windows don't always have these scrollbars
746 // and it tends to pile up a whole bunch of asserts
747 //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
751 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
755 int wxWindow::GetScrollThumb(int orient
) const
757 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
758 //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
762 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
766 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
768 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
772 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
775 SetInternalScrollPos((wxOrientation
)orient
, pos
);
778 // New function that will replace some of the above.
779 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
780 int range
, bool WXUNUSED(refresh
))
783 GetSize(& oldW
, & oldH
);
787 if (thumbVisible
== 0)
790 if (thumbVisible
> range
)
791 thumbVisible
= range
;
793 // Save the old state to see if it changed
794 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
796 if (orient
== wxHORIZONTAL
)
798 if (thumbVisible
== range
)
801 DestroyScrollbar(wxHORIZONTAL
);
806 CreateScrollbar(wxHORIZONTAL
);
809 if (orient
== wxVERTICAL
)
811 if (thumbVisible
== range
)
814 DestroyScrollbar(wxVERTICAL
);
819 CreateScrollbar(wxVERTICAL
);
822 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
824 if (oldScrollBar
!= newScrollBar
)
826 // This is important! Without it, scrollbars misbehave badly.
827 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
828 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
829 XtRealizeWidget((Widget
) m_scrolledWindow
);
830 XtManageChild((Widget
) m_scrolledWindow
);
835 XtVaSetValues((Widget
) newScrollBar
,
839 XmNsliderSize
, thumbVisible
,
843 SetInternalScrollPos((wxOrientation
)orient
, pos
);
846 GetSize(& newW
, & newH
);
848 // Adjusting scrollbars can resize the canvas accidentally
849 if (newW
!= oldW
|| newH
!= oldH
)
850 SetSize(wxDefaultCoord
, wxDefaultCoord
, oldW
, oldH
);
853 // Does a physical scroll
854 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
859 // Use specified rectangle
860 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
864 // Use whole client area
866 GetClientSize(& w
, & h
);
869 int x1
= (dx
>= 0) ? x
: x
- dx
;
870 int y1
= (dy
>= 0) ? y
: y
- dy
;
871 int w1
= w
- abs(dx
);
872 int h1
= h
- abs(dy
);
873 int x2
= (dx
>= 0) ? x
+ dx
: x
;
874 int y2
= (dy
>= 0) ? y
+ dy
: y
;
878 dc
.SetLogicalFunction (wxCOPY
);
880 Widget widget
= (Widget
) GetMainWidget();
881 Window window
= XtWindow(widget
);
882 Display
* display
= XtDisplay(widget
);
884 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
885 x1
, y1
, w1
, h1
, x2
, y2
);
887 dc
.SetAutoSetting(true);
888 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
889 dc
.SetBrush(brush
); // FIXME: needed?
891 wxWindowList::compatibility_iterator cnode
= m_children
.GetFirst();
894 wxWindow
*child
= cnode
->GetData();
897 child
->GetSize( &sx
, &sy
);
898 wxPoint
pos( child
->GetPosition() );
899 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
900 cnode
= cnode
->GetNext();
903 // We'll add rectangles to the list of update rectangles according to which
904 // bits we've exposed.
909 wxRect
*rect
= new wxRect
;
915 XFillRectangle(display
, window
,
916 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
920 rect
->width
= rect
->width
;
921 rect
->height
= rect
->height
;
923 updateRects
.Append((wxObject
*) rect
);
927 wxRect
*rect
= new wxRect
;
929 rect
->x
= x
+ w
+ dx
;
934 XFillRectangle(display
, window
,
935 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
940 rect
->width
= rect
->width
;
941 rect
->height
= rect
->height
;
943 updateRects
.Append((wxObject
*) rect
);
947 wxRect
*rect
= new wxRect
;
954 XFillRectangle(display
, window
,
955 (GC
) dc
.GetGC(), 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
,
974 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
978 rect
->width
= rect
->width
;
979 rect
->height
= rect
->height
;
981 updateRects
.Append((wxObject
*) rect
);
983 dc
.SetBrush(wxNullBrush
);
985 // Now send expose events
987 wxList::compatibility_iterator node
= updateRects
.GetFirst();
990 wxRect
* rect
= (wxRect
*) node
->GetData();
994 event
.display
= display
;
995 event
.send_event
= True
;
996 event
.window
= window
;
1000 event
.width
= rect
->width
;
1001 event
.height
= rect
->height
;
1005 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1007 node
= node
->GetNext();
1011 // Delete the update rects
1012 node
= updateRects
.GetFirst();
1015 wxRect
* rect
= (wxRect
*) node
->GetData();
1017 node
= node
->GetNext();
1020 XmUpdateDisplay((Widget
) GetMainWidget());
1023 // ---------------------------------------------------------------------------
1025 // ---------------------------------------------------------------------------
1027 #if wxUSE_DRAG_AND_DROP
1029 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1036 // Old style file-manager drag&drop
1037 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1042 // ----------------------------------------------------------------------------
1044 // ----------------------------------------------------------------------------
1048 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1053 #endif // wxUSE_TOOLTIPS
1055 // ----------------------------------------------------------------------------
1057 // ----------------------------------------------------------------------------
1061 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1063 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1065 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
1066 x
= mouse
.x
; y
= mouse
.y
;
1069 Widget widget
= (Widget
) GetMainWidget();
1071 /* The menuId field seems to be usused, so we'll use it to
1072 indicate whether a menu is popped up or not:
1073 0: Not currently created as a popup
1074 -1: Created as a popup, but not active
1078 if (menu
->GetParent() && (menu
->GetId() != -1))
1081 if (menu
->GetMainWidget())
1083 menu
->DestroyMenu(true);
1086 menu
->SetId(1); /* Mark as popped-up */
1087 menu
->CreateMenu(NULL
, widget
, menu
, 0);
1088 menu
->SetInvokingWindow(this);
1092 // menu->SetParent(parent);
1093 // parent->children->Append(menu); // Store menu for later deletion
1095 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1103 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1105 wxCanvas *canvas = (wxCanvas *) this;
1106 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1107 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1111 Display
*display
= XtDisplay (widget
);
1112 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1113 Window thisWindow
= XtWindow (widget
);
1115 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1116 &rootX
, &rootY
, &childWindow
);
1118 XButtonPressedEvent event
;
1119 event
.type
= ButtonPress
;
1125 event
.x_root
= rootX
;
1126 event
.y_root
= rootY
;
1128 XmMenuPosition (menuWidget
, &event
);
1129 XtManageChild (menuWidget
);
1131 // The ID of a pop-up menu is 1 when active, and is set to 0 by the
1132 // idle-time destroy routine.
1133 // Waiting until this ID changes causes this function to block until
1134 // the menu has been dismissed and the widgets cleaned up.
1135 // In other words, once this routine returns, it is safe to delete
1137 // Ian Brown <ian.brown@printsoft.de>
1139 wxEventLoop evtLoop
;
1141 while (menu
->GetId() == 1)
1143 wxDoEventLoopIteration( evtLoop
);
1151 // ---------------------------------------------------------------------------
1152 // moving and resizing
1153 // ---------------------------------------------------------------------------
1155 bool wxWindow::PreResize()
1161 void wxWindow::DoGetSize(int *x
, int *y
) const
1163 Widget widget
= (Widget
)( !m_drawingArea
? GetTopWidget() :
1164 ( m_borderWidget
? m_borderWidget
:
1165 m_scrolledWindow
? m_scrolledWindow
:
1170 XtVaGetValues( widget
,
1174 if(x
) *x
= widget
? xx
: -1;
1175 if(y
) *y
= widget
? yy
: -1;
1178 void wxWindow::DoGetPosition(int *x
, int *y
) const
1180 Widget widget
= (Widget
)
1182 ( m_borderWidget
? m_borderWidget
: m_scrolledWindow
) :
1186 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1188 // We may be faking the client origin. So a window that's really at (0, 30)
1189 // may appear (to wxWin apps) to be at (0, 0).
1192 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1193 xx
= (Position
)(xx
- pt
.x
);
1194 yy
= (Position
)(yy
- pt
.y
);
1201 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1203 Widget widget
= (Widget
) GetClientWidget();
1204 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1205 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1206 Window thisWindow
= XtWindow(widget
);
1209 int xx
= x
? *x
: 0;
1210 int yy
= y
? *y
: 0;
1211 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
1212 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
1216 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1218 Widget widget
= (Widget
) GetClientWidget();
1219 Display
*display
= XtDisplay(widget
);
1220 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1221 Window thisWindow
= XtWindow(widget
);
1224 int xx
= x
? *x
: 0;
1225 int yy
= y
? *y
: 0;
1226 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
1227 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
1232 // Get size *available for subwindows* i.e. excluding menu bar etc.
1233 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1235 Widget widget
= (Widget
) GetClientWidget();
1237 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1238 if(x
) *x
= xx
; if(y
) *y
= yy
;
1241 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1243 DoSetSizeIntr(x
, y
, width
, height
, sizeFlags
, false);
1246 void wxWindow::DoSetSizeIntr(int x
, int y
, int width
, int height
,
1247 int sizeFlags
, bool fromCtor
)
1249 // A bit of optimization to help sort out the flickers.
1250 int oldX
= -1, oldY
= -1, oldW
= -1, oldH
= -1;
1254 GetSize(& oldW
, & oldH
);
1255 GetPosition(& oldX
, & oldY
);
1263 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1271 wxSize
size(wxDefaultSize
);
1274 if ( ( sizeFlags
& wxSIZE_AUTO_WIDTH
) && !fromCtor
)
1276 size
= DoGetBestSize();
1287 if( ( sizeFlags
& wxSIZE_AUTO_HEIGHT
) && !fromCtor
)
1289 if( size
.x
== -1 ) size
= DoGetBestSize();
1298 if ( x
!= oldX
|| y
!= oldY
|| width
!= oldW
|| height
!= oldH
1299 || !wxNoOptimize::CanOptimize() )
1312 flags
|= wxMOVE_WIDTH
;
1315 flags
|= wxMOVE_HEIGHT
;
1317 int xx
= x
; int yy
= y
;
1318 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1320 DoMoveWindow( xx
, yy
, width
, height
);
1322 DoMoveWindowIntr( xx
, yy
, width
, height
, flags
);
1327 Widget widget
= (Widget
) GetTopWidget();
1331 bool managed
= XtIsManaged( widget
);
1333 XtUnmanageChild(widget
);
1337 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1339 DoMoveWindow(xx
, yy
, width
, height
);
1342 XtManageChild(widget
);
1346 void wxWindow::DoSetClientSize(int width
, int height
)
1350 Widget drawingArea
= (Widget
) m_drawingArea
;
1352 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1355 XtVaSetValues(drawingArea
, XmNwidth
, width
, NULL
);
1357 XtVaSetValues(drawingArea
, XmNheight
, height
, NULL
);
1359 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1363 Widget widget
= (Widget
) GetTopWidget();
1366 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1368 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1371 void wxWindow::DoMoveWindowIntr(int xx
, int yy
, int w
, int h
,
1376 Widget drawingArea
= (Widget
) m_drawingArea
;
1377 Widget borderOrScrolled
= m_borderWidget
?
1378 (Widget
) m_borderWidget
:
1379 (Widget
) m_scrolledWindow
;
1381 bool managed
= XtIsManaged(borderOrScrolled
);
1383 XtUnmanageChild (borderOrScrolled
);
1384 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1386 if (flags
& wxMOVE_X
)
1387 XtVaSetValues (borderOrScrolled
,
1390 if (flags
& wxMOVE_Y
)
1391 XtVaSetValues (borderOrScrolled
,
1395 if (flags
& wxMOVE_WIDTH
)
1399 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
1400 short thick
, margin
;
1401 XtVaGetValues ((Widget
) m_borderWidget
,
1402 XmNshadowThickness
, &thick
,
1403 XmNmarginWidth
, &margin
,
1405 w
-= 2 * (thick
+ margin
);
1409 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
1412 if (flags
& wxMOVE_HEIGHT
)
1416 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
1417 short thick
, margin
;
1418 XtVaGetValues ((Widget
) m_borderWidget
,
1419 XmNshadowThickness
, &thick
,
1420 XmNmarginHeight
, &margin
,
1422 h
-= 2 * (thick
+ margin
);
1426 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
1430 XtManageChild (borderOrScrolled
);
1431 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1438 XtVaSetValues((Widget
)GetTopWidget(),
1447 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1449 DoMoveWindowIntr (x
, y
, width
, height
,
1450 wxMOVE_X
|wxMOVE_Y
|wxMOVE_WIDTH
|wxMOVE_HEIGHT
);
1453 // ---------------------------------------------------------------------------
1455 // ---------------------------------------------------------------------------
1457 int wxWindow::GetCharHeight() const
1462 wxGetTextExtent (GetXDisplay(), m_font
, 1.0,
1463 "x", NULL
, &height
, NULL
, NULL
);
1465 wxGetTextExtent (this, "x", NULL
, &height
, NULL
, NULL
);
1470 int wxWindow::GetCharWidth() const
1475 wxGetTextExtent (GetXDisplay(), m_font
, 1.0,
1476 "x", &width
, NULL
, NULL
, NULL
);
1478 wxGetTextExtent (this, "x", &width
, NULL
, NULL
, NULL
);
1483 void wxWindow::GetTextExtent(const wxString
& string
,
1485 int *descent
, int *externalLeading
,
1486 const wxFont
*theFont
) const
1488 const wxFont
*fontToUse
= theFont
? theFont
: &m_font
;
1490 if (externalLeading
)
1491 *externalLeading
= 0;
1492 if (fontToUse
->Ok())
1493 wxGetTextExtent (GetXDisplay(), *fontToUse
, 1.0,
1494 string
, x
, y
, NULL
, descent
);
1496 wxGetTextExtent (this, string
, x
, y
, NULL
, descent
);
1499 // ----------------------------------------------------------------------------
1501 // ----------------------------------------------------------------------------
1503 void wxWindow::AddUpdateRect(int x
, int y
, int w
, int h
)
1505 m_updateRegion
.Union( x
, y
, w
, h
);
1508 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1510 Widget widget
= (Widget
) GetMainWidget();
1513 m_needsRefresh
= true;
1514 Display
*display
= XtDisplay(widget
);
1515 Window thisWindow
= XtWindow(widget
);
1517 XExposeEvent dummyEvent
;
1519 GetSize(&width
, &height
);
1521 dummyEvent
.type
= Expose
;
1522 dummyEvent
.display
= display
;
1523 dummyEvent
.send_event
= True
;
1524 dummyEvent
.window
= thisWindow
;
1527 dummyEvent
.x
= rect
->x
;
1528 dummyEvent
.y
= rect
->y
;
1529 dummyEvent
.width
= rect
->width
;
1530 dummyEvent
.height
= rect
->height
;
1536 dummyEvent
.width
= width
;
1537 dummyEvent
.height
= height
;
1539 dummyEvent
.count
= 0;
1543 wxClientDC
dc(this);
1544 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1545 dc
.SetBackground(backgroundBrush
);
1552 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1555 void wxWindow::DoPaint()
1557 //TODO : make a temporary gc so we can do the XCopyArea below
1558 if (m_backingPixmap
&& !m_needsRefresh
)
1562 GC tempGC
= (GC
) dc
.GetBackingGC();
1564 Widget widget
= (Widget
) GetMainWidget();
1569 // We have to test whether it's a wxScrolledWindow (hack!) because
1570 // otherwise we don't know how many pixels have been scrolled. We might
1571 // solve this in the future by defining virtual wxWindow functions to get
1572 // the scroll position in pixels. Or, each kind of scrolled window has to
1573 // implement backing stores itself, using generic wxWidgets code.
1574 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1575 if ( scrolledWindow
)
1578 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1584 // TODO: This could be optimized further by only copying the areas in the
1585 // current update region.
1587 // Only blit the part visible in the client area. The backing pixmap
1588 // always starts at 0, 0 but we may be looking at only a portion of it.
1589 wxSize clientArea
= GetClientSize();
1590 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1591 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1593 // Copy whichever is samller, the amount of pixmap we have to copy,
1594 // or the size of the client area.
1595 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1596 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1598 // Make sure we're not negative
1599 toBlitX
= wxMax(0, toBlitX
);
1600 toBlitY
= wxMax(0, toBlitY
);
1605 (Pixmap
) m_backingPixmap
,
1608 scrollPosX
, scrollPosY
, // Start at the scroll position
1609 toBlitX
, toBlitY
, // How much of the pixmap to copy
1615 wxWindowDC
dc(this);
1616 // Set an erase event first
1617 wxEraseEvent
eraseEvent(GetId(), &dc
);
1618 eraseEvent
.SetEventObject(this);
1619 GetEventHandler()->ProcessEvent(eraseEvent
);
1621 wxPaintEvent
event(GetId());
1622 event
.SetEventObject(this);
1623 GetEventHandler()->ProcessEvent(event
);
1625 m_needsRefresh
= false;
1629 // ----------------------------------------------------------------------------
1631 // ----------------------------------------------------------------------------
1633 // Responds to colour changes: passes event on to children.
1634 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1636 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1639 // Only propagate to non-top-level windows
1640 wxWindow
*win
= node
->GetData();
1641 if ( win
->GetParent() )
1643 wxSysColourChangedEvent event2
;
1644 event
.SetEventObject(win
);
1645 win
->GetEventHandler()->ProcessEvent(event2
);
1648 node
= node
->GetNext();
1652 void wxWindow::OnInternalIdle()
1654 // This calls the UI-update mechanism (querying windows for
1655 // menu/toolbar/control state information)
1656 if (wxUpdateUIEvent::CanUpdate(this))
1657 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1660 // ----------------------------------------------------------------------------
1662 // ----------------------------------------------------------------------------
1664 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1667 if (!m_acceleratorTable
.Ok())
1670 int count
= m_acceleratorTable
.GetCount();
1671 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1673 for (i
= 0; i
< count
; i
++)
1675 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1676 if (entry
->MatchesEvent(event
))
1678 // Bingo, we have a match. Now find a control that matches the
1679 // entry command id.
1681 // Need to go up to the top of the window hierarchy, since it might
1682 // be e.g. a menu item
1683 wxWindow
* parent
= this;
1684 while ( parent
&& !parent
->IsTopLevel() )
1685 parent
= parent
->GetParent();
1690 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1694 // Try for a menu command
1695 if (frame
->GetMenuBar())
1697 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1700 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1701 commandEvent
.SetEventObject(frame
);
1703 // If ProcessEvent returns true (it was handled), then
1704 // the calling code will skip the event handling.
1705 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1711 // Find a child matching the command id
1712 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1718 // Now we process those kinds of windows that we can.
1719 // For now, only buttons.
1720 if ( wxDynamicCast(child
, wxButton
) )
1722 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1723 commandEvent
.SetEventObject(child
);
1724 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1732 // We didn't match the key event against an accelerator.
1736 // ============================================================================
1737 // Motif-specific stuff from here on
1738 // ============================================================================
1740 // ----------------------------------------------------------------------------
1741 // function which maintain the global hash table mapping Widgets to wxWidgets
1742 // ----------------------------------------------------------------------------
1744 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1746 const long key
= (long)w
;
1747 if ( wxWidgetHashTable
->Get(key
))
1749 wxLogDebug("Widget table clash: new widget is %ld, %s",
1750 key
, win
->GetClassInfo()->GetClassName());
1754 wxWidgetHashTable
->Put(key
, win
);
1756 wxLogTrace("widget", "Widget 0x%p <-> window %p (%s)",
1757 w
, win
, win
->GetClassInfo()->GetClassName());
1762 wxWindow
*wxGetWindowFromTable(Widget w
)
1764 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1767 void wxDeleteWindowFromTable(Widget w
)
1769 wxLogTrace("widget", "Widget 0x%p", (WXWidget
)w
);
1771 wxWidgetHashTable
->Delete((long)w
);
1774 // ----------------------------------------------------------------------------
1775 // add/remove window from the table
1776 // ----------------------------------------------------------------------------
1778 // Add to hash table, add event handler
1779 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1780 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1782 wxAddWindowToTable((Widget
) mainWidget
, this);
1783 XtAddEventHandler( (Widget
) mainWidget
,
1784 ButtonPressMask
| ButtonReleaseMask
1785 | PointerMotionMask
,
1787 wxPanelItemEventHandler
,
1793 XtOverrideTranslations ((Widget
) mainWidget
,
1794 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1795 XtFree ((char *) ptr
);
1798 // Some widgets have a parent form widget, e.g. wxRadioBox
1801 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1805 XtOverrideTranslations ((Widget
) formWidget
,
1806 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1807 XtFree ((char *) ptr
);
1814 DoSetSize (x
, y
, width
, height
, wxSIZE_USE_EXISTING
);
1819 // Remove event handler, remove from hash table
1820 bool wxWindow::DetachWidget(WXWidget widget
)
1822 XtRemoveEventHandler( (Widget
) widget
,
1823 ButtonPressMask
| ButtonReleaseMask
1824 | PointerMotionMask
,
1826 wxPanelItemEventHandler
,
1829 wxDeleteWindowFromTable((Widget
) widget
);
1833 // ----------------------------------------------------------------------------
1834 // Motif-specific accessors
1835 // ----------------------------------------------------------------------------
1837 WXWindow
wxWindow::GetClientXWindow() const
1839 Widget wMain
= (Widget
)GetClientWidget();
1841 return (WXWindow
) XtWindow(wMain
);
1843 return (WXWindow
) 0;
1846 // Get the underlying X window
1847 WXWindow
wxWindow::GetXWindow() const
1849 Widget wMain
= (Widget
)GetMainWidget();
1851 return (WXWindow
) XtWindow(wMain
);
1853 return (WXWindow
) 0;
1856 // Get the underlying X display
1857 WXDisplay
*wxWindow::GetXDisplay() const
1859 Widget wMain
= (Widget
)GetMainWidget();
1861 return (WXDisplay
*) XtDisplay(wMain
);
1863 return (WXDisplay
*) NULL
;
1866 WXWidget
wxWindow::GetMainWidget() const
1869 return m_drawingArea
;
1871 return m_mainWidget
;
1874 WXWidget
wxWindow::GetClientWidget() const
1876 if (m_drawingArea
!= (WXWidget
) 0)
1877 return m_drawingArea
;
1879 return GetMainWidget();
1882 WXWidget
wxWindow::GetTopWidget() const
1884 return GetMainWidget();
1887 WXWidget
wxWindow::GetLabelWidget() const
1889 return GetMainWidget();
1892 // ----------------------------------------------------------------------------
1894 // ----------------------------------------------------------------------------
1896 // All widgets should have this as their resize proc.
1897 // OnSize sent to wxWindow via client data.
1898 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
),
1899 String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1901 wxWindow
*win
= wxGetWindowFromTable(w
);
1905 if (win
->PreResize())
1907 wxSize
newSize(win
->GetSize());
1908 wxSizeEvent
sizeEvent(newSize
, win
->GetId());
1909 sizeEvent
.SetEventObject(win
);
1910 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1914 static void wxCanvasRepaintProc(Widget drawingArea
,
1915 XtPointer clientData
,
1916 XmDrawingAreaCallbackStruct
* cbs
)
1918 if (!wxGetWindowFromTable(drawingArea
))
1921 XEvent
* event
= cbs
->event
;
1922 wxWindow
* win
= (wxWindow
*) clientData
;
1924 switch (event
->type
)
1928 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1929 event
->xexpose
.width
, event
->xexpose
.height
);
1931 if (event
-> xexpose
.count
== 0)
1940 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1941 static void wxCanvasEnterLeave(Widget drawingArea
,
1942 XtPointer
WXUNUSED(clientData
),
1943 XCrossingEvent
* event
)
1945 XmDrawingAreaCallbackStruct cbs
;
1948 ((XCrossingEvent
&) ev
) = *event
;
1950 cbs
.reason
= XmCR_INPUT
;
1953 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1956 // Fix to make it work under Motif 1.0 (!)
1957 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
),
1958 XButtonEvent
*WXUNUSED(event
))
1960 #if XmVersion <= 1000
1961 XmDrawingAreaCallbackStruct cbs
;
1964 ev
= *((XEvent
*) event
);
1965 cbs
.reason
= XmCR_INPUT
;
1968 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1969 #endif // XmVersion <= 1000
1972 static void wxCanvasInputEvent(Widget drawingArea
,
1973 XtPointer
WXUNUSED(data
),
1974 XmDrawingAreaCallbackStruct
* cbs
)
1976 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1977 XEvent
* xevent
= cbs
->event
;
1982 if (cbs
->reason
!= XmCR_INPUT
)
1985 switch (xevent
->xany
.type
)
1993 wxMouseEvent
wxevent(0);
1994 if (wxTranslateMouseEvent(wxevent
, canvas
, drawingArea
, xevent
))
1996 canvas
->GetEventHandler()->ProcessEvent(wxevent
);
2002 wxKeyEvent
event (wxEVT_CHAR
);
2003 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, xevent
))
2005 // Implement wxFrame::OnCharHook by checking ancestor.
2006 wxWindow
*parent
= canvas
;
2007 while (parent
&& !parent
->IsTopLevel())
2008 parent
= parent
->GetParent();
2012 event
.SetEventType(wxEVT_CHAR_HOOK
);
2013 if (parent
->GetEventHandler()->ProcessEvent(event
))
2017 // For simplicity, OnKeyDown is the same as OnChar
2018 // TODO: filter modifier key presses from OnChar
2019 event
.SetEventType(wxEVT_KEY_DOWN
);
2021 // Only process OnChar if OnKeyDown didn't swallow it
2022 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2024 event
.SetEventType(wxEVT_CHAR
);
2025 canvas
->GetEventHandler()->ProcessEvent (event
);
2032 wxKeyEvent
event (wxEVT_KEY_UP
);
2033 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, xevent
))
2035 canvas
->GetEventHandler()->ProcessEvent (event
);
2041 if (xevent
->xfocus
.detail
!= NotifyPointer
)
2043 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2044 event
.SetEventObject(canvas
);
2045 canvas
->GetEventHandler()->ProcessEvent(event
);
2051 if (xevent
->xfocus
.detail
!= NotifyPointer
)
2053 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2054 event
.SetEventObject(canvas
);
2055 canvas
->GetEventHandler()->ProcessEvent(event
);
2064 static void wxPanelItemEventHandler(Widget wid
,
2065 XtPointer
WXUNUSED(client_data
),
2067 Boolean
*continueToDispatch
)
2069 // Widget can be a label or the actual widget.
2071 wxWindow
*window
= wxGetWindowFromTable(wid
);
2074 wxMouseEvent
wxevent(0);
2075 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2077 window
->GetEventHandler()->ProcessEvent(wxevent
);
2081 // TODO: probably the key to allowing default behaviour to happen. Say we
2082 // set a m_doDefault flag to false at the start of this function. Then in
2083 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2084 // true, indicating that default processing can happen. Thus, behaviour can
2085 // appear to be overridden just by adding an event handler and not calling
2086 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2087 // way of handling drawing area events, to simplify things.
2088 *continueToDispatch
= True
;
2091 static void wxScrollBarCallback(Widget scrollbar
,
2092 XtPointer clientData
,
2093 XmScrollBarCallbackStruct
*cbs
)
2095 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2096 wxCHECK_RET( win
, _T("invalid widget in scrollbar callback") );
2098 wxOrientation orientation
= (wxOrientation
)wxPtrToUInt(clientData
);
2100 wxEventType eventType
= wxEVT_NULL
;
2101 switch (cbs
->reason
)
2103 case XmCR_INCREMENT
:
2105 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2108 case XmCR_DECREMENT
:
2110 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2115 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2118 case XmCR_VALUE_CHANGED
:
2120 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2123 case XmCR_PAGE_INCREMENT
:
2125 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2128 case XmCR_PAGE_DECREMENT
:
2130 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2135 eventType
= wxEVT_SCROLLWIN_TOP
;
2138 case XmCR_TO_BOTTOM
:
2140 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2145 // Should never get here
2146 wxFAIL_MSG("Unknown scroll event.");
2151 wxScrollWinEvent
event(eventType
,
2154 event
.SetEventObject( win
);
2155 win
->GetEventHandler()->ProcessEvent(event
);
2158 // For repainting arbitrary windows
2159 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2161 wxWindow
* win
= wxGetWindowFromTable(w
);
2165 switch ( event
->type
)
2169 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2170 event
->xexpose
.width
, event
->xexpose
.height
);
2172 if ( event
->xexpose
.count
== 0 )
2182 // ----------------------------------------------------------------------------
2183 // TranslateXXXEvent() functions
2184 // ----------------------------------------------------------------------------
2186 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
,
2187 Widget widget
, const XEvent
*xevent
)
2189 switch (xevent
->xany
.type
)
2194 fprintf(stderr
, "Widget 0x%p <-> window %p (%s), %s\n",
2195 (WXWidget
)widget
, win
, win
->GetClassInfo()->GetClassName(),
2196 (xevent
->xany
.type
== EnterNotify
? "ENTER" : "LEAVE"));
2202 int eventx
= xevent
->xbutton
.x
, eventy
= xevent
->xbutton
.y
;
2204 wxEventType eventType
= wxEVT_NULL
;
2206 if (xevent
->xany
.type
== LeaveNotify
)
2208 eventType
= wxEVT_LEAVE_WINDOW
;
2210 if (xevent
->xany
.type
== EnterNotify
)
2212 eventType
= wxEVT_ENTER_WINDOW
;
2214 else if (xevent
->xany
.type
== MotionNotify
)
2216 eventType
= wxEVT_MOTION
;
2218 if (xevent
->xmotion
.is_hint
== NotifyHint
)
2223 Display
*dpy
= XtDisplay (widget
);
2225 XQueryPointer (dpy
, XtWindow (widget
),
2227 &x_root
, &y_root
, &eventx
, &eventy
, &state
);
2230 else if (xevent
->xany
.type
== ButtonPress
)
2232 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2234 if (xevent
->xbutton
.button
== Button1
)
2236 eventType
= wxEVT_LEFT_DOWN
;
2239 else if (xevent
->xbutton
.button
== Button2
)
2241 eventType
= wxEVT_MIDDLE_DOWN
;
2244 else if (xevent
->xbutton
.button
== Button3
)
2246 eventType
= wxEVT_RIGHT_DOWN
;
2250 // check for a double click
2252 long dclickTime
= XtGetMultiClickTime(xevent
->xany
.display
);
2253 long ts
= wxevent
.GetTimestamp();
2255 int buttonLast
= win
->GetLastClickedButton();
2256 long lastTS
= win
->GetLastClickTime();
2257 if ( buttonLast
&& buttonLast
== button
&&
2258 (ts
- lastTS
) < dclickTime
)
2261 win
->SetLastClick(0, ts
);
2262 if ( eventType
== wxEVT_LEFT_DOWN
)
2263 eventType
= wxEVT_LEFT_DCLICK
;
2264 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2265 eventType
= wxEVT_MIDDLE_DCLICK
;
2266 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2267 eventType
= wxEVT_RIGHT_DCLICK
;
2271 // not fast enough or different button
2272 win
->SetLastClick(button
, ts
);
2275 else if (xevent
->xany
.type
== ButtonRelease
)
2277 if (xevent
->xbutton
.button
== Button1
)
2279 eventType
= wxEVT_LEFT_UP
;
2281 else if (xevent
->xbutton
.button
== Button2
)
2283 eventType
= wxEVT_MIDDLE_UP
;
2285 else if (xevent
->xbutton
.button
== Button3
)
2287 eventType
= wxEVT_RIGHT_UP
;
2297 wxevent
.SetEventType(eventType
);
2300 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2303 win
->GetPosition(&x2
, &y2
);
2305 // The button x/y must be translated to wxWidgets
2306 // window space - the widget might be a label or button,
2310 if (widget
!= (Widget
)win
->GetMainWidget())
2316 wxevent
.m_x
= eventx
+ dx
;
2317 wxevent
.m_y
= eventy
+ dy
;
2319 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2320 || (event_left_is_down (xevent
)
2321 && (eventType
!= wxEVT_LEFT_UP
)));
2322 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2323 || (event_middle_is_down (xevent
)
2324 && (eventType
!= wxEVT_MIDDLE_UP
)));
2325 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2326 || (event_right_is_down (xevent
)
2327 && (eventType
!= wxEVT_RIGHT_UP
)));
2329 wxevent
.m_shiftDown
= (xevent
->xbutton
.state
& ShiftMask
) == ShiftMask
;
2330 wxevent
.m_controlDown
= (xevent
->xbutton
.state
& ControlMask
) == ControlMask
;
2331 wxevent
.m_altDown
= (xevent
->xbutton
.state
& Mod3Mask
) == Mod3Mask
;
2332 wxevent
.m_metaDown
= (xevent
->xbutton
.state
& Mod1Mask
) == Mod1Mask
;
2334 wxevent
.SetId(win
->GetId());
2335 wxevent
.SetEventObject(win
);
2343 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
,
2344 Widget
WXUNUSED(widget
), const XEvent
*xevent
)
2346 switch (xevent
->xany
.type
)
2354 (void) XLookupString((XKeyEvent
*)xevent
, buf
, 20, &keySym
, NULL
);
2355 int id
= wxCharCodeXToWX (keySym
);
2356 // id may be WXK_xxx code - these are outside ASCII range, so we
2357 // can't just use toupper() on id
2358 if (id
>= 'a' && id
<= 'z')
2361 if (xevent
->xkey
.state
& ShiftMask
)
2362 wxevent
.m_shiftDown
= true;
2363 if (xevent
->xkey
.state
& ControlMask
)
2364 wxevent
.m_controlDown
= true;
2365 if (xevent
->xkey
.state
& Mod3Mask
)
2366 wxevent
.m_altDown
= true;
2367 if (xevent
->xkey
.state
& Mod1Mask
)
2368 wxevent
.m_metaDown
= true;
2369 wxevent
.SetEventObject(win
);
2370 wxevent
.m_keyCode
= id
;
2371 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2373 wxevent
.m_x
= xevent
->xbutton
.x
;
2374 wxevent
.m_y
= xevent
->xbutton
.y
;
2387 // ----------------------------------------------------------------------------
2389 // ----------------------------------------------------------------------------
2391 #define YAllocColor XAllocColor
2392 XColor g_itemColors
[5];
2393 int wxComputeColours (Display
*display
, const wxColour
* back
, const wxColour
* fore
)
2396 static XmColorProc colorProc
;
2398 result
= wxNO_COLORS
;
2402 g_itemColors
[0].red
= (unsigned short)(((long) back
->Red ()) << 8);
2403 g_itemColors
[0].green
= (unsigned short)(((long) back
->Green ()) << 8);
2404 g_itemColors
[0].blue
= (unsigned short)(((long) back
->Blue ()) << 8);
2405 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2406 if (colorProc
== (XmColorProc
) NULL
)
2408 // Get a ptr to the actual function
2409 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2410 // And set it back to motif.
2411 XmSetColorCalculation (colorProc
);
2413 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2414 &g_itemColors
[wxFORE_INDEX
],
2415 &g_itemColors
[wxSELE_INDEX
],
2416 &g_itemColors
[wxTOPS_INDEX
],
2417 &g_itemColors
[wxBOTS_INDEX
]);
2418 result
= wxBACK_COLORS
;
2422 g_itemColors
[wxFORE_INDEX
].red
= (unsigned short)(((long) fore
->Red ()) << 8);
2423 g_itemColors
[wxFORE_INDEX
].green
= (unsigned short)(((long) fore
->Green ()) << 8);
2424 g_itemColors
[wxFORE_INDEX
].blue
= (unsigned short)(((long) fore
->Blue ()) << 8);
2425 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2426 if (result
== wxNO_COLORS
)
2427 result
= wxFORE_COLORS
;
2430 Display
*dpy
= display
;
2431 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2435 /* 5 Colours to allocate */
2436 for (int i
= 0; i
< 5; i
++)
2437 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2438 result
= wxNO_COLORS
;
2442 /* Only 1 colour to allocate */
2443 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2444 result
= wxNO_COLORS
;
2450 // Changes the foreground and background colours to be derived from the current
2451 // background colour. To change the foreground colour, you must call
2452 // SetForegroundColour explicitly.
2453 void wxWindow::ChangeBackgroundColour()
2455 WXWidget mainWidget
= GetMainWidget();
2457 wxDoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2458 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2459 wxDoChangeForegroundColour(m_scrolledWindow
, m_backgroundColour
);
2462 void wxWindow::ChangeForegroundColour()
2464 WXWidget mainWidget
= GetMainWidget();
2466 wxDoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2467 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2468 wxDoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2471 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2473 if ( !wxWindowBase::SetBackgroundColour(col
) )
2476 ChangeBackgroundColour();
2481 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2483 if ( !wxWindowBase::SetForegroundColour(col
) )
2486 ChangeForegroundColour();
2491 void wxWindow::ChangeFont(bool keepOriginalSize
)
2493 // Note that this causes the widget to be resized back
2494 // to its original size! We therefore have to set the size
2495 // back again. TODO: a better way in Motif?
2496 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2497 if (w
&& m_font
.Ok())
2499 int width
, height
, width1
, height1
;
2500 GetSize(& width
, & height
);
2502 wxDoChangeFont( w
, m_font
);
2504 GetSize(& width1
, & height1
);
2505 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2507 SetSize(wxDefaultCoord
, wxDefaultCoord
, width
, height
);
2513 void wxWindow::PostCreation()
2516 ChangeForegroundColour();
2517 ChangeBackgroundColour();
2521 void wxWindow::PreCreation()
2523 InheritAttributes();
2526 // ----------------------------------------------------------------------------
2528 // ----------------------------------------------------------------------------
2530 wxWindow
*wxGetActiveWindow()
2533 wxFAIL_MSG("Not implemented");
2538 wxWindow
*wxWindowBase::GetCapture()
2540 return (wxWindow
*)g_captureWindow
;
2544 // Find the wxWindow at the current mouse position, returning the mouse
2546 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2548 pt
= wxGetMousePosition();
2549 return wxFindWindowAtPoint(pt
);
2552 void wxGetMouseState(int& rootX
, int& rootY
, unsigned& maskReturn
)
2554 Display
*display
= wxGlobalDisplay();
2555 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2556 Window rootReturn
, childReturn
;
2559 XQueryPointer (display
,
2563 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
2566 // Get the current mouse position.
2567 wxPoint
wxGetMousePosition()
2572 wxGetMouseState(x
, y
, mask
);
2573 return wxPoint(x
, y
);
2576 wxMouseState
wxGetMouseState()
2582 wxGetMouseState(x
, y
, mask
);
2587 ms
.SetLeftDown(mask
& Button1Mask
);
2588 ms
.SetMiddleDown(mask
& Button2Mask
);
2589 ms
.SetRightDown(mask
& Button3Mask
);
2591 ms
.SetControlDown(mask
& ControlMask
);
2592 ms
.SetShiftDown(mask
& ShiftMask
);
2593 ms
.SetAltDown(mask
& Mod3Mask
);
2594 ms
.SetMetaDown(mask
& Mod1Mask
);
2600 #if wxMOTIF_NEW_FONT_HANDLING
2604 void wxGetTextExtent(const wxWindow
* window
, const wxString
& str
,
2605 int* width
, int* height
, int* ascent
, int* descent
)
2609 XmRendition rendition
= NULL
;
2610 XmRenderTable table
= NULL
;
2611 Widget w
= (Widget
) window
->GetLabelWidget();
2613 XtVaGetValues( w
, XmNrenderTable
, &table
, NULL
);
2615 table
= XmeGetDefaultRenderTable(w
, XmTEXT_RENDER_TABLE
);
2617 rendition
= XmRenderTableGetRendition( table
, "" );
2618 XtSetArg( args
[count
], XmNfont
, 0 ); ++count
;
2619 XtSetArg( args
[count
], XmNfontType
, 0 ); ++count
;
2620 XmRenditionRetrieve( rendition
, args
, count
);
2622 if (args
[1].value
== XmFONT_IS_FONTSET
)
2624 XRectangle ink
, logical
;
2625 WXFontSet fset
= (WXFontSet
) args
[0].value
;
2627 XmbTextExtents( (XFontSet
)fset
, str
.c_str(), str
.length(),
2630 if( width
) *width
= logical
.width
;
2631 if( height
) *height
= logical
.height
;
2632 if( ascent
) *ascent
= -logical
.y
;
2633 if( descent
) *descent
= logical
.height
+ logical
.y
;
2637 int direction
, ascent2
, descent2
;
2638 XCharStruct overall
;
2639 XFontStruct
* fontStruct
;
2641 XmeRenderTableGetDefaultFont( table
, &fontStruct
);
2642 XTextExtents(fontStruct
, (const char*)str
.c_str(), str
.length(),
2643 &direction
, &ascent2
, &descent2
, &overall
);
2645 if ( width
) *width
= overall
.width
;
2646 if ( height
) *height
= ascent2
+ descent2
;
2647 if ( descent
) *descent
= descent2
;
2648 if ( ascent
) *ascent
= ascent2
;
2652 #else // if !wxMOTIF_NEW_FONT_HANDLING
2654 void wxGetTextExtent(const wxWindow
* window
, const wxString
& str
,
2655 int* width
, int* height
, int* ascent
, int* descent
)
2657 XmFontList list
= NULL
;
2660 Widget w
= (Widget
) window
->GetLabelWidget();
2662 XtVaGetValues( w
, XmNfontList
, &list
, NULL
);
2663 XmFontListInitFontContext( &cxt
, list
);
2665 XmFontListEntry entry
= XmFontListNextEntry( cxt
);
2666 XmFontListFreeFontContext( cxt
);
2667 XtPointer thing
= XmFontListEntryGetFont( entry
, &type
);
2669 if (type
== XmFONT_IS_FONTSET
)
2671 XRectangle ink
, logical
;
2673 XmbTextExtents( (XFontSet
)thing
, str
.c_str(), str
.length(),
2676 if( width
) *width
= logical
.width
;
2677 if( height
) *height
= logical
.height
;
2678 if( ascent
) *ascent
= -logical
.y
;
2679 if( descent
) *descent
= logical
.height
+ logical
.y
;
2683 int direction
, ascent2
, descent2
;
2684 XCharStruct overall
;
2686 XTextExtents( (XFontStruct
*)thing
, (char*)(const char*)str
.c_str(), str
.length(),
2687 &direction
, &ascent2
, &descent2
, &overall
);
2689 if ( width
) *width
= overall
.width
;
2690 if ( height
) *height
= ascent2
+ descent2
;
2691 if ( descent
) *descent
= descent2
;
2692 if ( ascent
) *ascent
= ascent2
;
2696 #endif // !wxMOTIF_NEW_FONT_HANDLING
2698 // ----------------------------------------------------------------------------
2699 // wxNoOptimize: switch off size optimization
2700 // ----------------------------------------------------------------------------
2702 int wxNoOptimize::ms_count
= 0;