Added `-[NSArray validateAsPropertyList]` and `-[NSDictionary validateAsPropertyList...
[adiumx.git] / Source / AIListThemePreviewCell.m
blob0467798be8de32c0f9771d16c51a4c537010a475
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "AIListThemePreviewCell.h"
18 #import "AIListThemeWindowController.h"
19 #import <AIUtilities/AIColorAdditions.h>
20 #import <AIUtilities/AIGradient.h>
21 #import <Adium/AIAbstractListController.h>
23 @implementation AIListThemePreviewCell
25 //Copy
26 - (id)copyWithZone:(NSZone *)zone
28         AIListThemePreviewCell *newCell = [super copyWithZone:zone];
29         
30         newCell->themeDict = nil;
31         [newCell setThemeDict:themeDict];
32         
33         newCell->colorKeyArray = [colorKeyArray retain];
34         
35         return newCell;
38 - (id)init
40         if ((self = [super init]))
41         {
42                 themeDict = nil;
43                 colorKeyArray = [[NSArray arrayWithObjects:
44                         KEY_LABEL_AWAY_COLOR,
45                         KEY_LABEL_IDLE_COLOR,
46                         KEY_LABEL_TYPING_COLOR,
47                         KEY_LABEL_SIGNED_OFF_COLOR,
48                         KEY_LABEL_SIGNED_ON_COLOR,
49                         KEY_LABEL_UNVIEWED_COLOR,
50                         KEY_LABEL_ONLINE_COLOR,
51                         KEY_LABEL_IDLE_AWAY_COLOR,
52                         KEY_LABEL_OFFLINE_COLOR,
53                         
54                         KEY_AWAY_COLOR,
55                         KEY_IDLE_COLOR,
56                         KEY_TYPING_COLOR,
57                         KEY_SIGNED_OFF_COLOR,
58                         KEY_SIGNED_ON_COLOR,
59                         KEY_UNVIEWED_COLOR,
60                         KEY_ONLINE_COLOR,
61                         KEY_IDLE_AWAY_COLOR,
62                         KEY_OFFLINE_COLOR,
63                         
64                         KEY_LIST_THEME_BACKGROUND_COLOR,
65                         KEY_LIST_THEME_GRID_COLOR,
66                         
67                         KEY_LIST_THEME_GROUP_BACKGROUND,
68                         KEY_LIST_THEME_GROUP_BACKGROUND_GRADIENT,
69                         nil] retain];
70         }
71                         
72         return self;
75 - (void)dealloc
77         [themeDict release];
78         [colorKeyArray release];
79         [super dealloc];
82 - (void)setThemeDict:(NSDictionary *)inDict
84         if (inDict != themeDict) {
85                 [themeDict release];
86                 themeDict = [inDict retain];
87         }
90 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
92         cellFrame.origin.y += 2;
93         cellFrame.size.height -= 4;
94         
95         NSEnumerator    *enumerator = [colorKeyArray objectEnumerator];
96         NSString                *key;
97         NSRect                  segmentRect = NSMakeRect(cellFrame.origin.x, cellFrame.origin.y,
98                                                                                          (cellFrame.size.width / [colorKeyArray count]), cellFrame.size.height);
99         
100         [[NSColor whiteColor] set];
101         [NSBezierPath fillRect:cellFrame];
102         
103         while ((key = [enumerator nextObject])) {
104                 [[[themeDict objectForKey:key] representedColor] set];
105                 [NSBezierPath fillRect:segmentRect];
106                 segmentRect.origin.x += segmentRect.size.width;
107         }
109         [[NSColor blackColor] set];
110         [NSBezierPath strokeRect:NSOffsetRect(cellFrame, .5, .5)];
111         
114 //Draw with the selected-control colours.
115 - (void)_drawHighlightWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
117         //Draw the gradient
118         AIGradient *gradient = [AIGradient selectedControlGradientWithDirection:AIVertical];
119         [gradient drawInRect:cellFrame];
120         
121         //Draw a line at the light side, to make it look a lot cleaner
122         cellFrame.size.height = 1;
123         [[NSColor alternateSelectedControlColor] set];
124         NSRectFillUsingOperation(cellFrame,NSCompositeSourceOver);
127 @end