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.

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