[829] | 1 | unit VA508AccessibilityPE;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, SysUtils, DesignIntf, DesignEditors, DesignConst, TypInfo, Controls, StdCtrls,
|
---|
| 7 | Classes, Forms, VA508AccessibilityManager, Dialogs, ColnEdit, RTLConsts;
|
---|
| 8 |
|
---|
| 9 | type
|
---|
| 10 | TVA508AccessibilityManager4PE = class(TVA508AccessibilityManager);
|
---|
| 11 |
|
---|
| 12 | TVA508AccessibilityPropertyMapper = class(TStringProperty)
|
---|
| 13 | public
|
---|
| 14 | function GetAttributes: TPropertyAttributes; override;
|
---|
| 15 | procedure GetProperties(Proc: TGetPropProc); override;
|
---|
| 16 | end;
|
---|
| 17 |
|
---|
| 18 | TVA508NestedPropertyType = (ptText, ptLabel, ptProperty, ptDefault); //, ptEvent);
|
---|
| 19 |
|
---|
| 20 | TVA508NestedPropertyEditor = class(TNestedProperty)
|
---|
| 21 | strict private
|
---|
| 22 | FName: String;
|
---|
| 23 | FType: TVA508NestedPropertyType;
|
---|
| 24 | FManager: TVA508AccessibilityManager4PE;
|
---|
| 25 | protected
|
---|
| 26 | property Manager: TVA508AccessibilityManager4PE read FManager;
|
---|
| 27 | public
|
---|
| 28 | constructor Create(AParent: TVA508AccessibilityPropertyMapper;
|
---|
| 29 | AName: String; PType: TVA508NestedPropertyType);
|
---|
| 30 | function AllEqual: Boolean; override;
|
---|
| 31 | procedure Edit; override;
|
---|
| 32 | function GetEditLimit: Integer; override;
|
---|
| 33 | function GetAttributes: TPropertyAttributes; override;
|
---|
| 34 | function GetName: string; override;
|
---|
| 35 | function GetValue: string; override;
|
---|
| 36 | procedure GetValues(Proc: TGetStrProc); override;
|
---|
| 37 | procedure SetValue(const Value: string); override;
|
---|
| 38 | end;
|
---|
| 39 |
|
---|
| 40 | {
|
---|
| 41 | TVA508AccessibilityEventPropertyEditor = class(TVA508NestedPropertyEditor, IMethodProperty)
|
---|
| 42 | protected
|
---|
| 43 | function GetMethodValue(Index: Integer): TMethod;
|
---|
| 44 | public
|
---|
| 45 | function AllNamed: Boolean; virtual;
|
---|
| 46 | procedure Edit; override;
|
---|
| 47 | function GetValue: string; override;
|
---|
| 48 | procedure GetValues(Proc: TGetStrProc); override;
|
---|
| 49 | procedure SetValue(const AValue: string); override;
|
---|
| 50 | function GetFormMethodName: string; virtual;
|
---|
| 51 | function GetTrimmedEventName: string;
|
---|
| 52 | end;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | TVA508CollectionPropertyEditor = class(TCollectionProperty)
|
---|
| 56 | public
|
---|
| 57 | function GetColOptions: TColOptions; override;
|
---|
| 58 | end;
|
---|
| 59 |
|
---|
| 60 | TVA508AccessibilityLabelPropertyEditor = class(TComponentProperty)
|
---|
| 61 | private
|
---|
| 62 | FManager: TVA508AccessibilityManager4PE;
|
---|
| 63 | function GetManager: TVA508AccessibilityManager4PE;
|
---|
| 64 | public
|
---|
| 65 | function GetAttributes: TPropertyAttributes; override;
|
---|
| 66 | procedure GetProperties(Proc: TGetPropProc); override;
|
---|
| 67 | function GetValue: string; override;
|
---|
| 68 | procedure GetValues(Proc: TGetStrProc); override;
|
---|
| 69 | procedure SetValue(const Value: string); override;
|
---|
| 70 | end;
|
---|
| 71 |
|
---|
| 72 | TVA508AccessibilityPropertyPropertyEditor = class(TStringProperty)
|
---|
| 73 | private
|
---|
| 74 | FManager: TVA508AccessibilityManager4PE;
|
---|
| 75 | function GetManager: TVA508AccessibilityManager4PE;
|
---|
| 76 | function GetRootComponent(index: integer): TWinControl;
|
---|
| 77 | public
|
---|
| 78 | function AllEqual: Boolean; override;
|
---|
| 79 | function GetAttributes: TPropertyAttributes; override;
|
---|
| 80 | function GetEditLimit: Integer; override;
|
---|
| 81 | function GetValue: string; override;
|
---|
| 82 | procedure GetValues(Proc: TGetStrProc); override;
|
---|
| 83 | procedure SetValue(const Value: string); override;
|
---|
| 84 | end;
|
---|
| 85 |
|
---|
| 86 | TVA508AccessibilityComponentPropertyEditor = class(TComponentProperty)
|
---|
| 87 | public
|
---|
| 88 | function GetAttributes: TPropertyAttributes; override;
|
---|
| 89 | end;
|
---|
| 90 |
|
---|
| 91 | const
|
---|
| 92 | WinControlPropertyToMap = 'Hint';
|
---|
| 93 |
|
---|
| 94 | procedure Register;
|
---|
| 95 |
|
---|
| 96 | implementation
|
---|
| 97 |
|
---|
| 98 | function GetAccessibilityManager(Editor: TPropertyEditor; Index: integer): TVA508AccessibilityManager4PE;
|
---|
| 99 | var
|
---|
| 100 | Control, Root: TComponent;
|
---|
| 101 | i: integer;
|
---|
| 102 |
|
---|
| 103 | begin
|
---|
| 104 | Result := nil;
|
---|
| 105 | if assigned(Editor.GetComponent(Index)) and (Editor.GetComponent(Index) is TComponent) then
|
---|
| 106 | begin
|
---|
| 107 | Control := TComponent(Editor.GetComponent(Index));
|
---|
| 108 | Root := Control;
|
---|
| 109 | while (assigned(Root) and (not (Root is TCustomForm))) do
|
---|
| 110 | Root := Root.Owner;
|
---|
| 111 | if assigned(Root) and (Root is TCustomForm) then
|
---|
| 112 | begin
|
---|
| 113 | for i := 0 to Root.ComponentCount-1 do
|
---|
| 114 | begin
|
---|
| 115 | if Root.Components[i] is TVA508AccessibilityManager then
|
---|
| 116 | begin
|
---|
| 117 | Result := TVA508AccessibilityManager4PE(Root.Components[i]);
|
---|
| 118 | exit;
|
---|
| 119 | end;
|
---|
| 120 | end;
|
---|
| 121 | end;
|
---|
| 122 | end;
|
---|
| 123 | end;
|
---|
| 124 |
|
---|
| 125 | function AllComponentsHaveSameManager(Editor: TPropertyEditor): boolean;
|
---|
| 126 | var
|
---|
| 127 | i: integer;
|
---|
| 128 | manager: TVA508AccessibilityManager4PE;
|
---|
| 129 | begin
|
---|
| 130 | manager := GetAccessibilityManager(Editor, 0);
|
---|
| 131 | Result := assigned(manager);
|
---|
| 132 | if (not result) or (Editor.PropCount < 2) then exit;
|
---|
| 133 | for i := 1 to Editor.PropCount-1 do
|
---|
| 134 | begin
|
---|
| 135 | if (GetAccessibilityManager(Editor, i) <> manager) then
|
---|
| 136 | begin
|
---|
| 137 | Result := FALSE;
|
---|
| 138 | exit;
|
---|
| 139 | end;
|
---|
| 140 | end;
|
---|
| 141 | end;
|
---|
| 142 |
|
---|
| 143 | procedure GetStringPropertyNames(Manager: TVA508AccessibilityManager4PE;
|
---|
| 144 | Component: TWinControl; List: TStringList; Add: boolean);
|
---|
| 145 | var
|
---|
| 146 | i: Integer;
|
---|
| 147 | current: TStringList;
|
---|
| 148 |
|
---|
| 149 | begin
|
---|
| 150 | current := TStringList.Create;
|
---|
| 151 | try
|
---|
| 152 | Manager.GetProperties(Component, current);
|
---|
| 153 | if Add then
|
---|
| 154 | list.Assign(current)
|
---|
| 155 | else
|
---|
| 156 | begin
|
---|
| 157 | for I := List.Count - 1 downto 0 do
|
---|
| 158 | begin
|
---|
| 159 | if current.IndexOf(list[i]) < 0 then
|
---|
| 160 | List.Delete(i);
|
---|
| 161 | end;
|
---|
| 162 | end;
|
---|
| 163 | finally
|
---|
| 164 | current.Free;
|
---|
| 165 | end;
|
---|
| 166 | end;
|
---|
| 167 |
|
---|
| 168 | function QVal(txt: string): string;
|
---|
| 169 | begin
|
---|
| 170 | Result := '="' + txt + '"';
|
---|
| 171 | end;
|
---|
| 172 |
|
---|
| 173 | function StripQVal(text: string): string;
|
---|
| 174 | var
|
---|
| 175 | i: integer;
|
---|
| 176 | begin
|
---|
| 177 | i := pos('=', text);
|
---|
| 178 | if (i > 0) then
|
---|
| 179 | Result := copy(text,1,i-1)
|
---|
| 180 | else
|
---|
| 181 | Result := text;
|
---|
| 182 | end;
|
---|
| 183 |
|
---|
| 184 | { TVA508AccessibilityPropertyMapper }
|
---|
| 185 |
|
---|
| 186 | const
|
---|
| 187 | DelphiPaletteName = 'VA 508';
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 | function TVA508AccessibilityPropertyMapper.GetAttributes: TPropertyAttributes;
|
---|
| 191 | begin
|
---|
| 192 | if AllComponentsHaveSameManager(Self) then
|
---|
| 193 | Result := [paMultiSelect, paRevertable, paSubProperties]
|
---|
| 194 | else
|
---|
| 195 | Result := inherited GetAttributes;
|
---|
| 196 | end;
|
---|
| 197 |
|
---|
| 198 | procedure TVA508AccessibilityPropertyMapper.GetProperties(
|
---|
| 199 | Proc: TGetPropProc);
|
---|
| 200 | begin
|
---|
| 201 | if not AllComponentsHaveSameManager(Self) then exit;
|
---|
| 202 | Proc(TVA508NestedPropertyEditor.Create(Self, AccessibilityLabelPropertyName, ptLabel));
|
---|
| 203 | Proc(TVA508NestedPropertyEditor.Create(Self, AccessibilityPropertyPropertyName, ptProperty));
|
---|
| 204 | Proc(TVA508NestedPropertyEditor.Create(Self, AccessibilityTextPropertyName, ptText));
|
---|
| 205 | Proc(TVA508NestedPropertyEditor.Create(Self, AccessibilityUseDefaultPropertyName, ptDefault));
|
---|
| 206 | // Proc(TVA508AccessibilityEventPropertyEditor.Create(Self, AccessibilityEventPropertyName, ptEvent));
|
---|
| 207 | end;
|
---|
| 208 |
|
---|
| 209 | { TVA508NestedStringProperty }
|
---|
| 210 |
|
---|
| 211 | function TVA508NestedPropertyEditor.AllEqual: Boolean;
|
---|
| 212 | var
|
---|
| 213 | i: Integer;
|
---|
| 214 | txt, prop: string;
|
---|
| 215 | lbl: TLabel;
|
---|
| 216 | // V, T: TMethod;
|
---|
| 217 | default: boolean;
|
---|
| 218 |
|
---|
| 219 | begin
|
---|
| 220 | if PropCount > 1 then
|
---|
| 221 | begin
|
---|
| 222 | Result := False;
|
---|
| 223 | if not (GetComponent(0) is TWinControl) then exit;
|
---|
| 224 | case FType of
|
---|
| 225 | ptText:
|
---|
| 226 | begin
|
---|
| 227 | txt := FManager.AccessText[TWinControl(GetComponent(0))];
|
---|
| 228 | for i := 1 to PropCount - 1 do
|
---|
| 229 | if txt <> FManager.AccessText[TWinControl(GetComponent(i))] then exit;
|
---|
| 230 | end;
|
---|
| 231 |
|
---|
| 232 | ptLabel:
|
---|
| 233 | begin
|
---|
| 234 | lbl := FManager.AccessLabel[TWinControl(GetComponent(0))];
|
---|
| 235 | for i := 1 to PropCount - 1 do
|
---|
| 236 | if lbl <> FManager.AccessLabel[TWinControl(GetComponent(i))] then exit;
|
---|
| 237 | end;
|
---|
| 238 |
|
---|
| 239 | ptProperty:
|
---|
| 240 | begin
|
---|
| 241 | prop := FManager.AccessProperty[TWinControl(GetComponent(0))];
|
---|
| 242 | for i := 1 to PropCount - 1 do
|
---|
| 243 | if prop <> FManager.AccessProperty[TWinControl(GetComponent(i))] then exit;
|
---|
| 244 | end;
|
---|
| 245 |
|
---|
| 246 | ptDefault:
|
---|
| 247 | begin
|
---|
| 248 | default := FManager.UseDefault[TWinControl(GetComponent(0))];
|
---|
| 249 | for i := 1 to PropCount - 1 do
|
---|
| 250 | if default <> FManager.UseDefault[TWinControl(GetComponent(i))] then exit;
|
---|
| 251 | end;
|
---|
| 252 |
|
---|
| 253 |
|
---|
| 254 | { ptEvent:
|
---|
| 255 | begin
|
---|
| 256 | V := TMethod(FManager.OnComponentAccessRequest[TWinControl(GetComponent(0))]);
|
---|
| 257 | for i := 1 to PropCount - 1 do
|
---|
| 258 | begin
|
---|
| 259 | T := TMethod(FManager.OnComponentAccessRequest[TWinControl(GetComponent(i))]);
|
---|
| 260 | if (T.Code <> V.Code) or (T.Data <> V.Data) then Exit;
|
---|
| 261 | end;
|
---|
| 262 | end;}
|
---|
| 263 | end;
|
---|
| 264 | end;
|
---|
| 265 | Result := True;
|
---|
| 266 | end;
|
---|
| 267 |
|
---|
| 268 | constructor TVA508NestedPropertyEditor.Create(AParent: TVA508AccessibilityPropertyMapper;
|
---|
| 269 | AName: String; PType: TVA508NestedPropertyType);
|
---|
| 270 | begin
|
---|
| 271 | inherited Create(AParent);
|
---|
| 272 | FManager := GetAccessibilityManager(AParent, 0);
|
---|
| 273 | FName := AName;
|
---|
| 274 | FType := PType;
|
---|
| 275 | end;
|
---|
| 276 |
|
---|
| 277 | procedure TVA508NestedPropertyEditor.Edit;
|
---|
| 278 | var
|
---|
| 279 | lbl: TLabel;
|
---|
| 280 |
|
---|
| 281 | begin
|
---|
| 282 | if (FType = ptLabel) and
|
---|
| 283 | (Designer.GetShiftState * [ssCtrl, ssLeft] = [ssCtrl, ssLeft]) then
|
---|
| 284 | begin
|
---|
| 285 | lbl := FManager.AccessLabel[TWinControl(GetComponent(0))];
|
---|
| 286 | if assigned(lbl) then
|
---|
| 287 | Designer.SelectComponent(lbl)
|
---|
| 288 | else
|
---|
| 289 | inherited Edit;
|
---|
| 290 | end
|
---|
| 291 | else
|
---|
| 292 | inherited Edit;
|
---|
| 293 | end;
|
---|
| 294 |
|
---|
| 295 | function TVA508NestedPropertyEditor.GetAttributes: TPropertyAttributes;
|
---|
| 296 | begin
|
---|
| 297 | case FType of
|
---|
| 298 | ptText:
|
---|
| 299 | Result := [paMultiSelect, paRevertable, paAutoUpdate];
|
---|
| 300 | ptLabel, ptProperty:
|
---|
| 301 | Result := [paMultiSelect, paRevertable, paValueList, paSortList, paAutoUpdate];
|
---|
| 302 | ptDefault:
|
---|
| 303 | Result := [paMultiSelect, paValueList, paSortList, paRevertable];
|
---|
| 304 |
|
---|
| 305 | // ptEvent:
|
---|
| 306 | // Result := [paMultiSelect, paValueList, paSortList, paRevertable];
|
---|
| 307 | else
|
---|
| 308 | Result := [];
|
---|
| 309 | end;
|
---|
| 310 |
|
---|
| 311 | end;
|
---|
| 312 |
|
---|
| 313 | function TVA508NestedPropertyEditor.GetEditLimit: Integer;
|
---|
| 314 | begin
|
---|
| 315 | case FType of
|
---|
| 316 | ptText: Result := 32767;
|
---|
| 317 | ptDefault : Result := 63;
|
---|
| 318 | // ptEvent: Result := MaxIdentLength;
|
---|
| 319 | else // ptLabel, ptProperty:
|
---|
| 320 | Result := 127;
|
---|
| 321 | end;
|
---|
| 322 | end;
|
---|
| 323 |
|
---|
| 324 | function TVA508NestedPropertyEditor.GetName: string;
|
---|
| 325 | begin
|
---|
| 326 | Result := FName;
|
---|
| 327 | end;
|
---|
| 328 |
|
---|
| 329 | function TVA508NestedPropertyEditor.GetValue: string;
|
---|
| 330 | var
|
---|
| 331 | lbl: TLabel;
|
---|
| 332 | Default: boolean;
|
---|
| 333 | begin
|
---|
| 334 | Result := '';
|
---|
| 335 | if not (GetComponent(0) is TWinControl) then exit;
|
---|
| 336 | case FType of
|
---|
| 337 | ptLabel:
|
---|
| 338 | begin
|
---|
| 339 | lbl := FManager.AccessLabel[TWinControl(GetComponent(0))];
|
---|
| 340 | if assigned(lbl) then
|
---|
| 341 | Result := FManager.GetComponentName(lbl) + QVal(lbl.Caption);
|
---|
| 342 | end;
|
---|
| 343 | ptText:
|
---|
| 344 | Result := FManager.AccessText[TWinControl(GetComponent(0))];
|
---|
| 345 | ptProperty:
|
---|
| 346 | begin
|
---|
| 347 | Result := FManager.AccessProperty[TWinControl(GetComponent(0))];
|
---|
| 348 | if Result <> '' then
|
---|
| 349 | Result := Result + QVal(GetPropValue(GetComponent(0), Result));
|
---|
| 350 | end;
|
---|
| 351 | ptDefault:
|
---|
| 352 | begin
|
---|
| 353 | Default := FManager.UseDefault[TWinControl(GetComponent(0))];
|
---|
| 354 | Result := GetEnumName(TypeInfo(Boolean), Ord(Default));
|
---|
| 355 | end;
|
---|
| 356 | end;
|
---|
| 357 | end;
|
---|
| 358 |
|
---|
| 359 | procedure TVA508NestedPropertyEditor.GetValues(Proc: TGetStrProc);
|
---|
| 360 | var
|
---|
| 361 | list: TStringList;
|
---|
| 362 | i: integer;
|
---|
| 363 | name: string;
|
---|
| 364 |
|
---|
| 365 | begin
|
---|
| 366 | list := TStringList.Create;
|
---|
| 367 | try
|
---|
| 368 | case FType of
|
---|
| 369 | ptLabel:
|
---|
| 370 | begin
|
---|
| 371 | FManager.GetLabelStrings(list);
|
---|
| 372 | for i := 0 to list.count-1 do
|
---|
| 373 | Proc(list[i]);
|
---|
| 374 | end;
|
---|
| 375 |
|
---|
| 376 | ptProperty:
|
---|
| 377 | begin
|
---|
| 378 | GetStringPropertyNames(FManager, TWinControl(GetComponent(0)), list, TRUE);
|
---|
| 379 | if PropCount > 1 then
|
---|
| 380 | begin
|
---|
| 381 | for i := 1 to PropCount-1 do
|
---|
| 382 | begin
|
---|
| 383 | if GetComponent(i) is TWinControl then
|
---|
| 384 | GetStringPropertyNames(FManager, TWinControl(GetComponent(i)), list, FALSE);
|
---|
| 385 | end;
|
---|
| 386 | end;
|
---|
| 387 | list.Sort;
|
---|
| 388 | for i := 0 to list.count-1 do
|
---|
| 389 | begin
|
---|
| 390 | name := list[i];
|
---|
| 391 | if PropCount = 1 then
|
---|
| 392 | name := name + QVal(GetPropValue(GetComponent(0), name));
|
---|
| 393 | Proc(name);
|
---|
| 394 | end;
|
---|
| 395 | end;
|
---|
| 396 |
|
---|
| 397 | ptDefault:
|
---|
| 398 | begin
|
---|
| 399 | Proc(GetEnumName(TypeInfo(Boolean), Ord(False)));
|
---|
| 400 | Proc(GetEnumName(TypeInfo(Boolean), Ord(True)));
|
---|
| 401 | end;
|
---|
| 402 |
|
---|
| 403 | end;
|
---|
| 404 | finally
|
---|
| 405 | list.free;
|
---|
| 406 | end;
|
---|
| 407 | end;
|
---|
| 408 |
|
---|
| 409 | procedure TVA508NestedPropertyEditor.SetValue(const Value: string);
|
---|
| 410 | var
|
---|
| 411 | i, BVal: Integer;
|
---|
| 412 | lbl: TLabel;
|
---|
| 413 | cmp: TComponent;
|
---|
| 414 | Name: String;
|
---|
| 415 |
|
---|
| 416 | begin
|
---|
| 417 | BVal := Ord(FALSE);
|
---|
| 418 | lbl := nil;
|
---|
| 419 | case FType of
|
---|
| 420 |
|
---|
| 421 | ptLabel:
|
---|
| 422 | begin
|
---|
| 423 | Name := StripQVal(Value);
|
---|
| 424 | cmp := Designer.GetComponent(Name);
|
---|
| 425 | if (cmp is TLabel) then
|
---|
| 426 | lbl := TLabel(cmp);
|
---|
| 427 | end;
|
---|
| 428 |
|
---|
| 429 | ptProperty: Name := StripQVal(Value);
|
---|
| 430 |
|
---|
| 431 | ptDefault:
|
---|
| 432 | begin
|
---|
| 433 | BVal := GetEnumValue(TypeInfo(Boolean), Value);
|
---|
| 434 | with GetTypeData(TypeInfo(Boolean))^ do
|
---|
| 435 | if (BVal < MinValue) or (BVal > MaxValue) then
|
---|
| 436 | raise EPropertyError.CreateRes(@SInvalidPropertyValue);
|
---|
| 437 | end;
|
---|
| 438 |
|
---|
| 439 | end;
|
---|
| 440 | for i := 0 to PropCount - 1 do
|
---|
| 441 | begin
|
---|
| 442 | if GetComponent(i) is TWinControl then
|
---|
| 443 | begin
|
---|
| 444 | case FType of
|
---|
| 445 | ptText: FManager.AccessText[TWinControl(GetComponent(i))] := Value;
|
---|
| 446 | ptLabel: FManager.AccessLabel[TWinControl(GetComponent(i))] := lbl;
|
---|
| 447 | ptProperty: FManager.AccessProperty[TWinControl(GetComponent(i))] := Name;
|
---|
| 448 | ptDefault: FManager.UseDefault[TWinControl(GetComponent(i))] := Boolean(BVal);
|
---|
| 449 | end;
|
---|
| 450 | end;
|
---|
| 451 | end;
|
---|
| 452 | Modified;
|
---|
| 453 | end;
|
---|
| 454 |
|
---|
| 455 | (*
|
---|
| 456 | { TVA508AccessibilityEventPropertyEditor }
|
---|
| 457 |
|
---|
| 458 | function TVA508AccessibilityEventPropertyEditor.AllNamed: Boolean;
|
---|
| 459 | var
|
---|
| 460 | I: Integer;
|
---|
| 461 | begin
|
---|
| 462 | Result := True;
|
---|
| 463 | for I := 0 to PropCount - 1 do
|
---|
| 464 | if GetComponent(I).GetNamePath = '' then
|
---|
| 465 | begin
|
---|
| 466 | Result := False;
|
---|
| 467 | Break;
|
---|
| 468 | end;
|
---|
| 469 | end;
|
---|
| 470 |
|
---|
| 471 | procedure TVA508AccessibilityEventPropertyEditor.Edit;
|
---|
| 472 | var
|
---|
| 473 | FormMethodName: string;
|
---|
| 474 | CurDesigner: IDesigner;
|
---|
| 475 | begin
|
---|
| 476 | CurDesigner := Designer; { Local property so if designer is nil'ed out, no AV will happen }
|
---|
| 477 | if not AllNamed then
|
---|
| 478 | raise EPropertyError.CreateRes(@SCannotCreateName);
|
---|
| 479 | FormMethodName := GetValue;
|
---|
| 480 | if (FormMethodName = '') or
|
---|
| 481 | CurDesigner.MethodFromAncestor(GetMethodValue(0)) then
|
---|
| 482 | begin
|
---|
| 483 | if FormMethodName = '' then
|
---|
| 484 | FormMethodName := GetFormMethodName;
|
---|
| 485 | if FormMethodName = '' then
|
---|
| 486 | raise EPropertyError.CreateRes(@SCannotCreateName);
|
---|
| 487 | SetValue(FormMethodName);
|
---|
| 488 | end;
|
---|
| 489 | CurDesigner.ShowMethod(FormMethodName);
|
---|
| 490 | end;
|
---|
| 491 |
|
---|
| 492 | function TVA508AccessibilityEventPropertyEditor.GetFormMethodName: string;
|
---|
| 493 | var
|
---|
| 494 | I: Integer;
|
---|
| 495 | begin
|
---|
| 496 | if GetComponent(0) = Designer.GetRoot then
|
---|
| 497 | begin
|
---|
| 498 | Result := Designer.GetRootClassName;
|
---|
| 499 | if (Result <> '') and (Result[1] = 'T') then
|
---|
| 500 | Delete(Result, 1, 1);
|
---|
| 501 | end
|
---|
| 502 | else
|
---|
| 503 | begin
|
---|
| 504 | Result := Designer.GetObjectName(GetComponent(0));
|
---|
| 505 | for I := Length(Result) downto 1 do
|
---|
| 506 | if Result[I] in ['.', '[', ']', '-', '>'] then
|
---|
| 507 | Delete(Result, I, 1);
|
---|
| 508 | end;
|
---|
| 509 | if Result = '' then
|
---|
| 510 | raise EPropertyError.CreateRes(@SCannotCreateName);
|
---|
| 511 | Result := Result + GetTrimmedEventName;
|
---|
| 512 | end;
|
---|
| 513 |
|
---|
| 514 | function TVA508AccessibilityEventPropertyEditor.GetMethodValue(Index: Integer): TMethod;
|
---|
| 515 | begin
|
---|
| 516 | if not (GetComponent(Index) is TWinControl) then
|
---|
| 517 | begin
|
---|
| 518 | Result.Code := nil;
|
---|
| 519 | Result.Data := nil;
|
---|
| 520 | end
|
---|
| 521 | else
|
---|
| 522 | Result := TMethod(Manager.OnComponentAccessRequest[TWinControl(GetComponent(Index))]);
|
---|
| 523 | end;
|
---|
| 524 |
|
---|
| 525 | { TVA508AccessibilityEventPropertyEditor }
|
---|
| 526 |
|
---|
| 527 | function TVA508AccessibilityEventPropertyEditor.GetTrimmedEventName: string;
|
---|
| 528 | begin
|
---|
| 529 | Result := GetName;
|
---|
| 530 | if (Length(Result) >= 2) and
|
---|
| 531 | (Result[1] in ['O', 'o']) and (Result[2] in ['N', 'n']) then
|
---|
| 532 | Delete(Result,1,2);
|
---|
| 533 | end;
|
---|
| 534 |
|
---|
| 535 | function TVA508AccessibilityEventPropertyEditor.GetValue: string;
|
---|
| 536 | begin
|
---|
| 537 | Result := Designer.GetMethodName(GetMethodValue(0));
|
---|
| 538 | end;
|
---|
| 539 |
|
---|
| 540 | procedure TVA508AccessibilityEventPropertyEditor.GetValues(Proc: TGetStrProc);
|
---|
| 541 | begin
|
---|
| 542 | Designer.GetMethods(GetTypeData(TypeInfo(TVA508ComponentScreenReaderEvent)), Proc);
|
---|
| 543 | end;
|
---|
| 544 |
|
---|
| 545 | procedure TVA508AccessibilityEventPropertyEditor.SetValue(const AValue: string);
|
---|
| 546 |
|
---|
| 547 | var
|
---|
| 548 | CurDesigner: IDesigner;
|
---|
| 549 |
|
---|
| 550 | procedure CheckChainCall(const MethodName: string; Method: TMethod);
|
---|
| 551 | var
|
---|
| 552 | Persistent: TPersistent;
|
---|
| 553 | Component: TComponent;
|
---|
| 554 | InstanceMethod: string;
|
---|
| 555 | Instance: TComponent;
|
---|
| 556 | begin
|
---|
| 557 | Persistent := GetComponent(0);
|
---|
| 558 | if Persistent is TComponent then
|
---|
| 559 | begin
|
---|
| 560 | Component := TComponent(Persistent);
|
---|
| 561 | if (Component.Name <> '') and (Method.Data <> CurDesigner.GetRoot) and
|
---|
| 562 | (TObject(Method.Data) is TComponent) then
|
---|
| 563 | begin
|
---|
| 564 | Instance := TComponent(Method.Data);
|
---|
| 565 | InstanceMethod := Instance.MethodName(Method.Code);
|
---|
| 566 | if InstanceMethod <> '' then
|
---|
| 567 | CurDesigner.ChainCall(MethodName, Instance.Name, InstanceMethod,
|
---|
| 568 | GetTypeData(TypeInfo(TVA508ComponentScreenReaderEvent)));
|
---|
| 569 | end;
|
---|
| 570 | end;
|
---|
| 571 | end;
|
---|
| 572 |
|
---|
| 573 | var
|
---|
| 574 | NewMethod: Boolean;
|
---|
| 575 | CurValue: string;
|
---|
| 576 | OldMethod: TMethod;
|
---|
| 577 | i: integer;
|
---|
| 578 | event: TVA508ComponentScreenReaderEvent;
|
---|
| 579 | begin
|
---|
| 580 | CurDesigner := Designer;
|
---|
| 581 | if not AllNamed then
|
---|
| 582 | raise EPropertyError.CreateRes(@SCannotCreateName);
|
---|
| 583 | CurValue:= GetValue;
|
---|
| 584 | if (CurValue <> '') and (AValue <> '') and (SameText(CurValue, AValue) or
|
---|
| 585 | not CurDesigner.MethodExists(AValue)) and
|
---|
| 586 | not CurDesigner.MethodFromAncestor(GetMethodValue(0)) then
|
---|
| 587 | CurDesigner.RenameMethod(CurValue, AValue)
|
---|
| 588 | else
|
---|
| 589 | begin
|
---|
| 590 | NewMethod := (AValue <> '') and not CurDesigner.MethodExists(AValue);
|
---|
| 591 | OldMethod := GetMethodValue(0);
|
---|
| 592 | event := TVA508ComponentScreenReaderEvent(CurDesigner.CreateMethod(AValue, GetTypeData(TypeInfo(TVA508ComponentScreenReaderEvent))));
|
---|
| 593 | for i := 0 to PropCount - 1 do
|
---|
| 594 | begin
|
---|
| 595 | if (GetComponent(i) is TWinControl) then
|
---|
| 596 | Manager.OnComponentAccessRequest[TWinControl(GetComponent(i))] := event;
|
---|
| 597 | end;
|
---|
| 598 | if NewMethod then
|
---|
| 599 | begin
|
---|
| 600 | { Designer may have been nil'ed out this point when the code editor
|
---|
| 601 | recieved focus. This fixes an AV by using a local variable which
|
---|
| 602 | keeps a reference to the designer }
|
---|
| 603 | if (PropCount = 1) and (OldMethod.Data <> nil) and (OldMethod.Code <> nil) then
|
---|
| 604 | CheckChainCall(AValue, OldMethod);
|
---|
| 605 | CurDesigner.ShowMethod(AValue);
|
---|
| 606 | end;
|
---|
| 607 | end;
|
---|
| 608 | Modified;
|
---|
| 609 | end;
|
---|
| 610 |
|
---|
| 611 | *)
|
---|
| 612 |
|
---|
| 613 | { TVA508CollectionProperty }
|
---|
| 614 |
|
---|
| 615 | function TVA508CollectionPropertyEditor.GetColOptions: TColOptions;
|
---|
| 616 | begin
|
---|
| 617 | Result := [coMove];
|
---|
| 618 | end;
|
---|
| 619 |
|
---|
| 620 |
|
---|
| 621 | { TVA508AccessibilityLabelPropertyEditor }
|
---|
| 622 |
|
---|
| 623 | function TVA508AccessibilityLabelPropertyEditor.GetAttributes: TPropertyAttributes;
|
---|
| 624 | begin
|
---|
| 625 | Result := [paMultiSelect, paRevertable, paValueList, paSortList, paAutoUpdate];
|
---|
| 626 | end;
|
---|
| 627 |
|
---|
| 628 | function TVA508AccessibilityLabelPropertyEditor.GetManager: TVA508AccessibilityManager4PE;
|
---|
| 629 | begin
|
---|
| 630 | if not assigned(FManager) then
|
---|
| 631 | FManager := TVA508AccessibilityManager4PE(TVA508AccessibilityItem(GetComponent(0)).Manager);
|
---|
| 632 | Result := FManager;
|
---|
| 633 | end;
|
---|
| 634 |
|
---|
| 635 | procedure TVA508AccessibilityLabelPropertyEditor.GetProperties(
|
---|
| 636 | Proc: TGetPropProc);
|
---|
| 637 | begin
|
---|
| 638 | exit;
|
---|
| 639 | end;
|
---|
| 640 |
|
---|
| 641 | function TVA508AccessibilityLabelPropertyEditor.GetValue: string;
|
---|
| 642 | var
|
---|
| 643 | lbl: TLabel;
|
---|
| 644 | begin
|
---|
| 645 | lbl := TVA508AccessibilityItem(GetComponent(0)).AccessLabel;
|
---|
| 646 | if assigned(lbl) then
|
---|
| 647 | Result := GetManager.GetComponentName(lbl) + QVal(lbl.Caption);
|
---|
| 648 | end;
|
---|
| 649 |
|
---|
| 650 | procedure TVA508AccessibilityLabelPropertyEditor.GetValues(Proc: TGetStrProc);
|
---|
| 651 | var
|
---|
| 652 | i: integer;
|
---|
| 653 | list: TStringList;
|
---|
| 654 | begin
|
---|
| 655 | list := TStringList.Create;
|
---|
| 656 | try
|
---|
| 657 | GetManager.GetLabelStrings(list);
|
---|
| 658 | for i := 0 to list.count-1 do
|
---|
| 659 | Proc(list[i]);
|
---|
| 660 | finally
|
---|
| 661 | list.Free;
|
---|
| 662 | end;
|
---|
| 663 | end;
|
---|
| 664 |
|
---|
| 665 | procedure TVA508AccessibilityLabelPropertyEditor.SetValue(const Value: string);
|
---|
| 666 | begin
|
---|
| 667 | inherited SetValue(StripQVal(Value));
|
---|
| 668 | end;
|
---|
| 669 |
|
---|
| 670 | { TVA508AccessibilityPropertyPropertyEditor }
|
---|
| 671 |
|
---|
| 672 | function TVA508AccessibilityPropertyPropertyEditor.AllEqual: Boolean;
|
---|
| 673 | var
|
---|
| 674 | i: integer;
|
---|
| 675 | prop: string;
|
---|
| 676 | begin
|
---|
| 677 | if PropCount > 1 then
|
---|
| 678 | begin
|
---|
| 679 | Result := FALSE;
|
---|
| 680 | prop := GetManager.AccessProperty[TWinControl(GetComponent(0))];
|
---|
| 681 | for i := 1 to PropCount - 1 do
|
---|
| 682 | if prop <> FManager.AccessProperty[TWinControl(GetComponent(i))] then exit;
|
---|
| 683 | end;
|
---|
| 684 | Result := TRUE;
|
---|
| 685 | end;
|
---|
| 686 |
|
---|
| 687 | function TVA508AccessibilityPropertyPropertyEditor.GetAttributes: TPropertyAttributes;
|
---|
| 688 | begin
|
---|
| 689 | Result := [paMultiSelect, paRevertable, paValueList, paSortList, paAutoUpdate];
|
---|
| 690 | end;
|
---|
| 691 |
|
---|
| 692 | function TVA508AccessibilityPropertyPropertyEditor.GetEditLimit: Integer;
|
---|
| 693 | begin
|
---|
| 694 | Result := 127;
|
---|
| 695 | end;
|
---|
| 696 |
|
---|
| 697 | function TVA508AccessibilityPropertyPropertyEditor.GetManager: TVA508AccessibilityManager4PE;
|
---|
| 698 | begin
|
---|
| 699 | if not assigned(FManager) then
|
---|
| 700 | FManager := TVA508AccessibilityManager4PE(TVA508AccessibilityItem(GetComponent(0)).Manager);
|
---|
| 701 | Result := FManager;
|
---|
| 702 | end;
|
---|
| 703 |
|
---|
| 704 | function TVA508AccessibilityPropertyPropertyEditor.GetRootComponent(
|
---|
| 705 | index: integer): TWinControl;
|
---|
| 706 | begin
|
---|
| 707 | Result := TVA508AccessibilityItem(GetComponent(index)).Component;
|
---|
| 708 | end;
|
---|
| 709 |
|
---|
| 710 | function TVA508AccessibilityPropertyPropertyEditor.GetValue: string;
|
---|
| 711 | begin
|
---|
| 712 | Result := inherited GetValue;
|
---|
| 713 | if Result <> '' then
|
---|
| 714 | Result := Result + QVal(GetPropValue(GetRootComponent(0), Result));
|
---|
| 715 | end;
|
---|
| 716 |
|
---|
| 717 | procedure TVA508AccessibilityPropertyPropertyEditor.GetValues(
|
---|
| 718 | Proc: TGetStrProc);
|
---|
| 719 | var
|
---|
| 720 | list: TStringList;
|
---|
| 721 | i: integer;
|
---|
| 722 | name: string;
|
---|
| 723 |
|
---|
| 724 | begin
|
---|
| 725 | list := TStringList.Create;
|
---|
| 726 | try
|
---|
| 727 | GetStringPropertyNames(GetManager, GetRootComponent(0), list, TRUE);
|
---|
| 728 | if PropCount > 1 then
|
---|
| 729 | begin
|
---|
| 730 | for i := 1 to PropCount-1 do
|
---|
| 731 | GetStringPropertyNames(FManager, GetRootComponent(i), list, FALSE);
|
---|
| 732 | end;
|
---|
| 733 | list.Sort;
|
---|
| 734 | for i := 0 to list.count-1 do
|
---|
| 735 | begin
|
---|
| 736 | name := list[i];
|
---|
| 737 | if PropCount = 1 then
|
---|
| 738 | name := name + QVal(GetPropValue(GetRootComponent(0), name));
|
---|
| 739 | Proc(name);
|
---|
| 740 | end;
|
---|
| 741 | finally
|
---|
| 742 | list.free;
|
---|
| 743 | end;
|
---|
| 744 | end;
|
---|
| 745 |
|
---|
| 746 | procedure TVA508AccessibilityPropertyPropertyEditor.SetValue(
|
---|
| 747 | const Value: string);
|
---|
| 748 | begin
|
---|
| 749 | inherited SetValue(StripQVal(Value));
|
---|
| 750 | end;
|
---|
| 751 |
|
---|
| 752 | { TVA508AccessibilityClassPropertyEditor }
|
---|
| 753 |
|
---|
| 754 | function TVA508AccessibilityComponentPropertyEditor.GetAttributes: TPropertyAttributes;
|
---|
| 755 | begin
|
---|
| 756 | Result := [paDisplayReadOnly];
|
---|
| 757 | end;
|
---|
| 758 |
|
---|
| 759 | procedure Register;
|
---|
| 760 | begin
|
---|
| 761 | RegisterComponents(DelphiPaletteName, [TVA508AccessibilityManager, TVA508ComponentAccessibility,
|
---|
| 762 | TVA508StaticText]);
|
---|
| 763 | RegisterPropertyEditor(TypeInfo(TVA508AccessibilityCollection),
|
---|
| 764 | TVA508AccessibilityManager, VA508DataPropertyName, TVA508CollectionPropertyEditor);
|
---|
| 765 | RegisterPropertyEditor(TypeInfo(String), TWinControl, WinControlPropertyToMap,
|
---|
| 766 | TVA508AccessibilityPropertyMapper);
|
---|
| 767 | RegisterPropertyEditor(TypeInfo(TLabel), TVA508AccessibilityItem, AccessibilityLabelPropertyName,
|
---|
| 768 | TVA508AccessibilityLabelPropertyEditor);
|
---|
| 769 | RegisterPropertyEditor(TypeInfo(String), TVA508AccessibilityItem, AccessibilityPropertyPropertyName,
|
---|
| 770 | TVA508AccessibilityPropertyPropertyEditor);
|
---|
| 771 | RegisterPropertyEditor(TypeInfo(TComponent), TVA508AccessibilityItem, AccessDataComponentText,
|
---|
| 772 | TVA508AccessibilityComponentPropertyEditor);
|
---|
| 773 | end;
|
---|
| 774 |
|
---|
| 775 | end.
|
---|
| 776 |
|
---|