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