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.

448 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: attr.cpp
  7. //
  8. // Contents: implementation of CAttribute
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "Attr.h"
  14. #include "snapmgr.h"
  15. #include "util.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CAttribute dialog
  23. void TrimNumber(CString &str)
  24. {
  25. int i = str.Find( L' ' );
  26. if( i > 0 ){
  27. str = str.Left(i);
  28. }
  29. }
  30. DWORD CAttribute::m_nDialogs = 0;
  31. CAttribute::CAttribute(UINT nTemplateID)
  32. : CSelfDeletingPropertyPage(nTemplateID ? nTemplateID : IDD),
  33. m_pSnapin(NULL),
  34. m_pData(NULL),
  35. m_bConfigure(TRUE),
  36. m_uTemplateResID(nTemplateID ? nTemplateID : IDD)
  37. {
  38. //{{AFX_DATA_INIT(CAttribute)
  39. // NOTE: the ClassWizard will add member initialization here
  40. //}}AFX_DATA_INIT
  41. m_nDialogs++;
  42. m_pHelpIDs = (DWORD_PTR)a173HelpIDs;
  43. }
  44. CAttribute::~CAttribute()
  45. {
  46. if (m_pData)
  47. {
  48. if( m_pSnapin )
  49. {
  50. m_pSnapin->ReleasePropertyPage(m_pData);
  51. }
  52. m_pData->Release();
  53. }
  54. m_nDialogs--;
  55. if (m_pSnapin) //Raid #464871, Yanggao, 10/09/2001
  56. {
  57. m_pSnapin->Release();
  58. }
  59. }
  60. void CAttribute::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CSelfDeletingPropertyPage::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CAttribute)
  64. // NOTE: the ClassWizard will add DDX and DDV calls here
  65. DDX_Check(pDX,IDC_CONFIGURE,m_bConfigure);
  66. DDX_Text(pDX,IDC_TITLE,m_strTitle);
  67. //}}AFX_DATA_MAP
  68. }
  69. BEGIN_MESSAGE_MAP(CAttribute, CSelfDeletingPropertyPage)
  70. //{{AFX_MSG_MAP(CAttribute)
  71. ON_WM_LBUTTONDBLCLK()
  72. ON_BN_CLICKED(IDC_CONFIGURE, OnConfigure)
  73. //}}AFX_MSG_MAP
  74. ON_MESSAGE(WM_HELP, OnHelp)
  75. ON_MESSAGE(WM_CONTEXTMENU, OnContextHelp) //Bug 139470, Yanggao
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CAttribute message handlers
  79. BOOL CAttribute::OnInitDialog ()
  80. {
  81. if( m_pData && m_pSnapin) //Raid #482059, Yanggao, 10/16/2001
  82. {
  83. m_pSnapin->AddPropertyPageRef(m_pData);
  84. }
  85. CSelfDeletingPropertyPage::OnInitDialog ();
  86. return TRUE;
  87. }
  88. void CAttribute::Initialize(CResult * pResult)
  89. {
  90. m_pData = pResult;
  91. if (m_pData) {
  92. m_pData->AddRef();
  93. }
  94. }
  95. void CAttribute::SetSnapin(CSnapin * pSnapin)
  96. {
  97. ASSERT(m_pSnapin==NULL);
  98. if ( !m_pSnapin )
  99. {
  100. m_pSnapin = pSnapin;
  101. if (m_pSnapin)
  102. {
  103. m_hwndParent = pSnapin->GetParentWindow();
  104. m_pSnapin->AddRef(); //Raid #464871, Yanggao, 10/09/2001
  105. }
  106. }
  107. }
  108. void CAttribute::OnCancel()
  109. {
  110. }
  111. BOOL CAttribute::OnApply()
  112. {
  113. if ( !m_bReadOnly )
  114. {
  115. UpdateData();
  116. //
  117. // If we get here we've applied our modifications for this page
  118. // Since it's possible that we got here via Apply we want to be
  119. // able to reapply if any further changes are made
  120. //
  121. SetModified(FALSE);
  122. CancelToClose();
  123. }
  124. return TRUE;
  125. }
  126. /*----------------------------------------------------------------------------
  127. Method: CAttribute::EnableUserControls
  128. Synopsis: Enables or disables this control user control array.
  129. Arugments: [bEnable] - If TRUE then enable the controls otherwise, disable
  130. them.
  131. ----------------------------------------------------------------------------*/
  132. void CAttribute::EnableUserControls (BOOL bEnable)
  133. {
  134. HWND hwnd = 0;
  135. if (QueryReadOnly())
  136. {
  137. bEnable = FALSE;
  138. hwnd = ::GetDlgItem( this->m_hWnd, IDOK );
  139. if (hwnd)
  140. {
  141. ::EnableWindow(hwnd, FALSE);
  142. }
  143. hwnd = ::GetDlgItem( this->m_hWnd, IDC_CONFIGURE );
  144. if (hwnd)
  145. {
  146. ::EnableWindow(hwnd, FALSE);
  147. }
  148. }
  149. for( int i = 0; i < m_aUserCtrlIDs.GetSize(); i++)
  150. {
  151. hwnd = ::GetDlgItem( this->m_hWnd, m_aUserCtrlIDs[i] );
  152. if(hwnd)
  153. {
  154. //
  155. // The reason that there are two calls below that apparently
  156. // do the same thing is that all of the controls in our dialogs
  157. // respond to the ::EnableWindow() call except the CheckList
  158. // control, which will respond to the ::SendMessage(WM_ENABLE).
  159. // And conversley, all the other controls will not respond to
  160. // the ::SendMessage(WM_ENABLE). It shouldn't be a problem
  161. // to make both calls but it is definitely something to watch.
  162. //
  163. // The reason the CheckList control has a problem is that when
  164. // it is told to disable itself, it disables all of its child windows
  165. // (check boxes) but re-enables its main window within the WM_ENABLE
  166. // handling so that it can scroll in the disabled state. Then when we
  167. // try to call ::EnableWindow on it, Windows or MFC thinks the
  168. // window is already enabled so it doesn't send it a WM_ENABLE
  169. // message. So if we send the WM_ENABLE message directly it
  170. // circumvents the other processing in ::EnableWindow that results
  171. // in the WM_ENABLE message not being sent.
  172. //
  173. ::SendMessage(hwnd, WM_ENABLE, (WPARAM) bEnable, (LPARAM) 0);
  174. ::EnableWindow(hwnd, bEnable);
  175. }
  176. }
  177. }
  178. /*----------------------------------------------------------------------------
  179. Method: CAttribute::OnConfigure
  180. Synopsis: Enable/Disable controls based on new state of the
  181. "Define this attribute...." checkbox
  182. ----------------------------------------------------------------------------*/
  183. void CAttribute::OnConfigure()
  184. {
  185. UpdateData(TRUE);
  186. // If the configure check box isn't visible then don't do anything.
  187. // Raid #603833, yanggao, 4/17/2002.
  188. CWnd *pConfigure = GetDlgItem(IDC_CONFIGURE);
  189. if (!pConfigure || (!pConfigure->IsWindowVisible() && this->IsWindowVisible()))
  190. {
  191. return;
  192. }
  193. SetModified(TRUE);
  194. EnableUserControls(m_bConfigure);
  195. if (m_bConfigure && m_pData)
  196. {
  197. switch(m_pData->GetType())
  198. {
  199. case ITEM_PROF_REGVALUE:
  200. case ITEM_REGVALUE:
  201. case ITEM_LOCALPOL_REGVALUE:
  202. SetInitialValue(m_pData->GetRegDefault());
  203. break;
  204. default:
  205. SetInitialValue(m_pData->GetProfileDefault());
  206. break;
  207. }
  208. UpdateData(FALSE);
  209. }
  210. }
  211. /*----------------------------------------------------------------------------
  212. Method: CAttribute::SetConfigure
  213. Synopsis: Set the configure state and
  214. Arugments: [bConfigure] - Configure is TRUE or FALSE.
  215. ----------------------------------------------------------------------------*/
  216. void CAttribute::SetConfigure( BOOL bConfigure )
  217. {
  218. m_bConfigure = bConfigure;
  219. UpdateData(FALSE);
  220. OnConfigure();
  221. }
  222. void CAttribute::OnLButtonDblClk(UINT nFlags, CPoint point)
  223. {
  224. CSelfDeletingPropertyPage::OnLButtonDblClk(nFlags, point);
  225. //
  226. // If the configure check box isn't visible then don't do anything
  227. // This dialog can't be configured
  228. //
  229. CWnd *pConfigure = GetDlgItem(IDC_CONFIGURE);
  230. if (!pConfigure || !pConfigure->IsWindowVisible()
  231. || !pConfigure->IsWindowEnabled() ) //Raid #461948, Yang Gao, 8/27/2001
  232. {
  233. return;
  234. }
  235. for( int i = 0; i < m_aUserCtrlIDs.GetSize(); i++ )
  236. {
  237. CWnd *pWnd = GetDlgItem( m_aUserCtrlIDs[i] );
  238. if(pWnd && pWnd == pConfigure) //Raid #529238, #580052, yanggao
  239. {
  240. CRect rect;
  241. pWnd->GetWindowRect(&rect);
  242. ScreenToClient(&rect);
  243. if(rect.PtInRect( point ) && !pWnd->IsWindowEnabled() )
  244. {
  245. SetConfigure( TRUE );
  246. break;
  247. }
  248. break;
  249. }
  250. }
  251. }
  252. BOOL CAttribute::OnHelp(WPARAM wParam, LPARAM lParam)
  253. {
  254. const LPHELPINFO pHelpInfo = (LPHELPINFO)lParam;
  255. if (pHelpInfo && pHelpInfo->iContextType == HELPINFO_WINDOW)
  256. {
  257. //Raid #499556, 12/12/2001, yanggao, turn off help for title.
  258. if( -1 != pHelpInfo->iCtrlId && IDC_TITLE != pHelpInfo->iCtrlId //Bug 311884, Yanggao
  259. && IDC_WARNING != pHelpInfo->iCtrlId && IDC_STATIC_DESCRIPTION !=pHelpInfo->iCtrlId //Raid #525153,526450,526422,526477, 2/27/2002, yanggao
  260. && IDC_NO_MEMBERS != pHelpInfo->iCtrlId && IDC_NO_MEMBER_OF != pHelpInfo->iCtrlId
  261. && IDC_NAME != pHelpInfo->iCtrlId && IDC_SETTING != pHelpInfo->iCtrlId
  262. && IDC_LI_TITLE != pHelpInfo->iCtrlId )
  263. this->DoContextHelp ((HWND) pHelpInfo->hItemHandle);
  264. }
  265. return TRUE;
  266. }
  267. void CAttribute::DoContextHelp (HWND hWndControl)
  268. {
  269. // Display context help for a control
  270. if ( !::WinHelp (
  271. hWndControl,
  272. GetSeceditHelpFilename(),
  273. HELP_WM_HELP,
  274. m_pHelpIDs))
  275. {
  276. }
  277. }
  278. BOOL CAttribute::OnContextHelp(WPARAM wParam, LPARAM lParam) //Bug 139470, Yanggao
  279. {
  280. HMENU hMenu = CreatePopupMenu();
  281. if( hMenu )
  282. {
  283. CString str;
  284. str.LoadString(IDS_WHAT_ISTHIS);
  285. if( AppendMenu(hMenu, MF_STRING, IDM_WHAT_ISTHIS, str) )
  286. {
  287. int itemID = TrackPopupMenu(hMenu,
  288. TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RETURNCMD|
  289. TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
  290. LOWORD(lParam), HIWORD(lParam), 0, (HWND)wParam, NULL);
  291. if( IDM_WHAT_ISTHIS == itemID ) //Raid #139470, 4/11/2001
  292. {
  293. itemID = 0;
  294. if( ((HWND)wParam) != this->m_hWnd )
  295. {
  296. //Raid #499556, 12/12/2001, yanggao, turn off help for title.
  297. itemID = ::GetDlgCtrlID((HWND)wParam);
  298. if( itemID != 0 && -1 != itemID && IDC_TITLE != itemID )
  299. {
  300. ::WinHelp((HWND)wParam,
  301. GetSeceditHelpFilename(),
  302. HELP_WM_HELP,
  303. m_pHelpIDs);
  304. }
  305. }
  306. else
  307. {
  308. POINT pos;
  309. pos.x = LOWORD(lParam);
  310. pos.y = HIWORD(lParam);
  311. ScreenToClient( &pos );
  312. CWnd* pWnd = ChildWindowFromPoint(pos, CWP_SKIPINVISIBLE);
  313. if( pWnd )
  314. {
  315. //Raid #499556, 12/12/2001, yanggao, turn off help for title.
  316. itemID = ::GetDlgCtrlID((HWND)wParam);
  317. if( itemID != 0 && -1 != itemID && IDC_TITLE != itemID )
  318. {
  319. ::WinHelp(pWnd->m_hWnd,
  320. GetSeceditHelpFilename(),
  321. HELP_WM_HELP,
  322. m_pHelpIDs);
  323. }
  324. }
  325. }
  326. }
  327. }
  328. }
  329. return TRUE;
  330. }
  331. //------------------------------------------------------------
  332. // implementation for CModelessSceEditor
  333. //------------------------------------------------------------
  334. //------------------------------------------------------------
  335. CModelessSceEditor::CModelessSceEditor (bool bIsContainer,
  336. DWORD flag,
  337. HWND hParent,
  338. SE_OBJECT_TYPE seType,
  339. LPCWSTR lpszObjName)
  340. : m_pThread(NULL)
  341. {
  342. m_MLShtData.bIsContainer = bIsContainer;
  343. m_MLShtData.flag = flag;
  344. m_MLShtData.hwndParent = hParent;
  345. m_MLShtData.SeType = seType,
  346. m_MLShtData.strObjectName = lpszObjName;
  347. }
  348. //------------------------------------------------------------
  349. //------------------------------------------------------------
  350. CModelessSceEditor::~CModelessSceEditor()
  351. {
  352. m_pThread->PostThreadMessage(WM_QUIT,0,0); //Raid #619921, yanggao, 5/14/2002
  353. }
  354. //------------------------------------------------------------
  355. // will create a modeless sce editor inside its own thread m_pThread
  356. //------------------------------------------------------------
  357. void CModelessSceEditor::Create (PSECURITY_DESCRIPTOR* ppSeDescriptor,
  358. SECURITY_INFORMATION* pSeInfo,
  359. HWND* phwndSheet)
  360. {
  361. *phwndSheet = NULL; // prepare to fail
  362. if (NULL == m_pThread)
  363. {
  364. m_pThread = (CModelessDlgUIThread*)AfxBeginThread(RUNTIME_CLASS(CModelessDlgUIThread));
  365. if (NULL == m_pThread)
  366. {
  367. CString strMsg;
  368. strMsg.LoadString(IDS_FAIL_CREATE_UITHREAD);
  369. AfxMessageBox(strMsg);
  370. return;
  371. }
  372. m_pThread->WaitTillRun(); // will suspend this thread till the m_pThread start running
  373. }
  374. m_MLShtData.ppSeDescriptor = ppSeDescriptor;
  375. m_MLShtData.pSeInfo = pSeInfo;
  376. m_MLShtData.phwndSheet = phwndSheet;
  377. m_pThread->PostThreadMessage(SCEM_CREATE_MODELESS_SHEET, (WPARAM)(&m_MLShtData), 0);
  378. }
  379. //------------------------------------------------------------
  380. //------------------------------------------------------------
  381. void CModelessSceEditor::Destroy(HWND hwndSheet)
  382. {
  383. if (::IsWindow(hwndSheet))
  384. {
  385. m_pThread->PostThreadMessage(SCEM_DESTROY_WINDOW, (WPARAM)hwndSheet, 0);
  386. }
  387. }