Prevent sending 0-byte files. Fixes #8711.
[adiumx.git] / Source / AITextColorPreviewView.m
blob117bd3a04508e762994f7c0eddadb901bf40d250
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 "AITextColorPreviewView.h"
18 #import <AIUtilities/AIStringUtilities.h>
19 #import <AIUtilities/AIGradient.h>
20 #import <AIUtilities/AIParagraphStyleAdditions.h>
21 #import <AIUtilities/AIApplicationAdditions.h>
23 @interface AITextColorPreviewView (PRIVATE)
24 - (void)_initTextColorPreviewView;
25 @end
27 @implementation AITextColorPreviewView
29 - (id)initWithCoder:(NSCoder *)aDecoder
31     [super initWithCoder:aDecoder];
32     [self _initTextColorPreviewView];
33     return self;
36 - (id)initWithFrame:(NSRect)frameRect
38     [super initWithFrame:frameRect];
39     [self _initTextColorPreviewView];
40     return self;
43 - (void)_initTextColorPreviewView
45         backColorOverride = nil;
48 - (void)drawRect:(NSRect)rect
50         NSMutableDictionary     *attributes;
51         NSAttributedString      *sample;
52         NSShadow                        *shadow = nil;
53         NSSize                          sampleSize;
54         
55         //Background
56         if ([backgroundEnabled state] != NSOffState) {
57                 if (backgroundGradientColor) {
58                         [[AIGradient gradientWithFirstColor:[backgroundGradientColor color]
59                                                                    secondColor:[backgroundColor color]
60                                                                          direction:AIVertical] drawInRect:rect];
61                 } else {
62                         [(backColorOverride ? backColorOverride : [backgroundColor color]) set];
63                         [NSBezierPath fillRect:rect];
64                 }
65         }
67         //Shadow
68         if (([textShadowColorEnabled state] != NSOffState) && [textShadowColor color]) {
69                 shadow = [[[NSShadow alloc] init] autorelease];
70                 [shadow setShadowOffset:NSMakeSize(0.0, -1.0)];
71                 [shadow setShadowBlurRadius:2.0];
72                 [shadow setShadowColor:[textShadowColor color]];
73         }
75         //Text
76         attributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
77                 [NSFont systemFontOfSize:12], NSFontAttributeName,
78                 [NSParagraphStyle styleWithAlignment:NSCenterTextAlignment], NSParagraphStyleAttributeName,
79                 [textColor color], NSForegroundColorAttributeName,
80                 shadow, NSShadowAttributeName,
81                 nil];
82         
83         sample = [[[NSAttributedString alloc] initWithString:AILocalizedString(@"Sample",nil)
84                                                                                           attributes:attributes] autorelease];
85         sampleSize = [sample size];
87         [sample drawInRect:NSIntegralRect(NSMakeRect(rect.origin.x + ((rect.size.width - sampleSize.width) / 2.0),
88                                                                                                  rect.origin.y + ((rect.size.height - sampleSize.height) / 2.0),
89                                                                                                  sampleSize.width,
90                                                                                                  sampleSize.height))];
93 - (void)dealloc
95         [backColorOverride release];
96         [super dealloc];
99 //Overrides.  pass nil to disable
100 - (void)setBackColorOverride:(NSColor *)inColor
102         if (backColorOverride != inColor) {
103                 [backColorOverride release];
104                 backColorOverride = [inColor retain];
105         }
108 @end