1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/utils.cpp
3 // Purpose: Various utilities
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
29 #include "wx/apptrait.h"
31 #include "wx/dcmemory.h"
32 #include "wx/bitmap.h"
33 #include "wx/evtloop.h"
37 #if (defined(__SUNCC__) || defined(__CLCC__))
42 #pragma message disable nosimpint
45 #include "wx/unix/execute.h"
50 #include "wx/motif/private.h"
53 #include "X11/Xresource.h"
56 #include "X11/Xutil.h"
59 #pragma message enable nosimpint
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // Yuck this is really BOTH site and platform dependent
67 // so we should use some other strategy!
69 #define DEFAULT_XRESOURCE_DIR "/usr/openwin/lib/app-defaults"
71 #define DEFAULT_XRESOURCE_DIR "/usr/lib/X11/app-defaults"
75 static char *GetIniFile (char *dest
, const char *filename
);
78 // ============================================================================
80 // ============================================================================
82 // ----------------------------------------------------------------------------
83 // async event processing
84 // ----------------------------------------------------------------------------
86 // Consume all events until no more left
87 void wxFlushEvents(WXDisplay
* wxdisplay
)
89 Display
*display
= (Display
*)wxdisplay
;
92 XSync (display
, False
);
94 while (evtLoop
.Pending())
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 static void xt_notify_end_process(XtPointer data
, int *WXUNUSED(fid
),
108 wxEndProcessData
*proc_data
= (wxEndProcessData
*)data
;
110 wxHandleProcessTermination(proc_data
);
112 // VZ: I think they should be the same...
113 wxASSERT( (int)*id
== proc_data
->tag
);
118 int wxAddProcessCallback(wxEndProcessData
*proc_data
, int fd
)
120 XtInputId id
= XtAppAddInput((XtAppContext
) wxTheApp
->GetAppContext(),
122 (XtPointer
*) XtInputReadMask
,
123 (XtInputCallbackProc
) xt_notify_end_process
,
124 (XtPointer
) proc_data
);
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
135 // on OS/2, we use the wxBell from wxBase library (src/os2/utils.cpp)
138 // Use current setting for the bell
139 XBell (wxGlobalDisplay(), 0);
143 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
145 static wxToolkitInfo info
;
147 info
.shortName
= _T("motif");
148 info
.name
= _T("wxMotif");
149 #ifdef __WXUNIVERSAL__
150 info
.shortName
<< _T("univ");
151 info
.name
<< _T("/wxUniversal");
154 // This code is WRONG!! Does NOT return the
155 // Motif version of the libs but the X protocol
157 Display
*display
= wxGlobalDisplay();
160 info
.versionMajor
= ProtocolVersion (display
);
161 info
.versionMinor
= ProtocolRevision (display
);
167 // ----------------------------------------------------------------------------
168 // Reading and writing resources (eg WIN.INI, .Xdefaults)
169 // ----------------------------------------------------------------------------
173 // Read $HOME for what it says is home, if not
174 // read $USER or $LOGNAME for user name else determine
175 // the Real User, then determine the Real home dir.
176 static char * GetIniFile (char *dest
, const char *filename
)
179 if (filename
&& wxIsAbsolutePath(filename
))
181 strcpy(dest
, filename
);
183 else if ((home
= wxGetUserHome()) != NULL
)
186 if (dest
[strlen(dest
) - 1] != '/')
188 if (filename
== NULL
)
190 if ((filename
= getenv ("XENVIRONMENT")) == NULL
)
191 filename
= ".Xdefaults";
193 else if (*filename
!= '.')
195 strcat (dest
, filename
);
203 static char *GetResourcePath(char *buf
, const char *name
, bool create
= false)
205 if (create
&& wxFileExists (name
) ) {
207 return buf
; // Exists so ...
213 // Put in standard place for resource files if not absolute
214 strcpy (buf
, DEFAULT_XRESOURCE_DIR
);
216 strcat (buf
, wxFileNameFromPath (name
).c_str());
220 // Touch the file to create it
221 FILE *fd
= fopen (buf
, "w");
228 * We have a cache for writing different resource files,
229 * which will only get flushed when we call wxFlushResources().
230 * Build up a list of resource databases waiting to be written.
234 wxList
wxResourceCache (wxKEY_STRING
);
237 wxFlushResources (void)
239 char nameBuffer
[512];
241 wxNode
*node
= wxResourceCache
.First ();
244 const char *file
= node
->GetKeyString();
245 // If file doesn't exist, create it first.
246 (void)GetResourcePath(nameBuffer
, file
, true);
248 XrmDatabase database
= (XrmDatabase
) node
->Data ();
249 XrmPutFileDatabase (database
, nameBuffer
);
250 XrmDestroyDatabase (database
);
251 wxNode
*next
= node
->Next ();
257 static XrmDatabase wxResourceDatabase
= 0;
259 void wxXMergeDatabases (wxApp
* theApp
, Display
* display
);
261 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
265 (void) GetIniFile (buffer
, file
);
267 XrmDatabase database
;
268 wxNode
*node
= wxResourceCache
.Find (buffer
);
270 database
= (XrmDatabase
) node
->Data ();
273 database
= XrmGetFileDatabase (buffer
);
274 wxResourceCache
.Append (buffer
, (wxObject
*) database
);
278 strcpy (resName
, section
.c_str());
279 strcat (resName
, ".");
280 strcat (resName
, entry
.c_str());
282 XrmPutStringResource (&database
, resName
, value
);
286 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
289 sprintf(buf
, "%.4f", value
);
290 return wxWriteResource(section
, entry
, buf
, file
);
293 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
296 sprintf(buf
, "%ld", value
);
297 return wxWriteResource(section
, entry
, buf
, file
);
300 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
303 sprintf(buf
, "%d", value
);
304 return wxWriteResource(section
, entry
, buf
, file
);
307 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
309 if (!wxResourceDatabase
)
311 Display
*display
= wxGlobalDisplay();
312 wxXMergeDatabases (wxTheApp
, display
);
315 XrmDatabase database
;
321 // Is this right? Trying to get it to look in the user's
322 // home directory instead of current directory -- JACS
323 (void) GetIniFile (buffer
, file
);
325 wxNode
*node
= wxResourceCache
.Find (buffer
);
327 database
= (XrmDatabase
) node
->Data ();
330 database
= XrmGetFileDatabase (buffer
);
331 wxResourceCache
.Append (buffer
, (wxObject
*) database
);
335 database
= wxResourceDatabase
;
340 strcpy (buf
, section
);
344 Bool success
= XrmGetResource (database
, buf
, "*", str_type
,
346 // Try different combinations of upper/lower case, just in case...
349 buf
[0] = (isupper (buf
[0]) ? tolower (buf
[0]) : toupper (buf
[0]));
350 success
= XrmGetResource (database
, buf
, "*", str_type
,
358 *value
= new char[xvalue
.size
+ 1];
359 strncpy (*value
, xvalue
.addr
, (int) xvalue
.size
);
365 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
368 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
371 *value
= (float)strtod(s
, NULL
);
378 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
381 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
384 *value
= strtol(s
, NULL
, 10);
391 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
394 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
397 // Handle True, False here
398 // True, Yes, Enables, Set or Activated
399 if (*s
== 'T' || *s
== 'Y' || *s
== 'E' || *s
== 'S' || *s
== 'A')
401 // False, No, Disabled, Reset, Cleared, Deactivated
402 else if (*s
== 'F' || *s
== 'N' || *s
== 'D' || *s
== 'R' || *s
== 'C')
406 *value
= (int) strtol (s
, NULL
, 10);
414 void wxXMergeDatabases (wxApp
* theApp
, Display
* display
)
416 XrmDatabase homeDB
, serverDB
, applicationDB
;
417 char filenamebuf
[1024];
419 char *filename
= &filenamebuf
[0];
421 wxString classname
= theApp
->GetClassName();
423 (void) strcpy (name
, "/usr/lib/X11/app-defaults/");
424 (void) strcat (name
, classname
.c_str());
426 /* Get application defaults file, if any */
427 applicationDB
= XrmGetFileDatabase (name
);
428 (void) XrmMergeDatabases (applicationDB
, &wxResourceDatabase
);
430 /* Merge server defaults, created by xrdb, loaded as a property of the root
431 * window when the server initializes and loaded into the display
432 * structure on XOpenDisplay;
433 * if not defined, use .Xdefaults
436 if (XResourceManagerString (display
) != NULL
)
438 serverDB
= XrmGetStringDatabase (XResourceManagerString (display
));
442 (void) GetIniFile (filename
, NULL
);
443 serverDB
= XrmGetFileDatabase (filename
);
445 XrmMergeDatabases (serverDB
, &wxResourceDatabase
);
447 /* Open XENVIRONMENT file, or if not defined, the .Xdefaults,
448 * and merge into existing database
451 if ((environment
= getenv ("XENVIRONMENT")) == NULL
)
454 environment
= GetIniFile (filename
, NULL
);
455 len
= strlen (environment
);
456 wxString hostname
= wxGetHostName();
457 if ( !hostname
.empty() )
458 strncat(environment
, hostname
, 1024 - len
);
460 homeDB
= XrmGetFileDatabase (environment
);
461 XrmMergeDatabases (homeDB
, &wxResourceDatabase
);
467 * Not yet used but may be useful.
471 wxSetDefaultResources (const Widget w
, const char **resourceSpec
, const char *name
)
474 Display
*dpy
= XtDisplay (w
); // Retrieve the display pointer
476 XrmDatabase rdb
= NULL
; // A resource data base
478 // Create an empty resource database
479 rdb
= XrmGetStringDatabase ("");
481 // Add the Component resources, prepending the name of the component
484 while (resourceSpec
[i
] != NULL
)
488 sprintf (buf
, "*%s%s", name
, resourceSpec
[i
++]);
489 XrmPutLineResource (&rdb
, buf
);
492 // Merge them into the Xt database, with lowest precendence
496 #if (XlibSpecificationRelease>=5)
497 XrmDatabase db
= XtDatabase (dpy
);
498 XrmCombineDatabase (rdb
, &db
, False
);
500 XrmMergeDatabases (dpy
->db
, &rdb
);
508 #endif // wxUSE_RESOURCES
510 // ----------------------------------------------------------------------------
512 // ----------------------------------------------------------------------------
514 void wxGetMousePosition( int* x
, int* y
)
523 XQueryPointer(wxGlobalDisplay(),
524 DefaultRootWindow(wxGlobalDisplay()),
526 &(xev
.x_root
), &(xev
.y_root
),
534 // Return true if we have a colour display
535 bool wxColourDisplay()
537 return wxDisplayDepth() > 1;
540 // Returns depth of screen
543 Display
*dpy
= wxGlobalDisplay();
545 return DefaultDepth (dpy
, DefaultScreen (dpy
));
548 // Get size of display
549 void wxDisplaySize(int *width
, int *height
)
551 Display
*dpy
= wxGlobalDisplay();
554 *width
= DisplayWidth (dpy
, DefaultScreen (dpy
));
556 *height
= DisplayHeight (dpy
, DefaultScreen (dpy
));
559 void wxDisplaySizeMM(int *width
, int *height
)
561 Display
*dpy
= wxGlobalDisplay();
564 *width
= DisplayWidthMM(dpy
, DefaultScreen (dpy
));
566 *height
= DisplayHeightMM(dpy
, DefaultScreen (dpy
));
569 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
571 // This is supposed to return desktop dimensions minus any window
572 // manager panels, menus, taskbars, etc. If there is a way to do that
573 // for this platform please fix this function, otherwise it defaults
574 // to the entire desktop.
577 wxDisplaySize(width
, height
);
581 // Configurable display in wxX11 and wxMotif
582 static WXDisplay
*gs_currentDisplay
= NULL
;
583 static wxString gs_displayName
;
585 WXDisplay
*wxGetDisplay()
587 if (gs_currentDisplay
)
588 return gs_currentDisplay
;
590 return wxTheApp
->GetInitialDisplay();
594 bool wxSetDisplay(const wxString
& display_name
)
596 gs_displayName
= display_name
;
598 if ( display_name
.empty() )
600 gs_currentDisplay
= NULL
;
608 Display
*display
= XtOpenDisplay((XtAppContext
) wxTheApp
->GetAppContext(),
609 display_name
.c_str(),
610 wxTheApp
->GetAppName().c_str(),
611 wxTheApp
->GetClassName().c_str(),
613 #if XtSpecificationRelease < 5
622 gs_currentDisplay
= (WXDisplay
*) display
;
630 wxString
wxGetDisplayName()
632 return gs_displayName
;
635 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
637 return wxGenericFindWindowAtPoint(pt
);
640 // ----------------------------------------------------------------------------
641 // Some colour manipulation routines
642 // ----------------------------------------------------------------------------
644 void wxHSVToXColor(wxHSV
*hsv
,XColor
*rgb
)
649 int r
= 0, g
= 0, b
= 0;
652 s
= (s
* wxMAX_RGB
) / wxMAX_SV
;
653 v
= (v
* wxMAX_RGB
) / wxMAX_SV
;
655 if (s
== 0) { h
= 0; r
= g
= b
= v
; }
658 p
= v
* (wxMAX_RGB
- s
) / wxMAX_RGB
;
659 q
= v
* (wxMAX_RGB
- s
* f
/ 60) / wxMAX_RGB
;
660 t
= v
* (wxMAX_RGB
- s
* (60 - f
) / 60) / wxMAX_RGB
;
663 case 0: r
= v
, g
= t
, b
= p
; break;
664 case 1: r
= q
, g
= v
, b
= p
; break;
665 case 2: r
= p
, g
= v
, b
= t
; break;
666 case 3: r
= p
, g
= q
, b
= v
; break;
667 case 4: r
= t
, g
= p
, b
= v
; break;
668 case 5: r
= v
, g
= p
, b
= q
; break;
670 rgb
->red
= (unsigned short)(r
<< 8);
671 rgb
->green
= (unsigned short)(g
<< 8);
672 rgb
->blue
= (unsigned short)(b
<< 8);
675 void wxXColorToHSV(wxHSV
*hsv
,XColor
*rgb
)
677 int r
= rgb
->red
>> 8;
678 int g
= rgb
->green
>> 8;
679 int b
= rgb
->blue
>> 8;
680 int maxv
= wxMax3(r
, g
, b
);
681 int minv
= wxMin3(r
, g
, b
);
684 if (maxv
) s
= (maxv
- minv
) * wxMAX_RGB
/ maxv
;
689 int rc
, gc
, bc
, hex
= 0;
690 rc
= (maxv
- r
) * wxMAX_RGB
/ (maxv
- minv
);
691 gc
= (maxv
- g
) * wxMAX_RGB
/ (maxv
- minv
);
692 bc
= (maxv
- b
) * wxMAX_RGB
/ (maxv
- minv
);
693 if (r
== maxv
) { h
= bc
- gc
, hex
= 0; }
694 else if (g
== maxv
) { h
= rc
- bc
, hex
= 2; }
695 else if (b
== maxv
) { h
= gc
- rc
, hex
= 4; }
696 h
= hex
* 60 + (h
* 60 / wxMAX_RGB
);
700 hsv
->s
= (s
* wxMAX_SV
) / wxMAX_RGB
;
701 hsv
->v
= (v
* wxMAX_SV
) / wxMAX_RGB
;
704 void wxAllocNearestColor(Display
*d
,Colormap cmp
,XColor
*xc
)
709 int screen
= DefaultScreen(d
);
710 int num_colors
= DisplayCells(d
,screen
);
712 XColor
*color_defs
= new XColor
[num_colors
];
713 for(llp
= 0;llp
< num_colors
;llp
++) color_defs
[llp
].pixel
= llp
;
714 XQueryColors(d
,cmp
,color_defs
,num_colors
);
717 wxXColorToHSV(&hsv
,xc
);
719 int diff
, min_diff
= 0, pixel
= 0;
721 for(llp
= 0;llp
< num_colors
;llp
++)
723 wxXColorToHSV(&hsv_defs
,&color_defs
[llp
]);
724 diff
= wxSIGN(wxH_WEIGHT
* (hsv
.h
- hsv_defs
.h
)) +
725 wxSIGN(wxS_WEIGHT
* (hsv
.s
- hsv_defs
.s
)) +
726 wxSIGN(wxV_WEIGHT
* (hsv
.v
- hsv_defs
.v
));
727 if (llp
== 0) min_diff
= diff
;
728 if (min_diff
> diff
) { min_diff
= diff
; pixel
= llp
; }
729 if (min_diff
== 0) break;
732 xc
-> red
= color_defs
[pixel
].red
;
733 xc
-> green
= color_defs
[pixel
].green
;
734 xc
-> blue
= color_defs
[pixel
].blue
;
735 xc
-> flags
= DoRed
| DoGreen
| DoBlue
;
738 if (!XAllocColor(d,cmp,xc))
739 cout << "wxAllocNearestColor : Warning : Cannot find nearest color !\n";
746 void wxAllocColor(Display
*d
,Colormap cmp
,XColor
*xc
)
748 if (!XAllocColor(d
,cmp
,xc
))
750 // cout << "wxAllocColor : Warning : Can not allocate color, attempt find nearest !\n";
751 wxAllocNearestColor(d
,cmp
,xc
);
756 wxString
wxGetXEventName(XEvent
& event
)
759 wxString
str(wxT("(some event)"));
762 int type
= event
.xany
.type
;
763 static char* event_name
[] = {
764 wxMOTIF_STR(""), wxMOTIF_STR("unknown(-)"), // 0-1
765 wxMOTIF_STR("KeyPress"), wxMOTIF_STR("KeyRelease"), wxMOTIF_STR("ButtonPress"), wxMOTIF_STR("ButtonRelease"), // 2-5
766 wxMOTIF_STR("MotionNotify"), wxMOTIF_STR("EnterNotify"), wxMOTIF_STR("LeaveNotify"), wxMOTIF_STR("FocusIn"), // 6-9
767 wxMOTIF_STR("FocusOut"), wxMOTIF_STR("KeymapNotify"), wxMOTIF_STR("Expose"), wxMOTIF_STR("GraphicsExpose"), // 10-13
768 wxMOTIF_STR("NoExpose"), wxMOTIF_STR("VisibilityNotify"), wxMOTIF_STR("CreateNotify"), // 14-16
769 wxMOTIF_STR("DestroyNotify"), wxMOTIF_STR("UnmapNotify"), wxMOTIF_STR("MapNotify"), wxMOTIF_STR("MapRequest"),// 17-20
770 wxMOTIF_STR("ReparentNotify"), wxMOTIF_STR("ConfigureNotify"), wxMOTIF_STR("ConfigureRequest"), // 21-23
771 wxMOTIF_STR("GravityNotify"), wxMOTIF_STR("ResizeRequest"), wxMOTIF_STR("CirculateNotify"), // 24-26
772 wxMOTIF_STR("CirculateRequest"), wxMOTIF_STR("PropertyNotify"), wxMOTIF_STR("SelectionClear"), // 27-29
773 wxMOTIF_STR("SelectionRequest"), wxMOTIF_STR("SelectionNotify"), wxMOTIF_STR("ColormapNotify"), // 30-32
774 wxMOTIF_STR("ClientMessage"), wxMOTIF_STR("MappingNotify"), // 33-34
775 wxMOTIF_STR("unknown(+)")}; // 35
776 type
= wxMin(35, type
); type
= wxMax(1, type
);
777 wxString
str(event_name
[type
]);
783 // ----------------------------------------------------------------------------
785 // ----------------------------------------------------------------------------
787 // Find the letter corresponding to the mnemonic, for Motif
788 char wxFindMnemonic (const char *s
)
791 int len
= strlen (s
);
794 for (i
= 0; i
< len
; i
++)
798 // Carefully handle &&
799 if ((i
+ 1) <= len
&& s
[i
+ 1] == '&')
811 char* wxFindAccelerator( const char *s
)
815 // VZ: this function returns incorrect keysym which completely breaks kbd
819 // The accelerator text is after the \t char.
820 s
= strchr( s
, '\t' );
822 if( !s
) return NULL
;
825 Now we need to format it as X standard:
830 Ctrl+N --> Ctrl<Key>N
832 Ctrl+Shift+A --> Ctrl Shift<Key>A
834 and handle Ctrl-N & similia
837 static char buf
[256];
840 wxString tmp
= s
+ 1; // skip TAB
843 while( index
< tmp
.length() )
845 size_t plus
= tmp
.find( '+', index
);
846 size_t minus
= tmp
.find( '-', index
);
848 // neither '+' nor '-', add <Key>
849 if( plus
== wxString::npos
&& minus
== wxString::npos
)
851 strcat( buf
, "<Key>" );
852 strcat( buf
, tmp
.c_str() + index
);
857 // OK: npos is big and positive
858 size_t sep
= wxMin( plus
, minus
);
859 wxString mod
= tmp
.substr( index
, sep
- index
);
870 strcat( buf
, mod
.c_str() );
879 XmString
wxFindAcceleratorText (const char *s
)
883 // VZ: this function returns incorrect keysym which completely breaks kbd
887 // The accelerator text is after the \t char.
888 s
= strchr( s
, '\t' );
890 if( !s
) return NULL
;
892 return wxStringToXmString( s
+ 1 ); // skip TAB!
896 // Change a widget's foreground and background colours.
897 void wxDoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
899 // When should we specify the foreground, if it's calculated
900 // by wxComputeColours?
901 // Solution: say we start with the default (computed) foreground colour.
902 // If we call SetForegroundColour explicitly for a control or window,
903 // then the foreground is changed.
904 // Therefore SetBackgroundColour computes the foreground colour, and
905 // SetForegroundColour changes the foreground colour. The ordering is
908 XtVaSetValues ((Widget
) widget
,
909 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
913 void wxDoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
915 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
918 XtVaSetValues ((Widget
) widget
,
919 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
920 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
921 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
922 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
926 XtVaSetValues ((Widget
) widget
,
927 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
931 extern void wxDoChangeFont(WXWidget widget
, const wxFont
& font
)
933 // Lesstif 0.87 hangs here, but 0.93 does not; MBN: sometimes it does
934 #if !wxCHECK_LESSTIF() // || wxCHECK_LESSTIF_VERSION( 0, 93 )
935 Widget w
= (Widget
)widget
;
937 wxFont::GetFontTag(), font
.GetFontTypeC( XtDisplay(w
) ),
946 wxString
wxXmStringToString( const XmString
& xmString
)
949 if( XmStringGetLtoR( xmString
, XmSTRING_DEFAULT_CHARSET
, &txt
) )
956 return wxEmptyString
;
959 XmString
wxStringToXmString( const wxString
& str
)
961 return XmStringCreateLtoR((char *)str
.c_str(), XmSTRING_DEFAULT_CHARSET
);
964 XmString
wxStringToXmString( const char* str
)
966 return XmStringCreateLtoR((char *)str
, XmSTRING_DEFAULT_CHARSET
);
969 // ----------------------------------------------------------------------------
970 // wxBitmap utility functions
971 // ----------------------------------------------------------------------------
973 // Creates a bitmap with transparent areas drawn in
975 wxBitmap
wxCreateMaskedBitmap(const wxBitmap
& bitmap
, const wxColour
& colour
)
977 wxBitmap
newBitmap(bitmap
.GetWidth(),
983 srcDC
.SelectObject(bitmap
);
984 destDC
.SelectObject(newBitmap
);
986 wxBrush
brush(colour
, wxSOLID
);
987 destDC
.SetBackground(brush
);
989 destDC
.Blit(0, 0, bitmap
.GetWidth(), bitmap
.GetHeight(),
990 &srcDC
, 0, 0, wxCOPY
, true);
995 // ----------------------------------------------------------------------------
996 // Miscellaneous functions
997 // ----------------------------------------------------------------------------
999 WXWidget
wxCreateBorderWidget( WXWidget parent
, long style
)
1001 Widget borderWidget
= (Widget
)NULL
, parentWidget
= (Widget
)parent
;
1003 if (style
& wxSIMPLE_BORDER
)
1005 borderWidget
= XtVaCreateManagedWidget
1008 xmFrameWidgetClass
, parentWidget
,
1009 XmNshadowType
, XmSHADOW_ETCHED_IN
,
1010 XmNshadowThickness
, 1,
1014 else if (style
& wxSUNKEN_BORDER
)
1016 borderWidget
= XtVaCreateManagedWidget
1019 xmFrameWidgetClass
, parentWidget
,
1020 XmNshadowType
, XmSHADOW_IN
,
1024 else if (style
& wxRAISED_BORDER
)
1026 borderWidget
= XtVaCreateManagedWidget
1029 xmFrameWidgetClass
, parentWidget
,
1030 XmNshadowType
, XmSHADOW_OUT
,
1035 return borderWidget
;