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.

309 lines
8.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: about.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "about.h"
  12. #include "bitmap.h"
  13. #define EDIT_CONTROL_CRLF _T("\r\r\n")
  14. //
  15. // This file implements the About Properties used by the snap-in manager
  16. //
  17. CSnapinAbout::CSnapinAbout()
  18. {
  19. TRACE_METHOD(CSnapinAbout, CSnapinAbout);
  20. CommonContruct();
  21. }
  22. void CSnapinAbout::CommonContruct()
  23. {
  24. m_bBasicInfo = FALSE;
  25. m_bFullInfo = FALSE;
  26. m_cMask = RGB(0,0,0);
  27. m_hrObjectStatus = S_OK;
  28. }
  29. BOOL CSnapinAbout::GetInformation(CLSID& clsid, int nType)
  30. {
  31. TRACE_METHOD(CSnapinAbout, GetInformation);
  32. if (m_bFullInfo == TRUE || m_bBasicInfo == TRUE)
  33. {
  34. TRACE(_T("Destroying old Snapin information\n"));
  35. // Preserve the snapin name, it can't be reloaded from
  36. // the snapin ISnapinAbout interface
  37. LPOLESTR strTemp = m_lpszSnapinName.Detach();
  38. CSnapinAbout::~CSnapinAbout();
  39. m_lpszSnapinName.Attach(strTemp);
  40. }
  41. m_bFullInfo = m_bBasicInfo = FALSE;
  42. // Create the interface and get the snap-in information
  43. ISnapinAboutPtr spAboutInfo;
  44. m_hrObjectStatus = spAboutInfo.CreateInstance(clsid, NULL, MMC_CLSCTX_INPROC);
  45. if (FAILED(m_hrObjectStatus))
  46. return FALSE;
  47. // Basic info (required to display snapin node)
  48. HBITMAP hbmSmallImage;
  49. HBITMAP hbmSmallImageOpen;
  50. HBITMAP hbmLargeImage;
  51. if (SUCCEEDED(spAboutInfo->GetStaticFolderImage (&hbmSmallImage,
  52. &hbmSmallImageOpen,
  53. &hbmLargeImage,
  54. &m_cMask)))
  55. {
  56. /*
  57. * Bug 249817: The bitmaps are out parameters, so the caller (MMC)
  58. * should own them and be responsible for destroying them.
  59. * Unfortunately, the docs for ISnapinAbout::GetStaticFolderImage
  60. * specifically instruct the snap-in to destroy them when the
  61. * ISnapinAbout interface is released. We have to make copies instead.
  62. */
  63. m_SmallImage = CopyBitmap (hbmSmallImage);
  64. m_SmallImageOpen = CopyBitmap (hbmSmallImageOpen);
  65. m_LargeImage = CopyBitmap (hbmLargeImage);
  66. }
  67. m_bBasicInfo = TRUE;
  68. if (nType == BASIC_INFO)
  69. return TRUE;
  70. // Full information (required for About box)
  71. HICON hTemp;
  72. /*
  73. * Bug 249817: The icon is an out parameter, so the caller (MMC)
  74. * should own it and be responsible for destroying it.
  75. * Unfortunately, the docs for ISnapinAbout::GetSnapinImage
  76. * specifically instruct the snap-in to destroy it when the
  77. * ISnapinAbout interface is released. We have to make a copy instead.
  78. */
  79. if (SUCCEEDED(spAboutInfo->GetSnapinImage(&hTemp)))
  80. m_AppIcon.Attach(CopyIcon(hTemp));
  81. LPOLESTR strTemp;
  82. if (SUCCEEDED(spAboutInfo->GetSnapinDescription(&strTemp)))
  83. m_lpszDescription.Attach(strTemp);
  84. if (SUCCEEDED(spAboutInfo->GetProvider(&strTemp)))
  85. m_lpszCompanyName.Attach(strTemp);
  86. if (SUCCEEDED(spAboutInfo->GetSnapinVersion(&strTemp)))
  87. m_lpszVersion.Attach(strTemp);
  88. m_bFullInfo = TRUE;
  89. return TRUE;
  90. }
  91. void CSnapinAbout::ShowAboutBox()
  92. {
  93. TRACE_METHOD(CSnapinAbout, Show);
  94. CSnapinAboutDialog dlg(this);
  95. dlg.DoModal();
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CSnapinAboutPage message handlers
  99. LRESULT CSnapinAboutDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  100. {
  101. // hook up controls
  102. DECLARE_SC(sc, TEXT("CSnapinAboutDialog::OnInitDialog"));
  103. sc = ScCheckPointers(m_pAboutInfo, E_UNEXPECTED);
  104. if (sc)
  105. return TRUE;
  106. // Title should be set "About <SnapinName>"
  107. // Raid# 661363: This does not work for some languages
  108. // where the <SnapinName> needs to appear after the equivalent
  109. // for "About". The fix is to obtain the title not by concatenation
  110. // but by string construction using the IDS_ABOUT resource as
  111. // a format specifier. For English, for example, the format
  112. // specifier is "About %s"
  113. // Format Specifier
  114. tstring szfmtAbout;
  115. bool bRet = szfmtAbout.LoadString(GetStringModule(), IDS_ABOUT);
  116. if (!bRet)
  117. return TRUE;
  118. USES_CONVERSION;
  119. // <Snapin Name>
  120. tstring szSnapin;
  121. LPCOLESTR lpszSnapinName = m_pAboutInfo->GetSnapinName();
  122. if (lpszSnapinName)
  123. {
  124. szSnapin = OLE2CT(lpszSnapinName);
  125. }
  126. else
  127. {
  128. bRet = szSnapin.LoadString(GetStringModule(), IDS_SNAPINSTR);
  129. if (!bRet)
  130. return TRUE;
  131. }
  132. // Construct the title
  133. WTL::CString szTitle;
  134. szTitle.Format (szfmtAbout.data(), szSnapin.data());
  135. SetWindowText(szTitle);
  136. HWND hwndSnapinInfo = ::GetDlgItem(*this, IDC_SNAPIN_INFO);
  137. sc = ScCheckPointers(hwndSnapinInfo, E_UNEXPECTED);
  138. if (sc)
  139. return TRUE;
  140. m_SnapinInfo.Attach(hwndSnapinInfo);
  141. if (lpszSnapinName)
  142. {
  143. m_SnapinInfo.AppendText(OLE2CT(lpszSnapinName));
  144. m_SnapinInfo.AppendText(EDIT_CONTROL_CRLF);
  145. }
  146. LPCOLESTR lpszCompanyName = m_pAboutInfo->GetCompanyName();
  147. if (lpszCompanyName)
  148. {
  149. m_SnapinInfo.AppendText(OLE2CT(lpszCompanyName));
  150. m_SnapinInfo.AppendText(EDIT_CONTROL_CRLF);
  151. }
  152. LPCOLESTR lpszVersion = m_pAboutInfo->GetVersion();
  153. if (lpszVersion)
  154. {
  155. tstring szVersion;
  156. bRet = szVersion.LoadString(GetStringModule(), IDS_VERSION);
  157. if (!bRet)
  158. return TRUE;
  159. m_SnapinInfo.AppendText(szVersion.data());
  160. m_SnapinInfo.AppendText(OLE2CT(lpszVersion));
  161. }
  162. HWND hwndSnapinDesc = ::GetDlgItem(*this, IDC_SNAPIN_DESC);
  163. sc = ScCheckPointers(hwndSnapinDesc, E_UNEXPECTED);
  164. if (sc)
  165. return TRUE;
  166. m_SnapinDesc.Attach(hwndSnapinDesc);
  167. LPCOLESTR lpszDescription = m_pAboutInfo->GetDescription();
  168. sc = ScSetDescriptionUIText(m_SnapinDesc, lpszDescription ? OLE2CT(lpszDescription) : _T(""));
  169. if (sc)
  170. return TRUE;
  171. // App icon
  172. HICON hAppIcon = m_pAboutInfo->GetSnapinIcon();
  173. if (hAppIcon)
  174. {
  175. HWND const icon = ::GetDlgItem(*this, IDC_APPICON);
  176. ASSERT(icon != NULL);
  177. m_hIcon.Attach(icon);
  178. m_hIcon.SetIcon(hAppIcon);
  179. }
  180. return TRUE;
  181. }
  182. LRESULT
  183. CSnapinAboutDialog::OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  184. {
  185. EndDialog(IDOK);
  186. return TRUE;
  187. }
  188. LRESULT
  189. CSnapinAboutDialog::OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  190. {
  191. EndDialog(IDCANCEL);
  192. return FALSE;
  193. }
  194. //+-------------------------------------------------------------------
  195. //
  196. // Member: ScSetDescriptionUIText
  197. //
  198. // Synopsis: Given a edit control window & description text. Insert
  199. // the text into the control and enable scrollbar if needed.
  200. //
  201. // Arguments: [hwndSnapinDescEdit] - The edit control window handle.
  202. // [lpszDescription] - The description text (cant be NULL).
  203. //
  204. // Returns: SC
  205. //
  206. //--------------------------------------------------------------------
  207. SC ScSetDescriptionUIText(HWND hwndSnapinDescEdit, LPCTSTR lpszDescription)
  208. {
  209. DECLARE_SC(sc, TEXT("ScSetDescriptionUIText"));
  210. sc = ScCheckPointers(hwndSnapinDescEdit, lpszDescription);
  211. if (sc)
  212. return sc;
  213. // 1. Attach the window to WTL::CEdit object.
  214. WTL::CEdit wndsnapinDesc(hwndSnapinDescEdit);
  215. // 2. Insert the text into the window.
  216. wndsnapinDesc.SetWindowText(lpszDescription);
  217. /*
  218. * 3. The description control may need scroll bar.
  219. * This is determined below, if ( (# of lines * height of one line) > rectangle-height).
  220. */
  221. // 3a) turn-off scroll & do the calculation, so that scroll-bar width does not
  222. // modify linecount below.
  223. wndsnapinDesc.ShowScrollBar(SB_VERT, FALSE);
  224. WTL::CDC dc(wndsnapinDesc.GetWindowDC());
  225. if (dc.IsNull())
  226. return (sc = E_UNEXPECTED);
  227. TEXTMETRIC tm;
  228. // 3b) Calculate height of a single line.
  229. HFONT hOldFont = dc.SelectFont(wndsnapinDesc.GetFont());
  230. dc.GetTextMetrics(&tm);
  231. int cyLineHeight = tm.tmHeight + tm.tmExternalLeading;
  232. // 3c) Calculate edit box dimensions in logical units.
  233. WTL::CRect rect;
  234. wndsnapinDesc.GetRect(&rect);
  235. dc.DPtoLP(&rect);
  236. int nLines = wndsnapinDesc.GetLineCount();
  237. // 3d) If the total text height exceeds edit box height so turn on scroll.
  238. if ( (nLines * cyLineHeight) > rect.Height())
  239. wndsnapinDesc.ShowScrollBar(SB_VERT, TRUE);
  240. dc.SelectFont(hOldFont);
  241. wndsnapinDesc.SetSel(0, 0);
  242. return sc;
  243. }