From c66c7783268e15fd35df5225911d9ca59e3f7c26 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sun, 23 Jun 2013 20:34:19 +0200 Subject: [PATCH] CComponentsForm: fix position of replaced item If cc-item is bound on a parent form, it's not enough to replace the item object only, also properties like parent and index must be moved to new item to ensure that positions are calculated correctly. But it's matter for unbound cc-items. --- src/gui/components/cc.h | 2 ++ src/gui/components/cc_frm.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/gui/components/cc.h b/src/gui/components/cc.h index 39b8909d6..3d01723d9 100644 --- a/src/gui/components/cc.h +++ b/src/gui/components/cc.h @@ -242,6 +242,8 @@ class CComponentsItem : public CComponents ///sets pointer to the form object in which this item is embedded. virtual void setParent(CComponentsItem *parent){cc_parent = parent;}; + ///returns pointer to the form object in which this item is embedded. + virtual CComponentsItem * getParent(){return cc_parent;}; ///abstract: paint item, arg: do_save_bg see paintInit() above virtual void paint(bool do_save_bg = CC_SAVE_SCREEN_YES) = 0; diff --git a/src/gui/components/cc_frm.cpp b/src/gui/components/cc_frm.cpp index 5040f7d47..46313ba2e 100644 --- a/src/gui/components/cc_frm.cpp +++ b/src/gui/components/cc_frm.cpp @@ -188,9 +188,14 @@ CComponentsItem* CComponentsForm::getCCItem(const uint& cc_item_id) void CComponentsForm::replaceCCItem(const uint& cc_item_id, CComponentsItem* new_cc_Item) { if (!v_cc_items.empty()){ - if (v_cc_items[cc_item_id]){ - delete v_cc_items[cc_item_id]; - v_cc_items[cc_item_id] = NULL; + CComponentsItem* old_Item = v_cc_items[cc_item_id]; + if (old_Item){ + if (old_Item->getParent()){ + new_cc_Item->setParent(old_Item); + new_cc_Item->setIndex(old_Item->getIndex()); + } + delete old_Item; + old_Item = NULL; v_cc_items[cc_item_id] = new_cc_Item; } }