From eb6fa4b4257897e4e9655b05e4105e8b47f67476 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Sun, 4 May 2003 17:40:46 +0000 Subject: [PATCH] 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 --- include/wx/motif/app.h | 16 ++-- include/wx/motif/private.h | 6 +- src/motif/app.cpp | 88 +++++++++++++----- src/motif/checkbox.cpp | 2 +- src/motif/dialog.cpp | 14 ++- src/motif/evtloop.cpp | 12 +-- src/motif/filedlg.cpp | 19 ++-- src/motif/frame.cpp | 35 ++------ src/motif/radiobox.cpp | 2 +- src/motif/radiobut.cpp | 2 +- src/motif/utils.cpp | 178 +++++++++++++------------------------ src/motif/window.cpp | 4 +- 12 files changed, 175 insertions(+), 203 deletions(-) diff --git a/include/wx/motif/app.h b/include/wx/motif/app.h index a0d914b1df..95c087af98 100644 --- a/include/wx/motif/app.h +++ b/include/wx/motif/app.h @@ -33,7 +33,7 @@ class WXDLLEXPORT wxKeyEvent; class WXDLLEXPORT wxLog; class WXDLLEXPORT wxEventLoop; class WXDLLEXPORT wxXVisualInfo; -class wxXVisualInfoMap; +class wxPerDisplayDataMap; // ---------------------------------------------------------------------------- // the wxApp class for Motif - see wxAppBase for more details @@ -85,29 +85,25 @@ public: // 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() }; diff --git a/include/wx/motif/private.h b/include/wx/motif/private.h index 601172e600..e48ad8311f 100644 --- a/include/wx/motif/private.h +++ b/include/wx/motif/private.h @@ -154,14 +154,18 @@ wxSize wxDoGetSingleTextCtrlBestSize( Widget textWidget, 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 // ---------------------------------------------------------------------------- diff --git a/src/motif/app.cpp b/src/motif/app.cpp index 1e62d38bda..cc1fad12dd 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -48,7 +48,20 @@ #include -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(); @@ -75,8 +88,6 @@ END_EVENT_TABLE() } #endif // __WXDEBUG__ -long wxApp::sm_lastMessageTime = 0; - bool wxApp::Initialize() { wxClassInfo::InitializeClasses(); @@ -265,24 +276,25 @@ wxApp::wxApp() 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() @@ -493,12 +505,6 @@ bool wxApp::OnInitGui() 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"; @@ -506,7 +512,6 @@ bool wxApp::OnInitGui() XtAppAddActions((XtAppContext) wxTheApp->m_appContext, &rec, 1); GetMainColormap(dpy); - m_maxRequestSize = XMaxRequestSize((Display*) dpy); wxAddIdleCallback(); @@ -531,18 +536,61 @@ WXColormap wxApp::GetMainColormap(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; 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; diff --git a/src/motif/checkbox.cpp b/src/motif/checkbox.cpp index edd27d1c2b..144e2c47d1 100644 --- a/src/motif/checkbox.cpp +++ b/src/motif/checkbox.cpp @@ -121,7 +121,7 @@ void wxCheckBox::ChangeBackgroundColour() 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. diff --git a/src/motif/dialog.cpp b/src/motif/dialog.cpp index 533cad7db5..a9a273a5f1 100644 --- a/src/motif/dialog.cpp +++ b/src/motif/dialog.cpp @@ -305,8 +305,8 @@ bool wxDialog::Show( bool show ) 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; @@ -319,6 +319,9 @@ int wxDialog::ShowModal() 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; @@ -329,12 +332,7 @@ int wxDialog::ShowModal() 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; diff --git a/src/motif/evtloop.cpp b/src/motif/evtloop.cpp index d4b150cddb..41c575d343 100644 --- a/src/motif/evtloop.cpp +++ b/src/motif/evtloop.cpp @@ -234,7 +234,7 @@ void ProcessXEvent(XEvent* event) * 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; @@ -260,7 +260,7 @@ bool CheckForAccelerator(XEvent* event) { // 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; @@ -294,8 +294,8 @@ bool CheckForKeyDown(XEvent* event) { 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 @@ -320,8 +320,8 @@ bool CheckForKeyUp(XEvent* event) { 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 diff --git a/src/motif/filedlg.cpp b/src/motif/filedlg.cpp index 27ad5f831f..ed2ca5e9c4 100644 --- a/src/motif/filedlg.cpp +++ b/src/motif/filedlg.cpp @@ -227,9 +227,7 @@ int wxFileDialog::ShowModal() // 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 @@ -349,28 +347,25 @@ int wxFileDialog::ShowModal() 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); diff --git a/src/motif/frame.cpp b/src/motif/frame.cpp index d6fc8327db..4e8cedb04f 100644 --- a/src/motif/frame.cpp +++ b/src/motif/frame.cpp @@ -88,10 +88,6 @@ static void wxFrameMapProc(Widget frameShell, XtPointer clientData, 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 // ---------------------------------------------------------------------------- @@ -120,7 +116,6 @@ void wxFrame::Init() m_mainWidget = (WXWidget) NULL;; m_workArea = (WXWidget) NULL;; m_clientArea = (WXWidget) NULL;; - // m_visibleStatus = TRUE; } bool wxFrame::Create(wxWindow *parent, @@ -206,25 +201,13 @@ bool wxFrame::DoCreate( wxWindow* parent, wxWindowID id, 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, @@ -232,10 +215,10 @@ bool wxFrame::DoCreate( wxWindow* parent, wxWindowID id, 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); @@ -266,11 +249,11 @@ bool wxFrame::DoCreate( wxWindow* parent, wxWindowID id, 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); diff --git a/src/motif/radiobox.cpp b/src/motif/radiobox.cpp index 6073ff07c3..9bf78c04a4 100644 --- a/src/motif/radiobox.cpp +++ b/src/motif/radiobox.cpp @@ -377,7 +377,7 @@ void wxRadioBox::ChangeBackgroundColour() { wxWindow::ChangeBackgroundColour(); - int selectPixel = wxBLACK->AllocColour(wxGetDisplay()); + int selectPixel = wxBLACK->AllocColour(XtDisplay((Widget)m_mainWidget)); int i; for (i = 0; i < m_noItems; i++) diff --git a/src/motif/radiobut.cpp b/src/motif/radiobut.cpp index 87c20587a9..4cada5de0e 100644 --- a/src/motif/radiobut.cpp +++ b/src/motif/radiobut.cpp @@ -160,7 +160,7 @@ void wxRadioButton::ChangeBackgroundColour() 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, diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index 56c48759cb..c43fe3189b 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -23,22 +23,11 @@ #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 -#include -#include #include -#include -#include -#include -#include -#include -#include -#include #if (defined(__SUNCC__) || defined(__CLCC__)) #include @@ -88,57 +77,20 @@ static char *GetIniFile (char *dest, const char *filename); // ---------------------------------------------------------------------------- // 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 // ---------------------------------------------------------------------------- @@ -175,7 +127,7 @@ int wxAddProcessCallback(wxEndProcessData *proc_data, int fd) void wxBell() { // Use current setting for the bell - XBell ((Display*) wxGetDisplay(), 0); + XBell (wxGlobalDisplay(), 0); } int wxGetOsVersion(int *majorVsn, int *minorVsn) @@ -184,7 +136,7 @@ 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) @@ -337,7 +289,7 @@ bool wxGetResource(const wxString& section, const wxString& entry, char **value, { if (!wxResourceDatabase) { - Display *display = (Display*) wxGetDisplay(); + Display *display = wxGlobalDisplay(); wxXMergeDatabases (wxTheApp, display); } @@ -549,8 +501,8 @@ void wxGetMousePosition( int* x, int* y ) #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), @@ -569,7 +521,7 @@ bool wxColourDisplay() // Returns depth of screen int wxDisplayDepth() { - Display *dpy = (Display*) wxGetDisplay(); + Display *dpy = wxGlobalDisplay(); return DefaultDepth (dpy, DefaultScreen (dpy)); } @@ -577,7 +529,7 @@ int wxDisplayDepth() // Get size of display void wxDisplaySize(int *width, int *height) { - Display *dpy = (Display*) wxGetDisplay(); + Display *dpy = wxGlobalDisplay(); if ( width ) *width = DisplayWidth (dpy, DefaultScreen (dpy)); @@ -587,7 +539,7 @@ void wxDisplaySize(int *width, int *height) void wxDisplaySizeMM(int *width, int *height) { - Display *dpy = (Display*) wxGetDisplay(); + Display *dpy = wxGlobalDisplay(); if ( width ) *width = DisplayWidthMM(dpy, DefaultScreen (dpy)); @@ -615,8 +567,6 @@ WXDisplay *wxGetDisplay() { if (gs_currentDisplay) return gs_currentDisplay; - if (wxTheApp && wxTheApp->GetTopLevelWidget()) - return XtDisplay ((Widget) wxTheApp->GetTopLevelWidget()); else if (wxTheApp) return wxTheApp->GetInitialDisplay(); return NULL; @@ -1064,6 +1014,7 @@ char wxFindMnemonic (const char *s) char mnem = 0; int len = strlen (s); int i; + for (i = 0; i < len; i++) { if (s[i] == '&') @@ -1081,19 +1032,18 @@ char wxFindMnemonic (const char *s) 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: @@ -1104,62 +1054,68 @@ char * wxFindAccelerator (const char *s) Alt+k --> Metak Ctrl+Shift+A --> Ctrl ShiftA + 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 + if( plus == wxString::npos && minus == wxString::npos ) { - strcat (buf, ""); - strcat (buf, s); - break; + strcat( buf, "" ); + 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 @@ -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 ) { char *txt; diff --git a/src/motif/window.cpp b/src/motif/window.cpp index 855d4e1785..c7f7e4e919 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -2337,7 +2337,7 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, // check for a double click // - long dclickTime = XtGetMultiClickTime(wxGlobalDisplay()); + long dclickTime = XtGetMultiClickTime(xevent->xany.display); long ts = wxevent.GetTimestamp(); int buttonLast = win->GetLastClickedButton(); @@ -2624,7 +2624,7 @@ wxWindow* wxFindWindowAtPointer(wxPoint& pt) // 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; -- 2.45.2