PageRenderTime 36ms CodeModel.GetById 25ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/AppKit/rhino.platform/CPCollectionView.j

http://github.com/polymar/polish
Unknown | 408 lines | 408 code | 0 blank | 0 comment | 0 complexity | 917f2686d395afdbfce445c4c88e304d MD5 | raw file
  1I;20;Foundation/CPArray.jI;19;Foundation/CPData.jI;23;Foundation/CPIndexSet.jI;28;Foundation/CPKeyedArchiver.jI;30;Foundation/CPKeyedUnarchiver.jI;15;AppKit/CPView.jc;13723;
  2var _1=objj_allocateClassPair(CPView,"CPCollectionView"),_2=_1.isa;
  3class_addIvars(_1,[new objj_ivar("_content"),new objj_ivar("_items"),new objj_ivar("_itemData"),new objj_ivar("_itemPrototype"),new objj_ivar("_itemForDragging"),new objj_ivar("_cachedItems"),new objj_ivar("_maxNumberOfRows"),new objj_ivar("_maxNumberOfColumns"),new objj_ivar("_minItemSize"),new objj_ivar("_maxItemSize"),new objj_ivar("_tileWidth"),new objj_ivar("_isSelectable"),new objj_ivar("_allowsMultipleSelection"),new objj_ivar("_allowsEmptySelection"),new objj_ivar("_selectionIndexes"),new objj_ivar("_itemSize"),new objj_ivar("_horizontalMargin"),new objj_ivar("_verticalMargin"),new objj_ivar("_numberOfRows"),new objj_ivar("_numberOfColumns"),new objj_ivar("_delegate")]);
  4objj_registerClassPair(_1);
  5objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  6class_addMethods(_1,[new objj_method(sel_getUid("initWithFrame:"),function(_3,_4,_5){
  7with(_3){
  8_3=objj_msgSendSuper({receiver:_3,super_class:objj_getClass("CPView")},"initWithFrame:",_5);
  9if(_3){
 10_items=[];
 11_content=[];
 12_cachedItems=[];
 13_itemSize=CGSizeMakeZero();
 14_minItemSize=CGSizeMakeZero();
 15_maxItemSize=CGSizeMakeZero();
 16_verticalMargin=5;
 17_tileWidth=-1;
 18_selectionIndexes=objj_msgSend(CPIndexSet,"indexSet");
 19_allowsEmptySelection=YES;
 20_isSelectable=YES;
 21}
 22return _3;
 23}
 24}),new objj_method(sel_getUid("setItemPrototype:"),function(_6,_7,_8){
 25with(_6){
 26_itemData=objj_msgSend(CPKeyedArchiver,"archivedDataWithRootObject:",_8);
 27_itemForDragging=_8;
 28_itemPrototype=_8;
 29objj_msgSend(_6,"reloadContent");
 30}
 31}),new objj_method(sel_getUid("itemPrototype"),function(_9,_a){
 32with(_9){
 33return _itemPrototype;
 34}
 35}),new objj_method(sel_getUid("newItemForRepresentedObject:"),function(_b,_c,_d){
 36with(_b){
 37var _e=nil;
 38if(_cachedItems.length){
 39_e=_cachedItems.pop();
 40}else{
 41_e=objj_msgSend(CPKeyedUnarchiver,"unarchiveObjectWithData:",_itemData);
 42}
 43objj_msgSend(_e,"setRepresentedObject:",_d);
 44objj_msgSend(objj_msgSend(_e,"view"),"setFrameSize:",_itemSize);
 45return _e;
 46}
 47}),new objj_method(sel_getUid("acceptsFirstResponder"),function(_f,_10){
 48with(_f){
 49return YES;
 50}
 51}),new objj_method(sel_getUid("isFirstResponder"),function(_11,_12){
 52with(_11){
 53return objj_msgSend(objj_msgSend(_11,"window"),"firstResponder")==_11;
 54}
 55}),new objj_method(sel_getUid("setContent:"),function(_13,_14,_15){
 56with(_13){
 57if(_content==_15){
 58return;
 59}
 60_content=_15;
 61objj_msgSend(_13,"reloadContent");
 62}
 63}),new objj_method(sel_getUid("content"),function(_16,_17){
 64with(_16){
 65return _content;
 66}
 67}),new objj_method(sel_getUid("items"),function(_18,_19){
 68with(_18){
 69return _items;
 70}
 71}),new objj_method(sel_getUid("setSelectable:"),function(_1a,_1b,_1c){
 72with(_1a){
 73if(_isSelectable==_1c){
 74return;
 75}
 76_isSelectable=_1c;
 77if(!_isSelectable){
 78var _1d=CPNotFound;
 79while((_1d=objj_msgSend(_selectionIndexes,"indexGreaterThanIndex:",_1d))!=CPNotFound){
 80objj_msgSend(_items[_1d],"setSelected:",NO);
 81}
 82}
 83}
 84}),new objj_method(sel_getUid("isSelected"),function(_1e,_1f){
 85with(_1e){
 86return _isSelected;
 87}
 88}),new objj_method(sel_getUid("setAllowsEmptySelection:"),function(_20,_21,_22){
 89with(_20){
 90_allowsEmptySelection=_22;
 91}
 92}),new objj_method(sel_getUid("allowsEmptySelection"),function(_23,_24){
 93with(_23){
 94return _allowsEmptySelection;
 95}
 96}),new objj_method(sel_getUid("setAllowsMultipleSelection:"),function(_25,_26,_27){
 97with(_25){
 98_allowsMultipleSelection=_27;
 99}
100}),new objj_method(sel_getUid("allowsMultipleSelection"),function(_28,_29){
101with(_28){
102return _allowsMultipleSelection;
103}
104}),new objj_method(sel_getUid("setSelectionIndexes:"),function(_2a,_2b,_2c){
105with(_2a){
106if(_selectionIndexes==_2c||!_isSelectable){
107return;
108}
109var _2d=CPNotFound;
110while((_2d=objj_msgSend(_selectionIndexes,"indexGreaterThanIndex:",_2d))!=CPNotFound){
111objj_msgSend(_items[_2d],"setSelected:",NO);
112}
113_selectionIndexes=_2c;
114var _2d=CPNotFound;
115while((_2d=objj_msgSend(_selectionIndexes,"indexGreaterThanIndex:",_2d))!=CPNotFound){
116objj_msgSend(_items[_2d],"setSelected:",YES);
117}
118if(objj_msgSend(_delegate,"respondsToSelector:",sel_getUid("collectionViewDidChangeSelection:"))){
119objj_msgSend(_delegate,"collectionViewDidChangeSelection:",_2a);
120}
121}
122}),new objj_method(sel_getUid("selectionIndexes"),function(_2e,_2f){
123with(_2e){
124return _selectionIndexes;
125}
126}),new objj_method(sel_getUid("reloadContent"),function(_30,_31){
127with(_30){
128var _32=_items.length;
129while(_32--){
130objj_msgSend(objj_msgSend(_items[_32],"view"),"removeFromSuperview");
131_cachedItems.push(_items[_32]);
132}
133_items=[];
134if(!_itemData||!_content){
135return;
136}
137var _33=0;
138_32=_content.length;
139for(;_33<_32;++_33){
140_items.push(objj_msgSend(_30,"newItemForRepresentedObject:",_content[_33]));
141objj_msgSend(_30,"addSubview:",objj_msgSend(_items[_33],"view"));
142}
143objj_msgSend(_30,"tile");
144}
145}),new objj_method(sel_getUid("tile"),function(_34,_35){
146with(_34){
147var _36=CGRectGetWidth(objj_msgSend(_34,"bounds"));
148if(!objj_msgSend(_content,"count")||_36==_tileWidth){
149return;
150}
151var _37=CGSizeMakeCopy(_minItemSize);
152_numberOfColumns=MAX(1,FLOOR(_36/_37.width));
153if(_maxNumberOfColumns>0){
154_numberOfColumns=MIN(_maxNumberOfColumns,_numberOfColumns);
155}
156var _38=_36-_numberOfColumns*_37.width,_39=NO;
157if(_38>0&&_37.width<_maxItemSize.width){
158_37.width=MIN(_maxItemSize.width,_37.width+FLOOR(_38/_numberOfColumns));
159}
160if(_maxNumberOfColumns==1&&_37.width<_maxItemSize.width&&_37.width<_36){
161_37.width=MIN(_maxItemSize.width,_36);
162}
163if(!CGSizeEqualToSize(_itemSize,_37)){
164_itemSize=_37;
165_39=YES;
166}
167var _3a=0,_3b=_items.length;
168if(_maxNumberOfColumns>0&&_maxNumberOfRows>0){
169_3b=MIN(_3b,_maxNumberOfColumns*_maxNumberOfRows);
170}
171_numberOfRows=CEIL(_3b/_numberOfColumns);
172_horizontalMargin=FLOOR((_36-_numberOfColumns*_37.width)/(_numberOfColumns+1));
173var x=_horizontalMargin,y=-_37.height;
174for(;_3a<_3b;++_3a){
175if(_3a%_numberOfColumns==0){
176x=_horizontalMargin;
177y+=_verticalMargin+_37.height;
178}
179var _3e=objj_msgSend(_items[_3a],"view");
180objj_msgSend(_3e,"setFrameOrigin:",CGPointMake(x,y));
181if(_39){
182objj_msgSend(_3e,"setFrameSize:",_itemSize);
183}
184x+=_37.width+_horizontalMargin;
185}
186_tileWidth=_36;
187objj_msgSend(_34,"setFrameSize:",CGSizeMake(_36,y+_37.height+_verticalMargin));
188_tileWidth=-1;
189}
190}),new objj_method(sel_getUid("resizeSubviewsWithOldSize:"),function(_3f,_40,_41){
191with(_3f){
192objj_msgSend(_3f,"tile");
193}
194}),new objj_method(sel_getUid("setMaxNumberOfRows:"),function(_42,_43,_44){
195with(_42){
196if(_maxNumberOfRows==_44){
197return;
198}
199_maxNumberOfRows=_44;
200objj_msgSend(_42,"tile");
201}
202}),new objj_method(sel_getUid("maxNumberOfRows"),function(_45,_46){
203with(_45){
204return _maxNumberOfRows;
205}
206}),new objj_method(sel_getUid("setMaxNumberOfColumns:"),function(_47,_48,_49){
207with(_47){
208if(_maxNumberOfColumns==_49){
209return;
210}
211_maxNumberOfColumns=_49;
212objj_msgSend(_47,"tile");
213}
214}),new objj_method(sel_getUid("maxNumberOfColumns"),function(_4a,_4b){
215with(_4a){
216return _maxNumberOfColumns;
217}
218}),new objj_method(sel_getUid("numberOfRows"),function(_4c,_4d){
219with(_4c){
220return _numberOfRows;
221}
222}),new objj_method(sel_getUid("numberOfColumns"),function(_4e,_4f){
223with(_4e){
224return _numberOfColumns;
225}
226}),new objj_method(sel_getUid("setMinItemSize:"),function(_50,_51,_52){
227with(_50){
228if(CGSizeEqualToSize(_minItemSize,_52)){
229return;
230}
231_minItemSize=CGSizeMakeCopy(_52);
232objj_msgSend(_50,"tile");
233}
234}),new objj_method(sel_getUid("minItemSize"),function(_53,_54){
235with(_53){
236return _minItemSize;
237}
238}),new objj_method(sel_getUid("setMaxItemSize:"),function(_55,_56,_57){
239with(_55){
240if(CGSizeEqualToSize(_maxItemSize,_57)){
241return;
242}
243_maxItemSize=CGSizeMakeCopy(_57);
244objj_msgSend(_55,"tile");
245}
246}),new objj_method(sel_getUid("maxItemSize"),function(_58,_59){
247with(_58){
248return _maxItemSize;
249}
250}),new objj_method(sel_getUid("mouseUp:"),function(_5a,_5b,_5c){
251with(_5a){
252if(objj_msgSend(_selectionIndexes,"count")&&objj_msgSend(_5c,"clickCount")==2&&objj_msgSend(_delegate,"respondsToSelector:",sel_getUid("collectionView:didDoubleClickOnItemAtIndex:"))){
253objj_msgSend(_delegate,"collectionView:didDoubleClickOnItemAtIndex:",_5a,objj_msgSend(_selectionIndexes,"firstIndex"));
254}
255}
256}),new objj_method(sel_getUid("mouseDown:"),function(_5d,_5e,_5f){
257with(_5d){
258var _60=objj_msgSend(_5d,"convertPoint:fromView:",objj_msgSend(_5f,"locationInWindow"),nil),row=FLOOR(_60.y/(_itemSize.height+_verticalMargin)),_62=FLOOR(_60.x/(_itemSize.width+_horizontalMargin)),_63=row*_numberOfColumns+_62;
259if(_63>=0&&_63<_items.length){
260objj_msgSend(_5d,"setSelectionIndexes:",objj_msgSend(CPIndexSet,"indexSetWithIndex:",_63));
261}else{
262if(_allowsEmptySelection){
263objj_msgSend(_5d,"setSelectionIndexes:",objj_msgSend(CPIndexSet,"indexSet"));
264}
265}
266}
267}),new objj_method(sel_getUid("mouseDragged:"),function(_64,_65,_66){
268with(_64){
269if(!objj_msgSend(_delegate,"respondsToSelector:",sel_getUid("collectionView:dragTypesForItemsAtIndexes:"))){
270return;
271}
272if(!objj_msgSend(_selectionIndexes,"count")){
273return;
274}
275var _67=objj_msgSend(_delegate,"collectionView:dragTypesForItemsAtIndexes:",_64,_selectionIndexes);
276objj_msgSend(objj_msgSend(CPPasteboard,"pasteboardWithName:",CPDragPboard),"declareTypes:owner:",_67,_64);
277var _68=objj_msgSend(_64,"convertPoint:fromView:",objj_msgSend(_66,"locationInWindow"),nil);
278objj_msgSend(_itemForDragging,"setRepresentedObject:",_content[objj_msgSend(_selectionIndexes,"firstIndex")]);
279var _69=objj_msgSend(_itemForDragging,"view"),_6a=objj_msgSend(_69,"frame");
280objj_msgSend(_69,"setFrameSize:",_itemSize);
281objj_msgSend(_69,"setAlphaValue:",0.7);
282objj_msgSend(_64,"dragView:at:offset:event:pasteboard:source:slideBack:",_69,objj_msgSend(objj_msgSend(_items[objj_msgSend(_selectionIndexes,"firstIndex")],"view"),"frame").origin,CGPointMakeZero(),_66,nil,_64,YES);
283}
284}),new objj_method(sel_getUid("pasteboard:provideDataForType:"),function(_6b,_6c,_6d,_6e){
285with(_6b){
286objj_msgSend(_6d,"setData:forType:",objj_msgSend(_delegate,"collectionView:dataForItemsAtIndexes:forType:",_6b,_selectionIndexes,_6e),_6e);
287}
288}),new objj_method(sel_getUid("setVerticalMargin:"),function(_6f,_70,_71){
289with(_6f){
290if(_verticalMargin==_71){
291return;
292}
293_verticalMargin=_71;
294objj_msgSend(_6f,"tile");
295}
296}),new objj_method(sel_getUid("verticalMargin"),function(_72,_73){
297with(_72){
298return _verticalMargin;
299}
300}),new objj_method(sel_getUid("setDelegate:"),function(_74,_75,_76){
301with(_74){
302_delegate=_76;
303}
304}),new objj_method(sel_getUid("delegate"),function(_77,_78){
305with(_77){
306return _delegate;
307}
308})]);
309var _1=objj_allocateClassPair(CPObject,"CPCollectionViewItem"),_2=_1.isa;
310class_addIvars(_1,[new objj_ivar("_representedObject"),new objj_ivar("_view"),new objj_ivar("_isSelected")]);
311objj_registerClassPair(_1);
312objj_addClassForBundle(_1,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
313class_addMethods(_1,[new objj_method(sel_getUid("setRepresentedObject:"),function(_79,_7a,_7b){
314with(_79){
315if(_representedObject==_7b){
316return;
317}
318_representedObject=_7b;
319objj_msgSend(_view,"setRepresentedObject:",_7b);
320}
321}),new objj_method(sel_getUid("representedObject"),function(_7c,_7d){
322with(_7c){
323return _representedObject;
324}
325}),new objj_method(sel_getUid("setView:"),function(_7e,_7f,_80){
326with(_7e){
327_view=_80;
328}
329}),new objj_method(sel_getUid("view"),function(_81,_82){
330with(_81){
331return _view;
332}
333}),new objj_method(sel_getUid("setSelected:"),function(_83,_84,_85){
334with(_83){
335if(_isSelected==_85){
336return;
337}
338_isSelected=_85;
339objj_msgSend(_view,"setSelected:",_isSelected);
340}
341}),new objj_method(sel_getUid("isSelected"),function(_86,_87){
342with(_86){
343return _isSelected;
344}
345}),new objj_method(sel_getUid("collectionView"),function(_88,_89){
346with(_88){
347return objj_msgSend(_view,"superview");
348}
349})]);
350var _8a="CPCollectionViewMinItemSizeKey",_8b="CPCollectionViewMaxItemSizeKey",_8c="CPCollectionViewVerticalMarginKey";
351var _1=objj_getClass("CPCollectionView");
352if(!_1){
353objj_exception_throw(new objj_exception(OBJJClassNotFoundException,"*** Could not find definition for class \"CPCollectionView\""));
354}
355var _2=_1.isa;
356class_addMethods(_1,[new objj_method(sel_getUid("initWithCoder:"),function(_8d,_8e,_8f){
357with(_8d){
358_8d=objj_msgSendSuper({receiver:_8d,super_class:objj_getClass("CPView")},"initWithCoder:",_8f);
359if(_8d){
360_items=[];
361_content=[];
362_cachedItems=[];
363_itemSize=CGSizeMakeZero();
364_minItemSize=objj_msgSend(_8f,"decodeSizeForKey:",_8a);
365_maxItemSize=objj_msgSend(_8f,"decodeSizeForKey:",_8b);
366_verticalMargin=objj_msgSend(_8f,"decodeSizeForKey:",_8c);
367_tileWidth=-1;
368_selectionIndexes=objj_msgSend(CPIndexSet,"indexSet");
369}
370return _8d;
371}
372}),new objj_method(sel_getUid("encodeWithCoder:"),function(_90,_91,_92){
373with(_90){
374objj_msgSendSuper({receiver:_90,super_class:objj_getClass("CPView")},"encodeWithCoder:",_92);
375objj_msgSend(_92,"encodeSize:forKey:",_minItemSize,_8a);
376objj_msgSend(_92,"encodeSize:forKey:",_maxItemSize,_8b);
377objj_msgSend(_92,"encodeSize:forKey:",_verticalMargin,_8c);
378}
379})]);
380var _93="CPCollectionViewItemViewKey";
381var _1=objj_getClass("CPCollectionViewItem");
382if(!_1){
383objj_exception_throw(new objj_exception(OBJJClassNotFoundException,"*** Could not find definition for class \"CPCollectionViewItem\""));
384}
385var _2=_1.isa;
386class_addMethods(_1,[new objj_method(sel_getUid("copy"),function(_94,_95){
387with(_94){
388}
389})]);
390var _93="CPCollectionViewItemViewKey";
391var _1=objj_getClass("CPCollectionViewItem");
392if(!_1){
393objj_exception_throw(new objj_exception(OBJJClassNotFoundException,"*** Could not find definition for class \"CPCollectionViewItem\""));
394}
395var _2=_1.isa;
396class_addMethods(_1,[new objj_method(sel_getUid("initWithCoder:"),function(_96,_97,_98){
397with(_96){
398_96=objj_msgSendSuper({receiver:_96,super_class:objj_getClass("CPObject")},"init");
399if(_96){
400_view=objj_msgSend(_98,"decodeObjectForKey:",_93);
401}
402return _96;
403}
404}),new objj_method(sel_getUid("encodeWithCoder:"),function(_99,_9a,_9b){
405with(_99){
406objj_msgSend(_9b,"encodeObject:forKey:",_view,_93);
407}
408})]);