X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7f985bd39a0605d8dea4b4b1abc717c5658209c6..3e1ed7d709cf4e81556589a8c2132882f40d97ff:/src/gtk1/utilsres.cpp diff --git a/src/gtk1/utilsres.cpp b/src/gtk1/utilsres.cpp index d743ad554e..ea2c8af90e 100644 --- a/src/gtk1/utilsres.cpp +++ b/src/gtk1/utilsres.cpp @@ -15,13 +15,15 @@ #include "wx/utils.h" #include "wx/string.h" #include "wx/list.h" +#include "wx/log.h" +#include "wx/gdicmn.h" #include #include #include -#ifdef __SVR4__ -#include -#endif +//#ifdef __SVR4__ +//#include +//#endif #include "gdk/gdkx.h" // GDK_DISPLAY #include "gdk/gdkprivate.h" // gdk_progclass @@ -30,7 +32,6 @@ #include #include -#include "wx/log.h" //----------------------------------------------------------------------------- // constants @@ -39,9 +40,9 @@ // 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" +# define DEFAULT_XRESOURCE_DIR wxT("/usr/openwin/lib/app-defaults") #else - #define DEFAULT_XRESOURCE_DIR "/usr/lib/X11/app-defaults" +# define DEFAULT_XRESOURCE_DIR wxT("/usr/lib/X11/app-defaults") #endif //----------------------------------------------------------------------------- @@ -55,23 +56,26 @@ extern XrmDatabase wxResourceDatabase; // utility functions for get/write resources //----------------------------------------------------------------------------- -static char *GetResourcePath(char *buf, char *name, bool create) +static wxChar *GetResourcePath(wxChar *buf, wxChar *name, bool create) { - if (create && FileExists(name)) { - strcpy(buf, name); + if (create && FileExists(name)) + { + wxStrcpy(buf, name); return buf; // Exists so ... } - if (*name == '/') - strcpy(buf, name); - else { + if (*name == wxT('/')) + wxStrcpy(buf, name); + else + { // Put in standard place for resource files if not absolute - strcpy(buf, DEFAULT_XRESOURCE_DIR); - strcat(buf, "/"); - strcat(buf, FileNameFromPath(name)); + wxStrcpy(buf, DEFAULT_XRESOURCE_DIR); + wxStrcat(buf, wxT("/")); + wxStrcat(buf, FileNameFromPath(name)); } - if (create) { + if (create) + { // Touch the file to create it - FILE *fd = fopen(buf, "w"); + FILE *fd = fopen(wxConvCurrent->cWX2MB(buf), "w"); if (fd) fclose(fd); } return buf; @@ -80,42 +84,42 @@ static char *GetResourcePath(char *buf, char *name, bool create) // 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) +static wxChar *GetIniFile(wxChar *dest, const wxChar *filename) { - char *home = (char *) NULL; + const wxChar *home = (const wxChar *) NULL; if (filename && wxIsAbsolutePath(filename)) { - strcpy(dest, filename); + wxStrcpy(dest, filename); } else { if ((home = wxGetUserHome(wxString())) != NULL) { - strcpy(dest, home); - if (dest[strlen(dest) - 1] != '/') strcat(dest, "/"); + wxStrcpy(dest, home); + if (dest[wxStrlen(dest) - 1] != wxT('/')) wxStrcat(dest, wxT("/")); if (filename == NULL) { - if ((filename = getenv("XENVIRONMENT")) == NULL) filename = ".Xdefaults"; + if ((filename = wxGetenv(wxT("XENVIRONMENT"))) == NULL) filename = wxT(".Xdefaults"); } else - if (*filename != '.') strcat(dest, "."); - strcat(dest, filename); + if (*filename != wxT('.')) wxStrcat(dest, wxT(".")); + wxStrcat(dest, filename); } else { - dest[0] = '\0'; + dest[0] = wxT('\0'); } } return dest; } -static void wxXMergeDatabases(void) +static void wxXMergeDatabases() { XrmDatabase homeDB, serverDB, applicationDB; - char filenamebuf[1024]; + wxChar filenamebuf[1024]; - char *filename = &filenamebuf[0]; - char *environment; + wxChar *filename = &filenamebuf[0]; + wxChar *environment; char *classname = gdk_progclass; // Robert Roebling ?? char name[256]; (void)strcpy(name, "/usr/lib/X11/app-defaults/"); @@ -129,11 +133,14 @@ static void wxXMergeDatabases(void) // window when the server initializes and loaded into the display // structure on XOpenDisplay; // if not defined, use .Xdefaults - if (XResourceManagerString(GDK_DISPLAY()) != NULL) { + if (XResourceManagerString(GDK_DISPLAY()) != NULL) + { serverDB = XrmGetStringDatabase(XResourceManagerString(GDK_DISPLAY())); - } else { - (void)GetIniFile(filename, (char *) NULL); - serverDB = XrmGetFileDatabase(filename); + } + else + { + (void)GetIniFile(filename, (wxChar *) NULL); + serverDB = XrmGetFileDatabase(wxConvCurrent->cWX2MB(filename)); } if (serverDB) XrmMergeDatabases(serverDB, &wxResourceDatabase); @@ -141,17 +148,18 @@ static void wxXMergeDatabases(void) // 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, (const char *) NULL); - len = strlen(environment); -#if !defined(SVR4) || defined(__sgi) - (void)gethostname(environment + len, 1024 - len); -#else - (void)sysinfo(SI_HOSTNAME, environment + len, 1024 - len); -#endif + if ((environment = wxGetenv(wxT("XENVIRONMENT"))) == NULL) + { + environment = GetIniFile(filename, (const wxChar *) NULL); + size_t len = wxStrlen(environment); + + wxChar hostbuf[1024]; + (void)wxGetHostName(hostbuf, WXSIZEOF(hostbuf) - len); + + wxStrcat(environment, hostbuf); } - if ((homeDB = XrmGetFileDatabase(environment))) + + if ((homeDB = XrmGetFileDatabase(wxConvCurrent->cWX2MB(environment)))) XrmMergeDatabases(homeDB, &wxResourceDatabase); } @@ -159,19 +167,19 @@ static void wxXMergeDatabases(void) // called on application exit //----------------------------------------------------------------------------- -void wxFlushResources(void) +void wxFlushResources() { - char nameBuffer[512]; + wxChar nameBuffer[512]; wxNode *node = wxTheResourceCache->First(); while (node) { wxString str = node->GetKeyString(); - char *file = WXSTRINGCAST str; + wxChar *file = WXSTRINGCAST str; // If file doesn't exist, create it first. (void)GetResourcePath(nameBuffer, file, TRUE); XrmDatabase database = (XrmDatabase)node->Data(); - XrmPutFileDatabase(database, nameBuffer); + XrmPutFileDatabase(database, wxConvCurrent->cWX2MB(nameBuffer)); XrmDestroyDatabase(database); wxNode *next = node->Next(); // delete node; @@ -179,10 +187,10 @@ void wxFlushResources(void) } } -void wxDeleteResources(const char *file) +void wxDeleteResources(const wxChar *file) { - wxLogTrace(wxTraceResAlloc, "Delete: Number = %d", wxTheResourceCache->Number()); - char buffer[500]; + wxLogTrace(wxTraceResAlloc, wxT("Delete: Number = %d"), wxTheResourceCache->Number()); + wxChar buffer[500]; (void)GetIniFile(buffer, file); wxNode *node = wxTheResourceCache->Find(buffer); @@ -199,7 +207,7 @@ void wxDeleteResources(const char *file) bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file ) { - char buffer[500]; + wxChar buffer[500]; if (!entry) return FALSE; @@ -210,15 +218,15 @@ bool wxWriteResource(const wxString& section, const wxString& entry, const wxStr if (node) database = (XrmDatabase)node->Data(); else { - database = XrmGetFileDatabase(buffer); - wxLogTrace(wxTraceResAlloc, "Write: Number = %d", wxTheResourceCache->Number()); + database = XrmGetFileDatabase(wxConvCurrent->cWX2MB(buffer)); + wxLogTrace(wxTraceResAlloc, wxT("Write: Number = %d"), wxTheResourceCache->Number()); wxTheResourceCache->Append(buffer, (wxObject *)database); } char resName[300]; - strcpy(resName, !section.IsNull() ? WXSTRINGCAST section : "wxWindows"); + strcpy(resName, !section.IsNull() ? wxMBSTRINGCAST section.mb_str() : "wxWindows"); strcat(resName, "."); - strcat(resName, entry); - XrmPutStringResource(&database, resName, value); + strcat(resName, entry.mb_str()); + XrmPutStringResource(&database, resName, value.mb_str()); return TRUE; }; @@ -249,18 +257,23 @@ bool wxGetResource(const wxString& section, const wxString& entry, char **value, wxXMergeDatabases(); XrmDatabase database; - if (file) { - char buffer[500]; + if (!file.IsEmpty()) + { + wxChar 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 = wxTheResourceCache->Find(buffer); + wxNode *node = (wxNode*) NULL; /* suppress egcs warning */ + node = wxTheResourceCache->Find(buffer); if (node) + { database = (XrmDatabase)node->Data(); - else { - database = XrmGetFileDatabase(buffer); - wxLogTrace(wxTraceResAlloc, "Get: Number = %d", wxTheResourceCache->Number()); + } + else + { + database = XrmGetFileDatabase(wxConvCurrent->cWX2MB(buffer)); + wxLogTrace(wxTraceResAlloc, wxT("Get: Number = %d"), wxTheResourceCache->Number()); wxTheResourceCache->Append(buffer, (wxObject *)database); } } else @@ -269,17 +282,19 @@ bool wxGetResource(const wxString& section, const wxString& entry, char **value, XrmValue xvalue; char *str_type[20]; char buf[150]; - strcpy(buf, section); + strcpy(buf, section.mb_str()); strcat(buf, "."); - strcat(buf, entry); + strcat(buf, entry.mb_str()); bool success = XrmGetResource(database, buf, "*", str_type, &xvalue); // Try different combinations of upper/lower case, just in case... - if (!success) { + if (!success) + { buf[0] = (isupper(buf[0]) ? tolower(buf[0]) : toupper(buf[0])); success = XrmGetResource(database, buf, "*", str_type, &xvalue); } - if (success) { + if (success) + { if (*value) delete[] *value; *value = new char[xvalue.size + 1]; @@ -293,7 +308,8 @@ bool wxGetResource(const wxString& section, const wxString& entry, float *value, { char *s = (char *) NULL; bool succ = wxGetResource(section, entry, &s, file); - if (succ) { + if (succ) + { *value = (float)strtod(s, (char **) NULL); delete[]s; return TRUE; @@ -305,7 +321,8 @@ bool wxGetResource(const wxString& section, const wxString& entry, long *value, { char *s = (char *) NULL; bool succ = wxGetResource(section, entry, &s, file); - if (succ) { + if (succ) + { *value = strtol(s, (char **) NULL, 10); delete[]s; return TRUE; @@ -317,7 +334,8 @@ bool wxGetResource(const wxString& section, const wxString& entry, int *value, c { char *s = (char *) NULL; bool succ = wxGetResource(section, entry, &s, file); - if (succ) { + if (succ) + { // Handle True, False here // True, Yes, Enables, Set or Activated if (*s == 'T' || *s == 'Y' || *s == 'E' || *s == 'S' || *s == 'A')