teelisb.pas

来自「Delphi TeeChartPro.6.01的源代码」· PAS 代码 · 共 942 行 · 第 1/2 页

PAS
942
字号
end;

Function TChartListBox.SeriesAtMousePos(Var p:TPoint):Integer;
begin
  p:=ScreenToClient(Mouse.CursorPos);
  result:=ItemAtPos(p,True);
end;

Function TChartListBox.PointInSection(Const P:TPoint; ASection:Integer):Boolean;
Var tmpPos : Integer;
begin
  if Sections[ASection].Visible then
  begin
    tmpPos:=SectionLeft(ASection);
    result:=(p.x>tmpPos) and (p.x<tmpPos+Sections[ASection].Width);
  end
  else result:=False;
end;

procedure TChartListBox.FillSeries(OldSeries:TChartSeries);
var tmp : Integer;
Begin
  ClearItems;
  if Assigned(Chart) then FillSeriesItems(Items,Chart);
  if Assigned(FOtherItems) then FOtherItems.Assign(Items);

  tmp:=Items.IndexOfObject(OldSeries);
  if (tmp=-1) and (Items.Count>0) then tmp:=0;

  if (tmp<>-1) and (Items.Count>tmp) then SelectSeries(tmp);

  if Assigned(FOtherItemsChange) then FOtherItemsChange(Self);
  DoRefresh;
end;

Function TChartListBox.AnySelected:Boolean;   { 5.01 }
begin
  if MultiSelect then result:=SelCount>0
                 else result:=ItemIndex<>-1;
end;

procedure TChartListBox.ChangeTypeSeries(Sender: TObject);
var tmpSeries : TChartSeries;
    NewClass  : TChartSeriesClass;
    t         : Integer;
    tmp       : Integer;
    FirstTime : Boolean;
    tmpList   : TChartSeriesList;
begin
  if AnySelected and Assigned(Chart) and Assigned(TeeChangeGalleryProc) then
  begin
    tmpList:=TChartSeriesList.Create;
    try
      { get selected list of series }
      if MultiSelect then { 5.01 }
      begin
         for t:=0 to Items.Count-1 do
             if Selected[t] then tmpList.Add(Series[t])
      end
      else tmpList.Add(Series[ItemIndex]);

      FirstTime:=True;
      NewClass:=nil;

      { change all selected... }
      for t:=0 to tmpList.Count-1 do
      begin
        tmpSeries:=tmpList[t];
        if FirstTime then
        begin
          NewClass:=TeeChangeGalleryProc(Owner,tmpSeries);
          FirstTime:=False;
        end
        else ChangeSeriesType(tmpSeries,NewClass);
        tmpList[t]:=tmpSeries;
      end;

      { reset the selected list... }
      for t:=0 to tmpList.Count-1 do
      begin
        tmp:=Items.IndexOfObject(tmpList[t]);
        if tmp<>-1 then SelectSeries(tmp);
      end;
    finally
      tmpList.Free;
    end;
    { refill and repaint list }
    DoRefresh;
    { tell the series designer we have changed... }
    RefreshDesigner;
  end;
end;

procedure TChartListBox.DblClick;

  Function IsSelected(tmp:Integer):Boolean;  { 5.01 }
  begin
    if MultiSelect then result:=Selected[tmp]
                   else result:=ItemIndex=tmp;
  end;

var p        : TPoint;
    tmp      : Integer;
    tmpColor : TColor;
begin
  ComingFromDoubleClick:=True;

  { find series at mouse position "p" }
  tmp:=SeriesAtMousePos(p);
  if (tmp<>-1) and IsSelected(tmp) then
  begin
    if PointInSection(p,0) and FEnableChangeType then ChangeTypeSeries(Self)
    else
    if PointInSection(p,2) and FEnableChangeColor then
    begin
      if TSeriesAccess(Series[tmp]).IUseSeriesColor then
      With Series[tmp] do
      begin
        tmpColor:=SeriesColor;
        if EditColorDialog(Self,tmpColor) then
        begin
          SeriesColor:=tmpColor;
          ColorEachPoint:=False;
          if Assigned(FOnChangeColor) then
             FOnChangeColor(Self,Series[tmp]);
        end;
      end;
    end
    else
    if PointInSection(p,3) then
       if Assigned(FOnEditSeries) then FOnEditSeries(Self,tmp);
  end;
end;

procedure TChartListBox.MouseDown(Button: TMouseButton; Shift: TShiftState;
                                  X, Y: Integer);
var tmp : Integer;
    p   : TPoint;
begin
  if ItemIndex<>-1 then
  begin
    tmp:=SeriesAtMousePos(p);
    if (tmp<>-1) and (PointInSection(p,1)) then
    begin
      with Series[tmp] do Active:=not Active;
      if not Assigned(Series[tmp].ParentChart) then Self.Repaint;
    end
    else
    if FEnableDragSeries and
       PointInSection(p,3) and (not ComingFromDoubleClick) and
       (not (ssShift in Shift)) and
       (not (ssCtrl in Shift)) and
       ( ( ssLeft in Shift) ) then
            BeginDrag(False);
    ComingFromDoubleClick:=False;
    if Assigned(FOtherItemsChange) then FOtherItemsChange(Self);
  end;
end;

Procedure TChartListBox.MoveCurrentUp;
begin
  if ItemIndex>0 then SwapSeries(ItemIndex,ItemIndex-1);
end;

Procedure TChartListBox.MoveCurrentDown;
begin
  if (ItemIndex<>-1) and (ItemIndex<Items.Count-1) then
     SwapSeries(ItemIndex,ItemIndex+1);
end;

{ Delete the current selected Series, if any. Returns True if deleted }
Function TChartListBox.DeleteSeries:Boolean;

  Procedure DoDelete;
  Var t : Integer;
  begin
    if MultiSelect then { 5.01 }
    begin
      t:=0;
      While t<Items.Count do
      if Selected[t] then Series[t].Free
                     else Inc(t);
    end
    else
    if ItemIndex<>-1 then Series[ItemIndex].Free;

    if Items.Count>0 then SelectSeries(0);

    DoRefresh;
    RefreshDesigner;
  end;

var tmpSt : String;
begin
  result:=False;
  if AnySelected then { 5.01 }
    if FAskDelete then
    begin
      if (not MultiSelect) or (SelCount=1) then  { 5.01 }
         tmpSt:=SeriesTitleOrName(SelectedSeries)
      else
         tmpSt:=TeeMsg_SelectedSeries;

      if TeeYesNoDelete(tmpSt,Self) then
      begin
        DoDelete;
        result:=True;
      end;
    end
    else
    begin
      DoDelete;
      result:=True;
    end;
end;

Procedure TChartListBox.CloneSeries;
begin { duplicate current selected series }
  if ItemIndex<>-1 then
  begin
    CloneChartSeries(SelectedSeries);
    RefreshDesigner;
  end;
end;

procedure TChartListBox.KeyUp(var Key: Word; Shift: TShiftState);
begin
  Case Key of
    {$IFDEF CLX}
    Key_Insert
    {$ELSE}
    VK_INSERT
    {$ENDIF}:  if FAllowAdd then AddSeriesGallery;

    {$IFDEF CLX}
    Key_Delete
    {$ELSE}
    VK_DELETE
    {$ENDIF}:  if FAllowDelete then DeleteSeries;
  end;
end;

Function TChartListBox.RenameSeries:Boolean; { 5.02 }
var tmp       : Integer;
    tmpSeries : TChartSeries;
    tmpSt     : String;
    Old       : String;
begin
  result:=False;
  tmp:=ItemIndex;
  if tmp<>-1 then
  begin
    tmpSeries:=SelectedSeries;
    tmpSt:=SeriesTitleOrName(tmpSeries);
    Old:=tmpSt;
    if InputQuery(TeeMsg_ChangeSeriesTitle,
                  TeeMsg_NewSeriesTitle,tmpSt) then
    begin
      if tmpSt<>'' then
         if tmpSt=tmpSeries.Name then tmpSeries.Title:=''
                                 else tmpSeries.Title:=tmpSt;
      { return True if the title has been changed }
      result:=Old<>SeriesTitleOrName(tmpSeries);
    end;
    SelectSeries(tmp);
  end;
end;

Procedure TChartListBox.RefreshDesigner;
begin
  if Assigned(Chart) and Assigned(Chart.Designer) then Chart.Designer.Refresh;
end;

Function TChartListBox.AddSeriesGallery:TChartSeries;
var t : Integer;
begin
  if Assigned(TeeAddGalleryProc) then
  begin
    result:=TeeAddGalleryProc(Owner,Chart,SelectedSeries);
    if Assigned(result) then
    begin
      if MultiSelect then // 5.01
         for t:=0 to Items.Count-1 do Selected[t]:=False;

      SelectSeries(Items.IndexOfObject(result));

      DoRefresh;
      RefreshDesigner;
    end;
  end
  else result:=nil;
end;

procedure TChartListBox.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
  inherited;
  if (Operation=opRemove) and Assigned(Chart) and (AComponent=Chart) then
     Chart:=nil;
end;

{$IFNDEF CLX}
procedure TChartListBox.WMNCHitTest(var Msg: TWMNCHitTest);
begin
  inherited;
  FHitTest:=SmallPointToPoint(Msg.Pos);
end;

procedure TChartListBox.WMSetCursor(var Msg: TWMSetCursor);
var I: Integer;
begin
  if csDesigning in ComponentState then Exit;

  if (Items.Count>0) and (SeriesAtMousePos(FHitTest)<>-1) and
     (Msg.HitTest=HTCLIENT) then

     for I:=0 to 2 do  { don't count last section }
     begin
       if PointInSection(FHitTest,I) then
       begin
         if ((I=0) and FEnableChangeType) or
            ((I=2) and FEnableChangeColor) then
         begin
           SetCursor(Screen.Cursors[crHandPoint]);
           Exit;
         end
         else break;
       end;
     end;
  inherited;
end;

{$ELSE}

procedure TChartListBox.MouseMove(Shift: TShiftState; X, Y: Integer);
var I : Integer;
    P : TPoint;
begin
  if csDesigning in ComponentState then Exit;

  P:=TeePoint(X,Y);
  if (Items.Count>0) and (SeriesAtMousePos(P)<>-1) then

     for I:=0 to 2 do  { don't count last section }
     begin
       if PointInSection(P,I) then
       begin
         if ((I=0) and FEnableChangeType) or
            ((I=2) and FEnableChangeColor) then
         begin
           Cursor:=crHandPoint;
           Exit;
         end
         else break;
       end;
     end;
  Cursor:=crDefault;
end;
{$ENDIF}

procedure TChartListBox.UpdateSeries;
begin
  FillSeries(SelectedSeries);
end;

Function TChartListBox.GetShowActive:Boolean;
begin
  result:=Sections[1].Visible;
end;

procedure TChartListBox.SetShowActive(Value:Boolean);
begin
  Sections[1].Visible:=Value; Repaint;
end;

Function TChartListBox.GetShowIcon:Boolean;
begin
  result:=Sections[0].Visible;
end;

procedure TChartListBox.SetShowIcon(Value:Boolean);
begin
  Sections[0].Visible:=Value; Repaint;
end;

Function TChartListBox.GetShowColor:Boolean;
begin
  result:=Sections[2].Visible;
end;

procedure TChartListBox.SetShowColor(Value:Boolean);
begin
  Sections[2].Visible:=Value; Repaint;
end;

Function TChartListBox.GetShowTitle:Boolean;
begin
  result:=Sections[3].Visible;
end;

procedure TChartListBox.SetShowTitle(Value:Boolean);
begin
  Sections[3].Visible:=Value; Repaint;
end;

procedure TChartListBox.SelectAll;
{$IFNDEF D6}
var t : Integer;
{$ENDIF}
begin
  if MultiSelect then { 5.01 }
  begin
    {$IFDEF D6}
    inherited;
    {$ELSE}
    for t:=0 to Items.Count-1 do Selected[t]:=True;
    {$ENDIF}
    RefreshDesigner;
  end;
end;

Function TChartListBox.GetSeries(Index:Integer):TChartSeries;
begin
  if (Index<>-1) and (Index<Items.Count) then
     result:=TChartSeries(Items.Objects[Index])
  else
     result:=nil;
end;

procedure TChartListBox.TeeEvent(Event:TTeeEvent);
var tmp : Integer;
begin
  if not (csDestroying in ComponentState) then
  if Event is TTeeSeriesEvent then
  With TTeeSeriesEvent(Event) do
  Case Event of
    seChangeColor,
    seChangeActive: Invalidate;
    seChangeTitle: begin
                tmp:=Items.IndexOfObject(Series);
                if tmp<>-1 then Items[tmp]:=SeriesTitleOrName(Series);
              end;
    seRemove: begin
                tmp:=Items.IndexOfObject(Series);
                if tmp<>-1 then
                begin
                  Items.Delete(tmp);
                  if Assigned(FOtherItems) then FOtherItems.Delete(tmp);
                  if Assigned(FOnRemovedSeries) then
                     FOnRemovedSeries(Self,Series); { 5.02 }
                end;
              end;
      seAdd,
      seSwap: UpdateSeries;
  end;
end;

{$IFNDEF D6}
Procedure TChartListBox.ClearSelection;
var t: Integer;
begin
  if MultiSelect then
     for t:=0 to Items.Count-1 do Selected[t]:=False
  else
     ItemIndex:=-1;
end;
{$ENDIF}

end.

⌨️ 快捷键说明

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