Copy of osx-environment at 9993042d6
[windows-environment.git] / Patches / wxwidgets-checkbox-colours.patch
1 --- src/osx/cocoa/window.mm.orig        2018-01-05 11:08:33.000000000 +0000
2 +++ src/osx/cocoa/window.mm     2018-01-05 11:11:17.000000000 +0000
3 @@ -2444,6 +2444,63 @@
4  
5  void wxWidgetCocoaImpl::SetLabel( const wxString& title, wxFontEncoding encoding )
6  {
7 +    if ( [m_osxView respondsToSelector:@selector(setAttributedTitle:) ] )
8 +    {
9 +        wxFont f = GetWXPeer()->GetFont();
10 +        // we should not override system font colors unless explicitly specified
11 +        wxColour col = GetWXPeer()->UseFgCol() ? GetWXPeer()->GetForegroundColour() : wxNullColour;
12 +        if ( f.GetStrikethrough() || f.GetUnderlined() || col.IsOk() )
13 +        {
14 +            wxCFStringRef cf(title, encoding );
15 +
16 +            NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]
17 +                                                     initWithString:cf.AsNSString()];
18 +
19 +            [attrString beginEditing];
20 +
21 +            NSTextAlignment textAlign;
22 +            if ( [m_osxView isKindOfClass:[NSControl class]] )
23 +                textAlign = [(id)m_osxView alignment];
24 +            else
25 +                textAlign = NSCenterTextAlignment;
26 +            [attrString setAlignment:textAlign
27 +                               range:NSMakeRange(0, [attrString length])];
28 +
29 +            [attrString addAttribute:NSFontAttributeName
30 +                               value:f.OSXGetNSFont()
31 +                               range:NSMakeRange(0, [attrString length])];
32 +            if ( f.GetStrikethrough() )
33 +            {
34 +                [attrString addAttribute:NSStrikethroughStyleAttributeName
35 +                                   value:@(NSUnderlineStyleSingle)
36 +                                   range:NSMakeRange(0, [attrString length])];
37 +            }
38 +
39 +            if ( f.GetUnderlined() )
40 +            {
41 +                [attrString addAttribute:NSUnderlineStyleAttributeName
42 +                                   value:@(NSUnderlineStyleSingle)
43 +                                   range:NSMakeRange(0, [attrString length])];
44 +
45 +            }
46 +
47 +            if ( col.IsOk() )
48 +            {
49 +                [attrString addAttribute:NSForegroundColorAttributeName
50 +                                   value:col.OSXGetNSColor()
51 +                                   range:NSMakeRange(0, [attrString length])];
52 +            }
53 +
54 +            [attrString endEditing];
55 +
56 +            [(id)m_osxView setAttributedTitle:attrString];
57 +            
58 +            [attrString release];
59 +
60 +            return;
61 +        }
62 +    }
63 +
64      if ( [m_osxView respondsToSelector:@selector(setTitle:) ] )
65      {
66          wxCFStringRef cf( title , encoding );
67 @@ -2683,13 +2740,13 @@
68      if ( [m_osxView isKindOfClass:[NSScrollView class] ] )
69          targetView = [(NSScrollView*) m_osxView documentView];
70  
71 +
72      if ([targetView respondsToSelector:@selector(setFont:)])
73          [targetView setFont: font.OSXGetNSFont()];
74      if ([targetView respondsToSelector:@selector(setTextColor:)])
75 -        [targetView setTextColor:[NSColor colorWithCalibratedRed:(CGFloat) (col.Red() / 255.0)
76 -                                                                 green:(CGFloat) (col.Green() / 255.0)
77 -                                                                  blue:(CGFloat) (col.Blue() / 255.0)
78 -                                                                 alpha:(CGFloat) (col.Alpha() / 255.0)]];
79 +        [targetView setTextColor: col.OSXGetNSColor()];
80 +    if ([m_osxView respondsToSelector:@selector(setAttributedTitle:)])
81 +        SetLabel(wxStripMenuCodes(GetWXPeer()->GetLabel(), wxStrip_Mnemonics), GetWXPeer()->GetFont().GetEncoding());
82  }
83  
84  void wxWidgetCocoaImpl::SetToolTip(wxToolTip* tooltip)
85 --- include/wx/window.h.orig    2018-01-05 11:38:33.000000000 +0000
86 +++ include/wx/window.h 2018-01-05 11:38:59.000000000 +0000
87 @@ -1089,6 +1089,10 @@
88      {
89          return m_hasBgCol;
90      }
91 +    bool UseFgCol() const
92 +    {
93 +        return m_hasFgCol;
94 +    }
95  
96      virtual bool SetForegroundColour(const wxColour& colour);
97      void SetOwnForegroundColour(const wxColour& colour)
98 --- interface/wx/window.h.orig  2018-01-05 11:37:43.000000000 +0000
99 +++ interface/wx/window.h       2018-01-05 11:38:18.000000000 +0000
100 @@ -2060,6 +2060,8 @@
101      */
102      bool UseBgCol() const;
103  
104 +    bool UseFgCol() const;
105 +
106      /**
107          Sets the font of the window but prevents it from being inherited by the
108          children of this window.