📄 vcleditors.pas
字号:
Monochrome := True;
Height := ImageList.Height;
Width := ImageList.Width;
end;
ImageList_Draw(ImageList.Handle, ImageIndex, Image.Canvas.Handle, 0, 0, ILD_NORMAL);
ImageList_Draw(ImageList.Handle, ImageIndex, Mask.Canvas.Handle, 0, 0, ILD_MASK);
//! Result.MaskHandle := Mask.ReleaseHandle;
except
Image.Free;
Mask.Free;
Image := nil;
Mask := nil;
raise;
end;
end;
begin
Result := ActionClass.Create(AOwner);
{ Attempt to find the first action with the same class Type as ActionClass in
the Resource component's resource stream, and use its property values as
our defaults. }
Res := nil;
for I := Low(ActionClasses) to High(ActionClasses) do
with ActionClasses[I] do
for J := Low(Actions) to High(Actions) do
if Actions[J].ActionClass = ActionClass then
begin
Res := Resource;
Break;
end;
if Res <> nil then
begin
Instance := Res.Create(nil);
try
Action := FindComponentByClass(Instance, ActionClass.ClassName) as TBasicAction;
if Action <> nil then
begin
with Action as TCustomAction do
begin
TCustomAction(Result).Caption := Caption;
TCustomAction(Result).Checked := Checked;
TCustomAction(Result).Enabled := Enabled;
TCustomAction(Result).HelpContext := HelpContext;
TCustomAction(Result).Hint := Hint;
TCustomAction(Result).ImageIndex := ImageIndex;
TCustomAction(Result).ShortCut := ShortCut;
TCustomAction(Result).Visible := Visible;
if (ImageIndex > -1) and (ActionList <> nil) and
(ActionList.Images <> nil) then
begin
THackAction(Result).FImage.Free;
THackAction(Result).FMask.Free;
CreateMaskedBmp(ActionList.Images, ImageIndex,
Graphics.TBitmap(THackAction(Result).FImage),
Graphics.TBitmap(THackAction(Result).FMask));
end;
end;
end;
finally
Instance.Free;
end;
end;
end;
const
{ context ids for the Font editor and the Color Editor, etc. }
hcDFontEditor = 25000;
hcDColorEditor = 25010;
hcDMediaPlayerOpen = 25020;
function GetDisplayValue(const Prop: IProperty): string;
begin
Result := '';
if Assigned(Prop) and Prop.AllEqual then
Result := Prop.GetValue;
end;
procedure DefaultPropertyDrawName(Prop: TPropertyEditor; Canvas: TCanvas;
const Rect: TRect);
begin
Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Prop.GetName);
end;
procedure DefaultPropertyDrawValue(Prop: TPropertyEditor; Canvas: TCanvas;
const Rect: TRect);
begin
Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Prop.GetVisualValue);
end;
procedure DefaultPropertyListDrawValue(const Value: string; Canvas: TCanvas;
const Rect: TRect; Selected: Boolean);
begin
Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Value);
end;
{ TFontNameProperty }
{ Owner draw code has been commented out, see the interface section's for info. }
function TFontNameProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paValueList, paSortList, paRevertable];
end;
procedure TFontNameProperty.GetValues(Proc: TGetStrProc);
var
I: Integer;
begin
for I := 0 to Screen.Fonts.Count - 1 do Proc(Screen.Fonts[I]);
end;
procedure TFontNameProperty.ListDrawValue(const Value: string;
ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
var
OldFontName: string;
begin
if FontNamePropertyDisplayFontNames then
with ACanvas do
begin
// save off things
OldFontName := Font.Name;
// set things up and do work
Font.Name := Value;
TextRect(ARect, ARect.Left + 2, ARect.Top + 1, Value);
// restore things
Font.Name := OldFontName;
end
else
DefaultPropertyListDrawValue(Value, ACanvas, ARect, ASelected);
end;
procedure TFontNameProperty.ListMeasureHeight(const Value: string;
ACanvas: TCanvas; var AHeight: Integer);
var
OldFontName: string;
begin
if FontNamePropertyDisplayFontNames then
with ACanvas do
begin
// save off things
OldFontName := Font.Name;
// set things up and do work
Font.Name := Value;
AHeight := TextHeight(Value) + 2;
// restore things
Font.Name := OldFontName;
end;
end;
procedure TFontNameProperty.ListMeasureWidth(const Value: string;
ACanvas: TCanvas; var AWidth: Integer);
var
OldFontName: string;
begin
if FontNamePropertyDisplayFontNames then
with ACanvas do
begin
// save off things
OldFontName := Font.Name;
// set things up and do work
Font.Name := Value;
AWidth := TextWidth(Value) + 4;
// restore things
Font.Name := OldFontName;
end;
end;
{ TFontCharsetProperty }
function TFontCharsetProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paSortList, paValueList];
end;
function TFontCharsetProperty.GetValue: string;
begin
if not CharsetToIdent(TFontCharset(GetOrdValue), Result) then
FmtStr(Result, '%d', [GetOrdValue]);
end;
procedure TFontCharsetProperty.GetValues(Proc: TGetStrProc);
begin
GetCharsetValues(Proc);
end;
procedure TFontCharsetProperty.SetValue(const Value: string);
var
NewValue: Longint;
begin
if IdentToCharset(Value, NewValue) then
SetOrdValue(NewValue)
else inherited SetValue(Value);
end;
{ TImeNameProperty }
function TImeNameProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paSortList, paMultiSelect];
end;
procedure TImeNameProperty.GetValues(Proc: TGetStrProc);
var
I: Integer;
begin
for I := 0 to Screen.Imes.Count - 1 do Proc(Screen.Imes[I]);
end;
{ TMPFilenameProperty }
procedure TMPFilenameProperty.Edit;
var
MPFileOpen: TOpenDialog;
begin
MPFileOpen := TOpenDialog.Create(Application);
MPFileOpen.Filename := GetValue;
MPFileOpen.Filter := SMPOpenFilter;
MPFileOpen.HelpContext := hcDMediaPlayerOpen;
MPFileOpen.Options := MPFileOpen.Options + [ofShowHelp, ofPathMustExist,
ofFileMustExist];
try
if MPFileOpen.Execute then SetValue(MPFileOpen.Filename);
finally
MPFileOpen.Free;
end;
end;
function TMPFilenameProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paRevertable];
end;
{ TColorProperty }
procedure TColorProperty.Edit;
var
ColorDialog: TColorDialog;
IniFile: TRegIniFile;
procedure GetCustomColors;
begin
if BaseRegistryKey = '' then Exit;
IniFile := TRegIniFile.Create(BaseRegistryKey);
try
IniFile.ReadSectionValues(SCustomColors, ColorDialog.CustomColors);
except
{ Ignore errors reading values }
end;
end;
procedure SaveCustomColors;
var
I, P: Integer;
S: string;
begin
if IniFile <> nil then
with ColorDialog do
for I := 0 to CustomColors.Count - 1 do
begin
S := CustomColors.Strings[I];
P := Pos('=', S);
if P <> 0 then
begin
S := Copy(S, 1, P - 1);
IniFile.WriteString(SCustomColors, S,
CustomColors.Values[S]);
end;
end;
end;
begin
IniFile := nil;
ColorDialog := TColorDialog.Create(Application);
try
GetCustomColors;
ColorDialog.Color := GetOrdValue;
ColorDialog.HelpContext := hcDColorEditor;
ColorDialog.Options := [cdShowHelp];
if ColorDialog.Execute then SetOrdValue(ColorDialog.Color);
SaveCustomColors;
finally
IniFile.Free;
ColorDialog.Free;
end;
end;
function TColorProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paDialog, paValueList, paRevertable];
end;
function TColorProperty.GetValue: string;
begin
Result := ColorToString(TColor(GetOrdValue));
end;
procedure TColorProperty.GetValues(Proc: TGetStrProc);
begin
GetColorValues(Proc);
end;
procedure TColorProperty.PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean);
begin
if GetVisualValue <> '' then
ListDrawValue(GetVisualValue, ACanvas, ARect, True{ASelected})
else
DefaultPropertyDrawValue(Self, ACanvas, ARect);
end;
procedure TColorProperty.ListDrawValue(const Value: string; ACanvas: TCanvas;
const ARect: TRect; ASelected: Boolean);
function ColorToBorderColor(AColor: TColor): TColor;
type
TColorQuad = record
Red,
Green,
Blue,
Alpha: Byte;
end;
begin
if (TColorQuad(AColor).Red > 192) or
(TColorQuad(AColor).Green > 192) or
(TColorQuad(AColor).Blue > 192) then
Result := clBlack
else if ASelected then
Result := clWhite
else
Result := AColor;
end;
var
Right: Integer;
OldPenColor, OldBrushColor: TColor;
begin
Right := (ARect.Bottom - ARect.Top) {* 2} + ARect.Left;
with ACanvas do
begin
// save off things
OldPenColor := Pen.Color;
OldBrushColor := Brush.Color;
// frame things
Pen.Color := Brush.Color;
Rectangle(ARect.Left, ARect.Top, Right, ARect.Bottom);
// set things up and do the work
Brush.Color := StringToColor(Value);
Pen.Color := ColorToBorderColor(ColorToRGB(Brush.Color));
Rectangle(ARect.Left + 1, ARect.Top + 1, Right - 1, ARect.Bottom - 1);
// restore the things we twiddled with
Brush.Color := OldBrushColor;
Pen.Color := OldPenColor;
DefaultPropertyListDrawValue(Value, ACanvas, Rect(Right, ARect.Top, ARect.Right,
ARect.Bottom), ASelected);
end;
end;
procedure TColorProperty.ListMeasureWidth(const Value: string;
ACanvas: TCanvas; var AWidth: Integer);
begin
AWidth := AWidth + ACanvas.TextHeight('M') {* 2};
end;
procedure TColorProperty.SetValue(const Value: string);
var
NewValue: Longint;
begin
if IdentToColor(Value, NewValue) then
SetOrdValue(NewValue)
else
inherited SetValue(Value);
end;
procedure TColorProperty.ListMeasureHeight(const Value: string;
ACanvas: TCanvas; var AHeight: Integer);
begin
// No implemenation necessary
end;
procedure TColorProperty.PropDrawName(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean);
begin
DefaultPropertyDrawName(Self, ACanvas, ARect);
end;
{ TBrushStyleProperty }
procedure TBrushStyleProperty.PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean);
begin
if GetVisualValue <> '' then
ListDrawValue(GetVisualValue, ACanvas, ARect, ASelected)
else
DefaultPropertyDrawValue(Self, ACanvas, ARect);
end;
procedure TBrushStyleProperty.ListDrawValue(const Value: string;
ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
var
Right: Integer;
OldPenColor, OldBrushColor: TColor;
OldBrushStyle: TBrushStyle;
begin
Right := (ARect.Bottom - ARect.Top) {* 2} + ARect.Left;
with ACanvas do
begin
// save off things
OldPenColor := Pen.Color;
OldBrushColor := Brush.Color;
OldBrushStyle := Brush.Style;
// frame things
Pen.Color := Brush.Color;
Brush.Color := clWindow;
Rectangle(ARect.Left, ARect.Top, Right, ARect.Bottom);
// set things up
Pen.Color := clWindowText;
Brush.Style := TBrushStyle(GetEnumValue(GetPropInfo^.PropType^, Value));
// bsClear hack
if Brush.Style = bsClear then
begin
Brush.Color := clWindow;
Brush.Style := bsSolid;
end
else
Brush.Color := clWindowText;
// ok on with the show
Rectangle(ARect.Left + 1, ARect.Top + 1, Right - 1, ARect.Bottom - 1);
// restore the things we twiddled with
Brush.Color := OldBrushColor;
Brush.Style := OldBrushStyle;
Pen.Color := OldPenColor;
DefaultPropertyListDrawValue(Value, ACanvas, Rect(Right, ARect.Top,
ARect.Right, ARect.Bottom), ASelected);
end;
end;
procedure TBrushStyleProperty.ListMeasureWidth(const Value: string;
ACanvas: TCanvas; var AWidth: Integer);
begin
AWidth := AWidth + ACanvas.TextHeight('A') {* 2};
end;
procedure TBrushStyleProperty.ListMeasureHeight(const Value: string;
ACanvas: TCanvas; var AHeight: Integer);
begin
// No implementation necessary
end;
procedure TBrushStyleProperty.PropDrawName(ACanvas: TCanvas;
const ARect: TRect; ASelected: Boolean);
begin
DefaultPropertyDrawName(Self, ACanvas, ARect);
end;
{ TPenStyleProperty }
procedure TPenStyleProperty.PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean);
begin
if GetVisualValue <> '' then
ListDrawValue(GetVisualValue, ACanvas, ARect, ASelected)
else
DefaultPropertyDrawValue(Self, ACanvas, ARect);
end;
procedure TPenStyleProperty.ListDrawValue(const Value: string;
ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
var
Right, Top: Integer;
OldPenColor, OldBrushColor: TColor;
OldPenStyle: TPenStyle;
begin
Right := (ARect.Bottom - ARect.Top) * 2 + ARect.Left;
Top := (ARect.Bottom - ARect.Top) div 2 + ARect.Top;
with ACanvas do
begin
// save off things
OldPenColor := Pen.Color;
OldBrushColor := Brush.Color;
OldPenStyle := Pen.Style;
// frame things
Pen.Color := Brush.Color;
Rectangle(ARect.Left, ARect.Top, Right, ARect.Bottom);
// white out the background
Pen.Color := clWindowText;
Brush.Color := clWindow;
Rectangle(ARect.Left + 1, ARect.Top + 1, Right - 1, ARect.Bottom - 1);
// set thing up and do work
Pen.Color := clWindowText;
Pen.Style := TPenStyle(GetEnumValue(GetPropInfo^.PropType^, Value));
MoveTo(ARect.Left + 1, Top);
LineTo(Right - 1, Top);
MoveTo(ARect.Left + 1, Top + 1);
LineTo(Right - 1, Top + 1);
// restore the things we twiddled with
Brush.Color := OldBrushColor;
Pen.Style := OldPenStyle;
Pen.Color := OldPenColor;
DefaultPropertyListDrawValue(Value, ACanvas, Rect(Right, ARect.Top,
ARect.Right, ARect.Bottom), ASelected);
end;
end;
procedure TPenStyleProperty.ListMeasureWidth(const Value: string;
ACanvas: TCanvas; var AWidth: Integer);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -