comparison src/w32menu.c @ 28275:2c8492145fc8

(single_submenu): Set help string to NULL if none. (w32_menu_show): Set help string correctly. (add-menu-item): Set help string in MIIM_DATA for menu item. Load SetMenuItemInfoA explicitly. (w32_menu_display_help): New function.
author Jason Rumney <jasonr@gnu.org>
date Wed, 22 Mar 2000 23:15:30 +0000
parents a590f8d0dbd2
children 33aa00975055
comparison
equal deleted inserted replaced
28274:e9c99955f520 28275:2c8492145fc8
52 typedef char Boolean; 52 typedef char Boolean;
53 53
54 #define True 1 54 #define True 1
55 #define False 0 55 #define False 0
56 56
57 #if 0 /* Not used below. */
58 typedef enum _change_type
59 {
60 NO_CHANGE = 0,
61 INVISIBLE_CHANGE = 1,
62 VISIBLE_CHANGE = 2,
63 STRUCTURAL_CHANGE = 3
64 } change_type;
65 #endif
66
67 enum button_type 57 enum button_type
68 { 58 {
69 BUTTON_TYPE_NONE, 59 BUTTON_TYPE_NONE,
70 BUTTON_TYPE_TOGGLE, 60 BUTTON_TYPE_TOGGLE,
71 BUTTON_TYPE_RADIO 61 BUTTON_TYPE_RADIO
77 char* name; 67 char* name;
78 /* value (meaning depend on widget type) */ 68 /* value (meaning depend on widget type) */
79 char* value; 69 char* value;
80 /* keyboard equivalent. no implications for XtTranslations */ 70 /* keyboard equivalent. no implications for XtTranslations */
81 char* key; 71 char* key;
82 /* Help string or null if none. */ 72 /* Help string. */
83 char *help; 73 char* help;
84 /* true if enabled */ 74 /* true if enabled */
85 Boolean enabled; 75 Boolean enabled;
86 /* true if selected */ 76 /* true if selected */
87 Boolean selected; 77 Boolean selected;
88 /* The type of a button. */ 78 /* The type of a button. */
1217 else 1207 else
1218 { 1208 {
1219 /* Create a new item within current pane. */ 1209 /* Create a new item within current pane. */
1220 Lisp_Object item_name, enable, descrip, def, type, selected; 1210 Lisp_Object item_name, enable, descrip, def, type, selected;
1221 Lisp_Object help; 1211 Lisp_Object help;
1212
1222 /* NTEMACS_TODO: implement popup/modeline help for menus. */ 1213 /* NTEMACS_TODO: implement popup/modeline help for menus. */
1223 1214
1224 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; 1215 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
1225 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; 1216 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
1226 descrip 1217 descrip
1261 else 1252 else
1262 abort (); 1253 abort ();
1263 1254
1264 wv->selected = !NILP (selected); 1255 wv->selected = !NILP (selected);
1265 if (STRINGP (help)) 1256 if (STRINGP (help))
1266 wv->help = XSTRING (help)->data; 1257 wv->help = (char *) XSTRING (help)->data;
1267 1258 else
1259 wv->help = NULL;
1260
1268 prev_wv = wv; 1261 prev_wv = wv;
1269 1262
1270 i += MENU_ITEMS_ITEM_LENGTH; 1263 i += MENU_ITEMS_ITEM_LENGTH;
1271 } 1264 }
1272 } 1265 }
1664 } 1657 }
1665 else 1658 else
1666 { 1659 {
1667 /* Create a new item within current pane. */ 1660 /* Create a new item within current pane. */
1668 Lisp_Object item_name, enable, descrip, def, type, selected, help; 1661 Lisp_Object item_name, enable, descrip, def, type, selected, help;
1669 char *help_string;
1670 1662
1671 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; 1663 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
1672 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; 1664 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
1673 descrip 1665 descrip
1674 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; 1666 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
1680 #ifndef HAVE_MULTILINGUAL_MENU 1672 #ifndef HAVE_MULTILINGUAL_MENU
1681 if (STRINGP (item_name) && STRING_MULTIBYTE (item_name)) 1673 if (STRINGP (item_name) && STRING_MULTIBYTE (item_name))
1682 item_name = string_make_unibyte (item_name); 1674 item_name = string_make_unibyte (item_name);
1683 if (STRINGP (descrip) && STRING_MULTIBYTE (descrip)) 1675 if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
1684 descrip = string_make_unibyte (descrip); 1676 descrip = string_make_unibyte (descrip);
1685 if (STRINGP (help) && STRING_MULTIBYTE (help))
1686 help = string_make_unibyte (help);
1687 #endif 1677 #endif
1688
1689 help_string = STRINGP (help) ? XSTRING (help)->data : NULL;
1690 1678
1691 wv = xmalloc_widget_value (); 1679 wv = xmalloc_widget_value ();
1692 if (prev_wv) 1680 if (prev_wv)
1693 prev_wv->next = wv; 1681 prev_wv->next = wv;
1694 else 1682 else
1710 wv->button_type = BUTTON_TYPE_RADIO; 1698 wv->button_type = BUTTON_TYPE_RADIO;
1711 else 1699 else
1712 abort (); 1700 abort ();
1713 1701
1714 wv->selected = !NILP (selected); 1702 wv->selected = !NILP (selected);
1715 1703
1704 if (STRINGP (help))
1705 wv->help = (char *) XSTRING (help)->data;
1706 else
1707 wv->help = NULL;
1708
1716 prev_wv = wv; 1709 prev_wv = wv;
1717 1710
1718 i += MENU_ITEMS_ITEM_LENGTH; 1711 i += MENU_ITEMS_ITEM_LENGTH;
1719 } 1712 }
1720 } 1713 }
1878 while (i < menu_items_used) 1871 while (i < menu_items_used)
1879 { 1872 {
1880 1873
1881 /* Create a new item within current pane. */ 1874 /* Create a new item within current pane. */
1882 Lisp_Object item_name, enable, descrip, help; 1875 Lisp_Object item_name, enable, descrip, help;
1883 char *help_string;
1884 1876
1885 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; 1877 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME];
1886 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; 1878 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE];
1887 descrip 1879 descrip
1888 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; 1880 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY];
1889 help = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_HELP]; 1881 help = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_HELP];
1890 help_string = STRINGP (help) ? XSTRING (help)->data : NULL;
1891 1882
1892 if (NILP (item_name)) 1883 if (NILP (item_name))
1893 { 1884 {
1894 free_menubar_widget_value_tree (first_wv); 1885 free_menubar_widget_value_tree (first_wv);
1895 *error = "Submenu in dialog items"; 1886 *error = "Submenu in dialog items";
2087 fuFlags, 2078 fuFlags,
2088 item != NULL ? (UINT) item : (UINT) wv->call_data, 2079 item != NULL ? (UINT) item : (UINT) wv->call_data,
2089 (fuFlags == MF_SEPARATOR) ? NULL: out_string ); 2080 (fuFlags == MF_SEPARATOR) ? NULL: out_string );
2090 2081
2091 /* This must be done after the menu item is created. */ 2082 /* This must be done after the menu item is created. */
2092 if (wv->button_type == BUTTON_TYPE_RADIO) 2083 {
2093 { 2084 HMODULE user32 = GetModuleHandle ("user32.dll");
2094 /* CheckMenuRadioItem allows us to differentiate TOGGLE and 2085 FARPROC set_menu_item_info = GetProcAddress (user32, "SetMenuItemInfoA");
2095 RADIO items, but is not available on NT 3.51 and earlier. */ 2086
2096 HMODULE user32 = GetModuleHandle ("user32.dll"); 2087 if (set_menu_item_info)
2097 FARPROC set_menu_item_info = GetProcAddress (user32, "SetMenuItemInfo"); 2088 {
2098 2089 MENUITEMINFO info;
2099 if (set_menu_item_info) 2090 bzero (&info, sizeof (info));
2100 { 2091 info.cbSize = sizeof (info);
2101 MENUITEMINFO info; 2092 info.fMask = MIIM_DATA;
2102 bzero (&info, sizeof (info)); 2093 /* Set help string for menu item. */
2103 info.cbSize = sizeof (info); 2094 info.dwItemData = (DWORD)wv->help;
2104 info.fMask = MIIM_TYPE | MIIM_STATE; 2095
2105 info.fType = MFT_RADIOCHECK; 2096 if (wv->button_type == BUTTON_TYPE_RADIO)
2106 info.fState = wv->selected ? MFS_CHECKED : MFS_UNCHECKED; 2097 {
2107 set_menu_item_info (menu, item, FALSE, &info); 2098 /* CheckMenuRadioItem allows us to differentiate TOGGLE and
2108 } 2099 RADIO items, but is not available on NT 3.51 and earlier. */
2109 } 2100 info.fMask |= MIIM_TYPE | MIIM_STATE;
2110 2101 info.fType = MFT_RADIOCHECK;
2102 info.fState = wv->selected ? MFS_CHECKED : MFS_UNCHECKED;
2103 }
2104 set_menu_item_info (menu,
2105 item != NULL ? (UINT) item : (UINT) wv->call_data,
2106 FALSE, &info);
2107 }
2108 }
2111 return return_value; 2109 return return_value;
2112 } 2110 }
2113 2111
2114 /* Construct native Windows menu(bar) based on widget_value tree. */ 2112 /* Construct native Windows menu(bar) based on widget_value tree. */
2115 static int 2113 static int
2147 { 2145 {
2148 /* popup_activated_flag not actually used on W32 */ 2146 /* popup_activated_flag not actually used on W32 */
2149 return 0; 2147 return 0;
2150 } 2148 }
2151 2149
2150 /* Display help string for currently pointed to menu item. Not
2151 supported on NT 3.51 and earlier, as GetMenuItemInfo is not
2152 available. */
2153 void
2154 w32_menu_display_help (HMENU menu, UINT item, UINT flags)
2155 {
2156 HMODULE user32 = GetModuleHandle ("user32.dll");
2157 FARPROC get_menu_item_info = GetProcAddress (user32, "GetMenuItemInfoA");
2158
2159 if (get_menu_item_info)
2160 {
2161 struct gcpro gcpro1;
2162 extern Lisp_Object Vshow_help_function;
2163 Lisp_Object msg;
2164 MENUITEMINFO info;
2165
2166 bzero (&info, sizeof (info));
2167 info.cbSize = sizeof (info);
2168 info.fMask = MIIM_DATA;
2169 get_menu_item_info (menu, item, FALSE, &info);
2170
2171 msg = info.dwItemData ? build_string ((char *) info.dwItemData) : Qnil;
2172 GCPRO1 (msg);
2173
2174 if (!NILP (Vshow_help_function))
2175 call1 (Vshow_help_function, msg);
2176 else if (!MINI_WINDOW_P (XWINDOW (selected_window)))
2177 {
2178 if (STRINGP(msg))
2179 message3_nolog (msg, XSTRING (msg)->size, STRING_MULTIBYTE (msg));
2180 else
2181 message (0);
2182 }
2183 UNGCPRO;
2184 }
2185 }
2186
2187
2188
2152 #endif /* HAVE_MENUS */ 2189 #endif /* HAVE_MENUS */
2153 2190
2154 syms_of_w32menu () 2191 syms_of_w32menu ()
2155 { 2192 {
2156 staticpro (&menu_items); 2193 staticpro (&menu_items);