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.

253 lines
6.5 KiB

  1. // Copyright (C) 1992-1999 Microsoft Corporation
  2. // All rights reserved.
  3. #include "stdafx.h"
  4. #include "stdafx2.h"
  5. #ifdef AFX_AUX_SEG
  6. #pragma code_seg(AFX_AUX_SEG)
  7. #endif
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. #define new DEBUG_NEW
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Choose Font dialog
  15. CFontDialog2::CFontDialog2(LPLOGFONT lplfInitial, DWORD dwFlags, CDC* pdcPrinter,
  16. CWnd* pParentWnd) : CCommonDialog(pParentWnd)
  17. {
  18. memset(&m_cf, 0, sizeof(m_cf));
  19. memset(&m_lf, 0, sizeof(m_lf));
  20. memset(&m_szStyleName, 0, sizeof(m_szStyleName));
  21. m_nIDHelp = AFX_IDD_FONT;
  22. m_cf.lStructSize = sizeof(m_cf);
  23. m_cf.lpszStyle = (LPTSTR)&m_szStyleName;
  24. m_cf.Flags = dwFlags | CF_ENABLEHOOK;
  25. if (!afxData.bWin4 && AfxHelpEnabled())
  26. m_cf.Flags |= CF_SHOWHELP;
  27. m_cf.lpfnHook = _AfxCommDlgProc;
  28. if (lplfInitial)
  29. {
  30. m_cf.lpLogFont = lplfInitial;
  31. m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
  32. memcpy(&m_lf, m_cf.lpLogFont, sizeof(m_lf));
  33. }
  34. else
  35. {
  36. m_cf.lpLogFont = &m_lf;
  37. }
  38. if (pdcPrinter)
  39. {
  40. ASSERT(pdcPrinter->m_hDC != NULL);
  41. m_cf.hDC = pdcPrinter->m_hDC;
  42. m_cf.Flags |= CF_PRINTERFONTS;
  43. }
  44. }
  45. CFontDialog2::CFontDialog2(const CHARFORMAT& charformat, DWORD dwFlags,
  46. CDC* pdcPrinter, CWnd* pParentWnd) : CCommonDialog(pParentWnd)
  47. {
  48. memset(&m_cf, 0, sizeof(m_cf));
  49. memset(&m_lf, 0, sizeof(m_lf));
  50. memset(&m_szStyleName, 0, sizeof(m_szStyleName));
  51. m_nIDHelp = AFX_IDD_FONT;
  52. m_cf.lStructSize = sizeof(m_cf);
  53. m_cf.lpszStyle = (LPTSTR)&m_szStyleName;
  54. m_cf.Flags = dwFlags | CF_ENABLEHOOK | CF_INITTOLOGFONTSTRUCT;
  55. m_cf.Flags |= FillInLogFont(charformat);
  56. if (!afxData.bWin4 && AfxHelpEnabled())
  57. m_cf.Flags |= CF_SHOWHELP;
  58. m_cf.lpfnHook = _AfxCommDlgProc;
  59. m_cf.lpLogFont = &m_lf;
  60. if (pdcPrinter)
  61. {
  62. ASSERT(pdcPrinter->m_hDC != NULL);
  63. m_cf.hDC = pdcPrinter->m_hDC;
  64. m_cf.Flags |= CF_PRINTERFONTS;
  65. }
  66. if (charformat.dwMask & CFM_COLOR)
  67. m_cf.rgbColors = charformat.crTextColor;
  68. }
  69. INT_PTR CFontDialog2::DoModal()
  70. {
  71. ASSERT_VALID(this);
  72. ASSERT(m_cf.Flags & CF_ENABLEHOOK);
  73. ASSERT(m_cf.lpfnHook != NULL); // can still be a user hook
  74. m_cf.hwndOwner = PreModal();
  75. int nResult = ::ChooseFont(&m_cf);
  76. PostModal();
  77. if (nResult == IDOK)
  78. {
  79. // copy logical font from user's initialization buffer (if needed)
  80. memcpy(&m_lf, m_cf.lpLogFont, sizeof(m_lf));
  81. return IDOK;
  82. }
  83. return nResult ? nResult : IDCANCEL;
  84. }
  85. void CFontDialog2::GetCurrentFont(LPLOGFONT lplf)
  86. {
  87. ASSERT(lplf != NULL);
  88. if (m_hWnd != NULL)
  89. SendMessage(WM_CHOOSEFONT_GETLOGFONT, 0, (DWORD_PTR)lplf);
  90. else
  91. *lplf = m_lf;
  92. }
  93. ////////////////////////////////////////////////////////////////////////////
  94. // CFontDialog2 CHARFORMAT helpers
  95. DWORD CFontDialog2::FillInLogFont(const CHARFORMAT& cf)
  96. {
  97. USES_CONVERSION;
  98. DWORD dwFlags = 0;
  99. if (cf.dwMask & CFM_SIZE)
  100. {
  101. CDC dc;
  102. dc.CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
  103. LONG yPerInch = dc.GetDeviceCaps(LOGPIXELSY);
  104. m_lf.lfHeight = -(int) ((cf.yHeight * yPerInch) / 1440);
  105. }
  106. else
  107. m_lf.lfHeight = 0;
  108. m_lf.lfWidth = 0;
  109. m_lf.lfEscapement = 0;
  110. m_lf.lfOrientation = 0;
  111. if ((cf.dwMask & (CFM_ITALIC|CFM_BOLD)) == (CFM_ITALIC|CFM_BOLD))
  112. {
  113. m_lf.lfWeight = (cf.dwEffects & CFE_BOLD) ? FW_BOLD : FW_NORMAL;
  114. m_lf.lfItalic = (BYTE)((cf.dwEffects & CFE_ITALIC) ? TRUE : FALSE);
  115. }
  116. else
  117. {
  118. dwFlags |= CF_NOSTYLESEL;
  119. m_lf.lfWeight = FW_DONTCARE;
  120. m_lf.lfItalic = FALSE;
  121. }
  122. if ((cf.dwMask & (CFM_UNDERLINE|CFM_STRIKEOUT|CFM_COLOR)) ==
  123. (CFM_UNDERLINE|CFM_STRIKEOUT|CFM_COLOR))
  124. {
  125. dwFlags |= CF_EFFECTS;
  126. m_lf.lfUnderline = (BYTE)((cf.dwEffects & CFE_UNDERLINE) ? TRUE : FALSE);
  127. m_lf.lfStrikeOut = (BYTE)((cf.dwEffects & CFE_STRIKEOUT) ? TRUE : FALSE);
  128. }
  129. else
  130. {
  131. m_lf.lfUnderline = (BYTE)FALSE;
  132. m_lf.lfStrikeOut = (BYTE)FALSE;
  133. }
  134. if (cf.dwMask & CFM_CHARSET)
  135. m_lf.lfCharSet = cf.bCharSet;
  136. else
  137. dwFlags |= CF_NOSCRIPTSEL;
  138. m_lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  139. m_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  140. m_lf.lfQuality = DEFAULT_QUALITY;
  141. if (cf.dwMask & CFM_FACE)
  142. {
  143. m_lf.lfPitchAndFamily = cf.bPitchAndFamily;
  144. StringCchCopy(m_lf.lfFaceName, ARRAYSIZE(m_lf.lfFaceName), cf.szFaceName); // ignoring return value
  145. }
  146. else
  147. {
  148. m_lf.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
  149. m_lf.lfFaceName[0] = (TCHAR)0;
  150. }
  151. return dwFlags;
  152. }
  153. void CFontDialog2::GetCharFormat(CHARFORMAT& cf) const
  154. {
  155. USES_CONVERSION;
  156. cf.dwEffects = 0;
  157. cf.dwMask = 0;
  158. if ((m_cf.Flags & CF_NOSTYLESEL) == 0)
  159. {
  160. cf.dwMask |= CFM_BOLD | CFM_ITALIC;
  161. cf.dwEffects |= (IsBold()) ? CFE_BOLD : 0;
  162. cf.dwEffects |= (IsItalic()) ? CFE_ITALIC : 0;
  163. }
  164. if ((m_cf.Flags & CF_NOSIZESEL) == 0)
  165. {
  166. cf.dwMask |= CFM_SIZE;
  167. //GetSize() returns in tenths of points so mulitply by 2 to get twips
  168. cf.yHeight = GetSize()*2;
  169. }
  170. if ((m_cf.Flags & CF_NOFACESEL) == 0)
  171. {
  172. cf.dwMask |= CFM_FACE;
  173. cf.bPitchAndFamily = m_cf.lpLogFont->lfPitchAndFamily;
  174. StringCchCopy(cf.szFaceName, ARRAYSIZE(cf.szFaceName), GetFaceName()); // ignoring return value
  175. }
  176. if (m_cf.Flags & CF_EFFECTS)
  177. {
  178. cf.dwMask |= CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR;
  179. cf.dwEffects |= (IsUnderline()) ? CFE_UNDERLINE : 0;
  180. cf.dwEffects |= (IsStrikeOut()) ? CFE_STRIKEOUT : 0;
  181. cf.crTextColor = GetColor();
  182. }
  183. if ((m_cf.Flags & CF_NOSCRIPTSEL) == 0)
  184. {
  185. cf.bCharSet = m_cf.lpLogFont->lfCharSet;
  186. cf.dwMask |= CFM_CHARSET;
  187. }
  188. cf.yOffset = 0;
  189. }
  190. ////////////////////////////////////////////////////////////////////////////
  191. // CFontDialog2 diagnostics
  192. #ifdef _DEBUG
  193. void CFontDialog2::Dump(CDumpContext& dc) const
  194. {
  195. CDialog::Dump(dc);
  196. dc << "m_cf.hwndOwner = " << (UINT)m_cf.hwndOwner;
  197. dc << "\nm_cf.hDC = " << (UINT)m_cf.hDC;
  198. dc << "\nm_cf.iPointSize = " << m_cf.iPointSize;
  199. dc << "\nm_cf.Flags = " << (LPVOID)m_cf.Flags;
  200. dc << "\nm_cf.lpszStyle = " << m_cf.lpszStyle;
  201. dc << "\nm_cf.nSizeMin = " << m_cf.nSizeMin;
  202. dc << "\nm_cf.nSizeMax = " << m_cf.nSizeMax;
  203. dc << "\nm_cf.nFontType = " << m_cf.nFontType;
  204. dc << "\nm_cf.rgbColors = " << (LPVOID)m_cf.rgbColors;
  205. if (m_cf.lpfnHook == _AfxCommDlgProc)
  206. dc << "\nhook function set to standard MFC hook function";
  207. else
  208. dc << "\nhook function set to non-standard hook function";
  209. dc << "\n";
  210. }
  211. #endif //_DEBUG
  212. #ifdef AFX_INIT_SEG
  213. #pragma code_seg(AFX_INIT_SEG)
  214. #endif
  215. IMPLEMENT_DYNAMIC(CFontDialog2, CDialog)
  216. ////////////////////////////////////////////////////////////////////////////