cxsplitter.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,764 行 · 第 1/5 页

PAS
1,764
字号
  begin
    FArrowHighlightColor := Value;
    Changed;
  end;
end;

procedure TcxSimpleStyle.SetDotsColor(Value: TColor);
begin
  if FDotsColor <> Value then
  begin
    FDotsColor := Value;
    Changed;
  end;
end;

procedure TcxSimpleStyle.SetDotsShadowColor(Value: TColor);
begin
  if FDotsShadowColor <> Value then
  begin
    FDotsShadowColor := Value;
    Changed;
  end;
end;

function TcxSimpleStyle.DrawHotZone(ACanvas: TcxCanvas; const ARect: TRect;
  const AHighlighted, AClicked: Boolean): TRect;
begin
  Result := CalculateHotZoneRect(ARect);
  ACanvas.Canvas.Lock;
  try
    ACanvas.Canvas.Brush.Color := Owner.Color;
    DrawBackground(ACanvas, HotZoneRect, AHighlighted, AClicked);
    DrawHotZoneArrow(ACanvas, FLTArrowRect, AHighlighted, AClicked, FArrowColor,
      FArrowHighlightColor, SplitterDirection);
    DrawHotZoneArrow(ACanvas, FRBArrowRect, AHighlighted, AClicked, FArrowColor,
      FArrowHighlightColor, SplitterDirection);
  finally
    ACanvas.Canvas.Unlock;
  end;
end;

function TcxSimpleStyle.CalculateHotZoneRect(const ABounds: TRect): TRect;
begin
  Result := inherited CalculateHotZoneRect(ABounds);
  case SplitterDirection of
    cxsdLeftToRight, cxsdRightToLeft:
    begin
      FLTArrowRect := Rect(Result.Left, Result.Top + 5, Result.Right, Result.Top + 12);
      FRBArrowRect := Rect(Result.Left, Result.Bottom - 12, Result.Right, Result.Bottom - 5);
    end;
    else
    begin
      FLTArrowRect := Rect(Result.Left + 5, Result.Top, Result.Left + 12, Result.Bottom);
      FRBArrowRect := Rect(Result.Right - 12, Result.Top, Result.Right - 5, Result.Bottom);
    end;
  end;
  HotZoneRect := Result;
end;

procedure TcxSimpleStyle.DrawBackground(ACanvas: TcxCanvas; const ARect: TRect;
  const AHighlighted, AClicked: Boolean);
var
  MiddlePos, I_count : Integer;
  FRect: TRect;
begin
  with ACanvas, ARect do
  begin
    FRect := DrawBounds(ACanvas, HotZoneRect, ShadowColor, ShadowColor);
    Brush.Color := Owner.Color;
    FillRect(FRect);
    {Draw Border}
    if AClicked = False then
      DrawBounds(ACanvas, FRect, LightColor, Owner.Color)
    else
      DrawBounds(ACanvas, FRect, Owner.Color, LightColor);

    Pen.Color := clHighlight;
    Brush.Color := clHighlight;
    if (SplitterDirection = cxsdTopToBottom) or (SplitterDirection = cxsdBottomToTop) then
    begin
      MiddlePos:=Top + (Bottom - Top) div 2;
      for I_count := 0 to ((Right - Left - 32) div 3) do
      begin
        if AClicked = False then
        begin
          Pixels[Left + 15 + I_count * 3, MiddlePos] := DotsShadowColor;
          Pixels[Left + 16 + I_count * 3, MiddlePos + 1] := DotsColor;
        end
        else
        begin
          Pixels[Left + 15 + I_count * 3, MiddlePos] := DotsColor;
          Pixels[Left + 16 + I_count * 3, MiddlePos + 1] := DotsShadowColor;
        end;
      end;
    end
    else
    begin
      MiddlePos := Left + (Right - Left) div 2;
      for I_count := 0 to ((Bottom - Top - 32) div 3) do
      begin
        if AClicked = False then
        begin
          Pixels[MiddlePos, Top + 15 + I_count * 3] := DotsShadowColor;
          Pixels[MiddlePos + 1, Top + 16 + I_count * 3] := DotsColor;
        end
        else
        begin
          Pixels[MiddlePos, Top + 15 + I_count * 3] := DotsColor;
          Pixels[MiddlePos + 1, Top + 16 + I_count * 3] := DotsShadowColor;
        end;
      end;
    end;
  end;
end;
{ TcxSimpleStyle }

{TdxSplitterDragImage}

procedure TdxSplitterDragImage.Paint;
begin
  Canvas.Canvas.FillRect(ClientRect);
end;

{ TcxCustomSplitter }
constructor TcxCustomSplitter.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle - [csSetCaption];
  FState := ssOpened;
  FResizeUpdate := False;
  FSplitterState := sstNormal;
  FMouseStates := [];
  FAllowHotZoneDrag := True;
  FDragThreshold := 3;
  FAutoSnap := False;
  FResizeIgnoreSnap := False; //deprecated
  FAutoPosition := True;
  FMinSize := 30;
  FPositionAfterOpen := 30;
  FNativeBackground := True;
  FInvertDirection := False;
  FNewSize := 30;
  FOldSize := -1;
  FPositionBeforeClose := FMinSize;
  FHotZone := nil;
  FHotZoneClickPoint := Point(-1, -1);
  FLastPatternDrawPosition := -1;
  FDrawBitmap := TBitmap.Create;
  FDrawCanvas := TcxCanvas.Create(FDrawBitmap.Canvas);
  BorderStyle := cxcbsNone;
  Align := alNone;
  SetBounds(0, 0, SplitterDefaultSize, 100 {must be >= 10});
  SetAlignSplitter(salLeft);
  TabStop := False;
end;

destructor TcxCustomSplitter.Destroy;
begin
  FControl := nil;
  DestroyHotZone;
  if Assigned(FBrush) then FreeAndNil(FBrush);
  if Assigned(FDrawCanvas) then FreeAndNil(FDrawCanvas);
  if Assigned(FDrawBitmap) then FreeAndNil(FDrawBitmap);
  inherited Destroy;
end;

procedure TcxCustomSplitter.Loaded;
begin
  inherited Loaded;
  if FControl = nil then
    FControl := FindControl;
  SetAlignSplitter(FAlignSplitter);
end;

procedure TcxCustomSplitter.Notification(AComponent: TComponent; Operation: Toperation);
begin
  inherited Notification(AComponent, Operation);
  if (Operation = opRemove) and (FControl <> nil) and
    (AComponent = FControl) then
    FControl := nil;
end;

procedure TcxCustomSplitter.SetHotZoneStyleClass(const Value: TcxHotZoneStyleClass);
var
  ASavedHotZone: TcxHotZoneStyle;
begin
  if FHotZoneStyleClass <> Value then
  begin
    ASavedHotZone := nil;
    try
      if Assigned(FHotZone) then
      begin
        ASavedHotZone := TcxHotZoneStyle.Create(Self);
        ASavedHotZone.Assign(FHotZone);
      end;
      DestroyHotZone;
      FHotZoneStyleClass := Value;
      CreateHotZone;
      if Assigned(FHotZone) and Assigned(ASavedHotZone) then
        FHotZone.Assign(ASavedHotZone);
    finally
      if Assigned(ASavedHotZone) then
        FreeAndNil(ASavedHotZone);
    end;
    NormalizeSplitterSize;
  end;
end;

function TcxCustomSplitter.GetHotZoneClassName: string;
begin
  if FHotZone = nil then
    Result := ''
  else
    Result := FHotZone.ClassName;
end;

procedure TcxCustomSplitter.SetHotZoneClassName(Value: string);
begin
  HotZoneStyleClass := TcxHotZoneStyleClass(GetRegisteredHotZoneStyles.FindByClassName(Value));
end;

procedure TcxCustomSplitter.CreateHotZone;
begin
  if FHotZoneStyleClass <> nil then
    FHotZone := FHotZoneStyleClass.Create(Self);
  Invalidate;
end;

procedure TcxCustomSplitter.DestroyHotZone;
begin
  if Assigned(FHotZone) then FreeAndNil(FHotZone);
end;

procedure TcxCustomSplitter.SetHotZone(Value: TcxHotZoneStyle);
begin
  FHotZone := Value;
  NormalizeSplitterSize;
  Invalidate;
end;

procedure TcxCustomSplitter.SetNativeBackground(Value: Boolean);
begin
  if FNativeBackground <> Value then
  begin
    FNativeBackground := Value;
    Invalidate;
  end;
end;

procedure TcxCustomSplitter.SetDefaultStates;
begin
  FMouseStates := [];
  FSplitterState := sstNormal;
end;

function TcxCustomSplitter.GetMaxControlSize: Integer;
begin
  Result := 0;
  if FControl = nil then
    Exit;
  case AlignSplitter of
    salBottom, salTop:
      Result := FControl.Constraints.MaxHeight;
    salLeft, salRight:
      Result := FControl.Constraints.MaxWidth;
  end;
end;

function TcxCustomSplitter.IsAllControlHotZoneStyle: Boolean;
begin
  Result := LookAndFeel.SkinPainter <> nil;
end;

function TcxCustomSplitter.GetDragImageTopLeft: TPoint;
begin
  Result := Point(Left, Top);
  if Align in [alLeft, alRight] then
    Result.X := Left + FSplit + 1
  else
    Result.Y := Top + FSplit + 1;
  Result := Parent.ClientToScreen(Result);
end;

procedure TcxCustomSplitter.InitDragImage;
begin
  if not ResizeUpdate then
  begin
    FDragImage := TdxSplitterDragImage.Create;
    FDragImage.Canvas.Brush.Bitmap := AllocPatternBitmap(clBlack, clWhite);
    FDragImage.SetBounds(GetDragImageTopLeft.X, GetDragImageTopLeft.Y,
      Width - 1, Height - 1);
    FDragImage.Show;
  end;
end;

procedure TcxCustomSplitter.MoveDragImage;
begin
  FDragImage.MoveTo(GetDragImageTopLeft);
end;

procedure TcxCustomSplitter.ReleaseDragImage;
begin
  FreeAndNil(FDragImage);
end;

procedure TcxCustomSplitter.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  if smsInHotZone in FMouseStates then
    Invalidate;
  Exclude(FMouseStates, smsInHotZone);
end;

procedure TcxCustomSplitter.SetAlignSplitter(Value: TcxSplitterAlign);
begin
  FAlignSplitter := Value;
  if Assigned(FHotZone) then
    NormalizeSplitterSize;
  case FAlignSplitter of
    salBottom: Align := alBottom;
    salLeft: Align := alLeft;
    salRight: Align := alRight;
    salTop: Align := alTop;
  end;
end;

function TcxCustomSplitter.GetSplitterMinSize: TcxNaturalNumber;
var
  AHorizontal: Boolean;
begin
  if LookAndFeel.SkinPainter <> nil then
  begin
    AHorizontal := AlignSplitter in [salBottom, salTop];
    if AHorizontal then
      Result := LookAndFeel.SkinPainter.GetSplitterSize(AHorizontal).cy
    else
      Result := LookAndFeel.SkinPainter.GetSplitterSize(AHorizontal).cx;
  end
  else
    if Assigned(FHotZone) then
      Result := FHotZone.GetMinSize
    else
      Result := SplitterDefaultSize;
end;

function TcxCustomSplitter.GetSplitterMaxSize: TcxNaturalNumber;
var
  AHorizontal: Boolean;
begin
  if LookAndFeel.SkinPainter <> nil then
  begin
    AHorizontal := AlignSplitter in 

⌨️ 快捷键说明

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