-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathWinNSButton.m
170 lines (145 loc) · 4.71 KB
/
WinNSButton.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* WINUXTheme A native Windows XP theme for GNUstep
Copyright (C) 2009 Free Software Foundation, Inc.
Written by: Fred Kiefer <[email protected]>
Riccardo Mottola <[email protected]>
Date: October 2009
Based on ideas:
Copyright (C) 2007 Christopher Armstrong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#import <AppKit/AppKit.h>
#import "WinUXTheme.h"
@implementation WinUXTheme (NSButton)
static int _ButtonStateForThemeControlState(GSThemeControlState state)
{
switch (state)
{
case GSThemeHighlightedState:
return PBS_DEFAULTED;
case GSThemeSelectedState:
return PBS_PRESSED;
case GSThemeDisabledState:
return PBS_DISABLED;
case GSThemeNormalState:
default:
return PBS_NORMAL;
}
}
- (void) drawButton: (NSRect) frame
in: (NSCell*) cell
view: (NSView*) view
style: (int) style
state: (GSThemeControlState) state
{
if(!IsThemeActive())
{
[super drawButton: frame
in: cell
view: view
style: style
state: state];
return;
}
HTHEME hTheme = [self themeWithClassName: @"button"];
int drawState = _ButtonStateForThemeControlState(state);
if (![self drawThemeBackground: hTheme
inRect: frame
part: BP_PUSHBUTTON
state: drawState])
{
[super drawButton: frame
in: cell
view: view
style: style
state: state];
}
[self releaseTheme: hTheme];
}
- (GSThemeMargins) buttonMarginsForCell: (NSCell*)cell
style: (int)style
state: (GSThemeControlState)state
{
GSThemeMargins margins = { 0 };
switch (style)
{
case NSRoundRectBezelStyle:
margins = [super buttonMarginsForCell:cell style:style state:state];
break;
case NSTexturedRoundedBezelStyle:
if ([cell imagePosition] == NSNoImage)
{
if ([cell controlSize] == NSRegularControlSize)
{
margins.left = 10; margins.top = 7; margins.right = 10; margins.bottom = 7;
}
else if ([cell controlSize] == NSSmallControlSize)
{
margins.left = 8; margins.top = 6; margins.right = 8; margins.bottom = 6;
}
}
break;
case NSRoundedBezelStyle:
{
if ([cell controlSize] == NSRegularControlSize)
{
margins.left = 10; margins.top = 7; margins.right = 10; margins.bottom = 7;
}
else if ([cell controlSize] == NSSmallControlSize)
{
margins.left = 8; margins.top = 6; margins.right = 8; margins.bottom = 6;
}
}
break;
case NSTexturedSquareBezelStyle:
margins = [super buttonMarginsForCell:cell style:style state:state];
break;
case NSRegularSquareBezelStyle:
break;
case NSShadowlessSquareBezelStyle:
case NSThickSquareBezelStyle:
case NSThickerSquareBezelStyle:
// Currently defaulting to super's margins...
margins = [super buttonMarginsForCell:cell style:style state:state];
break;
case NSCircularBezelStyle:
#if 0 // Apple doesn't seem to inset and/or draw a border around these...
{
if ([cell controlSize] == NSRegularControlSize)
{
margins.left = 10; margins.top = 9; margins.right = 10; margins.bottom = 9;
}
else if ([cell controlSize] == NSSmallControlSize)
{
margins.left = 8; margins.top = 7; margins.right = 8; margins.bottom = 7;
}
else if ([cell controlSize] == NSMiniControlSize)
{
margins.left = 7; margins.top = 6; margins.right = 7; margins.bottom = 6;
}
}
#endif
break;
case NSHelpButtonBezelStyle:
case NSDisclosureBezelStyle:
case NSRoundedDisclosureBezelStyle:
case NSRecessedBezelStyle:
// Currently defaulting to super's margins...
default:
margins = [super buttonMarginsForCell:cell style:style state:state];
break;
}
return margins;
}
@end