Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCoverFlowViewController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 310 - (hide annotations) (download)
Sat Feb 6 12:56:35 2010 UTC (14 years, 2 months ago) by masaki
File size: 6739 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 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 310
90 masaki 281 if(representedObject) {
91 masaki 301 [representedObject addObserver:self forKeyPath:@"arrangedObjects" options:0 context:NULL];
92     [representedObject addObserver:self forKeyPath:@"selectionIndex" options:0 context:NULL];
93     [coverFlow setSelectedIndex:[representedObject selectionIndex]];
94 masaki 281 }
95 masaki 301
96     [super setRepresentedObject:representedObject];
97     [listViewController setRepresentedObject:representedObject];
98     [coverFlow reloadData];
99 masaki 281 }
100    
101 masaki 301 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
102 masaki 281 {
103 masaki 301 if([keyPath isEqualToString:@"arrangedObjects"]) {
104     [coverFlow reloadData];
105     return;
106     }
107     if([keyPath isEqualToString:@"selectionIndex"]) {
108     [coverFlow setSelectedIndex:[[self representedObject] selectionIndex]];
109     return;
110     }
111 masaki 281
112 masaki 301 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
113 masaki 281 }
114    
115 masaki 301
116     - (NSUInteger)numberOfItemsInImageFlow:(id)imageFlowView
117     {
118     return [[[self representedObject] arrangedObjects] count];
119     }
120     - (id)imageFlow:(id)imageFlowView itemAtIndex:(NSUInteger)index
121     {
122     return [[[self representedObject] arrangedObjects] objectAtIndex:index];
123     }
124    
125     - (void)imageFlow:(id)imageFlowView didSelectItemAtIndex:(NSUInteger)index
126     {
127     [[self representedObject] setSelectionIndex:index];
128     }
129     - (void)imageFlow:(id)imageFlowView cellWasDoubleClickedAtIndex:(NSUInteger)index
130     {
131     [NSApp sendAction:@selector(openXspf:) to:nil from:nil];
132     }
133     - (void)imageFlow:(id)imageFlowView startResizingWithEvent:(NSEvent *)theEvent
134     {
135     NSPoint offset = [imageFlowView convertPoint:[theEvent locationInWindow] fromView:nil];
136    
137     NSWindow *window = [imageFlowView window];
138     while (theEvent = [window nextEventMatchingMask:NSLeftMouseDraggedMask | NSLeftMouseUpMask]) {
139     if(NSEventMaskFromType([theEvent type]) == NSLeftMouseUpMask) break;
140    
141     NSPoint p = [splitView convertPoint:[theEvent locationInWindow] fromView:nil];
142     [splitView setPosition:p.y+offset.y ofDividerAtIndex:0];
143     }
144     }
145    
146    
147 masaki 304 // QLPreviewPanel support
148     - (NSRect)selectionItemRect
149     {
150     NSRect rect = [coverFlow selectedImageFrame];
151     rect = [coverFlow convertRectToBase:rect];
152     rect.origin = [[coverFlow window] convertBaseToScreen:rect.origin];
153     return rect;
154     }
155    
156 masaki 294 #pragma mark#### NSSplitView Delegate ####
157     - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex
158     {
159     return 130;
160     }
161 masaki 281
162 masaki 301 @end
163 masaki 294
164    
165 masaki 301 @implementation XspfMXspfObject(XspfMIKImageBrowserItem)
166     /*!
167     @method imageUID
168     @abstract Returns a unique string that identify this data source item (required).
169     @discussion The image browser uses this identifier to keep the correspondance between its cache and the data source item
170     */
171     - (NSString *) imageUID
172     {
173     return self.urlString;
174     }
175    
176     /*!
177     @method imageRepresentationType
178     @abstract Returns the representation of the image to display (required).
179     @discussion Keys for imageRepresentationType are defined below.
180     */
181     - (NSString *) imageRepresentationType
182     {
183     return IKImageBrowserQuickLookPathRepresentationType;
184     }
185    
186     /*!
187     @method imageRepresentation
188     @abstract Returns the image to display (required). Can return nil if the item has no image to display.
189     @discussion This methods is called frequently, so the receiver should cache the returned instance.
190     */
191     - (id) imageRepresentation
192     {
193     return self.url;
194     }
195    
196     /*!
197     @method imageVersion
198     @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
199     */
200     //- (NSUInteger) imageVersion;
201    
202     /*!
203     @method imageTitle
204     @abstract Returns the title to display as a NSString. Use setValue:forKey: with IKImageBrowserCellTitleAttribute to set text attributes.
205     */
206     - (NSString *) imageTitle
207     {
208     return self.title;
209     }
210    
211     /*!
212     @method imageSubtitle
213     @abstract Returns the subtitle to display as a NSString. Use setValue:forKey: with IKImageBrowserCellSubtitleAttribute to set text attributes.
214     */
215     - (NSString *) imageSubtitle
216     {
217     return [NSString stringWithFormat:
218     NSLocalizedString(@"%@ Movies", @"%@ Movies"),
219     self.movieNum];
220     }
221    
222     /*!
223     @method isSelectable
224     @abstract Returns whether this item is selectable.
225     @discussion The receiver can implement this methods to forbid selection of this item by returning NO.
226     */
227     //- (BOOL) isSelectable;
228    
229 masaki 281 @end

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