libcm is a C development framework with an emphasis on audio signal processing applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cmUi.c 54KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147
  1. #include "cmGlobal.h"
  2. #include "cmRpt.h"
  3. #include "cmErr.h"
  4. #include "cmCtx.h"
  5. #include "cmMem.h"
  6. #include "cmMallocDebug.h"
  7. #include "cmLinkedHeap.h"
  8. #include "cmArray.h"
  9. #include "cmJson.h"
  10. #include "cmRtSysMsg.h"
  11. #include "cmUiDrvr.h"
  12. #include "cmUi.h"
  13. #include "cmText.h"
  14. typedef struct
  15. {
  16. int x;
  17. int y;
  18. int w;
  19. int h;
  20. } cmUiRect_t;
  21. enum
  22. {
  23. kUseRectUiFl = 0x01,
  24. kPlaceRightUiFl = 0x02, // place only next control to right of prev control
  25. kPlaceBelowUiFl = 0x04, // place only next control to below prev control
  26. kPlaceBaseRowUiFl = 0x08, // place only next control at base row
  27. kNextWHUiFl = 0x10, // size next control according to nextW,nextH
  28. kFillRowsUiFl = 0x20, // current dflt fill direction
  29. };
  30. typedef struct cmUiApp_str
  31. {
  32. unsigned appId; // app id and index into cmUI_t.appArrH[].
  33. unsigned rtSubIdx; //
  34. bool activeFl; // true if this app recd is active and valid
  35. cmArrayH_t ctlArrH; // cmUiCtl_t[]
  36. cmArrayH_t pnlArrH; // cmUiPanel_t[]
  37. } cmUiApp_t;
  38. struct cmUiCtl_str;
  39. typedef struct cmUiPanel_str
  40. {
  41. cmUiApp_t* appPtr; // owner app.
  42. struct cmUiCtl_str* ctl; // control recd assoc'd with this panel
  43. unsigned flags; // See kXXXUiFl above
  44. unsigned usrId; // app. supplied id
  45. cmUiRect_t rect; // rect to position next control (only used if kUseRectUiFl is set)
  46. cmUiRect_t prevRect;
  47. int baseCol;
  48. int baseRow;
  49. int dfltW;
  50. int dfltH;
  51. int nextW;
  52. int nextH;
  53. int dfltHBorder;
  54. int dfltVBorder;
  55. int nextHBorder;
  56. int nextVBorder;
  57. } cmUiPanel_t;
  58. typedef struct
  59. {
  60. unsigned id;
  61. cmChar_t* label;
  62. } cmUiListEle_t;
  63. typedef struct cmUiCtl_str
  64. {
  65. cmUiCId_t cId; // control type and used to decode the value union below.
  66. unsigned usrId; // control instance id and index into cmUiApp_t.ctlArrH[].
  67. unsigned panelId; // panel this ctl belongs to
  68. cmArrayH_t idArrH; // id's associated with each sub-element of this control (used by menu's, list's, etc...)
  69. cmUiDriverArg_t arg; // cached callback arg for this control
  70. // current value of this control
  71. union
  72. {
  73. int ival;
  74. double fval;
  75. cmChar_t* sval;
  76. cmUiPanel_t* pnl;
  77. } u;
  78. int (*getInt)( struct cmUiCtl_str* c );
  79. double (*getDbl)( struct cmUiCtl_str* c );
  80. const cmChar_t* (*getStr)( struct cmUiCtl_str* c );
  81. void (*setInt)( struct cmUiCtl_str* c, int v );
  82. void (*setDbl)( struct cmUiCtl_str* c, double v );
  83. void (*setStr)( struct cmUiCtl_str* c, const cmChar_t* s );
  84. } cmUiCtl_t;
  85. typedef struct
  86. {
  87. cmErr_t err; //
  88. cmCtx_t* ctx; // Global context.
  89. cmUiDriverFunc_t drvr; // Driver callback function
  90. void* drvrArg; // Driver callback function arg.
  91. int panelW; // Panel width.
  92. int panelH; // Panel height
  93. cmUiDriverFunc_t cbFunc; // Client callback function
  94. void* cbArg; //
  95. cmArrayH_t appArrH; // cmUiApp_t[]
  96. cmUiCtl_t dummy; // dummy recd used to create controls which will never be accessed after creation (like read-only labels)
  97. } cmUi_t;
  98. cmUiH_t cmUiNullHandle = cmSTATIC_NULL_HANDLE;
  99. cmUi_t* _cmUiHandleToPtr( cmUiH_t h )
  100. {
  101. cmUi_t* p = (cmUi_t*)h.h;
  102. assert(p != NULL );
  103. return p;
  104. }
  105. //---------------------------------------------------------------
  106. // int accessors
  107. int _cmUiGetIntFromInt( cmUiCtl_t* ctl )
  108. { return ctl->u.ival; }
  109. double _cmUiGetDblFromInt( cmUiCtl_t* ctl )
  110. { return ctl->u.ival; }
  111. const cmChar_t* _cmUiGetStrFromInt( cmUiCtl_t* ctl )
  112. { assert(0); return ""; }
  113. void _cmUiSetIntFromInt( cmUiCtl_t* ctl, int v )
  114. { ctl->u.ival = v; }
  115. void _cmUiSetIntFromDbl( cmUiCtl_t* ctl, double v )
  116. { ctl->u.ival = round(v); }
  117. void _cmUiSetIntFromStr( cmUiCtl_t* ctl, const cmChar_t* v )
  118. { assert(0); }
  119. void _cmUiSetIntAccessors( cmUiCtl_t* ctl )
  120. {
  121. ctl->getInt = _cmUiGetIntFromInt;
  122. ctl->getDbl = _cmUiGetDblFromInt;
  123. ctl->getStr = _cmUiGetStrFromInt;
  124. ctl->setInt = _cmUiSetIntFromInt;
  125. ctl->setDbl = _cmUiSetIntFromDbl;
  126. ctl->setStr = _cmUiSetIntFromStr;
  127. }
  128. //---------------------------------------------------------------
  129. // double accessors
  130. int _cmUiGetIntFromDbl( cmUiCtl_t* ctl )
  131. { return round(ctl->u.fval); }
  132. double _cmUiGetDblFromDbl( cmUiCtl_t* ctl )
  133. { return ctl->u.fval; }
  134. const cmChar_t* _cmUiGetStrFromDbl( cmUiCtl_t* ctl )
  135. { assert(0); return ""; }
  136. void _cmUiSetDblFromInt( cmUiCtl_t* ctl, int v )
  137. { ctl->u.fval = v; }
  138. void _cmUiSetDblFromDbl( cmUiCtl_t* ctl, double v )
  139. { ctl->u.fval = v; }
  140. void _cmUiSetDblFromStr( cmUiCtl_t* ctl, const cmChar_t* v )
  141. { assert(0); }
  142. void _cmUiSetDblAccessors( cmUiCtl_t* ctl )
  143. {
  144. ctl->getInt = _cmUiGetIntFromDbl;
  145. ctl->getDbl = _cmUiGetDblFromDbl;
  146. ctl->getStr = _cmUiGetStrFromDbl;
  147. ctl->setInt = _cmUiSetDblFromInt;
  148. ctl->setDbl = _cmUiSetDblFromDbl;
  149. ctl->setStr = _cmUiSetDblFromStr;
  150. }
  151. //---------------------------------------------------------------
  152. // string accessors
  153. int _cmUiGetIntFromStr( cmUiCtl_t* ctl )
  154. { assert(0); return -1; }
  155. double _cmUiGetDblFromStr( cmUiCtl_t* ctl )
  156. { assert(0); return -1; }
  157. const cmChar_t* _cmUiGetStrFromStr( cmUiCtl_t* ctl )
  158. { return ctl->u.sval; }
  159. void _cmUiSetStrFromInt( cmUiCtl_t* ctl, int v )
  160. { assert(0); }
  161. void _cmUiSetStrFromDbl( cmUiCtl_t* ctl, double v )
  162. { assert(0); }
  163. void _cmUiSetStrFromStr( cmUiCtl_t* ctl, const cmChar_t* v )
  164. { ctl->u.sval = cmMemResizeStr(ctl->u.sval, v==NULL ? "" : v); }
  165. void _cmUiSetStrAccessors( cmUiCtl_t* ctl )
  166. {
  167. ctl->getInt = _cmUiGetIntFromStr;
  168. ctl->getDbl = _cmUiGetDblFromStr;
  169. ctl->getStr = _cmUiGetStrFromStr;
  170. ctl->setInt = _cmUiSetStrFromInt;
  171. ctl->setDbl = _cmUiSetStrFromDbl;
  172. ctl->setStr = _cmUiSetStrFromStr;
  173. }
  174. //---------------------------------------------------------------
  175. cmUiRC_t _cmUiCallDriver( cmUi_t* p, cmUiDId_t dId, cmUiCtl_t* ctl, unsigned flags )
  176. {
  177. cmUiRC_t rc = kOkUiRC;
  178. if( p->drvr != NULL )
  179. {
  180. unsigned orgFlags = ctl->arg.flags;
  181. ctl->arg.dId = dId;
  182. ctl->arg.flags |= flags;
  183. ctl->arg.hdr.selId = kUiDrvrSelRtId;
  184. rc = p->drvr(p->drvrArg,&ctl->arg);
  185. ctl->arg.flags = orgFlags;
  186. if( rc != kOkUiRC )
  187. rc = cmErrMsg(&p->err,kDrvrErrUiRC,"UI manager driver error.");
  188. }
  189. return rc;
  190. }
  191. cmUiRC_t _cmUiSetDriverValueInt( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, int value )
  192. {
  193. ctl->setInt(ctl,value);
  194. ctl->arg.ival = value;
  195. return _cmUiCallDriver(p, kSetValDId, ctl, flag | kIvalUiFl);
  196. }
  197. cmUiRC_t _cmUiSetDriverValueDouble( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, double value )
  198. {
  199. ctl->setDbl(ctl,value);
  200. ctl->arg.fval = value;
  201. return _cmUiCallDriver(p, kSetValDId, ctl, flag | kFvalUiFl);
  202. }
  203. cmUiRC_t _cmUiSetDriverValueStr( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, const cmChar_t* value )
  204. {
  205. ctl->setStr(ctl,value);
  206. ctl->arg.sval = value;
  207. return _cmUiCallDriver(p, kSetValDId, ctl, flag | kSvalUiFl);
  208. }
  209. cmUiRC_t _cmUiSetDriverValueIntAndStr( cmUi_t* p, cmUiCtl_t* ctl, unsigned flag, int ival, const cmChar_t* sval )
  210. {
  211. ctl->arg.ival = ival;
  212. ctl->arg.sval = sval;
  213. return _cmUiCallDriver(p, kSetValDId, ctl, flag | kIvalUiFl|kSvalUiFl);
  214. }
  215. //---------------------------------------------------------------
  216. cmUiRC_t _cmUiFindApp( cmUi_t* p, unsigned appId, cmUiApp_t** appRef, bool errFl )
  217. {
  218. cmUiRC_t rc = kOkUiRC;
  219. cmUiApp_t* ap = NULL;
  220. // verify that the appId is a valid index
  221. if( appId < cmArrayCount(p->appArrH) )
  222. ap = cmArrayPtr(cmUiApp_t,p->appArrH,appId);
  223. // if the app record was not already allocated
  224. if( ap != NULL && ap->activeFl == false )
  225. ap = NULL;
  226. // report errors
  227. if( ap == NULL )
  228. {
  229. rc = kAppNotFoundUiRC;
  230. if( errFl )
  231. cmErrMsg(&p->err,rc,"App %i not found.", appId );
  232. }
  233. *appRef = ap;
  234. return rc;
  235. }
  236. cmUiRC_t _cmUiFindCtl( cmUi_t* p, unsigned appId, unsigned usrId, cmUiCtl_t** ctlRef, bool errFl )
  237. {
  238. cmUiRC_t rc = kOkUiRC;
  239. cmUiApp_t* ap = NULL;
  240. cmUiCtl_t* ctl = NULL;
  241. // find the app this ctl belongs to
  242. if(( rc =_cmUiFindApp(p,appId,&ap,errFl)) != kOkUiRC )
  243. goto errLabel;
  244. // verify that the usrId is a valid index
  245. if( usrId < cmArrayCount(ap->ctlArrH) )
  246. ctl = cmArrayPtr(cmUiCtl_t,ap->ctlArrH,usrId);
  247. // verify that the usrId of the recd matches the requested usr id
  248. if( ctl!=NULL && ctl->usrId != usrId )
  249. ctl = NULL;
  250. // report errors
  251. if( ctl==NULL )
  252. {
  253. rc = kCtlNotFoundUiRC;
  254. if( errFl )
  255. cmErrMsg(&p->err,rc,"Control %i not found.",usrId);
  256. }
  257. errLabel:
  258. *ctlRef = ctl;
  259. return rc;
  260. }
  261. cmUiRC_t _cmUiFastFindCtl( cmUi_t* p, unsigned appId, unsigned usrId, cmUiCtl_t** ctlRef, bool errFl )
  262. {
  263. assert( appId < cmArrayCount(p->appArrH) );
  264. cmUiApp_t* ap = cmArrayPtr(cmUiApp_t,p->appArrH,appId);
  265. assert( ap->activeFl && usrId < cmArrayCount(ap->ctlArrH) );
  266. *ctlRef = cmArrayPtr(cmUiCtl_t,ap->ctlArrH,usrId);
  267. assert( (*ctlRef)->usrId == usrId && (*ctlRef)->arg.appId == ap->appId );
  268. return kOkUiRC;
  269. }
  270. cmUiRC_t _cmUiFindPanel( cmUi_t* p, unsigned appId, unsigned panelId, cmUiPanel_t** ppRef, bool errFl )
  271. {
  272. cmUiRC_t rc = kOkUiRC;
  273. cmUiApp_t* ap = NULL;
  274. unsigned i,n;
  275. *ppRef = NULL;
  276. // find the app this ctl belongs to
  277. if(( rc =_cmUiFindApp(p,appId,&ap,errFl)) != kOkUiRC )
  278. goto errLabel;
  279. n = cmArrayCount(ap->pnlArrH);
  280. for(i=0; i<n; ++i)
  281. if( (*ppRef = cmArrayPtr(cmUiPanel_t,ap->pnlArrH,i))->usrId == panelId )
  282. break;
  283. errLabel:
  284. if(*ppRef == NULL)
  285. {
  286. rc = kPanelNotFoundUiRC;
  287. if( errFl )
  288. cmErrMsg(&p->err,rc,"Panel %i was not found.",panelId);
  289. }
  290. return rc;
  291. }
  292. //---------------------------------------------------------------
  293. void _cmUiReleaseListEles( cmUiCtl_t* ctl )
  294. {
  295. if( cmArrayIsValid(ctl->idArrH) )
  296. {
  297. unsigned n = cmArrayCount(ctl->idArrH);
  298. unsigned i;
  299. for(i=0; i<n; ++i)
  300. cmMemFree( cmArrayPtr(cmUiListEle_t,ctl->idArrH,i)->label );
  301. }
  302. }
  303. cmUiRC_t _cmUiDestroyCtl( cmUi_t* p, cmUiCtl_t* ctl, bool drvrFl )
  304. {
  305. cmUiRC_t rc = kOkUiRC;
  306. if( drvrFl )
  307. rc = _cmUiCallDriver(p,kDestroyCtlDId,ctl,0);
  308. switch(ctl->cId)
  309. {
  310. case kLabelUiCId:
  311. case kStringUiCId:
  312. case kConsoleUiCId:
  313. case kFilenameUiCId:
  314. case kDirUiCId:
  315. cmMemFree(ctl->u.sval);
  316. break;
  317. default:
  318. break;
  319. }
  320. ctl->cId = kInvalidUiCId;
  321. ctl->usrId = cmInvalidId;
  322. ctl->panelId = cmInvalidId;
  323. _cmUiReleaseListEles(ctl);
  324. cmArrayRelease(&ctl->idArrH);
  325. return rc;
  326. }
  327. cmUiRC_t _cmUiDestroyPanel( cmUi_t* p, unsigned appId, unsigned panelId )
  328. {
  329. cmUiRC_t rc = kOkUiRC;
  330. cmUiPanel_t* pp = NULL;
  331. // get the panel recd ptr
  332. if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC )
  333. return rc;
  334. cmUiApp_t* ap = pp->appPtr;
  335. // notify the driver to destroy the panel
  336. if((rc = _cmUiCallDriver(p,kDestroyCtlDId,pp->ctl,0)) != kOkUiRC )
  337. return rc;
  338. cmUiCtl_t* ctl = NULL;
  339. unsigned i = 0;
  340. unsigned n = cmArrayCount(ap->ctlArrH);
  341. cmUiRC_t rc0;
  342. // Destroy all controls that belong to this panel.
  343. // Notice that _cmUiDestroyCtl() does not need to call the driver
  344. // because destroying the drivers panel has implicitely also
  345. // destroyed all the contols assigned to it.
  346. for(i=0; i<n; ++i)
  347. if( _cmUiFindCtl(p,appId,i,&ctl,false) == kOkUiRC && ctl != NULL && ctl->panelId == panelId)
  348. if((rc0 = _cmUiDestroyCtl(p,ctl,false)) != kOkUiRC )
  349. rc = rc0;
  350. // release the panel record
  351. pp->appPtr = NULL;
  352. pp->usrId = cmInvalidId;
  353. return rc;
  354. }
  355. cmUiRC_t _cmUiDestroyApp( cmUi_t* p, unsigned appId, bool errFl )
  356. {
  357. cmUiRC_t rc = kOkUiRC;
  358. cmUiRC_t rc0;
  359. cmUiApp_t* ap;
  360. // find the app to destroy
  361. if( _cmUiFindApp(p,appId,&ap,false) != kOkUiRC )
  362. {
  363. if( errFl )
  364. rc = cmErrMsg(&p->err,kAppNotFoundUiRC,"The app %i was not found for destruction.",appId);
  365. goto errLabel;
  366. }
  367. assert( ap != NULL );
  368. // destroy all panels owned by this app
  369. unsigned i;
  370. unsigned n = cmArrayCount(ap->pnlArrH);
  371. for(i=0; i<n; ++i)
  372. {
  373. cmUiPanel_t* pp = cmArrayPtr(cmUiPanel_t,ap->pnlArrH,i);
  374. if( pp->usrId != cmInvalidId )
  375. if((rc0 = _cmUiDestroyPanel(p,appId,pp->usrId)) != kOkUiRC )
  376. rc = rc0;
  377. }
  378. ap->appId = -1;
  379. ap->activeFl = false;
  380. cmArrayRelease(&ap->ctlArrH);
  381. cmArrayRelease(&ap->pnlArrH);
  382. errLabel:
  383. //p->curAppId = orgAppId;
  384. return rc;
  385. }
  386. cmUiRC_t _cmUiDestroyAllApps( cmUi_t* p )
  387. {
  388. cmUiRC_t rc = kOkUiRC;
  389. unsigned n = cmArrayCount(p->appArrH);
  390. unsigned i;
  391. for(i=0; i<n; ++i)
  392. {
  393. cmUiRC_t rc0;
  394. if((rc0 = _cmUiDestroyApp(p,i,false)) != kOkUiRC )
  395. rc = rc0;
  396. }
  397. cmArrayClear(p->appArrH,false);
  398. return rc;
  399. }
  400. //---------------------------------------------------------------
  401. cmUiRC_t _cmUiGetCtlXYWH( cmUi_t* p, cmUiDriverArg_t* a, cmUiPanel_t* pp )
  402. {
  403. if( cmIsFlag(pp->flags,kUseRectUiFl ) )
  404. {
  405. pp->flags = cmClrFlag(pp->flags,kUseRectUiFl);
  406. a->x = pp->rect.x;
  407. a->y = pp->rect.y;
  408. a->w = pp->rect.w;
  409. a->h = pp->rect.h;
  410. return kOkUiRC;
  411. }
  412. if( pp->prevRect.x == -1 )
  413. pp->prevRect.x = pp->baseCol;
  414. if( pp->prevRect.y == -1 )
  415. pp->prevRect.y = pp->baseRow;
  416. if( pp->prevRect.w == -1 )
  417. pp->prevRect.w = 0;
  418. if( pp->prevRect.h == -1 )
  419. pp->prevRect.h = 0;
  420. // Get direction flag. Fill across rows? or down columns?
  421. bool fillRowFl = cmIsFlag(pp->flags,kFillRowsUiFl);
  422. // the 'place to right' flag overrides the directon flag for just this instance
  423. if( cmIsFlag(pp->flags,kPlaceRightUiFl ) )
  424. fillRowFl = true;
  425. // the 'place under' flag overides the direction flag for just this instance
  426. if( cmIsFlag(pp->flags,kPlaceBelowUiFl ) )
  427. fillRowFl = false;
  428. // set x coord - if filling acros rows ...
  429. if( fillRowFl )
  430. a->x = pp->prevRect.x + pp->prevRect.w + pp->nextHBorder;
  431. else
  432. a->x = pp->baseCol; // ... or down columns
  433. // if a new column was set then move to the base row
  434. if( cmIsFlag(pp->flags,kPlaceBaseRowUiFl) )
  435. a->y = pp->baseRow;
  436. else
  437. {
  438. // set y coord - if filling acros rows ...
  439. if( fillRowFl )
  440. a->y = pp->prevRect.y;
  441. else
  442. a->y = pp->prevRect.y + pp->prevRect.h + pp->nextVBorder; // ... or down columns
  443. }
  444. a->w = pp->nextW;
  445. a->h = pp->nextH;
  446. pp->prevRect.x = a->x;
  447. pp->prevRect.y = a->y;
  448. pp->prevRect.w = a->w;
  449. pp->prevRect.h = a->h;
  450. pp->nextW = pp->dfltW;
  451. pp->nextH = pp->dfltH;
  452. pp->nextHBorder = pp->dfltHBorder;
  453. pp->nextVBorder = pp->dfltVBorder;
  454. pp->flags = cmClrFlag(pp->flags,kNextWHUiFl | kPlaceRightUiFl | kPlaceBelowUiFl | kPlaceBaseRowUiFl );
  455. return kOkUiRC;
  456. }
  457. cmUiRC_t _cmUiCreateCtl( cmUi_t* p, unsigned appId, unsigned panelId, cmUiCId_t cId, unsigned usrId, const cmChar_t* label, unsigned flags, cmUiCtl_t** ctlRef )
  458. {
  459. cmUiRC_t rc;
  460. cmUiPanel_t* pp = NULL;
  461. cmUiApp_t* ap = NULL;
  462. if( ctlRef != NULL )
  463. *ctlRef = NULL;
  464. // locate the app
  465. if((rc = _cmUiFindApp(p,appId,&ap,true)) != kOkUiRC )
  466. return rc;
  467. // locate the panel the control belongs to
  468. if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC )
  469. return rc;
  470. // get the new ctl record
  471. cmUiCtl_t* ctl;
  472. if( usrId == cmInvalidId )
  473. {
  474. ctl = &p->dummy;
  475. memset(ctl,0,sizeof(*ctl));
  476. }
  477. else
  478. {
  479. if( cmArrayIsValid(ap->ctlArrH) == false || usrId >= cmArrayCount(ap->ctlArrH) )
  480. ctl = cmArrayClr(cmUiCtl_t,ap->ctlArrH,usrId);
  481. else
  482. {
  483. ctl = cmArrayPtr(cmUiCtl_t,ap->ctlArrH,usrId);
  484. // if the ctl recd is already in use
  485. if( ctl->cId != kInvalidUiCId )
  486. _cmUiDestroyCtl(p,ctl,true);
  487. }
  488. }
  489. // setup this controls cached callback arg record
  490. cmUiDriverArgSetup(&ctl->arg,ap->rtSubIdx,cmInvalidId,kInvalidDId,ap->appId,usrId,panelId,cId,flags,0,0,label,-1,-1,-1,-1);
  491. // calc the control location - for non-panel controls
  492. if( cId != kPanelUiCId )
  493. if((rc = _cmUiGetCtlXYWH(p,&ctl->arg,pp)) != kOkUiRC )
  494. return rc;
  495. // setup the new ctl record
  496. ctl->cId = cId;
  497. ctl->usrId = usrId;
  498. ctl->panelId = panelId;
  499. // display-only controls don't need an id array
  500. if( usrId != cmInvalidId )
  501. cmArrayAlloc(p->ctx,&ctl->idArrH,sizeof(cmUiListEle_t));
  502. if( ctlRef != NULL )
  503. *ctlRef = ctl;
  504. return _cmUiCallDriver(p,kCreateCtlDId,ctl,0);
  505. }
  506. cmUiRC_t cmUiAlloc(
  507. cmCtx_t* ctx,
  508. cmUiH_t* uiHPtr,
  509. cmUiDriverFunc_t drvrFunc,
  510. void* drvrArg,
  511. cmUiDriverFunc_t cbFunc,
  512. void * cbArg)
  513. {
  514. cmUiRC_t rc;
  515. if((rc = cmUiFree(uiHPtr)) != kOkUiRC )
  516. return rc;
  517. cmUi_t* p = cmMemAllocZ(cmUi_t,1);
  518. cmErrSetup(&p->err,&ctx->rpt,"cmUi");
  519. p->ctx = ctx;
  520. p->drvr = drvrFunc;
  521. p->drvrArg = drvrArg;
  522. p->cbFunc = cbFunc;
  523. p->cbArg = cbArg;
  524. p->panelW = 1000;
  525. p->panelH = 500;
  526. cmArrayAlloc(p->ctx,&p->appArrH,sizeof(cmUiApp_t));
  527. uiHPtr->h = p;
  528. return rc;
  529. }
  530. cmUiRC_t cmUiFree( cmUiH_t* hp )
  531. {
  532. cmUiRC_t rc = kOkUiRC;
  533. if( hp == NULL || cmUiIsValid(*hp) == false )
  534. return kOkUiRC;
  535. cmUi_t* p = _cmUiHandleToPtr(*hp);
  536. if((rc = _cmUiDestroyAllApps(p)) != kOkUiRC )
  537. return rc;
  538. cmArrayRelease(&p->appArrH);
  539. cmMemFree(p);
  540. hp->h = NULL;
  541. return rc;
  542. }
  543. bool cmUiIsValid( cmUiH_t h )
  544. { return h.h != NULL; }
  545. void cmUiSetDriver( cmUiH_t h, cmUiDriverFunc_t drvrFunc, void* drvrArg )
  546. {
  547. cmUi_t* p = _cmUiHandleToPtr(h);
  548. p->drvr = drvrFunc;
  549. p->drvrArg = drvrArg;
  550. }
  551. cmUiRC_t cmUiCreateApp( cmUiH_t h, unsigned appId, unsigned rtSubIdx )
  552. {
  553. cmUiRC_t rc = kOkUiRC;
  554. if( cmUiIsValid(h) == false)
  555. return rc;
  556. cmUi_t* p = _cmUiHandleToPtr(h);
  557. cmUiApp_t* ap = NULL;
  558. // verify that the requested app does not exist
  559. if( _cmUiFindApp(p,appId, &ap, false ) == kOkUiRC )
  560. return cmErrMsg(&p->err,kInvalidIdUiRC,"The id (%i) of the new application is already in use.",appId);
  561. ap = cmArrayClr(cmUiApp_t,p->appArrH,appId);
  562. ap->appId = appId;
  563. ap->rtSubIdx = rtSubIdx;
  564. ap->activeFl = true;
  565. cmArrayAlloc(p->ctx,&ap->ctlArrH,sizeof(cmUiCtl_t));
  566. cmArrayAlloc(p->ctx,&ap->pnlArrH,sizeof(cmUiPanel_t));
  567. return rc;
  568. }
  569. bool cmUiAppIsActive( cmUiH_t uiH, unsigned appId )
  570. {
  571. cmUi_t* p = _cmUiHandleToPtr(uiH);
  572. cmUiApp_t* ap = NULL;
  573. return _cmUiFindApp(p,appId, &ap, false ) == kOkUiRC;
  574. }
  575. cmUiRC_t cmUiDestroyApp( cmUiH_t h, unsigned appId )
  576. {
  577. if( cmUiIsValid(h)==false)
  578. return kOkUiRC;
  579. cmUi_t* p = _cmUiHandleToPtr(h);
  580. return _cmUiDestroyApp(p,appId,true);
  581. }
  582. cmUiRC_t cmUiDestroyAllApps( cmUiH_t h )
  583. {
  584. if( cmUiIsValid(h)==false)
  585. return kOkUiRC;
  586. cmUi_t* p = _cmUiHandleToPtr(h);
  587. return _cmUiDestroyAllApps(p);
  588. }
  589. unsigned cmUiAppIdToAsSubIndex( cmUiH_t uiH, unsigned appId )
  590. {
  591. cmUi_t* p = _cmUiHandleToPtr(uiH);
  592. cmUiApp_t* ap = NULL;
  593. if( _cmUiFindApp(p,appId, &ap, true ) != kOkUiRC )
  594. return cmInvalidIdx;
  595. return ap->rtSubIdx;
  596. }
  597. unsigned cmUiAppCount( cmUiH_t h )
  598. {
  599. if( cmUiIsValid(h)==false)
  600. return 0;
  601. cmUi_t* p = _cmUiHandleToPtr(h);
  602. return cmArrayCount(p->appArrH);
  603. }
  604. cmUiRC_t _cmUiCallClient( cmUi_t* p, cmUiDId_t dId, cmUiCtl_t* ctl, unsigned flags )
  605. {
  606. unsigned orgFlags = ctl->arg.flags;
  607. ctl->arg.hdr.selId = kUiSelRtId,
  608. ctl->arg.flags |= flags;
  609. ctl->arg.dId = dId;
  610. cmUiRC_t rc = p->cbFunc(p->cbArg,&ctl->arg);
  611. ctl->arg.dId = kInvalidDId;
  612. ctl->arg.flags = orgFlags;
  613. ctl->arg.hdr.selId = cmInvalidId;
  614. return rc;
  615. }
  616. cmUiRC_t cmUiOnDriverEvent( cmUiH_t h, const cmUiDriverArg_t* arg )
  617. {
  618. cmUiRC_t rc = kOkUiRC;
  619. cmUi_t* p = _cmUiHandleToPtr(h);
  620. cmUiCtl_t* ctl;
  621. //unsigned orgAppId = cmUiAppId(h);
  622. //if((rc = cmUiSetAppId(h,arg->appId)) != kOkUiRC )
  623. // return rc;
  624. if((rc = _cmUiFindCtl(p,arg->appId,arg->usrId,&ctl,true)) != kOkUiRC )
  625. goto errLabel;
  626. switch( arg->dId )
  627. {
  628. case kEnableDId:
  629. ctl->arg.ival = arg->ival;
  630. return _cmUiCallClient(p,kEnableDId,ctl,arg->flags);
  631. case kSetValDId:
  632. break;
  633. default:
  634. assert(0);
  635. break;
  636. }
  637. switch( arg->cId )
  638. {
  639. case kInvalidUiCId:
  640. break;
  641. case kPanelUiCId:
  642. case kBtnUiCId:
  643. case kCheckUiCId:
  644. ctl->arg.ival = ctl->u.ival = cmUiDriverArgGetInt(arg);
  645. break;
  646. case kMenuBtnUiCId:
  647. case kListUiCId:
  648. {
  649. if( cmIsFlag(arg->flags,kValUiFl ) )
  650. {
  651. unsigned eleIdx = cmUiDriverArgGetInt(arg);
  652. if(eleIdx >= cmArrayCount(ctl->idArrH))
  653. {
  654. rc = cmErrMsg(&p->err,kInvalidIdUiRC,"Invalid menu or list driver element id=%i element count:%i.",eleIdx,cmArrayCount(ctl->idArrH));
  655. goto errLabel;
  656. }
  657. // convert the selected items index to the associated client id value
  658. unsigned eleId = cmArrayPtr(cmUiListEle_t,ctl->idArrH,eleIdx)->id;
  659. ctl->setInt(ctl,eleId);
  660. ctl->arg.ival = eleId;
  661. }
  662. }
  663. break;
  664. case kConsoleUiCId:
  665. {
  666. const cmChar_t* s;
  667. if((s = cmUiDriverArgGetString(arg)) != NULL )
  668. ctl->arg.sval = ctl->u.sval = cmTextAppendSS(ctl->u.sval, s );
  669. }
  670. break;
  671. case kLabelUiCId:
  672. case kStringUiCId:
  673. case kFilenameUiCId:
  674. case kDirUiCId:
  675. {
  676. const cmChar_t* s;
  677. if((s = cmUiDriverArgGetString(arg)) != NULL )
  678. ctl->arg.sval = ctl->u.sval = cmMemResizeStr(ctl->u.sval,s);
  679. }
  680. break;
  681. case kSliderUiCId:
  682. case kNumberUiCId:
  683. ctl->arg.fval = ctl->u.fval = cmUiDriverArgGetDouble(arg);
  684. break;
  685. case kProgressUiCId:
  686. case kMeterUiCId:
  687. ctl->arg.ival = ctl->u.ival = cmUiDriverArgGetInt(arg);
  688. break;
  689. case kMaxUiCId:
  690. assert(0);
  691. break;
  692. }
  693. // reflect the event to the client
  694. if( cmIsNotFlag(arg->flags, kNoReflectUiFl ) )
  695. {
  696. rc = _cmUiCallClient(p,kSetValDId,ctl,0);
  697. }
  698. errLabel:
  699. //cmUiSetAppId(h,orgAppId);
  700. return rc;
  701. }
  702. void _cmUiPanelSetDefaultValues( cmUiPanel_t* pp)
  703. {
  704. pp->baseCol = 2;
  705. pp->baseRow = 2;
  706. pp->dfltW = 150;
  707. pp->dfltH = 25;
  708. pp->nextW = pp->dfltW;
  709. pp->nextH = pp->dfltH;
  710. pp->dfltHBorder= 2;
  711. pp->dfltVBorder= 2;
  712. pp->nextHBorder= pp->dfltHBorder;
  713. pp->nextVBorder= pp->dfltVBorder;
  714. pp->prevRect.x = -1;
  715. pp->prevRect.y = -1;
  716. pp->prevRect.w = -1;
  717. pp->prevRect.h = -1;
  718. }
  719. cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned appId, unsigned newPanelId, const cmChar_t* label, unsigned flags )
  720. {
  721. cmUiRC_t rc;
  722. cmUi_t* p = _cmUiHandleToPtr(uiH);
  723. cmUiCtl_t* ctl = NULL;
  724. cmUiApp_t* ap = NULL;
  725. if(( rc = _cmUiFindApp(p,appId,&ap,true)) != kOkUiRC )
  726. return rc;
  727. cmUiPanel_t* pp = cmArrayPush(ap->pnlArrH,NULL,1);
  728. assert( pp != NULL );
  729. pp->appPtr = ap;
  730. pp->ctl = NULL;
  731. pp->usrId = newPanelId;
  732. _cmUiPanelSetDefaultValues(pp);
  733. if((rc = _cmUiCreateCtl(p, appId, newPanelId, kPanelUiCId, newPanelId, label, flags, &pp->ctl )) != kOkUiRC )
  734. {
  735. // TODO - destroy panel record here
  736. return rc;
  737. }
  738. _cmUiFindCtl(p,appId,newPanelId,&ctl,true);
  739. assert(ctl!=NULL);
  740. ctl->u.pnl = pp;
  741. return rc;
  742. }
  743. cmUiRC_t cmUiCreateBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags )
  744. {
  745. cmUiRC_t rc;
  746. cmUi_t* p = _cmUiHandleToPtr(uiH);
  747. cmUiCtl_t* c;
  748. if((rc = _cmUiCreateCtl(p,appId,panelId,kBtnUiCId,id,label,flags,&c)) == kOkUiRC )
  749. {
  750. _cmUiSetIntAccessors(c);
  751. }
  752. return rc;
  753. }
  754. cmUiRC_t cmUiCreateCheck( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, bool dflt )
  755. {
  756. cmUiRC_t rc;
  757. cmUi_t* p = _cmUiHandleToPtr(uiH);
  758. cmUiCtl_t* c;
  759. if((rc = _cmUiCreateCtl(p,appId,panelId,kCheckUiCId,id,label,flags,&c)) == kOkUiRC )
  760. {
  761. _cmUiSetIntAccessors(c);
  762. rc = _cmUiSetDriverValueInt(p,c,kValUiFl | kNoReflectUiFl,dflt);
  763. }
  764. return rc;
  765. }
  766. cmUiRC_t cmUiCreateLabel( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags )
  767. {
  768. cmUiRC_t rc;
  769. cmUi_t* p = _cmUiHandleToPtr(uiH);
  770. cmUiCtl_t* c;
  771. if((rc = _cmUiCreateCtl(p,appId,panelId,kLabelUiCId,id,label,flags,&c)) == kOkUiRC )
  772. _cmUiSetStrAccessors(c);
  773. return rc;
  774. }
  775. cmUiRC_t cmUiCreateString( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text )
  776. {
  777. cmUiRC_t rc = kOkUiRC;
  778. cmUi_t* p = _cmUiHandleToPtr(uiH);
  779. cmUiCtl_t* c;
  780. if(( rc = _cmUiCreateCtl(p,appId,panelId,kStringUiCId,id,label,flags,&c)) == kOkUiRC )
  781. {
  782. _cmUiSetStrAccessors(c);
  783. rc = _cmUiSetDriverValueStr(p,c,kValUiFl | kNoReflectUiFl,text);
  784. }
  785. return rc;
  786. }
  787. cmUiRC_t cmUiCreateConsole( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text )
  788. {
  789. cmUiRC_t rc = kOkUiRC;
  790. cmUi_t* p = _cmUiHandleToPtr(uiH);
  791. cmUiCtl_t* c;
  792. if(( rc = _cmUiCreateCtl(p,appId,panelId,kConsoleUiCId,id,label,flags,&c)) == kOkUiRC )
  793. {
  794. _cmUiSetStrAccessors(c);
  795. rc = _cmUiSetDriverValueStr(p,c,kValUiFl | kNoReflectUiFl,text);
  796. }
  797. return rc;
  798. }
  799. 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 )
  800. {
  801. cmUiRC_t rc = kOkUiRC;
  802. cmUi_t* p = _cmUiHandleToPtr(uiH);
  803. cmUiCId_t cid = kNumberUiCId;
  804. cmUiCtl_t* c;
  805. cmUiPanel_t* pp;
  806. if( cmIsFlag(flags,kVertUiFl|kHorzUiFl) )
  807. {
  808. if( cmIsFlag(flags,kVertUiFl) )
  809. {
  810. if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC )
  811. return rc;
  812. // if the size of the control was not excplicitly set
  813. // then swap width and height
  814. if( cmIsNotFlag(pp->flags,kNextWHUiFl) && cmIsNotFlag(pp->flags,kUseRectUiFl) )
  815. cmUiSetNextWH( uiH, appId, panelId, cmUiH(uiH,appId,panelId), cmUiW(uiH,appId,panelId) );
  816. }
  817. cid = kSliderUiCId;
  818. }
  819. if(( rc = _cmUiCreateCtl(p,appId,panelId,cid,id,label,flags,&c)) == kOkUiRC )
  820. {
  821. cmUiRC_t rc0;
  822. _cmUiSetDblAccessors(c);
  823. if((rc0 = _cmUiSetDriverValueDouble(p,c,kMinUiFl | kNoReflectUiFl,min)) != kOkUiRC )
  824. rc = rc0;
  825. if((rc0 = _cmUiSetDriverValueDouble(p,c,kMaxUiFl | kNoReflectUiFl,max)) != kOkUiRC )
  826. rc = rc0;
  827. if((rc0 = _cmUiSetDriverValueDouble(p,c,kIncUiFl | kNoReflectUiFl,incr)) != kOkUiRC )
  828. rc = rc0;
  829. if((rc0 = _cmUiSetDriverValueDouble(p,c,kValUiFl | kNoReflectUiFl,dflt)) != kOkUiRC )
  830. rc = rc0;
  831. }
  832. return rc;
  833. }
  834. 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 )
  835. {
  836. return _cmUiCreateNumber(uiH,appId,panelId,id,label,flags,min,max,incr,dflt);
  837. }
  838. 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 )
  839. {
  840. return _cmUiCreateNumber(uiH,appId,panelId,id,label,flags | kHorzUiFl, min,max,incr,dflt);
  841. }
  842. 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 )
  843. {
  844. return _cmUiCreateNumber(uiH,appId,panelId,id,label,flags | kVertUiFl, min,max,incr,dflt);
  845. }
  846. cmUiRC_t cmUiCreateProgress(cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt )
  847. {
  848. cmUiRC_t rc = kOkUiRC;
  849. cmUi_t* p = _cmUiHandleToPtr(uiH);
  850. cmUiCtl_t* c;
  851. if(( rc = _cmUiCreateCtl(p,appId,panelId,kProgressUiCId,id,label,flags,&c)) == kOkUiRC )
  852. {
  853. cmUiRC_t rc0;
  854. _cmUiSetIntAccessors(c);
  855. if((rc0 = _cmUiSetDriverValueInt(p,c,kMinUiFl | kNoReflectUiFl,min)) != kOkUiRC )
  856. rc = rc0;
  857. if((rc0 = _cmUiSetDriverValueInt(p,c,kMaxUiFl | kNoReflectUiFl,max)) != kOkUiRC )
  858. rc = rc0;
  859. if((rc0 = _cmUiSetDriverValueInt(p,c,kValUiFl | kNoReflectUiFl,dflt)) != kOkUiRC )
  860. rc = rc0;
  861. }
  862. return rc;
  863. }
  864. cmUiRC_t _cmUiCreateMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt)
  865. {
  866. cmUiRC_t rc;
  867. cmUi_t* p = _cmUiHandleToPtr(uiH);
  868. cmUiCtl_t* c;
  869. cmUiPanel_t* pp;
  870. if( cmIsFlag(flags,kVertUiFl) )
  871. {
  872. if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC )
  873. return rc;
  874. // if the size of the control has not been explicitely set
  875. // then swap height and width for vertical meters.
  876. if( cmIsNotFlag(pp->flags,kNextWHUiFl) && cmIsNotFlag(pp->flags,kUseRectUiFl) )
  877. cmUiSetNextWH( uiH, appId, panelId, cmUiH(uiH,appId,panelId), cmUiW(uiH,appId,panelId) );
  878. }
  879. if((rc = _cmUiCreateCtl(p,appId,panelId,kMeterUiCId,id,label,flags,&c)) == kOkUiRC )
  880. {
  881. cmUiRC_t rc0;
  882. _cmUiSetIntAccessors(c);
  883. if((rc0 = _cmUiSetDriverValueInt(p,c,kMinUiFl | kNoReflectUiFl,min)) != kOkUiRC )
  884. rc = rc0;
  885. if((rc0 = _cmUiSetDriverValueInt(p,c,kMaxUiFl | kNoReflectUiFl,max)) != kOkUiRC )
  886. rc = rc0;
  887. if((rc0 = _cmUiSetDriverValueInt(p,c,kValUiFl | kNoReflectUiFl,dflt)) != kOkUiRC )
  888. rc = rc0;
  889. }
  890. return rc;
  891. }
  892. cmUiRC_t cmUiCreateHMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt )
  893. {
  894. return _cmUiCreateMeter(uiH,appId,panelId,id,label,flags | kHorzUiFl,min,max,dflt);
  895. }
  896. cmUiRC_t cmUiCreateVMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt )
  897. {
  898. return _cmUiCreateMeter(uiH,appId,panelId,id,label,flags | kVertUiFl,min,max,dflt);
  899. }
  900. 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 )
  901. {
  902. cmUiRC_t rc = kOkUiRC;
  903. cmUi_t* p = _cmUiHandleToPtr(uiH);
  904. cmUiCtl_t* c;
  905. if(( rc = _cmUiCreateCtl(p,appId,panelId,kFilenameUiCId,id,label,flags,&c)) == kOkUiRC )
  906. {
  907. cmUiRC_t rc0;
  908. _cmUiSetStrAccessors(c);
  909. if( dfltDir != NULL )
  910. {
  911. if((rc0 = _cmUiSetDriverValueStr(p,c,kFnDirUiFl | kNoReflectUiFl,dfltDir)) != kOkUiRC )
  912. rc = rc0;
  913. }
  914. if( patStr != NULL )
  915. {
  916. if((rc0 = _cmUiSetDriverValueStr(p,c,kFnPatUiFl | kNoReflectUiFl,patStr)) != kOkUiRC )
  917. rc = rc0;
  918. }
  919. }
  920. return rc;
  921. }
  922. cmUiRC_t cmUiCreateDirBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir )
  923. {
  924. cmUiRC_t rc = kOkUiRC;
  925. cmUi_t* p = _cmUiHandleToPtr(uiH);
  926. cmUiCtl_t* c;
  927. if(( rc = _cmUiCreateCtl(p,appId,panelId,kDirUiCId,id,label,flags,&c)) == kOkUiRC )
  928. {
  929. cmUiRC_t rc0;
  930. _cmUiSetStrAccessors(c);
  931. if( dfltDir != NULL )
  932. {
  933. if((rc0 = _cmUiSetDriverValueStr(p,c,kValUiFl | kNoReflectUiFl,dfltDir)) != kOkUiRC )
  934. rc = rc0;
  935. }
  936. }
  937. return rc;
  938. }
  939. cmUiRC_t cmUiCreateMenuBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags )
  940. {
  941. cmUiRC_t rc;
  942. cmUi_t* p = _cmUiHandleToPtr(uiH);
  943. cmUiCtl_t* c;
  944. if((rc = _cmUiCreateCtl(p,appId,panelId,kMenuBtnUiCId,id,label,flags,&c)) == kOkUiRC )
  945. _cmUiSetIntAccessors(c);
  946. return rc;
  947. }
  948. 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 )
  949. {
  950. cmUiRC_t rc = kOkUiRC;
  951. // TODO:
  952. return rc;
  953. }
  954. cmUiRC_t cmUiCreateMenuBtnA(cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* label0, unsigned id0, ... )
  955. {
  956. va_list vl;
  957. va_start(vl,id0);
  958. cmUiRC_t rc = cmUiCreateMenuBtnV(uiH,appId,panelId,id,label,flags,label0,id0,vl);
  959. va_end(vl);
  960. return rc;
  961. }
  962. 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 )
  963. {
  964. cmUiRC_t rc = kOkUiRC;
  965. // TODO:
  966. return rc;
  967. }
  968. cmUiRC_t cmUiCreateList(cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt )
  969. {
  970. cmUi_t* p = _cmUiHandleToPtr(uiH);
  971. cmUiRC_t rc;
  972. cmUiCtl_t* c;
  973. cmUiPanel_t* pp;
  974. if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC )
  975. return rc;
  976. if( cmIsNotFlag(pp->flags,kNextWHUiFl) )
  977. cmUiSetNextWH( uiH, appId, panelId, cmUiNextW(uiH,appId,panelId), cmUiH(uiH,appId,panelId) * visibleRowCnt );
  978. if((rc = _cmUiCreateCtl(p,appId,panelId,kListUiCId,id,label,flags,&c)) == kOkUiRC )
  979. _cmUiSetIntAccessors(c);
  980. return rc;
  981. }
  982. 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 )
  983. {
  984. cmUiRC_t rc = kOkUiRC;
  985. // TODO:
  986. return rc;
  987. }
  988. 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, ... )
  989. {
  990. va_list vl;
  991. va_start(vl,id0);
  992. cmUiRC_t rc = cmUiCreateListV(uiH,appId,panelId,id,label,flags,visibleRowCnt,label0,id0,vl);
  993. va_end(vl);
  994. return rc;
  995. }
  996. 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 )
  997. {
  998. cmUiRC_t rc = kOkUiRC;
  999. // TODO:
  1000. return rc;
  1001. }
  1002. cmUiRC_t cmUiAppendListEle( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* text, unsigned eleId )
  1003. {
  1004. cmUiRC_t rc = kOkUiRC;
  1005. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1006. cmUiCtl_t* ctl = NULL;
  1007. if((rc = _cmUiFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1008. return rc;
  1009. if( ctl->cId != kListUiCId && ctl->cId != kMenuBtnUiCId )
  1010. return cmErrMsg(&p->err,kInvalidCtlOpUiRC,"List elements may only be set on 'list' and 'menu button' controls.");
  1011. // set the local value
  1012. cmUiListEle_t ele;
  1013. ele.id = eleId;
  1014. ele.label = cmMemAllocStr(text);
  1015. cmArrayPush(ctl->idArrH,&ele,1);
  1016. return _cmUiSetDriverValueIntAndStr(p,ctl,kAppendUiFl,eleId,text);
  1017. }
  1018. cmUiRC_t cmUiClearList( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id )
  1019. {
  1020. cmUiRC_t rc = kOkUiRC;
  1021. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1022. cmUiCtl_t* ctl = NULL;
  1023. if((rc = _cmUiFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1024. return rc;
  1025. // verify that this is a list or menu btn
  1026. if( ctl->cId != kListUiCId && ctl->cId != kMenuBtnUiCId )
  1027. return cmErrMsg(&p->err,kInvalidCtlOpUiRC,"List elements may only be cleared on 'list' and 'menu button' controls.");
  1028. // call the driver
  1029. if((rc = _cmUiSetDriverValueInt(p, ctl, kClearUiFl, 0 )) != kOkUiRC )
  1030. return rc;
  1031. // clear the ctl's id array
  1032. if( cmArrayIsValid(ctl->idArrH) )
  1033. {
  1034. _cmUiReleaseListEles(ctl);
  1035. cmArrayClear(ctl->idArrH,false);
  1036. }
  1037. return rc;
  1038. }
  1039. cmUiRC_t cmUiEnableCtl( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, bool enableFl )
  1040. {
  1041. cmUiRC_t rc = kOkUiRC;
  1042. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1043. cmUiCtl_t* ctl = NULL;
  1044. if((rc = _cmUiFindCtl(p,appId,id,&ctl,true)) == kOkUiRC )
  1045. {
  1046. ctl->arg.ival = enableFl ? 1 : 0;
  1047. rc = _cmUiCallDriver(p, kEnableDId, ctl, kIvalUiFl );
  1048. }
  1049. return rc;
  1050. }
  1051. cmUiRC_t cmUiEnableAllExceptV( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, va_list vl )
  1052. {
  1053. va_list vl0;
  1054. cmUiRC_t rc = kOkUiRC;
  1055. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1056. unsigned n = 0;
  1057. cmUiApp_t* ap = NULL;
  1058. unsigned i,j;
  1059. // get a count of exception id's
  1060. va_copy(vl0,vl);
  1061. while( va_arg(vl0,unsigned) != cmInvalidId )
  1062. ++n;
  1063. va_end(vl0);
  1064. if( n == 0 )
  1065. return rc;
  1066. // alloc array to hold exception id's
  1067. unsigned id[n];
  1068. // store the exception id's
  1069. for(i=0; i<n; ++i)
  1070. id[i] = va_arg(vl,unsigned);
  1071. // locate the current app recd
  1072. if((rc = _cmUiFindApp(p,appId,&ap,true)) != kOkUiRC )
  1073. return rc;
  1074. // get a count of ctl's assigned to panel
  1075. unsigned ctlN = cmArrayCount(ap->ctlArrH);
  1076. // for each control
  1077. for(i=0; i<ctlN; ++i)
  1078. {
  1079. // get the control recd
  1080. cmUiCtl_t* ctl;
  1081. if((ctl = cmArrayPtr(cmUiCtl_t,ap->ctlArrH,i))!=NULL && ctl->panelId == panelId && ctl->usrId != panelId )
  1082. {
  1083. bool exceptFl = false;
  1084. // check if this control is in the except list
  1085. for(j=0; j<n; ++j)
  1086. if( id[j] == i )
  1087. {
  1088. exceptFl = true;
  1089. break;
  1090. }
  1091. // if the ctl is not in the except list then enable/disable it.
  1092. if( !exceptFl )
  1093. {
  1094. ctl->arg.ival = enableFl ? 1 : 0;
  1095. cmUiRC_t rc0;
  1096. if((rc0 = _cmUiCallDriver(p, kEnableDId, ctl, kIvalUiFl )) != kOkUiRC )
  1097. rc = rc0;
  1098. }
  1099. }
  1100. }
  1101. return rc;
  1102. }
  1103. cmUiRC_t cmUiEnableAllExcept( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, ... )
  1104. {
  1105. va_list vl;
  1106. va_start(vl,enableFl);
  1107. cmUiRC_t rc = cmUiEnableAllExceptV(uiH,appId,panelId,enableFl,vl);
  1108. va_end(vl);
  1109. return rc;
  1110. }
  1111. cmUiRC_t cmUiDestroyCtl( cmUiH_t uiH, unsigned appId, unsigned id )
  1112. {
  1113. cmUiRC_t rc = kOkUiRC;
  1114. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1115. cmUiCtl_t* ctl = NULL;
  1116. if((rc = _cmUiFindCtl(p,appId,id,&ctl,true)) == kOkUiRC )
  1117. {
  1118. if( ctl->cId == kPanelUiCId )
  1119. _cmUiDestroyPanel(p,appId,ctl->usrId);
  1120. else
  1121. rc = _cmUiDestroyCtl(p,ctl,true);
  1122. }
  1123. return rc;
  1124. }
  1125. bool cmUiCtlExists( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id )
  1126. {
  1127. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1128. if( panelId == id )
  1129. {
  1130. cmUiPanel_t* pp=NULL;
  1131. return _cmUiFindPanel(p, appId,panelId, &pp, false ) == kOkUiRC;
  1132. }
  1133. cmUiCtl_t* ctl=NULL;
  1134. return _cmUiFindCtl(p,appId,id,&ctl,false) == kOkUiRC;
  1135. }
  1136. cmUiRC_t cmUiClearPanel( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1137. {
  1138. cmUiRC_t rc = kOkUiRC;
  1139. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1140. cmUiPanel_t* pp = NULL;
  1141. // get the panel recd ptr
  1142. if((rc = _cmUiFindPanel(p,appId,panelId,&pp,true)) != kOkUiRC )
  1143. return rc;
  1144. cmUiApp_t* ap = pp->appPtr;
  1145. cmUiCtl_t* ctl = NULL;
  1146. unsigned i = 0;
  1147. unsigned n = cmArrayCount(ap->ctlArrH);
  1148. cmUiRC_t rc0;
  1149. // Destroy all controls that belong to this panel.
  1150. for(i=0; i<n; ++i)
  1151. if( _cmUiFindCtl(p,appId,i,&ctl,false) == kOkUiRC && ctl != NULL && ctl->panelId == panelId && ctl->usrId != panelId)
  1152. if((rc0 = _cmUiDestroyCtl(p,ctl,true)) != kOkUiRC )
  1153. rc = rc0;
  1154. // restore the layout variables to their default values.
  1155. _cmUiPanelSetDefaultValues(pp);
  1156. return rc;
  1157. }
  1158. cmUiRC_t cmUiSelectPanel( cmUiH_t uiH, const cmChar_t* label )
  1159. {
  1160. cmUiRC_t rc = kOkUiRC;
  1161. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1162. return rc;
  1163. }
  1164. cmUiRC_t cmUiNextRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int x, int y, int w, int h )
  1165. {
  1166. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1167. cmUiPanel_t* pp;
  1168. cmUiRC_t rc;
  1169. if((rc = _cmUiFindPanel(p, appId, panelId, &pp, true)) != kOkUiRC )
  1170. return rc;
  1171. pp->rect.x = x;
  1172. pp->rect.y = y;
  1173. pp->rect.w = w;
  1174. pp->rect.h = h;
  1175. pp->flags = cmSetFlag(pp->flags,kUseRectUiFl);
  1176. return rc;
  1177. }
  1178. cmUiRC_t cmUiPrevRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int* xRef, int* yRef, int* wRef, int* hRef )
  1179. {
  1180. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1181. cmUiPanel_t* pp;
  1182. cmUiRC_t rc;
  1183. if((rc = _cmUiFindPanel(p, appId, panelId, &pp, true)) != kOkUiRC )
  1184. return rc;
  1185. if( xRef != NULL )
  1186. *xRef = pp->prevRect.x;
  1187. if( yRef != NULL )
  1188. *yRef = pp->prevRect.y;
  1189. if( wRef != NULL )
  1190. *wRef = pp->prevRect.w;
  1191. if( hRef != NULL )
  1192. *hRef = pp->prevRect.h;
  1193. return rc;
  1194. }
  1195. bool cmUiFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1196. {
  1197. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1198. cmUiPanel_t* pp;
  1199. if( _cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1200. return false;
  1201. return cmIsFlag(pp->flags,kFillRowsUiFl);
  1202. }
  1203. bool cmUiSetFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl )
  1204. {
  1205. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1206. cmUiPanel_t* pp;
  1207. if( _cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1208. return false;
  1209. bool retFl = cmIsFlag(pp->flags,kFillRowsUiFl);
  1210. pp->flags = cmEnaFlag(pp->flags,kFillRowsUiFl,enableFl);
  1211. return retFl;
  1212. }
  1213. void cmUiPlaceRight( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1214. {
  1215. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1216. cmUiPanel_t* pp;
  1217. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1218. return;
  1219. pp->flags = cmClrFlag(pp->flags,kPlaceBelowUiFl);
  1220. pp->flags = cmSetFlag(pp->flags,kPlaceRightUiFl);
  1221. }
  1222. void cmUiPlaceBelow( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1223. {
  1224. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1225. cmUiPanel_t* pp;
  1226. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1227. return;
  1228. pp->flags = cmClrFlag(pp->flags,kPlaceRightUiFl);
  1229. pp->flags = cmSetFlag(pp->flags,kPlaceBelowUiFl);
  1230. }
  1231. void cmUiNewLine( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1232. {
  1233. cmUiSetBaseRow( uiH, appId, panelId, cmUiPrevB(uiH,appId,panelId) + cmUiNextVBorder(uiH,appId,panelId) );
  1234. cmUiSetBaseCol( uiH, appId, panelId, cmUiBaseCol(uiH,appId,panelId));
  1235. }
  1236. int cmUiBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1237. {
  1238. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1239. cmUiPanel_t* pp;
  1240. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1241. return -1;
  1242. return pp->baseCol;
  1243. }
  1244. int cmUiSetBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId, int x )
  1245. {
  1246. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1247. cmUiPanel_t* pp;
  1248. if( _cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1249. return -1;
  1250. int bc = pp->baseCol;
  1251. pp->baseCol = x;
  1252. pp->flags = cmSetFlag(pp->flags,kPlaceBaseRowUiFl);
  1253. return bc;
  1254. }
  1255. int cmUiBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1256. {
  1257. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1258. cmUiPanel_t* pp;
  1259. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1260. return -1;
  1261. return pp->baseRow;
  1262. }
  1263. int cmUiSetBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId, int y )
  1264. {
  1265. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1266. cmUiPanel_t* pp;
  1267. cmUiRC_t rc;
  1268. if((rc = _cmUiFindPanel(p, appId, panelId, &pp, true)) != kOkUiRC )
  1269. return -1;
  1270. int br = pp->baseRow;
  1271. pp->baseRow = y;
  1272. return br;
  1273. }
  1274. int cmUiW( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1275. {
  1276. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1277. cmUiPanel_t* pp;
  1278. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1279. return -1;
  1280. return pp->dfltW;
  1281. }
  1282. int cmUiH( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1283. {
  1284. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1285. cmUiPanel_t* pp;
  1286. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1287. return -1;
  1288. return pp->dfltH;
  1289. }
  1290. int cmUiSetW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w )
  1291. {
  1292. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1293. cmUiPanel_t* pp;
  1294. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1295. return -1;
  1296. int rv = pp->dfltW;
  1297. pp->dfltW = w;
  1298. pp->nextW = w;
  1299. return rv;
  1300. }
  1301. int cmUiSetH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h )
  1302. {
  1303. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1304. cmUiPanel_t* pp;
  1305. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1306. return -1;
  1307. int rv = pp->dfltH;
  1308. pp->dfltH = h;
  1309. pp->nextW = h;
  1310. return rv;
  1311. }
  1312. void cmUiSetWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h )
  1313. {
  1314. cmUiSetW( uiH, appId, panelId, w );
  1315. cmUiSetH( uiH, appId, panelId, h );
  1316. }
  1317. int cmUiNextW( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1318. {
  1319. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1320. cmUiPanel_t* pp;
  1321. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1322. return -1;
  1323. return pp->nextW;
  1324. }
  1325. int cmUiNextH( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1326. {
  1327. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1328. cmUiPanel_t* pp;
  1329. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1330. return -1;
  1331. return pp->nextH;
  1332. }
  1333. void cmUiSetNextW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w )
  1334. {
  1335. return cmUiSetNextWH( uiH, appId, panelId, w, cmUiNextH(uiH,appId,panelId));
  1336. }
  1337. void cmUiSetNextH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h )
  1338. {
  1339. return cmUiSetNextWH( uiH, appId, panelId, cmUiNextW(uiH,appId,panelId), h);
  1340. }
  1341. void cmUiSetNextWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h )
  1342. {
  1343. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1344. cmUiPanel_t* pp;
  1345. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1346. return;
  1347. pp->nextW = w;
  1348. pp->nextH = h;
  1349. pp->flags = cmSetFlag(pp->flags,kNextWHUiFl);
  1350. }
  1351. int cmUiHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1352. {
  1353. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1354. cmUiPanel_t* pp;
  1355. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1356. return -1;
  1357. return pp->dfltHBorder;
  1358. }
  1359. int cmUiVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1360. {
  1361. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1362. cmUiPanel_t* pp;
  1363. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1364. return -1;
  1365. return pp->dfltVBorder;
  1366. }
  1367. int cmUiSetHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w )
  1368. {
  1369. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1370. cmUiPanel_t* pp;
  1371. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1372. return -1;
  1373. int rv = pp->dfltHBorder;
  1374. pp->dfltHBorder = w;
  1375. return rv;
  1376. }
  1377. int cmUiSetVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h )
  1378. {
  1379. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1380. cmUiPanel_t* pp;
  1381. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1382. return -1;
  1383. int rv = pp->dfltVBorder;
  1384. pp->dfltVBorder = h;
  1385. return rv;
  1386. }
  1387. int cmUiNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1388. {
  1389. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1390. cmUiPanel_t* pp;
  1391. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1392. return -1;
  1393. return pp->nextHBorder;
  1394. }
  1395. int cmUiNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1396. {
  1397. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1398. cmUiPanel_t* pp;
  1399. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1400. return -1;
  1401. return pp->nextVBorder;
  1402. }
  1403. int cmUiSetNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w )
  1404. {
  1405. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1406. cmUiPanel_t* pp;
  1407. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1408. return -1;
  1409. int rv = pp->nextHBorder;
  1410. pp->nextHBorder = w;
  1411. return rv;
  1412. }
  1413. int cmUiSetNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h )
  1414. {
  1415. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1416. cmUiPanel_t* pp;
  1417. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1418. return -1;
  1419. int rv = pp->nextVBorder;
  1420. pp->nextVBorder = h;
  1421. return rv;
  1422. }
  1423. int cmUiPrevL( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1424. {
  1425. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1426. cmUiPanel_t* pp;
  1427. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1428. return -1;
  1429. return pp->prevRect.x;
  1430. }
  1431. int cmUiPrevT( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1432. {
  1433. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1434. cmUiPanel_t* pp;
  1435. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1436. return -1;
  1437. return pp->prevRect.y;
  1438. }
  1439. int cmUiPrevR( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1440. {
  1441. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1442. cmUiPanel_t* pp;
  1443. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1444. return -1;
  1445. return pp->prevRect.x + pp->prevRect.w;
  1446. }
  1447. int cmUiPrevB( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1448. {
  1449. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1450. cmUiPanel_t* pp;
  1451. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1452. return -1;
  1453. return pp->prevRect.y + pp->prevRect.h;
  1454. }
  1455. int cmUiPrevW( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1456. {
  1457. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1458. cmUiPanel_t* pp;
  1459. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1460. return -1;
  1461. return pp->prevRect.w;
  1462. }
  1463. int cmUiPrevH( cmUiH_t uiH, unsigned appId, unsigned panelId )
  1464. {
  1465. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1466. cmUiPanel_t* pp;
  1467. if(_cmUiFindPanel(p, appId, panelId, &pp, true) != kOkUiRC )
  1468. return -1;
  1469. return pp->prevRect.h;
  1470. }
  1471. cmUiRC_t cmUiSetInt( cmUiH_t uiH, unsigned appId, unsigned id, int v )
  1472. {
  1473. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1474. cmUiCtl_t* ctl;
  1475. cmUiRC_t rc;
  1476. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1477. return rc;
  1478. return _cmUiSetDriverValueInt(p,ctl,kValUiFl,v);
  1479. }
  1480. cmUiRC_t cmUiSetUInt( cmUiH_t uiH, unsigned appId, unsigned id, unsigned v )
  1481. {
  1482. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1483. cmUiCtl_t* ctl;
  1484. cmUiRC_t rc;
  1485. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1486. return rc;
  1487. return _cmUiSetDriverValueInt(p,ctl,kValUiFl,v);
  1488. }
  1489. cmUiRC_t cmUiSetDouble( cmUiH_t uiH, unsigned appId, unsigned id, double v )
  1490. {
  1491. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1492. cmUiCtl_t* ctl;
  1493. cmUiRC_t rc;
  1494. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1495. return rc;
  1496. return _cmUiSetDriverValueDouble(p,ctl,kValUiFl,v);
  1497. }
  1498. cmUiRC_t cmUiSetString( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* v )
  1499. {
  1500. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1501. cmUiCtl_t* ctl;
  1502. cmUiRC_t rc;
  1503. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1504. return rc;
  1505. return _cmUiSetDriverValueStr(p,ctl,kValUiFl,v);
  1506. }
  1507. cmUiRC_t cmUiSetVPrintf( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, va_list vl )
  1508. {
  1509. va_list vl1;
  1510. va_copy(vl1,vl);
  1511. unsigned n = vsnprintf(NULL,0,fmt,vl1);
  1512. va_end(vl1);
  1513. unsigned sbufN = 2047;
  1514. cmChar_t sbuf[ sbufN+1 ];
  1515. cmChar_t* b;
  1516. unsigned bn;
  1517. cmChar_t* abuf = NULL;
  1518. if( n >= sbufN )
  1519. {
  1520. bn = n + 1;
  1521. abuf = cmMemAlloc(cmChar_t,bn);
  1522. b = abuf;
  1523. }
  1524. else
  1525. {
  1526. bn = sbufN;
  1527. b = sbuf;
  1528. }
  1529. vsnprintf(b,bn,fmt,vl);
  1530. cmUiRC_t rc = cmUiSetString(uiH,appId,id,b);
  1531. cmMemFree(abuf);
  1532. return rc;
  1533. }
  1534. cmUiRC_t cmUiSetPrintf( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, ... )
  1535. {
  1536. va_list vl;
  1537. va_start(vl,fmt);
  1538. cmUiRC_t rc = cmUiSetVPrintf(uiH,appId,id,fmt,vl);
  1539. va_end(vl);
  1540. return rc;
  1541. }
  1542. int cmUiInt(cmUiH_t uiH, unsigned appId, unsigned id )
  1543. {
  1544. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1545. cmUiCtl_t* ctl;
  1546. cmUiRC_t rc;
  1547. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1548. return 0;
  1549. return ctl->getInt(ctl);
  1550. }
  1551. unsigned cmUiUInt( cmUiH_t uiH, unsigned appId, unsigned id )
  1552. {
  1553. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1554. cmUiCtl_t* ctl;
  1555. cmUiRC_t rc;
  1556. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1557. return 0;
  1558. return ctl->getInt(ctl);
  1559. }
  1560. double cmUiDouble( cmUiH_t uiH, unsigned appId, unsigned id )
  1561. {
  1562. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1563. cmUiCtl_t* ctl;
  1564. cmUiRC_t rc;
  1565. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1566. return 0;
  1567. return ctl->getDbl(ctl);
  1568. }
  1569. const cmChar_t* cmUiString( cmUiH_t uiH, unsigned appId, unsigned id )
  1570. {
  1571. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1572. cmUiCtl_t* ctl;
  1573. cmUiRC_t rc;
  1574. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1575. return 0;
  1576. return ctl->getStr(ctl);
  1577. }
  1578. unsigned cmUiListEleCount( cmUiH_t uiH, unsigned appId, unsigned id )
  1579. {
  1580. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1581. cmUiCtl_t* ctl;
  1582. cmUiRC_t rc;
  1583. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1584. return 0;
  1585. return cmArrayCount( ctl->idArrH );
  1586. }
  1587. unsigned cmUiListEleId( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index )
  1588. {
  1589. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1590. cmUiCtl_t* ctl;
  1591. cmUiRC_t rc;
  1592. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1593. return 0;
  1594. if( !cmArrayIsValid( ctl->idArrH ) || index >= cmArrayCount( ctl->idArrH) )
  1595. return cmInvalidId;
  1596. return cmArrayPtr(cmUiListEle_t, ctl->idArrH, index )->id;
  1597. }
  1598. const cmChar_t* cmUiListEleLabel( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index )
  1599. {
  1600. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1601. cmUiCtl_t* ctl;
  1602. cmUiRC_t rc;
  1603. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1604. return 0;
  1605. if( !cmArrayIsValid( ctl->idArrH ) || index >= cmArrayCount( ctl->idArrH) )
  1606. return NULL;
  1607. return cmArrayPtr(cmUiListEle_t, ctl->idArrH, index )->label;
  1608. }
  1609. unsigned cmUiListEleLabelToIndex( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* label )
  1610. {
  1611. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1612. cmUiCtl_t* ctl;
  1613. cmUiRC_t rc;
  1614. unsigned i,n;
  1615. if( label == NULL )
  1616. return cmInvalidIdx;
  1617. if((rc = _cmUiFastFindCtl(p,appId,id,&ctl,true)) != kOkUiRC )
  1618. return cmInvalidIdx;
  1619. if( cmArrayIsValid( ctl->idArrH )==false || (n = cmArrayCount( ctl->idArrH))==0 )
  1620. return cmInvalidIdx;
  1621. for(i=0; i<n; ++i)
  1622. if( cmTextCmp(cmArrayPtr(cmUiListEle_t, ctl->idArrH, i )->label,label) == 0 )
  1623. return i;
  1624. return cmInvalidIdx;
  1625. }
  1626. cmUiRC_t cmUiLastRC( cmUiH_t uiH )
  1627. {
  1628. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1629. return cmErrLastRC(&p->err);
  1630. }
  1631. cmUiRC_t cmUiSetRC( cmUiH_t uiH, cmUiRC_t rc )
  1632. {
  1633. cmUi_t* p = _cmUiHandleToPtr(uiH);
  1634. return cmErrSetRC(&p->err, rc);
  1635. }