libcm is a C development framework with an emphasis on audio signal processing applications.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. #ifndef cmUi_h
  2. #define cmUi_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /*( { file_desc:"UI control manager for rtSys." kw:[rtSys]}
  7. cmUI implements a platform independent UI control manager
  8. for multiple simultaneous applications. In this context
  9. an 'application' can be seen as a plug-in style program.
  10. The goal of the manager is to support the easy construction
  11. of panels of graphic user interface controls.
  12. Operation:
  13. 1) A cmUi manager is allocated by the master program. See cmUiAlloc().
  14. 2) The master program then assigns a 'driver' to implmenent
  15. the commands issued by cmUi. All commands can be
  16. described using the cmUiDriverArg_t record.
  17. 3) The master program then registers client applications with
  18. the cmUi manager by calling cmUiCreateApp().
  19. 4) Prior to calling any of the client application functions
  20. the master or client app. must call cmUiSetAppId(). This
  21. function sets the current application id and thereby slightly
  22. simplifies the client app interface by not requiring the
  23. app id be passed with every client app. function call.
  24. 5) Once the current app. id is set with cmUiSetAppId()
  25. the client app can make multiple calls to the cmUi manager
  26. to create or query controls.
  27. 6) Calls to create controls result in callbacks to the
  28. driver function which manages the actual windowing and
  29. initial event handling.
  30. 7) Events generated by the driver based graphic controls
  31. are routed back to the cmUi manager through calls to
  32. cmUiOnDriverEvent().
  33. 8) The cmUiOnDriverEvent() internally caches the
  34. state/value of the control based on the event information
  35. and calls the 'cbFunc' function registered with the
  36. cmUi manager by cmUiAlloc(). This call is intended to
  37. notify the client applications of changes in the state/value
  38. of a user interface control.
  39. Notes:
  40. 1) Application id's must be unique among all applications.
  41. Control id's must be unique among all controls assigned
  42. to the same application. Both application and control id's
  43. are used internally as array indexes they should therefore
  44. be the low, positive, and densely packed integers.
  45. 2) All communication between the cmUi and the driver,
  46. and all callbacks from the cmUi to the master app.
  47. use the cmUiDriverArg_t structure
  48. 3) The panel tabs act like radio buttons. When a tab is
  49. selected the clicked tab generates one event for each
  50. tab (cId=kPanelUiCId usrId=panelId) w/ ival=1 for the
  51. selected tab and ival=0 for all other tabs.
  52. TODO:
  53. 0) [DONE] Remove the 'cbArg' from the cmUiDriverArg_t record and
  54. pass it as a separate paramenter in the cmUiDriverFunc_t calls.
  55. 1) The controls should be based on a multilevel tree model
  56. not the simple two layer panel->controls framework used now.
  57. 2) Given that access to the control values can be non-blocked
  58. and fast many controls won't need to report changes back to
  59. the client - the client can simply read the control value
  60. as necessary directly from the cmUi manager. To decrease
  61. event processing overhead controls should therefore be
  62. flagged as 'callback/no-callback'. Some controls like
  63. buttons should default to turning the flag on, while other
  64. controls, like numbers, should default to turning it off.
  65. 3) Implement support for the creation of arrays of controls.
  66. This can be implemented with a scheme similar to 'next rect'.
  67. cmUiSetupArray(uiH,panelId,baseCtlId,cnt).
  68. 4) Come up with a threading model. For example maybe
  69. control creation should use a blocking scheme since it is
  70. generally too time consuming to do during real-time operation
  71. anyway. If the control flow generated from driver event
  72. callbacks then allows value, but not structural changes,
  73. then non blocking will be necessary.
  74. 5) The cmUiDriverArg_t structure is used for both
  75. commands to the driver and callbacks from the driver.
  76. Many of the fields are not use for event callbacks.
  77. Which fields are used under which circumstances should
  78. be documented. This would allow decreasing the size
  79. of the record during serialization.
  80. 6) [DONE] Write a serialization/deserialization routines for cmUiDriverArg_t.
  81. unsigned cmUiDriverArgSerialBufByteCount(const cmUiDriverArg_t* a);
  82. cmUiRC_t cmUiDriverArgSerialize( const cmUiDriverArg_t* a, char* buf, bufByteCnt );
  83. cmUiRC_t cmUiDriverArgDeserialize( cmUiDriverArg_t* a, const char* buf, bufByteCnt );
  84. 7) There is no duplex model for validating and then displaying the
  85. value of a control.
  86. */
  87. //)
  88. //(
  89. typedef cmHandle_t cmUiH_t;
  90. extern cmUiH_t cmUiNullHandle;
  91. //=============================================================================================
  92. //
  93. // Master program API
  94. //
  95. // Allocate the cmUi manager. If the driver function is not
  96. // yet available then set drvrFunc to NULL and use
  97. // cmUiSetDriver() to set the driver function at a later
  98. // time. cmUiAlloc() stores but does not call the driver
  99. // and so it is not needed when the cmUI manager is
  100. // constructed - however it must be set prior to making
  101. // any other calls to the manager.
  102. cmUiRC_t cmUiAlloc(
  103. cmCtx_t* ctx,
  104. cmUiH_t* hp,
  105. cmUiDriverFunc_t drvrFunc, // UI driver function
  106. void* drvrArg,
  107. cmUiDriverFunc_t cbFunc, // client event callback function
  108. void* cbArg );
  109. // Release all apps but assume that the driver has already
  110. // been released.
  111. cmUiRC_t cmUiFree( cmUiH_t* hp );
  112. // Validate the cmUiH_t handle.
  113. bool cmUiIsValid( cmUiH_t h );
  114. // Set the driver function. This function allows the driver
  115. // set in cmUiAlloc() to be replaced or set following the
  116. // call to cmUiAlloc().
  117. //
  118. // By setting the driver function to
  119. // NULL the application can prevent callback to the driver.
  120. // This is useful if the driver has been release prior
  121. // to the UI manager begining destroyed.
  122. void cmUiSetDriver( cmUiH_t h, cmUiDriverFunc_t drvrFunc, void* drvrArg );
  123. // Register a client application with the cmUi manager.
  124. // 'appId' must not have been used by any other previously registered.
  125. // application.
  126. // Automatically sets and restores the ambient appId.
  127. // In a plug-in context this function is generally called
  128. // just prior a instantiating a plug-in object.
  129. cmUiRC_t cmUiCreateApp( cmUiH_t uiH, unsigned appId, unsigned asSubIdx );
  130. // Return true if 'appId' is active.
  131. bool cmUiAppIsActive( cmUiH_t uiH, unsigned appId );
  132. // Notify the cmUi manager that the resources associated
  133. // with a client application can be released.
  134. // Automatically sets and restores the ambient appId.
  135. cmUiRC_t cmUiDestroyApp( cmUiH_t uiH, unsigned appId );
  136. // Release all apps.
  137. // Automatically sets and restores the ambient appId.
  138. cmUiRC_t cmUiDestroyAllApps( cmUiH_t h );
  139. // The master program sets the ambient 'appId' prior to passing control
  140. // to a client which will make User API calls. By making the
  141. // 'appId' an ambient parameter the User API calls are slightly
  142. // simplified because they do not have to include it in each of the
  143. // function calls.
  144. //cmUiRC_t cmUiSetAppId( cmUiH_t uiH, unsigned appId );
  145. //unsigned cmUiAppId( cmUiH_t uiH );
  146. unsigned cmUiAppIdToAsSubIndex( cmUiH_t uiH, unsigned appId );
  147. // Return the count of app's.
  148. unsigned cmUiAppCount( cmUiH_t uiH );
  149. // Callbacks from the driver arrive via this function.
  150. cmUiRC_t cmUiOnDriverEvent( cmUiH_t uiH, const cmUiDriverArg_t* p );
  151. //=============================================================================================
  152. //
  153. // Client Application API
  154. //
  155. // See above note on panel tabs acting like radio buttons.
  156. cmUiRC_t cmUiCreatePanel( cmUiH_t uiH, unsigned appId, unsigned newPanelId, const cmChar_t* label, unsigned flags );
  157. cmUiRC_t cmUiCreateBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags );
  158. cmUiRC_t cmUiCreateCheck( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, bool dflt );
  159. cmUiRC_t cmUiCreateLabel( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags );
  160. cmUiRC_t cmUiCreateString( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text );
  161. cmUiRC_t cmUiCreateConsole( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* text );
  162. 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 );
  163. 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 );
  164. 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 );
  165. cmUiRC_t cmUiCreateProgress( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt );
  166. cmUiRC_t cmUiCreateHMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt );
  167. cmUiRC_t cmUiCreateVMeter( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, int min, int max, int dflt );
  168. 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 );
  169. cmUiRC_t cmUiCreateDirBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, const cmChar_t* dfltDir );
  170. cmUiRC_t cmUiCreateMenuBtn( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags );
  171. cmUiRC_t cmUiCreateMenuBtnV( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmChar_t* label0, unsigned id0, va_list vl );
  172. cmUiRC_t cmUiCreateMenuBtnA( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* lavel, unsigned flags, const cmChar_t* label0, unsigned id0, ... );
  173. 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 );
  174. cmUiRC_t cmUiCreateList( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* label, unsigned flags, unsigned visibleRowCnt );
  175. 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 );
  176. 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, ... );
  177. 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 );
  178. // If 'id' identifies a 'list' control use tabs as column separators.
  179. cmUiRC_t cmUiAppendListEle( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, const cmChar_t* text, unsigned eleId );
  180. // Remove all the elements of a list control.
  181. cmUiRC_t cmUiClearList( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id );
  182. // Enable/Disable a control
  183. cmUiRC_t cmUiEnableCtl( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id, bool enableFl );
  184. // Enable/disable all controls on a panel except those included in the var args list.
  185. // Terminate the var args list with cmInvalidId.
  186. cmUiRC_t cmUiEnableAllExceptV( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, va_list vl );
  187. cmUiRC_t cmUiEnableAllExcept( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl, ... );
  188. // If 'id' identifies a panel then all control belonging to the panel
  189. // will also be destroyed.
  190. cmUiRC_t cmUiDestroyCtl( cmUiH_t uiH, unsigned appId, unsigned id );
  191. // Returns true if the control exists.
  192. // For panels set id=panelId.
  193. //bool cmUiCtlExists( cmUiH_t uiH, unsigned appId, unsigned panelId, unsigned id );
  194. // Destroy all the controls in a panel.
  195. cmUiRC_t cmUiClearPanel( cmUiH_t uiH, unsigned appId, unsigned panelId );
  196. cmUiRC_t cmUiSelectPanel( cmUiH_t uiH, const cmChar_t* label );
  197. //------------------------------------------------------------------------------------------
  198. // Location:
  199. // 1) If a 'next rect' is set the control will be placed according to it.
  200. // 2) If cmUiSetBaseCol() was set then the control will be placed at the
  201. // base col and base row.
  202. // 3) If cmUiPlaceRight() or cmUIPlaceBelow() have been called since the
  203. // previous control was created then the new control will be placed
  204. // accordingly.
  205. // 4) The control will be placed according to the 'fill rows' flag.
  206. // If not set (default) the new control will be placed in the
  207. // base column below the previous control.
  208. // If 'fill rows' is set the new control will be placed on the
  209. // same row to the right of the previous control.
  210. // If there is no previous control then it will be placed
  211. // in the base column and base row.
  212. // Get/Set the fill directions. If the 'fill columns' flag is enabled
  213. // then the next control is placed below the previous control otherwise
  214. // the next control is placed to the right of the next control.
  215. bool cmUiFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId );
  216. bool cmUiSetFillRows( cmUiH_t uiH, unsigned appId, unsigned panelId, bool enableFl );
  217. // Place the next control to the right/below of the previous ctl.
  218. // These flags override the current fill row/col setting.
  219. // Note that 'place right' and 'place below' are mutually
  220. // exclusive. Enabling one disables the other.
  221. void cmUiPlaceRight( cmUiH_t uiH, unsigned appId, unsigned panelId );
  222. void cmUiPlaceBelow( cmUiH_t uiH, unsigned appId, unsigned panelId );
  223. // Place the next control at the base column below the previous ctl.
  224. void cmUiNewLine( cmUiH_t uiH, unsigned appId, unsigned panelId );
  225. // Set/Get current base col and return previous value. Place the next
  226. // control on the base row.
  227. int cmUiBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId );
  228. int cmUiSetBaseCol( cmUiH_t uiH, unsigned appId, unsigned panelId, int x );
  229. // Set/Get current base row and return previous value.
  230. int cmUiBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId );
  231. int cmUiSetBaseRow( cmUiH_t uiH, unsigned appId, unsigned panelId, int y );
  232. // Size:
  233. // 1) If a 'next rect' is set the control will be placed according
  234. // to it.
  235. // 2) If a 'next w/h' is set the control will be placed according
  236. // to it. The 'next w/h' setting is only active for the
  237. // next control created.
  238. // 3) The w/h of the new control will be set to the default w/h.
  239. //
  240. // Get/Set the default control width and height.
  241. // Set returns previous value.
  242. int cmUiW( cmUiH_t uiH, unsigned appId, unsigned panelId );
  243. int cmUiH( cmUiH_t uiH, unsigned appId, unsigned panelId );
  244. int cmUiSetW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  245. int cmUiSetH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  246. void cmUiSetWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h );
  247. // Get/Set the control width and height for only the next control.
  248. // Set returns previous value.
  249. int cmUiNextW( cmUiH_t uiH, unsigned appId, unsigned panelId );
  250. int cmUiNextH( cmUiH_t uiH, unsigned appId, unsigned panelId );
  251. void cmUiSetNextW( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  252. void cmUiSetNextH( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  253. void cmUiSetNextWH( cmUiH_t uiH, unsigned appId, unsigned panelId, int w, int h );
  254. // Get/Set the default inter-control borders
  255. // Set returns previous value.
  256. int cmUiHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  257. int cmUiVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  258. int cmUiSetHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  259. int cmUiSetVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  260. // Get/Set the 'next' inter-control borders
  261. // Set returns previous value.
  262. int cmUiNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  263. int cmUiNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId );
  264. int cmUiSetNextHBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int w );
  265. int cmUiSetNextVBorder( cmUiH_t uiH, unsigned appId, unsigned panelId, int h );
  266. // Place the next control at the following coordinates. The
  267. // specified coordinates are only active during the next
  268. // cmUiCreateXXX() call. Setting the 'next rect' overrides all
  269. // other layout directives.
  270. cmUiRC_t cmUiNextRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int x, int y, int w, int h );
  271. // Get the location/size of the previously created control.
  272. // All ref. args are optional.
  273. cmUiRC_t cmUiPrevRect( cmUiH_t uiH, unsigned appId, unsigned panelId, int* xRef, int* yRef, int* wRef, int* hRef );
  274. int cmUiPrevL( cmUiH_t uiH, unsigned appId, unsigned panelId );
  275. int cmUiPrevT( cmUiH_t uiH, unsigned appId, unsigned panelId );
  276. int cmUiPrevR( cmUiH_t uiH, unsigned appId, unsigned panelId );
  277. int cmUiPrevB( cmUiH_t uiH, unsigned appId, unsigned panelId );
  278. int cmUiPrevW( cmUiH_t uiH, unsigned appId, unsigned panelId );
  279. int cmUiPrevH( cmUiH_t uiH, unsigned appId, unsigned panelId );
  280. //------------------------------------------------------------------------------------------
  281. //
  282. // Get/set the value of UI control.
  283. //
  284. // TODO:
  285. // + Need functions for setting auxilliary values like
  286. // min,max,etc..
  287. // Set the value associated with a control.
  288. // Set the local value of the specified control and then
  289. // send the value to the UI driver so that the UI reflects this value.
  290. cmUiRC_t cmUiSetInt( cmUiH_t uiH, unsigned appId, unsigned id, int v );
  291. cmUiRC_t cmUiSetUInt( cmUiH_t uiH, unsigned appId, unsigned id, unsigned v );
  292. cmUiRC_t cmUiSetDouble( cmUiH_t uiH, unsigned appId, unsigned id, double v );
  293. cmUiRC_t cmUiSetString( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* v );
  294. cmUiRC_t cmUiSetVPrintf(cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, va_list vl );
  295. cmUiRC_t cmUiSetPrintf( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* fmt, ... );
  296. // Get the value associated with a control. These functions return
  297. // the control value cached in the local control, they do not need
  298. // to call the driver and are therefore very fast.
  299. int cmUiInt( cmUiH_t uiH, unsigned appId, unsigned id );
  300. unsigned cmUiUInt( cmUiH_t uiH, unsigned appId, unsigned id );
  301. double cmUiDouble( cmUiH_t uiH, unsigned appId, unsigned id );
  302. const cmChar_t* cmUiString( cmUiH_t uiH, unsigned appId, unsigned id );
  303. unsigned cmUiListEleCount( cmUiH_t uiH, unsigned appId, unsigned id );
  304. unsigned cmUiListEleId( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index );
  305. const cmChar_t* cmUiListEleLabel( cmUiH_t uiH, unsigned appId, unsigned id, unsigned index );
  306. unsigned cmUiListEleLabelToIndex( cmUiH_t uiH, unsigned appId, unsigned id, const cmChar_t* label );
  307. // Query/set the current error state.
  308. cmUiRC_t cmUiLastRC( cmUiH_t uiH );
  309. cmUiRC_t cmUiSetRC( cmUiH_t uiH, cmUiRC_t rc );
  310. //)
  311. #ifdef __cplusplus
  312. }
  313. #endif
  314. #endif