| 1 |
masaki |
16 |
// |
| 2 |
|
|
// XspfMCollectionViewController.m |
| 3 |
|
|
// XspfManager |
| 4 |
|
|
// |
| 5 |
|
|
// Created by Hori,Masaki on 09/11/05. |
| 6 |
|
|
// Copyright 2009 masakih. All rights reserved. |
| 7 |
|
|
// |
| 8 |
|
|
|
| 9 |
|
|
#import "XspfMCollectionViewController.h" |
| 10 |
|
|
|
| 11 |
masaki |
304 |
#import "XspfMCollectionView.h" |
| 12 |
masaki |
175 |
#import "XspfMCollectionViewItem.h" |
| 13 |
masaki |
238 |
#import "XspfMXspfObject.h" |
| 14 |
masaki |
16 |
|
| 15 |
masaki |
306 |
@interface NSCollectionView(CocoaPrivatemethods) |
| 16 |
|
|
- (void)_getRow:(unsigned int *)fp8 column:(unsigned int *)fp12 forPoint:(struct _NSPoint)fp16; |
| 17 |
|
|
- (NSRect)_frameRectForIndexInGrid:(unsigned int)fp8 gridSize:(struct _NSSize)fp12; |
| 18 |
|
|
- (NSRange)columnCountRange; |
| 19 |
|
|
@end |
| 20 |
masaki |
175 |
|
| 21 |
masaki |
16 |
@implementation XspfMCollectionViewController |
| 22 |
|
|
|
| 23 |
|
|
- (id)init |
| 24 |
|
|
{ |
| 25 |
|
|
[super initWithNibName:@"CollectionView" bundle:nil]; |
| 26 |
|
|
|
| 27 |
|
|
return self; |
| 28 |
|
|
} |
| 29 |
|
|
|
| 30 |
masaki |
82 |
- (void)awakeFromNib |
| 31 |
|
|
{ |
| 32 |
|
|
NSView *view = [collectionViewItem view]; |
| 33 |
|
|
|
| 34 |
|
|
[scrollView setVerticalLineScroll:[view frame].size.height]; |
| 35 |
|
|
} |
| 36 |
|
|
|
| 37 |
masaki |
190 |
- (void)setCollectionItem:(XspfMCollectionViewItem *)newItem |
| 38 |
masaki |
175 |
{ |
| 39 |
|
|
[collectionView setItemPrototype:newItem]; |
| 40 |
|
|
NSSize viewSize = [[newItem view] frame].size; |
| 41 |
|
|
[collectionView setMinItemSize:viewSize]; |
| 42 |
|
|
[collectionView setMaxItemSize:viewSize]; |
| 43 |
|
|
[scrollView setVerticalLineScroll:viewSize.height]; |
| 44 |
masaki |
190 |
collectionViewItem = newItem; |
| 45 |
masaki |
175 |
} |
| 46 |
masaki |
229 |
|
| 47 |
|
|
- (IBAction)changeLabel:(id)sender |
| 48 |
|
|
{ |
| 49 |
masaki |
238 |
XspfMXspfObject *object = [sender representedObject]; |
| 50 |
masaki |
229 |
object.label = [sender objectValue]; |
| 51 |
|
|
} |
| 52 |
|
|
|
| 53 |
masaki |
175 |
- (IBAction)collectionViewItemViewRegular:(id)sender |
| 54 |
|
|
{ |
| 55 |
|
|
[self setCollectionItem:regularItem]; |
| 56 |
|
|
} |
| 57 |
|
|
- (IBAction)collectionViewItemViewSmall:(id)sender |
| 58 |
|
|
{ |
| 59 |
|
|
[self setCollectionItem:smallItem]; |
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
masaki |
190 |
- (XspfMCollectionItemType)collectionItemType |
| 63 |
|
|
{ |
| 64 |
|
|
if(collectionViewItem == regularItem) return typeXspfMRegularItem; |
| 65 |
|
|
if(collectionViewItem == smallItem) return typeXSpfMSmallItem; |
| 66 |
|
|
|
| 67 |
|
|
return typeXspfMUnknownItem; |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
masaki |
16 |
#pragma mark#### XspfMCollectionView Delegate #### |
| 71 |
|
|
- (void)enterAction:(XspfMCollectionView *)view |
| 72 |
|
|
{ |
| 73 |
masaki |
74 |
[NSApp sendAction:@selector(openXspf:) to:nil from:self]; |
| 74 |
masaki |
16 |
} |
| 75 |
|
|
|
| 76 |
masaki |
304 |
// QLPreviewPanel support |
| 77 |
masaki |
306 |
- (NSRect)selectionItemRectForLeopard |
| 78 |
|
|
{ |
| 79 |
|
|
NSRect collectionFrame = [collectionView frame]; |
| 80 |
|
|
NSSize itemSize = [collectionView minItemSize]; |
| 81 |
|
|
|
| 82 |
|
|
// get right edge item colum. |
| 83 |
|
|
NSPoint rightEdge = NSMakePoint(collectionFrame.size.width - 1, itemSize.height / 2); |
| 84 |
|
|
NSUInteger col = 0; |
| 85 |
|
|
NSUInteger row = 0; |
| 86 |
|
|
[collectionView _getRow:&row column:&col forPoint:rightEdge]; |
| 87 |
|
|
|
| 88 |
|
|
// get selected item's row and column. |
| 89 |
|
|
NSUInteger index = [[self representedObject] selectionIndex]; |
| 90 |
|
|
NSUInteger maxCol = col; |
| 91 |
|
|
col = index % maxCol; |
| 92 |
|
|
row = index / maxCol; |
| 93 |
|
|
|
| 94 |
|
|
// caluculate selected item view's image view point. |
| 95 |
|
|
NSPoint itemImagePoint; |
| 96 |
|
|
itemImagePoint.x = itemSize.width / 2 + itemSize.width * col; |
| 97 |
|
|
itemImagePoint.y = itemSize.height * .2 + itemSize.height * row; // CollectionView is fliped. |
| 98 |
|
|
|
| 99 |
|
|
// get item image view. |
| 100 |
|
|
NSView *thumbnail = [collectionView hitTest:itemImagePoint]; |
| 101 |
|
|
NSView *view = [[thumbnail superview] superview]; |
| 102 |
|
|
|
| 103 |
|
|
NSRect frame = [thumbnail frame]; |
| 104 |
|
|
|
| 105 |
|
|
NSRect convertedRect = [view convertRect:frame toView:collectionView]; |
| 106 |
|
|
if(!NSIntersectsRect([collectionView visibleRect], convertedRect)) { |
| 107 |
|
|
return NSZeroRect; |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
|
|
frame = [view convertRectToBase:frame]; |
| 111 |
|
|
frame.origin = [[view window] convertBaseToScreen:frame.origin]; |
| 112 |
|
|
return frame; |
| 113 |
|
|
} |
| 114 |
masaki |
304 |
- (NSRect)selectionItemRect |
| 115 |
|
|
{ |
| 116 |
masaki |
306 |
if(![collectionView respondsToSelector:@selector(itemAtIndex:)]) { |
| 117 |
|
|
return [self selectionItemRectForLeopard]; |
| 118 |
|
|
} |
| 119 |
masaki |
304 |
id item = [collectionView itemAtIndex:[[self representedObject] selectionIndex]]; |
| 120 |
|
|
NSRect rect = [item thumbnailFrameCoordinateBase]; |
| 121 |
|
|
return rect; |
| 122 |
|
|
} |
| 123 |
|
|
|
| 124 |
masaki |
16 |
#pragma mark#### Test #### |
| 125 |
|
|
- (void)test01:(id)sender |
| 126 |
|
|
{ |
| 127 |
masaki |
188 |
HMLog(HMLogLevelError, @"hoge"); |
| 128 |
masaki |
16 |
} |
| 129 |
|
|
|
| 130 |
|
|
|
| 131 |
|
|
@end |