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.

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