pslider.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. #include <precomp.h>
  2. #include <wasabicfg.h>
  3. #include "pslider.h"
  4. #include <api/script/scriptmgr.h>
  5. #include <api/script/vcpu.h>
  6. #include <api/skin/skinparse.h>
  7. #ifdef WASABI_WIDGETS_MEDIASLIDERS
  8. #include "seqband.h"
  9. #include "seqpreamp.h"
  10. #include "svolbar.h"
  11. #include "sseeker.h"
  12. #include "spanbar.h"
  13. #endif
  14. char sliderObjectStr[] = "Slider"; // This is the xml tag
  15. char sliderXuiSvcName[] = "Slider xui object"; // this is the name of the xuiservice
  16. XMLParamPair PSliderWnd::params[] =
  17. {
  18. {PSLIDER_SETBARLEFT, L"BARLEFT"},
  19. {PSLIDER_SETBARMIDDLE, L"BARMIDDLE"},
  20. {PSLIDER_SETBARRIGHT, L"BARRIGHT"},
  21. {PSLIDER_SETDOWNTHUMB, L"DOWNTHUMB"},
  22. {PSLIDER_SETHIGH, L"HIGH"},
  23. {PSLIDER_SETHOTPOS, L"HOTPOS"},
  24. {PSLIDER_SETHOTRANGE, L"HOTRANGE"},
  25. {PSLIDER_SETHOVERTHUMB, L"HOVERTHUMB"},
  26. {PSLIDER_SETLOW, L"LOW"},
  27. {PSLIDER_SETORIENTATION, L"ORIENTATION"},
  28. {PSLIDER_SETTHUMB, L"THUMB"},
  29. {PSLIDER_SETSTRETCHTHUMB, L"STRETCHTHUMB"},
  30. };
  31. PSliderWnd::PSliderWnd()
  32. {
  33. setLimits(0, 255);
  34. getScriptObject()->vcpu_setInterface(sliderGuid, (void *)static_cast<PSliderWnd *>(this));
  35. getScriptObject()->vcpu_setClassName(L"Slider");
  36. getScriptObject()->vcpu_setController(sliderController);
  37. xuihandle = newXuiHandle();
  38. CreateXMLParameters(xuihandle);
  39. }
  40. void PSliderWnd::CreateXMLParameters(int master_handle)
  41. {
  42. //PSLIDER_PARENT::CreateXMLParameters(master_handle);
  43. int numParams = sizeof(params) / sizeof(params[0]);
  44. hintNumberOfParams(xuihandle, numParams);
  45. for (int i = 0;i < numParams;i++)
  46. addParam(xuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  47. }
  48. PSliderWnd::~PSliderWnd()
  49. {}
  50. int PSliderWnd::setXuiParam(int _xuihandle, int attrid, const wchar_t *paramname, const wchar_t *strvalue)
  51. {
  52. if (xuihandle != _xuihandle) return PSLIDER_PARENT::setXuiParam(_xuihandle, attrid, paramname, strvalue);
  53. switch (attrid)
  54. {
  55. case PSLIDER_SETBARLEFT:
  56. setLeftBmp(strvalue);
  57. break;
  58. case PSLIDER_SETBARMIDDLE:
  59. setMiddleBmp(strvalue);
  60. break;
  61. case PSLIDER_SETBARRIGHT:
  62. setRightBmp(strvalue);
  63. break;
  64. case PSLIDER_SETTHUMB:
  65. setThumbBmp(strvalue);
  66. break;
  67. case PSLIDER_SETDOWNTHUMB:
  68. setThumbDownBmp(strvalue);
  69. break;
  70. case PSLIDER_SETHOVERTHUMB:
  71. setThumbHiliteBmp(strvalue);
  72. break;
  73. case PSLIDER_SETSTRETCHTHUMB:
  74. setThumbStretched(_wtoi(strvalue));
  75. break;
  76. case PSLIDER_SETORIENTATION:
  77. setOrientation(SkinParser::getOrientation(strvalue));
  78. break;
  79. case PSLIDER_SETLOW:
  80. {
  81. int mx = getMaxLimit();
  82. setLimits(WTOI(strvalue), mx);
  83. #ifdef WASABI_COMPILE_CONFIG
  84. reloadConfig();
  85. #endif
  86. break;
  87. }
  88. case PSLIDER_SETHIGH:
  89. {
  90. int mn = getMinLimit();
  91. setLimits(mn, WTOI(strvalue));
  92. #ifdef WASABI_COMPILE_CONFIG
  93. reloadConfig();
  94. #endif
  95. break;
  96. }
  97. case PSLIDER_SETHOTPOS:
  98. {
  99. int a = WTOI(strvalue);
  100. setHotPosition(a);
  101. break;
  102. }
  103. case PSLIDER_SETHOTRANGE:
  104. {
  105. int a = WTOI(strvalue);
  106. setHotPosRange(a);
  107. break;
  108. }
  109. default:
  110. return 0;
  111. }
  112. return 1;
  113. }
  114. int PSliderWnd::onInit()
  115. {
  116. setNoDefaultBackground(1);
  117. PSLIDER_PARENT::onInit();
  118. return 1;
  119. }
  120. #ifdef WASABI_COMPILE_CONFIG
  121. void PSliderWnd::reloadConfig()
  122. {
  123. if (getGuiObject()->guiobject_hasCfgAttrib())
  124. onReloadConfig();
  125. }
  126. #endif
  127. #ifdef WASABI_COMPILE_CONFIG
  128. int PSliderWnd::onReloadConfig()
  129. {
  130. int newVal = getGuiObject()->guiobject_getCfgInt();
  131. setPosition(newVal, 0);
  132. return PSLIDER_PARENT::onReloadConfig();
  133. }
  134. #endif
  135. int PSliderWnd::onSetPosition()
  136. {
  137. int r = PSLIDER_PARENT::onSetPosition();
  138. scriptVar p = SOM::makeVar(SCRIPT_INT);
  139. int intVal = getSliderPosition();
  140. #ifdef WASABI_COMPILE_CONFIG
  141. getGuiObject()->guiobject_setCfgInt(intVal);
  142. #endif
  143. SOM::assign(&p, intVal / scriptDivisor());
  144. script_onSetPosition(SCRIPT_CALL, getScriptObject(), p);
  145. return r;
  146. }
  147. int PSliderWnd::onPostedPosition(int pp)
  148. {
  149. scriptVar p = SOM::makeVar(SCRIPT_INT);
  150. int intVal = getSliderPosition();
  151. #ifdef WASABI_COMPILE_CONFIG
  152. getGuiObject()->guiobject_setCfgInt(intVal);
  153. #endif
  154. SOM::assign(&p, intVal / scriptDivisor());
  155. script_onPostedPosition(SCRIPT_CALL, getScriptObject(), p);
  156. return 1;
  157. }
  158. int PSliderWnd::onSetFinalPosition()
  159. {
  160. int r = PSLIDER_PARENT::onSetPosition();
  161. scriptVar p = SOM::makeVar(SCRIPT_INT);
  162. int intVal = getSliderPosition();
  163. #ifdef WASABI_COMPILE_CONFIG
  164. getGuiObject()->guiobject_setCfgInt(intVal);
  165. #endif
  166. SOM::assign(&p, intVal / scriptDivisor());
  167. script_onSetFinalPosition(SCRIPT_CALL, getScriptObject(), p);
  168. return r;
  169. }
  170. SliderScriptController _sliderController;
  171. SliderScriptController *sliderController = &_sliderController;
  172. // -- Functions table -------------------------------------
  173. function_descriptor_struct SliderScriptController::exportedFunction[] = {
  174. {L"setPosition", 1, (void*)PSliderWnd::script_setPosition },
  175. {L"getPosition", 0, (void*)PSliderWnd::script_getPosition },
  176. {L"onSetPosition", 1, (void*)PSliderWnd::script_onSetPosition },
  177. {L"onPostedPosition", 1, (void*)PSliderWnd::script_onPostedPosition },
  178. {L"onSetFinalPosition", 1, (void*)PSliderWnd::script_onSetFinalPosition },
  179. {L"lock", 0, (void*)PSliderWnd::script_lock},
  180. {L"unlock", 0, (void*)PSliderWnd::script_unlock},
  181. };
  182. // --------------------------------------------------------
  183. const wchar_t *SliderScriptController::getClassName()
  184. {
  185. return L"Slider";
  186. }
  187. const wchar_t *SliderScriptController::getAncestorClassName()
  188. {
  189. return L"GuiObject";
  190. }
  191. ScriptObject *SliderScriptController::instantiate()
  192. {
  193. PSliderWnd *s = new PSliderWnd;
  194. ASSERT(s != NULL);
  195. return s->getScriptObject();
  196. }
  197. void SliderScriptController::destroy(ScriptObject *o)
  198. {
  199. PSliderWnd *s = static_cast<PSliderWnd *>(o->vcpu_getInterface(sliderGuid));
  200. ASSERT(s != NULL);
  201. delete s;
  202. }
  203. void *SliderScriptController::encapsulate(ScriptObject *o)
  204. {
  205. return NULL; // no encapsulation for sliders yet
  206. }
  207. void SliderScriptController::deencapsulate(void *o)
  208. {}
  209. int SliderScriptController::getNumFunctions()
  210. {
  211. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  212. }
  213. const function_descriptor_struct *SliderScriptController::getExportedFunctions()
  214. {
  215. return exportedFunction;
  216. }
  217. GUID SliderScriptController::getClassGuid()
  218. {
  219. return sliderGuid;
  220. }
  221. const wchar_t *PSliderWnd::vcpu_getClassName()
  222. {
  223. return L"Slider";
  224. }
  225. void PSliderWnd::lock ()
  226. {}
  227. void PSliderWnd::unlock()
  228. {}
  229. //------------------------------------------------------------------------
  230. scriptVar PSliderWnd::script_onSetPosition(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar p)
  231. {
  232. SCRIPT_FUNCTION_INIT;
  233. PROCESS_HOOKS1(o, sliderController, p);
  234. SCRIPT_FUNCTION_CHECKABORTEVENT;
  235. SCRIPT_EXEC_EVENT1(o, p);
  236. }
  237. scriptVar PSliderWnd::script_onPostedPosition(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar p)
  238. {
  239. SCRIPT_FUNCTION_INIT;
  240. PROCESS_HOOKS1(o, sliderController, p);
  241. SCRIPT_FUNCTION_CHECKABORTEVENT;
  242. SCRIPT_EXEC_EVENT1(o, p);
  243. }
  244. scriptVar PSliderWnd::script_onSetFinalPosition(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar p)
  245. {
  246. SCRIPT_FUNCTION_INIT;
  247. PROCESS_HOOKS1(o, sliderController, p);
  248. SCRIPT_FUNCTION_CHECKABORTEVENT;
  249. SCRIPT_EXEC_EVENT1(o, p);
  250. }
  251. scriptVar PSliderWnd::script_setPosition(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar v)
  252. {
  253. SCRIPT_FUNCTION_INIT
  254. ASSERT(SOM::isNumeric(&v));
  255. PSliderWnd *s = static_cast<PSliderWnd *>(o->vcpu_getInterface(sliderGuid));
  256. if (s) s->setPosition(GET_SCRIPT_INT(v) * s->scriptDivisor());
  257. RETURN_SCRIPT_VOID;
  258. }
  259. scriptVar PSliderWnd::script_getPosition(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  260. {
  261. SCRIPT_FUNCTION_INIT
  262. PSliderWnd *s = static_cast<PSliderWnd *>(o->vcpu_getInterface(sliderGuid));
  263. if (s) return MAKE_SCRIPT_INT(s->getSliderPosition() / s->scriptDivisor());
  264. return MAKE_SCRIPT_FLOAT(0);
  265. }
  266. scriptVar PSliderWnd::script_lock(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  267. {
  268. SCRIPT_FUNCTION_INIT
  269. PSliderWnd *s = static_cast<PSliderWnd *>(o->vcpu_getInterface(sliderGuid));
  270. if (s) s->lock ();
  271. RETURN_SCRIPT_VOID;
  272. }
  273. scriptVar PSliderWnd::script_unlock(SCRIPT_FUNCTION_PARAMS, ScriptObject *o)
  274. {
  275. SCRIPT_FUNCTION_INIT
  276. PSliderWnd *s = static_cast<PSliderWnd *>(o->vcpu_getInterface(sliderGuid));
  277. if (s) s->unlock();
  278. RETURN_SCRIPT_VOID;
  279. }
  280. GuiObject *SliderXuiSvc::instantiate(const wchar_t *xmltag, ifc_xmlreaderparams *params)
  281. {
  282. #ifdef WASABI_WIDGETS_MEDIASLIDERS
  283. if (!params)
  284. {
  285. PSliderWnd *r = new PSliderWnd;
  286. return r->getGuiObject();
  287. }
  288. const wchar_t *action = params->getItemValue(L"action");
  289. const wchar_t *param = params->getItemValue(L"param");
  290. if (!action)
  291. action=L"";
  292. PSliderWnd *r = NULL;
  293. #ifdef WASABI_WIDGETS_MEDIASLIDERS
  294. if (!_wcsicmp(action, L"seek"))
  295. r = new SSeeker;
  296. else if (!_wcsicmp(action, L"volume"))
  297. r = new SVolBar;
  298. else if (!_wcsicmp(action, L"pan"))
  299. r = new SPanBar;
  300. else if (!_wcsicmp(action, L"eq_band"))
  301. {
  302. if (!_wcsicmp(param, L"preamp"))
  303. r = new SEQPreamp;
  304. else
  305. r = new SEQBand;
  306. }
  307. else if (!_wcsicmp(action, L"eq_preamp"))
  308. {
  309. r = new SEQPreamp;
  310. }
  311. else
  312. {
  313. #endif
  314. r = new PSliderWnd;
  315. #ifdef WASABI_WIDGETS_MEDIASLIDERS
  316. }
  317. #endif
  318. return r->getGuiObject();
  319. #else
  320. PSliderWnd *r = new PSliderWnd;
  321. return r->getGuiObject();
  322. #endif
  323. }
  324. void SliderXuiSvc::destroy(GuiObject *g)
  325. {
  326. PSliderWnd *obj = static_cast<PSliderWnd *>(g->guiobject_getRootWnd());
  327. delete obj;
  328. }