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.

357 lines
9.6 KiB

  1. #include "stdafx.h"
  2. #include "certmap.h"
  3. #include "AuthCtl.h"
  4. #include "AuthPpg.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. IMPLEMENT_DYNCREATE(CCertAuthCtrl, COleControl)
  11. /////////////////////////////////////////////////////////////////////////////
  12. // Message map
  13. BEGIN_MESSAGE_MAP(CCertAuthCtrl, COleControl)
  14. //{{AFX_MSG_MAP(CCertAuthCtrl)
  15. // NOTE - ClassWizard will add and remove message map entries
  16. // DO NOT EDIT what you see in these blocks of generated code !
  17. //}}AFX_MSG_MAP
  18. ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  19. END_MESSAGE_MAP()
  20. /////////////////////////////////////////////////////////////////////////////
  21. // Dispatch map
  22. BEGIN_DISPATCH_MAP(CCertAuthCtrl, COleControl)
  23. //{{AFX_DISPATCH_MAP(CCertAuthCtrl)
  24. DISP_FUNCTION(CCertAuthCtrl, "SetMachineName", SetMachineName, VT_EMPTY, VTS_BSTR)
  25. DISP_FUNCTION(CCertAuthCtrl, "SetServerInstance", SetServerInstance, VT_EMPTY, VTS_BSTR)
  26. DISP_STOCKPROP_FONT()
  27. DISP_STOCKPROP_BORDERSTYLE()
  28. DISP_STOCKPROP_ENABLED()
  29. DISP_STOCKPROP_CAPTION()
  30. DISP_FUNCTION_ID(CCertAuthCtrl, "DoClick", DISPID_DOCLICK, DoClick, VT_EMPTY, VTS_I4)
  31. //}}AFX_DISPATCH_MAP
  32. DISP_FUNCTION_ID(CCertAuthCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
  33. END_DISPATCH_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Event map
  36. BEGIN_EVENT_MAP(CCertAuthCtrl, COleControl)
  37. //{{AFX_EVENT_MAP(CCertAuthCtrl)
  38. EVENT_STOCK_CLICK()
  39. //}}AFX_EVENT_MAP
  40. END_EVENT_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // Property pages
  43. // TODO: Add more property pages as needed. Remember to increase the count!
  44. BEGIN_PROPPAGEIDS(CCertAuthCtrl, 2)
  45. PROPPAGEID(CCertAuthPropPage::guid)
  46. PROPPAGEID(CLSID_CFontPropPage)
  47. END_PROPPAGEIDS(CCertAuthCtrl)
  48. /////////////////////////////////////////////////////////////////////////////
  49. // Initialize class factory and guid
  50. IMPLEMENT_OLECREATE_EX(CCertAuthCtrl, "CERTMAP.CertmapCtrl.2",
  51. 0x996ff6f, 0xb6a1, 0x11d0, 0x92, 0x92, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b)
  52. /////////////////////////////////////////////////////////////////////////////
  53. // Type library ID and version
  54. IMPLEMENT_OLETYPELIB(CCertAuthCtrl, _tlid, _wVerMajor, _wVerMinor)
  55. /////////////////////////////////////////////////////////////////////////////
  56. // Interface IDs
  57. const IID BASED_CODE IID_DCertAuth =
  58. { 0x996ff6d, 0xb6a1, 0x11d0, { 0x92, 0x92, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b } };
  59. const IID BASED_CODE IID_DCertAuthEvents =
  60. { 0x996ff6e, 0xb6a1, 0x11d0, { 0x92, 0x92, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b } };
  61. /////////////////////////////////////////////////////////////////////////////
  62. // Control type information
  63. static const DWORD BASED_CODE _dwCertAuthOleMisc =
  64. OLEMISC_ACTIVATEWHENVISIBLE |
  65. OLEMISC_SETCLIENTSITEFIRST |
  66. OLEMISC_INSIDEOUT |
  67. OLEMISC_CANTLINKINSIDE |
  68. OLEMISC_RECOMPOSEONRESIZE;
  69. IMPLEMENT_OLECTLTYPE(CCertAuthCtrl, IDS_CERTAUTH, _dwCertAuthOleMisc)
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CCertAuthCtrl::CCertAuthCtrlFactory::UpdateRegistry -
  72. // Adds or removes system registry entries for CCertAuthCtrl
  73. BOOL CCertAuthCtrl::CCertAuthCtrlFactory::UpdateRegistry(BOOL bRegister)
  74. {
  75. if (bRegister)
  76. return AfxOleRegisterControlClass(
  77. AfxGetInstanceHandle(),
  78. m_clsid,
  79. m_lpszProgID,
  80. IDS_CERTAUTH,
  81. IDB_CERTAUTH,
  82. afxRegApartmentThreading,
  83. _dwCertAuthOleMisc,
  84. _tlid,
  85. _wVerMajor,
  86. _wVerMinor);
  87. else
  88. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  89. }
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CCertAuthCtrl::CCertAuthCtrl - Constructor
  92. CCertAuthCtrl::CCertAuthCtrl():
  93. m_fUpdateFont( FALSE ),
  94. m_hAccel( NULL ),
  95. m_cAccel( 0 )
  96. {
  97. InitializeIIDs(&IID_DCertAuth, &IID_DCertAuthEvents);
  98. }
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CCertAuthCtrl::~CCertAuthCtrl - Destructor
  101. CCertAuthCtrl::~CCertAuthCtrl()
  102. {
  103. if ( m_hAccel )
  104. DestroyAcceleratorTable( m_hAccel );
  105. m_hAccel = NULL;
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CCertAuthCtrl::OnDraw - Drawing function
  109. void CCertAuthCtrl::OnDraw(
  110. CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  111. {
  112. CFont* pOldFont;
  113. pOldFont = SelectStockFont( pdc );
  114. DoSuperclassPaint(pdc, rcBounds);
  115. pOldFont = pdc->SelectObject(pOldFont);
  116. if ( m_fUpdateFont )
  117. {
  118. m_fUpdateFont = FALSE;
  119. CWnd::SetFont( pOldFont );
  120. }
  121. }
  122. /////////////////////////////////////////////////////////////////////////////
  123. // CCertAuthCtrl::DoPropExchange - Persistence support
  124. void CCertAuthCtrl::DoPropExchange(CPropExchange* pPX)
  125. {
  126. ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  127. COleControl::DoPropExchange(pPX);
  128. }
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CCertAuthCtrl::OnResetState - Reset control to default state
  131. void CCertAuthCtrl::OnResetState()
  132. {
  133. COleControl::OnResetState(); // Resets defaults found in DoPropExchange
  134. }
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CCertAuthCtrl::AboutBox - Display an "About" box to the user
  137. void CCertAuthCtrl::AboutBox()
  138. {
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CCertAuthCtrl message handlers
  142. //---------------------------------------------------------------------------
  143. BOOL CCertAuthCtrl::PreCreateWindow(CREATESTRUCT& cs)
  144. {
  145. if ( cs.style & WS_CLIPSIBLINGS )
  146. cs.style ^= WS_CLIPSIBLINGS;
  147. cs.lpszClass = _T("BUTTON");
  148. return COleControl::PreCreateWindow(cs);
  149. }
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CAppsCtrl::IsSubclassedControl - This is a subclassed control
  152. BOOL CCertAuthCtrl::IsSubclassedControl()
  153. {
  154. return TRUE;
  155. }
  156. /////////////////////////////////////////////////////////////////////////////
  157. // OnOcmCommand - Handle command messages
  158. LRESULT CCertAuthCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
  159. {
  160. #ifdef _WIN32
  161. WORD wNotifyCode = HIWORD(wParam);
  162. #else
  163. WORD wNotifyCode = HIWORD(lParam);
  164. #endif
  165. return 0;
  166. }
  167. extern void test__non2Rons_WizClasses();
  168. void CCertAuthCtrl::OnClick(USHORT iButton)
  169. {
  170. COleControl::OnClick(iButton);
  171. }
  172. //---------------------------------------------------------------------------
  173. void CCertAuthCtrl::SetServerInstance(LPCTSTR szServerInstance)
  174. {
  175. m_szServerInstance = szServerInstance;
  176. }
  177. //---------------------------------------------------------------------------
  178. void CCertAuthCtrl::SetMachineName(LPCTSTR szMachine)
  179. {
  180. m_szMachineName = szMachine;
  181. }
  182. //---------------------------------------------------------------------------
  183. void CCertAuthCtrl::OnFontChanged()
  184. {
  185. m_fUpdateFont = TRUE;
  186. COleControl::OnFontChanged();
  187. }
  188. //---------------------------------------------------------------------------
  189. void CCertAuthCtrl::OnAmbientPropertyChange(DISPID dispid)
  190. {
  191. BOOL flag;
  192. UINT style;
  193. switch ( dispid )
  194. {
  195. case DISPID_AMBIENT_DISPLAYASDEFAULT:
  196. if ( GetAmbientProperty( DISPID_AMBIENT_DISPLAYASDEFAULT, VT_BOOL, &flag ) )
  197. {
  198. style = GetWindowLong(
  199. GetSafeHwnd(), // handle of window
  200. GWL_STYLE // offset of value to retrieve
  201. );
  202. if ( flag )
  203. style |= BS_DEFPUSHBUTTON;
  204. else
  205. style ^= BS_DEFPUSHBUTTON;
  206. SetWindowLong(
  207. GetSafeHwnd(), // handle of window
  208. GWL_STYLE, // offset of value to retrieve
  209. style
  210. );
  211. Invalidate(TRUE);
  212. }
  213. break;
  214. };
  215. COleControl::OnAmbientPropertyChange(dispid);
  216. }
  217. void CCertAuthCtrl::OnGetControlInfo(LPCONTROLINFO pControlInfo)
  218. {
  219. if ( !pControlInfo || pControlInfo->cb < sizeof(CONTROLINFO) )
  220. return;
  221. pControlInfo->hAccel = m_hAccel;
  222. pControlInfo->cAccel = m_cAccel;
  223. pControlInfo->dwFlags = CTRLINFO_EATS_RETURN;
  224. }
  225. void CCertAuthCtrl::OnKeyUpEvent(USHORT nChar, USHORT nShiftState)
  226. {
  227. if ( nChar == _T(' ') )
  228. {
  229. OnClick((USHORT)GetDlgCtrlID());
  230. }
  231. COleControl::OnKeyUpEvent(nChar, nShiftState);
  232. }
  233. //---------------------------------------------------------------------------
  234. void CCertAuthCtrl::OnMnemonic(LPMSG pMsg)
  235. {
  236. OnClick((USHORT)GetDlgCtrlID());
  237. COleControl::OnMnemonic(pMsg);
  238. }
  239. //---------------------------------------------------------------------------
  240. void CCertAuthCtrl::OnTextChanged()
  241. {
  242. DWORD i;
  243. ACCEL accel;
  244. BOOL f;
  245. BOOL flag;
  246. int iAccel;
  247. // get the new text
  248. CString sz = InternalGetText();
  249. sz.MakeLower();
  250. if ( m_hAccel )
  251. {
  252. DestroyAcceleratorTable( m_hAccel );
  253. m_hAccel = NULL;
  254. m_cAccel = 0;
  255. }
  256. iAccel = sz.Find(_T('&'));
  257. if ( iAccel >= 0 )
  258. {
  259. accel.fVirt = FALT;
  260. accel.key = sz.GetAt(iAccel + 1);
  261. accel.cmd = (WORD)GetDlgCtrlID();
  262. m_hAccel = CreateAcceleratorTable( &accel, 1 );
  263. if ( m_hAccel )
  264. m_cAccel = 1;
  265. }
  266. COleControl::OnTextChanged();
  267. }
  268. void CCertAuthCtrl::DoClick(IN long dwButtonNumber)
  269. {
  270. OnClick( (short) dwButtonNumber );
  271. }