📄 jvqcolorprovider.pas
字号:
end;
TJvColorProviderAddColorSettings = class(TJvColorProviderSubSettings)
private
FLocation: TJvColorProviderAddItemLocation;
FCaption: string;
FStyle: Integer;
protected
procedure SetLocation(Value: TJvColorProviderAddItemLocation); virtual;
procedure SetCaption(Value: string); virtual;
function GetStyle: TJvColorProviderAddColorStyle; virtual;
procedure SetStyle(Value: TJvColorProviderAddColorStyle); virtual;
public
constructor Create(AConsumerService: TJvDataConsumerAggregatedObject);
destructor Destroy; override;
published
property Active;
property Location: TJvColorProviderAddItemLocation read FLocation write SetLocation
default ailBottom;
property Caption: string read FCaption write SetCaption;
property Style: TJvColorProviderAddColorStyle read GetStyle write SetStyle;
end;
TJvColorProviderCustomColorGroupSettings = class(TJvColorProviderColorGroupSettings)
private
FAddColorSettings: TJvColorProviderAddColorSettings;
protected
procedure SetAddColorSettings(Value: TJvColorProviderAddColorSettings); virtual;
public
constructor Create(AConsumerService: TJvDataConsumerAggregatedObject; ACaption: string);
destructor Destroy; override;
published
property AddColorSettings: TJvColorProviderAddColorSettings read FAddColorSettings
write SetAddColorSettings;
end;
IJvColorProviderSettings = interface
['{5381D2E0-D8EA-46E7-A3C6-42B5353B896B}']
function Get_ColorBoxSettings: TJvColorProviderColorBoxSettings;
function Get_CustomColorSettings: TJvColorProviderCustomColorGroupSettings;
function Get_GroupingSettings: TJvColorProviderGroupingSettings;
function Get_NameMapping: TJvColorProviderNameMapping;
function Get_NameMappingIndex: Integer;
function Get_StandardColorSettings: TJvColorProviderColorGroupSettings;
function Get_SystemColorSettings: TJvColorProviderColorGroupSettings;
function Get_TextSettings: TJvColorProviderTextSettings;
procedure Set_NameMapping(Value: TJvColorProviderNameMapping);
procedure Set_NameMappingIndex(Value: Integer);
procedure MappingAdding;
procedure MappingAdded(Index: Integer; Mapping: TJvColorProviderNameMapping);
procedure MappingDestroying(Index: Integer; Mapping: TJvColorProviderNameMapping);
procedure MappingDestroyed;
property ColorBoxSettings: TJvColorProviderColorBoxSettings read Get_ColorBoxSettings;
property CustomColorSettings: TJvColorProviderCustomColorGroupSettings
read Get_CustomColorSettings;
property GroupingSettings: TJvColorProviderGroupingSettings read Get_GroupingSettings;
property NameMapping: TJvColorProviderNameMapping read Get_NameMapping write Set_NameMapping;
property NameMappingIndex: Integer read Get_NameMappingIndex write Set_NameMappingIndex;
property StandardColorSettings: TJvColorProviderColorGroupSettings
read Get_StandardColorSettings;
property SystemColorSettings: TJvColorProviderColorGroupSettings read Get_SystemColorSettings;
property TextSettings: TJvColorProviderTextSettings read Get_TextSettings;
end;
{ Provider containing the available name mappings of a color provider. }
TJvColorMappingProvider = class(TJvCustomDataProvider, IJvColorMappingProvider)
function IJvColorMappingProvider.Get_ClientProvider = GetColorProviderIntf;
procedure IJvColorMappingProvider.Set_ClientProvider = SetColorProviderIntf;
private
function GetColorProviderIntf: IJvColorProvider;
procedure SetColorProviderIntf(Value: IJvColorProvider);
protected
class function ItemsClass: TJvDataItemsClass; override;
function ConsumerClasses: TClassArray; override;
public
property ProviderIntf: IJvColorProvider read GetColorProviderIntf write SetColorProviderIntf;
published
property Provider: IJvColorProvider read GetColorProviderIntf write SetColorProviderIntf;
end;
TJvColorProviderServerNotify = class(TJvDataConsumerServerNotify)
protected
procedure ItemSelected(Value: IJvDataItem); override;
function IsValidClient(Client: IJvDataConsumerClientNotify): Boolean; override;
end;
TJvColorProviderColorAdderRegister = class(TObject)
private
FDefaultAdder: Integer;
FList: TStringList;
FMinimumKeep: Integer;
FDefaultAfterClear: Integer;
FNotifiers: TList;
protected
procedure RegisterNotify(Value: TJvColorProviderAddColorSettings);
procedure UnregisterNotify(Value: TJvColorProviderAddColorSettings);
public
constructor Create;
destructor Destroy; override;
function Add(Name: string; Callback: TJvColorProviderColorAdder): Integer;
procedure Delete(Callback: TJvColorProviderColorAdder); overload;
procedure Delete(Index: Integer); overload;
procedure Delete(Name: string); overload;
procedure Clear;
function IndexOf(Name: string): Integer; overload;
function IndexOf(Callback: TJvColorProviderColorAdder): Integer; overload;
function Count: Integer;
function Names(Index: Integer): string;
function Callbacks(Index: Integer): TJvColorProviderColorAdder;
property DefaultAdder: Integer read FDefaultAdder write FDefaultAdder;
end;
const
cColorItemIDPrefix = 'TCOLOR=';
cColorProviderGroupHeaderID = 'ColorGroupHeader_';
cColorProviderAddItemID = 'CP_ADDITEM';
cColorProviderColorMapItemID = 'COLMAP:';
ColorProvider_NotAColor = TColor($EFFFFFFF);
function ColorProviderColorAdderRegister: TJvColorProviderColorAdderRegister;
implementation
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
SysUtils,
{$IFDEF HAS_UNIT_RTLCONSTS}
RTLConsts,
{$ELSE}
QConsts,
{$ENDIF HAS_UNIT_RTLCONSTS}
QControls,
JclStrings,
JvQJVCLUtils, JvQJCLUtils, JvQConsts, JvQResources;
const
aisPrvEvt = 'aisPrvEvt';
aisStdDlg = 'aisStdDlg';
type
TWriterAccessProtected = class(TWriter);
function GetItemColorValue(Item: IJvDataItem; out Color: TColor): Boolean;
var
S: string;
begin
S := Item.GetID;
Result := Copy(S, 1, 7) = cColorItemIDPrefix;
if Result then
begin
Color := StrToInt('$0' + Copy(S, 8, 8));
end;
end;
function GetUniqueMappingName(Mappings: TJvColorProviderNameMappings; Prefix: string): string;
var
PrefixLen: Integer;
SuffixNum: Int64;
MapIdx: Integer;
TmpNum: Int64;
begin
PrefixLen := Length(Prefix);
SuffixNum := 1;
for MapIdx := 0 to Mappings.Count - 1 do
if AnsiSameStr(Prefix, Copy(Mappings[MapIdx].Name, 1, PrefixLen)) then
with Mappings[MapIdx] do
begin
if StrIsSubset(Copy(Name, PrefixLen + 1, Length(Name) - PrefixLen), DigitSymbols) then
begin
TmpNum := StrToInt64(Copy(Name, PrefixLen + 1, Length(Name) - PrefixLen));
if TmpNum >= SuffixNum then
SuffixNum := TmpNum + 1;
end;
end;
Result := Prefix + IntToStr(SuffixNum);
end;
//=== Color provider color adding methods ====================================
procedure AddColorProviderEvent(Provider: IJvColorProvider; ColorType: TColorType;
var Color: TColor; var DoAdd: Boolean);
begin
Provider.DoAddColor(ColorType, Color, DoAdd);
end;
procedure AddColorColorDialog(Provider: IJvColorProvider; ColorType: TColorType; var AColor: TColor;
var DoAdd: Boolean);
begin
with TColorDialog.Create(nil) do
try
DoAdd := Execute;
AColor := Color;
finally
Free;
end;
end;
//=== Color provider color adding methods registration =======================
var
AdderReg: TJvColorProviderColorAdderRegister;
function ColorProviderColorAdderRegister: TJvColorProviderColorAdderRegister;
begin
if AdderReg = nil then
begin
AdderReg := TJvColorProviderColorAdderRegister.Create;
AdderReg.Add(aisPrvEvt, AddColorProviderEvent);
AdderReg.DefaultAdder := AdderReg.Add(aisStdDlg, AddColorColorDialog);
AdderReg.FMinimumKeep := AdderReg.Count;
AdderReg.FDefaultAfterClear := AdderReg.DefaultAdder;
end;
Result := AdderReg;
end;
var
MasterColorConsumer: IJvDataConsumer;
type
TJvColorItems = class(TJvBaseDataItems)
private
FColorProvider: IJvColorProvider;
protected
function GetColorSettings: IJvColorProviderSettings;
function GetCount: Integer; override;
function GetItem(I: Integer): IJvDataItem; override;
procedure InitImplementers; override;
property ColorProvider: IJvColorProvider read FColorProvider write FColorProvider;
public
procedure AfterConstruction; override;
end;
TJvColorItemsList = class(TJvColorItems)
private
FListNum: Integer;
protected
function GetCount: Integer; override;
function GetItem(I: Integer): IJvDataItem; override;
property ListNum: Integer read FListNum write FListNum;
public
procedure AfterConstruction; override;
end;
TJvColorItem = class(TJvBaseDataItem, IJvDataItemText, IJvColorItem)
private
FListNumber: Integer; // 0 = StdColors, 1 = SysColors, 2 = CstColors
FListIndex: Integer; // Index in color list
protected
function GetCaption: string;
procedure SetCaption(const Value: string);
function Editable: Boolean;
function Get_Color: TColor;
procedure InitID; override;
property ListNumber: Integer read FListNumber;
property ListIndex: Integer read FListIndex;
public
constructor Create(AOwner: IJvDataItems; AListNumber, AListIndex: Integer);
end;
TJvColorHeaderItem = class(TJvBaseDataItem, IJvDataItemText)
private
FListNumber: Integer; // 0 = StdColors, 1 = SysColors, 2 = CstColors
protected
function GetCaption: string;
procedure SetCaption(const Value: string);
function Editable: Boolean;
procedure InitID; override;
procedure InitImplementers; override;
function IsDeletable: Boolean; override;
property ListNumber: Integer read FListNumber;
public
constructor Create(AOwner: IJvDataItems; AListNumber: Integer);
end;
TJvColorAddItem = class(TJvBaseDataItem, IJvDataItemText)
protected
function GetCaption: string;
procedure SetCaption(const Value: string);
function Editable: Boolean;
procedure InitID; override;
procedure InitImplementers; override;
end;
TJvColorItemAddExecute = class(TJvDataItemAggregatedObject, IJvDataItemBasicAction)
protected
function Execute(Sender: TObject): Boolean;
end;
TJvColorItemsRenderer = class(TJvCustomDataItemsRenderer)
protected
CurrentCanvas: TCanvas;
CurrentRect: TRect;
CurrentItem: IJvDataItem;
CurrentState: TProviderDrawStates;
CurrentSettings: IJvColorProviderSettings;
CurrentItemIsColorItem: Boolean;
CurrentColorValue: TColor;
function GetRenderText: string;
procedure RenderColorBox;
procedure RenderColorText;
procedure RenderGroupHeader;
procedure MeasureColorBox(var Size: TSize);
procedure MeasureColorText(var Size: TSize);
procedure DoDrawItem(ACanvas: TCanvas; var ARect: TRect; Item: IJvDataItem;
State: TProviderDrawStates); override;
function DoMeasureItem(ACanvas: TCanvas; Item: IJvDataItem): TSize; override;
function AvgItemSize(ACanvas: TCanvas): TSize; override;
function GetConsumerSettings: IJvColorProviderSettings;
end;
TJvDataConsumerAggregatedObjectAccessProtected = class(TJvDataConsumerAggregatedObject);
TJvColorProviderSettings = class;
TJvColorMappingChangeEvent = procedure(Sender: TJvColorProviderSettings; Index: Integer;
Mapping: TJvColorProviderNameMapping) of object;
TJvColorProviderSettings = class(TJvDataConsumerAggregatedObject, IJvColorProviderSettings)
private
FColorBoxSettings: TJvColorProviderColorBoxSettings;
FCustomColorSettings: TJvColorProviderCustomColorGroupSettings;
FGroupingSettings: TJvColorProviderGroupingSettings;
FStandardColorSettings: TJvColorProviderColorGroupSettings;
FSystemColorSettings: TJvColorProviderColorGroupSettings;
FTextSettings: TJvColorProviderTextSettings;
FMapping: Integer;
FOnMappingAdding: TNotifyEvent;
FOnMappingAdded: TJvColorMappingChangeEvent;
FOnMappingDestroying: TJvColorMappingChangeEvent;
FOnMappingDestroyed: TNotifyEvent;
protected
function Get_ColorBoxSettings: TJvColorProviderColorBoxSettings;
function Get_CustomColorSettings: TJvColorProviderCustomColorGroupSettings;
function Get_GroupingSettings: TJvColorProviderGroupingSettings;
function Get_NameMapping: TJvColorProviderNameMapping;
function Get_NameMappingIndex: Integer;
function Get_StandardColorSettings: TJvColorProviderColorGroupSettings;
function Get_SystemColorSettings: TJvColorProviderColorGroupSettings;
function Get_TextSettings: TJvColorProviderTextSettings;
procedure Set_ColorBoxSettings(Value: TJvColorProviderColorBoxSettings);
procedure Set_CustomColorSettings(Value: TJvColorProviderCustomColorGroupSettings);
procedure Set_GroupingSettings(Value: TJvColorProviderGroupingSettings);
procedure Set_NameMapping(Value: TJvColorProviderNameMapping);
procedure Set_NameMappingIndex(Value: Integer);
procedure Set_StandardColorSettings(Value: TJvColorProviderColorGroupSettings);
procedure Set_SystemColorSettings(Value: TJvColorProviderColorGroupSettings);
procedure Set_TextSettings(Value: TJvColorProviderTextSettings);
procedure MappingAdding;
procedure MappingAdded(Index: Integer; Mapping: TJvColorProviderNameMapping);
procedure MappingDestroying(Index: Integer; Mapping: TJvColorProviderNameMapping);
procedure MappingDestroyed;
function GetNameMappingIndex: TJvColorProviderMapping;
procedure SetNameMappingIndex(Value: TJvColorProviderMapping);
public
constructor Create(AOwner: TExtensibleInterfacedPersistent); override;
destructor Destroy; override;
property OnMappingAdding: TNotifyEvent read FOnMappingAdding write FOnMappingAdding;
property OnMappingAdded: TJvColorMappingChangeEvent read FOnMappingAdded write FOnMappingAdded;
property OnMappingDestroying: TJvColorMappingChangeEvent read FOnMappingDestroying
write FOnMappingDestroying;
property OnMappingDestroyed: TNotifyEvent read FOnMappingDestroyed write FOnMappingDestroyed;
published
property ColorBoxSettings: TJvColorProviderColorBoxSettings read Get_ColorBoxSettings
write Set_ColorBoxSettings;
property CustomColorSettings: TJvColorProviderCustomColorGroupSettings
read Get_CustomColorSettings write Set_CustomColorSettings;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -