2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
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.
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.
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.
17 #import "AIEmoticonPack.h"
18 #import "AIEmoticonPackPreviewView.h"
19 #import <AIUtilities/AIParagraphStyleAdditions.h>
20 #import <Adium/AIEmoticon.h>
22 //Max size + bottom margin should equal previewView's height
23 #define EMOTICON_MAX_SIZE 20
24 #define EMOTICON_SPACING 4
26 #define EMOTICON_LEFT_MARGIN 2 //Left padding of cell
27 #define EMOTICON_BOTTOM_MARGIN 2
29 static float distanceBetweenEmoticons = 0;
31 @implementation AIEmoticonPackPreviewView
33 - (void)setEmoticonPack:(AIEmoticonPack *)inEmoticonPack
35 emoticonPack = [inEmoticonPack retain];
40 [emoticonPack release];
45 - (void)drawRect:(NSRect)rect
47 NSRect cellFrame = [view_preview frame];
48 NSRect nameFrame = [view_name frame];
50 [super drawRect:rect];
52 if (NSIntersectsRect(rect,nameFrame)) {
53 //Display the title, truncating as necessary
54 NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle styleWithAlignment:NSLeftTextAlignment
55 lineBreakMode:NSLineBreakByTruncatingTail];
56 [paragraphStyle setMaximumLineHeight:nameFrame.size.height];
58 [[emoticonPack name] drawInRect:nameFrame
59 withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
60 paragraphStyle, NSParagraphStyleAttributeName,
61 [NSFont systemFontOfSize:12], NSFontAttributeName/*,
62 SELECTED_TEXT_COLOR, NSForegroundColorAttributeName*/, nil]];
65 if (NSIntersectsRect(rect,cellFrame)) {
66 NSEnumerator *enumerator;
70 //Display a few preview emoticons
71 enumerator = [[emoticonPack emoticons] objectEnumerator];
72 while ((x < cellFrame.size.width) && (emoticon = [enumerator nextObject])) {
73 NSImage *image = [emoticon image];
74 NSSize imageSize = [image size];
77 //Scale the emoticon, preserving its proportions.
78 if (imageSize.width > EMOTICON_MAX_SIZE) {
79 destRect.size.width = EMOTICON_MAX_SIZE;
80 destRect.size.height = imageSize.height * (EMOTICON_MAX_SIZE / imageSize.width);
81 } else if (imageSize.height > EMOTICON_MAX_SIZE) {
82 destRect.size.width = imageSize.width * (EMOTICON_MAX_SIZE / imageSize.height);
83 destRect.size.height = EMOTICON_MAX_SIZE;
85 destRect.size.width = imageSize.width;
86 destRect.size.height = imageSize.height;
90 destRect.origin.x = cellFrame.origin.x + x;
91 destRect.origin.y = cellFrame.origin.y + EMOTICON_BOTTOM_MARGIN;
93 //If there is enough room, draw the image
94 if ((destRect.origin.x + destRect.size.width) < (cellFrame.origin.x + cellFrame.size.width)) {
95 [image drawInRect:destRect
96 fromRect:NSMakeRect(0, 0, imageSize.width, imageSize.height)
97 operation:NSCompositeSourceOver
101 //Move over for the next emoticon, leaving some space
102 float desiredIncrease = destRect.size.width + EMOTICON_SPACING;
103 if (distanceBetweenEmoticons < desiredIncrease)
104 distanceBetweenEmoticons = desiredIncrease;
105 x += distanceBetweenEmoticons;