mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-04-22 22:20:44 +00:00
* Palettes/2Controls/GormNSPopUpButton.h
* Palettes/2Controls/GormNSPopUpButton.m: Added new files for Gorm subclass of NSPopUpButton. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@35095 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0f780c7001
commit
4b3e74e68e
3 changed files with 153 additions and 0 deletions
|
@ -1,3 +1,9 @@
|
|||
2012-04-20 12:16-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* Palettes/2Controls/GormNSPopUpButton.h
|
||||
* Palettes/2Controls/GormNSPopUpButton.m: Added new files for
|
||||
Gorm subclass of NSPopUpButton.
|
||||
|
||||
2012-04-20 12:03-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||
|
||||
* GormCore/GormCustomView.m
|
||||
|
|
18
Palettes/2Controls/GormNSPopUpButton.h
Normal file
18
Palettes/2Controls/GormNSPopUpButton.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include <AppKit/AppKit.h>
|
||||
|
||||
#ifndef INCLUDED_GormNSPopUpButton_h
|
||||
#define INCLUDED_GormNSPopUpButton_h
|
||||
|
||||
@interface GormNSPopUpButton : NSPopUpButton
|
||||
@end
|
||||
|
||||
@interface GormNSPopUpButtonCell : NSPopUpButtonCell
|
||||
{
|
||||
}
|
||||
@end
|
||||
|
||||
@interface NSPopUpButtonCell (DirtyHack)
|
||||
- (id) _gormInitTextCell: (NSString *) string;
|
||||
@end
|
||||
|
||||
#endif
|
129
Palettes/2Controls/GormNSPopUpButton.m
Normal file
129
Palettes/2Controls/GormNSPopUpButton.m
Normal file
|
@ -0,0 +1,129 @@
|
|||
#include <GormCore/GormPrivate.h>
|
||||
#include "GormNSPopUpButton.h"
|
||||
|
||||
Class _gormnspopupbuttonCellClass = 0;
|
||||
|
||||
@implementation GormNSPopUpButton
|
||||
/*
|
||||
* Class methods
|
||||
*/
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [GormNSPopUpButton class])
|
||||
{
|
||||
// Initial version
|
||||
[self setVersion: 1];
|
||||
[self setCellClass: [GormNSPopUpButtonCell class]];
|
||||
}
|
||||
}
|
||||
|
||||
+ (Class) cellClass
|
||||
{
|
||||
return _gormnspopupbuttonCellClass;
|
||||
}
|
||||
|
||||
+ (void) setCellClass: (Class)classId
|
||||
{
|
||||
_gormnspopupbuttonCellClass = classId;
|
||||
}
|
||||
|
||||
- (NSString*) editorClassName
|
||||
{
|
||||
return @"GormPopUpButtonEditor";
|
||||
}
|
||||
|
||||
- (NSString *) className
|
||||
{
|
||||
return @"NSPopUpButton";
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSPopUpButtonCell (DirtyHack)
|
||||
- (id) _gormInitTextCell: (NSString *) string
|
||||
{
|
||||
return [super initTextCell: string];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GormNSPopUpButtonCell
|
||||
|
||||
/* Overriden helper method */
|
||||
- (void) _initMenu
|
||||
{
|
||||
NSMenu *menu = [[NSMenu allocSubstitute] initWithTitle: @""];
|
||||
[self setMenu: menu];
|
||||
RELEASE(menu);
|
||||
}
|
||||
|
||||
- (NSString *) className
|
||||
{
|
||||
return @"NSPopUpButtonCell";
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this here, since themes may override it.
|
||||
* Always want to show the menu view since it's editable.
|
||||
*/
|
||||
- (void) attachPopUpWithFrame: (NSRect)cellFrame
|
||||
inView: (NSView *)controlView
|
||||
{
|
||||
NSRectEdge preferredEdge = _pbcFlags.preferredEdge;
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
NSWindow *cvWin = [controlView window];
|
||||
NSMenuView *mr = [[self menu] menuRepresentation];
|
||||
int selectedItem;
|
||||
|
||||
[nc postNotificationName: NSPopUpButtonCellWillPopUpNotification
|
||||
object: self];
|
||||
|
||||
[nc postNotificationName: NSPopUpButtonWillPopUpNotification
|
||||
object: controlView];
|
||||
|
||||
// Convert to Screen Coordinates
|
||||
cellFrame = [controlView convertRect: cellFrame toView: nil];
|
||||
cellFrame.origin = [cvWin convertBaseToScreen: cellFrame.origin];
|
||||
|
||||
if (_pbcFlags.pullsDown)
|
||||
selectedItem = -1;
|
||||
else
|
||||
{
|
||||
selectedItem = [self indexOfSelectedItem];
|
||||
if (selectedItem == -1) // Test
|
||||
selectedItem = 0;
|
||||
}
|
||||
|
||||
if (selectedItem > 0)
|
||||
{
|
||||
[mr setHighlightedItemIndex: selectedItem];
|
||||
}
|
||||
|
||||
if ([controlView isFlipped])
|
||||
{
|
||||
if (preferredEdge == NSMinYEdge)
|
||||
{
|
||||
preferredEdge = NSMaxYEdge;
|
||||
}
|
||||
else if (preferredEdge == NSMaxYEdge)
|
||||
{
|
||||
preferredEdge = NSMinYEdge;
|
||||
}
|
||||
}
|
||||
|
||||
// Ask the MenuView to attach the menu to this rect
|
||||
[mr setWindowFrameForAttachingToRect: cellFrame
|
||||
onScreen: [cvWin screen]
|
||||
preferredEdge: preferredEdge
|
||||
popUpSelectedItem: selectedItem];
|
||||
|
||||
// Set to be above the main window
|
||||
[cvWin addChildWindow: [mr window] ordered: NSWindowAbove];
|
||||
|
||||
// Last, display the window
|
||||
[[mr window] orderFrontRegardless];
|
||||
|
||||
[nc addObserver: self
|
||||
selector: @selector(_handleNotification:)
|
||||
name: NSMenuDidSendActionNotification
|
||||
object: _menu];
|
||||
}
|
||||
@end
|
Loading…
Reference in a new issue