import {ReportItemBaseDesigner} from "../designer/ReportItemBaseDesigner"; import {IServiceProvider} from "../../interfaces/Interfaces"; import {ItemBodyBehaviorBase} from "./ItemBodyBehaviorBase"; import {SelectionService} from "./SelectionService"; import {BehaviorService} from "./BehaviorService"; import {PointF} from "../../drawing/Unit"; import {ItemBodyGlyph} from "./ItemBodyGlyph"; import {ItemSelectionType, SelectionTypes, MouseButtons} from "./Enums"; import {Glyph} from "./Glyph"; import {DesignerUtils} from "../DesignerUtils"; import {ReportItemBase} from "../../items/ReportItemBase"; import {DropSourceBehavior} from "./DropSourceBehavior"; import {MouseStates} from "../../common/MouseStates"; import {KeyStates, Keys} from "../../common/KeyStates"; import EditingGlyph from "../glyph/EditingGlyph"; import ItemEditingBehavior from "./ItemEditingBehavior"; import {DesignerHost} from "../../design/DesignerHost"; import {HitMoveEvent} from "../../common/HitMoveEvent"; export class ItemBodyBehavior extends ItemBodyBehaviorBase { private _behaviorService:BehaviorService; private _selectionService: SelectionService; private _startPos:PointF; private _readyToMove:boolean; constructor(designer:ReportItemBaseDesigner, serviceProvider:IServiceProvider) { super(designer, serviceProvider); this._selectionService = this.getService(SelectionService) as SelectionService; this._behaviorService = this.getService(BehaviorService) as BehaviorService; } onMouseDown(glyph:Glyph, evt:HitMoveEvent, pt:PointF):boolean { this._startPos = PointF.Empty; this._readyToMove = false; if (glyph instanceof ItemBodyGlyph) { if (evt.button === MouseButtons.Left) { if(!evt.moveStep){ this._selectionService.setSelectedItems([glyph.item], SelectionTypes.Primary); } if(this._selectionService.getPrimarySelection() == glyph.item) { this._behaviorService.setPrimaryCursor(pt); } if (glyph.allowMove) { // 按住 Ctrl 键则不允许移动 this._readyToMove = ! KeyStates.isDown(Keys.Ctrl); if (this._readyToMove) { this._behaviorService.pushCaptureBehavior(this); } } } // 记录开始的位置, 在 Move 过程中会依据这个位置计算移动的新位置. this._startPos = new PointF(pt.x, pt.y); } return true; } onMouseMove(glyph:Glyph, evt:HitMoveEvent, pt:PointF):boolean { if (evt.button === MouseButtons.Left) { // isValidDrag 是为了防止抖动误差,在极小的范围内不启动 Drag if (DesignerUtils.isValidDrag(this._startPos, pt)) { if (this._readyToMove) { this.startDrag(); } if(evt.moveStep) { this._behaviorService.adornerWindow.doKeyMove(evt, pt); } } } return false; } onMouseUp(glyph:Glyph):boolean { if (this._readyToMove) { // 将当前行为从 BehaviorService 中移除. this._behaviorService.popBehavior(this); } this._startPos = PointF.Empty; this._readyToMove = false; return false; } onDoubleClick(glyph:Glyph, evt:MouseEvent, pt:PointF):boolean { DesignerHost.instance().uiModel.inspectorModel.showPropertyView(); return false; // this._startPos = PointF.Empty; // this._readyToMove = false; // // if (glyph instanceof ItemBodyGlyph) { // const editingAdorner = this._behaviorService.editingAdorner; // editingAdorner.clear(); // editingAdorner.addGlyph(new EditingGlyph(new ItemEditingBehavior(this._behaviorService.host),glyph)); // const editingLayer = this._behaviorService.adornerWindow.getLayer("editing-layer"); // editingLayer.forceUpdate(); // console.log(editingLayer); // // // /*if (evt.button === MouseButtons.Left) { // this._selectionService.setSelectedItems([glyph.item], SelectionTypes.Primary); // // if (glyph.allowMove) { // // 按住 Ctrl 键则不允许移动 // this._readyToMove = ! KeyStates.isDown(Keys.Ctrl); // // if (this._readyToMove) { // this._behaviorService.pushCaptureBehavior(this); // } // } // }*/ // // // 记录开始的位置, 在 Move 过程中会依据这个位置计算移动的新位置. // // this._startPos = new PointF(pt.x, pt.y); // } // // return true; } private startDrag():void { const dragItems = this.getDraggingItems(); if (dragItems.length > 0) { // 创建处理 Drag 的行为管理者. const dropSourceBehavior = new DropSourceBehavior(this.serviceProvider, dragItems, this._startPos); // 将当前行为从 BehaviorService 中移除. this._behaviorService.popBehavior(this); // 启动 Drag this._behaviorService.doDragDrop(dropSourceBehavior); // 一旦开始 Drag, 则恢复状态,避免在后续的 Mouse Move 中再次启动 Drag. this._startPos = PointF.Empty; this._readyToMove = false; } } /** * 返回即将要 Drag Move 的报表元素集合 * @returns {Array} */ private getDraggingItems(): Array { const list:Array = []; let parent:ReportItemBase = null; const host = DesignerHost.instance(); for (let item of this._selectionService.getSelectedItems()) { const designer = host.getDesigner(item); if (item && item.parent && (parent === null || item.parent === parent) && !designer.locked) { // 只允许属于同一个 Parent 下选择的元素一起进行 Drag Move parent = item.parent; list.push(item); } } return list; } }