AccessibleObject.cs 14 KB

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