Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCollectionViewController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 316 - (hide annotations) (download)
Sat Feb 6 15:27:43 2010 UTC (14 years, 2 months ago) by masaki
File size: 3939 byte(s)
[New] 表示タイプを記憶するようにした。
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 masaki 307 - (void)_getRow:(NSUInteger *)fp8 column:(NSUInteger *)fp12 forPoint:(NSPoint)fp16;
17     - (NSRect)_frameRectForIndexInGrid:(NSUInteger)fp8 gridSize:(NSSize)fp12;
18 masaki 306 - (NSRange)columnCountRange;
19     @end
20 masaki 175
21 masaki 316
22     @interface XspfMCollectionViewController (XspfMPrivate)
23     - (void)setCollectionItem:(XspfMCollectionViewItem *)newItem;
24     @end
25    
26     static NSString *const XspfMCollectionItemSizeKey = @"Collection Item Size";
27    
28 masaki 16 @implementation XspfMCollectionViewController
29    
30     - (id)init
31     {
32     [super initWithNibName:@"CollectionView" bundle:nil];
33    
34     return self;
35     }
36    
37 masaki 82 - (void)awakeFromNib
38     {
39 masaki 316 NSInteger type = [[NSUserDefaults standardUserDefaults] integerForKey:XspfMCollectionItemSizeKey];
40     [self setCollectionItem:type == 0 ? regularItem : smallItem];
41 masaki 82 }
42    
43 masaki 190 - (void)setCollectionItem:(XspfMCollectionViewItem *)newItem
44 masaki 175 {
45 masaki 316 if(collectionViewItem == newItem) return;
46    
47 masaki 175 [collectionView setItemPrototype:newItem];
48     NSSize viewSize = [[newItem view] frame].size;
49     [collectionView setMinItemSize:viewSize];
50     [collectionView setMaxItemSize:viewSize];
51     [scrollView setVerticalLineScroll:viewSize.height];
52 masaki 190 collectionViewItem = newItem;
53 masaki 316
54    
55     [[NSUserDefaults standardUserDefaults] setInteger:collectionViewItem == regularItem ? 0 : 1 forKey:XspfMCollectionItemSizeKey];
56 masaki 175 }
57 masaki 229
58     - (IBAction)changeLabel:(id)sender
59     {
60 masaki 238 XspfMXspfObject *object = [sender representedObject];
61 masaki 229 object.label = [sender objectValue];
62     }
63    
64 masaki 175 - (IBAction)collectionViewItemViewRegular:(id)sender
65     {
66     [self setCollectionItem:regularItem];
67     }
68     - (IBAction)collectionViewItemViewSmall:(id)sender
69     {
70     [self setCollectionItem:smallItem];
71     }
72    
73 masaki 190 - (XspfMCollectionItemType)collectionItemType
74     {
75     if(collectionViewItem == regularItem) return typeXspfMRegularItem;
76     if(collectionViewItem == smallItem) return typeXSpfMSmallItem;
77    
78     return typeXspfMUnknownItem;
79     }
80    
81 masaki 16 #pragma mark#### XspfMCollectionView Delegate ####
82     - (void)enterAction:(XspfMCollectionView *)view
83     {
84 masaki 74 [NSApp sendAction:@selector(openXspf:) to:nil from:self];
85 masaki 16 }
86    
87 masaki 304 // QLPreviewPanel support
88 masaki 306 - (NSRect)selectionItemRectForLeopard
89     {
90     NSRect collectionFrame = [collectionView frame];
91     NSSize itemSize = [collectionView minItemSize];
92    
93     // get right edge item colum.
94     NSPoint rightEdge = NSMakePoint(collectionFrame.size.width - 1, itemSize.height / 2);
95     NSUInteger col = 0;
96     NSUInteger row = 0;
97     [collectionView _getRow:&row column:&col forPoint:rightEdge];
98    
99     // get selected item's row and column.
100     NSUInteger index = [[self representedObject] selectionIndex];
101     NSUInteger maxCol = col;
102     col = index % maxCol;
103     row = index / maxCol;
104    
105     // caluculate selected item view's image view point.
106     NSPoint itemImagePoint;
107     itemImagePoint.x = itemSize.width / 2 + itemSize.width * col;
108     itemImagePoint.y = itemSize.height * .2 + itemSize.height * row; // CollectionView is fliped.
109    
110     // get item image view.
111     NSView *thumbnail = [collectionView hitTest:itemImagePoint];
112     NSView *view = [[thumbnail superview] superview];
113    
114     NSRect frame = [thumbnail frame];
115    
116     NSRect convertedRect = [view convertRect:frame toView:collectionView];
117     if(!NSIntersectsRect([collectionView visibleRect], convertedRect)) {
118     return NSZeroRect;
119     }
120    
121     frame = [view convertRectToBase:frame];
122     frame.origin = [[view window] convertBaseToScreen:frame.origin];
123     return frame;
124     }
125 masaki 304 - (NSRect)selectionItemRect
126     {
127 masaki 306 if(![collectionView respondsToSelector:@selector(itemAtIndex:)]) {
128     return [self selectionItemRectForLeopard];
129     }
130 masaki 304 id item = [collectionView itemAtIndex:[[self representedObject] selectionIndex]];
131     NSRect rect = [item thumbnailFrameCoordinateBase];
132     return rect;
133     }
134    
135 masaki 16 #pragma mark#### Test ####
136     - (void)test01:(id)sender
137     {
138 masaki 188 HMLog(HMLogLevelError, @"hoge");
139 masaki 16 }
140    
141    
142     @end

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