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

133 lines
3.4 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: fontlink.h
  7. *
  8. * Contents: Interface file for CFontLinker
  9. *
  10. * History: 17-Aug-98 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #ifndef FONTLINK_H
  14. #define FONTLINK_H
  15. #pragma once
  16. #include <string>
  17. #include <mlang.h>
  18. #include <comdef.h>
  19. HFONT GetFontFromDC (HDC hdc);
  20. class CRichText;
  21. class CFontLinker
  22. {
  23. public:
  24. CFontLinker ();
  25. virtual ~CFontLinker ();
  26. LRESULT OnCustomDraw (NMCUSTOMDRAW* pnmcd);
  27. void ReleaseFonts ();
  28. bool ComposeRichText (CRichText& rt);
  29. IMultiLanguage* GetMultiLang ();
  30. IMLangFontLink* GetFontLink ();
  31. virtual bool IsAnyItemLocalizable () const
  32. { return (true); }
  33. virtual bool IsItemLocalizable (NMCUSTOMDRAW* pnmcd) const
  34. { return (true); }
  35. virtual UINT GetDrawTextFlags () const
  36. { return (DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX | DT_SINGLELINE); }
  37. virtual std::wstring GetItemText (NMCUSTOMDRAW* pnmcd) const
  38. { return (L""); }
  39. private:
  40. LRESULT OnCustomDraw_PrePaint (NMCUSTOMDRAW* pnmcd);
  41. LRESULT OnCustomDraw_PostPaint (NMCUSTOMDRAW* pnmcd);
  42. LRESULT OnCustomDraw_ItemPrePaint (NMCUSTOMDRAW* pnmcd);
  43. bool GetFontCodePages (HDC hdc, HFONT hFont, DWORD& dwFontCodePages);
  44. typedef std::set<HFONT> FontSet;
  45. typedef std::map<HFONT, DWORD> FontToCodePagesMap;
  46. FontSet m_FontsToRelease;
  47. FontToCodePagesMap m_CodePages;
  48. IMultiLanguagePtr m_spMultiLang;
  49. IMLangFontLinkPtr m_spFontLink;
  50. UINT m_cPendingPostPaints;
  51. struct FontReleaser : public std::unary_function<HFONT, HRESULT>
  52. {
  53. public:
  54. FontReleaser (IMLangFontLink* pFontLink) : m_spFontLink (pFontLink) {}
  55. HRESULT operator() (HFONT hFont)
  56. {
  57. ASSERT (m_spFontLink != NULL);
  58. return (m_spFontLink->ReleaseFont (hFont));
  59. }
  60. private:
  61. IMLangFontLinkPtr const m_spFontLink;
  62. };
  63. };
  64. struct TextSegmentFontInfo
  65. {
  66. HFONT hFont;
  67. long cch;
  68. };
  69. class CRichText
  70. {
  71. friend class CFontLinker;
  72. public:
  73. CRichText (HDC hdc, std::wstring strText)
  74. : m_hdc (hdc),
  75. m_strText (strText),
  76. m_hDefaultFont (GetFontFromDC (hdc))
  77. {}
  78. ~CRichText ()
  79. {}
  80. bool IsDefaultFontSufficient () const
  81. { return (IsSingleFontSufficient() &&
  82. GetSufficientFont() == m_hDefaultFont); }
  83. bool IsSingleFontSufficient () const
  84. { return (m_TextSegments.size() == 1); }
  85. HFONT GetSufficientFont () const
  86. { return (m_TextSegments.front().hFont); }
  87. bool Draw (
  88. LPCRECT rect, /* i:rect to draw in */
  89. UINT uFormat, /* i:DrawText format flags */
  90. LPRECT prectRemaining = NULL) /* o:space remaining after drawing */
  91. const;
  92. private:
  93. typedef std::vector<TextSegmentFontInfo> TextSegmentFontInfoCollection;
  94. const HDC m_hdc;
  95. const std::wstring m_strText;
  96. const HFONT m_hDefaultFont;
  97. TextSegmentFontInfoCollection m_TextSegments;
  98. };
  99. #endif /* FONTLINK_H */