Source code of Windows XP (NT5)
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.

1202 lines
42 KiB

  1. /*************************************************************************/
  2. /* Copyright (C) 1999 Microsoft Corporation */
  3. /* File: MSMFSldr.cpp */
  4. /* Description: Implementation of CMSMFSldr */
  5. /* Author: David Janecek */
  6. /*************************************************************************/
  7. #include "stdafx.h"
  8. #include "MSMFCnt.h"
  9. #include "MSMFSldr.h"
  10. #define RECTWIDTH(lpRect) ((lpRect)->right - (lpRect)->left)
  11. #define RECTHEIGHT(lpRect) ((lpRect)->bottom - (lpRect)->top)
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMSMFSldr
  14. /*************************************************************************/
  15. /* Function: CMSMFSldr */
  16. /*************************************************************************/
  17. CMSMFSldr::CMSMFSldr(){
  18. Init();
  19. for(INT i = 0; i < cgMaxSldrStates; i++){
  20. m_pThumbBitmap[i] = new CBitmap;
  21. m_pBackBitmap[i] = new CBitmap;
  22. }/* end of for loop */
  23. }/* end of function CMSMFSldr */
  24. /*************************************************************************/
  25. /* Function: Init */
  26. /* Description: Initializes variable states. */
  27. /*************************************************************************/
  28. void CMSMFSldr::Init(){
  29. m_nEntry = SldrState::Static;
  30. m_fValue =0.2f;
  31. m_fMin =0;
  32. m_fMax = 100;
  33. m_lXOffset = 5;
  34. m_lYOffset = 2;
  35. m_fKeyIncrement = 4.0f;
  36. m_fKeyDecrement = 2.0f;
  37. m_lThumbWidth = 8;
  38. m_clrBackColor = ::GetSysColor(COLOR_BTNFACE);
  39. ::ZeroMemory(&m_rcThumb, sizeof(RECT));
  40. }/* end of function Init */
  41. /*************************************************************************/
  42. /* Function: ~CMSMFSldr */
  43. /* Description: Cleanup the stuff we allocated here rest will be done */
  44. /* in the button destructor. */
  45. /*************************************************************************/
  46. CMSMFSldr::~CMSMFSldr(){
  47. for(INT i = 0; i < cgMaxSldrStates; i++){
  48. delete m_pThumbBitmap[i];
  49. delete m_pBackBitmap[i];
  50. m_pBackBitmap[i] = NULL;
  51. m_pThumbBitmap[i] = NULL;
  52. }/* end of for loop */
  53. Init();
  54. }/* end of function CMSMFSldr */
  55. /*************************************************************************/
  56. /* Function: OnDraw */
  57. /* Description: Does the basic drawing */
  58. /* First draws the background the the thumb at the specific position. */
  59. /*************************************************************************/
  60. HRESULT CMSMFSldr::OnDraw(ATL_DRAWINFO& di){
  61. HRESULT hr = S_OK;
  62. BOOL bRet = TRUE;
  63. HDC hdc = di.hdcDraw;
  64. RECT rcClient = *(RECT*)di.prcBounds;
  65. // DRAW THE BACKGROUND
  66. if (::IsWindow(m_hWnd) && m_blitType != DISABLE) {
  67. // TODO: Optimaze palette handling
  68. #if 0
  69. HPALETTE hNewPal = m_pBitmap[m_nEntry]->GetPal();
  70. if(hNewPal){
  71. HPALETTE hPal = ::SelectPalette(di.hdcDraw, hNewPal, TRUE);
  72. ::RealizePalette(di.hdcDraw);
  73. }/* end of if statement */
  74. #endif
  75. COLORREF clr;
  76. HPALETTE hNewPal = m_pBackBitmap[m_nEntry]->GetPal();
  77. ::OleTranslateColor (m_clrBackColor, hNewPal, &clr);
  78. // fill background of specific color
  79. HBRUSH hbrBack = ::CreateSolidBrush(clr);
  80. //::FillRect(hdc, &rcClient, hbrBack);
  81. ::FillRect(di.hdcDraw, (LPRECT)di.prcBounds, hbrBack);
  82. ::DeleteObject(hbrBack);
  83. }/* end of if statement */
  84. if (m_pBackBitmap[m_nEntry]){
  85. bRet = m_pBackBitmap[m_nEntry]->PaintTransparentDIB(hdc, NULL,
  86. &rcClient, m_blitType);
  87. }
  88. else {
  89. COLORREF clr;
  90. ::OleTranslateColor (m_clrBackColor, m_pBackBitmap[m_nEntry]->GetPal(), &clr);
  91. HBRUSH hbrBack = ::CreateSolidBrush(clr);
  92. ::FillRect(hdc, &rcClient, hbrBack);
  93. ::DeleteObject(hbrBack);
  94. }/* end of if statement */
  95. // DRAW THE THUMB
  96. #if 0 // just for debugging purposes
  97. COLORREF clr = RGB(0xff, 0, 0);
  98. HBRUSH hbrBack = ::CreateSolidBrush(clr);
  99. ::FillRect(hdc, &m_rcThumb, hbrBack);
  100. ::DeleteObject(hbrBack);
  101. #endif
  102. if (m_pBackBitmap[m_nEntry]){
  103. RECT rcThumb = m_rcThumb;
  104. if(!m_bWndLess){
  105. ATLASSERT(::IsWindow(m_hWnd));
  106. ::OffsetRect(&rcThumb, -m_rcPos.left, -m_rcPos.top);
  107. }/* end of if statement */
  108. bRet = m_pThumbBitmap[m_nEntry]->PaintTransparentDIB(hdc, NULL,
  109. &rcThumb, m_blitType);
  110. } /* end of if statement */
  111. hr = GetFocus();
  112. // THIS ASSUMES WE ARE REPAINTING THE WHOLE CONTROL
  113. // WHICH IS WHAT ATL AT THIS INCARNATION DOES
  114. if(S_OK == hr){
  115. ::DrawFocusRect(hdc, &rcClient);
  116. }/* end of if statement */
  117. if(!bRet){
  118. hr = E_UNEXPECTED;
  119. }/* end of if statement */
  120. return (hr);
  121. }/* end of function OnDraw */
  122. /*************************************************************************/
  123. /* Function: OnSize */
  124. /* Description: Handles the onsize message if we are self contained. */
  125. /*************************************************************************/
  126. LRESULT CMSMFSldr::OnSize(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  127. bHandled = true;
  128. RecalculateTumbPos();
  129. //ATLASSERT(FALSE); // move the code from SetObjectRects in here
  130. return 0;
  131. }/* end of function OnSize */
  132. /*************************************************************************/
  133. /* Function: OnSetFocus */
  134. /* Description: If we are in disabled state SetFocus(false) */
  135. /*************************************************************************/
  136. LRESULT CMSMFSldr::OnSetFocus(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  137. if (m_nEntry == SldrState::Disabled){
  138. if(GetFocus() == S_OK){
  139. SetFocus(false);
  140. }/* end of if statement */
  141. FireViewChange();
  142. return(-1);
  143. }/* end of if statement */
  144. FireViewChange();
  145. return 0;
  146. }/* end of function OnSetFocus */
  147. /*************************************************************************/
  148. /* Function: OnKillFocus */
  149. /* Description: If we are in disabled state SetFocus(false) */
  150. /*************************************************************************/
  151. LRESULT CMSMFSldr::OnKillFocus(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  152. FireViewChange();
  153. return 0;
  154. }/* end of function OnKillFocus */
  155. /*************************************************************************/
  156. /* Function: OnButtonDown */
  157. /* Description: Handles when buttons is selected. Captures the mouse */
  158. /* movents (supported for windowless, via interfaces). */
  159. /*************************************************************************/
  160. LRESULT CMSMFSldr::OnButtonDown(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  161. if (m_nEntry == SldrState::Disabled){
  162. return 0;
  163. }/* end of if statement */
  164. LONG xPos = GET_X_LPARAM(lParam);
  165. LONG yPos = GET_Y_LPARAM(lParam);
  166. if(PtOnSlider(xPos, yPos)){
  167. if(SldrState::Hover != m_nEntry){
  168. // in hover case we already have captured the mouse, so do not do
  169. // that again
  170. SetCapture(true); // capture the mouse messages
  171. }/* end of if statement */
  172. OffsetX(xPos);
  173. SetThumbPos(xPos);
  174. SetSliderState(SldrState::Push);
  175. }/* end of if statement */
  176. Fire_OnMouseDown();
  177. return 0;
  178. }/* end of function OnButtonDown */
  179. /*************************************************************************/
  180. /* Function: OnButtonUp */
  181. /* Description: Releases the capture, updates the button visual state, */
  182. /* and if release on the buttons image fire the event. */
  183. /*************************************************************************/
  184. LRESULT CMSMFSldr::OnButtonUp(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  185. LONG lRes = 0;
  186. if (m_nEntry == SldrState::Disabled){
  187. ForwardWindowMessage(WM_USER_FOCUS, (WPARAM) m_hWnd, 0, lRes);
  188. return lRes;
  189. }/* end of if statement */
  190. LONG xPos = GET_X_LPARAM(lParam);
  191. LONG yPos = GET_Y_LPARAM(lParam);
  192. bool bOnButtonImage = PtOnSlider(xPos, yPos);
  193. bool bFire = (m_nEntry == SldrState::Push);
  194. if(bOnButtonImage){
  195. SetSliderState(SldrState::Static); //change to static even
  196. SetCapture(false); // release the capture of the mouse messages
  197. }
  198. else {
  199. SetSliderState(SldrState::Static);
  200. // do it only when we do not hower, if we hower, then keep the capture
  201. SetCapture(false); // release the capture of the mouse messages
  202. }/* end of if statement */
  203. if (bFire){
  204. if(bOnButtonImage){
  205. OffsetX(xPos);
  206. SetThumbPos(xPos);
  207. Fire_OnClick();
  208. }/* end of if statement */
  209. }/* end of if statement */
  210. Fire_OnMouseUp();
  211. ForwardWindowMessage(WM_USER_FOCUS, (WPARAM) m_hWnd, 0, lRes);
  212. return lRes;
  213. }/* end of function OnButtonUp */
  214. /*************************************************************************/
  215. /* Function: OnMouseMove */
  216. /* Description: Check if we were captured/pushed the do not do much, */
  217. /* otherwise do the hit detection and see if we are in static or hower */
  218. /* state. */
  219. /*************************************************************************/
  220. LRESULT CMSMFSldr::OnMouseMove(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  221. if (m_nEntry == SldrState::Disabled)
  222. return 0;
  223. LONG xPos = GET_X_LPARAM(lParam);
  224. LONG yPos = GET_Y_LPARAM(lParam);
  225. bool fPointOnSlider = PtOnSlider(xPos, yPos);
  226. if (m_nEntry != SldrState::Push){
  227. if(fPointOnSlider){
  228. if(SldrState::Hover != m_nEntry || S_OK != GetCapture()){
  229. SetCapture(true); // capture the mouse messages
  230. SetSliderState(SldrState::Hover);
  231. }/* end of if statement */
  232. }
  233. else {
  234. if(SldrState::Static != m_nEntry){
  235. SetCapture(false); // release the capture of the mouse messages
  236. SetSliderState(SldrState::Static);
  237. }/* end of if statement */
  238. }/* end of if statement */
  239. }
  240. else {
  241. if(fPointOnSlider){
  242. OffsetX(xPos);
  243. SetThumbPos(xPos);
  244. FireViewChange();
  245. }/* end of if statement */
  246. }/* end of if statement */
  247. return 0;
  248. }/* end of function OnMouseMove */
  249. /*************************************************************************/
  250. /* Function: OnKeyDown */
  251. /* Description: Depresses the button. */
  252. /*************************************************************************/
  253. LRESULT CMSMFSldr::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam,
  254. BOOL& bHandled){
  255. bHandled = FALSE;
  256. LONG lRes = 0;
  257. switch(wParam){
  258. case VK_RETURN:
  259. case VK_SPACE:
  260. case VK_LEFT:
  261. case VK_RIGHT:
  262. SetSliderState(SldrState::Push);
  263. break;
  264. }/* end of if statement */
  265. return(lRes);
  266. }/* end of function OnKeyDown */
  267. /*************************************************************************/
  268. /* Function: OnKeyUp */
  269. /* Description: Distrubutes the keyboard messages properly. */
  270. /*************************************************************************/
  271. LRESULT CMSMFSldr::OnKeyUp(UINT uMsg, WPARAM wParam, LPARAM lParam,
  272. BOOL& bHandled){
  273. bHandled = FALSE;
  274. LONG lRes = 0;
  275. LONG xPos = m_rcThumb.left + m_lThumbWidth /2;
  276. switch(wParam){
  277. case VK_RETURN:
  278. case VK_SPACE:
  279. break;
  280. case VK_LEFT: m_fValue -= m_fKeyDecrement; FitValue();
  281. break;
  282. case VK_RIGHT: m_fValue += m_fKeyIncrement; FitValue();
  283. break;
  284. }/* end of switch statement */
  285. RecalculateTumbPos();
  286. Fire_OnClick(); // we clicked on it, it does not meen
  287. // we did change the value of it
  288. SetSliderState(SldrState::Static);
  289. return(lRes);
  290. }/* end of function OnKeyUp */
  291. /*************************************************************/
  292. /* Function: FitValue */
  293. /* Description: Fits the xVal inside the params. */
  294. /*************************************************************/
  295. HRESULT CMSMFSldr::FitValue(){
  296. if(m_fValue < m_fMin){
  297. m_fValue = m_fMin;
  298. }/* end of if statement */
  299. if(m_fValue > m_fMax){
  300. m_fValue = m_fMax;
  301. }/* end of if statement */
  302. return(S_OK);
  303. }/* end of function FitValue */
  304. /*************************************************************/
  305. /* Name: SetObjectRects */
  306. /* Description: Update thumbnail rect object is being moved */
  307. /*************************************************************/
  308. STDMETHODIMP CMSMFSldr::SetObjectRects(LPCRECT prcPos,LPCRECT prcClip){
  309. // Call the default method first
  310. IOleInPlaceObjectWindowlessImpl<CMSMFSldr>::SetObjectRects(prcPos, prcClip);
  311. RecalculateTumbPos();
  312. return S_OK;
  313. }/* end of function SetObjectRects */
  314. /*************************************************************************/
  315. /* Function: PutThumbImage */
  316. /* Description: Sets the image to thumb. */
  317. /*************************************************************************/
  318. HRESULT CMSMFSldr::PutThumbImage(BSTR strFilename, int nEntry){
  319. HRESULT hr = S_OK;
  320. m_bstrThumbFilename[nEntry] = strFilename;
  321. // figure out if we need to gray out the image
  322. bool fGrayOut = false;
  323. if(SldrState::Disabled == nEntry){
  324. fGrayOut = gcfGrayOut;
  325. }/* end of if statement */
  326. hr = m_pThumbBitmap[nEntry]->PutImage(strFilename, m_hRes, GetUnknown(),fGrayOut ,m_blitType);
  327. if(FAILED(hr)){
  328. return(hr);
  329. }/* end of if statement */
  330. if(nEntry == m_nEntry ){
  331. // we are updating image that is being used, refresh it
  332. ATLTRACE2(atlTraceWindowing, 20, TEXT("Redrawing the image\n"));
  333. InvalidateRgn(); // our helper function
  334. }/* end of if statement */
  335. return(hr);
  336. }/* end of function PutThumbImage */
  337. /*************************************************************************/
  338. /* Function: PutBackImage */
  339. /* Description: Sets the image to Back. */
  340. /*************************************************************************/
  341. HRESULT CMSMFSldr::PutBackImage(BSTR strFilename, int nEntry){
  342. HRESULT hr = S_OK;
  343. m_bstrBackFilename[nEntry] = strFilename;
  344. bool fGrayOut = false;
  345. if(SldrState::Disabled == nEntry){
  346. fGrayOut = gcfGrayOut; // TODO some more complex stuff if we get custom disable
  347. // images
  348. }/* end of if statement */
  349. hr = m_pBackBitmap[nEntry]->PutImage(strFilename, m_hRes, GetUnknown(),fGrayOut ,m_blitType);
  350. if(FAILED(hr)){
  351. return(hr);
  352. }/* end of if statement */
  353. if(nEntry == m_nEntry ){
  354. // we are updating image that is being used, refresh it
  355. ATLTRACE2(atlTraceWindowing, 20, TEXT("Redrawing the image\n"));
  356. InvalidateRgn(); // our helper function
  357. }/* end of if statement */
  358. return(hr);
  359. }/* end of function PutBackImage */
  360. /*************************************************************************/
  361. /* Function: get_Value */
  362. /* Description: Get the current value. */
  363. /*************************************************************************/
  364. STDMETHODIMP CMSMFSldr::get_Value(float *pVal){
  365. *pVal = m_fValue;
  366. return S_OK;
  367. }/* end of function get_Value */
  368. /*************************************************************************/
  369. /* Function: put_Value */
  370. /* Description: Sets the current value */
  371. /*************************************************************************/
  372. STDMETHODIMP CMSMFSldr::put_Value(float newVal){
  373. HRESULT hr = S_OK;
  374. if(newVal < m_fMin || newVal > m_fMax){
  375. hr = E_INVALIDARG;
  376. return (hr);
  377. }/* end of if statement */
  378. if(newVal == m_fValue){
  379. hr = S_FALSE;
  380. return(hr);
  381. }/* end of if statement */
  382. m_fValue = newVal;
  383. RecalculateTumbPos(); // apply the new position to the tumb rect and invalidate
  384. return (hr);
  385. }/* end of function put_Value */
  386. /*************************************************************************/
  387. /* Function: get_Min */
  388. /* Description: Gets the minimum value on which the rect should expand */
  389. /*************************************************************************/
  390. STDMETHODIMP CMSMFSldr::get_Min(float *pVal){
  391. *pVal = m_fMin;
  392. return S_OK;
  393. }/* end of function get_Min */
  394. /*************************************************************************/
  395. /* Function: put_Max */
  396. /*************************************************************************/
  397. STDMETHODIMP CMSMFSldr::put_Min(float newVal){
  398. HRESULT hr = S_OK;
  399. m_fMin = newVal;
  400. hr = RecalculateTumbPos(); // apply the new position to the tumb rect and invalidate
  401. //ATLASSERT(SUCCEEDED(hr));
  402. return (S_OK);
  403. }/* end of function put_Min */
  404. /*************************************************************************/
  405. /* Function: get_Max */
  406. /*************************************************************************/
  407. STDMETHODIMP CMSMFSldr::get_Max(float *pVal){
  408. *pVal = m_fMax;
  409. return S_OK;
  410. }/* end of function get_Max */
  411. /*************************************************************************/
  412. /* Function: put_Max */
  413. /*************************************************************************/
  414. STDMETHODIMP CMSMFSldr::put_Max(float newVal){
  415. HRESULT hr = S_OK;
  416. m_fMax = newVal;
  417. hr = RecalculateTumbPos(); // apply the new position to the tumb rect and invalidate
  418. //ATLASSERT(SUCCEEDED(hr));
  419. return (S_OK);
  420. }/* end of function put_Max */
  421. /*************************************************************************/
  422. /* Function: get_XOffset */
  423. /* Descriptoin: The part we do not draw on, end of the rail.. */
  424. /*************************************************************************/
  425. STDMETHODIMP CMSMFSldr::get_XOffset(LONG *pVal){
  426. *pVal = m_lXOffset;
  427. return S_OK;
  428. }/* end of function get_XOffset */
  429. /*************************************************************************/
  430. /* Function: put_XOffset */
  431. /* Description: Adjust it, cache our new FLOAT offset and recalculate */
  432. /* the position. */
  433. /*************************************************************************/
  434. STDMETHODIMP CMSMFSldr::put_XOffset(LONG newVal){
  435. HRESULT hr = S_OK;
  436. m_lXOffset = newVal;
  437. hr = RecalculateTumbPos(); // apply the new position to the tumb rect and invalidate
  438. //ATLASSERT(SUCCEEDED(hr));
  439. return (S_OK);
  440. }/* end of function put_XOffset */
  441. /*************************************************************************/
  442. /* Function: get_Offset */
  443. /* Descriptoin: The part we do not draw on, end of the rail.. */
  444. /*************************************************************************/
  445. STDMETHODIMP CMSMFSldr::get_YOffset(LONG *pVal){
  446. *pVal = m_lYOffset;
  447. return S_OK;
  448. }/* end of function get_YOffset */
  449. /*************************************************************************/
  450. /* Function: put_YOffset */
  451. /* Description: Adjust it, cache our new FLOAT offset and recalculate */
  452. /* the position. */
  453. /*************************************************************************/
  454. STDMETHODIMP CMSMFSldr::put_YOffset(LONG newVal){
  455. HRESULT hr = S_OK;
  456. m_lYOffset = newVal;
  457. m_rcThumb.top = m_rcPos.top - m_lYOffset;
  458. m_rcThumb.bottom = m_rcPos.bottom - m_lYOffset;
  459. FireViewChange();
  460. return (hr);
  461. }/* end of function put_YOffset */
  462. /*************************************************************************/
  463. /* Function: get_ThumbWidth */
  464. /* Descriptoin: Width of the thumb. */
  465. /*************************************************************************/
  466. STDMETHODIMP CMSMFSldr::get_ThumbWidth(LONG *pVal){
  467. *pVal = m_lThumbWidth;
  468. return S_OK;
  469. }/* end of function get_YOffset */
  470. /*************************************************************************/
  471. /* Function: put_ThumbWidth */
  472. /* Description: Sets the thumb width. */
  473. /*************************************************************************/
  474. STDMETHODIMP CMSMFSldr::put_ThumbWidth(LONG newVal){
  475. HRESULT hr = S_OK;
  476. m_lThumbWidth = newVal;
  477. RecalculateTumbPos();
  478. return (S_OK);
  479. }/* end of function put_YOffset */
  480. /*************************************************************************/
  481. /* Function: get_ThumbStatic */
  482. /*************************************************************************/
  483. STDMETHODIMP CMSMFSldr::get_ThumbStatic(BSTR *pstrFilename){
  484. *pstrFilename = m_bstrThumbFilename[SldrState::Static].Copy();
  485. return S_OK;
  486. }/* end of function get_ThumbStatic */
  487. /*************************************************************************/
  488. /* Function: put_ThumbStatic */
  489. /*************************************************************************/
  490. STDMETHODIMP CMSMFSldr::put_ThumbStatic(BSTR strFilename){
  491. if (!m_bstrThumbFilename[SldrState::Disabled]){
  492. PutThumbImage(strFilename, SldrState::Disabled);
  493. }/* end of if statement */
  494. return (PutThumbImage(strFilename, SldrState::Static));
  495. }/* end of function put_ThumbStatic */
  496. /*************************************************************************/
  497. /* Function: get_ThumbHover */
  498. /*************************************************************************/
  499. STDMETHODIMP CMSMFSldr::get_ThumbHover(BSTR *pstrFilename){
  500. *pstrFilename = m_bstrThumbFilename[SldrState::Hover].Copy();
  501. return S_OK;
  502. }/* end of function get_ThumbHover */
  503. /*************************************************************************/
  504. /* Function: put_ThumbHover */
  505. /*************************************************************************/
  506. STDMETHODIMP CMSMFSldr::put_ThumbHover(BSTR strFilename){
  507. return (PutThumbImage(strFilename, SldrState::Hover));
  508. }/* end of function put_ThumbHover */
  509. /*************************************************************************/
  510. /* Function: get_ThumbPush */
  511. /*************************************************************************/
  512. STDMETHODIMP CMSMFSldr::get_ThumbPush(BSTR *pstrFilename){
  513. *pstrFilename = m_bstrThumbFilename[SldrState::Push].Copy();
  514. return S_OK;
  515. }/* end of function get_ThumbPush */
  516. /*************************************************************************/
  517. /* Function: put_ThumbPush */
  518. /*************************************************************************/
  519. STDMETHODIMP CMSMFSldr::put_ThumbPush(BSTR strFilename){
  520. return (PutThumbImage(strFilename, SldrState::Push));
  521. }/* end of function put_ThumbPush */
  522. /*************************************************************************/
  523. /* Function: get_ThumbDisabled */
  524. /*************************************************************************/
  525. STDMETHODIMP CMSMFSldr::get_ThumbDisabled(BSTR *pstrFilename){
  526. *pstrFilename = m_bstrThumbFilename[SldrState::Disabled].Copy();
  527. return S_OK;
  528. }/* end of function get_ThumbDisabled */
  529. /*************************************************************************/
  530. /* Function: put_ThumbDisabled */
  531. /*************************************************************************/
  532. STDMETHODIMP CMSMFSldr::put_ThumbDisabled(BSTR strFilename){
  533. return (PutThumbImage(strFilename, SldrState::Disabled));
  534. }/* end of function put_ThumbDisabled */
  535. /*************************************************************************/
  536. /* Function: get_ThumbActive */
  537. /*************************************************************************/
  538. STDMETHODIMP CMSMFSldr::get_ThumbActive(BSTR *pstrFilename){
  539. *pstrFilename = m_bstrThumbFilename[SldrState::Active].Copy();
  540. return S_OK;
  541. }/* end of function get_ThumbActive */
  542. /*************************************************************************/
  543. /* Function: put_ThumbActive */
  544. /*************************************************************************/
  545. STDMETHODIMP CMSMFSldr::put_ThumbActive(BSTR strFilename){
  546. return (PutThumbImage(strFilename, SldrState::Active));
  547. }/* end of function put_ThumbActive */
  548. /*************************************************************************/
  549. /* Function: get_BackStatic */
  550. /*************************************************************************/
  551. STDMETHODIMP CMSMFSldr::get_BackStatic(BSTR *pstrFilename){
  552. *pstrFilename = m_bstrBackFilename[SldrState::Static].Copy();
  553. return S_OK;
  554. }/* end of function get_BackStatic */
  555. /*************************************************************************/
  556. /* Function: put_BackStatic */
  557. /*************************************************************************/
  558. STDMETHODIMP CMSMFSldr::put_BackStatic(BSTR strFilename){
  559. if (!m_bstrBackFilename[SldrState::Disabled]){
  560. PutBackImage(strFilename, SldrState::Disabled);
  561. }/* end of if statement */
  562. return (PutBackImage(strFilename, SldrState::Static));
  563. }/* end of function put_BackStatic */
  564. /*************************************************************************/
  565. /* Function: get_BackHover */
  566. /*************************************************************************/
  567. STDMETHODIMP CMSMFSldr::get_BackHover(BSTR *pstrFilename){
  568. *pstrFilename = m_bstrBackFilename[SldrState::Hover].Copy();
  569. return S_OK;
  570. }/* end of function get_BackHover */
  571. /*************************************************************************/
  572. /* Function: put_BackHover */
  573. /*************************************************************************/
  574. STDMETHODIMP CMSMFSldr::put_BackHover(BSTR strFilename){
  575. return (PutBackImage(strFilename, SldrState::Hover));
  576. }/* end of function put_BackHover */
  577. /*************************************************************************/
  578. /* Function: get_BackPush */
  579. /*************************************************************************/
  580. STDMETHODIMP CMSMFSldr::get_BackPush(BSTR *pstrFilename){
  581. *pstrFilename = m_bstrBackFilename[SldrState::Push].Copy();
  582. return S_OK;
  583. }/* end of function get_BackPush */
  584. /*************************************************************************/
  585. /* Function: put_BackPush */
  586. /*************************************************************************/
  587. STDMETHODIMP CMSMFSldr::put_BackPush(BSTR strFilename){
  588. return (PutBackImage(strFilename, SldrState::Push));
  589. }/* end of function put_BackPush */
  590. /*************************************************************************/
  591. /* Function: get_BackDisabled */
  592. /*************************************************************************/
  593. STDMETHODIMP CMSMFSldr::get_BackDisabled(BSTR *pstrFilename){
  594. *pstrFilename = m_bstrBackFilename[SldrState::Disabled].Copy();
  595. return S_OK;
  596. }/* end of function get_BackDisabled */
  597. /*************************************************************************/
  598. /* Function: put_BackDisabled */
  599. /*************************************************************************/
  600. STDMETHODIMP CMSMFSldr::put_BackDisabled(BSTR strFilename){
  601. return (PutBackImage(strFilename, SldrState::Disabled));
  602. }/* end of function put_BackDisabled */
  603. /*************************************************************************/
  604. /* Function: get_BackActive */
  605. /*************************************************************************/
  606. STDMETHODIMP CMSMFSldr::get_BackActive(BSTR *pstrFilename){
  607. *pstrFilename = m_bstrBackFilename[SldrState::Active].Copy();
  608. return S_OK;
  609. }/* end of function get_BackActive */
  610. /*************************************************************************/
  611. /* Function: put_BackActive */
  612. /*************************************************************************/
  613. STDMETHODIMP CMSMFSldr::put_BackActive(BSTR strFilename){
  614. return (PutBackImage(strFilename, SldrState::Active));
  615. }/* end of function put_BackActive */
  616. /*************************************************************/
  617. /* Function: get_SldrState */
  618. /* Description: Gets current slider state. */
  619. /*************************************************************/
  620. STDMETHODIMP CMSMFSldr::get_SldrState(long *pVal){
  621. *pVal = (long) m_nEntry;
  622. return S_OK;
  623. }/* end of function get_SldrState */
  624. /*************************************************************************/
  625. /* Function: put_SldrState */
  626. /* Description: Sets slider state. */
  627. /*************************************************************************/
  628. STDMETHODIMP CMSMFSldr::put_SldrState(long newVal){
  629. HRESULT hr = SetSliderState((SldrState)newVal);
  630. return (hr);
  631. }/* end of function put_SldrState */
  632. /*************************************************************/
  633. /* Function: get_Disable */
  634. /* Description: Returns OLE-BOOL if disabled or enabled. */
  635. /*************************************************************/
  636. STDMETHODIMP CMSMFSldr::get_Disable(VARIANT_BOOL *pVal){
  637. *pVal = SldrState::Disabled == m_nEntry ? VARIANT_TRUE : VARIANT_FALSE;
  638. return S_OK;
  639. }/* end of function get_Disable */
  640. /*************************************************************/
  641. /* Function: put_Disable */
  642. /* Description: Disable or enable the buttons (disabled */
  643. /* are greyed out and do not except mouse clicks). */
  644. /*************************************************************/
  645. STDMETHODIMP CMSMFSldr::put_Disable(VARIANT_BOOL newVal){
  646. SldrState sldrSt = VARIANT_FALSE == newVal ? SldrState::Static : SldrState::Disabled;
  647. HRESULT hr = SetSliderState(sldrSt);
  648. return (hr);
  649. }/* end of function put_Disable */
  650. /*************************************************************************/
  651. /* HELPER Functions */
  652. /*************************************************************************/
  653. /*************************************************************************/
  654. /* Function: RecalculateTumbPos */
  655. /* Description: Centers the rect around x value. */
  656. /* This one calculate the thumb rectangle x position. */
  657. /*************************************************************************/
  658. HRESULT CMSMFSldr::RecalculateTumbPos(){
  659. HRESULT hr = S_OK;
  660. // offset the rect depending on the y value
  661. m_rcThumb.top = m_rcPos.top + m_lYOffset;
  662. m_rcThumb.bottom = m_rcPos.bottom - m_lYOffset;
  663. // just offset x coordibate of the thumb the rect depening on the new xValue
  664. // calculate the length
  665. FLOAT flLengthU = m_fMax - m_fMin; // length in units
  666. FLOAT flLengthR = (FLOAT)RECTWIDTH(&m_rcPos) - 2* m_lXOffset;
  667. // calcalate the center of the thumb in RECT coordinates
  668. FLOAT fPos = (m_fValue - m_fMin) * flLengthR / flLengthU;
  669. // fPos is at the center of the thumb
  670. LONG lThumbWidthHalf = m_lThumbWidth/2;
  671. LONG lPos = (INT)fPos + m_lXOffset + m_rcPos.left;
  672. if(lPos < (m_rcPos.left + lThumbWidthHalf) || lPos > (m_rcPos.right - lThumbWidthHalf)){
  673. // we are of the rectangle
  674. hr = E_FAIL;
  675. return(hr);
  676. }/* end of if statement */
  677. LONG lOldPos = m_rcThumb.left + lThumbWidthHalf;
  678. if(lOldPos == lPos){
  679. // thumb is in the same position as before so lets not bother with it
  680. hr = S_FALSE;
  681. return(hr);
  682. }/* end of if statement */
  683. m_rcThumb.left = lPos - lThumbWidthHalf;
  684. m_rcThumb.right = lPos + lThumbWidthHalf;
  685. FireViewChange();
  686. return(hr);
  687. }/* end of function RecalculateTumbPos */
  688. /*************************************************************************/
  689. /* Function: RecalculateValue */
  690. /* Description: Recalculates the slider value, since the thumb rect has */
  691. /* changed. */
  692. /*************************************************************************/
  693. HRESULT CMSMFSldr::RecalculateValue(){
  694. HRESULT hr = S_OK;
  695. // calculate the length
  696. FLOAT flLengthU = m_fMax - m_fMin; // length in units
  697. FLOAT flLengthR = (FLOAT)RECTWIDTH(&m_rcPos) - 2* m_lXOffset;
  698. LONG lThumbXPos = m_rcThumb.left + m_lThumbWidth/2;
  699. lThumbXPos -= m_rcPos.left + m_lXOffset; // shift it over to 0 origin at left offset
  700. // calcalate the center of the thumb in VALUE coordinates
  701. FLOAT fPos = m_fMin + (lThumbXPos) * flLengthU / flLengthR;
  702. // fPos is at the center of the thumb
  703. if(fPos < (m_fMin) || fPos > (m_fMax)){
  704. // we are of the rectangle
  705. hr = E_FAIL;
  706. return(hr);
  707. }/* end of if statement */
  708. m_fValue = fPos;
  709. // Fire Event that we have changed our value
  710. return(hr);
  711. }/* end of function RecalculateValue */
  712. /*************************************************************************/
  713. /* Function: SetSliderState */
  714. /* Description: Sets the button states forces redraw. */
  715. /*************************************************************************/
  716. HRESULT CMSMFSldr::SetSliderState(SldrState sldrState){
  717. HRESULT hr = S_OK;
  718. bool fRedraw = false;
  719. if(sldrState != m_nEntry ){
  720. fRedraw = true;
  721. }/* end of if statement */
  722. m_nEntry = sldrState;
  723. if(fRedraw){
  724. if (m_nEntry == SldrState::Disabled){
  725. SetFocus(false); // disable the focus
  726. SetCapture(false);
  727. }/* end of if statement */
  728. // we are updating image that is being used, refresh it
  729. ATLTRACE2(atlTraceWindowing, 20, TEXT("Redrawing the image\n"));
  730. FireViewChange(); // update the display
  731. //InvalidateRgn(); // our helper function
  732. }/* end of if statement */
  733. return(hr);
  734. }/* end of function SetSliderState */
  735. /*************************************************************************/
  736. /* Function: PtOnSlider */
  737. /* Description: Uses helper to do the same. */
  738. /*************************************************************************/
  739. bool CMSMFSldr::PtOnSlider(LONG x, LONG y){
  740. POINT pos = {x, y};
  741. return(PtOnSlider(pos));
  742. }/* end of function PtOnSlider */
  743. /*************************************************************************/
  744. /* Function: PtOnSlider */
  745. /* Description: Determines if the point is located on the slider. */
  746. /* TODO: Needs to be modified when we will handle transparent color. */
  747. /*************************************************************************/
  748. bool CMSMFSldr::PtOnSlider(POINT pos){
  749. RECT rc;
  750. bool bRet = false;
  751. if(m_bWndLess){
  752. rc = m_rcPos;
  753. }
  754. else {
  755. if(!::IsWindow(m_hWnd)){
  756. return(bRet);
  757. }/* end of if statement */
  758. ::GetClientRect(m_hWnd, &rc);
  759. }/* end of if statement */
  760. bRet = PtInRect(&rc, pos) ? true : false;
  761. //TODO: Add also if we are on bitmap itsels possibly
  762. #ifdef _DEBUG
  763. if(bRet)
  764. ATLTRACE2(atlTraceWindowing, 20, TEXT("Point x = %d y = %d in Rect left = %d top %d right %d bottom %d\n"),
  765. pos.x, pos.y, m_rcPos.left, m_rcPos.top, m_rcPos.right, m_rcPos.bottom);
  766. else
  767. ATLTRACE2(atlTraceWindowing, 20, TEXT("Point x = %d y = %d NOT ON RECT Rect left = %d top %d right %d bottom %d\n"),
  768. pos.x, pos.y, m_rcPos.left, m_rcPos.top, m_rcPos.right, m_rcPos.bottom);
  769. #endif
  770. return(bRet);
  771. }/* end of function PtOnSlider */
  772. /*************************************************************************/
  773. /* Function: PtOnThumb */
  774. /* Description: Uses helper to do the same. */
  775. /*************************************************************************/
  776. bool CMSMFSldr::PtOnThumb(LONG x, LONG y){
  777. POINT pos = {x, y};
  778. return(PtOnThumb(pos));
  779. }/* end of function PtOnThumb */
  780. /*************************************************************************/
  781. /* Function: PtOnThumb */
  782. /* Description: Determines if the point is located on the slider. */
  783. /* TODO: Needs to be modified when we will handle transparent color. */
  784. /*************************************************************************/
  785. bool CMSMFSldr::PtOnThumb(POINT pos){
  786. RECT rc;
  787. bool bRet = false;
  788. if(m_bWndLess){
  789. rc = m_rcPos;
  790. }
  791. else {
  792. if(!::IsWindow(m_hWnd)){
  793. return(bRet);
  794. }/* end of if statement */
  795. ::GetClientRect(m_hWnd, &rc);
  796. }/* end of if statement */
  797. bRet = PtInRect(&rc, pos) ? true : false;
  798. return(bRet);
  799. }/* end of function PtOnThumb */
  800. /*************************************************************************/
  801. /* Function: OffsetX */
  802. /* Description: Adjusts the x position for windows case when we are 0,0 */
  803. /* based. */
  804. /*************************************************************************/
  805. HRESULT CMSMFSldr::OffsetX(LONG& xPos){
  806. HRESULT hr = S_OK;
  807. if(m_bWndLess){
  808. return(hr);
  809. }/* end of if statement */
  810. ATLASSERT(::IsWindow(m_hWnd));
  811. xPos = m_rcPos.left + xPos;
  812. return(hr);
  813. }/* end of function OffsetX */
  814. /*************************************************************************/
  815. /* Function: SetThumbPos */
  816. /* Description: Sets the thumb position. */
  817. /*************************************************************************/
  818. HRESULT CMSMFSldr::SetThumbPos(LONG xPos){
  819. HRESULT hr = S_FALSE;
  820. //MOVE THE THUMB TO THIS X POSITION
  821. long ThumbWidthHalf = m_lThumbWidth /2;
  822. // see if the positions are the same
  823. if(m_rcThumb.left + ThumbWidthHalf != xPos){
  824. // see if we are with offset regions
  825. if((xPos > (m_rcPos.left + m_lXOffset)) &&
  826. (xPos < (m_rcPos.right - m_lXOffset))){
  827. m_rcThumb.left = xPos - ThumbWidthHalf;
  828. m_rcThumb.right = xPos + ThumbWidthHalf;
  829. hr = RecalculateValue();
  830. if(SUCCEEDED(hr)){
  831. Fire_OnValueChange(m_fValue); // fire to the container that we are chaning the value
  832. }/* end of if statement */
  833. }
  834. else {
  835. hr = E_FAIL; // not in the offset any more
  836. }/* end of if statement*/
  837. }/* end of if statement */
  838. return(hr);
  839. }/* end of function SetThumbPos */
  840. /*************************************************************************/
  841. /* Function: get_ArrowKeyIncrement */
  842. /*************************************************************************/
  843. STDMETHODIMP CMSMFSldr::get_ArrowKeyIncrement(FLOAT *pVal){
  844. *pVal = m_fKeyIncrement;
  845. return S_OK;
  846. }/* end of function get_ArrowKeyIncrement */
  847. /*************************************************************************/
  848. /* Function: put_ArrowKeyIncrement */
  849. /*************************************************************************/
  850. STDMETHODIMP CMSMFSldr::put_ArrowKeyIncrement(FLOAT newVal){
  851. m_fKeyIncrement = newVal;
  852. return S_OK;
  853. }/* end of function put_ArrowKeyIncrement */
  854. /*************************************************************************/
  855. /* Function: get_ArrowKeyDecrement */
  856. /*************************************************************************/
  857. STDMETHODIMP CMSMFSldr::get_ArrowKeyDecrement(float *pVal){
  858. *pVal = m_fKeyDecrement;
  859. return S_OK;
  860. }/* end of function get_ArrowKeyDecrement */
  861. /*************************************************************************/
  862. /* Function: put_ArrowKeyDecrement */
  863. /*************************************************************************/
  864. STDMETHODIMP CMSMFSldr::put_ArrowKeyDecrement(float newVal){
  865. m_fKeyDecrement = newVal;
  866. return S_OK;
  867. }/* end of function put_ArrowKeyDecrement */
  868. /*************************************************************************/
  869. /* End of file: MSMFSldr.cpp */
  870. /*************************************************************************/