Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCoverFlowViewController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 304 - (hide annotations) (download)
Thu Feb 4 14:27:49 2010 UTC (14 years, 2 months ago) by masaki
File size: 6813 byte(s)
[Mod] QLPreviewPanelの表示/非表示時の動きを最適化。
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 301 @end
24    
25 masaki 281 @implementation XspfMCoverFlowViewController
26    
27 masaki 301 static IMP originalKeyDown = NULL;
28     + (void)initialize
29     {
30     static BOOL isFirst = YES;
31     if(isFirst) {
32     isFirst = NO;
33    
34     Method originalMethod = class_getInstanceMethod(NSClassFromString(@"IKImageFlowView"), @selector(keyDown:));
35     Method replacedMethod = class_getInstanceMethod(self, @selector(hackKeyDown:));
36     IMP replacedIMP = method_getImplementation(replacedMethod);
37     originalKeyDown = method_setImplementation(originalMethod, replacedIMP);
38     }
39     }
40     - (void)hackKeyDown:(NSEvent *)theEvent
41     {
42     if([theEvent isARepeat]) goto finish;
43    
44     unsigned short code = [theEvent keyCode];
45     switch(code) {
46     case 49:
47     [NSApp sendAction:@selector(togglePreviewPanel:) to:nil from:nil];
48     return;
49     }
50     finish:
51     originalKeyDown(self, _cmd, theEvent);
52     }
53    
54 masaki 281 - (id)init
55     {
56     self = [super initWithNibName:@"XspfMCoverFlowView" bundle:nil];
57    
58     return self;
59     }
60    
61     - (void)awakeFromNib
62     {
63     NSArrayController *rep = [self representedObject];
64    
65 masaki 301 [coverFlow setShowSplitter:YES];
66 masaki 302 if([coverFlow respondsToSelector:@selector(setInlinePreviewEnabled:)]) {
67     [coverFlow setInlinePreviewEnabled:YES];
68     }
69 masaki 301 [coverFlow setDataSource:self];
70     [coverFlow setDelegate:self];
71     // NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSColor darkGrayColor] forKey:NSForegroundColorAttributeName];
72     // [coverFlow setValue:attr forKey:IKImageBrowserCellsSubtitleAttributesKey];
73 masaki 281
74     listViewController = [[XspfMListViewController alloc] init];
75     [listViewController view];
76     [listViewController setRepresentedObject:rep];
77     [listViewController recalculateKeyViewLoop];
78     [listPlaceHolder addSubview:[listViewController view]];
79     [[listViewController view] setFrame:[listPlaceHolder bounds]];
80     [self recalculateKeyViewLoop];
81    
82 masaki 294 [splitView setDelegate:self];
83 masaki 281 }
84    
85     - (void)setRepresentedObject:(id)representedObject
86     {
87 masaki 301 id oldRep = [self representedObject];
88     if([oldRep isEqual:representedObject]) return;
89 masaki 281
90 masaki 301 [oldRep unbind:@"arrangedObjects"];
91     [oldRep unbind:@"selectionIndex"];
92    
93 masaki 281 if(representedObject) {
94 masaki 301 [representedObject addObserver:self forKeyPath:@"arrangedObjects" options:0 context:NULL];
95     [representedObject addObserver:self forKeyPath:@"selectionIndex" options:0 context:NULL];
96     [coverFlow setSelectedIndex:[representedObject selectionIndex]];
97 masaki 281 }
98 masaki 301
99     [super setRepresentedObject:representedObject];
100     [listViewController setRepresentedObject:representedObject];
101     [coverFlow reloadData];
102 masaki 281 }
103    
104 masaki 301 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
105 masaki 281 {
106 masaki 301 if([keyPath isEqualToString:@"arrangedObjects"]) {
107     [coverFlow reloadData];
108     return;
109     }
110     if([keyPath isEqualToString:@"selectionIndex"]) {
111     [coverFlow setSelectedIndex:[[self representedObject] selectionIndex]];
112     return;
113     }
114 masaki 281
115 masaki 301 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
116 masaki 281 }
117    
118 masaki 301
119     - (NSUInteger)numberOfItemsInImageFlow:(id)imageFlowView
120     {
121     return [[[self representedObject] arrangedObjects] count];
122     }
123     - (id)imageFlow:(id)imageFlowView itemAtIndex:(NSUInteger)index
124     {
125     return [[[self representedObject] arrangedObjects] objectAtIndex:index];
126     }
127    
128     - (void)imageFlow:(id)imageFlowView didSelectItemAtIndex:(NSUInteger)index
129     {
130     [[self representedObject] setSelectionIndex:index];
131     }
132     - (void)imageFlow:(id)imageFlowView cellWasDoubleClickedAtIndex:(NSUInteger)index
133     {
134     [NSApp sendAction:@selector(openXspf:) to:nil from:nil];
135     }
136     - (void)imageFlow:(id)imageFlowView startResizingWithEvent:(NSEvent *)theEvent
137     {
138     NSPoint offset = [imageFlowView convertPoint:[theEvent locationInWindow] fromView:nil];
139    
140     NSWindow *window = [imageFlowView window];
141     while (theEvent = [window nextEventMatchingMask:NSLeftMouseDraggedMask | NSLeftMouseUpMask]) {
142     if(NSEventMaskFromType([theEvent type]) == NSLeftMouseUpMask) break;
143    
144     NSPoint p = [splitView convertPoint:[theEvent locationInWindow] fromView:nil];
145     [splitView setPosition:p.y+offset.y ofDividerAtIndex:0];
146     }
147     }
148    
149    
150 masaki 304 // QLPreviewPanel support
151     - (NSRect)selectionItemRect
152     {
153     NSRect rect = [coverFlow selectedImageFrame];
154     rect = [coverFlow convertRectToBase:rect];
155     rect.origin = [[coverFlow window] convertBaseToScreen:rect.origin];
156     return rect;
157     }
158    
159 masaki 294 #pragma mark#### NSSplitView Delegate ####
160     - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex
161     {
162     return 130;
163     }
164 masaki 281
165 masaki 301 @end
166 masaki 294
167    
168 masaki 301 @implementation XspfMXspfObject(XspfMIKImageBrowserItem)
169     /*!
170     @method imageUID
171     @abstract Returns a unique string that identify this data source item (required).
172     @discussion The image browser uses this identifier to keep the correspondance between its cache and the data source item
173     */
174     - (NSString *) imageUID
175     {
176     return self.urlString;
177     }
178    
179     /*!
180     @method imageRepresentationType
181     @abstract Returns the representation of the image to display (required).
182     @discussion Keys for imageRepresentationType are defined below.
183     */
184     - (NSString *) imageRepresentationType
185     {
186     return IKImageBrowserQuickLookPathRepresentationType;
187     }
188    
189     /*!
190     @method imageRepresentation
191     @abstract Returns the image to display (required). Can return nil if the item has no image to display.
192     @discussion This methods is called frequently, so the receiver should cache the returned instance.
193     */
194     - (id) imageRepresentation
195     {
196     return self.url;
197     }
198    
199     /*!
200     @method imageVersion
201     @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
202     */
203     //- (NSUInteger) imageVersion;
204    
205     /*!
206     @method imageTitle
207     @abstract Returns the title to display as a NSString. Use setValue:forKey: with IKImageBrowserCellTitleAttribute to set text attributes.
208     */
209     - (NSString *) imageTitle
210     {
211     return self.title;
212     }
213    
214     /*!
215     @method imageSubtitle
216     @abstract Returns the subtitle to display as a NSString. Use setValue:forKey: with IKImageBrowserCellSubtitleAttribute to set text attributes.
217     */
218     - (NSString *) imageSubtitle
219     {
220     return [NSString stringWithFormat:
221     NSLocalizedString(@"%@ Movies", @"%@ Movies"),
222     self.movieNum];
223     }
224    
225     /*!
226     @method isSelectable
227     @abstract Returns whether this item is selectable.
228     @discussion The receiver can implement this methods to forbid selection of this item by returning NO.
229     */
230     //- (BOOL) isSelectable;
231    
232 masaki 281 @end

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