| [453] | 1 |  | 
|---|
|  | 2 | {*****************************************************************************} | 
|---|
|  | 3 | {                                                                             } | 
|---|
|  | 4 | {    Tnt Delphi Unicode Controls                                              } | 
|---|
|  | 5 | {      http://www.tntware.com/delphicontrols/unicode/                         } | 
|---|
|  | 6 | {        Version: 2.3.0                                                       } | 
|---|
|  | 7 | {                                                                             } | 
|---|
|  | 8 | {    Copyright (c) 2002-2007, Troy Wolbrink (troy.wolbrink@tntware.com)       } | 
|---|
|  | 9 | {                                                                             } | 
|---|
|  | 10 | {*****************************************************************************} | 
|---|
|  | 11 |  | 
|---|
|  | 12 | unit TntDesignEditors_Design; | 
|---|
|  | 13 |  | 
|---|
|  | 14 | {$INCLUDE ..\Source\TntCompilers.inc} | 
|---|
|  | 15 |  | 
|---|
|  | 16 | interface | 
|---|
|  | 17 |  | 
|---|
|  | 18 | uses | 
|---|
|  | 19 | Classes, Forms, TypInfo, DesignIntf, DesignEditors; | 
|---|
|  | 20 |  | 
|---|
|  | 21 | type | 
|---|
|  | 22 | ITntDesigner = IDesigner; | 
|---|
|  | 23 |  | 
|---|
|  | 24 | TTntDesignerSelections = class(TInterfacedObject, IDesignerSelections) | 
|---|
|  | 25 | private | 
|---|
|  | 26 | FList: TList; | 
|---|
|  | 27 | {$IFDEF COMPILER_9_UP} | 
|---|
|  | 28 | function GetDesignObject(Index: Integer): IDesignObject; | 
|---|
|  | 29 | {$ENDIF} | 
|---|
|  | 30 | protected | 
|---|
|  | 31 | function Add(const Item: TPersistent): Integer; | 
|---|
|  | 32 | function Equals(const List: IDesignerSelections): Boolean; | 
|---|
|  | 33 | function Get(Index: Integer): TPersistent; | 
|---|
|  | 34 | function GetCount: Integer; | 
|---|
|  | 35 | property Count: Integer read GetCount; | 
|---|
|  | 36 | property Items[Index: Integer]: TPersistent read Get; default; | 
|---|
|  | 37 | public | 
|---|
|  | 38 | constructor Create; virtual; | 
|---|
|  | 39 | destructor Destroy; override; | 
|---|
|  | 40 | procedure ReplaceSelection(const OldInst, NewInst: TPersistent); | 
|---|
|  | 41 | end; | 
|---|
|  | 42 |  | 
|---|
|  | 43 | function GetObjectInspectorForm: TCustomForm; | 
|---|
|  | 44 | procedure EditPropertyWithDialog(Component: TPersistent; const PropName: AnsiString; const Designer: ITntDesigner); | 
|---|
|  | 45 |  | 
|---|
|  | 46 | implementation | 
|---|
|  | 47 |  | 
|---|
|  | 48 | uses | 
|---|
|  | 49 | SysUtils; | 
|---|
|  | 50 |  | 
|---|
|  | 51 | { TTntDesignerSelections } | 
|---|
|  | 52 |  | 
|---|
|  | 53 | function TTntDesignerSelections.Add(const Item: TPersistent): Integer; | 
|---|
|  | 54 | begin | 
|---|
|  | 55 | Result := FList.Add(Item); | 
|---|
|  | 56 | end; | 
|---|
|  | 57 |  | 
|---|
|  | 58 | constructor TTntDesignerSelections.Create; | 
|---|
|  | 59 | begin | 
|---|
|  | 60 | inherited; | 
|---|
|  | 61 | FList := TList.Create; | 
|---|
|  | 62 | end; | 
|---|
|  | 63 |  | 
|---|
|  | 64 | destructor TTntDesignerSelections.Destroy; | 
|---|
|  | 65 | begin | 
|---|
|  | 66 | FList.Free; | 
|---|
|  | 67 | inherited; | 
|---|
|  | 68 | end; | 
|---|
|  | 69 |  | 
|---|
|  | 70 | function TTntDesignerSelections.Equals(const List: IDesignerSelections): Boolean; | 
|---|
|  | 71 | var | 
|---|
|  | 72 | I: Integer; | 
|---|
|  | 73 | begin | 
|---|
|  | 74 | Result := False; | 
|---|
|  | 75 | if List.Count <> Count then Exit; | 
|---|
|  | 76 | for I := 0 to Count - 1 do | 
|---|
|  | 77 | begin | 
|---|
|  | 78 | if Items[I] <> List[I] then Exit; | 
|---|
|  | 79 | end; | 
|---|
|  | 80 | Result := True; | 
|---|
|  | 81 | end; | 
|---|
|  | 82 |  | 
|---|
|  | 83 | function TTntDesignerSelections.Get(Index: Integer): TPersistent; | 
|---|
|  | 84 | begin | 
|---|
|  | 85 | Result := TPersistent(FList[Index]); | 
|---|
|  | 86 | end; | 
|---|
|  | 87 |  | 
|---|
|  | 88 | function TTntDesignerSelections.GetCount: Integer; | 
|---|
|  | 89 | begin | 
|---|
|  | 90 | Result := FList.Count; | 
|---|
|  | 91 | end; | 
|---|
|  | 92 |  | 
|---|
|  | 93 | {$IFDEF COMPILER_9_UP} | 
|---|
|  | 94 | function TTntDesignerSelections.GetDesignObject(Index: Integer): IDesignObject; | 
|---|
|  | 95 | begin | 
|---|
|  | 96 | Result := nil; {TODO: Figure out what IDesignerSelections.GetDesignObject is all about.  Must wait for more documentation!} | 
|---|
|  | 97 | end; | 
|---|
|  | 98 | {$ENDIF} | 
|---|
|  | 99 |  | 
|---|
|  | 100 | procedure TTntDesignerSelections.ReplaceSelection(const OldInst, NewInst: TPersistent); | 
|---|
|  | 101 | var | 
|---|
|  | 102 | Idx: Integer; | 
|---|
|  | 103 | begin | 
|---|
|  | 104 | Idx := FList.IndexOf(OldInst); | 
|---|
|  | 105 | if Idx <> -1 then | 
|---|
|  | 106 | FList[Idx] := NewInst; | 
|---|
|  | 107 | end; | 
|---|
|  | 108 |  | 
|---|
|  | 109 | {//------------------------------ | 
|---|
|  | 110 | //  Helpful discovery routines to explore the components and classes inside the IDE... | 
|---|
|  | 111 | // | 
|---|
|  | 112 | procedure EnumerateComponents(Comp: TComponent); | 
|---|
|  | 113 | var | 
|---|
|  | 114 | i: integer; | 
|---|
|  | 115 | begin | 
|---|
|  | 116 | for i := Comp.ComponentCount - 1 downto 0 do | 
|---|
|  | 117 | MessageBoxW(0, PWideChar(WideString(Comp.Components[i].Name + ': ' + Comp.Components[i].ClassName)), | 
|---|
|  | 118 | PWideChar(WideString(Comp.Name)), 0); | 
|---|
|  | 119 | end; | 
|---|
|  | 120 |  | 
|---|
|  | 121 | procedure EnumerateClasses(Comp: TComponent); | 
|---|
|  | 122 | var | 
|---|
|  | 123 | AClass: TClass; | 
|---|
|  | 124 | begin | 
|---|
|  | 125 | AClass := Comp.ClassType; | 
|---|
|  | 126 | repeat | 
|---|
|  | 127 | MessageBoxW(0, PWideChar(WideString(AClass.ClassName)), | 
|---|
|  | 128 | PWideChar(WideString(Comp.Name)), 0); | 
|---|
|  | 129 | AClass := Aclass.ClassParent; | 
|---|
|  | 130 | until AClass = nil; | 
|---|
|  | 131 | end; | 
|---|
|  | 132 | //------------------------------} | 
|---|
|  | 133 |  | 
|---|
|  | 134 | //------------------------------ | 
|---|
|  | 135 | function GetIdeMainForm: TCustomForm; | 
|---|
|  | 136 | var | 
|---|
|  | 137 | Comp: TComponent; | 
|---|
|  | 138 | begin | 
|---|
|  | 139 | Result := nil; | 
|---|
|  | 140 | if Application <> nil then begin | 
|---|
|  | 141 | Comp := Application.FindComponent('AppBuilder'); | 
|---|
|  | 142 | if Comp is TCustomForm then | 
|---|
|  | 143 | Result := TCustomForm(Comp); | 
|---|
|  | 144 | end; | 
|---|
|  | 145 | end; | 
|---|
|  | 146 |  | 
|---|
|  | 147 | function GetObjectInspectorForm: TCustomForm; | 
|---|
|  | 148 | var | 
|---|
|  | 149 | Comp: TComponent; | 
|---|
|  | 150 | IdeMainForm: TCustomForm; | 
|---|
|  | 151 | begin | 
|---|
|  | 152 | Result := nil; | 
|---|
|  | 153 | IdeMainForm := GetIdeMainForm; | 
|---|
|  | 154 | if IdeMainForm <> nil then begin | 
|---|
|  | 155 | Comp := IdeMainForm.FindComponent('PropertyInspector'); | 
|---|
|  | 156 | if Comp is TCustomForm then | 
|---|
|  | 157 | Result := TCustomForm(Comp); | 
|---|
|  | 158 | end; | 
|---|
|  | 159 | end; | 
|---|
|  | 160 |  | 
|---|
|  | 161 | { TPropertyEditorWithDialog } | 
|---|
|  | 162 | type | 
|---|
|  | 163 | TPropertyEditorWithDialog = class | 
|---|
|  | 164 | private | 
|---|
|  | 165 | FPropName: AnsiString; | 
|---|
|  | 166 | procedure CheckEditProperty(const Prop: IProperty); | 
|---|
|  | 167 | procedure EditProperty(Component: TPersistent; const PropName: AnsiString; const Designer: ITntDesigner); | 
|---|
|  | 168 | end; | 
|---|
|  | 169 |  | 
|---|
|  | 170 | procedure TPropertyEditorWithDialog.CheckEditProperty(const Prop: IProperty); | 
|---|
|  | 171 | begin | 
|---|
|  | 172 | if Prop.GetName = FPropName then | 
|---|
|  | 173 | Prop.Edit; | 
|---|
|  | 174 | end; | 
|---|
|  | 175 |  | 
|---|
|  | 176 | procedure TPropertyEditorWithDialog.EditProperty(Component: TPersistent; const PropName: AnsiString; const Designer: ITntDesigner); | 
|---|
|  | 177 | var | 
|---|
|  | 178 | Components: IDesignerSelections; | 
|---|
|  | 179 | begin | 
|---|
|  | 180 | FPropName := PropName; | 
|---|
|  | 181 | Components := TDesignerSelections.Create; | 
|---|
|  | 182 | Components.Add(Component); | 
|---|
|  | 183 | GetComponentProperties(Components, [tkClass], Designer, CheckEditProperty); | 
|---|
|  | 184 | end; | 
|---|
|  | 185 |  | 
|---|
|  | 186 | procedure EditPropertyWithDialog(Component: TPersistent; const PropName: AnsiString; const Designer: ITntDesigner); | 
|---|
|  | 187 | begin | 
|---|
|  | 188 | with TPropertyEditorWithDialog.Create do | 
|---|
|  | 189 | try | 
|---|
|  | 190 | EditProperty(Component, PropName, Designer); | 
|---|
|  | 191 | finally | 
|---|
|  | 192 | Free; | 
|---|
|  | 193 | end; | 
|---|
|  | 194 | end; | 
|---|
|  | 195 |  | 
|---|
|  | 196 | end. | 
|---|