mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 15:31:56 +00:00
Add KVB for menu item and popup button.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25777 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
151e2f87f7
commit
2dee33a74e
3 changed files with 73 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2007-12-23 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/NSMenuItem.m: Add KVB for enable.
|
||||||
|
* Source/NSPopUpButton.m: Add KVB for selectedIndex.
|
||||||
|
|
||||||
2007-12-22 Fred Kiefer <FredKiefer@gmx.de>
|
2007-12-22 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSView.m (-visibleRect:, -setHidden:, -hitTest:): Full
|
* Source/NSView.m (-visibleRect:, -setHidden:, -hitTest:): Full
|
||||||
|
|
|
@ -34,11 +34,13 @@
|
||||||
#include <Foundation/NSDebug.h>
|
#include <Foundation/NSDebug.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
#include <GNUstepBase/GSCategories.h>
|
#include <GNUstepBase/GSCategories.h>
|
||||||
|
#include "AppKit/NSCell.h"
|
||||||
|
#include "AppKit/NSEvent.h"
|
||||||
|
#include "AppKit/NSImage.h"
|
||||||
|
#include "AppKit/NSKeyValueBinding.h"
|
||||||
#include "AppKit/NSMenuItem.h"
|
#include "AppKit/NSMenuItem.h"
|
||||||
#include "AppKit/NSMenu.h"
|
#include "AppKit/NSMenu.h"
|
||||||
#include "AppKit/NSImage.h"
|
#include "GSBindingHelpers.h"
|
||||||
#include "AppKit/NSEvent.h"
|
|
||||||
#include "AppKit/NSCell.h"
|
|
||||||
|
|
||||||
static BOOL usesUserKeyEquivalents = NO;
|
static BOOL usesUserKeyEquivalents = NO;
|
||||||
static Class imageClass;
|
static Class imageClass;
|
||||||
|
@ -76,6 +78,8 @@ static Class imageClass;
|
||||||
{
|
{
|
||||||
[self setVersion: 4];
|
[self setVersion: 4];
|
||||||
imageClass = [NSImage class];
|
imageClass = [NSImage class];
|
||||||
|
|
||||||
|
[self exposeBinding: NSEnabledBinding];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +107,9 @@ static Class imageClass;
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
|
// Remove all key value bindings for this view.
|
||||||
|
[GSKeyValueBinding unbindAllForObject: self];
|
||||||
|
|
||||||
TEST_RELEASE(_title);
|
TEST_RELEASE(_title);
|
||||||
TEST_RELEASE(_keyEquivalent);
|
TEST_RELEASE(_keyEquivalent);
|
||||||
TEST_RELEASE(_image);
|
TEST_RELEASE(_image);
|
||||||
|
@ -648,6 +655,30 @@ static Class imageClass;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) bind: (NSString *)binding
|
||||||
|
toObject: (id)anObject
|
||||||
|
withKeyPath: (NSString *)keyPath
|
||||||
|
options: (NSDictionary *)options
|
||||||
|
{
|
||||||
|
if ([binding hasPrefix: NSEnabledBinding])
|
||||||
|
{
|
||||||
|
[self unbind: binding];
|
||||||
|
[[GSKeyValueAndBinding alloc] initWithBinding: NSEnabledBinding
|
||||||
|
withName: binding
|
||||||
|
toObject: anObject
|
||||||
|
withKeyPath: keyPath
|
||||||
|
options: options
|
||||||
|
fromObject: self];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[super bind: binding
|
||||||
|
toObject: anObject
|
||||||
|
withKeyPath: keyPath
|
||||||
|
options: options];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSMenuItem (GNUstepExtra)
|
@implementation NSMenuItem (GNUstepExtra)
|
||||||
|
|
|
@ -29,8 +29,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
|
#include <Foundation/NSKeyValueObserving.h>
|
||||||
#include "AppKit/NSApplication.h"
|
#include "AppKit/NSApplication.h"
|
||||||
#include "AppKit/NSEvent.h"
|
#include "AppKit/NSEvent.h"
|
||||||
|
#include "AppKit/NSKeyValueBinding.h"
|
||||||
#include "AppKit/NSPopUpButton.h"
|
#include "AppKit/NSPopUpButton.h"
|
||||||
#include "AppKit/NSPopUpButtonCell.h"
|
#include "AppKit/NSPopUpButtonCell.h"
|
||||||
#include "AppKit/NSMenu.h"
|
#include "AppKit/NSMenu.h"
|
||||||
|
@ -58,6 +60,8 @@ Class _nspopupbuttonCellClass = 0;
|
||||||
// Initial version
|
// Initial version
|
||||||
[self setVersion: 1];
|
[self setVersion: 1];
|
||||||
[self setCellClass: [NSPopUpButtonCell class]];
|
[self setCellClass: [NSPopUpButtonCell class]];
|
||||||
|
|
||||||
|
[self exposeBinding: NSSelectedIndexBinding];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +253,9 @@ this to return nil to indicate that we have no context menu.
|
||||||
|
|
||||||
- (void) selectItem: (id <NSMenuItem>)anObject
|
- (void) selectItem: (id <NSMenuItem>)anObject
|
||||||
{
|
{
|
||||||
|
[self willChangeValueForKey: NSSelectedIndexBinding];
|
||||||
[_cell selectItem: anObject];
|
[_cell selectItem: anObject];
|
||||||
|
[self didChangeValueForKey: NSSelectedIndexBinding];
|
||||||
[self synchronizeTitleAndSelectedItem];
|
[self synchronizeTitleAndSelectedItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +265,9 @@ this to return nil to indicate that we have no context menu.
|
||||||
*/
|
*/
|
||||||
- (void) selectItemAtIndex: (int)index
|
- (void) selectItemAtIndex: (int)index
|
||||||
{
|
{
|
||||||
|
[self willChangeValueForKey: NSSelectedIndexBinding];
|
||||||
[_cell selectItemAtIndex: index];
|
[_cell selectItemAtIndex: index];
|
||||||
|
[self didChangeValueForKey: NSSelectedIndexBinding];
|
||||||
[self synchronizeTitleAndSelectedItem];
|
[self synchronizeTitleAndSelectedItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +278,9 @@ this to return nil to indicate that we have no context menu.
|
||||||
*/
|
*/
|
||||||
- (void) selectItemWithTitle: (NSString*)title
|
- (void) selectItemWithTitle: (NSString*)title
|
||||||
{
|
{
|
||||||
|
[self willChangeValueForKey: NSSelectedIndexBinding];
|
||||||
[_cell selectItemWithTitle: title];
|
[_cell selectItemWithTitle: title];
|
||||||
|
[self didChangeValueForKey: NSSelectedIndexBinding];
|
||||||
[self synchronizeTitleAndSelectedItem];
|
[self synchronizeTitleAndSelectedItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,4 +527,28 @@ this to return nil to indicate that we have no context menu.
|
||||||
[super keyDown: theEvent];
|
[super keyDown: theEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) setValue: (id)anObject forKey: (NSString*)aKey
|
||||||
|
{
|
||||||
|
if ([aKey isEqual: NSSelectedIndexBinding])
|
||||||
|
{
|
||||||
|
[self selectItemAtIndex: [anObject intValue]];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[super setValue: anObject forKey: aKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) valueForKey: (NSString*)aKey
|
||||||
|
{
|
||||||
|
if ([aKey isEqual: NSSelectedIndexBinding])
|
||||||
|
{
|
||||||
|
return [NSNumber numberWithInt: [self indexOfSelectedItem]];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return [super valueForKey: aKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue