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
31 #include "wx/dcmemory.h"
32 #include "wx/bitmap.h"
35 #include "wx/apptrait.h"
36 #include "wx/evtloop.h"
40 #if (defined(__SUNCC__) || defined(__CLCC__))
45 #pragma message disable nosimpint
48 #include "wx/unix/execute.h"
53 #include "wx/motif/private.h"
56 #include "X11/Xresource.h"
59 #include "X11/Xutil.h"
62 #pragma message enable nosimpint
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 // Yuck this is really BOTH site and platform dependent
70 // so we should use some other strategy!
72 #define DEFAULT_XRESOURCE_DIR "/usr/openwin/lib/app-defaults"
74 #define DEFAULT_XRESOURCE_DIR "/usr/lib/X11/app-defaults"
78 static char *GetIniFile (char *dest
, const char *filename
);
81 // ============================================================================
83 // ============================================================================
85 // ----------------------------------------------------------------------------
86 // async event processing
87 // ----------------------------------------------------------------------------
89 // Consume all events until no more left
90 void wxFlushEvents(WXDisplay
* wxdisplay
)
92 Display
*display
= (Display
*)wxdisplay
;
95 XSync (display
, False
);
97 while (evtLoop
.Pending())
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
108 static void xt_notify_end_process(XtPointer data
, int *WXUNUSED(fid
),
111 wxEndProcessData
*proc_data
= (wxEndProcessData
*)data
;
113 wxHandleProcessTermination(proc_data
);
115 // VZ: I think they should be the same...
116 wxASSERT( (int)*id
== proc_data
->tag
);
121 int wxAddProcessCallback(wxEndProcessData
*proc_data
, int fd
)
123 XtInputId id
= XtAppAddInput((XtAppContext
) wxTheApp
->GetAppContext(),
125 (XtPointer
*) XtInputReadMask
,
126 (XtInputCallbackProc
) xt_notify_end_process
,
127 (XtPointer
) proc_data
);
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
138 // on OS/2, we use the wxBell from wxBase library (src/os2/utils.cpp)
141 // Use current setting for the bell
142 XBell (wxGlobalDisplay(), 0);
146 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
148 static wxToolkitInfo info
;
150 info
.shortName
= _T("motif");
151 info
.name
= _T("wxMotif");
152 #ifdef __WXUNIVERSAL__
153 info
.shortName
<< _T("univ");
154 info
.name
<< _T("/wxUniversal");
157 // This code is WRONG!! Does NOT return the
158 // Motif version of the libs but the X protocol
160 Display
*display
= wxGlobalDisplay();
163 info
.versionMajor
= ProtocolVersion (display
);
164 info
.versionMinor
= ProtocolRevision (display
);
170 // ----------------------------------------------------------------------------
171 // Reading and writing resources (eg WIN.INI, .Xdefaults)
172 // ----------------------------------------------------------------------------
176 // Read $HOME for what it says is home, if not
177 // read $USER or $LOGNAME for user name else determine
178 // the Real User, then determine the Real home dir.
179 static char * GetIniFile (char *dest
, const char *filename
)
182 if (filename
&& wxIsAbsolutePath(filename
))
184 strcpy(dest
, filename
);
186 else if ((home
= wxGetUserHome()) != NULL
)
189 if (dest
[strlen(dest
) - 1] != '/')
191 if (filename
== NULL
)
193 if ((filename
= getenv ("XENVIRONMENT")) == NULL
)
194 filename
= ".Xdefaults";
196 else if (*filename
!= '.')
198 strcat (dest
, filename
);
206 static char *GetResourcePath(char *buf
, const char *name
, bool create
= false)
208 if (create
&& wxFileExists (name
) ) {
210 return buf
; // Exists so ...
216 // Put in standard place for resource files if not absolute
217 strcpy (buf
, DEFAULT_XRESOURCE_DIR
);
219 strcat (buf
, wxFileNameFromPath (name
).c_str());
223 // Touch the file to create it
224 FILE *fd
= fopen (buf
, "w");
231 * We have a cache for writing different resource files,
232 * which will only get flushed when we call wxFlushResources().
233 * Build up a list of resource databases waiting to be written.
237 wxList
wxResourceCache (wxKEY_STRING
);
240 wxFlushResources (void)
242 char nameBuffer
[512];
244 wxNode
*node
= wxResourceCache
.First ();
247 const char *file
= node
->GetKeyString();
248 // If file doesn't exist, create it first.
249 (void)GetResourcePath(nameBuffer
, file
, true);
251 XrmDatabase database
= (XrmDatabase
) node
->Data ();
252 XrmPutFileDatabase (database
, nameBuffer
);
253 XrmDestroyDatabase (database
);
254 wxNode
*next
= node
->Next ();
260 static XrmDatabase wxResourceDatabase
= 0;
262 void wxXMergeDatabases (wxApp
* theApp
, Display
* display
);
264 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
268 (void) GetIniFile (buffer
, file
);
270 XrmDatabase database
;
271 wxNode
*node
= wxResourceCache
.Find (buffer
);
273 database
= (XrmDatabase
) node
->Data ();
276 database
= XrmGetFileDatabase (buffer
);
277 wxResourceCache
.Append (buffer
, (wxObject
*) database
);
281 strcpy (resName
, section
.c_str());
282 strcat (resName
, ".");
283 strcat (resName
, entry
.c_str());
285 XrmPutStringResource (&database
, resName
, value
);
289 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
292 sprintf(buf
, "%.4f", value
);
293 return wxWriteResource(section
, entry
, buf
, file
);
296 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
299 sprintf(buf
, "%ld", value
);
300 return wxWriteResource(section
, entry
, buf
, file
);
303 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
306 sprintf(buf
, "%d", value
);
307 return wxWriteResource(section
, entry
, buf
, file
);
310 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
312 if (!wxResourceDatabase
)
314 Display
*display
= wxGlobalDisplay();
315 wxXMergeDatabases (wxTheApp
, display
);
318 XrmDatabase database
;
324 // Is this right? Trying to get it to look in the user's
325 // home directory instead of current directory -- JACS
326 (void) GetIniFile (buffer
, file
);
328 wxNode
*node
= wxResourceCache
.Find (buffer
);
330 database
= (XrmDatabase
) node
->Data ();
333 database
= XrmGetFileDatabase (buffer
);
334 wxResourceCache
.Append (buffer
, (wxObject
*) database
);
338 database
= wxResourceDatabase
;
343 strcpy (buf
, section
);
347 Bool success
= XrmGetResource (database
, buf
, "*", str_type
,
349 // Try different combinations of upper/lower case, just in case...
352 buf
[0] = (isupper (buf
[0]) ? tolower (buf
[0]) : toupper (buf
[0]));
353 success
= XrmGetResource (database
, buf
, "*", str_type
,
361 *value
= new char[xvalue
.size
+ 1];
362 strncpy (*value
, xvalue
.addr
, (int) xvalue
.size
);
368 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
371 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
374 *value
= (float)strtod(s
, NULL
);
381 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
384 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
387 *value
= strtol(s
, NULL
, 10);
394 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
397 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
400 // Handle True, False here
401 // True, Yes, Enables, Set or Activated
402 if (*s
== 'T' || *s
== 'Y' || *s
== 'E' || *s
== 'S' || *s
== 'A')
404 // False, No, Disabled, Reset, Cleared, Deactivated
405 else if (*s
== 'F' || *s
== 'N' || *s
== 'D' || *s
== 'R' || *s
== 'C')
409 *value
= (int) strtol (s
, NULL
, 10);
417 void wxXMergeDatabases (wxApp
* theApp
, Display
* display
)
419 XrmDatabase homeDB
, serverDB
, applicationDB
;
420 char filenamebuf
[1024];
422 char *filename
= &filenamebuf
[0];
424 wxString classname
= theApp
->GetClassName();
426 (void) strcpy (name
, "/usr/lib/X11/app-defaults/");
427 (void) strcat (name
, classname
.c_str());
429 /* Get application defaults file, if any */
430 applicationDB
= XrmGetFileDatabase (name
);
431 (void) XrmMergeDatabases (applicationDB
, &wxResourceDatabase
);
433 /* Merge server defaults, created by xrdb, loaded as a property of the root
434 * window when the server initializes and loaded into the display
435 * structure on XOpenDisplay;
436 * if not defined, use .Xdefaults
439 if (XResourceManagerString (display
) != NULL
)
441 serverDB
= XrmGetStringDatabase (XResourceManagerString (display
));
445 (void) GetIniFile (filename
, NULL
);
446 serverDB
= XrmGetFileDatabase (filename
);
448 XrmMergeDatabases (serverDB
, &wxResourceDatabase
);
450 /* Open XENVIRONMENT file, or if not defined, the .Xdefaults,
451 * and merge into existing database
454 if ((environment
= getenv ("XENVIRONMENT")) == NULL
)
457 environment
= GetIniFile (filename
, NULL
);
458 len
= strlen (environment
);
459 wxString hostname
= wxGetHostName();
460 if ( !hostname
.empty() )
461 strncat(environment
, hostname
, 1024 - len
);
463 homeDB
= XrmGetFileDatabase (environment
);
464 XrmMergeDatabases (homeDB
, &wxResourceDatabase
);
470 * Not yet used but may be useful.
474 wxSetDefaultResources (const Widget w
, const char **resourceSpec
, const char *name
)
477 Display
*dpy
= XtDisplay (w
); // Retrieve the display pointer
479 XrmDatabase rdb
= NULL
; // A resource data base
481 // Create an empty resource database
482 rdb
= XrmGetStringDatabase ("");
484 // Add the Component resources, prepending the name of the component
487 while (resourceSpec
[i
] != NULL
)
491 sprintf (buf
, "*%s%s", name
, resourceSpec
[i
++]);
492 XrmPutLineResource (&rdb
, buf
);
495 // Merge them into the Xt database, with lowest precendence
499 #if (XlibSpecificationRelease>=5)
500 XrmDatabase db
= XtDatabase (dpy
);
501 XrmCombineDatabase (rdb
, &db
, False
);
503 XrmMergeDatabases (dpy
->db
, &rdb
);
511 #endif // wxUSE_RESOURCES
513 // ----------------------------------------------------------------------------
515 // ----------------------------------------------------------------------------
517 void wxGetMousePosition( int* x
, int* y
)
526 XQueryPointer(wxGlobalDisplay(),
527 DefaultRootWindow(wxGlobalDisplay()),
529 &(xev
.x_root
), &(xev
.y_root
),
537 // Return true if we have a colour display
538 bool wxColourDisplay()
540 return wxDisplayDepth() > 1;
543 // Returns depth of screen
546 Display
*dpy
= wxGlobalDisplay();
548 return DefaultDepth (dpy
, DefaultScreen (dpy
));
551 // Get size of display
552 void wxDisplaySize(int *width
, int *height
)
554 Display
*dpy
= wxGlobalDisplay();
557 *width
= DisplayWidth (dpy
, DefaultScreen (dpy
));
559 *height
= DisplayHeight (dpy
, DefaultScreen (dpy
));
562 void wxDisplaySizeMM(int *width
, int *height
)
564 Display
*dpy
= wxGlobalDisplay();
567 *width
= DisplayWidthMM(dpy
, DefaultScreen (dpy
));
569 *height
= DisplayHeightMM(dpy
, DefaultScreen (dpy
));
572 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
574 // This is supposed to return desktop dimensions minus any window
575 // manager panels, menus, taskbars, etc. If there is a way to do that
576 // for this platform please fix this function, otherwise it defaults
577 // to the entire desktop.
580 wxDisplaySize(width
, height
);
584 // Configurable display in wxX11 and wxMotif
585 static WXDisplay
*gs_currentDisplay
= NULL
;
586 static wxString gs_displayName
;
588 WXDisplay
*wxGetDisplay()
590 if (gs_currentDisplay
)
591 return gs_currentDisplay
;
593 return wxTheApp
->GetInitialDisplay();
597 bool wxSetDisplay(const wxString
& display_name
)
599 gs_displayName
= display_name
;
601 if ( display_name
.empty() )
603 gs_currentDisplay
= NULL
;
611 Display
*display
= XtOpenDisplay((XtAppContext
) wxTheApp
->GetAppContext(),
612 display_name
.c_str(),
613 wxTheApp
->GetAppName().c_str(),
614 wxTheApp
->GetClassName().c_str(),
616 #if XtSpecificationRelease < 5
625 gs_currentDisplay
= (WXDisplay
*) display
;
633 wxString
wxGetDisplayName()
635 return gs_displayName
;
638 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
640 return wxGenericFindWindowAtPoint(pt
);
643 // ----------------------------------------------------------------------------
644 // Some colour manipulation routines
645 // ----------------------------------------------------------------------------
647 void wxHSVToXColor(wxHSV
*hsv
,XColor
*rgb
)
652 int r
= 0, g
= 0, b
= 0;
655 s
= (s
* wxMAX_RGB
) / wxMAX_SV
;
656 v
= (v
* wxMAX_RGB
) / wxMAX_SV
;
658 if (s
== 0) { h
= 0; r
= g
= b
= v
; }
661 p
= v
* (wxMAX_RGB
- s
) / wxMAX_RGB
;
662 q
= v
* (wxMAX_RGB
- s
* f
/ 60) / wxMAX_RGB
;
663 t
= v
* (wxMAX_RGB
- s
* (60 - f
) / 60) / wxMAX_RGB
;
666 case 0: r
= v
, g
= t
, b
= p
; break;
667 case 1: r
= q
, g
= v
, b
= p
; break;
668 case 2: r
= p
, g
= v
, b
= t
; break;
669 case 3: r
= p
, g
= q
, b
= v
; break;
670 case 4: r
= t
, g
= p
, b
= v
; break;
671 case 5: r
= v
, g
= p
, b
= q
; break;
673 rgb
->red
= (unsigned short)(r
<< 8);
674 rgb
->green
= (unsigned short)(g
<< 8);
675 rgb
->blue
= (unsigned short)(b
<< 8);
678 void wxXColorToHSV(wxHSV
*hsv
,XColor
*rgb
)
680 int r
= rgb
->red
>> 8;
681 int g
= rgb
->green
>> 8;
682 int b
= rgb
->blue
>> 8;
683 int maxv
= wxMax3(r
, g
, b
);
684 int minv
= wxMin3(r
, g
, b
);
687 if (maxv
) s
= (maxv
- minv
) * wxMAX_RGB
/ maxv
;
692 int rc
, gc
, bc
, hex
= 0;
693 rc
= (maxv
- r
) * wxMAX_RGB
/ (maxv
- minv
);
694 gc
= (maxv
- g
) * wxMAX_RGB
/ (maxv
- minv
);
695 bc
= (maxv
- b
) * wxMAX_RGB
/ (maxv
- minv
);
696 if (r
== maxv
) { h
= bc
- gc
, hex
= 0; }
697 else if (g
== maxv
) { h
= rc
- bc
, hex
= 2; }
698 else if (b
== maxv
) { h
= gc
- rc
, hex
= 4; }
699 h
= hex
* 60 + (h
* 60 / wxMAX_RGB
);
703 hsv
->s
= (s
* wxMAX_SV
) / wxMAX_RGB
;
704 hsv
->v
= (v
* wxMAX_SV
) / wxMAX_RGB
;
707 void wxAllocNearestColor(Display
*d
,Colormap cmp
,XColor
*xc
)
712 int screen
= DefaultScreen(d
);
713 int num_colors
= DisplayCells(d
,screen
);
715 XColor
*color_defs
= new XColor
[num_colors
];
716 for(llp
= 0;llp
< num_colors
;llp
++) color_defs
[llp
].pixel
= llp
;
717 XQueryColors(d
,cmp
,color_defs
,num_colors
);
720 wxXColorToHSV(&hsv
,xc
);
722 int diff
, min_diff
= 0, pixel
= 0;
724 for(llp
= 0;llp
< num_colors
;llp
++)
726 wxXColorToHSV(&hsv_defs
,&color_defs
[llp
]);
727 diff
= wxSIGN(wxH_WEIGHT
* (hsv
.h
- hsv_defs
.h
)) +
728 wxSIGN(wxS_WEIGHT
* (hsv
.s
- hsv_defs
.s
)) +
729 wxSIGN(wxV_WEIGHT
* (hsv
.v
- hsv_defs
.v
));
730 if (llp
== 0) min_diff
= diff
;
731 if (min_diff
> diff
) { min_diff
= diff
; pixel
= llp
; }
732 if (min_diff
== 0) break;
735 xc
-> red
= color_defs
[pixel
].red
;
736 xc
-> green
= color_defs
[pixel
].green
;
737 xc
-> blue
= color_defs
[pixel
].blue
;
738 xc
-> flags
= DoRed
| DoGreen
| DoBlue
;
741 if (!XAllocColor(d,cmp,xc))
742 cout << "wxAllocNearestColor : Warning : Cannot find nearest color !\n";
749 void wxAllocColor(Display
*d
,Colormap cmp
,XColor
*xc
)
751 if (!XAllocColor(d
,cmp
,xc
))
753 // cout << "wxAllocColor : Warning : Can not allocate color, attempt find nearest !\n";
754 wxAllocNearestColor(d
,cmp
,xc
);
759 wxString
wxGetXEventName(XEvent
& event
)
762 wxString
str(wxT("(some event)"));
765 int type
= event
.xany
.type
;
766 static char* event_name
[] = {
767 wxMOTIF_STR(""), wxMOTIF_STR("unknown(-)"), // 0-1
768 wxMOTIF_STR("KeyPress"), wxMOTIF_STR("KeyRelease"), wxMOTIF_STR("ButtonPress"), wxMOTIF_STR("ButtonRelease"), // 2-5
769 wxMOTIF_STR("MotionNotify"), wxMOTIF_STR("EnterNotify"), wxMOTIF_STR("LeaveNotify"), wxMOTIF_STR("FocusIn"), // 6-9
770 wxMOTIF_STR("FocusOut"), wxMOTIF_STR("KeymapNotify"), wxMOTIF_STR("Expose"), wxMOTIF_STR("GraphicsExpose"), // 10-13
771 wxMOTIF_STR("NoExpose"), wxMOTIF_STR("VisibilityNotify"), wxMOTIF_STR("CreateNotify"), // 14-16
772 wxMOTIF_STR("DestroyNotify"), wxMOTIF_STR("UnmapNotify"), wxMOTIF_STR("MapNotify"), wxMOTIF_STR("MapRequest"),// 17-20
773 wxMOTIF_STR("ReparentNotify"), wxMOTIF_STR("ConfigureNotify"), wxMOTIF_STR("ConfigureRequest"), // 21-23
774 wxMOTIF_STR("GravityNotify"), wxMOTIF_STR("ResizeRequest"), wxMOTIF_STR("CirculateNotify"), // 24-26
775 wxMOTIF_STR("CirculateRequest"), wxMOTIF_STR("PropertyNotify"), wxMOTIF_STR("SelectionClear"), // 27-29
776 wxMOTIF_STR("SelectionRequest"), wxMOTIF_STR("SelectionNotify"), wxMOTIF_STR("ColormapNotify"), // 30-32
777 wxMOTIF_STR("ClientMessage"), wxMOTIF_STR("MappingNotify"), // 33-34
778 wxMOTIF_STR("unknown(+)")}; // 35
779 type
= wxMin(35, type
); type
= wxMax(1, type
);
780 wxString
str(event_name
[type
]);
786 // ----------------------------------------------------------------------------
788 // ----------------------------------------------------------------------------
790 // Find the letter corresponding to the mnemonic, for Motif
791 char wxFindMnemonic (const char *s
)
794 int len
= strlen (s
);
797 for (i
= 0; i
< len
; i
++)
801 // Carefully handle &&
802 if ((i
+ 1) <= len
&& s
[i
+ 1] == '&')
814 char* wxFindAccelerator( const char *s
)
818 // VZ: this function returns incorrect keysym which completely breaks kbd
822 // The accelerator text is after the \t char.
823 s
= strchr( s
, '\t' );
825 if( !s
) return NULL
;
828 Now we need to format it as X standard:
833 Ctrl+N --> Ctrl<Key>N
835 Ctrl+Shift+A --> Ctrl Shift<Key>A
837 and handle Ctrl-N & similia
840 static char buf
[256];
843 wxString tmp
= s
+ 1; // skip TAB
846 while( index
< tmp
.length() )
848 size_t plus
= tmp
.find( '+', index
);
849 size_t minus
= tmp
.find( '-', index
);
851 // neither '+' nor '-', add <Key>
852 if( plus
== wxString::npos
&& minus
== wxString::npos
)
854 strcat( buf
, "<Key>" );
855 strcat( buf
, tmp
.c_str() + index
);
860 // OK: npos is big and positive
861 size_t sep
= wxMin( plus
, minus
);
862 wxString mod
= tmp
.substr( index
, sep
- index
);
873 strcat( buf
, mod
.c_str() );
882 XmString
wxFindAcceleratorText (const char *s
)
886 // VZ: this function returns incorrect keysym which completely breaks kbd
890 // The accelerator text is after the \t char.
891 s
= strchr( s
, '\t' );
893 if( !s
) return NULL
;
895 return wxStringToXmString( s
+ 1 ); // skip TAB!
899 // Change a widget's foreground and background colours.
900 void wxDoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
902 // When should we specify the foreground, if it's calculated
903 // by wxComputeColours?
904 // Solution: say we start with the default (computed) foreground colour.
905 // If we call SetForegroundColour explicitly for a control or window,
906 // then the foreground is changed.
907 // Therefore SetBackgroundColour computes the foreground colour, and
908 // SetForegroundColour changes the foreground colour. The ordering is
911 XtVaSetValues ((Widget
) widget
,
912 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
916 void wxDoChangeBackgroundColour(WXWidget widget
, const wxColour
& backgroundColour
, bool changeArmColour
)
918 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
921 XtVaSetValues ((Widget
) widget
,
922 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
923 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
924 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
925 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
929 XtVaSetValues ((Widget
) widget
,
930 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
934 extern void wxDoChangeFont(WXWidget widget
, const wxFont
& font
)
936 // Lesstif 0.87 hangs here, but 0.93 does not; MBN: sometimes it does
937 #if !wxCHECK_LESSTIF() // || wxCHECK_LESSTIF_VERSION( 0, 93 )
938 Widget w
= (Widget
)widget
;
940 wxFont::GetFontTag(), font
.GetFontTypeC( XtDisplay(w
) ),
949 wxString
wxXmStringToString( const XmString
& xmString
)
952 if( XmStringGetLtoR( xmString
, XmSTRING_DEFAULT_CHARSET
, &txt
) )
959 return wxEmptyString
;
962 XmString
wxStringToXmString( const wxString
& str
)
964 return XmStringCreateLtoR((char *)str
.c_str(), XmSTRING_DEFAULT_CHARSET
);
967 XmString
wxStringToXmString( const char* str
)
969 return XmStringCreateLtoR((char *)str
, XmSTRING_DEFAULT_CHARSET
);
972 // ----------------------------------------------------------------------------
973 // wxBitmap utility functions
974 // ----------------------------------------------------------------------------
976 // Creates a bitmap with transparent areas drawn in
978 wxBitmap
wxCreateMaskedBitmap(const wxBitmap
& bitmap
, const wxColour
& colour
)
980 wxBitmap
newBitmap(bitmap
.GetWidth(),
986 srcDC
.SelectObject(bitmap
);
987 destDC
.SelectObject(newBitmap
);
989 wxBrush
brush(colour
, wxSOLID
);
990 destDC
.SetBackground(brush
);
992 destDC
.Blit(0, 0, bitmap
.GetWidth(), bitmap
.GetHeight(),
993 &srcDC
, 0, 0, wxCOPY
, true);
998 // ----------------------------------------------------------------------------
999 // Miscellaneous functions
1000 // ----------------------------------------------------------------------------
1002 WXWidget
wxCreateBorderWidget( WXWidget parent
, long style
)
1004 Widget borderWidget
= (Widget
)NULL
, parentWidget
= (Widget
)parent
;
1006 if (style
& wxSIMPLE_BORDER
)
1008 borderWidget
= XtVaCreateManagedWidget
1011 xmFrameWidgetClass
, parentWidget
,
1012 XmNshadowType
, XmSHADOW_ETCHED_IN
,
1013 XmNshadowThickness
, 1,
1017 else if (style
& wxSUNKEN_BORDER
)
1019 borderWidget
= XtVaCreateManagedWidget
1022 xmFrameWidgetClass
, parentWidget
,
1023 XmNshadowType
, XmSHADOW_IN
,
1027 else if (style
& wxRAISED_BORDER
)
1029 borderWidget
= XtVaCreateManagedWidget
1032 xmFrameWidgetClass
, parentWidget
,
1033 XmNshadowType
, XmSHADOW_OUT
,
1038 return borderWidget
;