You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

354 lines
14 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-layout-BoxLayout'>/**
  19. </span> * @class Ext.layout.BoxLayout
  20. * @extends Ext.layout.ContainerLayout
  21. * &lt;p&gt;Base Class for HBoxLayout and VBoxLayout Classes. Generally it should not need to be used directly.&lt;/p&gt;
  22. */
  23. Ext.layout.BoxLayout = Ext.extend(Ext.layout.ContainerLayout, {
  24. <span id='Ext-layout-BoxLayout-cfg-defaultMargins'> /**
  25. </span> * @cfg {Object} defaultMargins
  26. * &lt;p&gt;If the individual contained items do not have a &lt;tt&gt;margins&lt;/tt&gt;
  27. * property specified, the default margins from this property will be
  28. * applied to each item.&lt;/p&gt;
  29. * &lt;br&gt;&lt;p&gt;This property may be specified as an object containing margins
  30. * to apply in the format:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  31. {
  32. top: (top margin),
  33. right: (right margin),
  34. bottom: (bottom margin),
  35. left: (left margin)
  36. }&lt;/code&gt;&lt;/pre&gt;
  37. * &lt;p&gt;This property may also be specified as a string containing
  38. * space-separated, numeric margin values. The order of the sides associated
  39. * with each value matches the way CSS processes margin values:&lt;/p&gt;
  40. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  41. * &lt;li&gt;If there is only one value, it applies to all sides.&lt;/li&gt;
  42. * &lt;li&gt;If there are two values, the top and bottom borders are set to the
  43. * first value and the right and left are set to the second.&lt;/li&gt;
  44. * &lt;li&gt;If there are three values, the top is set to the first value, the left
  45. * and right are set to the second, and the bottom is set to the third.&lt;/li&gt;
  46. * &lt;li&gt;If there are four values, they apply to the top, right, bottom, and
  47. * left, respectively.&lt;/li&gt;
  48. * &lt;/ul&gt;&lt;/div&gt;
  49. * &lt;p&gt;Defaults to:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  50. * {top:0, right:0, bottom:0, left:0}
  51. * &lt;/code&gt;&lt;/pre&gt;
  52. */
  53. defaultMargins : {left:0,top:0,right:0,bottom:0},
  54. <span id='Ext-layout-BoxLayout-cfg-padding'> /**
  55. </span> * @cfg {String} padding
  56. * &lt;p&gt;Sets the padding to be applied to all child items managed by this layout.&lt;/p&gt;
  57. * &lt;p&gt;This property must be specified as a string containing
  58. * space-separated, numeric padding values. The order of the sides associated
  59. * with each value matches the way CSS processes padding values:&lt;/p&gt;
  60. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  61. * &lt;li&gt;If there is only one value, it applies to all sides.&lt;/li&gt;
  62. * &lt;li&gt;If there are two values, the top and bottom borders are set to the
  63. * first value and the right and left are set to the second.&lt;/li&gt;
  64. * &lt;li&gt;If there are three values, the top is set to the first value, the left
  65. * and right are set to the second, and the bottom is set to the third.&lt;/li&gt;
  66. * &lt;li&gt;If there are four values, they apply to the top, right, bottom, and
  67. * left, respectively.&lt;/li&gt;
  68. * &lt;/ul&gt;&lt;/div&gt;
  69. * &lt;p&gt;Defaults to: &lt;code&gt;&quot;0&quot;&lt;/code&gt;&lt;/p&gt;
  70. */
  71. padding : '0',
  72. <span id='Ext-layout-BoxLayout-property-pack'> // documented in subclasses
  73. </span> pack : 'start',
  74. <span id='Ext-layout-BoxLayout-property-monitorResize'> // private
  75. </span> monitorResize : true,
  76. <span id='Ext-layout-BoxLayout-property-type'> type: 'box',
  77. </span><span id='Ext-layout-BoxLayout-property-scrollOffset'> scrollOffset : 0,
  78. </span><span id='Ext-layout-BoxLayout-cfg-extraCls'> extraCls : 'x-box-item',
  79. </span><span id='Ext-layout-BoxLayout-property-targetCls'> targetCls : 'x-box-layout-ct',
  80. </span><span id='Ext-layout-BoxLayout-property-innerCls'> innerCls : 'x-box-inner',
  81. </span>
  82. <span id='Ext-layout-BoxLayout-method-constructor'> constructor : function(config){
  83. </span> Ext.layout.BoxLayout.superclass.constructor.call(this, config);
  84. if (Ext.isString(this.defaultMargins)) {
  85. this.defaultMargins = this.parseMargins(this.defaultMargins);
  86. }
  87. var handler = this.overflowHandler;
  88. if (typeof handler == 'string') {
  89. handler = {
  90. type: handler
  91. };
  92. }
  93. var handlerType = 'none';
  94. if (handler &amp;&amp; handler.type != undefined) {
  95. handlerType = handler.type;
  96. }
  97. var constructor = Ext.layout.boxOverflow[handlerType];
  98. if (constructor[this.type]) {
  99. constructor = constructor[this.type];
  100. }
  101. this.overflowHandler = new constructor(this, handler);
  102. },
  103. <span id='Ext-layout-BoxLayout-method-onLayout'> /**
  104. </span> * @private
  105. * Runs the child box calculations and caches them in childBoxCache. Subclasses can used these cached values
  106. * when laying out
  107. */
  108. onLayout: function(container, target) {
  109. Ext.layout.BoxLayout.superclass.onLayout.call(this, container, target);
  110. var tSize = this.getLayoutTargetSize(),
  111. items = this.getVisibleItems(container),
  112. calcs = this.calculateChildBoxes(items, tSize),
  113. boxes = calcs.boxes,
  114. meta = calcs.meta;
  115. //invoke the overflow handler, if one is configured
  116. if (tSize.width &gt; 0) {
  117. var handler = this.overflowHandler,
  118. method = meta.tooNarrow ? 'handleOverflow' : 'clearOverflow';
  119. var results = handler[method](calcs, tSize);
  120. if (results) {
  121. if (results.targetSize) {
  122. tSize = results.targetSize;
  123. }
  124. if (results.recalculate) {
  125. items = this.getVisibleItems(container);
  126. calcs = this.calculateChildBoxes(items, tSize);
  127. boxes = calcs.boxes;
  128. }
  129. }
  130. }
  131. <span id='Ext-layout-BoxLayout-property-layoutTargetLastSize'> /**
  132. </span> * @private
  133. * @property layoutTargetLastSize
  134. * @type Object
  135. * Private cache of the last measured size of the layout target. This should never be used except by
  136. * BoxLayout subclasses during their onLayout run.
  137. */
  138. this.layoutTargetLastSize = tSize;
  139. <span id='Ext-layout-BoxLayout-property-childBoxCache'> /**
  140. </span> * @private
  141. * @property childBoxCache
  142. * @type Array
  143. * Array of the last calculated height, width, top and left positions of each visible rendered component
  144. * within the Box layout.
  145. */
  146. this.childBoxCache = calcs;
  147. this.updateInnerCtSize(tSize, calcs);
  148. this.updateChildBoxes(boxes);
  149. // Putting a box layout into an overflowed container is NOT correct and will make a second layout pass necessary.
  150. this.handleTargetOverflow(tSize, container, target);
  151. },
  152. <span id='Ext-layout-BoxLayout-method-updateChildBoxes'> /**
  153. </span> * Resizes and repositions each child component
  154. * @param {Array} boxes The box measurements
  155. */
  156. updateChildBoxes: function(boxes) {
  157. for (var i = 0, length = boxes.length; i &lt; length; i++) {
  158. var box = boxes[i],
  159. comp = box.component;
  160. if (box.dirtySize) {
  161. comp.setSize(box.width, box.height);
  162. }
  163. // Don't set positions to NaN
  164. if (isNaN(box.left) || isNaN(box.top)) {
  165. continue;
  166. }
  167. comp.setPosition(box.left, box.top);
  168. }
  169. },
  170. <span id='Ext-layout-BoxLayout-method-updateInnerCtSize'> /**
  171. </span> * @private
  172. * Called by onRender just before the child components are sized and positioned. This resizes the innerCt
  173. * to make sure all child items fit within it. We call this before sizing the children because if our child
  174. * items are larger than the previous innerCt size the browser will insert scrollbars and then remove them
  175. * again immediately afterwards, giving a performance hit.
  176. * Subclasses should provide an implementation.
  177. * @param {Object} currentSize The current height and width of the innerCt
  178. * @param {Array} calculations The new box calculations of all items to be laid out
  179. */
  180. updateInnerCtSize: function(tSize, calcs) {
  181. var align = this.align,
  182. padding = this.padding,
  183. width = tSize.width,
  184. height = tSize.height;
  185. if (this.type == 'hbox') {
  186. var innerCtWidth = width,
  187. innerCtHeight = calcs.meta.maxHeight + padding.top + padding.bottom;
  188. if (align == 'stretch') {
  189. innerCtHeight = height;
  190. } else if (align == 'middle') {
  191. innerCtHeight = Math.max(height, innerCtHeight);
  192. }
  193. } else {
  194. var innerCtHeight = height,
  195. innerCtWidth = calcs.meta.maxWidth + padding.left + padding.right;
  196. if (align == 'stretch') {
  197. innerCtWidth = width;
  198. } else if (align == 'center') {
  199. innerCtWidth = Math.max(width, innerCtWidth);
  200. }
  201. }
  202. this.innerCt.setSize(innerCtWidth || undefined, innerCtHeight || undefined);
  203. },
  204. <span id='Ext-layout-BoxLayout-method-handleTargetOverflow'> /**
  205. </span> * @private
  206. * This should be called after onLayout of any BoxLayout subclass. If the target's overflow is not set to 'hidden',
  207. * we need to lay out a second time because the scrollbars may have modified the height and width of the layout
  208. * target. Having a Box layout inside such a target is therefore not recommended.
  209. * @param {Object} previousTargetSize The size and height of the layout target before we just laid out
  210. * @param {Ext.Container} container The container
  211. * @param {Ext.Element} target The target element
  212. */
  213. handleTargetOverflow: function(previousTargetSize, container, target) {
  214. var overflow = target.getStyle('overflow');
  215. if (overflow &amp;&amp; overflow != 'hidden' &amp;&amp;!this.adjustmentPass) {
  216. var newTargetSize = this.getLayoutTargetSize();
  217. if (newTargetSize.width != previousTargetSize.width || newTargetSize.height != previousTargetSize.height){
  218. this.adjustmentPass = true;
  219. this.onLayout(container, target);
  220. }
  221. }
  222. delete this.adjustmentPass;
  223. },
  224. <span id='Ext-layout-BoxLayout-method-isValidParent'> // private
  225. </span> isValidParent : function(c, target) {
  226. return this.innerCt &amp;&amp; c.getPositionEl().dom.parentNode == this.innerCt.dom;
  227. },
  228. <span id='Ext-layout-BoxLayout-method-getVisibleItems'> /**
  229. </span> * @private
  230. * Returns all items that are both rendered and visible
  231. * @return {Array} All matching items
  232. */
  233. getVisibleItems: function(ct) {
  234. var ct = ct || this.container,
  235. t = ct.getLayoutTarget(),
  236. cti = ct.items.items,
  237. len = cti.length,
  238. i, c, items = [];
  239. for (i = 0; i &lt; len; i++) {
  240. if((c = cti[i]).rendered &amp;&amp; this.isValidParent(c, t) &amp;&amp; c.hidden !== true &amp;&amp; c.collapsed !== true &amp;&amp; c.shouldLayout !== false){
  241. items.push(c);
  242. }
  243. }
  244. return items;
  245. },
  246. <span id='Ext-layout-BoxLayout-method-renderAll'> // private
  247. </span> renderAll : function(ct, target) {
  248. if (!this.innerCt) {
  249. // the innerCt prevents wrapping and shuffling while the container is resizing
  250. this.innerCt = target.createChild({cls:this.innerCls});
  251. this.padding = this.parseMargins(this.padding);
  252. }
  253. Ext.layout.BoxLayout.superclass.renderAll.call(this, ct, this.innerCt);
  254. },
  255. <span id='Ext-layout-BoxLayout-method-getLayoutTargetSize'> getLayoutTargetSize : function() {
  256. </span> var target = this.container.getLayoutTarget(), ret;
  257. if (target) {
  258. ret = target.getViewSize();
  259. // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
  260. // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
  261. // with getViewSize
  262. if (Ext.isIE9m &amp;&amp; Ext.isStrict &amp;&amp; ret.width == 0){
  263. ret = target.getStyleSize();
  264. }
  265. ret.width -= target.getPadding('lr');
  266. ret.height -= target.getPadding('tb');
  267. }
  268. return ret;
  269. },
  270. <span id='Ext-layout-BoxLayout-method-renderItem'> // private
  271. </span> renderItem : function(c) {
  272. if(Ext.isString(c.margins)){
  273. c.margins = this.parseMargins(c.margins);
  274. }else if(!c.margins){
  275. c.margins = this.defaultMargins;
  276. }
  277. Ext.layout.BoxLayout.superclass.renderItem.apply(this, arguments);
  278. },
  279. <span id='Ext-layout-BoxLayout-method-destroy'> /**
  280. </span> * @private
  281. */
  282. destroy: function() {
  283. Ext.destroy(this.overflowHandler);
  284. Ext.layout.BoxLayout.superclass.destroy.apply(this, arguments);
  285. }
  286. });
  287. <span id='Ext-layout-boxOverflow-None'>/**
  288. </span> * @class Ext.layout.boxOverflow.None
  289. * @extends Object
  290. * Base class for Box Layout overflow handlers. These specialized classes are invoked when a Box Layout
  291. * (either an HBox or a VBox) has child items that are either too wide (for HBox) or too tall (for VBox)
  292. * for its container.
  293. */
  294. Ext.layout.boxOverflow.None = Ext.extend(Object, {
  295. <span id='Ext-layout-boxOverflow-None-method-constructor'> constructor: function(layout, config) {
  296. </span> this.layout = layout;
  297. Ext.apply(this, config || {});
  298. },
  299. <span id='Ext-layout-boxOverflow-None-method-handleOverflow'> handleOverflow: Ext.emptyFn,
  300. </span>
  301. <span id='Ext-layout-boxOverflow-None-method-clearOverflow'> clearOverflow: Ext.emptyFn
  302. </span>});
  303. Ext.layout.boxOverflow.none = Ext.layout.boxOverflow.None;
  304. </pre>
  305. </body>
  306. </html>