mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 12:00:52 +00:00
clean up somewhat.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27448 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
30d220530a
commit
539faec0d3
8 changed files with 2110 additions and 1913 deletions
|
@ -4,6 +4,13 @@
|
|||
control how application help is displayed.
|
||||
* Documentation/GuiUser/DefaultsSummary.gsdoc: Document the new
|
||||
user default.
|
||||
* Source/GSTheme.m: Move stuff out into separate files.
|
||||
* Source/GSThemeInspector.m: The inspector for viewing a theme.
|
||||
* Source/GSThemePanel.m: The panel for viewing/selecting themes.
|
||||
* Source/GSThemeTools.m: Low level drawing tools.
|
||||
* Source/GSThemeDrawing.m: Methods for drawing control.
|
||||
* Source/GSThemePrivate.h: Internal API
|
||||
* Source/GNUmakefile: Changes to build new theme files.
|
||||
|
||||
2008-12-28 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
|
|
|
@ -198,6 +198,10 @@ tiff.m \
|
|||
externs.m \
|
||||
linking.m \
|
||||
GSTheme.m \
|
||||
GSThemeDrawing.m \
|
||||
GSThemeInspector.m \
|
||||
GSThemePanel.m \
|
||||
GSThemeTools.m \
|
||||
GSDragView.m \
|
||||
GSFontInfo.m \
|
||||
GSTable.m \
|
||||
|
|
1942
Source/GSTheme.m
1942
Source/GSTheme.m
File diff suppressed because it is too large
Load diff
279
Source/GSThemeDrawing.m
Normal file
279
Source/GSThemeDrawing.m
Normal file
|
@ -0,0 +1,279 @@
|
|||
/** <title>GSThemeDrawing</title>
|
||||
|
||||
<abstract>The theme methods for drawing controls</abstract>
|
||||
|
||||
Copyright (C) 2004-2008 Free Software Foundation, Inc.
|
||||
|
||||
Author: Adam Fedor <fedor@gnu.org>
|
||||
Date: Jan 2004
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#import "GSThemePrivate.h"
|
||||
#import "AppKit/NSGraphics.h"
|
||||
|
||||
|
||||
@implementation GSTheme (Drawing)
|
||||
|
||||
- (void) drawButton: (NSRect)frame
|
||||
in: (NSCell*)cell
|
||||
view: (NSView*)view
|
||||
style: (int)style
|
||||
state: (GSThemeControlState)state
|
||||
{
|
||||
GSDrawTiles *tiles = nil;
|
||||
NSColor *color = nil;
|
||||
|
||||
if (state == GSThemeNormalState)
|
||||
{
|
||||
tiles = [self tilesNamed: @"NSButtonNormal" cache: YES];
|
||||
color = [NSColor controlBackgroundColor];
|
||||
}
|
||||
else if (state == GSThemeHighlightedState)
|
||||
{
|
||||
tiles = [self tilesNamed: @"NSButtonHighlighted" cache: YES];
|
||||
color = [NSColor selectedControlColor];
|
||||
}
|
||||
else if (state == GSThemeSelectedState)
|
||||
{
|
||||
tiles = [self tilesNamed: @"NSButtonPushed" cache: YES];
|
||||
color = [NSColor selectedControlColor];
|
||||
}
|
||||
|
||||
if (tiles == nil)
|
||||
{
|
||||
switch (style)
|
||||
{
|
||||
case NSRoundRectBezelStyle:
|
||||
case NSTexturedRoundBezelStyle:
|
||||
case NSRoundedBezelStyle:
|
||||
[self drawRoundBezel: frame withColor: color];
|
||||
break;
|
||||
case NSTexturedSquareBezelStyle:
|
||||
frame = NSInsetRect(frame, 0, 1);
|
||||
case NSSmallSquareBezelStyle:
|
||||
case NSRegularSquareBezelStyle:
|
||||
case NSShadowlessSquareBezelStyle:
|
||||
[color set];
|
||||
NSRectFill(frame);
|
||||
[[NSColor controlShadowColor] set];
|
||||
NSFrameRectWithWidth(frame, 1);
|
||||
break;
|
||||
case NSThickSquareBezelStyle:
|
||||
[color set];
|
||||
NSRectFill(frame);
|
||||
[[NSColor controlShadowColor] set];
|
||||
NSFrameRectWithWidth(frame, 1.5);
|
||||
break;
|
||||
case NSThickerSquareBezelStyle:
|
||||
[color set];
|
||||
NSRectFill(frame);
|
||||
[[NSColor controlShadowColor] set];
|
||||
NSFrameRectWithWidth(frame, 2);
|
||||
break;
|
||||
case NSCircularBezelStyle:
|
||||
frame = NSInsetRect(frame, 3, 3);
|
||||
case NSHelpButtonBezelStyle:
|
||||
[self drawCircularBezel: frame withColor: color];
|
||||
break;
|
||||
case NSDisclosureBezelStyle:
|
||||
case NSRoundedDisclosureBezelStyle:
|
||||
case NSRecessedBezelStyle:
|
||||
// FIXME
|
||||
break;
|
||||
default:
|
||||
[color set];
|
||||
NSRectFill(frame);
|
||||
|
||||
if (state == GSThemeNormalState || state == GSThemeHighlightedState)
|
||||
{
|
||||
[self drawButton: frame withClip: NSZeroRect];
|
||||
}
|
||||
else if (state == GSThemeSelectedState)
|
||||
{
|
||||
[self drawGrayBezel: frame withClip: NSZeroRect];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use tiles to draw button border with central part filled with color
|
||||
*/
|
||||
[self fillRect: frame
|
||||
withTiles: tiles
|
||||
background: color
|
||||
fillStyle: GSThemeFillStyleNone];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSSize) buttonBorderForStyle: (int)style
|
||||
state: (GSThemeControlState)state
|
||||
{
|
||||
GSDrawTiles *tiles = nil;
|
||||
|
||||
if (state == GSThemeNormalState)
|
||||
{
|
||||
tiles = [self tilesNamed: @"NSButtonNormal" cache: YES];
|
||||
}
|
||||
else if (state == GSThemeHighlightedState)
|
||||
{
|
||||
tiles = [self tilesNamed: @"NSButtonHighlighted" cache: YES];
|
||||
}
|
||||
else if (state == GSThemeSelectedState)
|
||||
{
|
||||
tiles = [self tilesNamed: @"NSButtonPushed" cache: YES];
|
||||
}
|
||||
|
||||
if (tiles == nil)
|
||||
{
|
||||
switch (style)
|
||||
{
|
||||
case NSRoundRectBezelStyle:
|
||||
case NSTexturedRoundBezelStyle:
|
||||
case NSRoundedBezelStyle:
|
||||
return NSMakeSize(5, 5);
|
||||
case NSTexturedSquareBezelStyle:
|
||||
return NSMakeSize(3, 3);
|
||||
case NSSmallSquareBezelStyle:
|
||||
case NSRegularSquareBezelStyle:
|
||||
case NSShadowlessSquareBezelStyle:
|
||||
return NSMakeSize(2, 2);
|
||||
case NSThickSquareBezelStyle:
|
||||
return NSMakeSize(3, 3);
|
||||
case NSThickerSquareBezelStyle:
|
||||
return NSMakeSize(4, 4);
|
||||
case NSCircularBezelStyle:
|
||||
return NSMakeSize(5, 5);
|
||||
case NSHelpButtonBezelStyle:
|
||||
return NSMakeSize(2, 2);
|
||||
case NSDisclosureBezelStyle:
|
||||
case NSRoundedDisclosureBezelStyle:
|
||||
case NSRecessedBezelStyle:
|
||||
// FIXME
|
||||
return NSMakeSize(0, 0);
|
||||
default:
|
||||
return NSMakeSize(3, 3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSSize cls = tiles->rects[TileCL].size;
|
||||
NSSize bms = tiles->rects[TileBM].size;
|
||||
|
||||
return NSMakeSize(cls.width, bms.height);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) drawFocusFrame: (NSRect) frame view: (NSView*) view
|
||||
{
|
||||
NSDottedFrameRect(frame);
|
||||
}
|
||||
|
||||
- (void) drawWindowBackground: (NSRect) frame view: (NSView*) view
|
||||
{
|
||||
NSColor *c;
|
||||
|
||||
c = [[view window] backgroundColor];
|
||||
[c set];
|
||||
NSRectFill (frame);
|
||||
}
|
||||
|
||||
- (void) drawBorderType: (NSBorderType)aType
|
||||
frame: (NSRect)frame
|
||||
view: (NSView*)view
|
||||
{
|
||||
switch (aType)
|
||||
{
|
||||
case NSLineBorder:
|
||||
[[NSColor controlDarkShadowColor] set];
|
||||
NSFrameRect(frame);
|
||||
break;
|
||||
case NSGrooveBorder:
|
||||
[self drawGroove: frame withClip: NSZeroRect];
|
||||
break;
|
||||
case NSBezelBorder:
|
||||
[self drawWhiteBezel: frame withClip: NSZeroRect];
|
||||
break;
|
||||
case NSNoBorder:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSSize) sizeForBorderType: (NSBorderType)aType
|
||||
{
|
||||
// Returns the size of a border
|
||||
switch (aType)
|
||||
{
|
||||
case NSLineBorder:
|
||||
return NSMakeSize(1, 1);
|
||||
case NSGrooveBorder:
|
||||
case NSBezelBorder:
|
||||
return NSMakeSize(2, 2);
|
||||
case NSNoBorder:
|
||||
default:
|
||||
return NSZeroSize;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) drawBorderForImageFrameStyle: (NSImageFrameStyle)frameStyle
|
||||
frame: (NSRect)frame
|
||||
view: (NSView*)view
|
||||
{
|
||||
switch (frameStyle)
|
||||
{
|
||||
case NSImageFrameNone:
|
||||
// do nothing
|
||||
break;
|
||||
case NSImageFramePhoto:
|
||||
[self drawFramePhoto: frame withClip: NSZeroRect];
|
||||
break;
|
||||
case NSImageFrameGrayBezel:
|
||||
[self drawGrayBezel: frame withClip: NSZeroRect];
|
||||
break;
|
||||
case NSImageFrameGroove:
|
||||
[self drawGroove: frame withClip: NSZeroRect];
|
||||
break;
|
||||
case NSImageFrameButton:
|
||||
[self drawButton: frame withClip: NSZeroRect];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSSize) sizeForImageFrameStyle: (NSImageFrameStyle)frameStyle
|
||||
{
|
||||
// Get border size
|
||||
switch (frameStyle)
|
||||
{
|
||||
case NSImageFrameNone:
|
||||
default:
|
||||
return NSZeroSize;
|
||||
case NSImageFramePhoto:
|
||||
// FIXME
|
||||
return NSMakeSize(2, 2);
|
||||
case NSImageFrameGrayBezel:
|
||||
case NSImageFrameGroove:
|
||||
case NSImageFrameButton:
|
||||
return NSMakeSize(2, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
178
Source/GSThemeInspector.m
Normal file
178
Source/GSThemeInspector.m
Normal file
|
@ -0,0 +1,178 @@
|
|||
/** <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 *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];
|
||||
|
||||
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
|
||||
|
346
Source/GSThemePanel.m
Normal file
346
Source/GSThemePanel.m
Normal file
|
@ -0,0 +1,346 @@
|
|||
/** <title>GSThemePanel</title>
|
||||
|
||||
<abstract>Theme management utility</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 <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSPathUtilities.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include "AppKit/NSButton.h"
|
||||
#include "AppKit/NSMatrix.h"
|
||||
#include "AppKit/NSScrollView.h"
|
||||
#include "GSThemePrivate.h"
|
||||
|
||||
|
||||
@implementation GSThemePanel
|
||||
|
||||
static GSThemePanel *sharedPanel = nil;
|
||||
|
||||
+ (GSThemePanel*) sharedThemePanel
|
||||
{
|
||||
if (sharedPanel == nil)
|
||||
{
|
||||
sharedPanel = [self new];
|
||||
}
|
||||
return sharedPanel;
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
NSRect winFrame;
|
||||
NSRect sideFrame;
|
||||
NSRect bottomFrame;
|
||||
NSRect frame;
|
||||
NSView *container;
|
||||
NSButtonCell *proto;
|
||||
|
||||
winFrame = NSMakeRect(0, 0, 367, 420);
|
||||
sideFrame = NSMakeRect(0, 0, 95, 420);
|
||||
bottomFrame = NSMakeRect(95, 0, 272, 32);
|
||||
|
||||
self = [super initWithContentRect: winFrame
|
||||
styleMask: (NSTitledWindowMask | NSClosableWindowMask
|
||||
| NSMiniaturizableWindowMask | NSResizableWindowMask)
|
||||
backing: NSBackingStoreBuffered
|
||||
defer: NO];
|
||||
|
||||
[self setReleasedWhenClosed: NO];
|
||||
container = [self contentView];
|
||||
sideView = [[NSScrollView alloc] initWithFrame: sideFrame];
|
||||
[sideView setHasHorizontalScroller: NO];
|
||||
[sideView setHasVerticalScroller: YES];
|
||||
[sideView setBorderType: NSBezelBorder];
|
||||
[sideView setAutoresizingMask: (NSViewHeightSizable | NSViewMaxXMargin)];
|
||||
[container addSubview: sideView];
|
||||
RELEASE(sideView);
|
||||
|
||||
proto = [[NSButtonCell alloc] init];
|
||||
[proto setBordered: NO];
|
||||
[proto setAlignment: NSCenterTextAlignment];
|
||||
[proto setImagePosition: NSImageAbove];
|
||||
[proto setSelectable: NO];
|
||||
[proto setEditable: NO];
|
||||
[matrix setPrototype: proto];
|
||||
|
||||
frame = [sideView frame];
|
||||
frame.origin = NSZeroPoint;
|
||||
matrix = [[NSMatrix alloc] initWithFrame: frame
|
||||
mode: NSRadioModeMatrix
|
||||
prototype: proto
|
||||
numberOfRows: 1
|
||||
numberOfColumns: 1];
|
||||
RELEASE(proto);
|
||||
[matrix setAutosizesCells: NO];
|
||||
[matrix setCellSize: NSMakeSize(72,72)];
|
||||
[matrix setIntercellSpacing: NSMakeSize(8,8)];
|
||||
[matrix setAutoresizingMask: NSViewNotSizable];
|
||||
[matrix setMode: NSRadioModeMatrix];
|
||||
[matrix setAction: @selector(changeSelection:)];
|
||||
[matrix setTarget: self];
|
||||
|
||||
[sideView setDocumentView: matrix];
|
||||
RELEASE(matrix);
|
||||
|
||||
bottomView = [[NSView alloc] initWithFrame: bottomFrame];
|
||||
[bottomView setAutoresizingMask: (NSViewWidthSizable | NSViewMaxYMargin)];
|
||||
[container addSubview: bottomView];
|
||||
RELEASE(bottomView);
|
||||
|
||||
[self setTitle: @"Themes"];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(notified:)
|
||||
name: GSThemeDidActivateNotification
|
||||
object: nil];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(notified:)
|
||||
name: GSThemeDidDeactivateNotification
|
||||
object: nil];
|
||||
|
||||
/* Fake a notification to set the initial value for the inspector.
|
||||
*/
|
||||
[self notified:
|
||||
[NSNotification notificationWithName: GSThemeDidActivateNotification
|
||||
object: [GSTheme theme]
|
||||
userInfo: nil]];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) changeSelection: (id)sender
|
||||
{
|
||||
NSButtonCell *cell = [sender selectedCell];
|
||||
NSString *name = [cell title];
|
||||
|
||||
[GSTheme setTheme: [GSTheme loadThemeNamed: name]];
|
||||
}
|
||||
|
||||
- (void) notified: (NSNotification*)n
|
||||
{
|
||||
NSView *cView;
|
||||
GSThemeInspector *inspector;
|
||||
|
||||
inspector = (GSThemeInspector*)[[n object] themeInspector];
|
||||
cView = [self contentView];
|
||||
|
||||
if ([[n name] isEqualToString: GSThemeDidActivateNotification] == YES)
|
||||
{
|
||||
NSView *iView;
|
||||
NSRect frame;
|
||||
NSButton *button;
|
||||
NSString *dName;
|
||||
|
||||
/* Ask the inspector to ensure that it is up to date.
|
||||
*/
|
||||
[inspector update: self];
|
||||
|
||||
/* Move the inspector view into our window.
|
||||
*/
|
||||
iView = RETAIN([inspector contentView]);
|
||||
[inspector setContentView: nil];
|
||||
[cView addSubview: iView];
|
||||
RELEASE(iView);
|
||||
|
||||
/* Set inspector view to fill the frame to the right of our
|
||||
* scrollview and above the bottom view
|
||||
*/
|
||||
frame.origin.x = [sideView frame].size.width;
|
||||
frame.origin.y = [bottomView frame].size.height;
|
||||
frame.size = [cView frame].size;
|
||||
frame.size.width -= [sideView frame].size.width;
|
||||
frame.size.height -= [bottomView frame].size.height;
|
||||
[iView setFrame: frame];
|
||||
|
||||
button = [[bottomView subviews] lastObject];
|
||||
if (button == nil)
|
||||
{
|
||||
button = [NSButton new];
|
||||
[button setTarget: self];
|
||||
[button setAction: @selector(setDefault:)];
|
||||
[bottomView addSubview: button];
|
||||
RELEASE(button);
|
||||
}
|
||||
dName = [[NSUserDefaults standardUserDefaults] stringForKey: @"GSTheme"];
|
||||
if ([[[n object] name] isEqual: dName] == YES)
|
||||
{
|
||||
[button setTitle: @"Revert default theme"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[button setTitle: @"Make this the default theme"];
|
||||
}
|
||||
[button sizeToFit];
|
||||
frame = [button frame];
|
||||
frame.origin.x = ([bottomView frame].size.width - frame.size.width) / 2;
|
||||
frame.origin.y = ([bottomView frame].size.height - frame.size.height) / 2;
|
||||
[button setFrame: frame];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Restore the inspector content view.
|
||||
*/
|
||||
[inspector setContentView: [[cView subviews] lastObject]];
|
||||
}
|
||||
[cView setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
- (void) setDefault: (id)sender
|
||||
{
|
||||
NSButton *button = (NSButton*)sender;
|
||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||
NSString *cName;
|
||||
NSString *dName;
|
||||
NSRect frame;
|
||||
|
||||
dName = [defs stringForKey: @"GSTheme"];
|
||||
cName = [[GSTheme theme] name];
|
||||
|
||||
if ([cName isEqual: dName] == YES)
|
||||
{
|
||||
[defs removeObjectForKey: @"GSTheme"];
|
||||
[button setTitle: @"Make this the default theme"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[defs setObject: cName forKey: @"GSTheme"];
|
||||
[button setTitle: @"Revert default theme"];
|
||||
}
|
||||
[defs synchronize];
|
||||
[button sizeToFit];
|
||||
frame = [button frame];
|
||||
frame.origin.x = ([bottomView frame].size.width - frame.size.width) / 2;
|
||||
frame.origin.y = ([bottomView frame].size.height - frame.size.height) / 2;
|
||||
[button setFrame: frame];
|
||||
[bottomView setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
- (void) update: (id)sender
|
||||
{
|
||||
NSArray *array;
|
||||
GSTheme *theme = [GSTheme loadThemeNamed: @"GNUstep.theme"];
|
||||
|
||||
/* Avoid [NSMutableSet set] that confuses GCC 3.3.3. It seems to confuse
|
||||
* this static +(id)set method with the instance -(void)set, so it would
|
||||
* refuse to compile saying
|
||||
* GSTheme.m:1565: error: void value not ignored as it ought to be
|
||||
*/
|
||||
NSMutableSet *set = AUTORELEASE([NSMutableSet new]);
|
||||
|
||||
NSString *selected = RETAIN([[matrix selectedCell] title]);
|
||||
unsigned existing = [[matrix cells] count];
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSEnumerator *enumerator;
|
||||
NSString *path;
|
||||
NSString *name;
|
||||
NSButtonCell *cell;
|
||||
unsigned count = 0;
|
||||
|
||||
/* Ensure the first cell contains the default theme.
|
||||
*/
|
||||
cell = [matrix cellAtRow: count++ column: 0];
|
||||
[cell setImage: [theme icon]];
|
||||
[cell setTitle: [theme name]];
|
||||
|
||||
/* Go through all the themes in the standard locations and find their names.
|
||||
*/
|
||||
enumerator = [NSSearchPathForDirectoriesInDomains
|
||||
(NSAllLibrariesDirectory, NSAllDomainsMask, YES) objectEnumerator];
|
||||
while ((path = [enumerator nextObject]) != nil)
|
||||
{
|
||||
NSEnumerator *files;
|
||||
NSString *file;
|
||||
|
||||
path = [path stringByAppendingPathComponent: @"Themes"];
|
||||
files = [[mgr directoryContentsAtPath: path] objectEnumerator];
|
||||
while ((file = [files nextObject]) != nil)
|
||||
{
|
||||
NSString *ext = [file pathExtension];
|
||||
|
||||
name = [file stringByDeletingPathExtension];
|
||||
if ([ext isEqualToString: @"theme"] == YES
|
||||
&& [name isEqualToString: @"GNUstep"] == NO)
|
||||
{
|
||||
[set addObject: name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Sort theme names alphabetically, and add each theme to the matrix.
|
||||
*/
|
||||
array = [[set allObjects] sortedArrayUsingSelector:
|
||||
@selector(caseInsensitiveCompare:)];
|
||||
enumerator = [array objectEnumerator];
|
||||
while ((name = [enumerator nextObject]) != nil)
|
||||
{
|
||||
GSTheme *loaded;
|
||||
|
||||
loaded = [GSTheme loadThemeNamed: name];
|
||||
if (loaded != nil)
|
||||
{
|
||||
if (count >= existing)
|
||||
{
|
||||
[matrix addRow];
|
||||
existing++;
|
||||
}
|
||||
cell = [matrix cellAtRow: count column: 0];
|
||||
[cell setImage: [loaded icon]];
|
||||
[cell setTitle: [loaded name]];
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Empty any unused cells.
|
||||
*/
|
||||
while (count < existing)
|
||||
{
|
||||
cell = [matrix cellAtRow: count column: 0];
|
||||
[cell setImage: nil];
|
||||
[cell setTitle: @""];
|
||||
count++;
|
||||
}
|
||||
|
||||
/* Restore the selected cell.
|
||||
*/
|
||||
array = [matrix cells];
|
||||
count = [array count];
|
||||
while (count-- > 0)
|
||||
{
|
||||
cell = [matrix cellAtRow: count column: 0];
|
||||
if ([[cell title] isEqual: selected])
|
||||
{
|
||||
[matrix selectCellAtRow: count column: 0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
RELEASE(selected);
|
||||
[matrix sizeToCells];
|
||||
[matrix setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
@end
|
||||
|
150
Source/GSThemePrivate.h
Normal file
150
Source/GSThemePrivate.h
Normal file
|
@ -0,0 +1,150 @@
|
|||
/** <title>GSThemePrivate</title>
|
||||
|
||||
<abstract>Private utilities for GSTheme</abstract>
|
||||
|
||||
Copyright (C) 2007,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.
|
||||
*/
|
||||
|
||||
#import "AppKit/NSPanel.h"
|
||||
#import "GNUstepGUI/GSTheme.h"
|
||||
|
||||
@class NSImage, NSMatrix, NSScrollView, NSView;
|
||||
|
||||
/** These are the nine types of tile used to draw a rectangular object.
|
||||
*/
|
||||
typedef enum {
|
||||
TileTL = 0, /** Top left corner */
|
||||
TileTM = 1, /** Top middle section */
|
||||
TileTR = 2, /** Top right corner */
|
||||
TileCL = 3, /** Centerj left corner */
|
||||
TileCM = 4, /** Centerj middle section */
|
||||
TileCR = 5, /** Centerj right corner */
|
||||
TileBL = 6, /** Bottom left corner */
|
||||
TileBM = 7, /** Bottom middle section */
|
||||
TileBR = 8 /** Bottom right corner */
|
||||
} GSThemeTileOffset;
|
||||
|
||||
/** This is a trivial class to hold the nine tiles needed to draw a rectangle
|
||||
*/
|
||||
@interface GSDrawTiles : NSObject
|
||||
{
|
||||
@public
|
||||
NSImage *images[9]; /** The tile images */
|
||||
NSRect rects[9]; /** The rectangles to use when drawing */
|
||||
}
|
||||
- (id) copyWithZone: (NSZone*)zone;
|
||||
|
||||
/* Initialise with a single image assuming division into nine equally
|
||||
* sized sections.
|
||||
*/
|
||||
- (id) initWithImage: (NSImage*)image;
|
||||
|
||||
/* Initialise with a single image divided x pixels in from either end on
|
||||
* the horizontal, and y pixels in from either end on the vertical.
|
||||
*/
|
||||
- (id) initWithImage: (NSImage*)image horizontal: (float)x vertical: (float)y;
|
||||
|
||||
/* Scale the images up by the specified factor.
|
||||
*/
|
||||
- (void) scaleUp: (int)multiple;
|
||||
@end
|
||||
|
||||
/** This is the panel used to select and inspect themes.
|
||||
*/
|
||||
@interface GSThemePanel : NSPanel
|
||||
{
|
||||
NSMatrix *matrix; // Not retained.
|
||||
NSScrollView *sideView; // Not retained.
|
||||
NSView *bottomView; // Not retained.
|
||||
}
|
||||
|
||||
/** Return the shared panel.
|
||||
*/
|
||||
+ (GSThemePanel*) sharedThemePanel;
|
||||
|
||||
/** Update current theme to the one clicked on in the matrix.
|
||||
*/
|
||||
- (void) changeSelection: (id)sender;
|
||||
|
||||
/** Handle notifications
|
||||
*/
|
||||
- (void) notified: (NSNotification*)n;
|
||||
|
||||
/** Toggle whether the current theme is the default theme.
|
||||
*/
|
||||
- (void) setDefault: (id)sender;
|
||||
|
||||
/** Update list of available themes.
|
||||
*/
|
||||
- (void) update: (id)sender;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
/** This is the window used to inspect themes.
|
||||
*/
|
||||
@interface GSThemeInspector : NSWindow
|
||||
{
|
||||
}
|
||||
|
||||
/** Return the shared panel.
|
||||
*/
|
||||
+ (GSThemeInspector*) sharedThemeInspector;
|
||||
|
||||
/** Update to show current theme.
|
||||
*/
|
||||
- (void) update: (id)sender;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
/** This category defines private methods for internal use by GSTheme
|
||||
*/
|
||||
@interface GSTheme (internal)
|
||||
/**
|
||||
* Called whenever user defaults are changed ... this checks for the
|
||||
* GSTheme user default and ensures that the specified theme is the
|
||||
* current active theme.
|
||||
*/
|
||||
+ (void) defaultsDidChange: (NSNotification*)n;
|
||||
|
||||
/**
|
||||
* Called to load specified theme.<br />
|
||||
* If aName is nil or an empty string or 'GNUstep',
|
||||
* this returns the default theme.<br />
|
||||
* If the named is a full path specification, this uses that path.<br />
|
||||
* Otherwise this method searches the standard locations.<br />
|
||||
* Returns nil on failure.
|
||||
*/
|
||||
+ (GSTheme*) loadThemeNamed: (NSString*)aName;
|
||||
|
||||
// These two drawing method may be made public later on
|
||||
- (void) drawCircularBezel: (NSRect)cellFrame
|
||||
withColor: (NSColor*)backgroundColor;
|
||||
- (void) drawRoundBezel: (NSRect)cellFrame
|
||||
withColor: (NSColor*)backgroundColor;
|
||||
@end
|
||||
|
1117
Source/GSThemeTools.m
Normal file
1117
Source/GSThemeTools.m
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue