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.

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