mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 18:50:48 +00:00
Fixed the toolbar layout problem introduced by NSButtonCell changes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19941 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0238dd7e11
commit
9c44969b67
5 changed files with 244 additions and 80 deletions
47
ChangeLog
47
ChangeLog
|
@ -1,3 +1,21 @@
|
||||||
|
2004-08-30 Quentin Mathe <qmathe@club-internet.fr>
|
||||||
|
|
||||||
|
* Headers/AppKit/NSCell.h:
|
||||||
|
* Source/NSCell.m:
|
||||||
|
Make the code a bit more modular with a distinct private method to
|
||||||
|
implement the image drawing (the text drawing is already located in a
|
||||||
|
separate method), see -_drawImage:inFrame:isFlipped:,
|
||||||
|
previously implemented in -drawInteriorWithFrame:inView:
|
||||||
|
* Source/NSButtonCell.m: Moved code specific to NSButtonCell
|
||||||
|
-drawInteriorWithFrame:inView: in a new method
|
||||||
|
-_drawImage:inFrame:isFlipped to match the method added to NSCell. Also
|
||||||
|
reverted the 2004-08-11 21:35 Alexander Malmberg commit to have identical
|
||||||
|
margin between the border and the text with every image positions.
|
||||||
|
Source/NSToolbarItem.m:
|
||||||
|
Added -_drawImage:inFrame:isFlipped and _drawAttributedText:inFrame:
|
||||||
|
to override the superclasses behavior, it permits to have the
|
||||||
|
GSToolbarButtonCell layout not dependent on the NSButtonCell code.
|
||||||
|
|
||||||
2004-08-29 02:48 Matt Rice <ratmice@yahoo.com>
|
2004-08-29 02:48 Matt Rice <ratmice@yahoo.com>
|
||||||
|
|
||||||
* Source/NSTableView.m (-draggingUpdated:): Return
|
* Source/NSTableView.m (-draggingUpdated:): Return
|
||||||
|
@ -27,17 +45,24 @@
|
||||||
|
|
||||||
2004-08-13 Quentin Mathe <qmathe@club-internet.fr>
|
2004-08-13 Quentin Mathe <qmathe@club-internet.fr>
|
||||||
|
|
||||||
* Source/NSComboBoxCell.m:
|
* Source/NSComboBoxCell.m -(runModalPopUpWithComboBoxCell:): Remove the
|
||||||
* Source/NSComboBox.m:
|
observer only for the variable onWindow, then it is not needed anymore
|
||||||
Fixed broken combo box behavior introduced June 17 with version 1.27,
|
to reset the table view delegate.
|
||||||
which produced wrong tracking in the button cell and extra mouse down
|
(-deselectItemAtIndex:): Added a _localSelection flag, the result is now
|
||||||
call in the NSComboBox superclass. Now the rewritten version is also
|
the method still triggers -[GSComboWindow tableViewSelectionDidChange:]
|
||||||
documented.
|
call but the _localSelection variable in -validateSelection
|
||||||
Also now -[GSComboWindow deselectItemAtIndex:] still produces a
|
avoids to have -selectItemAtIndex: wrongly called.
|
||||||
-[GSComboWindow tableViewSelectionDidChange:] call but the chain is
|
(-trackMouse:inRect:ofView:untilMouseUp:): Fixed broken combo box
|
||||||
stopped in -[GSComboWindow validateSelection] by the _locationSelection
|
behavior introduced June 17 with version 1.27, which produced wrong
|
||||||
variable, then -[NSComboBoxCell selectItemAtIndex:] is not anymore
|
tracking in the button cell and extra mouse down call in the NSComboBox
|
||||||
wrongly called.
|
superclass. Now the rewritten version is also documented.
|
||||||
|
* Source/NSComboBox.m (-mouseDown:): Reverted the use of the variable
|
||||||
|
clicked (that contributes to fix the bug explained above) and renamed it
|
||||||
|
buttonClicked.
|
||||||
|
* Headers/AppKit/NSComboBoxCell.h: Added the method
|
||||||
|
-trackMouse:inRect:ofView:untilMouseUp to have the documentation
|
||||||
|
generated for this overriden method , it shouldn't be needed( it is a
|
||||||
|
temporary hack until we have the root problem corrected).
|
||||||
|
|
||||||
2004-08-12 01:42 Alexander Malmberg <alexander@malmberg.org>
|
2004-08-12 01:42 Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
|
|
|
@ -454,7 +454,8 @@ typedef enum _NSControlSize {
|
||||||
- (void) _drawText: (NSString*)aString inFrame: (NSRect)cellFrame;
|
- (void) _drawText: (NSString*)aString inFrame: (NSRect)cellFrame;
|
||||||
- (void) _drawAttributedText: (NSAttributedString*)aString
|
- (void) _drawAttributedText: (NSAttributedString*)aString
|
||||||
inFrame: (NSRect)aRect;
|
inFrame: (NSRect)aRect;
|
||||||
|
- (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect
|
||||||
|
isFlipped: (BOOL)flipped;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -55,6 +55,12 @@
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
@interface NSButtonCell (Private)
|
||||||
|
// Overriden private internal method
|
||||||
|
- (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect
|
||||||
|
isFlipped: (BOOL)flipped;
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation NSButtonCell
|
@implementation NSButtonCell
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -942,12 +948,12 @@
|
||||||
* The drawing code below will then center the image in imageRect.
|
* The drawing code below will then center the image in imageRect.
|
||||||
*/
|
*/
|
||||||
titleRect.origin.x = cellFrame.origin.x;
|
titleRect.origin.x = cellFrame.origin.x;
|
||||||
titleRect.origin.y = cellFrame.origin.y;
|
titleRect.origin.y = cellFrame.origin.y + GSCellTextImageYDist;
|
||||||
titleRect.size.width = cellFrame.size.width;
|
titleRect.size.width = cellFrame.size.width;
|
||||||
titleRect.size.height = titleSize.height;
|
titleRect.size.height = titleSize.height;
|
||||||
|
|
||||||
imageRect.origin.x = cellFrame.origin.x;
|
imageRect.origin.x = cellFrame.origin.x;
|
||||||
imageRect.origin.y = NSMaxY(titleRect) + GSCellTextImageYDist;
|
imageRect.origin.y = NSMaxY(titleRect);
|
||||||
imageRect.size.width = cellFrame.size.width;
|
imageRect.size.width = cellFrame.size.width;
|
||||||
imageRect.size.height = NSMaxY(cellFrame) - imageRect.origin.y;
|
imageRect.size.height = NSMaxY(cellFrame) - imageRect.origin.y;
|
||||||
|
|
||||||
|
@ -1009,30 +1015,7 @@
|
||||||
// Draw image
|
// Draw image
|
||||||
if (imageToDisplay != nil)
|
if (imageToDisplay != nil)
|
||||||
{
|
{
|
||||||
NSSize size;
|
[self _drawImage: imageToDisplay inFrame: imageRect isFlipped: flippedView];
|
||||||
NSPoint position;
|
|
||||||
|
|
||||||
size = [imageToDisplay size];
|
|
||||||
position.x = MAX(NSMidX(imageRect) - (size.width / 2.), 0.);
|
|
||||||
position.y = MAX(NSMidY(imageRect) - (size.height / 2.), 0.);
|
|
||||||
/*
|
|
||||||
* Images are always drawn with their bottom-left corner at the origin
|
|
||||||
* so we must adjust the position to take account of a flipped view.
|
|
||||||
*/
|
|
||||||
if (flippedView)
|
|
||||||
{
|
|
||||||
position.y += size.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_cell.is_disabled && _image_dims_when_disabled)
|
|
||||||
{
|
|
||||||
[imageToDisplay dissolveToPoint: position fraction: 0.5];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[imageToDisplay compositeToPoint: position
|
|
||||||
operation: NSCompositeSourceOver];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw title
|
// Draw title
|
||||||
|
@ -1327,3 +1310,40 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation NSButtonCell (Private)
|
||||||
|
|
||||||
|
// Overriden private internal method
|
||||||
|
- (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect
|
||||||
|
isFlipped: (BOOL)flipped
|
||||||
|
{
|
||||||
|
// To keep partially in sync with the NSCell overriden method
|
||||||
|
|
||||||
|
NSSize size;
|
||||||
|
NSPoint position;
|
||||||
|
|
||||||
|
size = [anImage size];
|
||||||
|
position.x = MAX(NSMidX(aRect) - (size.width / 2.), 0.);
|
||||||
|
position.y = MAX(NSMidY(aRect) - (size.height / 2.), 0.);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Images are always drawn with their bottom-left corner at the origin
|
||||||
|
* so we must adjust the position to take account of a flipped view.
|
||||||
|
*/
|
||||||
|
if (flipped)
|
||||||
|
{
|
||||||
|
position.y += size.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_cell.is_disabled && _image_dims_when_disabled)
|
||||||
|
{
|
||||||
|
[anImage dissolveToPoint: position fraction: 0.5];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[anImage compositeToPoint: position
|
||||||
|
operation: NSCompositeSourceOver];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
|
@ -1664,34 +1664,21 @@ static NSColor *shadowCol;
|
||||||
switch (_cell.type)
|
switch (_cell.type)
|
||||||
{
|
{
|
||||||
case NSTextCellType:
|
case NSTextCellType:
|
||||||
{
|
[self _drawAttributedText: [self attributedStringValue]
|
||||||
[self _drawAttributedText: [self attributedStringValue]
|
inFrame: cellFrame];
|
||||||
inFrame: cellFrame];
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSImageCellType:
|
case NSImageCellType:
|
||||||
if (_cell_image)
|
if (_cell_image)
|
||||||
{
|
{
|
||||||
NSSize size;
|
[self _drawImage: _cell_image
|
||||||
NSPoint position;
|
inFrame: cellFrame
|
||||||
|
isFlipped: [controlView isFlipped]];
|
||||||
size = [_cell_image size];
|
}
|
||||||
position.x = MAX(NSMidX(cellFrame) - (size.width/2.),0.);
|
break;
|
||||||
position.y = MAX(NSMidY(cellFrame) - (size.height/2.),0.);
|
|
||||||
/*
|
|
||||||
* Images are always drawn with their bottom-left corner
|
|
||||||
* at the origin so we must adjust the position to take
|
|
||||||
* account of a flipped view.
|
|
||||||
*/
|
|
||||||
if ([controlView isFlipped])
|
|
||||||
position.y += size.height;
|
|
||||||
[_cell_image compositeToPoint: position operation: NSCompositeSourceOver];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case NSNullCellType:
|
case NSNullCellType:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_cell.shows_first_responder)
|
if (_cell.shows_first_responder)
|
||||||
|
@ -2206,6 +2193,27 @@ static NSColor *shadowCol;
|
||||||
RELEASE (attributes);
|
RELEASE (attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect
|
||||||
|
isFlipped: (BOOL)flipped
|
||||||
|
{
|
||||||
|
NSSize size;
|
||||||
|
NSPoint position;
|
||||||
|
|
||||||
|
size = [anImage size];
|
||||||
|
position.x = MAX(NSMidX(aRect) - (size.width/2.),0.);
|
||||||
|
position.y = MAX(NSMidY(aRect) - (size.height/2.),0.);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Images are always drawn with their bottom-left corner
|
||||||
|
* at the origin so we must adjust the position to take
|
||||||
|
* account of a flipped view.
|
||||||
|
*/
|
||||||
|
if (flipped)
|
||||||
|
position.y += size.height;
|
||||||
|
|
||||||
|
[anImage compositeToPoint: position operation: NSCompositeSourceOver];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -38,8 +38,10 @@
|
||||||
#include "AppKit/NSMenuItem.h"
|
#include "AppKit/NSMenuItem.h"
|
||||||
#include "AppKit/NSImage.h"
|
#include "AppKit/NSImage.h"
|
||||||
#include "AppKit/NSButton.h"
|
#include "AppKit/NSButton.h"
|
||||||
|
#include "AppKit/NSButtonCell.h"
|
||||||
#include "AppKit/NSFont.h"
|
#include "AppKit/NSFont.h"
|
||||||
#include "AppKit/NSEvent.h"
|
#include "AppKit/NSEvent.h"
|
||||||
|
#include "AppKit/NSParagraphStyle.h"
|
||||||
#include "GNUstepGUI/GSToolbar.h"
|
#include "GNUstepGUI/GSToolbar.h"
|
||||||
#include "GNUstepGUI/GSToolbarView.h"
|
#include "GNUstepGUI/GSToolbarView.h"
|
||||||
|
|
||||||
|
@ -122,16 +124,35 @@ static NSFont *SmallFont = nil;
|
||||||
- (void) setToolbarItemAction: (SEL)action;
|
- (void) setToolbarItemAction: (SEL)action;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface GSToolbarButtonCell : NSButtonCell
|
||||||
|
{
|
||||||
|
NSRect titleRect;
|
||||||
|
NSRect imageRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
// ---
|
||||||
|
|
||||||
@implementation GSToolbarButton
|
@implementation GSToolbarButton
|
||||||
|
+ (void) initialize
|
||||||
|
{
|
||||||
|
if (self == [GSToolbarButton class])
|
||||||
|
[GSToolbarButton setCellClass: [GSToolbarButtonCell class]];
|
||||||
|
}
|
||||||
|
|
||||||
- (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)
|
||||||
{
|
{
|
||||||
// Don't do an ASSIGN here, the toolbar item itself retains us.
|
// Don't do an ASSIGN here, the toolbar item itself retains us.
|
||||||
_toolbarItem = toolbarItem;
|
_toolbarItem = toolbarItem;
|
||||||
|
|
||||||
|
//[self setCell: [[GSToolbarButtonCell alloc] init]];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -280,6 +301,84 @@ static NSFont *SmallFont = nil;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation GSToolbarButtonCell
|
||||||
|
|
||||||
|
// Overriden NSButtonCell method
|
||||||
|
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
|
{
|
||||||
|
NSSize titleSize = [[self attributedTitle] size];
|
||||||
|
// We ignore alternateAttributedTitle, it is not needed
|
||||||
|
|
||||||
|
// We store the values we need to customize the drawing into titleRect and imageRect
|
||||||
|
|
||||||
|
titleRect.origin.x = cellFrame.origin.x;
|
||||||
|
titleRect.origin.y = cellFrame.origin.y + InsetItemTextY;
|
||||||
|
titleRect.size.width = cellFrame.size.width;
|
||||||
|
titleRect.size.height = titleSize.height;
|
||||||
|
|
||||||
|
imageRect.origin.x = cellFrame.origin.x;
|
||||||
|
imageRect.origin.y = cellFrame.origin.y;
|
||||||
|
if ([self imagePosition] != NSImageOnly)
|
||||||
|
imageRect.origin.y += titleRect.size.height;
|
||||||
|
imageRect.size.width = cellFrame.size.width;
|
||||||
|
imageRect.size.height = cellFrame.size.height;
|
||||||
|
if ([self imagePosition] != NSImageOnly)
|
||||||
|
imageRect.size.height -= titleRect.size.height;
|
||||||
|
|
||||||
|
[super drawInteriorWithFrame: cellFrame inView: controlView];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overriden NSCell method
|
||||||
|
- (void) _drawAttributedText: (NSAttributedString*)aString
|
||||||
|
inFrame: (NSRect)aRect
|
||||||
|
{
|
||||||
|
if (aString == nil)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/** Important: text should always be vertically centered without
|
||||||
|
* considering descender [as if descender did not exist].
|
||||||
|
* This is particularly important for single line texts.
|
||||||
|
* Please make sure the output remains always correct.
|
||||||
|
*/
|
||||||
|
// We ignore aRect value
|
||||||
|
|
||||||
|
[aString drawInRect: titleRect];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overriden NSButtonCell method
|
||||||
|
- (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect isFlipped: (BOOL)flipped
|
||||||
|
{
|
||||||
|
NSSize size;
|
||||||
|
NSPoint position;
|
||||||
|
|
||||||
|
// We ignore aRect value
|
||||||
|
|
||||||
|
size = [anImage size];
|
||||||
|
position.x = MAX(NSMidX(imageRect) - (size.width / 2.), 0.);
|
||||||
|
position.y = MAX(NSMidY(imageRect) - (size.height / 2.), 0.);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Images are always drawn with their bottom-left corner at the origin
|
||||||
|
* so we must adjust the position to take account of a flipped view.
|
||||||
|
*/
|
||||||
|
if (flipped)
|
||||||
|
{
|
||||||
|
position.y += size.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_cell.is_disabled && _image_dims_when_disabled)
|
||||||
|
{
|
||||||
|
[anImage dissolveToPoint: position fraction: 0.5];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[anImage compositeToPoint: position
|
||||||
|
operation: NSCompositeSourceOver];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Back view used to enclose toolbar item's custom view
|
* Back view used to enclose toolbar item's custom view
|
||||||
*/
|
*/
|
||||||
|
@ -322,37 +421,48 @@ static NSFont *SmallFont = nil;
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)drawRect: (NSRect)rect
|
- (void) drawRect: (NSRect)rect
|
||||||
{
|
{
|
||||||
NSAttributedString *attrString;
|
|
||||||
NSDictionary *attr;
|
|
||||||
NSColor *color;
|
|
||||||
float textX;
|
|
||||||
|
|
||||||
[super drawRect: rect]; // We draw _view which is a subview
|
[super drawRect: rect]; // We draw _view which is a subview
|
||||||
|
|
||||||
if (_enabled)
|
|
||||||
{
|
|
||||||
color = [NSColor blackColor];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
color = [NSColor disabledControlTextColor];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_showLabel)
|
if (_showLabel)
|
||||||
{
|
{
|
||||||
|
NSAttributedString *attrString;
|
||||||
|
NSDictionary *attr;
|
||||||
|
NSColor *color;
|
||||||
|
NSMutableParagraphStyle *pStyle = [NSMutableParagraphStyle defaultParagraphStyle];
|
||||||
|
NSRect titleRect;
|
||||||
|
NSRect viewBounds = [self bounds];
|
||||||
|
|
||||||
|
if (_enabled)
|
||||||
|
{
|
||||||
|
color = [NSColor blackColor];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color = [NSColor disabledControlTextColor];
|
||||||
|
}
|
||||||
|
|
||||||
|
[pStyle setAlignment: NSCenterTextAlignment];
|
||||||
|
|
||||||
// We draw the label
|
// We draw the label
|
||||||
attr = [NSDictionary dictionaryWithObjectsAndKeys: _font,
|
attr = [NSDictionary dictionaryWithObjectsAndKeys: _font,
|
||||||
NSFontAttributeName,
|
NSFontAttributeName,
|
||||||
color,
|
color,
|
||||||
NSForegroundColorAttributeName,
|
NSForegroundColorAttributeName,
|
||||||
|
pStyle,
|
||||||
|
NSParagraphStyleAttributeName,
|
||||||
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;
|
|
||||||
[attrString drawAtPoint: NSMakePoint(textX, InsetItemTextY)];
|
titleRect.origin.x = viewBounds.origin.x;
|
||||||
|
titleRect.origin.y = viewBounds.origin.y + InsetItemTextY;
|
||||||
|
titleRect.size.width = viewBounds.size.width;
|
||||||
|
titleRect.size.height = [attrString size].height;
|
||||||
|
[attrString drawInRect: titleRect];
|
||||||
|
|
||||||
DESTROY(attrString);
|
DESTROY(attrString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) layout
|
- (void) layout
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue