From d88a4d9e44caee22098d7600f074c29909e8e58a Mon Sep 17 00:00:00 2001 From: deadwood Date: Sun, 17 Jan 2016 15:41:47 +0000 Subject: [PATCH] Listtree.mcc: make creation of tree node symmetrical to other proxied operations Move deletion of the internal pool after call to super, which causes execution of destruct hooks in NListtree. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@51308 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- workbench/classes/zune/listtree/listtree.c | 67 +++++++++++++++------- workbench/classes/zune/listtree/listtree_private.h | 1 + 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/workbench/classes/zune/listtree/listtree.c b/workbench/classes/zune/listtree/listtree.c index a17b0f3ff3..766a7b5318 100644 --- a/workbench/classes/zune/listtree/listtree.c +++ b/workbench/classes/zune/listtree/listtree.c @@ -50,6 +50,10 @@ struct MUIS_Listtree_TreeNodeInt if (tn && tn->tn_User) \ ((struct MUIS_Listtree_TreeNode *)tn->tn_User)->tn_Flags = tn->tn_Flags; +#define SYNC_TREENODE_NAME(tn) \ + if (tn && tn->tn_User) \ + ((struct MUIS_Listtree_TreeNode *)tn->tn_User)->tn_Name = tn->tn_Name; + static IPTR NotifySimulate_Function(struct Hook *hook, Object *obj, void ** msg) { struct opSet setmsg; @@ -132,6 +136,26 @@ static IPTR DestructHook_Proxy(struct Hook *hook, Object *obj, struct MUIP_NList return 0; } +static IPTR ConstructHook_Proxy(struct Hook *hook, Object *obj, struct MUIP_NListtree_ConstructMessage *msg) +{ + struct Listtree_DATA * data = (struct Listtree_DATA *)hook->h_Data; + struct MUIS_Listtree_TreeNode * tn = NULL; + if(!data) + return 0; + + tn = AllocPooled(data->pool, sizeof(struct MUIS_Listtree_TreeNodeInt)); + + if (tn == NULL) + return 0; + + if (data->constrhook) + tn->tn_User = (APTR)CallHookPkt(data->constrhook, data->pool, msg->UserData); + else + tn->tn_User = msg->UserData; + + return (IPTR)tn; +} + #define CONV(AATTR, BATTR) \ case(AATTR): \ convtags[i].ti_Tag = BATTR; \ @@ -266,6 +290,13 @@ Object *Listtree__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg) nnset(data->nlisttree, MUIA_NListtree_CompareHook, &data->sorthookproxy); } + /* Construct hook is mandatory to allocate proxy structures */ + { + data->constructhookproxy.h_Entry = HookEntry; + data->constructhookproxy.h_SubEntry = (HOOKFUNC)ConstructHook_Proxy; + data->constructhookproxy.h_Data = data; + nnset(data->nlisttree, MUIA_NListtree_ConstructHook, &data->constructhookproxy); + } /* Destroy hook is mandatory to free proxy structures */ { data->destructhookproxy.h_Entry = HookEntry; @@ -286,9 +317,12 @@ IPTR Listtree__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg) { struct Listtree_DATA *data = INST_DATA(cl, obj); + IPTR result = DoSuperMethodA(cl, obj, msg); + + /* Destruct hook called by dispose on NListree will need the pool */ DeletePool(data->pool); - return DoSuperMethodA(cl, obj, msg); + return result; } #define FORWARDSET(AATTR, BATTR) \ @@ -397,20 +431,7 @@ IPTR Listtree__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg) IPTR Listtree__MUIM_Listtree_Insert(struct IClass *cl, Object *obj, struct MUIP_Listtree_Insert *msg) { struct Listtree_DATA *data = INST_DATA(cl, obj); - struct MUIS_Listtree_TreeNodeInt * _int = AllocPooled(data->pool, sizeof(struct MUIS_Listtree_TreeNodeInt)); - struct MUIS_Listtree_TreeNode * _return = NULL; - struct MUI_NListtree_TreeNode * ln = NULL, * pn = NULL; - - if (_int == NULL) - return (IPTR)NULL; - - _return = &_int->base; - - _return->tn_Flags = (UWORD)msg->Flags; - if (data->constrhook) - _return->tn_User = (APTR)CallHookPkt(data->constrhook, data->pool, msg->User); - else - _return->tn_User = msg->User; + struct MUI_NListtree_TreeNode * ln = NULL, * pn = NULL, * created = NULL; switch((IPTR)msg->ListNode) { @@ -434,12 +455,18 @@ IPTR Listtree__MUIM_Listtree_Insert(struct IClass *cl, Object *obj, struct MUIP_ pn = ((struct MUIS_Listtree_TreeNodeInt *)msg->PrevNode)->ref; } - _int->ref = (struct MUI_NListtree_TreeNode *)DoMethod(data->nlisttree, - MUIM_NListtree_Insert, msg->Name, _return, ln, pn, msg->Flags); + created = (struct MUI_NListtree_TreeNode *)DoMethod(data->nlisttree, + MUIM_NListtree_Insert, msg->Name, msg->User, ln, pn, msg->Flags); - _return->tn_Name = _int->ref->tn_Name; - - return (IPTR)_return; + if (created) + { + SYNC_TREENODE_FLAGS(created); + SYNC_TREENODE_NAME(created); + ((struct MUIS_Listtree_TreeNodeInt *)created->tn_User)->ref = created; + return (IPTR)created->tn_User; + } + else + return (IPTR)NULL; } IPTR Listtree__MUIM_Listtree_GetEntry(struct IClass *cl, Object *obj, struct MUIP_Listtree_GetEntry *msg) diff --git a/workbench/classes/zune/listtree/listtree_private.h b/workbench/classes/zune/listtree/listtree_private.h index a202dc4fdd..7253214896 100644 --- a/workbench/classes/zune/listtree/listtree_private.h +++ b/workbench/classes/zune/listtree/listtree_private.h @@ -23,6 +23,7 @@ struct Listtree_DATA struct Hook displayhookproxy; struct Hook sorthookproxy; struct Hook destructhookproxy; + struct Hook constructhookproxy; /*- Protected ----------------------------------------------------------*/ -- 2.11.4.GIT