From cb693a1c8edac1bdc8273c515021d6c7d4243a37 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 8 Apr 2013 23:06:44 -0700 Subject: [PATCH] cmUi.h/c and cmUiDrvr.h/c: Many changes and additions. --- cmUi.c | 1030 +++++++++++++++++++++++++++++++++------------------- cmUi.h | 196 +++++----- cmUiDrvr.c | 8 +- cmUiDrvr.h | 63 ++-- 4 files changed, 817 insertions(+), 480 deletions(-) diff --git a/cmUi.c b/cmUi.c index dc05d81..8f497c0 100644 --- a/cmUi.c +++ b/cmUi.c @@ -4,10 +4,13 @@ #include "cmCtx.h" #include "cmMem.h" #include "cmMallocDebug.h" +#include "cmLinkedHeap.h" #include "cmArray.h" #include "cmJson.h" +#include "cmRtSysMsg.h" #include "cmUiDrvr.h" #include "cmUi.h" +#include "cmText.h" typedef struct @@ -30,43 +33,49 @@ enum typedef struct cmUiApp_str { - unsigned appId; // app id and index into cmUI_t.appArrH[]. - bool activeFl; // true if this app recd is active and valid - cmArrayH_t ctlArrH; // cmUiCtl_t[] - cmArrayH_t pnlArrH; // cmUiPanel_t[] + unsigned appId; // app id and index into cmUI_t.appArrH[]. + unsigned rtSubIdx; // + bool activeFl; // true if this app recd is active and valid + cmArrayH_t ctlArrH; // cmUiCtl_t[] + cmArrayH_t pnlArrH; // cmUiPanel_t[] } cmUiApp_t; struct cmUiCtl_str; typedef struct cmUiPanel_str { - cmUiApp_t* appPtr; // owner app. - struct cmUiCtl_str* ctl; // control recd assoc'd with this panel - unsigned flags; // See kXXXUiFl above - unsigned usrId; // app. supplied id - cmUiRect_t rect; // rect to position next control (only used if kUseRectUiFl is set) - cmUiRect_t prevRect; - int baseCol; - int baseRow; - int dfltW; - int dfltH; - int nextW; - int nextH; - int dfltHBorder; - int dfltVBorder; - int nextHBorder; - int nextVBorder; - + cmUiApp_t* appPtr; // owner app. + struct cmUiCtl_str* ctl; // control recd assoc'd with this panel + unsigned flags; // See kXXXUiFl above + unsigned usrId; // app. supplied id + cmUiRect_t rect; // rect to position next control (only used if kUseRectUiFl is set) + cmUiRect_t prevRect; + int baseCol; + int baseRow; + int dfltW; + int dfltH; + int nextW; + int nextH; + int dfltHBorder; + int dfltVBorder; + int nextHBorder; + int nextVBorder; } cmUiPanel_t; +typedef struct +{ + unsigned id; + cmChar_t* label; +} cmUiListEle_t; + typedef struct cmUiCtl_str { - cmUiCId_t cId; // control type and used to decode the value union below. - unsigned usrId; // control instance id and index into cmUiApp_t.ctlArrH[]. - unsigned panelId; // panel this ctl belongs to - cmArrayH_t idArrH; // id's associated with each sub-element of this control (used by menu's, list's, etc...) - cmUiDriverArg_t arg; // cached callback arg for this control + cmUiCId_t cId; // control type and used to decode the value union below. + unsigned usrId; // control instance id and index into cmUiApp_t.ctlArrH[]. + unsigned panelId; // panel this ctl belongs to + cmArrayH_t idArrH; // id's associated with each sub-element of this control (used by menu's, list's, etc...) + cmUiDriverArg_t arg; // cached callback arg for this control // current value of this control union @@ -90,20 +99,19 @@ typedef struct cmUiCtl_str typedef struct { - cmErr_t err; // - cmCtx_t* ctx; // Global context. - cmUiDriverFunc_t drvr; // Driver callback function - void* drvrArg; // Driver callback function arg. - int panelW; // Panel width. - int panelH; // Panel height - unsigned curAppId; // Id of application currently receiveing commands/queries. - cmUiDriverFunc_t cbFunc; // Client callback function - void * cbArg; // - cmArrayH_t appArrH; // cmUiApp_t[] - cmUiCtl_t dummy; // dummy recd used to create controls which will never be accessed after creation (like read-only labels) + cmErr_t err; // + cmCtx_t* ctx; // Global context. + cmUiDriverFunc_t drvr; // Driver callback function + void* drvrArg; // Driver callback function arg. + int panelW; // Panel width. + int panelH; // Panel height + cmUiDriverFunc_t cbFunc; // Client callback function + void* cbArg; // + cmArrayH_t appArrH; // cmUiApp_t[] + cmUiCtl_t dummy; // dummy recd used to create controls which will never be accessed after creation (like read-only labels) } cmUi_t; -cmUiH_t cmUiNullHandle = cmSTATIC_NULL_HANDLE; +cmUiH_t cmUiNullHandle = cmSTATIC_NULL_HANDLE; cmUi_t* _cmUiHandleToPtr( cmUiH_t h ) { @@ -211,51 +219,52 @@ void _cmUiSetStrAccessors( cmUiCtl_t* ctl ) //--------------------------------------------------------------- -cmUiRC_t _cmUiCallDriver( cmUi_t* p, cmUiDId_t dId, cmUiCtl_t* ctl ) +cmUiRC_t _cmUiCallDriver( cmUi_t* p, cmUiDId_t dId, cmUiCtl_t* ctl, unsigned flags ) { cmUiRC_t rc = kOkUiRC; if( p->drvr != NULL ) { - ctl->arg.dId = dId; + unsigned orgFlags = ctl->arg.flags; + ctl->arg.dId = dId; + ctl->arg.flags |= flags; + ctl->arg.hdr.selId = kUiDrvrSelRtId; - if((rc = p->drvr(p->drvrArg,&ctl->arg)) != kOkUiRC ) + rc = p->drvr(p->drvrArg,&ctl->arg); + + ctl->arg.flags = orgFlags; + + if( rc != kOkUiRC ) rc = cmErrMsg(&p->err,kDrvrErrUiRC,"UI manager driver error."); } return rc; } -cmUiRC_t _cmUiSetDriverValue( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag ) -{ - unsigned orgFlags = ctl->arg.flags; - ctl->arg.flags |= flag; - cmUiRC_t rc = _cmUiCallDriver(p,kSetValDId,ctl); - ctl->arg.flags = orgFlags; - return rc; -} - cmUiRC_t _cmUiSetDriverValueInt( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, int value ) { + ctl->setInt(ctl,value); ctl->arg.ival = value; - return _cmUiSetDriverValue(p,ctl,flag); + return _cmUiCallDriver(p, kSetValDId, ctl, flag | kIvalUiFl); } cmUiRC_t _cmUiSetDriverValueDouble( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, double value ) { + ctl->setDbl(ctl,value); ctl->arg.fval = value; - return _cmUiSetDriverValue(p,ctl,flag); + return _cmUiCallDriver(p, kSetValDId, ctl, flag | kFvalUiFl); } cmUiRC_t _cmUiSetDriverValueStr( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, const cmChar_t* value ) { + ctl->setStr(ctl,value); ctl->arg.sval = value; - return _cmUiSetDriverValue(p,ctl,flag); + return _cmUiCallDriver(p, kSetValDId, ctl, flag | kSvalUiFl); } cmUiRC_t _cmUiSetDriverValueIntAndStr( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, int ival, const cmChar_t* sval ) { ctl->arg.ival = ival; ctl->arg.sval = sval; - return _cmUiSetDriverValue(p,ctl,flag); + return _cmUiCallDriver(p, kSetValDId, ctl, flag | kIvalUiFl|kSvalUiFl); } @@ -263,7 +272,7 @@ cmUiRC_t _cmUiSetDriverValueIntAndStr( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, cmUiRC_t _cmUiFindApp( cmUi_t* p, unsigned appId, cmUiApp_t** appRef, bool errFl ) { - cmUiRC_t rc = kOkUiRC; + cmUiRC_t rc = kOkUiRC; cmUiApp_t* ap = NULL; // verify that the appId is a valid index @@ -290,14 +299,14 @@ cmUiRC_t _cmUiFindApp( cmUi_t* p, unsigned appId, cmUiApp_t** appRef, bool errF } -cmUiRC_t _cmUiFindCtl( cmUi_t* p, unsigned usrId, cmUiCtl_t** ctlRef, bool errFl ) +cmUiRC_t _cmUiFindCtl( cmUi_t* p, unsigned appId, unsigned usrId, cmUiCtl_t** ctlRef, bool errFl ) { - cmUiRC_t rc = kOkUiRC; - cmUiApp_t* ap = NULL; - cmUiCtl_t* ctl = NULL; + cmUiRC_t rc = kOkUiRC; + cmUiApp_t* ap = NULL; + cmUiCtl_t* ctl = NULL; // find the app this ctl belongs to - if(( rc =_cmUiFindApp(p,p->curAppId,&ap,errFl)) != kOkUiRC ) + if(( rc =_cmUiFindApp(p,appId,&ap,errFl)) != kOkUiRC ) goto errLabel; // verify that the usrId is a valid index @@ -323,35 +332,35 @@ cmUiRC_t _cmUiFindCtl( cmUi_t* p, unsigned usrId, cmUiCtl_t** ctlRef, bool errF return rc; } -cmUiRC_t _cmUiFastFindCtl( cmUi_t* p, unsigned usrId, cmUiCtl_t** ctlRef, bool errFl ) +cmUiRC_t _cmUiFastFindCtl( cmUi_t* p, unsigned appId, unsigned usrId, cmUiCtl_t** ctlRef, bool errFl ) { - assert( p->curAppId < cmArrayCount(p->appArrH) ); + assert( appId < cmArrayCount(p->appArrH) ); - cmUiApp_t* ap = cmArrayPtr(cmUiApp_t,p->appArrH,p->curAppId); + cmUiApp_t* ap = cmArrayPtr(cmUiApp_t,p->appArrH,appId); assert( ap->activeFl && usrId < cmArrayCount(ap->ctlArrH) ); *ctlRef = cmArrayPtr(cmUiCtl_t,ap->ctlArrH,usrId); - assert( (*ctlRef)->usrId == usrId ); + assert( (*ctlRef)->usrId == usrId && (*ctlRef)->arg.appId == ap->appId ); return kOkUiRC; } -cmUiRC_t _cmUiFindPanel( cmUi_t* p, unsigned panelId, cmUiPanel_t** ppRef, bool errFl ) +cmUiRC_t _cmUiFindPanel( cmUi_t* p, unsigned appId, unsigned panelId, cmUiPanel_t** ppRef, bool errFl ) { - cmUiRC_t rc = kOkUiRC; - cmUiApp_t* ap = NULL; - unsigned i,n; + cmUiRC_t rc = kOkUiRC; + cmUiApp_t* ap = NULL; + unsigned i,n; *ppRef = NULL; // find the app this ctl belongs to - if(( rc =_cmUiFindApp(p,p->curAppId,&ap,errFl)) != kOkUiRC ) + if(( rc =_cmUiFindApp(p,appId,&ap,errFl)) != kOkUiRC ) goto errLabel; - n = cmArrayCount(ap->pnlArrH); + n = cmArrayCount(ap->pnlArrH); for(i=0; ipnlArrH,i))->usrId == panelId ) break; @@ -372,16 +381,30 @@ cmUiRC_t _cmUiFindPanel( cmUi_t* p, unsigned panelId, cmUiPanel_t** ppRef, bool //--------------------------------------------------------------- -cmUiRC_t _cmUiDestroyCtl( cmUi_t* p, cmUiCtl_t* ctl ) +void _cmUiReleaseListEles( cmUiCtl_t* ctl ) +{ + if( cmArrayIsValid(ctl->idArrH) ) + { + unsigned n = cmArrayCount(ctl->idArrH); + unsigned i; + for(i=0; iidArrH,i)->label ); + } + +} + +cmUiRC_t _cmUiDestroyCtl( cmUi_t* p, cmUiCtl_t* ctl, bool drvrFl ) { cmUiRC_t rc = kOkUiRC; - rc = _cmUiCallDriver(p,kDestroyCtlDId,ctl); + if( drvrFl ) + rc = _cmUiCallDriver(p,kDestroyCtlDId,ctl,0); switch(ctl->cId) { case kLabelUiCId: - case kTextUiCId: + case kStringUiCId: + case kConsoleUiCId: case kFilenameUiCId: case kDirUiCId: cmMemFree(ctl->u.sval); @@ -394,24 +417,27 @@ cmUiRC_t _cmUiDestroyCtl( cmUi_t* p, cmUiCtl_t* ctl ) ctl->cId = kInvalidUiCId; ctl->usrId = cmInvalidId; ctl->panelId = cmInvalidId; + + _cmUiReleaseListEles(ctl); + cmArrayRelease(&ctl->idArrH); return rc; } -cmUiRC_t _cmUiDestroyPanel( cmUi_t* p, unsigned panelId ) +cmUiRC_t _cmUiDestroyPanel( cmUi_t* p, unsigned appId, unsigned panelId ) { - cmUiRC_t rc = kOkUiRC; + cmUiRC_t rc = kOkUiRC; cmUiPanel_t* pp = NULL; // get the panel recd ptr - if((rc = _cmUiFindPanel(p,panelId,&pp,true)) != kOkUiRC ) + if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC ) return rc; cmUiApp_t* ap = pp->appPtr; // notify the driver to destroy the panel - if((rc = _cmUiCallDriver(p,kDestroyCtlDId,pp->ctl)) != kOkUiRC ) + if((rc = _cmUiCallDriver(p,kDestroyCtlDId,pp->ctl,0)) != kOkUiRC ) return rc; cmUiCtl_t* ctl = NULL; @@ -424,9 +450,9 @@ cmUiRC_t _cmUiDestroyPanel( cmUi_t* p, unsigned panelId ) // because destroying the drivers panel has implicitely also // destroyed all the contols assigned to it. for(i=0; ipanelId == panelId) - if((rc0 = _cmUiDestroyCtl(p,ctl)) != kOkUiRC ) - rc = rc0; + if( _cmUiFindCtl(p,appId,i,&ctl,false) == kOkUiRC && ctl != NULL && ctl->panelId == panelId) + if((rc0 = _cmUiDestroyCtl(p,ctl,false)) != kOkUiRC ) + rc = rc0; // release the panel record pp->appPtr = NULL; @@ -440,9 +466,6 @@ cmUiRC_t _cmUiDestroyApp( cmUi_t* p, unsigned appId, bool errFl ) cmUiRC_t rc = kOkUiRC; cmUiRC_t rc0; cmUiApp_t* ap; - unsigned orgAppId = p->curAppId; - - p->curAppId = appId; // find the app to destroy if( _cmUiFindApp(p,appId,&ap,false) != kOkUiRC ) @@ -460,19 +483,19 @@ cmUiRC_t _cmUiDestroyApp( cmUi_t* p, unsigned appId, bool errFl ) unsigned n = cmArrayCount(ap->pnlArrH); for(i=0; ipnlArrH,i); + cmUiPanel_t* pp = cmArrayPtr(cmUiPanel_t,ap->pnlArrH,i); if( pp->usrId != cmInvalidId ) - if((rc0 = _cmUiDestroyPanel(p,pp->usrId)) != kOkUiRC ) - rc = rc0; + if((rc0 = _cmUiDestroyPanel(p,appId,pp->usrId)) != kOkUiRC ) + rc = rc0; } - ap->appId = -1; + ap->appId = -1; ap->activeFl = false; cmArrayRelease(&ap->ctlArrH); cmArrayRelease(&ap->pnlArrH); errLabel: - p->curAppId = orgAppId; + //p->curAppId = orgAppId; return rc; } @@ -486,7 +509,7 @@ cmUiRC_t _cmUiDestroyAllApps( cmUi_t* p ) { cmUiRC_t rc0; if((rc0 = _cmUiDestroyApp(p,i,false)) != kOkUiRC ) - rc = rc0; + rc = rc0; } cmArrayClear(p->appArrH,false); @@ -501,10 +524,10 @@ cmUiRC_t _cmUiGetCtlXYWH( cmUi_t* p, cmUiDriverArg_t* a, cmUiPanel_t* pp ) if( cmIsFlag(pp->flags,kUseRectUiFl ) ) { pp->flags = cmClrFlag(pp->flags,kUseRectUiFl); - a->x = pp->rect.x; - a->y = pp->rect.y; - a->w = pp->rect.w; - a->h = pp->rect.h; + a->x = pp->rect.x; + a->y = pp->rect.y; + a->w = pp->rect.w; + a->h = pp->rect.h; return kOkUiRC; } @@ -535,7 +558,7 @@ cmUiRC_t _cmUiGetCtlXYWH( cmUi_t* p, cmUiDriverArg_t* a, cmUiPanel_t* pp ) if( fillRowFl ) a->x = pp->prevRect.x + pp->prevRect.w + pp->nextHBorder; else - a->x = pp->baseCol; // ... or down columns + a->x = pp->baseCol; // ... or down columns // if a new column was set then move to the base row if( cmIsFlag(pp->flags,kPlaceBaseRowUiFl) ) @@ -549,26 +572,26 @@ cmUiRC_t _cmUiGetCtlXYWH( cmUi_t* p, cmUiDriverArg_t* a, cmUiPanel_t* pp ) a->y = pp->prevRect.y + pp->prevRect.h + pp->nextVBorder; // ... or down columns } - a->w = pp->nextW; - a->h = pp->nextH; + a->w = pp->nextW; + a->h = pp->nextH; pp->prevRect.x = a->x; pp->prevRect.y = a->y; pp->prevRect.w = a->w; pp->prevRect.h = a->h; - pp->nextW = pp->dfltW; - pp->nextH = pp->dfltH; - pp->nextHBorder= pp->dfltHBorder; - pp->nextVBorder= pp->dfltVBorder; + pp->nextW = pp->dfltW; + pp->nextH = pp->dfltH; + pp->nextHBorder = pp->dfltHBorder; + pp->nextVBorder = pp->dfltVBorder; - pp->flags = cmClrFlag(pp->flags,kNextWHUiFl | kPlaceRightUiFl | kPlaceBelowUiFl | kPlaceBaseRowUiFl ); + pp->flags = cmClrFlag(pp->flags,kNextWHUiFl | kPlaceRightUiFl | kPlaceBelowUiFl | kPlaceBaseRowUiFl ); return kOkUiRC; } -cmUiRC_t _cmUiCreateCtl( cmUi_t* p, unsigned panelId, cmUiCId_t cId, unsigned usrId, const cmChar_t* label, unsigned flags, cmUiCtl_t** ctlRef ) +cmUiRC_t _cmUiCreateCtl( cmUi_t* p, unsigned appId, unsigned panelId, cmUiCId_t cId, unsigned usrId, const cmChar_t* label, unsigned flags, cmUiCtl_t** ctlRef ) { cmUiRC_t rc; cmUiPanel_t* pp = NULL; @@ -578,11 +601,11 @@ cmUiRC_t _cmUiCreateCtl( cmUi_t* p, unsigned panelId, cmUiCId_t cId, unsigned us *ctlRef = NULL; // locate the app - if((rc = _cmUiFindApp(p,p->curAppId,&ap,true)) != kOkUiRC ) + if((rc = _cmUiFindApp(p,appId,&ap,true)) != kOkUiRC ) return rc; // locate the panel the control belongs to - if((rc = _cmUiFindPanel(p,panelId,&pp,true)) != kOkUiRC ) + if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC ) return rc; // get the new ctl record @@ -594,20 +617,20 @@ cmUiRC_t _cmUiCreateCtl( cmUi_t* p, unsigned panelId, cmUiCId_t cId, unsigned us } else { - if( cmArrayIsValid(ap->ctlArrH)==false || usrId >= cmArrayCount(ap->ctlArrH) ) - ctl = cmArrayClr(cmUiCtl_t,ap->ctlArrH,usrId); + if( cmArrayIsValid(ap->ctlArrH) == false || usrId >= cmArrayCount(ap->ctlArrH) ) + ctl = cmArrayClr(cmUiCtl_t,ap->ctlArrH,usrId); else { ctl = cmArrayPtr(cmUiCtl_t,ap->ctlArrH,usrId); // if the ctl recd is already in use if( ctl->cId != kInvalidUiCId ) - _cmUiDestroyCtl(p,ctl); + _cmUiDestroyCtl(p,ctl,true); } } // setup this controls cached callback arg record - cmUiDriverArgSetup(&ctl->arg,kInvalidDId,ap->appId,usrId,panelId,cId,flags,0,0,label,-1,-1,-1,-1); + cmUiDriverArgSetup(&ctl->arg,ap->rtSubIdx,cmInvalidId,kInvalidDId,ap->appId,usrId,panelId,cId,flags,0,0,label,-1,-1,-1,-1); // calc the control location - for non-panel controls if( cId != kPanelUiCId ) @@ -622,13 +645,13 @@ cmUiRC_t _cmUiCreateCtl( cmUi_t* p, unsigned panelId, cmUiCId_t cId, unsigned us // display-only controls don't need an id array if( usrId != cmInvalidId ) - cmArrayAlloc(p->ctx,&ctl->idArrH,sizeof(unsigned)); + cmArrayAlloc(p->ctx,&ctl->idArrH,sizeof(cmUiListEle_t)); if( ctlRef != NULL ) *ctlRef = ctl; - return _cmUiCallDriver(p,kCreateCtlDId,ctl); + return _cmUiCallDriver(p,kCreateCtlDId,ctl,0); } @@ -666,7 +689,7 @@ cmUiRC_t cmUiFree( cmUiH_t* hp ) { cmUiRC_t rc = kOkUiRC; - if( hp == NULL || cmUiIsValid(*hp)==false ) + if( hp == NULL || cmUiIsValid(*hp) == false ) return kOkUiRC; cmUi_t* p = _cmUiHandleToPtr(*hp); @@ -689,21 +712,21 @@ bool cmUiIsValid( cmUiH_t h ) void cmUiSetDriver( cmUiH_t h, cmUiDriverFunc_t drvrFunc, void* drvrArg ) { - cmUi_t* p = _cmUiHandleToPtr(h); + cmUi_t* p = _cmUiHandleToPtr(h); p->drvr = drvrFunc; p->drvrArg = drvrArg; } -cmUiRC_t cmUiCreateApp( cmUiH_t h, unsigned appId ) +cmUiRC_t cmUiCreateApp( cmUiH_t h, unsigned appId, unsigned rtSubIdx ) { - cmUiRC_t rc = kOkUiRC; + cmUiRC_t rc = kOkUiRC; - if( cmUiIsValid(h)==false) + if( cmUiIsValid(h) == false) return rc; - cmUi_t* p = _cmUiHandleToPtr(h); - cmUiApp_t* ap = NULL; + cmUi_t* p = _cmUiHandleToPtr(h); + cmUiApp_t* ap = NULL; // verify that the requested app does not exist if( _cmUiFindApp(p,appId, &ap, false ) == kOkUiRC ) @@ -711,7 +734,8 @@ cmUiRC_t cmUiCreateApp( cmUiH_t h, unsigned appId ) ap = cmArrayClr(cmUiApp_t,p->appArrH,appId); ap->appId = appId; - ap->activeFl = true; + ap->rtSubIdx = rtSubIdx; + ap->activeFl = true; cmArrayAlloc(p->ctx,&ap->ctlArrH,sizeof(cmUiCtl_t)); cmArrayAlloc(p->ctx,&ap->pnlArrH,sizeof(cmUiPanel_t)); @@ -719,6 +743,15 @@ cmUiRC_t cmUiCreateApp( cmUiH_t h, unsigned appId ) return rc; } +bool cmUiAppIsActive( cmUiH_t uiH, unsigned appId ) +{ + cmUi_t* p = _cmUiHandleToPtr(uiH); + cmUiApp_t* ap = NULL; + + return _cmUiFindApp(p,appId, &ap, false ) == kOkUiRC; +} + + cmUiRC_t cmUiDestroyApp( cmUiH_t h, unsigned appId ) { if( cmUiIsValid(h)==false) @@ -738,25 +771,19 @@ cmUiRC_t cmUiDestroyAllApps( cmUiH_t h ) return _cmUiDestroyAllApps(p); } -cmUiRC_t cmUiSetAppId( cmUiH_t h, unsigned appId ) + +unsigned cmUiAppIdToAsSubIndex( cmUiH_t uiH, unsigned appId ) { - cmUiRC_t rc = kOkUiRC; - - if( cmUiIsValid(h)==false) - return rc; - - cmUi_t* p = _cmUiHandleToPtr(h); + cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiApp_t* ap = NULL; - // verify that the requested app exists - if( appId != cmInvalidId ) - if((rc = _cmUiFindApp(p,appId, &ap, true )) != kOkUiRC ) - return rc; + if( _cmUiFindApp(p,appId, &ap, true ) != kOkUiRC ) + return cmInvalidIdx; - p->curAppId = appId; - return rc; + return ap->rtSubIdx; } + unsigned cmUiAppCount( cmUiH_t h ) { if( cmUiIsValid(h)==false) @@ -767,20 +794,47 @@ unsigned cmUiAppCount( cmUiH_t h ) return cmArrayCount(p->appArrH); } +cmUiRC_t _cmUiCallClient( cmUi_t* p, cmUiDId_t dId, cmUiCtl_t* ctl, unsigned flags ) +{ + unsigned orgFlags = ctl->arg.flags; + ctl->arg.hdr.selId = kUiSelRtId, + ctl->arg.flags |= flags; + ctl->arg.dId = dId; + cmUiRC_t rc = p->cbFunc(p->cbArg,&ctl->arg); + ctl->arg.dId = kInvalidDId; + ctl->arg.flags = orgFlags; + ctl->arg.hdr.selId = cmInvalidId; + return rc; +} cmUiRC_t cmUiOnDriverEvent( cmUiH_t h, const cmUiDriverArg_t* arg ) { cmUiRC_t rc = kOkUiRC; cmUi_t* p = _cmUiHandleToPtr(h); cmUiCtl_t* ctl; + //unsigned orgAppId = cmUiAppId(h); - if((rc = cmUiSetAppId(h,arg->appId)) != kOkUiRC ) - return rc; + //if((rc = cmUiSetAppId(h,arg->appId)) != kOkUiRC ) + // return rc; - if((rc = _cmUiFindCtl(p,arg->usrId,&ctl,true)) != kOkUiRC ) + if((rc = _cmUiFindCtl(p,arg->appId,arg->usrId,&ctl,true)) != kOkUiRC ) goto errLabel; - + + switch( arg->dId ) + { + case kEnableDId: + ctl->arg.ival = arg->ival; + return _cmUiCallClient(p,kEnableDId,ctl,arg->flags); + + case kSetValDId: + break; + + default: + assert(0); + break; + } + switch( arg->cId ) { case kInvalidUiCId: @@ -795,23 +849,34 @@ cmUiRC_t cmUiOnDriverEvent( cmUiH_t h, const cmUiDriverArg_t* arg ) case kMenuBtnUiCId: case kListUiCId: { - unsigned eleIdx = cmUiDriverArgGetInt(arg); - - if(eleIdx >= cmArrayCount(ctl->idArrH)) + if( cmIsFlag(arg->flags,kValUiFl ) ) { - rc = cmErrMsg(&p->err,kInvalidIdUiRC,"Invalid menu or list driver element id=%i element count:%i.",eleIdx,cmArrayCount(ctl->idArrH)); - goto errLabel; + unsigned eleIdx = cmUiDriverArgGetInt(arg); + + if(eleIdx >= cmArrayCount(ctl->idArrH)) + { + rc = cmErrMsg(&p->err,kInvalidIdUiRC,"Invalid menu or list driver element id=%i element count:%i.",eleIdx,cmArrayCount(ctl->idArrH)); + goto errLabel; + } + + // convert the selected items index to the associated client id value + unsigned eleId = cmArrayPtr(cmUiListEle_t,ctl->idArrH,eleIdx)->id; + ctl->setInt(ctl,eleId); + ctl->arg.ival = eleId; } - - // convert the selected items index to the associated client id value - ctl->arg.ival = ctl->u.ival = cmArrayEle(unsigned,ctl->idArrH,eleIdx); - } break; + case kConsoleUiCId: + { + const cmChar_t* s; + if((s = cmUiDriverArgGetString(arg)) != NULL ) + ctl->arg.sval = ctl->u.sval = cmTextAppendSS(ctl->u.sval, s ); + } + break; case kLabelUiCId: - case kTextUiCId: + case kStringUiCId: case kFilenameUiCId: case kDirUiCId: { @@ -828,7 +893,7 @@ cmUiRC_t cmUiOnDriverEvent( cmUiH_t h, const cmUiDriverArg_t* arg ) case kProgressUiCId: case kMeterUiCId: - assert(0); // progress and meters are display only + ctl->arg.ival = ctl->u.ival = cmUiDriverArgGetInt(arg); break; case kMaxUiCId: @@ -837,33 +902,22 @@ cmUiRC_t cmUiOnDriverEvent( cmUiH_t h, const cmUiDriverArg_t* arg ) } - ctl->arg.dId = kSetValDId; - rc = p->cbFunc(p->cbArg,&ctl->arg); + // reflect the event to the client + if( cmIsNotFlag(arg->flags, kNoReflectUiFl ) ) + { + rc = _cmUiCallClient(p,kSetValDId,ctl,0); + } errLabel: - cmUiSetAppId(h,cmInvalidId); + //cmUiSetAppId(h,orgAppId); return rc; } -cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned newPanelId, const cmChar_t* label ) +void _cmUiPanelSetDefaultValues( cmUiPanel_t* pp) { - cmUiRC_t rc; - cmUi_t* p = _cmUiHandleToPtr(uiH); - cmUiCtl_t* ctl = NULL; - cmUiApp_t* ap = NULL; - - if(( rc = _cmUiFindApp(p,p->curAppId,&ap,true)) != kOkUiRC ) - return rc; - - cmUiPanel_t* pp = cmArrayPush(ap->pnlArrH,NULL,1); - assert( pp != NULL ); - - pp->appPtr = ap; - pp->ctl = NULL; - pp->usrId = newPanelId; pp->baseCol = 2; - pp->baseRow = 0; + pp->baseRow = 2; pp->dfltW = 150; pp->dfltH = 25; pp->nextW = pp->dfltW; @@ -876,15 +930,36 @@ cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned newPanelId, const cmChar_t* la pp->prevRect.y = -1; pp->prevRect.w = -1; pp->prevRect.h = -1; - +} - if((rc = _cmUiCreateCtl(p, newPanelId, kPanelUiCId, newPanelId, label, 0, &pp->ctl )) != kOkUiRC ) + + +cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned appId, unsigned newPanelId, const cmChar_t* label, unsigned flags ) +{ + cmUiRC_t rc; + cmUi_t* p = _cmUiHandleToPtr(uiH); + cmUiCtl_t* ctl = NULL; + cmUiApp_t* ap = NULL; + + if(( rc = _cmUiFindApp(p,appId,&ap,true)) != kOkUiRC ) + return rc; + + cmUiPanel_t* pp = cmArrayPush(ap->pnlArrH,NULL,1); + assert( pp != NULL ); + + pp->appPtr = ap; + pp->ctl = NULL; + pp->usrId = newPanelId; + + _cmUiPanelSetDefaultValues(pp); + + if((rc = _cmUiCreateCtl(p, appId, newPanelId, kPanelUiCId, newPanelId, label, flags, &pp->ctl )) != kOkUiRC ) { // TODO - destroy panel record here return rc; } - _cmUiFindCtl(p,newPanelId,&ctl,true); + _cmUiFindCtl(p,appId,newPanelId,&ctl,true); assert(ctl!=NULL); ctl->u.pnl = pp; @@ -892,62 +967,78 @@ cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned newPanelId, const cmChar_t* la } -cmUiRC_t cmUiCreateBtn( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ) +cmUiRC_t cmUiCreateBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ) { cmUiRC_t rc; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* c; - if((rc = _cmUiCreateCtl(p,panelId,kBtnUiCId,id,label,flags,&c)) == kOkUiRC ) + if((rc = _cmUiCreateCtl(p,appId,panelId,kBtnUiCId,id,label,flags,&c)) == kOkUiRC ) { _cmUiSetIntAccessors(c); } return rc; } -cmUiRC_t cmUiCreateCheck( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, bool dflt ) +cmUiRC_t cmUiCreateCheck( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, bool dflt ) { cmUiRC_t rc; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* c; - if((rc = _cmUiCreateCtl(p,panelId,kCheckUiCId,id,label,flags,&c)) == kOkUiRC ) + if((rc = _cmUiCreateCtl(p,appId,panelId,kCheckUiCId,id,label,flags,&c)) == kOkUiRC ) { _cmUiSetIntAccessors(c); - rc = _cmUiSetDriverValueInt(p,c,kValUiFl,dflt); + rc = _cmUiSetDriverValueInt(p,c,kValUiFl | kNoReflectUiFl,dflt); } return rc; } -cmUiRC_t cmUiCreateLabel( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ) +cmUiRC_t cmUiCreateLabel( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ) { cmUiRC_t rc; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* c; - if((rc = _cmUiCreateCtl(p,panelId,kLabelUiCId,id,label,flags,&c)) == kOkUiRC ) + if((rc = _cmUiCreateCtl(p,appId,panelId,kLabelUiCId,id,label,flags,&c)) == kOkUiRC ) _cmUiSetStrAccessors(c); return rc; } -cmUiRC_t cmUiCreateText( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text ) +cmUiRC_t cmUiCreateString( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text ) { cmUiRC_t rc = kOkUiRC; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* c; - if(( rc = _cmUiCreateCtl(p,panelId,kTextUiCId,id,label,flags,&c)) == kOkUiRC ) + if(( rc = _cmUiCreateCtl(p,appId,panelId,kStringUiCId,id,label,flags,&c)) == kOkUiRC ) { _cmUiSetStrAccessors(c); - rc = _cmUiSetDriverValueStr(p,c,kValUiFl,text); + rc = _cmUiSetDriverValueStr(p,c,kValUiFl | kNoReflectUiFl,text); } return rc; } -cmUiRC_t _cmUiCreateNumber( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ) +cmUiRC_t cmUiCreateConsole( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text ) +{ + cmUiRC_t rc = kOkUiRC; + cmUi_t* p = _cmUiHandleToPtr(uiH); + cmUiCtl_t* c; + + if(( rc = _cmUiCreateCtl(p,appId,panelId,kConsoleUiCId,id,label,flags,&c)) == kOkUiRC ) + { + _cmUiSetStrAccessors(c); + + rc = _cmUiSetDriverValueStr(p,c,kValUiFl | kNoReflectUiFl,text); + } + + return rc; +} + +cmUiRC_t _cmUiCreateNumber( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ) { cmUiRC_t rc = kOkUiRC; cmUi_t* p = _cmUiHandleToPtr(uiH); @@ -959,34 +1050,34 @@ cmUiRC_t _cmUiCreateNumber( cmUiH_t uiH, unsigned panelId, unsigned id, const c { if( cmIsFlag(flags,kVertUiFl) ) { - if((rc = _cmUiFindPanel(p,panelId,&pp,true)) != kOkUiRC ) + if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC ) return rc; // if the size of the control was not excplicitly set // then swap width and height if( cmIsNotFlag(pp->flags,kNextWHUiFl) && cmIsNotFlag(pp->flags,kUseRectUiFl) ) - cmUiSetNextWH( uiH, panelId, cmUiH(uiH,panelId), cmUiW(uiH,panelId) ); + cmUiSetNextWH( uiH, appId, panelId, cmUiH(uiH,appId,panelId), cmUiW(uiH,appId,panelId) ); } cid = kSliderUiCId; } - if(( rc = _cmUiCreateCtl(p,panelId,cid,id,label,flags,&c)) == kOkUiRC ) + if(( rc = _cmUiCreateCtl(p,appId,panelId,cid,id,label,flags,&c)) == kOkUiRC ) { cmUiRC_t rc0; _cmUiSetDblAccessors(c); - if((rc0 = _cmUiSetDriverValueDouble(p,c,kMinUiFl,min)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueDouble(p,c,kMinUiFl | kNoReflectUiFl,min)) != kOkUiRC ) rc = rc0; - if((rc0 = _cmUiSetDriverValueDouble(p,c,kMaxUiFl,max)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueDouble(p,c,kMaxUiFl | kNoReflectUiFl,max)) != kOkUiRC ) rc = rc0; - if((rc0 = _cmUiSetDriverValueDouble(p,c,kIncUiFl,incr)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueDouble(p,c,kIncUiFl | kNoReflectUiFl,incr)) != kOkUiRC ) rc = rc0; - if((rc0 = _cmUiSetDriverValueDouble(p,c,kValUiFl,dflt)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueDouble(p,c,kValUiFl | kNoReflectUiFl,dflt)) != kOkUiRC ) rc = rc0; } @@ -994,41 +1085,41 @@ cmUiRC_t _cmUiCreateNumber( cmUiH_t uiH, unsigned panelId, unsigned id, const c return rc; } -cmUiRC_t cmUiCreateNumber( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ) +cmUiRC_t cmUiCreateNumber( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ) { - return _cmUiCreateNumber(uiH,panelId,id,label,flags,min,max,incr,dflt); + return _cmUiCreateNumber(uiH,appId,panelId,id,label,flags,min,max,incr,dflt); } -cmUiRC_t cmUiCreateHSlider( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ) +cmUiRC_t cmUiCreateHSlider( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ) { - return _cmUiCreateNumber(uiH,panelId,id,label,flags | kHorzUiFl, min,max,incr,dflt); + return _cmUiCreateNumber(uiH,appId,panelId,id,label,flags | kHorzUiFl, min,max,incr,dflt); } -cmUiRC_t cmUiCreateVSlider( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ) +cmUiRC_t cmUiCreateVSlider( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ) { - return _cmUiCreateNumber(uiH,panelId,id,label,flags | kVertUiFl, min,max,incr,dflt); + return _cmUiCreateNumber(uiH,appId,panelId,id,label,flags | kVertUiFl, min,max,incr,dflt); } -cmUiRC_t cmUiCreateProgress(cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ) +cmUiRC_t cmUiCreateProgress(cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ) { cmUiRC_t rc = kOkUiRC; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* c; - if(( rc = _cmUiCreateCtl(p,panelId,kProgressUiCId,id,label,flags,&c)) == kOkUiRC ) + if(( rc = _cmUiCreateCtl(p,appId,panelId,kProgressUiCId,id,label,flags,&c)) == kOkUiRC ) { cmUiRC_t rc0; _cmUiSetIntAccessors(c); - if((rc0 = _cmUiSetDriverValueInt(p,c,kMinUiFl,min)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueInt(p,c,kMinUiFl | kNoReflectUiFl,min)) != kOkUiRC ) rc = rc0; - if((rc0 = _cmUiSetDriverValueInt(p,c,kMaxUiFl,max)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueInt(p,c,kMaxUiFl | kNoReflectUiFl,max)) != kOkUiRC ) rc = rc0; - if((rc0 = _cmUiSetDriverValueInt(p,c,kValUiFl,dflt)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueInt(p,c,kValUiFl | kNoReflectUiFl,dflt)) != kOkUiRC ) rc = rc0; } @@ -1036,7 +1127,7 @@ cmUiRC_t cmUiCreateProgress(cmUiH_t uiH, unsigned panelId, unsigned id, const cm return rc; } -cmUiRC_t _cmUiCreateMeter( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt) +cmUiRC_t _cmUiCreateMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt) { cmUiRC_t rc; cmUi_t* p = _cmUiHandleToPtr(uiH); @@ -1045,28 +1136,28 @@ cmUiRC_t _cmUiCreateMeter( cmUiH_t uiH, unsigned panelId, unsigned id, const c if( cmIsFlag(flags,kVertUiFl) ) { - if((rc = _cmUiFindPanel(p,panelId,&pp,true)) != kOkUiRC ) + if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC ) return rc; // if the size of the control has not been explicitely set // then swap height and width for vertical meters. if( cmIsNotFlag(pp->flags,kNextWHUiFl) && cmIsNotFlag(pp->flags,kUseRectUiFl) ) - cmUiSetNextWH( uiH, panelId, cmUiH(uiH,panelId), cmUiW(uiH,panelId) ); + cmUiSetNextWH( uiH, appId, panelId, cmUiH(uiH,appId,panelId), cmUiW(uiH,appId,panelId) ); } - if((rc = _cmUiCreateCtl(p,panelId,kMeterUiCId,id,label,flags,&c)) == kOkUiRC ) + if((rc = _cmUiCreateCtl(p,appId,panelId,kMeterUiCId,id,label,flags,&c)) == kOkUiRC ) { cmUiRC_t rc0; _cmUiSetIntAccessors(c); - if((rc0 = _cmUiSetDriverValueInt(p,c,kMinUiFl,min)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueInt(p,c,kMinUiFl | kNoReflectUiFl,min)) != kOkUiRC ) rc = rc0; - if((rc0 = _cmUiSetDriverValueInt(p,c,kMaxUiFl,max)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueInt(p,c,kMaxUiFl | kNoReflectUiFl,max)) != kOkUiRC ) rc = rc0; - if((rc0 = _cmUiSetDriverValueInt(p,c,kValUiFl,dflt)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueInt(p,c,kValUiFl | kNoReflectUiFl,dflt)) != kOkUiRC ) rc = rc0; } @@ -1074,23 +1165,23 @@ cmUiRC_t _cmUiCreateMeter( cmUiH_t uiH, unsigned panelId, unsigned id, const c } -cmUiRC_t cmUiCreateHMeter( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ) +cmUiRC_t cmUiCreateHMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ) { - return _cmUiCreateMeter(uiH,panelId,id,label,flags | kHorzUiFl,min,max,dflt); + return _cmUiCreateMeter(uiH,appId,panelId,id,label,flags | kHorzUiFl,min,max,dflt); } -cmUiRC_t cmUiCreateVMeter( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ) +cmUiRC_t cmUiCreateVMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ) { - return _cmUiCreateMeter(uiH,panelId,id,label,flags | kVertUiFl,min,max,dflt); + return _cmUiCreateMeter(uiH,appId,panelId,id,label,flags | kVertUiFl,min,max,dflt); } -cmUiRC_t cmUiCreateFileBtn(cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir, const cmChar_t* patStr ) +cmUiRC_t cmUiCreateFileBtn(cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir, const cmChar_t* patStr ) { cmUiRC_t rc = kOkUiRC; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* c; - if(( rc = _cmUiCreateCtl(p,panelId,kFilenameUiCId,id,label,flags,&c)) == kOkUiRC ) + if(( rc = _cmUiCreateCtl(p,appId,panelId,kFilenameUiCId,id,label,flags,&c)) == kOkUiRC ) { cmUiRC_t rc0; @@ -1098,26 +1189,26 @@ cmUiRC_t cmUiCreateFileBtn(cmUiH_t uiH, unsigned panelId, unsigned id, const cmC if( dfltDir != NULL ) { - if((rc0 = _cmUiSetDriverValueStr(p,c,kValUiFl,dfltDir)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueStr(p,c,kFnDirUiFl | kNoReflectUiFl,dfltDir)) != kOkUiRC ) rc = rc0; } if( patStr != NULL ) { - if((rc0 = _cmUiSetDriverValueStr(p,c,kValUiFl,patStr)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueStr(p,c,kFnPatUiFl | kNoReflectUiFl,patStr)) != kOkUiRC ) rc = rc0; } } return rc; } -cmUiRC_t cmUiCreateDirBtn( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir ) +cmUiRC_t cmUiCreateDirBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir ) { cmUiRC_t rc = kOkUiRC; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* c; - if(( rc = _cmUiCreateCtl(p,panelId,kDirUiCId,id,label,flags,&c)) == kOkUiRC ) + if(( rc = _cmUiCreateCtl(p,appId,panelId,kDirUiCId,id,label,flags,&c)) == kOkUiRC ) { cmUiRC_t rc0; @@ -1125,145 +1216,271 @@ cmUiRC_t cmUiCreateDirBtn( cmUiH_t uiH, unsigned panelId, unsigned id, const cm if( dfltDir != NULL ) { - if((rc0 = _cmUiSetDriverValueStr(p,c,kValUiFl,dfltDir)) != kOkUiRC ) + if((rc0 = _cmUiSetDriverValueStr(p,c,kValUiFl | kNoReflectUiFl,dfltDir)) != kOkUiRC ) rc = rc0; } } return rc; } -cmUiRC_t cmUiCreateMenuBtn( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ) +cmUiRC_t cmUiCreateMenuBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ) { cmUiRC_t rc; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* c; - if((rc = _cmUiCreateCtl(p,panelId,kMenuBtnUiCId,id,label,flags,&c)) == kOkUiRC ) + if((rc = _cmUiCreateCtl(p,appId,panelId,kMenuBtnUiCId,id,label,flags,&c)) == kOkUiRC ) _cmUiSetIntAccessors(c); return rc; } -cmUiRC_t cmUiCreateMenuBtnV(cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* label0, unsigned id0, va_list vl ) +cmUiRC_t cmUiCreateMenuBtnV(cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* label0, unsigned id0, va_list vl ) { cmUiRC_t rc = kOkUiRC; // TODO: return rc; } -cmUiRC_t cmUiCreateMenuBtnA(cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* label0, unsigned id0, ... ) +cmUiRC_t cmUiCreateMenuBtnA(cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* label0, unsigned id0, ... ) { va_list vl; va_start(vl,id0); - cmUiRC_t rc = cmUiCreateMenuBtnV(uiH,panelId,id,label,flags,label0,id0,vl); + cmUiRC_t rc = cmUiCreateMenuBtnV(uiH,appId,panelId,id,label,flags,label0,id0,vl); va_end(vl); return rc; } -cmUiRC_t cmUiCreateMenuBtnJson(cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmJsonNode_t* root, const cmChar_t* memberLabel ) +cmUiRC_t cmUiCreateMenuBtnJson(cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmJsonNode_t* root, const cmChar_t* memberLabel ) { cmUiRC_t rc = kOkUiRC; // TODO: return rc; } -cmUiRC_t cmUiCreateList(cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt ) +cmUiRC_t cmUiCreateList(cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiRC_t rc; cmUiCtl_t* c; cmUiPanel_t* pp; - if((rc = _cmUiFindPanel(p,panelId,&pp,true)) != kOkUiRC ) + if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC ) return rc; if( cmIsNotFlag(pp->flags,kNextWHUiFl) ) - cmUiSetNextWH( uiH, panelId, cmUiNextW(uiH,panelId), cmUiH(uiH,panelId) * visibleRowCnt ); + cmUiSetNextWH( uiH, appId, panelId, cmUiNextW(uiH,appId,panelId), cmUiH(uiH,appId,panelId) * visibleRowCnt ); - if((rc = _cmUiCreateCtl(p,panelId,kListUiCId,id,label,flags,&c)) == kOkUiRC ) + if((rc = _cmUiCreateCtl(p,appId,panelId,kListUiCId,id,label,flags,&c)) == kOkUiRC ) _cmUiSetIntAccessors(c); return rc; } -cmUiRC_t cmUiCreateListV( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, va_list vl ) +cmUiRC_t cmUiCreateListV( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, va_list vl ) { cmUiRC_t rc = kOkUiRC; // TODO: return rc; } -cmUiRC_t cmUiCreateListA( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, ... ) +cmUiRC_t cmUiCreateListA( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, ... ) { va_list vl; va_start(vl,id0); - cmUiRC_t rc = cmUiCreateListV(uiH,panelId,id,label,flags,visibleRowCnt,label0,id0,vl); + cmUiRC_t rc = cmUiCreateListV(uiH,appId,panelId,id,label,flags,visibleRowCnt,label0,id0,vl); va_end(vl); return rc; } -cmUiRC_t cmUiCreateListJson( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmJsonNode_t* root, const cmChar_t* memberLabel ) +cmUiRC_t cmUiCreateListJson( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmJsonNode_t* root, const cmChar_t* memberLabel ) { cmUiRC_t rc = kOkUiRC; // TODO: return rc; } -cmUiRC_t cmUiAppendListEle( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* text, unsigned eleId ) +cmUiRC_t cmUiAppendListEle( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* text, unsigned eleId ) { cmUiRC_t rc = kOkUiRC; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* ctl = NULL; - if((rc = _cmUiFindCtl(p,id,&ctl,true)) != kOkUiRC ) + if((rc = _cmUiFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) return rc; if( ctl->cId != kListUiCId && ctl->cId != kMenuBtnUiCId ) return cmErrMsg(&p->err,kInvalidCtlOpUiRC,"List elements may only be set on 'list' and 'menu button' controls."); - if( cmArrayIsValid(ctl->idArrH) ) - cmArrayPush(ctl->idArrH,&eleId,1); + + + // set the local value + cmUiListEle_t ele; + ele.id = eleId; + ele.label = cmMemAllocStr(text); + cmArrayPush(ctl->idArrH,&ele,1); return _cmUiSetDriverValueIntAndStr(p,ctl,kAppendUiFl,eleId,text); } -cmUiRC_t cmUiDestroyCtl( cmUiH_t uiH, unsigned id ) +cmUiRC_t cmUiClearList( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id ) +{ + cmUiRC_t rc = kOkUiRC; + cmUi_t* p = _cmUiHandleToPtr(uiH); + cmUiCtl_t* ctl = NULL; + + if((rc = _cmUiFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) + return rc; + + // verify that this is a list or menu btn + if( ctl->cId != kListUiCId && ctl->cId != kMenuBtnUiCId ) + return cmErrMsg(&p->err,kInvalidCtlOpUiRC,"List elements may only be cleared on 'list' and 'menu button' controls."); + + // call the driver + if((rc = _cmUiSetDriverValueInt(p, ctl, kClearUiFl, 0 )) != kOkUiRC ) + return rc; + + // clear the ctl's id array + if( cmArrayIsValid(ctl->idArrH) ) + { + _cmUiReleaseListEles(ctl); + + cmArrayClear(ctl->idArrH,false); + } + + return rc; +} + +cmUiRC_t cmUiEnableCtl( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, bool enableFl ) { cmUiRC_t rc = kOkUiRC; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* ctl = NULL; - if((rc = _cmUiFindCtl(p,id,&ctl,true)) == kOkUiRC ) + + if((rc = _cmUiFindCtl(p,appId,id,&ctl,true)) == kOkUiRC ) + { + ctl->arg.ival = enableFl ? 1 : 0; + + rc = _cmUiCallDriver(p, kEnableDId, ctl, kIvalUiFl ); + } + + return rc; +} + +cmUiRC_t cmUiEnableAllExceptV( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, va_list vl ) +{ + va_list vl0; + cmUiRC_t rc = kOkUiRC; + cmUi_t* p = _cmUiHandleToPtr(uiH); + unsigned n = 0; + cmUiApp_t* ap = NULL; + unsigned i,j; + + // get a count of exception id's + va_copy(vl0,vl); + while( va_arg(vl0,unsigned) != cmInvalidId ) + ++n; + va_end(vl0); + + if( n == 0 ) + return rc; + + // alloc array to hold exception id's + unsigned id[n]; + + // store the exception id's + for(i=0; ictlArrH); + + // for each control + for(i=0; ictlArrH,i))!=NULL && ctl->panelId == panelId && ctl->usrId != panelId ) + { + bool exceptFl = false; + + // check if this control is in the except list + for(j=0; jarg.ival = enableFl ? 1 : 0; + + cmUiRC_t rc0; + if((rc0 = _cmUiCallDriver(p, kEnableDId, ctl, kIvalUiFl )) != kOkUiRC ) + rc = rc0; + + } + } + } + + + return rc; +} + + +cmUiRC_t cmUiEnableAllExcept( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, ... ) +{ + va_list vl; + va_start(vl,enableFl); + cmUiRC_t rc = cmUiEnableAllExceptV(uiH,appId,panelId,enableFl,vl); + va_end(vl); + return rc; +} + +cmUiRC_t cmUiDestroyCtl( cmUiH_t uiH, unsigned appId, unsigned id ) +{ + cmUiRC_t rc = kOkUiRC; + cmUi_t* p = _cmUiHandleToPtr(uiH); + cmUiCtl_t* ctl = NULL; + + if((rc = _cmUiFindCtl(p,appId,id,&ctl,true)) == kOkUiRC ) { if( ctl->cId == kPanelUiCId ) - _cmUiDestroyPanel(p,ctl->usrId); + _cmUiDestroyPanel(p,appId,ctl->usrId); else - rc = _cmUiDestroyCtl(p,ctl); + rc = _cmUiDestroyCtl(p,ctl,true); } return rc; } -bool cmUiCtlExists( cmUiH_t uiH, unsigned panelId, unsigned id ) +bool cmUiCtlExists( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id ) { cmUi_t* p = _cmUiHandleToPtr(uiH); if( panelId == id ) { cmUiPanel_t* pp=NULL; - return _cmUiFindPanel(p, panelId, &pp, false ) == kOkUiRC; + return _cmUiFindPanel(p, appId,panelId, &pp, false ) == kOkUiRC; } cmUiCtl_t* ctl=NULL; - return _cmUiFindCtl(p,id,&ctl,false) == kOkUiRC; + return _cmUiFindCtl(p,appId,id,&ctl,false) == kOkUiRC; } -cmUiRC_t cmUiClearPanel( cmUiH_t uiH, unsigned panelId ) +cmUiRC_t cmUiClearPanel( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUiRC_t rc = kOkUiRC; cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp = NULL; // get the panel recd ptr - if((rc = _cmUiFindPanel(p,panelId,&pp,true)) != kOkUiRC ) + if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC ) return rc; cmUiApp_t* ap = pp->appPtr; @@ -1274,20 +1491,23 @@ cmUiRC_t cmUiClearPanel( cmUiH_t uiH, unsigned panelId ) // Destroy all controls that belong to this panel. for(i=0; ipanelId == panelId && ctl->usrId != panelId) - if((rc0 = _cmUiDestroyCtl(p,ctl)) != kOkUiRC ) + if( _cmUiFindCtl(p,appId,i,&ctl,false) == kOkUiRC && ctl != NULL && ctl->panelId == panelId && ctl->usrId != panelId) + if((rc0 = _cmUiDestroyCtl(p,ctl,true)) != kOkUiRC ) rc = rc0; + // restore the layout variables to their default values. + _cmUiPanelSetDefaultValues(pp); + return rc; } -cmUiRC_t cmUiNextRect( cmUiH_t uiH, unsigned panelId, int x, int y, int w, int h ) +cmUiRC_t cmUiNextRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int x, int y, int w, int h ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; cmUiRC_t rc; - - if((rc = _cmUiFindPanel(p, panelId, &pp, true)) != kOkUiRC ) + + if((rc = _cmUiFindPanel(p, appId, panelId, &pp, true)) != kOkUiRC ) return rc; pp->rect.x = x; @@ -1299,14 +1519,14 @@ cmUiRC_t cmUiNextRect( cmUiH_t uiH, unsigned panelId, int x, int y, int w, in return rc; } -cmUiRC_t cmUiPrevRect( cmUiH_t uiH, unsigned panelId, int* xRef, int* yRef, int* wRef, int* hRef ) +cmUiRC_t cmUiPrevRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int* xRef, int* yRef, int* wRef, int* hRef ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; cmUiRC_t rc; - - if((rc = _cmUiFindPanel(p, panelId, &pp, true)) != kOkUiRC ) + + if((rc = _cmUiFindPanel(p, appId, panelId, &pp, true)) != kOkUiRC ) return rc; if( xRef != NULL ) @@ -1324,23 +1544,24 @@ cmUiRC_t cmUiPrevRect( cmUiH_t uiH, unsigned panelId, int* xRef, int* yRef, return rc; } -bool cmUiFillRows( cmUiH_t uiH, unsigned panelId ) +bool cmUiFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if( _cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if( _cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return false; return cmIsFlag(pp->flags,kFillRowsUiFl); } -bool cmUiSetFillRows( cmUiH_t uiH, unsigned panelId, bool enableFl ) +bool cmUiSetFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if( _cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if( _cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return false; bool retFl = cmIsFlag(pp->flags,kFillRowsUiFl); @@ -1350,53 +1571,53 @@ bool cmUiSetFillRows( cmUiH_t uiH, unsigned panelId, bool enableFl ) return retFl; } -void cmUiPlaceRight( cmUiH_t uiH, unsigned panelId ) +void cmUiPlaceRight( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return; pp->flags = cmClrFlag(pp->flags,kPlaceBelowUiFl); pp->flags = cmSetFlag(pp->flags,kPlaceRightUiFl); } -void cmUiPlaceBelow( cmUiH_t uiH, unsigned panelId ) +void cmUiPlaceBelow( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return; pp->flags = cmClrFlag(pp->flags,kPlaceRightUiFl); pp->flags = cmSetFlag(pp->flags,kPlaceBelowUiFl); } -void cmUiNewLine( cmUiH_t uiH, unsigned panelId ) +void cmUiNewLine( cmUiH_t uiH, unsigned appId, unsigned panelId ) { - cmUiSetBaseRow( uiH, panelId, cmUiPrevB(uiH,panelId) + cmUiNextVBorder(uiH,panelId) ); - cmUiSetBaseCol( uiH, panelId, cmUiBaseCol(uiH,panelId)); + cmUiSetBaseRow( uiH, appId, panelId, cmUiPrevB(uiH,appId,panelId) + cmUiNextVBorder(uiH,appId,panelId) ); + cmUiSetBaseCol( uiH, appId, panelId, cmUiBaseCol(uiH,appId,panelId)); } -int cmUiBaseCol( cmUiH_t uiH, unsigned panelId ) +int cmUiBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->baseCol; } -int cmUiSetBaseCol( cmUiH_t uiH, unsigned panelId, int x ) +int cmUiSetBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId, int x ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if( _cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if( _cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; int bc = pp->baseCol; @@ -1405,24 +1626,24 @@ int cmUiSetBaseCol( cmUiH_t uiH, unsigned panelId, int x ) return bc; } -int cmUiBaseRow( cmUiH_t uiH, unsigned panelId ) +int cmUiBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) - return -1; + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) + return -1; return pp->baseRow; } -int cmUiSetBaseRow( cmUiH_t uiH, unsigned panelId, int y ) +int cmUiSetBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId, int y ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; cmUiRC_t rc; - - if((rc = _cmUiFindPanel(p, panelId, &pp, true)) != kOkUiRC ) + + if((rc = _cmUiFindPanel(p, appId, panelId, &pp, true)) != kOkUiRC ) return -1; int br = pp->baseRow; @@ -1432,34 +1653,34 @@ int cmUiSetBaseRow( cmUiH_t uiH, unsigned panelId, int y ) -int cmUiW( cmUiH_t uiH, unsigned panelId ) +int cmUiW( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->dfltW; } -int cmUiH( cmUiH_t uiH, unsigned panelId ) +int cmUiH( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->dfltH; } -int cmUiSetW( cmUiH_t uiH, unsigned panelId, int w ) +int cmUiSetW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; int rv = pp->dfltW; @@ -1468,12 +1689,12 @@ int cmUiSetW( cmUiH_t uiH, unsigned panelId, int w ) return rv; } -int cmUiSetH( cmUiH_t uiH, unsigned panelId, int h ) +int cmUiSetH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; int rv = pp->dfltH; @@ -1482,55 +1703,50 @@ int cmUiSetH( cmUiH_t uiH, unsigned panelId, int h ) return rv; } -void cmUiSetWH( cmUiH_t uiH, unsigned panelId, int w, int h ) +void cmUiSetWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h ) { - cmUi_t* p = _cmUiHandleToPtr(uiH); - cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) - return; - - pp->dfltW = w; - pp->dfltH = h; - pp->nextW = w; - pp->nextH = h; - + cmUiSetW( uiH, appId, panelId, w ); + cmUiSetH( uiH, appId, panelId, h ); } -int cmUiNextW( cmUiH_t uiH, unsigned panelId ) +int cmUiNextW( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->nextW; } -int cmUiNextH( cmUiH_t uiH, unsigned panelId ) +int cmUiNextH( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->nextH; } -void cmUiSetNextW( cmUiH_t uiH, unsigned panelId, int w ) -{ return cmUiSetNextWH( uiH, panelId, w, cmUiNextH(uiH,panelId)); } +void cmUiSetNextW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w ) +{ + return cmUiSetNextWH( uiH, appId, panelId, w, cmUiNextH(uiH,appId,panelId)); +} -void cmUiSetNextH( cmUiH_t uiH, unsigned panelId, int h ) -{ return cmUiSetNextWH( uiH, panelId, cmUiNextW(uiH,panelId), h); } +void cmUiSetNextH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h ) +{ + return cmUiSetNextWH( uiH, appId, panelId, cmUiNextW(uiH,appId,panelId), h); +} -void cmUiSetNextWH( cmUiH_t uiH, unsigned panelId, int w, int h ) +void cmUiSetNextWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return; pp->nextW = w; @@ -1538,34 +1754,33 @@ void cmUiSetNextWH( cmUiH_t uiH, unsigned panelId, int w, int h ) pp->flags = cmSetFlag(pp->flags,kNextWHUiFl); } -int cmUiHBorder( cmUiH_t uiH, unsigned panelId ) +int cmUiHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->dfltHBorder; } -int cmUiVBorder( cmUiH_t uiH, unsigned panelId ) +int cmUiVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->dfltVBorder; } -int cmUiSetHBorder( cmUiH_t uiH, unsigned panelId, int w ) +int cmUiSetHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; int rv = pp->dfltHBorder; @@ -1573,12 +1788,12 @@ int cmUiSetHBorder( cmUiH_t uiH, unsigned panelId, int w ) return rv; } -int cmUiSetVBorder( cmUiH_t uiH, unsigned panelId, int h ) +int cmUiSetVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; int rv = pp->dfltVBorder; @@ -1586,34 +1801,34 @@ int cmUiSetVBorder( cmUiH_t uiH, unsigned panelId, int h ) return rv; } -int cmUiNextHBorder( cmUiH_t uiH, unsigned panelId ) +int cmUiNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->nextHBorder; } -int cmUiNextVBorder( cmUiH_t uiH, unsigned panelId ) +int cmUiNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->nextVBorder; } -int cmUiSetNextHBorder( cmUiH_t uiH, unsigned panelId, int w ) +int cmUiSetNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; int rv = pp->nextHBorder; @@ -1621,12 +1836,12 @@ int cmUiSetNextHBorder( cmUiH_t uiH, unsigned panelId, int w ) return rv; } -int cmUiSetNextVBorder( cmUiH_t uiH, unsigned panelId, int h ) +int cmUiSetNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; int rv = pp->nextVBorder; @@ -1634,171 +1849,254 @@ int cmUiSetNextVBorder( cmUiH_t uiH, unsigned panelId, int h ) return rv; } -int cmUiPrevL( cmUiH_t uiH, unsigned panelId ) +int cmUiPrevL( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->prevRect.x; } -int cmUiPrevT( cmUiH_t uiH, unsigned panelId ) +int cmUiPrevT( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->prevRect.y; } -int cmUiPrevR( cmUiH_t uiH, unsigned panelId ) +int cmUiPrevR( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->prevRect.x + pp->prevRect.w; } -int cmUiPrevB( cmUiH_t uiH, unsigned panelId ) +int cmUiPrevB( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->prevRect.y + pp->prevRect.h; } -int cmUiPrevW( cmUiH_t uiH, unsigned panelId ) +int cmUiPrevW( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->prevRect.w; } -int cmUiPrevH( cmUiH_t uiH, unsigned panelId ) +int cmUiPrevH( cmUiH_t uiH, unsigned appId, unsigned panelId ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiPanel_t* pp; - if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC ) + if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC ) return -1; return pp->prevRect.h; } - - -cmUiRC_t cmUiSetInt( cmUiH_t uiH, unsigned id, int v ) +cmUiRC_t cmUiSetInt( cmUiH_t uiH, unsigned appId, unsigned id, int v ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* ctl; cmUiRC_t rc; - - if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC ) + + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) return rc; return _cmUiSetDriverValueInt(p,ctl,kValUiFl,v); } -cmUiRC_t cmUiSetUInt( cmUiH_t uiH, unsigned id, unsigned v ) +cmUiRC_t cmUiSetUInt( cmUiH_t uiH, unsigned appId, unsigned id, unsigned v ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* ctl; cmUiRC_t rc; - if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC ) + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) return rc; return _cmUiSetDriverValueInt(p,ctl,kValUiFl,v); } -cmUiRC_t cmUiSetDouble( cmUiH_t uiH, unsigned id, double v ) +cmUiRC_t cmUiSetDouble( cmUiH_t uiH, unsigned appId, unsigned id, double v ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* ctl; cmUiRC_t rc; - if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC ) + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) return rc; return _cmUiSetDriverValueDouble(p,ctl,kValUiFl,v); } -cmUiRC_t cmUiSetString( cmUiH_t uiH, unsigned id, const cmChar_t* v ) +cmUiRC_t cmUiSetString( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* v ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* ctl; cmUiRC_t rc; - if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC ) + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) return rc; return _cmUiSetDriverValueStr(p,ctl,kValUiFl,v); } -int cmUiInt( cmUiH_t uiH, unsigned id ) +cmUiRC_t cmUiSetVPrintf( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, va_list vl ) +{ + va_list vl1; + va_copy(vl1,vl); + unsigned n = vsnprintf(NULL,0,fmt,vl1); + va_end(vl1); + + unsigned sbufN = 2047; + cmChar_t sbuf[ sbufN+1 ]; + cmChar_t* b; + unsigned bn; + cmChar_t* abuf = NULL; + + if( n >= sbufN ) + { + bn = n + 1; + abuf = cmMemAlloc(cmChar_t,bn); + b = abuf; + } + else + { + bn = sbufN; + b = sbuf; + } + + vsnprintf(b,bn,fmt,vl); + cmUiRC_t rc = cmUiSetString(uiH,appId,id,b); + cmMemFree(abuf); + return rc; +} + + +cmUiRC_t cmUiSetPrintf( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, ... ) +{ + va_list vl; + va_start(vl,fmt); + cmUiRC_t rc = cmUiSetVPrintf(uiH,appId,id,fmt,vl); + va_end(vl); + return rc; +} + + +int cmUiInt(cmUiH_t uiH, unsigned appId, unsigned id ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* ctl; cmUiRC_t rc; - - if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC ) + + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) return 0; return ctl->getInt(ctl); } -unsigned cmUiUInt( cmUiH_t uiH, unsigned id ) +unsigned cmUiUInt( cmUiH_t uiH, unsigned appId, unsigned id ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* ctl; cmUiRC_t rc; - - if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC ) + + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) return 0; return ctl->getInt(ctl); } -double cmUiDouble( cmUiH_t uiH, unsigned id ) +double cmUiDouble( cmUiH_t uiH, unsigned appId, unsigned id ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* ctl; cmUiRC_t rc; - if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC ) + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) return 0; return ctl->getDbl(ctl); } -const cmChar_t* cmUiString( cmUiH_t uiH, unsigned id ) +const cmChar_t* cmUiString( cmUiH_t uiH, unsigned appId, unsigned id ) +{ + cmUi_t* p = _cmUiHandleToPtr(uiH); + cmUiCtl_t* ctl; + cmUiRC_t rc; + + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) + return 0; + + return ctl->getStr(ctl); +} + +unsigned cmUiListEleCount( cmUiH_t uiH, unsigned appId, unsigned id ) +{ + cmUi_t* p = _cmUiHandleToPtr(uiH); + cmUiCtl_t* ctl; + cmUiRC_t rc; + + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) + return 0; + + return cmArrayCount( ctl->idArrH ); +} + +unsigned cmUiListEleId( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index ) +{ + cmUi_t* p = _cmUiHandleToPtr(uiH); + cmUiCtl_t* ctl; + cmUiRC_t rc; + + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) + return 0; + + if( !cmArrayIsValid( ctl->idArrH ) || index >= cmArrayCount( ctl->idArrH) ) + return cmInvalidId; + + return cmArrayPtr(cmUiListEle_t, ctl->idArrH, index )->id; +} + +const cmChar_t* cmUiListEleLabel( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index ) { cmUi_t* p = _cmUiHandleToPtr(uiH); cmUiCtl_t* ctl; cmUiRC_t rc; - if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC ) + if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC ) return 0; - return ctl->getStr(ctl); + if( !cmArrayIsValid( ctl->idArrH ) || index >= cmArrayCount( ctl->idArrH) ) + return NULL; + + return cmArrayPtr(cmUiListEle_t, ctl->idArrH, index )->label; } + cmUiRC_t cmUiLastRC( cmUiH_t uiH ) { cmUi_t* p = _cmUiHandleToPtr(uiH); diff --git a/cmUi.h b/cmUi.h index 487139f..b1a4251 100644 --- a/cmUi.h +++ b/cmUi.h @@ -61,8 +61,13 @@ extern "C" { and all callbacks from the cmUi to the master app. use the cmUiDriverArg_t structure + 3) The panel tabs act like radio buttons. When a tab is + selected the clicked tab generates one event for each + tab (cId=kPanelUiCId usrId=panelId) w/ ival=1 for the + selected tab and ival=0 for all other tabs. + TODO: - 0) Remove the 'cbArg' from the cmUiDriverArg_t record and + 0) [DONE] Remove the 'cbArg' from the cmUiDriverArg_t record and pass it as a separate paramenter in the cmUiDriverFunc_t calls. 1) The controls should be based on a multilevel tree model @@ -93,9 +98,9 @@ extern "C" { Many of the fields are not use for event callbacks. Which fields are used under which circumstances should be documented. This would allow decreasing the size - of the record during serialization.7 + of the record during serialization. - 6) Write a serialization/deserialization routines for cmUiDriverArg_t. + 6) [DONE] Write a serialization/deserialization routines for cmUiDriverArg_t. unsigned cmUiDriverArgSerialBufByteCount(const cmUiDriverArg_t* a); cmUiRC_t cmUiDriverArgSerialize( const cmUiDriverArg_t* a, char* buf, bufByteCnt ); cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, const char* buf, bufByteCnt ); @@ -153,7 +158,11 @@ extern "C" { // Automatically sets and restores the ambient appId. // In a plug-in context this function is generally called // just prior a instantiating a plug-in object. - cmUiRC_t cmUiCreateApp( cmUiH_t uiH, unsigned appId ); + cmUiRC_t cmUiCreateApp( cmUiH_t uiH, unsigned appId, unsigned asSubIdx ); + + // Return true if 'appId' is active. + bool cmUiAppIsActive( cmUiH_t uiH, unsigned appId ); + // Notify the cmUi manager that the resources associated // with a client application can be released. @@ -170,7 +179,10 @@ extern "C" { // 'appId' an ambient parameter the User API calls are slightly // simplified because they do not have to include it in each of the // function calls. - cmUiRC_t cmUiSetAppId( cmUiH_t uiH, unsigned appId ); + //cmUiRC_t cmUiSetAppId( cmUiH_t uiH, unsigned appId ); + //unsigned cmUiAppId( cmUiH_t uiH ); + + unsigned cmUiAppIdToAsSubIndex( cmUiH_t uiH, unsigned appId ); // Return the count of app's. unsigned cmUiAppCount( cmUiH_t uiH ); @@ -185,46 +197,59 @@ extern "C" { // Client Application API // + // See above note on panel tabs acting like radio buttons. + cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned appId, unsigned newPanelId, const cmChar_t* label, unsigned flags ); - cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned newPanelId, const cmChar_t* label ); - - cmUiRC_t cmUiCreateBtn( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ); - cmUiRC_t cmUiCreateCheck( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, bool dflt ); - cmUiRC_t cmUiCreateLabel( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ); - cmUiRC_t cmUiCreateText( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text ); - cmUiRC_t cmUiCreateNumber( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ); - cmUiRC_t cmUiCreateHSlider( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ); - cmUiRC_t cmUiCreateVSlider( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ); - cmUiRC_t cmUiCreateProgress( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ); - cmUiRC_t cmUiCreateHMeter( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ); - cmUiRC_t cmUiCreateVMeter( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ); - cmUiRC_t cmUiCreateFileBtn( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir, const cmChar_t* patStr ); - cmUiRC_t cmUiCreateDirBtn( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir ); - cmUiRC_t cmUiCreateMenuBtn( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ); - cmUiRC_t cmUiCreateMenuBtnV( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmChar_t* label0, unsigned id0, va_list vl ); - cmUiRC_t cmUiCreateMenuBtnA( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmChar_t* label0, unsigned id0, ... ); - cmUiRC_t cmUiCreateMenuBtnJson( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmJsonNode_t* root, const cmChar_t* memberLabel ); - cmUiRC_t cmUiCreateList( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt ); - cmUiRC_t cmUiCreateListV( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, va_list vl ); - cmUiRC_t cmUiCreateListA( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, ... ); - cmUiRC_t cmUiCreateListJson( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmJsonNode_t* root, const cmChar_t* memberLabel ); + cmUiRC_t cmUiCreateBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ); + cmUiRC_t cmUiCreateCheck( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, bool dflt ); + cmUiRC_t cmUiCreateLabel( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ); + cmUiRC_t cmUiCreateString( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text ); + cmUiRC_t cmUiCreateConsole( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text ); + cmUiRC_t cmUiCreateNumber( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ); + cmUiRC_t cmUiCreateHSlider( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ); + cmUiRC_t cmUiCreateVSlider( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, double min, double max, double incr, double dflt ); + cmUiRC_t cmUiCreateProgress( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ); + cmUiRC_t cmUiCreateHMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ); + cmUiRC_t cmUiCreateVMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt ); + cmUiRC_t cmUiCreateFileBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir, const cmChar_t* patStr ); + cmUiRC_t cmUiCreateDirBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir ); + cmUiRC_t cmUiCreateMenuBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags ); + cmUiRC_t cmUiCreateMenuBtnV( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmChar_t* label0, unsigned id0, va_list vl ); + cmUiRC_t cmUiCreateMenuBtnA( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmChar_t* label0, unsigned id0, ... ); + cmUiRC_t cmUiCreateMenuBtnJson( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmJsonNode_t* root, const cmChar_t* memberLabel ); + cmUiRC_t cmUiCreateList( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt ); + cmUiRC_t cmUiCreateListV( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, va_list vl ); + cmUiRC_t cmUiCreateListA( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmChar_t* label0, unsigned id0, ... ); + cmUiRC_t cmUiCreateListJson( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt, const cmJsonNode_t* root, const cmChar_t* memberLabel ); // If 'id' identifies a 'list' control use tabs as column separators. - cmUiRC_t cmUiAppendListEle( cmUiH_t uiH, unsigned panelId, unsigned id, const cmChar_t* text, unsigned eleId ); + cmUiRC_t cmUiAppendListEle( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* text, unsigned eleId ); + + // Remove all the elements of a list control. + cmUiRC_t cmUiClearList( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id ); + + // Enable/Disable a control + cmUiRC_t cmUiEnableCtl( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, bool enableFl ); + + // Enable/disable all controls on a panel except those included in the var args list. + // Terminate the var args list with cmInvalidId. + cmUiRC_t cmUiEnableAllExceptV( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, va_list vl ); + cmUiRC_t cmUiEnableAllExcept( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, ... ); // If 'id' identifies a panel then all control belonging to the panel // will also be destroyed. - cmUiRC_t cmUiDestroyCtl( cmUiH_t uiH, unsigned id ); + cmUiRC_t cmUiDestroyCtl( cmUiH_t uiH, unsigned appId, unsigned id ); // Returns true if the control exists. // For panels set id=panelId. - bool cmUiCtlExists( cmUiH_t uiH, unsigned panelId, unsigned id ); + //bool cmUiCtlExists( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id ); // Destroy all the controls in a panel. - cmUiRC_t cmUiClearPanel( cmUiH_t uiH, unsigned panelId ); - + cmUiRC_t cmUiClearPanel( cmUiH_t uiH, unsigned appId, unsigned panelId ); + //------------------------------------------------------------------------------------------ // Location: + // 1) If a 'next rect' is set the control will be placed according to it. // 2) If cmUiSetBaseCol() was set then the control will be placed at the // base col and base row. @@ -242,29 +267,29 @@ extern "C" { // Get/Set the fill directions. If the 'fill columns' flag is enabled // then the next control is placed below the previous control otherwise // the next control is placed to the right of the next control. - bool cmUiFillRows( cmUiH_t uiH, unsigned panelId ); - bool cmUiSetFillRows( cmUiH_t uiH, unsigned panelId, bool enableFl ); + bool cmUiFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId ); + bool cmUiSetFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl ); // Place the next control to the right/below of the previous ctl. // These flags override the current fill row/col setting. // Note that 'place right' and 'place below' are mutually // exclusive. Enabling one disables the other. - void cmUiPlaceRight( cmUiH_t uiH, unsigned panelId ); - void cmUiPlaceBelow( cmUiH_t uiH, unsigned panelId ); + void cmUiPlaceRight( cmUiH_t uiH, unsigned appId, unsigned panelId ); + void cmUiPlaceBelow( cmUiH_t uiH, unsigned appId, unsigned panelId ); // Place the next control at the base column below the previous ctl. - void cmUiNewLine( cmUiH_t uiH, unsigned panelId ); + void cmUiNewLine( cmUiH_t uiH, unsigned appId, unsigned panelId ); // Set/Get current base col and return previous value. Place the next // control on the base row. - int cmUiBaseCol( cmUiH_t uiH, unsigned panelId ); - int cmUiSetBaseCol( cmUiH_t uiH, unsigned panelId, int x ); + int cmUiBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiSetBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId, int x ); // Set/Get current base row and return previous value. - int cmUiBaseRow( cmUiH_t uiH, unsigned panelId ); - int cmUiSetBaseRow( cmUiH_t uiH, unsigned panelId, int y ); + int cmUiBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiSetBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId, int y ); // Size: // 1) If a 'next rect' is set the control will be placed according @@ -277,81 +302,80 @@ extern "C" { // Get/Set the default control width and height. // Set returns previous value. - int cmUiW( cmUiH_t uiH, unsigned panelId ); - int cmUiH( cmUiH_t uiH, unsigned panelId ); - int cmUiSetW( cmUiH_t uiH, unsigned panelId, int w ); - int cmUiSetH( cmUiH_t uiH, unsigned panelId, int h ); - void cmUiSetWH( cmUiH_t uiH, unsigned panelId, int w, int h ); + int cmUiW( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiH( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiSetW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w ); + int cmUiSetH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h ); + void cmUiSetWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h ); // Get/Set the control width and height for only the next control. // Set returns previous value. - int cmUiNextW( cmUiH_t uiH, unsigned panelId ); - int cmUiNextH( cmUiH_t uiH, unsigned panelId ); - void cmUiSetNextW( cmUiH_t uiH, unsigned panelId, int w ); - void cmUiSetNextH( cmUiH_t uiH, unsigned panelId, int h ); - void cmUiSetNextWH( cmUiH_t uiH, unsigned panelId, int w, int h ); + int cmUiNextW( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiNextH( cmUiH_t uiH, unsigned appId, unsigned panelId ); + void cmUiSetNextW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w ); + void cmUiSetNextH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h ); + void cmUiSetNextWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h ); // Get/Set the default inter-control borders // Set returns previous value. - int cmUiHBorder( cmUiH_t uiH, unsigned panelId ); - int cmUiVBorder( cmUiH_t uiH, unsigned panelId ); - int cmUiSetHBorder( cmUiH_t uiH, unsigned panelId, int w ); - int cmUiSetVBorder( cmUiH_t uiH, unsigned panelId, int h ); + int cmUiHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiSetHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w ); + int cmUiSetVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h ); // Get/Set the 'next' inter-control borders // Set returns previous value. - int cmUiNextHBorder( cmUiH_t uiH, unsigned panelId ); - int cmUiNextVBorder( cmUiH_t uiH, unsigned panelId ); - int cmUiSetNextHBorder( cmUiH_t uiH, unsigned panelId, int w ); - int cmUiSetNextVBorder( cmUiH_t uiH, unsigned panelId, int h ); + int cmUiNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiSetNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w ); + int cmUiSetNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h ); // Place the next control at the following coordinates. The // specified coordinates are only active during the next // cmUiCreateXXX() call. Setting the 'next rect' overrides all // other layout directives. - cmUiRC_t cmUiNextRect( cmUiH_t uiH, unsigned panelId, int x, int y, int w, int h ); + cmUiRC_t cmUiNextRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int x, int y, int w, int h ); // Get the location/size of the previously created control. // All ref. args are optional. - cmUiRC_t cmUiPrevRect( cmUiH_t uiH, unsigned panelId, int* xRef, int* yRef, int* wRef, int* hRef ); - int cmUiPrevL( cmUiH_t uiH, unsigned panelId ); - int cmUiPrevT( cmUiH_t uiH, unsigned panelId ); - int cmUiPrevR( cmUiH_t uiH, unsigned panelId ); - int cmUiPrevB( cmUiH_t uiH, unsigned panelId ); - int cmUiPrevW( cmUiH_t uiH, unsigned panelId ); - int cmUiPrevH( cmUiH_t uiH, unsigned panelId ); - + cmUiRC_t cmUiPrevRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int* xRef, int* yRef, int* wRef, int* hRef ); + int cmUiPrevL( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiPrevT( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiPrevR( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiPrevB( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiPrevW( cmUiH_t uiH, unsigned appId, unsigned panelId ); + int cmUiPrevH( cmUiH_t uiH, unsigned appId, unsigned panelId ); + //------------------------------------------------------------------------------------------ // // Get/set the value of UI control. // // TODO: - // 1) Still need functions for setting auxilliary values like + // + Need functions for setting auxilliary values like // min,max,etc.. - // 2) A coherent model needs to be selected for determining - // how local values get set. As it is local values are - // only set via callbacs from the UI driver. // Set the value associated with a control. - // These functions would be better named 'cmUiSendXXX()' since - // they don't actually set the local value but rather call the - // driver to set the UI value. The driver may then respond with - // a callback which will set the local value. One advantage of - // this is that the value will be filtered according to the - // ui's rules (e.g. min, max .... ) - cmUiRC_t cmUiSetInt( cmUiH_t uiH, unsigned id, int v ); - cmUiRC_t cmUiSetUInt( cmUiH_t uiH, unsigned id, unsigned v ); - cmUiRC_t cmUiSetDouble( cmUiH_t uiH, unsigned id, double v ); - cmUiRC_t cmUiSetString( cmUiH_t uiH, unsigned id, const cmChar_t* v ); + // Set the local value of the specified control and then + // send the value to the UI driver so that the UI reflects this value. + cmUiRC_t cmUiSetInt( cmUiH_t uiH, unsigned appId, unsigned id, int v ); + cmUiRC_t cmUiSetUInt( cmUiH_t uiH, unsigned appId, unsigned id, unsigned v ); + cmUiRC_t cmUiSetDouble( cmUiH_t uiH, unsigned appId, unsigned id, double v ); + cmUiRC_t cmUiSetString( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* v ); + cmUiRC_t cmUiSetVPrintf(cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, va_list vl ); + cmUiRC_t cmUiSetPrintf( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, ... ); // Get the value associated with a control. These functions return // the control value cached in the local control, they do not need // to call the driver and are therefore very fast. - int cmUiInt( cmUiH_t uiH, unsigned id ); - unsigned cmUiUInt( cmUiH_t uiH, unsigned id ); - double cmUiDouble( cmUiH_t uiH, unsigned id ); - const cmChar_t* cmUiString( cmUiH_t uiH, unsigned id ); + int cmUiInt( cmUiH_t uiH, unsigned appId, unsigned id ); + unsigned cmUiUInt( cmUiH_t uiH, unsigned appId, unsigned id ); + double cmUiDouble( cmUiH_t uiH, unsigned appId, unsigned id ); + const cmChar_t* cmUiString( cmUiH_t uiH, unsigned appId, unsigned id ); + + unsigned cmUiListEleCount( cmUiH_t uiH, unsigned appId, unsigned id ); + unsigned cmUiListEleId( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index ); + const cmChar_t* cmUiListEleLabel( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index ); // Query/set the current error state. cmUiRC_t cmUiLastRC( cmUiH_t uiH ); diff --git a/cmUiDrvr.c b/cmUiDrvr.c index da657cb..146cece 100644 --- a/cmUiDrvr.c +++ b/cmUiDrvr.c @@ -1,7 +1,10 @@ #include "cmGlobal.h" +#include "cmRtSysMsg.h" #include "cmUiDrvr.h" void cmUiDriverArgSetup( cmUiDriverArg_t* a, + unsigned rtSubIdx, + unsigned selId, cmUiDId_t dId, unsigned appId, unsigned usrId, @@ -19,7 +22,8 @@ void cmUiDriverArgSetup( cmUiDriverArg_t* a, { flags = cmEnaFlag(flags,kSvalUiFl,sval!=NULL); - + a->hdr.rtSubIdx= rtSubIdx; + a->hdr.selId = selId; a->dId = dId; a->appId = appId; a->usrId = usrId; @@ -56,7 +60,7 @@ cmUiRC_t cmUiDriverArgSerialize( const cmUiDriverArg_t* a, void* buf, unsigned b return kOkUiRC; } -cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, void* buf, unsigned bufByteCnt ) +cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, const void* buf, unsigned bufByteCnt ) { bool fl = bufByteCnt >= sizeof(*a); assert( fl ); diff --git a/cmUiDrvr.h b/cmUiDrvr.h index 7a4dd85..84b956f 100644 --- a/cmUiDrvr.h +++ b/cmUiDrvr.h @@ -14,6 +14,7 @@ extern "C" { kAppNotFoundUiRC, kCtlNotFoundUiRC, kPanelNotFoundUiRC, + kInvalidAppIdUiRC, kPanelFullUiRC, kDrvrErrUiRC, kInvalidCtlOpUiRC, @@ -21,7 +22,8 @@ extern "C" { kInvalidIdUiRC, kSubSysFailUiRC, kBufTooSmallUiRC, - kBufCorruptUiRC + kBufCorruptUiRC, + kNotImplementedUiRC }; // Built-in control types. @@ -34,7 +36,8 @@ extern "C" { kMenuBtnUiCId, kListUiCId, kLabelUiCId, - kTextUiCId, + kStringUiCId, + kConsoleUiCId, kNumberUiCId, kSliderUiCId, kProgressUiCId, @@ -51,7 +54,7 @@ extern "C" { kCreateCtlDId, kDestroyCtlDId, kSetValDId, - kDestroyAllDId, + kEnableDId, // ival holds new enable state kMaxDId } cmUiDId_t; @@ -59,38 +62,43 @@ extern "C" { enum { // All controls recognize kValUiFl and kLblUiFl - kValUiFl = 0x0000001, - kLblUiFl = 0x0000002, + kValUiFl = 0x00000001, + kLblUiFl = 0x00000002, // Flags for Number,Progress,Meter - kMinUiFl = 0x000004, - kMaxUiFl = 0x000010, - kIncUiFl = 0x000020, - kNumMask = kValUiFl | kMinUiFl | kMaxUiFl | kIncUiFl, - kHorzUiFl = 0x000040, - kVertUiFl = 0x000080, + kMinUiFl = 0x00000004, + kMaxUiFl = 0x00000010, + kIncUiFl = 0x00000020, + kNumMask = kValUiFl | kMinUiFl | kMaxUiFl | kIncUiFl, + + kHorzUiFl = 0x00000040, + kVertUiFl = 0x00000080, // Flags for Filename and Dir - kFnPatUiFl = 0x000100, // file pattern string - kFnDirUiFl = 0x000200, // toggle file btn type - kFnMask = kFnPatUiFl | kFnDirUiFl, + kFnPatUiFl = 0x00000100, // file pattern string + kFnDirUiFl = 0x00000200, // toggle file btn type + kFnMask = kFnPatUiFl | kFnDirUiFl, // Append list or menu element. - kAppendUiFl = 0x000400, + kAppendUiFl = 0x00000400, + kPrependUiFl = 0x00000800, + kClearUiFl = 0x00001000, // clear all ele' from a list or menu - kLeftUiFl = 0x001000, - kTopUiFl = 0x002000, - kRightUiFl = 0x004000, - kBottomUiFl = 0x008000, - kHCtrUiFl = 0x010000, - kVCtrUiFl = 0x020000, - kInsideUiFl = 0x040000, + kLeftUiFl = 0x00002000, + kTopUiFl = 0x00004000, + kRightUiFl = 0x00008000, + kBottomUiFl = 0x00010000, + kHCtrUiFl = 0x00020000, + kVCtrUiFl = 0x00040000, + kInsideUiFl = 0x00080000, // Value flags indicate which value fields are valid - kIvalUiFl = 0x100000, - kFvalUiFl = 0x200000, - kSvalUiFl = 0x400000 + kIvalUiFl = 0x00100000, + kFvalUiFl = 0x00200000, + kSvalUiFl = 0x00400000, + kNoReflectUiFl = 0x01000000, // do not reflect event to the client + }; @@ -101,6 +109,7 @@ extern "C" { // because they are used internally as indexes. typedef struct { + cmRtSysMsgHdr_t hdr; cmUiDId_t dId; // function selector id unsigned appId; // app id (plug-in instance id) unsigned usrId; // ctl id @@ -119,6 +128,8 @@ extern "C" { typedef cmUiRC_t (*cmUiDriverFunc_t)( void* arg, const cmUiDriverArg_t* a ); void cmUiDriverArgSetup( cmUiDriverArg_t* a, + unsigned rtSubIdx, + unsigned selId, cmUiDId_t dId, unsigned appId, unsigned usrId, @@ -144,7 +155,7 @@ extern "C" { // Return kBufTooSmallUiRC or kBufCorruptUiRC if buffer corruption is detected // otherwise returns kOkUiRC. This function does not call cmErrMsg() on error // the caller is therefore responsible for generating errors. - cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, void* buf, unsigned bufByteCnt ); + cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, const void* buf, unsigned bufByteCnt ); // Return an arg. value converted to the requiested type. // Note that numeric values will be automatically converted but