X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fbfb8bcc3fa17e079d4219655b173f8ed2ccc65a..68ca12fef650ce4622e05ba4eb21a7aa23849107:/src/motif/utils.cpp diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index fee2d0fb03..595e14696a 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: utils.cpp +// Name: src/motif/utils.cpp // Purpose: Various utilities // Author: Julian Smart // Modified by: @@ -24,13 +24,17 @@ #define XtDisplay XTDISPLAY #endif -#include "wx/setup.h" #include "wx/utils.h" + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/dcmemory.h" + #include "wx/bitmap.h" +#endif + #include "wx/apptrait.h" -#include "wx/app.h" -#include "wx/dcmemory.h" -#include "wx/bitmap.h" #include "wx/evtloop.h" +#include "wx/motif/private/timer.h" #include @@ -49,31 +53,12 @@ #include "wx/motif/private.h" -#if wxUSE_RESOURCES -#include "X11/Xresource.h" -#endif - #include "X11/Xutil.h" #ifdef __VMS__ #pragma message enable nosimpint #endif -// ---------------------------------------------------------------------------- -// private functions -// ---------------------------------------------------------------------------- - -// Yuck this is really BOTH site and platform dependent -// so we should use some other strategy! -#ifdef sun - #define DEFAULT_XRESOURCE_DIR "/usr/openwin/lib/app-defaults" -#else - #define DEFAULT_XRESOURCE_DIR "/usr/lib/X11/app-defaults" -#endif - -#if wxUSE_RESOURCES -static char *GetIniFile (char *dest, const char *filename); -#endif // ============================================================================ // implementation @@ -140,373 +125,27 @@ void wxBell() } #endif -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo info; + // XmVERSION and XmREVISION are defined in Xm/Xm.h + if ( verMaj ) + *verMaj = XmVERSION; + if ( verMin ) + *verMin = XmREVISION; - info.shortName = _T("motif"); - info.name = _T("wxMotif"); -#ifdef __WXUNIVERSAL__ - info.shortName << _T("univ"); - info.name << _T("/wxUniversal"); -#endif - // FIXME TODO - // This code is WRONG!! Does NOT return the - // Motif version of the libs but the X protocol - // version! - Display *display = wxGlobalDisplay(); - if (display) - { - info.versionMajor = ProtocolVersion (display); - info.versionMinor = ProtocolRevision (display); - } - info.os = wxMOTIF_X; - return info; + return wxPORT_MOTIF; } -// ---------------------------------------------------------------------------- -// Reading and writing resources (eg WIN.INI, .Xdefaults) -// ---------------------------------------------------------------------------- - -#if wxUSE_RESOURCES - -// Read $HOME for what it says is home, if not -// read $USER or $LOGNAME for user name else determine -// the Real User, then determine the Real home dir. -static char * GetIniFile (char *dest, const char *filename) +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() { - char *home = NULL; - if (filename && wxIsAbsolutePath(filename)) - { - strcpy(dest, filename); - } - else if ((home = wxGetUserHome("")) != NULL) - { - strcpy(dest, home); - if (dest[strlen(dest) - 1] != '/') - strcat (dest, "/"); - if (filename == NULL) - { - if ((filename = getenv ("XENVIRONMENT")) == NULL) - filename = ".Xdefaults"; - } - else if (*filename != '.') - strcat (dest, "."); - strcat (dest, filename); - } else - { - dest[0] = '\0'; - } - return dest; + return new wxEventLoop; } -static char *GetResourcePath(char *buf, const char *name, bool create = false) +wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer* timer) { - if (create && wxFileExists (name) ) { - strcpy(buf, name); - return buf; // Exists so ... - } - - if (*name == '/') - strcpy(buf, name); - else { - // Put in standard place for resource files if not absolute - strcpy (buf, DEFAULT_XRESOURCE_DIR); - strcat (buf, "/"); - strcat (buf, wxFileNameFromPath (name).c_str()); - } - - if (create) { - // Touch the file to create it - FILE *fd = fopen (buf, "w"); - if (fd) fclose (fd); - } - return buf; + return new wxMotifTimerImpl(timer); } -/* -* We have a cache for writing different resource files, -* which will only get flushed when we call wxFlushResources(). -* Build up a list of resource databases waiting to be written. -* -*/ - -wxList wxResourceCache (wxKEY_STRING); - -void -wxFlushResources (void) -{ - char nameBuffer[512]; - - wxNode *node = wxResourceCache.First (); - while (node) - { - const char *file = node->GetKeyString(); - // If file doesn't exist, create it first. - (void)GetResourcePath(nameBuffer, file, true); - - XrmDatabase database = (XrmDatabase) node->Data (); - XrmPutFileDatabase (database, nameBuffer); - XrmDestroyDatabase (database); - wxNode *next = node->Next (); - delete node; - node = next; - } -} - -static XrmDatabase wxResourceDatabase = 0; - -void wxXMergeDatabases (wxApp * theApp, Display * display); - -bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) -{ - char buffer[500]; - - (void) GetIniFile (buffer, file); - - XrmDatabase database; - wxNode *node = wxResourceCache.Find (buffer); - if (node) - database = (XrmDatabase) node->Data (); - else - { - database = XrmGetFileDatabase (buffer); - wxResourceCache.Append (buffer, (wxObject *) database); - } - - char resName[300]; - strcpy (resName, section.c_str()); - strcat (resName, "."); - strcat (resName, entry.c_str()); - - XrmPutStringResource (&database, resName, value); - return true; -} - -bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file) -{ - char buf[50]; - sprintf(buf, "%.4f", value); - return wxWriteResource(section, entry, buf, file); -} - -bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file) -{ - char buf[50]; - sprintf(buf, "%ld", value); - return wxWriteResource(section, entry, buf, file); -} - -bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file) -{ - char buf[50]; - sprintf(buf, "%d", value); - return wxWriteResource(section, entry, buf, file); -} - -bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file) -{ - if (!wxResourceDatabase) - { - Display *display = wxGlobalDisplay(); - wxXMergeDatabases (wxTheApp, display); - } - - XrmDatabase database; - - if (file != "") - { - char buffer[500]; - - // Is this right? Trying to get it to look in the user's - // home directory instead of current directory -- JACS - (void) GetIniFile (buffer, file); - - wxNode *node = wxResourceCache.Find (buffer); - if (node) - database = (XrmDatabase) node->Data (); - else - { - database = XrmGetFileDatabase (buffer); - wxResourceCache.Append (buffer, (wxObject *) database); - } - } - else - database = wxResourceDatabase; - - XrmValue xvalue; - char *str_type[20]; - char buf[150]; - strcpy (buf, section); - strcat (buf, "."); - strcat (buf, entry); - - Bool success = XrmGetResource (database, buf, "*", str_type, - &xvalue); - // Try different combinations of upper/lower case, just in case... - if (!success) - { - buf[0] = (isupper (buf[0]) ? tolower (buf[0]) : toupper (buf[0])); - success = XrmGetResource (database, buf, "*", str_type, - &xvalue); - } - if (success) - { - if (*value) - delete[] *value; - - *value = new char[xvalue.size + 1]; - strncpy (*value, xvalue.addr, (int) xvalue.size); - return true; - } - return false; -} - -bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file) -{ - char *s = NULL; - bool succ = wxGetResource(section, entry, (char **)&s, file); - if (succ) - { - *value = (float)strtod(s, NULL); - delete[] s; - return true; - } - else return false; -} - -bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file) -{ - char *s = NULL; - bool succ = wxGetResource(section, entry, (char **)&s, file); - if (succ) - { - *value = strtol(s, NULL, 10); - delete[] s; - return true; - } - else return false; -} - -bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file) -{ - char *s = NULL; - bool succ = wxGetResource(section, entry, (char **)&s, file); - if (succ) - { - // Handle True, False here - // True, Yes, Enables, Set or Activated - if (*s == 'T' || *s == 'Y' || *s == 'E' || *s == 'S' || *s == 'A') - *value = true; - // False, No, Disabled, Reset, Cleared, Deactivated - else if (*s == 'F' || *s == 'N' || *s == 'D' || *s == 'R' || *s == 'C') - *value = false; - // Handle as Integer - else - *value = (int) strtol (s, NULL, 10); - delete[] s; - return true; - } - else - return false; -} - -void wxXMergeDatabases (wxApp * theApp, Display * display) -{ - XrmDatabase homeDB, serverDB, applicationDB; - char filenamebuf[1024]; - - char *filename = &filenamebuf[0]; - char *environment; - wxString classname = theApp->GetClassName(); - char name[256]; - (void) strcpy (name, "/usr/lib/X11/app-defaults/"); - (void) strcat (name, classname.c_str()); - - /* Get application defaults file, if any */ - applicationDB = XrmGetFileDatabase (name); - (void) XrmMergeDatabases (applicationDB, &wxResourceDatabase); - - /* Merge server defaults, created by xrdb, loaded as a property of the root - * window when the server initializes and loaded into the display - * structure on XOpenDisplay; - * if not defined, use .Xdefaults - */ - - if (XResourceManagerString (display) != NULL) - { - serverDB = XrmGetStringDatabase (XResourceManagerString (display)); - } - else - { - (void) GetIniFile (filename, NULL); - serverDB = XrmGetFileDatabase (filename); - } - XrmMergeDatabases (serverDB, &wxResourceDatabase); - - /* Open XENVIRONMENT file, or if not defined, the .Xdefaults, - * and merge into existing database - */ - - if ((environment = getenv ("XENVIRONMENT")) == NULL) - { - size_t len; - environment = GetIniFile (filename, NULL); - len = strlen (environment); - wxString hostname = wxGetHostName(); - if ( !!hostname ) - strncat(environment, hostname, 1024 - len); - } - homeDB = XrmGetFileDatabase (environment); - XrmMergeDatabases (homeDB, &wxResourceDatabase); -} - -#if 0 - -/* -* Not yet used but may be useful. -* -*/ -void -wxSetDefaultResources (const Widget w, const char **resourceSpec, const char *name) -{ - int i; - Display *dpy = XtDisplay (w); // Retrieve the display pointer - - XrmDatabase rdb = NULL; // A resource data base - - // Create an empty resource database - rdb = XrmGetStringDatabase (""); - - // Add the Component resources, prepending the name of the component - - i = 0; - while (resourceSpec[i] != NULL) - { - char buf[1000]; - - sprintf (buf, "*%s%s", name, resourceSpec[i++]); - XrmPutLineResource (&rdb, buf); - } - - // Merge them into the Xt database, with lowest precendence - - if (rdb) - { -#if (XlibSpecificationRelease>=5) - XrmDatabase db = XtDatabase (dpy); - XrmCombineDatabase (rdb, &db, False); -#else - XrmMergeDatabases (dpy->db, &rdb); - dpy->db = rdb; -#endif - } -} -#endif -// 0 - -#endif // wxUSE_RESOURCES - // ---------------------------------------------------------------------------- // display info // ---------------------------------------------------------------------------- @@ -529,7 +168,7 @@ void wxGetMousePosition( int* x, int* y ) *x = xev.x_root; *y = xev.y_root; #endif -}; +} // Return true if we have a colour display bool wxColourDisplay() @@ -566,18 +205,6 @@ void wxDisplaySizeMM(int *width, int *height) *height = DisplayHeightMM(dpy, DefaultScreen (dpy)); } -void wxClientDisplayRect(int *x, int *y, int *width, int *height) -{ - // This is supposed to return desktop dimensions minus any window - // manager panels, menus, taskbars, etc. If there is a way to do that - // for this platform please fix this function, otherwise it defaults - // to the entire desktop. - if (x) *x = 0; - if (y) *y = 0; - wxDisplaySize(width, height); -} - - // Configurable display in wxX11 and wxMotif static WXDisplay *gs_currentDisplay = NULL; static wxString gs_displayName; @@ -667,9 +294,9 @@ void wxHSVToXColor(wxHSV *hsv,XColor *rgb) case 4: r = t, g = p, b = v; break; case 5: r = v, g = p, b = q; break; } - rgb->red = r << 8; - rgb->green = g << 8; - rgb->blue = b << 8; + rgb->red = (unsigned short)(r << 8); + rgb->green = (unsigned short)(g << 8); + rgb->blue = (unsigned short)(b << 8); } void wxXColorToHSV(wxHSV *hsv,XColor *rgb) @@ -811,6 +438,7 @@ char wxFindMnemonic (const char *s) char* wxFindAccelerator( const char *s ) { #if 1 + wxUnusedVar(s); // VZ: this function returns incorrect keysym which completely breaks kbd // handling return NULL; @@ -878,6 +506,7 @@ char* wxFindAccelerator( const char *s ) XmString wxFindAcceleratorText (const char *s) { #if 1 + wxUnusedVar(s); // VZ: this function returns incorrect keysym which completely breaks kbd // handling return NULL; @@ -894,6 +523,9 @@ XmString wxFindAcceleratorText (const char *s) // Change a widget's foreground and background colours. void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) { + if (!foregroundColour.Ok()) + return; + // When should we specify the foreground, if it's calculated // by wxComputeColours? // Solution: say we start with the default (computed) foreground colour. @@ -908,8 +540,11 @@ void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) NULL); } -void wxDoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour) +void wxDoChangeBackgroundColour(WXWidget widget, const wxColour& backgroundColour, bool changeArmColour) { + if (!backgroundColour.Ok()) + return; + wxComputeColours (XtDisplay((Widget) widget), & backgroundColour, (wxColour*) NULL); @@ -934,6 +569,9 @@ extern void wxDoChangeFont(WXWidget widget, const wxFont& font) XtVaSetValues( w, wxFont::GetFontTag(), font.GetFontTypeC( XtDisplay(w) ), NULL ); +#else + wxUnusedVar(widget); + wxUnusedVar(font); #endif } @@ -951,11 +589,6 @@ wxString wxXmStringToString( const XmString& xmString ) return wxEmptyString; } -XmString wxStringToXmString( const wxString& str ) -{ - return XmStringCreateLtoR((char *)str.c_str(), XmSTRING_DEFAULT_CHARSET); -} - XmString wxStringToXmString( const char* str ) { return XmStringCreateLtoR((char *)str, XmSTRING_DEFAULT_CHARSET); @@ -975,7 +608,7 @@ wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, const wxColour& colour) wxMemoryDC destDC; wxMemoryDC srcDC; - srcDC.SelectObject(bitmap); + srcDC.SelectObjectAsSource(bitmap); destDC.SelectObject(newBitmap); wxBrush brush(colour, wxSOLID); @@ -1006,7 +639,7 @@ WXWidget wxCreateBorderWidget( WXWidget parent, long style ) NULL ); } - else if (style & wxSUNKEN_BORDER) + else if ((style & wxSUNKEN_BORDER) || (style & wxBORDER_THEME)) { borderWidget = XtVaCreateManagedWidget (