implemented default values for property editors and OI

git-svn-id: trunk@4978 -
This commit is contained in:
mattias 2003-12-27 19:34:13 +00:00
parent 8e542cff62
commit add918bbb0
5 changed files with 234 additions and 53 deletions

View File

@ -60,7 +60,7 @@ type
public
procedure Edit; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: ansistring; override;
function OrdValueToVisualValue(OrdValue: longint): string; override;
procedure GetValues(Proc: TGetStringProc); override;
procedure SetValue(const NewValue: ansistring); override;
procedure ListMeasureWidth(const CurValue:ansistring; Index:integer;
@ -82,12 +82,13 @@ type
TBrushStylePropertyEditor = class(TEnumPropertyEditor)
public
function GetAttributes: TPropertyAttributes; override;
procedure ListMeasureWidth(const CurValue: ansistring; Index:integer;
ACanvas: TCanvas; var AWidth: Integer); override;
procedure ListDrawValue(const CurValue: ansistring; Index:integer;
ACanvas: TCanvas; const ARect: TRect; AState: TPropEditDrawState); override;
procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
AState:TPropEditDrawState); override;
AState: TPropEditDrawState); override;
end;
{ TPenStylePropertyEditor
@ -95,6 +96,7 @@ type
TPenStylePropertyEditor = class(TEnumPropertyEditor)
public
function GetAttributes: TPropertyAttributes; override;
procedure ListMeasureWidth(const CurValue: ansistring; Index:integer;
ACanvas: TCanvas; var AWidth: Integer); override;
procedure ListDrawValue(const CurValue: ansistring; Index:integer;
@ -551,12 +553,12 @@ end;
function TColorPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paDialog, paValueList, paRevertable];
Result := [paMultiSelect,paDialog,paValueList,paRevertable,paHasDefaultValue];
end;
function TColorPropertyEditor.GetValue: ansistring;
function TColorPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
begin
Result := ColorToString(TColor(GetOrdValue));
Result := ColorToString(TColor(OrdValue));
end;
procedure TColorPropertyEditor.GetValues(Proc: TGetStringProc);
@ -732,6 +734,11 @@ begin
end;
end;
function TBrushStylePropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result:=(inherited GetAttributes)-[paHasDefaultValue];
end;
procedure TBrushStylePropertyEditor.ListMeasureWidth(const CurValue: ansistring;
Index:integer; ACanvas: TCanvas; var AWidth: Integer);
begin
@ -797,6 +804,11 @@ begin
end;
end;
function TPenStylePropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result:=(inherited GetAttributes)-[paHasDefaultValue];
end;
procedure TPenStylePropertyEditor.ListMeasureWidth(const CurValue: ansistring;
Index:integer; ACanvas: TCanvas; var AWidth: Integer);
begin

View File

@ -293,6 +293,9 @@ type
function GetRowByPath(const PropPath:string):TOIPropertyGridRow;
function MouseToIndex(y:integer;MustExist:boolean):integer;
function GetActiveRow: TOIPropertyGridRow;
procedure SetCurrentRowValue(const NewValue: string);
function CanEditRowValue: boolean;
property OnModified: TNotifyEvent read FOnModified write FOnModified;
procedure SetBounds(aLeft,aTop,aWidth,aHeight:integer); override;
@ -324,6 +327,7 @@ type
StatusBar: TStatusBar;
MainPopupMenu: TPopupMenu;
ColorsPopupMenuItem: TMenuItem;
SetDefaultPopupMenuItem: TMenuItem;
BackgroundColPopupMenuItem: TMenuItem;
ShowHintsPopupMenuItem: TMenuItem;
ShowComponentTreePopupMenuItem: TMenuItem;
@ -331,10 +335,12 @@ type
procedure AvailComboBoxCloseUp(Sender: TObject);
procedure ComponentTreeSelectionChanged(Sender: TObject);
procedure ObjectInspectorResize(Sender: TObject);
procedure OnBackgroundColPopupMenuItemClick(Sender :TObject);
procedure OnShowHintPopupMenuItemClick(Sender :TObject);
procedure OnShowOptionsPopupMenuItemClick(Sender :TObject);
procedure OnShowComponentTreePopupMenuItemClick(Sender :TObject);
procedure OnSetDefaultPopupmenuItemClick(Sender: TObject);
procedure OnBackgroundColPopupMenuItemClick(Sender: TObject);
procedure OnShowHintPopupMenuItemClick(Sender: TObject);
procedure OnShowOptionsPopupMenuItemClick(Sender: TObject);
procedure OnShowComponentTreePopupMenuItemClick(Sender: TObject);
procedure OnMainPopupMenuPopup(Sender: TObject);
procedure HookRefreshPropertyValues;
private
FComponentList: TComponentSelectionList;
@ -375,6 +381,9 @@ type
procedure FillComponentComboBox;
procedure BeginUpdate;
procedure EndUpdate;
function GetActivePropertyGrid: TOIPropertyGrid;
function GetActivePropertyRow: TOIPropertyGridRow;
function GetCurRowDefaultValue(var DefaultStr: string): boolean;
public
property DefaultItemHeight: integer read FDefaultItemHeight
write SetDefaultItemHeight;
@ -704,17 +713,7 @@ var
OldExpanded: boolean;
OldChangeStep: integer;
begin
if (FStates*[pgsChangingItemIndex,pgsApplyingValue]<>[])
or (FCurrentEdit=nil)
or (FItemIndex<0)
or (FItemIndex>=FRows.Count)
or ((FCurrentEditorLookupRoot<>nil)
and (FPropertyEditorHook<>nil)
and (FPropertyEditorHook.LookupRoot<>FCurrentEditorLookupRoot))
then begin
exit;
end;
if not CanEditRowValue then exit;
OldChangeStep:=fChangeStep;
CurRow:=Rows[FItemIndex];
if FCurrentEdit=ValueEdit then
@ -1153,6 +1152,39 @@ begin
end else Result:=-1;
end;
function TOIPropertyGrid.GetActiveRow: TOIPropertyGridRow;
begin
Result:=nil;
if ItemIndex<0 then exit;
Result:=Rows[ItemIndex];
end;
procedure TOIPropertyGrid.SetCurrentRowValue(const NewValue: string);
begin
if not CanEditRowValue then exit;
if FCurrentEdit is TComboBox then
TComboBox(FCurrentEdit).Text:=NewValue
else if FCurrentEdit is TEdit then
TEdit(FCurrentEdit).Text:=NewValue;
SetRowValue;
end;
function TOIPropertyGrid.CanEditRowValue: boolean;
begin
if (FStates*[pgsChangingItemIndex,pgsApplyingValue]<>[])
or (FCurrentEdit=nil)
or (FItemIndex<0)
or (FItemIndex>=FRows.Count)
or ((FCurrentEditorLookupRoot<>nil)
and (FPropertyEditorHook<>nil)
and (FPropertyEditorHook.LookupRoot<>FCurrentEditorLookupRoot))
then begin
Result:=false;
end else begin
Result:=true;
end;
end;
procedure TOIPropertyGrid.MouseDown(Button:TMouseButton; Shift:TShiftState;
X,Y:integer);
begin
@ -2126,7 +2158,7 @@ end;
constructor TObjectInspector.Create(AnOwner: TComponent);
procedure AddPopupMenuItem(var NewMenuItem: TmenuItem;
procedure AddPopupMenuItem(var NewMenuItem: TMenuItem;
ParentMenuItem: TMenuItem; const AName, ACaption, AHint: string;
AnOnClick: TNotifyEvent; CheckedFlag, EnabledFlag, VisibleFlag: boolean);
begin
@ -2146,6 +2178,23 @@ constructor TObjectInspector.Create(AnOwner: TComponent);
MainPopupMenu.Items.Add(NewMenuItem);
end;
procedure AddSeparatorMenuItem(ParentMenuItem: TMenuItem;
const AName: string; VisibleFlag: boolean);
var
NewMenuItem: TMenuItem;
begin
NewMenuItem:=TMenuItem.Create(Self);
with NewMenuItem do begin
Name:=AName;
Caption:='-';
Visible:=VisibleFlag;
end;
if ParentMenuItem<>nil then
ParentMenuItem.Add(NewMenuItem)
else
MainPopupMenu.Items.Add(NewMenuItem);
end;
begin
inherited Create(AnOwner);
Caption := oisObjectInspector;
@ -2171,9 +2220,14 @@ begin
MainPopupMenu:=TPopupMenu.Create(Self);
with MainPopupMenu do begin
Name:='MainPopupMenu';
OnPopup:=@OnMainPopupMenuPopup;
AutoPopup:=true;
end;
AddPopupMenuItem(ColorsPopupmenuItem,nil,'ColorsPopupMenuItem','Colors',''
AddPopupMenuItem(SetDefaultPopupmenuItem,nil,'SetDefaultPopupMenuItem',
'Set to Default Value','Set property value to Default',
@OnSetDefaultPopupmenuItemClick,false,true,true);
AddSeparatorMenuItem(nil,'OptionsSeparatorMenuItem',true);
AddPopupMenuItem(ColorsPopupmenuItem,nil,'ColorsPopupMenuItem','Set Colors',''
,nil,false,true,true);
AddPopupMenuItem(BackgroundColPopupMenuItem,ColorsPopupMenuItem
,'BackgroundColPopupMenuItem','Background','Grid background color'
@ -2379,6 +2433,43 @@ begin
end;
end;
function TObjectInspector.GetActivePropertyGrid: TOIPropertyGrid;
begin
Result:=nil;
if NoteBook=nil then exit;
if NoteBook.PageIndex=0 then
Result:=PropertyGrid
else if NoteBook.PageIndex=1 then
Result:=EventGrid;
end;
function TObjectInspector.GetActivePropertyRow: TOIPropertyGridRow;
var
CurGrid: TOIPropertyGrid;
begin
Result:=nil;
CurGrid:=GetActivePropertyGrid;
if CurGrid=nil then exit;
Result:=CurGrid.GetActiveRow;
end;
function TObjectInspector.GetCurRowDefaultValue(var DefaultStr: string): boolean;
var
CurRow: TOIPropertyGridRow;
begin
Result:=false;
DefaultStr:='';
CurRow:=GetActivePropertyRow;
if (CurRow=nil) or (not (paHasDefaultValue in CurRow.Editor.GetAttributes))
then exit;
try
DefaultStr:=CurRow.Editor.GetDefaultValue;
Result:=true;
except
DefaultStr:='';
end;
end;
procedure TObjectInspector.SetSelections(
const NewSelections:TComponentSelectionList);
begin
@ -2468,6 +2559,18 @@ begin
ComponentTree.Height:=ClientHeight div 4;
end;
procedure TObjectInspector.OnSetDefaultPopupmenuItemClick(Sender: TObject);
var
CurGrid: TOIPropertyGrid;
DefaultStr: string;
begin
if not GetCurRowDefaultValue(DefaultStr) then exit;
CurGrid:=GetActivePropertyGrid;
if CurGrid=nil then exit;
CurGrid.SetCurrentRowValue(DefaultStr);
RefreshPropertyValues;
end;
procedure TObjectInspector.OnBackgroundColPopupMenuItemClick(Sender :TObject);
var ColorDialog:TColorDialog;
begin
@ -2656,6 +2759,17 @@ begin
ShowComponentTree:=not ShowComponentTree;
end;
procedure TObjectInspector.OnMainPopupMenuPopup(Sender: TObject);
var
DefaultStr: String;
begin
SetDefaultPopupMenuItem.Enabled:=GetCurRowDefaultValue(DefaultStr);
if SetDefaultPopupMenuItem.Enabled then
SetDefaultPopupMenuItem.Caption:='Set to default: '+DefaultStr
else
SetDefaultPopupMenuItem.Caption:='Set to default value';
end;
procedure TObjectInspector.HookRefreshPropertyValues;
begin
RefreshPropertyValues;

View File

@ -249,7 +249,8 @@ type
paVolatileSubProperties,
paDisableSubProperties,
paReference,
paNotNestable
paNotNestable,
paHasDefaultValue
);
TPropertyAttributes=set of TPropertyAttribute;
@ -273,7 +274,7 @@ type
TPropertyEditor=class
private
FComponents:TComponentSelectionList;
FComponents: TComponentSelectionList;
FOnSubPropertiesChanged: TNotifyEvent;
FPropertyHook: TPropertyEditorHook;
FPropCount: Integer;
@ -289,6 +290,7 @@ type
function GetMethodValueAt(Index:Integer):TMethod;
function GetOrdValue:Longint;
function GetOrdValueAt(Index:Integer):Longint;
function GetDefaultOrdValue:Longint;
function GetStrValue:AnsiString;
function GetStrValueAt(Index:Integer):AnsiString;
function GetVarValue:Variant;
@ -318,10 +320,11 @@ type
procedure GetProperties(Proc: TGetPropEditProc); virtual;
function GetPropType: PTypeInfo;
function GetValue: ansistring; virtual;
function GetDefaultValue: ansistring; virtual;
function GetVisualValue: ansistring;
procedure GetValues(Proc: TGetStringProc); virtual;
procedure Initialize; virtual;
procedure Revert;
procedure Revert; virtual;
procedure SetValue(const NewValue:ansistring); virtual;
procedure SetPropEntry(Index: Integer; AnInstance: TPersistent;
APropInfo: PPropInfo);
@ -353,11 +356,16 @@ type
{ TOrdinalPropertyEditor
The base class of all ordinal property editors. It establishes that ordinal
properties are all equal if the GetOrdValue all return the same value. }
properties are all equal if the GetOrdValue all return the same value and
provide methods to retrieve the default value. }
TOrdinalPropertyEditor = class(TPropertyEditor)
function AllEqual: Boolean; override;
function GetEditLimit: Integer; override;
function GetAttributes: TPropertyAttributes; override;
function GetValue: ansistring; override;
function GetDefaultValue: ansistring; override;
function OrdValueToVisualValue(OrdValue: longint): string; virtual;
end;
{ TIntegerPropertyEditor
@ -367,7 +375,7 @@ type
TIntegerPropertyEditor = class(TOrdinalPropertyEditor)
public
function GetValue: ansistring; override;
function OrdValueToVisualValue(OrdValue: longint): string; override;
procedure SetValue(const NewValue: ansistring); override;
end;
@ -377,7 +385,7 @@ type
TCharPropertyEditor = class(TOrdinalPropertyEditor)
public
function GetValue: ansistring; override;
function OrdValueToVisualValue(OrdValue: longint): string; override;
procedure SetValue(const NewValue: ansistring); override;
end;
@ -388,7 +396,7 @@ type
TEnumPropertyEditor = class(TOrdinalPropertyEditor)
public
function GetAttributes: TPropertyAttributes; override;
function GetValue: ansistring; override;
function OrdValueToVisualValue(OrdValue: longint): string; override;
procedure GetValues(Proc: TGetStringProc); override;
procedure SetValue(const NewValue: ansistring); override;
end;
@ -397,7 +405,7 @@ type
Default property editor for all boolean properties }
TBoolPropertyEditor = class(TEnumPropertyEditor)
function GetValue: ansistring; override;
function OrdValueToVisualValue(OrdValue: longint): string; override;
procedure GetValues(Proc: TGetStringProc); override;
procedure SetValue(const NewValue: ansistring); override;
end;
@ -478,7 +486,7 @@ type
public
function GetAttributes: TPropertyAttributes; override;
procedure GetProperties(Proc: TGetPropEditProc); override;
function GetValue: AnsiString; override;
function OrdValueToVisualValue(OrdValue: longint): string; override;
end;
{ TClassPropertyEditor
@ -616,7 +624,7 @@ type
TShortCutPropertyEditor = class(TOrdinalPropertyEditor)
public
function GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
function OrdValueToVisualValue(OrdValue: longint): string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
@ -1973,6 +1981,19 @@ begin
with FPropList^[Index] do Result:=GetOrdProp(Instance,PropInfo);
end;
function TPropertyEditor.GetDefaultOrdValue: Longint;
var
APropInfo: PPropInfo;
begin
writeln('TPropertyEditor.GetDefaultOrdValue START ',ClassName);
APropInfo:=FPropList^[0].PropInfo;
{if HasAncestor then
Result:=GetOrdValue(Ancestor,APropInfo)
else}
Result:=APropInfo^.Default;
writeln('TPropertyEditor.GetDefaultOrdValue END ',Result);
end;
function TPropertyEditor.GetPrivateDirectory:ansistring;
begin
Result:='';
@ -2019,6 +2040,13 @@ begin
Result:=oisUnknown;
end;
function TPropertyEditor.GetDefaultValue: ansistring;
begin
if not (paHasDefaultValue in GetAttributes) then
raise EPropertyError.Create('No default property available');
Result:='';
end;
function TPropertyEditor.GetVisualValue:ansistring;
begin
if AllEqual then
@ -2325,19 +2353,40 @@ begin
Result := 63;
end;
function TOrdinalPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result:=(inherited GetAttributes)+[paHasDefaultValue];
end;
function TOrdinalPropertyEditor.GetValue: ansistring;
begin
Result:=OrdValueToVisualValue(GetOrdValue);
end;
function TOrdinalPropertyEditor.GetDefaultValue: ansistring;
begin
Result:=OrdValueToVisualValue(GetDefaultOrdValue);
end;
function TOrdinalPropertyEditor.OrdValueToVisualValue(OrdValue: longint
): string;
begin
Result:=IntToStr(OrdValue);
end;
{ TIntegerPropertyEditor }
function TIntegerPropertyEditor.GetValue: ansistring;
function TIntegerPropertyEditor.OrdValueToVisualValue(OrdValue: longint
): string;
begin
with GetTypeData(GetPropType)^ do
case OrdType of
otSByte : Result:= IntToStr(ShortInt(GetOrdValue));
otUByte : Result:= IntToStr(Byte(GetOrdValue));
otSWord : Result:= IntToStr(SmallInt(GetOrdValue));
otUWord : Result:= IntToStr(Word(GetOrdValue));
otULong : Result:= IntToStr(Cardinal(GetOrdValue));
else Result := IntToStr(GetOrdValue);
otSByte : Result:= IntToStr(ShortInt(OrdValue));
otUByte : Result:= IntToStr(Byte(OrdValue));
otSWord : Result:= IntToStr(SmallInt(OrdValue));
otUWord : Result:= IntToStr(Word(OrdValue));
otULong : Result:= IntToStr(Cardinal(OrdValue));
else Result := IntToStr(OrdValue);
end;
end;
@ -2371,11 +2420,11 @@ end;
{ TCharPropertyEditor }
function TCharPropertyEditor.GetValue: ansistring;
function TCharPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
var
Ch: Char;
begin
Ch := Chr(GetOrdValue);
Ch := Chr(OrdValue);
if Ch in [#33..#127] then
Result := Ch
else
@ -2405,14 +2454,14 @@ end;
function TEnumPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paValueList, paSortList, paRevertable];
Result:=[paMultiSelect,paValueList,paSortList,paRevertable,paHasDefaultValue];
end;
function TEnumPropertyEditor.GetValue: ansistring;
function TEnumPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
var
L: Longint;
begin
L := GetOrdValue;
L := OrdValue;
with GetTypeData(GetPropType)^ do
if (L < MinValue) or (L > MaxValue) then L := MaxValue;
Result := GetEnumName(GetPropType, L);
@ -2446,9 +2495,9 @@ end;
{ TBoolPropertyEditor }
function TBoolPropertyEditor.GetValue: ansistring;
function TBoolPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
begin
if GetOrdValue = 0 then
if OrdValue = 0 then
Result := 'False'
else
Result := 'True';
@ -2662,7 +2711,8 @@ end;
function TSetPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paSubProperties, paReadOnly, paRevertable];
Result := [paMultiSelect,paSubProperties,paReadOnly,paRevertable,
paHasDefaultValue];
end;
procedure TSetPropertyEditor.GetProperties(Proc: TGetPropEditProc);
@ -2674,13 +2724,13 @@ begin
Proc(TSetElementPropertyEditor.Create(Self, I));
end;
function TSetPropertyEditor.GetValue: ansistring;
function TSetPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
var
S: TIntegerSet;
TypeInfo: PTypeInfo;
I: Integer;
begin
Integer(S) := GetOrdValue;
Integer(S) := OrdValue;
TypeInfo := GetTypeData(GetPropType)^.CompType;
Result := '[';
for I := 0 to SizeOf(Integer) * 8 - 1 do
@ -3950,14 +4000,15 @@ const
function TShortCutPropertyEditor.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paValueList, paRevertable];
Result := [paMultiSelect, paValueList, paRevertable, paHasDefaultValue];
end;
function TShortCutPropertyEditor.GetValue: string;
function TShortCutPropertyEditor.OrdValueToVisualValue(OrdValue: longint
): string;
var
CurValue: TShortCut;
begin
CurValue := TShortCut(GetOrdValue);
CurValue := TShortCut(OrdValue);
if CurValue = scNone then
Result := '(None)'//srNone
else

View File

@ -442,6 +442,7 @@ type
property BorderStyle: TFormBorderStyle
read FBorderStyle write SetBorderStyle default bsSizeable;
property Caption stored IsForm;
property Color default clBtnFace;
property Designer: TIDesigner read FDesigner write SetDesigner;
property FormState: TFormState read FFormState;
property FormStyle: TFormStyle read FFormStyle write SetFormStyle

View File

@ -19,7 +19,7 @@
{------------------------------------------------------------------------------}
constructor TCustomGroupBox.Create(AOwner: TComponent);
begin
inherited Create (AOwner);
inherited Create(AOwner);
fCompStyle := csGroupBox;
ControlStyle := ControlStyle + [csAcceptsControls];
Width:= 185;
@ -35,6 +35,9 @@ end;
{
$Log$
Revision 1.10 2003/12/27 19:34:13 mattias
implemented default values for property editors and OI
Revision 1.9 2003/06/10 17:23:34 mattias
implemented tabstop