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.

213 lines
5.9 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // AtlBaseSheet.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CBaseSheetWindow class.
  10. //
  11. // Author:
  12. // David Potter (davidp) December 4, 1997
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include <StrSafe.h>
  20. #include "AtlBaseSheet.h"
  21. #include "AtlExtDll.h"
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Global Variables
  24. /////////////////////////////////////////////////////////////////////////////
  25. static LPCTSTR g_pszDefaultFontFaceName = _T("MS Shell Dlg");
  26. /////////////////////////////////////////////////////////////////////////////
  27. // class CBaseSheetWindow
  28. /////////////////////////////////////////////////////////////////////////////
  29. /////////////////////////////////////////////////////////////////////////////
  30. //++
  31. //
  32. // CBaseSheetWindow::~CBaseSheetWindow
  33. //
  34. // Routine Description:
  35. // Destructor.
  36. //
  37. // Arguments:
  38. // None.
  39. //
  40. // Return Value:
  41. // None.
  42. //
  43. //--
  44. /////////////////////////////////////////////////////////////////////////////
  45. CBaseSheetWindow::~CBaseSheetWindow( void )
  46. {
  47. //
  48. // Delete the extension information.
  49. //
  50. delete m_pext;
  51. } //*** CBaseSheetWindow::~CBaseSheetWindow()
  52. /////////////////////////////////////////////////////////////////////////////
  53. //++
  54. //
  55. // static
  56. // CBaseSheetWindow::BCreateFont
  57. //
  58. // Routine Description:
  59. // Create a font with only point size and type face name.
  60. //
  61. // Arguments:
  62. // rfont [OUT] Font to create.
  63. // nPoints [IN] Point size.
  64. // pszFaceName [IN] Font face name. Defaults to "MS Shell Dlg".
  65. // bBold [IN] Font should be bold.
  66. // bItalic [IN] Font should be italic.
  67. // bUnderline [IN] Font should be underline.
  68. //
  69. // Return Value:
  70. // TRUE Font created successfully.
  71. // FALSE Error creating font. Call GetLastError() for more details.
  72. //
  73. //--
  74. /////////////////////////////////////////////////////////////////////////////
  75. BOOL CBaseSheetWindow::BCreateFont(
  76. OUT CFont & rfont,
  77. IN LONG nPoints,
  78. IN LPCTSTR pszFaceName, // = _T("MS Shell Dlg")
  79. IN BOOL bBold, // = FALSE
  80. IN BOOL bItalic, // = FALSE
  81. IN BOOL bUnderline // = FALSE
  82. )
  83. {
  84. HRESULT hr;
  85. HFONT hfont = NULL;
  86. //
  87. // Get non-client metrics for basing the new font off of.
  88. //
  89. NONCLIENTMETRICS ncm = { 0 };
  90. ncm.cbSize = sizeof( ncm );
  91. SystemParametersInfo( SPI_GETNONCLIENTMETRICS, 0, &ncm, 0 );
  92. //
  93. // Copy the message font and set the face name and point size to what
  94. // was passed in. The point size needs to be multiplied by 10 due to how
  95. // the CFont::CreatePointFontIndirect calculates the actual font height.
  96. //
  97. LOGFONT lfNewFont = ncm.lfMessageFont;
  98. if ( pszFaceName == NULL )
  99. {
  100. pszFaceName = g_pszDefaultFontFaceName;
  101. } // if: no type face name specified
  102. ATLASSERT( _tcslen( pszFaceName ) + 1 < RTL_NUMBER_OF( lfNewFont.lfFaceName ) );
  103. hr = StringCchCopy( lfNewFont.lfFaceName, RTL_NUMBER_OF( lfNewFont.lfFaceName ), pszFaceName );
  104. if ( FAILED( hr ) )
  105. {
  106. SetLastError( hr );
  107. goto Cleanup;
  108. }
  109. lfNewFont.lfHeight = nPoints * 10;
  110. //
  111. // Set bold, italic, and underline values.
  112. //
  113. if ( bBold )
  114. {
  115. lfNewFont.lfWeight = FW_BOLD;
  116. } // if: bold font requested
  117. if ( bItalic )
  118. {
  119. lfNewFont.lfItalic = TRUE;
  120. } // if: italic font requested
  121. if ( bUnderline )
  122. {
  123. lfNewFont.lfUnderline = TRUE;
  124. } // if: underlined font requested
  125. //
  126. // Create the font.
  127. //
  128. hfont = rfont.CreatePointFontIndirect( &lfNewFont );
  129. Cleanup:
  130. return ( hfont != NULL );
  131. } //*** BCreateFont()
  132. /////////////////////////////////////////////////////////////////////////////
  133. //++
  134. //
  135. // static
  136. // CBaseSheetWindow::BCreateFont
  137. //
  138. // Routine Description:
  139. // Create a font with only point size and type face name.
  140. //
  141. // Arguments:
  142. // rfont [OUT] Font to create.
  143. // idsPoints [IN] Resource ID for the font point size.
  144. // idsFaceName [IN] Resource ID for the font face name. Defaults to "MS Shell Dlg".
  145. // bBold [IN] Font should be bold.
  146. // bItalic [IN] Font should be italic.
  147. // bUnderline [IN] Font should be underline.
  148. //
  149. // Return Value:
  150. // TRUE Font created successfully.
  151. // FALSE Error creating font. Call GetLastError() for more details.
  152. //
  153. //--
  154. /////////////////////////////////////////////////////////////////////////////
  155. BOOL CBaseSheetWindow::BCreateFont(
  156. OUT CFont & rfont,
  157. IN UINT idsPoints,
  158. IN UINT idsFaceName,
  159. IN BOOL bBold, // = FALSE
  160. IN BOOL bItalic, // = FALSE
  161. IN BOOL bUnderline // = FALSE
  162. )
  163. {
  164. BOOL bSuccess;
  165. CString strFaceName;
  166. CString strPoints;
  167. LONG nPoints;
  168. //
  169. // Load the face name.
  170. //
  171. bSuccess = strFaceName.LoadString( idsFaceName );
  172. ATLASSERT( bSuccess );
  173. if ( ! bSuccess )
  174. {
  175. strFaceName = g_pszDefaultFontFaceName;
  176. } // if: no errors loading the string
  177. //
  178. // Load the point size.
  179. //
  180. bSuccess = strPoints.LoadString( idsPoints );
  181. ATLASSERT( bSuccess );
  182. if ( ! bSuccess)
  183. {
  184. nPoints = 12;
  185. } // if: no errors loading the string
  186. else
  187. {
  188. nPoints = _tcstoul( strPoints, NULL, 10 );
  189. } // else: error loading the string
  190. //
  191. // Create the font.
  192. //
  193. return BCreateFont( rfont, nPoints, strFaceName, bBold, bItalic, bUnderline );
  194. } //*** CBaseSheetWindow::BCreateFont()