Properly delete all GUIObjects and pages on theme reload
Signed-off-by: Vojtech Bocek <vbocek@gmail.com>
Change-Id: I8df41877f8f4439a434becfd47a9914b50649b34
diff --git a/gui/input.cpp b/gui/input.cpp
index e402074..b006560 100644
--- a/gui/input.cpp
+++ b/gui/input.cpp
@@ -216,7 +216,6 @@
if (mInputText) delete mInputText;
if (mBackground) delete mBackground;
if (mCursor) delete mCursor;
- if (mFont) delete mFont;
if (mAction) delete mAction;
}
diff --git a/gui/keyboard.cpp b/gui/keyboard.cpp
index f08d714..78e27a1 100644
--- a/gui/keyboard.cpp
+++ b/gui/keyboard.cpp
@@ -304,10 +304,7 @@
GUIKeyboard::~GUIKeyboard()
{
- int layoutindex;
- for (layoutindex=0; layoutindex<MAX_KEYBOARD_LAYOUTS; layoutindex++)
- if (keyboardImg[layoutindex]) delete keyboardImg[layoutindex];
}
int GUIKeyboard::Render(void)
diff --git a/gui/pages.cpp b/gui/pages.cpp
index dc9edc7..73aab03 100644
--- a/gui/pages.cpp
+++ b/gui/pages.cpp
@@ -193,6 +193,12 @@
return;
}
+Page::~Page()
+{
+ for (std::vector<GUIObject*>::iterator itr = mObjects.begin(); itr != mObjects.end(); ++itr)
+ delete *itr;
+}
+
bool Page::ProcessNode(xml_node<>* page, xml_node<>* templates /* = NULL */, int depth /* = 0 */)
{
if (depth == 10)
@@ -225,86 +231,101 @@
if (type == "text")
{
GUIText* element = new GUIText(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
else if (type == "image")
{
GUIImage* element = new GUIImage(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
}
else if (type == "fill")
{
GUIFill* element = new GUIFill(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
}
else if (type == "action")
{
GUIAction* element = new GUIAction(child);
+ mObjects.push_back(element);
mActions.push_back(element);
}
else if (type == "console")
{
GUIConsole* element = new GUIConsole(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
else if (type == "button")
{
GUIButton* element = new GUIButton(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
else if (type == "checkbox")
{
GUICheckbox* element = new GUICheckbox(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
else if (type == "fileselector")
{
GUIFileSelector* element = new GUIFileSelector(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
else if (type == "animation")
{
GUIAnimation* element = new GUIAnimation(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
}
else if (type == "progressbar")
{
GUIProgressBar* element = new GUIProgressBar(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
else if (type == "slider")
{
GUISlider* element = new GUISlider(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
else if (type == "slidervalue")
{
GUISliderValue *element = new GUISliderValue(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
else if (type == "listbox")
{
GUIListBox* element = new GUIListBox(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
else if (type == "keyboard")
{
GUIKeyboard* element = new GUIKeyboard(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
else if (type == "input")
{
GUIInput* element = new GUIInput(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
mInputs.push_back(element);
@@ -312,6 +333,7 @@
else if (type == "partitionlist")
{
GUIPartitionList* element = new GUIPartitionList(child);
+ mObjects.push_back(element);
mRenders.push_back(element);
mActions.push_back(element);
}
@@ -526,6 +548,9 @@
PageSet::~PageSet()
{
+ for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr)
+ delete *itr;
+
delete mResources;
free(mXmlFile);
}
@@ -869,6 +894,8 @@
}
if (mCurrentSet == set)
SelectPackage(name);
+ if (mBaseSet == set)
+ mBaseSet = mCurrentSet;
delete set;
return 0;
}
diff --git a/gui/pages.hpp b/gui/pages.hpp
index 2a2ef2c..23ceee9 100644
--- a/gui/pages.hpp
+++ b/gui/pages.hpp
@@ -29,14 +29,14 @@
class ActionObject;
class InputObject;
class MouseCursor;
+class GUIObject;
class Page
{
public:
- virtual ~Page() {}
-
-public:
Page(xml_node<>* page, xml_node<>* templates = NULL);
+ virtual ~Page();
+
std::string GetName(void) { return mName; }
public:
@@ -51,6 +51,7 @@
protected:
std::string mName;
+ std::vector<GUIObject*> mObjects;
std::vector<RenderObject*> mRenders;
std::vector<ActionObject*> mActions;
std::vector<InputObject*> mInputs;