#include "wx/setup.h"
#include "wx/utils.h"
#include "wx/app.h"
+#include "wx/apptrait.h"
#include "wx/msgdlg.h"
#include "wx/cursor.h"
#include "wx/window.h" // for wxTopLevelWindows
#include <sys/wait.h>
#include <pwd.h>
#include <errno.h>
-#include <netdb.h>
+// #include <netdb.h>
#include <signal.h>
#if (defined(__SUNCC__) || defined(__CLCC__))
#pragma message disable nosimpint
#endif
-#ifdef __WXMOTIF__
-#include <Xm/Xm.h>
-#endif
-
-#ifdef __VMS__
-#pragma message enable nosimpint
-#endif
-
#include "wx/unix/execute.h"
-#ifdef __WXMOTIF__
-#include "wx/motif/private.h"
-#endif
-
-#ifdef __WXX11__
#include "wx/x11/private.h"
-#endif
-#include "X11/Xresource.h"
#include "X11/Xutil.h"
-// ----------------------------------------------------------------------------
-// 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"
+#ifdef __VMS__
+#pragma message enable nosimpint
#endif
-static char *GetIniFile (char *dest, const char *filename);
-
-// ============================================================================
-// implementation
-// ============================================================================
-
// ----------------------------------------------------------------------------
// async event processing
// ----------------------------------------------------------------------------
XSync (display, FALSE);
-#ifdef __WXMOTIF__
- // XtAppPending returns availability of events AND timers/inputs, which
- // are processed via callbacks, so XtAppNextEvent will not return if
- // there are no events. So added '& XtIMXEvent' - Sergey.
- while (XtAppPending ((XtAppContext) wxTheApp->GetAppContext()) & XtIMXEvent)
- {
- XFlush (XtDisplay ((Widget) wxTheApp->GetTopLevelWidget()));
- // Jan Lessner: works better when events are non-X events
- XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMXEvent);
- }
-#endif
-#ifdef __WXX11__
// TODO for X11
// ??
-#endif
}
-// Check whether this window wants to process messages, e.g. Stop button
-// in long calculations.
bool wxCheckForInterrupt(wxWindow *wnd)
{
-#ifdef __WXMOTIF__
- wxCHECK_MSG( wnd, FALSE, "NULL window in wxCheckForInterrupt" );
-
- Display *dpy=(Display*) wnd->GetXDisplay();
- Window win=(Window) wnd->GetXWindow();
- XEvent event;
- XFlush(dpy);
- if (wnd->GetMainWidget())
- {
- XmUpdateDisplay((Widget)(wnd->GetMainWidget()));
- }
-
- bool hadEvents = FALSE;
- while( XCheckMaskEvent(dpy,
- ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|
- PointerMotionMask|KeyPressMask|KeyReleaseMask,
- &event) )
- {
- if ( event.xany.window == win )
- {
- hadEvents = TRUE;
-
- XtDispatchEvent(&event);
- }
- }
-
- return hadEvents;
-#else
- wxASSERT_MSG(FALSE, "wxCheckForInterrupt not yet implemented.");
+ wxASSERT_MSG(FALSE, wxT("wxCheckForInterrupt not yet implemented."));
return FALSE;
-#endif
}
// ----------------------------------------------------------------------------
// wxExecute stuff
// ----------------------------------------------------------------------------
-#ifdef __WXMOTIF__
-static void xt_notify_end_process(XtPointer data, int *WXUNUSED(fid),
- XtInputId *id)
-{
- wxEndProcessData *proc_data = (wxEndProcessData *)data;
-
- wxHandleProcessTermination(proc_data);
-
- // VZ: I think they should be the same...
- wxASSERT( (int)*id == proc_data->tag );
-
- XtRemoveInput(*id);
-}
-#endif
int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
{
-#ifdef __WXMOTIF__
- XtInputId id = XtAppAddInput((XtAppContext) wxTheApp->GetAppContext(),
- fd,
- (XtPointer *) XtInputReadMask,
- (XtInputCallbackProc) xt_notify_end_process,
- (XtPointer) proc_data);
-
- return (int)id;
-#endif
-#ifdef __WXX11__
// TODO
return 0;
-#endif
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Emit a beeeeeep
+#ifndef __EMX__
+// on OS/2, we use the wxBell from wxBase library (src/os2/utils.cpp)
void wxBell()
{
// Use current setting for the bell
XBell ((Display*) wxGetDisplay(), 0);
}
-
-int wxGetOsVersion(int *majorVsn, int *minorVsn)
-{
-#ifdef __WXMOTIF__
- // FIXME TODO
- // This code is WRONG!! Does NOT return the
- // Motif version of the libs but the X protocol
- // version!
- Display *display = XtDisplay ((Widget) wxTheApp->GetTopLevelWidget());
- if (majorVsn)
- *majorVsn = ProtocolVersion (display);
- if (minorVsn)
- *minorVsn = ProtocolRevision (display);
-
- return wxMOTIF_X;
#endif
-#ifdef __WXX11__
- if (majorVsn)
- *majorVsn = 0;
- if (minorVsn)
- *minorVsn = 0;
- return wxX11;
-#endif
-}
-
-// ----------------------------------------------------------------------------
-// Reading and writing resources (eg WIN.INI, .Xdefaults)
-// ----------------------------------------------------------------------------
-
-// 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)
-{
- 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;
-}
-
-#if wxUSE_RESOURCES
-
-static char *GetResourcePath(char *buf, const char *name, bool create = FALSE)
-{
- 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, (const char*) wxFileNameFromPath (name));
- }
-
- if (create) {
- // Touch the file to create it
- FILE *fd = fopen (buf, "w");
- if (fd) fclose (fd);
- }
- return buf;
-}
-
-/*
-* 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, (const char*) section);
- strcat (resName, ".");
- strcat (resName, (const char*) entry);
-
- 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 = (Display*) wxGetDisplay();
- 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)
+wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
{
- 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;
+ static wxToolkitInfo info;
+ info.shortName = _T("x11univ");
+ info.name = _T("wxX11");
+ info.versionMajor = 0;
+ info.versionMinor = 0;
+ info.os = wxX11;
+ return info;
}
-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, (const char*) classname);
-
- /* 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
// ----------------------------------------------------------------------------
void wxGetMousePosition( int* x, int* y )
{
+#if wxUSE_NANOX
+ // TODO
+ *x = 0;
+ *y = 0;
+#else
XMotionEvent xev;
Window root, child;
XQueryPointer((Display*) wxGetDisplay(),
&(xev.state));
*x = xev.x_root;
*y = xev.y_root;
+#endif
};
// Return TRUE if we have a colour display
{
if (gs_currentDisplay)
return gs_currentDisplay;
-#ifdef __WXMOTIF__
- if (wxTheApp && wxTheApp->GetTopLevelWidget())
- return XtDisplay ((Widget) wxTheApp->GetTopLevelWidget());
- else if (wxTheApp)
- return wxTheApp->GetInitialDisplay();
- return NULL;
-#endif
-#ifdef __WXX11__
return wxApp::GetDisplay();
-#endif
}
bool wxSetDisplay(const wxString& display_name)
}
else
{
-#ifdef __WXMOTIF__
- Cardinal argc = 0;
-
- Display *display = XtOpenDisplay((XtAppContext) wxTheApp->GetAppContext(),
- (const char*) display_name,
- (const char*) wxTheApp->GetAppName(),
- (const char*) wxTheApp->GetClassName(),
- NULL,
-#if XtSpecificationRelease < 5
- 0, &argc,
-#else
- 0, (int *)&argc,
-#endif
- NULL);
+ Display* display = XOpenDisplay((char*) display_name.c_str());
if (display)
{
}
else
return FALSE;
-#endif
-#ifdef __WXX11__
- Display* display = XOpenDisplay((const char*) display_name);
-
- if (display)
- {
- gs_currentDisplay = (WXDisplay*) display;
- return TRUE;
- }
- else
- return FALSE;
-#endif
}
}
void wxAllocNearestColor(Display *d,Colormap cmp,XColor *xc)
{
+#if !wxUSE_NANOX
int llp;
int screen = DefaultScreen(d);
*/
delete[] color_defs;
+#endif
}
void wxAllocColor(Display *d,Colormap cmp,XColor *xc)
#ifdef __WXDEBUG__
wxString wxGetXEventName(XEvent& event)
{
+#if wxUSE_NANOX
+ wxString str(wxT("(some event)"));
+ return str;
+#else
int type = event.xany.type;
static char* event_name[] = {
"", "unknown(-)", // 0-1
"ClientMessage", "MappingNotify", // 33-34
"unknown(+)"}; // 35
type = wxMin(35, type); type = wxMax(1, type);
- wxString str(event_name[type]);
- return str;
- }
-#endif
-
-#ifdef __WXMOTIF__
-// ----------------------------------------------------------------------------
-// accelerators
-// ----------------------------------------------------------------------------
-
-// Find the letter corresponding to the mnemonic, for Motif
-char wxFindMnemonic (const char *s)
-{
- char mnem = 0;
- int len = strlen (s);
- int i;
- for (i = 0; i < len; i++)
- {
- if (s[i] == '&')
- {
- // Carefully handle &&
- if ((i + 1) <= len && s[i + 1] == '&')
- i++;
- else
- {
- mnem = s[i + 1];
- break;
- }
- }
- }
- return mnem;
-}
-
-char * wxFindAccelerator (const char *s)
-{
- // VZ: this function returns incorrect keysym which completely breaks kbd
- // handling
- return NULL;
-
-#if 0
- // The accelerator text is after the \t char.
- while (*s && *s != '\t')
- s++;
- if (*s == '\0')
- return (NULL);
- s++;
- /*
- Now we need to format it as X standard:
-
- input output
-
- F7 --> <Key>F7
- Ctrl+N --> Ctrl<Key>N
- Alt+k --> Meta<Key>k
- Ctrl+Shift+A --> Ctrl Shift<Key>A
-
- */
-
- static char buf[256];
- buf[0] = '\0';
- char *tmp = copystring (s);
- s = tmp;
- char *p = tmp;
-
- while (1)
- {
- while (*p && *p != '+')
- p++;
- if (*p)
- {
- *p = '\0';
- if (buf[0])
- strcat (buf, " ");
- if (strcmp (s, "Alt"))
- strcat (buf, s);
- else
- strcat (buf, "Meta");
- s = p++;
- }
- else
- {
- strcat (buf, "<Key>");
- strcat (buf, s);
- break;
- }
- }
- delete[]tmp;
- return buf;
+ return wxString::FromAscii(event_name[type]);
#endif
}
-
-XmString wxFindAcceleratorText (const char *s)
-{
- // VZ: this function returns incorrect keysym which completely breaks kbd
- // handling
- return NULL;
-
-#if 0
- // The accelerator text is after the \t char.
- while (*s && *s != '\t')
- s++;
- if (*s == '\0')
- return (NULL);
- s++;
- XmString text = XmStringCreateSimple ((char *)s);
- return text;
#endif
-}
-
-// These functions duplicate those in wxWindow, but are needed
-// for use outside of wxWindow (e.g. wxMenu, wxMenuBar).
-
-// Change a widget's foreground and background colours.
-
-void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour)
+bool wxWindowIsVisible(Window win)
{
- // When should we specify the foreground, if it's calculated
- // by wxComputeColours?
- // Solution: say we start with the default (computed) foreground colour.
- // If we call SetForegroundColour explicitly for a control or window,
- // then the foreground is changed.
- // Therefore SetBackgroundColour computes the foreground colour, and
- // SetForegroundColour changes the foreground colour. The ordering is
- // important.
-
- XtVaSetValues ((Widget) widget,
- XmNforeground, foregroundColour.AllocColour(XtDisplay((Widget) widget)),
- NULL);
-}
+ XWindowAttributes wa;
+ XGetWindowAttributes(wxGlobalDisplay(), win, &wa);
-void wxDoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour)
-{
- wxComputeColours (XtDisplay((Widget) widget), & backgroundColour,
- (wxColour*) NULL);
-
- XtVaSetValues ((Widget) widget,
- XmNbackground, g_itemColors[wxBACK_INDEX].pixel,
- XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel,
- XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel,
- XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
- NULL);
-
- if (changeArmColour)
- XtVaSetValues ((Widget) widget,
- XmNarmColor, g_itemColors[wxSELE_INDEX].pixel,
- NULL);
+ return (wa.map_state == IsViewable);
}
-
-#endif
- // __WXMOTIF__