Componentes.Terceros.jvcl/official/3.36/design/JvDsgnEditors.pas
2009-02-27 12:23:32 +00:00

1332 lines
37 KiB
ObjectPascal

{-----------------------------------------------------------------------------
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: JvDsgnEditors.PAS, released on 2002-05-26.
The Initial Developer of the Original Code is Peter Thörnqvist [peter3 att users dott sourceforge dott net]
Portions created by Peter Thörnqvist are Copyright (C) 2002 Peter Thörnqvist.
All Rights Reserved.
Contributor(s):
Added editors for JvFooter and JvGroupHeader
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvDsgnEditors.pas 11830 2008-07-23 17:34:56Z obones $
unit JvDsgnEditors;
{$I jvcl.inc}
{$I crossplatform.inc}
interface
uses
Windows, Forms, Controls, Graphics, ExtCtrls, Dialogs,
ExtDlgs, Menus, StdCtrls, ImgList, Tabs,
ImgEdit, TypInfo, DsnConst,
{$IFDEF COMPILER6_UP}
RTLConsts, DesignIntf, DesignEditors, DesignMenus, VCLEditors,
FiltEdit,
{$ELSE}
LibIntf, DsgnIntf,
{$ENDIF COMPILER6_UP}
Classes, SysUtils;
type
// Special TJvPersistent property event editor, that show events along with all other properties
// This is only useful with version 5 and before --created by dejoy
{$IFNDEF COMPILER6_UP}
TGetPropProc = TGetPropEditProc;
TJvPersistentNestedElementEventProperty = class(TNestedProperty)
private
FParent: TPropertyEditor;
FPropInfo: PPropInfo;
FInstance: TPersistent;
function GetPersistentPropertyName: string;
function GetInstance: TPersistent;
protected
constructor Create(Parent: TPropertyEditor; APropInfo: PPropInfo); reintroduce;
function AllNamed: Boolean; virtual;
function GetTrimmedEventName: string;
function GetFormMethodName: string; virtual;
property Instance: TPersistent read GetInstance;
public
function AllEqual: Boolean; override;
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetName: string; override;
function GetValue: string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const AValue: string); override;
end;
{$ENDIF COMPILER6_UP}
{$IFDEF COMPILER6_UP}
// Special TJvPersistent property editor, that allow show event properties
// This is useful with version 5 and up --created by dejoy
TJvPersistentPropertyEditor = class(TComponentProperty)
{$ELSE}
TJvPersistentPropertyEditor = class(TClassProperty)
// Special TJvPersistent property editor, that show events along with all other properties
// This is only useful with version 5 and before --created by dejoy
{$ENDIF COMPILER6_UP}
private
FInstance: TPersistent;
protected
function GetInstance: TPersistent; virtual; //d5/d6
public
procedure Initialize; override; //d5/d6
procedure GetProperties(Proc: TGetPropProc); override; //d5
function GetValue: string; override; //d5/d6
property Instance: TPersistent read GetInstance;
end;
TJvHintProperty = class(TStringProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;
TJvFilenameProperty = class(TStringProperty)
protected
procedure OnDialogShow(Sender: TObject); virtual;
function GetFilter: string; virtual;
function GetOptions: TOpenOptions; virtual;
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
end;
TJvExeNameProperty = class(TJvFilenameProperty)
protected
function GetFilter: string; override;
end;
TJvDirectoryProperty = class(TStringProperty)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
end;
TJvStringsProperty = class(TStringProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;
TJvBasePropertyEditor = class(TDefaultEditor)
protected
{$IFDEF COMPILER6_UP}
procedure EditProperty(const Prop: IProperty; var Continue: Boolean); override;
{$ELSE}
procedure EditProperty(PropertyEditor: TPropertyEditor; var Continue, FreeEditor: Boolean); override;
{$ENDIF COMPILER6_UP}
function GetEditPropertyName: string; virtual; abstract;
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
TJvStringsEditor = class(TJvBasePropertyEditor)
protected
function GetEditPropertyName: string; override;
end;
TJvItemsEditor = class(TJvBasePropertyEditor)
protected
function GetEditPropertyName: string; override;
end;
TJvDateTimeExProperty = class(TDateTimeProperty)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
end;
TJvDateExProperty = class(TDateProperty)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
end;
TJvTimeExProperty = class(TTimeProperty)
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
end;
TJvShortCutProperty = class(TIntegerProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
function GetValue: string; override;
procedure SetValue(const Value: string); override;
end;
{$IFDEF COMPILER6_UP}
TJvDefaultImageIndexProperty = class(TIntegerProperty, ICustomPropertyDrawing, ICustomPropertyListDrawing)
protected
function ImageList: TCustomImageList; virtual;
public
function GetAttributes: TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
function GetValue: string; override;
procedure SetValue(const Value: string); override;
procedure ListMeasureWidth(const Value: string;
ACanvas: TCanvas; var AWidth: Integer); virtual;
procedure ListMeasureHeight(const Value: string;
ACanvas: TCanvas; var AHeight: Integer); virtual;
procedure ListDrawValue(const Value: string;
ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean); virtual;
procedure PropDrawName(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean);
procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean);
end;
{$ENDIF COMPILER6_UP}
{$IFDEF COMPILER5}
TJvDefaultImageIndexProperty = class(TIntegerProperty)
protected
function ImageList: TCustomImageList; virtual;
public
function GetValue: string; override;
procedure SetValue(const Value: string); override;
function GetAttributes: TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure ListMeasureWidth(const Value: string; ACanvas: TCanvas;
var AWidth: Integer); override;
procedure ListMeasureHeight(const Value: string; ACanvas: TCanvas;
var AHeight: Integer); override;
procedure ListDrawValue(const Value: string; ACanvas: TCanvas;
const ARect: TRect; ASelected: Boolean); override;
procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean); override;
end;
{$ENDIF COMPILER5}
TJvNosortEnumProperty = class(TEnumProperty)
public
function GetAttributes: TPropertyAttributes; override;
end;
TJvIntegerProperty = class(TIntegerProperty)
public
function GetValue: string; override;
procedure SetValue(const Value: string); override;
end;
TJvFloatProperty = class(TFloatProperty)
public
function GetValue: string; override;
procedure SetValue(const Value: string); override;
end;
TJvImageListEditor = class(TComponentEditor)
private
procedure SaveAsBitmap(ImageList: TImageList);
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
TJvWeekDayProperty = class(TEnumProperty)
function GetAttributes: TPropertyAttributes; override;
end;
TJvComponentFormProperty = class(TComponentProperty)
public
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
implementation
uses
Math, FileCtrl, Consts,
Registry,
Dlgs, JvDateTimeForm,
JvTypes, JvStringsForm, JvDsgnConsts, JvConsts;
function ValueName(E: Extended): string;
begin
if E = High(Integer) then
Result := RsMaxInt
else
if E = Low(Integer) then
Result := RsMinInt
else
if E = High(Longint) then
Result := RsMaxLong
else
if E = Low(Longint) then
Result := RsMinLong
else
if E = High(Shortint) then
Result := RsMaxShort
else
if E = Low(Shortint) then
Result :=RsMinShort
else
if E = High(Word) then
Result := RsMaxWord
else
Result := '';
end;
function StrToValue(const S: string): Longint;
begin
if CompareText(S, RsMaxLong) = 0 then
Result := High(Longint)
else
if CompareText(S, RsMinLong) = 0 then
Result := Low(Longint)
else
if CompareText(S, RsMaxInt) = 0 then
Result := High(Integer)
else
if CompareText(S, RsMinInt) = 0 then
Result := Low(Integer)
else
if CompareText(S, RsMaxShort) = 0 then
Result := High(Shortint)
else
if CompareText(S, RsMinShort) = 0 then
Result := Low(Shortint)
else
if CompareText(S, RsMaxWord) = 0 then
Result := High(Word)
else
Result := 0;
end;
{$IFNDEF COMPILER6_UP}
procedure JvPersistentEventProperty_GetProperties(APropertyEditor: TPropertyEditor;
AInstance: TPersistent; Proc: TGetPropProc);
var
APropList: TPropList;
I, ACount : Integer;
begin
if AInstance = nil then
Exit;
ACount := GetPropList(AInstance.ClassInfo, [tkMethod], @APropList);
for I := 0 to ACount - 1 do
Proc(TJvPersistentNestedElementEventProperty.Create(APropertyEditor, APropList[I]));
end;
//=== { TJvPersistentNestedElementEventProperty } ================================================
function TJvPersistentNestedElementEventProperty.AllEqual: Boolean;
var
I: Integer;
V, T: TMethod;
begin
Result := False;
if PropCount > 1 then
begin
V := GetMethodValue;
for I := 1 to PropCount - 1 do
begin
T := GetMethodValueAt(I);
if (T.Code <> V.Code) or (T.Data <> V.Data) then Exit;
end;
end;
Result := True;
end;
function TJvPersistentNestedElementEventProperty.AllNamed: Boolean;
var
I: Integer;
begin
Result := True;
for I := 0 to PropCount - 1 do
if GetComponent(I).GetNamePath = '' then
begin
Result := False;
Break;
end;
end;
function TJvPersistentNestedElementEventProperty.GetPersistentPropertyName: string;
begin
Result := '';
if FParent <> nil then
Result := FParent.GetName + Result;
end;
function TJvPersistentNestedElementEventProperty.GetInstance: TPersistent;
begin
if not Assigned(FInstance) then
begin
if FParent is TJvPersistentPropertyEditor then
FInstance := TJvPersistentPropertyEditor(FParent).Instance;
end;
Result := FInstance;
end;
constructor TJvPersistentNestedElementEventProperty.Create(Parent: TPropertyEditor;
APropInfo: PPropInfo);
begin
inherited Create(Parent);
FPropInfo := APropInfo;
FParent := Parent;
end;
procedure TJvPersistentNestedElementEventProperty.Edit;
var
FormMethodName: string;
begin
FormMethodName := GetValue;
if (FormMethodName = '') or
Designer.MethodFromAncestor(GetMethodValue) then
begin
if FormMethodName = '' then
FormMethodName := GetFormMethodName;
if FormMethodName = '' then
raise EPropertyError.Create(SCannotCreateName);
SetValue(FormMethodName);
end;
Designer.ShowMethod(FormMethodName);
end;
function TJvPersistentNestedElementEventProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paValueList, paSortList, paRevertable];
end;
function TJvPersistentNestedElementEventProperty.GetFormMethodName: string;
var
I: Integer;
begin
if GetComponent(0) = Designer.GetRoot then
begin
Result := Designer.GetRootClassName;
if (Result <> '') and (Result[1] = 'T') then
Delete(Result, 1, 1);
end
else
begin
Result := Designer.GetObjectName(GetComponent(0));
for I := Length(Result) downto 1 do
if Result[I] in ['.','[',']','-','>'] then
Delete(Result, I, 1);
end;
if Result = '' then
raise EPropertyError.CreateRes(@SCannotCreateName);
Result := Result + GetPersistentPropertyName + GetTrimmedEventName;
end;
function TJvPersistentNestedElementEventProperty.GetName: string;
begin
Result := FPropInfo.Name;
end;
function TJvPersistentNestedElementEventProperty.GetTrimmedEventName: string;
begin
Result := GetName;
if (Length(Result) >= 2) and
(Result[1] in ['O', 'o']) and (Result[2] in ['N', 'n']) then
Delete(Result,1,2);
end;
function TJvPersistentNestedElementEventProperty.GetValue: string;
begin
Result := Designer.GetMethodName(GetMethodProp(Instance, FPropInfo));
end;
procedure TJvPersistentNestedElementEventProperty.GetValues(Proc: TGetStrProc);
begin
Designer.GetMethods(GetTypeData(FPropInfo.PropType^), Proc);
end;
procedure TJvPersistentNestedElementEventProperty.SetValue(const AValue: string);
procedure CheckChainCall(const MethodName: string; Method: TMethod);
var
Persistent: TPersistent;
Component: TComponent;
InstanceMethod: string;
Instance: TComponent;
begin
Persistent := GetComponent(0);
if Persistent is TComponent then
begin
Component := TComponent(Persistent);
if (Component.Name <> '') and (Method.Data <> Designer.GetRoot) and
(TObject(Method.Data) is TComponent) then
begin
Instance := TComponent(Method.Data);
InstanceMethod := Instance.MethodName(Method.Code);
if InstanceMethod <> '' then
Designer.ChainCall(MethodName, Instance.Name, InstanceMethod,
GetTypeData(GetPropType));
end;
end;
end;
var
NewMethod: Boolean;
CurValue: string;
OldMethod: TMethod;
begin
CurValue:= GetValue;
if (CurValue <> '') and (AValue <> '') and ((CompareText(CurValue, AValue) = 0) or
not Designer.MethodExists(AValue)) and not Designer.MethodFromAncestor(GetMethodValue) then
Designer.RenameMethod(CurValue, AValue)
else
begin
NewMethod := (AValue <> '') and not Designer.MethodExists(AValue);
OldMethod := GetMethodValue;
SetMethodProp(Instance, FPropInfo,
Designer.CreateMethod(AValue, GetTypeData(FPropInfo.PropType^)));
if NewMethod then
begin
if (PropCount = 1) and (OldMethod.Data <> nil) and (OldMethod.Code <> nil) then
CheckChainCall(AValue, OldMethod);
Designer.ShowMethod(AValue);
end;
Designer.Modified;
end;
end;
//=== { TJvPersistentNestedElementEventProperty } ================================================
{$ENDIF COMPILER6_UP}
//=== { TJvPersistentPropertyEditor } ================================================
function TJvPersistentPropertyEditor.GetInstance: TPersistent;
var
LInstance: TPersistent;
LPersistentPropertyName: string;
begin
if not Assigned(FInstance) then
begin
LInstance := GetComponent(0);
LPersistentPropertyName := GetName;
if IsPublishedProp(LInstance, LPersistentPropertyName) then
begin
{$IFDEF COMPILER6_UP}
FInstance := TPersistent(GetObjectProp(LInstance, LPersistentPropertyName));
{$ELSE}
FInstance := TPersistent(GetOrdProp(LInstance, LPersistentPropertyName));
{$ENDIF COMPILER6_UP}
end;
end;
Result := FInstance;
end;
procedure TJvPersistentPropertyEditor.GetProperties(Proc: TGetPropProc);
{$IFNDEF COMPILER6_UP}
var
I: Integer;
Components: TDesignerSelectionList;
{$ENDIF COMPILER6_UP}
begin
{$IFNDEF COMPILER6_UP}
//Process show all Properties with event
Components := TDesignerSelectionList.Create;
try
for I := 0 to PropCount - 1 do
Components.Add(TComponent(GetOrdValueAt(I)));
GetComponentProperties(Components, tkProperties, Designer, Proc);
finally
Components.Free;
end;
//Process show event Properties
JvPersistentEventProperty_GetProperties(Self, Instance, Proc);
{$ELSE}
inherited;
{$ENDIF COMPILER6_UP}
end;
//Set property name in property editor procedure "Initialize" dynamically,
//Do't set property name in property constructor Create,that will raise a
//SDuplicateName error if
//you have more then one TJvPersistent property in a component.
//Like this 'A component named xx already exists'
procedure TJvPersistentPropertyEditor.Initialize;
var
LInstance: TPersistent;
LPersistentPropertyName: string;
begin
inherited Initialize;
LInstance := Instance;
LPersistentPropertyName := GetName;
if LInstance is TComponent then
begin
if (TComponent(LInstance).Name = '') and
(TComponent(LInstance).Name <> LPersistentPropertyName) then
begin
TComponent(LInstance).Name := LPersistentPropertyName;
end;
end else
if LInstance is TJvPersistent then
begin
if (TJvPersistent(LInstance).Name = '') and
(TJvPersistent(LInstance).Name <> LPersistentPropertyName) then
begin
TJvPersistent(LInstance).Name := LPersistentPropertyName;
end;
end;
end;
function TJvPersistentPropertyEditor.GetValue:string;
begin
FmtStr(Result, '(%s)', [GetPropType^.Name]);
end;
//=== { TJvPersistentPropertyEditor } ================================================
//=== { TJvFilenameProperty } ================================================
procedure TJvFilenameProperty.Edit;
begin
with TOpenDialog.Create(nil) do
try
FileName := GetStrValue;
Filter := GetFilter;
Options := GetOptions;
OnShow := OnDialogShow;
if Execute then
SetStrValue(FileName);
finally
Free;
end;
end;
function TJvFilenameProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paRevertable];
end;
function TJvFilenameProperty.GetFilter: string;
begin
Result := RsAllFilesFilter;
end;
function TJvFilenameProperty.GetOptions: TOpenOptions;
begin
Result := [ofHideReadOnly, ofEnableSizing];
end;
function TJvFilenameProperty.GetValue: string;
begin
Result := inherited GetValue;
if Result = '' then
Result := RsFileName;
end;
//=== { TJvDirectoryProperty } ===============================================
procedure TJvDirectoryProperty.Edit;
var
AName: string;
FolderName: THintString; // (ahuser) TCaption is "type Xxxstring", THintString is "Xxxstring"
C: TPersistent;
begin
C := GetComponent(0);
if C is TComponent then
AName := TComponent(C).Name
else
if C is TCollectionItem then
AName := TCollectionItem(C).GetNamePath
else
AName := C.ClassName;
if SelectDirectory(AName + '.' + GetName, '', FolderName) then
SetValue(FolderName);
end;
function TJvDirectoryProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paRevertable];
end;
function TJvDirectoryProperty.GetValue: string;
begin
Result := inherited GetValue;
if Result = '' then
Result := RsDirectory;
end;
//=== { TJvHintProperty } ====================================================
function TJvHintProperty.GetAttributes: TPropertyAttributes;
begin
Result := {inherited GetAttributes +} [paDialog];
end;
procedure TJvHintProperty.Edit;
var
Temp: string;
Comp: TPersistent;
begin
with TJvStrEditDlg.Create(Application) do
try
Comp := GetComponent(0);
if Comp is TComponent then
Caption := TComponent(Comp).Name + '.' + GetName
else
Caption := GetName;
Temp := GetStrValue;
Memo.Lines.Text := Temp;
UpdateStatus(nil);
if ShowModal = mrOk then
begin
Temp := Memo.Text;
while (Length(Temp) > 0) and (Temp[Length(Temp)] < ' ') do
System.Delete(Temp, Length(Temp), 1);
SetStrValue(Temp);
end;
finally
Free;
end;
end;
//=== { TJvStringsProperty } =================================================
procedure TJvStringsProperty.Edit;
var
Temp: string;
Comp: TPersistent;
begin
with TJvStrEditDlg.Create(Application) do
try
Comp := GetComponent(0);
if Comp is TComponent then
Caption := TComponent(Comp).Name + '.' + GetName
else
Caption := GetName;
Temp := GetStrValue;
Memo.Lines.Text := Temp;
UpdateStatus(nil);
if ShowModal = mrOk then
begin
Temp := Memo.Text;
while (Length(Temp) > 0) and (Temp[Length(Temp)] < ' ') do
System.Delete(Temp, Length(Temp), 1);
SetStrValue(Temp);
end;
finally
Free;
end;
end;
function TJvStringsProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paDialog, paRevertable];
end;
//=== { TJvBasePropertyEditor } ==============================================
{$IFDEF COMPILER6_UP}
procedure TJvBasePropertyEditor.EditProperty(const Prop: IProperty; var Continue: Boolean);
var
PropName: string;
begin
PropName := Prop.GetName;
if SameText(PropName, GetEditPropertyName) then
begin
Prop.Edit;
Continue := False;
end;
end;
{$ELSE}
procedure TJvBasePropertyEditor.EditProperty(PropertyEditor: TPropertyEditor; var Continue, FreeEditor: Boolean);
var
PropName: string;
begin
PropName := PropertyEditor.GetName;
if SameText(PropName, GetEditPropertyName) then
begin
PropertyEditor.Edit;
Continue := False;
end;
end;
{$ENDIF COMPILER6_UP}
procedure TJvBasePropertyEditor.ExecuteVerb(Index: Integer);
begin
if Index = 0 then
Edit
else
inherited ExecuteVerb(Index);
end;
function TJvBasePropertyEditor.GetVerb(Index: Integer): string;
begin
if Index = 0 then
Result := Format(RsFmtEditEllipsis, [GetEditPropertyName])
else
Result := '';
end;
function TJvBasePropertyEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
//=== { TJvDateTimeExProperty } ==============================================
procedure TJvDateTimeExProperty.Edit;
var
D: TDateTime;
begin
D := GetFloatValue;
if D = 0.0 then
D := Now;
if TFrmSelectDateTimeDlg.SelectDateTime(D, dstDateTime) then
begin
SetFloatValue(D);
Designer.Modified;
end;
end;
function TJvDateTimeExProperty.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paDialog];
end;
//=== { TJvDateExProperty } ==================================================
procedure TJvDateExProperty.Edit;
var
D: TDateTime;
begin
D := GetFloatValue;
if D = 0.0 then
D := Now;
if TFrmSelectDateTimeDlg.SelectDateTime(D, dstDate) then
begin
SetFloatValue(D);
Designer.Modified;
end;
end;
function TJvDateExProperty.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paDialog];
end;
//=== { TJvTimeExProperty } ==================================================
procedure TJvTimeExProperty.Edit;
var
D: TDateTime;
begin
D := GetFloatValue;
if D = 0.0 then
D := Now
else // (p3) we need the date part or we might get a "Must be in ShowCheckBox mode" error
D := SysUtils.Date + Frac(D);
if TFrmSelectDateTimeDlg.SelectDateTime(D, dstTime) then
begin
SetFloatValue(Frac(D)); // (p3) only return the time portion
Designer.Modified;
end;
end;
function TJvTimeExProperty.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paDialog];
end;
//=== { TJvDefaultImageIndexProperty } =======================================
{$IFDEF COMPILER6_UP}
function TJvDefaultImageIndexProperty.ImageList: TCustomImageList;
const
cImageList = 'ImageList';
cImages = 'Images';
begin
if TypInfo.GetPropInfo(GetComponent(0), cImageList) <> nil then
Result := TCustomImageList(TypInfo.GetObjectProp(GetComponent(0), cImageList))
else
if TypInfo.GetPropInfo(GetComponent(0), cImages) <> nil then
Result := TCustomImageList(TypInfo.GetObjectProp(GetComponent(0), cImages))
else
Result := nil;
end;
function TJvDefaultImageIndexProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paMultiSelect, paRevertable];
end;
function TJvDefaultImageIndexProperty.GetValue: string;
begin
Result := IntToStr(GetOrdValue);
end;
procedure TJvDefaultImageIndexProperty.SetValue(const Value: string);
var
XValue: Integer;
begin
try
XValue := StrToInt(Value);
SetOrdValue(XValue);
except
inherited SetValue(Value);
end;
end;
procedure TJvDefaultImageIndexProperty.GetValues(Proc: TGetStrProc);
var
Tmp: TCustomImageList;
I: Integer;
begin
Tmp := ImageList;
if Assigned(Tmp) then
for I := 0 to Tmp.Count - 1 do
Proc(IntToStr(I));
end;
procedure TJvDefaultImageIndexProperty.ListMeasureWidth(const Value: string; ACanvas: TCanvas; var AWidth: Integer);
var
Tmp: TCustomImageList;
begin
Tmp := ImageList;
if Assigned(Tmp) then
AWidth := Tmp.Width + ACanvas.TextHeight(Value) + 4;
end;
procedure TJvDefaultImageIndexProperty.ListMeasureHeight(const Value: string; ACanvas: TCanvas; var AHeight: Integer);
var
Tmp: TCustomImageList;
begin
Tmp := ImageList;
if Assigned(Tmp) then
AHeight := Max(Tmp.Height + 2, ACanvas.TextHeight(Value) + 2);
end;
procedure TJvDefaultImageIndexProperty.ListDrawValue(const Value: string; ACanvas:
TCanvas; const ARect: TRect; ASelected: Boolean);
var
Tmp: TCustomImageList;
R: TRect;
begin
DefaultPropertyListDrawValue(Value, ACanvas, ARect, ASelected);
Tmp := ImageList;
if Tmp <> nil then
begin
R := ARect;
ACanvas.FillRect(ARect);
Tmp.Draw(ACanvas, ARect.Left, ARect.Top, StrToInt(Value));
OffsetRect(R, Tmp.Width + 2, 0);
DrawText(ACanvas.Handle, PChar(Value), -1, R, 0);
end;
end;
procedure TJvDefaultImageIndexProperty.PropDrawName(ACanvas: TCanvas;
const ARect: TRect; ASelected: Boolean);
begin
DefaultPropertyDrawName(Self, ACanvas, ARect);
end;
procedure TJvDefaultImageIndexProperty.PropDrawValue(ACanvas: TCanvas;
const ARect: TRect; ASelected: Boolean);
var
Tmp: TCustomImageList;
begin
Tmp := ImageList;
if (GetVisualValue <> '') and Assigned(Tmp) then
ListDrawValue(GetVisualValue, ACanvas, ARect, ASelected)
else
DefaultPropertyDrawValue(Self, ACanvas, ARect);
end;
{$ENDIF COMPILER6_UP}
{$IFDEF COMPILER5}
function TJvDefaultImageIndexProperty.ImageList: TCustomImageList;
const
cImageList = 'ImageList';
cImages = 'Images';
begin
if TypInfo.GetPropInfo(GetComponent(0), cImageList) <> nil then
Result := TCustomImageList(TypInfo.GetObjectProp(GetComponent(0), cImageList))
else
if TypInfo.GetPropInfo(GetComponent(0), cImages) <> nil then
Result := TCustomImageList(TypInfo.GetObjectProp(GetComponent(0), cImages))
else
Result := nil;
end;
function TJvDefaultImageIndexProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paMultiSelect, paRevertable];
end;
function TJvDefaultImageIndexProperty.GetValue: string;
begin
Result := IntToStr(GetOrdValue);
end;
procedure TJvDefaultImageIndexProperty.SetValue(const Value: string);
var
XValue: Integer;
begin
try
XValue := StrToInt(Value);
SetOrdValue(XValue);
except
inherited SetValue(Value);
end;
end;
procedure TJvDefaultImageIndexProperty.GetValues(Proc: TGetStrProc);
var
Tmp: TCustomImageList;
I: Integer;
begin
Tmp := ImageList;
if Assigned(Tmp) then
for I := 0 to Tmp.Count - 1 do
Proc(IntToStr(I));
end;
procedure TJvDefaultImageIndexProperty.ListDrawValue(const Value: string;
ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
var
Tmp: TCustomImageList;
R: TRect;
begin
inherited ListDrawValue(Value, ACanvas, ARect, ASelected);
Tmp := ImageList;
if Tmp <> nil then
begin
R := ARect;
ACanvas.FillRect(ARect);
Tmp.Draw(ACanvas, ARect.Left, ARect.Top, StrToInt(Value));
OffsetRect(R, Tmp.Width + 2, 0);
DrawText(ACanvas.Handle, PChar(Value), -1, R, 0);
end;
end;
procedure TJvDefaultImageIndexProperty.ListMeasureHeight(const Value: string;
ACanvas: TCanvas; var AHeight: Integer);
var
Tmp: TCustomImageList;
begin
Tmp := ImageList;
if Assigned(Tmp) then
AHeight := Max(Tmp.Height + 2, ACanvas.TextHeight(Value) + 2);
end;
procedure TJvDefaultImageIndexProperty.ListMeasureWidth(const Value: string;
ACanvas: TCanvas; var AWidth: Integer);
var
Tmp: TCustomImageList;
begin
Tmp := ImageList;
if Assigned(Tmp) then
AWidth := Tmp.Width + ACanvas.TextHeight(Value) + 4;
end;
procedure TJvDefaultImageIndexProperty.PropDrawValue(ACanvas: TCanvas;
const ARect: TRect; ASelected: Boolean);
begin
// if GetVisualValue <> '' then
// ListDrawValue(GetVisualValue, ACanvas, ARect, True)
// else
inherited PropDrawValue(ACanvas, ARect, ASelected);
end;
{$ENDIF COMPILER5}
//=== { TJvShortCutProperty } ================================================
function TJvShortCutProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paValueList, paMultiSelect, paRevertable];
end;
function TJvShortCutProperty.GetValue: string;
begin
try
Result := ShortCutToText(GetOrdValue);
if Result = '' then
Result := RsNone;
except
Result := inherited GetValue;
end;
end;
procedure TJvShortCutProperty.GetValues(Proc: TGetStrProc);
var
Key: Word;
Shift: TShiftState;
begin
Proc(RsNone);
Shift := [ssCtrl];
for Key := Ord('A') to Ord('Z') do
Proc(ShortCutToText(ShortCut(Key, Shift)));
Shift := [ssAlt, ssCtrl];
for Key := Ord('A') to Ord('Z') do
Proc(ShortCutToText(ShortCut(Key, Shift)));
Shift := [];
for Key := VK_F1 to VK_F10 do
Proc(ShortCutToText(ShortCut(Key, Shift)));
Shift := [ssCtrl];
for Key := VK_F1 to VK_F10 do
Proc(ShortCutToText(ShortCut(Key, Shift)));
Shift := [ssShift];
for Key := VK_F1 to VK_F10 do
Proc(ShortCutToText(ShortCut(Key, Shift)));
Shift := [ssShift, ssCtrl];
for Key := VK_F1 to VK_F10 do
Proc(ShortCutToText(ShortCut(Key, Shift)));
Shift := [ssShift, ssAlt, ssCtrl];
for Key := VK_F1 to VK_F10 do
Proc(ShortCutToText(ShortCut(Key, Shift)));
Proc(ShortCutToText(ShortCut(VK_INSERT, [])));
Proc(ShortCutToText(ShortCut(VK_INSERT, [ssShift])));
Proc(ShortCutToText(ShortCut(VK_INSERT, [ssCtrl])));
Proc(ShortCutToText(ShortCut(VK_DELETE, [])));
Proc(ShortCutToText(ShortCut(VK_DELETE, [ssShift])));
Proc(ShortCutToText(ShortCut(VK_DELETE, [ssCtrl])));
Proc(ShortCutToText(ShortCut(VK_BACK, [ssAlt])));
Proc(ShortCutToText(ShortCut(VK_BACK, [ssAlt, ssShift])));
end;
procedure TJvShortCutProperty.SetValue(const Value: string);
begin
try
SetOrdValue(TextToShortCut(Value));
except
inherited SetValue(Value);
end;
end;
//=== { TJvNosortEnumProperty } ==============================================
function TJvNosortEnumProperty.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes - [paSortList];
end;
procedure TJvFilenameProperty.OnDialogShow(Sender: TObject);
begin
SetDlgItemText(GetParent(TOpenDialog(Sender).Handle), chx1, PChar(RsStripFilePath));
end;
//=== { TJvExeNameProperty } =================================================
function TJvExeNameProperty.GetFilter: string;
begin
Result := RsExecutableFilesExeExeAllFiles;
end;
//=== { TJvIntegerProperty } =================================================
function TJvIntegerProperty.GetValue: string;
begin
Result := ValueName(GetOrdValue);
if Result = '' then
Result := IntToStr(GetOrdValue);
end;
procedure TJvIntegerProperty.SetValue(const Value: string);
var
L: Longint;
begin
L := StrToValue(Value);
if L = 0 then
L := StrToInt(Value);
inherited SetValue(IntToStr(L));
end;
//=== { TJvFloatProperty } ===================================================
function TJvFloatProperty.GetValue: string;
const
Precisions: array [TFloatType] of Integer = (7, 15, 18, 18, 18);
begin
Result := ValueName(GetFloatValue);
if Result = '' then
Result := FloatToStrF(GetFloatValue, ffGeneral,
Precisions[GetTypeData(GetPropType)^.FloatType], 0);
end;
procedure TJvFloatProperty.SetValue(const Value: string);
var
L: Longint;
begin
L := StrToValue(Value);
if L <> 0 then
SetFloatValue(L)
else
SetFloatValue(StrToFloat(Value));
end;
procedure TJvImageListEditor.SaveAsBitmap(ImageList: TImageList);
var
Bitmap: TBitmap;
SaveDlg: TOpenDialog;
I: Integer;
begin
if ImageList.Count > 0 then
begin
SaveDlg := TSavePictureDialog.Create(Application);
with SaveDlg do
try
Options := [ofHideReadOnly, ofOverwritePrompt];
DefaultExt := GraphicExtension(TBitmap);
Filter := GraphicFilter(TBitmap);
if Execute then
begin
Bitmap := TBitmap.Create;
try
with Bitmap do
begin
Width := ImageList.Width * ImageList.Count;
Height := ImageList.Height;
if ImageList.BkColor <> clNone then
Canvas.Brush.Color := ImageList.BkColor
else
Canvas.Brush.Color := clWindow;
Canvas.FillRect(Bounds(0, 0, Width, Height));
for I := 0 to ImageList.Count - 1 do
ImageList.Draw(Canvas, ImageList.Width * I, 0, I);
HandleType := bmDIB;
if PixelFormat in [pf15bit, pf16bit] then
try
PixelFormat := pf24bit;
except
end;
end;
Bitmap.SaveToFile(FileName);
finally
Bitmap.Free;
end;
end;
finally
Free;
end;
end
else
Beep;
end;
procedure TJvImageListEditor.ExecuteVerb(Index: Integer);
begin
{ The hard typecast to TImageList is necessary because EditImageList does
not want a TCustomImageList but the component could be one. This seems to
be ok because TListView.SmallImages is also a TCustomImageList and not a
TImageList. So the Component Editor for TCustomImageList must also use a
hard typecast. }
if Designer <> nil then
case Index of
0:
if EditImageList(TImageList(Component)) then
Designer.Modified;
1:
SaveAsBitmap(TImageList(Component));
end;
end;
function TJvImageListEditor.GetVerb(Index: Integer): string;
begin
case Index of
0:
Result := SImageListEditor;
1:
Result := RsSaveImageList;
else
Result := '';
end;
end;
function TJvImageListEditor.GetVerbCount: Integer;
begin
Result := 2;
end;
//=== { TJvWeekDayProperty } =================================================
function TJvWeekDayProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paValueList];
end;
//=== { TJvComponentFormProperty } ===========================================
procedure TJvComponentFormProperty.GetValues(Proc: TGetStrProc);
var
Form: TComponent;
begin
inherited GetValues(Proc);
Form := Designer.{$IFDEF COMPILER6_UP} Root {$ELSE} Form {$ENDIF};
if (Form is GetTypeData(GetPropType)^.ClassType) and (Form.Name <> '') then
Proc(Form.Name);
end;
procedure TJvComponentFormProperty.SetValue(const Value: string);
var
Component: TComponent;
Form: TComponent;
begin
Component := Designer.GetComponent(Value);
Form := Designer.{$IFDEF COMPILER6_UP} Root {$ELSE} Form {$ENDIF};
if ((Component = nil) or not (Component is GetTypeData(GetPropType)^.ClassType)) and
(CompareText(Form.Name, Value) = 0) then
begin
if not (Form is GetTypeData(GetPropType)^.ClassType) then
raise EPropertyError.CreateRes(@SInvalidPropertyValue);
SetOrdValue(Longint(Form));
end
else
inherited SetValue(Value);
end;
//=== { TJvStringsEditor } ===================================================
function TJvStringsEditor.GetEditPropertyName: string;
begin
Result := 'Strings';
end;
//=== { TJvItemsEditor } =====================================================
function TJvItemsEditor.GetEditPropertyName: string;
begin
Result := 'Items';
end;
end.