/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

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