Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCoverFlowViewController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 345 - (hide annotations) (download)
Mon Mar 22 00:57:18 2010 UTC (14 years, 1 month ago) by masakih
File size: 7493 byte(s)
[Mod] ドラッグ時のアルゴリズムを変更。
1 masaki 281 //
2     // XspfMCoverFlowViewController.m
3     // XspfManager
4     //
5     // Created by Hori,Masaki on 10/01/21.
6     // Copyright 2010 masakih. All rights reserved.
7     //
8    
9     #import "XspfMCoverFlowViewController.h"
10    
11     #import "XspfMListViewController.h"
12    
13 masaki 301 #import "XspfMXspfObject.h"
14     #import <Quartz/Quartz.h>
15 masaki 281
16 masaki 301 #import <objc/runtime.h>
17 masaki 281
18 masaki 301 @interface NSObject(XpsfMIKImageFlowViewSupport)
19     - (void)setShowSplitter:(BOOL)flag;
20     - (void)setInlinePreviewEnabled:(BOOL)flag;
21     - (void)setSelectedIndex:(NSUInteger)index;
22 masaki 304 - (NSRect)selectedImageFrame;
23 masaki 325 - (id)cacheManager;
24    
25    
26     - (void)IKCleanTimedOutCache;
27 masaki 301 @end
28    
29 masaki 281 @implementation XspfMCoverFlowViewController
30    
31 masaki 301 static IMP originalKeyDown = NULL;
32     + (void)initialize
33     {
34     static BOOL isFirst = YES;
35     if(isFirst) {
36     isFirst = NO;
37    
38     Method originalMethod = class_getInstanceMethod(NSClassFromString(@"IKImageFlowView"), @selector(keyDown:));
39 masakih 345 Method replacedMethod = class_getInstanceMethod(self, @selector(hackKeyDown:));
40 masaki 301 IMP replacedIMP = method_getImplementation(replacedMethod);
41 masakih 345 originalKeyDown = method_setImplementation(originalMethod, replacedIMP);
42 masaki 301 }
43     }
44     - (void)hackKeyDown:(NSEvent *)theEvent
45     {
46     if([theEvent isARepeat]) goto finish;
47 masaki 329
48     #define kRETURN_KEY 36
49     #define kENTER_KEY 52
50 masaki 301 unsigned short code = [theEvent keyCode];
51     switch(code) {
52 masaki 329 case kRETURN_KEY:
53     case kENTER_KEY:
54     [NSApp sendAction:@selector(openXspf:) to:nil from:nil];
55     return;
56 masaki 301 case 49:
57     [NSApp sendAction:@selector(togglePreviewPanel:) to:nil from:nil];
58     return;
59     }
60     finish:
61     originalKeyDown(self, _cmd, theEvent);
62     }
63    
64 masaki 281 - (id)init
65     {
66     self = [super initWithNibName:@"XspfMCoverFlowView" bundle:nil];
67    
68     return self;
69     }
70    
71     - (void)awakeFromNib
72     {
73     NSArrayController *rep = [self representedObject];
74    
75 masaki 301 [coverFlow setShowSplitter:YES];
76 masaki 302 if([coverFlow respondsToSelector:@selector(setInlinePreviewEnabled:)]) {
77     [coverFlow setInlinePreviewEnabled:YES];
78     }
79 masaki 301 [coverFlow setDataSource:self];
80     [coverFlow setDelegate:self];
81     // NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSColor darkGrayColor] forKey:NSForegroundColorAttributeName];
82     // [coverFlow setValue:attr forKey:IKImageBrowserCellsSubtitleAttributesKey];
83 masaki 281
84     listViewController = [[XspfMListViewController alloc] init];
85     [listViewController view];
86     [listViewController setRepresentedObject:rep];
87     [listViewController recalculateKeyViewLoop];
88     [listPlaceHolder addSubview:[listViewController view]];
89     [[listViewController view] setFrame:[listPlaceHolder bounds]];
90     [self recalculateKeyViewLoop];
91    
92 masaki 294 [splitView setDelegate:self];
93 masaki 281 }
94    
95     - (void)setRepresentedObject:(id)representedObject
96     {
97 masaki 301 id oldRep = [self representedObject];
98     if([oldRep isEqual:representedObject]) return;
99 masaki 329
100 masaki 281 if(representedObject) {
101 masaki 301 [representedObject addObserver:self forKeyPath:@"arrangedObjects" options:0 context:NULL];
102     [representedObject addObserver:self forKeyPath:@"selectionIndex" options:0 context:NULL];
103     [coverFlow setSelectedIndex:[representedObject selectionIndex]];
104 masaki 281 }
105 masaki 301
106     [super setRepresentedObject:representedObject];
107     [listViewController setRepresentedObject:representedObject];
108     [coverFlow reloadData];
109 masaki 281 }
110 masaki 329 - (void)recalculateKeyViewLoop
111     {
112     [coverFlow setNextKeyView:[listViewController firstKeyView]];
113    
114     // TODO: change key view loop if list view is not visible.
115     lastKeyView = [listViewController lastKeyView];
116     }
117 masaki 281
118 masaki 301 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
119 masaki 281 {
120 masaki 301 if([keyPath isEqualToString:@"arrangedObjects"]) {
121     [coverFlow reloadData];
122     return;
123     }
124     if([keyPath isEqualToString:@"selectionIndex"]) {
125     [coverFlow setSelectedIndex:[[self representedObject] selectionIndex]];
126     return;
127     }
128 masaki 281
129 masaki 301 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
130 masaki 281 }
131    
132 masaki 301
133 masaki 325 - (IBAction)clearCoverFlowCache:(id)sender
134     {
135     if(![coverFlow respondsToSelector:@selector(cacheManager)]) {
136     NSBeep();
137     return;
138     }
139     id cacheManager = [coverFlow cacheManager];
140     if(![cacheManager respondsToSelector:@selector(IKCleanTimedOutCache)]) {
141     NSBeep();
142     return;
143     }
144     [cacheManager IKCleanTimedOutCache];
145     }
146     - (IBAction)test01:(id)sender
147     {
148     [self clearCoverFlowCache:sender];
149     }
150    
151 masaki 301 - (NSUInteger)numberOfItemsInImageFlow:(id)imageFlowView
152     {
153     return [[[self representedObject] arrangedObjects] count];
154     }
155     - (id)imageFlow:(id)imageFlowView itemAtIndex:(NSUInteger)index
156     {
157     return [[[self representedObject] arrangedObjects] objectAtIndex:index];
158     }
159    
160     - (void)imageFlow:(id)imageFlowView didSelectItemAtIndex:(NSUInteger)index
161     {
162     [[self representedObject] setSelectionIndex:index];
163     }
164     - (void)imageFlow:(id)imageFlowView cellWasDoubleClickedAtIndex:(NSUInteger)index
165     {
166     [NSApp sendAction:@selector(openXspf:) to:nil from:nil];
167     }
168     - (void)imageFlow:(id)imageFlowView startResizingWithEvent:(NSEvent *)theEvent
169     {
170 masakih 345 NSPoint offset = [imageFlowView convertPoint:[theEvent locationInWindow] fromView:nil];
171    
172 masaki 301 NSWindow *window = [imageFlowView window];
173 masakih 345 while (theEvent = [window nextEventMatchingMask:NSLeftMouseDraggedMask | NSLeftMouseUpMask]) {
174     if(NSEventMaskFromType([theEvent type]) == NSLeftMouseUpMask) break;
175    
176     NSPoint p = [splitView convertPoint:[theEvent locationInWindow] fromView:nil];
177     [splitView setPosition:p.y+offset.y ofDividerAtIndex:0];
178     }
179 masaki 301 }
180    
181    
182 masaki 304 // QLPreviewPanel support
183     - (NSRect)selectionItemRect
184     {
185     NSRect rect = [coverFlow selectedImageFrame];
186     rect = [coverFlow convertRectToBase:rect];
187     rect.origin = [[coverFlow window] convertBaseToScreen:rect.origin];
188     return rect;
189     }
190    
191 masaki 294 #pragma mark#### NSSplitView Delegate ####
192     - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex
193     {
194     return 130;
195     }
196 masaki 281
197 masaki 301 @end
198 masaki 294
199    
200 masaki 301 @implementation XspfMXspfObject(XspfMIKImageBrowserItem)
201     /*!
202     @method imageUID
203     @abstract Returns a unique string that identify this data source item (required).
204     @discussion The image browser uses this identifier to keep the correspondance between its cache and the data source item
205     */
206     - (NSString *) imageUID
207     {
208     return self.urlString;
209     }
210    
211     /*!
212     @method imageRepresentationType
213     @abstract Returns the representation of the image to display (required).
214     @discussion Keys for imageRepresentationType are defined below.
215     */
216     - (NSString *) imageRepresentationType
217     {
218     return IKImageBrowserQuickLookPathRepresentationType;
219     }
220    
221     /*!
222     @method imageRepresentation
223     @abstract Returns the image to display (required). Can return nil if the item has no image to display.
224     @discussion This methods is called frequently, so the receiver should cache the returned instance.
225     */
226     - (id) imageRepresentation
227     {
228     return self.url;
229     }
230    
231     /*!
232     @method imageVersion
233     @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
234     */
235     //- (NSUInteger) imageVersion;
236    
237     /*!
238     @method imageTitle
239     @abstract Returns the title to display as a NSString. Use setValue:forKey: with IKImageBrowserCellTitleAttribute to set text attributes.
240     */
241     - (NSString *) imageTitle
242     {
243     return self.title;
244     }
245    
246     /*!
247     @method imageSubtitle
248     @abstract Returns the subtitle to display as a NSString. Use setValue:forKey: with IKImageBrowserCellSubtitleAttribute to set text attributes.
249     */
250     - (NSString *) imageSubtitle
251     {
252     return [NSString stringWithFormat:
253     NSLocalizedString(@"%@ Movies", @"%@ Movies"),
254     self.movieNum];
255     }
256    
257     /*!
258     @method isSelectable
259     @abstract Returns whether this item is selectable.
260     @discussion The receiver can implement this methods to forbid selection of this item by returning NO.
261     */
262     //- (BOOL) isSelectable;
263    
264 masaki 281 @end

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