Migrated fontbutton.m back.

This commit is contained in:
Pietro Gagliardi 2018-03-04 19:51:45 -05:00
parent 0b3176cead
commit 1fc9f137bc
3 changed files with 20 additions and 19 deletions

View File

@ -1,7 +1,8 @@
// 14 april 2016
#import "uipriv_darwin.h"
#import "attrstr.h"
@interface fontButton : NSButton {
@interface uiprivFontButton : NSButton {
uiFontButton *libui_b;
NSFont *libui_font;
}
@ -15,16 +16,16 @@
@end
// only one may be active at one time
static fontButton *activeFontButton = nil;
static uiprivFontButton *activeFontButton = nil;
struct uiFontButton {
uiDarwinControl c;
fontButton *button;
uiprivFontButton *button;
void (*onChanged)(uiFontButton *, void *);
void *onChangedData;
};
@implementation fontButton
@implementation uiprivFontButton
- (id)initWithFrame:(NSRect)frame libuiFontButton:(uiFontButton *)b
{
@ -145,7 +146,7 @@ struct uiFontButton {
ctfont = (CTFontRef) (self->libui_font);
ctdesc = CTFontCopyFontDescriptor(ctfont);
fontdescFromCTFontDescriptor(ctdesc, uidesc);
uiprivDrawFontDescriptorFromCTFontDescriptor(ctdesc, uidesc);
CFRelease(ctdesc);
uidesc->Size = CTFontGetSize(ctfont);
}
@ -156,16 +157,16 @@ uiDarwinControlAllDefaults(uiFontButton, button)
// 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)
BOOL uiprivFontButtonInhibitSendAction(SEL sel, id from, id to)
{
if (sel != @selector(changeFont:))
return NO;
return ![to isKindOfClass:[fontButton class]];
return ![to isKindOfClass:[uiprivFontButton 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)
BOOL uiprivFontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override)
{
if (activeFontButton == nil)
return NO;
@ -177,10 +178,10 @@ BOOL fontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override)
// we also don't want the panel to be usable when there's a dialog running; see stddialogs.m for more details on that
// unfortunately the panel seems to ignore -setWorksWhenModal: so we'll have to do things ourselves
@interface nonModalFontPanel : NSFontPanel
@interface uiprivNonModalFontPanel : NSFontPanel
@end
@implementation nonModalFontPanel
@implementation uiprivNonModalFontPanel
- (BOOL)worksWhenModal
{
@ -189,9 +190,9 @@ BOOL fontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override)
@end
void setupFontPanel(void)
void uiprivSetupFontPanel(void)
{
[NSFontManager setFontPanelFactory:[nonModalFontPanel class]];
[NSFontManager setFontPanelFactory:[uiprivNonModalFontPanel class]];
}
static void defaultOnChanged(uiFontButton *b, void *data)
@ -216,7 +217,7 @@ uiFontButton *uiNewFontButton(void)
uiDarwinNewControl(uiFontButton, b);
b->button = [[fontButton alloc] initWithFrame:NSZeroRect libuiFontButton:b];
b->button = [[uiprivFontButton alloc] initWithFrame:NSZeroRect libuiFontButton:b];
uiDarwinSetControlFont(b->button, NSRegularControlSize);
uiFontButtonOnChanged(b, defaultOnChanged, NULL);

View File

@ -26,7 +26,7 @@ static BOOL stepsIsRunning;
{
if (colorButtonInhibitSendAction(sel, from, to))
return NO;
if (fontButtonInhibitSendAction(sel, from, to))
if (uiprivFontButtonInhibitSendAction(sel, from, to))
return NO;
return [super sendAction:sel to:to from:from];
}
@ -38,7 +38,7 @@ static BOOL stepsIsRunning;
{
id override;
if (fontButtonOverrideTargetForAction(sel, from, to, &override))
if (uiprivFontButtonOverrideTargetForAction(sel, from, to, &override))
return override;
return [super targetForAction:sel to:to from:from];
}
@ -126,7 +126,7 @@ const char *uiInit(uiInitOptions *o)
appDelegate().menuManager = [[menuManager new] autorelease];
[realNSApp() setMainMenu:[appDelegate().menuManager makeMenubar]];
setupFontPanel();
uiprivSetupFontPanel();
initUnderlineColors();
}

View File

@ -111,9 +111,9 @@ extern uiDrawContext *newContext(CGContextRef, CGFloat);
extern void freeContext(uiDrawContext *);
// fontbutton.m
extern BOOL fontButtonInhibitSendAction(SEL sel, id from, id to);
extern BOOL fontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override);
extern void setupFontPanel(void);
extern BOOL uiprivFontButtonInhibitSendAction(SEL sel, id from, id to);
extern BOOL uiprivFontButtonOverrideTargetForAction(SEL sel, id from, id to, id *override);
extern void uiprivSetupFontPanel(void);
// colorbutton.m
extern BOOL colorButtonInhibitSendAction(SEL sel, id from, id to);