From b8b6ebb6ec0de4fac1828294f71a7bd95ada304f Mon Sep 17 00:00:00 2001 From: Deiz Date: Tue, 31 Jul 2012 03:34:09 +0000 Subject: [PATCH] Properly re-initialize drop-down lists when the list items changes. Fixes #1558. This was SVN commit r12244. --- source/gui/CDropDown.cpp | 5 +++++ source/gui/CList.cpp | 5 ++++- source/gui/CList.h | 10 +++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/source/gui/CDropDown.cpp b/source/gui/CDropDown.cpp index cf9f348867..f15f6f205b 100644 --- a/source/gui/CDropDown.cpp +++ b/source/gui/CDropDown.cpp @@ -192,6 +192,11 @@ void CDropDown::HandleMessage(SGUIMessage &Message) // Important that this is after, so that overshadowed implementations aren't processed CList::HandleMessage(Message); + + // As HandleMessage functions return void, we need to manually verify + // whether the child list's items were modified. + if (CList::GetModified()) + SetupText(); } InReaction CDropDown::ManuallyHandleEvent(const SDL_Event_* ev) diff --git a/source/gui/CList.cpp b/source/gui/CList.cpp index dce9e5d371..48d53b0627 100644 --- a/source/gui/CList.cpp +++ b/source/gui/CList.cpp @@ -31,7 +31,8 @@ CList //------------------------------------------------------------------- // Constructor / Destructor //------------------------------------------------------------------- -CList::CList() +CList::CList() : + m_Modified(false) { // Add sprite_disabled! TODO @@ -74,6 +75,7 @@ void CList::SetupText() if (!GetGUI()) return; + m_Modified = true; CGUIList *pList; GUI::GetSettingPointer(this, "list", pList); @@ -151,6 +153,7 @@ void CList::HandleMessage(SGUIMessage &Message) IGUIScrollBarOwner::HandleMessage(Message); //IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead! + m_Modified = false; switch (Message.type) { case GUIM_SETTINGS_UPDATED: diff --git a/source/gui/CList.h b/source/gui/CList.h index 4378313652..4f4e654a6d 100644 --- a/source/gui/CList.h +++ b/source/gui/CList.h @@ -124,10 +124,14 @@ protected: void DrawList(const int &selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor); - // Get the area of the list. This is so that i can easily be changed, like in CDropDown + // Get the area of the list. This is so that it can easily be changed, like in CDropDown // where the area is not equal to m_CachedActualSize. virtual CRect GetListRect() const { return m_CachedActualSize; } + // Returns whether SetupText() has run since the last message was received + // (and thus whether list items have possibly changed). + virtual bool GetModified() const { return m_Modified; } + // List of items. //CGUIList m_List; @@ -138,6 +142,10 @@ protected: * be zero, but still stored for easy handling. */ std::vector m_ItemsYPositions; + +private: + // Whether the list's items have been modified since last handling a message. + bool m_Modified; }; #endif