| 1 | unit uaccessibleTreeView;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | ComObj, ActiveX, CPRSChart_TLB, StdVcl, ORCtrls, Accessibility_TLB, Variants;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | TChildType = (ctInvalid, ctNoChild, ctChild);
|
|---|
| 10 |
|
|---|
| 11 | TAccessibleTreeView = class(TAutoObject, IaccessibleTreeView, IAccessible)
|
|---|
| 12 | private
|
|---|
| 13 | FDefaultObject: IAccessible;
|
|---|
| 14 | FDefaultObjectLoaded: boolean;
|
|---|
| 15 | FControl: TORTreeView;
|
|---|
| 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: TORtreeView read FControl write FControl;
|
|---|
| 47 | property DefaultObject: IAccessible read GetDefaultObject write FDefaultObject;
|
|---|
| 48 | function ChildType( varChild: OleVariant): TChildType;
|
|---|
| 49 | class procedure WrapControl( Control: TORTreeView);
|
|---|
| 50 | class procedure UnwrapControl( Control: TORTreeView);
|
|---|
| 51 | end;
|
|---|
| 52 |
|
|---|
| 53 | implementation
|
|---|
| 54 |
|
|---|
| 55 | uses uComServ, uAccessAPI, Windows, CommCtrl;
|
|---|
| 56 |
|
|---|
| 57 | var
|
|---|
| 58 | UserIsRestricted: boolean = False;
|
|---|
| 59 |
|
|---|
| 60 | function TAccessibleTreeView.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 TAccessibleTreeView.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 TAccessibleTreeView.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 TAccessibleTreeView.Get_accChildCount: Integer;
|
|---|
| 83 | begin
|
|---|
| 84 | result := 0;
|
|---|
| 85 | if Assigned(DefaultObject) then
|
|---|
| 86 | result := DefaultObject.Get_accChildCount;
|
|---|
| 87 | end;
|
|---|
| 88 |
|
|---|
| 89 | function TAccessibleTreeView.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 TAccessibleTreeView.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 TAccessibleTreeView.Get_accFocus: OleVariant;
|
|---|
| 106 | begin
|
|---|
| 107 | result := NULL;
|
|---|
| 108 | if Assigned(DefaultObject) then
|
|---|
| 109 | result := DefaultObject.Get_accFocus;
|
|---|
| 110 | end;
|
|---|
| 111 |
|
|---|
| 112 | function TAccessibleTreeView.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 TAccessibleTreeView.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 TAccessibleTreeView.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 TAccessibleTreeView.Get_accName(varChild: OleVariant): WideString;
|
|---|
| 136 | var
|
|---|
| 137 | TheNode:TORTreeNode;
|
|---|
| 138 | begin
|
|---|
| 139 | if ChildType(varChild) = ctChild then
|
|---|
| 140 | begin
|
|---|
| 141 | if Assigned(FControl) then
|
|---|
| 142 | begin
|
|---|
| 143 | TheNode := FControl.Items.GetNode(HTREEITEM(integer(varChild))) as TORTreeNode;
|
|---|
| 144 | result := TheNode.Accessible.Get_accName(CHILDID_SELF);
|
|---|
| 145 | end
|
|---|
| 146 | else
|
|---|
| 147 | result := '[No Data]';
|
|---|
| 148 | end
|
|---|
| 149 | else if Assigned(DefaultObject) then
|
|---|
| 150 | result := DefaultObject.Get_accName(varChild);
|
|---|
| 151 | end;
|
|---|
| 152 |
|
|---|
| 153 | function TAccessibleTreeView.Get_accParent: IDispatch;
|
|---|
| 154 | begin
|
|---|
| 155 | result := nil;
|
|---|
| 156 | if Assigned(DefaultObject) then
|
|---|
| 157 | result := DefaultObject.Get_accParent;
|
|---|
| 158 | end;
|
|---|
| 159 |
|
|---|
| 160 | function TAccessibleTreeView.Get_accRole(varChild: OleVariant): OleVariant;
|
|---|
| 161 | begin
|
|---|
| 162 | result := NULL;
|
|---|
| 163 | if Assigned(DefaultObject) then
|
|---|
| 164 | result := DefaultObject.Get_accRole(varChild);
|
|---|
| 165 | end;
|
|---|
| 166 |
|
|---|
| 167 | function TAccessibleTreeView.Get_accSelection: OleVariant;
|
|---|
| 168 | begin
|
|---|
| 169 | result := NULL;
|
|---|
| 170 | if Assigned(DefaultObject) then
|
|---|
| 171 | result := DefaultObject.Get_accSelection;
|
|---|
| 172 | end;
|
|---|
| 173 |
|
|---|
| 174 | function TAccessibleTreeView.Get_accState(varChild: OleVariant): OleVariant;
|
|---|
| 175 | begin
|
|---|
| 176 | result := NULL;
|
|---|
| 177 | if Assigned(DefaultObject) then
|
|---|
| 178 | result := DefaultObject.Get_accState(varChild);
|
|---|
| 179 | end;
|
|---|
| 180 |
|
|---|
| 181 | function TAccessibleTreeView.Get_accValue(varChild: OleVariant): WideString;
|
|---|
| 182 | begin
|
|---|
| 183 | result := '';
|
|---|
| 184 | if Assigned(DefaultObject) then
|
|---|
| 185 | result := DefaultObject.Get_accValue(varChild);
|
|---|
| 186 | end;
|
|---|
| 187 |
|
|---|
| 188 | procedure TAccessibleTreeView.accDoDefaultAction(varChild: OleVariant);
|
|---|
| 189 | begin
|
|---|
| 190 | if Assigned(DefaultObject) then
|
|---|
| 191 | DefaultObject.accDoDefaultAction(varChild);
|
|---|
| 192 | end;
|
|---|
| 193 |
|
|---|
| 194 | procedure TAccessibleTreeView.accLocation(out pxLeft, pyTop, pcxWidth,
|
|---|
| 195 | pcyHeight: Integer; varChild: OleVariant);
|
|---|
| 196 | begin
|
|---|
| 197 | if Assigned(DefaultObject) then
|
|---|
| 198 | DefaultObject.accLocation(pxLeft,pyTop,pcxWidth,pcyHeight,VarChild);
|
|---|
| 199 | end;
|
|---|
| 200 |
|
|---|
| 201 | procedure TAccessibleTreeView.accSelect(flagsSelect: Integer;
|
|---|
| 202 | varChild: OleVariant);
|
|---|
| 203 | begin
|
|---|
| 204 | if Assigned(DefaultObject) then
|
|---|
| 205 | DefaultObject.accSelect(flagsSelect, varChild);
|
|---|
| 206 | end;
|
|---|
| 207 |
|
|---|
| 208 | procedure TAccessibleTreeView.Set_accName(varChild: OleVariant;
|
|---|
| 209 | const pszName: WideString);
|
|---|
| 210 | begin
|
|---|
| 211 | if Assigned(DefaultObject) then
|
|---|
| 212 | DefaultObject.Set_accName(varChild, pszName);
|
|---|
| 213 | end;
|
|---|
| 214 |
|
|---|
| 215 | procedure TAccessibleTreeView.Set_accValue(varChild: OleVariant;
|
|---|
| 216 | const pszValue: WideString);
|
|---|
| 217 | begin
|
|---|
| 218 | if Assigned(DefaultObject) then
|
|---|
| 219 | DefaultObject.Set_accValue(varChild, pszValue);
|
|---|
| 220 | end;
|
|---|
| 221 |
|
|---|
| 222 | function TAccessibleTreeView.GetDefaultObject: IAccessible;
|
|---|
| 223 | begin
|
|---|
| 224 | if Assigned(FControl) and not FDefaultObjectLoaded then begin
|
|---|
| 225 | FDefaultObject := uAccessAPI.GetDefaultObject(FControl);
|
|---|
| 226 | FDefaultObjectLoaded := True;
|
|---|
| 227 | end;
|
|---|
| 228 | Result := FDefaultObject;
|
|---|
| 229 | end;
|
|---|
| 230 |
|
|---|
| 231 | function TAccessibleTreeView.ChildType(varChild: OleVariant): TChildType;
|
|---|
| 232 | begin
|
|---|
| 233 | if (VarType(varChild) <> varInteger) then
|
|---|
| 234 | result := ctInvalid
|
|---|
| 235 | else if varChild = CHILDID_SELF then
|
|---|
| 236 | result := ctNoChild
|
|---|
| 237 | else
|
|---|
| 238 | result := ctChild;
|
|---|
| 239 | end;
|
|---|
| 240 |
|
|---|
| 241 | class procedure TAccessibleTreeView.WrapControl(Control: TORTreeView);
|
|---|
| 242 | var
|
|---|
| 243 | AccessibleTreeView: TAccessibleTreeView;
|
|---|
| 244 | {Using Accessible here is probably just interface reference count paranoia}
|
|---|
| 245 | Accessible: IAccessible;
|
|---|
| 246 | begin
|
|---|
| 247 | if not UserIsRestricted then
|
|---|
| 248 | begin
|
|---|
| 249 | AccessibleTreeView := TAccessibleTreeView.Create;
|
|---|
| 250 | Accessible := AccessibleTreeView;
|
|---|
| 251 | AccessibleTreeView.Control := Control;
|
|---|
| 252 | Control.MakeAccessible(Accessible);
|
|---|
| 253 | end;
|
|---|
| 254 | end;
|
|---|
| 255 |
|
|---|
| 256 | class procedure TAccessibleTreeView.UnwrapControl(Control: TORTreeView);
|
|---|
| 257 | begin
|
|---|
| 258 | if not UserIsRestricted then
|
|---|
| 259 | Control.MakeAccessible(nil);
|
|---|
| 260 | end;
|
|---|
| 261 |
|
|---|
| 262 | initialization
|
|---|
| 263 | try
|
|---|
| 264 | TAutoObjectFactory.Create(ComServer, TAccessibleTreeView, Class_accessibleTreeView,
|
|---|
| 265 | ciMultiInstance, tmApartment);
|
|---|
| 266 | except
|
|---|
| 267 | {Let the poor restricted users pass!}
|
|---|
| 268 | UserIsRestricted := True;
|
|---|
| 269 | end;
|
|---|
| 270 |
|
|---|
| 271 | end.
|
|---|