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 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
148 // XmVERSION and XmREVISION are defined in Xm/Xm.h
152 *verMin
= XmREVISION
;
158 // ----------------------------------------------------------------------------
159 // Reading and writing resources (eg WIN.INI, .Xdefaults)
160 // ----------------------------------------------------------------------------
164 // Read $HOME for what it says is home, if not
165 // read $USER or $LOGNAME for user name else determine
166 // the Real User, then determine the Real home dir.
167 static char * GetIniFile (char *dest
, const char *filename
)
170 if (filename
&& wxIsAbsolutePath(filename
))
172 strcpy(dest
, filename
);
174 else if ((home
= wxGetUserHome()) != NULL
)
177 if (dest
[strlen(dest
) - 1] != '/')
179 if (filename
== NULL
)
181 if ((filename
= getenv ("XENVIRONMENT")) == NULL
)
182 filename
= ".Xdefaults";
184 else if (*filename
!= '.')
186 strcat (dest
, filename
);
194 static char *GetResourcePath(char *buf
, const char *name
, bool create
= false)
196 if (create
&& wxFileExists (name
) ) {
198 return buf
; // Exists so ...
204 // Put in standard place for resource files if not absolute
205 strcpy (buf
, DEFAULT_XRESOURCE_DIR
);
207 strcat (buf
, wxFileNameFromPath (name
).c_str());
211 // Touch the file to create it
212 FILE *fd
= fopen (buf
, "w");
219 * We have a cache for writing different resource files,
220 * which will only get flushed when we call wxFlushResources().
221 * Build up a list of resource databases waiting to be written.
225 wxList
wxResourceCache (wxKEY_STRING
);
228 wxFlushResources (void)
230 char nameBuffer
[512];
232 wxNode
*node
= wxResourceCache
.First ();
235 const char *file
= node
->GetKeyString();
236 // If file doesn't exist, create it first.
237 (void)GetResourcePath(nameBuffer
, file
, true);
239 XrmDatabase database
= (XrmDatabase
) node
->Data ();
240 XrmPutFileDatabase (database
, nameBuffer
);
241 XrmDestroyDatabase (database
);
242 wxNode
*next
= node
->Next ();
248 static XrmDatabase wxResourceDatabase
= 0;
250 void wxXMergeDatabases (wxApp
* theApp
, Display
* display
);
252 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
256 (void) GetIniFile (buffer
, file
);
258 XrmDatabase database
;
259 wxNode
*node
= wxResourceCache
.Find (buffer
);
261 database
= (XrmDatabase
) node
->Data ();
264 database
= XrmGetFileDatabase (buffer
);
265 wxResourceCache
.Append (buffer
, (wxObject
*) database
);
269 strcpy (resName
, section
.c_str());
270 strcat (resName
, ".");
271 strcat (resName
, entry
.c_str());
273 XrmPutStringResource (&database
, resName
, value
);
277 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
280 sprintf(buf
, "%.4f", value
);
281 return wxWriteResource(section
, entry
, buf
, file
);
284 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
287 sprintf(buf
, "%ld", value
);
288 return wxWriteResource(section
, entry
, buf
, file
);
291 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
294 sprintf(buf
, "%d", value
);
295 return wxWriteResource(section
, entry
, buf
, file
);
298 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
300 if (!wxResourceDatabase
)
302 Display
*display
= wxGlobalDisplay();
303 wxXMergeDatabases (wxTheApp
, display
);
306 XrmDatabase database
;
312 // Is this right? Trying to get it to look in the user's
313 // home directory instead of current directory -- JACS
314 (void) GetIniFile (buffer
, file
);
316 wxNode
*node
= wxResourceCache
.Find (buffer
);
318 database
= (XrmDatabase
) node
->Data ();
321 database
= XrmGetFileDatabase (buffer
);
322 wxResourceCache
.Append (buffer
, (wxObject
*) database
);
326 database
= wxResourceDatabase
;
331 strcpy (buf
, section
);
335 Bool success
= XrmGetResource (database
, buf
, "*", str_type
,
337 // Try different combinations of upper/lower case, just in case...
340 buf
[0] = (isupper (buf
[0]) ? tolower (buf
[0]) : toupper (buf
[0]));
341 success
= XrmGetResource (database
, buf
, "*", str_type
,
349 *value
= new char[xvalue
.size
+ 1];
350 strncpy (*value
, xvalue
.addr
, (int) xvalue
.size
);
356 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
359 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
362 *value
= (float)strtod(s
, NULL
);
369 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
372 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
375 *value
= strtol(s
, NULL
, 10);
382 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
385 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
388 // Handle True, False here
389 // True, Yes, Enables, Set or Activated
390 if (*s
== 'T' || *s
== 'Y' || *s
== 'E' || *s
== 'S' || *s
== 'A')
392 // False, No, Disabled, Reset, Cleared, Deactivated
393 else if (*s
== 'F' || *s
== 'N' || *s
== 'D' || *s
== 'R' || *s
== 'C')
397 *value
= (int) strtol (s
, NULL
, 10);
405 void wxXMergeDatabases (wxApp
* theApp
, Display
* display
)
407 XrmDatabase homeDB
, serverDB
, applicationDB
;
408 char filenamebuf
[1024];
410 char *filename
= &filenamebuf
[0];
412 wxString classname
= theApp
->GetClassName();
414 (void) strcpy (name
, "/usr/lib/X11/app-defaults/");
415 (void) strcat (name
, classname
.c_str());
417 /* Get application defaults file, if any */
418 applicationDB
= XrmGetFileDatabase (name
);
419 (void) XrmMergeDatabases (applicationDB
, &wxResourceDatabase
);
421 /* Merge server defaults, created by xrdb, loaded as a property of the root
422 * window when the server initializes and loaded into the display
423 * structure on XOpenDisplay;
424 * if not defined, use .Xdefaults
427 if (XResourceManagerString (display
) != NULL
)
429 serverDB
= XrmGetStringDatabase (XResourceManagerString (display
));
433 (void) GetIniFile (filename
, NULL
);
434 serverDB
= XrmGetFileDatabase (filename
);
436 XrmMergeDatabases (serverDB
, &wxResourceDatabase
);
438 /* Open XENVIRONMENT file, or if not defined, the .Xdefaults,
439 * and merge into existing database
442 if ((environment
= getenv ("XENVIRONMENT")) == NULL
)
445 environment
= GetIniFile (filename
, NULL
);
446 len
= strlen (environment
);
447 wxString hostname
= wxGetHostName();
448 if ( !hostname
.empty() )
449 strncat(environment
, hostname
, 1024 - len
);
451 homeDB
= XrmGetFileDatabase (environment
);
452 XrmMergeDatabases (homeDB
, &wxResourceDatabase
);
458 * Not yet used but may be useful.
462 wxSetDefaultResources (const Widget w
, const char **resourceSpec
, const char *name
)
465 Display
*dpy
= XtDisplay (w
); // Retrieve the display pointer
467 XrmDatabase rdb
= NULL
; // A resource data base
469 // Create an empty resource database
470 rdb
= XrmGetStringDatabase ("");
472 // Add the Component resources, prepending the name of the component
475 while (resourceSpec
[i
] != NULL
)
479 sprintf (buf
, "*%s%s", name
, resourceSpec
[i
++]);
480 XrmPutLineResource (&rdb
, buf
);
483 // Merge them into the Xt database, with lowest precendence
487 #if (XlibSpecificationRelease>=5)
488 XrmDatabase db
= XtDatabase (dpy
);
489 XrmCombineDatabase (rdb
, &db
, False
);
491 XrmMergeDatabases (dpy
->db
, &rdb
);
499 #endif // wxUSE_RESOURCES
501 // ----------------------------------------------------------------------------
503 // ----------------------------------------------------------------------------
505 void wxGetMousePosition( int* x
, int* y
)
514 XQueryPointer(wxGlobalDisplay(),
515 DefaultRootWindow(wxGlobalDisplay()),
517 &(xev
.x_root
), &(xev
.y_root
),
525 // Return true if we have a colour display
526 bool wxColourDisplay()
528 return wxDisplayDepth() > 1;
531 // Returns depth of screen
534 Display
*dpy
= wxGlobalDisplay();
536 return DefaultDepth (dpy
, DefaultScreen (dpy
));
539 // Get size of display
540 void wxDisplaySize(int *width
, int *height
)
542 Display
*dpy
= wxGlobalDisplay();
545 *width
= DisplayWidth (dpy
, DefaultScreen (dpy
));
547 *height
= DisplayHeight (dpy
, DefaultScreen (dpy
));
550 void wxDisplaySizeMM(int *width
, int *height
)
552 Display
*dpy
= wxGlobalDisplay();
555 *width
= DisplayWidthMM(dpy
, DefaultScreen (dpy
));
557 *height
= DisplayHeightMM(dpy
, DefaultScreen (dpy
));
560 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
562 // This is supposed to return desktop dimensions minus any window
563 // manager panels, menus, taskbars, etc. If there is a way to do that
564 // for this platform please fix this function, otherwise it defaults
565 // to the entire desktop.
568 wxDisplaySize(width
, height
);
572 // Configurable display in wxX11 and wxMotif
573 static WXDisplay
*gs_currentDisplay
= NULL
;
574 static wxString gs_displayName
;
576 WXDisplay
*wxGetDisplay()
578 if (gs_currentDisplay
)
579 return gs_currentDisplay
;
581 return wxTheApp
->GetInitialDisplay();
585 bool wxSetDisplay(const wxString
& display_name
)
587 gs_displayName
= display_name
;
589 if ( display_name
.empty() )
591 gs_currentDisplay
= NULL
;
599 Display
*display
= XtOpenDisplay((XtAppContext
) wxTheApp
->GetAppContext(),
600 display_name
.c_str(),
601 wxTheApp
->GetAppName().c_str(),
602 wxTheApp
->GetClassName().c_str(),
604 #if XtSpecificationRelease < 5
613 gs_currentDisplay
= (WXDisplay
*) display
;
621 wxString
wxGetDisplayName()
623 return gs_displayName
;
626 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
628 return wxGenericFindWindowAtPoint(pt
);
631 // ----------------------------------------------------------------------------
632 // Some colour manipulation routines
633 // ----------------------------------------------------------------------------
635 void wxHSVToXColor(wxHSV
*hsv
,XColor
*rgb
)
640 int r
= 0, g
= 0, b
= 0;
643 s
= (s
* wxMAX_RGB
) / wxMAX_SV
;
644 v
= (v
* wxMAX_RGB
) / wxMAX_SV
;
646 if (s
== 0) { h
= 0; r
= g
= b
= v
; }
649 p
= v
* (wxMAX_RGB
- s
) / wxMAX_RGB
;
650 q
= v
* (wxMAX_RGB
- s
* f
/ 60) / wxMAX_RGB
;
651 t
= v
* (wxMAX_RGB
- s
* (60 - f
) / 60) / wxMAX_RGB
;
654 case 0: r
= v
, g
= t
, b
= p
; break;
655 case 1: r
= q
, g
= v
, b
= p
; break;
656 case 2: r
= p
, g
= v
, b
= t
; break;
657 case 3: r
= p
, g
= q
, b
= v
; break;
658 case 4: r
= t
, g
= p
, b
= v
; break;
659 case 5: r
= v
, g
= p
, b
= q
; break;
661 rgb
->red
= (unsigned short)(r
<< 8);
662 rgb
->green
= (unsigned short)(g
<< 8);
663 rgb
->blue
= (unsigned short)(b
<< 8);
666 void wxXColorToHSV(wxHSV
*hsv
,XColor
*rgb
)
668 int r
= rgb
->red
>> 8;
669 int g
= rgb
->green
>> 8;
670 int b
= rgb
->blue
>> 8;
671 int maxv
= wxMax3(r
, g
, b
);
672 int minv
= wxMin3(r
, g
, b
);
675 if (maxv
) s
= (maxv
- minv
) * wxMAX_RGB
/ maxv
;
680 int rc
, gc
, bc
, hex
= 0;
681 rc
= (maxv
- r
) * wxMAX_RGB
/ (maxv
- minv
);
682 gc
= (maxv
- g
) * wxMAX_RGB
/ (maxv
- minv
);
683 bc
= (maxv
- b
) * wxMAX_RGB
/ (maxv
- minv
);
684 if (r
== maxv
) { h
= bc
- gc
, hex
= 0; }
685 else if (g
== maxv
) { h
= rc
- bc
, hex
= 2; }
686 else if (b
== maxv
) { h
= gc
- rc
, hex
= 4; }
687 h
= hex
* 60 + (h
* 60 / wxMAX_RGB
);
691 hsv
->s
= (s
* wxMAX_SV
) / wxMAX_RGB
;
692 hsv
->v
= (v
* wxMAX_SV
) / wxMAX_RGB
;
695 void wxAllocNearestColor(Display
*d
,Colormap cmp
,XColor
*xc
)
700 int screen
= DefaultScreen(d
);
701 int num_colors
= DisplayCells(d
,screen
);
703 XColor
*color_defs
= new XColor
[num_colors
];
704 for(llp
= 0;llp
< num_colors
;llp
++) color_defs
[llp
].pixel
= llp
;
705 XQueryColors(d
,cmp
,color_defs
,num_colors
);
708 wxXColorToHSV(&hsv
,xc
);
710 int diff
, min_diff
= 0, pixel
= 0;
712 for(llp
= 0;llp
< num_colors
;llp
++)
714 wxXColorToHSV(&hsv_defs
,&color_defs
[llp
]);
715 diff
= wxSIGN(wxH_WEIGHT
* (hsv
.h
- hsv_defs
.h
)) +
716 wxSIGN(wxS_WEIGHT
* (hsv
.s
- hsv_defs
.s
)) +
717 wxSIGN(wxV_WEIGHT
* (hsv
.v
- hsv_defs
.v
));
718 if (llp
== 0) min_diff
= diff
;
719 if (min_diff
> diff
) { min_diff
= diff
; pixel
= llp
; }
720 if (min_diff
== 0) break;
723 xc
-> red
= color_defs
[pixel
].red
;
724 xc
-> green
= color_defs
[pixel
].green
;
725 xc
-> blue
= color_defs
[pixel
].blue
;
726 xc
-> flags
= DoRed
| DoGreen
| DoBlue
;
729 if (!XAllocColor(d,cmp,xc))
730 cout << "wxAllocNearestColor : Warning : Cannot find nearest color !\n";
737 void wxAllocColor(Display
*d
,Colormap cmp
,XColor
*xc
)
739 if (!XAllocColor(d
,cmp
,xc
))
741 // cout << "wxAllocColor : Warning : Can not allocate color, attempt find nearest !\n";
742 wxAllocNearestColor(d
,cmp
,xc
);
747 wxString
wxGetXEventName(XEvent
& event
)
750 wxString
str(wxT("(some event)"));
753 int type
= event
.xany
.type
;
754 static char* event_name
[] = {
755 wxMOTIF_STR(""), wxMOTIF_STR("unknown(-)"), // 0-1
756 wxMOTIF_STR("KeyPress"), wxMOTIF_STR("KeyRelease"), wxMOTIF_STR("ButtonPress"), wxMOTIF_STR("ButtonRelease"), // 2-5
757 wxMOTIF_STR("MotionNotify"), wxMOTIF_STR("EnterNotify"), wxMOTIF_STR("LeaveNotify"), wxMOTIF_STR("FocusIn"), // 6-9
758 wxMOTIF_STR("FocusOut"), wxMOTIF_STR("KeymapNotify"), wxMOTIF_STR("Expose"), wxMOTIF_STR("GraphicsExpose"), // 10-13
759 wxMOTIF_STR("NoExpose"), wxMOTIF_STR("VisibilityNotify"), wxMOTIF_STR("CreateNotify"), // 14-16
760 wxMOTIF_STR("DestroyNotify"), wxMOTIF_STR("UnmapNotify"), wxMOTIF_STR("MapNotify"), wxMOTIF_STR("MapRequest"),// 17-20
761 wxMOTIF_STR("ReparentNotify"), wxMOTIF_STR("ConfigureNotify"), wxMOTIF_STR("ConfigureRequest"), // 21-23
762 wxMOTIF_STR("GravityNotify"), wxMOTIF_STR("ResizeRequest"), wxMOTIF_STR("CirculateNotify"), // 24-26
763 wxMOTIF_STR("CirculateRequest"), wxMOTIF_STR("PropertyNotify"), wxMOTIF_STR("SelectionClear"), // 27-29
764 wxMOTIF_STR("SelectionRequest"), wxMOTIF_STR("SelectionNotify"), wxMOTIF_STR("ColormapNotify"), // 30-32
765 wxMOTIF_STR("ClientMessage"), wxMOTIF_STR("MappingNotify"), // 33-34
766 wxMOTIF_STR("unknown(+)")}; // 35
767 type
= wxMin(35, type
); type
= wxMax(1, type
);
768 wxString
str(event_name
[type
]);
774 // ----------------------------------------------------------------------------
776 // ----------------------------------------------------------------------------
778 // Find the letter corresponding to the mnemonic, for Motif
779 char wxFindMnemonic (const char *s
)
782 int len
= strlen (s
);
785 for (i
= 0; i
< len
; i
++)
789 // Carefully handle &&
790 if ((i
+ 1) <= len
&& s
[i
+ 1] == '&')
802 char* wxFindAccelerator( const char *s
)
806 // VZ: this function returns incorrect keysym which completely breaks kbd
810 // The accelerator text is after the \t char.
811 s
= strchr( s
, '\t' );
813 if( !s
) return NULL
;
816 Now we need to format it as X standard:
821 Ctrl+N --> Ctrl<Key>N
823 Ctrl+Shift+A --> Ctrl Shift<Key>A
825 and handle Ctrl-N & similia
828 static char buf
[256];
831 wxString tmp
= s
+ 1; // skip TAB
834 while( index
< tmp
.length() )
836 size_t plus
= tmp
.find( '+', index
);
837 size_t minus
= tmp
.find( '-', index
);
839 // neither '+' nor '-', add <Key>
840 if( plus
== wxString::npos
&& minus
== wxString::npos
)
842 strcat( buf
, "<Key>" );
843 strcat( buf
, tmp
.c_str() + index
);
848 // OK: npos is big and positive
849 size_t sep
= wxMin( plus
, minus
);
850 wxString mod
= tmp
.substr( index
, sep
- index
);
861 strcat( buf
, mod
.c_str() );
870 XmString
wxFindAcceleratorText (const char *s
)
874 // VZ: this function returns incorrect keysym which completely breaks kbd
878 // The accelerator text is after the \t char.
879 s
= strchr( s
, '\t' );
881 if( !s
) return NULL
;
883 return wxStringToXmString( s
+ 1 ); // skip TAB!
887 // Change a widget's foreground and background colours.
888 void wxDoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
890 // When should we specify the foreground, if it's calculated
891 // by wxComputeColours?
892 // Solution: say we start with the default (computed) foreground colour.
893 // If we call SetForegroundColour explicitly for a control or window,
894 // then the foreground is changed.
895 // Therefore SetBackgroundColour computes the foreground colour, and
896 // SetForegroundColour changes the foreground colour. The ordering is
899 XtVaSetValues ((Widget
) widget
,
900 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
904 void wxDoChangeBackgroundColour(WXWidget widget
, const wxColour
& backgroundColour
, bool changeArmColour
)
906 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
909 XtVaSetValues ((Widget
) widget
,
910 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
911 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
912 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
913 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
917 XtVaSetValues ((Widget
) widget
,
918 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
922 extern void wxDoChangeFont(WXWidget widget
, const wxFont
& font
)
924 // Lesstif 0.87 hangs here, but 0.93 does not; MBN: sometimes it does
925 #if !wxCHECK_LESSTIF() // || wxCHECK_LESSTIF_VERSION( 0, 93 )
926 Widget w
= (Widget
)widget
;
928 wxFont::GetFontTag(), font
.GetFontTypeC( XtDisplay(w
) ),
937 wxString
wxXmStringToString( const XmString
& xmString
)
940 if( XmStringGetLtoR( xmString
, XmSTRING_DEFAULT_CHARSET
, &txt
) )
947 return wxEmptyString
;
950 XmString
wxStringToXmString( const wxString
& str
)
952 return XmStringCreateLtoR((char *)str
.c_str(), XmSTRING_DEFAULT_CHARSET
);
955 XmString
wxStringToXmString( const char* str
)
957 return XmStringCreateLtoR((char *)str
, XmSTRING_DEFAULT_CHARSET
);
960 // ----------------------------------------------------------------------------
961 // wxBitmap utility functions
962 // ----------------------------------------------------------------------------
964 // Creates a bitmap with transparent areas drawn in
966 wxBitmap
wxCreateMaskedBitmap(const wxBitmap
& bitmap
, const wxColour
& colour
)
968 wxBitmap
newBitmap(bitmap
.GetWidth(),
974 srcDC
.SelectObject(bitmap
);
975 destDC
.SelectObject(newBitmap
);
977 wxBrush
brush(colour
, wxSOLID
);
978 destDC
.SetBackground(brush
);
980 destDC
.Blit(0, 0, bitmap
.GetWidth(), bitmap
.GetHeight(),
981 &srcDC
, 0, 0, wxCOPY
, true);
986 // ----------------------------------------------------------------------------
987 // Miscellaneous functions
988 // ----------------------------------------------------------------------------
990 WXWidget
wxCreateBorderWidget( WXWidget parent
, long style
)
992 Widget borderWidget
= (Widget
)NULL
, parentWidget
= (Widget
)parent
;
994 if (style
& wxSIMPLE_BORDER
)
996 borderWidget
= XtVaCreateManagedWidget
999 xmFrameWidgetClass
, parentWidget
,
1000 XmNshadowType
, XmSHADOW_ETCHED_IN
,
1001 XmNshadowThickness
, 1,
1005 else if (style
& wxSUNKEN_BORDER
)
1007 borderWidget
= XtVaCreateManagedWidget
1010 xmFrameWidgetClass
, parentWidget
,
1011 XmNshadowType
, XmSHADOW_IN
,
1015 else if (style
& wxRAISED_BORDER
)
1017 borderWidget
= XtVaCreateManagedWidget
1020 xmFrameWidgetClass
, parentWidget
,
1021 XmNshadowType
, XmSHADOW_OUT
,
1026 return borderWidget
;