diff --git a/darwin/fontbutton.m b/darwin/fontbutton.m index 0b380117..8206459f 100644 --- a/darwin/fontbutton.m +++ b/darwin/fontbutton.m @@ -119,6 +119,27 @@ uiDarwinDefineControl( @end +// we do not want font change events to be sent to any controls other than the font buttons +// see main.m for more details +BOOL fontButtonInhibitSendAction(SEL sel, id from, id to) +{ + if (sel != @selector(changeFont:)) + return NO; + return ![to isKindOfClass:[fontButton class]]; +} + +// we do not want NSFontPanelValidation messages to be sent to any controls other than the font buttons when a font button is active +// see main.m for more details +BOOL fontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override) +{ + if (activeFontButton == nil) + return NO; + if (sel != @selector(validModesForFontPanel:)) + return NO; + *override = activeFontButton; + return YES; +} + uiFontButton *uiNewFontButton(void) { uiFontButton *b; diff --git a/darwin/main.m b/darwin/main.m index 623deb99..08f33ab9 100644 --- a/darwin/main.m +++ b/darwin/main.m @@ -12,6 +12,29 @@ static BOOL canQuit = NO; [super sendEvent:e]; } +// NSColorPanel always sends changeColor: to the first responder regardless of whether there's a target set on it +// we can override it here (see colorbutton.m) +// thanks to mikeash in irc.freenode.net/#macdev for informing me this is how the first responder chain is initiated +// it turns out NSFontManager also sends changeFont: through this; let's inhibit that here too (see fontbutton.m) +- (BOOL)sendAction:(SEL)sel to:(id)to from:(id)from +{ + if (fontButtonInhibitSendAction(sel, from, to)) + return NO; + return [super sendAction:sel to:to from:from]; +} + +// likewise, NSFontManager also sends NSFontPanelValidation messages to the first responder, however it does NOT use sendAction:from:to:! +// instead, it uses this one (thanks swillits in irc.freenode.net/#macdev) +// we also need to override it (see fontbutton.m) +- (id)targetForAction:(SEL)sel to:(id)to from:(id)from +{ + id override; + + if (fontButtonOverrideTargetForAction(sel, from, to, &override)) + return override; + return [super targetForAction:sel to:to from:from]; +} + // hey look! we're overriding terminate:! // we're going to make sure we can go back to main() whether Cocoa likes it or not! // and just how are we going to do that, hm? diff --git a/darwin/uipriv_darwin.h b/darwin/uipriv_darwin.h index 9442083b..1c912188 100644 --- a/darwin/uipriv_darwin.h +++ b/darwin/uipriv_darwin.h @@ -83,3 +83,7 @@ extern void freeContext(uiDrawContext *); // drawtext.m extern void doDrawText(CGContextRef c, CGFloat cheight, double x, double y, uiDrawTextLayout *layout); + +// fontbutton.m +extern BOOL fontButtonInhibitSendAction(SEL sel, id from, id to); +extern BOOL fontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override);