AccessibleObject.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. //
  25. //
  26. // $Log: AccessibleObject.cs,v $
  27. // Revision 1.3 2004/09/02 20:25:21 pbartok
  28. // - Added missing methods
  29. //
  30. // Revision 1.2 2004/08/11 13:44:33 pbartok
  31. // - Fixed to match ControlCollection rewrite
  32. //
  33. // Revision 1.1 2004/07/09 05:21:25 pbartok
  34. // - Initial check-in
  35. //
  36. //
  37. // NOT COMPLETE
  38. using Accessibility;
  39. using System.Drawing;
  40. using System.Globalization;
  41. using System.Reflection;
  42. using System.Runtime.InteropServices;
  43. namespace System.Windows.Forms {
  44. public class AccessibleObject : MarshalByRefObject, IReflect, IAccessible {
  45. #region Private Variables
  46. private string name;
  47. private string value;
  48. private Control owner;
  49. internal AccessibleRole role;
  50. internal string default_action;
  51. internal string description;
  52. internal string help;
  53. internal string keyboard_shortcut;
  54. #endregion // Private Variables
  55. #region Public Constructors
  56. public AccessibleObject() {
  57. this.owner=null;
  58. this.value=null;
  59. this.name=null;
  60. this.role=AccessibleRole.Default;
  61. this.default_action=null;
  62. this.description=null;
  63. this.help=null;
  64. this.keyboard_shortcut=null;
  65. }
  66. #endregion // Public Constructors
  67. #region Private Constructors
  68. internal AccessibleObject(Control owner) : this () {
  69. this.owner=owner;
  70. }
  71. #endregion // Private Constructors
  72. #region Public Instance Properties
  73. public virtual Rectangle Bounds {
  74. get {
  75. return Rectangle.Empty;
  76. }
  77. }
  78. public virtual string DefaultAction {
  79. get {
  80. return default_action;
  81. }
  82. }
  83. public virtual string Description {
  84. get {
  85. return description;
  86. }
  87. }
  88. public virtual string Help {
  89. get {
  90. return help;
  91. }
  92. }
  93. public virtual string KeyboardShortcut {
  94. get {
  95. return keyboard_shortcut;
  96. }
  97. }
  98. public virtual string Name {
  99. get {
  100. return name;
  101. }
  102. set {
  103. name=value;
  104. }
  105. }
  106. public virtual AccessibleObject Parent {
  107. get {
  108. if ((owner!=null) && (owner.Parent!=null)) {
  109. return owner.Parent.AccessibilityObject;
  110. }
  111. return null;
  112. }
  113. }
  114. public virtual AccessibleRole Role {
  115. get {
  116. return role;
  117. }
  118. }
  119. public virtual AccessibleStates State {
  120. get {
  121. AccessibleStates state=AccessibleStates.None;
  122. if (owner!=null) {
  123. if (owner.Focused) {
  124. state |= AccessibleStates.Focused;
  125. }
  126. if (!owner.Visible) {
  127. state |= AccessibleStates.Invisible;
  128. }
  129. }
  130. return state;
  131. }
  132. }
  133. public virtual string Value {
  134. get {
  135. return this.value;
  136. }
  137. set {
  138. this.value=value;
  139. }
  140. }
  141. #endregion // Public Instance Properties
  142. #region Public Instance Methods
  143. public virtual void DoDefaultAction() {
  144. if (owner!=null) {
  145. owner.DoDefaultAction();
  146. }
  147. }
  148. public virtual AccessibleObject GetChild(int index) {
  149. if (owner!=null) {
  150. if (index<owner.child_controls.Count) {
  151. return owner.child_controls[index].AccessibilityObject;
  152. }
  153. }
  154. return null;
  155. }
  156. public virtual int GetChildCount() {
  157. if (owner!=null) {
  158. return owner.child_controls.Count;
  159. }
  160. return -1;
  161. }
  162. public virtual AccessibleObject GetFocused() {
  163. Control result;
  164. if (owner.has_focus) {
  165. return owner.AccessibilityObject;
  166. }
  167. result = FindFocusControl(owner);
  168. if (result != null) {
  169. return result.AccessibilityObject;
  170. }
  171. return null;
  172. }
  173. [MonoTODO("Integrate help into accessibility system")]
  174. public virtual int GetHelpTopic(out string FileName) {
  175. FileName = null;
  176. return -1;
  177. }
  178. public virtual AccessibleObject GetSelected() {
  179. Control result;
  180. if (owner.is_selected) {
  181. return owner.AccessibilityObject;
  182. }
  183. result = FindSelectedControl(owner);
  184. if (result != null) {
  185. return result.AccessibilityObject;
  186. }
  187. return null;
  188. }
  189. public virtual AccessibleObject HitTest(int x, int y) {
  190. Control result;
  191. result = FindHittestControl(owner, x, y);
  192. if (result != null) {
  193. return result.AccessibilityObject;
  194. }
  195. return null;
  196. }
  197. public virtual AccessibleObject Navigate(AccessibleNavigation navdir) {
  198. int index;
  199. // I'm not throwing exceptions if an object doesn't exist in the specified direction
  200. // Might not be too helpful to a blind dude trying to navigate. Instead we return
  201. // our own object
  202. if (owner.parent != null) {
  203. index = owner.parent.child_controls.IndexOf(owner);
  204. } else {
  205. index = -1;
  206. }
  207. switch (navdir) {
  208. // Spatial navigation; limited to siblings
  209. case AccessibleNavigation.Up: {
  210. if (owner.parent != null) {
  211. for (int i=0; i<owner.parent.child_controls.Count; i++) {
  212. if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Top<owner.Top)) {
  213. return owner.parent.child_controls[i].AccessibilityObject;
  214. }
  215. }
  216. }
  217. return owner.AccessibilityObject;
  218. }
  219. case AccessibleNavigation.Down: {
  220. if (owner.parent != null) {
  221. for (int i=0; i<owner.parent.child_controls.Count; i++) {
  222. if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Top>owner.Bottom)) {
  223. return owner.parent.child_controls[i].AccessibilityObject;
  224. }
  225. }
  226. }
  227. return owner.AccessibilityObject;
  228. }
  229. case AccessibleNavigation.Left: {
  230. if (owner.parent != null) {
  231. for (int i=0; i<owner.parent.child_controls.Count; i++) {
  232. if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Left<owner.Left)) {
  233. return owner.parent.child_controls[i].AccessibilityObject;
  234. }
  235. }
  236. }
  237. return owner.AccessibilityObject;
  238. }
  239. case AccessibleNavigation.Right: {
  240. if (owner.parent != null) {
  241. for (int i=0; i<owner.parent.child_controls.Count; i++) {
  242. if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Left>owner.Right)) {
  243. return owner.parent.child_controls[i].AccessibilityObject;
  244. }
  245. }
  246. }
  247. return owner.AccessibilityObject;
  248. }
  249. // Logical navigation
  250. case AccessibleNavigation.Next: {
  251. if (owner.parent != null) {
  252. if ((index+1)<owner.parent.child_controls.Count) {
  253. return owner.parent.child_controls[index+1].AccessibilityObject;
  254. } else {
  255. return owner.parent.child_controls[0].AccessibilityObject;
  256. }
  257. } else {
  258. return owner.AccessibilityObject;
  259. }
  260. }
  261. case AccessibleNavigation.Previous: {
  262. if (owner.parent != null) {
  263. if (index>0) {
  264. return owner.parent.child_controls[index-1].AccessibilityObject;
  265. } else {
  266. return owner.parent.child_controls[owner.parent.child_controls.Count-1].AccessibilityObject;
  267. }
  268. } else {
  269. return owner.AccessibilityObject;
  270. }
  271. }
  272. case AccessibleNavigation.FirstChild: {
  273. if (owner.child_controls.Count>0) {
  274. return owner.child_controls[0].AccessibilityObject;
  275. } else {
  276. return owner.AccessibilityObject;
  277. }
  278. }
  279. case AccessibleNavigation.LastChild: {
  280. if (owner.child_controls.Count>0) {
  281. return owner.child_controls[owner.child_controls.Count-1].AccessibilityObject;
  282. } else {
  283. return owner.AccessibilityObject;
  284. }
  285. }
  286. }
  287. return owner.AccessibilityObject;
  288. }
  289. [MonoTODO("Finish Select when Control.Select is complete")]
  290. public virtual void Select(AccessibleSelection flags) {
  291. if ((flags & AccessibleSelection.TakeFocus) != 0){
  292. owner.has_focus = true;
  293. }
  294. return;
  295. }
  296. #endregion // Public Instance Methods
  297. #region Protected Instance Methods
  298. protected void UseStdAccessibleObjects(IntPtr handle) {
  299. }
  300. protected void UseStdAccessibleObjects(IntPtr handle, int objid) {
  301. UseStdAccessibleObjects(handle, 0);
  302. }
  303. #endregion // Protected Instance Methods
  304. #region Internal Methods
  305. internal static Control FindFocusControl(Control parent) {
  306. Control child;
  307. for (int i=0; i < parent.child_controls.Count; i++) {
  308. child=parent.child_controls[i];
  309. if (child.has_focus) {
  310. return child;
  311. }
  312. if (child.child_controls.Count>0) {
  313. Control result;
  314. result = FindFocusControl(child);
  315. if (result != null) {
  316. return result;
  317. }
  318. }
  319. }
  320. return null;
  321. }
  322. internal static Control FindSelectedControl(Control parent) {
  323. Control child;
  324. for (int i=0; i < parent.child_controls.Count; i++) {
  325. child=parent.child_controls[i];
  326. if (child.has_focus) {
  327. return child;
  328. }
  329. if (child.child_controls.Count>0) {
  330. Control result;
  331. result = FindSelectedControl(child);
  332. if (result != null) {
  333. return result;
  334. }
  335. }
  336. }
  337. return null;
  338. }
  339. internal static Control FindHittestControl(Control parent, int x, int y) {
  340. Control child;
  341. Point child_point;
  342. Point hittest_point;
  343. hittest_point = new Point(x, y);
  344. child_point = parent.PointToClient(hittest_point);
  345. if (parent.ClientRectangle.Contains(child_point)) {
  346. return parent;
  347. }
  348. for (int i=0; i < parent.child_controls.Count; i++) {
  349. child=parent.child_controls[i];
  350. child_point = child.PointToClient(hittest_point);
  351. if (child.ClientRectangle.Contains(child_point)) {
  352. return child;
  353. }
  354. if (child.child_controls.Count>0) {
  355. Control result;
  356. result = FindHittestControl(child, x, y);
  357. if (result != null) {
  358. return result;
  359. }
  360. }
  361. }
  362. return null;
  363. }
  364. #endregion // Internal Methods
  365. #region IReflection Methods and Properties
  366. FieldInfo IReflect.GetField(String name, BindingFlags bindingAttr) {
  367. throw new NotImplementedException();
  368. }
  369. FieldInfo[] IReflect.GetFields(BindingFlags bindingAttr) {
  370. throw new NotImplementedException();
  371. }
  372. MemberInfo[] IReflect.GetMember(String name, BindingFlags bindingAttr) {
  373. throw new NotImplementedException();
  374. }
  375. MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr) {
  376. throw new NotImplementedException();
  377. }
  378. MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr) {
  379. throw new NotImplementedException();
  380. }
  381. MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) {
  382. throw new NotImplementedException();
  383. }
  384. MethodInfo[] IReflect.GetMethods(BindingFlags bindingAttr) {
  385. throw new NotImplementedException();
  386. }
  387. PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr) {
  388. throw new NotImplementedException();
  389. }
  390. PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
  391. throw new NotImplementedException();
  392. }
  393. PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr) {
  394. throw new NotImplementedException();
  395. }
  396. Object IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) {
  397. throw new NotImplementedException();
  398. }
  399. Type IReflect.UnderlyingSystemType {
  400. get {
  401. throw new NotImplementedException();
  402. }
  403. }
  404. #endregion // IReflection Methods and Properties
  405. #region IAccessible Methods and Properties
  406. void IAccessible.accDoDefaultAction(object childID) {
  407. throw new NotImplementedException();
  408. }
  409. int IAccessible.accChildCount {
  410. get {
  411. throw new NotImplementedException();
  412. }
  413. }
  414. object IAccessible.accFocus {
  415. get {
  416. throw new NotImplementedException();
  417. }
  418. }
  419. object IAccessible.accHitTest(int xLeft, int yTop) {
  420. throw new NotImplementedException();
  421. }
  422. void IAccessible.accLocation(out int pxLeft, out int pyTop, out int pcxWidth, out int pcyHeight, object childID) {
  423. throw new NotImplementedException();
  424. }
  425. object IAccessible.accNavigate(int navDir, object childID) {
  426. throw new NotImplementedException();
  427. }
  428. object IAccessible.accParent {
  429. get {
  430. throw new NotImplementedException();
  431. }
  432. }
  433. void IAccessible.accSelect(int flagsSelect, object childID) {
  434. throw new NotImplementedException();
  435. }
  436. object IAccessible.accSelection {
  437. get {
  438. throw new NotImplementedException();
  439. }
  440. }
  441. object IAccessible.get_accChild(object childID) {
  442. throw new NotImplementedException();
  443. }
  444. string IAccessible.get_accDefaultAction(object childID) {
  445. throw new NotImplementedException();
  446. }
  447. string IAccessible.get_accDescription(object childID) {
  448. throw new NotImplementedException();
  449. }
  450. string IAccessible.get_accHelp(object childID) {
  451. throw new NotImplementedException();
  452. }
  453. int IAccessible.get_accHelpTopic(out string pszHelpFile,object childID) {
  454. throw new NotImplementedException();
  455. }
  456. string IAccessible.get_accKeyboardShortcut(object childID) {
  457. throw new NotImplementedException();
  458. }
  459. string IAccessible.get_accName(object childID) {
  460. throw new NotImplementedException();
  461. }
  462. object IAccessible.get_accRole(object childID) {
  463. throw new NotImplementedException();
  464. }
  465. object IAccessible.get_accState(object childID) {
  466. throw new NotImplementedException();
  467. }
  468. string IAccessible.get_accValue(object childID) {
  469. throw new NotImplementedException();
  470. }
  471. void IAccessible.set_accName(object childID, string newName) {
  472. throw new NotImplementedException();
  473. }
  474. void IAccessible.set_accValue(object childID, string newValue) {
  475. throw new NotImplementedException();
  476. }
  477. #endregion // IAccessible Methods and Properties
  478. }
  479. }