NSMenuView patch

2011-02-17 Thread Christopher Armstrong

I've reposted this here because I don't believe patches show up on the mailing 
lists. 

I've attached a patch at savannah that fixes some outside mouse behaviour 
issues with Mac and Windows style menus. Specifically:

* Clicking outside the attached menu window to close it doesn't close the menu
* Moving the mouse outside the menu in Windows mode closes the menu
* Attached sub-menus in Windows mode stay open until another top-level menu is 
selected, instead of disappearing when the mouse is moved outside the attached 
sub-menu

https://savannah.gnu.org/patch/?7470

Cheers

Christopher Armstrong
carmstr...@fastmail.com.au
--

Index: Source/NSMenuView.m
===
--- Source/NSMenuView.m (revision 32140)
+++ Source/NSMenuView.m (working copy)
@@ -1439,7 +1439,6 @@
   int delayCount = 0;
   int indexOfActionToExecute = -1;
   int firstIndex = -1;
-  int space = 0;
   NSEvent *original;
   NSEventType type;
   NSEventType end;
@@ -1487,7 +1486,6 @@
   eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask;
   eventMask |= NSLeftMouseDownMask;
 }
-
   /* We attempt to mimic Mac OS X behavior for pop up menus. If the user
  presses the mouse button over a pop up button and then drags the mouse
  over the menu, the is closed when the user releases the mouse. On the
@@ -1503,6 +1501,11 @@
*/
   shouldFinish = NO;
 }
+  
+  // Capture the mouse so we get clicks outside the menus and
+  // GNUstep windows.
+  [_window _captureMouse: self];
+
   do
 {
   /*Close the menu if the user press a modifier key and menu
@@ -1512,6 +1515,7 @@
{
  [self setHighlightedItemIndex: -1];
  NSApp mainWindow] menu] attachedMenu] close];
+ [_window _releaseMouse: self];
  return NO;
}
 
@@ -1585,7 +1589,6 @@
   NSPoint locationInScreenCoordinates;
   NSWindow *windowUnderMouse;
   NSMenu *candidateMenu;
- NSMenu *anAttachedMenu = [[[NSApp mainWindow] menu] attachedMenu];
 
   subMenusNeedRemoving = NO;
 
@@ -1631,6 +1634,7 @@
   
   candidateMenuResult = [[candidateMenu menuRepresentation]
trackWithEvent: original];
+  [_window _releaseMouse: self];
   return candidateMenuResult;
 }
 
@@ -1650,6 +1654,7 @@
 {
   [self detachSubmenu];
 }
+  [_window _releaseMouse: self];
   return subMenuResult;
 }
  
@@ -1660,23 +1665,16 @@
  ![[self menu] isTransient] &&
  ![[self menu] _ownedByPopUp])
{
- if ([self hitTest: location] == nil)
+  // If the user moves the mouse into the main window
+  // horizontal menu, start tracking again.
+  NSWindow *mainWindow = [NSApp mainWindow];
+  NSPoint locationInMainWindow = [mainWindow 
+convertScreenToBase: locationInScreenCoordinates];
+ if ([[[mainWindow menu] menuRepresentation] 
+hitTest: locationInMainWindow] != nil)
{
- /*This gives us time to move the cursor between a menu and
-   its submenu (or vice versa) without lose the mouse
-   tracking*/
- space += 1;
-
- if (space == 2)
-   {
- [anAttachedMenu close];
- return NO;
-   }
-   }
- 
- if (self != [[[NSApp mainWindow] menu] menuRepresentation])
-   {
  [self setHighlightedItemIndex: -1];
+ [_window _releaseMouse: self];
  return NSApp mainWindow] menu] menuRepresentation]
   trackWithEvent: original];
}
@@ -1711,6 +1709,9 @@
 }
   while (type != end || shouldFinish == NO);
 
+  // Uncapture the mouse again.
+  [_window _releaseMouse: self];
+
   /*
* Ok, we released the mouse
* There are now a few possibilities:


___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: GNUstep Make not adding -fblocks

2011-02-17 Thread David Chisnall
On 16 Feb 2011, at 14:57, Richard Frith-Macdonald wrote:

> I can't see that in my email archive ... mybe I accidentally deleted it, or 
> perhaps it was a private email to Nicola.

I thought I sent a mail to Nicola, but looking at my mail history I actually 
just made a note to myself to mail Nicola when I'd done some testing, which 
would explain why neither you nor he received it.

>> It seems that the configure script is testing whether exceptions work, then 
>> deciding that, even though they do, it won't let you use them because it 
>> doesn't like the version of GCC that you have.
> 
> That may well be the case ... because we don't just need to check that we can 
> throw/catch exceptions, we also need to check that we can set a handler for 
> uncaught exceptions, and it may well have been a lot easier to just test for 
> the version of gcc which added support for that to the runtime than to check 
> to see what really happens.
> 
> So, a good test for exception support would check both that the compiler 
> generates exception code and that the runtime supports setting a handler for 
> uncaught exceptions (and that both actually work).
> I seem to remember hacking some sort of test into the base config scripts, 
> but I don't recall whether it was actually what I'd call a good one.

The test seems to be rejecting GCC 4.2: I've not had any problems with native 
exceptions in any of the 4.x series - including the pop-up when apps throw an 
exception that isn't caught - and I think this was also working fine in the 3.x 
series when I was using that, but it's been a few years...

We also check for the availability of the uncaught exception handler in a 
separate test, so it would make sense to just disable native exceptions if this 
doesn't work.

David
___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


NSNumber Bug I can't fix

2011-02-17 Thread Marcus Müller
Hi,

I just stumbled across a bug in NSNumber that I can't fix as I don't understand 
the NSNumber code. The problem is easy to see, though:

#import 

int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSNumber *n   = [NSNumber numberWithInt:2];
NSNumber *nan = [NSDecimalNumber notANumber];

NSLog(@"%@ (class:%@ double:%g) == %@ -> %s",
  n, NSStringFromClass([n class]), [n doubleValue],
  nan, [n isEqualToNumber:nan] ? "YES" : "NO");

[pool release];
return 0;
}

On FreeBSD-8.2rc3 (amd64) this produces the following output:
2011-02-17 16:02:15.316 NumberTest[59574] 2 (class:NSIntNumber double:2) == NaN 
-> YES
Which is clearly wrong.

I came across this issue via NSNumberFormatter, which instead of formatting any 
integer numbers always printed NaN. In my project  I tried to debug into the 
issue and found this:
769   if ([anObject isEqual: [NSDecimalNumber notANumber]])
(gdb) s
-[NSNumber isEqual:] (self=0x803e8d1d0, _cmd=0x801410980, anObject=0x805e625c0)
at NSNumber.m:376
376   if ([anObject isKindOfClass: NSNumberClass])
(gdb) n
378   return [self isEqualToNumber: anObject];
(gdb) po anObject
NaN
(gdb) po [anObject class]
NSDecimalNumber
(gdb) s
-[NSNumber isEqualToNumber:] (self=0x803e8d1d0, _cmd=0x80140d300, 
aNumber=0x805e625c0) at NSNumber.m:371
371   return ([self compare: aNumber] == NSOrderedSame) ? YES : NO;
(gdb) s
-[NSSignedIntegerNumber compare:] (self=0x803e8d1d0, _cmd=0x80140d2e0, 
aNumber=0x805e625c0) at NSNumber.m:107
107   if (aNumber == self)
[…]
(gdb) n
165   double value = [self doubleValue];
(gdb) p other
$3 = nan(0x8)
(gdb) p value
$4 = 6.9533556002420585e-310

As you can see above, asking an NSIntNumber instance for its doubleValue works 
properly, however, it fails at NSNumber.m:165. I don't know the reason, but I 
also don't understand the implications of the macros used. Can somebody 
elaborate? Please note that I'm on a 64-bit (amd64) system.

Thanks,

  Marcus

-- 
Marcus Mueller  .  .  .  crack-admin/coder ;-)
Mulle kybernetiK  .  http://www.mulle-kybernetik.com
Current projects: http://www.mulle-kybernetik.com/znek/




smime.p7s
Description: S/MIME cryptographic signature
___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: NSNumber Bug I can't fix

2011-02-17 Thread Marcus Müller

> As you can see above, asking an NSIntNumber instance for its doubleValue 
> works properly, however, it fails at NSNumber.m:165. I don't know the reason, 
> but I also don't understand the implications of the macros used. Can somebody 
> elaborate? Please note that I'm on a 64-bit (amd64) system.

Thinking about it, I guess my hint was pretty bogus. I believe the real problem 
here is the COMPARE macro which compares a double with a NaN, which simply 
won't work:

#define COMPARE(value, other) \
if (value < other)\
  {\
return NSOrderedAscending;\
  }\
if (value > other)\
  {\
return NSOrderedDescending;\
  }\
return NSOrderedSame;

If either is a nan, this will return NSOrderedSame which is, well, not 
incorrect. However, in the context of NSNumber.m:165 it returns a wrong result.

This raises the question, what should be done to - (NSComparisonResult) 
compare: (NSNumber*)aNumber?
Comparing a NaN with another number is undefined and might lead to 
NSOrderedSame, but it should never lead to [2 isEqualToNumber:NaN] == YES. I'm 
not sure how to fix this properly, but not returning NSOrderedSame in this case 
would certainly help.

Cheers,

  Marcus

-- 
Marcus Mueller  .  .  .  crack-admin/coder ;-)
Mulle kybernetiK  .  http://www.mulle-kybernetik.com
Current projects: http://www.mulle-kybernetik.com/znek/




smime.p7s
Description: S/MIME cryptographic signature
___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: NSNumber Bug I can't fix

2011-02-17 Thread Jens Ayton
For reference, under Mac OS X 10.6.6:

2 compare: nan = NSOrderedDescending
nan compare: 2 = NSOrderedAscending
nan compare: nan = NSOrderedSame
2 isEqual: nan = NO
nan isEqual: n = NO
nan isEqual: nan = YES

Just for fun, I tried it with [NSNumber numberWithDouble:INFINITY] instead of 2:

inf compare: nan = NSOrderedDescending
nan compare: inf = NSOrderedAscending
-inf compare: nan = NSOrderedAscending
nan compare: -inf = NSOrderedDescending

-- 
Jens Ayton


___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: NSNumber Bug I can't fix

2011-02-17 Thread Richard Frith-Macdonald

On 17 Feb 2011, at 16:01, Marcus Müller wrote:

> 
>> As you can see above, asking an NSIntNumber instance for its doubleValue 
>> works properly, however, it fails at NSNumber.m:165. I don't know the 
>> reason, but I also don't understand the implications of the macros used. Can 
>> somebody elaborate? Please note that I'm on a 64-bit (amd64) system.
> 
> Thinking about it, I guess my hint was pretty bogus. I believe the real 
> problem here is the COMPARE macro which compares a double with a NaN, which 
> simply won't work:
> 
> #define COMPARE(value, other) \
> if (value < other)\
>   {\
> return NSOrderedAscending;\
>   }\
> if (value > other)\
>   {\
> return NSOrderedDescending;\
>   }\
> return NSOrderedSame;
> 
> If either is a nan, this will return NSOrderedSame which is, well, not 
> incorrect. However, in the context of NSNumber.m:165 it returns a wrong 
> result.
> 
> This raises the question, what should be done to - (NSComparisonResult) 
> compare: (NSNumber*)aNumber?
> Comparing a NaN with another number is undefined and might lead to 
> NSOrderedSame, but it should never lead to [2 isEqualToNumber:NaN] == YES. 
> I'm not sure how to fix this properly, but not returning NSOrderedSame in 
> this case would certainly help.

Thanks, I added a quick hack to try to fix this and put a few very simple tests 
in svn://svn.gna.org/svn/gnustep/libs/base/trunk/Tests/base/NSNumber/test01.m


___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: NSMenuView patch

2011-02-17 Thread Germán Arias
Well, definitely this behavior is better. But there are some problems:

* You need do three clicks on title bar to get a response (minimize,
close,...) when a submenu is displayed.

* If a submenu is displayed, and you do a click at horizontal bar in a
place where there isn't an item, after some second the app crash.


On jue, 2011-02-17 at 22:39 +1100, Christopher Armstrong wrote:
> I've reposted this here because I don't believe patches show up on the 
> mailing lists. 
> 
> I've attached a patch at savannah that fixes some outside mouse behaviour 
> issues with Mac and Windows style menus. Specifically:
> 
> * Clicking outside the attached menu window to close it doesn't close the menu
> * Moving the mouse outside the menu in Windows mode closes the menu
> * Attached sub-menus in Windows mode stay open until another top-level menu 
> is selected, instead of disappearing when the mouse is moved outside the 
> attached sub-menu
> 
> https://savannah.gnu.org/patch/?7470
> 
> Cheers
> 
> Christopher Armstrong
> carmstr...@fastmail.com.au
> --
> 
> Index: Source/NSMenuView.m
> ===
> --- Source/NSMenuView.m   (revision 32140)
> +++ Source/NSMenuView.m   (working copy)
> @@ -1439,7 +1439,6 @@
>int delayCount = 0;
>int indexOfActionToExecute = -1;
>int firstIndex = -1;
> -  int space = 0;
>NSEvent *original;
>NSEventType type;
>NSEventType end;
> @@ -1487,7 +1486,6 @@
>eventMask |= NSLeftMouseUpMask | NSLeftMouseDraggedMask;
>eventMask |= NSLeftMouseDownMask;
>  }
> -
>/* We attempt to mimic Mac OS X behavior for pop up menus. If the user
>   presses the mouse button over a pop up button and then drags the mouse
>   over the menu, the is closed when the user releases the mouse. On the
> @@ -1503,6 +1501,11 @@
> */
>shouldFinish = NO;
>  }
> +  
> +  // Capture the mouse so we get clicks outside the menus and
> +  // GNUstep windows.
> +  [_window _captureMouse: self];
> +
>do
>  {
>/*Close the menu if the user press a modifier key and menu
> @@ -1512,6 +1515,7 @@
>   {
> [self setHighlightedItemIndex: -1];
> NSApp mainWindow] menu] attachedMenu] close];
> +   [_window _releaseMouse: self];
> return NO;
>   }
>  
> @@ -1585,7 +1589,6 @@
>NSPoint locationInScreenCoordinates;
>NSWindow *windowUnderMouse;
>NSMenu *candidateMenu;
> -   NSMenu *anAttachedMenu = [[[NSApp mainWindow] menu] attachedMenu];
>  
>subMenusNeedRemoving = NO;
>  
> @@ -1631,6 +1634,7 @@
>
>candidateMenuResult = [[candidateMenu menuRepresentation]
> trackWithEvent: original];
> +  [_window _releaseMouse: self];
>return candidateMenuResult;
>  }
>  
> @@ -1650,6 +1654,7 @@
>  {
>[self detachSubmenu];
>  }
> +  [_window _releaseMouse: self];
>return subMenuResult;
>  }
> 
> @@ -1660,23 +1665,16 @@
> ![[self menu] isTransient] &&
> ![[self menu] _ownedByPopUp])
>   {
> -   if ([self hitTest: location] == nil)
> +  // If the user moves the mouse into the main window
> +  // horizontal menu, start tracking again.
> +  NSWindow *mainWindow = [NSApp mainWindow];
> +  NSPoint locationInMainWindow = [mainWindow 
> +convertScreenToBase: locationInScreenCoordinates];
> +   if ([[[mainWindow menu] menuRepresentation] 
> +hitTest: locationInMainWindow] != nil)
>   {
> -   /*This gives us time to move the cursor between a menu and
> - its submenu (or vice versa) without lose the mouse
> - tracking*/
> -   space += 1;
> -
> -   if (space == 2)
> - {
> -   [anAttachedMenu close];
> -   return NO;
> - }
> - }
> -   
> -   if (self != [[[NSApp mainWindow] menu] menuRepresentation])
> - {
> [self setHighlightedItemIndex: -1];
> +   [_window _releaseMouse: self];
> return NSApp mainWindow] menu] menuRepresentation]
>  trackWithEvent: original];
>   }
> @@ -1711,6 +1709,9 @@
>  }
>while (type != end || shouldFinish == NO);
>  
> +  // Uncapture the mouse again.
> +  [_window _releaseMouse: self];
> +
>/*
> * Ok, we released the mouse
> * There are now a few possibilities:
> 
> 
> _