| 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 |
355 |
Copyright (c) 2010, masakih |
| 10 |
masakih |
350 |
All rights reserved. |
| 11 |
|
|
ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に限り、再頒布および使用が許可されます。 |
| 12 |
|
|
|
| 13 |
|
|
1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含めること。 |
| 14 |
|
|
2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表示、本条件一覧、および下記免責条項を含めること。 |
| 15 |
|
|
3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、コントリビューターの名前を使用してはならない。 |
| 16 |
|
|
本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューターも、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害について、一切責任を負わないものとします。 |
| 17 |
|
|
------------------------------------------------------------------- |
| 18 |
masakih |
355 |
Copyright (c) 2010, masakih |
| 19 |
masakih |
350 |
All rights reserved. |
| 20 |
|
|
|
| 21 |
|
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
| 22 |
|
|
|
| 23 |
|
|
1, Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
| 24 |
|
|
2, Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
| 25 |
|
|
3, The names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. |
| 26 |
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
|
|
*/ |
| 28 |
|
|
|
| 29 |
masaki |
281 |
#import "XspfMCoverFlowViewController.h" |
| 30 |
|
|
|
| 31 |
|
|
#import "XspfMListViewController.h" |
| 32 |
|
|
|
| 33 |
masaki |
301 |
#import "XspfMXspfObject.h" |
| 34 |
|
|
#import <Quartz/Quartz.h> |
| 35 |
masaki |
281 |
|
| 36 |
masaki |
301 |
#import <objc/runtime.h> |
| 37 |
masaki |
281 |
|
| 38 |
masaki |
301 |
@interface NSObject(XpsfMIKImageFlowViewSupport) |
| 39 |
|
|
- (void)setShowSplitter:(BOOL)flag; |
| 40 |
|
|
- (void)setInlinePreviewEnabled:(BOOL)flag; |
| 41 |
|
|
- (void)setSelectedIndex:(NSUInteger)index; |
| 42 |
masaki |
304 |
- (NSRect)selectedImageFrame; |
| 43 |
masaki |
325 |
- (id)cacheManager; |
| 44 |
|
|
|
| 45 |
|
|
|
| 46 |
|
|
- (void)IKCleanTimedOutCache; |
| 47 |
masaki |
301 |
@end |
| 48 |
|
|
|
| 49 |
masaki |
281 |
@implementation XspfMCoverFlowViewController |
| 50 |
|
|
|
| 51 |
masaki |
301 |
static IMP originalKeyDown = NULL; |
| 52 |
|
|
+ (void)initialize |
| 53 |
|
|
{ |
| 54 |
|
|
static BOOL isFirst = YES; |
| 55 |
|
|
if(isFirst) { |
| 56 |
|
|
isFirst = NO; |
| 57 |
|
|
|
| 58 |
|
|
Method originalMethod = class_getInstanceMethod(NSClassFromString(@"IKImageFlowView"), @selector(keyDown:)); |
| 59 |
masakih |
345 |
Method replacedMethod = class_getInstanceMethod(self, @selector(hackKeyDown:)); |
| 60 |
masaki |
301 |
IMP replacedIMP = method_getImplementation(replacedMethod); |
| 61 |
masakih |
345 |
originalKeyDown = method_setImplementation(originalMethod, replacedIMP); |
| 62 |
masaki |
301 |
} |
| 63 |
|
|
} |
| 64 |
|
|
- (void)hackKeyDown:(NSEvent *)theEvent |
| 65 |
|
|
{ |
| 66 |
|
|
if([theEvent isARepeat]) goto finish; |
| 67 |
masaki |
329 |
|
| 68 |
|
|
#define kRETURN_KEY 36 |
| 69 |
|
|
#define kENTER_KEY 52 |
| 70 |
masaki |
301 |
unsigned short code = [theEvent keyCode]; |
| 71 |
|
|
switch(code) { |
| 72 |
masaki |
329 |
case kRETURN_KEY: |
| 73 |
|
|
case kENTER_KEY: |
| 74 |
|
|
[NSApp sendAction:@selector(openXspf:) to:nil from:nil]; |
| 75 |
|
|
return; |
| 76 |
masaki |
301 |
case 49: |
| 77 |
|
|
[NSApp sendAction:@selector(togglePreviewPanel:) to:nil from:nil]; |
| 78 |
|
|
return; |
| 79 |
|
|
} |
| 80 |
|
|
finish: |
| 81 |
|
|
originalKeyDown(self, _cmd, theEvent); |
| 82 |
|
|
} |
| 83 |
|
|
|
| 84 |
masaki |
281 |
- (id)init |
| 85 |
|
|
{ |
| 86 |
|
|
self = [super initWithNibName:@"XspfMCoverFlowView" bundle:nil]; |
| 87 |
|
|
|
| 88 |
|
|
return self; |
| 89 |
|
|
} |
| 90 |
|
|
|
| 91 |
|
|
- (void)awakeFromNib |
| 92 |
|
|
{ |
| 93 |
|
|
NSArrayController *rep = [self representedObject]; |
| 94 |
|
|
|
| 95 |
masaki |
301 |
[coverFlow setShowSplitter:YES]; |
| 96 |
masaki |
302 |
if([coverFlow respondsToSelector:@selector(setInlinePreviewEnabled:)]) { |
| 97 |
|
|
[coverFlow setInlinePreviewEnabled:YES]; |
| 98 |
|
|
} |
| 99 |
masaki |
301 |
[coverFlow setDataSource:self]; |
| 100 |
|
|
[coverFlow setDelegate:self]; |
| 101 |
|
|
// NSDictionary *attr = [NSDictionary dictionaryWithObject:[NSColor darkGrayColor] forKey:NSForegroundColorAttributeName]; |
| 102 |
|
|
// [coverFlow setValue:attr forKey:IKImageBrowserCellsSubtitleAttributesKey]; |
| 103 |
masaki |
281 |
|
| 104 |
|
|
listViewController = [[XspfMListViewController alloc] init]; |
| 105 |
|
|
[listViewController view]; |
| 106 |
|
|
[listViewController setRepresentedObject:rep]; |
| 107 |
|
|
[listViewController recalculateKeyViewLoop]; |
| 108 |
|
|
[listPlaceHolder addSubview:[listViewController view]]; |
| 109 |
|
|
[[listViewController view] setFrame:[listPlaceHolder bounds]]; |
| 110 |
|
|
[self recalculateKeyViewLoop]; |
| 111 |
|
|
|
| 112 |
masaki |
294 |
[splitView setDelegate:self]; |
| 113 |
masaki |
281 |
} |
| 114 |
|
|
|
| 115 |
|
|
- (void)setRepresentedObject:(id)representedObject |
| 116 |
|
|
{ |
| 117 |
masaki |
301 |
id oldRep = [self representedObject]; |
| 118 |
|
|
if([oldRep isEqual:representedObject]) return; |
| 119 |
masaki |
329 |
|
| 120 |
masaki |
281 |
if(representedObject) { |
| 121 |
masaki |
301 |
[representedObject addObserver:self forKeyPath:@"arrangedObjects" options:0 context:NULL]; |
| 122 |
|
|
[representedObject addObserver:self forKeyPath:@"selectionIndex" options:0 context:NULL]; |
| 123 |
|
|
[coverFlow setSelectedIndex:[representedObject selectionIndex]]; |
| 124 |
masaki |
281 |
} |
| 125 |
masaki |
301 |
|
| 126 |
|
|
[super setRepresentedObject:representedObject]; |
| 127 |
|
|
[listViewController setRepresentedObject:representedObject]; |
| 128 |
|
|
[coverFlow reloadData]; |
| 129 |
masaki |
281 |
} |
| 130 |
masaki |
329 |
- (void)recalculateKeyViewLoop |
| 131 |
|
|
{ |
| 132 |
|
|
[coverFlow setNextKeyView:[listViewController firstKeyView]]; |
| 133 |
|
|
|
| 134 |
|
|
// TODO: change key view loop if list view is not visible. |
| 135 |
|
|
lastKeyView = [listViewController lastKeyView]; |
| 136 |
|
|
} |
| 137 |
masaki |
281 |
|
| 138 |
masaki |
301 |
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context |
| 139 |
masaki |
281 |
{ |
| 140 |
masaki |
301 |
if([keyPath isEqualToString:@"arrangedObjects"]) { |
| 141 |
|
|
[coverFlow reloadData]; |
| 142 |
|
|
return; |
| 143 |
|
|
} |
| 144 |
|
|
if([keyPath isEqualToString:@"selectionIndex"]) { |
| 145 |
|
|
[coverFlow setSelectedIndex:[[self representedObject] selectionIndex]]; |
| 146 |
|
|
return; |
| 147 |
|
|
} |
| 148 |
masaki |
281 |
|
| 149 |
masaki |
301 |
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; |
| 150 |
masaki |
281 |
} |
| 151 |
|
|
|
| 152 |
masaki |
301 |
|
| 153 |
masaki |
325 |
- (IBAction)clearCoverFlowCache:(id)sender |
| 154 |
|
|
{ |
| 155 |
|
|
if(![coverFlow respondsToSelector:@selector(cacheManager)]) { |
| 156 |
|
|
NSBeep(); |
| 157 |
|
|
return; |
| 158 |
|
|
} |
| 159 |
|
|
id cacheManager = [coverFlow cacheManager]; |
| 160 |
|
|
if(![cacheManager respondsToSelector:@selector(IKCleanTimedOutCache)]) { |
| 161 |
|
|
NSBeep(); |
| 162 |
|
|
return; |
| 163 |
|
|
} |
| 164 |
|
|
[cacheManager IKCleanTimedOutCache]; |
| 165 |
|
|
} |
| 166 |
|
|
- (IBAction)test01:(id)sender |
| 167 |
|
|
{ |
| 168 |
|
|
[self clearCoverFlowCache:sender]; |
| 169 |
|
|
} |
| 170 |
|
|
|
| 171 |
masaki |
301 |
- (NSUInteger)numberOfItemsInImageFlow:(id)imageFlowView |
| 172 |
|
|
{ |
| 173 |
|
|
return [[[self representedObject] arrangedObjects] count]; |
| 174 |
|
|
} |
| 175 |
|
|
- (id)imageFlow:(id)imageFlowView itemAtIndex:(NSUInteger)index |
| 176 |
|
|
{ |
| 177 |
|
|
return [[[self representedObject] arrangedObjects] objectAtIndex:index]; |
| 178 |
|
|
} |
| 179 |
|
|
|
| 180 |
|
|
- (void)imageFlow:(id)imageFlowView didSelectItemAtIndex:(NSUInteger)index |
| 181 |
|
|
{ |
| 182 |
|
|
[[self representedObject] setSelectionIndex:index]; |
| 183 |
|
|
} |
| 184 |
|
|
- (void)imageFlow:(id)imageFlowView cellWasDoubleClickedAtIndex:(NSUInteger)index |
| 185 |
|
|
{ |
| 186 |
|
|
[NSApp sendAction:@selector(openXspf:) to:nil from:nil]; |
| 187 |
|
|
} |
| 188 |
|
|
- (void)imageFlow:(id)imageFlowView startResizingWithEvent:(NSEvent *)theEvent |
| 189 |
|
|
{ |
| 190 |
masakih |
345 |
NSPoint offset = [imageFlowView convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 191 |
|
|
|
| 192 |
masaki |
301 |
NSWindow *window = [imageFlowView window]; |
| 193 |
masakih |
345 |
while (theEvent = [window nextEventMatchingMask:NSLeftMouseDraggedMask | NSLeftMouseUpMask]) { |
| 194 |
|
|
if(NSEventMaskFromType([theEvent type]) == NSLeftMouseUpMask) break; |
| 195 |
|
|
|
| 196 |
|
|
NSPoint p = [splitView convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 197 |
|
|
[splitView setPosition:p.y+offset.y ofDividerAtIndex:0]; |
| 198 |
|
|
} |
| 199 |
masaki |
301 |
} |
| 200 |
|
|
|
| 201 |
|
|
|
| 202 |
masaki |
304 |
// QLPreviewPanel support |
| 203 |
|
|
- (NSRect)selectionItemRect |
| 204 |
|
|
{ |
| 205 |
|
|
NSRect rect = [coverFlow selectedImageFrame]; |
| 206 |
|
|
rect = [coverFlow convertRectToBase:rect]; |
| 207 |
|
|
rect.origin = [[coverFlow window] convertBaseToScreen:rect.origin]; |
| 208 |
|
|
return rect; |
| 209 |
|
|
} |
| 210 |
|
|
|
| 211 |
masaki |
294 |
#pragma mark#### NSSplitView Delegate #### |
| 212 |
|
|
- (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex |
| 213 |
|
|
{ |
| 214 |
|
|
return 130; |
| 215 |
|
|
} |
| 216 |
masaki |
281 |
|
| 217 |
masaki |
301 |
@end |
| 218 |
masaki |
294 |
|
| 219 |
|
|
|
| 220 |
masaki |
301 |
@implementation XspfMXspfObject(XspfMIKImageBrowserItem) |
| 221 |
|
|
/*! |
| 222 |
|
|
@method imageUID |
| 223 |
|
|
@abstract Returns a unique string that identify this data source item (required). |
| 224 |
|
|
@discussion The image browser uses this identifier to keep the correspondance between its cache and the data source item |
| 225 |
|
|
*/ |
| 226 |
|
|
- (NSString *) imageUID |
| 227 |
|
|
{ |
| 228 |
|
|
return self.urlString; |
| 229 |
|
|
} |
| 230 |
|
|
|
| 231 |
|
|
/*! |
| 232 |
|
|
@method imageRepresentationType |
| 233 |
|
|
@abstract Returns the representation of the image to display (required). |
| 234 |
|
|
@discussion Keys for imageRepresentationType are defined below. |
| 235 |
|
|
*/ |
| 236 |
|
|
- (NSString *) imageRepresentationType |
| 237 |
|
|
{ |
| 238 |
|
|
return IKImageBrowserQuickLookPathRepresentationType; |
| 239 |
|
|
} |
| 240 |
|
|
|
| 241 |
|
|
/*! |
| 242 |
|
|
@method imageRepresentation |
| 243 |
|
|
@abstract Returns the image to display (required). Can return nil if the item has no image to display. |
| 244 |
|
|
@discussion This methods is called frequently, so the receiver should cache the returned instance. |
| 245 |
|
|
*/ |
| 246 |
|
|
- (id) imageRepresentation |
| 247 |
|
|
{ |
| 248 |
|
|
return self.url; |
| 249 |
|
|
} |
| 250 |
|
|
|
| 251 |
|
|
/*! |
| 252 |
|
|
@method imageVersion |
| 253 |
|
|
@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 |
| 254 |
|
|
*/ |
| 255 |
|
|
//- (NSUInteger) imageVersion; |
| 256 |
|
|
|
| 257 |
|
|
/*! |
| 258 |
|
|
@method imageTitle |
| 259 |
|
|
@abstract Returns the title to display as a NSString. Use setValue:forKey: with IKImageBrowserCellTitleAttribute to set text attributes. |
| 260 |
|
|
*/ |
| 261 |
|
|
- (NSString *) imageTitle |
| 262 |
|
|
{ |
| 263 |
|
|
return self.title; |
| 264 |
|
|
} |
| 265 |
|
|
|
| 266 |
|
|
/*! |
| 267 |
|
|
@method imageSubtitle |
| 268 |
|
|
@abstract Returns the subtitle to display as a NSString. Use setValue:forKey: with IKImageBrowserCellSubtitleAttribute to set text attributes. |
| 269 |
|
|
*/ |
| 270 |
|
|
- (NSString *) imageSubtitle |
| 271 |
|
|
{ |
| 272 |
|
|
return [NSString stringWithFormat: |
| 273 |
|
|
NSLocalizedString(@"%@ Movies", @"%@ Movies"), |
| 274 |
|
|
self.movieNum]; |
| 275 |
|
|
} |
| 276 |
|
|
|
| 277 |
|
|
/*! |
| 278 |
|
|
@method isSelectable |
| 279 |
|
|
@abstract Returns whether this item is selectable. |
| 280 |
|
|
@discussion The receiver can implement this methods to forbid selection of this item by returning NO. |
| 281 |
|
|
*/ |
| 282 |
|
|
//- (BOOL) isSelectable; |
| 283 |
|
|
|
| 284 |
masaki |
281 |
@end |