-#include "wx/gdicmn.h"
-
-#include <ctype.h>
-#include <string.h>
-#include <unistd.h>
-//#ifdef __SVR4__
-//#include <sys/systeminfo.h>
-//#endif
-
-#include "gdk/gdkx.h" // GDK_DISPLAY
-#include "gdk/gdkprivate.h" // gdk_progclass
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xresource.h>
-
-
-//-----------------------------------------------------------------------------
-// constants
-//-----------------------------------------------------------------------------
-
-// Yuck this is really BOTH site and platform dependent
-// so we should use some other strategy!
-#ifdef __SUN__
-# define DEFAULT_XRESOURCE_DIR wxT("/usr/openwin/lib/app-defaults")
-#else
-# define DEFAULT_XRESOURCE_DIR wxT("/usr/lib/X11/app-defaults")
-#endif
-
-//-----------------------------------------------------------------------------
-// glabal data (data.cpp)
-//-----------------------------------------------------------------------------
-
-extern wxResourceCache *wxTheResourceCache;
-extern XrmDatabase wxResourceDatabase;
-
-//-----------------------------------------------------------------------------
-// utility functions for get/write resources
-//-----------------------------------------------------------------------------
-
-static wxChar *GetResourcePath(wxChar *buf, wxChar *name, bool create)
-{
- if (create && FileExists(name))
- {
- wxStrcpy(buf, name);
- return buf; // Exists so ...
- }
- if (*name == wxT('/'))
- wxStrcpy(buf, name);
- else
- {
- // Put in standard place for resource files if not absolute
- wxStrcpy(buf, DEFAULT_XRESOURCE_DIR);
- wxStrcat(buf, wxT("/"));
- wxStrcat(buf, FileNameFromPath(name));
- }
- if (create)
- {
- // Touch the file to create it
- FILE *fd = fopen(wxConvCurrent->cWX2MB(buf), "w");
- if (fd) fclose(fd);
- }
- return buf;
-}
-
-// 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 wxChar *GetIniFile(wxChar *dest, const wxChar *filename)
-{
- const wxChar *home = (const wxChar *) NULL;
- if (filename && wxIsAbsolutePath(filename))
- {
- wxStrcpy(dest, filename);
- }
- else
- {
- if ((home = wxGetUserHome(wxString())) != NULL)
- {
- wxStrcpy(dest, home);
- if (dest[wxStrlen(dest) - 1] != wxT('/')) wxStrcat(dest, wxT("/"));
- if (filename == NULL)
- {
- if ((filename = wxGetenv(wxT("XENVIRONMENT"))) == NULL) filename = wxT(".Xdefaults");
- }
- else
- if (*filename != wxT('.')) wxStrcat(dest, wxT("."));
- wxStrcat(dest, filename);
- }
- else
- {
- dest[0] = wxT('\0');
- }
- }
- return dest;
-}
-
-static void wxXMergeDatabases()
-{
- XrmDatabase homeDB, serverDB, applicationDB;
- wxChar filenamebuf[1024];
-
- wxChar *filename = &filenamebuf[0];
- wxChar *environment;
- char *classname = gdk_progclass; // Robert Roebling ??
- char name[256];
- (void)strcpy(name, "/usr/lib/X11/app-defaults/");
- (void)strcat(name, classname ? classname : "wxWindows");
-
- // Get application defaults file, if any
- if ((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(GDK_DISPLAY()) != NULL)
- {
- serverDB = XrmGetStringDatabase(XResourceManagerString(GDK_DISPLAY()));
- }
- else
- {
- (void)GetIniFile(filename, (wxChar *) NULL);
- serverDB = XrmGetFileDatabase(wxConvCurrent->cWX2MB(filename));
- }
- if (serverDB)
- XrmMergeDatabases(serverDB, &wxResourceDatabase);
-
- // Open XENVIRONMENT file, or if not defined, the .Xdefaults,
- // and merge into existing database
-
- if ((environment = wxGetenv(wxT("XENVIRONMENT"))) == NULL)
- {
- environment = GetIniFile(filename, (const wxChar *) NULL);
- size_t len = wxStrlen(environment);
-
- char hostbuf[1024];
- (void)wxGetHostName(hostbuf, WXSIZEOF(hostbuf) - len);
-
- wxStrcat(environment, wxConvCurrent->cMB2WX(hostbuf));
- }
-
- if ((homeDB = XrmGetFileDatabase(wxConvCurrent->cWX2MB(environment))))
- XrmMergeDatabases(homeDB, &wxResourceDatabase);
-}
-
-//-----------------------------------------------------------------------------
-// called on application exit
-//-----------------------------------------------------------------------------
-
-void wxFlushResources()
-{
- wxChar nameBuffer[512];
-
- wxNode *node = wxTheResourceCache->First();
- while (node) {
- wxString str = node->GetKeyString();
- wxChar *file = WXSTRINGCAST str;
- // If file doesn't exist, create it first.
- (void)GetResourcePath(nameBuffer, file, TRUE);
-
- XrmDatabase database = (XrmDatabase)node->Data();
- XrmPutFileDatabase(database, wxConvCurrent->cWX2MB(nameBuffer));
- XrmDestroyDatabase(database);
- wxNode *next = node->Next();
-// delete node;
- node = next;
- }
-}
-
-void wxDeleteResources(const wxChar *file)
-{
- wxLogTrace(wxTraceResAlloc, wxT("Delete: Number = %d"), wxTheResourceCache->Number());
- wxChar buffer[500];
- (void)GetIniFile(buffer, file);
-
- wxNode *node = wxTheResourceCache->Find(buffer);
- if (node) {
- XrmDatabase database = (XrmDatabase)node->Data();
- XrmDestroyDatabase(database);
-// delete node;
- }
-}