diff options
Diffstat (limited to 'src/nsmenu.m')
| -rw-r--r-- | src/nsmenu.m | 70 |
1 files changed, 52 insertions, 18 deletions
diff --git a/src/nsmenu.m b/src/nsmenu.m index baa683941f8..1d3d111e9a1 100644 --- a/src/nsmenu.m +++ b/src/nsmenu.m | |||
| @@ -45,8 +45,6 @@ Carbon version by Yamamoto Mitsuharu. */ | |||
| 45 | #include <sys/types.h> | 45 | #include <sys/types.h> |
| 46 | #endif | 46 | #endif |
| 47 | 47 | ||
| 48 | #define MenuStagger 10.0 | ||
| 49 | |||
| 50 | #if 0 | 48 | #if 0 |
| 51 | int menu_trace_num = 0; | 49 | int menu_trace_num = 0; |
| 52 | #define NSTRACE(x) fprintf (stderr, "%s:%d: [%d] " #x "\n", \ | 50 | #define NSTRACE(x) fprintf (stderr, "%s:%d: [%d] " #x "\n", \ |
| @@ -112,7 +110,7 @@ popup_activated (void) | |||
| 112 | 2) deep_p, submenu = nil: Recompute all submenus. | 110 | 2) deep_p, submenu = nil: Recompute all submenus. |
| 113 | 3) deep_p, submenu = non-nil: Update contents of a single submenu. | 111 | 3) deep_p, submenu = non-nil: Update contents of a single submenu. |
| 114 | -------------------------------------------------------------------------- */ | 112 | -------------------------------------------------------------------------- */ |
| 115 | void | 113 | static void |
| 116 | ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu) | 114 | ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu) |
| 117 | { | 115 | { |
| 118 | NSAutoreleasePool *pool; | 116 | NSAutoreleasePool *pool; |
| @@ -505,6 +503,7 @@ set_frame_menubar (struct frame *f, bool first_time, bool deep_p) | |||
| 505 | void | 503 | void |
| 506 | x_activate_menubar (struct frame *f) | 504 | x_activate_menubar (struct frame *f) |
| 507 | { | 505 | { |
| 506 | #ifdef NS_IMPL_COCOA | ||
| 508 | NSArray *a = [[NSApp mainMenu] itemArray]; | 507 | NSArray *a = [[NSApp mainMenu] itemArray]; |
| 509 | /* Update each submenu separately so ns_update_menubar doesn't reset | 508 | /* Update each submenu separately so ns_update_menubar doesn't reset |
| 510 | the delegate. */ | 509 | the delegate. */ |
| @@ -521,6 +520,7 @@ x_activate_menubar (struct frame *f) | |||
| 521 | ++i; | 520 | ++i; |
| 522 | } | 521 | } |
| 523 | ns_check_pending_open_menu (); | 522 | ns_check_pending_open_menu (); |
| 523 | #endif | ||
| 524 | } | 524 | } |
| 525 | 525 | ||
| 526 | 526 | ||
| @@ -740,7 +740,7 @@ extern NSString *NSMenuDidBeginTrackingNotification; | |||
| 740 | [self setSubmenu: submenu forItem: item]; | 740 | [self setSubmenu: submenu forItem: item]; |
| 741 | [submenu fillWithWidgetValue: wv->contents]; | 741 | [submenu fillWithWidgetValue: wv->contents]; |
| 742 | [submenu release]; | 742 | [submenu release]; |
| 743 | [item setAction: nil]; | 743 | [item setAction: (SEL)nil]; |
| 744 | } | 744 | } |
| 745 | } | 745 | } |
| 746 | 746 | ||
| @@ -757,7 +757,7 @@ extern NSString *NSMenuDidBeginTrackingNotification; | |||
| 757 | { | 757 | { |
| 758 | NSString *titleStr = [NSString stringWithUTF8String: title]; | 758 | NSString *titleStr = [NSString stringWithUTF8String: title]; |
| 759 | NSMenuItem *item = [self addItemWithTitle: titleStr | 759 | NSMenuItem *item = [self addItemWithTitle: titleStr |
| 760 | action: nil /*@selector (menuDown:) */ | 760 | action: (SEL)nil /*@selector (menuDown:) */ |
| 761 | keyEquivalent: @""]; | 761 | keyEquivalent: @""]; |
| 762 | EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: titleStr frame: f]; | 762 | EmacsMenu *submenu = [[EmacsMenu alloc] initWithTitle: titleStr frame: f]; |
| 763 | [self setSubmenu: submenu forItem: item]; | 763 | [self setSubmenu: submenu forItem: item]; |
| @@ -1045,13 +1045,18 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1045 | Update toolbar contents | 1045 | Update toolbar contents |
| 1046 | -------------------------------------------------------------------------- */ | 1046 | -------------------------------------------------------------------------- */ |
| 1047 | { | 1047 | { |
| 1048 | int i; | 1048 | int i, k = 0; |
| 1049 | EmacsView *view = FRAME_NS_VIEW (f); | 1049 | EmacsView *view = FRAME_NS_VIEW (f); |
| 1050 | NSWindow *window = [view window]; | 1050 | NSWindow *window = [view window]; |
| 1051 | EmacsToolbar *toolbar = [view toolbar]; | 1051 | EmacsToolbar *toolbar = [view toolbar]; |
| 1052 | 1052 | ||
| 1053 | block_input (); | 1053 | block_input (); |
| 1054 | |||
| 1055 | #ifdef NS_IMPL_COCOA | ||
| 1054 | [toolbar clearActive]; | 1056 | [toolbar clearActive]; |
| 1057 | #else | ||
| 1058 | [toolbar clearAll]; | ||
| 1059 | #endif | ||
| 1055 | 1060 | ||
| 1056 | /* update EmacsToolbar as in GtkUtils, build items list */ | 1061 | /* update EmacsToolbar as in GtkUtils, build items list */ |
| 1057 | for (i = 0; i < f->n_tool_bar_items; ++i) | 1062 | for (i = 0; i < f->n_tool_bar_items; ++i) |
| @@ -1067,6 +1072,15 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1067 | Lisp_Object helpObj; | 1072 | Lisp_Object helpObj; |
| 1068 | const char *helpText; | 1073 | const char *helpText; |
| 1069 | 1074 | ||
| 1075 | /* Check if this is a separator. */ | ||
| 1076 | if (EQ (TOOLPROP (TOOL_BAR_ITEM_TYPE), Qt)) | ||
| 1077 | { | ||
| 1078 | /* Skip separators. Newer OSX don't show them, and on GNUStep they | ||
| 1079 | are wide as a button, thus overflowing the toolbar most of | ||
| 1080 | the time. */ | ||
| 1081 | continue; | ||
| 1082 | } | ||
| 1083 | |||
| 1070 | /* If image is a vector, choose the image according to the | 1084 | /* If image is a vector, choose the image according to the |
| 1071 | button state. */ | 1085 | button state. */ |
| 1072 | image = TOOLPROP (TOOL_BAR_ITEM_IMAGES); | 1086 | image = TOOLPROP (TOOL_BAR_ITEM_IMAGES); |
| @@ -1103,7 +1117,10 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1103 | continue; | 1117 | continue; |
| 1104 | } | 1118 | } |
| 1105 | 1119 | ||
| 1106 | [toolbar addDisplayItemWithImage: img->pixmap idx: i helpText: helpText | 1120 | [toolbar addDisplayItemWithImage: img->pixmap |
| 1121 | idx: k++ | ||
| 1122 | tag: i | ||
| 1123 | helpText: helpText | ||
| 1107 | enabled: enabled_p]; | 1124 | enabled: enabled_p]; |
| 1108 | #undef TOOLPROP | 1125 | #undef TOOLPROP |
| 1109 | } | 1126 | } |
| @@ -1111,6 +1128,7 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1111 | if (![toolbar isVisible]) | 1128 | if (![toolbar isVisible]) |
| 1112 | [toolbar setVisible: YES]; | 1129 | [toolbar setVisible: YES]; |
| 1113 | 1130 | ||
| 1131 | #ifdef NS_IMPL_COCOA | ||
| 1114 | if ([toolbar changed]) | 1132 | if ([toolbar changed]) |
| 1115 | { | 1133 | { |
| 1116 | /* inform app that toolbar has changed */ | 1134 | /* inform app that toolbar has changed */ |
| @@ -1132,6 +1150,7 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1132 | [toolbar setConfigurationFromDictionary: newDict]; | 1150 | [toolbar setConfigurationFromDictionary: newDict]; |
| 1133 | [newDict release]; | 1151 | [newDict release]; |
| 1134 | } | 1152 | } |
| 1153 | #endif | ||
| 1135 | 1154 | ||
| 1136 | FRAME_TOOLBAR_HEIGHT (f) = | 1155 | FRAME_TOOLBAR_HEIGHT (f) = |
| 1137 | NSHeight ([window frameRectForContentRect: NSMakeRect (0, 0, 0, 0)]) | 1156 | NSHeight ([window frameRectForContentRect: NSMakeRect (0, 0, 0, 0)]) |
| @@ -1159,6 +1178,7 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1159 | [self setDelegate: self]; | 1178 | [self setDelegate: self]; |
| 1160 | identifierToItem = [[NSMutableDictionary alloc] initWithCapacity: 10]; | 1179 | identifierToItem = [[NSMutableDictionary alloc] initWithCapacity: 10]; |
| 1161 | activeIdentifiers = [[NSMutableArray alloc] initWithCapacity: 8]; | 1180 | activeIdentifiers = [[NSMutableArray alloc] initWithCapacity: 8]; |
| 1181 | prevIdentifiers = nil; | ||
| 1162 | prevEnablement = enablement = 0L; | 1182 | prevEnablement = enablement = 0L; |
| 1163 | return self; | 1183 | return self; |
| 1164 | } | 1184 | } |
| @@ -1180,18 +1200,29 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1180 | enablement = 0L; | 1200 | enablement = 0L; |
| 1181 | } | 1201 | } |
| 1182 | 1202 | ||
| 1203 | - (void) clearAll | ||
| 1204 | { | ||
| 1205 | [self clearActive]; | ||
| 1206 | while ([[self items] count] > 0) | ||
| 1207 | [self removeItemAtIndex: 0]; | ||
| 1208 | } | ||
| 1209 | |||
| 1183 | - (BOOL) changed | 1210 | - (BOOL) changed |
| 1184 | { | 1211 | { |
| 1185 | return [activeIdentifiers isEqualToArray: prevIdentifiers] && | 1212 | return [activeIdentifiers isEqualToArray: prevIdentifiers] && |
| 1186 | enablement == prevEnablement ? NO : YES; | 1213 | enablement == prevEnablement ? NO : YES; |
| 1187 | } | 1214 | } |
| 1188 | 1215 | ||
| 1189 | - (void) addDisplayItemWithImage: (EmacsImage *)img idx: (int)idx | 1216 | - (void) addDisplayItemWithImage: (EmacsImage *)img |
| 1190 | helpText: (const char *)help enabled: (BOOL)enabled | 1217 | idx: (int)idx |
| 1218 | tag: (int)tag | ||
| 1219 | helpText: (const char *)help | ||
| 1220 | enabled: (BOOL)enabled | ||
| 1191 | { | 1221 | { |
| 1192 | /* 1) come up w/identifier */ | 1222 | /* 1) come up w/identifier */ |
| 1193 | NSString *identifier | 1223 | NSString *identifier |
| 1194 | = [NSString stringWithFormat: @"%u", [img hash]]; | 1224 | = [NSString stringWithFormat: @"%u", [img hash]]; |
| 1225 | [activeIdentifiers addObject: identifier]; | ||
| 1195 | 1226 | ||
| 1196 | /* 2) create / reuse item */ | 1227 | /* 2) create / reuse item */ |
| 1197 | NSToolbarItem *item = [identifierToItem objectForKey: identifier]; | 1228 | NSToolbarItem *item = [identifierToItem objectForKey: identifier]; |
| @@ -1203,20 +1234,25 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1203 | [item setToolTip: [NSString stringWithUTF8String: help]]; | 1234 | [item setToolTip: [NSString stringWithUTF8String: help]]; |
| 1204 | [item setTarget: emacsView]; | 1235 | [item setTarget: emacsView]; |
| 1205 | [item setAction: @selector (toolbarClicked:)]; | 1236 | [item setAction: @selector (toolbarClicked:)]; |
| 1237 | [identifierToItem setObject: item forKey: identifier]; | ||
| 1206 | } | 1238 | } |
| 1207 | 1239 | ||
| 1208 | [item setTag: idx]; | 1240 | #ifdef NS_IMPL_GNUSTEP |
| 1241 | [self insertItemWithItemIdentifier: identifier atIndex: idx]; | ||
| 1242 | #endif | ||
| 1243 | |||
| 1244 | [item setTag: tag]; | ||
| 1209 | [item setEnabled: enabled]; | 1245 | [item setEnabled: enabled]; |
| 1210 | 1246 | ||
| 1211 | /* 3) update state */ | 1247 | /* 3) update state */ |
| 1212 | [identifierToItem setObject: item forKey: identifier]; | ||
| 1213 | [activeIdentifiers addObject: identifier]; | ||
| 1214 | enablement = (enablement << 1) | (enabled == YES); | 1248 | enablement = (enablement << 1) | (enabled == YES); |
| 1215 | } | 1249 | } |
| 1216 | 1250 | ||
| 1217 | /* This overrides super's implementation, which automatically sets | 1251 | /* This overrides super's implementation, which automatically sets |
| 1218 | all items to enabled state (for some reason). */ | 1252 | all items to enabled state (for some reason). */ |
| 1219 | - (void)validateVisibleItems { } | 1253 | - (void)validateVisibleItems |
| 1254 | { | ||
| 1255 | } | ||
| 1220 | 1256 | ||
| 1221 | 1257 | ||
| 1222 | /* delegate methods */ | 1258 | /* delegate methods */ |
| @@ -1239,7 +1275,8 @@ update_frame_tool_bar (FRAME_PTR f) | |||
| 1239 | - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar | 1275 | - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar |
| 1240 | { | 1276 | { |
| 1241 | /* return entire set... */ | 1277 | /* return entire set... */ |
| 1242 | return [identifierToItem allKeys]; | 1278 | return activeIdentifiers; |
| 1279 | //return [identifierToItem allKeys]; | ||
| 1243 | } | 1280 | } |
| 1244 | 1281 | ||
| 1245 | /* optional and unneeded */ | 1282 | /* optional and unneeded */ |
| @@ -1531,7 +1568,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header) | |||
| 1531 | [img autorelease]; | 1568 | [img autorelease]; |
| 1532 | [imgView autorelease]; | 1569 | [imgView autorelease]; |
| 1533 | 1570 | ||
| 1534 | aStyle = NSTitledWindowMask; | 1571 | aStyle = NSTitledWindowMask|NSClosableWindowMask|NSUtilityWindowMask; |
| 1535 | flag = YES; | 1572 | flag = YES; |
| 1536 | rows = 0; | 1573 | rows = 0; |
| 1537 | cols = 1; | 1574 | cols = 1; |
| @@ -1599,9 +1636,6 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header) | |||
| 1599 | [self setOneShot: YES]; | 1636 | [self setOneShot: YES]; |
| 1600 | [self setReleasedWhenClosed: YES]; | 1637 | [self setReleasedWhenClosed: YES]; |
| 1601 | [self setHidesOnDeactivate: YES]; | 1638 | [self setHidesOnDeactivate: YES]; |
| 1602 | [self setStyleMask: | ||
| 1603 | NSTitledWindowMask|NSClosableWindowMask|NSUtilityWindowMask]; | ||
| 1604 | |||
| 1605 | return self; | 1639 | return self; |
| 1606 | } | 1640 | } |
| 1607 | 1641 | ||