Added more of the implementation for toolbar/toolbaritem. Added check in GSClassSwapper to prevent an error case.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17532 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2003-08-24 17:22:11 +00:00
parent 577c9532e6
commit a32c4a14df
8 changed files with 173 additions and 40 deletions

View file

@ -1,3 +1,17 @@
2003-08-23 Gregory John Casamento <greg_casamento@yahoo.com>
* Source/GNUmakefile: Added new header to the list.
* Source/GSNibTemplates.m: Added assertion to GSClassSwapper to
prevent it from being initialized with superClassName and className
being the same.
* Source/NSToolbar.m: Added some more code to properly implement
this class.
* Source/NSToolbarItem.m: Added code to implement this class.
* Headers/AppKit/NSToolbar.h: Added flags declaration.
* Headers/AppKit/NSToolbarItem.h: Added attributes.
* Headers/Additions/GNUStepGUI/GSToolbarView.h: Private class which
will be used to display the toolbar in the window.
2003-08-22 Adam Fedor <fedor@gnu.org>
* Tools/gsnd/gsnd.m (main): Close any open file descriptors so

View file

@ -0,0 +1,50 @@
/*
<title>GSToolbarView.h</title>
<abstract>The private toolbar class which draws the actual toolbar.</abstract>
Copyright (C) 2002 Free Software Foundation, Inc.
Author: Gregory John Casamento <greg_casamento@yahoo.com>,
Fabien Vallon <fabien.vallon@fr.alcove.com>
Date: May 2002
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 Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _GSToolbarView_h_INCLUDE
#define _GSToolbarView_h_INCLUDE
#include <Foundation/NSObject.h>
#include "AppKit/NSToolbarItem.h"
#include "AppKit/NSToolbar.h"
#include "AppKit/NSView.h"
@interface GSToolbarView : NSView
{
NSToolbar *_toolbar;
}
- (void) setToolbar: (NSToolbar *)toolbar;
- (NSToolbar *) toolbar;
@end
@interface NSToolbar (GNUstepPrivate)
- (id) _toolbarView;
@end
#endif

View file

@ -96,12 +96,6 @@ APPKIT_EXPORT NSString *NSToolbarWillAddItemNotification;
- (NSArray*) visibleItems;
@end /* interface of NSToolbar */
@class GSToolbarView;
@interface NSToolbar (GNUstepPrivate)
- (GSToolbarView *) _toolbarView;
@end
/*
* Methods Implemented by the Delegate
*/

View file

@ -58,21 +58,41 @@ APPKIT_EXPORT NSString *NSToolbarPrintItemIdentifier;
@interface NSToolbarItem : NSObject <NSCopying, NSValidatedUserInterfaceItem>
{
// externally visible variables
SEL _action;
BOOL _allowsDuplicatesInToolbar;
BOOL _enabled;
NSImage *_image;
NSString *_itemIdentifier;
NSString *_label;
NSSize _maxSize;
NSMenuItem *_menuFormRepresentation;
NSSize _minSize;
NSString *_paletteLabel;
int _tag;
id _target;
// toolbar
NSToolbar *_toolbar;
NSString *_toolTip;
NSView *_view;
id _view;
// size
NSSize _maxSize;
NSSize _minSize;
// record the fact that the view responds to these
// to save time.
struct __tbflags
{
// gets
unsigned int viewRespondsToIsEnabled:1;
unsigned int viewRespondsToTag:1;
unsigned int viewRespondsToAction:1;
unsigned int viewRespondsToTarget:1;
unsigned int viewRespondsToImage:1;
// sets
unsigned int viewRespondsToSetEnabled:1;
unsigned int viewRespondsToSetTag:1;
unsigned int viewRespondsToSetAction:1;
unsigned int viewRespondsToSetTarget:1;
unsigned int viewRespondsToSetImage:1;
// other flags
unsigned int isUserRemovable:1;
unsigned int RESERVED:21; // to even out the long.
} _flags;
}
// Instance methods

View file

@ -335,7 +335,8 @@ IMLoading.h \
GSLayoutManager.h \
GSLayoutManager_internal.h \
GSTypesetter.h \
GSHorizontalTypesetter.h
GSHorizontalTypesetter.h \
GSToolbarView.h
libgnustep-gui_HEADER_FILES = ${GUI_HEADERS}

View file

@ -380,9 +380,10 @@ static const int currentVersion = 1; // GSNibItem version number...
{
if((self = [self init]) != nil)
{
NSLog(@"Created template %@ -> %@",NSStringFromClass([self class]), className);
NSDebugLog(@"Created template %@ -> %@",NSStringFromClass([self class]), className);
ASSIGN(_object, object);
ASSIGN(_className, className);
NSAssert(![className isEqualToString: superClassName], NSInvalidArgumentException);
_superClass = NSClassFromString(superClassName);
if(_superClass == nil)
{

View file

@ -38,19 +38,12 @@
#include "AppKit/NSView.h"
#include "AppKit/NSButton.h"
#include "AppKit/NSNibLoading.h"
#include "GNUstepGUI/GSToolbarView.h"
// internal
static NSNotificationCenter *nc = nil;
static const int current_version = 1;
@interface GSToolbarView : NSView
{
NSToolbar *_toolbar;
}
- (void) setToolbar: (NSToolbar *)toolbar;
- (NSToolbar *) toolbar;
@end
@implementation GSToolbarView
- (void) dealloc
{
@ -61,6 +54,7 @@ static const int current_version = 1;
- (void) setToolbar: (NSToolbar *)toolbar
{
ASSIGN(_toolbar, toolbar);
}
- (NSToolbar *) toolbar
{
@ -69,7 +63,23 @@ static const int current_version = 1;
- (void) drawRect: (NSRect)aRect
{
NSArray *items = [_toolbar items];
NSEnumerator *en = [items objectEnumerator];
id item = nil;
float x = 0;
[super drawRect: aRect];
while((item = [en nextObject]) != nil)
{
NSView *itemView = [item view];
NSRect itemFrame = [itemView frame];
// now we need to draw the items...
itemFrame.origin.x = x; // start at x
itemFrame.origin.y = 0; // reset to top of view.
[itemView drawRect: itemFrame];
x += NSWidth(itemFrame) + 2; // move over by the frame width plus 2 pixels.
}
}
@end
@ -101,13 +111,12 @@ static const int current_version = 1;
@end
@implementation NSToolbar (GNUstepPrivate)
- (GSToolbarView *) _toolbarView
- (id) _toolbarView
{
return _toolbarView;
}
@end
@implementation NSToolbar
// Initialize the class when it is loaded
+ (void) initialize
@ -309,5 +318,3 @@ static const int current_version = 1;
return _visibleItems;
}
@end /* interface of NSToolbar */

View file

@ -42,7 +42,11 @@
- (NSImage *)image
{
return _image;
if(_flags.viewRespondsToImage)
{
return [_view image];
}
return nil;
}
- (id)initWithItemIdentifier: (NSString *)itemIdentifier
@ -53,7 +57,11 @@
- (BOOL)isEnabled
{
return _enabled;
if(_flags.viewRespondsToIsEnabled)
{
return [_view isEnabled];
}
return NO;
}
- (NSString *)itemIdentifier
@ -88,17 +96,26 @@
- (void)setAction: (SEL)action
{
_action = action;
if(_flags.viewRespondsToSetAction)
{
[_view setAction: action];
}
}
- (void)setEnabled: (BOOL)enabled
{
enabled = _enabled;
if(_flags.viewRespondsToSetEnabled)
{
[_view setEnabled: enabled];
}
}
- (void)setImage: (NSImage *)image
{
ASSIGN(_image, image);
if(_flags.viewRespondsToSetImage)
{
[_view setImage: image];
}
}
- (void)setLabel: (NSString *)label
@ -128,12 +145,18 @@
- (void)setTag: (int)tag
{
_tag = tag;
if(_flags.viewRespondsToTag)
{
[_view setTag: tag];
}
}
- (void)setTarget: (id)target
{
ASSIGN(_target, target);
{
if(_flags.viewRespondsToTarget)
{
[_view setTarget: target];
}
}
- (void)setToolTip: (NSString *)toolTip
@ -144,11 +167,27 @@
- (void)setView: (NSView *)view
{
ASSIGN(_view, view);
// gets
_flags.viewRespondsToIsEnabled = [_view respondsToSelector: @selector(isEnabled)];
_flags.viewRespondsToTag = [_view respondsToSelector: @selector(tag)];
_flags.viewRespondsToAction = [_view respondsToSelector: @selector(action)];
_flags.viewRespondsToTarget = [_view respondsToSelector: @selector(target)];
_flags.viewRespondsToImage = [_view respondsToSelector: @selector(image)];
// sets
_flags.viewRespondsToSetEnabled = [_view respondsToSelector: @selector(setEnabled:)];
_flags.viewRespondsToSetTag = [_view respondsToSelector: @selector(setTag:)];
_flags.viewRespondsToSetAction = [_view respondsToSelector: @selector(setAction:)];
_flags.viewRespondsToSetTarget = [_view respondsToSelector: @selector(setTarget:)];
_flags.viewRespondsToSetImage = [_view respondsToSelector: @selector(setImage:)];
}
- (int)tag
{
return _tag;
if(_flags.viewRespondsToTag)
{
return [_view tag];
}
return 0;
}
- (NSString *)toolTip
@ -165,7 +204,6 @@
{
// validate by default, we know that all of the
// "standard" items are correct.
_enabled = YES;
}
- (NSView *)view
@ -176,12 +214,20 @@
// NSValidatedUserInterfaceItem protocol
- (SEL)action
{
return _action;
if(_flags.viewRespondsToAction)
{
return [_view action];
}
return 0;
}
- (id)target
{
return _target;
if(_flags.viewRespondsToTarget)
{
return [_view target];
}
return nil;
}
// NSCopying protocol