Added color customization to the toolbar and first part of the validation support

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19372 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Quentin Mathe 2004-05-18 19:35:58 +00:00
parent 43997f992f
commit 3963927f9c
4 changed files with 239 additions and 68 deletions

View file

@ -1,3 +1,13 @@
2004-05-18 Quentin Mathe <qmathe@club-internet.fr>
* Source/GSToolbarView: Added color customization (default background
color is now no color), part of the toolbar validation mechanism
and other minor changes.
* Headers/GNUstepGUI/GSToolbarView.h: Same.
* Source/NSToolbarItem: Added part of the toolbar validation mechanism,
new menuFormRepresentation implementation to have the menu item titles
used as label with the text display mode and other minor changes.
2004-05-14 Adam Fedor <fedor@gnu.org>
* Source/NSDocumentController.m ([NSDocumentController -currentDirectory]):

View file

@ -31,16 +31,16 @@
#ifndef _GSToolbarView_h_INCLUDE
#define _GSToolbarView_h_INCLUDE
#include <Foundation/NSObject.h>
#include <Foundation/NSGeometry.h>
#include <AppKit/NSView.h>
#include <AppKit/NSColor.h>
#include "GNUstepGUI/GSToolbar.h"
// Necessary for NSToolbarDisplayMode and NSToolbarSizeMode
@class NSMutableArray;
@class NSToolbarItem;
@class NSClipView;
@class NSToolbarItem;
@class GSToolbarClippedItemsButton;
enum {
@ -104,4 +104,13 @@ static const int _ClippedItemsViewWidth = 28;
@end
// Toolbar related NSColor methods
@interface NSColor (Extensions)
+ (NSColor *) toolbarBackgroundColor;
+ (NSColor *) toolbarBorderColor;
@end
#endif

View file

@ -29,21 +29,106 @@
#include <Foundation/NSObject.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSUserDefaults.h>
#include <Foundation/NSString.h>
#include "AppKit/NSToolbarItem.h"
#include "AppKit/NSView.h"
#include "AppKit/NSClipView.h"
#include "AppKit/NSButton.h"
#include "AppKit/NSBezierPath.h"
#include "AppKit/NSButton.h"
#include "AppKit/NSClipView.h"
#include "AppKit/NSColor.h"
#include "AppKit/NSColorList.h"
#include "AppKit/NSEvent.h"
#include "AppKit/NSImage.h"
#include "AppKit/NSMenu.h"
#include "AppKit/NSEvent.h"
#include "AppKit/NSView.h"
#include "AppKit/NSWindow.h"
#include "GNUstepGUI/GSToolbarView.h"
// internal
static const int current_version = 1;
static NSColorList *SystemExtensionsColors;
static NSColor *ClassicBackgroundColor;
static NSColor *BackgroundColor;
static NSColor *BorderColor;
// Toolbar color extensions
@interface NSColor (GNUstepPrivate)
+ (NSColor *) colorFromString: (NSString *)string;
@end
static void initSystemExtensionsColors(void)
{
NSColor *toolbarBackgroundColor;
NSColor *toolbarBorderColor;
NSDictionary *colors;
// Set up a dictionary containing the names of all the system extensions
// colors as keys and with colors in string format as values.
toolbarBorderColor = [NSColor colorWithCalibratedRed: 0.5
green: 0.5
blue: 0.5
alpha: 1.0];
toolbarBackgroundColor = [NSColor clearColor]; // window background color by tranparency
/* toolbarBackgroundColor = [NSColor colorWithCalibratedRed: 0.8
green: 0.8
blue: 0.8
alpha: 1.0]; */
colors = [[NSDictionary alloc]
initWithObjectsAndKeys: toolbarBackgroundColor,
@"toolbarBackgroundColor",
toolbarBorderColor,
@"toolbarBorderColor",
nil];
SystemExtensionsColors = [NSColorList colorListNamed: @"System extensions"];
if (SystemExtensionsColors == nil)
{
SystemExtensionsColors = [[NSColorList alloc] initWithName: @"System extensions"];
}
{
NSEnumerator *e;
NSString *colorKey;
NSColor *color;
BOOL changed = NO;
// Set up default system extensions colors
e = [colors keyEnumerator];
while ((colorKey = (NSString *)[e nextObject]))
{
if ([SystemExtensionsColors colorWithKey: colorKey])
continue;
color = [colors objectForKey: colorKey];
[SystemExtensionsColors setColor: color forKey: colorKey];
changed = YES;
}
if (changed)
[SystemExtensionsColors writeToFile: nil];
}
}
@implementation NSColor (Extensions)
+ (NSColor *) toolbarBackgroundColor
{
return [SystemExtensionsColors colorWithKey: @"toolbarBackgroundColor"];
}
+ (NSColor *) toolbarBorderColor
{
return [SystemExtensionsColors colorWithKey: @"toolbarBorderColor"];
}
@end
/*
* Toolbar related code
*/
@interface GSToolbar (GNUstepPrivate)
- (void) _build;
- (void) _setToolbarView: (GSToolbarView *)toolbarView;
@ -52,6 +137,7 @@ static const int current_version = 1;
@interface NSToolbarItem (GNUstepPrivate)
- (NSView *) _backView;
- (NSMenuItem *) _defaultMenuFormRepresentation;
- (BOOL) _isModified;
- (BOOL) _isFlexibleSpace;
- (void) _layout;
@ -157,7 +243,10 @@ static const int current_version = 1;
id menuItem;
menuItem = [item menuFormRepresentation];
if (menuItem != nil)
if (menuItem == nil)
menuItem = [item _defaultMenuFormRepresentation];
if (menuItem != nil)
[menu addItem: menuItem];
}
}
@ -176,6 +265,16 @@ static const int current_version = 1;
// Implementation GSToolbarView
@implementation GSToolbarView
+ (void) initialize
{
if (self != [GSToolbarView class])
return;
initSystemExtensionsColors();
ClassicBackgroundColor =
RETAIN([NSColor colorWithCalibratedRed: 0.8 green: 0.8 blue: 0.8 alpha: 1.0]);
}
- (id) initWithFrame: (NSRect)frame
{
return [self initWithFrame: frame
@ -190,7 +289,7 @@ static const int current_version = 1;
if((self = [super initWithFrame: frame]) != nil)
{
float toolbarViewHeight;
_displayMode = displayMode;
_sizeMode = sizeMode;
@ -230,6 +329,11 @@ static const int current_version = 1;
_borderMask = GSToolbarViewTopBorder | GSToolbarViewBottomBorder
| GSToolbarViewRightBorder | GSToolbarViewLeftBorder;
BackgroundColor = [SystemExtensionsColors colorWithKey: @"toolbarBackgroundColor"];
BorderColor = [SystemExtensionsColors colorWithKey: @"toolbarBorderColor"];
RETAIN(BackgroundColor);
RETAIN(BorderColor);
// ---
@ -256,11 +360,14 @@ static const int current_version = 1;
NSRect viewFrame = [self frame];
// We draw the background
[[NSColor colorWithDeviceRed: 0.8 green: 0.8 blue: 0.8 alpha:1] set];
[rect fill];
if (![BackgroundColor isEqual: [NSColor clearColor]])
{
[BackgroundColor set];
[rect fill];
}
// We draw the border
[[NSColor colorWithDeviceRed: 0.5 green: 0.5 blue: 0.5 alpha:1] set];
[BorderColor set];
if (_borderMask & GSToolbarViewBottomBorder)
{
[NSBezierPath strokeLineFromPoint: NSMakePoint(0, 0.5)
@ -290,7 +397,14 @@ static const int current_version = 1;
- (BOOL) isOpaque
{
return YES;
if ([BackgroundColor isEqual: [NSColor clearColor]])
{
return NO;
}
else
{
return YES;
}
}
- (void) windowDidResize: (NSNotification *)notification
@ -324,6 +438,17 @@ static const int current_version = 1;
name: NSWindowDidResizeNotification object: nil];
//[self viewDidMoveToSuperview];
[nc postNotificationName: @"GSViewDidMoveToWindow" object: self];
}
- (void) viewWillMoveToWindow: (NSWindow *)newWindow
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[super viewWillMoveToWindow: newWindow];
[nc postNotificationName: @"GSViewWillMoveToWindow" object: self];
}
// More methods... Accessors
@ -354,6 +479,11 @@ static const int current_version = 1;
[self _setToolbar: toolbar];
}
- (NSColor *) classicBackgroundColor
{
return ClassicBackgroundColor;
}
// Private methods
- (void) _handleBackViewsFrame

View file

@ -62,10 +62,11 @@
@end
@interface NSToolbarItem (GNUstepPrivate)
- (void) _layout;
- (NSView *) _backView;
- (BOOL) _isModified;
- (NSMenuItem *) _defaultMenuFormRepresentation;
- (BOOL) _isFlexibleSpace;
- (BOOL) _isModified;
- (void) _layout;
- (void) _setToolbar: (GSToolbar *)toolbar;
@end
@ -422,7 +423,7 @@
return self;
}
- (NSMenuItem *) menuFormRepresentation
- (NSMenuItem *) _defaultMenuFormRepresentation
{
return nil; // override the default implementation in order to do nothing
}
@ -448,7 +449,7 @@
return self;
}
- (NSMenuItem *) menuFormRepresentation
- (NSMenuItem *) _defaultMenuFormRepresentation
{
return nil;// override the default implementation in order to do nothing
}
@ -475,7 +476,7 @@
return self;
}
- (NSMenuItem *) menuFormRepresentation
- (NSMenuItem *) _defaultMenuFormRepresentation
{
return nil;// override the default implementation in order to do nothing
}
@ -584,7 +585,7 @@
@implementation NSToolbarItem
- (BOOL)allowsDuplicatesInToolbar
- (BOOL) allowsDuplicatesInToolbar
{
return _allowsDuplicatesInToolbar;
}
@ -598,7 +599,7 @@
return nil;
}
- (id)initWithItemIdentifier: (NSString *)itemIdentifier
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
GSToolbarButton *button;
NSButtonCell *cell;
@ -695,7 +696,7 @@
return self;
}
- (BOOL)isEnabled
- (BOOL) isEnabled
{
if(_flags._isEnabled)
{
@ -704,52 +705,46 @@
return NO;
}
- (NSString *)itemIdentifier
- (NSString *) itemIdentifier
{
return _itemIdentifier;
}
- (NSString *)label
- (NSString *) label
{
return _label;
NSMenuItem *menuItem = [self menuFormRepresentation];
if ([[self toolbar] displayMode] == NSToolbarDisplayModeLabelOnly && menuItem != nil)
{
return [menuItem title];
}
else
{
return _label;
}
}
- (NSSize)maxSize
- (NSSize) maxSize
{
return _maxSize;
}
- (NSMenuItem *)menuFormRepresentation
- (NSMenuItem *) menuFormRepresentation
{
NSMenuItem *menuItem;
if (_menuFormRepresentation == nil)
{
menuItem = [[NSMenuItem alloc] initWithTitle: [self label]
action: [self action]
keyEquivalent: @""];
[menuItem setTarget: [self target]];
AUTORELEASE(menuItem);
}
else
{
menuItem = [_menuFormRepresentation copy];
}
return menuItem;
return _menuFormRepresentation;
}
- (NSSize)minSize
- (NSSize) minSize
{
return _minSize;
}
- (NSString *)paletteLabel
- (NSString *) paletteLabel
{
return _paletteLabel;
}
- (void)setAction: (SEL)action
- (void) setAction: (SEL)action
{
if(_flags._setAction)
{
@ -757,22 +752,22 @@
[(GSToolbarButton *)_backView setToolbarItemAction: action];
if (action != NULL)
{
[(NSButton *)_backView setEnabled: YES];
[self setEnabled: YES];
}
else
{
[(NSButton *)_backView setEnabled: NO];
[self setEnabled: NO];
}
}
}
- (void)setEnabled: (BOOL)enabled
- (void) setEnabled: (BOOL)enabled
{
if(_flags._setEnabled)
[(id)_backView setEnabled: enabled];
}
- (void)setImage: (NSImage *)image
- (void) setImage: (NSImage *)image
{
if(_flags._setImage)
{
@ -786,7 +781,7 @@
}
}
- (void)setLabel: (NSString *)label
- (void) setLabel: (NSString *)label
{
ASSIGN(_label, label);
@ -798,33 +793,33 @@
[[_toolbar _toolbarView] _reload];
}
- (void)setMaxSize: (NSSize)maxSize
- (void) setMaxSize: (NSSize)maxSize
{
_maxSize = maxSize;
}
- (void)setMenuFormRepresentation: (NSMenuItem *)menuItem
- (void) setMenuFormRepresentation: (NSMenuItem *)menuItem
{
ASSIGN(_menuFormRepresentation, menuItem);
}
- (void)setMinSize: (NSSize)minSize
- (void) setMinSize: (NSSize)minSize
{
_minSize = minSize;
}
- (void)setPaletteLabel: (NSString *)paletteLabel
- (void) setPaletteLabel: (NSString *)paletteLabel
{
ASSIGN(_paletteLabel, paletteLabel);
}
- (void)setTag: (int)tag
- (void) setTag: (int)tag
{
if(_flags._tag)
[_backView setTag: tag];
}
- (void)setTarget: (id)target
- (void) setTarget: (id)target
{
if(_flags._target)
{
@ -833,12 +828,12 @@
}
}
- (void)setToolTip: (NSString *)toolTip
- (void) setToolTip: (NSString *)toolTip
{
ASSIGN(_toolTip, toolTip);
}
- (void)setView: (NSView *)view
- (void) setView: (NSView *)view
{
ASSIGN(_view, view);
@ -873,7 +868,7 @@
_backView = [[GSToolbarBackView alloc] initWithToolbarItem: self];
}
- (int)tag
- (int) tag
{
if(_flags._tag)
return [_backView tag];
@ -881,45 +876,71 @@
return 0;
}
- (NSString *)toolTip
- (NSString *) toolTip
{
return _toolTip;
}
- (GSToolbar *)toolbar
- (GSToolbar *) toolbar
{
return _toolbar;
}
- (void)validate
- (void) validate
{
// validate by default, we know that all of the
// "standard" items are correct.
NSMenuItem *menuItem = [self menuFormRepresentation];
id target = [self target];
if ([[self toolbar] displayMode] == NSToolbarDisplayModeLabelOnly && menuItem != nil)
{
if ([target respondsToSelector: @selector(validateMenuItem:)])
[self setEnabled: [target validateMenuItem: menuItem]];
}
else
{
if ([target respondsToSelector: @selector(validateToolbarItem:)])
[self setEnabled: [target validateToolbarItem: self]];
}
}
- (NSView *)view
- (NSView *) view
{
return _view;
}
// Private or package like visibility methods
- (NSView *)_backView
- (NSView *) _backView
{
return _backView;
}
- (NSMenuItem *) _defaultMenuFormRepresentation
{
NSMenuItem *menuItem;
menuItem = [[NSMenuItem alloc] initWithTitle: [self label]
action: [self action]
keyEquivalent: @""];
[menuItem setTarget: [self target]];
AUTORELEASE(menuItem);
return menuItem;
}
- (void) _layout
{
[(id)_backView layout];
}
- (BOOL)_isModified
- (BOOL) _isModified
{
return _modified;
}
- (BOOL)_isFlexibleSpace
- (BOOL) _isFlexibleSpace
{
return [self isKindOfClass: [GSToolbarFlexibleSpaceItem class]];
}
@ -930,7 +951,7 @@
}
// NSValidatedUserInterfaceItem protocol
- (SEL)action
- (SEL) action
{
if(_flags._action)
{
@ -940,7 +961,7 @@
return 0;
}
- (id)target
- (id) target
{
if(_flags._target)
{
@ -952,7 +973,7 @@
}
// NSCopying protocol
- (id)copyWithZone: (NSZone *)zone
- (id) copyWithZone: (NSZone *)zone
{
NSToolbarItem *new = [[NSToolbarItem allocWithZone: zone] initWithItemIdentifier: _itemIdentifier];
@ -970,4 +991,5 @@
return self;
}
@end