1/*
2    PPOSXGlue_PreserveDrawColorDuringAboutPanel.m
3
4    Copyright 2013-2018 Josh Freeman
5    http://www.twilightedge.com
6
7    This file is part of PikoPixel for Mac OS X.
8    PikoPixel is a graphical application for drawing & editing pixel-art images.
9
10    PikoPixel is free software: you can redistribute it and/or modify it under
11    the terms of the GNU Affero General Public License as published by the
12    Free Software Foundation, either version 3 of the License, or (at your
13    option) any later version approved for PikoPixel by its copyright holder (or
14    an authorized proxy).
15
16    PikoPixel is distributed in the hope that it will be useful, but WITHOUT ANY
17    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18    FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19    details.
20
21    You should have received a copy of the GNU Affero General Public License
22    along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25//  On OS X 10.5 Leopard & later, opening the About Panel or clicking on its text will change
26// the shared Color Panel's color to light blue - this affects any active color wells, so if the
27// shared Color Panel is visible in order to select a document's draw color, showing or clicking
28// the About Panel will cause the document's draw color to be set to light blue.
29//  This happens because the About Panel's text views are set to use the Font Panel (even though
30// they're not editable), so any interactions with the views will automatically update the Font
31// Panel's settings, which includes updating the Color Panel with the Font Panel's current color.
32//  Workaround prevents NSTextView instances from using the Font Panel by patching
33// -[NSTextView usesFontPanel] to always return NO. Note that this disables the Font Panel for
34// ALL text views, not just the About Panel's (figuring out which text views belong to the
35// system's About Panel would be a more complicated workaround), however, this doesn't appear to
36// cause any issues, since no current text view in PikoPixel needs to use the Font Panel.
37
38#ifdef __APPLE__
39
40#import <Cocoa/Cocoa.h>
41#import "NSObject_PPUtilities.h"
42#import "PPAppBootUtilities.h"
43
44
45#define PP_RUNTIME_CHECK__ABOUT_PANEL_CAN_CAUSE_DRAW_COLOR_CHANGE       \
46            (_PP_RUNTIME_CHECK__MAC_OS_X_VERSION_IS_AT_LEAST_10_(5))
47
48
49@implementation NSObject (PPOSXGlue_PreserveDrawColorDuringAboutPanel)
50
51+ (void) ppOSXGlue_PreserveDrawColorDuringAboutPanel_InstallPatches
52{
53    macroSwizzleInstanceMethod(NSTextView, usesFontPanel, ppOSXPatch_UsesFontPanel);
54}
55
56+ (void) load
57{
58    if (PP_RUNTIME_CHECK__ABOUT_PANEL_CAN_CAUSE_DRAW_COLOR_CHANGE)
59    {
60        macroPerformNSObjectSelectorAfterAppLoads(
61                                    ppOSXGlue_PreserveDrawColorDuringAboutPanel_InstallPatches);
62    }
63}
64
65@end
66
67@implementation NSTextView (PPOSXGlue_PreserveDrawColorDuringAboutPanel)
68
69- (BOOL) ppOSXPatch_UsesFontPanel
70{
71    return NO;
72}
73
74@end
75
76#endif  // __APPLE__
77