📄 jvofficecolorpanel.pas
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvOfficeColorPanel.PAS, released on 2004-02-26.
The Initial Developer of the Original Code is dejoy [dejoy att ynl dott gov dott cn]
Portions created by Peter Th鰎nqvist are Copyright (C) 2004 Peter Th鰎nqvist.
All Rights Reserved.
Contributor(s):
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Description:
Color panel for the @link(TJvOfficeColorButton) component
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvOfficeColorPanel.pas,v 1.31 2005/02/17 10:20:44 marquardt Exp $
unit JvOfficeColorPanel;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
SysUtils, Classes,
Windows, Messages, Graphics, Controls, Forms, Buttons, ExtCtrls, Dialogs,
{$IFDEF VisualCLX}
Qt,
{$ENDIF VisualCLX}
JvComponent, JvSpeedButton;
const
MaxColorButtonNumber = 40;
Tag_AutoCaption = 0;
Tag_OtherCaption = 1;
Tag_AutoHint = 2;
Tag_OtherHint = 3;
MinButtonHeight = 22;
MinButtonWidth = 23;
MinColorSize = 18;
MinColorSpace = 0;
MinColorSpaceTop = 4;
MinColorSpaceBottom = 4;
MinTopMargin = 2;
MinBottomMargin = 4;
MinHorizontalMargin = 7;
Tag_ButtonHeight = 0;
Tag_ButtonWidth = 1;
Tag_ColorSize = 2;
Tag_ColorSpace = 3;
Tag_ColorSpaceTop = 4;
Tag_ColorSpaceBottom = 5;
Tag_TopMargin = 6;
Tag_BottomMargin = 7;
Tag_HorizontalMargin = 8;
LineColorButtonCount = 8;
SubColorButtonColors: array [0..MaxColorButtonNumber - 1] of TColor =
($000000, $003399, $003333, $003300, $663300, $800000, $993333, $333333,
$000080, $0066FF, $008080, $008000, $808000, $FF0000, $996666, $808080,
$0000FF, $0099FF, $00CC99, $669933, $CCCC33, $FF6633, $800080, $999999,
$FF00FF, $00CCFF, $00FFFF, $00FF00, $FFFF00, $FFCC00, $663399, $C0C0C0,
$CC99FF, $99CCFF, $99FFFF, $CCFFCC, $FFFFCC, $FFCC99, $FF99CC, $FFFFFF);
type
TJvClickColorButtonType =
(cbctColorsButton, cbctAutoButton, cbctOtherButton, cbctNone);
TJvPropertiesChangedEvent = procedure(Sender: TObject; PropName: string) of object;
TJvColorSpeedButton = class(TJvSpeedButton)
private
FButtonColor: TColor;
procedure SetButtonColor(const Value: TColor);
public
constructor Create(AOwner: TComponent); override;
property ButtonColor: TColor read FButtonColor write SetButtonColor;
end;
TJvSubColorButton = class(TJvColorSpeedButton)
private
procedure SetEdgeWidth(const Value: Integer);
protected
FEdgeWidth: Integer;
procedure Paint; override;
function GetEdgeWidth: Integer; virtual;
public
constructor Create(AOwner: TComponent); override;
property Canvas;
property EdgeWidth: Integer read GetEdgeWidth write SetEdgeWidth;
end;
// (ahuser) TJvColorDialog is not registered as component
TJvOfficeColorDialog = class(TColorDialog)
published
property OnShow;
property OnClose;
end;
TJvOfficeColorPanelProperties = class(TPersistent)
private
FShowAutoButton: Boolean;
FShowOtherButton: Boolean;
FTopMargin: Integer;
FColorSpaceBottom: Integer;
FHorizontalMargin: Integer;
FColorSpace: Integer;
FColorSpaceTop: Integer;
FButtonHeight: Integer;
FColorSize: Integer;
FBottomMargin: Integer;
FAutoCaption: string;
FOtherCaption: string;
FAutoHint: string;
FOtherHint: string;
FOnPropertiesChanged: TJvPropertiesChangedEvent;
FAutoColor: TColor;
FShowColorHint: Boolean;
FRightClickSelect: Boolean;
FSelectIfPopup: Boolean;
procedure SetShowAutoButton(const Value: Boolean);
procedure SetShowOtherButton(const Value: Boolean);
procedure SetMeasure(const Index, Value: Integer);
function GetStringValue(const Index: Integer): string;
procedure SetStringValue(const Index: Integer; const Value: string);
procedure SetAutoColor(const Value: TColor);
procedure SetShowColorHint(const Value: Boolean);
procedure SetRightClickSelect(const Value: Boolean);
procedure SetSelectIfPopup(const Value: Boolean);
protected
procedure Changed(PropName: string); virtual;
procedure CreateDefaultText; virtual;
public
constructor Create; virtual;
procedure Assign(Source: TPersistent); override;
property AutoColor: TColor read FAutoColor write SetAutoColor default clDefault;
property OnPropertiesChanged: TJvPropertiesChangedEvent read FOnPropertiesChanged write FOnPropertiesChanged;
published
property ShowAutoButton: Boolean read FShowAutoButton write SetShowAutoButton default True;
property ShowOtherButton: Boolean read FShowOtherButton write SetShowOtherButton default True;
property ShowColorHint: Boolean read FShowColorHint write SetShowColorHint default True;
property TopMargin: Integer index Tag_TopMargin read FTopMargin write SetMeasure
default MinTopMargin;
property BottomMargin: Integer index Tag_BottomMargin read FBottomMargin write SetMeasure
default MinBottomMargin;
property HorizontalMargin: Integer index Tag_HorizontalMargin read FHorizontalMargin write SetMeasure
default MinHorizontalMargin;
property ColorSpace: Integer index Tag_ColorSpace read FColorSpace write SetMeasure
default MinColorSpace;
property ColorSpaceTop: Integer index Tag_ColorSpaceTop read FColorSpaceTop write SetMeasure
default MinColorSpaceTop;
property ColorSpaceBottom: Integer index Tag_ColorSpaceBottom read FColorSpaceBottom write SetMeasure
default MinColorSpaceBottom;
property ColorSize: Integer index Tag_ColorSize read FColorSize write SetMeasure
default MinColorSize;
property ButtonHeight: Integer index Tag_ButtonHeight read FButtonHeight write SetMeasure
default MinButtonHeight;
property AutoCaption: string index Tag_AutoCaption read GetStringValue write SetStringValue;
property OtherCaption: string index Tag_OtherCaption read GetStringValue write SetStringValue;
property AutoHint: string index Tag_AutoHint read GetStringValue write SetStringValue;
property OtherHint: string index Tag_OtherHint read GetStringValue write SetStringValue;
property RightClickSelect: Boolean read FRightClickSelect write SetRightClickSelect default False;
property SelectIfPopup: Boolean read FSelectIfPopup write SetSelectIfPopup default False;
end;
TJvCustomOfficeColorPanel = class(TJvCustomPanel)
private
FColorButtons: array [0..MaxColorButtonNumber - 1] of TJvSubColorButton;
FAutoButton: TJvSubColorButton;
FOtherButton: TJvColorSpeedButton;
FProperties: TJvOfficeColorPanelProperties;
FOwner: TControl;
FColorDialog: TJvOfficeColorDialog;
FSelectedColor: TColor;
FWordStyle: Boolean;
FFlat: Boolean;
FInited: Boolean;
FOnColorChange: TNotifyEvent;
FOnColorButtonClick: TNotifyEvent;
FClickColorButton: TJvClickColorButtonType;
{$IFDEF VCL}
FColorDialogOptions: TColorDialogOptions;
procedure SetColorDialogOptions(const Value: TColorDialogOptions);
{$ENDIF VCL}
procedure ColorButtonClick(Sender: TObject);
procedure RedirectToColorButtonClick(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SetFlat(const Value: Boolean);
procedure SetSelectedColor(const Value: TColor);
function GetCustomColors: TStrings;
procedure SetCustomColors(const Value: TStrings);
function GetProperties: TJvOfficeColorPanelProperties;
procedure SetProperties(const Value: TJvOfficeColorPanelProperties);
protected
{$IFDEF VCL}
procedure CreateWnd; override;
{$ENDIF VCL}
{$IFDEF VisualCLX}
procedure InitWidget; override;
{$ENDIF VisualCLX}
procedure Resize; override;
procedure Paint; override;
procedure ShowHintChanged; override;
procedure PropertiesChanged(Sender: TObject; PropName: string); virtual;
procedure SetWordStyle(const Value: Boolean);
procedure MakeColorButtons;
procedure AdjustColorButtons;
procedure SetEnabled({$IFDEF VisualCLX} const {$ENDIF} Value: Boolean); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetButton(Button: TControl);
property ColorDialog: TJvOfficeColorDialog read FColorDialog write FColorDialog;
property SelectedColor: TColor read FSelectedColor write SetSelectedColor default clBlack;
property ClickColorButton: TJvClickColorButtonType read FClickColorButton;
property Color: TColor read FSelectedColor write SetSelectedColor default clBlack;
property Flat: Boolean read FFlat write SetFlat default True;
property CustomColors: TStrings read GetCustomColors write SetCustomColors;
property Properties: TJvOfficeColorPanelProperties read GetProperties write SetProperties;
{$IFDEF VCL}
property Options: TColorDialogOptions read FColorDialogOptions write SetColorDialogOptions default [];
{$ENDIF VCL}
property OnColorChange: TNotifyEvent read FOnColorChange write FOnColorChange;
property OnColorButtonClick: TNotifyEvent read FOnColorButtonClick write FOnColorButtonClick;
end;
TJvOfficeColorPanel = class(TJvCustomOfficeColorPanel)
published
property Flat;
property Color;
property CustomColors;
{$IFDEF VCL}
property Options;
property BiDiMode;
property DragCursor;
property DragKind;
property ParentBiDiMode;
property OnCanResize;
property OnEndDock;
property OnGetSiteInfo;
{$ENDIF VCL}
property Align;
property Anchors;
property Constraints;
property DragMode;
property Enabled;
property Font;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnConstrainedResize;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDrag;
property Properties;
property OnColorChange;
property OnColorButtonClick;
property OnClick;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvOfficeColorPanel.pas,v $';
Revision: '$Revision: 1.31 $';
Date: '$Date: 2005/02/17 10:20:44 $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
JvJCLUtils, JvResources;
const
cAutoCaption = 'AutoCaption';
cAutoColor = 'AutoColor';
cAutoHint = 'AutoHint';
cOtherCaption = 'OtherCaption';
cOtherHint = 'OtherHint';
cShowAutoButton = 'ShowAutoButton';
cShowColorHint = 'ShowColorHint';
cShowOtherButton = 'ShowOtherButton';
//=== { TJvOfficeColorPanelProperties } ======================================
constructor TJvOfficeColorPanelProperties.Create;
begin
inherited Create;
FShowAutoButton := True;
FShowOtherButton := True;
FShowColorHint := True;
FAutoColor := clDefault;
FHorizontalMargin := MinHorizontalMargin;
FTopMargin := MinTopMargin;
FColorSpace := MinColorSize;
FColorSpaceTop := MinColorSpaceTop;
FColorSize := MinColorSize;
FButtonHeight := MinButtonHeight;
FColorSpaceBottom := MinColorSpaceBottom;
FBottomMargin := MinBottomMargin;
FRightClickSelect := False;
FSelectIfPopup := False;
CreateDefaultText;
end;
procedure TJvOfficeColorPanelProperties.Assign(Source: TPersistent);
begin
if Source is TJvOfficeColorPanelProperties then
with TJvOfficeColorPanelProperties(Source) do
begin
Self.FShowAutoButton := ShowAutoButton;
Self.FShowOtherButton := ShowOtherButton;
Self.FShowColorHint := ShowColorHint;
Self.FTopMargin := TopMargin;
Self.FColorSpaceBottom := ColorSpaceBottom;
Self.FHorizontalMargin := HorizontalMargin;
Self.FColorSpace := ColorSpace;
Self.FColorSpaceTop := ColorSpaceTop;
Self.FButtonHeight := ButtonHeight;
Self.FColorSize := ColorSize;
Self.FBottomMargin := BottomMargin;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -