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