]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/wincmn.cpp
Fix from Hartwig
[wxWidgets.git] / src / common / wincmn.cpp
index c79c389854d31283884f914182f6801c1f2e6246..04ee2969608ff32e0f26ea107d6581ac311a6855 100644 (file)
@@ -44,6 +44,7 @@
     #include "wx/scrolbar.h"
     #include "wx/layout.h"
     #include "wx/sizer.h"
+    #include "wx/menu.h"
 #endif //WX_PRECOMP
 
 #if wxUSE_DRAG_AND_DROP
 // Windows List
 WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows;
 
+// globals
+#if wxUSE_MENUS_NATIVE
+wxMenu *wxCurrentPopupMenu = NULL;
+#endif // wxUSE_MENUS_NATIVE
+
 // ----------------------------------------------------------------------------
 // static data
 // ----------------------------------------------------------------------------
@@ -317,6 +323,11 @@ wxWindowBase::~wxWindowBase()
     // we weren't a dialog class
     wxTopLevelWindows.DeleteObject((wxWindow*)this);
 
+    // The associated popup menu can still be alive, disassociate from it in
+    // this case
+    if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetInvokingWindow() == this )
+        wxCurrentPopupMenu->SetInvokingWindow(NULL);
+
     wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
 
     // notify the parent about this window destruction
@@ -881,8 +892,11 @@ bool wxWindowBase::Enable(bool enable)
 
 bool wxWindowBase::IsShownOnScreen() const
 {
+    // A window is shown on screen if it itself is shown and so are all its
+    // parents. But if a window is toplevel one, then its always visible on
+    // screen if IsShown() returns true, even if it has a hidden parent.
     return IsShown() &&
-           (GetParent() == NULL || GetParent()->IsShownOnScreen());
+           (IsTopLevel() || GetParent() == NULL || GetParent()->IsShownOnScreen());
 }
 
 // ----------------------------------------------------------------------------
@@ -1105,7 +1119,7 @@ wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
 
 wxColour wxWindowBase::GetBackgroundColour() const
 {
-    if ( !m_backgroundColour.Ok() )
+    if ( !m_backgroundColour.IsOk() )
     {
         wxASSERT_MSG( !m_hasBgCol, _T("we have invalid explicit bg colour?") );
 
@@ -1133,7 +1147,7 @@ wxColour wxWindowBase::GetForegroundColour() const
     {
         wxColour colFg = GetDefaultAttributes().colFg;
 
-        if ( !colFg.Ok() )
+        if ( !colFg.IsOk() )
             colFg = GetClassDefaultAttributes().colFg;
 
         return colFg;
@@ -1147,7 +1161,7 @@ bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
     if ( colour == m_backgroundColour )
         return false;
 
-    m_hasBgCol = colour.Ok();
+    m_hasBgCol = colour.IsOk();
     if ( m_backgroundStyle != wxBG_STYLE_CUSTOM )
         m_backgroundStyle = m_hasBgCol ? wxBG_STYLE_COLOUR : wxBG_STYLE_SYSTEM;
 
@@ -1162,7 +1176,7 @@ bool wxWindowBase::SetForegroundColour( const wxColour &colour )
     if (colour == m_foregroundColour )
         return false;
 
-    m_hasFgCol = colour.Ok();
+    m_hasFgCol = colour.IsOk();
     m_inheritFgCol = m_hasFgCol;
     m_foregroundColour = colour;
     SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() );
@@ -1187,12 +1201,12 @@ bool wxWindowBase::SetCursor(const wxCursor& cursor)
 wxFont wxWindowBase::GetFont() const
 {
     // logic is the same as in GetBackgroundColour()
-    if ( !m_font.Ok() )
+    if ( !m_font.IsOk() )
     {
         wxASSERT_MSG( !m_hasFont, _T("we have invalid explicit font?") );
 
         wxFont font = GetDefaultAttributes().font;
-        if ( !font.Ok() )
+        if ( !font.IsOk() )
             font = GetClassDefaultAttributes().font;
 
         return font;
@@ -1210,7 +1224,7 @@ bool wxWindowBase::SetFont(const wxFont& font)
     }
 
     m_font = font;
-    m_hasFont = font.Ok();
+    m_hasFont = font.IsOk();
     m_inheritFont = m_hasFont;
 
     InvalidateBestSize();
@@ -2242,6 +2256,17 @@ void wxWindowBase::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
 
 #if wxUSE_MENUS
 
+bool wxWindowBase::PopupMenu(wxMenu *menu, int x, int y)
+{
+    wxCHECK_MSG( menu, false, "can't popup NULL menu" );
+
+    wxCurrentPopupMenu = menu;
+    const bool rc = DoPopupMenu(menu, x, y);
+    wxCurrentPopupMenu = NULL;
+
+    return rc;
+}
+
 // this is used to pass the id of the selected item from the menu event handler
 // to the main function itself
 //