| 1 | //kt -- Modified with SourceScanner on 8/25/2007 | 
|---|
| 2 | unit uAccessibleListBox; | 
|---|
| 3 |  | 
|---|
| 4 | interface | 
|---|
| 5 |  | 
|---|
| 6 | uses | 
|---|
| 7 | ComObj, ActiveX, CPRSChart_TLB, StdVcl, Accessibility_TLB, ORCtrls, Variants; | 
|---|
| 8 |  | 
|---|
| 9 | type | 
|---|
| 10 | TChildType = (ctInvalid, ctNoChild, ctChild); | 
|---|
| 11 |  | 
|---|
| 12 | TAccessibleListBox = class(TAutoObject, IAccessibleListBox, IAccessible) | 
|---|
| 13 | private | 
|---|
| 14 | FDefaultObject: IAccessible; | 
|---|
| 15 | FDefaultObjectLoaded: boolean; | 
|---|
| 16 | FControl: TORListBox; | 
|---|
| 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: TORListBox read FControl write FControl; | 
|---|
| 48 | property DefaultObject: IAccessible read GetDefaultObject write FDefaultObject; | 
|---|
| 49 | function ChildType( varChild: OleVariant): TChildType; | 
|---|
| 50 | class procedure WrapControl( Control: TORComboBox); overload; | 
|---|
| 51 | class procedure UnwrapControl( Control: TORComboBox); overload; | 
|---|
| 52 | class procedure WrapControl( Control: TORListBox); overload; | 
|---|
| 53 | class procedure UnwrapControl( Control: TORListBox); overload; | 
|---|
| 54 | end; | 
|---|
| 55 |  | 
|---|
| 56 | implementation | 
|---|
| 57 |  | 
|---|
| 58 | uses uComServ, uAccessAPI, Windows, SysUtils; | 
|---|
| 59 |  | 
|---|
| 60 | var | 
|---|
| 61 | UserIsRestricted: boolean = False; | 
|---|
| 62 |  | 
|---|
| 63 | function TAccessibleListBox.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 TAccessibleListBox.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 TAccessibleListBox.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 TAccessibleListBox.Get_accChildCount: Integer; | 
|---|
| 86 | begin | 
|---|
| 87 | result := 0; | 
|---|
| 88 | if Assigned(DefaultObject) then | 
|---|
| 89 | result := DefaultObject.Get_accChildCount; | 
|---|
| 90 | end; | 
|---|
| 91 |  | 
|---|
| 92 | function TAccessibleListBox.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 TAccessibleListBox.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 TAccessibleListBox.Get_accFocus: OleVariant; | 
|---|
| 109 | begin | 
|---|
| 110 | result := NULL; | 
|---|
| 111 | if Assigned(DefaultObject) then | 
|---|
| 112 | result := DefaultObject.Get_accFocus; | 
|---|
| 113 | end; | 
|---|
| 114 |  | 
|---|
| 115 | function TAccessibleListBox.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 TAccessibleListBox.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 TAccessibleListBox.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 TAccessibleListBox.Get_accName(varChild: OleVariant): WideString; | 
|---|
| 139 | var | 
|---|
| 140 | LongName: string; | 
|---|
| 141 | Previous: string; | 
|---|
| 142 | i: integer; | 
|---|
| 143 | begin | 
|---|
| 144 | if ChildType(varChild) = ctChild then | 
|---|
| 145 | begin | 
|---|
| 146 | result := ''; | 
|---|
| 147 | if Assigned(FControl) then | 
|---|
| 148 | begin | 
|---|
| 149 | i := varChild - 1; | 
|---|
| 150 | LongName := FControl.DisplayText[i]; | 
|---|
| 151 | if i > 0 then | 
|---|
| 152 | Previous := FControl.DisplayText[i-1] | 
|---|
| 153 | else | 
|---|
| 154 | Previous := ''; | 
|---|
| 155 | result := CalcShortName( LongName, Previous); | 
|---|
| 156 | end; | 
|---|
| 157 | end | 
|---|
| 158 | else if Assigned(DefaultObject) then | 
|---|
| 159 | result := DefaultObject.Get_accName(varChild); | 
|---|
| 160 | end; | 
|---|
| 161 |  | 
|---|
| 162 | function TAccessibleListBox.Get_accParent: IDispatch; | 
|---|
| 163 | begin | 
|---|
| 164 | result := nil; | 
|---|
| 165 | if Assigned(DefaultObject) then | 
|---|
| 166 | result := DefaultObject.Get_accParent; | 
|---|
| 167 | end; | 
|---|
| 168 |  | 
|---|
| 169 | function TAccessibleListBox.Get_accRole(varChild: OleVariant): OleVariant; | 
|---|
| 170 | begin | 
|---|
| 171 | result := NULL; | 
|---|
| 172 | if Assigned(DefaultObject) then | 
|---|
| 173 | result := DefaultObject.Get_accRole(varChild); | 
|---|
| 174 | end; | 
|---|
| 175 |  | 
|---|
| 176 | function TAccessibleListBox.Get_accSelection: OleVariant; | 
|---|
| 177 | begin | 
|---|
| 178 | result := NULL; | 
|---|
| 179 | if Assigned(DefaultObject) then | 
|---|
| 180 | result := DefaultObject.Get_accSelection; | 
|---|
| 181 | end; | 
|---|
| 182 |  | 
|---|
| 183 | function TAccessibleListBox.Get_accState(varChild: OleVariant): OleVariant; | 
|---|
| 184 | begin | 
|---|
| 185 | result := NULL; | 
|---|
| 186 | if Assigned(DefaultObject) then | 
|---|
| 187 | result := DefaultObject.Get_accState(varChild); | 
|---|
| 188 | end; | 
|---|
| 189 |  | 
|---|
| 190 | function TAccessibleListBox.Get_accValue(varChild: OleVariant): WideString; | 
|---|
| 191 | begin | 
|---|
| 192 | result := ''; | 
|---|
| 193 | if Assigned(DefaultObject) then | 
|---|
| 194 | result := DefaultObject.Get_accValue(varChild); | 
|---|
| 195 | end; | 
|---|
| 196 |  | 
|---|
| 197 | procedure TAccessibleListBox.accDoDefaultAction(varChild: OleVariant); | 
|---|
| 198 | begin | 
|---|
| 199 | if Assigned(DefaultObject) then | 
|---|
| 200 | DefaultObject.accDoDefaultAction(varChild); | 
|---|
| 201 | end; | 
|---|
| 202 |  | 
|---|
| 203 | procedure TAccessibleListBox.accLocation(out pxLeft, pyTop, pcxWidth, | 
|---|
| 204 | pcyHeight: Integer; varChild: OleVariant); | 
|---|
| 205 | begin | 
|---|
| 206 | if Assigned(DefaultObject) then | 
|---|
| 207 | DefaultObject.accLocation(pxLeft,pyTop,pcxWidth,pcyHeight,VarChild); | 
|---|
| 208 | end; | 
|---|
| 209 |  | 
|---|
| 210 | procedure TAccessibleListBox.accSelect(flagsSelect: Integer; | 
|---|
| 211 | varChild: OleVariant); | 
|---|
| 212 | begin | 
|---|
| 213 | if Assigned(DefaultObject) then | 
|---|
| 214 | DefaultObject.accSelect(flagsSelect, varChild); | 
|---|
| 215 | end; | 
|---|
| 216 |  | 
|---|
| 217 | procedure TAccessibleListBox.Set_accName(varChild: OleVariant; | 
|---|
| 218 | const pszName: WideString); | 
|---|
| 219 | begin | 
|---|
| 220 | if Assigned(DefaultObject) then | 
|---|
| 221 | DefaultObject.Set_accName(varChild, pszName); | 
|---|
| 222 | end; | 
|---|
| 223 |  | 
|---|
| 224 | procedure TAccessibleListBox.Set_accValue(varChild: OleVariant; | 
|---|
| 225 | const pszValue: WideString); | 
|---|
| 226 | begin | 
|---|
| 227 | if Assigned(DefaultObject) then | 
|---|
| 228 | DefaultObject.Set_accValue(varChild, pszValue); | 
|---|
| 229 | end; | 
|---|
| 230 |  | 
|---|
| 231 | function TAccessibleListBox.GetDefaultObject: IAccessible; | 
|---|
| 232 | begin | 
|---|
| 233 | if Assigned(FControl) and not FDefaultObjectLoaded then begin | 
|---|
| 234 | FDefaultObject := uAccessAPI.GetDefaultObject(FControl); | 
|---|
| 235 | FDefaultObjectLoaded := True; | 
|---|
| 236 | end; | 
|---|
| 237 | Result := FDefaultObject; | 
|---|
| 238 | end; | 
|---|
| 239 |  | 
|---|
| 240 | function TAccessibleListBox.ChildType(varChild: OleVariant): TChildType; | 
|---|
| 241 | begin | 
|---|
| 242 | if VarType(varChild) <> varInteger then | 
|---|
| 243 | result := ctInvalid | 
|---|
| 244 | else if varChild = CHILDID_SELF then | 
|---|
| 245 | result := ctNoChild | 
|---|
| 246 | else | 
|---|
| 247 | result := ctChild; | 
|---|
| 248 | end; | 
|---|
| 249 |  | 
|---|
| 250 | class procedure TAccessibleListBox.WrapControl(Control: TORComboBox); | 
|---|
| 251 | var | 
|---|
| 252 | AccessibleListBox: TAccessibleListBox; | 
|---|
| 253 | {Using Accessible here is probably just interface reference count paranoia} | 
|---|
| 254 | Accessible: IAccessible; | 
|---|
| 255 | begin | 
|---|
| 256 | if not UserIsRestricted then | 
|---|
| 257 | begin | 
|---|
| 258 | AccessibleListBox := TAccessibleListBox.Create; | 
|---|
| 259 | Accessible := AccessibleListBox; | 
|---|
| 260 | AccessibleListBox.Control := Control.MakeAccessible(Accessible); | 
|---|
| 261 | end; | 
|---|
| 262 | end; | 
|---|
| 263 |  | 
|---|
| 264 | class procedure TAccessibleListBox.UnwrapControl(Control: TORComboBox); | 
|---|
| 265 | begin | 
|---|
| 266 | if not UserIsRestricted then | 
|---|
| 267 | Control.MakeAccessible(nil); | 
|---|
| 268 | end; | 
|---|
| 269 |  | 
|---|
| 270 | class procedure TAccessibleListBox.UnwrapControl(Control: TORListBox); | 
|---|
| 271 | begin | 
|---|
| 272 | if not UserIsRestricted then | 
|---|
| 273 | Control.MakeAccessible(nil); | 
|---|
| 274 | end; | 
|---|
| 275 |  | 
|---|
| 276 | class procedure TAccessibleListBox.WrapControl(Control: TORListBox); | 
|---|
| 277 | var | 
|---|
| 278 | AccessibleListBox: TAccessibleListBox; | 
|---|
| 279 | {Using Accessible here is probably just interface reference count paranoia} | 
|---|
| 280 | Accessible: IAccessible; | 
|---|
| 281 | begin | 
|---|
| 282 | if not UserIsRestricted then | 
|---|
| 283 | begin | 
|---|
| 284 | AccessibleListBox := TAccessibleListBox.Create; | 
|---|
| 285 | Accessible := AccessibleListBox; | 
|---|
| 286 | AccessibleListBox.Control := Control; | 
|---|
| 287 | Control.MakeAccessible(Accessible); | 
|---|
| 288 | end; | 
|---|
| 289 | end; | 
|---|
| 290 |  | 
|---|
| 291 | initialization | 
|---|
| 292 | try | 
|---|
| 293 | TAutoObjectFactory.Create(ComServer, TAccessibleListBox, Class_AccessibleListBox, | 
|---|
| 294 | ciMultiInstance, tmApartment); | 
|---|
| 295 | except | 
|---|
| 296 | {Let the poor restricted users pass!} | 
|---|
| 297 | UserIsRestricted := True; | 
|---|
| 298 | end; | 
|---|
| 299 | end. | 
|---|