Rewritten part of performClick: to avoid various problems (crashing

included) when there is no control view.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5030 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
nico 1999-10-18 22:50:40 +00:00
parent be81d56e2e
commit ca0920e81a

View file

@ -824,32 +824,28 @@ static Class cellClass;
- (void) performClick: (id)sender - (void) performClick: (id)sender
{ {
NSView *cv; SEL action = [self action];
NSRect cvBounds;
NSWindow *cvWin;
if (control_view) if (control_view)
cv = control_view; {
else NSRect cvBounds = [control_view bounds];
cv = [NSView focusView]; NSWindow *cvWin = [control_view window];
cvBounds = [cv bounds]; [self highlight: YES withFrame: cvBounds inView: control_view];
cvWin = [cv window];
[self highlight: YES withFrame: cvBounds inView: cv];
[cvWin flushWindow]; [cvWin flushWindow];
// Wait approx 1/5 seconds
// Wait approx 1/10 seconds
[[NSRunLoop currentRunLoop] [[NSRunLoop currentRunLoop]
runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.2]]; runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.1]];
[self highlight: NO withFrame: cvBounds inView: cv]; [self highlight: NO withFrame: cvBounds inView: control_view];
[cvWin flushWindow]; [cvWin flushWindow];
if ([self action]) if (action)
{ {
NS_DURING NS_DURING
{ {
[(NSControl*)cv sendAction: [self action] to: [self target]]; [(NSControl *)control_view sendAction: action to: [self target]];
} }
NS_HANDLER NS_HANDLER
{ {
@ -857,6 +853,24 @@ static Class cellClass;
} }
NS_ENDHANDLER NS_ENDHANDLER
} }
}
else // We have no control view. The best we can do is the following.
{
if (action)
{
NS_DURING
{
[[NSApplication sharedApplication] sendAction: action
to: [self target]
from: self];
}
NS_HANDLER
{
[localException raise];
}
NS_ENDHANDLER
}
}
} }
/* /*
* Assigning a Tag * Assigning a Tag