forked from thezerobit/gnustep-gui-sony
/
GSThemeInspector.m
194 lines (166 loc) · 5.65 KB
/
GSThemeInspector.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/** <title>GSThemeInspector</title>
<abstract>Utility fgor inspecting themes</abstract>
Copyright (C) 2008 Free Software Foundation, Inc.
Author: Richard Frith-Macdonald <rfm@gnu.org>
Date: 2007,2008
This file is part of the GNU Objective C User interface library.
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.
*/
#include "AppKit/NSImageView.h"
#include "AppKit/NSScrollView.h"
#include "AppKit/NSTextField.h"
#include "AppKit/NSTextContainer.h"
#include "AppKit/NSTextView.h"
#include "AppKit/NSWindow.h"
#include "GSThemePrivate.h"
static NSTextField *
new_label (NSString *value)
{
NSTextField *t;
t = AUTORELEASE([NSTextField new]);
[t setStringValue: value];
[t setDrawsBackground: NO];
[t setEditable: NO];
[t setSelectable: NO];
[t setBezeled: NO];
[t setBordered: NO];
[t setAlignment: NSLeftTextAlignment];
return t;
}
/* Implemented in GSInfoPanel.m
* An object that displays a list of left-aligned strings (used for the authors)
*/
@interface _GSLabelListView: NSView
{
}
/* After initialization, its size is the size it needs, just move it
where we want it to show */
- (id) initWithStringArray: (NSArray *)array
font: (NSFont *)font;
@end
@implementation GSThemeInspector
static GSThemeInspector *sharedInspector = nil;
+ (GSThemeInspector*) sharedThemeInspector
{
if (sharedInspector == nil)
{
sharedInspector = [self new];
}
return sharedInspector;
}
- (id) init
{
NSRect frame;
NSView *content;
frame.size = NSMakeSize(272,388);
frame.origin = NSZeroPoint;
self = [super initWithContentRect: frame
styleMask: (NSTitledWindowMask | NSClosableWindowMask
| NSMiniaturizableWindowMask | NSResizableWindowMask)
backing: NSBackingStoreBuffered
defer: NO];
[self setReleasedWhenClosed: NO];
content = [self contentView];
return self;
}
- (void) update: (id)sender
{
GSTheme *theme = [GSTheme theme];
NSString *version;
NSString *details;
NSArray *authors;
NSView *content = [self contentView];
NSRect cFrame = [content frame];
NSView *view;
NSImageView *iv;
NSTextField *tf;
NSRect nameFrame;
NSRect frame;
while ((view = [[content subviews] lastObject]) != nil)
{
[view removeFromSuperview];
}
frame = NSMakeRect(cFrame.size.width - 58, cFrame.size.height - 58, 48, 48);
iv = [[NSImageView alloc] initWithFrame: frame];
[iv setImage: [[GSTheme theme] icon]];
[content addSubview: iv];
tf = new_label([theme name]);
[tf setFont: [NSFont boldSystemFontOfSize: 32]];
[tf sizeToFit];
nameFrame = [tf frame];
nameFrame.origin.x
= (cFrame.size.width - frame.size.width - nameFrame.size.width) / 2;
nameFrame.origin.y = cFrame.size.height - nameFrame.size.height - 25;
[tf setFrame: nameFrame];
[content addSubview: tf];
version = [[theme infoDictionary] objectForKey: @"GSThemeVersion"];
if ([version length] > 0)
{
version = [NSString stringWithFormat: @"Version: %@", version];
tf = new_label(version);
[tf setFont: [NSFont systemFontOfSize: 12]];
[tf sizeToFit];
frame = [tf frame];
frame.origin.x = (cFrame.size.width - frame.size.width) / 2;
frame.origin.y = nameFrame.origin.y - frame.size.height - 25;
[tf setFrame: frame];
[content addSubview: tf];
nameFrame = [tf frame];
}
authors = [[theme infoDictionary] objectForKey: @"GSThemeAuthors"];
if ([authors count] > 0)
{
view = [[_GSLabelListView alloc] initWithStringArray: authors
font: [NSFont systemFontOfSize: 14]];
frame = [view frame];
frame.origin.x = (cFrame.size.width - frame.size.width) / 2;
frame.origin.y = nameFrame.origin.y - frame.size.height - 25;
[view setFrame: frame];
[content addSubview: view];
}
details = [[theme infoDictionary] objectForKey: @"GSThemeDetails"];
if ([details length] > 0)
{
NSScrollView *s;
NSTextView *v;
NSRect r;
r = NSMakeRect(10, 10, cFrame.size.width - 20, frame.origin.y - 20);
s = [[NSScrollView alloc] initWithFrame: r];
[s setHasHorizontalScroller: NO];
[s setHasVerticalScroller: YES];
[s setBorderType: NSBezelBorder];
[s setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
[content addSubview: s];
RELEASE(s);
r = [[s documentView] frame];
v = [[NSTextView alloc] initWithFrame: r];
[v setBackgroundColor: [self backgroundColor]];
[v setHorizontallyResizable: YES];
[v setVerticallyResizable: YES];
[v setEditable: NO];
[v setRichText: YES];
[v setMinSize: NSMakeSize (0, 0)];
[v setMaxSize: NSMakeSize (1E7, 1E7)];
[v setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
[[v textContainer] setContainerSize:
NSMakeSize (r.size.width, 1e7)];
[[v textContainer] setWidthTracksTextView: YES];
[v setString: details];
[s setDocumentView: v];
RELEASE(v);
}
[content setNeedsDisplay: YES];
}
@end