X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b5f62a0b2db198609b45dec622a018dae37008e..6ceef8efe9e38313dba9f7c8a64efcb344a0056e:/src/motif/window.cpp diff --git a/src/motif/window.cpp b/src/motif/window.cpp index 15a5f5240f..4c8c81a7ec 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; } @@ -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(); + 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(); + 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,7 +1219,6 @@ 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 // idle-time destroy routine. // Waiting until this ID changes causes this function to block until @@ -1215,29 +1226,19 @@ bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) // 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 } } @@ -1720,6 +1712,7 @@ void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event)) bool wxWindow::ProcessAccelerator(wxKeyEvent& event) { +#if wxUSE_ACCEL if (!m_acceleratorTable.Ok()) return FALSE; @@ -1746,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()) { @@ -1760,6 +1754,7 @@ bool wxWindow::ProcessAccelerator(wxKeyEvent& event) return frame->GetEventHandler()->ProcessEvent(commandEvent); } } +#endif } // Find a child matching the command id @@ -1781,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; @@ -1806,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; } @@ -2001,7 +1997,8 @@ static void wxCanvasEnterLeave(Widget drawingArea, } // Fix to make it work under Motif 1.0 (!) -static void wxCanvasMotionEvent (Widget WXUNUSED(drawingArea), XButtonEvent * WXUNUSED(event)) +static void wxCanvasMotionEvent (Widget WXUNUSED(drawingArea), + XButtonEvent *WXUNUSED(event)) { #if XmVersion <= 1000 XmDrawingAreaCallbackStruct cbs; @@ -2918,41 +2915,17 @@ void wxWindow::ChangeForegroundColour() } // Change a widget's foreground and background colours. -void wxWindow::DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) +void wxWindow::DoChangeForegroundColour(WXWidget widget, + wxColour& foregroundColour) { - // 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. - - Widget w = (Widget)widget; - XtVaSetValues( - w, - XmNforeground, foregroundColour.AllocColour(XtDisplay(w)), - NULL - ); + wxDoChangeForegroundColour( widget, foregroundColour ); } -void wxWindow::DoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour) +void wxWindow::DoChangeBackgroundColour(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); + wxDoChangeBackgroundColour( widget, backgroundColour, changeArmColour ); } bool wxWindow::SetBackgroundColour(const wxColour& col) @@ -2986,12 +2959,7 @@ void wxWindow::ChangeFont(bool keepOriginalSize) int width, height, width1, height1; GetSize(& width, & height); - // lesstif 0.87 hangs here -#ifndef LESSTIF_VERSION - XtVaSetValues (w, - XmNfontList, (XmFontList) m_font.GetFontList(1.0, XtDisplay(w)), - NULL); -#endif + wxDoChangeFont( GetLabelWidget(), m_font ); GetSize(& width1, & height1); if (keepOriginalSize && (width != width1 || height != height1))