Author: fredkiefer
Date: Sat Dec 31 17:03:01 2016
New Revision: 40283

URL: http://svn.gna.org/viewcvs/gnustep?rev=40283&view=rev
Log:
        * Source/NSMenu.m (-update): Update only visible submenus.
        * Source/NSMenu.m: Complete switch to NSUInteger.

Modified:
    libs/gui/trunk/ChangeLog
    libs/gui/trunk/Source/NSMenu.m

Modified: libs/gui/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/ChangeLog?rev=40283&r1=40282&r2=40283&view=diff
==============================================================================
--- libs/gui/trunk/ChangeLog    (original)
+++ libs/gui/trunk/ChangeLog    Sat Dec 31 17:03:01 2016
@@ -1,3 +1,8 @@
+2016-12-31 Fred Kiefer <[email protected]>
+
+       * Source/NSMenu.m (-update): Update only visible submenus.
+       * Source/NSMenu.m: Complete switch to NSUInteger.
+
 2016-12-18 Fred Kiefer <[email protected]>
 
        * Source/GSLayoutManager.m: Don't try to get the advancement for

Modified: libs/gui/trunk/Source/NSMenu.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/trunk/Source/NSMenu.m?rev=40283&r1=40282&r2=40283&view=diff
==============================================================================
--- libs/gui/trunk/Source/NSMenu.m      (original)
+++ libs/gui/trunk/Source/NSMenu.m      Sat Dec 31 17:03:01 2016
@@ -1,6 +1,6 @@
 /** <title>NSMenu</title>
 
-   Copyright (C) 1999 Free Software Foundation, Inc.
+   Copyright (C) 1999,2016 Free Software Foundation, Inc.
 
    Author: Fred Kiefer <[email protected]>
    Date: Aug 2001
@@ -746,7 +746,7 @@
   
   // Create the notification for the menu representation.
   d = [NSDictionary
-         dictionaryWithObject: [NSNumber numberWithInt: index]
+         dictionaryWithObject: [NSNumber numberWithInteger: index]
          forKey: @"NSMenuItemIndex"];
   inserted = [NSNotification
                 notificationWithName: NSMenuDidAddItemNotification
@@ -796,7 +796,7 @@
 
 - (void) removeItem: (id <NSMenuItem>)anItem
 {
-  int index = [self indexOfItem: anItem];
+  NSInteger index = [self indexOfItem: anItem];
 
   if (-1 == index)
     return;
@@ -818,7 +818,7 @@
   _menu.needsSizing = YES;
   [(NSMenuView*)_view setNeedsSizing: YES];
   
-  d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: index]
+  d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger: index]
                    forKey: @"NSMenuItemIndex"];
   removed = [NSNotification
                notificationWithName: NSMenuDidRemoveItemNotification
@@ -844,7 +844,7 @@
   _menu.needsSizing = YES;
   [(NSMenuView*)_view setNeedsSizing: YES];
 
-  d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: index]
+  d = [NSDictionary dictionaryWithObject: [NSNumber numberWithInteger: index]
                    forKey: @"NSMenuItemIndex"];
   changed = [NSNotification
              notificationWithName: NSMenuDidChangeItemNotification
@@ -866,8 +866,8 @@
  */
 - (id <NSMenuItem>) itemWithTag: (NSInteger)aTag
 {
-  unsigned i;
-  unsigned count = [_items count];
+  NSUInteger i;
+  NSUInteger count = [_items count];
 
   for (i = 0; i < count; i++)
     {
@@ -881,8 +881,8 @@
 
 - (id <NSMenuItem>) itemWithTitle: (NSString*)aString
 {
-  unsigned i;
-  unsigned count = [_items count];
+  NSUInteger i;
+  NSUInteger count = [_items count];
 
   for (i = 0; i < count; i++)
     {
@@ -951,8 +951,8 @@
 - (NSInteger) indexOfItemWithTarget: (id)anObject
                    andAction: (SEL)actionSelector
 {
-  unsigned i;
-  unsigned count = [_items count];
+  NSUInteger i;
+  NSUInteger count = [_items count];
 
   for (i = 0; i < count; i++)
     {
@@ -973,7 +973,8 @@
 
 - (NSInteger) indexOfItemWithRepresentedObject: (id)anObject
 {
-  NSInteger i, count = [_items count];
+  NSUInteger i;
+  NSUInteger count = [_items count];
 
   for (i = 0; i < count; i++)
     {
@@ -989,7 +990,8 @@
 
 - (NSInteger) indexOfItemWithSubmenu: (NSMenu *)anObject
 {
-  NSInteger i, count = [_items count];
+  NSUInteger i;
+  NSUInteger count = [_items count];
 
   for (i = 0; i < count; i++)
     {
@@ -1083,15 +1085,40 @@
   return _menu.autoenable;
 }
 
+- (void) _updateSubmenu
+{
+  if ([self isAttached] || [self isTornOff])
+    {
+      // Update the menu items when the menu is visible...
+      [self update];
+    }
+  else
+    {
+      // ...else only progress to submenus
+      NSUInteger i;
+      NSUInteger count = [_items count];
+
+      for (i = 0; i < count; i++)
+        {
+          NSMenuItem *item = [_items objectAtIndex: i];
+          
+          if ([item hasSubmenu])
+            {
+              [[item submenu] _updateSubmenu];
+            }
+        }
+    }
+}
+
 - (void) update
 {
   if (_delegate)
     {
-      if ([_delegate respondsToSelector:@selector(menuNeedsUpdate:)])
-        {
-          [_delegate menuNeedsUpdate:self];
-        }
-      else if ([_delegate respondsToSelector:@selector(numberOfItemsInMenu:)])
+      if ([_delegate respondsToSelector: @selector(menuNeedsUpdate:)])
+        {
+          [_delegate menuNeedsUpdate: self];
+        }
+      else if ([_delegate respondsToSelector: @selector(numberOfItemsInMenu:)])
         {
           NSInteger num;
 
@@ -1133,9 +1160,8 @@
 
   if ([self autoenablesItems])
     {
-      unsigned i, count;
-
-      count = [_items count];  
+      NSUInteger i;
+      NSUInteger count = [_items count];
       
       // Temporary disable automatic displaying of menu.
       [self setMenuChangedMessagesEnabled: NO];
@@ -1150,9 +1176,10 @@
              BOOL            wasEnabled = [item isEnabled];
              BOOL            shouldBeEnabled;
 
-             // Update the submenu items if any.
              if ([item hasSubmenu])
-               [[item submenu] update];
+                {
+                  [[item submenu] _updateSubmenu];
+                }
 
              // If there is no action - there can be no validator for the item.
              if (action)
@@ -1239,12 +1266,12 @@
 //
 - (BOOL) performKeyEquivalent: (NSEvent*)theEvent
 {
-  unsigned      i;
-  unsigned      count = [_items count];
-  NSEventType   type = [theEvent type];
-  unsigned int modifiers = [theEvent modifierFlags];
-  NSString     *keyEquivalent = [theEvent charactersIgnoringModifiers];
-  unsigned int relevantModifiersMask = NSCommandKeyMask | NSAlternateKeyMask | 
NSControlKeyMask;
+  NSUInteger i;
+  NSUInteger count = [_items count];
+  NSEventType type = [theEvent type];
+  NSUInteger modifiers = [theEvent modifierFlags];
+  NSString *keyEquivalent = [theEvent charactersIgnoringModifiers];
+  NSUInteger relevantModifiersMask = NSCommandKeyMask | NSAlternateKeyMask | 
NSControlKeyMask;
   /* Take shift key into account only for control keys and arrow and function 
keys */
   if ((modifiers & NSFunctionKeyMask)
       || ([keyEquivalent length] > 0 && [[NSCharacterSet controlCharacterSet] 
characterIsMember:[keyEquivalent characterAtIndex:0]]))
@@ -1272,7 +1299,6 @@
          // menus so that users don't get confused.
          if ([item submenu] == [NSApp servicesMenu])
            continue;
-         // Recurse through submenus whether active or not.
           // Recurse through submenus whether active or not.
           if ([[item submenu] performKeyEquivalent: theEvent])
             {
@@ -1282,7 +1308,7 @@
         }
       else
         {
-          unsigned int mask = [item keyEquivalentModifierMask];
+          NSUInteger mask = [item keyEquivalentModifierMask];
 
           if ([[item keyEquivalent] isEqualToString: keyEquivalent] 
             && (modifiers & relevantModifiersMask) == (mask & 
relevantModifiersMask))
@@ -1614,7 +1640,8 @@
   NSString     *dName;
   NSArray      *dItems;
   BOOL         dAuto;
-  unsigned     i;
+  NSUInteger i;
+  NSUInteger count;
 
   if ([aDecoder allowsKeyedCoding])
     {
@@ -1658,9 +1685,10 @@
   /*
    * Make sure that items and submenus are set correctly.
    */
-  for (i = 0; i < [dItems count]; i++)
-    {
-      NSMenuItem       *item = [dItems objectAtIndex: i];
+  count = [dItems count];
+  for (i = 0; i < count; i++)
+    {
+      NSMenuItem *item = [dItems objectAtIndex: i];
       [self addItem: item];
     }
   [self setMenuChangedMessagesEnabled: YES];
@@ -1709,8 +1737,8 @@
 - (id) copyWithZone: (NSZone*)zone
 {
   NSMenu *new = [[NSMenu allocWithZone: zone] initWithTitle: _title];
-  unsigned i;
-  unsigned count = [_items count];
+  NSUInteger i;
+  NSUInteger count = [_items count];
 
   [new setAutoenablesItems: _menu.autoenable];
   for (i = 0; i < count; i++)
@@ -1730,7 +1758,7 @@
 
 - (void) setTornOff: (BOOL)flag
 {
-  NSMenu       *supermenu;
+  NSMenu *supermenu;
 
   _menu.is_tornoff = flag; 
 
@@ -1788,7 +1816,7 @@
     {
       [[GSTheme theme] updateAllWindowsWithMenu: [NSApp mainMenu]];
     }
-  [self _showTornOffMenuIfAny:notification];
+  [self _showTornOffMenuIfAny: notification];
 }
 
 - (void) _showOnActivateApp: (NSNotification*)notification


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to