AccessibleObject.cs 14 KB

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