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"
83 #include "wx/motif/dcclient.h"
87 // ----------------------------------------------------------------------------
88 // global variables for this module
89 // ----------------------------------------------------------------------------
91 extern wxHashTable
*wxWidgetHashTable
;
92 static wxWindow
* g_captureWindow
= NULL
;
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
100 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
101 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
102 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
103 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
104 XmScrollBarCallbackStruct
*cbs
);
105 static void wxPanelItemEventHandler(Widget wid
,
106 XtPointer client_data
,
108 Boolean
*continueToDispatch
);
113 // Helper function for 16-bit fonts
114 static int str16len(const char *s
)
118 while (s
[0] && s
[1]) {
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
132 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
133 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
134 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
140 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
142 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
143 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
146 // ============================================================================
148 // ============================================================================
150 // ----------------------------------------------------------------------------
152 // ----------------------------------------------------------------------------
154 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
156 Widget w
= (Widget
)widget
;
164 bool wxWindow::MapOrUnmap(WXWidget widget
, bool domap
)
166 Widget w
= (Widget
)widget
;
170 // Rationale: a lot of common operations (including but not
171 // limited to moving, resizing and appending items to a listbox)
172 // unmamange the widget, do their work, then manage it again.
173 // This means that, for example adding an item to a listbox will show it,
174 // or that most controls are shown every time they are moved or resized!
175 XtSetMappedWhenManaged( w
, domap
);
177 // if the widget is not unmanaged, it still intercepts
178 // mouse events, even if it is not mapped (and hence invisible)
193 // ----------------------------------------------------------------------------
195 // ----------------------------------------------------------------------------
197 void wxWindow::Init()
200 m_needsRefresh
= true;
201 m_mainWidget
= (WXWidget
) 0;
203 m_winCaptured
= false;
211 m_drawingArea
= (WXWidget
) 0;
216 m_backingPixmap
= (WXPixmap
) 0;
227 // real construction (Init() must have been called before!)
228 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
232 const wxString
& name
)
234 // Get default border
235 wxBorder border
= GetBorder(style
);
236 style
&= ~wxBORDER_MASK
;
239 wxCHECK_MSG( parent
, false, "can't create wxWindow without parent" );
241 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
243 parent
->AddChild(this);
246 //// TODO: we should probably optimize by only creating a
247 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
248 //// But for now, let's simplify things by always creating the
249 //// drawing area, since otherwise the translations are different.
251 // New translations for getting mouse motion feedback
252 static const String translations
= wxMOTIF_STR(
253 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
254 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
255 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
256 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
257 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
258 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
259 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
260 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
261 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
262 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
263 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
264 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
265 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
266 <Key>: DrawingAreaInput()");
268 XtActionsRec actions
[1];
269 actions
[0].string
= wxMOTIF_STR("wxCanvasMotionEvent");
270 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
271 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
273 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
274 m_borderWidget
= wxCreateBorderWidget( (WXWidget
)parentWidget
, style
);
276 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
279 xmScrolledWindowWidgetClass
,
280 m_borderWidget
? (Widget
) m_borderWidget
282 XmNresizePolicy
, XmRESIZE_NONE
,
284 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
285 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
289 XtTranslations ptr
= XtParseTranslationTable(translations
);
290 m_drawingArea
= (WXWidget
)XtVaCreateWidget
293 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
294 XmNunitType
, XmPIXELS
,
295 // XmNresizePolicy, XmRESIZE_ANY,
296 XmNresizePolicy
, XmRESIZE_NONE
,
299 XmNtranslations
, ptr
,
302 XtFree((char *) ptr
);
305 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
307 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
308 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
309 XtFree ((char *) ptr
);
313 wxAddWindowToTable((Widget
) m_drawingArea
, this);
314 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
316 // This order is very important in Motif 1.2.1
317 XtRealizeWidget ((Widget
) m_scrolledWindow
);
318 XtRealizeWidget ((Widget
) m_drawingArea
);
319 XtManageChild ((Widget
) m_drawingArea
);
321 ptr
= XtParseTranslationTable("<Configure>: resize()");
322 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
323 XtFree ((char *) ptr
);
325 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
326 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
329 (Widget
)m_drawingArea
,
330 PointerMotionHintMask
| EnterWindowMask
|
331 LeaveWindowMask
| FocusChangeMask
,
333 (XtEventHandler
) wxCanvasEnterLeave
,
337 XmScrolledWindowSetAreas(
338 (Widget
)m_scrolledWindow
,
339 (Widget
) 0, (Widget
) 0,
340 (Widget
) m_drawingArea
);
344 // Without this, the cursor may not be restored properly (e.g. in splitter
346 SetCursor(*wxSTANDARD_CURSOR
);
347 DoSetSizeIntr(pos
.x
, pos
.y
, size
.x
,size
.y
, wxSIZE_AUTO
, true);
352 wxWindow::~wxWindow()
354 if (g_captureWindow
== this)
355 g_captureWindow
= NULL
;
357 m_isBeingDeleted
= true;
359 // Motif-specific actions first
360 WXWidget wMain
= GetMainWidget();
363 // Removes event handlers
367 // If m_drawingArea, we're a fully-fledged window with drawing area,
368 // scrollbars etc. (what wxCanvas used to be)
371 // Destroy children before destroying self
375 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
377 Widget w
= (Widget
) m_drawingArea
;
378 wxDeleteWindowFromTable(w
);
383 m_drawingArea
= (WXWidget
) 0;
386 // Only if we're _really_ a canvas (not a dialog box/panel)
387 if (m_scrolledWindow
)
389 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
394 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
395 XtUnmanageChild((Widget
) m_hScrollBar
);
399 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
400 XtUnmanageChild((Widget
) m_vScrollBar
);
404 XtDestroyWidget((Widget
) m_hScrollBar
);
406 XtDestroyWidget((Widget
) m_vScrollBar
);
408 UnmanageAndDestroy(m_scrolledWindow
);
412 XtDestroyWidget ((Widget
) m_borderWidget
);
413 m_borderWidget
= (WXWidget
) 0;
416 else // Why wasn't this here before? JACS 8/3/2000
420 // Destroy the window
423 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
424 // Child widgets will get destroyed automatically when a frame
425 // or dialog is destroyed, but before that you may get some memory
426 // leaks and potential layout problems if you delete and then add
429 // GRG, Feb/2000: commented this out when adding support for
430 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
431 // that this call crashed wxMotif under OS/2, so it seems
432 // that leaving it out is the right thing to do.
433 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
434 XtDestroyWidget((Widget
) GetMainWidget());
435 SetMainWidget((WXWidget
) NULL
);
439 // ----------------------------------------------------------------------------
440 // scrollbar management
441 // ----------------------------------------------------------------------------
443 WXWidget
wxWindow::DoCreateScrollBar(WXWidget parent
,
444 wxOrientation orientation
,
447 int orient
= ( orientation
& wxHORIZONTAL
) ? XmHORIZONTAL
: XmVERTICAL
;
449 XtVaCreateManagedWidget( "scrollBarWidget",
450 xmScrollBarWidgetClass
, (Widget
)parent
,
451 XmNorientation
, orient
,
456 XtPointer o
= (XtPointer
)orientation
;
457 XtCallbackProc cb
= (XtCallbackProc
)callback
;
459 XtAddCallback( sb
, XmNvalueChangedCallback
, cb
, o
);
460 XtAddCallback( sb
, XmNdragCallback
, cb
, o
);
461 XtAddCallback( sb
, XmNincrementCallback
, cb
, o
);
462 XtAddCallback( sb
, XmNdecrementCallback
, cb
, o
);
463 XtAddCallback( sb
, XmNpageIncrementCallback
, cb
, o
);
464 XtAddCallback( sb
, XmNpageDecrementCallback
, cb
, o
);
465 XtAddCallback( sb
, XmNtoTopCallback
, cb
, o
);
466 XtAddCallback( sb
, XmNtoBottomCallback
, cb
, o
);
472 void wxWindow::CreateScrollbar(wxOrientation orientation
)
474 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
476 XtVaSetValues( (Widget
) m_scrolledWindow
,
477 XmNresizePolicy
, XmRESIZE_NONE
,
480 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
481 // Add scrollbars if required
482 if (orientation
== wxHORIZONTAL
)
484 m_hScrollBar
= DoCreateScrollBar( m_scrolledWindow
, wxHORIZONTAL
,
485 (void (*)())wxScrollBarCallback
);
487 wxDoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, true);
489 XtRealizeWidget( (Widget
)m_hScrollBar
);
491 XtVaSetValues((Widget
) m_scrolledWindow
,
492 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
495 wxAddWindowToTable( (Widget
)m_hScrollBar
, this );
497 else if (orientation
== wxVERTICAL
)
499 m_vScrollBar
= DoCreateScrollBar( m_scrolledWindow
, wxVERTICAL
,
500 (void (*)())wxScrollBarCallback
);
502 wxDoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, true);
504 XtRealizeWidget((Widget
)m_vScrollBar
);
506 XtVaSetValues((Widget
) m_scrolledWindow
,
507 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
510 wxAddWindowToTable( (Widget
)m_vScrollBar
, this );
513 XtVaSetValues( (Widget
) m_scrolledWindow
,
514 XmNresizePolicy
, XmRESIZE_ANY
,
518 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
520 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
522 XtVaSetValues((Widget
) m_scrolledWindow
,
523 XmNresizePolicy
, XmRESIZE_NONE
,
525 String stringSB
= orientation
== wxHORIZONTAL
?
526 XmNhorizontalScrollBar
: XmNverticalScrollBar
;
527 WXWidget
* widgetSB
= orientation
== wxHORIZONTAL
?
528 &m_hScrollBar
: &m_vScrollBar
;
532 wxDeleteWindowFromTable( (Widget
)*widgetSB
);
533 XtDestroyWidget( (Widget
)*widgetSB
);
534 *widgetSB
= (WXWidget
)NULL
;
537 XtVaSetValues( (Widget
)m_scrolledWindow
,
538 stringSB
, (Widget
) 0,
541 XtVaSetValues((Widget
) m_scrolledWindow
,
542 XmNresizePolicy
, XmRESIZE_ANY
,
546 // ---------------------------------------------------------------------------
548 // ---------------------------------------------------------------------------
550 void wxWindow::SetFocus()
552 Widget wMain
= (Widget
) GetMainWidget();
553 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
554 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
557 // Get the window with the focus
558 wxWindow
*wxWindowBase::DoFindFocus()
561 // (1) Can there be multiple focussed widgets in an application?
562 // In which case we need to find the top-level window that's
564 // (2) The widget with the focus may not be in the widget table
565 // depending on which widgets I put in the table
566 wxWindow
*winFocus
= (wxWindow
*)NULL
;
567 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
569 node
= node
->GetNext() )
571 wxWindow
*win
= node
->GetData();
573 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
575 if (w
!= (Widget
) NULL
)
577 winFocus
= wxGetWindowFromTable(w
);
586 bool wxWindow::Enable(bool enable
)
588 if ( !wxWindowBase::Enable(enable
) )
591 Widget wMain
= (Widget
)GetMainWidget();
594 XtSetSensitive(wMain
, enable
);
595 XmUpdateDisplay(wMain
);
601 bool wxWindow::Show(bool show
)
603 if ( !wxWindowBase::Show(show
) )
606 if (m_borderWidget
|| m_scrolledWindow
)
608 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
609 // MapOrUnmap(m_drawingArea, show);
613 if ( !MapOrUnmap(GetTopWidget(), show
) )
614 MapOrUnmap(GetMainWidget(), show
);
620 // Raise the window to the top of the Z order
621 void wxWindow::Raise()
623 Widget wTop
= (Widget
) GetTopWidget();
624 Window window
= XtWindow(wTop
);
625 XRaiseWindow(XtDisplay(wTop
), window
);
628 // Lower the window to the bottom of the Z order
629 void wxWindow::Lower()
631 Widget wTop
= (Widget
) GetTopWidget();
632 Window window
= XtWindow(wTop
);
633 XLowerWindow(XtDisplay(wTop
), window
);
636 void wxWindow::SetLabel(const wxString
& label
)
638 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
,
639 (const char*)label
.mb_str(), NULL
);
642 wxString
wxWindow::GetLabel() const
645 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &label
, NULL
);
647 return wxString(label
);
650 void wxWindow::DoCaptureMouse()
652 g_captureWindow
= this;
656 Widget wMain
= (Widget
)GetMainWidget();
658 XtAddGrab(wMain
, True
, False
);
660 m_winCaptured
= true;
663 void wxWindow::DoReleaseMouse()
665 g_captureWindow
= NULL
;
666 if ( !m_winCaptured
)
669 Widget wMain
= (Widget
)GetMainWidget();
673 m_winCaptured
= false;
676 bool wxWindow::SetFont(const wxFont
& font
)
678 if ( !wxWindowBase::SetFont(font
) )
689 bool wxWindow::SetCursor(const wxCursor
& cursor
)
691 if ( !wxWindowBase::SetCursor(cursor
) )
697 // wxASSERT_MSG( m_cursor.Ok(),
698 // wxT("cursor must be valid after call to the base version"));
699 const wxCursor
* cursor2
= NULL
;
701 cursor2
= & m_cursor
;
703 cursor2
= wxSTANDARD_CURSOR
;
705 WXDisplay
*dpy
= GetXDisplay();
706 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
708 Widget w
= (Widget
) GetMainWidget();
709 Window win
= XtWindow(w
);
710 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
715 // Coordinates relative to the window
716 void wxWindow::WarpPointer (int x
, int y
)
718 Widget wClient
= (Widget
)GetClientWidget();
720 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
723 // ---------------------------------------------------------------------------
725 // ---------------------------------------------------------------------------
727 int wxWindow::GetScrollPos(int orient
) const
729 if (orient
== wxHORIZONTAL
)
735 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
739 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
747 // This now returns the whole range, not just the number of positions that we
749 int wxWindow::GetScrollRange(int orient
) const
751 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
752 // CE scintilla windows don't always have these scrollbars
753 // and it tends to pile up a whole bunch of asserts
754 //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
758 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
762 int wxWindow::GetScrollThumb(int orient
) const
764 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
765 //wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
769 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
773 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
775 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
779 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
782 SetInternalScrollPos((wxOrientation
)orient
, pos
);
785 // New function that will replace some of the above.
786 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
787 int range
, bool WXUNUSED(refresh
))
790 GetSize(& oldW
, & oldH
);
794 if (thumbVisible
== 0)
797 if (thumbVisible
> range
)
798 thumbVisible
= range
;
800 // Save the old state to see if it changed
801 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
803 if (orient
== wxHORIZONTAL
)
805 if (thumbVisible
== range
)
808 DestroyScrollbar(wxHORIZONTAL
);
813 CreateScrollbar(wxHORIZONTAL
);
816 if (orient
== wxVERTICAL
)
818 if (thumbVisible
== range
)
821 DestroyScrollbar(wxVERTICAL
);
826 CreateScrollbar(wxVERTICAL
);
829 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
831 if (oldScrollBar
!= newScrollBar
)
833 // This is important! Without it, scrollbars misbehave badly.
834 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
835 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
836 XtRealizeWidget((Widget
) m_scrolledWindow
);
837 XtManageChild((Widget
) m_scrolledWindow
);
842 XtVaSetValues((Widget
) newScrollBar
,
846 XmNsliderSize
, thumbVisible
,
850 SetInternalScrollPos((wxOrientation
)orient
, pos
);
853 GetSize(& newW
, & newH
);
855 // Adjusting scrollbars can resize the canvas accidentally
856 if (newW
!= oldW
|| newH
!= oldH
)
857 SetSize(wxDefaultCoord
, wxDefaultCoord
, oldW
, oldH
);
860 // Does a physical scroll
861 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
866 // Use specified rectangle
867 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
871 // Use whole client area
873 GetClientSize(& w
, & h
);
876 int x1
= (dx
>= 0) ? x
: x
- dx
;
877 int y1
= (dy
>= 0) ? y
: y
- dy
;
878 int w1
= w
- abs(dx
);
879 int h1
= h
- abs(dy
);
880 int x2
= (dx
>= 0) ? x
+ dx
: x
;
881 int y2
= (dy
>= 0) ? y
+ dy
: y
;
884 wxClientDCImpl
* const
885 dcimpl
= static_cast<wxClientDCImpl
*>(dc
.GetImpl());
886 GC
const gc
= (GC
) dcimpl
->GetGC();
888 dc
.SetLogicalFunction (wxCOPY
);
890 Widget widget
= (Widget
) GetMainWidget();
891 Window window
= XtWindow(widget
);
892 Display
* display
= XtDisplay(widget
);
894 XCopyArea(display
, window
, window
, gc
, x1
, y1
, w1
, h1
, x2
, y2
);
896 dcimpl
->SetAutoSetting(true);
897 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
898 dc
.SetBrush(brush
); // FIXME: needed?
900 wxWindowList::compatibility_iterator cnode
= m_children
.GetFirst();
903 wxWindow
*child
= cnode
->GetData();
906 child
->GetSize( &sx
, &sy
);
907 wxPoint
pos( child
->GetPosition() );
908 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
909 cnode
= cnode
->GetNext();
912 // We'll add rectangles to the list of update rectangles according to which
913 // bits we've exposed.
918 wxRect
*rect
= new wxRect
;
924 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
928 rect
->width
= rect
->width
;
929 rect
->height
= rect
->height
;
931 updateRects
.Append((wxObject
*) rect
);
935 wxRect
*rect
= new wxRect
;
937 rect
->x
= x
+ w
+ dx
;
942 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
946 rect
->width
= rect
->width
;
947 rect
->height
= rect
->height
;
949 updateRects
.Append((wxObject
*) rect
);
953 wxRect
*rect
= new wxRect
;
960 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
964 rect
->width
= rect
->width
;
965 rect
->height
= rect
->height
;
967 updateRects
.Append((wxObject
*) rect
);
971 wxRect
*rect
= new wxRect
;
974 rect
->y
= y
+ h
+ dy
;
978 XFillRectangle(display
, window
, gc
, rect
->x
, rect
->y
, rect
->width
, rect
->height
);
982 rect
->width
= rect
->width
;
983 rect
->height
= rect
->height
;
985 updateRects
.Append((wxObject
*) rect
);
987 dc
.SetBrush(wxNullBrush
);
989 // Now send expose events
991 wxList::compatibility_iterator node
= updateRects
.GetFirst();
994 wxRect
* rect
= (wxRect
*) node
->GetData();
998 event
.display
= display
;
999 event
.send_event
= True
;
1000 event
.window
= window
;
1004 event
.width
= rect
->width
;
1005 event
.height
= rect
->height
;
1009 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1011 node
= node
->GetNext();
1015 // Delete the update rects
1016 node
= updateRects
.GetFirst();
1019 wxRect
* rect
= (wxRect
*) node
->GetData();
1021 node
= node
->GetNext();
1024 XmUpdateDisplay((Widget
) GetMainWidget());
1027 // ---------------------------------------------------------------------------
1029 // ---------------------------------------------------------------------------
1031 #if wxUSE_DRAG_AND_DROP
1033 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1040 // Old style file-manager drag&drop
1041 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1046 // ----------------------------------------------------------------------------
1048 // ----------------------------------------------------------------------------
1052 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1057 #endif // wxUSE_TOOLTIPS
1059 // ----------------------------------------------------------------------------
1061 // ----------------------------------------------------------------------------
1065 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1067 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1069 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
1070 x
= mouse
.x
; y
= mouse
.y
;
1073 Widget widget
= (Widget
) GetMainWidget();
1075 /* The menuId field seems to be usused, so we'll use it to
1076 indicate whether a menu is popped up or not:
1077 0: Not currently created as a popup
1078 -1: Created as a popup, but not active
1082 if (menu
->GetParent() && (menu
->GetId() != -1))
1085 if (menu
->GetMainWidget())
1087 menu
->DestroyMenu(true);
1090 menu
->SetId(1); /* Mark as popped-up */
1091 menu
->CreateMenu(NULL
, widget
, menu
, 0);
1092 menu
->SetInvokingWindow(this);
1096 // menu->SetParent(parent);
1097 // parent->children->Append(menu); // Store menu for later deletion
1099 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1107 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1109 wxCanvas *canvas = (wxCanvas *) this;
1110 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1111 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1115 Display
*display
= XtDisplay (widget
);
1116 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1117 Window thisWindow
= XtWindow (widget
);
1119 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1120 &rootX
, &rootY
, &childWindow
);
1122 XButtonPressedEvent event
;
1123 event
.type
= ButtonPress
;
1129 event
.x_root
= rootX
;
1130 event
.y_root
= rootY
;
1132 XmMenuPosition (menuWidget
, &event
);
1133 XtManageChild (menuWidget
);
1135 // The ID of a pop-up menu is 1 when active, and is set to 0 by the
1136 // idle-time destroy routine.
1137 // Waiting until this ID changes causes this function to block until
1138 // the menu has been dismissed and the widgets cleaned up.
1139 // In other words, once this routine returns, it is safe to delete
1141 // Ian Brown <ian.brown@printsoft.de>
1143 wxEventLoop evtLoop
;
1145 while (menu
->GetId() == 1)
1147 wxDoEventLoopIteration( evtLoop
);
1155 // ---------------------------------------------------------------------------
1156 // moving and resizing
1157 // ---------------------------------------------------------------------------
1159 bool wxWindow::PreResize()
1165 void wxWindow::DoGetSize(int *x
, int *y
) const
1167 Widget widget
= (Widget
)( !m_drawingArea
? GetTopWidget() :
1168 ( m_borderWidget
? m_borderWidget
:
1169 m_scrolledWindow
? m_scrolledWindow
:
1174 XtVaGetValues( widget
,
1178 if(x
) *x
= widget
? xx
: -1;
1179 if(y
) *y
= widget
? yy
: -1;
1182 void wxWindow::DoGetPosition(int *x
, int *y
) const
1184 Widget widget
= (Widget
)
1186 ( m_borderWidget
? m_borderWidget
: m_scrolledWindow
) :
1190 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1192 // We may be faking the client origin. So a window that's really at (0, 30)
1193 // may appear (to wxWin apps) to be at (0, 0).
1196 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1197 xx
= (Position
)(xx
- pt
.x
);
1198 yy
= (Position
)(yy
- pt
.y
);
1205 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1207 Widget widget
= (Widget
) GetClientWidget();
1208 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1209 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1210 Window thisWindow
= XtWindow(widget
);
1213 int xx
= x
? *x
: 0;
1214 int yy
= y
? *y
: 0;
1215 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
1216 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
1220 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1222 Widget widget
= (Widget
) GetClientWidget();
1223 Display
*display
= XtDisplay(widget
);
1224 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1225 Window thisWindow
= XtWindow(widget
);
1228 int xx
= x
? *x
: 0;
1229 int yy
= y
? *y
: 0;
1230 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
1231 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
1236 // Get size *available for subwindows* i.e. excluding menu bar etc.
1237 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1239 Widget widget
= (Widget
) GetClientWidget();
1241 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1242 if(x
) *x
= xx
; if(y
) *y
= yy
;
1245 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1247 DoSetSizeIntr(x
, y
, width
, height
, sizeFlags
, false);
1250 void wxWindow::DoSetSizeIntr(int x
, int y
, int width
, int height
,
1251 int sizeFlags
, bool fromCtor
)
1253 // A bit of optimization to help sort out the flickers.
1254 int oldX
= -1, oldY
= -1, oldW
= -1, oldH
= -1;
1258 GetSize(& oldW
, & oldH
);
1259 GetPosition(& oldX
, & oldY
);
1267 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1275 wxSize
size(wxDefaultSize
);
1278 if ( ( sizeFlags
& wxSIZE_AUTO_WIDTH
) && !fromCtor
)
1280 size
= DoGetBestSize();
1291 if( ( sizeFlags
& wxSIZE_AUTO_HEIGHT
) && !fromCtor
)
1293 if( size
.x
== -1 ) size
= DoGetBestSize();
1302 if ( x
!= oldX
|| y
!= oldY
|| width
!= oldW
|| height
!= oldH
1303 || !wxNoOptimize::CanOptimize() )
1316 flags
|= wxMOVE_WIDTH
;
1319 flags
|= wxMOVE_HEIGHT
;
1321 int xx
= x
; int yy
= y
;
1322 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1324 DoMoveWindow( xx
, yy
, width
, height
);
1326 DoMoveWindowIntr( xx
, yy
, width
, height
, flags
);
1331 Widget widget
= (Widget
) GetTopWidget();
1335 bool managed
= XtIsManaged( widget
);
1337 XtUnmanageChild(widget
);
1341 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1343 DoMoveWindow(xx
, yy
, width
, height
);
1346 XtManageChild(widget
);
1350 void wxWindow::DoSetClientSize(int width
, int height
)
1354 Widget drawingArea
= (Widget
) m_drawingArea
;
1356 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1359 XtVaSetValues(drawingArea
, XmNwidth
, width
, NULL
);
1361 XtVaSetValues(drawingArea
, XmNheight
, height
, NULL
);
1363 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1367 Widget widget
= (Widget
) GetTopWidget();
1370 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1372 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1375 void wxWindow::DoMoveWindowIntr(int xx
, int yy
, int w
, int h
,
1380 Widget drawingArea
= (Widget
) m_drawingArea
;
1381 Widget borderOrScrolled
= m_borderWidget
?
1382 (Widget
) m_borderWidget
:
1383 (Widget
) m_scrolledWindow
;
1385 bool managed
= XtIsManaged(borderOrScrolled
);
1387 XtUnmanageChild (borderOrScrolled
);
1388 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1390 if (flags
& wxMOVE_X
)
1391 XtVaSetValues (borderOrScrolled
,
1394 if (flags
& wxMOVE_Y
)
1395 XtVaSetValues (borderOrScrolled
,
1399 if (flags
& wxMOVE_WIDTH
)
1403 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
1404 short thick
, margin
;
1405 XtVaGetValues ((Widget
) m_borderWidget
,
1406 XmNshadowThickness
, &thick
,
1407 XmNmarginWidth
, &margin
,
1409 w
-= 2 * (thick
+ margin
);
1413 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
1416 if (flags
& wxMOVE_HEIGHT
)
1420 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
1421 short thick
, margin
;
1422 XtVaGetValues ((Widget
) m_borderWidget
,
1423 XmNshadowThickness
, &thick
,
1424 XmNmarginHeight
, &margin
,
1426 h
-= 2 * (thick
+ margin
);
1430 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
1434 XtManageChild (borderOrScrolled
);
1435 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1442 XtVaSetValues((Widget
)GetTopWidget(),
1451 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1453 DoMoveWindowIntr (x
, y
, width
, height
,
1454 wxMOVE_X
|wxMOVE_Y
|wxMOVE_WIDTH
|wxMOVE_HEIGHT
);
1457 // ---------------------------------------------------------------------------
1459 // ---------------------------------------------------------------------------
1461 int wxWindow::GetCharHeight() const
1466 wxGetTextExtent (GetXDisplay(), m_font
, 1.0,
1467 "x", NULL
, &height
, NULL
, NULL
);
1469 wxGetTextExtent (this, "x", NULL
, &height
, NULL
, NULL
);
1474 int wxWindow::GetCharWidth() const
1479 wxGetTextExtent (GetXDisplay(), m_font
, 1.0,
1480 "x", &width
, NULL
, NULL
, NULL
);
1482 wxGetTextExtent (this, "x", &width
, NULL
, NULL
, NULL
);
1487 void wxWindow::GetTextExtent(const wxString
& string
,
1489 int *descent
, int *externalLeading
,
1490 const wxFont
*theFont
) const
1492 const wxFont
*fontToUse
= theFont
? theFont
: &m_font
;
1494 if (externalLeading
)
1495 *externalLeading
= 0;
1496 if (fontToUse
->Ok())
1497 wxGetTextExtent (GetXDisplay(), *fontToUse
, 1.0,
1498 string
, x
, y
, NULL
, descent
);
1500 wxGetTextExtent (this, string
, x
, y
, NULL
, descent
);
1503 // ----------------------------------------------------------------------------
1505 // ----------------------------------------------------------------------------
1507 void wxWindow::AddUpdateRect(int x
, int y
, int w
, int h
)
1509 m_updateRegion
.Union( x
, y
, w
, h
);
1512 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1514 Widget widget
= (Widget
) GetMainWidget();
1517 m_needsRefresh
= true;
1518 Display
*display
= XtDisplay(widget
);
1519 Window thisWindow
= XtWindow(widget
);
1521 XExposeEvent dummyEvent
;
1523 GetSize(&width
, &height
);
1525 dummyEvent
.type
= Expose
;
1526 dummyEvent
.display
= display
;
1527 dummyEvent
.send_event
= True
;
1528 dummyEvent
.window
= thisWindow
;
1531 dummyEvent
.x
= rect
->x
;
1532 dummyEvent
.y
= rect
->y
;
1533 dummyEvent
.width
= rect
->width
;
1534 dummyEvent
.height
= rect
->height
;
1540 dummyEvent
.width
= width
;
1541 dummyEvent
.height
= height
;
1543 dummyEvent
.count
= 0;
1547 wxClientDC
dc(this);
1548 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1549 dc
.SetBackground(backgroundBrush
);
1551 wxClientDCImpl
* const
1552 dcimpl
= static_cast<wxClientDCImpl
*>(dc
.GetImpl());
1554 dcimpl
->Clear(*rect
);
1559 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1562 void wxWindow::DoPaint()
1564 //TODO : make a temporary gc so we can do the XCopyArea below
1565 if (m_backingPixmap
&& !m_needsRefresh
)
1569 wxPaintDCImpl
* const
1570 dcimpl
= static_cast<wxPaintDCImpl
*>(dc
.GetImpl());
1572 GC tempGC
= (GC
) dcimpl
->GetBackingGC();
1574 Widget widget
= (Widget
) GetMainWidget();
1579 // We have to test whether it's a wxScrolledWindow (hack!) because
1580 // otherwise we don't know how many pixels have been scrolled. We might
1581 // solve this in the future by defining virtual wxWindow functions to get
1582 // the scroll position in pixels. Or, each kind of scrolled window has to
1583 // implement backing stores itself, using generic wxWidgets code.
1584 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1585 if ( scrolledWindow
)
1588 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1594 // TODO: This could be optimized further by only copying the areas in the
1595 // current update region.
1597 // Only blit the part visible in the client area. The backing pixmap
1598 // always starts at 0, 0 but we may be looking at only a portion of it.
1599 wxSize clientArea
= GetClientSize();
1600 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1601 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1603 // Copy whichever is samller, the amount of pixmap we have to copy,
1604 // or the size of the client area.
1605 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1606 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1608 // Make sure we're not negative
1609 toBlitX
= wxMax(0, toBlitX
);
1610 toBlitY
= wxMax(0, toBlitY
);
1615 (Pixmap
) m_backingPixmap
,
1618 scrollPosX
, scrollPosY
, // Start at the scroll position
1619 toBlitX
, toBlitY
, // How much of the pixmap to copy
1625 wxWindowDC
dc(this);
1626 // Set an erase event first
1627 wxEraseEvent
eraseEvent(GetId(), &dc
);
1628 eraseEvent
.SetEventObject(this);
1629 HandleWindowEvent(eraseEvent
);
1631 wxPaintEvent
event(GetId());
1632 event
.SetEventObject(this);
1633 HandleWindowEvent(event
);
1635 m_needsRefresh
= false;
1639 // ----------------------------------------------------------------------------
1641 // ----------------------------------------------------------------------------
1643 // Responds to colour changes: passes event on to children.
1644 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1646 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1649 // Only propagate to non-top-level windows
1650 wxWindow
*win
= node
->GetData();
1651 if ( win
->GetParent() )
1653 wxSysColourChangedEvent event2
;
1654 event
.SetEventObject(win
);
1655 win
->HandleWindowEvent(event2
);
1658 node
= node
->GetNext();
1662 void wxWindow::OnInternalIdle()
1664 // This calls the UI-update mechanism (querying windows for
1665 // menu/toolbar/control state information)
1666 if (wxUpdateUIEvent::CanUpdate(this) && IsShown())
1667 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1670 // ----------------------------------------------------------------------------
1672 // ----------------------------------------------------------------------------
1674 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1677 if (!m_acceleratorTable
.Ok())
1680 int count
= m_acceleratorTable
.GetCount();
1681 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1683 for (i
= 0; i
< count
; i
++)
1685 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1686 if (entry
->MatchesEvent(event
))
1688 // Bingo, we have a match. Now find a control that matches the
1689 // entry command id.
1691 // Need to go up to the top of the window hierarchy, since it might
1692 // be e.g. a menu item
1693 wxWindow
* parent
= this;
1694 while ( parent
&& !parent
->IsTopLevel() )
1695 parent
= parent
->GetParent();
1700 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1704 // Try for a menu command
1705 if (frame
->GetMenuBar())
1707 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1710 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1711 commandEvent
.SetEventObject(frame
);
1713 // If ProcessEvent returns true (it was handled), then
1714 // the calling code will skip the event handling.
1715 return frame
->HandleWindowEvent(commandEvent
);
1721 // Find a child matching the command id
1722 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1728 // Now we process those kinds of windows that we can.
1729 // For now, only buttons.
1730 if ( wxDynamicCast(child
, wxButton
) )
1732 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1733 commandEvent
.SetEventObject(child
);
1734 return child
->HandleWindowEvent(commandEvent
);
1742 // We didn't match the key event against an accelerator.
1746 // ============================================================================
1747 // Motif-specific stuff from here on
1748 // ============================================================================
1750 // ----------------------------------------------------------------------------
1751 // function which maintain the global hash table mapping Widgets to wxWidgets
1752 // ----------------------------------------------------------------------------
1754 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1756 const long key
= (long)w
;
1757 if ( wxWidgetHashTable
->Get(key
))
1759 wxLogDebug("Widget table clash: new widget is %ld, %s",
1760 key
, win
->GetClassInfo()->GetClassName());
1764 wxWidgetHashTable
->Put(key
, win
);
1766 wxLogTrace("widget", "Widget 0x%p <-> window %p (%s)",
1767 w
, win
, win
->GetClassInfo()->GetClassName());
1772 wxWindow
*wxGetWindowFromTable(Widget w
)
1774 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1777 void wxDeleteWindowFromTable(Widget w
)
1779 wxLogTrace("widget", "Widget 0x%p", (WXWidget
)w
);
1781 wxWidgetHashTable
->Delete((long)w
);
1784 // ----------------------------------------------------------------------------
1785 // add/remove window from the table
1786 // ----------------------------------------------------------------------------
1788 // Add to hash table, add event handler
1789 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1790 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1792 wxAddWindowToTable((Widget
) mainWidget
, this);
1793 XtAddEventHandler( (Widget
) mainWidget
,
1794 ButtonPressMask
| ButtonReleaseMask
1795 | PointerMotionMask
,
1797 wxPanelItemEventHandler
,
1803 XtOverrideTranslations ((Widget
) mainWidget
,
1804 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1805 XtFree ((char *) ptr
);
1808 // Some widgets have a parent form widget, e.g. wxRadioBox
1811 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1815 XtOverrideTranslations ((Widget
) formWidget
,
1816 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1817 XtFree ((char *) ptr
);
1824 DoSetSize (x
, y
, width
, height
, wxSIZE_USE_EXISTING
);
1829 // Remove event handler, remove from hash table
1830 bool wxWindow::DetachWidget(WXWidget widget
)
1832 XtRemoveEventHandler( (Widget
) widget
,
1833 ButtonPressMask
| ButtonReleaseMask
1834 | PointerMotionMask
,
1836 wxPanelItemEventHandler
,
1839 wxDeleteWindowFromTable((Widget
) widget
);
1843 // ----------------------------------------------------------------------------
1844 // Motif-specific accessors
1845 // ----------------------------------------------------------------------------
1847 WXWindow
wxWindow::GetClientXWindow() const
1849 Widget wMain
= (Widget
)GetClientWidget();
1851 return (WXWindow
) XtWindow(wMain
);
1853 return (WXWindow
) 0;
1856 // Get the underlying X window
1857 WXWindow
wxWindow::GetXWindow() const
1859 Widget wMain
= (Widget
)GetMainWidget();
1861 return (WXWindow
) XtWindow(wMain
);
1863 return (WXWindow
) 0;
1866 // Get the underlying X display
1867 WXDisplay
*wxWindow::GetXDisplay() const
1869 Widget wMain
= (Widget
)GetMainWidget();
1871 return (WXDisplay
*) XtDisplay(wMain
);
1873 return (WXDisplay
*) NULL
;
1876 WXWidget
wxWindow::GetMainWidget() const
1879 return m_drawingArea
;
1881 return m_mainWidget
;
1884 WXWidget
wxWindow::GetClientWidget() const
1886 if (m_drawingArea
!= (WXWidget
) 0)
1887 return m_drawingArea
;
1889 return GetMainWidget();
1892 WXWidget
wxWindow::GetTopWidget() const
1894 return GetMainWidget();
1897 WXWidget
wxWindow::GetLabelWidget() const
1899 return GetMainWidget();
1902 // ----------------------------------------------------------------------------
1904 // ----------------------------------------------------------------------------
1906 // All widgets should have this as their resize proc.
1907 // OnSize sent to wxWindow via client data.
1908 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
),
1909 String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1911 wxWindow
*win
= wxGetWindowFromTable(w
);
1915 if (win
->PreResize())
1917 wxSize
newSize(win
->GetSize());
1918 wxSizeEvent
sizeEvent(newSize
, win
->GetId());
1919 sizeEvent
.SetEventObject(win
);
1920 win
->HandleWindowEvent(sizeEvent
);
1924 static void wxCanvasRepaintProc(Widget drawingArea
,
1925 XtPointer clientData
,
1926 XmDrawingAreaCallbackStruct
* cbs
)
1928 if (!wxGetWindowFromTable(drawingArea
))
1931 XEvent
* event
= cbs
->event
;
1932 wxWindow
* win
= (wxWindow
*) clientData
;
1934 switch (event
->type
)
1938 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1939 event
->xexpose
.width
, event
->xexpose
.height
);
1941 if (event
-> xexpose
.count
== 0)
1950 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1951 static void wxCanvasEnterLeave(Widget drawingArea
,
1952 XtPointer
WXUNUSED(clientData
),
1953 XCrossingEvent
* event
)
1955 XmDrawingAreaCallbackStruct cbs
;
1958 ((XCrossingEvent
&) ev
) = *event
;
1960 cbs
.reason
= XmCR_INPUT
;
1963 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1966 // Fix to make it work under Motif 1.0 (!)
1967 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
),
1968 XButtonEvent
*WXUNUSED(event
))
1970 #if XmVersion <= 1000
1971 XmDrawingAreaCallbackStruct cbs
;
1974 ev
= *((XEvent
*) event
);
1975 cbs
.reason
= XmCR_INPUT
;
1978 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1979 #endif // XmVersion <= 1000
1982 static void wxCanvasInputEvent(Widget drawingArea
,
1983 XtPointer
WXUNUSED(data
),
1984 XmDrawingAreaCallbackStruct
* cbs
)
1986 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1987 XEvent
* xevent
= cbs
->event
;
1992 if (cbs
->reason
!= XmCR_INPUT
)
1995 switch (xevent
->xany
.type
)
2003 wxMouseEvent
wxevent(0);
2004 if (wxTranslateMouseEvent(wxevent
, canvas
, drawingArea
, xevent
))
2006 canvas
->HandleWindowEvent(wxevent
);
2012 wxKeyEvent
event (wxEVT_CHAR
);
2013 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, xevent
))
2015 // Implement wxFrame::OnCharHook by checking ancestor.
2016 wxWindow
*parent
= canvas
;
2017 while (parent
&& !parent
->IsTopLevel())
2018 parent
= parent
->GetParent();
2022 event
.SetEventType(wxEVT_CHAR_HOOK
);
2023 if (parent
->HandleWindowEvent(event
))
2027 // For simplicity, OnKeyDown is the same as OnChar
2028 // TODO: filter modifier key presses from OnChar
2029 event
.SetEventType(wxEVT_KEY_DOWN
);
2031 // Only process OnChar if OnKeyDown didn't swallow it
2032 if (!canvas
->HandleWindowEvent (event
))
2034 event
.SetEventType(wxEVT_CHAR
);
2035 canvas
->HandleWindowEvent (event
);
2042 wxKeyEvent
event (wxEVT_KEY_UP
);
2043 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, xevent
))
2045 canvas
->HandleWindowEvent (event
);
2051 if (xevent
->xfocus
.detail
!= NotifyPointer
)
2053 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2054 event
.SetEventObject(canvas
);
2055 canvas
->HandleWindowEvent(event
);
2061 if (xevent
->xfocus
.detail
!= NotifyPointer
)
2063 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2064 event
.SetEventObject(canvas
);
2065 canvas
->HandleWindowEvent(event
);
2074 static void wxPanelItemEventHandler(Widget wid
,
2075 XtPointer
WXUNUSED(client_data
),
2077 Boolean
*continueToDispatch
)
2079 // Widget can be a label or the actual widget.
2081 wxWindow
*window
= wxGetWindowFromTable(wid
);
2084 wxMouseEvent
wxevent(0);
2085 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2087 window
->HandleWindowEvent(wxevent
);
2091 // TODO: probably the key to allowing default behaviour to happen. Say we
2092 // set a m_doDefault flag to false at the start of this function. Then in
2093 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2094 // true, indicating that default processing can happen. Thus, behaviour can
2095 // appear to be overridden just by adding an event handler and not calling
2096 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2097 // way of handling drawing area events, to simplify things.
2098 *continueToDispatch
= True
;
2101 static void wxScrollBarCallback(Widget scrollbar
,
2102 XtPointer clientData
,
2103 XmScrollBarCallbackStruct
*cbs
)
2105 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2106 wxCHECK_RET( win
, _T("invalid widget in scrollbar callback") );
2108 wxOrientation orientation
= (wxOrientation
)wxPtrToUInt(clientData
);
2110 wxEventType eventType
= wxEVT_NULL
;
2111 switch (cbs
->reason
)
2113 case XmCR_INCREMENT
:
2115 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2118 case XmCR_DECREMENT
:
2120 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2125 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2128 case XmCR_VALUE_CHANGED
:
2130 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2133 case XmCR_PAGE_INCREMENT
:
2135 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2138 case XmCR_PAGE_DECREMENT
:
2140 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2145 eventType
= wxEVT_SCROLLWIN_TOP
;
2148 case XmCR_TO_BOTTOM
:
2150 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2155 // Should never get here
2156 wxFAIL_MSG("Unknown scroll event.");
2161 wxScrollWinEvent
event(eventType
,
2164 event
.SetEventObject( win
);
2165 win
->HandleWindowEvent(event
);
2168 // For repainting arbitrary windows
2169 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2171 wxWindow
* win
= wxGetWindowFromTable(w
);
2175 switch ( event
->type
)
2179 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2180 event
->xexpose
.width
, event
->xexpose
.height
);
2182 if ( event
->xexpose
.count
== 0 )
2192 // ----------------------------------------------------------------------------
2193 // TranslateXXXEvent() functions
2194 // ----------------------------------------------------------------------------
2196 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
,
2197 Widget widget
, const XEvent
*xevent
)
2199 switch (xevent
->xany
.type
)
2204 fprintf(stderr
, "Widget 0x%p <-> window %p (%s), %s\n",
2205 (WXWidget
)widget
, win
, win
->GetClassInfo()->GetClassName(),
2206 (xevent
->xany
.type
== EnterNotify
? "ENTER" : "LEAVE"));
2212 int eventx
= xevent
->xbutton
.x
, eventy
= xevent
->xbutton
.y
;
2214 wxEventType eventType
= wxEVT_NULL
;
2216 if (xevent
->xany
.type
== LeaveNotify
)
2218 eventType
= wxEVT_LEAVE_WINDOW
;
2220 if (xevent
->xany
.type
== EnterNotify
)
2222 eventType
= wxEVT_ENTER_WINDOW
;
2224 else if (xevent
->xany
.type
== MotionNotify
)
2226 eventType
= wxEVT_MOTION
;
2228 if (xevent
->xmotion
.is_hint
== NotifyHint
)
2233 Display
*dpy
= XtDisplay (widget
);
2235 XQueryPointer (dpy
, XtWindow (widget
),
2237 &x_root
, &y_root
, &eventx
, &eventy
, &state
);
2240 else if (xevent
->xany
.type
== ButtonPress
)
2242 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2244 if (xevent
->xbutton
.button
== Button1
)
2246 eventType
= wxEVT_LEFT_DOWN
;
2249 else if (xevent
->xbutton
.button
== Button2
)
2251 eventType
= wxEVT_MIDDLE_DOWN
;
2254 else if (xevent
->xbutton
.button
== Button3
)
2256 eventType
= wxEVT_RIGHT_DOWN
;
2260 // check for a double click
2262 long dclickTime
= XtGetMultiClickTime(xevent
->xany
.display
);
2263 long ts
= wxevent
.GetTimestamp();
2265 int buttonLast
= win
->GetLastClickedButton();
2266 long lastTS
= win
->GetLastClickTime();
2267 if ( buttonLast
&& buttonLast
== button
&&
2268 (ts
- lastTS
) < dclickTime
)
2271 win
->SetLastClick(0, ts
);
2272 if ( eventType
== wxEVT_LEFT_DOWN
)
2273 eventType
= wxEVT_LEFT_DCLICK
;
2274 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2275 eventType
= wxEVT_MIDDLE_DCLICK
;
2276 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2277 eventType
= wxEVT_RIGHT_DCLICK
;
2281 // not fast enough or different button
2282 win
->SetLastClick(button
, ts
);
2285 else if (xevent
->xany
.type
== ButtonRelease
)
2287 if (xevent
->xbutton
.button
== Button1
)
2289 eventType
= wxEVT_LEFT_UP
;
2291 else if (xevent
->xbutton
.button
== Button2
)
2293 eventType
= wxEVT_MIDDLE_UP
;
2295 else if (xevent
->xbutton
.button
== Button3
)
2297 eventType
= wxEVT_RIGHT_UP
;
2307 wxevent
.SetEventType(eventType
);
2310 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2313 win
->GetPosition(&x2
, &y2
);
2315 // The button x/y must be translated to wxWidgets
2316 // window space - the widget might be a label or button,
2320 if (widget
!= (Widget
)win
->GetMainWidget())
2326 wxevent
.m_x
= eventx
+ dx
;
2327 wxevent
.m_y
= eventy
+ dy
;
2329 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2330 || (event_left_is_down (xevent
)
2331 && (eventType
!= wxEVT_LEFT_UP
)));
2332 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2333 || (event_middle_is_down (xevent
)
2334 && (eventType
!= wxEVT_MIDDLE_UP
)));
2335 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2336 || (event_right_is_down (xevent
)
2337 && (eventType
!= wxEVT_RIGHT_UP
)));
2339 wxevent
.m_shiftDown
= (xevent
->xbutton
.state
& ShiftMask
) == ShiftMask
;
2340 wxevent
.m_controlDown
= (xevent
->xbutton
.state
& ControlMask
) == ControlMask
;
2341 wxevent
.m_altDown
= (xevent
->xbutton
.state
& Mod3Mask
) == Mod3Mask
;
2342 wxevent
.m_metaDown
= (xevent
->xbutton
.state
& Mod1Mask
) == Mod1Mask
;
2344 wxevent
.SetId(win
->GetId());
2345 wxevent
.SetEventObject(win
);
2353 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
,
2354 Widget
WXUNUSED(widget
), const XEvent
*xevent
)
2356 switch (xevent
->xany
.type
)
2364 (void) XLookupString((XKeyEvent
*)xevent
, buf
, 20, &keySym
, NULL
);
2365 int id
= wxCharCodeXToWX (keySym
);
2366 // id may be WXK_xxx code - these are outside ASCII range, so we
2367 // can't just use toupper() on id
2368 if (id
>= 'a' && id
<= 'z')
2371 if (xevent
->xkey
.state
& ShiftMask
)
2372 wxevent
.m_shiftDown
= true;
2373 if (xevent
->xkey
.state
& ControlMask
)
2374 wxevent
.m_controlDown
= true;
2375 if (xevent
->xkey
.state
& Mod3Mask
)
2376 wxevent
.m_altDown
= true;
2377 if (xevent
->xkey
.state
& Mod1Mask
)
2378 wxevent
.m_metaDown
= true;
2379 wxevent
.SetEventObject(win
);
2380 wxevent
.m_keyCode
= id
;
2381 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2383 wxevent
.m_x
= xevent
->xbutton
.x
;
2384 wxevent
.m_y
= xevent
->xbutton
.y
;
2397 // ----------------------------------------------------------------------------
2399 // ----------------------------------------------------------------------------
2401 #define YAllocColor XAllocColor
2402 XColor g_itemColors
[5];
2403 int wxComputeColours (Display
*display
, const wxColour
* back
, const wxColour
* fore
)
2406 static XmColorProc colorProc
;
2408 result
= wxNO_COLORS
;
2412 g_itemColors
[0].red
= (unsigned short)(((long) back
->Red ()) << 8);
2413 g_itemColors
[0].green
= (unsigned short)(((long) back
->Green ()) << 8);
2414 g_itemColors
[0].blue
= (unsigned short)(((long) back
->Blue ()) << 8);
2415 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2416 if (colorProc
== (XmColorProc
) NULL
)
2418 // Get a ptr to the actual function
2419 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2420 // And set it back to motif.
2421 XmSetColorCalculation (colorProc
);
2423 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2424 &g_itemColors
[wxFORE_INDEX
],
2425 &g_itemColors
[wxSELE_INDEX
],
2426 &g_itemColors
[wxTOPS_INDEX
],
2427 &g_itemColors
[wxBOTS_INDEX
]);
2428 result
= wxBACK_COLORS
;
2432 g_itemColors
[wxFORE_INDEX
].red
= (unsigned short)(((long) fore
->Red ()) << 8);
2433 g_itemColors
[wxFORE_INDEX
].green
= (unsigned short)(((long) fore
->Green ()) << 8);
2434 g_itemColors
[wxFORE_INDEX
].blue
= (unsigned short)(((long) fore
->Blue ()) << 8);
2435 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2436 if (result
== wxNO_COLORS
)
2437 result
= wxFORE_COLORS
;
2440 Display
*dpy
= display
;
2441 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2445 /* 5 Colours to allocate */
2446 for (int i
= 0; i
< 5; i
++)
2447 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2448 result
= wxNO_COLORS
;
2452 /* Only 1 colour to allocate */
2453 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2454 result
= wxNO_COLORS
;
2460 // Changes the foreground and background colours to be derived from the current
2461 // background colour. To change the foreground colour, you must call
2462 // SetForegroundColour explicitly.
2463 void wxWindow::ChangeBackgroundColour()
2465 WXWidget mainWidget
= GetMainWidget();
2467 wxDoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2468 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2469 wxDoChangeForegroundColour(m_scrolledWindow
, m_backgroundColour
);
2472 void wxWindow::ChangeForegroundColour()
2474 WXWidget mainWidget
= GetMainWidget();
2476 wxDoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2477 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2478 wxDoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2481 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2483 if ( !wxWindowBase::SetBackgroundColour(col
) )
2486 ChangeBackgroundColour();
2491 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2493 if ( !wxWindowBase::SetForegroundColour(col
) )
2496 ChangeForegroundColour();
2501 void wxWindow::ChangeFont(bool keepOriginalSize
)
2503 // Note that this causes the widget to be resized back
2504 // to its original size! We therefore have to set the size
2505 // back again. TODO: a better way in Motif?
2506 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2507 if (w
&& m_font
.Ok())
2509 int width
, height
, width1
, height1
;
2510 GetSize(& width
, & height
);
2512 wxDoChangeFont( w
, m_font
);
2514 GetSize(& width1
, & height1
);
2515 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2517 SetSize(wxDefaultCoord
, wxDefaultCoord
, width
, height
);
2523 void wxWindow::PostCreation()
2526 ChangeForegroundColour();
2527 ChangeBackgroundColour();
2531 void wxWindow::PreCreation()
2533 InheritAttributes();
2536 // ----------------------------------------------------------------------------
2538 // ----------------------------------------------------------------------------
2540 wxWindow
*wxGetActiveWindow()
2543 wxFAIL_MSG("Not implemented");
2548 wxWindow
*wxWindowBase::GetCapture()
2550 return (wxWindow
*)g_captureWindow
;
2554 // Find the wxWindow at the current mouse position, returning the mouse
2556 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2558 pt
= wxGetMousePosition();
2559 return wxFindWindowAtPoint(pt
);
2562 void wxGetMouseState(int& rootX
, int& rootY
, unsigned& maskReturn
)
2564 Display
*display
= wxGlobalDisplay();
2565 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2566 Window rootReturn
, childReturn
;
2569 XQueryPointer (display
,
2573 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
2576 // Get the current mouse position.
2577 wxPoint
wxGetMousePosition()
2582 wxGetMouseState(x
, y
, mask
);
2583 return wxPoint(x
, y
);
2586 wxMouseState
wxGetMouseState()
2592 wxGetMouseState(x
, y
, mask
);
2597 ms
.SetLeftDown(mask
& Button1Mask
);
2598 ms
.SetMiddleDown(mask
& Button2Mask
);
2599 ms
.SetRightDown(mask
& Button3Mask
);
2601 ms
.SetControlDown(mask
& ControlMask
);
2602 ms
.SetShiftDown(mask
& ShiftMask
);
2603 ms
.SetAltDown(mask
& Mod3Mask
);
2604 ms
.SetMetaDown(mask
& Mod1Mask
);
2610 #if wxMOTIF_NEW_FONT_HANDLING
2614 void wxGetTextExtent(const wxWindow
* window
, const wxString
& str
,
2615 int* width
, int* height
, int* ascent
, int* descent
)
2619 XmRendition rendition
= NULL
;
2620 XmRenderTable table
= NULL
;
2621 Widget w
= (Widget
) window
->GetLabelWidget();
2623 XtVaGetValues( w
, XmNrenderTable
, &table
, NULL
);
2625 table
= XmeGetDefaultRenderTable(w
, XmTEXT_RENDER_TABLE
);
2627 rendition
= XmRenderTableGetRendition( table
, "" );
2628 XtSetArg( args
[count
], XmNfont
, 0 ); ++count
;
2629 XtSetArg( args
[count
], XmNfontType
, 0 ); ++count
;
2630 XmRenditionRetrieve( rendition
, args
, count
);
2632 if (args
[1].value
== XmFONT_IS_FONTSET
)
2634 XRectangle ink
, logical
;
2635 WXFontSet fset
= (WXFontSet
) args
[0].value
;
2637 XmbTextExtents( (XFontSet
)fset
, str
.c_str(), str
.length(),
2640 if( width
) *width
= logical
.width
;
2641 if( height
) *height
= logical
.height
;
2642 if( ascent
) *ascent
= -logical
.y
;
2643 if( descent
) *descent
= logical
.height
+ logical
.y
;
2647 int direction
, ascent2
, descent2
;
2648 XCharStruct overall
;
2649 XFontStruct
* fontStruct
;
2651 XmeRenderTableGetDefaultFont( table
, &fontStruct
);
2652 XTextExtents(fontStruct
, (const char*)str
.c_str(), str
.length(),
2653 &direction
, &ascent2
, &descent2
, &overall
);
2655 if ( width
) *width
= overall
.width
;
2656 if ( height
) *height
= ascent2
+ descent2
;
2657 if ( descent
) *descent
= descent2
;
2658 if ( ascent
) *ascent
= ascent2
;
2662 #else // if !wxMOTIF_NEW_FONT_HANDLING
2664 void wxGetTextExtent(const wxWindow
* window
, const wxString
& str
,
2665 int* width
, int* height
, int* ascent
, int* descent
)
2667 XmFontList list
= NULL
;
2670 Widget w
= (Widget
) window
->GetLabelWidget();
2672 XtVaGetValues( w
, XmNfontList
, &list
, NULL
);
2673 XmFontListInitFontContext( &cxt
, list
);
2675 XmFontListEntry entry
= XmFontListNextEntry( cxt
);
2676 XmFontListFreeFontContext( cxt
);
2677 XtPointer thing
= XmFontListEntryGetFont( entry
, &type
);
2679 if (type
== XmFONT_IS_FONTSET
)
2681 XRectangle ink
, logical
;
2683 XmbTextExtents( (XFontSet
)thing
, str
.c_str(), str
.length(),
2686 if( width
) *width
= logical
.width
;
2687 if( height
) *height
= logical
.height
;
2688 if( ascent
) *ascent
= -logical
.y
;
2689 if( descent
) *descent
= logical
.height
+ logical
.y
;
2693 int direction
, ascent2
, descent2
;
2694 XCharStruct overall
;
2696 XTextExtents( (XFontStruct
*)thing
, (char*)(const char*)str
.c_str(), str
.length(),
2697 &direction
, &ascent2
, &descent2
, &overall
);
2699 if ( width
) *width
= overall
.width
;
2700 if ( height
) *height
= ascent2
+ descent2
;
2701 if ( descent
) *descent
= descent2
;
2702 if ( ascent
) *ascent
= ascent2
;
2706 #endif // !wxMOTIF_NEW_FONT_HANDLING
2708 // ----------------------------------------------------------------------------
2709 // wxNoOptimize: switch off size optimization
2710 // ----------------------------------------------------------------------------
2712 int wxNoOptimize::ms_count
= 0;