Changed the way ApplicationShells are used: now wxMotif

creates one ApplicationShell per display, and makes top
level windows popup childs of the ApplicationShell.
  Removed a couple of unused variables from wxApp.
  Replaced some calls to wxGetDisplay with XtDisplay(widget)
or event.xany.display, and some others with wxGlobalDisplay
(the latter changes are just eyecandy).
  Used wxFlushEvents where appropriate.
  Fixed (hopefully) wxFindAcceleratorText and wxFindAccelerator;
for now the new version is still disabled, awaiting further testing.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20474 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon
2003-05-04 17:40:46 +00:00
parent b0feedc5db
commit eb6fa4b425
12 changed files with 176 additions and 204 deletions

View File

@@ -33,7 +33,7 @@ class WXDLLEXPORT wxKeyEvent;
class WXDLLEXPORT wxLog; class WXDLLEXPORT wxLog;
class WXDLLEXPORT wxEventLoop; class WXDLLEXPORT wxEventLoop;
class WXDLLEXPORT wxXVisualInfo; class WXDLLEXPORT wxXVisualInfo;
class wxXVisualInfoMap; class wxPerDisplayDataMap;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// the wxApp class for Motif - see wxAppBase for more details // the wxApp class for Motif - see wxAppBase for more details
@@ -85,10 +85,11 @@ public:
// Motif-specific // Motif-specific
WXAppContext GetAppContext() const { return m_appContext; } WXAppContext GetAppContext() const { return m_appContext; }
WXWidget GetTopLevelWidget() const { return m_topLevelWidget; } WXWidget GetTopLevelWidget();
WXColormap GetMainColormap(WXDisplay* display); WXColormap GetMainColormap(WXDisplay* display);
WXDisplay* GetInitialDisplay() const { return m_initialDisplay; } 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 // This handler is called when a property change event occurs
virtual void HandlePropertyChange(WXEvent *event); virtual void HandlePropertyChange(WXEvent *event);
@@ -96,18 +97,13 @@ public:
wxXVisualInfo* GetVisualInfo(WXDisplay* display); wxXVisualInfo* GetVisualInfo(WXDisplay* display);
private: private:
static long sm_lastMessageTime;
int m_nCmdShow;
wxEventLoop* m_eventLoop; wxEventLoop* m_eventLoop;
// Motif-specific // Motif-specific
WXAppContext m_appContext; WXAppContext m_appContext;
WXWidget m_topLevelWidget;
WXColormap m_mainColormap; WXColormap m_mainColormap;
WXDisplay* m_initialDisplay; WXDisplay* m_initialDisplay;
long m_maxRequestSize; wxPerDisplayDataMap* m_perDisplayData;
wxXVisualInfoMap* m_visualInfoMap;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -154,14 +154,18 @@ wxSize wxDoGetSingleTextCtrlBestSize( Widget textWidget,
const wxWindow* window ); const wxWindow* window );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// executes one main loop iteration (implemented in src/motif/evtloop.cpp) // event-related functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class wxEventLoop; class wxEventLoop;
// executes one main loop iteration (implemented in src/motif/evtloop.cpp)
// returns true if the loop should be exited // returns true if the loop should be exited
bool wxDoEventLoopIteration( wxEventLoop& evtLoop ); 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 // macros to avoid casting WXFOO to Foo all the time
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -48,7 +48,20 @@
#include <string.h> #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 wxList wxPendingDelete;
extern bool wxAddIdleCallback(); extern bool wxAddIdleCallback();
@@ -75,8 +88,6 @@ END_EVENT_TABLE()
} }
#endif // __WXDEBUG__ #endif // __WXDEBUG__
long wxApp::sm_lastMessageTime = 0;
bool wxApp::Initialize() bool wxApp::Initialize()
{ {
wxClassInfo::InitializeClasses(); wxClassInfo::InitializeClasses();
@@ -265,24 +276,25 @@ wxApp::wxApp()
m_eventLoop = new wxEventLoop; m_eventLoop = new wxEventLoop;
m_mainColormap = (WXColormap) NULL; m_mainColormap = (WXColormap) NULL;
m_appContext = (WXAppContext) NULL; m_appContext = (WXAppContext) NULL;
m_topLevelWidget = (WXWidget) NULL;
m_maxRequestSize = 0;
m_initialDisplay = (WXDisplay*) 0; m_initialDisplay = (WXDisplay*) 0;
m_visualInfoMap = new wxXVisualInfoMap; m_perDisplayData = new wxPerDisplayDataMap;
} }
wxApp::~wxApp() wxApp::~wxApp()
{ {
delete m_eventLoop; delete m_eventLoop;
for( wxXVisualInfoMap::iterator it = m_visualInfoMap->begin(), for( wxPerDisplayDataMap::iterator it = m_perDisplayData->begin(),
end = m_visualInfoMap->end(); end = m_perDisplayData->end();
it != end; ++it ) 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() bool wxApp::Initialized()
@@ -493,12 +505,6 @@ bool wxApp::OnInitGui()
gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler); gs_pfnXErrorHandler = XSetErrorHandler(wxXErrorHandler);
#endif // __WXDEBUG__ #endif // __WXDEBUG__
wxTheApp->m_topLevelWidget =
(WXWidget) XtAppCreateShell((String)NULL,
wxTheApp->GetClassName().c_str(),
applicationShellWidgetClass,dpy,
NULL,0) ;
// Add general resize proc // Add general resize proc
XtActionsRec rec; XtActionsRec rec;
rec.string = "resize"; rec.string = "resize";
@@ -506,7 +512,6 @@ bool wxApp::OnInitGui()
XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1); XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1);
GetMainColormap(dpy); GetMainColormap(dpy);
m_maxRequestSize = XMaxRequestSize((Display*) dpy);
wxAddIdleCallback(); wxAddIdleCallback();
@@ -531,18 +536,61 @@ WXColormap wxApp::GetMainColormap(WXDisplay* display)
wxXVisualInfo* wxApp::GetVisualInfo( WXDisplay* display ) 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; wxXVisualInfo* vi = new wxXVisualInfo;
wxFillXVisualInfo( vi, (Display*)display ); wxFillXVisualInfo( vi, (Display*)display );
(*m_visualInfoMap)[display] = vi; (*m_perDisplayData)[display].m_visualInfo = vi;
return 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() void wxExit()
{ {
int retValue = 0; int retValue = 0;

View File

@@ -121,7 +121,7 @@ void wxCheckBox::ChangeBackgroundColour()
XmNforeground, g_itemColors[wxFORE_INDEX].pixel, XmNforeground, g_itemColors[wxFORE_INDEX].pixel,
NULL); 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 // Better to have the checkbox selection in black, or it's
// hard to determine what state it is in. // hard to determine what state it is in.

View File

@@ -305,8 +305,8 @@ bool wxDialog::Show( bool show )
else else
XtUnmanageChild((Widget)m_mainWidget) ; XtUnmanageChild((Widget)m_mainWidget) ;
XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())); XFlush(XtDisplay((Widget)m_mainWidget));
XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE); XSync(XtDisplay((Widget)m_mainWidget), FALSE);
} }
return TRUE; return TRUE;
@@ -319,6 +319,9 @@ int wxDialog::ShowModal()
Show(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) if (m_modalShowing)
return 0; return 0;
m_eventLoop = new wxEventLoop; m_eventLoop = new wxEventLoop;
@@ -329,12 +332,7 @@ int wxDialog::ShowModal()
m_eventLoop->Run(); m_eventLoop->Run();
// Now process all events in case they get sent to a destroyed dialog // Now process all events in case they get sent to a destroyed dialog
XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE); wxFlushEvents( display );
while (m_eventLoop->Pending())
{
XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()));
m_eventLoop->Dispatch();
}
delete m_eventLoop; delete m_eventLoop;
m_eventLoop = NULL; m_eventLoop = NULL;

View File

@@ -234,7 +234,7 @@ void ProcessXEvent(XEvent* event)
* window is recieved. Prevents flicker as windows are resized. * 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; Window win = event->xany.window;
XEvent report; XEvent report;
@@ -260,7 +260,7 @@ bool CheckForAccelerator(XEvent* event)
{ {
// Find a wxWindow for this window // Find a wxWindow for this window
// TODO: should get display for the window, not the current display // 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); event->xany.window);
wxWindow* win = NULL; wxWindow* win = NULL;
@@ -294,7 +294,7 @@ bool CheckForKeyDown(XEvent* event)
{ {
if (event->xany.type == KeyPress) if (event->xany.type == KeyPress)
{ {
Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), Widget widget = XtWindowToWidget(event->xany.display,
event->xany.window); event->xany.window);
wxWindow* win = NULL; wxWindow* win = NULL;
@@ -320,7 +320,7 @@ bool CheckForKeyUp(XEvent* event)
{ {
if (event->xany.type == KeyRelease) if (event->xany.type == KeyRelease)
{ {
Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), Widget widget = XtWindowToWidget(event->xany.display,
event->xany.window); event->xany.window);
wxWindow* win = NULL; wxWindow* win = NULL;

View File

@@ -227,9 +227,7 @@ int wxFileDialog::ShowModal()
// static char fileBuf[512]; // static char fileBuf[512];
Widget parentWidget = (Widget) 0; Widget parentWidget = (Widget) 0;
if (m_parent) if (m_parent)
{
parentWidget = (Widget) m_parent->GetTopWidget(); parentWidget = (Widget) m_parent->GetTopWidget();
}
else else
parentWidget = (Widget) wxTheApp->GetTopLevelWidget(); parentWidget = (Widget) wxTheApp->GetTopLevelWidget();
// prepare the arg list // prepare the arg list
@@ -349,28 +347,25 @@ int wxFileDialog::ShowModal()
wxEndBusyCursor(); wxEndBusyCursor();
XtAddGrab(XtParent(fileSel), TRUE, FALSE); XtAddGrab(XtParent(fileSel), TRUE, FALSE);
XtAppContext context = (XtAppContext) wxTheApp->GetAppContext();
XEvent event; XEvent event;
while (!m_fileSelectorReturned) while (!m_fileSelectorReturned)
{ {
XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll); XtAppNextEvent(context, &event);
XtDispatchEvent(&event);
} }
XtRemoveGrab(XtParent(fileSel)); XtRemoveGrab(XtParent(fileSel));
XmUpdateDisplay((Widget) wxTheApp->GetTopLevelWidget()); // Experimental // XmUpdateDisplay((Widget) wxTheApp->GetTopLevelWidget()); // Experimental
Display* display = XtDisplay(fileSel);
// XtDestroyWidget(fileSel);
XtUnmapWidget(XtParent(fileSel)); XtUnmapWidget(XtParent(fileSel));
XtDestroyWidget(XtParent(fileSel)); XtDestroyWidget(XtParent(fileSel));
// Now process all events, because otherwise // Now process all events, because otherwise
// this might remain on the screen // this might remain on the screen
XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE); wxFlushEvents(display);
while (XtAppPending((XtAppContext) wxTheApp->GetAppContext()))
{
XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()));
XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event);
XtDispatchEvent(&event);
}
m_path = m_fileSelectorAnswer; m_path = m_fileSelectorAnswer;
m_fileName = wxFileNameFromPath(m_fileSelectorAnswer); m_fileName = wxFileNameFromPath(m_fileSelectorAnswer);

View File

@@ -88,10 +88,6 @@ static void wxFrameMapProc(Widget frameShell, XtPointer clientData,
extern wxList wxModelessWindows; extern wxList wxModelessWindows;
extern wxList wxPendingDelete; extern wxList wxPendingDelete;
// TODO: this should be tidied so that any frame can be the
// top frame
// static bool wxTopLevelUsed = FALSE;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxWin macros // wxWin macros
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -120,7 +116,6 @@ void wxFrame::Init()
m_mainWidget = (WXWidget) NULL;; m_mainWidget = (WXWidget) NULL;;
m_workArea = (WXWidget) NULL;; m_workArea = (WXWidget) NULL;;
m_clientArea = (WXWidget) NULL;; m_clientArea = (WXWidget) NULL;;
// m_visibleStatus = TRUE;
} }
bool wxFrame::Create(wxWindow *parent, bool wxFrame::Create(wxWindow *parent,
@@ -206,25 +201,13 @@ bool wxFrame::DoCreate( wxWindow* parent, wxWindowID id,
long style, long style,
const wxString& name ) const wxString& name )
{ {
static bool wxTopLevelUsed = FALSE; /* this is global */ Widget frameShell;
WXWidget frameShell;
if (wxTopLevelUsed) frameShell = XtCreatePopupShell( name, topLevelShellWidgetClass,
{ (Widget)wxTheApp->GetTopLevelWidget(),
// Change suggested by Matthew Flatt
frameShell = (WXWidget)XtAppCreateShell( name,
wxTheApp->GetClassName(),
topLevelShellWidgetClass,
(Display*) wxGetDisplay(),
NULL, 0 ); NULL, 0 );
}
else
{
frameShell = wxTheApp->GetTopLevelWidget();
wxTopLevelUsed = TRUE;
}
XtVaSetValues((Widget) frameShell, XtVaSetValues(frameShell,
// Allows menu to resize // Allows menu to resize
XmNallowShellResize, True, XmNallowShellResize, True,
XmNdeleteResponse, XmDO_NOTHING, XmNdeleteResponse, XmDO_NOTHING,
@@ -232,10 +215,10 @@ bool wxFrame::DoCreate( wxWindow* parent, wxWindowID id,
XmNiconic, (style & wxICONIZE) ? TRUE : FALSE, XmNiconic, (style & wxICONIZE) ? TRUE : FALSE,
NULL); NULL);
m_frameShell = frameShell; m_frameShell = (WXWidget)frameShell;
m_mainWidget = (WXWidget) XtVaCreateManagedWidget("main_window", m_mainWidget = (WXWidget) XtVaCreateManagedWidget("main_window",
xmMainWindowWidgetClass, (Widget) frameShell, xmMainWindowWidgetClass, frameShell,
XmNresizePolicy, XmRESIZE_NONE, XmNresizePolicy, XmRESIZE_NONE,
NULL); NULL);
@@ -266,11 +249,11 @@ bool wxFrame::DoCreate( wxWindow* parent, wxWindowID id,
XtFree( (char *)ptr ); XtFree( (char *)ptr );
/* Part of show-&-hide fix */ /* Part of show-&-hide fix */
XtAddEventHandler( (Widget)frameShell, StructureNotifyMask, XtAddEventHandler( frameShell, StructureNotifyMask,
False, (XtEventHandler)wxFrameMapProc, False, (XtEventHandler)wxFrameMapProc,
(XtPointer)this ); (XtPointer)this );
XtRealizeWidget((Widget) frameShell); XtRealizeWidget(frameShell);
wxAddWindowToTable( (Widget)m_workArea, this); wxAddWindowToTable( (Widget)m_workArea, this);
wxAddWindowToTable( (Widget)m_clientArea, this); wxAddWindowToTable( (Widget)m_clientArea, this);

View File

@@ -377,7 +377,7 @@ void wxRadioBox::ChangeBackgroundColour()
{ {
wxWindow::ChangeBackgroundColour(); wxWindow::ChangeBackgroundColour();
int selectPixel = wxBLACK->AllocColour(wxGetDisplay()); int selectPixel = wxBLACK->AllocColour(XtDisplay((Widget)m_mainWidget));
int i; int i;
for (i = 0; i < m_noItems; i++) for (i = 0; i < m_noItems; i++)

View File

@@ -160,7 +160,7 @@ void wxRadioButton::ChangeBackgroundColour()
wxWindow::ChangeBackgroundColour(); wxWindow::ChangeBackgroundColour();
// What colour should this be? // What colour should this be?
int selectPixel = wxBLACK->AllocColour(wxGetDisplay()); int selectPixel = wxBLACK->AllocColour(XtDisplay((Widget)m_mainWidget));
XtVaSetValues ((Widget) GetMainWidget(), XtVaSetValues ((Widget) GetMainWidget(),
XmNselectColor, selectPixel, XmNselectColor, selectPixel,

View File

@@ -23,22 +23,11 @@
#include "wx/setup.h" #include "wx/setup.h"
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/app.h" #include "wx/app.h"
#include "wx/msgdlg.h"
#include "wx/cursor.h"
#include "wx/dcmemory.h" #include "wx/dcmemory.h"
#include "wx/bitmap.h" #include "wx/bitmap.h"
#include "wx/evtloop.h"
#include <ctype.h>
#include <stdarg.h>
#include <dirent.h>
#include <string.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__)) #if (defined(__SUNCC__) || defined(__CLCC__))
#include <sysent.h> #include <sysent.h>
@@ -88,57 +77,20 @@ static char *GetIniFile (char *dest, const char *filename);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Consume all events until no more left // 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); XSync (display, FALSE);
// XtAppPending returns availability of events AND timers/inputs, which while (evtLoop.Pending())
// 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())); XFlush (display);
// Jan Lessner: works better when events are non-X events evtLoop.Dispatch();
XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMXEvent);
} }
} }
#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 // wxExecute stuff
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -175,7 +127,7 @@ int wxAddProcessCallback(wxEndProcessData *proc_data, int fd)
void wxBell() void wxBell()
{ {
// Use current setting for the bell // Use current setting for the bell
XBell ((Display*) wxGetDisplay(), 0); XBell (wxGlobalDisplay(), 0);
} }
int wxGetOsVersion(int *majorVsn, int *minorVsn) int wxGetOsVersion(int *majorVsn, int *minorVsn)
@@ -184,7 +136,7 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn)
// This code is WRONG!! Does NOT return the // This code is WRONG!! Does NOT return the
// Motif version of the libs but the X protocol // Motif version of the libs but the X protocol
// version! // version!
Display *display = XtDisplay ((Widget) wxTheApp->GetTopLevelWidget()); Display *display = wxGlobalDisplay();
if (majorVsn) if (majorVsn)
*majorVsn = ProtocolVersion (display); *majorVsn = ProtocolVersion (display);
if (minorVsn) if (minorVsn)
@@ -337,7 +289,7 @@ bool wxGetResource(const wxString& section, const wxString& entry, char **value,
{ {
if (!wxResourceDatabase) if (!wxResourceDatabase)
{ {
Display *display = (Display*) wxGetDisplay(); Display *display = wxGlobalDisplay();
wxXMergeDatabases (wxTheApp, display); wxXMergeDatabases (wxTheApp, display);
} }
@@ -549,8 +501,8 @@ void wxGetMousePosition( int* x, int* y )
#else #else
XMotionEvent xev; XMotionEvent xev;
Window root, child; Window root, child;
XQueryPointer((Display*) wxGetDisplay(), XQueryPointer(wxGlobalDisplay(),
DefaultRootWindow((Display*) wxGetDisplay()), DefaultRootWindow(wxGlobalDisplay()),
&root, &child, &root, &child,
&(xev.x_root), &(xev.y_root), &(xev.x_root), &(xev.y_root),
&(xev.x), &(xev.y), &(xev.x), &(xev.y),
@@ -569,7 +521,7 @@ bool wxColourDisplay()
// Returns depth of screen // Returns depth of screen
int wxDisplayDepth() int wxDisplayDepth()
{ {
Display *dpy = (Display*) wxGetDisplay(); Display *dpy = wxGlobalDisplay();
return DefaultDepth (dpy, DefaultScreen (dpy)); return DefaultDepth (dpy, DefaultScreen (dpy));
} }
@@ -577,7 +529,7 @@ int wxDisplayDepth()
// Get size of display // Get size of display
void wxDisplaySize(int *width, int *height) void wxDisplaySize(int *width, int *height)
{ {
Display *dpy = (Display*) wxGetDisplay(); Display *dpy = wxGlobalDisplay();
if ( width ) if ( width )
*width = DisplayWidth (dpy, DefaultScreen (dpy)); *width = DisplayWidth (dpy, DefaultScreen (dpy));
@@ -587,7 +539,7 @@ void wxDisplaySize(int *width, int *height)
void wxDisplaySizeMM(int *width, int *height) void wxDisplaySizeMM(int *width, int *height)
{ {
Display *dpy = (Display*) wxGetDisplay(); Display *dpy = wxGlobalDisplay();
if ( width ) if ( width )
*width = DisplayWidthMM(dpy, DefaultScreen (dpy)); *width = DisplayWidthMM(dpy, DefaultScreen (dpy));
@@ -615,8 +567,6 @@ WXDisplay *wxGetDisplay()
{ {
if (gs_currentDisplay) if (gs_currentDisplay)
return gs_currentDisplay; return gs_currentDisplay;
if (wxTheApp && wxTheApp->GetTopLevelWidget())
return XtDisplay ((Widget) wxTheApp->GetTopLevelWidget());
else if (wxTheApp) else if (wxTheApp)
return wxTheApp->GetInitialDisplay(); return wxTheApp->GetInitialDisplay();
return NULL; return NULL;
@@ -1064,6 +1014,7 @@ char wxFindMnemonic (const char *s)
char mnem = 0; char mnem = 0;
int len = strlen (s); int len = strlen (s);
int i; int i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
if (s[i] == '&') if (s[i] == '&')
@@ -1083,17 +1034,16 @@ char wxFindMnemonic (const char *s)
char* wxFindAccelerator( const char *s ) char* wxFindAccelerator( const char *s )
{ {
#if 1
// VZ: this function returns incorrect keysym which completely breaks kbd // VZ: this function returns incorrect keysym which completely breaks kbd
// handling // handling
return NULL; return NULL;
#else
#if 0
// The accelerator text is after the \t char. // The accelerator text is after the \t char.
while (*s && *s != '\t') s = strchr( s, '\t' );
s++;
if (*s == '\0') if( !s ) return NULL;
return (NULL);
s++;
/* /*
Now we need to format it as X standard: Now we need to format it as X standard:
@@ -1104,62 +1054,68 @@ char * wxFindAccelerator (const char *s)
Alt+k --> Meta<Key>k Alt+k --> Meta<Key>k
Ctrl+Shift+A --> Ctrl Shift<Key>A Ctrl+Shift+A --> Ctrl Shift<Key>A
and handle Ctrl-N & similia
*/ */
static char buf[256]; static char buf[256];
buf[0] = '\0';
char *tmp = copystring (s);
s = tmp;
char *p = tmp;
while (1) buf[0] = '\0';
wxString tmp = s + 1; // skip TAB
size_t index = 0;
while( index < tmp.length() )
{ {
while (*p && *p != '+') size_t plus = tmp.find( '+', index );
p++; size_t minus = tmp.find( '-', index );
if (*p)
{ // neither '+' nor '-', add <Key>
*p = '\0'; if( plus == wxString::npos && minus == wxString::npos )
if (buf[0])
strcat (buf, " ");
if (strcmp (s, "Alt"))
strcat (buf, s);
else
strcat (buf, "Meta");
s = p++;
}
else
{ {
strcat( buf, "<Key>" ); strcat( buf, "<Key>" );
strcat (buf, s); strcat( buf, tmp.c_str() + index );
break;
}
}
delete[]tmp;
return buf; 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;
}
return NULL;
#endif #endif
} }
XmString wxFindAcceleratorText (const char *s) XmString wxFindAcceleratorText (const char *s)
{ {
#if 1
// VZ: this function returns incorrect keysym which completely breaks kbd // VZ: this function returns incorrect keysym which completely breaks kbd
// handling // handling
return NULL; return NULL;
#else
#if 0
// The accelerator text is after the \t char. // The accelerator text is after the \t char.
while (*s && *s != '\t') s = strchr( s, '\t' );
s++;
if (*s == '\0') if( !s ) return NULL;
return (NULL);
s++; return wxStringToXmString( s + 1 ); // skip TAB!
XmString text = XmStringCreateSimple ((char *)s);
return text;
#endif #endif
} }
// Change a widget's foreground and background colours. // Change a widget's foreground and background colours.
void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour)
{ {
// When should we specify the foreground, if it's calculated // When should we specify the foreground, if it's calculated
@@ -1206,14 +1162,6 @@ extern void wxDoChangeFont(WXWidget widget, wxFont& font)
} }
bool wxWindowIsVisible(Window win)
{
XWindowAttributes wa;
XGetWindowAttributes(wxGlobalDisplay(), win, &wa);
return (wa.map_state == IsViewable);
}
wxString wxXmStringToString( const XmString& xmString ) wxString wxXmStringToString( const XmString& xmString )
{ {
char *txt; char *txt;

View File

@@ -2337,7 +2337,7 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win,
// check for a double click // check for a double click
// //
long dclickTime = XtGetMultiClickTime(wxGlobalDisplay()); long dclickTime = XtGetMultiClickTime(xevent->xany.display);
long ts = wxevent.GetTimestamp(); long ts = wxevent.GetTimestamp();
int buttonLast = win->GetLastClickedButton(); int buttonLast = win->GetLastClickedButton();
@@ -2624,7 +2624,7 @@ wxWindow* wxFindWindowAtPointer(wxPoint& pt)
// Get the current mouse position. // Get the current mouse position.
wxPoint wxGetMousePosition() wxPoint wxGetMousePosition()
{ {
Display *display = (Display*) wxGetDisplay(); Display *display = wxGlobalDisplay();
Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display)); Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display));
Window rootReturn, childReturn; Window rootReturn, childReturn;
int rootX, rootY, winX, winY; int rootX, rootY, winX, winY;