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

📄 jvofficecolorpanel.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  TempHeight: Integer;
  LButtonCount, LColorsButtonTop, LColorsButtonLeft: Integer;
begin
  if (not FInited) or (Parent = nil) then
    Exit;
  DisableAlign;
  TempHeight := 0;
  LButtonCount := 0;
  ButtonLine := (MaxColorButtonNumber + LineColorButtonCount - 1) div LineColorButtonCount;

  if Properties.ShowAutoButton then
    Inc(LButtonCount);
  if Properties.ShowOtherButton then
    Inc(LButtonCount);

  with Properties do
  begin
    Width := HorizontalMargin * 2 + ColorSize * LineColorButtonCount +
      ColorSpace * (LineColorButtonCount - 1);
    Height := TopMargin + BottomMargin + ColorSpaceTop + ColorSpaceBottom + ColorSize * ButtonLine +
      ColorSpace * (ButtonLine - 1) + ButtonHeight * LButtonCount + TempHeight;
  end;

  with Properties do
    if not Properties.ShowAutoButton then
    begin
      FAutoButton.Visible := False;
      LColorsButtonTop := 0;
      LColorsButtonLeft := HorizontalMargin;
    end
    else
    begin
      FAutoButton.Visible := True;
      FAutoButton.Caption := AutoCaption;
      LColorsButtonTop := FAutoButton.Top + FAutoButton.Height;
      FAutoButton.SetBounds(HorizontalMargin, TopMargin + TempHeight,
        ClientWidth - HorizontalMargin * 2, ButtonHeight);
      LColorsButtonLeft := FAutoButton.Left;
    end;

  with Properties do
    for I := 0 to MaxColorButtonNumber - 1 do
      FColorButtons[I].SetBounds(LColorsButtonLeft + (I mod LineColorButtonCount) * (ColorSpace + ColorSize),
        LColorsButtonTop + ColorSpaceTop + (I div LineColorButtonCount) * (ColorSpace + ColorSize),
        ColorSize, ColorSize);

  with Properties do
    if not Properties.ShowOtherButton then
      FOtherButton.Visible := False
    else
    begin
      FOtherButton.Visible := True;
      FOtherButton.Caption := OtherCaption;
      FOtherButton.SetBounds(FAutoButton.Left,
        FColorButtons[MaxColorButtonNumber - 1].Top + ColorSize + ColorSpaceBottom,
        FAutoButton.Width, ButtonHeight);
    end;
end;

procedure TJvCustomOfficeColorPanel.ColorButtonClick(Sender: TObject);
{$IFDEF VisualCLX}
var
  I: Integer;
{$ENDIF VisualCLX}
begin
  if Sender is TJvColorSpeedButton then
  begin
    if TComponent(Sender).Tag = FAutoButton.Tag then
       FClickColorButton := cbctAutoButton
    else
    if TComponent(Sender).Tag = FOtherButton.Tag then
       FClickColorButton := cbctOtherButton
    else
      FClickColorButton := cbctColorsButton;
  end
  else
    FClickColorButton := cbctNone;

  if Assigned(FOnColorButtonClick) then
     FOnColorButtonClick(Sender);

  if TComponent(Sender).Tag = FOtherButton.Tag then
  begin
    {$IFDEF VCL}
    FColorDialog.Options := FColorDialogOptions;
    {$ENDIF VCL}
    FColorDialog.Color := FSelectedColor;
    if FColorDialog.Execute then
    begin
      SetSelectedColor(FColorDialog.Color);
      FOtherButton.ButtonColor := FSelectedColor;
      FOtherButton.Hint := ColorToString(FOtherButton.ButtonColor);
    end
    else
      Exit;
  end
  else
  begin
    TJvSubColorButton(Sender).Down := True;
    {$IFDEF VisualCLX}
    //in clx have bug
    FAutoButton.Down := FAutoButton = Sender;
    FOtherButton.Down := FOtherButton = Sender;
    for I := 0 to MaxColorButtonNumber - 1 do
      FColorButtons[I].Down := FColorButtons[I] = Sender;
    {$ENDIF VisualCLX}
    SetSelectedColor(TJvSubColorButton(Sender).ButtonColor);
  end;
end;

procedure TJvCustomOfficeColorPanel.SetWordStyle(const Value: Boolean);
begin
  if FWordStyle <> Value then
  begin
    FWordStyle := Value;
    with Properties do
      if FWordStyle then
      begin
        SetFlat(True);

        ButtonHeight := MinButtonHeight;
        ColorSize := MinColorSize;
        ColorSpace := MinColorSpace;
        ColorSpaceTop := MinColorSpaceTop;
        ColorSpaceBottom := MinColorSpaceBottom;
        TopMargin := MinTopMargin;
        BottomMargin := MinBottomMargin;
        HorizontalMargin := MinHorizontalMargin;
      end;
  end;
end;

procedure TJvCustomOfficeColorPanel.SetFlat(const Value: Boolean);
begin
  if FFlat <> Value then
  begin
    FFlat := Value;
    Invalidate;
  end;
end;

procedure TJvCustomOfficeColorPanel.SetSelectedColor(const Value: TColor);
var
  I: Integer;
begin
  if FSelectedColor <> Value then
  begin
    FSelectedColor := Value;
    Color := Value;
    if FAutoButton.ButtonColor = Value then
      FAutoButton.Down := True
    else
    begin
      FAutoButton.Down := False;
      for I := 0 to MaxColorButtonNumber - 1 do
        if FColorButtons[I].ButtonColor = Value then
        begin
          FColorButtons[I].Down := True;
          Break;
        end
        else
          FColorButtons[I].Down := False;
    end;

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

function TJvCustomOfficeColorPanel.GetCustomColors: TStrings;
begin
  Result := FColorDialog.CustomColors;
end;

procedure TJvCustomOfficeColorPanel.SetCustomColors(const Value: TStrings);
begin
  FColorDialog.CustomColors.Assign(Value);
end;

procedure TJvCustomOfficeColorPanel.Resize;
begin
  inherited Resize;
  if FInited then
    AdjustColorButtons;
end;

procedure TJvCustomOfficeColorPanel.Paint;
begin
  inherited Paint;
  if FFlat then
  begin
    Canvas.Brush.Color := clBtnFace;
    {$IFDEF VCL}
    Canvas.FrameRect(ClientRect);
    {$ENDIF VCL}
    {$IFDEF VisualCLX}
    FrameRect(Canvas, ClientRect);
    {$ENDIF VisualCLX}
    Canvas.Brush.Color := Color;
  end;
  if FInited then
    AdjustColorButtons;
end;

procedure TJvCustomOfficeColorPanel.SetEnabled({$IFDEF VisualCLX} const {$ENDIF} Value: Boolean);
var
  I: Integer;
begin
  inherited SetEnabled(Value);
  FAutoButton.Enabled := Value;
  FOtherButton.Enabled := Value;
  for I := 0 to MaxColorButtonNumber - 1 do
    FColorButtons[I].Enabled := Value;
end;

procedure TJvCustomOfficeColorPanel.ShowHintChanged;
var
  I: Integer;
begin
  inherited ShowHintChanged;
  FAutoButton.ShowHint := ShowHint;
  FOtherButton.ShowHint := ShowHint;
  for I := 0 to MaxColorButtonNumber - 1 do
    FColorButtons[I].ShowHint := ShowHint;
end;

{$IFDEF VCL}

procedure TJvCustomOfficeColorPanel.SetColorDialogOptions(const Value: TColorDialogOptions);
begin
  FColorDialogOptions := Value;
end;

procedure TJvCustomOfficeColorPanel.CreateWnd;
begin
  inherited CreateWnd;
  AdjustColorButtons;
end;

{$ENDIF VCL}

{$IFDEF VisualCLX}
procedure TJvCustomOfficeColorPanel.InitWidget;
begin
  inherited InitWidget;
  AdjustColorButtons;
end;
{$ENDIF VisualCLX}

function TJvCustomOfficeColorPanel.GetProperties: TJvOfficeColorPanelProperties;
begin
  Result := FProperties;
end;

procedure TJvCustomOfficeColorPanel.SetProperties(const Value: TJvOfficeColorPanelProperties);
begin
  if FProperties <> Value then
    FProperties.Assign(Value);
end;

procedure TJvCustomOfficeColorPanel.PropertiesChanged(Sender: TObject;
  PropName: string);
var
  LFlag: Boolean;
  I: Integer;
begin
  LFlag := False;
  if Cmp(PropName, cShowAutoButton) or Cmp(PropName, cShowOtherButton) then
    LFlag := True
  else
  if Cmp(PropName, cAutoCaption) then
  begin
    if Properties.AutoCaption = '' then
      Properties.ShowAutoButton := False;
  end
  else
  if Cmp(PropName, cOtherCaption) then
  begin
    if Properties.OtherCaption = '' then
      Properties.ShowOtherButton := False;
  end
  else
  if Cmp(PropName, cAutoHint) then
    FAutoButton.Hint := Properties.AutoHint
  else
  if Cmp(PropName, cOtherHint) then
    FOtherButton.Hint := Properties.OtherHint
  else
  if Cmp(PropName, cAutoColor) then
    FAutoButton.ButtonColor := Properties.AutoColor
  else
  if Cmp(PropName, cShowColorHint) then
  begin
    FAutoButton.ShowHint :=  Properties.ShowColorHint;
    FOtherButton.ShowHint :=  Properties.ShowColorHint;
    for I := 0 to MaxColorButtonNumber - 1 do
      FColorButtons[I].ShowHint := Properties.ShowColorHint;
  end
  else
    LFlag := True;
  if LFlag then
    AdjustColorButtons;
end;

type
  TControlAccessProtected = class(TControl);

procedure TJvCustomOfficeColorPanel.RedirectToColorButtonClick(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
   LParent: TWinControl;
begin
  if Assigned(OnMouseUp) then
    OnMouseUp(Sender, Button, Shift, X, Y);

  // If any of the possible parents has a popup menu, we let it
  // run, and do not select the button (hence the exit), unless
  // the properties tell us to select anyway
  LParent := Self;
  while Assigned(LParent) do
    if Assigned(TControlAccessProtected(LParent).PopupMenu) then
    begin
      if not Properties.SelectIfPopup then
        Exit;
    end
    else
      LParent := LParent.Parent;

  // if the user asked not to right click select, we stop here
  if not Properties.RightClickSelect then
    Exit;

  if Button = mbRight then
    ColorButtonClick(Sender);
end;

//=== { TJvColorSpeedButton } ================================================

constructor TJvColorSpeedButton.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FButtonColor := clDefault;
end;

procedure TJvColorSpeedButton.SetButtonColor(const Value: TColor);
begin
  if FButtonColor <> Value then
  begin
    FButtonColor := Value;
    Invalidate;
  end;
end;

{$IFDEF UNITVERSIONING}
initialization
  RegisterUnitVersion(HInstance, UnitVersioning);

finalization
  UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}

end.

⌨️ 快捷键说明

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