diff --git a/ChangeLog b/ChangeLog index 32dd60cab..9a678aac8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2004-04-02 Quentin Mathe + + With the help of Fred Kiefer and Alexander Malmberg, the modifications + below are mainly introduced to fix the fact -[NSCell performClick:] + doesn't work correctly when the cell frame is not identical to the control + frame which is displaying it : + * Source/NSButton.m: Removed -performClick: method already present in + the superclass NSControl. + * Headers/AppKit/NSButton.h: Same. + * Source/NSButtonCell.m: Replaced -performClick: method by + -performClickWithFrame:inView: method which overrides new method with + the same name in the superclass NSCell. + * Headers/AppKit/NSButtonCell.h: Same + * Source/NSCell.m: Added a method -performClickWithFrame:inView: + to be used in place of -performClick: method which has been deprecated. + * Headers/AppKit/NSCell.h: Same + * Source/NSControl.m: Modified -performClick: method to use the new + NSCell method -performClickWithFrame:inView:. + * Source/NSPopUpButtonCell.m: Modified -performClickWithFrame:inView: to + override the new method with the same name in the superclass NSCell. + 2004-04-02 Quentin Mathe * Source/NSWindow+Toolbar.h: Moved into Headers/AppKit diff --git a/Headers/AppKit/NSButton.h b/Headers/AppKit/NSButton.h index cb3a48496..d6f57520d 100644 --- a/Headers/AppKit/NSButton.h +++ b/Headers/AppKit/NSButton.h @@ -122,7 +122,6 @@ // // Handling Events and Action Messages // -- (void)performClick:(id)sender; - (BOOL)performKeyEquivalent:(NSEvent *)anEvent; // diff --git a/Headers/AppKit/NSButtonCell.h b/Headers/AppKit/NSButtonCell.h index 8274c4f2e..51894149e 100644 --- a/Headers/AppKit/NSButtonCell.h +++ b/Headers/AppKit/NSButtonCell.h @@ -183,7 +183,6 @@ typedef enum _NSGradientType { #ifndef STRICT_OPENSTEP - (void)mouseEntered:(NSEvent *)event; - (void)mouseExited:(NSEvent *)event; -- (void)performClick:(id)sender; #endif @end diff --git a/Headers/AppKit/NSCell.h b/Headers/AppKit/NSCell.h index 0a70631d2..44b8c9ea2 100644 --- a/Headers/AppKit/NSCell.h +++ b/Headers/AppKit/NSCell.h @@ -333,7 +333,12 @@ typedef enum _NSControlSize { - (unsigned int)mnemonicLocation; - (BOOL)refusesFirstResponder; - (void)setRefusesFirstResponder:(BOOL)flag; -- (void)performClick:(id)sender; + +// deprecated method now in favor of performClickWithFrame:inView: +- (void)performClick:(id)sender; + +- (void)performClickWithFrame: (NSRect)cellFrame + inView: (NSView *)controlView; #endif // diff --git a/Source/NSButton.m b/Source/NSButton.m index adebfeb37..d33e19a24 100644 --- a/Source/NSButton.m +++ b/Source/NSButton.m @@ -387,11 +387,6 @@ static id buttonCellClass = nil; // Handling Events and Action Messages // -- (void) performClick: (id)sender -{ - [_cell performClick: sender]; -} - - (BOOL) performKeyEquivalent: (NSEvent *)anEvent { if ([self isEnabled]) diff --git a/Source/NSButtonCell.m b/Source/NSButtonCell.m index aedc44b33..b8c98d06e 100644 --- a/Source/NSButtonCell.m +++ b/Source/NSButtonCell.m @@ -1081,13 +1081,19 @@ [(NSView *)[event userData] setNeedsDisplay: YES]; } -- (void) performClick: (id)sender +/** + * Simulates a single mouse click on the button cell. This method overrides the + * cell method performClickWithFrame:inView: to add the possibility to play a sound + * associated with the click. + */ +- (void) performClickWithFrame: (NSRect)cellFrame inView: (NSView *)controlView { if (_sound != nil) { [_sound play]; } - [super performClick: sender]; + + [super performClickWithFrame: cellFrame inView: controlView]; } /* diff --git a/Source/NSCell.m b/Source/NSCell.m index 824ba6584..eda68e836 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -1143,41 +1143,57 @@ static NSColor *shadowCol; _cell.refuses_first_responder = flag; } +/** + * Simulates a single click in the cell (only works with controls which have + * no more than one cell). This method is deprecated, + * performClickWithFrame:inView: is the right method to use now. + */ - (void) performClick: (id)sender { - SEL action = [self action]; NSView *cv = [self controlView]; + if (cv != nil) + [self performClickWithFrame: [cv bounds] inView: cv]; +} + +/** + * Simulates a single click in the cell. The display of the cell with this event + * occurs in the area delimited by cellFrame within + * controlView. + */ +- (void) performClickWithFrame: (NSRect)cellFrame inView: (NSView *)controlView +{ + SEL action = [self action]; + if(_cell.is_disabled == YES) { return; } - if (cv != nil) + if (controlView != nil) { - NSRect cvBounds = [cv bounds]; - NSWindow *cvWin = [cv window]; + NSWindow *cvWin = [controlView window]; - [cv lockFocus]; + [controlView lockFocus]; [self setNextState]; - [self highlight: YES withFrame: cvBounds inView: cv]; + [self highlight: YES withFrame: cellFrame inView: controlView]; [cvWin flushWindow]; // Wait approx 1/10 seconds [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]]; - [self highlight: NO withFrame: cvBounds inView: cv]; + [self highlight: NO withFrame: cellFrame inView: controlView]; [cvWin flushWindow]; - [cv unlockFocus]; + [controlView unlockFocus]; if (action) { NS_DURING { - [(NSControl*)cv sendAction: action to: [self target]]; + [(NSControl*)controlView sendAction: action to: [self target]]; } NS_HANDLER { diff --git a/Source/NSControl.m b/Source/NSControl.m index f3bd2c22d..1940ccd37 100644 --- a/Source/NSControl.m +++ b/Source/NSControl.m @@ -509,9 +509,15 @@ static Class actionCellClass; /* * Activation */ + +/** + * Simulates a single mouse click on the control. This method calls the cell's + * method performClickWithFrame:inView:. Take note that sender is not + * used. + */ - (void) performClick: (id)sender { - [_cell performClick: sender]; + [_cell performClickWithFrame: [self bounds] inView: self]; } - (BOOL)refusesFirstResponder diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m index f55aabf6a..93079abe8 100644 --- a/Source/NSPopUpButtonCell.m +++ b/Source/NSPopUpButtonCell.m @@ -633,50 +633,24 @@ static NSImage *_pbc_image[2]; return NO; } -// This method is called to simulate programmatically a click -// [as NSCell's performClick:] -// This method is not executed upon mouse down; rather, it should -// simulate what would happen upon mouse down. It should not start -// any real mouse tracking. -- (void) performClickWithFrame: (NSRect)frame - inView: (NSView *)controlView -{ - NSWindow *cvWin = [controlView window]; - - if(_cell.is_disabled == YES) - { - return; - } - - [controlView lockFocus]; - - [self setNextState]; - [self highlight: YES withFrame: frame inView: controlView]; - [cvWin flushWindow]; - - // Wait approx 1/10 seconds - [[NSRunLoop currentRunLoop] - runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]]; - - [self highlight: NO withFrame: frame inView: controlView]; - [cvWin flushWindow]; - - [controlView unlockFocus]; - +// This method is called to simulate programmatically a click by overriding +// -[NSCell performClickWithFrame:inView:] +// This method is not executed upon mouse down; rather, it should simulate what +// would happen upon mouse down. It should not start any real mouse tracking. +/** + * Simulates a single click in the pop up button cell (the display of the cell + * with this event occurs in the area delimited by frame in the view + * controlView) and displays the popup button cell menu attached to + * the view controlView, the menu width depends on the + * frame width value. + */ +- (void) performClickWithFrame: (NSRect)frame inView: (NSView *)controlView +{ + [super performClickWithFrame: frame inView: controlView]; + [self attachPopUpWithFrame: frame inView: controlView]; } -- (void) performClick: (id)sender -{ - NSView *cv = [self controlView]; - - if (cv != nil) - { - [self performClickWithFrame: [cv bounds] - inView: cv]; - } -} - // Arrow position for bezel style and borderless popups. - (NSPopUpArrowPosition) arrowPosition {