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.

309 lines
7.8 KiB

  1. /*****************************************************************************
  2. I N I T M E N U
  3. Name: initmenu.c
  4. Date: 21-Jan-1994
  5. Creator: Unknown
  6. Description:
  7. This file contains the function to initialize the menus.
  8. History:
  9. 21-Jan-1994 John Fu, reformat and cleanup.
  10. 13-Mar-1995 John Fu, add Paste to Page
  11. *****************************************************************************/
  12. #define WIN31
  13. #define STRICT
  14. #include <windows.h>
  15. #include <windowsx.h>
  16. #include <assert.h>
  17. #include <memory.h>
  18. #include "common.h"
  19. #include "clipbook.h"
  20. #include "clipbrd.h"
  21. #include "clipdsp.h"
  22. #include "commctrl.h"
  23. #include "cvinit.h"
  24. #include "cvutil.h"
  25. #include "initmenu.h"
  26. /*
  27. * InitializeMenu
  28. *
  29. * this function controls the enabled/grayed state of
  30. * the menu items and the state of the toolbar buttons.
  31. * It is called when the selection within a listbox changes,
  32. * or the focus changes from one MDI child window to another.
  33. */
  34. VOID PASCAL InitializeMenu (
  35. HANDLE hmenu)
  36. {
  37. LPLISTENTRY lpLE = NULL;
  38. int index;
  39. int fMenu;
  40. int fButton;
  41. DWORD flags;
  42. assert(NULL != pActiveMDI);
  43. hmenu = GetMenu(hwndApp);
  44. flags = pActiveMDI->flags;
  45. if (flags & F_CLPBRD)
  46. {
  47. index = LB_ERR;
  48. }
  49. else if (pActiveMDI->hWndListbox)
  50. {
  51. index = (int)SendMessage (pActiveMDI->hWndListbox, LB_GETCURSEL, 0, 0L);
  52. if ( index != LB_ERR )
  53. {
  54. SendMessage (pActiveMDI->hWndListbox, LB_GETTEXT, index, (LPARAM)(LPCSTR)&lpLE);
  55. }
  56. }
  57. else
  58. index = LB_ERR;
  59. EnableMenuItem (hmenu,
  60. IDM_OPEN,
  61. (flags & F_CLPBRD ? MF_ENABLED : MF_GRAYED)| MF_BYCOMMAND);
  62. EnableMenuItem (hmenu,
  63. IDM_SAVEAS,
  64. (CountClipboardFormats() && flags & (F_CLPBRD|F_LOCAL)?
  65. MF_ENABLED :
  66. MF_GRAYED)
  67. | MF_BYCOMMAND );
  68. if ( fShareEnabled )
  69. {
  70. // SHARE allowed?
  71. if ( (flags & F_LOCAL) && (index != LB_ERR) )
  72. {
  73. fMenu = MF_ENABLED;
  74. fButton = TRUE;
  75. }
  76. else
  77. {
  78. fMenu = MF_GRAYED;
  79. fButton = FALSE;
  80. }
  81. EnableMenuItem (hmenu, IDM_SHARE, fMenu | MF_BYCOMMAND );
  82. SendMessage ( hwndToolbar, TB_ENABLEBUTTON, IDM_SHARE, fButton );
  83. // UNSHARE allowed?
  84. if ( (flags & F_LOCAL) && (index != LB_ERR) && IsShared(lpLE) )
  85. {
  86. fMenu = MF_ENABLED;
  87. fButton = TRUE;
  88. }
  89. else
  90. {
  91. fMenu = MF_GRAYED;
  92. fButton = FALSE;
  93. }
  94. EnableMenuItem (hmenu, IDM_UNSHARE, fMenu | MF_BYCOMMAND);
  95. SendMessage ( hwndToolbar, TB_ENABLEBUTTON, IDM_UNSHARE, fButton );
  96. }
  97. if ( fNetDDEActive )
  98. {
  99. // DISCONNECT allowed?
  100. EnableMenuItem (hmenu, IDM_DISCONNECT,
  101. (flags & ( F_LOCAL | F_CLPBRD ) ? MF_GRAYED : MF_ENABLED) | MF_BYCOMMAND );
  102. SendMessage ( hwndToolbar, TB_ENABLEBUTTON, IDM_DISCONNECT,
  103. flags & ( F_LOCAL | F_CLPBRD ) ? FALSE : TRUE );
  104. }
  105. else // If netdde isn't active, we can't connect
  106. {
  107. EnableMenuItem(hmenu, IDM_CONNECT, MF_GRAYED | MF_BYCOMMAND);
  108. EnableMenuItem(hmenu, IDM_DISCONNECT, MF_GRAYED | MF_BYCOMMAND);
  109. SendMessage(hwndToolbar, TB_ENABLEBUTTON, IDM_CONNECT, FALSE);
  110. SendMessage(hwndToolbar, TB_ENABLEBUTTON, IDM_DISCONNECT, FALSE);
  111. }
  112. // Delete allowed?
  113. if ( ( flags & F_LOCAL && index != LB_ERR ) ||
  114. flags & F_CLPBRD && CountClipboardFormats() )
  115. {
  116. fMenu = MF_ENABLED;
  117. fButton = TRUE;
  118. }
  119. else
  120. {
  121. fMenu = MF_GRAYED;
  122. fButton = FALSE;
  123. }
  124. EnableMenuItem (hmenu, IDM_DELETE, fMenu | MF_BYCOMMAND);
  125. SendMessage ( hwndToolbar, TB_ENABLEBUTTON, IDM_DELETE, fButton );
  126. // a page selected?
  127. if ( index != LB_ERR )
  128. {
  129. fMenu = MF_ENABLED;
  130. fButton = TRUE;
  131. }
  132. else
  133. {
  134. fMenu = MF_GRAYED;
  135. fButton = FALSE;
  136. }
  137. EnableMenuItem (hmenu, IDM_COPY, fMenu | MF_BYCOMMAND);
  138. SendMessage ( hwndToolbar, TB_ENABLEBUTTON, IDM_COPY, fButton );
  139. // Paste Allowed?
  140. if (CountClipboardFormats() && hwndActiveChild == hwndLocal && !(flags & F_CLPBRD))
  141. {
  142. fMenu = MF_ENABLED;
  143. fButton = TRUE;
  144. }
  145. else
  146. {
  147. fMenu = MF_GRAYED;
  148. fButton = FALSE;
  149. }
  150. EnableMenuItem (hmenu, IDM_KEEP, fMenu | MF_BYCOMMAND);
  151. SendMessage (hwndToolbar, TB_ENABLEBUTTON, IDM_KEEP, fButton );
  152. // if a page is selected
  153. if (LB_ERR != index)
  154. EnableMenuItem (hmenu, IDM_PASTE_PAGE, fMenu|MF_BYCOMMAND);
  155. else
  156. EnableMenuItem (hmenu, IDM_PASTE_PAGE, MF_GRAYED|MF_BYCOMMAND);
  157. // TOOLBAR, STATUS BAR
  158. CheckMenuItem ( hmenu, IDM_TOOLBAR, fToolBar ? MF_CHECKED : MF_UNCHECKED );
  159. CheckMenuItem ( hmenu, IDM_STATUSBAR, fStatus ? MF_CHECKED:MF_UNCHECKED );
  160. // disable some view options if clipboard window
  161. EnableMenuItem (hmenu,
  162. IDM_LISTVIEW,
  163. (flags & F_CLPBRD ? MF_GRAYED : MF_ENABLED) | MF_BYCOMMAND );
  164. EnableMenuItem (hmenu,
  165. IDM_PREVIEWS,
  166. (flags & F_CLPBRD ? MF_GRAYED : MF_ENABLED) | MF_BYCOMMAND );
  167. EnableMenuItem (hmenu,
  168. IDM_PAGEVIEW,
  169. ((flags & F_CLPBRD) || index != LB_ERR ? MF_ENABLED : MF_GRAYED) | MF_BYCOMMAND);
  170. SendMessage (hwndToolbar,
  171. TB_ENABLEBUTTON,
  172. IDM_LISTVIEW,
  173. flags & F_CLPBRD ? FALSE : TRUE);
  174. SendMessage (hwndToolbar,
  175. TB_ENABLEBUTTON,
  176. IDM_PREVIEWS,
  177. flags & F_CLPBRD ? FALSE : TRUE);
  178. SendMessage (hwndToolbar,
  179. TB_ENABLEBUTTON,
  180. IDM_PAGEVIEW,
  181. (( flags & F_CLPBRD ) || index != LB_ERR ) ? TRUE : FALSE );
  182. // Disable "Security" menu for other than Local Clipbook window
  183. // or if there's no item selected in the clipbook window
  184. fMenu = MF_GRAYED | MF_BYCOMMAND;
  185. if ((flags & F_LOCAL) && LB_ERR != index)
  186. {
  187. fMenu = MF_ENABLED | MF_BYCOMMAND;
  188. }
  189. EnableMenuItem (hmenu, IDM_PERMISSIONS, fMenu);
  190. EnableMenuItem (hmenu, IDM_OWNER, fMenu);
  191. EnableMenuItem (hmenu, IDM_AUDITING, fAuditEnabled ? fMenu : MF_GRAYED | MF_BYCOMMAND);
  192. // check selected view...
  193. CheckMenuItem (hmenu,
  194. IDM_LISTVIEW,
  195. pActiveMDI->DisplayMode == DSP_LIST ? MF_CHECKED : MF_UNCHECKED );
  196. CheckMenuItem (hmenu,
  197. IDM_PREVIEWS,
  198. pActiveMDI->DisplayMode == DSP_PREV ? MF_CHECKED : MF_UNCHECKED );
  199. CheckMenuItem (hmenu,
  200. IDM_PAGEVIEW,
  201. pActiveMDI->DisplayMode == DSP_PAGE ? MF_CHECKED : MF_UNCHECKED );
  202. SendMessage (hwndToolbar,
  203. TB_CHECKBUTTON,
  204. IDM_LISTVIEW,
  205. pActiveMDI->DisplayMode == DSP_LIST ? TRUE : FALSE );
  206. SendMessage (hwndToolbar,
  207. TB_CHECKBUTTON,
  208. IDM_PREVIEWS,
  209. pActiveMDI->DisplayMode == DSP_PREV ? TRUE : FALSE );
  210. SendMessage (hwndToolbar,
  211. TB_CHECKBUTTON,
  212. IDM_PAGEVIEW,
  213. pActiveMDI->DisplayMode == DSP_PAGE ? TRUE : FALSE );
  214. DrawMenuBar(hwndApp);
  215. return;
  216. }