1 | /* |
---|
2 | Adium, Copyright 2001-2005, Adam Iser |
---|
3 | |
---|
4 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
---|
5 | General Public License as published by the Free Software Foundation; either version 2 of the License, |
---|
6 | or (at your option) any later version. |
---|
7 | |
---|
8 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
---|
9 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
10 | Public License for more details. |
---|
11 | |
---|
12 | You should have received a copy of the GNU General Public License along with this program; if not, |
---|
13 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
14 | */ |
---|
15 | |
---|
16 | //Selection changed notification. Object is the image grid whose selection changed. |
---|
17 | #define AIImageGridViewSelectionDidChangeNotification @"AIImageGridViewSelectionDidChangeNotification" |
---|
18 | #define AIImageGridViewSelectionIsChangingNotification @"AIImageGridViewSelectionIsChangingNotification" |
---|
19 | |
---|
20 | @class AIScaledImageCell; |
---|
21 | |
---|
22 | /*! |
---|
23 | * @class AIImageGridView |
---|
24 | * @brief View that displays a grid of images |
---|
25 | * |
---|
26 | * This view displays images in a grid similiar to iPhoto. Image size is adjustable and the view handles image layout |
---|
27 | * and spacing automatically. |
---|
28 | * |
---|
29 | * Important note: This view MUST be enclosed within an NSScrollView to function properly! Make it borderless, non-background-drawing, |
---|
30 | * and with neither horizontal nor vertical scrollers if you don't want there to be any scrolling. |
---|
31 | */ |
---|
32 | @interface AIImageGridView : NSView { |
---|
33 | id delegate; |
---|
34 | AIScaledImageCell *cell; |
---|
35 | NSTrackingRectTag trackingTag; |
---|
36 | |
---|
37 | NSSize imageSize; |
---|
38 | NSSize padding; //Padding between images |
---|
39 | int columns; //Number of columns |
---|
40 | int selectedIndex; //Currently selected image index |
---|
41 | int hoveredIndex; //Currently hovered image index |
---|
42 | |
---|
43 | //The optional methods our current delegate responds to (So we don't have to ask it repeatedly) |
---|
44 | BOOL _respondsToShouldSelect; |
---|
45 | BOOL _respondsToSelectionDidChange; |
---|
46 | BOOL _respondsToSelectionIsChanging; |
---|
47 | BOOL _respondsToDeleteSelection; |
---|
48 | BOOL _respondsToImageHovered; |
---|
49 | BOOL drawsBackground; |
---|
50 | BOOL isTracking; |
---|
51 | } |
---|
52 | |
---|
53 | /*! |
---|
54 | * @brief Set the delegate for this view |
---|
55 | * |
---|
56 | * The delegate is informed of selection changes, cursor movement, and serves as the data source for the images |
---|
57 | * that will be displayed. |
---|
58 | * @param inDelegate Delegate and datasource |
---|
59 | */ |
---|
60 | - (void)setDelegate:(id)inDelegate; |
---|
61 | |
---|
62 | /*! |
---|
63 | * @brief Retrieve the delegate for this view |
---|
64 | * |
---|
65 | * @return the current delegate |
---|
66 | */ |
---|
67 | - (id)delegate; |
---|
68 | |
---|
69 | /*! |
---|
70 | * @brief Set the size images will display |
---|
71 | * |
---|
72 | * Set the size for image display and layout within the grid. The view will automatically re-layout and column the |
---|
73 | * the images as this value is changed. |
---|
74 | * @param inSize <tt>NSSize</tt> for image display |
---|
75 | */ |
---|
76 | - (void)setImageSize:(NSSize)inSize; |
---|
77 | |
---|
78 | /*! |
---|
79 | * @brief Retrieve image display size |
---|
80 | * |
---|
81 | * @return <tt>NSSize</tt> current image size |
---|
82 | */ |
---|
83 | - (NSSize)imageSize; |
---|
84 | |
---|
85 | /*! |
---|
86 | * @brief Reload images from delegate |
---|
87 | * |
---|
88 | * Invokes a reload of images from the delegate. Call this method when the images or number of images changes and the |
---|
89 | * view needs re-layout in response. The view will automatically redisplay if needed. |
---|
90 | */ |
---|
91 | - (void)reloadData; |
---|
92 | |
---|
93 | /*! |
---|
94 | * @brief Returns the rect occupied by an image in our grid |
---|
95 | * |
---|
96 | * @param index Index of the image |
---|
97 | * @return <tt>NSRect</tt> the image occupies in our grid |
---|
98 | */ |
---|
99 | - (NSRect)rectForImageAtIndex:(int)index; |
---|
100 | |
---|
101 | /*! |
---|
102 | * @brief Returns the image present at a point in our grid |
---|
103 | * |
---|
104 | * @param point Location |
---|
105 | * @return index of the image at point |
---|
106 | */ |
---|
107 | - (int)imageIndexAtPoint:(NSPoint)point; |
---|
108 | |
---|
109 | /*! |
---|
110 | * @brief Redisplay an image in our grid |
---|
111 | * |
---|
112 | * @param index Index of the image |
---|
113 | */ |
---|
114 | - (void)setNeedsDisplayOfImageAtIndex:(int)index; |
---|
115 | |
---|
116 | /*! |
---|
117 | * @brief Set the selected image |
---|
118 | * |
---|
119 | * Set the currently selected image. The delegate is informed of selection changes. |
---|
120 | * @param index Image index to select |
---|
121 | */ |
---|
122 | - (void)selectIndex:(int)index; |
---|
123 | |
---|
124 | /*! |
---|
125 | * @brief Set the selected image, relative to the current one |
---|
126 | * |
---|
127 | * Select an image with a position relative to the current selected image. The delegate is informed of selection changes. |
---|
128 | * @param delta Amount of positions to relocate the selection (0 = keep current selection; +1 = select next item) |
---|
129 | */ |
---|
130 | - (void)selectRelativeIndex:(signed int)delta; |
---|
131 | |
---|
132 | /*! |
---|
133 | * @brief Retrieve the selected image |
---|
134 | * |
---|
135 | * @return index of the currently selected image |
---|
136 | */ |
---|
137 | - (int)selectedIndex; |
---|
138 | |
---|
139 | /*! |
---|
140 | * @brief Check whether the receiver is set to draw its background |
---|
141 | * |
---|
142 | * @return a BOOL indicating if the background is drawn |
---|
143 | */ |
---|
144 | - (BOOL)drawsBackground; |
---|
145 | |
---|
146 | /*! |
---|
147 | * @brief Set whether the receiver draws its background |
---|
148 | * |
---|
149 | * @param flag A BOOL indicating whether or not to draw the background |
---|
150 | */ |
---|
151 | - (void)setDrawsBackground:(BOOL)flag; |
---|
152 | |
---|
153 | @end |
---|
154 | |
---|
155 | //AIImageGridView delegate methods. These are very similar to NSTableView. |
---|
156 | @interface NSObject (AIImageGridViewDelegate) |
---|
157 | - (int)numberOfImagesInImageGridView:(AIImageGridView *)imageGridView; |
---|
158 | - (NSImage *)imageGridView:(AIImageGridView *)imageGridView imageAtIndex:(int)index; |
---|
159 | - (BOOL)imageGridView:(AIImageGridView *)imageGridView shouldSelectIndex:(int)index; //Optional |
---|
160 | - (void)imageGridViewDeleteSelectedImage:(AIImageGridView *)imageGridView; //Optional |
---|
161 | - (void)imageGridView:(AIImageGridView *)imageGridView cursorIsHoveringImageAtIndex:(int)index; //Optional |
---|
162 | @end |
---|
163 | |
---|
164 | //Notifications. These are automatically sent to the delegate. |
---|
165 | @interface NSObject(AIImageGridViewNotifications) |
---|
166 | - (void)imageGridViewSelectionDidChange:(NSNotification *)notification; |
---|
167 | - (void)imageGridViewSelectionIsChanging:(NSNotification *)notification; |
---|
168 | @end |
---|