gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnustep-cvs] r33837 - in /libs/gui/trunk: ChangeLog Source/GSThemeM


From: Germán Arias
Subject: Re: [Gnustep-cvs] r33837 - in /libs/gui/trunk: ChangeLog Source/GSThemeMenu.m
Date: Wed, 21 Sep 2011 11:35:00 -0600

On mar, 2011-09-20 at 22:50 +0200, Fred Kiefer wrote: 
> On 20.09.2011 19:27, Germán Arias wrote:
> > This works with the exception that the horizontal menu don't track the
> > mouse when the user return from a submenu. This is because now we cant
> > access the menu representation with [menu menuRepresentation]. So for
> 
> Yes, that was the problem I was refering to in my mail.
> 
> > the moment, I have something like this at line 1687 in NSMenuView.m:
> >
> >                    NSEnumerator *e = [[[mainWindow _windowView] subviews]
> >                                   objectEnumerator];
> >               NSView *v;
> >                    NSMenuView *mainWindowMenuView;
> >
> >               while ((v = [e nextObject]) != nil)
> >                 {
> >                   if ([v isKindOfClass: [NSMenuView class]] == YES)
> >                     {
> >                       mainWindowMenuView = v;
> >                       break;
> >                     }
> >                 }
> >
> > But I think maybe is better add the _menuView variable in NSWindow (no
> > retained) and methods -menuView and -setMenuView. So we can access
> > easily the menu representation.
> 
> I would rather like to add a method -menuView to the 
> GSWindowDecorationView, which is a GNUstep private class. We should not 
> mess around too much with official classes.
> 
> In this specific case it may even be better to rearrange the code a bit. 
> Are we expecting for this code to work between different windows? I 
> don't think so. So why not pass on the original menu view when calling 
> _trackWithEvent:, just as we do with the event?

Are you referring to the menu view of the original main menu? But this
menu isn't displayed.

> And even another step better would be to completely rewrite this method 
> to get rid of all these calls to the [menu window] and the like...


Well, now I have these changes in my copy. 


Index: Source/GSWindowDecorationView.m
===================================================================
--- Source/GSWindowDecorationView.m     (revision 33873)
+++ Source/GSWindowDecorationView.m     (working copy)
@@ -152,6 +152,7 @@
     {
       hasToolbar = NO;
       hasMenu = NO;
+      _menuView = nil;
       window = w;
       // Content rect will be everything apart from the border
       // that is including menu, toolbar and the like.
@@ -453,6 +454,11 @@
   NSAssert(NO, @"The top-level window view should never be encoded.");
 }
 
+- (NSMenuView *) menuView
+{
+  return _menuView;
+}
+
 @end
 
 @implementation GSWindowDecorationView (ToolbarPrivate)
@@ -533,6 +539,7 @@
   hasMenu = YES;
   // Plug the menu view
   [menuView setFrame: menuRect];
+  _menuView = menuView;
   [self addSubview: menuView];
 
   [self changeWindowHeight: menubarHeight];  
@@ -556,6 +563,7 @@
 
          hasMenu = NO;
          [RETAIN(v) removeFromSuperviewWithoutNeedingDisplay];
+         _menuView = nil;
          
          [self changeWindowHeight: -(menubarHeight)];  
          return AUTORELEASE(v);
Index: Source/NSMenuView.m
===================================================================
--- Source/NSMenuView.m (revision 33873)
+++ Source/NSMenuView.m (working copy)
@@ -53,6 +53,7 @@
 
 #import "GNUstepGUI/GSTheme.h"
 #import "GNUstepGUI/GSTitleView.h"
+#import "GNUstepGUI/GSWindowDecorationView.h"
 
 
 typedef struct _GSCellRect {
@@ -97,6 +98,17 @@
 }
 @end
 
address@hidden NSWindow (GSTheme)
+- (GSWindowDecorationView *) windowView;
address@hidden
+
address@hidden NSWindow (GSTheme)
+- (GSWindowDecorationView *) windowView
+{
+  return _wv;
+}
address@hidden
+
 @interface NSMenuView (Private)
 - (BOOL) _rootIsHorizontal: (BOOL*)isAppMenu;
 @end
@@ -1683,23 +1695,27 @@
                {
                   // If the user moves the mouse into the main window
                   // horizontal menu, start tracking again.
-                  NSWindow *mainWindow = [NSApp mainWindow];
-                  NSMenuView *mainWindowMenuView = [[mainWindow menu]
-                    menuRepresentation];
-                  NSPoint locationInMainWindow = [mainWindow 
-                    convertScreenToBase: locationInScreenCoordinates];
-                 if ([mainWindowMenuView 
+                 NSWindow *mainWindow;
+                 NSMenuView *windowMenuView;
+                 NSPoint locationInMainWindow;
+
+                  mainWindow = [NSApp mainWindow];
+                 windowMenuView = [[mainWindow windowView] menuView];
+                 locationInMainWindow = [mainWindow
+                  convertScreenToBase: locationInScreenCoordinates];
+
+                 if ([windowMenuView 
                         hitTest: locationInMainWindow] != nil)
                    {
-                      int index = [mainWindowMenuView
indexOfItemAtPoint: 
-                        [mainWindowMenuView 
+                      int index = [windowMenuView indexOfItemAtPoint: 
+                        [windowMenuView 
                           convertPoint: locationInMainWindow
                               fromView: nil]];
                       if (index != -1 &&
-                          index != [mainWindowMenuView
highlightedItemIndex])
+                          index != [windowMenuView
highlightedItemIndex])
                         {
                          [self setHighlightedItemIndex: -1];
-                         return [mainWindowMenuView
+                         return [windowMenuView
                               _trackWithEvent: original];
                         }
                    }
Index: Headers/Additions/GNUstepGUI/GSWindowDecorationView.h
===================================================================
--- Headers/Additions/GNUstepGUI/GSWindowDecorationView.h       (revision
33873)
+++ Headers/Additions/GNUstepGUI/GSWindowDecorationView.h       (working copy)
@@ -31,6 +31,7 @@
 #import <AppKit/NSView.h>
 
 @class NSWindow;
address@hidden NSMenuView;
 
 // These are implemented as class methods on GSWindowDecorationView
 @protocol GSWindowDecorator
@@ -59,6 +60,7 @@
   BOOL documentEdited;
   BOOL hasMenu;
   BOOL hasToolbar;
+  NSMenuView *_menuView;
 }
 + (id<GSWindowDecorator>) windowDecorator;
 
@@ -89,6 +91,7 @@
 - (void) setHasToolbar: (BOOL) flag;
 - (BOOL) hasMenu;
 - (BOOL) hasToolbar;
+- (NSMenuView *) menuView;
 @end
 
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]