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.

1011 lines
29 KiB

  1. /*************************************************************************/
  2. /* Copyright (C) 1999 Microsoft Corporation */
  3. /* File: MSMFText.cpp */
  4. /* Description: Implementation of CMSMFText control object */
  5. /* Author: phillu */
  6. /* Date: 10/06/99 */
  7. /*************************************************************************/
  8. #include "stdafx.h"
  9. #include "MSMFCnt.h"
  10. #include "MSMFText.h"
  11. #include "CBitmap.h"
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMSMFText
  14. /*************************************************************************/
  15. /* Function: CMSMFText::CMSMFText() */
  16. /* Description: Initialize the properties and states. */
  17. /*************************************************************************/
  18. CMSMFText::CMSMFText()
  19. {
  20. m_fDirty = true;
  21. //properties
  22. m_clrBackColor = ::GetSysColor(COLOR_BTNFACE);
  23. m_uiState = TextState::Static;
  24. m_uiFontSize = 10;
  25. m_fDisabled = false;
  26. m_clrColorActive = 0x00ff0000; // blue
  27. m_clrColorStatic = 0x00000000; // black
  28. m_clrColorHover = 0x00ff0000; // blue
  29. m_clrColorPush = 0x00ffffff; // white
  30. m_clrColorDisable = 0x00808080; // grey
  31. m_bstrTextValue = L"";
  32. m_bstrFontFace = L"Arial";
  33. m_bstrAlignment = L"Center";
  34. m_bstrFontStyle = L"Normal";
  35. m_uiEdgeStyle = 0; // no edge
  36. #if 0 // used for getting the windowed case working DJ
  37. m_bWindowOnly = TRUE;
  38. #endif
  39. m_fTransparent = false;
  40. }
  41. /*************************************************************************/
  42. /* Function: CMSMFText::SetTextProperties */
  43. /* Description: Set the properties for the CText object. */
  44. /*************************************************************************/
  45. HRESULT CMSMFText::SetTextProperties()
  46. {
  47. HRESULT hr = S_OK;
  48. m_cText.SetFontFace(m_bstrFontFace);
  49. m_cText.SetFontSize(m_uiFontSize);
  50. m_cText.SetFontStyle(m_bstrFontStyle);
  51. m_cText.SetTextAlignment(m_bstrAlignment);
  52. m_cText.SetFixedSizeFont(true);
  53. // set the font color based on the current state
  54. OLE_COLOR clrColorCurrent = m_clrColorStatic;
  55. switch(m_uiState)
  56. {
  57. case(TextState::Static):
  58. clrColorCurrent = m_clrColorStatic;
  59. break;
  60. case(TextState::Hover):
  61. clrColorCurrent = m_clrColorHover;
  62. break;
  63. case(TextState::Active):
  64. clrColorCurrent = m_clrColorActive;
  65. break;
  66. case(TextState::Push):
  67. clrColorCurrent = m_clrColorPush;
  68. break;
  69. case(TextState::Disabled):
  70. clrColorCurrent = m_clrColorDisable;
  71. break;
  72. }
  73. // translate OLE_COLOR to COLORREF
  74. COLORREF crCurrentState;
  75. hr = OleTranslateColor(clrColorCurrent, CBitmap::GetSuperPal(), &crCurrentState);
  76. if (FAILED(hr))
  77. {
  78. crCurrentState = GetSysColor(COLOR_WINDOWTEXT);
  79. }
  80. m_cText.SetTextColor(crCurrentState);
  81. m_fDirty = false;
  82. return hr;
  83. }
  84. /*************************************************************************/
  85. /* Function: OnDraw */
  86. /* Description: Draw text in the specified rectangle. */
  87. /*************************************************************************/
  88. HRESULT CMSMFText::OnDraw(ATL_DRAWINFO& di)
  89. {
  90. USES_CONVERSION;
  91. HRESULT hr = S_OK;
  92. RECT& rc = *(RECT*)di.prcBounds;
  93. HPALETTE hNewPal = CBitmap::GetSuperPal();
  94. if (::IsWindow(m_hWnd)){ // is not windowless
  95. CBitmap::SelectRelizePalette(di.hdcDraw, hNewPal);
  96. }/* end of if statement */
  97. // draw background
  98. if (!m_fTransparent)
  99. {
  100. COLORREF clr;
  101. ::OleTranslateColor (m_clrBackColor, hNewPal, &clr);
  102. HBRUSH hbrBack = ::CreateSolidBrush(clr);
  103. if(NULL == hbrBack){
  104. hr = E_FAIL;
  105. return(hr);
  106. }/* end of if statement */
  107. ::FillRect(di.hdcDraw, &rc, hbrBack);
  108. ::DeleteObject(hbrBack);
  109. }
  110. if (m_fDirty)
  111. {
  112. SetTextProperties();
  113. }
  114. hr = m_cText.Write(di.hdcDraw, rc, m_bstrTextValue);
  115. // draw edge
  116. if (m_uiEdgeStyle != 0)
  117. {
  118. ::DrawEdge(di.hdcDraw, &rc, m_uiEdgeStyle, BF_RECT);
  119. }
  120. // draw focus rectagle
  121. HRESULT hr2 = GetFocus();
  122. if(S_OK == hr2)
  123. {
  124. ::DrawFocusRect(di.hdcDraw, (LPRECT)di.prcBounds);
  125. }
  126. return hr;
  127. }/* end of function OnDraw */
  128. /*************************************************************************/
  129. /* Function: get_FontSize */
  130. /* Description: return the FontSize property. */
  131. /*************************************************************************/
  132. STDMETHODIMP CMSMFText::get_FontSize(long *pVal)
  133. {
  134. if (!pVal)
  135. {
  136. return E_POINTER;
  137. }
  138. *pVal = m_uiFontSize;
  139. return S_OK;
  140. }
  141. /*************************************************************************/
  142. /* Function: put_FontSize */
  143. /* Description: set the FontSize property, in pt. */
  144. /*************************************************************************/
  145. STDMETHODIMP CMSMFText::put_FontSize(long lSize)
  146. {
  147. if ((UINT)lSize != m_uiFontSize)
  148. {
  149. m_uiFontSize = (UINT)lSize;
  150. m_fDirty = true;
  151. }
  152. return S_OK;
  153. }
  154. /*************************************************************************/
  155. /* Function: get_Text */
  156. /* Description: return the Text that is displayed in the control. */
  157. /*************************************************************************/
  158. STDMETHODIMP CMSMFText::get_Text(BSTR *pText)
  159. {
  160. if (!pText)
  161. {
  162. return E_POINTER;
  163. }
  164. *pText = m_bstrTextValue.Copy();
  165. return S_OK;
  166. }
  167. /*************************************************************************/
  168. /* Function: put_Text */
  169. /* Description: set the text to be displayed in the control. */
  170. /*************************************************************************/
  171. STDMETHODIMP CMSMFText::put_Text(BSTR wsText)
  172. {
  173. if (_wcsicmp(m_bstrTextValue, wsText) != 0)
  174. {
  175. m_bstrTextValue = wsText;
  176. FireViewChange();
  177. }
  178. return S_OK;
  179. }
  180. /*************************************************************************/
  181. /* Function: get_FontFace */
  182. /* Description: return the FontFace property. */
  183. /*************************************************************************/
  184. STDMETHODIMP CMSMFText::get_FontFace(BSTR *pFontFace)
  185. {
  186. if (!pFontFace)
  187. {
  188. return E_POINTER;
  189. }
  190. *pFontFace = m_bstrFontFace.Copy();
  191. return S_OK;
  192. }
  193. /*************************************************************************/
  194. /* Function: put_FontFace */
  195. /* Description: set the FontFace property. */
  196. /*************************************************************************/
  197. STDMETHODIMP CMSMFText::put_FontFace(BSTR wsFontFace)
  198. {
  199. if (_wcsicmp(m_bstrFontFace, wsFontFace) != 0)
  200. {
  201. m_bstrFontFace = wsFontFace;
  202. m_fDirty = true;
  203. }
  204. return S_OK;
  205. }
  206. /*************************************************************************/
  207. /* Function: get_FontStyle */
  208. /* Description: return the FontSize property. */
  209. /*************************************************************************/
  210. STDMETHODIMP CMSMFText::get_FontStyle(BSTR *pFontStyle)
  211. {
  212. if (!pFontStyle)
  213. {
  214. return E_POINTER;
  215. }
  216. *pFontStyle = m_bstrFontStyle.Copy();
  217. return S_OK;
  218. }
  219. /*************************************************************************/
  220. /* Function: put_FontStyle */
  221. /* Description: set the FontStyle property. The style string should */
  222. /* contain either "Normal", or concatenation of one or more strings of: */
  223. /* "Bold", "Italic", "Underline", "Strikeout". Default is "Normal". */
  224. /*************************************************************************/
  225. STDMETHODIMP CMSMFText::put_FontStyle(BSTR wsFontStyle)
  226. {
  227. if (_wcsicmp(m_bstrFontStyle, wsFontStyle) != 0)
  228. {
  229. m_bstrFontStyle = wsFontStyle;
  230. m_fDirty = true;
  231. }
  232. return S_OK;
  233. }
  234. /*************************************************************************/
  235. /* Function: get_TextAlignment */
  236. /* Description: return the TextAlignment (horizontal) property. */
  237. /*************************************************************************/
  238. STDMETHODIMP CMSMFText::get_TextAlignment(BSTR *pAlignment)
  239. {
  240. if (!pAlignment)
  241. {
  242. return E_POINTER;
  243. }
  244. *pAlignment = m_bstrAlignment.Copy();
  245. return S_OK;
  246. }
  247. /*************************************************************************/
  248. /* Function: put_TextAlignment */
  249. /* Description: set the TextAlignment property. It controls the */
  250. /* horizontal text alignment. Must be one of "Left", "Center", or */
  251. /* "Right". Default is "Center". */
  252. /*************************************************************************/
  253. STDMETHODIMP CMSMFText::put_TextAlignment(BSTR wsAlignment)
  254. {
  255. if (_wcsicmp(m_bstrAlignment, wsAlignment) != 0)
  256. {
  257. m_bstrAlignment = wsAlignment;
  258. m_fDirty = true;
  259. }
  260. return S_OK;
  261. }
  262. /*************************************************************************/
  263. /* Function: get_ColorPush */
  264. /* Description: return the ColorPush property. */
  265. /*************************************************************************/
  266. STDMETHODIMP CMSMFText::get_ColorPush(OLE_COLOR *pColor)
  267. {
  268. if (!pColor)
  269. {
  270. return E_POINTER;
  271. }
  272. *pColor = m_clrColorPush;
  273. return S_OK;
  274. }
  275. /*************************************************************************/
  276. /* Function: put_ColorPush */
  277. /* Description: set the ColorPush property. This is the color of text */
  278. /* in the Push state. */
  279. /*************************************************************************/
  280. STDMETHODIMP CMSMFText::put_ColorPush(OLE_COLOR clrColor)
  281. {
  282. m_clrColorPush = clrColor;
  283. if (m_uiState == TextState::Push)
  284. {
  285. m_fDirty = true;
  286. }
  287. return S_OK;
  288. }
  289. /*************************************************************************/
  290. /* Function: get_ColorHover */
  291. /* Description: return the ColorHover property. */
  292. /*************************************************************************/
  293. STDMETHODIMP CMSMFText::get_ColorHover(OLE_COLOR *pColor)
  294. {
  295. if (!pColor)
  296. {
  297. return E_POINTER;
  298. }
  299. *pColor = m_clrColorHover;
  300. return S_OK;
  301. }
  302. /*************************************************************************/
  303. /* Function: put_ColorHover */
  304. /* Description: set the ColorHover property. This is the color of text */
  305. /* in the Hover state. */
  306. /*************************************************************************/
  307. STDMETHODIMP CMSMFText::put_ColorHover(OLE_COLOR clrColor)
  308. {
  309. m_clrColorHover = clrColor;
  310. if (m_uiState == TextState::Hover)
  311. {
  312. m_fDirty = true;
  313. }
  314. return S_OK;
  315. }
  316. /*************************************************************************/
  317. /* Function: get_ColorStatic */
  318. /* Description: return the ColorStatic property. */
  319. /*************************************************************************/
  320. STDMETHODIMP CMSMFText::get_ColorStatic(OLE_COLOR *pColor)
  321. {
  322. if (!pColor)
  323. {
  324. return E_POINTER;
  325. }
  326. *pColor = m_clrColorStatic;
  327. return S_OK;
  328. }
  329. /*************************************************************************/
  330. /* Function: put_ColorPush */
  331. /* Description: set the ColorPush property. This is the color of text */
  332. /* in the Static (normal) state. */
  333. /*************************************************************************/
  334. STDMETHODIMP CMSMFText::put_ColorStatic(OLE_COLOR clrColor)
  335. {
  336. m_clrColorStatic = clrColor;
  337. if (m_uiState == TextState::Static)
  338. {
  339. m_fDirty = true;
  340. }
  341. return S_OK;
  342. }
  343. /*************************************************************************/
  344. /* Function: get_ColorDisable */
  345. /* Description: return the ColorDisable property. */
  346. /*************************************************************************/
  347. STDMETHODIMP CMSMFText::get_ColorDisable(OLE_COLOR *pColor)
  348. {
  349. if (!pColor)
  350. {
  351. return E_POINTER;
  352. }
  353. *pColor = m_clrColorDisable;
  354. return S_OK;
  355. }
  356. /*************************************************************************/
  357. /* Function: put_ColorDisable */
  358. /* Description: set the ColorDisable property. This is the color of text */
  359. /* in the Disabled state. */
  360. /*************************************************************************/
  361. STDMETHODIMP CMSMFText::put_ColorDisable(OLE_COLOR clrColor)
  362. {
  363. m_clrColorDisable = clrColor;
  364. if (m_uiState == TextState::Disabled)
  365. {
  366. m_fDirty = true;
  367. }
  368. return S_OK;
  369. }
  370. /*************************************************************************/
  371. /* Function: get_ColorActive */
  372. /* Description: return the ColorActive property. */
  373. /*************************************************************************/
  374. STDMETHODIMP CMSMFText::get_ColorActive(OLE_COLOR *pColor)
  375. {
  376. if (!pColor)
  377. {
  378. return E_POINTER;
  379. }
  380. *pColor = m_clrColorActive;
  381. return S_OK;
  382. }
  383. /*************************************************************************/
  384. /* Function: put_ColorActive */
  385. /* Description: set the ColorActive property. This is the color of text */
  386. /* in the Active state. */
  387. /*************************************************************************/
  388. STDMETHODIMP CMSMFText::put_ColorActive(OLE_COLOR clrColor)
  389. {
  390. m_clrColorActive = clrColor;
  391. if (m_uiState == TextState::Active)
  392. {
  393. m_fDirty = true;
  394. }
  395. return S_OK;
  396. }
  397. /*************************************************************************/
  398. /* Function: get_TextState */
  399. /* Description: return the TextState property. */
  400. /*************************************************************************/
  401. STDMETHODIMP CMSMFText::get_TextState(long *pState)
  402. {
  403. if (!pState)
  404. {
  405. return E_POINTER;
  406. }
  407. *pState = m_uiState;
  408. return S_OK;
  409. }
  410. /*************************************************************************/
  411. /* Function: put_TextState */
  412. /* Description: set the TextState property. It should be one of: */
  413. /* Static = 0, Hover = 1, Push = 2, Disabled = 3, Active = 4. */
  414. /*************************************************************************/
  415. STDMETHODIMP CMSMFText::put_TextState(long lState)
  416. {
  417. if (lState < 0 || lState > 4)
  418. {
  419. return E_INVALIDARG;
  420. }
  421. if ((UINT)lState != m_uiState)
  422. {
  423. m_uiState = (UINT)lState;
  424. m_fDirty = true;
  425. }
  426. return S_OK;
  427. }
  428. /*************************************************************************/
  429. /* Function: get_Disable */
  430. /* Description: return the Disable property. */
  431. /*************************************************************************/
  432. STDMETHODIMP CMSMFText::get_Disable(VARIANT_BOOL *pVal)
  433. {
  434. if (!pVal)
  435. {
  436. return E_POINTER;
  437. }
  438. *pVal = m_fDisabled?VARIANT_TRUE:VARIANT_FALSE;
  439. return S_OK;
  440. }
  441. /*************************************************************************/
  442. /* Function: put_Disable */
  443. /* Description: set the Disable property. */
  444. /*************************************************************************/
  445. STDMETHODIMP CMSMFText::put_Disable(VARIANT_BOOL newVal)
  446. {
  447. bool fDisabled;
  448. if (newVal == VARIANT_TRUE)
  449. {
  450. fDisabled = true;
  451. m_uiState = TextState::Disabled;
  452. }
  453. else
  454. {
  455. fDisabled = false;
  456. m_uiState = TextState::Static;
  457. }
  458. if (fDisabled != m_fDisabled)
  459. {
  460. m_fDisabled = fDisabled;
  461. m_fDirty = true;
  462. }
  463. return S_OK;
  464. }
  465. /*************************************************************************/
  466. /* Function: get_EdgeStyle */
  467. /* Description: return the EdgeStyle. */
  468. /*************************************************************************/
  469. STDMETHODIMP CMSMFText::get_EdgeStyle(BSTR *pStyle)
  470. {
  471. if (!pStyle)
  472. {
  473. return E_POINTER;
  474. }
  475. switch (m_uiEdgeStyle)
  476. {
  477. case 0: // no edge
  478. *pStyle = SysAllocString(L"None");
  479. break;
  480. case EDGE_SUNKEN:
  481. *pStyle = SysAllocString(L"Sunken");
  482. break;
  483. case EDGE_RAISED:
  484. *pStyle = SysAllocString(L"Raised");
  485. break;
  486. default:
  487. // we should not reach here
  488. *pStyle = NULL;
  489. DebugBreak();
  490. }
  491. return S_OK;
  492. }
  493. /*************************************************************************/
  494. /* Function: put_EdgeStyle */
  495. /* Description: set the EdgeStyle property. Must be one of "None", */
  496. /* "Raised", or "Sunken". Default is "None". */
  497. /*************************************************************************/
  498. STDMETHODIMP CMSMFText::put_EdgeStyle(BSTR wsStyle)
  499. {
  500. UINT uiStyle = 0;
  501. //set the text alignment
  502. if (!_wcsicmp(wsStyle, L"None"))
  503. {
  504. uiStyle = 0;
  505. }
  506. else if (!_wcsicmp(wsStyle, L"Sunken"))
  507. {
  508. uiStyle = EDGE_SUNKEN;
  509. }
  510. else if (!_wcsicmp(wsStyle, L"Raised"))
  511. {
  512. uiStyle = EDGE_RAISED;
  513. }
  514. if (m_uiEdgeStyle != uiStyle)
  515. {
  516. m_uiEdgeStyle = uiStyle;
  517. FireViewChange();
  518. }
  519. return S_OK;
  520. }
  521. /*************************************************************************/
  522. /* Function: OnButtonDown */
  523. /* Description: Handles when buttons is selected. Captures the mouse */
  524. /* movents (supported for windowless, via interfaces). */
  525. /*************************************************************************/
  526. LRESULT CMSMFText::OnButtonDown(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  527. if (m_uiState == TextState::Disabled){
  528. return 0;
  529. }/* end of if statement */
  530. LONG xPos = GET_X_LPARAM(lParam);
  531. LONG yPos = GET_Y_LPARAM(lParam);
  532. if(PtOnButton(xPos, yPos)){
  533. // we are really on the buttons bitmap and we pushed it
  534. if(TextState::Hover != m_uiState){
  535. // in hover case we already have captured the mouse, so do not do
  536. // that again
  537. SetCapture(true); // capture the mouse messages
  538. }/* end of if statement */
  539. SetButtonState(TextState::Push);
  540. }/* end of if statement */
  541. return 0;
  542. }/* end of function OnButtonDown */
  543. /*************************************************************************/
  544. /* Function: OnButtonUp */
  545. /* Description: Releases the capture, updates the button visual state, */
  546. /* and if release on the buttons image fire the event. */
  547. /*************************************************************************/
  548. LRESULT CMSMFText::OnButtonUp(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  549. if (m_uiState == TextState::Disabled){
  550. LONG lRes;
  551. ForwardWindowMessage(WM_USER_ENDHELP, (WPARAM) m_hWnd, 0, lRes);
  552. return 0;
  553. }/* end of if statement */
  554. LONG xPos = GET_X_LPARAM(lParam);
  555. LONG yPos = GET_Y_LPARAM(lParam);
  556. bool bOnButtonImage = PtOnButton(xPos, yPos);
  557. bool bFire = (m_uiState == TextState::Push);
  558. if(bOnButtonImage){
  559. SetButtonState(TextState::Static); //change to static even
  560. SetCapture(false); // release the capture of the mouse messages
  561. }
  562. else {
  563. SetButtonState(TextState::Static);
  564. // do it only when we do not hower, if we hower, then keep the capture
  565. SetCapture(false); // release the capture of the mouse messages
  566. }/* end of if statement */
  567. if (bFire){
  568. if(bOnButtonImage){
  569. Fire_OnClick();
  570. }/* end of if statement */
  571. }/* end of if statement */
  572. LONG lRes;
  573. ForwardWindowMessage(WM_USER_ENDHELP, (WPARAM) m_hWnd, 0, lRes);
  574. return 0;
  575. }/* end of function OnButtonUp */
  576. /*************************************************************************/
  577. /* Function: OnMouseMove */
  578. /* Description: Check if we were captured/pushed the do not do much, */
  579. /* otherwise do the hit detection and see if we are in static or hower */
  580. /* state. */
  581. /*************************************************************************/
  582. LRESULT CMSMFText::OnMouseMove(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  583. if (m_uiState == TextState::Disabled)
  584. return 0;
  585. LONG xPos = GET_X_LPARAM(lParam);
  586. LONG yPos = GET_Y_LPARAM(lParam);
  587. if (m_uiState != TextState::Push){
  588. if(PtOnButton(xPos, yPos)){
  589. if(TextState::Hover != m_uiState || S_OK != GetCapture()){
  590. SetCapture(true); // capture the mouse messages
  591. SetButtonState(TextState::Hover);
  592. }/* end of if statement */
  593. }
  594. else {
  595. if(TextState::Static != m_uiState){
  596. SetCapture(false); // release the capture of the mouse messages
  597. SetButtonState(TextState::Static);
  598. }/* end of if statement */
  599. }/* end of if statement */
  600. }/* end of if statement */
  601. return 0;
  602. }/* end of function OnMouseMove */
  603. /*************************************************************************/
  604. /* Function: OnSetFocus */
  605. /* Description: If we are in disabled state SetFocus(false) */
  606. /*************************************************************************/
  607. LRESULT CMSMFText::OnSetFocus(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  608. if (m_uiState == TextState::Disabled){
  609. if(GetFocus() == S_OK){
  610. SetFocus(false);
  611. }/* end of if statement */
  612. return(-1);
  613. }/* end of if statement */
  614. return 0;
  615. }/* end of function OnSetFocus */
  616. /*************************************************************************/
  617. /* Function: PtOnButton */
  618. /* Description: Uses helper to do the same. */
  619. /*************************************************************************/
  620. bool CMSMFText::PtOnButton(LONG x, LONG y){
  621. POINT pos = {x, y};
  622. return(PtOnButton(pos));
  623. }/* end of function PtOnButton */
  624. /*************************************************************************/
  625. /* Function: PtOnButton */
  626. /* Description: Determines if the point is located on the button. */
  627. /* TODO: Needs to be modified when we will handle transparent color. */
  628. /*************************************************************************/
  629. bool CMSMFText::PtOnButton(POINT pos){
  630. RECT rc;
  631. bool bRet = false;
  632. if(m_bWndLess){
  633. rc = m_rcPos;
  634. }
  635. else {
  636. if(!::IsWindow(m_hWnd)){
  637. return(bRet);
  638. }/* end of if statement */
  639. ::GetClientRect(m_hWnd, &rc);
  640. }/* end of if statement */
  641. bRet = PtInRect(&rc, pos) ? true : false;
  642. //TODO: Add also if we are on bitmap itsels possibly
  643. #ifdef _DEBUG
  644. if(bRet)
  645. ATLTRACE2(atlTraceWindowing, 20, TEXT("Point x = %d y = %d in Rect left = %d top %d right %d bottom %d\n"),
  646. pos.x, pos.y, m_rcPos.left, m_rcPos.top, m_rcPos.right, m_rcPos.bottom);
  647. else
  648. ATLTRACE2(atlTraceWindowing, 20, TEXT("Point x = %d y = %d NOT ON RECT Rect left = %d top %d right %d bottom %d\n"),
  649. pos.x, pos.y, m_rcPos.left, m_rcPos.top, m_rcPos.right, m_rcPos.bottom);
  650. #endif
  651. return(bRet);
  652. }/* end of function PtOnButton */
  653. /*************************************************************************/
  654. /* Function: SetButtonState */
  655. /* Description: Sets the button states forces redraw. */
  656. /*************************************************************************/
  657. HRESULT CMSMFText::SetButtonState(TextState txtState){
  658. HRESULT hr = S_OK;
  659. bool fRedraw = false;
  660. if((UINT)txtState != m_uiState ){
  661. fRedraw = true;
  662. }/* end of if statement */
  663. m_uiState = txtState;
  664. if(fRedraw){
  665. if (m_uiState == TextState::Disabled){
  666. SetFocus(false); // disable the focus
  667. SetCapture(false);
  668. }/* end of if statement */
  669. m_fDirty = true;
  670. FireViewChange(); // update the display
  671. }/* end of if statement */
  672. return(hr);
  673. }/* end of function SetButtonState */
  674. STDMETHODIMP CMSMFText::get_TextWidth(long *pVal)
  675. {
  676. HRESULT hr = S_OK;
  677. // special case early return
  678. if (m_bstrTextValue.Length() == 0){
  679. *pVal = 0;
  680. return S_OK;
  681. }/* end of if statement */
  682. // get the current window or the window of its parent
  683. HWND hwnd = GetWindow();
  684. HDC hdc = ::GetWindowDC(hwnd);
  685. if(NULL == hdc){
  686. return E_FAIL;
  687. }/* end of if statement */
  688. // normalize to pixel coord as required by the container
  689. SetMapMode(hdc, MM_TEXT);
  690. if (m_fDirty)
  691. {
  692. SetTextProperties();
  693. }
  694. SIZE size;
  695. hr = m_cText.GetTextWidth(hdc, m_bstrTextValue, &size);
  696. if (S_OK == hr)
  697. {
  698. *pVal = size.cx;
  699. }
  700. else
  701. {
  702. *pVal = 0;
  703. }
  704. ::ReleaseDC(hwnd, hdc);
  705. return hr;
  706. }
  707. STDMETHODIMP CMSMFText::get_TextHeight(long *pVal)
  708. {
  709. HRESULT hr = S_OK;
  710. // get the current window or the window of its parent
  711. HWND hwnd = GetWindow();
  712. HDC hdc = ::GetWindowDC(hwnd);
  713. if(NULL == hdc){
  714. return E_FAIL;
  715. }/* end of if statement */
  716. // normalize to pixel coord as required by the container
  717. SetMapMode(hdc, MM_TEXT);
  718. if (m_fDirty)
  719. {
  720. SetTextProperties();
  721. }
  722. SIZE size;
  723. hr = m_cText.GetTextWidth(hdc, m_bstrTextValue, &size);
  724. if (S_OK == hr)
  725. {
  726. *pVal = size.cy;
  727. }
  728. else
  729. {
  730. *pVal = 0;
  731. }
  732. ::ReleaseDC(hwnd, hdc); // do not forget to free DC
  733. return hr;
  734. }
  735. STDMETHODIMP CMSMFText::get_TransparentText(VARIANT_BOOL *pVal)
  736. {
  737. if (!pVal)
  738. {
  739. return E_POINTER;
  740. }
  741. *pVal = m_fTransparent?VARIANT_TRUE:VARIANT_FALSE;
  742. return S_OK;
  743. }
  744. STDMETHODIMP CMSMFText::put_TransparentText(VARIANT_BOOL newVal)
  745. {
  746. bool fTransparent;
  747. if (newVal == VARIANT_FALSE)
  748. {
  749. fTransparent = false;
  750. }
  751. else
  752. {
  753. fTransparent = true;
  754. }
  755. if (fTransparent != m_fTransparent)
  756. {
  757. m_fTransparent = fTransparent;
  758. FireViewChange();
  759. }
  760. return S_OK;
  761. }
  762. /*************************************************************/
  763. /* Name: SetObjectRects */
  764. /*************************************************************/
  765. STDMETHODIMP CMSMFText::SetObjectRects(LPCRECT prcPos,LPCRECT prcClip){
  766. // Call the default method first
  767. IOleInPlaceObjectWindowlessImpl<CMSMFText>::SetObjectRects(prcPos, prcClip);
  768. FireViewChange();
  769. return S_OK;
  770. }/* end of function SetObjectRects */
  771. /*************************************************************************/
  772. /* Function: OnSize */
  773. /*************************************************************************/
  774. LRESULT CMSMFText::OnSize(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
  775. bHandled = true;
  776. FireViewChange();
  777. return 0;
  778. }/* end of function OnSize */
  779. /*************************************************************************/
  780. /* End of file: MSMFText.cpp */
  781. /*************************************************************************/