1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813 |
- #include "cmGlobal.h"
- #include "cmRpt.h"
- #include "cmErr.h"
- #include "cmCtx.h"
- #include "cmMem.h"
- #include "cmMallocDebug.h"
- #include "cmArray.h"
- #include "cmJson.h"
- #include "cmUiDrvr.h"
- #include "cmUi.h"
-
-
- typedef struct
- {
- int x;
- int y;
- int w;
- int h;
- } cmUiRect_t;
-
- enum
- {
- kUseRectUiFl = 0x01,
- kPlaceRightUiFl = 0x02, // place only next control to right of prev control
- kPlaceBelowUiFl = 0x04, // place only next control to below prev control
- kPlaceBaseRowUiFl = 0x08, // place only next control at base row
- kNextWHUiFl = 0x10, // size next control according to nextW,nextH
- kFillRowsUiFl = 0x20, // current dflt fill direction
- };
-
- 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[]
- } 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;
-
- } cmUiPanel_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
-
- // current value of this control
- union
- {
- int ival;
- double fval;
- cmChar_t* sval;
- cmUiPanel_t* pnl;
- } u;
-
- int (*getInt)( struct cmUiCtl_str* c );
- double (*getDbl)( struct cmUiCtl_str* c );
- const cmChar_t* (*getStr)( struct cmUiCtl_str* c );
-
- void (*setInt)( struct cmUiCtl_str* c, int v );
- void (*setDbl)( struct cmUiCtl_str* c, double v );
- void (*setStr)( struct cmUiCtl_str* c, const cmChar_t* s );
-
- } cmUiCtl_t;
-
-
- 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)
- } cmUi_t;
-
- cmUiH_t cmUiNullHandle = cmSTATIC_NULL_HANDLE;
-
- cmUi_t* _cmUiHandleToPtr( cmUiH_t h )
- {
- cmUi_t* p = (cmUi_t*)h.h;
- assert(p != NULL );
- return p;
- }
-
- //---------------------------------------------------------------
- // int accessors
-
- int _cmUiGetIntFromInt( cmUiCtl_t* ctl )
- { return ctl->u.ival; }
-
- double _cmUiGetDblFromInt( cmUiCtl_t* ctl )
- { return ctl->u.ival; }
-
- const cmChar_t* _cmUiGetStrFromInt( cmUiCtl_t* ctl )
- { assert(0); return ""; }
-
- void _cmUiSetIntFromInt( cmUiCtl_t* ctl, int v )
- { ctl->u.ival = v; }
-
- void _cmUiSetIntFromDbl( cmUiCtl_t* ctl, double v )
- { ctl->u.ival = round(v); }
-
- void _cmUiSetIntFromStr( cmUiCtl_t* ctl, const cmChar_t* v )
- { assert(0); }
-
- void _cmUiSetIntAccessors( cmUiCtl_t* ctl )
- {
- ctl->getInt = _cmUiGetIntFromInt;
- ctl->getDbl = _cmUiGetDblFromInt;
- ctl->getStr = _cmUiGetStrFromInt;
-
- ctl->setInt = _cmUiSetIntFromInt;
- ctl->setDbl = _cmUiSetIntFromDbl;
- ctl->setStr = _cmUiSetIntFromStr;
- }
-
- //---------------------------------------------------------------
- // double accessors
-
- int _cmUiGetIntFromDbl( cmUiCtl_t* ctl )
- { return round(ctl->u.fval); }
-
- double _cmUiGetDblFromDbl( cmUiCtl_t* ctl )
- { return ctl->u.fval; }
-
- const cmChar_t* _cmUiGetStrFromDbl( cmUiCtl_t* ctl )
- { assert(0); return ""; }
-
- void _cmUiSetDblFromInt( cmUiCtl_t* ctl, int v )
- { ctl->u.fval = v; }
-
- void _cmUiSetDblFromDbl( cmUiCtl_t* ctl, double v )
- { ctl->u.fval = v; }
-
- void _cmUiSetDblFromStr( cmUiCtl_t* ctl, const cmChar_t* v )
- { assert(0); }
-
- void _cmUiSetDblAccessors( cmUiCtl_t* ctl )
- {
- ctl->getInt = _cmUiGetIntFromDbl;
- ctl->getDbl = _cmUiGetDblFromDbl;
- ctl->getStr = _cmUiGetStrFromDbl;
-
- ctl->setInt = _cmUiSetDblFromInt;
- ctl->setDbl = _cmUiSetDblFromDbl;
- ctl->setStr = _cmUiSetDblFromStr;
- }
-
- //---------------------------------------------------------------
- // string accessors
-
- int _cmUiGetIntFromStr( cmUiCtl_t* ctl )
- { assert(0); return -1; }
-
- double _cmUiGetDblFromStr( cmUiCtl_t* ctl )
- { assert(0); return -1; }
-
- const cmChar_t* _cmUiGetStrFromStr( cmUiCtl_t* ctl )
- { return ctl->u.sval; }
-
- void _cmUiSetStrFromInt( cmUiCtl_t* ctl, int v )
- { assert(0); }
-
- void _cmUiSetStrFromDbl( cmUiCtl_t* ctl, double v )
- { assert(0); }
-
- void _cmUiSetStrFromStr( cmUiCtl_t* ctl, const cmChar_t* v )
- { ctl->u.sval = cmMemResizeStr(ctl->u.sval, v==NULL ? "" : v); }
-
- void _cmUiSetStrAccessors( cmUiCtl_t* ctl )
- {
- ctl->getInt = _cmUiGetIntFromStr;
- ctl->getDbl = _cmUiGetDblFromStr;
- ctl->getStr = _cmUiGetStrFromStr;
-
- ctl->setInt = _cmUiSetStrFromInt;
- ctl->setDbl = _cmUiSetStrFromDbl;
- ctl->setStr = _cmUiSetStrFromStr;
- }
-
- //---------------------------------------------------------------
-
-
- cmUiRC_t _cmUiCallDriver( cmUi_t* p, cmUiDId_t dId, cmUiCtl_t* ctl )
- {
- cmUiRC_t rc = kOkUiRC;
- if( p->drvr != NULL )
- {
- ctl->arg.dId = dId;
-
- if((rc = p->drvr(p->drvrArg,&ctl->arg)) != 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->arg.ival = value;
- return _cmUiSetDriverValue(p,ctl,flag);
- }
-
- cmUiRC_t _cmUiSetDriverValueDouble( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, double value )
- {
- ctl->arg.fval = value;
- return _cmUiSetDriverValue(p,ctl,flag);
- }
-
- cmUiRC_t _cmUiSetDriverValueStr( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, const cmChar_t* value )
- {
- ctl->arg.sval = value;
- return _cmUiSetDriverValue(p,ctl,flag);
- }
-
- 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);
- }
-
-
- //---------------------------------------------------------------
-
- cmUiRC_t _cmUiFindApp( cmUi_t* p, unsigned appId, cmUiApp_t** appRef, bool errFl )
- {
- cmUiRC_t rc = kOkUiRC;
- cmUiApp_t* ap = NULL;
-
- // verify that the appId is a valid index
- if( appId < cmArrayCount(p->appArrH) )
- ap = cmArrayPtr(cmUiApp_t,p->appArrH,appId);
-
- // if the app record was not already allocated
- if( ap != NULL && ap->activeFl == false )
- ap = NULL;
-
- // report errors
- if( ap == NULL )
- {
- rc = kAppNotFoundUiRC;
-
- if( errFl )
- cmErrMsg(&p->err,rc,"App %i not found.", appId );
-
- }
-
- *appRef = ap;
-
- return rc;
- }
-
-
- cmUiRC_t _cmUiFindCtl( cmUi_t* p, unsigned usrId, cmUiCtl_t** ctlRef, bool errFl )
- {
- 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 )
- goto errLabel;
-
- // verify that the usrId is a valid index
- if( usrId < cmArrayCount(ap->ctlArrH) )
- ctl = cmArrayPtr(cmUiCtl_t,ap->ctlArrH,usrId);
-
- // verify that the usrId of the recd matches the requested usr id
- if( ctl!=NULL && ctl->usrId != usrId )
- ctl = NULL;
-
- // report errors
- if( ctl==NULL )
- {
- rc = kCtlNotFoundUiRC;
-
- if( errFl )
- cmErrMsg(&p->err,rc,"Control %i not found.",usrId);
- }
- errLabel:
-
- *ctlRef = ctl;
-
- return rc;
- }
-
- cmUiRC_t _cmUiFastFindCtl( cmUi_t* p, unsigned usrId, cmUiCtl_t** ctlRef, bool errFl )
- {
- assert( p->curAppId < cmArrayCount(p->appArrH) );
-
- cmUiApp_t* ap = cmArrayPtr(cmUiApp_t,p->appArrH,p->curAppId);
-
- assert( ap->activeFl && usrId < cmArrayCount(ap->ctlArrH) );
-
- *ctlRef = cmArrayPtr(cmUiCtl_t,ap->ctlArrH,usrId);
-
- assert( (*ctlRef)->usrId == usrId );
-
- return kOkUiRC;
- }
-
- cmUiRC_t _cmUiFindPanel( cmUi_t* p, unsigned panelId, cmUiPanel_t** ppRef, bool errFl )
-
- {
- 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 )
- goto errLabel;
-
- n = cmArrayCount(ap->pnlArrH);
- for(i=0; i<n; ++i)
- if( (*ppRef = cmArrayPtr(cmUiPanel_t,ap->pnlArrH,i))->usrId == panelId )
- break;
-
- errLabel:
-
- if(*ppRef == NULL)
- {
- rc = kPanelNotFoundUiRC;
-
- if( errFl )
- cmErrMsg(&p->err,rc,"Panel %i was not found.",panelId);
- }
-
-
- return rc;
- }
-
- //---------------------------------------------------------------
-
- cmUiRC_t _cmUiDestroyCtl( cmUi_t* p, cmUiCtl_t* ctl )
- {
- cmUiRC_t rc = kOkUiRC;
-
- rc = _cmUiCallDriver(p,kDestroyCtlDId,ctl);
-
- switch(ctl->cId)
- {
- case kLabelUiCId:
- case kTextUiCId:
- case kFilenameUiCId:
- case kDirUiCId:
- cmMemFree(ctl->u.sval);
- break;
-
- default:
- break;
- }
-
- ctl->cId = kInvalidUiCId;
- ctl->usrId = cmInvalidId;
- ctl->panelId = cmInvalidId;
- cmArrayRelease(&ctl->idArrH);
-
- return rc;
- }
-
- cmUiRC_t _cmUiDestroyPanel( cmUi_t* p, unsigned panelId )
- {
- cmUiRC_t rc = kOkUiRC;
- cmUiPanel_t* pp = NULL;
-
- // get the panel recd ptr
- if((rc = _cmUiFindPanel(p,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 )
- return rc;
-
- cmUiCtl_t* ctl = NULL;
- unsigned i = 0;
- unsigned n = cmArrayCount(ap->ctlArrH);
- cmUiRC_t rc0;
-
- // Destroy all controls that belong to this panel.
- // Notice that _cmUiDestroyCtl() does not need to call the driver
- // because destroying the drivers panel has implicitely also
- // destroyed all the contols assigned to it.
- for(i=0; i<n; ++i)
- if( _cmUiFindCtl(p,i,&ctl,false) == kOkUiRC && ctl != NULL && ctl->panelId == panelId)
- if((rc0 = _cmUiDestroyCtl(p,ctl)) != kOkUiRC )
- rc = rc0;
-
- // release the panel record
- pp->appPtr = NULL;
- pp->usrId = cmInvalidId;
-
- return rc;
- }
-
- 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 )
- {
- if( errFl )
- rc = cmErrMsg(&p->err,kAppNotFoundUiRC,"The app %i was not found for destruction.",appId);
-
- goto errLabel;
- }
-
- assert( ap != NULL );
-
- // destroy all panels owned by this app
- unsigned i;
- unsigned n = cmArrayCount(ap->pnlArrH);
- for(i=0; i<n; ++i)
- {
- cmUiPanel_t* pp = cmArrayPtr(cmUiPanel_t,ap->pnlArrH,i);
- if( pp->usrId != cmInvalidId )
- if((rc0 = _cmUiDestroyPanel(p,pp->usrId)) != kOkUiRC )
- rc = rc0;
- }
-
- ap->appId = -1;
- ap->activeFl = false;
- cmArrayRelease(&ap->ctlArrH);
- cmArrayRelease(&ap->pnlArrH);
-
- errLabel:
- p->curAppId = orgAppId;
-
- return rc;
- }
-
- cmUiRC_t _cmUiDestroyAllApps( cmUi_t* p )
- {
- cmUiRC_t rc = kOkUiRC;
- unsigned n = cmArrayCount(p->appArrH);
- unsigned i;
- for(i=0; i<n; ++i)
- {
- cmUiRC_t rc0;
- if((rc0 = _cmUiDestroyApp(p,i,false)) != kOkUiRC )
- rc = rc0;
- }
-
- cmArrayClear(p->appArrH,false);
-
- return rc;
- }
-
- //---------------------------------------------------------------
-
- 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;
- return kOkUiRC;
- }
-
- if( pp->prevRect.x == -1 )
- pp->prevRect.x = pp->baseCol;
-
- if( pp->prevRect.y == -1 )
- pp->prevRect.y = pp->baseRow;
-
- if( pp->prevRect.w == -1 )
- pp->prevRect.w = 0;
-
- if( pp->prevRect.h == -1 )
- pp->prevRect.h = 0;
-
- // Get direction flag. Fill across rows? or down columns?
- bool fillRowFl = cmIsFlag(pp->flags,kFillRowsUiFl);
-
- // the 'place to right' flag overrides the directon flag for just this instance
- if( cmIsFlag(pp->flags,kPlaceRightUiFl ) )
- fillRowFl = true;
-
- // the 'place under' flag overides the direction flag for just this instance
- if( cmIsFlag(pp->flags,kPlaceBelowUiFl ) )
- fillRowFl = false;
-
- // set x coord - if filling acros rows ...
- if( fillRowFl )
- a->x = pp->prevRect.x + pp->prevRect.w + pp->nextHBorder;
- else
- a->x = pp->baseCol; // ... or down columns
-
- // if a new column was set then move to the base row
- if( cmIsFlag(pp->flags,kPlaceBaseRowUiFl) )
- a->y = pp->baseRow;
- else
- {
- // set y coord - if filling acros rows ...
- if( fillRowFl )
- a->y = pp->prevRect.y;
- else
- a->y = pp->prevRect.y + pp->prevRect.h + pp->nextVBorder; // ... or down columns
- }
-
- 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->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 rc;
- cmUiPanel_t* pp = NULL;
- cmUiApp_t* ap = NULL;
-
- if( ctlRef != NULL )
- *ctlRef = NULL;
-
- // locate the app
- if((rc = _cmUiFindApp(p,p->curAppId,&ap,true)) != kOkUiRC )
- return rc;
-
- // locate the panel the control belongs to
- if((rc = _cmUiFindPanel(p,panelId,&pp,true)) != kOkUiRC )
- return rc;
-
- // get the new ctl record
- cmUiCtl_t* ctl;
- if( usrId == cmInvalidId )
- {
- ctl = &p->dummy;
- memset(ctl,0,sizeof(*ctl));
- }
- else
- {
- 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);
- }
- }
-
- // setup this controls cached callback arg record
- cmUiDriverArgSetup(&ctl->arg,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 )
- if((rc = _cmUiGetCtlXYWH(p,&ctl->arg,pp)) != kOkUiRC )
- return rc;
-
-
- // setup the new ctl record
- ctl->cId = cId;
- ctl->usrId = usrId;
- ctl->panelId = panelId;
-
- // display-only controls don't need an id array
- if( usrId != cmInvalidId )
- cmArrayAlloc(p->ctx,&ctl->idArrH,sizeof(unsigned));
-
-
- if( ctlRef != NULL )
- *ctlRef = ctl;
-
- return _cmUiCallDriver(p,kCreateCtlDId,ctl);
- }
-
-
- cmUiRC_t cmUiAlloc(
- cmCtx_t* ctx,
- cmUiH_t* uiHPtr,
- cmUiDriverFunc_t drvrFunc,
- void* drvrArg,
- cmUiDriverFunc_t cbFunc,
- void * cbArg)
- {
- cmUiRC_t rc;
- if((rc = cmUiFree(uiHPtr)) != kOkUiRC )
- return rc;
-
- cmUi_t* p = cmMemAllocZ(cmUi_t,1);
- cmErrSetup(&p->err,&ctx->rpt,"cmUi");
-
- p->ctx = ctx;
- p->drvr = drvrFunc;
- p->drvrArg = drvrArg;
- p->cbFunc = cbFunc;
- p->cbArg = cbArg;
- p->panelW = 1000;
- p->panelH = 500;
-
- cmArrayAlloc(p->ctx,&p->appArrH,sizeof(cmUiApp_t));
-
- uiHPtr->h = p;
-
- return rc;
- }
-
- cmUiRC_t cmUiFree( cmUiH_t* hp )
- {
- cmUiRC_t rc = kOkUiRC;
-
- if( hp == NULL || cmUiIsValid(*hp)==false )
- return kOkUiRC;
-
- cmUi_t* p = _cmUiHandleToPtr(*hp);
-
-
- if((rc = _cmUiDestroyAllApps(p)) != kOkUiRC )
- return rc;
-
- cmArrayRelease(&p->appArrH);
- cmMemFree(p);
-
- hp->h = NULL;
-
- return rc;
- }
-
-
- bool cmUiIsValid( cmUiH_t h )
- { return h.h != NULL; }
-
- void cmUiSetDriver( cmUiH_t h, cmUiDriverFunc_t drvrFunc, void* drvrArg )
- {
- cmUi_t* p = _cmUiHandleToPtr(h);
- p->drvr = drvrFunc;
- p->drvrArg = drvrArg;
- }
-
-
- cmUiRC_t cmUiCreateApp( cmUiH_t h, unsigned appId )
- {
- cmUiRC_t rc = kOkUiRC;
-
- if( cmUiIsValid(h)==false)
- return rc;
-
- cmUi_t* p = _cmUiHandleToPtr(h);
- cmUiApp_t* ap = NULL;
-
- // verify that the requested app does not exist
- if( _cmUiFindApp(p,appId, &ap, false ) == kOkUiRC )
- return cmErrMsg(&p->err,kInvalidIdUiRC,"The id (%i) of the new application is already in use.",appId);
-
- ap = cmArrayClr(cmUiApp_t,p->appArrH,appId);
- ap->appId = appId;
- ap->activeFl = true;
- cmArrayAlloc(p->ctx,&ap->ctlArrH,sizeof(cmUiCtl_t));
- cmArrayAlloc(p->ctx,&ap->pnlArrH,sizeof(cmUiPanel_t));
-
-
- return rc;
- }
-
- cmUiRC_t cmUiDestroyApp( cmUiH_t h, unsigned appId )
- {
- if( cmUiIsValid(h)==false)
- return kOkUiRC;
-
- cmUi_t* p = _cmUiHandleToPtr(h);
- return _cmUiDestroyApp(p,appId,true);
- }
-
-
- cmUiRC_t cmUiDestroyAllApps( cmUiH_t h )
- {
- if( cmUiIsValid(h)==false)
- return kOkUiRC;
-
- cmUi_t* p = _cmUiHandleToPtr(h);
- return _cmUiDestroyAllApps(p);
- }
-
- cmUiRC_t cmUiSetAppId( cmUiH_t h, unsigned appId )
- {
- cmUiRC_t rc = kOkUiRC;
-
- if( cmUiIsValid(h)==false)
- return rc;
-
- cmUi_t* p = _cmUiHandleToPtr(h);
- cmUiApp_t* ap = NULL;
-
- // verify that the requested app exists
- if( appId != cmInvalidId )
- if((rc = _cmUiFindApp(p,appId, &ap, true )) != kOkUiRC )
- return rc;
-
- p->curAppId = appId;
- return rc;
- }
-
- unsigned cmUiAppCount( cmUiH_t h )
- {
- if( cmUiIsValid(h)==false)
- return 0;
-
- cmUi_t* p = _cmUiHandleToPtr(h);
-
- return cmArrayCount(p->appArrH);
- }
-
-
-
- cmUiRC_t cmUiOnDriverEvent( cmUiH_t h, const cmUiDriverArg_t* arg )
- {
- cmUiRC_t rc = kOkUiRC;
- cmUi_t* p = _cmUiHandleToPtr(h);
- cmUiCtl_t* ctl;
-
- if((rc = cmUiSetAppId(h,arg->appId)) != kOkUiRC )
- return rc;
-
- if((rc = _cmUiFindCtl(p,arg->usrId,&ctl,true)) != kOkUiRC )
- goto errLabel;
-
- switch( arg->cId )
- {
- case kInvalidUiCId:
- break;
-
- case kPanelUiCId:
- case kBtnUiCId:
- case kCheckUiCId:
- ctl->arg.ival = ctl->u.ival = cmUiDriverArgGetInt(arg);
- break;
-
- case kMenuBtnUiCId:
- case kListUiCId:
- {
- 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
- ctl->arg.ival = ctl->u.ival = cmArrayEle(unsigned,ctl->idArrH,eleIdx);
-
- }
- break;
-
-
- case kLabelUiCId:
- case kTextUiCId:
- case kFilenameUiCId:
- case kDirUiCId:
- {
- const cmChar_t* s;
- if((s = cmUiDriverArgGetString(arg)) != NULL )
- ctl->arg.sval = ctl->u.sval = cmMemResizeStr(ctl->u.sval,s);
- }
- break;
-
- case kSliderUiCId:
- case kNumberUiCId:
- ctl->arg.fval = ctl->u.fval = cmUiDriverArgGetDouble(arg);
- break;
-
- case kProgressUiCId:
- case kMeterUiCId:
- assert(0); // progress and meters are display only
- break;
-
- case kMaxUiCId:
- assert(0);
- break;
-
- }
-
- ctl->arg.dId = kSetValDId;
- rc = p->cbFunc(p->cbArg,&ctl->arg);
-
- errLabel:
- cmUiSetAppId(h,cmInvalidId);
-
- return rc;
- }
-
- cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned newPanelId, const cmChar_t* label )
- {
- 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->dfltW = 150;
- pp->dfltH = 25;
- pp->nextW = pp->dfltW;
- pp->nextH = pp->dfltH;
- pp->dfltHBorder= 2;
- pp->dfltVBorder= 2;
- pp->nextHBorder= pp->dfltHBorder;
- pp->nextVBorder= pp->dfltVBorder;
- pp->prevRect.x = -1;
- pp->prevRect.y = -1;
- pp->prevRect.w = -1;
- pp->prevRect.h = -1;
-
-
- if((rc = _cmUiCreateCtl(p, newPanelId, kPanelUiCId, newPanelId, label, 0, &pp->ctl )) != kOkUiRC )
- {
- // TODO - destroy panel record here
- return rc;
- }
-
- _cmUiFindCtl(p,newPanelId,&ctl,true);
-
- assert(ctl!=NULL);
- ctl->u.pnl = pp;
- return rc;
- }
-
-
- cmUiRC_t cmUiCreateBtn( cmUiH_t uiH, 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 )
- {
- _cmUiSetIntAccessors(c);
- }
- return rc;
- }
-
- cmUiRC_t cmUiCreateCheck( cmUiH_t uiH, 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 )
- {
- _cmUiSetIntAccessors(c);
-
- rc = _cmUiSetDriverValueInt(p,c,kValUiFl,dflt);
- }
- return rc;
- }
-
- cmUiRC_t cmUiCreateLabel( cmUiH_t uiH, 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 )
- _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 rc = kOkUiRC;
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* c;
-
- if(( rc = _cmUiCreateCtl(p,panelId,kTextUiCId,id,label,flags,&c)) == kOkUiRC )
- {
- _cmUiSetStrAccessors(c);
-
- rc = _cmUiSetDriverValueStr(p,c,kValUiFl,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 rc = kOkUiRC;
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCId_t cid = kNumberUiCId;
- cmUiCtl_t* c;
- cmUiPanel_t* pp;
-
- if( cmIsFlag(flags,kVertUiFl|kHorzUiFl) )
- {
- if( cmIsFlag(flags,kVertUiFl) )
- {
- if((rc = _cmUiFindPanel(p,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) );
- }
-
- cid = kSliderUiCId;
- }
-
- if(( rc = _cmUiCreateCtl(p,panelId,cid,id,label,flags,&c)) == kOkUiRC )
- {
- cmUiRC_t rc0;
-
- _cmUiSetDblAccessors(c);
-
- if((rc0 = _cmUiSetDriverValueDouble(p,c,kMinUiFl,min)) != kOkUiRC )
- rc = rc0;
-
- if((rc0 = _cmUiSetDriverValueDouble(p,c,kMaxUiFl,max)) != kOkUiRC )
- rc = rc0;
-
- if((rc0 = _cmUiSetDriverValueDouble(p,c,kIncUiFl,incr)) != kOkUiRC )
- rc = rc0;
-
- if((rc0 = _cmUiSetDriverValueDouble(p,c,kValUiFl,dflt)) != kOkUiRC )
- rc = rc0;
-
- }
-
- 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 )
- {
- return _cmUiCreateNumber(uiH,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 )
- {
- return _cmUiCreateNumber(uiH,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 )
- {
- return _cmUiCreateNumber(uiH,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 rc = kOkUiRC;
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* c;
-
- if(( rc = _cmUiCreateCtl(p,panelId,kProgressUiCId,id,label,flags,&c)) == kOkUiRC )
- {
- cmUiRC_t rc0;
-
- _cmUiSetIntAccessors(c);
-
- if((rc0 = _cmUiSetDriverValueInt(p,c,kMinUiFl,min)) != kOkUiRC )
- rc = rc0;
-
- if((rc0 = _cmUiSetDriverValueInt(p,c,kMaxUiFl,max)) != kOkUiRC )
- rc = rc0;
-
- if((rc0 = _cmUiSetDriverValueInt(p,c,kValUiFl,dflt)) != kOkUiRC )
- rc = rc0;
-
- }
-
- 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 rc;
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* c;
- cmUiPanel_t* pp;
-
- if( cmIsFlag(flags,kVertUiFl) )
- {
- if((rc = _cmUiFindPanel(p,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) );
- }
-
- if((rc = _cmUiCreateCtl(p,panelId,kMeterUiCId,id,label,flags,&c)) == kOkUiRC )
- {
- cmUiRC_t rc0;
-
- _cmUiSetIntAccessors(c);
-
- if((rc0 = _cmUiSetDriverValueInt(p,c,kMinUiFl,min)) != kOkUiRC )
- rc = rc0;
-
- if((rc0 = _cmUiSetDriverValueInt(p,c,kMaxUiFl,max)) != kOkUiRC )
- rc = rc0;
-
- if((rc0 = _cmUiSetDriverValueInt(p,c,kValUiFl,dflt)) != kOkUiRC )
- rc = rc0;
-
- }
- return rc;
- }
-
-
- cmUiRC_t cmUiCreateHMeter( cmUiH_t uiH, 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);
- }
-
- cmUiRC_t cmUiCreateVMeter( cmUiH_t uiH, 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);
- }
-
- 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 rc = kOkUiRC;
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* c;
-
- if(( rc = _cmUiCreateCtl(p,panelId,kFilenameUiCId,id,label,flags,&c)) == kOkUiRC )
- {
- cmUiRC_t rc0;
-
- _cmUiSetStrAccessors(c);
-
- if( dfltDir != NULL )
- {
- if((rc0 = _cmUiSetDriverValueStr(p,c,kValUiFl,dfltDir)) != kOkUiRC )
- rc = rc0;
- }
-
- if( patStr != NULL )
- {
- if((rc0 = _cmUiSetDriverValueStr(p,c,kValUiFl,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 rc = kOkUiRC;
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* c;
-
- if(( rc = _cmUiCreateCtl(p,panelId,kDirUiCId,id,label,flags,&c)) == kOkUiRC )
- {
- cmUiRC_t rc0;
-
- _cmUiSetStrAccessors(c);
-
- if( dfltDir != NULL )
- {
- if((rc0 = _cmUiSetDriverValueStr(p,c,kValUiFl,dfltDir)) != kOkUiRC )
- rc = rc0;
- }
- }
- return rc;
- }
-
- cmUiRC_t cmUiCreateMenuBtn( cmUiH_t uiH, 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 )
- _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 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, ... )
- {
- va_list vl;
- va_start(vl,id0);
- cmUiRC_t rc = cmUiCreateMenuBtnV(uiH,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 rc = kOkUiRC;
- // TODO:
- return rc;
- }
-
- cmUiRC_t cmUiCreateList(cmUiH_t uiH, 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 )
- return rc;
-
- if( cmIsNotFlag(pp->flags,kNextWHUiFl) )
- cmUiSetNextWH( uiH, panelId, cmUiNextW(uiH,panelId), cmUiH(uiH,panelId) * visibleRowCnt );
-
- if((rc = _cmUiCreateCtl(p,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 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, ... )
- {
- va_list vl;
- va_start(vl,id0);
- cmUiRC_t rc = cmUiCreateListV(uiH,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 rc = kOkUiRC;
- // TODO:
- return rc;
- }
-
- cmUiRC_t cmUiAppendListEle( cmUiH_t uiH, 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 )
- 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);
-
- return _cmUiSetDriverValueIntAndStr(p,ctl,kAppendUiFl,eleId,text);
- }
-
- cmUiRC_t cmUiDestroyCtl( cmUiH_t uiH, unsigned id )
- {
- cmUiRC_t rc = kOkUiRC;
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* ctl = NULL;
-
- if((rc = _cmUiFindCtl(p,id,&ctl,true)) == kOkUiRC )
- {
- if( ctl->cId == kPanelUiCId )
- _cmUiDestroyPanel(p,ctl->usrId);
- else
- rc = _cmUiDestroyCtl(p,ctl);
- }
- return rc;
- }
-
- bool cmUiCtlExists( cmUiH_t uiH, unsigned panelId, unsigned id )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
-
- if( panelId == id )
- {
- cmUiPanel_t* pp=NULL;
- return _cmUiFindPanel(p, panelId, &pp, false ) == kOkUiRC;
- }
-
- cmUiCtl_t* ctl=NULL;
- return _cmUiFindCtl(p,id,&ctl,false) == kOkUiRC;
- }
-
- cmUiRC_t cmUiClearPanel( cmUiH_t uiH, 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 )
- return rc;
-
- cmUiApp_t* ap = pp->appPtr;
- cmUiCtl_t* ctl = NULL;
- unsigned i = 0;
- unsigned n = cmArrayCount(ap->ctlArrH);
- cmUiRC_t rc0;
-
- // Destroy all controls that belong to this panel.
- for(i=0; i<n; ++i)
- if( _cmUiFindCtl(p,i,&ctl,false) == kOkUiRC && ctl != NULL && ctl->panelId == panelId && ctl->usrId != panelId)
- if((rc0 = _cmUiDestroyCtl(p,ctl)) != kOkUiRC )
- rc = rc0;
-
- return rc;
- }
-
- cmUiRC_t cmUiNextRect( cmUiH_t uiH, 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 )
- return rc;
-
- pp->rect.x = x;
- pp->rect.y = y;
- pp->rect.w = w;
- pp->rect.h = h;
- pp->flags = cmSetFlag(pp->flags,kUseRectUiFl);
-
- return rc;
- }
-
- cmUiRC_t cmUiPrevRect( cmUiH_t uiH, 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 )
- return rc;
-
- if( xRef != NULL )
- *xRef = pp->prevRect.x;
-
- if( yRef != NULL )
- *yRef = pp->prevRect.y;
-
- if( wRef != NULL )
- *wRef = pp->prevRect.w;
-
- if( hRef != NULL )
- *hRef = pp->prevRect.h;
-
- return rc;
- }
-
- bool cmUiFillRows( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if( _cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return false;
-
- return cmIsFlag(pp->flags,kFillRowsUiFl);
- }
-
- bool cmUiSetFillRows( cmUiH_t uiH, unsigned panelId, bool enableFl )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if( _cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return false;
-
- bool retFl = cmIsFlag(pp->flags,kFillRowsUiFl);
-
- pp->flags = cmEnaFlag(pp->flags,kFillRowsUiFl,enableFl);
-
- return retFl;
- }
-
- void cmUiPlaceRight( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return;
-
- pp->flags = cmClrFlag(pp->flags,kPlaceBelowUiFl);
- pp->flags = cmSetFlag(pp->flags,kPlaceRightUiFl);
- }
-
- void cmUiPlaceBelow( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return;
-
- pp->flags = cmClrFlag(pp->flags,kPlaceRightUiFl);
- pp->flags = cmSetFlag(pp->flags,kPlaceBelowUiFl);
- }
-
- void cmUiNewLine( cmUiH_t uiH, unsigned panelId )
- {
- cmUiSetBaseRow( uiH, panelId, cmUiPrevB(uiH,panelId) + cmUiNextVBorder(uiH,panelId) );
- cmUiSetBaseCol( uiH, panelId, cmUiBaseCol(uiH,panelId));
- }
-
- int cmUiBaseCol( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->baseCol;
- }
-
- int cmUiSetBaseCol( cmUiH_t uiH, unsigned panelId, int x )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if( _cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- int bc = pp->baseCol;
- pp->baseCol = x;
- pp->flags = cmSetFlag(pp->flags,kPlaceBaseRowUiFl);
- return bc;
- }
-
- int cmUiBaseRow( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->baseRow;
- }
-
- int cmUiSetBaseRow( cmUiH_t uiH, unsigned panelId, int y )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
- cmUiRC_t rc;
-
- if((rc = _cmUiFindPanel(p, panelId, &pp, true)) != kOkUiRC )
- return -1;
-
- int br = pp->baseRow;
- pp->baseRow = y;
- return br;
- }
-
-
-
- int cmUiW( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->dfltW;
- }
-
- int cmUiH( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->dfltH;
- }
-
- int cmUiSetW( cmUiH_t uiH, unsigned panelId, int w )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- int rv = pp->dfltW;
- pp->dfltW = w;
- pp->nextW = w;
- return rv;
- }
-
- int cmUiSetH( cmUiH_t uiH, unsigned panelId, int h )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- int rv = pp->dfltH;
- pp->dfltH = h;
- pp->nextW = h;
- return rv;
- }
-
- void cmUiSetWH( cmUiH_t uiH, 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;
-
- }
-
- int cmUiNextW( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->nextW;
- }
-
- int cmUiNextH( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, 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 cmUiSetNextH( cmUiH_t uiH, unsigned panelId, int h )
- { return cmUiSetNextWH( uiH, panelId, cmUiNextW(uiH,panelId), h); }
-
- void cmUiSetNextWH( cmUiH_t uiH, unsigned panelId, int w, int h )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return;
-
- pp->nextW = w;
- pp->nextH = h;
- pp->flags = cmSetFlag(pp->flags,kNextWHUiFl);
- }
-
- int cmUiHBorder( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->dfltHBorder;
- }
-
- int cmUiVBorder( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->dfltVBorder;
- }
-
- int cmUiSetHBorder( cmUiH_t uiH, unsigned panelId, int w )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- int rv = pp->dfltHBorder;
- pp->dfltHBorder = w;
- return rv;
- }
-
- int cmUiSetVBorder( cmUiH_t uiH, unsigned panelId, int h )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- int rv = pp->dfltVBorder;
- pp->dfltVBorder = h;
- return rv;
- }
-
- int cmUiNextHBorder( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->nextHBorder;
- }
-
- int cmUiNextVBorder( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->nextVBorder;
- }
-
- int cmUiSetNextHBorder( cmUiH_t uiH, unsigned panelId, int w )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- int rv = pp->nextHBorder;
- pp->nextHBorder = w;
- return rv;
- }
-
- int cmUiSetNextVBorder( cmUiH_t uiH, unsigned panelId, int h )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- int rv = pp->nextVBorder;
- pp->nextVBorder = h;
- return rv;
- }
-
- int cmUiPrevL( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->prevRect.x;
- }
-
- int cmUiPrevT( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->prevRect.y;
- }
-
- int cmUiPrevR( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->prevRect.x + pp->prevRect.w;
- }
-
- int cmUiPrevB( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->prevRect.y + pp->prevRect.h;
- }
- int cmUiPrevW( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->prevRect.w;
- }
-
- int cmUiPrevH( cmUiH_t uiH, unsigned panelId )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiPanel_t* pp;
-
- if(_cmUiFindPanel(p, panelId, &pp, true) != kOkUiRC )
- return -1;
-
- return pp->prevRect.h;
- }
-
-
-
- cmUiRC_t cmUiSetInt( cmUiH_t uiH, unsigned id, int v )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* ctl;
- cmUiRC_t rc;
-
- if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC )
- return rc;
-
- return _cmUiSetDriverValueInt(p,ctl,kValUiFl,v);
-
- }
-
- cmUiRC_t cmUiSetUInt( cmUiH_t uiH, unsigned id, unsigned v )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* ctl;
- cmUiRC_t rc;
-
- if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC )
- return rc;
-
- return _cmUiSetDriverValueInt(p,ctl,kValUiFl,v);
- }
-
- cmUiRC_t cmUiSetDouble( cmUiH_t uiH, unsigned id, double v )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* ctl;
- cmUiRC_t rc;
-
- if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC )
- return rc;
-
- return _cmUiSetDriverValueDouble(p,ctl,kValUiFl,v);
- }
-
- cmUiRC_t cmUiSetString( cmUiH_t uiH, 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 )
- return rc;
-
- return _cmUiSetDriverValueStr(p,ctl,kValUiFl,v);
- }
-
- int cmUiInt( cmUiH_t uiH, unsigned id )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* ctl;
- cmUiRC_t rc;
-
- if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC )
- return 0;
-
- return ctl->getInt(ctl);
- }
-
- unsigned cmUiUInt( cmUiH_t uiH, unsigned id )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* ctl;
- cmUiRC_t rc;
-
- if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC )
- return 0;
-
- return ctl->getInt(ctl);
- }
-
- double cmUiDouble( cmUiH_t uiH, unsigned id )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* ctl;
- cmUiRC_t rc;
-
- if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC )
- return 0;
-
- return ctl->getDbl(ctl);
- }
-
- const cmChar_t* cmUiString( cmUiH_t uiH, unsigned id )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- cmUiCtl_t* ctl;
- cmUiRC_t rc;
-
- if((rc = _cmUiFastFindCtl(p,id,&ctl,true)) != kOkUiRC )
- return 0;
-
- return ctl->getStr(ctl);
- }
-
-
- cmUiRC_t cmUiLastRC( cmUiH_t uiH )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- return cmErrLastRC(&p->err);
- }
-
- cmUiRC_t cmUiSetRC( cmUiH_t uiH, cmUiRC_t rc )
- {
- cmUi_t* p = _cmUiHandleToPtr(uiH);
- return cmErrSetRC(&p->err, rc);
- }
|