diff --git a/ChangeLog b/ChangeLog index c569cf023..21a886b33 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2003-08-23 Gregory John Casamento + + * 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 * Tools/gsnd/gsnd.m (main): Close any open file descriptors so diff --git a/Headers/Additions/GNUstepGUI/GSToolbarView.h b/Headers/Additions/GNUstepGUI/GSToolbarView.h new file mode 100644 index 000000000..4407eca72 --- /dev/null +++ b/Headers/Additions/GNUstepGUI/GSToolbarView.h @@ -0,0 +1,50 @@ +/* + GSToolbarView.h + + The private toolbar class which draws the actual toolbar. + + Copyright (C) 2002 Free Software Foundation, Inc. + + Author: Gregory John Casamento , + Fabien Vallon + 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 +#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 diff --git a/Headers/AppKit/NSToolbar.h b/Headers/AppKit/NSToolbar.h index 0c3f5fb22..68134e6b9 100644 --- a/Headers/AppKit/NSToolbar.h +++ b/Headers/AppKit/NSToolbar.h @@ -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 */ diff --git a/Headers/AppKit/NSToolbarItem.h b/Headers/AppKit/NSToolbarItem.h index fb897a1d1..c3dac2562 100644 --- a/Headers/AppKit/NSToolbarItem.h +++ b/Headers/AppKit/NSToolbarItem.h @@ -58,21 +58,41 @@ APPKIT_EXPORT NSString *NSToolbarPrintItemIdentifier; @interface NSToolbarItem : NSObject { // 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 diff --git a/Source/GNUmakefile b/Source/GNUmakefile index cb3a4de89..e4c88be85 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -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} diff --git a/Source/GSNibTemplates.m b/Source/GSNibTemplates.m index e9fbf13bb..5ea10f6d7 100644 --- a/Source/GSNibTemplates.m +++ b/Source/GSNibTemplates.m @@ -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) { diff --git a/Source/NSToolbar.m b/Source/NSToolbar.m index 497e2a82c..89eac6c5c 100644 --- a/Source/NSToolbar.m +++ b/Source/NSToolbar.m @@ -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 */ - - diff --git a/Source/NSToolbarItem.m b/Source/NSToolbarItem.m index b07ea1c1e..51c81a3a6 100644 --- a/Source/NSToolbarItem.m +++ b/Source/NSToolbarItem.m @@ -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