mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 19:00:47 +00:00
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:
parent
7bd6218f56
commit
d42cd879d1
5 changed files with 81 additions and 68 deletions
12
ChangeLog
12
ChangeLog
|
@ -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>
|
2004-07-24 22:47 Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
* Source/NSToolbarItem.m: Use the predefined variables instead of
|
* Source/NSToolbarItem.m: Use the predefined variables instead of
|
||||||
|
|
|
@ -43,40 +43,13 @@
|
||||||
@class NSToolbarItem;
|
@class NSToolbarItem;
|
||||||
@class GSToolbarClippedItemsButton;
|
@class GSToolbarClippedItemsButton;
|
||||||
|
|
||||||
enum {
|
typedef enum {
|
||||||
GSToolbarViewNoBorder = 0,
|
GSToolbarViewNoBorder = 0,
|
||||||
GSToolbarViewRightBorder = 2,
|
GSToolbarViewRightBorder = 2,
|
||||||
GSToolbarViewLeftBorder = 4,
|
GSToolbarViewLeftBorder = 4,
|
||||||
GSToolbarViewTopBorder = 8,
|
GSToolbarViewTopBorder = 8,
|
||||||
GSToolbarViewBottomBorder = 16
|
GSToolbarViewBottomBorder = 16
|
||||||
};
|
} GSToolbarViewBorder;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
@interface GSToolbarView : NSView
|
@interface GSToolbarView : NSView
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,6 +44,14 @@
|
||||||
#include "AppKit/NSWindow.h"
|
#include "AppKit/NSWindow.h"
|
||||||
#include "GNUstepGUI/GSToolbarView.h"
|
#include "GNUstepGUI/GSToolbarView.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ToolbarViewDefaultHeight = 62,
|
||||||
|
ToolbarViewRegularHeight = 62,
|
||||||
|
ToolbarViewSmallHeight = 52
|
||||||
|
} ToolbarViewHeight;
|
||||||
|
|
||||||
|
static const int ClippedItemsViewWidth = 28;
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
static const int current_version = 1;
|
static const int current_version = 1;
|
||||||
static NSColorList *SystemExtensionsColors;
|
static NSColorList *SystemExtensionsColors;
|
||||||
|
@ -187,7 +195,7 @@ static void initSystemExtensionsColors(void)
|
||||||
{
|
{
|
||||||
NSImage *image = [NSImage imageNamed: @"common_ToolbarClippedItemsMark"];
|
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
|
100)]) != nil) // The correct height will be set by the layout method
|
||||||
{
|
{
|
||||||
[self setBordered: NO];
|
[self setBordered: NO];
|
||||||
|
@ -307,13 +315,13 @@ static void initSystemExtensionsColors(void)
|
||||||
switch (_sizeMode)
|
switch (_sizeMode)
|
||||||
{
|
{
|
||||||
case NSToolbarSizeModeDefault:
|
case NSToolbarSizeModeDefault:
|
||||||
toolbarViewHeight = _ToolbarViewDefaultHeight;
|
toolbarViewHeight = ToolbarViewDefaultHeight;
|
||||||
break;
|
break;
|
||||||
case NSToolbarSizeModeRegular:
|
case NSToolbarSizeModeRegular:
|
||||||
toolbarViewHeight = _ToolbarViewRegularHeight;
|
toolbarViewHeight = ToolbarViewRegularHeight;
|
||||||
break;
|
break;
|
||||||
case NSToolbarSizeModeSmall:
|
case NSToolbarSizeModeSmall:
|
||||||
toolbarViewHeight = _ToolbarViewSmallHeight;
|
toolbarViewHeight = ToolbarViewSmallHeight;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Raise exception
|
// Raise exception
|
||||||
|
@ -480,13 +488,13 @@ static void initSystemExtensionsColors(void)
|
||||||
switch (_sizeMode)
|
switch (_sizeMode)
|
||||||
{
|
{
|
||||||
case NSToolbarSizeModeDefault:
|
case NSToolbarSizeModeDefault:
|
||||||
rect.size.height = _ToolbarViewDefaultHeight;
|
rect.size.height = ToolbarViewDefaultHeight;
|
||||||
break;
|
break;
|
||||||
case NSToolbarSizeModeRegular:
|
case NSToolbarSizeModeRegular:
|
||||||
rect.size.height = _ToolbarViewRegularHeight;
|
rect.size.height = ToolbarViewRegularHeight;
|
||||||
break;
|
break;
|
||||||
case NSToolbarSizeModeSmall:
|
case NSToolbarSizeModeSmall:
|
||||||
rect.size.height = _ToolbarViewSmallHeight;
|
rect.size.height = ToolbarViewSmallHeight;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
; // Invalid
|
; // Invalid
|
||||||
|
@ -654,7 +662,7 @@ static void initSystemExtensionsColors(void)
|
||||||
|
|
||||||
clipViewFrame = [_clipView frame]; // We get the new _clipView frame
|
clipViewFrame = [_clipView frame]; // We get the new _clipView frame
|
||||||
[_clippedItemsMark setFrameOrigin: NSMakePoint(
|
[_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;
|
backViewsWidth += [backView frame].size.width;
|
||||||
|
|
||||||
if ((backViewsWidth + _ClippedItemsViewWidth <= toolbarWidth)
|
if ((backViewsWidth + ClippedItemsViewWidth <= toolbarWidth)
|
||||||
|| (i == n - 1 && backViewsWidth <= toolbarWidth))
|
|| (i == n - 1 && backViewsWidth <= toolbarWidth))
|
||||||
{
|
{
|
||||||
[_visibleBackViews addObject: backView];
|
[_visibleBackViews addObject: backView];
|
||||||
|
|
|
@ -57,6 +57,25 @@
|
||||||
* with the item identifier.
|
* 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
|
static NSFont *NormalFont = nil; // See NSToolbarItem -initialize method
|
||||||
// [NSFont smallSystemFontSize] or better should be NSControlContentFontSize
|
// [NSFont smallSystemFontSize] or better should be NSControlContentFontSize
|
||||||
|
|
||||||
|
@ -106,7 +125,7 @@ static NSFont *SmallFont = nil;
|
||||||
@implementation GSToolbarButton
|
@implementation GSToolbarButton
|
||||||
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem
|
- (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
|
// Frame will be reset by the layout method
|
||||||
|
|
||||||
if (self != nil)
|
if (self != nil)
|
||||||
|
@ -140,18 +159,18 @@ static NSFont *SmallFont = nil;
|
||||||
switch ([[_toolbarItem toolbar] sizeMode])
|
switch ([[_toolbarItem toolbar] sizeMode])
|
||||||
{
|
{
|
||||||
case NSToolbarSizeModeDefault:
|
case NSToolbarSizeModeDefault:
|
||||||
layoutedWidth = _ItemBackViewDefaultWidth;
|
layoutedWidth = ItemBackViewDefaultWidth;
|
||||||
layoutedHeight = _ItemBackViewDefaultHeight;
|
layoutedHeight = ItemBackViewDefaultHeight;
|
||||||
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
||||||
break;
|
break;
|
||||||
case NSToolbarSizeModeRegular:
|
case NSToolbarSizeModeRegular:
|
||||||
layoutedWidth = _ItemBackViewRegularWidth;
|
layoutedWidth = ItemBackViewRegularWidth;
|
||||||
layoutedHeight = _ItemBackViewRegularHeight;
|
layoutedHeight = ItemBackViewRegularHeight;
|
||||||
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
[[_toolbarItem image] setSize: NSMakeSize(32, 32)];
|
||||||
break;
|
break;
|
||||||
case NSToolbarSizeModeSmall:
|
case NSToolbarSizeModeSmall:
|
||||||
layoutedWidth = _ItemBackViewSmallWidth;
|
layoutedWidth = ItemBackViewSmallWidth;
|
||||||
layoutedHeight = _ItemBackViewSmallHeight;
|
layoutedHeight = ItemBackViewSmallHeight;
|
||||||
[[_toolbarItem image] setSize: NSMakeSize(24, 24)];
|
[[_toolbarItem image] setSize: NSMakeSize(24, 24)];
|
||||||
// Not use [self image] here because it can return nil, when image position is
|
// Not use [self image] here because it can return nil, when image position is
|
||||||
// set to NSNoImage. Even if NSToolbarDisplayModeTextOnly is not true anymore
|
// set to NSNoImage. Even if NSToolbarDisplayModeTextOnly is not true anymore
|
||||||
|
@ -186,7 +205,7 @@ static NSFont *SmallFont = nil;
|
||||||
label = @"Dummy";
|
label = @"Dummy";
|
||||||
attrStr = [[NSAttributedString alloc] initWithString: label attributes: attr];
|
attrStr = [[NSAttributedString alloc] initWithString: label attributes: attr];
|
||||||
|
|
||||||
textWidth = [attrStr size].width + 2 * _InsetItemTextX;
|
textWidth = [attrStr size].width + 2 * InsetItemTextX;
|
||||||
if (layoutedWidth != -1 && textWidth > layoutedWidth)
|
if (layoutedWidth != -1 && textWidth > layoutedWidth)
|
||||||
layoutedWidth = textWidth;
|
layoutedWidth = textWidth;
|
||||||
|
|
||||||
|
@ -202,12 +221,12 @@ static NSFont *SmallFont = nil;
|
||||||
break;
|
break;
|
||||||
case NSToolbarDisplayModeIconOnly:
|
case NSToolbarDisplayModeIconOnly:
|
||||||
[self setImagePosition: NSImageOnly];
|
[self setImagePosition: NSImageOnly];
|
||||||
layoutedHeight -= [attrStr size].height + _InsetItemTextY;
|
layoutedHeight -= [attrStr size].height + InsetItemTextY;
|
||||||
layoutedWidth -= [attrStr size].height + _InsetItemTextY;
|
layoutedWidth -= [attrStr size].height + InsetItemTextY;
|
||||||
break;
|
break;
|
||||||
case NSToolbarDisplayModeLabelOnly:
|
case NSToolbarDisplayModeLabelOnly:
|
||||||
[self setImagePosition: NSNoImage];
|
[self setImagePosition: NSNoImage];
|
||||||
layoutedHeight = [attrStr size].height + _InsetItemTextY * 2;
|
layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
; // Invalid
|
; // Invalid
|
||||||
|
@ -282,8 +301,8 @@ static NSFont *SmallFont = nil;
|
||||||
|
|
||||||
- (id)initWithToolbarItem: (NSToolbarItem *)toolbarItem
|
- (id)initWithToolbarItem: (NSToolbarItem *)toolbarItem
|
||||||
{
|
{
|
||||||
self = [super initWithFrame: NSMakeRect(_ItemBackViewX, _ItemBackViewY, _ItemBackViewDefaultWidth,
|
self = [super initWithFrame: NSMakeRect(ItemBackViewX, ItemBackViewY, ItemBackViewDefaultWidth,
|
||||||
_ItemBackViewDefaultHeight)];
|
ItemBackViewDefaultHeight)];
|
||||||
// Frame will be reset by the layout method
|
// Frame will be reset by the layout method
|
||||||
|
|
||||||
if (self != nil)
|
if (self != nil)
|
||||||
|
@ -330,8 +349,8 @@ static NSFont *SmallFont = nil;
|
||||||
NSForegroundColorAttributeName,
|
NSForegroundColorAttributeName,
|
||||||
nil];
|
nil];
|
||||||
attrString = [[NSAttributedString alloc] initWithString: [_toolbarItem label] attributes: attr];
|
attrString = [[NSAttributedString alloc] initWithString: [_toolbarItem label] attributes: attr];
|
||||||
textX = (([self frame].size.width - _InsetItemTextX) - [attrString size].width) / 2;
|
textX = (([self frame].size.width - InsetItemTextX) - [attrString size].width) / 2;
|
||||||
[attrString drawAtPoint: NSMakePoint(textX, _InsetItemTextY)];
|
[attrString drawAtPoint: NSMakePoint(textX, InsetItemTextY)];
|
||||||
DESTROY(attrString);
|
DESTROY(attrString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,20 +375,20 @@ static NSFont *SmallFont = nil;
|
||||||
switch ([[_toolbarItem toolbar] sizeMode])
|
switch ([[_toolbarItem toolbar] sizeMode])
|
||||||
{
|
{
|
||||||
case NSToolbarSizeModeDefault:
|
case NSToolbarSizeModeDefault:
|
||||||
layoutedWidth = _ItemBackViewDefaultWidth;
|
layoutedWidth = ItemBackViewDefaultWidth;
|
||||||
layoutedHeight = _ItemBackViewDefaultHeight;
|
layoutedHeight = ItemBackViewDefaultHeight;
|
||||||
if ([view frame].size.height > 32)
|
if ([view frame].size.height > 32)
|
||||||
[view removeFromSuperview];
|
[view removeFromSuperview];
|
||||||
break;
|
break;
|
||||||
case NSToolbarSizeModeRegular:
|
case NSToolbarSizeModeRegular:
|
||||||
layoutedWidth = _ItemBackViewRegularWidth;
|
layoutedWidth = ItemBackViewRegularWidth;
|
||||||
layoutedHeight = _ItemBackViewRegularHeight;
|
layoutedHeight = ItemBackViewRegularHeight;
|
||||||
if ([view frame].size.height > 32)
|
if ([view frame].size.height > 32)
|
||||||
[view removeFromSuperview];
|
[view removeFromSuperview];
|
||||||
break;
|
break;
|
||||||
case NSToolbarSizeModeSmall:
|
case NSToolbarSizeModeSmall:
|
||||||
layoutedWidth = _ItemBackViewSmallWidth;
|
layoutedWidth = ItemBackViewSmallWidth;
|
||||||
layoutedHeight = _ItemBackViewSmallHeight;
|
layoutedHeight = ItemBackViewSmallHeight;
|
||||||
_font = SmallFont;
|
_font = SmallFont;
|
||||||
if ([view frame].size.height > 24)
|
if ([view frame].size.height > 24)
|
||||||
[view removeFromSuperview];
|
[view removeFromSuperview];
|
||||||
|
@ -399,7 +418,7 @@ static NSFont *SmallFont = nil;
|
||||||
label = @"Dummy";
|
label = @"Dummy";
|
||||||
attrStr = [[NSAttributedString alloc] initWithString: label attributes: attr];
|
attrStr = [[NSAttributedString alloc] initWithString: label attributes: attr];
|
||||||
|
|
||||||
textWidth = [attrStr size].width + 2 * _InsetItemTextX;
|
textWidth = [attrStr size].width + 2 * InsetItemTextX;
|
||||||
if (textWidth > layoutedWidth)
|
if (textWidth > layoutedWidth)
|
||||||
layoutedWidth = textWidth;
|
layoutedWidth = textWidth;
|
||||||
|
|
||||||
|
@ -418,11 +437,11 @@ static NSFont *SmallFont = nil;
|
||||||
break; // Nothing to do
|
break; // Nothing to do
|
||||||
case NSToolbarDisplayModeIconOnly:
|
case NSToolbarDisplayModeIconOnly:
|
||||||
_showLabel = NO;
|
_showLabel = NO;
|
||||||
layoutedHeight -= [attrStr size].height + _InsetItemTextY;
|
layoutedHeight -= [attrStr size].height + InsetItemTextY;
|
||||||
break;
|
break;
|
||||||
case NSToolbarDisplayModeLabelOnly:
|
case NSToolbarDisplayModeLabelOnly:
|
||||||
_enabled = NO;
|
_enabled = NO;
|
||||||
layoutedHeight = [attrStr size].height + _InsetItemTextY * 2;
|
layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
|
||||||
if ([view superview] != nil)
|
if ([view superview] != nil)
|
||||||
[view removeFromSuperview];
|
[view removeFromSuperview];
|
||||||
break;
|
break;
|
||||||
|
@ -435,8 +454,8 @@ static NSFont *SmallFont = nil;
|
||||||
|
|
||||||
if ([view superview] != nil)
|
if ([view superview] != nil)
|
||||||
{
|
{
|
||||||
if (layoutedWidth < [view frame].size.width + 2 * _InsetItemViewX)
|
if (layoutedWidth < [view frame].size.width + 2 * InsetItemViewX)
|
||||||
layoutedWidth = [view frame].size.width + 2 * _InsetItemViewX;
|
layoutedWidth = [view frame].size.width + 2 * InsetItemViewX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the frame size to use the new layout
|
// Set the frame size to use the new layout
|
||||||
|
@ -451,8 +470,8 @@ static NSFont *SmallFont = nil;
|
||||||
if (_showLabel)
|
if (_showLabel)
|
||||||
{
|
{
|
||||||
insetItemViewY = ([self frame].size.height
|
insetItemViewY = ([self frame].size.height
|
||||||
- [view frame].size.height - [attrStr size].height - _InsetItemTextX) / 2
|
- [view frame].size.height - [attrStr size].height - InsetItemTextX) / 2
|
||||||
+ [attrStr size].height + _InsetItemTextX;
|
+ [attrStr size].height + InsetItemTextX;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -517,7 +536,7 @@ static NSFont *SmallFont = nil;
|
||||||
[(NSButton *)[self _backView] setImage: image];
|
[(NSButton *)[self _backView] setImage: image];
|
||||||
// We bypass the toolbar item accessor to set the image in order to have it (48 * 48) not resized
|
// 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;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,7 +219,8 @@
|
||||||
|
|
||||||
// We do that in this way...
|
// We do that in this way...
|
||||||
// because _toggleToolbarViewWithDisplay: will call -toolbarView method for the toolbar
|
// because _toggleToolbarViewWithDisplay: will call -toolbarView method for the toolbar
|
||||||
[self _toggleToolbarViewWithDisplay: YES];
|
if ([toolbar isVisible])
|
||||||
|
[self _toggleToolbarViewWithDisplay: YES];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue