/Frameworks/AppKit/rhino.platform/_CPImageAndTextView.j

http://github.com/jfahrenkrug/MapKit-HelloWorld · Unknown · 249 lines · 249 code · 0 blank · 0 comment · 0 complexity · b6a44a28958481d72901a5cb75366519 MD5 · raw file

  1. I;21;Foundation/CPString.ji;9;CPColor.ji;8;CPFont.ji;9;CPImage.ji;13;CPTextField.ji;8;CPView.jc;7026;
  2. CPTopVerticalTextAlignment=1,CPCenterVerticalTextAlignment=2,CPBottomVerticalTextAlignment=3;
  3. var _1=1<<0,_2=1<<1,_3=1<<2,_4=1<<3,_5=1<<4,_6=1<<5,_7=1<<6,_8=1<<7,_9=1<<8,_a=1<<9,_b=1<<10;
  4. var _c=3,_d=5;
  5. var _e=objj_allocateClassPair(CPView,"_CPImageAndTextView"),_f=_e.isa;
  6. class_addIvars(_e,[new objj_ivar("_alignment"),new objj_ivar("_verticalAlignment"),new objj_ivar("_lineBreakMode"),new objj_ivar("_textColor"),new objj_ivar("_font"),new objj_ivar("_textShadowColor"),new objj_ivar("_textShadowOffset"),new objj_ivar("_imagePosition"),new objj_ivar("_imageScaling"),new objj_ivar("_image"),new objj_ivar("_text"),new objj_ivar("_textSize"),new objj_ivar("_flags")]);
  7. objj_registerClassPair(_e);
  8. objj_addClassForBundle(_e,objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  9. class_addMethods(_e,[new objj_method(sel_getUid("initWithFrame:control:"),function(_10,_11,_12,_13){
  10. with(_10){
  11. _10=objj_msgSendSuper({receiver:_10,super_class:objj_getClass("CPView")},"initWithFrame:",_12);
  12. if(_10){
  13. _textShadowOffset={width:0,height:0};
  14. objj_msgSend(_10,"setVerticalAlignment:",CPTopVerticalTextAlignment);
  15. if(_13){
  16. objj_msgSend(_10,"setLineBreakMode:",objj_msgSend(_13,"lineBreakMode"));
  17. objj_msgSend(_10,"setTextColor:",objj_msgSend(_13,"textColor"));
  18. objj_msgSend(_10,"setAlignment:",objj_msgSend(_13,"alignment"));
  19. objj_msgSend(_10,"setVerticalAlignment:",objj_msgSend(_13,"verticalAlignment"));
  20. objj_msgSend(_10,"setFont:",objj_msgSend(_13,"font"));
  21. objj_msgSend(_10,"setImagePosition:",objj_msgSend(_13,"imagePosition"));
  22. objj_msgSend(_10,"setImageScaling:",objj_msgSend(_13,"imageScaling"));
  23. }else{
  24. objj_msgSend(_10,"setLineBreakMode:",CPLineBreakByClipping);
  25. objj_msgSend(_10,"setAlignment:",CPCenterTextAlignment);
  26. objj_msgSend(_10,"setFont:",objj_msgSend(CPFont,"systemFontOfSize:",12));
  27. objj_msgSend(_10,"setImagePosition:",CPNoImage);
  28. objj_msgSend(_10,"setImageScaling:",CPScaleNone);
  29. }
  30. _textSize=NULL;
  31. }
  32. return _10;
  33. }
  34. }),new objj_method(sel_getUid("initWithFrame:"),function(_14,_15,_16){
  35. with(_14){
  36. return objj_msgSend(_14,"initWithFrame:control:",_16,nil);
  37. }
  38. }),new objj_method(sel_getUid("setAlignment:"),function(_17,_18,_19){
  39. with(_17){
  40. if(_alignment===_19){
  41. return;
  42. }
  43. _alignment=_19;
  44. }
  45. }),new objj_method(sel_getUid("alignment"),function(_1a,_1b){
  46. with(_1a){
  47. return _alignment;
  48. }
  49. }),new objj_method(sel_getUid("setVerticalAlignment:"),function(_1c,_1d,_1e){
  50. with(_1c){
  51. if(_verticalAlignment===_1e){
  52. return;
  53. }
  54. _verticalAlignment=_1e;
  55. _flags|=_5;
  56. objj_msgSend(_1c,"setNeedsLayout");
  57. }
  58. }),new objj_method(sel_getUid("verticalAlignment"),function(_1f,_20){
  59. with(_1f){
  60. return _verticalAlignment;
  61. }
  62. }),new objj_method(sel_getUid("setLineBreakMode:"),function(_21,_22,_23){
  63. with(_21){
  64. if(_lineBreakMode===_23){
  65. return;
  66. }
  67. _lineBreakMode=_23;
  68. _flags|=_6;
  69. objj_msgSend(_21,"setNeedsLayout");
  70. }
  71. }),new objj_method(sel_getUid("lineBreakMode"),function(_24,_25){
  72. with(_24){
  73. return _lineBreakMode;
  74. }
  75. }),new objj_method(sel_getUid("setImagePosition:"),function(_26,_27,_28){
  76. with(_26){
  77. if(_imagePosition==_28){
  78. return;
  79. }
  80. _imagePosition=_28;
  81. _flags|=_a;
  82. objj_msgSend(_26,"setNeedsLayout");
  83. }
  84. }),new objj_method(sel_getUid("imagePosition"),function(_29,_2a){
  85. with(_29){
  86. return _imagePosition;
  87. }
  88. }),new objj_method(sel_getUid("setImageScaling:"),function(_2b,_2c,_2d){
  89. with(_2b){
  90. if(_imageScaling==_2d){
  91. return;
  92. }
  93. _imageScaling=_2d;
  94. _flags|=_b;
  95. objj_msgSend(_2b,"setNeedsLayout");
  96. }
  97. }),new objj_method(sel_getUid("imageScaling"),function(_2e,_2f){
  98. with(_2e){
  99. return _imageScaling;
  100. }
  101. }),new objj_method(sel_getUid("setTextColor:"),function(_30,_31,_32){
  102. with(_30){
  103. if(_textColor===_32){
  104. return;
  105. }
  106. _textColor=_32;
  107. }
  108. }),new objj_method(sel_getUid("textColor"),function(_33,_34){
  109. with(_33){
  110. return _textColor;
  111. }
  112. }),new objj_method(sel_getUid("setFont:"),function(_35,_36,_37){
  113. with(_35){
  114. if(_font===_37){
  115. return;
  116. }
  117. _font=_37;
  118. _flags|=_8;
  119. _textSize=NULL;
  120. objj_msgSend(_35,"setNeedsLayout");
  121. }
  122. }),new objj_method(sel_getUid("font"),function(_38,_39){
  123. with(_38){
  124. return _font;
  125. }
  126. }),new objj_method(sel_getUid("setTextShadowColor:"),function(_3a,_3b,_3c){
  127. with(_3a){
  128. if(_textShadowColor===_3c){
  129. return;
  130. }
  131. _textShadowColor=_3c;
  132. _flags|=_9;
  133. objj_msgSend(_3a,"setNeedsLayout");
  134. }
  135. }),new objj_method(sel_getUid("textShadowColor"),function(_3d,_3e){
  136. with(_3d){
  137. return _textShadowColor;
  138. }
  139. }),new objj_method(sel_getUid("setTextShadowOffset:"),function(_3f,_40,_41){
  140. with(_3f){
  141. if((_textShadowOffset.width==_41.width&&_textShadowOffset.height==_41.height)){
  142. return;
  143. }
  144. _textShadowOffset={width:_41.width,height:_41.height};
  145. objj_msgSend(_3f,"setNeedsLayout");
  146. }
  147. }),new objj_method(sel_getUid("textShadowOffset"),function(_42,_43){
  148. with(_42){
  149. return _textShadowOffset;
  150. }
  151. }),new objj_method(sel_getUid("setImage:"),function(_44,_45,_46){
  152. with(_44){
  153. if(_image==_46){
  154. return;
  155. }
  156. _image=_46;
  157. _flags|=_2;
  158. objj_msgSend(_44,"setNeedsLayout");
  159. }
  160. }),new objj_method(sel_getUid("image"),function(_47,_48){
  161. with(_47){
  162. return _image;
  163. }
  164. }),new objj_method(sel_getUid("setText:"),function(_49,_4a,_4b){
  165. with(_49){
  166. if(_text===_4b){
  167. return;
  168. }
  169. _text=_4b;
  170. _flags|=_3;
  171. _textSize=NULL;
  172. objj_msgSend(_49,"setNeedsLayout");
  173. }
  174. }),new objj_method(sel_getUid("text"),function(_4c,_4d){
  175. with(_4c){
  176. return _text;
  177. }
  178. }),new objj_method(sel_getUid("layoutSubviews"),function(_4e,_4f){
  179. with(_4e){
  180. var _50=objj_msgSend(_4e,"bounds").size,_51={origin:{x:0,y:0},size:{width:_50.width,height:_50.height}};
  181. if(hasDOMImageElement){
  182. if(!_52){
  183. var _52=_DOMImageElement.style;
  184. }
  185. if(_flags&_2){
  186. _DOMImageElement.src=objj_msgSend(_image,"filename");
  187. }
  188. var _53=_50.width/2,_54=_50.height/2,_55=objj_msgSend(_image,"size"),_56=_55.width,_57=_55.height;
  189. if(_imageScaling===CPScaleToFit){
  190. _56=_50.width;
  191. _57=_50.height;
  192. }else{
  193. if(_imageScaling===CPScaleProportionally){
  194. var _58=MIN(MIN(_50.width,_56)/_56,MIN(_50.height,_57)/_57);
  195. _56*=_58;
  196. _57*=_58;
  197. }
  198. }
  199. if(_imagePosition===CPImageBelow){
  200. _51.size.height=_50.height-_57-_d;
  201. }else{
  202. if(_imagePosition===CPImageAbove){
  203. _51.origin.y+=_57+_d;
  204. _51.size.height=_50.height-_57-_d;
  205. }else{
  206. if(_imagePosition===CPImageLeft){
  207. _51.origin.x=_56+_c;
  208. _51.size.width-=_56+_c;
  209. }else{
  210. if(_imagePosition===CPImageRight){
  211. _51.size.width-=_56+_c;
  212. }else{
  213. if(_imagePosition===CPImageOnly){
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }
  220. _flags=0;
  221. }
  222. }),new objj_method(sel_getUid("sizeToFit"),function(_59,_5a){
  223. with(_59){
  224. var _5b=CGSizeMakeZero();
  225. if((_imagePosition!==CPNoImage)&&_image){
  226. var _5c=objj_msgSend(_image,"size");
  227. _5b.width+=_5c.width;
  228. _5b.height+=_5c.height;
  229. }
  230. if((_imagePosition!==CPImageOnly)&&objj_msgSend(_text,"length")>0){
  231. if(!_textSize){
  232. _textSize=objj_msgSend(_text,"sizeWithFont:",_font?_font:objj_msgSend(CPFont,"systemFontOfSize:",12));
  233. }
  234. if(_imagePosition===CPImageLeft||_imagePosition===CPImageRight){
  235. _5b.width+=_textSize.width+_c;
  236. _5b.height=MAX(_5b.height,_textSize.height);
  237. }else{
  238. if(_imagePosition===CPImageAbove||_imagePosition===CPImageBelow){
  239. _5b.width=MAX(_5b.width,_textSize.width);
  240. _5b.height+=_textSize.height+_d;
  241. }else{
  242. _5b.width=MAX(_5b.width,_textSize.width);
  243. _5b.height=MAX(_5b.height,_textSize.height);
  244. }
  245. }
  246. }
  247. objj_msgSend(_59,"setFrameSize:",_5b);
  248. }
  249. })]);