📄 jvqofficecolorbutton.pas
字号:
end;
procedure TJvCustomOfficeColorButton.DoArrowClick(Sender: TObject);
begin
if TJvColorSpeedButton(Sender).Tag = FArrowButton.Tag then
begin
if FColorsForm.Visible or FColorFormDropDown then
begin
FColorsForm.Hide;
FColorFormDropDown := False;
FArrowButton.Down := False;
end
else
begin
if Assigned(FOnDropDown) then
FOnDropDown(Self);
ShowColorForm;
FColorFormDropDown := True;
end
end
else
begin
TJvSubColorButton(Sender).Down := True;
SetSelectedColor(TJvSubColorButton(Sender).ButtonColor);
end;
if Assigned(FOnArrowClick) then
FOnArrowClick(Self);
end;
procedure TJvCustomOfficeColorButton.DoColorButtonClick(Sender: TObject);
begin
if not FColorsForm.ToolWindowStyle then
begin
FColorsForm.Hide;
FColorsForm.ToolWindowStyle := False;
if FArrowButton.Down then
FArrowButton.Down := False;
FColorFormDropDown := False;
end
else
begin
if FColorsForm.ColorPanel.ClickColorButton = cbctOtherButton then
FColorsForm.FormStyle := fsNormal;
end;
if Assigned(FOnColorButtonClick) then
FOnColorButtonClick(Sender);
end;
function TJvCustomOfficeColorButton.GetCustomColors: TStrings;
begin
Result := FColorsForm.ColorPanel.CustomColors;
end;
function TJvCustomOfficeColorButton.GetSelectedColor: TColor;
begin
Result := FColorsForm.ColorPanel.Color;
end;
procedure TJvCustomOfficeColorButton.DoOnColorChange(Sender: TObject);
begin
FMainButton.ButtonColor := FColorsForm.ColorPanel.SelectedColor;
if FColorsForm.ToolWindowStyle and (FColorsForm.FormStyle <> fsStayOnTop) then
FColorsForm.FormStyle := fsStayOnTop;
if Assigned(FOnColorChange) then
FOnColorChange(Self);
end;
procedure TJvCustomOfficeColorButton.SetCustomColors(const Value: TStrings);
begin
FColorsForm.ColorPanel.CustomColors.Assign(Value);
end;
procedure TJvCustomOfficeColorButton.SetFlat(const Value: Boolean);
begin
if FFlat <> Value then
begin
FFlat := Value;
FMainButton.Flat := Value;
FArrowButton.Flat := Value;
FColorsForm.Flat := Value;
end;
end;
// NEW: Set Control Background Color
procedure TJvCustomOfficeColorButton.SetControlBgColor(const Value: TColor);
begin
if Value = clDefault then // If set to clDefault then no change.
Exit;
if Value <> FArrowButton.Color then
begin
FMainButton.Color := Value;
FArrowButton.Color := Value;
end;
end;
function TJvCustomOfficeColorButton.GetControlBgColor: TColor;
begin
Result := FArrowButton.Color;
end;
{WPostma - Property SelectedColor (GetColor/SetColor) is the actual user-selected value}
procedure TJvCustomOfficeColorButton.SetSelectedColor(const Value: TColor);
begin
if FColorsForm.ColorPanel.SelectedColor <> Value then
FColorsForm.ColorPanel.SelectedColor := Value;
end;
procedure TJvCustomOfficeColorButton.AdjustColorForm(X: Integer = 0; Y: Integer = 0);
var
Pt: TPoint;
begin
if (X = 0) and (Y = 0) then
Pt := ClientToScreen(Point(FMainButton.Left, FMainButton.Top))
else
Pt := Point(X, Y);
FColorsForm.Left := Pt.X;
if (FColorsForm.Left + FColorsForm.Width) > Screen.Width then
FColorsForm.Left := Screen.Width - FColorsForm.Width;
FColorsForm.Top := Pt.Y + Height;
if (FColorsForm.Top + FColorsForm.Height) > Screen.Height then
FColorsForm.Top := Pt.Y - FColorsForm.Height;
end;
procedure TJvCustomOfficeColorButton.ShowColorForm(X: Integer = 0; Y: Integer = 0);
begin
AdjustColorForm(X, Y);
FColorsForm.Show;
FColorFormDropDown := True;
end;
procedure TJvCustomOfficeColorButton.DoFormShowingChanged(Sender: TObject);
begin
if not FColorsForm.Visible then
begin
FArrowButton.Down := False;
TColorSpeedButtonAccessProtected(FArrowButton).MouseLeave(FArrowButton);
TColorSpeedButtonAccessProtected(FMainButton).MouseLeave(FMainButton);
end;
end;
procedure TJvCustomOfficeColorButton.DoFormKillFocus(Sender: TObject);
var
R: TRect;
P: TPoint;
begin
R := FArrowButton.ClientRect;
GetCursorPos(P);
P := FArrowButton.ScreenToClient(P);
if (not FColorsForm.ToolWindowStyle) and (not PtInRect(R, P)) then //mouse in ArrowButton
begin
FColorsForm.Hide;
FColorsForm.ToolWindowStyle := False;
if FArrowButton.Down then
FArrowButton.Down := False;
FColorFormDropDown := False;
end;
end;
procedure TJvCustomOfficeColorButton.DoFormClose(Sender: TObject; var Action: TCloseAction);
begin
if FColorsForm.ToolWindowStyle then
FColorFormDropDown := False;
if csDestroying in ComponentState then
Action := caFree
else
Action := caHide;
end;
procedure TJvCustomOfficeColorButton.DoFormWindowStyleChanged(Sender: TObject);
begin
if FColorsForm.ToolWindowStyle then
begin
FArrowButton.Down := False;
TColorSpeedButtonAccessProtected(FArrowButton).MouseLeave(FArrowButton);
TColorSpeedButtonAccessProtected(FMainButton).MouseLeave(FMainButton);
end;
end;
procedure TJvCustomOfficeColorButton.DoButtonMouseEnter(Sender: TObject);
begin
if FFlat and Enabled then
begin
TColorSpeedButtonAccessProtected(FMainButton).MouseEnter(FMainButton);
TColorSpeedButtonAccessProtected(FArrowButton).MouseEnter(FArrowButton);
end;
end;
procedure TJvCustomOfficeColorButton.DoButtonMouseLeave(Sender: TObject);
begin
if FFlat and Enabled then
begin
if Sender = FMainButton then
begin
if FColorsForm.Visible then
TColorSpeedButtonAccessProtected(FMainButton).MouseEnter(FMainButton)
else
TColorSpeedButtonAccessProtected(FArrowButton).MouseLeave(FArrowButton);
end
else
if Sender = FArrowButton then
begin
if not FColorsForm.Visible then
TColorSpeedButtonAccessProtected(FMainButton).MouseLeave(FMainButton)
else
TColorSpeedButtonAccessProtected(FArrowButton).MouseEnter(FArrowButton);
end;
end;
end;
function TJvCustomOfficeColorButton.GetGlyph: TBitmap;
begin
Result := FMainButton.Glyph;
end;
procedure TJvCustomOfficeColorButton.SetGlyph(const Value: TBitmap);
begin
FMainButton.Glyph := Value;
end;
function TJvCustomOfficeColorButton.GetProperties: TJvOfficeColorButtonProperties;
begin
Result := FProperties;
end;
procedure TJvCustomOfficeColorButton.SetProperties(const Value: TJvOfficeColorButtonProperties);
begin
if FProperties <> Value then
begin
FProperties.Assign(Value);
FColorsForm.ColorPanel.Properties.Assign(Value);
end;
end;
procedure TJvCustomOfficeColorButton.PropertiesChanged(Sender: TObject;
PropName: string);
begin
if Cmp(PropName, cShowDragBar) then
begin
if FColorsForm.ShowDragBar <> Properties.ShowDragBar then
FColorsForm.ShowDragBar := Properties.ShowDragBar;
if not Properties.ShowDragBar and
TJvOfficeColorFormAccessProtected(FColorsForm).DropDownMoved then
AdjustColorForm;
end
else
if Cmp(PropName, cDragCaption) then
FColorsForm.Caption := Properties.DragCaption
else
if Cmp(PropName, cDragBarHeight) then
begin
FColorsForm.DragBarHeight := Properties.DragBarHeight;
AdjustColorForm;
end
else
if Cmp(PropName, cDragBarHint) then
FColorsForm.DragBarHint := Properties.DragBarHint
else
if Cmp(PropName, cDragBarSpace) then
begin
FColorsForm.DragBarSpace := Properties.DragBarSpace;
AdjustColorForm;
end
else
if Cmp(PropName, cArrowWidth) then
AdjustSize
else
if Cmp(PropName, cEdgeWidth) then
FMainButton.EdgeWidth := Properties.EdgeWidth
else
begin
FColorsForm.ColorPanel.Properties.Assign(Properties);
TJvOfficeColorPanelAccessProtected(FColorsForm.ColorPanel).PropertiesChanged(Properties, PropName);
TJvOfficeColorFormAccessProtected(FColorsForm).AdjustColorForm;
end;
end;
procedure TJvCustomOfficeColorButton.DefineProperties(Filer: TFiler);
begin
inherited DefineProperties(Filer);
//Hint: next 3 for compatible old version
Filer.DefineProperty(cArrowWidth, ReadArrowWidth, nil, True);
Filer.DefineProperty(cEdgeWidth, ReadEdgeWidth, nil, True);
Filer.DefineProperty(cOtherCaption, ReadOtherCaption, nil, True);
end;
procedure TJvCustomOfficeColorButton.ReadArrowWidth(Reader: TReader);
begin
Properties.ArrowWidth := Reader.ReadInteger;
end;
procedure TJvCustomOfficeColorButton.ReadEdgeWidth(Reader: TReader);
begin
Properties.EdgeWidth := Reader.ReadInteger;
end;
procedure TJvCustomOfficeColorButton.ReadOtherCaption(Reader: TReader);
begin
Properties.OtherCaption := Reader.ReadString;
end;
//=== { TJvOfficeColorButtonProperties } =====================================
constructor TJvOfficeColorButtonProperties.Create;
begin
inherited Create;
FShowDragBar := True;
FEdgeWidth := 4;
FArrowWidth := MinArrowWidth;
FDragBarHeight := MinDragBarHeight;
FDragBarSpace := MinDragBarSpace;
FDragBarHint := RsDragToFloating;
end;
procedure TJvOfficeColorButtonProperties.Assign(Source: TPersistent);
begin
inherited Assign(Source);
if Source is TJvOfficeColorButtonProperties then
with TJvOfficeColorButtonProperties(Source) do
begin
Self.FShowDragBar := ShowDragBar;
Self.FDragCaption := DragCaption;
Self.FEdgeWidth := EdgeWidth;
Self.FArrowWidth := ArrowWidth;
Self.FDragBarHeight := DragBarHeight;
Self.FDragBarHint := DragBarHint;
Self.FDragBarSpace := DragBarSpace;
end;
end;
procedure TJvOfficeColorButtonProperties.SetArrowWidth(const Value: Integer);
begin
if FArrowWidth <> Value then
begin
FArrowWidth := Value;
Changed(cArrowWidth);
end;
end;
procedure TJvOfficeColorButtonProperties.SetDragBarHeight(const Value: Integer);
begin
if FDragBarHeight <> Value then
begin
FDragBarHeight := Value;
Changed(cDragBarHeight);
end;
end;
procedure TJvOfficeColorButtonProperties.SetDragBarSpace(const Value: Integer);
begin
if FDragBarSpace <> Value then
begin
FDragBarSpace := Value;
Changed(cDragBarSpace);
end;
end;
procedure TJvOfficeColorButtonProperties.SetDragBarHint(const Value: string);
begin
if FDragBarHint<>Value then
begin
FDragBarHint := Value;
Changed(cDragBarHint);
end;
end;
procedure TJvOfficeColorButtonProperties.SetDragCaption(const Value: string);
begin
if FDragCaption <> Value then
begin
FDragCaption := Value;
Changed(cDragCaption);
end;
end;
procedure TJvOfficeColorButtonProperties.SetEdgeWidth(const Value: Integer);
begin
if FEdgeWidth <> Value then
begin
FEdgeWidth := Value;
Changed(cEdgeWidth);
end;
end;
procedure TJvOfficeColorButtonProperties.SetShowDragBar(const Value: Boolean);
begin
if FShowDragBar <> Value then
begin
FShowDragBar := Value;
Changed(cShowDragBar);
end;
end;
procedure TJvCustomOfficeColorButton.DoClick(Sender: TObject);
begin
if Assigned(OnClick) then
OnClick(Self);
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvQOfficeColorButton.pas,v $';
Revision: '$Revision: 1.28 $';
Date: '$Date: 2004/11/07 22:53:55 $';
LogPath: 'JVCL\run'
);
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -