NSToolbar visibility issue corrected

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19780 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Quentin Mathe 2004-07-27 15:15:29 +00:00
parent 5d0e3f4755
commit 6576a77429
5 changed files with 81 additions and 68 deletions

View file

@ -1,3 +1,15 @@
2004-07-27 Quentin Mathe <qmathe@club-internet.fr>
* Headers/Additions/GNUstepGUI/GSToolbarView.h:
* Source/GSToolbarView.m:
* Source/NSToolbarItem.m:
Moved static const and enum declarations from GSToolbarView.h to
GSToolbarView.m and NSToolbarItem.m.
* Source/NSWindow+Toolbar.m:
Fixed non correct toolbar view visibility when [NSToolbar -setVisible:]
is called before [NSWindow -setToolbar:](bug reported by Yen-Ju Chen
<yjchenx@hotmail.com>).
2004-07-24 22:47 Alexander Malmberg <alexander@malmberg.org>
* Source/NSToolbarItem.m: Use the predefined variables instead of

View file

@ -43,40 +43,13 @@
@class NSToolbarItem;
@class GSToolbarClippedItemsButton;
enum {
typedef enum {
GSToolbarViewNoBorder = 0,
GSToolbarViewRightBorder = 2,
GSToolbarViewLeftBorder = 4,
GSToolbarViewTopBorder = 8,
GSToolbarViewBottomBorder = 16
};
typedef enum {
_ToolbarViewDefaultHeight = 62,
_ToolbarViewRegularHeight = 62,
_ToolbarViewSmallHeight = 52
} _ToolbarViewHeight;
typedef enum {
_ItemBackViewDefaultHeight = 60,
_ItemBackViewRegularHeight = 60,
_ItemBackViewSmallHeight = 50
} _ItemBackViewHeight;
typedef enum {
_ItemBackViewDefaultWidth = 60,
_ItemBackViewRegularWidth = 60,
_ItemBackViewSmallWidth = 50
} _ItemBackViewWidth;
static const int _ItemBackViewX = 0;
static const int _ItemBackViewY = 0;
static const int _InsetItemViewX = 10;
static const int _InsetItemViewY = 26;
static const int _InsetItemTextX = 3;
static const int _InsetItemTextY = 4;
static const int _ClippedItemsViewWidth = 28;
} GSToolbarViewBorder;
@interface GSToolbarView : NSView
{

View file

@ -44,6 +44,14 @@
#include "AppKit/NSWindow.h"
#include "GNUstepGUI/GSToolbarView.h"
typedef enum {
ToolbarViewDefaultHeight = 62,
ToolbarViewRegularHeight = 62,
ToolbarViewSmallHeight = 52
} ToolbarViewHeight;
static const int ClippedItemsViewWidth = 28;
// internal
static const int current_version = 1;
static NSColorList *SystemExtensionsColors;
@ -187,7 +195,7 @@ static void initSystemExtensionsColors(void)
{
NSImage *image = [NSImage imageNamed: @"common_ToolbarClippedItemsMark"];
if ((self = [super initWithFrame: NSMakeRect(0, 0, _ClippedItemsViewWidth,
if ((self = [super initWithFrame: NSMakeRect(0, 0, ClippedItemsViewWidth,
100)]) != nil) // The correct height will be set by the layout method
{
[self setBordered: NO];
@ -307,13 +315,13 @@ static void initSystemExtensionsColors(void)
switch (_sizeMode)
{
case NSToolbarSizeModeDefault:
toolbarViewHeight = _ToolbarViewDefaultHeight;
toolbarViewHeight = ToolbarViewDefaultHeight;
break;
case NSToolbarSizeModeRegular:
toolbarViewHeight = _ToolbarViewRegularHeight;
toolbarViewHeight = ToolbarViewRegularHeight;
break;
case NSToolbarSizeModeSmall:
toolbarViewHeight = _ToolbarViewSmallHeight;
toolbarViewHeight = ToolbarViewSmallHeight;
break;
default:
// Raise exception
@ -480,13 +488,13 @@ static void initSystemExtensionsColors(void)
switch (_sizeMode)
{
case NSToolbarSizeModeDefault:
rect.size.height = _ToolbarViewDefaultHeight;
rect.size.height = ToolbarViewDefaultHeight;
break;
case NSToolbarSizeModeRegular:
rect.size.height = _ToolbarViewRegularHeight;
rect.size.height = ToolbarViewRegularHeight;
break;
case NSToolbarSizeModeSmall:
rect.size.height = _ToolbarViewSmallHeight;
rect.size.height = ToolbarViewSmallHeight;
break;
default:
; // Invalid
@ -654,7 +662,7 @@ static void initSystemExtensionsColors(void)
clipViewFrame = [_clipView frame]; // We get the new _clipView frame
[_clippedItemsMark setFrameOrigin: NSMakePoint(
[self frame].size.width - _ClippedItemsViewWidth, clipViewFrame.origin.y)];
[self frame].size.width - ClippedItemsViewWidth, clipViewFrame.origin.y)];
// ---
@ -787,7 +795,7 @@ static void initSystemExtensionsColors(void)
backViewsWidth += [backView frame].size.width;
if ((backViewsWidth + _ClippedItemsViewWidth <= toolbarWidth)
if ((backViewsWidth + ClippedItemsViewWidth <= toolbarWidth)
|| (i == n - 1 && backViewsWidth <= toolbarWidth))
{
[_visibleBackViews addObject: backView];

View file

@ -57,6 +57,25 @@
* with the item identifier.
*/
typedef enum {
ItemBackViewDefaultHeight = 60,
ItemBackViewRegularHeight = 60,
ItemBackViewSmallHeight = 50
} ItemBackViewHeight;
typedef enum {
ItemBackViewDefaultWidth = 60,
ItemBackViewRegularWidth = 60,
ItemBackViewSmallWidth = 50
} ItemBackViewWidth;
static const int ItemBackViewX = 0;
static const int ItemBackViewY = 0;
static const int InsetItemViewX = 10;
static const int InsetItemViewY = 26;
static const int InsetItemTextX = 3;
static const int InsetItemTextY = 4;
static NSFont *NormalFont = nil; // See NSToolbarItem -initialize method
// [NSFont smallSystemFontSize] or better should be NSControlContentFontSize
@ -106,7 +125,7 @@ static NSFont *SmallFont = nil;
@implementation GSToolbarButton
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem
{
self = [super initWithFrame: NSMakeRect(_ItemBackViewX, _ItemBackViewY, _ItemBackViewDefaultWidth, _ItemBackViewDefaultHeight)];
self = [super initWithFrame: NSMakeRect(ItemBackViewX, ItemBackViewY, ItemBackViewDefaultWidth, ItemBackViewDefaultHeight)];
// Frame will be reset by the layout method
if (self != nil)
@ -140,18 +159,18 @@ static NSFont *SmallFont = nil;
switch ([[_toolbarItem toolbar] sizeMode])
{
case NSToolbarSizeModeDefault:
layoutedWidth = _ItemBackViewDefaultWidth;
layoutedHeight = _ItemBackViewDefaultHeight;
layoutedWidth = ItemBackViewDefaultWidth;
layoutedHeight = ItemBackViewDefaultHeight;
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
break;
case NSToolbarSizeModeRegular:
layoutedWidth = _ItemBackViewRegularWidth;
layoutedHeight = _ItemBackViewRegularHeight;
layoutedWidth = ItemBackViewRegularWidth;
layoutedHeight = ItemBackViewRegularHeight;
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
break;
case NSToolbarSizeModeSmall:
layoutedWidth = _ItemBackViewSmallWidth;
layoutedHeight = _ItemBackViewSmallHeight;
layoutedWidth = ItemBackViewSmallWidth;
layoutedHeight = ItemBackViewSmallHeight;
[[_toolbarItem image] setSize: NSMakeSize(24, 24)];
// Not use [self image] here because it can return nil, when image position is
// set to NSNoImage. Even if NSToolbarDisplayModeTextOnly is not true anymore
@ -186,7 +205,7 @@ static NSFont *SmallFont = nil;
label = @"Dummy";
attrStr = [[NSAttributedString alloc] initWithString: label attributes: attr];
textWidth = [attrStr size].width + 2 * _InsetItemTextX;
textWidth = [attrStr size].width + 2 * InsetItemTextX;
if (layoutedWidth != -1 && textWidth > layoutedWidth)
layoutedWidth = textWidth;
@ -202,12 +221,12 @@ static NSFont *SmallFont = nil;
break;
case NSToolbarDisplayModeIconOnly:
[self setImagePosition: NSImageOnly];
layoutedHeight -= [attrStr size].height + _InsetItemTextY;
layoutedWidth -= [attrStr size].height + _InsetItemTextY;
layoutedHeight -= [attrStr size].height + InsetItemTextY;
layoutedWidth -= [attrStr size].height + InsetItemTextY;
break;
case NSToolbarDisplayModeLabelOnly:
[self setImagePosition: NSNoImage];
layoutedHeight = [attrStr size].height + _InsetItemTextY * 2;
layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
break;
default:
; // Invalid
@ -282,8 +301,8 @@ static NSFont *SmallFont = nil;
- (id)initWithToolbarItem: (NSToolbarItem *)toolbarItem
{
self = [super initWithFrame: NSMakeRect(_ItemBackViewX, _ItemBackViewY, _ItemBackViewDefaultWidth,
_ItemBackViewDefaultHeight)];
self = [super initWithFrame: NSMakeRect(ItemBackViewX, ItemBackViewY, ItemBackViewDefaultWidth,
ItemBackViewDefaultHeight)];
// Frame will be reset by the layout method
if (self != nil)
@ -330,8 +349,8 @@ static NSFont *SmallFont = nil;
NSForegroundColorAttributeName,
nil];
attrString = [[NSAttributedString alloc] initWithString: [_toolbarItem label] attributes: attr];
textX = (([self frame].size.width - _InsetItemTextX) - [attrString size].width) / 2;
[attrString drawAtPoint: NSMakePoint(textX, _InsetItemTextY)];
textX = (([self frame].size.width - InsetItemTextX) - [attrString size].width) / 2;
[attrString drawAtPoint: NSMakePoint(textX, InsetItemTextY)];
DESTROY(attrString);
}
}
@ -356,20 +375,20 @@ static NSFont *SmallFont = nil;
switch ([[_toolbarItem toolbar] sizeMode])
{
case NSToolbarSizeModeDefault:
layoutedWidth = _ItemBackViewDefaultWidth;
layoutedHeight = _ItemBackViewDefaultHeight;
layoutedWidth = ItemBackViewDefaultWidth;
layoutedHeight = ItemBackViewDefaultHeight;
if ([view frame].size.height > 32)
[view removeFromSuperview];
break;
case NSToolbarSizeModeRegular:
layoutedWidth = _ItemBackViewRegularWidth;
layoutedHeight = _ItemBackViewRegularHeight;
layoutedWidth = ItemBackViewRegularWidth;
layoutedHeight = ItemBackViewRegularHeight;
if ([view frame].size.height > 32)
[view removeFromSuperview];
break;
case NSToolbarSizeModeSmall:
layoutedWidth = _ItemBackViewSmallWidth;
layoutedHeight = _ItemBackViewSmallHeight;
layoutedWidth = ItemBackViewSmallWidth;
layoutedHeight = ItemBackViewSmallHeight;
_font = SmallFont;
if ([view frame].size.height > 24)
[view removeFromSuperview];
@ -399,7 +418,7 @@ static NSFont *SmallFont = nil;
label = @"Dummy";
attrStr = [[NSAttributedString alloc] initWithString: label attributes: attr];
textWidth = [attrStr size].width + 2 * _InsetItemTextX;
textWidth = [attrStr size].width + 2 * InsetItemTextX;
if (textWidth > layoutedWidth)
layoutedWidth = textWidth;
@ -418,11 +437,11 @@ static NSFont *SmallFont = nil;
break; // Nothing to do
case NSToolbarDisplayModeIconOnly:
_showLabel = NO;
layoutedHeight -= [attrStr size].height + _InsetItemTextY;
layoutedHeight -= [attrStr size].height + InsetItemTextY;
break;
case NSToolbarDisplayModeLabelOnly:
_enabled = NO;
layoutedHeight = [attrStr size].height + _InsetItemTextY * 2;
layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
if ([view superview] != nil)
[view removeFromSuperview];
break;
@ -435,8 +454,8 @@ static NSFont *SmallFont = nil;
if ([view superview] != nil)
{
if (layoutedWidth < [view frame].size.width + 2 * _InsetItemViewX)
layoutedWidth = [view frame].size.width + 2 * _InsetItemViewX;
if (layoutedWidth < [view frame].size.width + 2 * InsetItemViewX)
layoutedWidth = [view frame].size.width + 2 * InsetItemViewX;
}
// Set the frame size to use the new layout
@ -451,8 +470,8 @@ static NSFont *SmallFont = nil;
if (_showLabel)
{
insetItemViewY = ([self frame].size.height
- [view frame].size.height - [attrStr size].height - _InsetItemTextX) / 2
+ [attrStr size].height + _InsetItemTextX;
- [view frame].size.height - [attrStr size].height - InsetItemTextX) / 2
+ [attrStr size].height + InsetItemTextX;
}
else
{
@ -517,7 +536,7 @@ static NSFont *SmallFont = nil;
[(NSButton *)[self _backView] setImage: image];
// We bypass the toolbar item accessor to set the image in order to have it (48 * 48) not resized
[[self _backView] setFrameSize: NSMakeSize(30, _ItemBackViewDefaultHeight)];
[[self _backView] setFrameSize: NSMakeSize(30, ItemBackViewDefaultHeight)];
return self;
}

View file

@ -219,7 +219,8 @@
// We do that in this way...
// because _toggleToolbarViewWithDisplay: will call -toolbarView method for the toolbar
[self _toggleToolbarViewWithDisplay: YES];
if ([toolbar isVisible])
[self _toggleToolbarViewWithDisplay: YES];
}