Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCoverFlowViewController.m

Parent Directory Parent Directory | Revision Log Revision Log


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

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