+// Get the current mouse position.
+wxPoint wxGetMousePosition()
+{
+ int x, y;
+ unsigned mask;
+
+ wxGetMouseState(x, y, mask);
+ return wxPoint(x, y);
+}
+
+wxMouseState wxGetMouseState()
+{
+ wxMouseState ms;
+ int x, y;
+ unsigned mask;
+
+ wxGetMouseState(x, y, mask);
+
+ ms.SetX(x);
+ ms.SetY(y);
+
+ ms.SetLeftDown(mask & Button1Mask);
+ ms.SetMiddleDown(mask & Button2Mask);
+ ms.SetRightDown(mask & Button3Mask);
+
+ ms.SetControlDown(mask & ControlMask);
+ ms.SetShiftDown(mask & ShiftMask);
+ ms.SetAltDown(mask & Mod3Mask);
+ ms.SetMetaDown(mask & Mod1Mask);
+
+ return ms;
+}
+
+
+#if wxMOTIF_NEW_FONT_HANDLING
+
+#include <Xm/XmP.h>
+
+void wxGetTextExtent(const wxWindow* window, const wxString& str,
+ int* width, int* height, int* ascent, int* descent)
+{
+ Arg args[2];
+ int count = 0;
+ XmRendition rendition = NULL;
+ XmRenderTable table = NULL;
+ Widget w = (Widget) window->GetLabelWidget();
+
+ XtVaGetValues( w, XmNrenderTable, &table, NULL );
+ if (table == NULL)
+ table = XmeGetDefaultRenderTable(w, XmTEXT_RENDER_TABLE);
+
+ rendition = XmRenderTableGetRendition( table, "" );
+ XtSetArg( args[count], XmNfont, 0 ); ++count;
+ XtSetArg( args[count], XmNfontType, 0 ); ++count;
+ XmRenditionRetrieve( rendition, args, count );
+
+ if (args[1].value == XmFONT_IS_FONTSET)
+ {
+ XRectangle ink, logical;
+ WXFontSet fset = (WXFontSet) args[0].value;
+
+ XmbTextExtents( (XFontSet)fset, str.c_str(), str.length(),
+ &ink, &logical);
+
+ if( width ) *width = logical.width;
+ if( height ) *height = logical.height;
+ if( ascent ) *ascent = -logical.y;
+ if( descent ) *descent = logical.height + logical.y;
+ }
+ else
+ {
+ int direction, ascent2, descent2;
+ XCharStruct overall;
+ XFontStruct* fontStruct;
+
+ XmeRenderTableGetDefaultFont( table, &fontStruct );
+ XTextExtents(fontStruct, (const char*)str.c_str(), str.length(),
+ &direction, &ascent2, &descent2, &overall);
+
+ if ( width ) *width = overall.width;
+ if ( height ) *height = ascent2 + descent2;
+ if ( descent ) *descent = descent2;
+ if ( ascent ) *ascent = ascent2;
+ }
+}
+
+#else // if !wxMOTIF_NEW_FONT_HANDLING
+
+void wxGetTextExtent(const wxWindow* window, const wxString& str,
+ int* width, int* height, int* ascent, int* descent)
+{
+ XmFontList list = NULL;
+ XmFontContext cxt;
+ XmFontType type;
+ Widget w = (Widget) window->GetLabelWidget();
+
+ XtVaGetValues( w, XmNfontList, &list, NULL );
+ XmFontListInitFontContext( &cxt, list );
+
+ XmFontListEntry entry = XmFontListNextEntry( cxt );
+ XmFontListFreeFontContext( cxt );
+ XtPointer thing = XmFontListEntryGetFont( entry, &type );
+
+ if (type == XmFONT_IS_FONTSET)
+ {
+ XRectangle ink, logical;
+
+ XmbTextExtents( (XFontSet)thing, str.c_str(), str.length(),
+ &ink, &logical);
+
+ if( width ) *width = logical.width;
+ if( height ) *height = logical.height;
+ if( ascent ) *ascent = -logical.y;
+ if( descent ) *descent = logical.height + logical.y;
+ }
+ else
+ {
+ int direction, ascent2, descent2;
+ XCharStruct overall;
+
+ XTextExtents( (XFontStruct*)thing, (char*)(const char*)str.c_str(), str.length(),
+ &direction, &ascent2, &descent2, &overall);
+
+ if ( width ) *width = overall.width;
+ if ( height ) *height = ascent2 + descent2;
+ if ( descent ) *descent = descent2;
+ if ( ascent ) *ascent = ascent2;
+ }
+}
+
+#endif // !wxMOTIF_NEW_FONT_HANDLING