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
28 #include "wx/apptrait.h"
30 #include "wx/dcmemory.h"
31 #include "wx/bitmap.h"
32 #include "wx/evtloop.h"
36 #if (defined(__SUNCC__) || defined(__CLCC__))
41 #pragma message disable nosimpint
44 #include "wx/unix/execute.h"
49 #include "wx/motif/private.h"
52 #include "X11/Xresource.h"
55 #include "X11/Xutil.h"
58 #pragma message enable nosimpint
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 // Yuck this is really BOTH site and platform dependent
66 // so we should use some other strategy!
68 #define DEFAULT_XRESOURCE_DIR "/usr/openwin/lib/app-defaults"
70 #define DEFAULT_XRESOURCE_DIR "/usr/lib/X11/app-defaults"
74 static char *GetIniFile (char *dest
, const char *filename
);
77 // ============================================================================
79 // ============================================================================
81 // ----------------------------------------------------------------------------
82 // async event processing
83 // ----------------------------------------------------------------------------
85 // Consume all events until no more left
86 void wxFlushEvents(WXDisplay
* wxdisplay
)
88 Display
*display
= (Display
*)wxdisplay
;
91 XSync (display
, False
);
93 while (evtLoop
.Pending())
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 static void xt_notify_end_process(XtPointer data
, int *WXUNUSED(fid
),
107 wxEndProcessData
*proc_data
= (wxEndProcessData
*)data
;
109 wxHandleProcessTermination(proc_data
);
111 // VZ: I think they should be the same...
112 wxASSERT( (int)*id
== proc_data
->tag
);
117 int wxAddProcessCallback(wxEndProcessData
*proc_data
, int fd
)
119 XtInputId id
= XtAppAddInput((XtAppContext
) wxTheApp
->GetAppContext(),
121 (XtPointer
*) XtInputReadMask
,
122 (XtInputCallbackProc
) xt_notify_end_process
,
123 (XtPointer
) proc_data
);
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
134 // on OS/2, we use the wxBell from wxBase library (src/os2/utils.cpp)
137 // Use current setting for the bell
138 XBell (wxGlobalDisplay(), 0);
142 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
144 static wxToolkitInfo info
;
146 info
.shortName
= _T("motif");
147 info
.name
= _T("wxMotif");
148 #ifdef __WXUNIVERSAL__
149 info
.shortName
<< _T("univ");
150 info
.name
<< _T("/wxUniversal");
153 // This code is WRONG!! Does NOT return the
154 // Motif version of the libs but the X protocol
156 Display
*display
= wxGlobalDisplay();
159 info
.versionMajor
= ProtocolVersion (display
);
160 info
.versionMinor
= ProtocolRevision (display
);
166 // ----------------------------------------------------------------------------
167 // Reading and writing resources (eg WIN.INI, .Xdefaults)
168 // ----------------------------------------------------------------------------
172 // Read $HOME for what it says is home, if not
173 // read $USER or $LOGNAME for user name else determine
174 // the Real User, then determine the Real home dir.
175 static char * GetIniFile (char *dest
, const char *filename
)
178 if (filename
&& wxIsAbsolutePath(filename
))
180 strcpy(dest
, filename
);
182 else if ((home
= wxGetUserHome()) != NULL
)
185 if (dest
[strlen(dest
) - 1] != '/')
187 if (filename
== NULL
)
189 if ((filename
= getenv ("XENVIRONMENT")) == NULL
)
190 filename
= ".Xdefaults";
192 else if (*filename
!= '.')
194 strcat (dest
, filename
);
202 static char *GetResourcePath(char *buf
, const char *name
, bool create
= false)
204 if (create
&& wxFileExists (name
) ) {
206 return buf
; // Exists so ...
212 // Put in standard place for resource files if not absolute
213 strcpy (buf
, DEFAULT_XRESOURCE_DIR
);
215 strcat (buf
, wxFileNameFromPath (name
).c_str());
219 // Touch the file to create it
220 FILE *fd
= fopen (buf
, "w");
227 * We have a cache for writing different resource files,
228 * which will only get flushed when we call wxFlushResources().
229 * Build up a list of resource databases waiting to be written.
233 wxList
wxResourceCache (wxKEY_STRING
);
236 wxFlushResources (void)
238 char nameBuffer
[512];
240 wxNode
*node
= wxResourceCache
.First ();
243 const char *file
= node
->GetKeyString();
244 // If file doesn't exist, create it first.
245 (void)GetResourcePath(nameBuffer
, file
, true);
247 XrmDatabase database
= (XrmDatabase
) node
->Data ();
248 XrmPutFileDatabase (database
, nameBuffer
);
249 XrmDestroyDatabase (database
);
250 wxNode
*next
= node
->Next ();
256 static XrmDatabase wxResourceDatabase
= 0;
258 void wxXMergeDatabases (wxApp
* theApp
, Display
* display
);
260 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
264 (void) GetIniFile (buffer
, file
);
266 XrmDatabase database
;
267 wxNode
*node
= wxResourceCache
.Find (buffer
);
269 database
= (XrmDatabase
) node
->Data ();
272 database
= XrmGetFileDatabase (buffer
);
273 wxResourceCache
.Append (buffer
, (wxObject
*) database
);
277 strcpy (resName
, section
.c_str());
278 strcat (resName
, ".");
279 strcat (resName
, entry
.c_str());
281 XrmPutStringResource (&database
, resName
, value
);
285 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
288 sprintf(buf
, "%.4f", value
);
289 return wxWriteResource(section
, entry
, buf
, file
);
292 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
295 sprintf(buf
, "%ld", value
);
296 return wxWriteResource(section
, entry
, buf
, file
);
299 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
302 sprintf(buf
, "%d", value
);
303 return wxWriteResource(section
, entry
, buf
, file
);
306 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
308 if (!wxResourceDatabase
)
310 Display
*display
= wxGlobalDisplay();
311 wxXMergeDatabases (wxTheApp
, display
);
314 XrmDatabase database
;
320 // Is this right? Trying to get it to look in the user's
321 // home directory instead of current directory -- JACS
322 (void) GetIniFile (buffer
, file
);
324 wxNode
*node
= wxResourceCache
.Find (buffer
);
326 database
= (XrmDatabase
) node
->Data ();
329 database
= XrmGetFileDatabase (buffer
);
330 wxResourceCache
.Append (buffer
, (wxObject
*) database
);
334 database
= wxResourceDatabase
;
339 strcpy (buf
, section
);
343 Bool success
= XrmGetResource (database
, buf
, "*", str_type
,
345 // Try different combinations of upper/lower case, just in case...
348 buf
[0] = (isupper (buf
[0]) ? tolower (buf
[0]) : toupper (buf
[0]));
349 success
= XrmGetResource (database
, buf
, "*", str_type
,
357 *value
= new char[xvalue
.size
+ 1];
358 strncpy (*value
, xvalue
.addr
, (int) xvalue
.size
);
364 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
367 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
370 *value
= (float)strtod(s
, NULL
);
377 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
380 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
383 *value
= strtol(s
, NULL
, 10);
390 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
393 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
396 // Handle True, False here
397 // True, Yes, Enables, Set or Activated
398 if (*s
== 'T' || *s
== 'Y' || *s
== 'E' || *s
== 'S' || *s
== 'A')
400 // False, No, Disabled, Reset, Cleared, Deactivated
401 else if (*s
== 'F' || *s
== 'N' || *s
== 'D' || *s
== 'R' || *s
== 'C')
405 *value
= (int) strtol (s
, NULL
, 10);
413 void wxXMergeDatabases (wxApp
* theApp
, Display
* display
)
415 XrmDatabase homeDB
, serverDB
, applicationDB
;
416 char filenamebuf
[1024];
418 char *filename
= &filenamebuf
[0];
420 wxString classname
= theApp
->GetClassName();
422 (void) strcpy (name
, "/usr/lib/X11/app-defaults/");
423 (void) strcat (name
, classname
.c_str());
425 /* Get application defaults file, if any */
426 applicationDB
= XrmGetFileDatabase (name
);
427 (void) XrmMergeDatabases (applicationDB
, &wxResourceDatabase
);
429 /* Merge server defaults, created by xrdb, loaded as a property of the root
430 * window when the server initializes and loaded into the display
431 * structure on XOpenDisplay;
432 * if not defined, use .Xdefaults
435 if (XResourceManagerString (display
) != NULL
)
437 serverDB
= XrmGetStringDatabase (XResourceManagerString (display
));
441 (void) GetIniFile (filename
, NULL
);
442 serverDB
= XrmGetFileDatabase (filename
);
444 XrmMergeDatabases (serverDB
, &wxResourceDatabase
);
446 /* Open XENVIRONMENT file, or if not defined, the .Xdefaults,
447 * and merge into existing database
450 if ((environment
= getenv ("XENVIRONMENT")) == NULL
)
453 environment
= GetIniFile (filename
, NULL
);
454 len
= strlen (environment
);
455 wxString hostname
= wxGetHostName();
456 if ( !hostname
.empty() )
457 strncat(environment
, hostname
, 1024 - len
);
459 homeDB
= XrmGetFileDatabase (environment
);
460 XrmMergeDatabases (homeDB
, &wxResourceDatabase
);
466 * Not yet used but may be useful.
470 wxSetDefaultResources (const Widget w
, const char **resourceSpec
, const char *name
)
473 Display
*dpy
= XtDisplay (w
); // Retrieve the display pointer
475 XrmDatabase rdb
= NULL
; // A resource data base
477 // Create an empty resource database
478 rdb
= XrmGetStringDatabase ("");
480 // Add the Component resources, prepending the name of the component
483 while (resourceSpec
[i
] != NULL
)
487 sprintf (buf
, "*%s%s", name
, resourceSpec
[i
++]);
488 XrmPutLineResource (&rdb
, buf
);
491 // Merge them into the Xt database, with lowest precendence
495 #if (XlibSpecificationRelease>=5)
496 XrmDatabase db
= XtDatabase (dpy
);
497 XrmCombineDatabase (rdb
, &db
, False
);
499 XrmMergeDatabases (dpy
->db
, &rdb
);
507 #endif // wxUSE_RESOURCES
509 // ----------------------------------------------------------------------------
511 // ----------------------------------------------------------------------------
513 void wxGetMousePosition( int* x
, int* y
)
522 XQueryPointer(wxGlobalDisplay(),
523 DefaultRootWindow(wxGlobalDisplay()),
525 &(xev
.x_root
), &(xev
.y_root
),
533 // Return true if we have a colour display
534 bool wxColourDisplay()
536 return wxDisplayDepth() > 1;
539 // Returns depth of screen
542 Display
*dpy
= wxGlobalDisplay();
544 return DefaultDepth (dpy
, DefaultScreen (dpy
));
547 // Get size of display
548 void wxDisplaySize(int *width
, int *height
)
550 Display
*dpy
= wxGlobalDisplay();
553 *width
= DisplayWidth (dpy
, DefaultScreen (dpy
));
555 *height
= DisplayHeight (dpy
, DefaultScreen (dpy
));
558 void wxDisplaySizeMM(int *width
, int *height
)
560 Display
*dpy
= wxGlobalDisplay();
563 *width
= DisplayWidthMM(dpy
, DefaultScreen (dpy
));
565 *height
= DisplayHeightMM(dpy
, DefaultScreen (dpy
));
568 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
570 // This is supposed to return desktop dimensions minus any window
571 // manager panels, menus, taskbars, etc. If there is a way to do that
572 // for this platform please fix this function, otherwise it defaults
573 // to the entire desktop.
576 wxDisplaySize(width
, height
);
580 // Configurable display in wxX11 and wxMotif
581 static WXDisplay
*gs_currentDisplay
= NULL
;
582 static wxString gs_displayName
;
584 WXDisplay
*wxGetDisplay()
586 if (gs_currentDisplay
)
587 return gs_currentDisplay
;
589 return wxTheApp
->GetInitialDisplay();
593 bool wxSetDisplay(const wxString
& display_name
)
595 gs_displayName
= display_name
;
597 if ( display_name
.empty() )
599 gs_currentDisplay
= NULL
;
607 Display
*display
= XtOpenDisplay((XtAppContext
) wxTheApp
->GetAppContext(),
608 display_name
.c_str(),
609 wxTheApp
->GetAppName().c_str(),
610 wxTheApp
->GetClassName().c_str(),
612 #if XtSpecificationRelease < 5
621 gs_currentDisplay
= (WXDisplay
*) display
;
629 wxString
wxGetDisplayName()
631 return gs_displayName
;
634 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
636 return wxGenericFindWindowAtPoint(pt
);
639 // ----------------------------------------------------------------------------
640 // Some colour manipulation routines
641 // ----------------------------------------------------------------------------
643 void wxHSVToXColor(wxHSV
*hsv
,XColor
*rgb
)
648 int r
= 0, g
= 0, b
= 0;
651 s
= (s
* wxMAX_RGB
) / wxMAX_SV
;
652 v
= (v
* wxMAX_RGB
) / wxMAX_SV
;
654 if (s
== 0) { h
= 0; r
= g
= b
= v
; }
657 p
= v
* (wxMAX_RGB
- s
) / wxMAX_RGB
;
658 q
= v
* (wxMAX_RGB
- s
* f
/ 60) / wxMAX_RGB
;
659 t
= v
* (wxMAX_RGB
- s
* (60 - f
) / 60) / wxMAX_RGB
;
662 case 0: r
= v
, g
= t
, b
= p
; break;
663 case 1: r
= q
, g
= v
, b
= p
; break;
664 case 2: r
= p
, g
= v
, b
= t
; break;
665 case 3: r
= p
, g
= q
, b
= v
; break;
666 case 4: r
= t
, g
= p
, b
= v
; break;
667 case 5: r
= v
, g
= p
, b
= q
; break;
669 rgb
->red
= (unsigned short)(r
<< 8);
670 rgb
->green
= (unsigned short)(g
<< 8);
671 rgb
->blue
= (unsigned short)(b
<< 8);
674 void wxXColorToHSV(wxHSV
*hsv
,XColor
*rgb
)
676 int r
= rgb
->red
>> 8;
677 int g
= rgb
->green
>> 8;
678 int b
= rgb
->blue
>> 8;
679 int maxv
= wxMax3(r
, g
, b
);
680 int minv
= wxMin3(r
, g
, b
);
683 if (maxv
) s
= (maxv
- minv
) * wxMAX_RGB
/ maxv
;
688 int rc
, gc
, bc
, hex
= 0;
689 rc
= (maxv
- r
) * wxMAX_RGB
/ (maxv
- minv
);
690 gc
= (maxv
- g
) * wxMAX_RGB
/ (maxv
- minv
);
691 bc
= (maxv
- b
) * wxMAX_RGB
/ (maxv
- minv
);
692 if (r
== maxv
) { h
= bc
- gc
, hex
= 0; }
693 else if (g
== maxv
) { h
= rc
- bc
, hex
= 2; }
694 else if (b
== maxv
) { h
= gc
- rc
, hex
= 4; }
695 h
= hex
* 60 + (h
* 60 / wxMAX_RGB
);
699 hsv
->s
= (s
* wxMAX_SV
) / wxMAX_RGB
;
700 hsv
->v
= (v
* wxMAX_SV
) / wxMAX_RGB
;
703 void wxAllocNearestColor(Display
*d
,Colormap cmp
,XColor
*xc
)
708 int screen
= DefaultScreen(d
);
709 int num_colors
= DisplayCells(d
,screen
);
711 XColor
*color_defs
= new XColor
[num_colors
];
712 for(llp
= 0;llp
< num_colors
;llp
++) color_defs
[llp
].pixel
= llp
;
713 XQueryColors(d
,cmp
,color_defs
,num_colors
);
716 wxXColorToHSV(&hsv
,xc
);
718 int diff
, min_diff
= 0, pixel
= 0;
720 for(llp
= 0;llp
< num_colors
;llp
++)
722 wxXColorToHSV(&hsv_defs
,&color_defs
[llp
]);
723 diff
= wxSIGN(wxH_WEIGHT
* (hsv
.h
- hsv_defs
.h
)) +
724 wxSIGN(wxS_WEIGHT
* (hsv
.s
- hsv_defs
.s
)) +
725 wxSIGN(wxV_WEIGHT
* (hsv
.v
- hsv_defs
.v
));
726 if (llp
== 0) min_diff
= diff
;
727 if (min_diff
> diff
) { min_diff
= diff
; pixel
= llp
; }
728 if (min_diff
== 0) break;
731 xc
-> red
= color_defs
[pixel
].red
;
732 xc
-> green
= color_defs
[pixel
].green
;
733 xc
-> blue
= color_defs
[pixel
].blue
;
734 xc
-> flags
= DoRed
| DoGreen
| DoBlue
;
737 if (!XAllocColor(d,cmp,xc))
738 cout << "wxAllocNearestColor : Warning : Cannot find nearest color !\n";
745 void wxAllocColor(Display
*d
,Colormap cmp
,XColor
*xc
)
747 if (!XAllocColor(d
,cmp
,xc
))
749 // cout << "wxAllocColor : Warning : Can not allocate color, attempt find nearest !\n";
750 wxAllocNearestColor(d
,cmp
,xc
);
755 wxString
wxGetXEventName(XEvent
& event
)
758 wxString
str(wxT("(some event)"));
761 int type
= event
.xany
.type
;
762 static char* event_name
[] = {
763 wxMOTIF_STR(""), wxMOTIF_STR("unknown(-)"), // 0-1
764 wxMOTIF_STR("KeyPress"), wxMOTIF_STR("KeyRelease"), wxMOTIF_STR("ButtonPress"), wxMOTIF_STR("ButtonRelease"), // 2-5
765 wxMOTIF_STR("MotionNotify"), wxMOTIF_STR("EnterNotify"), wxMOTIF_STR("LeaveNotify"), wxMOTIF_STR("FocusIn"), // 6-9
766 wxMOTIF_STR("FocusOut"), wxMOTIF_STR("KeymapNotify"), wxMOTIF_STR("Expose"), wxMOTIF_STR("GraphicsExpose"), // 10-13
767 wxMOTIF_STR("NoExpose"), wxMOTIF_STR("VisibilityNotify"), wxMOTIF_STR("CreateNotify"), // 14-16
768 wxMOTIF_STR("DestroyNotify"), wxMOTIF_STR("UnmapNotify"), wxMOTIF_STR("MapNotify"), wxMOTIF_STR("MapRequest"),// 17-20
769 wxMOTIF_STR("ReparentNotify"), wxMOTIF_STR("ConfigureNotify"), wxMOTIF_STR("ConfigureRequest"), // 21-23
770 wxMOTIF_STR("GravityNotify"), wxMOTIF_STR("ResizeRequest"), wxMOTIF_STR("CirculateNotify"), // 24-26
771 wxMOTIF_STR("CirculateRequest"), wxMOTIF_STR("PropertyNotify"), wxMOTIF_STR("SelectionClear"), // 27-29
772 wxMOTIF_STR("SelectionRequest"), wxMOTIF_STR("SelectionNotify"), wxMOTIF_STR("ColormapNotify"), // 30-32
773 wxMOTIF_STR("ClientMessage"), wxMOTIF_STR("MappingNotify"), // 33-34
774 wxMOTIF_STR("unknown(+)")}; // 35
775 type
= wxMin(35, type
); type
= wxMax(1, type
);
776 wxString
str(event_name
[type
]);
782 // ----------------------------------------------------------------------------
784 // ----------------------------------------------------------------------------
786 // Find the letter corresponding to the mnemonic, for Motif
787 char wxFindMnemonic (const char *s
)
790 int len
= strlen (s
);
793 for (i
= 0; i
< len
; i
++)
797 // Carefully handle &&
798 if ((i
+ 1) <= len
&& s
[i
+ 1] == '&')
810 char* wxFindAccelerator( const char *s
)
814 // VZ: this function returns incorrect keysym which completely breaks kbd
818 // The accelerator text is after the \t char.
819 s
= strchr( s
, '\t' );
821 if( !s
) return NULL
;
824 Now we need to format it as X standard:
829 Ctrl+N --> Ctrl<Key>N
831 Ctrl+Shift+A --> Ctrl Shift<Key>A
833 and handle Ctrl-N & similia
836 static char buf
[256];
839 wxString tmp
= s
+ 1; // skip TAB
842 while( index
< tmp
.length() )
844 size_t plus
= tmp
.find( '+', index
);
845 size_t minus
= tmp
.find( '-', index
);
847 // neither '+' nor '-', add <Key>
848 if( plus
== wxString::npos
&& minus
== wxString::npos
)
850 strcat( buf
, "<Key>" );
851 strcat( buf
, tmp
.c_str() + index
);
856 // OK: npos is big and positive
857 size_t sep
= wxMin( plus
, minus
);
858 wxString mod
= tmp
.substr( index
, sep
- index
);
869 strcat( buf
, mod
.c_str() );
878 XmString
wxFindAcceleratorText (const char *s
)
882 // VZ: this function returns incorrect keysym which completely breaks kbd
886 // The accelerator text is after the \t char.
887 s
= strchr( s
, '\t' );
889 if( !s
) return NULL
;
891 return wxStringToXmString( s
+ 1 ); // skip TAB!
895 // Change a widget's foreground and background colours.
896 void wxDoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
898 // When should we specify the foreground, if it's calculated
899 // by wxComputeColours?
900 // Solution: say we start with the default (computed) foreground colour.
901 // If we call SetForegroundColour explicitly for a control or window,
902 // then the foreground is changed.
903 // Therefore SetBackgroundColour computes the foreground colour, and
904 // SetForegroundColour changes the foreground colour. The ordering is
907 XtVaSetValues ((Widget
) widget
,
908 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
912 void wxDoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
914 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
917 XtVaSetValues ((Widget
) widget
,
918 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
919 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
920 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
921 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
925 XtVaSetValues ((Widget
) widget
,
926 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
930 extern void wxDoChangeFont(WXWidget widget
, const wxFont
& font
)
932 // Lesstif 0.87 hangs here, but 0.93 does not; MBN: sometimes it does
933 #if !wxCHECK_LESSTIF() // || wxCHECK_LESSTIF_VERSION( 0, 93 )
934 Widget w
= (Widget
)widget
;
936 wxFont::GetFontTag(), font
.GetFontTypeC( XtDisplay(w
) ),
945 wxString
wxXmStringToString( const XmString
& xmString
)
948 if( XmStringGetLtoR( xmString
, XmSTRING_DEFAULT_CHARSET
, &txt
) )
955 return wxEmptyString
;
958 XmString
wxStringToXmString( const wxString
& str
)
960 return XmStringCreateLtoR((char *)str
.c_str(), XmSTRING_DEFAULT_CHARSET
);
963 XmString
wxStringToXmString( const char* str
)
965 return XmStringCreateLtoR((char *)str
, XmSTRING_DEFAULT_CHARSET
);
968 // ----------------------------------------------------------------------------
969 // wxBitmap utility functions
970 // ----------------------------------------------------------------------------
972 // Creates a bitmap with transparent areas drawn in
974 wxBitmap
wxCreateMaskedBitmap(const wxBitmap
& bitmap
, const wxColour
& colour
)
976 wxBitmap
newBitmap(bitmap
.GetWidth(),
982 srcDC
.SelectObject(bitmap
);
983 destDC
.SelectObject(newBitmap
);
985 wxBrush
brush(colour
, wxSOLID
);
986 destDC
.SetBackground(brush
);
988 destDC
.Blit(0, 0, bitmap
.GetWidth(), bitmap
.GetHeight(),
989 &srcDC
, 0, 0, wxCOPY
, true);
994 // ----------------------------------------------------------------------------
995 // Miscellaneous functions
996 // ----------------------------------------------------------------------------
998 WXWidget
wxCreateBorderWidget( WXWidget parent
, long style
)
1000 Widget borderWidget
= (Widget
)NULL
, parentWidget
= (Widget
)parent
;
1002 if (style
& wxSIMPLE_BORDER
)
1004 borderWidget
= XtVaCreateManagedWidget
1007 xmFrameWidgetClass
, parentWidget
,
1008 XmNshadowType
, XmSHADOW_ETCHED_IN
,
1009 XmNshadowThickness
, 1,
1013 else if (style
& wxSUNKEN_BORDER
)
1015 borderWidget
= XtVaCreateManagedWidget
1018 xmFrameWidgetClass
, parentWidget
,
1019 XmNshadowType
, XmSHADOW_IN
,
1023 else if (style
& wxRAISED_BORDER
)
1025 borderWidget
= XtVaCreateManagedWidget
1028 xmFrameWidgetClass
, parentWidget
,
1029 XmNshadowType
, XmSHADOW_OUT
,
1034 return borderWidget
;