Le 30 mars 04, à 12:06, Quentin Mathé a écrit :
Hi Fred,
Actually when you have set the font or the title of a button cell with
the -setFont: or -setTitle: methods, you cannot anymore retrieve the
image associated with the button cell because the cell has been
converted from NSImageCellType to NSTextCellType and the -image method
is written like that :
- (NSImage*) image
{
if (_cell.type == NSImageCellType)
{
return _cell_image;
}
else
return nil;
}
The code above is in accordance with the specification. Then I propose
to not change this method but to simplify NSButtonCell -setFont:
-setTitle: like in the patch below… in order to have the cell type not
changed when you call -setFont: and -setTitle:. I propose to have the
cell type changed only by the -setImagePosition: method.
<NSButtonCell.m.patch>
We have such issue because NSButtonCell unlike NSCell can have a title
(_contents ivar with a specified font) without being an NSTextCellType
cell but an NSImageCellType cell by using an image.
What we do with this patch ?
… reply to Fred Kiefer question :
Le 30 mars 04, à 22:18, Fred Kiefer a écrit :
This patch looks dubious to me. NSButtonCell also has a method
setAttributedTitle: if this gets called and later we ask for the
title we get back an NSAttributedString where we would expect a
normal NSString. What about decoupling the contents and the title of
a button cell completely?
It was my first idea : to create a _title ivar, but I take a look at
the Cocoa header for NSButtonCell and I saw no such ivar, then I have
decided to still use the _contents ivar.
To fix the problem you are talking about… when the method -title can
return an attributed string we have the possibility to check that and
to return in such case an NSString copy from the NSAttributedString.
Otherwise if we choose to decouple the title and the contents, then we
should choose to be always an NSImageCellType or NSTextCellType cell
(currently for NSButtonCell in Cocoa, the cell type is always
NSTextCellType which is not the case with GNUstep).
What do you think of the explanations above for you question ? (I have
received no reply from you).
What should we choose to implement ?