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.

408 lines
11 KiB

  1. // RatCtl.cpp : Implementation of the CRatCtrl OLE control class.
  2. #include "stdafx.h"
  3. #include "cnfgprts.h"
  4. #include "RatCtl.h"
  5. #include "RatPpg.h"
  6. #include "parserat.h"
  7. #include "RatData.h"
  8. #include "RatGenPg.h"
  9. #include "RatSrvPg.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. IMPLEMENT_DYNCREATE(CRatCtrl, COleControl)
  16. /////////////////////////////////////////////////////////////////////////////
  17. // Message map
  18. BEGIN_MESSAGE_MAP(CRatCtrl, COleControl)
  19. //{{AFX_MSG_MAP(CRatCtrl)
  20. //}}AFX_MSG_MAP
  21. ON_MESSAGE(OCM_COMMAND, OnOcmCommand)
  22. ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  23. END_MESSAGE_MAP()
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Dispatch map
  26. BEGIN_DISPATCH_MAP(CRatCtrl, COleControl)
  27. //{{AFX_DISPATCH_MAP(CRatCtrl)
  28. DISP_FUNCTION(CRatCtrl, "SetAdminTarget", SetAdminTarget, VT_EMPTY, VTS_BSTR VTS_BSTR)
  29. DISP_FUNCTION(CRatCtrl, "SetUserData", SetUserData, VT_EMPTY, VTS_BSTR VTS_BSTR)
  30. DISP_FUNCTION(CRatCtrl, "SetUrl", SetUrl, VT_EMPTY, VTS_BSTR)
  31. DISP_STOCKFUNC_DOCLICK()
  32. DISP_STOCKPROP_BORDERSTYLE()
  33. DISP_STOCKPROP_ENABLED()
  34. DISP_STOCKPROP_FONT()
  35. DISP_STOCKPROP_CAPTION()
  36. //}}AFX_DISPATCH_MAP
  37. END_DISPATCH_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // Event map
  40. BEGIN_EVENT_MAP(CRatCtrl, COleControl)
  41. //{{AFX_EVENT_MAP(CRatCtrl)
  42. EVENT_STOCK_CLICK()
  43. EVENT_STOCK_KEYUP()
  44. //}}AFX_EVENT_MAP
  45. END_EVENT_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // Property pages
  48. BEGIN_PROPPAGEIDS(CRatCtrl, 2)
  49. PROPPAGEID(CRatPropPage::guid)
  50. PROPPAGEID(CLSID_CFontPropPage)
  51. END_PROPPAGEIDS(CRatCtrl)
  52. /////////////////////////////////////////////////////////////////////////////
  53. // Initialize class factory and guid
  54. IMPLEMENT_OLECREATE_EX(CRatCtrl, "CNFGPRTS.RatCtrl.1",
  55. 0xba634607, 0xb771, 0x11d0, 0x92, 0x96, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b)
  56. /////////////////////////////////////////////////////////////////////////////
  57. // Type library ID and version
  58. IMPLEMENT_OLETYPELIB(CRatCtrl, _tlid, _wVerMajor, _wVerMinor)
  59. /////////////////////////////////////////////////////////////////////////////
  60. // Interface IDs
  61. const IID BASED_CODE IID_DRat =
  62. { 0xba634605, 0xb771, 0x11d0, { 0x92, 0x96, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b } };
  63. //const IID BASED_CODE IID_DRat2 =
  64. // { 0x9352B26C, 0x7907, 0x4c8e, { 0xa1, 0x64, 0x14, 0xe3, 0x42, 0x53, 0x2f, 0x8b } };
  65. const IID BASED_CODE IID_DRatEvents =
  66. { 0xba634606, 0xb771, 0x11d0, { 0x92, 0x96, 0, 0xc0, 0x4f, 0xb6, 0x67, 0x8b } };
  67. /////////////////////////////////////////////////////////////////////////////
  68. // Control type information
  69. static const DWORD BASED_CODE _dwRatOleMisc =
  70. OLEMISC_ACTIVATEWHENVISIBLE |
  71. OLEMISC_SETCLIENTSITEFIRST |
  72. OLEMISC_INSIDEOUT |
  73. OLEMISC_CANTLINKINSIDE |
  74. OLEMISC_ACTSLIKEBUTTON |
  75. OLEMISC_RECOMPOSEONRESIZE;
  76. IMPLEMENT_OLECTLTYPE(CRatCtrl, IDS_RAT, _dwRatOleMisc)
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CRatCtrl::CRatCtrlFactory::UpdateRegistry -
  79. // Adds or removes system registry entries for CRatCtrl
  80. BOOL CRatCtrl::CRatCtrlFactory::UpdateRegistry(BOOL bRegister)
  81. {
  82. // TODO: Verify that your control follows apartment-model threading rules.
  83. // Refer to MFC TechNote 64 for more information.
  84. // If your control does not conform to the apartment-model rules, then
  85. // you must modify the code below, changing the 6th parameter from
  86. // afxRegApartmentThreading to 0.
  87. if (bRegister)
  88. return AfxOleRegisterControlClass(
  89. AfxGetInstanceHandle(),
  90. m_clsid,
  91. m_lpszProgID,
  92. IDS_RAT,
  93. IDB_RAT,
  94. afxRegApartmentThreading,
  95. _dwRatOleMisc,
  96. _tlid,
  97. _wVerMajor,
  98. _wVerMinor);
  99. else
  100. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  101. }
  102. /////////////////////////////////////////////////////////////////////////////
  103. // CRatCtrl::CRatCtrl - Constructor
  104. CRatCtrl::CRatCtrl():
  105. m_fUpdateFont( FALSE ),
  106. m_hAccel( NULL ),
  107. m_cAccel( 0 )
  108. {
  109. InitializeIIDs(&IID_DRat, &IID_DRatEvents);
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CRatCtrl::~CRatCtrl - Destructor
  113. CRatCtrl::~CRatCtrl()
  114. {
  115. if ( m_hAccel )
  116. DestroyAcceleratorTable( m_hAccel );
  117. m_hAccel = NULL;
  118. }
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CRatCtrl::OnDraw - Drawing function
  121. void CRatCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  122. {
  123. DoSuperclassPaint(pdc, rcBounds);
  124. }
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CRatCtrl::DoPropExchange - Persistence support
  127. void CRatCtrl::DoPropExchange(CPropExchange* pPX)
  128. {
  129. ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  130. COleControl::DoPropExchange(pPX);
  131. }
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CRatCtrl::OnResetState - Reset control to default state
  134. void CRatCtrl::OnResetState()
  135. {
  136. COleControl::OnResetState(); // Resets defaults found in DoPropExchange
  137. }
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CRatCtrl::PreCreateWindow - Modify parameters for CreateWindowEx
  140. BOOL CRatCtrl::PreCreateWindow(CREATESTRUCT& cs)
  141. {
  142. if ( cs.style & WS_CLIPSIBLINGS )
  143. cs.style ^= WS_CLIPSIBLINGS;
  144. cs.lpszClass = _T("BUTTON");
  145. return COleControl::PreCreateWindow(cs);
  146. }
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CRatCtrl::IsSubclassedControl - This is a subclassed control
  149. BOOL CRatCtrl::IsSubclassedControl()
  150. {
  151. return TRUE;
  152. }
  153. /////////////////////////////////////////////////////////////////////////////
  154. // CRatCtrl::OnOcmCommand - Handle command messages
  155. LRESULT CRatCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
  156. {
  157. #ifdef _WIN32
  158. WORD wNotifyCode = HIWORD(wParam);
  159. #else
  160. WORD wNotifyCode = HIWORD(lParam);
  161. #endif
  162. return 0;
  163. }
  164. /////////////////////////////////////////////////////////////////////////////
  165. // CRatCtrl message handlers
  166. //---------------------------------------------------------------------------
  167. void CRatCtrl::OnClick(USHORT iButton)
  168. {
  169. CString sz;
  170. sz.LoadString( IDS_RAT_ERR_TITLE );
  171. AfxGetApp()->m_pszAppName = _tcsdup(sz);
  172. CWaitCursor wait;
  173. // if there is no set metabase path - give it a test path
  174. if ( m_szMetaObject.IsEmpty() )
  175. m_szMetaObject = _T("/lm/w3svc/1/Root");
  176. // we have to be able to initialize the ratings data object
  177. CRatingsData dataRatings;
  178. dataRatings.SetServer(m_szMachine, m_szMetaObject);
  179. CString csTempPassword;
  180. m_szUserPassword.CopyTo(csTempPassword);
  181. dataRatings.SetUser(m_szUserName, csTempPassword);
  182. dataRatings.SetURL(m_szURL);
  183. if (!dataRatings.Init())
  184. {
  185. AfxMessageBox( IDS_RAT_READFILE_ERROR );
  186. return;
  187. }
  188. CRatServicePage pageService;
  189. CRatGenPage pageSetRatings;
  190. CPropertySheet propsheet( IDS_RAT_SHEETTITLE );
  191. pageService.m_pRatData = &dataRatings;
  192. pageSetRatings.m_pRatData = &dataRatings;
  193. // BUG:684590
  194. //propsheet.AddPage( &pageService );
  195. propsheet.AddPage( &pageSetRatings );
  196. propsheet.m_psh.dwFlags |= PSH_HASHELP;
  197. pageService.m_psp.dwFlags |= PSP_HASHELP;
  198. pageSetRatings.m_psp.dwFlags |= PSP_HASHELP;
  199. try
  200. {
  201. PreModalDialog();
  202. if ( propsheet.DoModal() == IDOK )
  203. {
  204. dataRatings.SaveTheLabel();
  205. }
  206. // let the host container know we are done with the modality
  207. PostModalDialog();
  208. }
  209. catch ( CException* pException )
  210. {
  211. pException->Delete();
  212. }
  213. COleControl::OnClick(iButton);
  214. }
  215. //---------------------------------------------------------------------------
  216. void CRatCtrl::OnFontChanged()
  217. {
  218. m_fUpdateFont = TRUE;
  219. COleControl::OnFontChanged();
  220. }
  221. //---------------------------------------------------------------------------
  222. void CRatCtrl::SetAdminTarget(LPCTSTR szMachineName, LPCTSTR szMetaTarget)
  223. {
  224. m_szMachine = szMachineName;
  225. m_szMetaObject = szMetaTarget;
  226. }
  227. void CRatCtrl::SetUserData(LPCTSTR szUserName, LPCTSTR szUserPassword)
  228. {
  229. m_szUserName = szUserName;
  230. m_szUserPassword = szUserPassword;
  231. }
  232. void CRatCtrl::SetUrl(LPCTSTR szURL)
  233. {
  234. m_szURL = szURL;
  235. }
  236. //---------------------------------------------------------------------------
  237. // an important method where we tell the container how to deal with us.
  238. // pControlInfo is passed in by the container, although we are responsible
  239. // for maintining the hAccel structure
  240. void CRatCtrl::OnGetControlInfo(LPCONTROLINFO pControlInfo)
  241. {
  242. // do a rudimentary check to see if we understand pControlInfo
  243. if ( !pControlInfo || pControlInfo->cb < sizeof(CONTROLINFO) )
  244. return;
  245. // set the accelerator handle into place
  246. pControlInfo->hAccel = m_hAccel;
  247. pControlInfo->cAccel = m_cAccel;
  248. // when we have focus, we do want the enter key
  249. pControlInfo->dwFlags = CTRLINFO_EATS_RETURN;
  250. }
  251. //---------------------------------------------------------------------------
  252. // when the caption text has changed, we need to rebuild the accelerator handle
  253. void CRatCtrl::OnTextChanged()
  254. {
  255. ACCEL accel;
  256. int iAccel;
  257. // get the new text
  258. CString sz = InternalGetText();
  259. sz.MakeLower();
  260. // if the handle has already been allocated, free it
  261. if ( m_hAccel )
  262. {
  263. DestroyAcceleratorTable( m_hAccel );
  264. m_hAccel = NULL;
  265. m_cAccel = 0;
  266. }
  267. // if there is a & character, then declare the accelerator
  268. iAccel = sz.Find(_T('&'));
  269. if ( iAccel >= 0 )
  270. {
  271. // fill in the accererator record
  272. accel.fVirt = FALT;
  273. accel.key = sz.GetAt(iAccel + 1);
  274. accel.cmd = (USHORT)GetDlgCtrlID();
  275. m_hAccel = CreateAcceleratorTable( &accel, 1 );
  276. if ( m_hAccel )
  277. m_cAccel = 1;
  278. // make sure the new accelerator table gets loaded
  279. ControlInfoChanged();
  280. }
  281. // finish with the default handling.
  282. COleControl::OnTextChanged();
  283. }
  284. //---------------------------------------------------------------------------
  285. void CRatCtrl::OnMnemonic(LPMSG pMsg)
  286. {
  287. OnClick((USHORT)GetDlgCtrlID());
  288. COleControl::OnMnemonic(pMsg);
  289. }
  290. //---------------------------------------------------------------------------
  291. void CRatCtrl::OnAmbientPropertyChange(DISPID dispid)
  292. {
  293. BOOL flag;
  294. UINT style;
  295. // do the right thing depending on the dispid
  296. switch ( dispid )
  297. {
  298. case DISPID_AMBIENT_DISPLAYASDEFAULT:
  299. if ( GetAmbientProperty( DISPID_AMBIENT_DISPLAYASDEFAULT, VT_BOOL, &flag ) )
  300. {
  301. style = GetWindowLong(GetSafeHwnd(), GWL_STYLE);
  302. if ( flag )
  303. style |= BS_DEFPUSHBUTTON;
  304. else
  305. style ^= BS_DEFPUSHBUTTON;
  306. SetWindowLong(GetSafeHwnd(), GWL_STYLE, style);
  307. Invalidate(TRUE);
  308. }
  309. break;
  310. };
  311. COleControl::OnAmbientPropertyChange(dispid);
  312. }
  313. //---------------------------------------------------------------------------
  314. // the ole control container object specifically filters out the space
  315. // key so we do not get it as a OnMnemonic call. Thus we need to look
  316. // for it ourselves
  317. void CRatCtrl::OnKeyUpEvent(USHORT nChar, USHORT nShiftState)
  318. {
  319. if ( nChar == _T(' ') )
  320. {
  321. OnClick((USHORT)GetDlgCtrlID());
  322. }
  323. COleControl::OnKeyUpEvent(nChar, nShiftState);
  324. }