Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCoverFlowViewController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 584 - (hide annotations) (download)
Wed Nov 23 02:44:14 2011 UTC (12 years, 4 months ago) by masakih
File size: 12916 byte(s)
[Fix] アナライザを黙らせた。
1 masaki 281 //
2     // XspfMCoverFlowViewController.m
3     // XspfManager
4     //
5     // Created by Hori,Masaki on 10/01/21.
6     //
7    
8 masakih 350 /*
9 masakih 365 This source code is release under the New BSD License.
10 masakih 355 Copyright (c) 2010, masakih
11 masakih 350 All rights reserved.
12    
13 masakih 365 ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に
14     限り、再頒布および使用が許可されます。
15    
16     1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含
17     めること。
18     2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表
19     示、本条件一覧、および下記免責条項を含めること。
20     3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、
21     コントリビューターの名前を使用してはならない。
22     本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、
23     明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証
24     も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター
25     も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか
26     厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する
27     可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用
28     サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定
29     されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい
30     て、一切責任を負わないものとします。
31 masakih 350 -------------------------------------------------------------------
32 masakih 355 Copyright (c) 2010, masakih
33 masakih 350 All rights reserved.
34    
35 masakih 365 Redistribution and use in source and binary forms, with or without
36     modification, are permitted provided that the following conditions
37     are met:
38 masakih 350
39 masakih 365 1, Redistributions of source code must retain the above copyright
40     notice, this list of conditions and the following disclaimer.
41     2, Redistributions in binary form must reproduce the above copyright
42     notice, this list of conditions and the following disclaimer in
43     the documentation and/or other materials provided with the
44     distribution.
45     3, The names of its contributors may be used to endorse or promote
46     products derived from this software without specific prior
47     written permission.
48     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
51     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
52     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
53     INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
54     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
55     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
56     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
58     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59     POSSIBILITY OF SUCH DAMAGE.
60 masakih 350 */
61    
62 masaki 281 #import "XspfMCoverFlowViewController.h"
63    
64     #import "XspfMListViewController.h"
65    
66 masaki 301 #import "XspfMXspfObject.h"
67     #import <Quartz/Quartz.h>
68 masaki 281
69 masaki 301 #import <objc/runtime.h>
70 masaki 281
71 masaki 301 @interface NSObject(XpsfMIKImageFlowViewSupport)
72     - (void)setShowSplitter:(BOOL)flag;
73     - (void)setInlinePreviewEnabled:(BOOL)flag;
74     - (void)setSelectedIndex:(NSUInteger)index;
75 masaki 304 - (NSRect)selectedImageFrame;
76 masaki 325 - (id)cacheManager;
77    
78 masakih 483 - (NSUInteger)selectedIndex;
79 masaki 325
80 masakih 483 - (NSUInteger)numberOfItemsInImageFlow:(id)imageFlowView;
81    
82 masaki 325 - (void)IKCleanTimedOutCache;
83 masaki 301 @end
84    
85 masakih 584 @interface XspfMCoverFlowViewController(XspfMSplitViewSUpport) <NSSplitViewDelegate>
86     @end
87    
88 masaki 281 @implementation XspfMCoverFlowViewController
89    
90     - (id)init
91     {
92     self = [super initWithNibName:@"XspfMCoverFlowView" bundle:nil];
93    
94     return self;
95     }
96    
97     - (void)awakeFromNib
98     {
99     NSArrayController *rep = [self representedObject];
100    
101 masaki 301 [coverFlow setShowSplitter:YES];
102 masaki 302 if([coverFlow respondsToSelector:@selector(setInlinePreviewEnabled:)]) {
103     [coverFlow setInlinePreviewEnabled:YES];
104     }
105 masaki 301 [coverFlow setDataSource:self];
106     [coverFlow setDelegate:self];
107 masaki 281
108     listViewController = [[XspfMListViewController alloc] init];
109     [listViewController view];
110     [listViewController setRepresentedObject:rep];
111     [listViewController recalculateKeyViewLoop];
112     [listPlaceHolder addSubview:[listViewController view]];
113     [[listViewController view] setFrame:[listPlaceHolder bounds]];
114     [self recalculateKeyViewLoop];
115    
116 masaki 294 [splitView setDelegate:self];
117 masakih 440
118     [[NSNotificationCenter defaultCenter] addObserver:self
119     selector:@selector(windowDidUpdate:)
120     name:NSWindowDidUpdateNotification
121     object:nil];
122 masaki 281 }
123    
124 masakih 584 - (void)windowDidUpdate:(NSNotification *)notification
125 masakih 436 {
126 masakih 440 NSWindow *window = [notification object];
127    
128     if(window == [[self view] window]) {
129 masakih 554 [window addObserver:self forKeyPath:@"firstResponder" options:0 context:NULL];
130 masakih 440 [[NSNotificationCenter defaultCenter] removeObserver:self name:[notification name] object:nil];
131     }
132 masakih 436 }
133    
134 masaki 281 - (void)setRepresentedObject:(id)representedObject
135     {
136 masaki 301 id oldRep = [self representedObject];
137     if([oldRep isEqual:representedObject]) return;
138 masaki 329
139 masaki 281 if(representedObject) {
140 masaki 301 [representedObject addObserver:self forKeyPath:@"arrangedObjects" options:0 context:NULL];
141     [representedObject addObserver:self forKeyPath:@"selectionIndex" options:0 context:NULL];
142     [coverFlow setSelectedIndex:[representedObject selectionIndex]];
143 masaki 281 }
144 masaki 301
145     [super setRepresentedObject:representedObject];
146     [listViewController setRepresentedObject:representedObject];
147     [coverFlow reloadData];
148 masaki 281 }
149 masaki 329 - (void)recalculateKeyViewLoop
150     {
151 masakih 430 // [coverFlow setNextKeyView:[listViewController firstKeyView]];
152 masaki 329
153     // TODO: change key view loop if list view is not visible.
154 masakih 430 // lastKeyView = [listViewController lastKeyView];
155    
156     firstKeyView = [listViewController firstKeyView];
157     initialFirstResponder = [listViewController firstKeyView];
158 masaki 329 }
159 masaki 281
160 masaki 301 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
161 masaki 281 {
162 masaki 301 if([keyPath isEqualToString:@"arrangedObjects"]) {
163     [coverFlow reloadData];
164     return;
165     }
166     if([keyPath isEqualToString:@"selectionIndex"]) {
167     [coverFlow setSelectedIndex:[[self representedObject] selectionIndex]];
168 masakih 430 [listViewController scrollToSelection:self];
169 masaki 301 return;
170     }
171 masakih 436 if([keyPath isEqualToString:@"firstResponder"]) {
172     id firstResponder = [[splitView window] firstResponder];
173     if(firstResponder == coverFlow) {
174     [[splitView window] makeFirstResponder:[listViewController view]];
175     }
176     return;
177     }
178 masaki 281
179 masaki 301 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
180 masaki 281 }
181    
182 masakih 430 - (void)keyDown:(NSEvent *)theEvent
183     {
184 masakih 567 NSString *charactor = [theEvent charactersIgnoringModifiers];
185     if([charactor length] == 0) return;
186    
187     unichar uc = [charactor characterAtIndex:0];
188     switch(uc) {
189     case NSLeftArrowFunctionKey:
190     case NSRightArrowFunctionKey:
191 masakih 430 return [coverFlow keyDown:theEvent];
192     break;
193     }
194     NSBeep();
195     }
196 masaki 301
197 masaki 325 - (IBAction)clearCoverFlowCache:(id)sender
198     {
199     if(![coverFlow respondsToSelector:@selector(cacheManager)]) {
200     NSBeep();
201     return;
202     }
203     id cacheManager = [coverFlow cacheManager];
204     if(![cacheManager respondsToSelector:@selector(IKCleanTimedOutCache)]) {
205     NSBeep();
206     return;
207     }
208     [cacheManager IKCleanTimedOutCache];
209     }
210 masakih 483 - (IBAction)moveLeft:(id)sender
211     {
212     NSUInteger selection = [coverFlow selectedIndex];
213     if(selection == 0) return;
214    
215     [coverFlow setSelectedIndex:selection - 1];
216     }
217     - (IBAction)moveRight:(id)sender
218     {
219     NSUInteger selection = [coverFlow selectedIndex];
220     if(selection == [self numberOfItemsInImageFlow:coverFlow] - 1) return;
221    
222     [coverFlow setSelectedIndex:selection + 1];
223     }
224    
225    
226 masakih 554 //- (IBAction)test01:(id)sender
227     //{
228     // [self clearCoverFlowCache:sender];
229     //}
230 masaki 325
231 masaki 301 - (NSUInteger)numberOfItemsInImageFlow:(id)imageFlowView
232     {
233     return [[[self representedObject] arrangedObjects] count];
234     }
235     - (id)imageFlow:(id)imageFlowView itemAtIndex:(NSUInteger)index
236     {
237     return [[[self representedObject] arrangedObjects] objectAtIndex:index];
238     }
239    
240 masakih 430 - (void)setRepSelectedIndex:(NSNumber *)indexValue
241     {
242     [[self representedObject] setSelectionIndex:[indexValue unsignedIntegerValue]];
243     }
244 masaki 301 - (void)imageFlow:(id)imageFlowView didSelectItemAtIndex:(NSUInteger)index
245     {
246 masakih 430 // [[self representedObject] setSelectionIndex:index];
247    
248     [NSObject cancelPreviousPerformRequestsWithTarget:self];
249     [self performSelector:@selector(setRepSelectedIndex:)
250     withObject:[NSNumber numberWithUnsignedInteger:index]
251     afterDelay:0.5];
252 masaki 301 }
253     - (void)imageFlow:(id)imageFlowView cellWasDoubleClickedAtIndex:(NSUInteger)index
254     {
255     [NSApp sendAction:@selector(openXspf:) to:nil from:nil];
256     }
257     - (void)imageFlow:(id)imageFlowView startResizingWithEvent:(NSEvent *)theEvent
258     {
259 masakih 345 NSPoint offset = [imageFlowView convertPoint:[theEvent locationInWindow] fromView:nil];
260    
261 masaki 301 NSWindow *window = [imageFlowView window];
262 masakih 574 while( (theEvent = [window nextEventMatchingMask:NSLeftMouseDraggedMask | NSLeftMouseUpMask]) ) {
263 masakih 345 if(NSEventMaskFromType([theEvent type]) == NSLeftMouseUpMask) break;
264    
265     NSPoint p = [splitView convertPoint:[theEvent locationInWindow] fromView:nil];
266     [splitView setPosition:p.y+offset.y ofDividerAtIndex:0];
267     }
268 masaki 301 }
269    
270 masakih 429 - (IBAction)scrollToSelection:(id)sender
271     {
272     [listViewController scrollToSelection:sender];
273     }
274 masaki 301
275 masaki 304 // QLPreviewPanel support
276     - (NSRect)selectionItemRect
277     {
278     NSRect rect = [coverFlow selectedImageFrame];
279     rect = [coverFlow convertRectToBase:rect];
280     rect.origin = [[coverFlow window] convertBaseToScreen:rect.origin];
281     return rect;
282     }
283    
284 masaki 294 #pragma mark#### NSSplitView Delegate ####
285     - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex
286     {
287     return 130;
288     }
289 masakih 437 - (void)splitView:(NSSplitView *)aSplitView resizeSubviewsWithOldSize:(NSSize)oldSize
290     {
291     NSView *rightView = [[splitView subviews] objectAtIndex:1];
292     NSRect newsplitViewFrame = [splitView frame];
293     NSRect coverFlowFrame = [coverFlow frame];
294     NSRect listFrame = [rightView frame];
295     CGFloat dividerThickness = [splitView dividerThickness];
296    
297     coverFlowFrame.size.width = newsplitViewFrame.size.width;
298     listFrame.size.width = newsplitViewFrame.size.width;
299    
300     coverFlowFrame.size.height = newsplitViewFrame.size.height - listFrame.size.height - dividerThickness;
301    
302     if(listFrame.size.height < 0) {
303     listFrame.size.height = 0;
304     coverFlowFrame.size = newsplitViewFrame.size;
305     }
306    
307     coverFlowFrame.origin.y = 0;
308     listFrame.origin.y = NSMaxY(coverFlowFrame) + dividerThickness;
309    
310     [coverFlow setFrame:coverFlowFrame];
311     [rightView setFrame:listFrame];
312     }
313 masaki 281
314 masaki 301 @end
315 masaki 294
316    
317 masaki 301 @implementation XspfMXspfObject(XspfMIKImageBrowserItem)
318     /*!
319     @method imageUID
320     @abstract Returns a unique string that identify this data source item (required).
321     @discussion The image browser uses this identifier to keep the correspondance between its cache and the data source item
322     */
323     - (NSString *) imageUID
324     {
325 masakih 562 return self.filePath;
326 masaki 301 }
327    
328     /*!
329     @method imageRepresentationType
330     @abstract Returns the representation of the image to display (required).
331     @discussion Keys for imageRepresentationType are defined below.
332     */
333     - (NSString *) imageRepresentationType
334     {
335     return IKImageBrowserQuickLookPathRepresentationType;
336     }
337    
338     /*!
339     @method imageRepresentation
340     @abstract Returns the image to display (required). Can return nil if the item has no image to display.
341     @discussion This methods is called frequently, so the receiver should cache the returned instance.
342     */
343     - (id) imageRepresentation
344     {
345     return self.url;
346     }
347    
348     /*!
349     @method imageVersion
350     @abstract Returns a version of this item. The receiver can return a new version to let the image browser knows that it shouldn't use its cache for this item
351     */
352     //- (NSUInteger) imageVersion;
353    
354     /*!
355     @method imageTitle
356     @abstract Returns the title to display as a NSString. Use setValue:forKey: with IKImageBrowserCellTitleAttribute to set text attributes.
357     */
358     - (NSString *) imageTitle
359     {
360     return self.title;
361     }
362    
363     /*!
364     @method imageSubtitle
365     @abstract Returns the subtitle to display as a NSString. Use setValue:forKey: with IKImageBrowserCellSubtitleAttribute to set text attributes.
366     */
367     - (NSString *) imageSubtitle
368     {
369     return [NSString stringWithFormat:
370     NSLocalizedString(@"%@ Movies", @"%@ Movies"),
371     self.movieNum];
372     }
373    
374     /*!
375     @method isSelectable
376     @abstract Returns whether this item is selectable.
377     @discussion The receiver can implement this methods to forbid selection of this item by returning NO.
378     */
379     //- (BOOL) isSelectable;
380    
381 masaki 281 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26