aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsmenu.m
diff options
context:
space:
mode:
authorJan Djärv2013-06-02 21:14:25 +0200
committerJan Djärv2013-06-02 21:14:25 +0200
commitc0342369acfbad2f0ea86b949a2f116304186353 (patch)
treeee60679ec6f2c20b201ef8a71be515582e27c268 /src/nsmenu.m
parenta2d98946738ffd42f90b3f54d2a32be9d7b6429e (diff)
downloademacs-c0342369acfbad2f0ea86b949a2f116304186353.tar.gz
emacs-c0342369acfbad2f0ea86b949a2f116304186353.zip
Update the GNUStep port so it works OK. Redraw and sizing bugs remain.
* nextstep/templates/Info-gnustep.plist.in: Add NSDocumentClass EmacsDocument. * src/nsfns.m (x_set_foreground_color, x_set_background_color): Use EmacsCGFloat. (ns_implicitly_set_icon_type, Fx_create_frame): Make static, remove unused variables. (Fns_read_file_name): Keep track if panel is for save. Use ns_filename_from_panel/ns_directory_from_panel. (Fns_list_services): delegate only used for COCOA. (Fns_convert_utf8_nfd_to_nfc): Remove warning for GNUStep. Just return the input if GNUStep. (x_screen_planes): Remove. (Fxw_color_values): Use EmacsCGFloat (Fns_display_monitor_attributes_list): Only get screen number for Cocoa. (getDirectory, getFilename): Removed from EmacsOpenPanel and EmacsSavePanel. (EmacsOpenPanel:ok:): Use ns_filename_from_panel and ns_directory_from_panel. * src/nsfont.m (ns_attribute_fvalue, ns_spec_to_descriptor) (ns_charset_covers, ns_get_covering_families, nsfont_open): Use F suffix on floats. (ns_char_width): Returns CGFloat. (ns_ascii_average_width): w is CGFloat instead of float. (nsfont_draw): cbuf and c are unsigned. Cast to char* in call to DPSxshow. (ns_glyph_metrics): CGFloat instead of float. * src/nsimage.m (setXBMColor:, getPixelAtX:Y:): Use EmacsCGFloat. * src/nsmenu.m (ns_update_menubar): Make static. (x_activate_menubar): Surround with ifdef NS_IMPL_COCOA (fillWithWidgetValue:): Add cast to SEL for setAction. (addSubmenuWithTitle:forFrame:): Add cast to SEL for action. (update_frame_tool_bar): Update code for GNUStep. (clearAll): New method. (addDisplayItemWithImage:idx:tag:helpText:enabled:): Handle new tag argument. Call insertItemWithItemIdentifier when NS_IMPL_GNUSTEP. Move identifierToItem setObject and activeIdentifiers addObject before call to insertItemWithItemIdentifier. (validateVisibleItems): Fix indentation. (toolbarAllowedItemIdentifiers:): Return activeIdentifiers. (initWithContentRect:styleMask:backing:defer:): Add ClosableWindow and UtilityWindow to aStyle, remove call to setStyleMask. * src/nsselect.m (ns_get_local_selection): Remove unused variable type. * src/nsterm.h (EmacsCGFloat): Typedef for OSX and GNUStep when the size of CGFloat differs. (EmacsApp): New variable nextappdefined. Declare sendFromMainThread when NS_IMPL_GNUSTEP. (EmacsDocument): Declare when NS_IMPL_GNUSTEP. (EmacsView): Remove unlockFocusNeedsFlush, add windowDidMove. (EmacsToolbar): Add clearAll. Add tag argument to addDisplayItemWithImage. (EmacsSavePanel, EmacsOpenPanel): Remove getFilename and getDirectory. * src/nsterm.m: Include src/process.h if NS_IMPL_GNUSTEP. (ns_menu_bar_is_hidden, menu_will_open_state): Define only if NS_IMPL_COCOA. (x_set_cursor_type): Remove declaration. (ns_update_begin): Only use r and bp if NS_IMPL_COCOA. (ns_update_end, ns_focus, ns_unfocus): Remove GNUStep specific code. (x_set_window_size): Remove 3 pixels from toolbar if NS_IMPL_GNUSTEP. (ns_get_color): Use F suffix on float. (ns_color_to_lisp, ns_query_color): Use EmacsCGFloat. (ns_get_rgb_color): Remove. (x_set_frame_alpha): Move view inside NS_IMPL_COCOA. (note_mouse_movement): x and y are CGFloat. (ns_draw_fringe_bitmap): Remove unused rowY. Change #if to COCOA && >= 10_6. (ns_draw_window_cursor): Remove unused overspill. (ns_draw_underwave): width and x are EamcsCGFloat. (ns_draw_box): thickness is CGFloat. (ns_dumpglyphs_image): Change #if to COCOA && >= 10_6. (ns_send_appdefined): When NS_IMPL_GNUSTEP, redirect to main thread if not in main thread. (ns_get_pending_menu_title, ns_check_menu_open) (ns_check_pending_open_menu): Put inside #if COCOA && >= 10_5. (ns_term_init): Call catch_child_signal if NS_IMPL_GNUSTEP && SIGCHLD. (sendFromMainThread:): New method. (changeFont:): size is CGFloat. (keyDown:): Check for Delete when NS_IMPL_GNUSTEP. Disable warning about permanent text. (characterIndexForPoint:): Adjust return type depending on GNUStep version. (mouseDown:): delta is CGFloat. (updateFrameSize): Remove unised variable f. (initFrameFromEmacs): Move toggleButton inside NS_IMPL_COCOA. Cast float to EmacsCGFloat. (windowWillUseStandardFrame:defaultFrame:): Set maximized_height also to -1 when restoring. (windowDidExitFullScreen:): Put call to updateCollectionBehaviour inside NS_IMPL_COCOA. (toggleFullScreen:): Put call to toggleFullScreen inside NS_IMPL_COCOA. Cast float to EmacsCGFloat. (setPosition:portion:whole:): por is CGFloat. (getMouseMotionPart:window:x:y:): Add F suffix to float. (mouseDown:): Use CGFloat. (mouseDragged:): Remove unised variable edge. (EmacsDocument): Implement for NS_IMPL_GNUSTEP. * src/process.c (catch_child_signal): New function. (init_process_emacs): Call it. * src/process.h (catch_child_signal): Declare.
Diffstat (limited to 'src/nsmenu.m')
-rw-r--r--src/nsmenu.m70
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
51int menu_trace_num = 0; 49int 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 -------------------------------------------------------------------------- */
115void 113static void
116ns_update_menubar (struct frame *f, bool deep_p, EmacsMenu *submenu) 114ns_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)
505void 503void
506x_activate_menubar (struct frame *f) 504x_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