Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMCollectionViewController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 524 - (hide annotations) (download)
Thu Jan 27 15:05:26 2011 UTC (13 years, 2 months ago) by masakih
File size: 8009 byte(s)
[Fix] アイコンビュー、スモールアイコンビューに変更時にfirstResponderがwindowになってしまう問題を解消。
1 masaki 16 //
2     // XspfMCollectionViewController.m
3     // XspfManager
4     //
5     // Created by Hori,Masaki on 09/11/05.
6     //
7    
8 masakih 350 /*
9 masakih 365 This source code is release under the New BSD License.
10 masakih 350 Copyright (c) 2009-2010, masakih
11     All rights reserved.
12    
13 masakih 365 ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に
14     限り、再頒布および使用が許可されます。
15    
16     1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含
17     めること。
18     2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表
19     示、本条件一覧、および下記免責条項を含めること。
20     3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、
21     コントリビューターの名前を使用してはならない。
22     本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、
23     明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証
24     も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター
25     も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか
26     厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する
27     可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用
28     サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定
29     されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい
30     て、一切責任を負わないものとします。
31 masakih 350 -------------------------------------------------------------------
32     Copyright (c) 2009-2010, masakih
33     All rights reserved.
34    
35 masakih 365 Redistribution and use in source and binary forms, with or without
36     modification, are permitted provided that the following conditions
37     are met:
38 masakih 350
39 masakih 365 1, Redistributions of source code must retain the above copyright
40     notice, this list of conditions and the following disclaimer.
41     2, Redistributions in binary form must reproduce the above copyright
42     notice, this list of conditions and the following disclaimer in
43     the documentation and/or other materials provided with the
44     distribution.
45     3, The names of its contributors may be used to endorse or promote
46     products derived from this software without specific prior
47     written permission.
48     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
51     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
52     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
53     INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
54     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
55     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
56     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
58     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59     POSSIBILITY OF SUCH DAMAGE.
60 masakih 350 */
61    
62 masaki 16 #import "XspfMCollectionViewController.h"
63    
64 masaki 304 #import "XspfMCollectionView.h"
65 masaki 175 #import "XspfMCollectionViewItem.h"
66 masaki 238 #import "XspfMXspfObject.h"
67 masaki 16
68 masakih 374 #import "XspfMPreferences.h"
69    
70 masaki 306 @interface NSCollectionView(CocoaPrivatemethods)
71 masaki 307 - (void)_getRow:(NSUInteger *)fp8 column:(NSUInteger *)fp12 forPoint:(NSPoint)fp16;
72     - (NSRect)_frameRectForIndexInGrid:(NSUInteger)fp8 gridSize:(NSSize)fp12;
73 masaki 306 - (NSRange)columnCountRange;
74     @end
75 masaki 175
76 masaki 316
77     @interface XspfMCollectionViewController (XspfMPrivate)
78     - (void)setCollectionItem:(XspfMCollectionViewItem *)newItem;
79     @end
80    
81     static NSString *const XspfMCollectionItemSizeKey = @"Collection Item Size";
82    
83 masaki 16 @implementation XspfMCollectionViewController
84    
85     - (id)init
86     {
87     [super initWithNibName:@"CollectionView" bundle:nil];
88    
89     return self;
90     }
91    
92 masaki 82 - (void)awakeFromNib
93     {
94 masakih 374 NSInteger type = [XspfMPreferences sharedPreference].collectionItemSize;
95 masaki 316 [self setCollectionItem:type == 0 ? regularItem : smallItem];
96 masaki 82 }
97    
98 masaki 190 - (void)setCollectionItem:(XspfMCollectionViewItem *)newItem
99 masaki 175 {
100 masaki 316 if(collectionViewItem == newItem) return;
101    
102 masakih 359
103     // editing text field resign from first responder.
104 masakih 524 [[[self view] window] endEditingFor:nil];
105 masakih 359
106 masaki 175 [collectionView setItemPrototype:newItem];
107     NSSize viewSize = [[newItem view] frame].size;
108     [collectionView setMinItemSize:viewSize];
109     [collectionView setMaxItemSize:viewSize];
110     [scrollView setVerticalLineScroll:viewSize.height];
111 masaki 190 collectionViewItem = newItem;
112 masaki 316
113 masakih 524 [[[self view] window] makeFirstResponder:[self view]];
114 masaki 316
115 masakih 524
116 masakih 374 [XspfMPreferences sharedPreference].collectionItemSize = collectionViewItem == regularItem ? 0 : 1;
117 masaki 175 }
118 masaki 229
119     - (IBAction)changeLabel:(id)sender
120     {
121 masaki 238 XspfMXspfObject *object = [sender representedObject];
122 masaki 229 object.label = [sender objectValue];
123     }
124    
125 masaki 175 - (IBAction)collectionViewItemViewRegular:(id)sender
126     {
127     [self setCollectionItem:regularItem];
128     }
129     - (IBAction)collectionViewItemViewSmall:(id)sender
130     {
131     [self setCollectionItem:smallItem];
132     }
133    
134 masakih 429 - (IBAction)scrollToSelection:(id)sender
135     {
136    
137     id item = nil;
138     @try {
139     item = [collectionView itemAtIndex:[[self representedObject] selectionIndex]];
140     }
141     @catch (id ex) {
142     NSLog(@"Exception -> %@", ex);
143     }
144     if(!item) return;
145    
146     NSRect rect = [[item view] frame];
147     // NSLog(@"selected rect -> %@", NSStringFromRect(rect));
148     [collectionView scrollRectToVisible:rect];
149     }
150    
151 masaki 190 - (XspfMCollectionItemType)collectionItemType
152     {
153     if(collectionViewItem == regularItem) return typeXspfMRegularItem;
154     if(collectionViewItem == smallItem) return typeXSpfMSmallItem;
155    
156     return typeXspfMUnknownItem;
157     }
158    
159 masaki 16 #pragma mark#### XspfMCollectionView Delegate ####
160     - (void)enterAction:(XspfMCollectionView *)view
161     {
162 masaki 74 [NSApp sendAction:@selector(openXspf:) to:nil from:self];
163 masaki 16 }
164    
165 masaki 304 // QLPreviewPanel support
166 masaki 306 - (NSRect)selectionItemRectForLeopard
167     {
168     NSRect collectionFrame = [collectionView frame];
169     NSSize itemSize = [collectionView minItemSize];
170    
171     // get right edge item colum.
172     NSPoint rightEdge = NSMakePoint(collectionFrame.size.width - 1, itemSize.height / 2);
173     NSUInteger col = 0;
174     NSUInteger row = 0;
175     [collectionView _getRow:&row column:&col forPoint:rightEdge];
176    
177     // get selected item's row and column.
178     NSUInteger index = [[self representedObject] selectionIndex];
179     NSUInteger maxCol = col;
180     col = index % maxCol;
181     row = index / maxCol;
182    
183     // caluculate selected item view's image view point.
184     NSPoint itemImagePoint;
185     itemImagePoint.x = itemSize.width / 2 + itemSize.width * col;
186     itemImagePoint.y = itemSize.height * .2 + itemSize.height * row; // CollectionView is fliped.
187    
188     // get item image view.
189     NSView *thumbnail = [collectionView hitTest:itemImagePoint];
190     NSView *view = [[thumbnail superview] superview];
191    
192     NSRect frame = [thumbnail frame];
193    
194     NSRect convertedRect = [view convertRect:frame toView:collectionView];
195     if(!NSIntersectsRect([collectionView visibleRect], convertedRect)) {
196     return NSZeroRect;
197     }
198    
199     frame = [view convertRectToBase:frame];
200     frame.origin = [[view window] convertBaseToScreen:frame.origin];
201     return frame;
202     }
203 masaki 304 - (NSRect)selectionItemRect
204     {
205 masaki 306 if(![collectionView respondsToSelector:@selector(itemAtIndex:)]) {
206     return [self selectionItemRectForLeopard];
207     }
208 masakih 429
209     id item = nil;
210     @try {
211     item = [collectionView itemAtIndex:[[self representedObject] selectionIndex]];
212     }
213     @catch (id ex) {
214     NSLog(@"Exception -> %@", ex);
215     return NSZeroRect;
216     }
217    
218 masaki 304 NSRect rect = [item thumbnailFrameCoordinateBase];
219     return rect;
220     }
221    
222 masaki 16 #pragma mark#### Test ####
223     - (void)test01:(id)sender
224     {
225 masaki 188 HMLog(HMLogLevelError, @"hoge");
226 masaki 16 }
227    
228    
229     @end

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