cwUi.cpp : Added 'div' aliases 'panel','row,'col' and assoc'd relaxed parent searching in _createEle().

This commit is contained in:
kevin.larke 2020-04-28 08:40:53 -04:00
parent f121997d53
commit a324184c7a

View File

@ -232,6 +232,8 @@ namespace cw
return rc; return rc;
} }
ele_t* _createEle( ui_t* p, ele_t* parent, unsigned appId, const char* eleName ) ele_t* _createEle( ui_t* p, ele_t* parent, unsigned appId, const char* eleName )
{ {
ele_t* e = mem::allocZ<ele_t>(); ele_t* e = mem::allocZ<ele_t>();
@ -253,8 +255,20 @@ namespace cw
if( appId == kInvalidId && parent != nullptr ) if( appId == kInvalidId && parent != nullptr )
{ {
appIdMapRecd_t* m; appIdMapRecd_t* m;
// Go up the tree looking for the first parent with a valid appId
// This is useful to cover the situation where the parent is an unamed div (e.g. row, col, panel)
// and the appIdMap gives the panel name as the parent.
unsigned parentAppId = parent->appId;
for(const ele_t* par=parent; par!=nullptr; par=par->parent)
if( par->appId != kInvalidId )
{
parentAppId = par->appId;
break;
}
// ... then try to look it up from the appIdMap. // ... then try to look it up from the appIdMap.
if((m = _findAppIdMap( p, parent->appId, eleName)) != nullptr ) if((m = _findAppIdMap(p, parentAppId, eleName)) != nullptr )
e->appId = m->appId; e->appId = m->appId;
} }
@ -273,7 +287,7 @@ namespace cw
// check for an existing child of parentEle with the same name // check for an existing child of parentEle with the same name
ele = _parentUuId_EleName_ToEle( p, parentEle->uuId, eleName, false ); ele = _parentUuId_EleName_ToEle( p, parentEle->uuId, eleName, false );
// if a child with the same name does exist but has a different id then // if a child with the same name does exist but has a different app id then
// ignore the match and create a new element // ignore the match and create a new element
if( ele != nullptr && appId != kInvalidId && ele->appId != appId ) if( ele != nullptr && appId != kInvalidId && ele->appId != appId )
ele = nullptr; ele = nullptr;
@ -376,7 +390,7 @@ namespace cw
ele_t* ele = nullptr; ele_t* ele = nullptr;
char* eleName = nullptr; char* eleName = nullptr;
object_t* o = srcObj->duplicate(); // duplicate the rsrc object so that we can modify it. object_t* o = srcObj->duplicate(); // duplicate the rsrc object so that we can modify it.
const char* divAliasA[] = { "row","col","panel",nullptr }; const char* divAliasA[] = { "div","row","col","panel",nullptr }; // all these types are div's
bool divAliasFl = false; bool divAliasFl = false;
if( !o->is_dict() ) if( !o->is_dict() )
@ -389,11 +403,25 @@ namespace cw
co->unlink(); co->unlink();
} }
// is this element a 'div' alias?
for(unsigned i=0; divAliasA[i]!=nullptr; ++i)
if( textCompare(divAliasA[i],eleType) == 0 )
{
divAliasFl = true;
break;
}
// get the ui ele name // get the ui ele name
if((rc = o->get("name",eleName)) != kOkRC ) if((rc = o->get("name",eleName, cw::kNoRecurseFl | cw::kOptionalFl)) != kOkRC )
{ {
rc = cwLogError(rc,"The UI element name could not be read."); if( rc == kLabelNotFoundRC && divAliasFl )
goto errLabel; rc = kOkRC;
else
{
rc = cwLogError(rc,"The UI element name could not be read.");
goto errLabel;
}
} }
// get or create the ele record to associate with this ele // get or create the ele record to associate with this ele
@ -455,14 +483,6 @@ namespace cw
goto errLabel; goto errLabel;
} }
// is this element a 'div' alias?
for(unsigned i=0; divAliasA[i]!=nullptr; ++i)
if( textCompare(divAliasA[i],eleType) == 0 )
{
divAliasFl = true;
break;
}
// if this element has a list of children then create them here // if this element has a list of children then create them here
if( co != nullptr || divAliasFl ) if( co != nullptr || divAliasFl )
@ -742,7 +762,7 @@ cw::rc_t cw::ui::create(
goto errLabel; goto errLabel;
} }
// register any suppled appId maps // register any supplied appId maps
if((rc = _registerAppIdMap(p,appIdMapA,appIdMapN)) != kOkRC ) if((rc = _registerAppIdMap(p,appIdMapA,appIdMapN)) != kOkRC )
goto errLabel; goto errLabel;