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