Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCollectionViewController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 350 - (hide annotations) (download)
Sun May 16 02:50:00 2010 UTC (13 years, 11 months ago) by masakih
File size: 7285 byte(s)
著作権表示、免責表示を追加。
1 masaki 16 //
2     // XspfMCollectionViewController.m
3     // XspfManager
4     //
5     // Created by Hori,Masaki on 09/11/05.
6     //
7    
8 masakih 350 /*
9     Copyright (c) 2009-2010, masakih
10     All rights reserved.
11     ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に限り、再頒布および使用が許可されます。
12    
13     1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含めること。
14     2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表示、本条件一覧、および下記免責条項を含めること。
15     3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、コントリビューターの名前を使用してはならない。
16     本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューターも、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害について、一切責任を負わないものとします。
17     -------------------------------------------------------------------
18     Copyright (c) 2009-2010, masakih
19     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 16 #import "XspfMCollectionViewController.h"
30    
31 masaki 304 #import "XspfMCollectionView.h"
32 masaki 175 #import "XspfMCollectionViewItem.h"
33 masaki 238 #import "XspfMXspfObject.h"
34 masaki 16
35 masaki 306 @interface NSCollectionView(CocoaPrivatemethods)
36 masaki 307 - (void)_getRow:(NSUInteger *)fp8 column:(NSUInteger *)fp12 forPoint:(NSPoint)fp16;
37     - (NSRect)_frameRectForIndexInGrid:(NSUInteger)fp8 gridSize:(NSSize)fp12;
38 masaki 306 - (NSRange)columnCountRange;
39     @end
40 masaki 175
41 masaki 316
42     @interface XspfMCollectionViewController (XspfMPrivate)
43     - (void)setCollectionItem:(XspfMCollectionViewItem *)newItem;
44     @end
45    
46     static NSString *const XspfMCollectionItemSizeKey = @"Collection Item Size";
47    
48 masaki 16 @implementation XspfMCollectionViewController
49    
50     - (id)init
51     {
52     [super initWithNibName:@"CollectionView" bundle:nil];
53    
54     return self;
55     }
56    
57 masaki 82 - (void)awakeFromNib
58     {
59 masaki 316 NSInteger type = [[NSUserDefaults standardUserDefaults] integerForKey:XspfMCollectionItemSizeKey];
60     [self setCollectionItem:type == 0 ? regularItem : smallItem];
61 masaki 82 }
62    
63 masaki 190 - (void)setCollectionItem:(XspfMCollectionViewItem *)newItem
64 masaki 175 {
65 masaki 316 if(collectionViewItem == newItem) return;
66    
67 masaki 175 [collectionView setItemPrototype:newItem];
68     NSSize viewSize = [[newItem view] frame].size;
69     [collectionView setMinItemSize:viewSize];
70     [collectionView setMaxItemSize:viewSize];
71     [scrollView setVerticalLineScroll:viewSize.height];
72 masaki 190 collectionViewItem = newItem;
73 masaki 316
74    
75     [[NSUserDefaults standardUserDefaults] setInteger:collectionViewItem == regularItem ? 0 : 1 forKey:XspfMCollectionItemSizeKey];
76 masaki 175 }
77 masaki 229
78     - (IBAction)changeLabel:(id)sender
79     {
80 masaki 238 XspfMXspfObject *object = [sender representedObject];
81 masaki 229 object.label = [sender objectValue];
82     }
83    
84 masaki 175 - (IBAction)collectionViewItemViewRegular:(id)sender
85     {
86     [self setCollectionItem:regularItem];
87     }
88     - (IBAction)collectionViewItemViewSmall:(id)sender
89     {
90     [self setCollectionItem:smallItem];
91     }
92    
93 masaki 190 - (XspfMCollectionItemType)collectionItemType
94     {
95     if(collectionViewItem == regularItem) return typeXspfMRegularItem;
96     if(collectionViewItem == smallItem) return typeXSpfMSmallItem;
97    
98     return typeXspfMUnknownItem;
99     }
100    
101 masaki 16 #pragma mark#### XspfMCollectionView Delegate ####
102     - (void)enterAction:(XspfMCollectionView *)view
103     {
104 masaki 74 [NSApp sendAction:@selector(openXspf:) to:nil from:self];
105 masaki 16 }
106    
107 masaki 304 // QLPreviewPanel support
108 masaki 306 - (NSRect)selectionItemRectForLeopard
109     {
110     NSRect collectionFrame = [collectionView frame];
111     NSSize itemSize = [collectionView minItemSize];
112    
113     // get right edge item colum.
114     NSPoint rightEdge = NSMakePoint(collectionFrame.size.width - 1, itemSize.height / 2);
115     NSUInteger col = 0;
116     NSUInteger row = 0;
117     [collectionView _getRow:&row column:&col forPoint:rightEdge];
118    
119     // get selected item's row and column.
120     NSUInteger index = [[self representedObject] selectionIndex];
121     NSUInteger maxCol = col;
122     col = index % maxCol;
123     row = index / maxCol;
124    
125     // caluculate selected item view's image view point.
126     NSPoint itemImagePoint;
127     itemImagePoint.x = itemSize.width / 2 + itemSize.width * col;
128     itemImagePoint.y = itemSize.height * .2 + itemSize.height * row; // CollectionView is fliped.
129    
130     // get item image view.
131     NSView *thumbnail = [collectionView hitTest:itemImagePoint];
132     NSView *view = [[thumbnail superview] superview];
133    
134     NSRect frame = [thumbnail frame];
135    
136     NSRect convertedRect = [view convertRect:frame toView:collectionView];
137     if(!NSIntersectsRect([collectionView visibleRect], convertedRect)) {
138     return NSZeroRect;
139     }
140    
141     frame = [view convertRectToBase:frame];
142     frame.origin = [[view window] convertBaseToScreen:frame.origin];
143     return frame;
144     }
145 masaki 304 - (NSRect)selectionItemRect
146     {
147 masaki 306 if(![collectionView respondsToSelector:@selector(itemAtIndex:)]) {
148     return [self selectionItemRectForLeopard];
149     }
150 masaki 304 id item = [collectionView itemAtIndex:[[self representedObject] selectionIndex]];
151     NSRect rect = [item thumbnailFrameCoordinateBase];
152     return rect;
153     }
154    
155 masaki 16 #pragma mark#### Test ####
156     - (void)test01:(id)sender
157     {
158 masaki 188 HMLog(HMLogLevelError, @"hoge");
159 masaki 16 }
160    
161    
162     @end

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