Deactivated the toolbar delegate synchronisation and other toolbar modifications

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20001 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Quentin Mathe 2004-09-05 17:56:11 +00:00
parent f981e6343f
commit 06bd77f976
4 changed files with 125 additions and 72 deletions

View file

@ -1,3 +1,28 @@
2004-09-05 Quentin Mathe <qmathe@club-internet.fr>
* Headers/Additions/GNUstepGUI/GSToolbarView.h: Changed
_heightFromLayout from unsigned int to float.
* Source/GSToolbarView.m (-initWithFrame:displayMode:sizeMode:): Removed
the local variable toolbarViewHeight to use the ivar _heightFromLayout
in order to have a toolbar height which is not equal to zero when the
toolbar is empty. (the toolbar height now matches initially the height
associated with the selected size mode)
(-_handleBackViewsFrame): Added a local variable newHeight to store the
highest caculated height for a toolbar item in order to not have
_heightFromLayout set to zero when the toolbar is empty (no toolbar
items).
* Source/GSToolbar.m (-setDelegate:, -_setDelegate:broadcast:,
-setToolbarView:): Deactived the delegate
synchronization with broadcast set to NO for the method
-_setDelegate:broadcast: because it could produce strange segmentation
faults or exceptions with Cocoa applications which haven't been written
with this delegate synchronization behavior in mind.
(-setSelectedItemIdentifier:, -_build,
-_insertItemWithItemIdentifier:atIndex:broadcast:,
-_setDelegate:broadcast:): Added the nil delegate check because a nil
delegate could happen more easily without the delegate synchronization,
moreover it wasn't handled correctly before.
2004-09-05 10:30 Matt Rice <ratmice@yahoo.com>
* Source/NSTableView.m: [NSTableView mouseDown:] removed code which
@ -39,16 +64,17 @@
2004-09-02 Quentin Mathe <qmathe@club-internet.fr>
* Headers/AppKit/NSToolbarItem.h: Added GSMovableToolbarPboardType
* Headers/AppKit/NSToolbarItem.h: Added GSMovableToolbarItemPboardType
declaration.
* Source/NSToolbarItem.m: Added the toolbar items rearranging possibility by
implementing the dragging source methods.
* Source/GSToolbar.m: Added or reworked some methods to support model updates
without direct view effects to manipulate the toolbar items when a dragging
session happens.
* Source/GSToolbarView.m: Added the toolbar items rearranging possibility by
implementing the dragging destination methods. And added a method to
support the insertion index calculation based on the mouse location.
* Source/NSToolbarItem.m: Added the toolbar items rearranging
possibility by implementing the dragging source methods.
* Source/GSToolbar.m: Added or reworked some methods to support model
updates without direct view effects to manipulate the toolbar items when
a dragging session happens.
* Source/GSToolbarView.m: Added the toolbar items rearranging
possibility by implementing the dragging destination methods. And added
a method -_insertionIndexAtPoint: to support the insertion index
calculation based on the mouse location.
2004-09-01 Adam Fedor <fedor@gnu.org>

View file

@ -62,7 +62,7 @@ typedef enum {
NSToolbarDisplayMode _displayMode;
NSToolbarSizeMode _sizeMode;
NSRect _rectAvailable;
unsigned int _heightFromLayout;
float _heightFromLayout;
}
- (id) initWithFrame: (NSRect)frame;

View file

@ -597,12 +597,11 @@ static GSValidationCenter *vc;
_configurationDictionary = nil;
// [self _loadConfig];
_delegate = nil;
}
_displayMode = displayMode;
_sizeMode = sizeMode;
_delegate = nil;
[toolbars addObject: self];
@ -611,7 +610,7 @@ static GSValidationCenter *vc;
- (void) dealloc
{
NSLog(@"Toolbar dealloc %@", self);
//NSLog(@"Toolbar dealloc %@", self);
[vc removeObserver: self window: nil];
@ -782,7 +781,15 @@ static GSValidationCenter *vc;
- (void) setDelegate: (id)delegate
{
[self _setDelegate: delegate broadcast: YES];
[self _setDelegate: delegate broadcast: NO];
//[self _setDelegate: delegate broadcast: YES];
// Deactivated the delegate synchronization because it can create segmentation
// faults when the application has not been written specially to support it
// which is the case for the Cocoa applications. Moreover it can be
// difficult to understand how it works in detail because it doesn't fit
// exactly with the delegate philosophy.
// Will be made optional later in the case the developers want to use it.
}
- (void) setSelectedItemIdentifier: (NSString *)itemIdentifier
@ -794,6 +801,9 @@ static GSValidationCenter *vc;
NSArray *selectableIdentifiers = nil;
BOOL updated = NO;
if (_delegate == nil)
return;
// First, we have to deselect the previous selected toolbar items
selectedItems = [[self items] objectsWithValue: [self selectedItemIdentifier]
forKey: @"_itemIdentifier"];
@ -879,16 +889,22 @@ static GSValidationCenter *vc;
RELEASE(_items);
_items = [[NSMutableArray alloc] init];
if (_delegate == nil)
{
_build = NO;
return;
}
toolbarModel = [self _toolbarModel];
if (toolbarModel != nil && [toolbarModel delegate] == _delegate)
if (toolbarModel != nil)
{
wantedItemIdentifiers =
[[toolbarModel items] valueForKey: @"_itemIdentifier"];
}
else
{
{
wantedItemIdentifiers = [_delegate toolbarDefaultItemIdentifiers:self];
}
@ -1008,7 +1024,12 @@ static GSValidationCenter *vc;
broadcast: (BOOL)broadcast
{
NSToolbarItem *item = nil;
NSArray *allowedItems = [_delegate toolbarAllowedItemIdentifiers: self];
NSArray *allowedItems;
if (_delegate == nil)
return;
allowedItems = [_delegate toolbarAllowedItemIdentifiers: self];
if([allowedItems containsObject: itemIdentifier])
{
@ -1121,41 +1142,37 @@ static GSValidationCenter *vc;
{
//if(_delegate)
// [nc removeObserver: _delegate name: nil object: self];
if (_delegate == delegate
|| (broadcast == NO && [_delegate isMemberOfClass: [delegate class]]))
if (_delegate == delegate)
return;
/* We don't reload instances which received this message and already have a
* delegate based on a class identical to the parameter delegate, it permits
* to use only one nib owner class as a toolbar delegate even if a new
* instance of the nib owner are created with each new window (see
* MiniController.m in the toolbar example application).
*/
if(_delegate)
if (_delegate != nil)
[nc removeObserver: _delegate name: nil object: self];
#define CHECK_REQUIRED_METHOD(selector_name) \
if (![delegate respondsToSelector: @selector(selector_name)]) \
[NSException raise: NSInternalInconsistencyException \
format: @"delegate does not respond to %@",@#selector_name]
CHECK_REQUIRED_METHOD(toolbar:itemForItemIdentifier:
willBeInsertedIntoToolbar:);
CHECK_REQUIRED_METHOD(toolbarAllowedItemIdentifiers:);
CHECK_REQUIRED_METHOD(toolbarDefaultItemIdentifiers:);
// Assign the delegate...
_delegate = delegate;
#define SET_DELEGATE_NOTIFICATION(notif_name) \
if ([_delegate respondsToSelector: @selector(toolbar##notif_name:)]) \
[nc addObserver: _delegate \
selector: @selector(toolbar##notif_name:) \
name: NSToolbar##notif_name##Notification object: self]
SET_DELEGATE_NOTIFICATION(DidRemoveItem);
SET_DELEGATE_NOTIFICATION(WillAddItem);
if (_delegate != nil)
{
#define CHECK_REQUIRED_METHOD(selector_name) \
if (![_delegate respondsToSelector: @selector(selector_name)]) \
[NSException raise: NSInternalInconsistencyException \
format: @"delegate does not respond to %@",@#selector_name]
CHECK_REQUIRED_METHOD(toolbar:itemForItemIdentifier:
willBeInsertedIntoToolbar:);
CHECK_REQUIRED_METHOD(toolbarAllowedItemIdentifiers:);
CHECK_REQUIRED_METHOD(toolbarDefaultItemIdentifiers:);
#define SET_DELEGATE_NOTIFICATION(notif_name) \
if ([_delegate respondsToSelector: @selector(toolbar##notif_name:)]) \
[nc addObserver: _delegate \
selector: @selector(toolbar##notif_name:) \
name: NSToolbar##notif_name##Notification object: self]
SET_DELEGATE_NOTIFICATION(DidRemoveItem);
SET_DELEGATE_NOTIFICATION(WillAddItem);
}
[self _build];
if (_toolbarView != nil)
@ -1197,7 +1214,7 @@ static GSValidationCenter *vc;
- (void) _setToolbarView: (GSToolbarView *)toolbarView
{
GSToolbar *toolbarModel = [self _toolbarModel];
//GSToolbar *toolbarModel = [self _toolbarModel];
if (_toolbarView != nil)
{
@ -1228,8 +1245,15 @@ static GSValidationCenter *vc;
* Another toolbar load content would occur related to a probably different
* delegate.
*/
if (_delegate == nil)
[self _setDelegate: [toolbarModel delegate] broadcast: NO];
//if (_delegate == nil)
//[self _setDelegate: [toolbarModel delegate] broadcast: NO];
// Deactivated the delegate synchronization because it can create segmentation
// faults when the application has not been written specially to support it
// which is the case for the Cocoa applications. Moreover it can be
// difficult to understand how it works in detail because it doesn't fit
// exactly with the delegate philosophy.
// Will be made optional later in the case the developers want to use it.
}
- (GSToolbarView *) _toolbarView

View file

@ -238,6 +238,8 @@ static void initSystemExtensionsColors(void)
return nil;
}
// Not really used, it is here to be used by the developer who want to adjust
// easily a toolbar view attached to a toolbar which is not bind to a window
- (void) layout {
[self setFrameSize: NSMakeSize([self frame].size.width,
[[_toolbar _toolbarView] _heightFromLayout])];
@ -342,31 +344,30 @@ static void initSystemExtensionsColors(void)
{
if ((self = [super initWithFrame: frame]) != nil)
{
float toolbarViewHeight;
_displayMode = displayMode;
_sizeMode = sizeMode;
switch (_sizeMode)
{
case NSToolbarSizeModeDefault:
toolbarViewHeight = ToolbarViewDefaultHeight;
break;
case NSToolbarSizeModeRegular:
toolbarViewHeight = ToolbarViewRegularHeight;
break;
case NSToolbarSizeModeSmall:
toolbarViewHeight = ToolbarViewSmallHeight;
break;
default:
// Raise exception
toolbarViewHeight = 0;
}
case NSToolbarSizeModeDefault:
_heightFromLayout = ToolbarViewDefaultHeight;
break;
case NSToolbarSizeModeRegular:
_heightFromLayout = ToolbarViewRegularHeight;
break;
case NSToolbarSizeModeSmall:
_heightFromLayout = ToolbarViewSmallHeight;
break;
default:
// Raise exception
_heightFromLayout = 0;
}
[self setFrame: NSMakeRect(frame.origin.x,
frame.origin.y,
frame.size.width,
toolbarViewHeight)];
_heightFromLayout)];
// ---
@ -406,7 +407,7 @@ static void initSystemExtensionsColors(void)
- (void) dealloc
{
NSLog(@"Toolbar view dealloc");
//NSLog(@"Toolbar view dealloc");
[[NSNotificationCenter defaultCenter] removeObserver: self];
@ -649,10 +650,11 @@ static void initSystemExtensionsColors(void)
NSView *itemBackView;
NSRect itemBackViewFrame;
float x = 0;
float newHeight = 0;
// ---
NSArray *subviews = [self subviews];
_heightFromLayout = 0;
//_heightFromLayout = 0;
while ((item = [e nextObject]) != nil)
{
@ -674,10 +676,12 @@ static void initSystemExtensionsColors(void)
itemBackViewFrame.size.height)];
x += [itemBackView frame].size.width;
if (itemBackViewFrame.size.height > _heightFromLayout)
_heightFromLayout = itemBackViewFrame.size.height;
if (itemBackViewFrame.size.height > newHeight)
newHeight = itemBackViewFrame.size.height;
}
if (newHeight > 0)
_heightFromLayout = newHeight;
}
- (void) _handleViewsVisibility
@ -889,8 +893,7 @@ static void initSystemExtensionsColors(void)
{
height++;
}
return height;
}