]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix crash in wxListbook if image list is assigned after adding pages.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 12 Apr 2010 00:37:08 +0000 (00:37 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 12 Apr 2010 00:37:08 +0000 (00:37 +0000)
The generic wxListCtrl didn't properly support switching between report and
non-report modes without invalidating the control contents, the required in
non report view geometry info pointers were not allocated when the control was
switched to a, say, list mode and not created in it.

Fix this by updating all list control lines when the report mode changes.

Closes #11698.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63946 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/private/listctrl.h
src/generic/listctrl.cpp

index 0123cacc1d3a2faf67d6bf70f0a2bd5b782ba232..f257fcd7a89bd16054f3fb3341163250361c7973 100644 (file)
@@ -213,6 +213,21 @@ public:
         delete m_gi;
     }
 
+    // called by the owner when it toggles report view
+    void SetReportView(bool inReportView)
+    {
+        // we only need m_gi when we're not in report view so update as needed
+        if ( inReportView )
+        {
+            delete m_gi;
+            m_gi = NULL;
+        }
+        else
+        {
+            m_gi = new GeometryInfo;
+        }
+    }
+
     // are we in report mode?
     inline bool InReportView() const;
 
@@ -424,6 +439,10 @@ public:
 
     virtual ~wxListMainWindow();
 
+    // called by the main control when its mode changes
+    void SetReportView(bool inReportView);
+
+    // helper to simplify testing for wxLC_XXX flags
     bool HasFlag(int flag) const { return m_parent->HasFlag(flag); }
 
     // return true if this is a virtual list control
index ae17c83a8a0553776824915c298389eed2fbc55f..732241fdf45a6afb94592e29c0cdfafb72feaeb8 100644 (file)
@@ -1650,6 +1650,15 @@ wxListMainWindow::~wxListMainWindow()
     delete m_renameTimer;
 }
 
+void wxListMainWindow::SetReportView(bool inReportView)
+{
+    const size_t count = m_lines.size();
+    for ( size_t n = 0; n < count; n++ )
+    {
+        m_lines[n].SetReportView(inReportView);
+    }
+}
+
 void wxListMainWindow::CacheLineData(size_t line)
 {
     wxGenericListCtrl *listctrl = GetListCtrl();
@@ -4443,12 +4452,22 @@ void wxGenericListCtrl::SetSingleStyle( long style, bool add )
 
 void wxGenericListCtrl::SetWindowStyleFlag( long flag )
 {
+    const bool wasInReportView = HasFlag(wxLC_REPORT);
+
     // update the window style first so that the header is created or destroyed
     // corresponding to the new style
     wxWindow::SetWindowStyleFlag( flag );
 
     if (m_mainWin)
     {
+        const bool inReportView = (flag & wxLC_REPORT) != 0;
+        if ( inReportView != wasInReportView )
+        {
+            // we need to notify the main window about this change as it must
+            // update its data structures
+            m_mainWin->SetReportView(inReportView);
+        }
+
         // m_mainWin->DeleteEverything();  wxMSW doesn't do that
 
         CreateOrDestroyHeaderWindowAsNeeded();