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.

429 lines
12 KiB

  1. /*======================================================================================//
  2. | Process Control //
  3. | //
  4. |Copyright (c) 1998 Sequent Computer Systems, Incorporated. All rights reserved. //
  5. | //
  6. |File Name: NameRulePages.cpp //
  7. | //
  8. |Description: Implementation of name rule property pages //
  9. | //
  10. |Created: Paul Skoglund 07-1998 //
  11. | //
  12. |Rev History: //
  13. | //
  14. |=======================================================================================*/
  15. #include "stdafx.h"
  16. #include "NameRulePages.h"
  17. #include "globals.h"
  18. #include "HelpTopics.h"
  19. #include "ManagementPages.h"
  20. #include "ManagementRuleWizards.h"
  21. BOOL NameRuleDlg(PCNameRule &out, PCNameRule *In /* = NULL */, BOOL bReadOnly /* = FALSE */ )
  22. {
  23. PROPSHEETHEADER sheet;
  24. memset(&sheet, 0, sizeof(PROPSHEETHEADER));
  25. sheet.dwSize = sizeof(PROPSHEETHEADER);
  26. sheet.dwFlags = PSH_NOAPPLYNOW | PSH_USEICONID;
  27. sheet.hwndParent = ::GetActiveWindow();
  28. sheet.hInstance = _Module.GetResourceInstance();
  29. sheet.pszIcon = MAKEINTRESOURCE(IDI_ALIASRULES);
  30. if (In)
  31. sheet.pszCaption = MAKEINTRESOURCE(IDS_NRULE_EDIT_PROPERTIES);
  32. else
  33. sheet.pszCaption = MAKEINTRESOURCE(IDS_NRULE_DEFINE_PROPERTIES);
  34. sheet.nPages = 1;
  35. sheet.nStartPage = 0;
  36. CNRulePage *pPage = new CNRulePage(NULL, &out, In); //the "title" becomes the tab header not the window title...
  37. if (!pPage)
  38. return -1;
  39. if (bReadOnly)
  40. pPage->SetReadOnly();
  41. HPROPSHEETPAGE hPages[1];
  42. hPages[0] = pPage->Create();
  43. sheet.phpage = &hPages[0];
  44. sheet.pfnCallback = NULL;
  45. INT_PTR id = PropertySheet(&sheet);
  46. // CNRulePage pointer pPage does not need to be freed, it has "autodelete", see the templated class it is devired from...
  47. if (id > 0)
  48. return TRUE;
  49. return FALSE;
  50. }
  51. CNRulePage::CNRulePage(int nTitle, PCNameRule *OutBuffer, PCNameRule *InData)
  52. : CMySnapInPropertyPageImpl<CNRulePage>(nTitle), m_bName(_T("")), m_bMask(_T("")), m_bComment(_T("")), m_Type(MATCH_PGM)
  53. {
  54. ASSERT(sizeof(PageFields.on) == sizeof(PageFields));
  55. PageFields.on = 0;
  56. m_bReadOnly = FALSE;
  57. m_OutBuffer = OutBuffer;
  58. if (m_OutBuffer)
  59. memset(m_OutBuffer, 0, sizeof(*m_OutBuffer));
  60. if (InData)
  61. {
  62. m_bName = InData->procName;
  63. m_bMask = InData->matchString;
  64. m_bComment = InData->description;
  65. m_Type = InData->matchType;
  66. }
  67. m_hBtnImage = NULL;
  68. m_psp.dwFlags |= PSP_HASHELP;
  69. }
  70. CNRulePage::~CNRulePage()
  71. {
  72. if (m_hBtnImage)
  73. VERIFY(::DestroyIcon( (HICON) m_hBtnImage));
  74. if (m_hMenu)
  75. VERIFY( ::DestroyMenu(m_hMenu) );
  76. }
  77. LRESULT CNRulePage::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  78. {
  79. m_hBtnImage = ::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_RARROW), IMAGE_ICON, 6, 7, LR_DEFAULTCOLOR );
  80. ASSERT(m_hBtnImage);
  81. if (m_hBtnImage)
  82. SendDlgItemMessage(IDC_BTN_ALIAS, BM_SETIMAGE, IMAGE_ICON, (LPARAM) m_hBtnImage);
  83. m_hMenu = ::LoadMenu( _Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_ALIAS_MACRO) );
  84. ASSERT(m_hMenu);
  85. SendDlgItemMessage( IDC_NAME, EM_SETLIMITTEXT, PROC_NAME_LEN, 0);
  86. SendDlgItemMessage( IDC_MATCHMASK, EM_SETLIMITTEXT, MATCH_STRING_LEN, 0);
  87. SendDlgItemMessage( IDC_COMMENT, EM_SETLIMITTEXT, NAME_DESCRIPTION_LEN, 0);
  88. if (m_bReadOnly)
  89. {
  90. UINT ids[] = { IDC_DIR, IDC_IMAGE, IDC_STRING, IDC_NAME, IDC_MATCHMASK, IDC_COMMENT, IDC_BTN_ALIAS, 0 };
  91. for (int i = 0; ids[i]; i++)
  92. DisableControl(ids[i]);
  93. }
  94. UpdateData(FALSE);
  95. return TRUE; // Let the system set the focus
  96. }
  97. LRESULT CNRulePage::OnWMHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  98. {
  99. HELPINFO *phi = (HELPINFO*) lParam;
  100. if (phi && phi->iContextType == HELPINFO_WINDOW)
  101. {
  102. IDCsToIDHs HelpMap[] = {{IDC_MATCHTYPE_FRAME, HELP_NRULE_MATCHTYPE_FRAME},
  103. {IDC_DIR, HELP_NRULE_DIR},
  104. {IDC_IMAGE, HELP_NRULE_IMAGE},
  105. {IDC_STRING, HELP_NRULE_STRING},
  106. {IDC_MATCHMASK, HELP_NRULE_MATCHMASK},
  107. {IDC_COMMENT, HELP_NRULE_COMMENT},
  108. {IDC_NAME, HELP_NRULE_NAME},
  109. {IDC_BTN_ALIAS, HELP_NRULE_BTN_ALIAS},
  110. {0,0} };
  111. ::WinHelp((HWND) phi->hItemHandle, ContextHelpFile, HELP_WM_HELP, (DWORD_PTR) &HelpMap);
  112. //ATLTRACE(_T("Call to WinHelp(hwnd=0x%lX) failed %lu"), phi->hItemHandle, GetLastError() );
  113. return TRUE;
  114. }
  115. bHandled = FALSE;
  116. return FALSE;
  117. }
  118. BOOL CNRulePage::OnHelp()
  119. {
  120. MMCPropertyHelp(const_cast<TCHAR*>(HELP_ru_alias));
  121. return TRUE;
  122. }
  123. BOOL CNRulePage::Validate(BOOL bSave)
  124. {
  125. CComBSTR bNameStr;
  126. CComBSTR bMaskStr;
  127. CComBSTR bCommentStr;
  128. MATCH_TYPE TempType;
  129. if (!GetDlgItemText( IDC_MATCHMASK, bMaskStr.m_str ) || !bMaskStr.Length() || bMaskStr.Length() > MATCH_STRING_LEN)
  130. {
  131. HWND hWndCtl = GetDlgItem(IDC_MATCHMASK);
  132. if(hWndCtl)
  133. ::SetFocus(hWndCtl);
  134. MessageBeep(MB_ICONASTERISK);
  135. return FALSE;
  136. }
  137. if (!GetDlgItemText( IDC_NAME, bNameStr.m_str ) ||
  138. !IsValidName(bNameStr, FALSE) )
  139. {
  140. HWND hWndCtl = GetDlgItem(IDC_NAME);
  141. if(hWndCtl)
  142. ::SetFocus(hWndCtl);
  143. ITEM_STR strOut;
  144. LoadStringHelper(strOut, IDS_JOBNAME_WARNING);
  145. MessageBox(strOut, NULL, MB_OK | MB_ICONWARNING);
  146. return FALSE;
  147. }
  148. // comment/description field can be left blank...
  149. if ( !GetDlgItemText(IDC_COMMENT, bCommentStr.m_str))
  150. bCommentStr = _T("");
  151. if (bCommentStr.Length() > NAME_DESCRIPTION_LEN)
  152. {
  153. HWND hWndCtl = GetDlgItem(IDC_COMMENT);
  154. if(hWndCtl)
  155. ::SetFocus(hWndCtl);
  156. MessageBeep(MB_ICONASTERISK);
  157. return FALSE;
  158. }
  159. if ( IsDlgButtonChecked(IDC_IMAGE) )
  160. TempType = MATCH_PGM;
  161. else if ( IsDlgButtonChecked(IDC_DIR) )
  162. TempType = MATCH_DIR;
  163. else if ( IsDlgButtonChecked(IDC_STRING) )
  164. TempType = MATCH_ANY;
  165. else
  166. {
  167. MessageBeep(MB_ICONASTERISK);
  168. return FALSE;
  169. }
  170. if (bSave)
  171. {
  172. if (m_OutBuffer)
  173. {
  174. _tcscpy(m_OutBuffer->procName, bNameStr);
  175. _tcscpy(m_OutBuffer->matchString, bMaskStr);
  176. _tcscpy(m_OutBuffer->description, bCommentStr);
  177. m_OutBuffer->matchType = TempType;
  178. }
  179. }
  180. return TRUE;
  181. }
  182. BOOL CNRulePage::UpdateData(BOOL bSaveAndValidate)
  183. {
  184. if (bSaveAndValidate)
  185. {
  186. return Validate(TRUE);
  187. }
  188. else
  189. {
  190. ASSERT(IDC_DIR + 1 == IDC_IMAGE && IDC_IMAGE + 1 == IDC_STRING);
  191. VERIFY(SetDlgItemText( IDC_NAME, m_bName.m_str ));
  192. VERIFY(SetDlgItemText( IDC_MATCHMASK, m_bMask.m_str ));
  193. VERIFY(SetDlgItemText( IDC_COMMENT, m_bComment.m_str ));
  194. CheckRadioButton(IDC_DIR, IDC_STRING, MatchTypeToID(m_Type) );
  195. // save a copy to output buffer, if the page is readonly the output
  196. // will be the same as the initialzed values
  197. if (m_OutBuffer)
  198. {
  199. _tcscpy(m_OutBuffer->procName, m_bName);
  200. _tcscpy(m_OutBuffer->matchString, m_bMask);
  201. _tcscpy(m_OutBuffer->description, m_bComment);
  202. m_OutBuffer->matchType = m_Type;
  203. }
  204. return TRUE;
  205. }
  206. }
  207. LRESULT CNRulePage::OnEditChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  208. {
  209. CComBSTR bStr; // GetDlgItemText returns FALSE, and doesn't create an empty
  210. switch (wID) {
  211. case IDC_NAME:
  212. if (! GetDlgItemText(wID, bStr.m_str) )
  213. bStr = _T("");
  214. PageFields.Fields.matchname = (0 != _tcscmp(bStr, m_bName));
  215. break;
  216. case IDC_MATCHMASK:
  217. if (! GetDlgItemText(wID, bStr.m_str) )
  218. bStr = _T("");
  219. PageFields.Fields.matchmask = (0 != _tcscmp(bStr, m_bMask));
  220. break;
  221. case IDC_COMMENT:
  222. if (! GetDlgItemText(wID, bStr.m_str) )
  223. bStr = _T("");
  224. PageFields.Fields.comment = (0 != _tcscmp(bStr, m_bComment));
  225. break;
  226. default:
  227. ASSERT(FALSE); //
  228. break;
  229. }
  230. SetModified(PageFields.on);
  231. bHandled = FALSE;
  232. return 0;
  233. }
  234. LRESULT CNRulePage::OnAliasMacro(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  235. {
  236. if (wNotifyCode == BN_CLICKED && wID == IDC_BTN_ALIAS)
  237. {
  238. HMENU hSubMenu;
  239. if (m_hMenu && (hSubMenu = GetSubMenu(m_hMenu, 0)) )
  240. {
  241. CComBSTR bStrName;
  242. if (!GetDlgItemText( IDC_NAME, bStrName.m_str ) )
  243. bStrName = _T("");
  244. MENUITEMINFO info = { 0 };
  245. info.cbSize = sizeof(info);
  246. info.fMask = MIIM_STATE;
  247. info.fState = MFS_ENABLED;
  248. UINT nItems[] = {IDM_DIR, IDM_IMAGE, IDM_HIDE };
  249. // enable all items
  250. for (int i = 0; i < ARRAY_SIZE(nItems); i++)
  251. {
  252. VERIFY( SetMenuItemInfo(hSubMenu, nItems[i], FALSE, &info) );
  253. }
  254. // now disable selective options if not allowed...
  255. // if not a sub-dir match disable <d> macro...
  256. if ( !IsDlgButtonChecked(IDC_DIR) )
  257. {
  258. info.fState = MFS_GRAYED;
  259. VERIFY( SetMenuItemInfo(hSubMenu, IDM_DIR, FALSE, &info) );
  260. }
  261. if ( _tcsstr(bStrName, COPY_PGM_NAME) )
  262. {
  263. info.fState = MFS_GRAYED;
  264. VERIFY( SetMenuItemInfo(hSubMenu, IDM_IMAGE, FALSE, &info) );
  265. }
  266. if ( _tcsstr(bStrName, HIDE_THIS_PROC) )
  267. {
  268. info.fState = MFS_GRAYED;
  269. VERIFY( SetMenuItemInfo(hSubMenu, IDM_HIDE, FALSE, &info) );
  270. }
  271. if ( _tcsstr(bStrName, COPY_DIR_NAME) )
  272. {
  273. info.fState = MFS_GRAYED;
  274. VERIFY( SetMenuItemInfo(hSubMenu, IDM_DIR, FALSE, &info) );
  275. }
  276. HWND hwndp = ::GetParent(m_hWnd); // the property page is still a child window, so get it's parent...the sheet
  277. RECT rect = { 0 }; // button's rect
  278. TPMPARAMS tpmparams = { 0 }; // use rect of assigned name edit control window
  279. tpmparams.cbSize = sizeof(tpmparams);
  280. VERIFY( ::GetWindowRect(GetDlgItem(IDC_BTN_ALIAS), &rect ) );
  281. VERIFY( ::GetWindowRect(GetDlgItem(IDC_NAME), &tpmparams.rcExclude) );
  282. TCHAR *txt = NULL;
  283. int mID = TrackPopupMenuEx(hSubMenu,
  284. TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD | TPM_VERTICAL,
  285. rect.right, rect.top, hwndp, &tpmparams);
  286. if (mID == IDM_IMAGE)
  287. txt = COPY_PGM_NAME;
  288. else if (mID == IDM_HIDE)
  289. txt = HIDE_THIS_PROC;
  290. else if (mID == IDM_DIR)
  291. txt = COPY_DIR_NAME;
  292. if (txt)
  293. SendDlgItemMessage(IDC_NAME, EM_REPLACESEL, TRUE, (LPARAM) txt);
  294. }
  295. }
  296. bHandled = FALSE;
  297. return 0;
  298. }
  299. LRESULT CNRulePage::OnMaskTypeEdit(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  300. {
  301. if (wNotifyCode == BN_CLICKED)
  302. {
  303. switch (wID) {
  304. case IDC_IMAGE:
  305. PageFields.Fields.matchtype = (m_Type != MATCH_PGM);
  306. break;
  307. case IDC_DIR:
  308. PageFields.Fields.matchtype = (m_Type != MATCH_DIR);
  309. break;
  310. case IDC_STRING:
  311. PageFields.Fields.matchtype = (m_Type != MATCH_ANY);
  312. break;
  313. default:
  314. PageFields.Fields.matchtype = 0;
  315. ASSERT(FALSE); //
  316. break;
  317. }
  318. SetModified(PageFields.on);
  319. }
  320. if ( !IsDlgButtonChecked(IDC_DIR) )
  321. {
  322. CComBSTR bStr;
  323. if ( GetDlgItemText(IDC_NAME, bStr.m_str) )
  324. {
  325. tstring tname(bStr.m_str);
  326. tstring::size_type sub = tname.find(COPY_DIR_NAME);
  327. if (sub != tstring::npos)
  328. {
  329. tname.erase(sub, _tcslen(COPY_DIR_NAME));
  330. SetDlgItemText(IDC_NAME, tname.c_str());
  331. }
  332. }
  333. }
  334. bHandled = FALSE;
  335. return 0;
  336. }
  337. BOOL CNRulePage::OnApply()
  338. {
  339. if (m_bReadOnly || !PageFields.on)
  340. return TRUE;
  341. if (m_OutBuffer)
  342. {
  343. m_bName = m_OutBuffer->procName;
  344. m_bMask = m_OutBuffer->matchString;
  345. m_bComment = m_OutBuffer->description;
  346. m_Type = m_OutBuffer->matchType;
  347. PageFields.on = 0;
  348. }
  349. return TRUE;
  350. }