Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
6.4 KiB

  1. /*
  2. * Copyright (c) 1996 1997, 1998 Philips CE I&C
  3. *
  4. * FILE PRPCTRL.CPP
  5. * DATE 7-1-97
  6. * VERSION 1.00
  7. * AUTHOR M.J. Verberne
  8. * DESCRIPTION Handle controls associated with
  9. * properties
  10. * HISTORY
  11. */
  12. #include <windows.h>
  13. #include <winioctl.h>
  14. #include <ks.h>
  15. #include <ksmedia.h>
  16. #include <commctrl.h>
  17. #include "prpcom.h"
  18. #include "debug.h"
  19. #include "phvcmext.h"
  20. #include "prpctrl.h"
  21. /*======================== LOCAL FUNCTION DEFINITIONS ====================*/
  22. static void PRPCTRL_ScaleToPercent(LONG *plValue, LONG lMin, LONG lMax);
  23. /*======================== EXPORTED FUNCTIONS =============================*/
  24. /*-------------------------------------------------------------------------*/
  25. BOOL PRPCTRL_Init(
  26. HWND hDlg,
  27. PRPCTRL_INFO *pCtrl,
  28. BOOL bEnable)
  29. /*-------------------------------------------------------------------------*/
  30. {
  31. BOOL bResult = TRUE;
  32. PVFWEXT_INFO pVfWExtInfo = (PVFWEXT_INFO) GetWindowLongPtr(hDlg, DWLP_USER);
  33. // check control
  34. if (!pCtrl->PrpCtrl)
  35. return FALSE;
  36. // get and set the ranges for slider controls
  37. if (pCtrl->PrpCtrlType == PRPCTRL_TYPE_SLIDER)
  38. {
  39. // preinit min and max for savety reasons
  40. pCtrl->lMin = 0;
  41. pCtrl->lMax = 0;
  42. // get property range
  43. bResult = PRPCOM_Get_Range(
  44. pCtrl->PropertySet,
  45. pCtrl->ulPropertyId,
  46. pVfWExtInfo->pfnDeviceIoControl,
  47. pVfWExtInfo->lParam,
  48. &pCtrl->lMin, &pCtrl->lMax);
  49. if (!bResult)
  50. return FALSE;
  51. // check ranges
  52. if (pCtrl->lMin > pCtrl->lMax)
  53. return FALSE;
  54. // set property range
  55. SendMessage(
  56. GetDlgItem(hDlg, pCtrl->PrpCtrl),
  57. TBM_SETRANGE, TRUE, MAKELONG(pCtrl->lMin, pCtrl->lMax));
  58. // set the thick marks
  59. SendMessage(
  60. GetDlgItem(hDlg, pCtrl->PrpCtrl),
  61. TBM_SETTICFREQ, (WPARAM) ((pCtrl->lMax - pCtrl->lMin) / 10), (LPARAM) 0);
  62. }
  63. else if (pCtrl->PrpCtrlType == PRPCTRL_TYPE_CHECKBOX)
  64. {
  65. // already filled in by user
  66. }
  67. else
  68. return FALSE;
  69. // update actual state
  70. bResult = PRPCTRL_Enable(hDlg, pCtrl, bEnable);
  71. return bResult;
  72. }
  73. /*-------------------------------------------------------------------------*/
  74. BOOL PRPCTRL_Enable(
  75. HWND hDlg,
  76. PRPCTRL_INFO *pCtrl,
  77. BOOL bEnable)
  78. /*-------------------------------------------------------------------------*/
  79. {
  80. LONG lValue;
  81. BOOL bResult = TRUE;
  82. PVFWEXT_INFO pVfWExtInfo = (PVFWEXT_INFO) GetWindowLongPtr(hDlg, DWLP_USER);
  83. // check control
  84. if (!pCtrl->PrpCtrl)
  85. return FALSE;
  86. // get value if enable
  87. if (bEnable)
  88. {
  89. // get value of the control
  90. bResult = PRPCOM_Get_Value(
  91. pCtrl->PropertySet,
  92. pCtrl->ulPropertyId,
  93. pVfWExtInfo->pfnDeviceIoControl,
  94. pVfWExtInfo->lParam,
  95. &lValue);
  96. if (!bResult)
  97. return FALSE;
  98. // bring it into range of slider
  99. if (lValue < pCtrl->lMin)
  100. lValue = pCtrl->lMin;
  101. else if (lValue > pCtrl->lMax)
  102. lValue = pCtrl->lMax;
  103. // adjust if reverse
  104. if (pCtrl->bReverse)
  105. {
  106. lValue = pCtrl->lMin + pCtrl->lMax - lValue;
  107. }
  108. if (pCtrl->PrpCtrlType == PRPCTRL_TYPE_SLIDER)
  109. {
  110. // update slider pos
  111. SendMessage(
  112. GetDlgItem(hDlg, pCtrl->PrpCtrl),
  113. TBM_SETPOS, TRUE, (LPARAM)(LONG) lValue);
  114. }
  115. else if (pCtrl->PrpCtrlType == PRPCTRL_TYPE_CHECKBOX)
  116. {
  117. // update checkbox state
  118. SendMessage(GetDlgItem(hDlg, pCtrl->PrpCtrl), BM_SETCHECK, lValue, 0);
  119. }
  120. else
  121. return FALSE;
  122. // update buddy
  123. if (pCtrl->BuddyCtrl)
  124. {
  125. if (pCtrl->BuddyStrings != NULL)
  126. {
  127. SetDlgItemText(hDlg, pCtrl->BuddyCtrl, pCtrl->BuddyStrings[lValue]);
  128. }
  129. else
  130. {
  131. PRPCTRL_ScaleToPercent(&lValue, pCtrl->lMin, pCtrl->lMax);
  132. SetDlgItemInt(hDlg, pCtrl->BuddyCtrl, lValue, FALSE);
  133. }
  134. }
  135. }
  136. else
  137. {
  138. if (pCtrl->PrpCtrlType == PRPCTRL_TYPE_SLIDER)
  139. {
  140. // set the thumb to the middle of the slider
  141. lValue = pCtrl->lMin + (pCtrl->lMax - pCtrl->lMin) / 2;
  142. SendMessage(
  143. GetDlgItem(hDlg, pCtrl->PrpCtrl),
  144. TBM_SETPOS, TRUE, (LPARAM)(LONG) lValue);
  145. }
  146. // clear the buddy
  147. if (pCtrl->BuddyCtrl)
  148. SetDlgItemText(hDlg, pCtrl->BuddyCtrl, "");
  149. }
  150. // enable / disable controls.
  151. EnableWindow(GetDlgItem(hDlg, pCtrl->PrpCtrl), bEnable);
  152. if (pCtrl->BuddyCtrl)
  153. EnableWindow(GetDlgItem(hDlg, pCtrl->BuddyCtrl), bEnable);
  154. if (pCtrl->TextCtrl)
  155. EnableWindow(GetDlgItem(hDlg, pCtrl->TextCtrl), bEnable);
  156. return bResult;
  157. }
  158. /*-------------------------------------------------------------------------*/
  159. BOOL PRPCTRL_Handle_Msg(
  160. HWND hDlg,
  161. PRPCTRL_INFO *pCtrl)
  162. /*-------------------------------------------------------------------------*/
  163. {
  164. LONG lValue, lPos;
  165. BOOL bResult;
  166. PVFWEXT_INFO pVfWExtInfo = (PVFWEXT_INFO) GetWindowLongPtr(hDlg, DWLP_USER);
  167. if (pCtrl->PrpCtrlType == PRPCTRL_TYPE_SLIDER)
  168. {
  169. // get position of slider
  170. lPos = (LONG)SendMessage(
  171. GetDlgItem(hDlg, pCtrl->PrpCtrl),
  172. TBM_GETPOS, (WPARAM) 0, (LPARAM) 0);
  173. // bring it into range of slider
  174. if (lPos < pCtrl->lMin)
  175. lPos = pCtrl->lMin;
  176. else if (lPos > pCtrl->lMax)
  177. lPos = pCtrl->lMax;
  178. }
  179. else if (pCtrl->PrpCtrlType == PRPCTRL_TYPE_CHECKBOX)
  180. {
  181. // get state of checkbox
  182. if (SendMessage(GetDlgItem(hDlg, pCtrl->PrpCtrl),
  183. BM_GETCHECK, 0, 0) == BST_CHECKED)
  184. lPos = pCtrl->lMax;
  185. else
  186. lPos = pCtrl->lMin;
  187. }
  188. else
  189. return FALSE;
  190. // reverse if needed
  191. if (pCtrl->bReverse)
  192. lValue = pCtrl->lMin + pCtrl->lMax - lPos;
  193. else
  194. lValue = lPos;
  195. // Set value of property
  196. bResult = PRPCOM_Set_Value(
  197. pCtrl->PropertySet,
  198. pCtrl->ulPropertyId,
  199. pVfWExtInfo->pfnDeviceIoControl,
  200. pVfWExtInfo->lParam,
  201. lValue);
  202. if (!bResult)
  203. return FALSE;
  204. // update buddy
  205. if (pCtrl->BuddyCtrl)
  206. {
  207. if (pCtrl->BuddyStrings != NULL)
  208. {
  209. SetDlgItemText(hDlg, pCtrl->BuddyCtrl, pCtrl->BuddyStrings[lPos]);
  210. }
  211. else
  212. {
  213. PRPCTRL_ScaleToPercent(&lPos, pCtrl->lMin, pCtrl->lMax);
  214. SetDlgItemInt(hDlg, pCtrl->BuddyCtrl, lPos, FALSE);
  215. }
  216. }
  217. return TRUE;
  218. }
  219. /*-------------------------------------------------------------------------*/
  220. static void PRPCTRL_ScaleToPercent(LONG *plValue, LONG lMin, LONG lMax)
  221. /*-------------------------------------------------------------------------*/
  222. {
  223. // validate
  224. if (lMin >= lMax)
  225. {
  226. (*plValue) = lMin;
  227. return;
  228. }
  229. // check borders
  230. if ((*plValue) < lMin)
  231. {
  232. (*plValue) = 0;
  233. return;
  234. }
  235. if ((*plValue) > lMax)
  236. {
  237. (*plValue) = 10000;
  238. return;
  239. }
  240. (*plValue) = (((*plValue) - lMin) * 100) / (lMax - lMin);
  241. }