📄 seditorsmanager.pas
字号:
unit sEditorsManager;
interface
uses
windows, Graphics, Classes, Controls,
sUtils, SysUtils, StdCtrls, sDefaults,
Dialogs, Forms, Messages, sConst, extctrls, IniFiles;
type
TsEditorsManager = class;
TsManagerSelection = class;
// Type for sEdits borders painting
TsManagerBorder = class(TPersistent)
private
procedure SetBevel(const Value: TsEditorBevel);
protected
FOwner : TsManagerSelection;
FWidth: integer;
FBevel: TsEditorBevel;
procedure SetWidth(const Value: integer);
public
constructor Create(AOwner: TsManagerSelection);
published
// Width of border. Default value - is 2
property Width : integer read FWidth write SetWidth default 2;
// Mode of border painting
property Bevel : TsEditorBevel read FBevel write SetBevel default ebAsBottomBorder;
end;
TsManagerSelection = class(TPersistent)
private
FMode : TModeSelection;
FOwner : TsEditorsManager;
FColor: TColor;
procedure SetMode(const Value: TModeSelection);
procedure SetColor(const Value: TColor);
public
FBorder : TsManagerBorder;
procedure Assign(Source: TPersistent); override;
constructor Create(AOwner: TsEditorsManager);
destructor destroy; override;
published
// Mode for control selection - (msBorder, msColor)
property Mode : TModeSelection read FMode write SetMode default [msBorder, msColor];
// @Link(TsEditorBorder). Border properties for selected sEdits
property Border : TsManagerBorder read FBorder write FBorder;
property Color: TColor read FColor write SetColor default clWindow;
end;
TsManagerShadow = class(TPersistent)
private
FEnabled : boolean;
FColor : TColor;
FOffset : integer;
FOwner : TsEditorsManager;
FTransparency : integer;
FBlur : integer;
procedure SetBoolean(const Index: Integer; const Value: boolean);
procedure SetInteger(Index: Integer; Value: integer);
procedure SetColors (Index: Integer; Value: TColor);
public
procedure Assign(Source: TPersistent); override;
constructor Create(AOwner : TsEditorsManager);
destructor Destroy; override;
published
property Transparency: integer index 0 read FTransparency write SetInteger default 60;
property Enabled : boolean index 0 read FEnabled write SetBoolean default False;
property Color : TColor index 0 read FColor write SetColors default clBlack;
property Offset : integer index 1 read FOffset write SetInteger default 8;
property Blur : integer index 2 read FBlur write SetInteger default 4;
end;
TsManagerPainting = class(TPersistent)
private
FBevel : TsEditorBevel;
FColor : Graphics.TColor;
FColorBorderTop : Graphics.TColor;
FColorBorderBottom : Graphics.TColor;
FOwner : TsEditorsManager;
procedure SetColors (Index: Integer; Value: Graphics.TColor);
procedure SetBevel(const Value: TsEditorBevel);
// procedure SetBoolean(const Index: Integer; const Value: boolean);
public
constructor Create(AOwner : TsEditorsManager);
procedure Assign(Source: TPersistent); override;
published
property Bevel : TsEditorBevel read FBevel write SetBevel default ebAsBottomBorder;
property ColorBorderTop: Graphics.TColor index 0 read FColorBorderTop write SetColors default clWhite;
property ColorBorderBottom: Graphics.TColor index 1 read FColorBorderBottom write SetColors default $007E756B;
property Color: Graphics.TColor index 3 read FColor write SetColors default DefaultColor;
end;
TsEditorsManager = class(TComponent)
private
FForm : TCustomForm;
FPainting: TsManagerPainting;
FShadow : TsManagerShadow;
FActive : boolean;
FKeysNextControl : string;
FKeysPrevControl : string;
FFlat : boolean;
FGroupIndex : integer;
FFont: TFont;
// FWhatOperate : TsWhatOperate;
FOnAssign : TNotifyEvent;
FSoftControls: boolean;
FSelection: TsManagerSelection;
// procedure SetFonts(Index: Integer; Value: TFont);
procedure SetString(Index: Integer; Value: string);
procedure SetActive(const Value: boolean);
procedure SetSoftControls(const Value: boolean);
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure LoadFromFile(FileName : string);
procedure SaveToFile(FileName : string);
property KeysNextControl : string index 0 read FKeysNextControl write SetString;
property KeysPrevControl : string index 1 read FKeysPrevControl write SetString;
published
property OnAssign: TNotifyEvent read FOnAssign write FOnAssign;
property Painting : TsManagerPainting read FPainting write FPainting;
property Shadow : TsManagerShadow read FShadow write FShadow;
property GroupIndex : integer read FGroupIndex write FGroupIndex;
property Active : boolean read FActive write SetActive default False;
property SoftControls : boolean read FSoftControls write SetSoftControls default True;
property Selection : TsManagerSelection read FSelection write FSelection;
end;
procedure AssignSC(cmp: TComponent; src: TsEditorsManager);
function GeTsEditorsManager(Form: TCustomForm; GroupIndex : integer) : TsEditorsManager;
implementation
uses sMessages, sStyleSimply, sStoreUtils, sGraphUtils;
procedure AssignSC(cmp: TComponent; src: TsEditorsManager);
var
i: integer;
begin
for i := 0 to cmp.ComponentCount-1 do begin
if cmp.Components[i] is TsEditorsManager
then TsEditorsManager(cmp.Components[i]).Assign(src)
else AssignSC(cmp.Components[i], src);
end;
end;
function GeTsEditorsManager(Form: TCustomForm; GroupIndex : integer) : TsEditorsManager;
var
i : integer;
begin
Result := nil;
if Assigned(Form) then begin
for i := 0 to Form.ComponentCount - 1 do begin
if (Form.Components[i] is TsEditorsManager) then
if ((TsEditorsManager(Form.Components[i]).GroupIndex = GroupIndex) or (TsEditorsManager(Form.Components[i]).GroupIndex = 0))
and TsEditorsManager(Form.Components[i]).Active then begin
Result := TsEditorsManager(Form.Components[i]);
exit;
end;
end;
end;
end;
{ TsEditorsManager }
constructor TsEditorsManager.Create(AOwner: TComponent);
begin
inherited;
FPainting := TsManagerPainting.Create(Self);
FShadow := TsManagerShadow.Create(Self);
FSelection := TsManagerSelection.Create(Self);
FFont := TFont.Create;
FKeysNextControl := '40';
FKeysPrevControl := '38';
FFlat := True;
FActive := False;
FSoftControls := True;
if not (AOwner is TCustomForm) then FForm := GetParentForm(TWinControl(AOwner)) else FForm :=TCustomForm(AOwner);
end;
procedure TsEditorsManager.SetString(Index: Integer; Value: string);
var
M : TSMSetString;
begin
if FActive then begin
M.Value := Value;
M.GroupIndex := GroupIndex;
case Index of
0: {M.Msg := SM_SETKEYNEXT};
1: {M.Msg := SM_SETKEYPREV};
{ 2: if (GroupIndex = 0) and (FileExists(Value) or (Value = '')) then begin
M.GroupIndex := GI_FORPANELPATTERN;
M.Msg := SM_SETPATTERN;
end else
M.Msg := WM_NULL;}
end;
BroadCastS(FForm, TMessage(M));
end;
case Index of
0: FKeysNextControl := Value;
1: FKeysPrevControl := Value;
// 2: if (GroupIndex = 0) and (FileExists(Value) or (Value = '')) then FPatternFileName := Value;
end;
end;
procedure TsEditorsManager.Assign(Source: TPersistent);
var
M : TEMChangeAll;
begin
if Assigned(Source) {and (GroupIndex = sSC.GroupIndex)} then begin
FActive := False;
FShadow.Assign(TsEditorsManager(Source).Shadow);
FPainting.Assign(TsEditorsManager(Source).Painting);
FSelection.Assign(TsEditorsManager(Source).Selection);
FSoftControls := TsEditorsManager(Source).SoftControls;
M.sStyleControl := Self;
M.GroupIndex := GroupIndex;
M.Msg := EM_CHANGEALL;
BroadCastS(FForm, TMessage(M));
FActive := True;
UpdateShadows(FForm, GroupIndex);
if Assigned(OnAssign) then OnAssign(Self);
end;
end;
destructor TsEditorsManager.Destroy;
begin
FreeAndNil(FPainting);
FreeAndNil(FFont);
FreeAndNil(FShadow);
FreeAndNil(FSelection);
inherited Destroy;
end;
procedure TsEditorsManager.SetActive(const Value: boolean);
begin
if FActive <> Value then begin
if Value then begin
Assign(Self);
end
else FActive := False;
end;
end;
procedure TsEditorsManager.LoadFromFile(FileName: string);
const
Section = 'Controls';
var
IniFile : TMemIniFile;
begin
if not FileExists(FileName) then Exit;
Active := False;
IniFile := TMemIniFile.Create(FileName);
// Painting
Painting.Color := ReadIniInteger(Section, 'Color', integer(clBtnFace), IniFile);
Selection.Color := ReadIniInteger(Section, 'SelectionColor', integer(clWhite), IniFile);
Painting.ColorBorderTop := ReadIniInteger(Section, 'ColorBorderTop', integer(clWhite), IniFile);
Painting.ColorBorderBottom := ReadIniInteger(Section, 'ColorBorderBottom', integer(clBtnShadow), IniFile);
Painting.Bevel := aEditorBevels[ReadIniInteger(Section, 'PaintingBevel', 1, IniFile)];
Selection.Border.Bevel := aEditorBevels[ReadIniInteger(Section, 'PaintingBevelHot', 1, IniFile)];
// Shadow
Shadow.Color := ReadIniInteger(Section, 'ShadowColor', integer(clBlack), IniFile);
Shadow.Enabled := sStoreUtils.ReadIniString(Section, 'ShadowEnabled', IniFile) = 'True';
Shadow.Offset := ReadIniInteger(Section, 'ShadowOffset', 8, IniFile);
Shadow.Blur := ReadIniInteger(Section, 'ShadowBlur', 4, IniFile);
Shadow.Transparency := ReadIniInteger(Section, 'ShadowTransparency', 60, IniFile);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -