X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bf5c9d349fb25c069e66e86ee551e3605f6c5b90..904a2463aaf4f29e3b8f96436aefb7528aebe397:/src/motif/window.cpp diff --git a/src/motif/window.cpp b/src/motif/window.cpp index 85a9fd34fe..88dff30462 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -45,6 +45,8 @@ #include "wx/module.h" #include "wx/menuitem.h" #include "wx/log.h" +#include "wx/evtloop.h" +#include "wx/hash.h" #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" @@ -172,17 +174,24 @@ void wxWindow::UnmanageAndDestroy(WXWidget widget) } } -bool wxWindow::MapOrUnmap(WXWidget widget, bool map) +bool wxWindow::MapOrUnmap(WXWidget widget, bool domap) { Widget w = (Widget)widget; if ( !w ) return FALSE; - if ( map ) + if ( domap ) XtMapWidget(w); else XtUnmapWidget(w); + // Rationale: a lot of common operations (including but not + // limited to moving, resizing and appending items to a listbox) + // unmamange the widget, do their work, then manage it again. + // This means that, for example adding an item to a listbox will show it, + // or that most controls are shown every time they are moved or resized! + XtSetMappedWhenManaged( w, domap ); + return TRUE; } @@ -404,7 +413,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, wxWindow::~wxWindow() { if (g_captureWindow == this) - g_captureWindow = NULL; + g_captureWindow = NULL; m_isBeingDeleted = TRUE; @@ -437,7 +446,7 @@ wxWindow::~wxWindow() if (w) { XtDestroyWidget(w); - m_drawingArea = (WXWidget) 0; + m_drawingArea = (WXWidget) 0; } // Only if we're _really_ a canvas (not a dialog box/panel) @@ -449,18 +458,18 @@ wxWindow::~wxWindow() if (m_hScrollBar) { wxDeleteWindowFromTable((Widget) m_hScrollBar); - XtUnmanageChild((Widget) m_hScrollBar); + XtUnmanageChild((Widget) m_hScrollBar); } if (m_vScrollBar) { wxDeleteWindowFromTable((Widget) m_vScrollBar); - XtUnmanageChild((Widget) m_vScrollBar); + XtUnmanageChild((Widget) m_vScrollBar); } if (m_hScrollBar) - XtDestroyWidget((Widget) m_hScrollBar); + XtDestroyWidget((Widget) m_hScrollBar); if (m_vScrollBar) - XtDestroyWidget((Widget) m_vScrollBar); + XtDestroyWidget((Widget) m_vScrollBar); UnmanageAndDestroy(m_scrolledWindow); @@ -954,16 +963,16 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) GetClientSize(& w, & h); } - wxNode *cnode = m_children.First(); + wxWindowList::Node *cnode = m_children.GetFirst(); while (cnode) { - wxWindow *child = (wxWindow*) cnode->Data(); - int sx = 0; - int sy = 0; - child->GetSize( &sx, &sy ); + wxWindow *child = cnode->GetData(); + int sx = 0; + int sy = 0; + child->GetSize( &sx, &sy ); wxPoint pos( child->GetPosition() ); - child->SetSize( pos.x + dx, pos.y + dy, sx, sy, wxSIZE_ALLOW_MINUS_ONE ); - cnode = cnode->Next(); + child->SetSize( pos.x + dx, pos.y + dy, sx, sy, wxSIZE_ALLOW_MINUS_ONE ); + cnode = cnode->GetNext(); } int x1 = (dx >= 0) ? x : x - dx; @@ -1072,10 +1081,10 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) // Now send expose events - wxNode* node = updateRects.First(); + wxList::Node* node = updateRects.GetFirst(); while (node) { - wxRect* rect = (wxRect*) node->Data(); + wxRect* rect = (wxRect*) node->GetData(); XExposeEvent event; event.type = Expose; @@ -1092,17 +1101,17 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) XSendEvent(display, window, False, ExposureMask, (XEvent *)&event); - node = node->Next(); + node = node->GetNext(); } // Delete the update rects - node = updateRects.First(); + node = updateRects.GetFirst(); while (node) { - wxRect* rect = (wxRect*) node->Data(); + wxRect* rect = (wxRect*) node->GetData(); delete rect; - node = node->Next(); + node = node->GetNext(); } XmUpdateDisplay((Widget) GetMainWidget()); @@ -1144,6 +1153,8 @@ void wxWindow::DoSetToolTip(wxToolTip * WXUNUSED(tooltip)) // popup menus // ---------------------------------------------------------------------------- +#if wxUSE_MENUS + bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) { Widget widget = (Widget) GetMainWidget(); @@ -1158,7 +1169,8 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) if (menu->GetParent() && (menu->GetId() != -1)) return FALSE; - if (menu->GetMainWidget()) { + if (menu->GetMainWidget()) + { menu->DestroyMenu(TRUE); } @@ -1207,37 +1219,26 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) XmMenuPosition (menuWidget, &event); XtManageChild (menuWidget); - XEvent x_event; - // The ID of a pop-up menu is 1 when active, and is set to 0 by the + // The ID of a pop-up menu is 1 when active, and is set to 0 by the // idle-time destroy routine. - // Waiting until this ID changes causes this function to block until + // Waiting until this ID changes causes this function to block until // the menu has been dismissed and the widgets cleaned up. // In other words, once this routine returns, it is safe to delete // the menu object. // Ian Brown - while (menu->GetId() == 1) - { - XtAppNextEvent( (XtAppContext) wxTheApp->GetAppContext(), &x_event); - wxTheApp->ProcessXEvent((WXEvent*) & x_event); + wxEventLoop evtLoop; - if (XtAppPending( (XtAppContext) wxTheApp->GetAppContext() ) == 0) - { - if (!wxTheApp->ProcessIdle()) - { -#if wxUSE_THREADS - // leave the main loop to give other threads a chance to - // perform their GUI work - wxMutexGuiLeave(); - wxUsleep(20); - wxMutexGuiEnter(); -#endif - } - } + while (menu->GetId() == 1) + { + wxDoEventLoopIteration( evtLoop ); } + return TRUE; } +#endif + // --------------------------------------------------------------------------- // moving and resizing // --------------------------------------------------------------------------- @@ -1345,9 +1346,9 @@ void wxWindow::DoSetSizeIntr(int x, int y, int width, int height, y = oldY; } - if ( width == -1 ) + if ( width <= 0 ) width = oldW; - if ( height == -1 ) + if ( height <= 0 ) height = oldH; bool nothingChanged = (x == oldX) && (y == oldY) && @@ -1383,15 +1384,6 @@ void wxWindow::DoSetSizeIntr(int x, int y, int width, int height, if (managed) XtManageChild(widget); - - // How about this bit. Maybe we don't need to generate size events - // all the time -- they'll be generated when the window is sized anyway. -#if 0 - wxSizeEvent sizeEvent(wxSize(width, height), GetId()); - sizeEvent.SetEventObject(this); - - GetEventHandler()->ProcessEvent(sizeEvent); -#endif // 0 } } @@ -1459,6 +1451,11 @@ void wxWindow::DoMoveWindow(int x, int y, int width, int height) if (m_drawingArea) return; + if (width == 0) + width = 1; + if (height == 0) + height = 1; + XtVaSetValues((Widget)GetTopWidget(), XmNx, x, XmNy, y, @@ -1715,6 +1712,7 @@ void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event)) bool wxWindow::ProcessAccelerator(wxKeyEvent& event) { +#if wxUSE_ACCEL if (!m_acceleratorTable.Ok()) return FALSE; @@ -1727,7 +1725,7 @@ bool wxWindow::ProcessAccelerator(wxKeyEvent& event) if (entry->MatchesEvent(event)) { // Bingo, we have a match. Now find a control that matches the - // entry command id. + // entry command id. // Need to go up to the top of the window hierarchy, since it might // be e.g. a menu item @@ -1741,6 +1739,7 @@ bool wxWindow::ProcessAccelerator(wxKeyEvent& event) wxFrame* frame = wxDynamicCast(parent, wxFrame); if ( frame ) { +#if wxUSE_MENUS // Try for a menu command if (frame->GetMenuBar()) { @@ -1755,6 +1754,7 @@ bool wxWindow::ProcessAccelerator(wxKeyEvent& event) return frame->GetEventHandler()->ProcessEvent(commandEvent); } } +#endif } // Find a child matching the command id @@ -1776,6 +1776,7 @@ bool wxWindow::ProcessAccelerator(wxKeyEvent& event) return FALSE; } // matches event }// for +#endif // We didn't match the key event against an accelerator. return FALSE; @@ -1801,8 +1802,8 @@ bool wxAddWindowToTable(Widget w, wxWindow *win) wxWidgetHashTable->Put((long) w, win); - wxLogTrace("widget", "Widget 0x%08x <-> window %p (%s)", - w, win, win->GetClassInfo()->GetClassName()); + wxLogTrace("widget", "Widget 0x%p <-> window %p (%s)", + (WXWidget)w, win, win->GetClassInfo()->GetClassName()); return TRUE; } @@ -2196,33 +2197,8 @@ static void wxCanvasInputEvent(Widget drawingArea, } case KeyPress: { - KeySym keySym; - static char buf[100]; -#if 0 - XComposeStatus compose; - (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, &compose); -#endif // 0 - - (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, NULL); - int id = wxCharCodeXToWX (keySym); - - wxEventType eventType = wxEVT_CHAR; - - wxKeyEvent event (eventType); - - if (local_event.xkey.state & ShiftMask) - event.m_shiftDown = TRUE; - if (local_event.xkey.state & ControlMask) - event.m_controlDown = TRUE; - if (local_event.xkey.state & Mod3Mask) - event.m_altDown = TRUE; - if (local_event.xkey.state & Mod1Mask) - event.m_metaDown = TRUE; - event.SetEventObject(canvas); - event.m_keyCode = id; - event.SetTimestamp(local_event.xkey.time); - - if (id > -1) + wxKeyEvent event (wxEVT_CHAR); + if (wxTranslateKeyEvent (event, canvas, (Widget) 0, &local_event)) { // Implement wxFrame::OnCharHook by checking ancestor. wxWindow *parent = canvas->GetParent(); @@ -2251,26 +2227,8 @@ static void wxCanvasInputEvent(Widget drawingArea, } case KeyRelease: { - static char buf[100]; - KeySym keySym; - (void) XLookupString ((XKeyEvent *) & local_event, buf, 20, &keySym, NULL); - int id = wxCharCodeXToWX (keySym); - wxKeyEvent event (wxEVT_KEY_UP); - - if (local_event.xkey.state & ShiftMask) - event.m_shiftDown = TRUE; - if (local_event.xkey.state & ControlMask) - event.m_controlDown = TRUE; - if (local_event.xkey.state & Mod3Mask) - event.m_altDown = TRUE; - if (local_event.xkey.state & Mod1Mask) - event.m_metaDown = TRUE; - event.SetEventObject(canvas); - event.m_keyCode = id; - event.SetTimestamp(local_event.xkey.time); - - if (id > -1) + if (wxTranslateKeyEvent (event, canvas, (Widget) 0, &local_event)) { canvas->GetEventHandler()->ProcessEvent (event); } @@ -2823,6 +2781,10 @@ bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget WXUNUSED(wid #endif // 0 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL); int id = wxCharCodeXToWX (keySym); + // id may be WXK_xxx code - these are outside ASCII range, so we + // can't just use toupper() on id + if (id >= 'a' && id <= 'z') + id = toupper(id); if (xevent->xkey.state & ShiftMask) wxevent.m_shiftDown = TRUE; @@ -3020,8 +2982,9 @@ void wxWindow::ChangeFont(bool keepOriginalSize) int width, height, width1, height1; GetSize(& width, & height); - // lesstif 0.87 hangs here -#ifndef LESSTIF_VERSION + // lesstif 0.87 hangs here, but 0.93 does not +#if !defined(LESSTIF_VERSION) \ + || (defined(LesstifVersion) && LesstifVersion >= 93) XtVaSetValues (w, XmNfontList, (XmFontList) m_font.GetFontList(1.0, XtDisplay(w)), NULL); @@ -3070,8 +3033,8 @@ wxPoint wxGetMousePosition() unsigned int maskReturn; XQueryPointer (display, - rootWindow, - &rootReturn, + rootWindow, + &rootReturn, &childReturn, &rootX, &rootY, &winX, &winY, &maskReturn); return wxPoint(rootX, rootY);