class WXDLLEXPORT wxLog;
class WXDLLEXPORT wxEventLoop;
class WXDLLEXPORT wxXVisualInfo;
-class wxXVisualInfoMap;
+class wxPerDisplayDataMap;
// ----------------------------------------------------------------------------
// the wxApp class for Motif - see wxAppBase for more details
// Motif-specific
WXAppContext GetAppContext() const { return m_appContext; }
- WXWidget GetTopLevelWidget() const { return m_topLevelWidget; }
+ WXWidget GetTopLevelWidget();
WXColormap GetMainColormap(WXDisplay* display);
WXDisplay* GetInitialDisplay() const { return m_initialDisplay; }
- long GetMaxRequestSize() const { return m_maxRequestSize; }
-
+
+ void SetTopLevelWidget(WXDisplay* display, WXWidget widget);
+
// This handler is called when a property change event occurs
virtual void HandlePropertyChange(WXEvent *event);
wxXVisualInfo* GetVisualInfo(WXDisplay* display);
private:
- static long sm_lastMessageTime;
- int m_nCmdShow;
-
wxEventLoop* m_eventLoop;
// Motif-specific
WXAppContext m_appContext;
- WXWidget m_topLevelWidget;
WXColormap m_mainColormap;
WXDisplay* m_initialDisplay;
- long m_maxRequestSize;
- wxXVisualInfoMap* m_visualInfoMap;
+ wxPerDisplayDataMap* m_perDisplayData;
DECLARE_EVENT_TABLE()
};
const wxWindow* window );
// ----------------------------------------------------------------------------
-// executes one main loop iteration (implemented in src/motif/evtloop.cpp)
+// event-related functions
// ----------------------------------------------------------------------------
class wxEventLoop;
+// executes one main loop iteration (implemented in src/motif/evtloop.cpp)
// returns true if the loop should be exited
bool wxDoEventLoopIteration( wxEventLoop& evtLoop );
+// Consume all events until no more left
+void wxFlushEvents(WXDisplay* display);
+
// ----------------------------------------------------------------------------
// macros to avoid casting WXFOO to Foo all the time
// ----------------------------------------------------------------------------
#include <string.h>
-WX_DECLARE_VOIDPTR_HASH_MAP( wxXVisualInfo*, wxXVisualInfoMap );
+struct wxPerDisplayData
+{
+ wxPerDisplayData()
+ { m_visualInfo = NULL; m_topLevelWidget = NULL; }
+
+ wxXVisualInfo* m_visualInfo;
+ Widget m_topLevelWidget;
+};
+
+WX_DECLARE_VOIDPTR_HASH_MAP( wxPerDisplayData, wxPerDisplayDataMap );
+
+static void wxTLWidgetDestroyCallback(Widget w, XtPointer clientData,
+ XtPointer ptr);
+static WXWidget wxCreateTopLevelWidget( WXDisplay* display );
extern wxList wxPendingDelete;
extern bool wxAddIdleCallback();
}
#endif // __WXDEBUG__
-long wxApp::sm_lastMessageTime = 0;
-
bool wxApp::Initialize()
{
wxClassInfo::InitializeClasses();
m_eventLoop = new wxEventLoop;
m_mainColormap = (WXColormap) NULL;
m_appContext = (WXAppContext) NULL;
- m_topLevelWidget = (WXWidget) NULL;
- m_maxRequestSize = 0;
m_initialDisplay = (WXDisplay*) 0;
- m_visualInfoMap = new wxXVisualInfoMap;
+ m_perDisplayData = new wxPerDisplayDataMap;
}
wxApp::~wxApp()
{
delete m_eventLoop;
- for( wxXVisualInfoMap::iterator it = m_visualInfoMap->begin(),
- end = m_visualInfoMap->end();
+ for( wxPerDisplayDataMap::iterator it = m_perDisplayData->begin(),
+ end = m_perDisplayData->end();
it != end; ++it )
{
- delete it->second;
+ delete it->second.m_visualInfo;
+ XtDestroyWidget( it->second.m_topLevelWidget );
}
- delete m_visualInfoMap;
+ delete m_perDisplayData;
+
+ wxTheApp = NULL;
}
bool wxApp::Initialized()
gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler);
#endif // __WXDEBUG__
- wxTheApp->m_topLevelWidget =
- (WXWidget) XtAppCreateShell((String)NULL,
- wxTheApp->GetClassName().c_str(),
- applicationShellWidgetClass,dpy,
- NULL,0) ;
-
// Add general resize proc
XtActionsRec rec;
rec.string = "resize";
XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1);
GetMainColormap(dpy);
- m_maxRequestSize = XMaxRequestSize((Display*) dpy);
wxAddIdleCallback();
wxXVisualInfo* wxApp::GetVisualInfo( WXDisplay* display )
{
- wxXVisualInfoMap::iterator it = m_visualInfoMap->find( display );
+ wxPerDisplayDataMap::iterator it = m_perDisplayData->find( display );
- if( it != m_visualInfoMap->end() ) return it->second;
+ if( it != m_perDisplayData->end() && it->second.m_visualInfo )
+ return it->second.m_visualInfo;
wxXVisualInfo* vi = new wxXVisualInfo;
wxFillXVisualInfo( vi, (Display*)display );
- (*m_visualInfoMap)[display] = vi;
+ (*m_perDisplayData)[display].m_visualInfo = vi;
return vi;
}
+static void wxTLWidgetDestroyCallback(Widget w, XtPointer clientData,
+ XtPointer ptr)
+{
+ if( wxTheApp )
+ wxTheApp->SetTopLevelWidget( (WXDisplay*)XtDisplay(w),
+ (WXWidget)NULL );
+}
+
+WXWidget wxCreateTopLevelWidget( WXDisplay* display )
+{
+ Widget tlw = XtAppCreateShell( (String)NULL,
+ wxTheApp->GetClassName().c_str(),
+ applicationShellWidgetClass,
+ (Display*)display,
+ NULL, 0 );
+
+ XtAddCallback( tlw, XmNdestroyCallback,
+ (XtCallbackProc)wxTLWidgetDestroyCallback,
+ (XtPointer)NULL );
+
+ return (WXWidget)tlw;
+}
+
+WXWidget wxApp::GetTopLevelWidget()
+{
+ WXDisplay* display = wxGetDisplay();
+ wxPerDisplayDataMap::iterator it = m_perDisplayData->find( display );
+
+ if( it != m_perDisplayData->end() && it->second.m_topLevelWidget )
+ return (WXWidget)it->second.m_topLevelWidget;
+
+ WXWidget tlw = wxCreateTopLevelWidget( display );
+ SetTopLevelWidget( display, tlw );
+
+ return tlw;
+}
+
+void wxApp::SetTopLevelWidget(WXDisplay* display, WXWidget widget)
+{
+ (*m_perDisplayData)[display].m_topLevelWidget = (Widget)widget;
+}
+
void wxExit()
{
int retValue = 0;
XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
NULL);
- int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
+ int selectPixel = wxBLACK->AllocColour(XtDisplay((Widget)m_mainWidget));
// Better to have the checkbox selection in black, or it's
// hard to determine what state it is in.
else
XtUnmanageChild((Widget)m_mainWidget) ;
- XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()));
- XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE);
+ XFlush(XtDisplay((Widget)m_mainWidget));
+ XSync(XtDisplay((Widget)m_mainWidget), FALSE);
}
return TRUE;
Show(TRUE);
+ // after the event loop ran, the widget might already have been destroyed
+ WXDisplay* display = (WXDisplay*)XtDisplay( (Widget)m_mainWidget );
+
if (m_modalShowing)
return 0;
m_eventLoop = new wxEventLoop;
m_eventLoop->Run();
// Now process all events in case they get sent to a destroyed dialog
- XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE);
- while (m_eventLoop->Pending())
- {
- XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()));
- m_eventLoop->Dispatch();
- }
+ wxFlushEvents( display );
delete m_eventLoop;
m_eventLoop = NULL;
* window is recieved. Prevents flicker as windows are resized.
*/
- Display *disp = XtDisplay((Widget) wxTheApp->GetTopLevelWidget());
+ Display *disp = event->xany.display;
Window win = event->xany.window;
XEvent report;
{
// Find a wxWindow for this window
// TODO: should get display for the window, not the current display
- Widget widget = XtWindowToWidget((Display*) wxGetDisplay(),
+ Widget widget = XtWindowToWidget(event->xany.display,
event->xany.window);
wxWindow* win = NULL;
{
if (event->xany.type == KeyPress)
{
- Widget widget = XtWindowToWidget((Display*) wxGetDisplay(),
- event->xany.window);
+ Widget widget = XtWindowToWidget(event->xany.display,
+ event->xany.window);
wxWindow* win = NULL;
// Find the first wxWindow that corresponds to this event window
{
if (event->xany.type == KeyRelease)
{
- Widget widget = XtWindowToWidget((Display*) wxGetDisplay(),
- event->xany.window);
+ Widget widget = XtWindowToWidget(event->xany.display,
+ event->xany.window);
wxWindow* win = NULL;
// Find the first wxWindow that corresponds to this event window
// static char fileBuf[512];
Widget parentWidget = (Widget) 0;
if (m_parent)
- {
parentWidget = (Widget) m_parent->GetTopWidget();
- }
else
parentWidget = (Widget) wxTheApp->GetTopLevelWidget();
// prepare the arg list
wxEndBusyCursor();
XtAddGrab(XtParent(fileSel), TRUE, FALSE);
+ XtAppContext context = (XtAppContext) wxTheApp->GetAppContext();
XEvent event;
while (!m_fileSelectorReturned)
{
- XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll);
+ XtAppNextEvent(context, &event);
+ XtDispatchEvent(&event);
}
XtRemoveGrab(XtParent(fileSel));
- XmUpdateDisplay((Widget) wxTheApp->GetTopLevelWidget()); // Experimental
+ // XmUpdateDisplay((Widget) wxTheApp->GetTopLevelWidget()); // Experimental
+
+ Display* display = XtDisplay(fileSel);
- // XtDestroyWidget(fileSel);
XtUnmapWidget(XtParent(fileSel));
XtDestroyWidget(XtParent(fileSel));
// Now process all events, because otherwise
// this might remain on the screen
- XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE);
- while (XtAppPending((XtAppContext) wxTheApp->GetAppContext()))
- {
- XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()));
- XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event);
- XtDispatchEvent(&event);
- }
+ wxFlushEvents(display);
m_path = m_fileSelectorAnswer;
m_fileName = wxFileNameFromPath(m_fileSelectorAnswer);
extern wxList wxModelessWindows;
extern wxList wxPendingDelete;
-// TODO: this should be tidied so that any frame can be the
-// top frame
-// static bool wxTopLevelUsed = FALSE;
-
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
m_mainWidget = (WXWidget) NULL;;
m_workArea = (WXWidget) NULL;;
m_clientArea = (WXWidget) NULL;;
- // m_visibleStatus = TRUE;
}
bool wxFrame::Create(wxWindow *parent,
long style,
const wxString& name )
{
- static bool wxTopLevelUsed = FALSE; /* this is global */
- WXWidget frameShell;
+ Widget frameShell;
- if (wxTopLevelUsed)
- {
- // Change suggested by Matthew Flatt
- frameShell = (WXWidget)XtAppCreateShell( name,
- wxTheApp->GetClassName(),
- topLevelShellWidgetClass,
- (Display*) wxGetDisplay(),
- NULL, 0 );
- }
- else
- {
- frameShell = wxTheApp->GetTopLevelWidget();
- wxTopLevelUsed = TRUE;
- }
+ frameShell = XtCreatePopupShell( name, topLevelShellWidgetClass,
+ (Widget)wxTheApp->GetTopLevelWidget(),
+ NULL, 0 );
- XtVaSetValues((Widget) frameShell,
+ XtVaSetValues(frameShell,
// Allows menu to resize
XmNallowShellResize, True,
XmNdeleteResponse, XmDO_NOTHING,
XmNiconic, (style & wxICONIZE) ? TRUE : FALSE,
NULL);
- m_frameShell = frameShell;
+ m_frameShell = (WXWidget)frameShell;
m_mainWidget = (WXWidget) XtVaCreateManagedWidget("main_window",
- xmMainWindowWidgetClass, (Widget) frameShell,
+ xmMainWindowWidgetClass, frameShell,
XmNresizePolicy, XmRESIZE_NONE,
NULL);
XtFree( (char *)ptr );
/* Part of show-&-hide fix */
- XtAddEventHandler( (Widget)frameShell, StructureNotifyMask,
+ XtAddEventHandler( frameShell, StructureNotifyMask,
False, (XtEventHandler)wxFrameMapProc,
(XtPointer)this );
- XtRealizeWidget((Widget) frameShell);
+ XtRealizeWidget(frameShell);
wxAddWindowToTable( (Widget)m_workArea, this);
wxAddWindowToTable( (Widget)m_clientArea, this);
{
wxWindow::ChangeBackgroundColour();
- int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
+ int selectPixel = wxBLACK->AllocColour(XtDisplay((Widget)m_mainWidget));
int i;
for (i = 0; i < m_noItems; i++)
wxWindow::ChangeBackgroundColour();
// What colour should this be?
- int selectPixel = wxBLACK->AllocColour(wxGetDisplay());
+ int selectPixel = wxBLACK->AllocColour(XtDisplay((Widget)m_mainWidget));
XtVaSetValues ((Widget) GetMainWidget(),
XmNselectColor, selectPixel,
#include "wx/setup.h"
#include "wx/utils.h"
#include "wx/app.h"
-#include "wx/msgdlg.h"
-#include "wx/cursor.h"
#include "wx/dcmemory.h"
#include "wx/bitmap.h"
+#include "wx/evtloop.h"
-#include <ctype.h>
-#include <stdarg.h>
-#include <dirent.h>
#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <pwd.h>
-#include <errno.h>
-#include <signal.h>
#if (defined(__SUNCC__) || defined(__CLCC__))
#include <sysent.h>
// ----------------------------------------------------------------------------
// Consume all events until no more left
-void wxFlushEvents()
+void wxFlushEvents(WXDisplay* wxdisplay)
{
- Display *display = (Display*) wxGetDisplay();
+ Display *display = (Display*)wxdisplay;
+ wxEventLoop evtLoop;
XSync (display, FALSE);
- // 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)
+ while (evtLoop.Pending())
{
- XFlush (XtDisplay ((Widget) wxTheApp->GetTopLevelWidget()));
- // Jan Lessner: works better when events are non-X events
- XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMXEvent);
+ XFlush (display);
+ evtLoop.Dispatch();
}
}
-#if 0
-// Check whether this window wants to process messages, e.g. Stop button
-// in long calculations.
-bool wxCheckForInterrupt(wxWindow *wnd)
-{
- 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;
-}
-#endif
-
// ----------------------------------------------------------------------------
// wxExecute stuff
// ----------------------------------------------------------------------------
void wxBell()
{
// Use current setting for the bell
- XBell ((Display*) wxGetDisplay(), 0);
+ XBell (wxGlobalDisplay(), 0);
}
int wxGetOsVersion(int *majorVsn, int *minorVsn)
// This code is WRONG!! Does NOT return the
// Motif version of the libs but the X protocol
// version!
- Display *display = XtDisplay ((Widget) wxTheApp->GetTopLevelWidget());
+ Display *display = wxGlobalDisplay();
if (majorVsn)
*majorVsn = ProtocolVersion (display);
if (minorVsn)
{
if (!wxResourceDatabase)
{
- Display *display = (Display*) wxGetDisplay();
+ Display *display = wxGlobalDisplay();
wxXMergeDatabases (wxTheApp, display);
}
#else
XMotionEvent xev;
Window root, child;
- XQueryPointer((Display*) wxGetDisplay(),
- DefaultRootWindow((Display*) wxGetDisplay()),
+ XQueryPointer(wxGlobalDisplay(),
+ DefaultRootWindow(wxGlobalDisplay()),
&root, &child,
&(xev.x_root), &(xev.y_root),
&(xev.x), &(xev.y),
// Returns depth of screen
int wxDisplayDepth()
{
- Display *dpy = (Display*) wxGetDisplay();
+ Display *dpy = wxGlobalDisplay();
return DefaultDepth (dpy, DefaultScreen (dpy));
}
// Get size of display
void wxDisplaySize(int *width, int *height)
{
- Display *dpy = (Display*) wxGetDisplay();
+ Display *dpy = wxGlobalDisplay();
if ( width )
*width = DisplayWidth (dpy, DefaultScreen (dpy));
void wxDisplaySizeMM(int *width, int *height)
{
- Display *dpy = (Display*) wxGetDisplay();
+ Display *dpy = wxGlobalDisplay();
if ( width )
*width = DisplayWidthMM(dpy, DefaultScreen (dpy));
{
if (gs_currentDisplay)
return gs_currentDisplay;
- if (wxTheApp && wxTheApp->GetTopLevelWidget())
- return XtDisplay ((Widget) wxTheApp->GetTopLevelWidget());
else if (wxTheApp)
return wxTheApp->GetInitialDisplay();
return NULL;
char mnem = 0;
int len = strlen (s);
int i;
+
for (i = 0; i < len; i++)
{
if (s[i] == '&')
return mnem;
}
-char * wxFindAccelerator (const char *s)
+char* wxFindAccelerator( const char *s )
{
+#if 1
// VZ: this function returns incorrect keysym which completely breaks kbd
// handling
return NULL;
+#else
+ // The accelerator text is after the \t char.
+ s = strchr( s, '\t' );
+
+ if( !s ) 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:
Alt+k --> Meta<Key>k
Ctrl+Shift+A --> Ctrl Shift<Key>A
+ and handle Ctrl-N & similia
*/
static char buf[256];
+
buf[0] = '\0';
- char *tmp = copystring (s);
- s = tmp;
- char *p = tmp;
+ wxString tmp = s + 1; // skip TAB
+ size_t index = 0;
- while (1)
+ while( index < tmp.length() )
{
- 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
+ size_t plus = tmp.find( '+', index );
+ size_t minus = tmp.find( '-', index );
+
+ // neither '+' nor '-', add <Key>
+ if( plus == wxString::npos && minus == wxString::npos )
{
- strcat (buf, "<Key>");
- strcat (buf, s);
- break;
+ strcat( buf, "<Key>" );
+ strcat( buf, tmp.c_str() + index );
+
+ return buf;
}
+
+ // OK: npos is big and positive
+ size_t sep = wxMin( plus, minus );
+ wxString mod = tmp.substr( index, sep - index );
+
+ // Ctrl -> Ctrl
+ // Shift -> Shift
+ // Alt -> Meta
+ if( mod == "Alt" )
+ mod = "Meta";
+
+ if( buf[0] )
+ strcat( buf, " " );
+
+ strcat( buf, mod.c_str() );
+
+ index = sep + 1;
}
- delete[]tmp;
- return buf;
+
+ return NULL;
#endif
}
XmString wxFindAcceleratorText (const char *s)
{
+#if 1
// VZ: this function returns incorrect keysym which completely breaks kbd
// handling
return NULL;
+#else
+ // The accelerator text is after the \t char.
+ s = strchr( s, '\t' );
-#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;
+ if( !s ) return NULL;
+
+ return wxStringToXmString( s + 1 ); // skip TAB!
#endif
}
-
// Change a widget's foreground and background colours.
-
void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour)
{
// When should we specify the foreground, if it's calculated
}
-bool wxWindowIsVisible(Window win)
-{
- XWindowAttributes wa;
- XGetWindowAttributes(wxGlobalDisplay(), win, &wa);
-
- return (wa.map_state == IsViewable);
-}
-
wxString wxXmStringToString( const XmString& xmString )
{
char *txt;
// check for a double click
//
- long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
+ long dclickTime = XtGetMultiClickTime(xevent->xany.display);
long ts = wxevent.GetTimestamp();
int buttonLast = win->GetLastClickedButton();
// Get the current mouse position.
wxPoint wxGetMousePosition()
{
- Display *display = (Display*) wxGetDisplay();
+ Display *display = wxGlobalDisplay();
Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display));
Window rootReturn, childReturn;
int rootX, rootY, winX, winY;