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.

439 lines
12 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1993 **
  4. //*********************************************************************
  5. #include "admincfg.h"
  6. #include "grouppri.h"
  7. VIEWINFO ViewInfo;
  8. HWND hwndToolbar;
  9. HWND hwndStatusBar;
  10. extern UINT nFileShortcutItems;
  11. #ifdef INCL_GROUP_SUPPORT
  12. extern GROUPPRIENTRY * pGroupPriEntryFirst;
  13. #endif
  14. VOID EnableMenuItems(HWND hwndApp,DWORD dwState)
  15. {
  16. HMENU hMenu = GetMenu(hwndApp);
  17. BOOL fEnable;
  18. UINT nIndex;
  19. // enable "New" and "Open" if we can have a document (i.e. a template
  20. // is loaded)
  21. fEnable = dwState & AS_CANHAVEDOCUMENT;
  22. EnableMenuItem(hMenu,IDM_NEW,(fEnable ? MF_ENABLED : MF_GRAYED));
  23. SendMessage(hwndToolbar,TB_ENABLEBUTTON,IDM_NEW,MAKELONG(fEnable,0));
  24. EnableMenuItem(hMenu,IDM_OPEN,(fEnable ? MF_ENABLED : MF_GRAYED));
  25. SendMessage(hwndToolbar,TB_ENABLEBUTTON,IDM_OPEN,MAKELONG(fEnable,0));
  26. for (nIndex=0;nIndex < nFileShortcutItems; nIndex++)
  27. EnableMenuItem(hMenu,IDM_FILEHISTORY+nIndex,
  28. (fEnable ? MF_ENABLED : MF_GRAYED));
  29. // enable "Open Registry" if we can have a document, and if it's not already
  30. // open
  31. fEnable = ((dwState & AS_CANHAVEDOCUMENT) && !(dwState & AS_LOCALREGISTRY));
  32. EnableMenuItem(hMenu,IDM_OPENREGISTRY,(fEnable ? MF_ENABLED : MF_GRAYED));
  33. // enable "Save" and "Close" if we have a policy file or registry open
  34. fEnable = dwState & AS_FILELOADED;
  35. EnableMenuItem(hMenu,IDM_SAVE,( fEnable ? MF_ENABLED : MF_GRAYED));
  36. SendMessage(hwndToolbar,TB_ENABLEBUTTON,IDM_SAVE,MAKELONG(fEnable,0));
  37. EnableMenuItem(hMenu,IDM_CLOSE,(fEnable ? MF_ENABLED : MF_GRAYED));
  38. // enable "Save As", "Add User", "Add Workstation", if we have a policy file
  39. // but not if we're directly editing a registry
  40. fEnable = ((dwState & AS_FILELOADED) && (dwState & AS_POLICYFILE));
  41. EnableMenuItem(hMenu,IDM_SAVEAS,(fEnable ? MF_ENABLED : MF_GRAYED));
  42. EnableMenuItem(hMenu,IDM_ADDUSER,(fEnable ? MF_ENABLED : MF_GRAYED));
  43. SendMessage(hwndToolbar,TB_ENABLEBUTTON,IDM_ADDUSER,MAKELONG(fEnable,0));
  44. EnableMenuItem(hMenu,IDM_ADDWORKSTATION,(fEnable ? MF_ENABLED : MF_GRAYED));
  45. SendMessage(hwndToolbar,TB_ENABLEBUTTON,IDM_ADDWORKSTATION,MAKELONG(fEnable,0));
  46. #ifdef INCL_GROUP_SUPPORT
  47. EnableMenuItem(hMenu,IDM_ADDGROUP,(fEnable ? MF_ENABLED : MF_GRAYED));
  48. SendMessage(hwndToolbar,TB_ENABLEBUTTON,IDM_ADDGROUP,MAKELONG(fEnable,0));
  49. #endif
  50. // enable "Remove" if we're editing policy file and the "OK to remove" flag
  51. // is set (item is selected in list control)
  52. fEnable = ((dwState & AS_CANREMOVE) && (dwState & AS_POLICYFILE));
  53. EnableMenuItem(hMenu,IDM_REMOVE, (fEnable ? MF_ENABLED : MF_GRAYED));
  54. SendMessage(hwndToolbar,TB_ENABLEBUTTON,IDM_REMOVE,MAKELONG(fEnable,0));
  55. // enable "Copy" and "Paste" appropriately
  56. fEnable = CanCopy(hwndUser);
  57. EnableMenuItem(hMenu,IDM_COPY, (fEnable ? MF_ENABLED : MF_GRAYED));
  58. fEnable = CanPaste(hwndUser);
  59. EnableMenuItem(hMenu,IDM_PASTE, (fEnable ? MF_ENABLED : MF_GRAYED));
  60. // enable "Properties" the "OK to remove" flag
  61. // is set (item is selected in list control)
  62. fEnable = (dwState & AS_CANREMOVE);
  63. EnableMenuItem(hMenu,IDM_PROPERTIES, (fEnable ? MF_ENABLED : MF_GRAYED));
  64. #ifdef INCL_GROUP_SUPPORT
  65. // enable "Group priority..." if any group priority items in list
  66. EnableMenuItem(hMenu,IDM_GROUPPRIORITY, (pGroupPriEntryFirst ?
  67. MF_ENABLED : MF_GRAYED));
  68. #endif
  69. }
  70. VOID CheckMenuItems(HWND hwndApp)
  71. {
  72. HMENU hMenu = GetMenu(hwndApp);
  73. if (hMenu)
  74. {
  75. // update the menu item checkmarks
  76. CheckMenuItem(hMenu,IDM_TOOLBAR,MF_BYCOMMAND | (ViewInfo.fToolbar ?
  77. MF_CHECKED : MF_UNCHECKED));
  78. CheckMenuItem(hMenu,IDM_STATUSBAR,MF_BYCOMMAND | (ViewInfo.fStatusBar ?
  79. MF_CHECKED : MF_UNCHECKED));
  80. }
  81. }
  82. VOID CheckViewItem(HWND hwndApp,DWORD dwView)
  83. {
  84. HMENU hMenu = GetMenu(hwndApp);
  85. UINT uCmd;
  86. switch (dwView) {
  87. case VT_LARGEICONS:
  88. uCmd = IDM_LARGEICONS;
  89. break;
  90. case VT_SMALLICONS:
  91. uCmd = IDM_SMALLICONS;
  92. break;
  93. case VT_LIST:
  94. uCmd = IDM_LIST;
  95. break;
  96. case VT_REPORT:
  97. uCmd = IDM_DETAILS;
  98. break;
  99. default:
  100. return;
  101. }
  102. CheckMenuRadioItem(hMenu, IDM_LARGEICONS, IDM_DETAILS,
  103. uCmd, MF_BYCOMMAND);
  104. }
  105. VOID SetNewView(HWND hwndApp,HWND hwndList,DWORD dwNewView)
  106. {
  107. ViewInfo.dwView = dwNewView;
  108. SetViewType(hwndList,ViewInfo.dwView);
  109. CheckViewItem(hwndApp,ViewInfo.dwView);
  110. }
  111. VOID SetTitleBar(HWND hwndApp,CHAR * szFilename)
  112. {
  113. CHAR szTitle[255+SMALLBUF];
  114. CHAR szAppName[SMALLBUF];
  115. CHAR szUntitled[SMALLBUF];
  116. CHAR szFormat[SMALLBUF];
  117. LoadSz(IDS_APPNAME,szAppName,sizeof(szAppName));
  118. LoadSz(IDS_TITLEFORMAT,szFormat,sizeof(szFormat));
  119. if (dwAppState & AS_LOCALREGISTRY) {
  120. wsprintf(szTitle,szFormat,szAppName,LoadSz(IDS_LOCALREGISTRY,szSmallBuf,
  121. sizeof(szSmallBuf)));
  122. } else if (dwAppState & AS_REMOTEREGISTRY) {
  123. if (szFilename) {
  124. CHAR szMsg[SMALLBUF+COMPUTERNAMELEN+1];
  125. wsprintf(szMsg,LoadSz(IDS_REGISTRYON,szSmallBuf,sizeof(szSmallBuf)),
  126. szFilename);
  127. wsprintf(szTitle,szFormat,szAppName,szMsg);
  128. } else {
  129. lstrcpy(szTitle,szAppName);
  130. }
  131. } else if (szFilename) {
  132. // make a title a la "AdminConfig - <filename>". If no filename yet,
  133. // use "(untitled)".
  134. wsprintf(szTitle,szFormat,szAppName,(lstrlen(szFilename) ? szFilename :
  135. LoadSz(IDS_UNTITLED,szUntitled,sizeof(szUntitled))));
  136. } else {
  137. lstrcpy(szTitle,szAppName);
  138. }
  139. // Set the window text
  140. SetWindowText(hwndApp,szTitle);
  141. }
  142. /*******************************************************************
  143. NAME: InitToolbar
  144. SYNOPSIS: Creates and initializes toolbar and status bar
  145. ENTRY: HWND of main window
  146. ********************************************************************/
  147. BOOL InitToolbar(HWND hWnd)
  148. {
  149. int border[3];
  150. TBBUTTON tbButtons[] = {
  151. { 6, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  152. { 7, IDM_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0},
  153. { 8, IDM_SAVE, 0, TBSTYLE_BUTTON, 0},
  154. { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0},
  155. { 0, IDM_ADDUSER, 0, TBSTYLE_BUTTON,0},
  156. #ifdef INCL_GROUP_SUPPORT
  157. { 2, IDM_ADDGROUP, 0, TBSTYLE_BUTTON,0},
  158. #endif
  159. { 1, IDM_ADDWORKSTATION,0, TBSTYLE_BUTTON,0},
  160. { 5, IDM_REMOVE, 0, TBSTYLE_BUTTON,0} };
  161. RECT rc;
  162. TBADDBITMAP ab;
  163. int nStdBtnOffset;
  164. /* create Tool Bar */
  165. hwndToolbar = CreateWindowEx (WS_EX_TOOLWINDOW,szToolbarClass,szNull,
  166. (ViewInfo.fToolbar ? WS_VISIBLE : 0) | WS_CHILD | TBSTYLE_TOOLTIPS | WS_CLIPSIBLINGS,
  167. 0,0,100,30,hWnd,0,ghInst,NULL);
  168. if (!hwndToolbar) {
  169. MsgBox(hWnd,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  170. return FALSE;
  171. }
  172. // this tells the toolbar what version we are
  173. SendMessage(hwndToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
  174. ab.hInst = HINST_COMMCTRL; // take them from commctrl
  175. ab.nID = IDB_STD_SMALL_COLOR; // standard toolbar images
  176. SendMessage(hwndToolbar, TB_ADDBITMAP, 0, (LPARAM)&ab);
  177. ab.hInst = ghInst; // take them from our instance
  178. ab.nID = IDB_TOOLBAR;
  179. nStdBtnOffset = (int) SendMessage(hwndToolbar, TB_ADDBITMAP, 3, (LPARAM)&ab);
  180. tbButtons[4].iBitmap = nStdBtnOffset + 0;
  181. #ifdef INCL_GROUP_SUPPORT
  182. tbButtons[5].iBitmap = nStdBtnOffset + 2;
  183. tbButtons[6].iBitmap = nStdBtnOffset + 1;
  184. #else
  185. tbButtons[5].iBitmap = nStdBtnOffset + 1;
  186. #endif
  187. // add buttons
  188. SendMessage(hwndToolbar,TB_ADDBUTTONS,sizeof(tbButtons)/sizeof(TBBUTTON),
  189. (LPARAM) tbButtons);
  190. GetClientRect( hwndToolbar, &rc );
  191. ViewInfo.dyToolbar = rc.bottom+1;
  192. /* create Status Bar */
  193. hwndStatusBar = CreateStatusWindow( WS_CHILD | CCS_NOHILITE |
  194. SBARS_SIZEGRIP | (ViewInfo.fStatusBar ? WS_VISIBLE : 0),
  195. szNull, hWnd, IDC_STATUSBAR );
  196. if (!hwndStatusBar) {
  197. MsgBox(hWnd,IDS_ErrOUTOFMEMORY,MB_ICONEXCLAMATION,MB_OK);
  198. return FALSE;
  199. }
  200. // set the border spacing
  201. border[0] = 0;
  202. border[1] = -1;
  203. border[2] = 2;
  204. SendMessage(hwndStatusBar, SB_SETBORDERS, 0, (LPARAM)(LPINT)border);
  205. GetClientRect( hwndStatusBar, &rc );
  206. ViewInfo.dyStatusBar = rc.bottom;
  207. return TRUE;
  208. }
  209. /*******************************************************************
  210. NAME: DeInitToolbar
  211. SYNOPSIS: Destroys toolbar and status bar
  212. ********************************************************************/
  213. VOID DeInitToolbar(VOID)
  214. {
  215. if (hwndToolbar) DestroyWindow(hwndToolbar);
  216. if (hwndStatusBar) DestroyWindow(hwndStatusBar);
  217. }
  218. /*******************************************************************
  219. NAME: ProcessTooltips
  220. SYNOPSIS: Loads appropriate tip resource string and copies it into
  221. buffer.
  222. ********************************************************************/
  223. BOOL ProcessTooltips(TOOLTIPTEXT * pttt)
  224. {
  225. if (!pttt->hdr.idFrom) {
  226. lstrcpy(pttt->szText,szNull);
  227. return FALSE;
  228. }
  229. lstrcpy(pttt->szText,LoadSz(IDS_TIPS + (UINT)pttt->hdr.idFrom,szSmallBuf,
  230. sizeof(szSmallBuf)));
  231. return TRUE;
  232. }
  233. BOOL ReplaceMenuItem(HWND hWnd,UINT idOld,UINT idNew,UINT idResourceTxt)
  234. {
  235. MENUITEMINFO mii;
  236. HMENU hMenu = GetMenu(hWnd);
  237. if (!hMenu) return FALSE;
  238. memset(&mii,0,sizeof(mii));
  239. mii.cbSize = sizeof(mii);
  240. mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_DATA;
  241. mii.fType = MFT_STRING;
  242. mii.wID = idNew;
  243. mii.dwTypeData = (LPSTR) LoadSz(idResourceTxt,szSmallBuf,sizeof(szSmallBuf));
  244. mii.cch = lstrlen(mii.dwTypeData);
  245. if (InsertMenuItem(hMenu,idOld,FALSE,&mii)) {
  246. RemoveMenu(hMenu,idOld,MF_BYCOMMAND);
  247. }
  248. DrawMenuBar(hWnd);
  249. return TRUE;
  250. }
  251. VOID SetStatusText(CHAR * pszText)
  252. {
  253. // if NULL pointer, set to null string ("")
  254. if (!pszText)
  255. pszText = (CHAR *) szNull;
  256. if (hwndStatusBar) {
  257. SendMessage(hwndStatusBar,WM_SETTEXT,0,(LPARAM) pszText);
  258. UpdateWindow(hwndStatusBar);
  259. }
  260. }
  261. VOID GetStatusText(CHAR * pszText,UINT cbText)
  262. {
  263. if (!pszText)
  264. return;
  265. if (hwndStatusBar)
  266. SendMessage(hwndStatusBar,WM_GETTEXT,cbText,(LPARAM) pszText);
  267. }
  268. VOID SetStatusItemCount(HWND hwndList)
  269. {
  270. UINT nCount = ListView_GetItemCount(hwndList);
  271. if (nCount > 1) {
  272. CHAR szStatusText[SMALLBUF];
  273. wsprintf(szStatusText,LoadSz(IDS_ENTRIES,szSmallBuf,sizeof(szSmallBuf))
  274. ,nCount);
  275. SetStatusText(szStatusText);
  276. } else {
  277. SetStatusText(LoadSz( (nCount == 0 ? IDS_NOENTRIES : IDS_ONEENTRY),
  278. szSmallBuf,sizeof(szSmallBuf)));
  279. }
  280. }
  281. VOID AddFileShortcut(HMENU hMenu,CHAR * pszNewFilename)
  282. {
  283. MENUITEMINFO mii;
  284. CHAR szFilename[MAX_PATH+1];
  285. UINT nIndex;
  286. memset(&mii,0,sizeof(mii));
  287. mii.cbSize = sizeof(mii);
  288. mii.fMask = MIIM_TYPE;
  289. mii.fType = MFT_STRING;
  290. mii.dwTypeData = szFilename;
  291. mii.cch = sizeof(szFilename);
  292. // see if there is an existing shortcut with this name
  293. for (nIndex = 0;nIndex<nFileShortcutItems;nIndex++) {
  294. mii.cch = sizeof(szFilename);
  295. if (GetMenuItemInfo(hMenu,IDM_FILEHISTORY+nIndex,
  296. FALSE,&mii) && !lstrcmpi(szFilename,pszNewFilename))
  297. return; // already has a shortcut menu item, nothing to do
  298. }
  299. // add another menu item if we have less than max shorcuts
  300. if (nFileShortcutItems < FILEHISTORY_COUNT) {
  301. MENUITEMINFO miiTmp;
  302. memset(&miiTmp,0,sizeof(miiTmp));
  303. miiTmp.cbSize = sizeof(miiTmp);
  304. // add a separator if this is first shortcut item
  305. if (!nFileShortcutItems) {
  306. miiTmp.fMask = MIIM_TYPE;
  307. miiTmp.fType = MFT_SEPARATOR;
  308. InsertMenuItem(hMenu,GetMenuItemCount(hMenu),TRUE,&miiTmp);
  309. }
  310. // add a menu item with empty string, string will get set below
  311. miiTmp.fType = MFT_STRING;
  312. miiTmp.wID = IDM_FILEHISTORY + nFileShortcutItems;
  313. miiTmp.fMask = MIIM_TYPE | MIIM_ID;
  314. miiTmp.dwTypeData = (LPSTR) szNull;
  315. mii.cch = 1;
  316. InsertMenuItem(hMenu,GetMenuItemCount(hMenu),TRUE,&miiTmp);
  317. nFileShortcutItems ++;
  318. }
  319. // move existing items down one slot to make new one most recent
  320. if (nFileShortcutItems) {
  321. for (nIndex=nFileShortcutItems-1;nIndex > 0;nIndex --) {
  322. mii.cch = sizeof(szFilename);
  323. if (GetMenuItemInfo(hMenu,IDM_FILEHISTORY+nIndex-1,
  324. FALSE,&mii))
  325. SetMenuItemInfo(hMenu,IDM_FILEHISTORY+nIndex,
  326. FALSE,&mii);
  327. }
  328. }
  329. lstrcpy(szFilename,pszNewFilename);
  330. mii.cch = lstrlen(szFilename);
  331. SetMenuItemInfo(hMenu,IDM_FILEHISTORY,
  332. FALSE,&mii);
  333. }
  334. VOID SetViewType(HWND hwndList,DWORD dwView)
  335. {
  336. DWORD dwStyle;
  337. switch (dwView) {
  338. case VT_LARGEICONS:
  339. dwStyle = LVS_ICON;
  340. break;
  341. case VT_SMALLICONS:
  342. dwStyle = LVS_SMALLICON;
  343. break;
  344. case VT_LIST:
  345. dwStyle = LVS_LIST;
  346. break;
  347. case VT_REPORT:
  348. dwStyle = LVS_REPORT;
  349. break;
  350. default:
  351. return; // invalid dwView constant
  352. }
  353. // set the window style to change the view type
  354. SetWindowLong(hwndList,GWL_STYLE,
  355. (GetWindowLong(hwndList,GWL_STYLE) & ~LVS_TYPEMASK) | dwStyle);
  356. ListView_Arrange(hwndList,LVA_SORTASCENDING);
  357. }