Made the uiFontButton more robust by making it not show irrelevant controls and not affect other controls. Also sets up things for uiColorButton.

This commit is contained in:
Pietro Gagliardi 2016-04-14 14:01:33 -04:00
parent 307ec746ef
commit f1c9b2b15b
3 changed files with 48 additions and 0 deletions

View File

@ -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;

View File

@ -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?

View File

@ -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);