PageRenderTime 104ms CodeModel.GetById 31ms RepoModel.GetById 6ms app.codeStats 1ms

/DataGridHeaderColor/src/mx/controls/dataGridClasses/DataGridHeader.as

http://jc-examples.googlecode.com/
ActionScript | 1606 lines | 1059 code | 210 blank | 337 comment | 210 complexity | 02d451e05e18277cc33bd69e5b233188 MD5 | raw file
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED
  4. // Copyright 2007 Adobe Systems Incorporated
  5. // All Rights Reserved.
  6. //
  7. // NOTICE: Adobe permits you to use, modify, and distribute this file
  8. // in accordance with the terms of the license agreement accompanying it.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. package mx.controls.dataGridClasses
  12. {
  13. import flash.display.DisplayObject;
  14. import flash.display.GradientType;
  15. import flash.display.Graphics;
  16. import flash.display.Shape;
  17. import flash.display.Sprite;
  18. import flash.events.Event;
  19. import flash.events.MouseEvent;
  20. import flash.geom.Matrix;
  21. import flash.geom.Point;
  22. import flash.geom.Rectangle;
  23. import mx.controls.DataGrid;
  24. import mx.controls.listClasses.IDropInListItemRenderer;
  25. import mx.controls.listClasses.IListItemRenderer;
  26. import mx.core.EdgeMetrics;
  27. import mx.core.FlexSprite;
  28. import mx.core.FlexVersion;
  29. import mx.core.IFlexDisplayObject;
  30. import mx.core.UIComponent;
  31. import mx.core.UIComponentGlobals;
  32. import mx.core.mx_internal;
  33. import mx.events.DataGridEvent;
  34. import mx.events.SandboxMouseEvent;
  35. import mx.managers.CursorManager;
  36. import mx.managers.CursorManagerPriority;
  37. import mx.skins.halo.DataGridColumnDropIndicator;
  38. import mx.styles.ISimpleStyleClient;
  39. import mx.styles.StyleManager;
  40. use namespace mx_internal;
  41. /**
  42. * The DataGridHeader class defines the default header
  43. * renderer for a DataGrid control.
  44. * By default, the header renderer
  45. * draws the text associated with each header in the list, and an optional
  46. * sort arrow (if sorted by that column).
  47. *
  48. * @see mx.controls.DataGrid
  49. *
  50. *
  51. * This is a modified version of the Flex 3.2.0 SDK DataGridHeader.as class.
  52. * This version has the following added functionality over the standard implementation:
  53. *
  54. * <ul>
  55. * <li>Specify a header (gradient) header color when the mouse over and mouse down events occur over the header.</li>
  56. * </ul>
  57. *
  58. * The colors are specified via the <code>startColor</code> and <code>endColor</code> style attributes. These colors define
  59. * the start and end of the gradient fill. For a solid fill color, use the same color for both the start and end.
  60. *
  61. * * <p>
  62. * The <code>&lt;mx:DataGridHeader&gt;</code> adds the following new styles
  63. * attributes:
  64. * </p>
  65. * <pre>
  66. * &lt;mx:DataGridHeader
  67. * <b>Styles</b>
  68. * startColor="0x000000"
  69. * endColor="0x000000"
  70. * /&gt;
  71. */
  72. [Style(name="startColor",type="Number",format="Color",inherit="no")]
  73. [Style(name="endColor",type="Number",format="Color",inherit="no")]
  74. public class DataGridHeader extends DataGridHeaderBase
  75. {
  76. /**
  77. * Constructor.
  78. */
  79. public function DataGridHeader()
  80. {
  81. super();
  82. addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
  83. addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
  84. addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
  85. addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
  86. }
  87. /**
  88. * @private
  89. * Additional affordance given to header separators.
  90. */
  91. private var separatorAffordance:Number = 3;
  92. /**
  93. * a function to clear selections
  94. */
  95. override mx_internal function clearSelectionLayer():void
  96. {
  97. while (selectionLayer.numChildren > 0)
  98. {
  99. selectionLayer.removeChildAt(0);
  100. }
  101. }
  102. /**
  103. * The DataGrid control associated with this renderer.
  104. */
  105. protected var dataGrid:DataGrid;
  106. /**
  107. * An Array of header renderer instances.
  108. */
  109. protected var headerItems:Array = [];
  110. /**
  111. * The cached header height, in pixels.
  112. */
  113. protected var cachedHeaderHeight:Number = 0;
  114. /**
  115. * The cached padding for the bottom of the renderer, in pixels.
  116. */
  117. protected var cachedPaddingBottom:Number = 0;
  118. /**
  119. * The cached padding for the top of the renderer, in pixels.
  120. */
  121. protected var cachedPaddingTop:Number = 0;
  122. /**
  123. * Whether we need the separator on the far right
  124. */
  125. public var needRightSeparator:Boolean = false;
  126. /**
  127. * Whether we need the separator events on the far right
  128. */
  129. public var needRightSeparatorEvents:Boolean = false;
  130. /**
  131. * @inheritDoc
  132. */
  133. override protected function createChildren():void
  134. {
  135. dataGrid = parent as DataGrid;
  136. // this is the layer where we draw selection indicators
  137. selectionLayer = new UIComponent();
  138. addChild(selectionLayer);
  139. }
  140. /**
  141. * @inheritDoc
  142. */
  143. override protected function measure():void
  144. {
  145. super.measure();
  146. var calculatedHeight:Number = dataGrid.calculateHeaderHeight();
  147. cachedHeaderHeight = dataGrid._explicitHeaderHeight ? dataGrid.headerHeight : calculatedHeight;
  148. cachedPaddingBottom = getStyle("paddingBottom");
  149. cachedPaddingTop = getStyle("paddingTop");
  150. measuredHeight = cachedHeaderHeight;
  151. }
  152. /**
  153. * @inheritDoc
  154. */
  155. override protected function updateDisplayList(w:Number, h:Number):void
  156. {
  157. allowItemSizeChangeNotification = false;
  158. // make new ones
  159. var cols:Array = visibleColumns;
  160. if (headerItemsChanged && (cols && cols.length > 0 || dataGrid.headerVisible))
  161. {
  162. headerItemsChanged = false;
  163. var xx:Number = 0;
  164. var yy:Number = 0;
  165. var hh:Number = 0;
  166. var ww:Number = 0;
  167. var rh:Number;
  168. var colNum:int = 0; // visible columns compensate for firstCol offset
  169. var rowData:DataGridListData;
  170. var item:IListItemRenderer;
  171. var extraItem:IListItemRenderer;
  172. var data:Object;
  173. var uid:String;
  174. var c:DataGridColumn;
  175. var maxHeaderHeight:Number = 0;
  176. while (cols && colNum < cols.length)
  177. {
  178. c = cols[colNum];
  179. item = dataGrid.createColumnItemRenderer(c, true, c);
  180. rowData = new DataGridListData((c.headerText != null) ? c.headerText : c.dataField,
  181. c.dataField, colNum, uid, dataGrid, 0);
  182. if (item is IDropInListItemRenderer)
  183. IDropInListItemRenderer(item).listData = rowData;
  184. item.data = c;
  185. item.visible = true;
  186. item.styleName = c;
  187. addChild(DisplayObject(item));
  188. var oldHeader:DisplayObject = headerItems[colNum];
  189. if (oldHeader)
  190. {
  191. removeChild(oldHeader);
  192. }
  193. headerItems[colNum] = item;
  194. // set prefW so we can compute prefH
  195. item.explicitWidth = ww = c.width;
  196. UIComponentGlobals.layoutManager.validateClient(item, true);
  197. // but size it regardless of what prefW is
  198. rh = item.getExplicitOrMeasuredHeight();
  199. item.setActualSize(ww, dataGrid._explicitHeaderHeight ?
  200. cachedHeaderHeight - cachedPaddingTop - cachedPaddingBottom : rh);
  201. item.move(xx, yy + cachedPaddingTop);
  202. xx += ww;
  203. colNum++;
  204. hh = Math.ceil(Math.max(hh, dataGrid._explicitHeaderHeight ?
  205. cachedHeaderHeight : rh + cachedPaddingBottom + cachedPaddingTop));
  206. maxHeaderHeight = Math.max(maxHeaderHeight, dataGrid._explicitHeaderHeight ?
  207. cachedHeaderHeight - cachedPaddingTop - cachedPaddingBottom : rh);
  208. }
  209. // expand all headers to be of maximum height
  210. for (var i:int = 0; i < headerItems.length; i++)
  211. headerItems[i].setActualSize(headerItems[i].width, maxHeaderHeight);
  212. while (headerItems.length > colNum)
  213. {
  214. // remove extra columns
  215. extraItem = headerItems.pop();
  216. removeChild(DisplayObject(extraItem));
  217. }
  218. }
  219. var headerBG:UIComponent =
  220. UIComponent(getChildByName("headerBG"));
  221. if (headerBGSkinChanged)
  222. {
  223. headerBGSkinChanged = false;
  224. if (headerBG)
  225. removeChild(headerBG);
  226. headerBG = null;
  227. }
  228. if (!headerBG)
  229. {
  230. headerBG = new UIComponent();
  231. headerBG.name = "headerBG";
  232. addChildAt(DisplayObject(headerBG), 0);
  233. if (FlexVersion.compatibilityVersion >= FlexVersion.VERSION_3_0)
  234. {
  235. var headerBGSkinClass:Class = getStyle("headerBackgroundSkin");
  236. var headerBGSkin:IFlexDisplayObject = new headerBGSkinClass();
  237. if (headerBGSkin is ISimpleStyleClient)
  238. ISimpleStyleClient(headerBGSkin).styleName = this;
  239. headerBG.addChild(DisplayObject(headerBGSkin));
  240. }
  241. }
  242. if (dataGrid.headerVisible)
  243. {
  244. headerBG.visible = true;
  245. if (FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  246. {
  247. dataGrid._drawHeaderBackground(headerBG);
  248. }
  249. else
  250. {
  251. drawHeaderBackgroundSkin(IFlexDisplayObject(headerBG.getChildAt(0)));
  252. }
  253. dataGrid._drawSeparators();
  254. }
  255. else
  256. {
  257. headerBG.visible = false;
  258. dataGrid._clearSeparators();
  259. }
  260. dataGrid._placeSortArrow();
  261. allowItemSizeChangeNotification = true;
  262. }
  263. mx_internal function _drawHeaderBackground(headerBG:UIComponent):void
  264. {
  265. drawHeaderBackground(headerBG);
  266. }
  267. /**
  268. * Draws the background of the headers into the given
  269. * UIComponent. The graphics drawn may be scaled horizontally
  270. * if the component's width changes or this method will be
  271. * called again to redraw at a different width and/or height
  272. *
  273. * @param headerBG A UIComponent that will contain the header
  274. * background graphics.
  275. */
  276. protected function drawHeaderBackground(headerBG:UIComponent):void
  277. {
  278. var tot:Number = width;
  279. var hh:Number = cachedHeaderHeight;
  280. var g:Graphics = headerBG.graphics;
  281. g.clear();
  282. var colors:Array = getStyle("headerColors");
  283. StyleManager.getColorNames(colors);
  284. var matrix:Matrix = new Matrix();
  285. matrix.createGradientBox(tot, hh + 1, Math.PI/2, 0, 0);
  286. colors = [ colors[0], colors[0], colors[1] ];
  287. var ratios:Array = [ 0, 60, 255 ];
  288. var alphas:Array = [ 1.0, 1.0, 1.0 ];
  289. g.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
  290. g.lineStyle(0, 0x000000, 0);
  291. g.moveTo(0, 0);
  292. g.lineTo(tot, 0);
  293. g.lineTo(tot, hh - 0.5);
  294. g.lineStyle(0, getStyle("borderColor"), 100);
  295. g.lineTo(0, hh - 0.5);
  296. g.lineStyle(0, 0x000000, 0);
  297. g.endFill();
  298. }
  299. private function drawHeaderBackgroundSkin(headerBGSkin:IFlexDisplayObject):void
  300. {
  301. headerBGSkin.setActualSize(unscaledWidth, Math.ceil(cachedHeaderHeight));
  302. }
  303. mx_internal function _clearSeparators():void
  304. {
  305. clearSeparators();
  306. }
  307. /**
  308. * Removes column header separators that the user normally uses
  309. * to resize columns.
  310. */
  311. protected function clearSeparators():void
  312. {
  313. if (!separators)
  314. return;
  315. var lines:Sprite = Sprite(getChildByName("lines"));
  316. while (lines.numChildren)
  317. {
  318. lines.removeChildAt(lines.numChildren - 1);
  319. separators.pop();
  320. }
  321. }
  322. mx_internal function _drawSeparators():void
  323. {
  324. drawSeparators();
  325. }
  326. /**
  327. * Creates and displays the column header separators that the user
  328. * normally uses to resize columns. This implementation uses
  329. * the same Sprite as the lines and column backgrounds and adds
  330. * instances of the <code>headerSeparatorSkin</code> and attaches mouse
  331. * listeners to them in order to know when the user wants
  332. * to resize a column.
  333. */
  334. protected function drawSeparators():void
  335. {
  336. if (!separators)
  337. separators = [];
  338. var lines:UIComponent = UIComponent(getChildByName("lines"));
  339. if (!lines)
  340. {
  341. lines = new UIComponent();
  342. lines.name = "lines";
  343. addChild(lines);
  344. }
  345. else
  346. setChildIndex(lines, numChildren - 1);
  347. // required to deal with some 2.x clipping behavior
  348. lines.scrollRect = new Rectangle(0, 0, unscaledWidth, unscaledHeight + 1);
  349. if (headerSepSkinChanged)
  350. {
  351. headerSepSkinChanged = false;
  352. clearSeparators();
  353. }
  354. var n:int = visibleColumns ? visibleColumns.length : 0;
  355. if (!needRightSeparator && n > 0)
  356. n--;
  357. for (var i:int = 0; i < n; i++)
  358. {
  359. var sep:UIComponent;
  360. var sepSkin:IFlexDisplayObject;
  361. if (i < lines.numChildren)
  362. {
  363. sep = UIComponent(lines.getChildAt(i));
  364. sepSkin = IFlexDisplayObject(sep.getChildAt(0));
  365. }
  366. else
  367. {
  368. var headerSeparatorClass:Class =
  369. getStyle("headerSeparatorSkin");
  370. sepSkin = new headerSeparatorClass();
  371. if (sepSkin is ISimpleStyleClient)
  372. ISimpleStyleClient(sepSkin).styleName = this;
  373. sep = new UIComponent();
  374. sep.addChild(DisplayObject(sepSkin));
  375. lines.addChild(sep);
  376. separators.push(sep);
  377. }
  378. // if not separator
  379. if ( !(i == visibleColumns.length-1 && !needRightSeparatorEvents) )
  380. {
  381. DisplayObject(sep).addEventListener(
  382. MouseEvent.MOUSE_OVER, columnResizeMouseOverHandler);
  383. DisplayObject(sep).addEventListener(
  384. MouseEvent.MOUSE_OUT, columnResizeMouseOutHandler);
  385. DisplayObject(sep).addEventListener(
  386. MouseEvent.MOUSE_DOWN, columnResizeMouseDownHandler);
  387. }
  388. else
  389. {
  390. // if not separator
  391. if ( (i == visibleColumns.length-1 && !needRightSeparatorEvents) )
  392. {
  393. DisplayObject(sep).removeEventListener(
  394. MouseEvent.MOUSE_OVER, columnResizeMouseOverHandler);
  395. DisplayObject(sep).removeEventListener(
  396. MouseEvent.MOUSE_OUT, columnResizeMouseOutHandler);
  397. DisplayObject(sep).removeEventListener(
  398. MouseEvent.MOUSE_DOWN, columnResizeMouseDownHandler);
  399. }
  400. }
  401. var cols:Array = visibleColumns;
  402. if (!(cols && cols.length > 0 || dataGrid.headerVisible))
  403. {
  404. sep.visible = false;
  405. continue;
  406. }
  407. sep.visible = true;
  408. sep.x = headerItems[i].x +
  409. visibleColumns[i].width - Math.round(sepSkin.measuredWidth / 2);
  410. if (i > 0)
  411. {
  412. sep.x = Math.max(sep.x,
  413. separators[i - 1].x + Math.round(sepSkin.measuredWidth / 2));
  414. }
  415. sep.y = 0;
  416. sepSkin.setActualSize(sepSkin.measuredWidth, Math.ceil(cachedHeaderHeight));
  417. // Draw invisible background for separator affordance
  418. sep.graphics.clear();
  419. sep.graphics.beginFill(0xFFFFFF, 0);
  420. sep.graphics.drawRect(-separatorAffordance, 0,
  421. sepSkin.measuredWidth + separatorAffordance,
  422. cachedHeaderHeight);
  423. sep.graphics.endFill();
  424. sep.mouseEnabled = true;
  425. }
  426. while (lines.numChildren > n)
  427. {
  428. lines.removeChildAt(lines.numChildren - 1);
  429. separators.pop();
  430. }
  431. }
  432. /**
  433. * Draws the highlight indicator into the given Sprite
  434. * at the position, width and height specified using the
  435. * color specified.
  436. *
  437. * @param indicator A Sprite that should contain the graphics
  438. * that make a renderer look highlighted.
  439. *
  440. * @param x The suggested x position for the indicator.
  441. *
  442. * @param y The suggested y position for the indicator.
  443. *
  444. * @param width The suggested width for the indicator.
  445. *
  446. * @param height The suggested height for the indicator.
  447. *
  448. * @param color The suggested color for the indicator.
  449. *
  450. * @param itemRenderer The item renderer that is being highlighted.
  451. *
  452. */
  453. protected function drawHeaderIndicator(indicator:Sprite, x:Number, y:Number, width:Number, height:Number, color:uint, itemRenderer:IListItemRenderer):void
  454. {
  455. var g:Graphics = indicator.graphics;
  456. g.clear();
  457. g.beginFill(color);
  458. g.drawRect(0, 0, width, height);
  459. g.endFill();
  460. indicator.x = x;
  461. indicator.y = y;
  462. }
  463. /**
  464. * Draws the selection indicator into the given Sprite
  465. * at the position, width and height specified using the
  466. * color specified.
  467. *
  468. * @param indicator A Sprite that should contain the graphics
  469. * that make a renderer look selected.
  470. *
  471. * @param x The suggested x position for the indicator.
  472. *
  473. * @param y The suggested y position for the indicator.
  474. *
  475. * @param width The suggested width for the indicator.
  476. *
  477. * @param height The suggested height for the indicator.
  478. *
  479. * @param color The suggested color for the indicator.
  480. *
  481. * @param itemRenderer The item renderer that is being selected.
  482. *
  483. */
  484. protected function drawSelectionIndicator(indicator:Sprite, x:Number, y:Number, width:Number, height:Number, color:uint, itemRenderer:IListItemRenderer):void
  485. {
  486. var g:Graphics = indicator.graphics;
  487. g.clear();
  488. g.beginFill(color);
  489. g.drawRect(0, 0, width, height);
  490. g.endFill();
  491. indicator.x = x;
  492. indicator.y = y;
  493. }
  494. /**
  495. * Draws the overlay on the dragged column into the given Sprite
  496. * at the position, width and height specified using the
  497. * color specified.
  498. *
  499. * @param indicator A Sprite that should contain the graphics
  500. * that indicate that a column is being dragged.
  501. *
  502. * @param x The suggested x position for the indicator.
  503. *
  504. * @param y The suggested y position for the indicator.
  505. *
  506. * @param width The suggested width for the indicator.
  507. *
  508. * @param height The suggested height for the indicator.
  509. *
  510. * @param color The suggested color for the indicator.
  511. *
  512. * @param itemRenderer The item renderer that is being dragged.
  513. *
  514. */
  515. protected function drawColumnDragOverlay(indicator:Sprite, x:Number, y:Number, width:Number, height:Number, color:uint, itemRenderer:IListItemRenderer):void
  516. {
  517. var g:Graphics = indicator.graphics;
  518. g.clear();
  519. g.beginFill(color);
  520. g.drawRect(0, 0, width, height);
  521. g.endFill();
  522. indicator.x = x;
  523. indicator.y = y;
  524. }
  525. //--------------------------------------------------------------------------
  526. //
  527. // Event handlers
  528. //
  529. //--------------------------------------------------------------------------
  530. /**
  531. * @private
  532. */
  533. private function columnResizeMouseOverHandler(event:MouseEvent):void
  534. {
  535. if (!enabled || !dataGrid.resizableColumns)
  536. return;
  537. var target:DisplayObject = DisplayObject(event.target);
  538. var index:int = target.parent.getChildIndex(target);
  539. if (!visibleColumns[index].resizable)
  540. return;
  541. // hide the mouse, attach and show the cursor
  542. var stretchCursorClass:Class = getStyle("stretchCursor");
  543. resizeCursorID = cursorManager.setCursor(stretchCursorClass,
  544. CursorManagerPriority.HIGH, 0, 0);
  545. }
  546. /**
  547. * @private
  548. */
  549. private function columnResizeMouseOutHandler(event:MouseEvent):void
  550. {
  551. if (!enabled || !dataGrid.resizableColumns)
  552. return;
  553. var target:DisplayObject = DisplayObject(event.target);
  554. var index:int = target.parent.getChildIndex(target);
  555. if (!visibleColumns[index].resizable)
  556. return;
  557. cursorManager.removeCursor(resizeCursorID);
  558. }
  559. /**
  560. * @private
  561. * Indicates where the right side of a resized column appears.
  562. */
  563. private function columnResizeMouseDownHandler(event:MouseEvent):void
  564. {
  565. if (!enabled || !dataGrid.resizableColumns)
  566. return;
  567. var target:DisplayObject = DisplayObject(event.target);
  568. var index:int = target.parent.getChildIndex(target);
  569. if (!visibleColumns[index].resizable)
  570. return;
  571. startX = DisplayObject(event.target).x + x;
  572. lastPt = new Point(event.stageX, event.stageY);
  573. lastPt = dataGrid.globalToLocal(lastPt);
  574. var n:int = separators.length;
  575. var colIndex:int = 0;
  576. for (var i:int = 0; i < n; i++)
  577. {
  578. if (separators[i] == event.target)
  579. {
  580. resizingColumn = visibleColumns[i];
  581. colIndex = i;
  582. }
  583. else
  584. separators[i].mouseEnabled = false;
  585. }
  586. if (!resizingColumn)
  587. return;
  588. minX = headerItems[colIndex].x + x + resizingColumn.minWidth;
  589. var sbRoot:DisplayObject = systemManager.getSandboxRoot();
  590. sbRoot.addEventListener(MouseEvent.MOUSE_MOVE, columnResizingHandler, true);
  591. sbRoot.addEventListener(MouseEvent.MOUSE_UP, columnResizeMouseUpHandler, true);
  592. sbRoot.addEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE, columnResizeMouseUpHandler);
  593. systemManager.deployMouseShields(true);
  594. var resizeSkinClass:Class = getStyle("columnResizeSkin");
  595. resizeGraphic = new resizeSkinClass();
  596. if (resizeGraphic is Sprite)
  597. Sprite(resizeGraphic).mouseEnabled = false;
  598. dataGrid.addChild(DisplayObject(resizeGraphic));
  599. resizeGraphic.move(DisplayObject(event.target).x + x, 0);
  600. resizeGraphic.setActualSize(resizeGraphic.measuredWidth,
  601. dataGrid.height / dataGrid.scaleY);
  602. }
  603. /**
  604. * @private
  605. */
  606. private function columnResizingHandler(event:MouseEvent):void
  607. {
  608. if (!MouseEvent(event).buttonDown)
  609. {
  610. columnResizeMouseUpHandler(event);
  611. return;
  612. }
  613. var vsw:int = dataGrid.vScrollBar ? dataGrid.vScrollBar.width : 0;
  614. var pt:Point = new Point(event.stageX, event.stageY);
  615. pt = dataGrid.globalToLocal(pt);
  616. lastPt = pt;
  617. resizeGraphic.move(Math.min(Math.max(minX, pt.x),
  618. (dataGrid.width / dataGrid.scaleX) - separators[0].width - vsw), 0);
  619. }
  620. /**
  621. * @private
  622. * Determines how much to resize the column.
  623. */
  624. private function columnResizeMouseUpHandler(event:Event):void
  625. {
  626. if (!enabled || !dataGrid.resizableColumns)
  627. return;
  628. // Set this to null so sort doesn't happen.
  629. lastItemDown = null;
  630. var sbRoot:DisplayObject = systemManager.getSandboxRoot();
  631. sbRoot.removeEventListener(MouseEvent.MOUSE_MOVE, columnResizingHandler, true);
  632. sbRoot.removeEventListener(MouseEvent.MOUSE_UP, columnResizeMouseUpHandler, true);
  633. sbRoot.removeEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE, columnResizeMouseUpHandler);
  634. systemManager.deployMouseShields(false);
  635. dataGrid.removeChild(DisplayObject(resizeGraphic));
  636. resizeGraphic = null;
  637. cursorManager.removeCursor(resizeCursorID);
  638. var c:DataGridColumn = resizingColumn;
  639. resizingColumn = null;
  640. var vsw:int = dataGrid.vScrollBar ? dataGrid.vScrollBar.width : 0;
  641. var mouseEvent:MouseEvent = event as MouseEvent;
  642. var pt:Point;
  643. if (mouseEvent)
  644. {
  645. pt = new Point(mouseEvent.stageX, mouseEvent.stageY);
  646. pt = dataGrid.globalToLocal(pt);
  647. }
  648. else
  649. pt = lastPt;
  650. // resize the column
  651. var widthChange:Number = Math.min(Math.max(minX, pt.x),
  652. (dataGrid.width / dataGrid.scaleX) - separators[0].width - vsw) - startX;
  653. dataGrid.resizeColumn(c.colNum, Math.floor(c.width + widthChange));
  654. invalidateDisplayList(); // force redraw of columns
  655. // event
  656. var dataGridEvent:DataGridEvent =
  657. new DataGridEvent(DataGridEvent.COLUMN_STRETCH);
  658. dataGridEvent.columnIndex = c.colNum;
  659. dataGridEvent.dataField = c.dataField;
  660. dataGridEvent.localX = pt.x;
  661. dataGrid.dispatchEvent(dataGridEvent);
  662. }
  663. /**
  664. * @private
  665. */
  666. private function columnDraggingMouseMoveHandler(event:MouseEvent):void
  667. {
  668. if (!event.buttonDown)
  669. {
  670. columnDraggingMouseUpHandler(event);
  671. return;
  672. }
  673. var item:IListItemRenderer;
  674. var c:DataGridColumn = dataGrid.movingColumn;
  675. var s:Sprite;
  676. var i:int = 0;
  677. var n:int = headerItems.length;
  678. var dgSelectionLayer:Sprite;
  679. if (isNaN(startX))
  680. {
  681. // If startX is not a number, dragging has just started.
  682. // Initialise and return without actually moving anything.
  683. startX = event.stageX;
  684. // Set this to null so sort doesn't happen.
  685. lastItemDown = null;
  686. var vm:EdgeMetrics = dataGrid.viewMetrics;
  687. // Create, position and draw selection layer over both headers.
  688. dgSelectionLayer = new UIComponent();
  689. dgSelectionLayer.name = "columnDragSelectionLayer";
  690. dgSelectionLayer.alpha = 0.6;
  691. dataGrid.addChild(dgSelectionLayer);
  692. dgSelectionLayer.x = vm.left;
  693. dgSelectionLayer.y = vm.top;
  694. // Create and position proxy.
  695. var proxy:IListItemRenderer = dataGrid.createColumnItemRenderer(c, true, c);
  696. proxy.name = "headerDragProxy";
  697. var rowData:DataGridListData = new DataGridListData((c.headerText != null) ? c.headerText : c.dataField,
  698. c.dataField, c.colNum, uid, dataGrid, 0);
  699. if (proxy is IDropInListItemRenderer)
  700. IDropInListItemRenderer(proxy).listData = rowData;
  701. dgSelectionLayer.addChild(DisplayObject(proxy));
  702. proxy.data = c;
  703. proxy.styleName = getStyle("headerDragProxyStyleName");
  704. UIComponentGlobals.layoutManager.validateClient(proxy, true);
  705. proxy.setActualSize(c.width, dataGrid._explicitHeaderHeight ?
  706. dataGrid.headerHeight : proxy.getExplicitOrMeasuredHeight());
  707. for (i = 0; i < n; i++)
  708. {
  709. item = headerItems[i];
  710. if (item.data == dataGrid.movingColumn)
  711. break;
  712. }
  713. proxy.move(item.x + x, item.y);
  714. // Create, position and draw column overlay.
  715. s = new FlexSprite();
  716. s.name = "columnDragOverlay";
  717. s.alpha = 0.6;
  718. dataGrid.addChild(s);
  719. if (c.width > 0)
  720. {
  721. drawColumnDragOverlay(s, item.x + x, 0, c.width,
  722. dataGrid.height / dataGrid.scaleY - vm.bottom - s.y,
  723. getStyle("disabledColor"), item);
  724. }
  725. s = Sprite(selectionLayer.getChildByName("headerSelection"));
  726. if (s)
  727. {
  728. s.width = dataGrid.movingColumn.width;
  729. dgSelectionLayer.addChild(s);
  730. s.x += x;
  731. }
  732. // Clip the contents so the header drag proxy doesn't show
  733. // outside the list.
  734. dgSelectionLayer.scrollRect = new Rectangle(0, 0,
  735. dataGrid.width / dataGrid.scaleX,
  736. unscaledHeight);
  737. return;
  738. }
  739. var deltaX:Number = event.stageX - startX;
  740. dgSelectionLayer = Sprite(dataGrid.getChildByName("columnDragSelectionLayer"));
  741. // Move header selection.
  742. s = Sprite(dgSelectionLayer.getChildByName("headerSelection"));
  743. if (s)
  744. s.x += deltaX;
  745. // Move header proxy.
  746. item = IListItemRenderer(dgSelectionLayer.getChildByName("headerDragProxy"));
  747. if (item)
  748. item.move(item.x + deltaX, item.y);
  749. startX += deltaX;
  750. var allVisibleColumns:Array = dataGrid.getAllVisibleColumns();
  751. var pt:Point = new Point(event.stageX, event.stageY);
  752. pt = dataGrid.globalToLocal(pt);
  753. lastPt = pt;
  754. n = allVisibleColumns.length;
  755. var xx:Number = dataGrid.viewMetrics.left;
  756. var ww:Number;
  757. for (i = 0; i < n; i++)
  758. {
  759. ww = allVisibleColumns[i].width;
  760. if (pt.x < xx + ww)
  761. {
  762. // If the mouse pointer over the right half of the column, the
  763. // drop indicator should be shown before the next column.
  764. if (pt.x > xx + ww / 2)
  765. {
  766. i++;
  767. xx += ww;
  768. }
  769. if (dropColumnIndex != i)
  770. {
  771. dropColumnIndex = i;
  772. if (!columnDropIndicator)
  773. {
  774. var dropIndicatorClass:Class
  775. = getStyle("columnDropIndicatorSkin");
  776. if (!dropIndicatorClass)
  777. dropIndicatorClass = DataGridColumnDropIndicator;
  778. columnDropIndicator = IFlexDisplayObject(
  779. new dropIndicatorClass());
  780. if (columnDropIndicator is ISimpleStyleClient)
  781. ISimpleStyleClient(columnDropIndicator).styleName = this;
  782. dataGrid.addChild(
  783. DisplayObject(columnDropIndicator));
  784. var m:Shape = new Shape();
  785. m.graphics.beginFill(0xffffff);
  786. m.graphics.drawRect(0, 0, 10, 10);
  787. m.graphics.endFill();
  788. dataGrid.addChild(m);
  789. columnDropIndicator.mask = m;
  790. }
  791. dataGrid.setChildIndex(
  792. DisplayObject(columnDropIndicator),
  793. dataGrid.numChildren - 1);
  794. columnDropIndicator.visible = true;
  795. m = columnDropIndicator.mask as Shape;
  796. m.x = dataGrid.viewMetrics.left;
  797. m.y = dataGrid.viewMetrics.top;
  798. m.width = dataGrid.width / dataGrid.scaleX - m.x - dataGrid.viewMetrics.right;
  799. m.height = dataGrid.height / dataGrid.scaleY - m.x - dataGrid.viewMetrics.bottom;
  800. columnDropIndicator.x = xx - columnDropIndicator.width;
  801. columnDropIndicator.y = 0;
  802. columnDropIndicator.setActualSize(3, dataGrid.height / dataGrid.scaleY);
  803. }
  804. break;
  805. }
  806. xx += ww;
  807. }
  808. }
  809. /**
  810. * @private
  811. *
  812. * @param event MouseEvent or SandboxMouseEvent.
  813. */
  814. private function columnDraggingMouseUpHandler(event:Event):void
  815. {
  816. if (!dataGrid.movingColumn)
  817. return;
  818. var origIndex:int = dataGrid.movingColumn.colNum;
  819. var allVisibleColumns:Array = dataGrid.getAllVisibleColumns();
  820. if (dropColumnIndex >= 0)
  821. {
  822. if (dropColumnIndex >= allVisibleColumns.length)
  823. {
  824. dropColumnIndex = allVisibleColumns.length - 1;
  825. }
  826. else
  827. {
  828. if (origIndex < allVisibleColumns[dropColumnIndex].colNum)
  829. dropColumnIndex--;
  830. }
  831. // dropColumnIndex is actually the index into the headerItems
  832. // array. Get the corresponding index into the _columns array.
  833. dropColumnIndex = allVisibleColumns[dropColumnIndex].colNum;
  834. }
  835. // Shift columns.
  836. dataGrid.shiftColumns(origIndex, dropColumnIndex, event as MouseEvent);
  837. var sbRoot:DisplayObject = systemManager.getSandboxRoot();
  838. sbRoot.removeEventListener(MouseEvent.MOUSE_MOVE, columnDraggingMouseMoveHandler, true);
  839. sbRoot.removeEventListener(MouseEvent.MOUSE_UP, columnDraggingMouseUpHandler, true);
  840. sbRoot.removeEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE, columnDraggingMouseUpHandler);
  841. systemManager.deployMouseShields(false);
  842. var dgSelectionLayer:Sprite = Sprite(dataGrid.getChildByName("columnDragSelectionLayer"));
  843. if (!dgSelectionLayer)
  844. {
  845. startX = NaN;
  846. dataGrid.movingColumn = null;
  847. dropColumnIndex = -1;
  848. return;
  849. }
  850. var proxy:IListItemRenderer =
  851. IListItemRenderer(getChildByName("headerDragProxy"));
  852. if (proxy)
  853. dgSelectionLayer.removeChild(DisplayObject(proxy));
  854. var s:Sprite = Sprite(dgSelectionLayer.getChildByName("headerSelection"));
  855. if (s)
  856. dgSelectionLayer.removeChild(s);
  857. if (columnDropIndicator)
  858. columnDropIndicator.visible = false;
  859. s = Sprite(dataGrid.getChildByName("columnDragOverlay"));
  860. if (s)
  861. dataGrid.removeChild(s);
  862. dataGrid.removeChild(dgSelectionLayer);
  863. startX = NaN;
  864. dataGrid.movingColumn = null;
  865. dropColumnIndex = -1;
  866. invalidateDisplayList(); // force redraw
  867. }
  868. /**
  869. * @private
  870. */
  871. protected function mouseOverHandler(event:MouseEvent):void
  872. {
  873. var r:IListItemRenderer;
  874. var i:int;
  875. if (resizingColumn || dataGrid.movingColumn)
  876. return;
  877. if (dataGrid.enabled && dataGrid.sortableColumns && dataGrid.headerVisible)
  878. {
  879. // find out if we hit the sort arrow
  880. s = Sprite(getChildByName("sortArrowHitArea"));
  881. if (event.target == s)
  882. {
  883. var n:int = visibleColumns.length;
  884. for (i = 0; i < n; i++)
  885. {
  886. if (visibleColumns[i].colNum == dataGrid.sortIndex)
  887. {
  888. r = headerItems[i];
  889. break;
  890. }
  891. }
  892. }
  893. else
  894. {
  895. for (i = 0; i < separators.length; i++)
  896. {
  897. if (event.target == separators[i] && visibleColumns[i].resizable)
  898. return;
  899. }
  900. var pt:Point = new Point(event.stageX, event.stageY);
  901. pt = globalToLocal(pt);
  902. for (i = 0; i < headerItems.length; i++)
  903. {
  904. if (headerItems[i].x + headerItems[i].width >= pt.x)
  905. {
  906. r = headerItems[i];
  907. break;
  908. }
  909. }
  910. if (i >= headerItems.length)
  911. return;
  912. }
  913. s = Sprite(getChildByName("sortArrowHitArea"));
  914. if (visibleColumns[i].sortable)
  915. {
  916. var s:Sprite = Sprite(
  917. selectionLayer.getChildByName("headerSelection"));
  918. if (!s)
  919. {
  920. s = new FlexSprite();
  921. s.name = "headerSelection";
  922. s.mouseEnabled = false;
  923. selectionLayer.addChild(s);
  924. }
  925. this.drawGradientBackGround(s, r.x, 0, visibleColumns[i].width, cachedHeaderHeight - 0.5, r);
  926. }
  927. }
  928. if (event.buttonDown)
  929. lastItemDown = r;
  930. else
  931. lastItemDown = null;
  932. }
  933. /**
  934. * Draws a gradient background color.
  935. *
  936. * The start- and endcolor of the gradient are specified via the styles <code>startColor</code> and <code>endColor</code>.
  937. */
  938. private function drawGradientBackGround(indicator:Sprite, x:Number, y:Number, w:Number, h:Number, itemRenderer:IListItemRenderer):void {
  939. var g:Graphics = indicator.graphics;
  940. g.clear();
  941. var matrix:Matrix = new Matrix();
  942. matrix.createGradientBox(w, h + 1, Math.PI/2, 0, 0);
  943. var colors:Array = [ getStyle("startColor"), getStyle("startColor"), getStyle("endColor") ];
  944. var ratios:Array = [ 0, 60, 255 ];
  945. var alphas:Array = [ 1.0, 1.0, 1.0 ];
  946. g.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix);
  947. g.drawRect(0, 0, w, h);
  948. g.endFill();
  949. indicator.x = x;
  950. indicator.y = y;
  951. }
  952. /**
  953. * @private
  954. */
  955. protected function mouseOutHandler(event:MouseEvent):void
  956. {
  957. var r:IListItemRenderer;
  958. var i:int;
  959. if (resizeGraphic || dataGrid.movingColumn)
  960. return;
  961. if (dataGrid.enabled && dataGrid.sortableColumns && dataGrid.headerVisible)
  962. {
  963. // find out if we hit the sort arrow
  964. s = Sprite(getChildByName("sortArrowHitArea"));
  965. if (event.target == s)
  966. {
  967. var n:int = visibleColumns.length;
  968. for (i = 0; i < n; i++)
  969. {
  970. if (visibleColumns[i].colNum == dataGrid.sortIndex)
  971. {
  972. r = headerItems[i];
  973. break;
  974. }
  975. }
  976. if (i >= visibleColumns.length)
  977. return;
  978. }
  979. else
  980. {
  981. for (i = 0; i < separators.length; i++)
  982. {
  983. if (event.target == separators[i] && visibleColumns[i].resizable)
  984. return;
  985. }
  986. var pt:Point = new Point(event.stageX, event.stageY);
  987. pt = globalToLocal(pt);
  988. for (i = 0; i < headerItems.length; i++)
  989. {
  990. if (headerItems[i].x + headerItems[i].width >= pt.x)
  991. {
  992. r = headerItems[i];
  993. break;
  994. }
  995. }
  996. if (i >= headerItems.length)
  997. i = headerItems.length - 1;
  998. }
  999. if (visibleColumns.length > 0 && visibleColumns[i].sortable)
  1000. {
  1001. var s:Sprite = Sprite(
  1002. selectionLayer.getChildByName("headerSelection"));
  1003. if (s)
  1004. selectionLayer.removeChild(s);
  1005. }
  1006. }
  1007. if (event.buttonDown)
  1008. lastItemDown = r;
  1009. else
  1010. lastItemDown = null;
  1011. }
  1012. /**
  1013. * @private
  1014. */
  1015. protected function mouseDownHandler(event:MouseEvent):void
  1016. {
  1017. // trace(">>mouseDownHandler");
  1018. var r:IListItemRenderer;
  1019. var s:Sprite;
  1020. var i:int;
  1021. // find out if we hit the sort arrow
  1022. s = Sprite(getChildByName("sortArrowHitArea"));
  1023. if (event.target == s)
  1024. {
  1025. var n:int = visibleColumns.length;
  1026. for (i = 0; i < n; i++)
  1027. {
  1028. if (visibleColumns[i].colNum == dataGrid.sortIndex)
  1029. {
  1030. r = headerItems[i];
  1031. break;
  1032. }
  1033. }
  1034. }
  1035. else
  1036. {
  1037. for (i = 0; i < separators.length; i++)
  1038. {
  1039. if (event.target == separators[i] && visibleColumns[i].resizable)
  1040. return;
  1041. }
  1042. var pt:Point = new Point(event.stageX, event.stageY);
  1043. pt = globalToLocal(pt);
  1044. for (i = 0; i < headerItems.length; i++)
  1045. {
  1046. if (headerItems[i].x + headerItems[i].width >= pt.x)
  1047. {
  1048. r = headerItems[i];
  1049. break;
  1050. }
  1051. }
  1052. if (i >= headerItems.length)
  1053. return;
  1054. }
  1055. // if headers are visible and clickable for sorting
  1056. if (dataGrid.enabled && (dataGrid.sortableColumns || dataGrid.draggableColumns)
  1057. && dataGrid.headerVisible)
  1058. {
  1059. if (dataGrid.sortableColumns && visibleColumns[i].sortable)
  1060. {
  1061. lastItemDown = r;
  1062. s = Sprite(selectionLayer.getChildByName("headerSelection"));
  1063. if (!s)
  1064. {
  1065. s = new FlexSprite();
  1066. s.name = "headerSelection";
  1067. selectionLayer.addChild(s);
  1068. }
  1069. // drawSelectionIndicator(s, r.x, 0, visibleColumns[i].width, cachedHeaderHeight - 0.5, getStyle("selectionColor"), r);
  1070. this.drawGradientBackGround(s, r.x, 0, visibleColumns[i].width, cachedHeaderHeight - 0.5, r);
  1071. }
  1072. // begin column dragging
  1073. if (dataGrid.draggableColumns && visibleColumns[i].draggable)
  1074. {
  1075. startX = NaN;
  1076. var sbRoot:DisplayObject = systemManager.getSandboxRoot();
  1077. sbRoot.addEventListener(MouseEvent.MOUSE_MOVE, columnDraggingMouseMoveHandler, true);
  1078. sbRoot.addEventListener(MouseEvent.MOUSE_UP, columnDraggingMouseUpHandler, true);
  1079. sbRoot.addEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE, columnDraggingMouseUpHandler);
  1080. systemManager.deployMouseShields(true);
  1081. dataGrid.movingColumn = visibleColumns[i];
  1082. }
  1083. }
  1084. }
  1085. /**
  1086. * @private
  1087. */
  1088. protected function mouseUpHandler(event:MouseEvent):void
  1089. {
  1090. var dataGridEvent:DataGridEvent;
  1091. var r:IListItemRenderer;
  1092. var s:Sprite;
  1093. var n:int;
  1094. var i:int;
  1095. // find out if we hit the sort arrow
  1096. s = Sprite(getChildByName("sortArrowHitArea"));
  1097. if (event.target == s)
  1098. {
  1099. n = visibleColumns.length;
  1100. for (i = 0; i < n; i++)
  1101. {
  1102. if (visibleColumns[i].colNum == dataGrid.sortIndex)
  1103. {
  1104. r = headerItems[i];
  1105. break;
  1106. }
  1107. }
  1108. }
  1109. else
  1110. {
  1111. for (i = 0; i < separators.length; i++)
  1112. {
  1113. if (event.target == separators[i] && visibleColumns[i].resizable)
  1114. return;
  1115. }
  1116. var pt:Point = new Point(event.stageX, event.stageY);
  1117. pt = globalToLocal(pt);
  1118. for (i = 0; i < headerItems.length; i++)
  1119. {
  1120. if (headerItems[i].x + headerItems[i].width >= pt.x)
  1121. {
  1122. r = headerItems[i];
  1123. break;
  1124. }
  1125. }
  1126. if (i >= headerItems.length)
  1127. return;
  1128. }
  1129. if (dataGrid.enabled && (dataGrid.sortableColumns || dataGrid.draggableColumns)
  1130. && dataGrid.dataProvider && dataGrid.headerVisible)
  1131. {
  1132. if (r == lastItemDown)
  1133. {
  1134. if (dataGrid.sortableColumns && visibleColumns[i].sortable)
  1135. {
  1136. lastItemDown = null;
  1137. dataGridEvent = new DataGridEvent(DataGridEvent.HEADER_RELEASE, false, true);
  1138. // HEADER_RELEASE event is cancelable
  1139. dataGridEvent.columnIndex = visibleColumns[i].colNum;
  1140. dataGridEvent.dataField = visibleColumns[i].dataField;
  1141. dataGridEvent.itemRenderer = r;
  1142. dataGrid.dispatchEvent(dataGridEvent);
  1143. }
  1144. }
  1145. }
  1146. }
  1147. mx_internal function _placeSortArrow():void
  1148. {
  1149. placeSortArrow();
  1150. }
  1151. /**
  1152. * Draws the sort arrow graphic on the column that is the current sort key.
  1153. * This implementation creates or reuses an instance of the skin specified
  1154. * by <code>sortArrowSkin</code> style property and places
  1155. * it in the appropriate column header. It
  1156. * also shrinks the size of the column header if the text in the header
  1157. * would be obscured by the sort arrow.
  1158. */
  1159. protected function placeSortArrow():void
  1160. {
  1161. var sortArrowHitArea:Sprite =
  1162. Sprite(getChildByName("sortArrowHitArea"));
  1163. if (dataGrid.sortIndex == -1 && dataGrid.lastSortIndex == -1)
  1164. {
  1165. if (sortArrow)
  1166. sortArrow.visible = false;
  1167. if (sortArrowHitArea)
  1168. sortArrowHitArea.visible = false;
  1169. return;
  1170. }
  1171. if (!dataGrid.headerVisible)
  1172. {
  1173. if (sortArrow)
  1174. sortArrow.visible = false;
  1175. if (sortArrowHitArea)
  1176. sortArrowHitArea.visible = false;
  1177. return;
  1178. }
  1179. if (!sortArrow)
  1180. {
  1181. var sortArrowClass:Class = getStyle("sortArrowSkin");
  1182. sortArrow = new sortArrowClass();
  1183. DisplayObject(sortArrow).name = enabled ? "sortArrow" : "sortArrowDisabled";
  1184. if (sortArrow is ISimpleStyleClient)
  1185. ISimpleStyleClient(sortArrow).styleName = this;
  1186. addChild(DisplayObject(sortArrow));
  1187. }
  1188. var xx:Number;
  1189. var n:int;
  1190. var i:int;
  1191. var found:Boolean = false;
  1192. if (headerItems && headerItems.length)
  1193. {
  1194. n = headerItems.length;
  1195. for (i = 0; i < n; i++)
  1196. {
  1197. if (visibleColumns[i].colNum == dataGrid.sortIndex)
  1198. {
  1199. xx = headerItems[i].x + visibleColumns[i].width;
  1200. headerItems[i].setActualSize(visibleColumns[i].width - sortArrow.measuredWidth - 8, headerItems[i].height);
  1201. if (!isNaN(headerItems[i].explicitWidth))
  1202. headerItems[i].explicitWidth = headerItems[i].width;
  1203. UIComponentGlobals.layoutManager.validateClient(headerItems[i], true);
  1204. // Create hit area to capture mouse clicks behind arrow.
  1205. if (!sortArrowHitArea)
  1206. {
  1207. sortArrowHitArea = new FlexSprite();
  1208. sortArrowHitArea.name = "sortArrowHitArea";
  1209. addChild(sortArrowHitArea);
  1210. }
  1211. else
  1212. sortArrowHitArea.visible = true;
  1213. sortArrowHitArea.x = headerItems[i].x + headerItems[i].width;
  1214. sortArrowHitArea.y = headerItems[i].y;
  1215. var g:Graphics = sortArrowHitArea.graphics;
  1216. g.clear();
  1217. g.beginFill(0, 0);
  1218. g.drawRect(0, 0, sortArrow.measuredWidth + 8,
  1219. headerItems[i].height);
  1220. g.endFill();
  1221. found = true;
  1222. break;
  1223. }
  1224. }
  1225. }
  1226. if (isNaN(xx))
  1227. sortArrow.visible = false;
  1228. else
  1229. sortArrow.visible = true;
  1230. if (visibleColumns.length && dataGrid.lastSortIndex >= 0 && dataGrid.lastSortIndex != dataGrid.sortIndex)
  1231. if (visibleColumns[0].colNum <= dataGrid.lastSortIndex &&
  1232. dataGrid.lastSortIndex <= visibleColumns[visibleColumns.length - 1].colNum)
  1233. {
  1234. n = headerItems.length;
  1235. for (var j:int = 0; j < n; j++)
  1236. {
  1237. if (visibleColumns[j].colNum == dataGrid.lastSortIndex)
  1238. {
  1239. headerItems[j].setActualSize(visibleColumns[j].width, headerItems[j].height);
  1240. UIComponentGlobals.layoutManager.validateClient(headerItems[j], true);
  1241. break;
  1242. }
  1243. }
  1244. }
  1245. var d:Boolean = (dataGrid.sortDirection == "ASC");
  1246. sortArrow.width = sortArrow.measuredWidth;
  1247. sortArrow.height = sortArrow.measuredHeight;
  1248. DisplayObject(sortArrow).scaleY = (d) ? -1.0 : 1.0;
  1249. sortArrow.x = xx - sortArrow.measuredWidth - 8;
  1250. var hh:Number = cachedHeaderHeight;
  1251. sortArrow.y = (hh - sortArrow.measuredHeight) / 2 + ((d) ? sortArrow.measuredHeight: 0);
  1252. if (found && sortArrow.x < headerItems[i].x)
  1253. sortArrow.visible = false;
  1254. if (!sortArrow.visible && sortArrowHitArea)
  1255. sortArrowHitArea.visible = false;
  1256. }
  1257. //--------------------------------------------------------------------------
  1258. //
  1259. // Overridden methods: UIComponent
  1260. //
  1261. //--------------------------------------------------------------------------
  1262. /**
  1263. * @private
  1264. */
  1265. override public function invalidateSize():void
  1266. {
  1267. if (allowItemSizeChangeNotification)
  1268. super.invalidateSize();
  1269. }
  1270. /**
  1271. * @copy mx.core.IUIComponent#enabled
  1272. */
  1273. override public function set enabled(value:Boolean):void
  1274. {
  1275. super.enabled = value;
  1276. if (sortArrow)
  1277. {
  1278. removeChild(DisplayObject(sortArrow));
  1279. sortArrow = null;
  1280. placeSortArrow();
  1281. }
  1282. }
  1283. /**
  1284. * @private
  1285. */
  1286. override public function styleChanged(styleProp:String):void
  1287. {
  1288. super.styleChanged(styleProp);
  1289. if (styleProp == "headerBackgroundSkin")
  1290. {
  1291. headerBGSkinChanged = true;
  1292. }
  1293. else if (styleProp == "headerSeparatorSkin")
  1294. {
  1295. headerSepSkinChanged = true;
  1296. }
  1297. }
  1298. /**
  1299. * @private
  1300. */
  1301. private var resizeCursorID:int = CursorManager.NO_CURSOR;
  1302. /**
  1303. * @private
  1304. * A tmp var to store the stretching col's X coord.
  1305. */
  1306. private var startX:Number;
  1307. /**
  1308. * @private
  1309. * A tmp var to store the stretching col's min X coord for column's minWidth.
  1310. */
  1311. private var minX:Number;
  1312. /**
  1313. * @private
  1314. * A tmp var to store the last point (in dataGrid coords) received while dragging.
  1315. */
  1316. private var lastPt:Point;
  1317. /**
  1318. * @private
  1319. * List of header separators for column resizing.
  1320. */
  1321. private var separators:Array;
  1322. /**
  1323. * @private
  1324. */
  1325. mx_internal function getSeparators():Array
  1326. {
  1327. return separators;
  1328. }
  1329. /**
  1330. * @private
  1331. * The column that is being resized.
  1332. */
  1333. private function get resizingColumn():DataGridColumn
  1334. {
  1335. return dataGrid.resizingColumn;
  1336. }
  1337. /**
  1338. * @private
  1339. * The column that is being resized.
  1340. */
  1341. private function set resizingColumn(value:DataGridColumn):void
  1342. {
  1343. dataGrid.resizingColumn = value;
  1344. }
  1345. /**
  1346. * Specifies a graphic that shows the proposed column width as the user stretches it.
  1347. */
  1348. private var resizeGraphic:IFlexDisplayObject; //
  1349. /**
  1350. * @private
  1351. */
  1352. private var lastItemDown:IListItemRenderer;
  1353. /**
  1354. * @private
  1355. * Index of column before which to drop
  1356. */
  1357. private var dropColumnIndex:int = -1;
  1358. /**
  1359. * @private
  1360. */
  1361. mx_internal var columnDropIndicator:IFlexDisplayObject;
  1362. /**
  1363. * The small arrow graphic used to show sortable columns and direction.
  1364. */
  1365. mx_internal var sortArrow:IFlexDisplayObject;
  1366. /**
  1367. * diagnostics
  1368. */
  1369. mx_internal function get rendererArray():Array
  1370. {
  1371. return headerItems;
  1372. }
  1373. /**
  1374. * The offset, in pixels, from the left side of the content of the renderer.
  1375. */
  1376. public var leftOffset:Number = 0;
  1377. /**
  1378. * The offset, in pixels, from the top of the content of the renderer.
  1379. */
  1380. public var topOffset:Number = 0;
  1381. /**
  1382. * The offset, in pixels, from the right side of the content of the renderer.
  1383. */
  1384. public var rightOffset:Number = 0;
  1385. /**
  1386. * The offset, in pixels, from the bottom of the content of the renderer.
  1387. */
  1388. public var bottomOffset:Number = 0;
  1389. /**
  1390. * @private
  1391. */
  1392. private var allowItemSizeChangeNotification:Boolean = true;
  1393. private var headerBGSkinChanged:Boolean = false;
  1394. private var headerSepSkinChanged:Boolean = false;
  1395. }
  1396. }