diff options
-rw-r--r-- | gui/action.cpp | 11 | ||||
-rw-r--r-- | gui/fileselector.cpp | 4 | ||||
-rw-r--r-- | gui/input.cpp | 5 | ||||
-rw-r--r-- | gui/keyboard.cpp | 3 | ||||
-rw-r--r-- | gui/listbox.cpp | 4 | ||||
-rw-r--r-- | gui/object.cpp | 26 | ||||
-rw-r--r-- | gui/objects.hpp | 32 | ||||
-rw-r--r-- | gui/pages.cpp | 39 | ||||
-rw-r--r-- | gui/pages.hpp | 7 | ||||
-rw-r--r-- | gui/partitionlist.cpp | 4 | ||||
-rw-r--r-- | gui/progressbar.cpp | 4 | ||||
-rw-r--r-- | gui/slidervalue.cpp | 4 | ||||
-rw-r--r-- | gui/text.cpp | 4 |
13 files changed, 96 insertions, 51 deletions
diff --git a/gui/action.cpp b/gui/action.cpp index 951feb114..66ee5d6f0 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -144,16 +144,13 @@ int GUIAction::NotifyKey(int key) return 0; } -int GUIAction::NotifyVarChange(std::string varName, std::string value) +int GUIAction::NotifyVarChange(const std::string& varName, const std::string& value) { + GUIObject::NotifyVarChange(varName, value); + if (varName.empty() && !isConditionValid() && !mKey && !mActionW) doActions(); - - // This handles notifying the condition system of page start - if (varName.empty() && isConditionValid()) - NotifyPageSet(); - - if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue()) + else if((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue()) doActions(); return 0; diff --git a/gui/fileselector.cpp b/gui/fileselector.cpp index 484bcff11..e1570edd0 100644 --- a/gui/fileselector.cpp +++ b/gui/fileselector.cpp @@ -865,8 +865,10 @@ int GUIFileSelector::NotifyTouch(TOUCH_STATE state, int x, int y) return 0; } -int GUIFileSelector::NotifyVarChange(std::string varName, std::string value) +int GUIFileSelector::NotifyVarChange(const std::string& varName, const std::string& value) { + GUIObject::NotifyVarChange(varName, value); + if(!isConditionTrue()) return 0; diff --git a/gui/input.cpp b/gui/input.cpp index e4020745c..61b0cff1f 100644 --- a/gui/input.cpp +++ b/gui/input.cpp @@ -216,7 +216,6 @@ GUIInput::~GUIInput() if (mInputText) delete mInputText; if (mBackground) delete mBackground; if (mCursor) delete mCursor; - if (mFont) delete mFont; if (mAction) delete mAction; } @@ -592,8 +591,10 @@ int GUIInput::NotifyTouch(TOUCH_STATE state, int x, int y) return 0; } -int GUIInput::NotifyVarChange(std::string varName, std::string value) +int GUIInput::NotifyVarChange(const std::string& varName, const std::string& value) { + GUIObject::NotifyVarChange(varName, value); + if (varName == mVariable && !isLocalChange) { HandleTextLocation(-1003); return 0; diff --git a/gui/keyboard.cpp b/gui/keyboard.cpp index f08d71488..78e27a164 100644 --- a/gui/keyboard.cpp +++ b/gui/keyboard.cpp @@ -304,10 +304,7 @@ GUIKeyboard::GUIKeyboard(xml_node<>* node) 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/listbox.cpp b/gui/listbox.cpp index 99e2dedf1..bbfc9344a 100644 --- a/gui/listbox.cpp +++ b/gui/listbox.cpp @@ -760,8 +760,10 @@ int GUIListBox::NotifyTouch(TOUCH_STATE state, int x, int y) return 0; } -int GUIListBox::NotifyVarChange(std::string varName, std::string value) +int GUIListBox::NotifyVarChange(const std::string& varName, const std::string& value) { + GUIObject::NotifyVarChange(varName, value); + if(!isConditionTrue()) return 0; diff --git a/gui/object.cpp b/gui/object.cpp index b6010d778..41cc822bb 100644 --- a/gui/object.cpp +++ b/gui/object.cpp @@ -29,6 +29,8 @@ extern "C" { GUIObject::GUIObject(xml_node<>* node) { + mConditionsResult = true; + // Break out early, it's too hard to check if valid every step if (!node) return; @@ -78,13 +80,7 @@ bool GUIObject::IsConditionVariable(std::string var) bool GUIObject::isConditionTrue() { - std::vector<Condition>::iterator iter; - for (iter = mConditions.begin(); iter != mConditions.end(); iter++) - { - if (!isConditionTrue(&(*iter))) - return false; - } - return true; + return mConditionsResult; } bool GUIObject::isConditionTrue(Condition* condition) @@ -159,12 +155,15 @@ bool GUIObject::isConditionValid() return !mConditions.empty(); } -void GUIObject::NotifyPageSet() +int GUIObject::NotifyVarChange(const std::string& varName, const std::string& value) { + mConditionsResult = true; + + const bool varNameEmpty = varName.empty(); std::vector<Condition>::iterator iter; - for (iter = mConditions.begin(); iter != mConditions.end(); iter++) + for (iter = mConditions.begin(); iter != mConditions.end(); ++iter) { - if (iter->mCompareOp == "modified") + if(varNameEmpty && iter->mCompareOp == "modified") { string val; @@ -176,7 +175,14 @@ void GUIObject::NotifyPageSet() } iter->mLastVal = val; } + + if(varNameEmpty || iter->mVar1 == varName || iter->mVar2 == varName) + iter->mLastResult = isConditionTrue(&(*iter)); + + if(!iter->mLastResult) + mConditionsResult = false; } + return 0; } bool GUIObject::isMounted(string vol) diff --git a/gui/objects.hpp b/gui/objects.hpp index 42dfb1f09..472d23b42 100644 --- a/gui/objects.hpp +++ b/gui/objects.hpp @@ -114,10 +114,6 @@ public: // Return 0 if this object handles the request, 1 if not virtual int IsInRegion(int x, int y) { return ((x < mActionX || x > mActionX + mActionW || y < mActionY || y > mActionY + mActionH) ? 0 : 1); } - // NotifyVarChange - Notify of a variable change - // Returns 0 on success, <0 on error - virtual int NotifyVarChange(std::string varName, std::string value) { return 0; } - protected: int mActionX, mActionY, mActionW, mActionH; }; @@ -132,16 +128,24 @@ public: bool IsConditionVariable(std::string var); bool isConditionTrue(); bool isConditionValid(); - void NotifyPageSet(); + + // NotifyVarChange - Notify of a variable change + // Returns 0 on success, <0 on error + virtual int NotifyVarChange(const std::string& varName, const std::string& value); protected: class Condition { public: + Condition() { + mLastResult = true; + } + std::string mVar1; std::string mVar2; std::string mCompareOp; std::string mLastVal; + bool mLastResult; }; std::vector<Condition> mConditions; @@ -149,6 +153,8 @@ protected: protected: bool isMounted(std::string vol); bool isConditionTrue(Condition* condition); + + bool mConditionsResult; }; class InputObject @@ -189,7 +195,7 @@ public: virtual int GetCurrentBounds(int& w, int& h); // Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + virtual int NotifyVarChange(const std::string& varName, const std::string& value); // Set maximum width in pixels virtual int SetMaxWidth(unsigned width); @@ -264,7 +270,7 @@ public: public: virtual int NotifyTouch(TOUCH_STATE state, int x, int y); virtual int NotifyKey(int key); - virtual int NotifyVarChange(std::string varName, std::string value); + virtual int NotifyVarChange(const std::string& varName, const std::string& value); virtual int doActions(); protected: @@ -441,7 +447,7 @@ public: virtual int NotifyTouch(TOUCH_STATE state, int x, int y); // NotifyVarChange - Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + virtual int NotifyVarChange(const std::string& varName, const std::string& value); // SetPos - Update the position of the render object // Return 0 on success, <0 on error @@ -545,7 +551,7 @@ public: virtual int NotifyTouch(TOUCH_STATE state, int x, int y); // NotifyVarChange - Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + virtual int NotifyVarChange(const std::string& varName, const std::string& value); // SetPos - Update the position of the render object // Return 0 on success, <0 on error @@ -633,7 +639,7 @@ public: virtual int NotifyTouch(TOUCH_STATE state, int x, int y); // NotifyVarChange - Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + virtual int NotifyVarChange(const std::string& varName, const std::string& value); // SetPos - Update the position of the render object // Return 0 on success, <0 on error @@ -737,7 +743,7 @@ public: // NotifyVarChange - Notify of a variable change // Returns 0 on success, <0 on error - virtual int NotifyVarChange(std::string varName, std::string value); + virtual int NotifyVarChange(const std::string& varName, const std::string& value); protected: Resource* mEmptyBar; @@ -854,7 +860,7 @@ public: virtual int Update(void); // Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + virtual int NotifyVarChange(const std::string& varName, const std::string& value); // NotifyTouch - Notify of a touch event // Return 0 on success, >0 to ignore remainder of touch, and <0 on error @@ -937,7 +943,7 @@ public: virtual int NotifyTouch(TOUCH_STATE state, int x, int y); // Notify of a variable change - virtual int NotifyVarChange(std::string varName, std::string value); + virtual int NotifyVarChange(const std::string& varName, const std::string& value); // SetPageFocus - Notify when a page gains or loses focus virtual void SetPageFocus(int inFocus); diff --git a/gui/pages.cpp b/gui/pages.cpp index dc9edc798..2953eddb8 100644 --- a/gui/pages.cpp +++ b/gui/pages.cpp @@ -193,6 +193,12 @@ Page::Page(xml_node<>* page, xml_node<>* templates /* = NULL */) 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 @@ bool Page::ProcessNode(xml_node<>* page, xml_node<>* templates /* = NULL */, int 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 @@ bool Page::ProcessNode(xml_node<>* page, xml_node<>* templates /* = NULL */, int else if (type == "partitionlist") { GUIPartitionList* element = new GUIPartitionList(child); + mObjects.push_back(element); mRenders.push_back(element); mActions.push_back(element); } @@ -497,13 +519,8 @@ void Page::SetPageFocus(int inFocus) int Page::NotifyVarChange(std::string varName, std::string value) { - std::vector<ActionObject*>::iterator iter; - - // Don't try to handle a lack of handlers - if (mActions.size() == 0) - return 1; - - for (iter = mActions.begin(); iter != mActions.end(); ++iter) + std::vector<GUIObject*>::iterator iter; + for (iter = mObjects.begin(); iter != mObjects.end(); ++iter) { if ((*iter)->NotifyVarChange(varName, value)) LOGERR("An action handler errored on NotifyVarChange.\n"); @@ -526,6 +543,9 @@ PageSet::PageSet(char* xmlFile) PageSet::~PageSet() { + for (std::vector<Page*>::iterator itr = mPages.begin(); itr != mPages.end(); ++itr) + delete *itr; + delete mResources; free(mXmlFile); } @@ -840,7 +860,10 @@ PageSet* PageManager::SelectPackage(std::string name) tmp = FindPackage(name); if (tmp) + { mCurrentSet = tmp; + mCurrentSet->NotifyVarChange("", ""); + } else LOGERR("Unable to find package.\n"); @@ -869,6 +892,8 @@ int PageManager::ReloadPackage(std::string name, std::string package) } 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 2a2ef2c32..23ceee9c8 100644 --- a/gui/pages.hpp +++ b/gui/pages.hpp @@ -29,14 +29,14 @@ class RenderObject; 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 @@ public: protected: std::string mName; + std::vector<GUIObject*> mObjects; std::vector<RenderObject*> mRenders; std::vector<ActionObject*> mActions; std::vector<InputObject*> mInputs; diff --git a/gui/partitionlist.cpp b/gui/partitionlist.cpp index cb9011f30..064b9df01 100644 --- a/gui/partitionlist.cpp +++ b/gui/partitionlist.cpp @@ -827,8 +827,10 @@ int GUIPartitionList::NotifyTouch(TOUCH_STATE state, int x, int y) return 0; } -int GUIPartitionList::NotifyVarChange(std::string varName, std::string value) +int GUIPartitionList::NotifyVarChange(const std::string& varName, const std::string& value) { + GUIObject::NotifyVarChange(varName, value); + if(!isConditionTrue()) return 0; diff --git a/gui/progressbar.cpp b/gui/progressbar.cpp index 9c80eb40a..83de4d13b 100644 --- a/gui/progressbar.cpp +++ b/gui/progressbar.cpp @@ -172,8 +172,10 @@ int GUIProgressBar::Update(void) return 2; } -int GUIProgressBar::NotifyVarChange(std::string varName, std::string value) +int GUIProgressBar::NotifyVarChange(const std::string& varName, const std::string& value) { + GUIObject::NotifyVarChange(varName, value); + if(!isConditionTrue()) return 0; diff --git a/gui/slidervalue.cpp b/gui/slidervalue.cpp index c83456b9e..972d1f728 100644 --- a/gui/slidervalue.cpp +++ b/gui/slidervalue.cpp @@ -396,8 +396,10 @@ int GUISliderValue::NotifyTouch(TOUCH_STATE state, int x, int y) return 0; } -int GUISliderValue::NotifyVarChange(std::string varName, std::string value) +int GUISliderValue::NotifyVarChange(const std::string& varName, const std::string& value) { + GUIObject::NotifyVarChange(varName, value); + if (mLabel) mLabel->NotifyVarChange(varName, value); if (varName == mVariable) { diff --git a/gui/text.cpp b/gui/text.cpp index 715880b62..c594f4824 100644 --- a/gui/text.cpp +++ b/gui/text.cpp @@ -222,8 +222,10 @@ std::string GUIText::parseText(void) } } -int GUIText::NotifyVarChange(std::string varName, std::string value) +int GUIText::NotifyVarChange(const std::string& varName, const std::string& value) { + GUIObject::NotifyVarChange(varName, value); + mVarChanged = 1; return 0; } |