⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teeselectortool.pas

📁 BCB第三方组件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      if IDragged or (Abs(FShape.Top-(Y+IDif.Y))>2) then
      begin
        Old:=FShape.Height;
        FShape.Top:=Y+IDif.Y;
        FShape.Height:=Old;

        IDragged:=True;
      end;
    end;

    { call OnDragging event }
    if Assigned(FOnDragging) then
       FOnDragging(Self);
  end;

  procedure GuessClick;
  begin
    IResizingChart:=False;

    EmptySelection;

    { check if mouse XY is over an annotation }
    FAnnotation:=CalcClickedAnnotation;
    if Assigned(FAnnotation) then
       FShape:=FAnnotation.Shape;

    if not Assigned(FShape) then
    begin
      { calc clicked chart part }
      TCustomChart(ParentChart).CalcClickedPart(TeePoint(X,Y),Part);

      { if clicked part is a legend or a title ... }
      if Part.Part=cpLegend then
         FShape:=TCustomChart(ParentChart).Legend
      else
      if Part.Part=cpTitle then
         FShape:=TCustomChart(ParentChart).Title
      else
      if Part.Part=cpSubTitle then
         FShape:=TCustomChart(ParentChart).SubTitle
      else
      if Part.Part=cpFoot then
         FShape:=TCustomChart(ParentChart).Foot
      else
      if Part.Part=cpSubFoot then
         FShape:=TCustomChart(ParentChart).SubFoot
      else
      if Part.Part=cpChartRect then
         { select back wall }
         FWall:=TCustomChart(ParentChart).BackWall;
    end;

    { call OnSelected event }
    DoSelected;

    // ParentChart.CancelMouse:=True; <-- check Legend checkboxes !

    { start dragging if selection is a Shape or Annotation }
    IDragging:=AllowDrag and Assigned(FShape);

    if IDragging then
    begin
      IDif.X:=FShape.Left-X;
      IDif.Y:=FShape.Top-Y;
      IDragged:=False;
      ParentChart.CancelMouse:=True;
    end;
  end;

begin
  inherited;

  if not (ssDouble in Shift) then
  Case AEvent of
    cmeDown: if Button=mbLeft then
             begin
               { check if XY is over the right-bottom corner }
               if AllowResizeChart and ClickedCorner(X,Y) then
               begin
                 IResizingChart:=True;
                 IResized:=False;
               end
               else
                 GuessClick;
             end;

    cmeMove: if IDragging and Assigned(FShape) then
                DoDragShape
             else
             if IResizingChart then
             begin
               with ParentChart do
               begin
                 if Align<>alNone then Align:=alNone;
                 if Width<>X then Width:=X;
                 if Height<>Y then Height:=Y;
               end;

               IResized:=True;

               { call OnResizing event }
               if Assigned(FOnResizing) then
                  FOnResizing(Self);
             end
             else
             if Cursor<>crDefault then
                GuessCursor;

      cmeUp: begin
               { finish dragging / resizing }
               if IDragged and Assigned(FOnDragged) then
                  FOnDragged(Self);

               if IResized and Assigned(FOnResized) then
                  FOnResized(Self);

               StopDragging;
             end;
  end;
end;

Procedure TSelectorTool.DoSelected;
begin
  if not (csDestroying in ComponentState) then
  begin
    Repaint;

    if Assigned(OnSelected) then
       OnSelected(Self);
  end;
end;

class function TSelectorTool.Description: String;
begin
  result:=TeeMsg_SelectorTool;
end;

class function TSelectorTool.GetEditorClass: String;
begin
  result:='TSelectorToolEditor';
end;

procedure TSelectorTool.SetHandleSize(const Value: Integer);
begin
  if FHandleSize<>Value then
  begin
    FHandleSize:=Value;
    Repaint;
  end;
end;

procedure TSelectorTool.SetAnnotation(const Value: TAnnotationTool);
begin
  if (Part.Part<>cpNone) or (FAnnotation<>Value) then
  begin
    EmptySelection;

    FAnnotation:=Value;

    if Assigned(FAnnotation) then
       FShape:=FAnnotation.Shape
    else
       FShape:=nil;

    Part.Part:=cpNone;
    DoSelected;
  end;
end;

function TSelectorTool.SelectedTitle: TChartTitle;
begin
  with TCustomChart(ParentChart) do
  Case Part.Part of
    cpTitle    : result:=Title;
    cpFoot     : result:=Foot;
    cpSubTitle : result:=SubTitle;
    cpSubFoot  : result:=SubFoot;
  else
    result:=nil;
  end;
end;

Procedure TSelectorTool.ClearSelection;
begin { remove selection }
  if (Part.Part<>cpNone) or
     (Assigned(FAnnotation) or Assigned(FShape) or Assigned(FWall)) then
  begin
    EmptySelection;
    DoSelected;
  end;
end;

Procedure TSelectorTool.EmptySelection;
begin
  Part.Part:=cpNone;
  Part.ASeries:=nil;
  Part.AAxis:=nil;
  FAnnotation:=nil;
  FShape:=nil;
  FWall:=nil;
end;

procedure TSelectorTool.StopDragging;
begin
  IDragging:=False;
  IDragged:=False;
  IResizingChart:=False;
  IResized:=False;
end;

procedure TSelectorTool.SetWall(const Value: TChartWall);
begin
  if (Part.Part<>cpNone) or (FWall<>Value) then
  begin
    EmptySelection;
    Part.Part:=cpNone;
    FWall:=Value;

    if Assigned(FWall) and (FWall=TCustomChart(ParentChart).BackWall) then
       Part.Part:=cpChartRect;

    DoSelected;
  end;
end;

function TSelectorTool.GetSeries: TChartSeries;
begin
  result:=Part.ASeries;
end;

{$IFNDEF CLR}
type
  TTeePanelAccess=class(TCustomAxisPanel);
{$ENDIF}

Procedure TSelectorTool.SetParentChart(Const Value:TCustomAxisPanel);
var tmpOk : Boolean;
begin
  tmpOk:=ParentChart<>Value;

  if tmpOk and Assigned(ParentChart) then
     if (not (csDestroying in ParentChart.ComponentState)) then
        {$IFNDEF CLR}TTeePanelAccess{$ENDIF}(ParentChart).RemoveListener(Self);

  inherited;

  if tmpOk and Assigned(ParentChart) then
     if (not (csDestroying in ParentChart.ComponentState)) then
        {$IFNDEF CLR}TTeePanelAccess{$ENDIF}(ParentChart).Listeners.Add(Self);
end;

procedure TSelectorTool.SetSeries(const Value: TChartSeries);
begin
  if (Part.Part<>cpSeries) or (Part.ASeries<>Value) then
  begin
    {$IFDEF D5}
    if Assigned(Part.ASeries) then
       Part.ASeries.RemoveFreeNotification(Self);
    {$ENDIF}

    EmptySelection;

    { select Series }
    Part.Part:=cpSeries;
    Part.ASeries:=Value;

    if Assigned(Part.ASeries) then
    begin
      Part.ASeries.FreeNotification(Self);
      ParentChart:=Part.ASeries.ParentChart;
    end;

    Part.PointIndex:=-1;
    DoSelected;
  end;
end;

function TSelectorTool.GetSelection: TPersistent;
begin
  result:=nil;

  if Assigned(Annotation) then
     result:=Annotation
  else
  case Part.Part of
    cpNone        : result:=ParentChart;
    cpChartRect   : result:=Wall;

    cpTitle,
    cpFoot,
    cpSubTitle,
    cpSubFoot,
    cpLegend      : result:=DraggingShape;

    cpAxis        : result:=Part.AAxis;
    cpSeries      : result:=Part.ASeries;
    cpSeriesMarks : result:=Part.ASeries.Marks;
    cpAxisTitle   : result:=Part.AAxis.Title;
  end;
end;

{ SelectorToolEditor }
procedure TSelectorToolEditor.FormShow(Sender: TObject);
begin
  Selector:=TSelectorTool(Tag);

  if Assigned(Selector) then
  with Selector do
  begin
    ButtonPen1.LinkPen(Pen);
    ButtonColor1.LinkProperty(Brush,'Color');
    UDSize.Position:=HandleSize;
    CBAllowDrag.Checked:=AllowDrag;
    CBResizeChart.Checked:=AllowResizeChart;

    TeeFillCursors(CBCursor,Cursor);
  end;
end;

procedure TSelectorToolEditor.Edit1Change(Sender: TObject);
begin
  if Showing and Assigned(Selector) then
     Selector.HandleSize:=UDSize.Position;
end;

procedure TSelectorToolEditor.CBAllowDragClick(Sender: TObject);
begin
  Selector.AllowDrag:=CBAllowDrag.Checked;
end;

procedure TSelectorToolEditor.CBResizeChartClick(Sender: TObject);
begin
  Selector.AllowResizeChart:=CBResizeChart.Checked;
end;

procedure TSelectorToolEditor.CBCursorChange(Sender: TObject);
begin
  with Selector do
       Cursor:=TeeSetCursor(Cursor,CBCursor.CurrentItem);
end;

class function TSelectorTool.LongDescription: String;
begin
  result:=TeeMsg_SelectorDesc;
end;

Destructor TSelectorTool.Destroy;
begin
  Series:=nil;
  inherited;
end;

procedure TSelectorTool.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;

  if (Operation=opRemove) and (AComponent=Part.ASeries) then
     Series:=nil;
end;

procedure TSelectorTool.TeeEvent(Event: TTeeEvent); // 8.01
begin
  if not (csDestroying in ComponentState) then
     if Series<>nil then
        if Event is TTeeSeriesEvent then
           if TTeeSeriesEvent(Event).Event=seChangeActive then
              if TTeeSeriesEvent(Event).Series=Series then
                 ClearSelection;
end;

initialization
  RegisterClass(TSelectorToolEditor);
  RegisterTeeTools([TSelectorTool]);
finalization
  UnRegisterTeeTools([TSelectorTool]);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -