| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 typedef void EditCellRangeFunction(CellRange range); | 5 typedef void EditCellRangeFunction(CellRange range); |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Spreadsheet widget. | 8 * Spreadsheet widget. |
| 9 */ | 9 */ |
| 10 class SpreadsheetPresenter implements SpreadsheetListener, SelectionListener { | 10 class SpreadsheetPresenter implements SpreadsheetListener, SelectionListener { |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // Recalculate the spreadsheet. The caller is responsible for marking as dirt
y any cells | 369 // Recalculate the spreadsheet. The caller is responsible for marking as dirt
y any cells |
| 370 // that require actual recalculation. Code that causes the table to be resized
is responsible | 370 // that require actual recalculation. Code that causes the table to be resized
is responsible |
| 371 // for updating the DOM table size before this method is called. | 371 // for updating the DOM table size before this method is called. |
| 372 int recalculate() { | 372 int recalculate() { |
| 373 int start = _currentTimeMllis(); | 373 int start = _currentTimeMllis(); |
| 374 _spreadsheet.beginRecalc(); | 374 _spreadsheet.beginRecalc(); |
| 375 | 375 |
| 376 _setTableWidth(_getVisibleTableWidth()); | 376 _setTableWidth(_getVisibleTableWidth()); |
| 377 _tableSizeChanged(); | 377 _tableSizeChanged(); |
| 378 | 378 |
| 379 int num = _table.redraw(_selectionManager, _rows, _columns, | 379 int renderedCells = _table.redraw(_selectionManager, _rows, _columns, |
| 380 _rowShift, _columnShift, _cellDisplay); | 380 _rowShift, _columnShift, _cellDisplay); |
| 381 | 381 |
| 382 // Cell sizes may change so update the selection marquee | 382 // Cell sizes may change so update the selection marquee |
| 383 _selectionManager.updateSelection(); | 383 _selectionManager.updateSelection(); |
| 384 | 384 |
| 385 int calculated = _spreadsheet.endRecalc(); | 385 int calculated = _spreadsheet.endRecalc(); |
| 386 int end = _currentTimeMllis(); | 386 int end = _currentTimeMllis(); |
| 387 | 387 |
| 388 int t = end - start; | 388 int t = end - start; |
| 389 double s = _spreadsheet.calculated * 1000.0 / t; | 389 double s = _spreadsheet.calculated * 1000.0 / t; |
| 390 print("Recalculated ${calculated}, rendered ${num} cells in ${t} msec (${s}
cells/sec)"); | 390 print("Recalculated ${calculated}, rendered ${renderedCells} cells in ${t} m
sec (${s} cells/sec)"); |
| 391 | 391 |
| 392 return calculated; | 392 return calculated; |
| 393 } | 393 } |
| 394 | 394 |
| 395 // Recalculate the entire spreadsheet | 395 // Recalculate the entire spreadsheet |
| 396 void recalculateAll() { | 396 void recalculateAll() { |
| 397 _spreadsheet.markAllDirty(); | 397 _spreadsheet.markAllDirty(); |
| 398 recalculate(); | 398 recalculate(); |
| 399 } | 399 } |
| 400 | 400 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 | 674 |
| 675 int mouseStartX = e.x; | 675 int mouseStartX = e.x; |
| 676 int mouseStartY = e.y; | 676 int mouseStartY = e.y; |
| 677 | 677 |
| 678 _spreadsheetElement.rect.then((ElementRect elementRect) { | 678 _spreadsheetElement.rect.then((ElementRect elementRect) { |
| 679 ClientRect rect = elementRect.bounding; | 679 ClientRect rect = elementRect.bounding; |
| 680 int startX = rect.left; | 680 int startX = rect.left; |
| 681 int startY = rect.top; | 681 int startY = rect.top; |
| 682 _window.document.body.style.setProperty("cursor", "move"); | 682 _window.document.body.style.setProperty("cursor", "move"); |
| 683 | 683 |
| 684 _setDragFunction((MouseEvent e) { | 684 _setDragFunction((MouseEvent e_) { |
| 685 int x = startX + e.x - mouseStartX; | 685 int x = startX + e_.x - mouseStartX; |
| 686 int y = startY + e.y - mouseStartY; | 686 int y = startY + e_.y - mouseStartY; |
| 687 | 687 |
| 688 x = Math.max(x, CssStyles.OBJECTBAR_WIDTH); | 688 x = Math.max(x, CssStyles.OBJECTBAR_WIDTH); |
| 689 y = Math.max(y, CssStyles.SANDBAR_HEIGHT); | 689 y = Math.max(y, CssStyles.SANDBAR_HEIGHT); |
| 690 // Move the spreadsheet container | 690 // Move the spreadsheet container |
| 691 _spreadsheetElement.style.setProperty("left", HtmlUtils.toPx(x)); | 691 _spreadsheetElement.style.setProperty("left", HtmlUtils.toPx(x)); |
| 692 _spreadsheetElement.style.setProperty("top", HtmlUtils.toPx(y)); | 692 _spreadsheetElement.style.setProperty("top", HtmlUtils.toPx(y)); |
| 693 }); | 693 }); |
| 694 }); | 694 }); |
| 695 | 695 |
| 696 _setUndragFunction((MouseEvent e) { | 696 _setUndragFunction((MouseEvent e_) { |
| 697 _window.document.body.style.setProperty("cursor", "auto"); | 697 _window.document.body.style.setProperty("cursor", "auto"); |
| 698 }); | 698 }); |
| 699 }); | 699 }); |
| 700 } | 700 } |
| 701 | 701 |
| 702 void _createResizeDragger(Document doc) { | 702 void _createResizeDragger(Document doc) { |
| 703 _resizeDragger = new Element.tag("div"); | 703 _resizeDragger = new Element.tag("div"); |
| 704 _resizeDragger.id = "resizeDragger-${_spreadsheet.name}"; | 704 _resizeDragger.id = "resizeDragger-${_spreadsheet.name}"; |
| 705 _resizeDragger.attributes["class"] = "resizeDragger"; | 705 _resizeDragger.attributes["class"] = "resizeDragger"; |
| 706 _spreadsheetElement.nodes.add(_resizeDragger); | 706 _spreadsheetElement.nodes.add(_resizeDragger); |
| 707 | 707 |
| 708 _resizeDragger.on.mouseDown.add((MouseEvent e) { | 708 _resizeDragger.on.mouseDown.add((MouseEvent e) { |
| 709 _moveToTop(); | 709 _moveToTop(); |
| 710 | 710 |
| 711 // Hide popups | 711 // Hide popups |
| 712 _hideFormula(); | 712 _hideFormula(); |
| 713 _popupHandler.deactivatePopup(); | 713 _popupHandler.deactivatePopup(); |
| 714 | 714 |
| 715 int mouseStartX = e.x; | 715 int mouseStartX = e.x; |
| 716 int mouseStartY = e.y; | 716 int mouseStartY = e.y; |
| 717 int startX = HtmlUtils.fromPx(_resizeDragger.style.getPropertyValue("left"
)); | 717 int startX = HtmlUtils.fromPx(_resizeDragger.style.getPropertyValue("left"
)); |
| 718 int startY = HtmlUtils.fromPx(_resizeDragger.style.getPropertyValue("top")
); | 718 int startY = HtmlUtils.fromPx(_resizeDragger.style.getPropertyValue("top")
); |
| 719 _window.document.body.style.setProperty("cursor", "move"); | 719 _window.document.body.style.setProperty("cursor", "move"); |
| 720 | 720 |
| 721 _setDragFunction((MouseEvent e) { | 721 _setDragFunction((MouseEvent e_) { |
| 722 int x = startX + e.x - mouseStartX; | 722 int x = startX + e_.x - mouseStartX; |
| 723 int y = startY + e.y - mouseStartY; | 723 int y = startY + e_.y - mouseStartY; |
| 724 | 724 |
| 725 // Move the drag handle | 725 // Move the drag handle |
| 726 _resizeDragger.style.setProperty("left", HtmlUtils.toPx(x)); | 726 _resizeDragger.style.setProperty("left", HtmlUtils.toPx(x)); |
| 727 _resizeDragger.style.setProperty("top", HtmlUtils.toPx(y)); | 727 _resizeDragger.style.setProperty("top", HtmlUtils.toPx(y)); |
| 728 | 728 |
| 729 int column = _getMaxRowOrColumn(x, COL); | 729 int column = _getMaxRowOrColumn(x, COL); |
| 730 int row = _getMaxRowOrColumn(y, ROW) + 1; | 730 int row = _getMaxRowOrColumn(y, ROW) + 1; |
| 731 if (column == -1 || row == -1) { | 731 if (column == -1 || row == -1) { |
| 732 return; | 732 return; |
| 733 } | 733 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 747 } | 747 } |
| 748 _removeTableRowHtml(_rows); | 748 _removeTableRowHtml(_rows); |
| 749 _rows--; | 749 _rows--; |
| 750 } | 750 } |
| 751 while (row > _rows + _rowShift) { | 751 while (row > _rows + _rowShift) { |
| 752 _spreadsheet.insertRow(_rows, _spreadsheet.getDefaultRowHeight(_rows))
; | 752 _spreadsheet.insertRow(_rows, _spreadsheet.getDefaultRowHeight(_rows))
; |
| 753 } | 753 } |
| 754 _spreadsheet.refresh(); | 754 _spreadsheet.refresh(); |
| 755 }); | 755 }); |
| 756 | 756 |
| 757 _setUndragFunction((MouseEvent e) { | 757 _setUndragFunction((MouseEvent e_) { |
| 758 _window.document.body.style.setProperty("cursor", "auto"); | 758 _window.document.body.style.setProperty("cursor", "auto"); |
| 759 }); | 759 }); |
| 760 }); | 760 }); |
| 761 | 761 |
| 762 _refreshResizeDragger(); | 762 _refreshResizeDragger(); |
| 763 } | 763 } |
| 764 | 764 |
| 765 // Initialize the HTML elements used to indicate dragging | 765 // Initialize the HTML elements used to indicate dragging |
| 766 void _createSpreadsheetLayout(Document doc) { | 766 void _createSpreadsheetLayout(Document doc) { |
| 767 DivElement columnDraggerElement = new Element.tag("div"); | 767 DivElement columnDraggerElement = new Element.tag("div"); |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1543 ClientRect boundingRect = rect.bounding; | 1543 ClientRect boundingRect = rect.bounding; |
| 1544 int scrollOffsetX = -boundingRect.left; | 1544 int scrollOffsetX = -boundingRect.left; |
| 1545 int scrollOffsetY = -boundingRect.top; | 1545 int scrollOffsetY = -boundingRect.top; |
| 1546 _contextMenu.show(e.x + scrollOffsetX, e.y + scrollOffsetY); | 1546 _contextMenu.show(e.x + scrollOffsetX, e.y + scrollOffsetY); |
| 1547 }); | 1547 }); |
| 1548 return; | 1548 return; |
| 1549 } | 1549 } |
| 1550 | 1550 |
| 1551 _setDragFunction(mouseMove); | 1551 _setDragFunction(mouseMove); |
| 1552 | 1552 |
| 1553 _setUndragFunction((MouseEvent e) { | 1553 _setUndragFunction((MouseEvent e_) { |
| 1554 dragRowColumn(true); | 1554 dragRowColumn(true); |
| 1555 _table.setDefaultCursor(); | 1555 _table.setDefaultCursor(); |
| 1556 draggingSelection = false; | 1556 draggingSelection = false; |
| 1557 draggingRowColumn[COL] = -1; | 1557 draggingRowColumn[COL] = -1; |
| 1558 setDrag(COL, false); | 1558 setDrag(COL, false); |
| 1559 draggingRowColumn[ROW] = -1; | 1559 draggingRowColumn[ROW] = -1; |
| 1560 setDrag(ROW, false); | 1560 setDrag(ROW, false); |
| 1561 // Finalize the selection | 1561 // Finalize the selection |
| 1562 _selectionManager.selectionChanged(); | 1562 _selectionManager.selectionChanged(); |
| 1563 // Check to see if the selection we just finalized is a request | 1563 // Check to see if the selection we just finalized is a request |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1594 return; | 1594 return; |
| 1595 } | 1595 } |
| 1596 | 1596 |
| 1597 // Click on cell during formula editing | 1597 // Click on cell during formula editing |
| 1598 if (_formulaEditing) { | 1598 if (_formulaEditing) { |
| 1599 _formulaCellSelecting = true; | 1599 _formulaCellSelecting = true; |
| 1600 _formulaCellSelectingRememberSelectionRange(); | 1600 _formulaCellSelectingRememberSelectionRange(); |
| 1601 // disable text selection, because browser inverts selection once we dra
g over input | 1601 // disable text selection, because browser inverts selection once we dra
g over input |
| 1602 _formulaInput.style.setProperty("-webkit-user-select", "none"); | 1602 _formulaInput.style.setProperty("-webkit-user-select", "none"); |
| 1603 // listen for drag operation | 1603 // listen for drag operation |
| 1604 _setDragFunction((MouseEvent e) { | 1604 _setDragFunction((MouseEvent e_) { |
| 1605 Element target = e.target; | 1605 Element target_ = e_.target; |
| 1606 CellLocation location = _getCellLocation(target); | 1606 CellLocation location_ = _getCellLocation(target_); |
| 1607 if (location == null) { | 1607 if (location_ == null) { |
| 1608 return; | 1608 return; |
| 1609 } | 1609 } |
| 1610 _formulaCellSelectingInsertReference(null, location.rowCol); | 1610 _formulaCellSelectingInsertReference(null, location_.rowCol); |
| 1611 }); | 1611 }); |
| 1612 _setUndragFunction((MouseEvent e) { | 1612 _setUndragFunction((MouseEvent e_) { |
| 1613 _formulaInput.style.removeProperty("-webkit-user-select"); | 1613 _formulaInput.style.removeProperty("-webkit-user-select"); |
| 1614 _formulaCellSelectingSelectText(); | 1614 _formulaCellSelectingSelectText(); |
| 1615 }); | 1615 }); |
| 1616 // set "click" location | 1616 // set "click" location |
| 1617 _formulaCellSelectingInsertReference(location.rowCol, null); | 1617 _formulaCellSelectingInsertReference(location.rowCol, null); |
| 1618 return; | 1618 return; |
| 1619 } | 1619 } |
| 1620 | 1620 |
| 1621 // Begin selection | 1621 // Begin selection |
| 1622 draggingSelection = true; | 1622 draggingSelection = true; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 _spreadsheet.execute(command); | 1721 _spreadsheet.execute(command); |
| 1722 } else { | 1722 } else { |
| 1723 if (rowOrCol == COL) { | 1723 if (rowOrCol == COL) { |
| 1724 _spreadsheet.setColumnWidth(index, size); | 1724 _spreadsheet.setColumnWidth(index, size); |
| 1725 } else { | 1725 } else { |
| 1726 _spreadsheet.setRowHeight(index, size); | 1726 _spreadsheet.setRowHeight(index, size); |
| 1727 } | 1727 } |
| 1728 } | 1728 } |
| 1729 } | 1729 } |
| 1730 } | 1730 } |
| OLD | NEW |