[456] | 1 | unit uAccessibleTreeNode;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | ComObj, ActiveX, CPRSChart_TLB, StdVcl, ORCtrls, Accessibility_TLB;
|
---|
| 7 |
|
---|
| 8 | type
|
---|
| 9 | TChildType = (ctInvalid, ctNoChild, ctChild);
|
---|
| 10 |
|
---|
| 11 | TAccessibleTreeNode = class(TAutoObject, IAccessibleTreeNode, IAccessible)
|
---|
| 12 | private
|
---|
| 13 | FDefaultObject: IAccessible;
|
---|
| 14 | FDefaultObjectLoaded: boolean;
|
---|
| 15 | FControl: TORTreeNode;
|
---|
| 16 | function GetDefaultObject: IAccessible;
|
---|
| 17 | protected
|
---|
| 18 | function accHitTest(xLeft, yTop: Integer): OleVariant; safecall;
|
---|
| 19 | function accNavigate(navDir: Integer; varStart: OleVariant): OleVariant;
|
---|
| 20 | safecall;
|
---|
| 21 | function Get_accChild(varChild: OleVariant): IDispatch; safecall;
|
---|
| 22 | function Get_accChildCount: Integer; safecall;
|
---|
| 23 | function Get_accDefaultAction(varChild: OleVariant): WideString; safecall;
|
---|
| 24 | function Get_accDescription(varChild: OleVariant): WideString; safecall;
|
---|
| 25 | function Get_accFocus: OleVariant; safecall;
|
---|
| 26 | function Get_accHelp(varChild: OleVariant): WideString; safecall;
|
---|
| 27 | function Get_accHelpTopic(out pszHelpFile: WideString;
|
---|
| 28 | varChild: OleVariant): Integer; safecall;
|
---|
| 29 | function Get_accKeyboardShortcut(varChild: OleVariant): WideString;
|
---|
| 30 | safecall;
|
---|
| 31 | function Get_accName(varChild: OleVariant): WideString; safecall;
|
---|
| 32 | function Get_accParent: IDispatch; safecall;
|
---|
| 33 | function Get_accRole(varChild: OleVariant): OleVariant; safecall;
|
---|
| 34 | function Get_accSelection: OleVariant; safecall;
|
---|
| 35 | function Get_accState(varChild: OleVariant): OleVariant; safecall;
|
---|
| 36 | function Get_accValue(varChild: OleVariant): WideString; safecall;
|
---|
| 37 | procedure accDoDefaultAction(varChild: OleVariant); safecall;
|
---|
| 38 | procedure accLocation(out pxLeft, pyTop, pcxWidth, pcyHeight: Integer;
|
---|
| 39 | varChild: OleVariant); safecall;
|
---|
| 40 | procedure accSelect(flagsSelect: Integer; varChild: OleVariant); safecall;
|
---|
| 41 | procedure Set_accName(varChild: OleVariant; const pszName: WideString);
|
---|
| 42 | safecall;
|
---|
| 43 | procedure Set_accValue(varChild: OleVariant; const pszValue: WideString);
|
---|
| 44 | safecall;
|
---|
| 45 | public
|
---|
| 46 | property Control: TORTreeNode read FControl write FControl;
|
---|
| 47 | property DefaultObject: IAccessible read GetDefaultObject write FDefaultObject;
|
---|
| 48 | function ChildType( varChild: OleVariant): TChildType;
|
---|
| 49 | class procedure WrapControl( Control: TORTreeNode);
|
---|
| 50 | class procedure UnwrapControl( Control: TORTreeNode);
|
---|
| 51 | end;
|
---|
| 52 |
|
---|
| 53 | implementation
|
---|
| 54 |
|
---|
| 55 | uses uComServ, uAccessAPI, Windows, SysUtils, Variants;
|
---|
| 56 |
|
---|
| 57 | var
|
---|
| 58 | UserIsRestricted: boolean = False;
|
---|
| 59 |
|
---|
| 60 | function TAccessibleTreeNode.accHitTest(xLeft, yTop: Integer): OleVariant;
|
---|
| 61 | begin
|
---|
| 62 | result := Null;
|
---|
| 63 | if Assigned(DefaultObject) then
|
---|
| 64 | result := DefaultObject.accHitTest(xLeft,yTop);
|
---|
| 65 | end;
|
---|
| 66 |
|
---|
| 67 | function TAccessibleTreeNode.accNavigate(navDir: Integer;
|
---|
| 68 | varStart: OleVariant): OleVariant;
|
---|
| 69 | begin
|
---|
| 70 | result := Null;
|
---|
| 71 | if Assigned(DefaultObject) then
|
---|
| 72 | result := DefaultObject.accNavigate(navDir, varStart);
|
---|
| 73 | end;
|
---|
| 74 |
|
---|
| 75 | function TAccessibleTreeNode.Get_accChild(varChild: OleVariant): IDispatch;
|
---|
| 76 | begin
|
---|
| 77 | result := nil;
|
---|
| 78 | if Assigned(DefaultObject) then
|
---|
| 79 | result := DefaultObject.Get_accChild(varChild);
|
---|
| 80 | end;
|
---|
| 81 |
|
---|
| 82 | function TAccessibleTreeNode.Get_accChildCount: Integer;
|
---|
| 83 | begin
|
---|
| 84 | result := 0;
|
---|
| 85 | if Assigned(DefaultObject) then
|
---|
| 86 | result := DefaultObject.Get_accChildCount;
|
---|
| 87 | end;
|
---|
| 88 |
|
---|
| 89 | function TAccessibleTreeNode.Get_accDefaultAction(
|
---|
| 90 | varChild: OleVariant): WideString;
|
---|
| 91 | begin
|
---|
| 92 | result := '';
|
---|
| 93 | if Assigned(DefaultObject) then
|
---|
| 94 | result := DefaultObject.Get_accDefaultAction(varChild);
|
---|
| 95 | end;
|
---|
| 96 |
|
---|
| 97 | function TAccessibleTreeNode.Get_accDescription(
|
---|
| 98 | varChild: OleVariant): WideString;
|
---|
| 99 | begin
|
---|
| 100 | result := '';
|
---|
| 101 | if Assigned(DefaultObject) then
|
---|
| 102 | result := DefaultObject.Get_accDescription(varChild);
|
---|
| 103 | end;
|
---|
| 104 |
|
---|
| 105 | function TAccessibleTreeNode.Get_accFocus: OleVariant;
|
---|
| 106 | begin
|
---|
| 107 | result := NULL;
|
---|
| 108 | if Assigned(DefaultObject) then
|
---|
| 109 | result := DefaultObject.Get_accFocus;
|
---|
| 110 | end;
|
---|
| 111 |
|
---|
| 112 | function TAccessibleTreeNode.Get_accHelp(varChild: OleVariant): WideString;
|
---|
| 113 | begin
|
---|
| 114 | result := '';
|
---|
| 115 | if Assigned(DefaultObject) then
|
---|
| 116 | result := DefaultObject.Get_accHelp(varChild);
|
---|
| 117 | end;
|
---|
| 118 |
|
---|
| 119 | function TAccessibleTreeNode.Get_accHelpTopic(out pszHelpFile: WideString;
|
---|
| 120 | varChild: OleVariant): Integer;
|
---|
| 121 | begin
|
---|
| 122 | result := 0;
|
---|
| 123 | if Assigned(DefaultObject) then
|
---|
| 124 | result := DefaultObject.Get_accHelpTopic(pszHelpFile, varChild);
|
---|
| 125 | end;
|
---|
| 126 |
|
---|
| 127 | function TAccessibleTreeNode.Get_accKeyboardShortcut(
|
---|
| 128 | varChild: OleVariant): WideString;
|
---|
| 129 | begin
|
---|
| 130 | result := '';
|
---|
| 131 | if Assigned(DefaultObject) then
|
---|
| 132 | result := DefaultObject.Get_accKeyboardShortcut(varChild);
|
---|
| 133 | end;
|
---|
| 134 |
|
---|
| 135 | function TAccessibleTreeNode.Get_accName(varChild: OleVariant): WideString;
|
---|
| 136 | begin
|
---|
| 137 | if ChildType(varChild) = ctNoChild then
|
---|
| 138 | begin
|
---|
| 139 | result := '';
|
---|
| 140 | if Assigned(FControl) then
|
---|
| 141 | result := FControl.Caption;
|
---|
| 142 | end
|
---|
| 143 | else if Assigned(DefaultObject) then
|
---|
| 144 | result := DefaultObject.Get_accName(varChild);
|
---|
| 145 | end;
|
---|
| 146 |
|
---|
| 147 | function TAccessibleTreeNode.Get_accParent: IDispatch;
|
---|
| 148 | begin
|
---|
| 149 | result := nil;
|
---|
| 150 | if Assigned(DefaultObject) then
|
---|
| 151 | result := DefaultObject.Get_accParent;
|
---|
| 152 | end;
|
---|
| 153 |
|
---|
| 154 | function TAccessibleTreeNode.Get_accRole(varChild: OleVariant): OleVariant;
|
---|
| 155 | begin
|
---|
| 156 | result := NULL;
|
---|
| 157 | if Assigned(DefaultObject) then
|
---|
| 158 | result := DefaultObject.Get_accRole(varChild);
|
---|
| 159 | end;
|
---|
| 160 |
|
---|
| 161 | function TAccessibleTreeNode.Get_accSelection: OleVariant;
|
---|
| 162 | begin
|
---|
| 163 | result := NULL;
|
---|
| 164 | if Assigned(DefaultObject) then
|
---|
| 165 | result := DefaultObject.Get_accSelection;
|
---|
| 166 | end;
|
---|
| 167 |
|
---|
| 168 | function TAccessibleTreeNode.Get_accState(varChild: OleVariant): OleVariant;
|
---|
| 169 | begin
|
---|
| 170 | result := NULL;
|
---|
| 171 | if Assigned(DefaultObject) then
|
---|
| 172 | result := DefaultObject.Get_accState(varChild);
|
---|
| 173 | end;
|
---|
| 174 |
|
---|
| 175 | function TAccessibleTreeNode.Get_accValue(varChild: OleVariant): WideString;
|
---|
| 176 | begin
|
---|
| 177 | result := '';
|
---|
| 178 | if Assigned(DefaultObject) then
|
---|
| 179 | result := DefaultObject.Get_accValue(varChild);
|
---|
| 180 | end;
|
---|
| 181 |
|
---|
| 182 | procedure TAccessibleTreeNode.accDoDefaultAction(varChild: OleVariant);
|
---|
| 183 | begin
|
---|
| 184 | if Assigned(DefaultObject) then
|
---|
| 185 | DefaultObject.accDoDefaultAction(varChild);
|
---|
| 186 | end;
|
---|
| 187 |
|
---|
| 188 | procedure TAccessibleTreeNode.accLocation(out pxLeft, pyTop, pcxWidth,
|
---|
| 189 | pcyHeight: Integer; varChild: OleVariant);
|
---|
| 190 | begin
|
---|
| 191 | if Assigned(DefaultObject) then
|
---|
| 192 | DefaultObject.accLocation(pxLeft,pyTop,pcxWidth,pcyHeight,VarChild);
|
---|
| 193 | end;
|
---|
| 194 |
|
---|
| 195 | procedure TAccessibleTreeNode.accSelect(flagsSelect: Integer;
|
---|
| 196 | varChild: OleVariant);
|
---|
| 197 | begin
|
---|
| 198 | if Assigned(DefaultObject) then
|
---|
| 199 | DefaultObject.accSelect(flagsSelect, varChild);
|
---|
| 200 | end;
|
---|
| 201 |
|
---|
| 202 | procedure TAccessibleTreeNode.Set_accName(varChild: OleVariant;
|
---|
| 203 | const pszName: WideString);
|
---|
| 204 | begin
|
---|
| 205 | if Assigned(DefaultObject) then
|
---|
| 206 | DefaultObject.Set_accName(varChild, pszName);
|
---|
| 207 | end;
|
---|
| 208 |
|
---|
| 209 | procedure TAccessibleTreeNode.Set_accValue(varChild: OleVariant;
|
---|
| 210 | const pszValue: WideString);
|
---|
| 211 | begin
|
---|
| 212 | if Assigned(DefaultObject) then
|
---|
| 213 | DefaultObject.Set_accValue(varChild, pszValue);
|
---|
| 214 | end;
|
---|
| 215 |
|
---|
| 216 | function TAccessibleTreeNode.GetDefaultObject: IAccessible;
|
---|
| 217 | begin
|
---|
| 218 | if Assigned(FControl) and not FDefaultObjectLoaded then begin
|
---|
| 219 | FDefaultObject := uAccessAPI.GetDefaultObject(FControl);
|
---|
| 220 | FDefaultObjectLoaded := True;
|
---|
| 221 | end;
|
---|
| 222 | Result := FDefaultObject;
|
---|
| 223 | end;
|
---|
| 224 |
|
---|
| 225 | function TAccessibleTreeNode.ChildType(varChild: OleVariant): TChildType;
|
---|
| 226 | begin
|
---|
| 227 | if (VarType(varChild) <> varInteger) then
|
---|
| 228 | result := ctInvalid
|
---|
| 229 | else if varChild = CHILDID_SELF then
|
---|
| 230 | result := ctNoChild
|
---|
| 231 | else
|
---|
| 232 | result := ctChild;
|
---|
| 233 | end;
|
---|
| 234 |
|
---|
| 235 | class procedure TAccessibleTreeNode.WrapControl(Control: TORTreeNode);
|
---|
| 236 | var
|
---|
| 237 | AccessibleTreeNode: TAccessibleTreeNode;
|
---|
| 238 | {Using Accessible here is probably just interface reference count paranoia}
|
---|
| 239 | Accessible: IAccessible;
|
---|
| 240 | begin
|
---|
| 241 | if not UserIsRestricted then
|
---|
| 242 | begin
|
---|
| 243 | AccessibleTreeNode := TAccessibleTreeNode.Create;
|
---|
| 244 | Accessible := AccessibleTreeNode;
|
---|
| 245 | AccessibleTreeNode.Control := Control;
|
---|
| 246 | Control.MakeAccessible(Accessible);
|
---|
| 247 | end;
|
---|
| 248 | end;
|
---|
| 249 |
|
---|
| 250 | class procedure TAccessibleTreeNode.UnwrapControl(Control: TORTreeNode);
|
---|
| 251 | begin
|
---|
| 252 | if not UserIsRestricted then
|
---|
| 253 | Control.MakeAccessible(nil);
|
---|
| 254 | end;
|
---|
| 255 |
|
---|
| 256 | initialization
|
---|
| 257 | try
|
---|
| 258 | TAutoObjectFactory.Create(ComServer, TAccessibleTreeNode, Class_AccessibleTreeNode,
|
---|
| 259 | ciMultiInstance, tmApartment);
|
---|
| 260 | except
|
---|
| 261 | {Let the poor restricted users pass!}
|
---|
| 262 | UserIsRestricted := True;
|
---|
| 263 | end;
|
---|
| 264 |
|
---|
| 265 | end.
|
---|