From 6590fa6a1f3cb02ee59409497a9af72477ea3985 Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Sat, 17 Aug 2013 13:39:16 +0000 Subject: [PATCH] Add code by Nikolaus Schaller , reformatted and simplified. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@36982 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 20 +++- Headers/AppKit/AppKit.h | 1 + Headers/AppKit/NSStatusBar.h | 57 +++++++++++ Headers/AppKit/NSStatusItem.h | 53 ++++++++++ Source/GNUmakefile | 2 + Source/NSStatusBar.m | 87 ++++++++++++++++ Source/NSStatusItem.m | 182 ++++++++++++++++++++++++++++++++++ 7 files changed, 397 insertions(+), 5 deletions(-) create mode 100644 Headers/AppKit/NSStatusBar.h create mode 100644 Source/NSStatusBar.m diff --git a/ChangeLog b/ChangeLog index 3d1512b68..357b49a29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2013-08-17 Fred Kiefer + + * Headers/AppKit/NSStatusBar.h, + * Source/NSStatusBar.m: Add new class implementation. + * Headers/AppKit/AppKit.h: Add new header for NSStatusBar.h + * Source/GNUmakefile: Add new class. + * Headers/AppKit/NSStatusItem.h, + * Source/NSStatusItem.m: + Add fill in code by Nikolaus Schaller . + 2013-08-12 Lubos Dolezel * Headers/AppKit/NSSavePanel.h, @@ -13,12 +23,12 @@ 2013-07-22 Quentin Mathe - * Source/NSImage.m (+_pathForImageNamed:, +_pathForSystemImageNamed:type:, - +_pathForThemeImageNamed:type:, +_resourceNameForImageNamed:type:): - Fixed missing theme images if not listed in the theme bundle Info.plist. - Theme bundles that contain theme images named using either GNUstep or + * Source/NSImage.m (+_pathForImageNamed:, +_pathForSystemImageNamed:type:, + +_pathForThemeImageNamed:type:, +_resourceNameForImageNamed:type:): + Fixed missing theme images if not listed in the theme bundle Info.plist. + Theme bundles that contain theme images named using either GNUstep or OPENSTEP names now work properly again (bug introduced in r36836). - Finished to clean and reduce duplication in the image searching code + Finished to clean and reduce duplication in the image searching code related to -_pathForImageNamed:. * Images/nsmapping.strings: Updated documentation. diff --git a/Headers/AppKit/AppKit.h b/Headers/AppKit/AppKit.h index 55098b86c..ddaf9bbb2 100644 --- a/Headers/AppKit/AppKit.h +++ b/Headers/AppKit/AppKit.h @@ -111,6 +111,7 @@ #import #import #import +#import #import #import #import diff --git a/Headers/AppKit/NSStatusBar.h b/Headers/AppKit/NSStatusBar.h new file mode 100644 index 000000000..3ed3a15dd --- /dev/null +++ b/Headers/AppKit/NSStatusBar.h @@ -0,0 +1,57 @@ +/* + NSStatusBar.h + + The status bar class + + Copyright (C) 2013 Free Software Foundation, Inc. + + Author: Dr. H. Nikolaus Schaller + Date: 2013 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef _GNUstep_H_NSStatusBar +#define _GNUstep_H_NSStatusBar + +#import + +@class NSStatusItem; + +@interface NSStatusBar : NSObject +{ + @private + NSMutableArray *_items; +} + +#ifndef NSSquareStatusItemLength +// length == thickness +#define NSSquareStatusItemLength ((CGFloat) -2.0) +// variable +#define NSVariableStatusItemLength ((CGFloat) -1.0) +#endif + ++ (NSStatusBar*) systemStatusBar; + +- (BOOL) isVertical; +- (void) removeStatusItem: (NSStatusItem*)item; +- (NSStatusItem*) statusItemWithLength: (CGFloat)length; +- (CGFloat) thickness; + +@end +#endif // _GNUstep_H_NSStatusBar diff --git a/Headers/AppKit/NSStatusItem.h b/Headers/AppKit/NSStatusItem.h index de5cc113e..25c846364 100644 --- a/Headers/AppKit/NSStatusItem.h +++ b/Headers/AppKit/NSStatusItem.h @@ -33,9 +33,62 @@ #ifndef _GNUstep_H_NSStatusItem #define _GNUstep_H_NSStatusItem +#import #import +#import + +@class NSAttributedString; +@class NSString; +@class NSStatusBar; +@class NSView; +@class NSImage; +@class NSMenu; +@class NSMenuItem; @interface NSStatusItem : NSObject +{ + @private + NSMenuItem *_menuItem; + NSStatusBar *_statusBar; + NSView *_view; + CGFloat _length; + BOOL _highlightMode; +} + +- (SEL) action; +- (NSAttributedString*) attributedTitle; +- (SEL) doubleAction; +- (void) drawStatusBarBackgroundInRect: (NSRect)rect withHighlight: (BOOL)flag; +- (BOOL) highlightMode; +- (NSImage*) image; +- (BOOL) isEnabled; +- (CGFloat) length; +- (NSMenu*) menu; +- (void) popUpStatusItemMenu: (NSMenu*)menu; +- (void) sendActionOn: (NSInteger)mask; +- (void) setAction: (SEL)action; +- (void) setAttributedTitle: (NSAttributedString*)title; +- (void) setDoubleAction: (SEL)sel; +- (void) setEnabled: (BOOL)flag; +- (void) setHighlightMode: (BOOL)highlightMode; +- (void) setImage: (NSImage*)image; +- (void) setLength: (CGFloat)length; +- (void) setMenu: (NSMenu*)menu; +- (void) setTarget: (id)target; +- (void) setTitle: (NSString*)title; +- (void) setToolTip: (NSString*)toolTip; +- (void) setView: (NSView*)view; +- (NSStatusBar*) statusBar; +- (id) target; +- (NSString*) title; +- (NSString*) toolTip; +- (NSView*) view; + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) +- (NSImage*) alternateImage; +- (void) setAlternateImage: (NSImage*)img; +#endif + @end #endif // _GNUstep_H_NSStatusItem diff --git a/Source/GNUmakefile b/Source/GNUmakefile index 914b8eb97..5583daed3 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -163,6 +163,7 @@ NSSplitView.m \ NSStepper.m \ NSStepperCell.m \ NSStringDrawing.m \ +NSStatusBar.m \ NSStatusItem.m \ NSTabView.m \ NSTabViewItem.m \ @@ -376,6 +377,7 @@ NSSplitView.h \ NSStepper.h \ NSStepperCell.h \ NSStringDrawing.h \ +NSStatusBar.h \ NSStatusItem.h \ NSTabView.h \ NSTabViewItem.h \ diff --git a/Source/NSStatusBar.m b/Source/NSStatusBar.m new file mode 100644 index 000000000..0b7c075e5 --- /dev/null +++ b/Source/NSStatusBar.m @@ -0,0 +1,87 @@ +/* + NSStatusBar.m + + The status bar class + + Copyright (C) 2013 Free Software Foundation, Inc. + + Author: Dr. H. Nikolaus Schaller + Date: 2013 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; see the file COPYING.LIB. + If not, see or write to the + Free Software Foundation, 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#import +#import +#import + +@interface NSStatusItem (Private) +- (id) _initForStatusBar: (NSStatusBar*)bar + withLength: (CGFloat)len; +@end + + +@implementation NSStatusBar + +- (id) init +{ + self = [super init]; + if (self) + { + _items = [[NSMutableArray alloc] init]; + } + return self; +} + +- (void) dealloc +{ + RELEASE(_items); + [super dealloc]; +} + ++ (NSStatusBar*) systemStatusBar +{ + return nil; +} + +- (BOOL) isVertical +{ + return NO; +} + +- (void) removeStatusItem: (NSStatusItem*)item +{ + [_items removeObjectIdenticalTo: item]; +} + +- (NSStatusItem*) statusItemWithLength: (CGFloat)length +{ + NSStatusItem *item = [[NSStatusItem alloc] _initForStatusBar: self + withLength: length]; + [_items addObject: item]; + + return AUTORELEASE(item); +} + +- (CGFloat) thickness +{ + return 22; +} + +@end diff --git a/Source/NSStatusItem.m b/Source/NSStatusItem.m index bb724ff18..3f680ec3f 100644 --- a/Source/NSStatusItem.m +++ b/Source/NSStatusItem.m @@ -7,6 +7,7 @@ Author: Gregory Casamento Date: 2013 + Author: Dr. H. Nikolaus Schaller This file is part of the GNUstep GUI Library. @@ -31,7 +32,188 @@ // apps which require NSStatusItem. Currently there is not a clean, // cross-platform way to implement this functionality. +#import +#import + #import +#import +#import @implementation NSStatusItem + +- (id) _initForStatusBar: (NSStatusBar*)bar + withLength: (CGFloat)len +{ + if ((self = [super init])) + { + _statusBar = bar; + _menuItem = [[NSMenuItem alloc] initWithTitle: @"?" + action: NULL + keyEquivalent: @""]; + [_menuItem setRepresentedObject: self]; + [self setLength: len]; + } + + return self; +} + +- (void) dealloc +{ + RELEASE(_menuItem); + [super dealloc]; +} + +- (SEL) action +{ + return [_menuItem action]; +} + +- (NSAttributedString*) attributedTitle +{ + return [_menuItem attributedTitle]; +} + +- (SEL) doubleAction +{ + // NIMP + return NULL; +} + +- (void) drawStatusBarBackgroundInRect: (NSRect)rect withHighlight: (BOOL)flag +{ + // NIMP +} + +- (BOOL) highlightMode +{ + return _highlightMode; +} + +- (NSImage*) image +{ + return [_menuItem image]; +} + +- (BOOL) isEnabled +{ + return [_menuItem isEnabled]; +} + +- (CGFloat) length +{ + return _length; +} + +- (NSMenu *) menu +{ + return [_menuItem submenu]; +} + +- (void) popUpStatusItemMenu: (NSMenu*)menu +{ + // NIMP +} + +- (void) sendActionOn: (NSInteger)mask +{ + //NIMP +} + +- (void) setAction: (SEL)action +{ + [_menuItem setAction: action]; +} + +- (void) setAttributedTitle: (NSAttributedString*) title +{ + [_menuItem setAttributedTitle: title]; +} + +- (void) setDoubleAction: (SEL)sel +{ + // NIMP +} + +- (void) setEnabled: (BOOL)flag +{ + [_menuItem setEnabled: flag]; +} + +- (void) setHighlightMode: (BOOL)highlightMode +{ + _highlightMode = highlightMode; +} + +- (void) setImage: (NSImage*)image +{ + [_menuItem setImage: image]; +} + +- (void) setLength: (CGFloat)len +{ + _length = len; + //[_menuItem _changed]; +} + +- (void) setMenu: (NSMenu*)menu +{ + [_menuItem setSubmenu: menu]; +} + +- (void) setTarget: (id)target +{ + [_menuItem setTarget: target]; +} + +- (void) setTitle: (NSString*)title +{ + [_menuItem setTitle: title]; +} + +- (void) setToolTip: (NSString*)toolTip +{ + [_menuItem setToolTip: toolTip]; +} + +- (void) setView: (NSView*)view +{ + ASSIGN(_view, view); +} + +- (NSStatusBar*) statusBar +{ + return _statusBar; +} + +- (id) target +{ + return [_menuItem target]; +} + +- (NSString*) title +{ + return [_menuItem title]; +} + +- (NSString*) toolTip +{ + return [_menuItem toolTip]; +} + +- (NSView*) view +{ + return _view; +} + +- (NSImage*) alternateImage +{ + //NIMP + return nil; +} + +- (void) setAlternateImage: (NSImage*)img +{ + //NIMP +} + @end