accesstest.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: accesstest.cpp
  3. // Purpose: wxWidgets accessibility sample
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 2002-02-12
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // ============================================================================
  11. // declarations
  12. // ============================================================================
  13. // ----------------------------------------------------------------------------
  14. // headers
  15. // ----------------------------------------------------------------------------
  16. // For compilers that support precompilation, includes "wx/wx.h".
  17. #include "wx/wxprec.h"
  18. #ifdef __BORLANDC__
  19. #pragma hdrstop
  20. #endif
  21. // for all others, include the necessary headers (this file is usually all you
  22. // need because it includes almost all "standard" wxWidgets headers)
  23. #ifndef WX_PRECOMP
  24. #include "wx/wx.h"
  25. #endif
  26. #if wxUSE_ACCESSIBILITY
  27. #include "wx/access.h"
  28. #endif // wxUSE_ACCESSIBILITY
  29. #include "wx/splitter.h"
  30. #include "wx/cshelp.h"
  31. #ifdef __WXMSW__
  32. #include "windows.h"
  33. #include <ole2.h>
  34. #include <oleauto.h>
  35. #if wxUSE_ACCESSIBILITY
  36. #include <oleacc.h>
  37. #endif // wxUSE_ACCESSIBILITY
  38. #include "wx/msw/ole/oleutils.h"
  39. #include "wx/msw/winundef.h"
  40. #ifndef OBJID_CLIENT
  41. #define OBJID_CLIENT 0xFFFFFFFC
  42. #endif
  43. #endif
  44. // ----------------------------------------------------------------------------
  45. // resources
  46. // ----------------------------------------------------------------------------
  47. // the application icon (under Windows and OS/2 it is in resources)
  48. #ifndef wxHAS_IMAGES_IN_RESOURCES
  49. #include "../sample.xpm"
  50. #endif
  51. // ----------------------------------------------------------------------------
  52. // private classes
  53. // ----------------------------------------------------------------------------
  54. // Define a new application type, each program should derive a class from wxApp
  55. class MyApp : public wxApp
  56. {
  57. public:
  58. // override base class virtuals
  59. // ----------------------------
  60. // this one is called on application startup and is a good place for the app
  61. // initialization (doing it here and not in the ctor allows to have an error
  62. // return: if OnInit() returns false, the application terminates)
  63. virtual bool OnInit();
  64. };
  65. #if wxUSE_ACCESSIBILITY
  66. // Define a new frame type: this is going to be our main frame
  67. class MyFrame : public wxFrame
  68. {
  69. public:
  70. // ctor(s)
  71. MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
  72. long style = wxDEFAULT_FRAME_STYLE);
  73. // event handlers (these functions should _not_ be virtual)
  74. void OnQuit(wxCommandEvent& event);
  75. void OnQuery(wxCommandEvent& event);
  76. void OnAbout(wxCommandEvent& event);
  77. // Log messages to the text control
  78. void Log(const wxString& text);
  79. // Recursively give information about an object
  80. void LogObject(int indent, IAccessible* obj);
  81. // Get info for a child (id > 0) or object (id == 0)
  82. void GetInfo(IAccessible* accessible, int id, wxString& name, wxString& role);
  83. private:
  84. wxTextCtrl* m_textCtrl;
  85. // any class wishing to process wxWidgets events must use this macro
  86. wxDECLARE_EVENT_TABLE();
  87. };
  88. // ----------------------------------------------------------------------------
  89. // constants
  90. // ----------------------------------------------------------------------------
  91. // IDs for the controls and the menu commands
  92. enum
  93. {
  94. // menu items
  95. AccessTest_Quit = 1,
  96. // query the hierarchy
  97. AccessTest_Query,
  98. // it is important for the id corresponding to the "About" command to have
  99. // this standard value as otherwise it won't be handled properly under Mac
  100. // (where it is special and put into the "Apple" menu)
  101. AccessTest_About = wxID_ABOUT
  102. };
  103. // ----------------------------------------------------------------------------
  104. // event tables and other macros for wxWidgets
  105. // ----------------------------------------------------------------------------
  106. // the event tables connect the wxWidgets events with the functions (event
  107. // handlers) which process them. It can be also done at run-time, but for the
  108. // simple menu events like this the static method is much simpler.
  109. wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
  110. EVT_MENU(AccessTest_Quit, MyFrame::OnQuit)
  111. EVT_MENU(AccessTest_Query, MyFrame::OnQuery)
  112. EVT_MENU(AccessTest_About, MyFrame::OnAbout)
  113. wxEND_EVENT_TABLE()
  114. #endif // wxUSE_ACCESSIBILITY
  115. // Create a new application object: this macro will allow wxWidgets to create
  116. // the application object during program execution (it's better than using a
  117. // static object for many reasons) and also declares the accessor function
  118. // wxGetApp() which will return the reference of the right type (i.e. MyApp and
  119. // not wxApp)
  120. IMPLEMENT_APP(MyApp)
  121. // ============================================================================
  122. // implementation
  123. // ============================================================================
  124. // ----------------------------------------------------------------------------
  125. // the application class
  126. // ----------------------------------------------------------------------------
  127. // 'Main program' equivalent: the program execution "starts" here
  128. bool MyApp::OnInit()
  129. {
  130. if ( !wxApp::OnInit() )
  131. return false;
  132. #if wxUSE_ACCESSIBILITY
  133. // Note: JAWS for Windows will only speak the context-sensitive
  134. // help if you use this help provider:
  135. // wxHelpProvider::Set(new wxHelpControllerHelpProvider(m_helpController)).
  136. // JAWS does not seem to be getting the help text from
  137. // the wxAccessible object.
  138. wxHelpProvider::Set(new wxSimpleHelpProvider());
  139. // create the main application window
  140. MyFrame *frame = new MyFrame(wxT("AccessTest wxWidgets App"),
  141. wxPoint(50, 50), wxSize(450, 340));
  142. // and show it (the frames, unlike simple controls, are not shown when
  143. // created initially)
  144. frame->Show(true);
  145. // success: wxApp::OnRun() will be called which will enter the main message
  146. // loop and the application will run. If we returned false here, the
  147. // application would exit immediately.
  148. return true;
  149. #else
  150. wxMessageBox( wxT("This sample has to be compiled with wxUSE_ACCESSIBILITY"), wxT("Building error"), wxOK);
  151. return false;
  152. #endif // wxUSE_ACCESSIBILITY
  153. }
  154. #if wxUSE_ACCESSIBILITY
  155. class FrameAccessible: public wxWindowAccessible
  156. {
  157. public:
  158. FrameAccessible(wxWindow* win): wxWindowAccessible(win) {}
  159. // Gets the name of the specified object.
  160. virtual wxAccStatus GetName(int childId, wxString* name)
  161. {
  162. if (childId == wxACC_SELF)
  163. {
  164. * name = wxT("Julian's Frame");
  165. return wxACC_OK;
  166. }
  167. else
  168. return wxACC_NOT_IMPLEMENTED;
  169. }
  170. };
  171. class ScrolledWindowAccessible: public wxWindowAccessible
  172. {
  173. public:
  174. ScrolledWindowAccessible(wxWindow* win): wxWindowAccessible(win) {}
  175. // Gets the name of the specified object.
  176. virtual wxAccStatus GetName(int childId, wxString* name)
  177. {
  178. if (childId == wxACC_SELF)
  179. {
  180. * name = wxT("My scrolled window");
  181. return wxACC_OK;
  182. }
  183. else
  184. return wxACC_NOT_IMPLEMENTED;
  185. }
  186. };
  187. class SplitterWindowAccessible: public wxWindowAccessible
  188. {
  189. public:
  190. SplitterWindowAccessible(wxWindow* win): wxWindowAccessible(win) {}
  191. // Gets the name of the specified object.
  192. virtual wxAccStatus GetName(int childId, wxString* name);
  193. // Can return either a child object, or an integer
  194. // representing the child element, starting from 1.
  195. virtual wxAccStatus HitTest(const wxPoint& pt, int* childId, wxAccessible** childObject);
  196. // Returns the rectangle for this object (id = 0) or a child element (id > 0).
  197. virtual wxAccStatus GetLocation(wxRect& rect, int elementId);
  198. // Navigates from fromId to toId/toObject.
  199. virtual wxAccStatus Navigate(wxNavDir navDir, int fromId,
  200. int* toId, wxAccessible** toObject);
  201. // Gets the number of children.
  202. virtual wxAccStatus GetChildCount(int* childCount);
  203. // Gets the specified child (starting from 1).
  204. // If *child is NULL and return value is wxACC_OK,
  205. // this means that the child is a simple element and
  206. // not an accessible object.
  207. virtual wxAccStatus GetChild(int childId, wxAccessible** child);
  208. // Gets the parent, or NULL.
  209. virtual wxAccStatus GetParent(wxAccessible** parent);
  210. // Performs the default action. childId is 0 (the action for this object)
  211. // or > 0 (the action for a child).
  212. // Return wxACC_NOT_SUPPORTED if there is no default action for this
  213. // window (e.g. an edit control).
  214. virtual wxAccStatus DoDefaultAction(int childId);
  215. // Gets the default action for this object (0) or > 0 (the action for a child).
  216. // Return wxACC_OK even if there is no action. actionName is the action, or the empty
  217. // string if there is no action.
  218. // The retrieved string describes the action that is performed on an object,
  219. // not what the object does as a result. For example, a toolbar button that prints
  220. // a document has a default action of "Press" rather than "Prints the current document."
  221. virtual wxAccStatus GetDefaultAction(int childId, wxString* actionName);
  222. // Returns the description for this object or a child.
  223. virtual wxAccStatus GetDescription(int childId, wxString* description);
  224. // Returns help text for this object or a child, similar to tooltip text.
  225. virtual wxAccStatus GetHelpText(int childId, wxString* helpText);
  226. // Returns the keyboard shortcut for this object or child.
  227. // Return e.g. ALT+K
  228. virtual wxAccStatus GetKeyboardShortcut(int childId, wxString* shortcut);
  229. // Returns a role constant.
  230. virtual wxAccStatus GetRole(int childId, wxAccRole* role);
  231. // Returns a state constant.
  232. virtual wxAccStatus GetState(int childId, long* state);
  233. // Returns a localized string representing the value for the object
  234. // or child.
  235. virtual wxAccStatus GetValue(int childId, wxString* strValue);
  236. // Selects the object or child.
  237. virtual wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags);
  238. // Gets the window with the keyboard focus.
  239. // If childId is 0 and child is NULL, no object in
  240. // this subhierarchy has the focus.
  241. // If this object has the focus, child should be 'this'.
  242. virtual wxAccStatus GetFocus(int* childId, wxAccessible** child);
  243. // Gets a variant representing the selected children
  244. // of this object.
  245. // Acceptable values:
  246. // - a null variant (IsNull() returns true)
  247. // - a list variant (GetType() == wxT("list"))
  248. // - an integer representing the selected child element,
  249. // or 0 if this object is selected (GetType() == wxT("long"))
  250. // - a "void*" pointer to a wxAccessible child object
  251. virtual wxAccStatus GetSelections(wxVariant* selections);
  252. };
  253. // ----------------------------------------------------------------------------
  254. // main frame
  255. // ----------------------------------------------------------------------------
  256. // frame constructor
  257. MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
  258. : wxFrame(NULL, wxID_ANY, title, pos, size, style)
  259. {
  260. m_textCtrl = NULL;
  261. SetAccessible(new FrameAccessible(this));
  262. // set the frame icon
  263. SetIcon(wxICON(sample));
  264. #if wxUSE_MENUS
  265. // create a menu bar
  266. wxMenu *menuFile = new wxMenu;
  267. // the "About" item should be in the help menu
  268. wxMenu *helpMenu = new wxMenu;
  269. helpMenu->Append(AccessTest_About, wxT("&About"), wxT("Show about dialog"));
  270. menuFile->Append(AccessTest_Query, wxT("Query"), wxT("Query the window hierarchy"));
  271. menuFile->AppendSeparator();
  272. menuFile->Append(AccessTest_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
  273. // now append the freshly created menu to the menu bar...
  274. wxMenuBar *menuBar = new wxMenuBar();
  275. menuBar->Append(menuFile, wxT("&File"));
  276. menuBar->Append(helpMenu, wxT("&Help"));
  277. // ... and attach this menu bar to the frame
  278. SetMenuBar(menuBar);
  279. #endif // wxUSE_MENUS
  280. #if 0 // wxUSE_STATUSBAR
  281. // create a status bar just for fun (by default with 1 pane only)
  282. CreateStatusBar(2);
  283. SetStatusText(wxT("Welcome to wxWidgets!"));
  284. #endif // wxUSE_STATUSBAR
  285. wxSplitterWindow* splitter = new wxSplitterWindow(this, wxID_ANY);
  286. splitter->SetAccessible(new SplitterWindowAccessible(splitter));
  287. wxListBox* listBox = new wxListBox(splitter, wxID_ANY);
  288. listBox->Append(wxT("Cabbages"));
  289. listBox->Append(wxT("Kings"));
  290. listBox->Append(wxT("Sealing wax"));
  291. listBox->Append(wxT("Strings"));
  292. listBox->CreateAccessible();
  293. listBox->SetHelpText(wxT("This is a sample wxWidgets listbox, with a number of items in it."));
  294. m_textCtrl = new wxTextCtrl(splitter, wxID_ANY, wxT(""), wxDefaultPosition,
  295. wxDefaultSize, wxTE_MULTILINE);
  296. m_textCtrl->CreateAccessible();
  297. m_textCtrl->SetHelpText(wxT("This is a sample wxWidgets multiline text control."));
  298. splitter->SplitHorizontally(listBox, m_textCtrl, 150);
  299. #if 0
  300. wxScrolledWindow* scrolledWindow = new wxScrolledWindow(this, wxID_ANY);
  301. scrolledWindow->SetAccessible(new ScrolledWindowAccessible(scrolledWindow));
  302. #endif
  303. }
  304. // event handlers
  305. void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
  306. {
  307. // true is to force the frame to close
  308. Close(true);
  309. }
  310. void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
  311. {
  312. wxString msg;
  313. msg.Printf( wxT("This is the About dialog of the AccessTest sample.\n")
  314. wxT("Welcome to %s"), wxVERSION_STRING);
  315. wxMessageBox(msg, wxT("About AccessTest"), wxOK | wxICON_INFORMATION, this);
  316. }
  317. void MyFrame::OnQuery(wxCommandEvent& WXUNUSED(event))
  318. {
  319. m_textCtrl->Clear();
  320. IAccessible* accessibleFrame = NULL;
  321. if (S_OK != AccessibleObjectFromWindow((HWND) GetHWND(), OBJID_CLIENT,
  322. IID_IAccessible, (void**) & accessibleFrame))
  323. {
  324. Log(wxT("Could not get object."));
  325. return;
  326. }
  327. if (accessibleFrame)
  328. {
  329. //Log(wxT("Got an IAccessible for the frame."));
  330. LogObject(0, accessibleFrame);
  331. Log(wxT("Checking children using AccessibleChildren()..."));
  332. // Now check the AccessibleChildren function works OK
  333. long childCount = 0;
  334. if (S_OK != accessibleFrame->get_accChildCount(& childCount))
  335. {
  336. Log(wxT("Could not get number of children."));
  337. accessibleFrame->Release();
  338. return;
  339. }
  340. else if (childCount == 0)
  341. {
  342. Log(wxT("No children."));
  343. accessibleFrame->Release();
  344. return;
  345. }
  346. long obtained = 0;
  347. VARIANT *var = new VARIANT[childCount];
  348. int i;
  349. for (i = 0; i < childCount; i++)
  350. {
  351. VariantInit(& (var[i]));
  352. var[i].vt = VT_DISPATCH;
  353. }
  354. if (S_OK == AccessibleChildren(accessibleFrame, 0, childCount, var, &obtained))
  355. {
  356. for (i = 0; i < childCount; i++)
  357. {
  358. IAccessible* childAccessible = NULL;
  359. if (var[i].pdispVal)
  360. {
  361. if (var[i].pdispVal->QueryInterface(IID_IAccessible, (LPVOID*) & childAccessible) == S_OK)
  362. {
  363. var[i].pdispVal->Release();
  364. wxString name, role;
  365. GetInfo(childAccessible, 0, name, role);
  366. wxString str;
  367. str.Printf(wxT("Found child %s/%s"), name.c_str(), role.c_str());
  368. Log(str);
  369. childAccessible->Release();
  370. }
  371. else
  372. {
  373. var[i].pdispVal->Release();
  374. }
  375. }
  376. }
  377. }
  378. else
  379. {
  380. Log(wxT("AccessibleChildren failed."));
  381. }
  382. delete[] var;
  383. accessibleFrame->Release();
  384. }
  385. }
  386. // Log messages to the text control
  387. void MyFrame::Log(const wxString& text)
  388. {
  389. if (m_textCtrl)
  390. {
  391. wxString text2(text);
  392. text2.Replace(wxT("\n"), wxT(" "));
  393. text2.Replace(wxT("\r"), wxT(" "));
  394. m_textCtrl->SetInsertionPointEnd();
  395. m_textCtrl->WriteText(text2 + wxT("\n"));
  396. }
  397. }
  398. // Recursively give information about an object
  399. void MyFrame::LogObject(int indent, IAccessible* obj)
  400. {
  401. wxString name, role;
  402. if (indent == 0)
  403. {
  404. GetInfo(obj, 0, name, role);
  405. wxString str;
  406. str.Printf(wxT("Name = %s; Role = %s"), name.c_str(), role.c_str());
  407. str.Pad(indent, wxT(' '), false);
  408. Log(str);
  409. }
  410. long childCount = 0;
  411. if (S_OK == obj->get_accChildCount(& childCount))
  412. {
  413. wxString str;
  414. str.Printf(wxT("There are %d children."), (int) childCount);
  415. str.Pad(indent, wxT(' '), false);
  416. Log(str);
  417. Log(wxT(""));
  418. }
  419. int i;
  420. for (i = 1; i <= childCount; i++)
  421. {
  422. GetInfo(obj, i, name, role);
  423. wxString str;
  424. str.Printf(wxT("%d) Name = %s; Role = %s"), i, name.c_str(), role.c_str());
  425. str.Pad(indent, wxT(' '), false);
  426. Log(str);
  427. VARIANT var;
  428. VariantInit(& var);
  429. var.vt = VT_I4;
  430. var.lVal = i;
  431. IDispatch* pDisp = NULL;
  432. IAccessible* childObject = NULL;
  433. if (S_OK == obj->get_accChild(var, & pDisp) && pDisp)
  434. {
  435. wxString str;
  436. str.Printf(wxT("This is a real object."));
  437. str.Pad(indent+4, wxT(' '), false);
  438. Log(str);
  439. if (pDisp->QueryInterface(IID_IAccessible, (LPVOID*) & childObject) == S_OK)
  440. {
  441. LogObject(indent + 4, childObject);
  442. childObject->Release();
  443. }
  444. pDisp->Release();
  445. }
  446. else
  447. {
  448. wxString str;
  449. str.Printf(wxT("This is an element."));
  450. str.Pad(indent+4, wxT(' '), false);
  451. Log(str);
  452. }
  453. // Log(wxT(""));
  454. }
  455. }
  456. // Get info for a child (id > 0) or object (id == 0)
  457. void MyFrame::GetInfo(IAccessible* accessible, int id, wxString& name, wxString& role)
  458. {
  459. VARIANT var;
  460. VariantInit(& var);
  461. var.vt = VT_I4;
  462. var.lVal = id;
  463. BSTR bStrName = 0;
  464. HRESULT hResult = accessible->get_accName(var, & bStrName);
  465. if (hResult == S_OK)
  466. {
  467. name = wxConvertStringFromOle(bStrName);
  468. SysFreeString(bStrName);
  469. }
  470. else
  471. {
  472. name = wxT("NO NAME");
  473. }
  474. VARIANT varRole;
  475. VariantInit(& varRole);
  476. hResult = accessible->get_accRole(var, & varRole);
  477. if (hResult == S_OK && varRole.vt == VT_I4)
  478. {
  479. wxChar buf[256];
  480. GetRoleText(varRole.lVal, buf, 256);
  481. role = buf;
  482. }
  483. else
  484. {
  485. role = wxT("NO ROLE");
  486. }
  487. }
  488. /*
  489. * SplitterWindowAccessible implementation
  490. */
  491. // Gets the name of the specified object.
  492. wxAccStatus SplitterWindowAccessible::GetName(int childId, wxString* name)
  493. {
  494. if (childId == wxACC_SELF)
  495. {
  496. * name = wxT("Splitter window");
  497. return wxACC_OK;
  498. }
  499. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  500. if (splitter)
  501. {
  502. if (splitter->IsSplit())
  503. {
  504. // Two windows, and the sash.
  505. if (childId == 1 || childId == 3)
  506. return wxACC_NOT_IMPLEMENTED;
  507. else if (childId == 2)
  508. {
  509. *name = wxT("Sash");
  510. return wxACC_OK;
  511. }
  512. }
  513. }
  514. // Let the framework handle the other cases.
  515. return wxACC_NOT_IMPLEMENTED;
  516. }
  517. // Can return either a child object, or an integer
  518. // representing the child element, starting from 1.
  519. wxAccStatus SplitterWindowAccessible::HitTest(const wxPoint& pt, int* childId, wxAccessible** WXUNUSED(childObject))
  520. {
  521. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  522. if (splitter)
  523. {
  524. if (splitter->IsSplit())
  525. {
  526. wxPoint clientPt = splitter->ScreenToClient(pt);
  527. if (splitter->SashHitTest(clientPt.x, clientPt.y, 1))
  528. {
  529. // We're over the sash
  530. *childId = 2;
  531. return wxACC_OK;
  532. }
  533. }
  534. }
  535. // Let the framework handle the other cases.
  536. return wxACC_NOT_IMPLEMENTED;
  537. }
  538. // Returns the rectangle for this object (id = 0) or a child element (id > 0).
  539. wxAccStatus SplitterWindowAccessible::GetLocation(wxRect& rect, int elementId)
  540. {
  541. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  542. if (splitter && elementId == 2 && splitter->IsSplit())
  543. {
  544. wxSize clientSize = splitter->GetClientSize();
  545. if (splitter->GetSplitMode() == wxSPLIT_VERTICAL)
  546. {
  547. rect.x = splitter->GetSashPosition();
  548. rect.y = 0;
  549. rect.SetPosition(splitter->ClientToScreen(rect.GetPosition()));
  550. rect.width = splitter->GetSashSize();
  551. rect.height = clientSize.y;
  552. }
  553. else
  554. {
  555. rect.x = 0;
  556. rect.y = splitter->GetSashPosition();
  557. rect.SetPosition(splitter->ClientToScreen(rect.GetPosition()));
  558. rect.width = clientSize.x;
  559. rect.height = splitter->GetSashSize();
  560. }
  561. return wxACC_OK;
  562. }
  563. // Let the framework handle the other cases.
  564. return wxACC_NOT_IMPLEMENTED;
  565. }
  566. // Navigates from fromId to toId/toObject.
  567. wxAccStatus SplitterWindowAccessible::Navigate(wxNavDir navDir, int fromId,
  568. int* toId, wxAccessible** toObject)
  569. {
  570. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  571. if (splitter && splitter->IsSplit())
  572. {
  573. switch (navDir)
  574. {
  575. case wxNAVDIR_DOWN:
  576. {
  577. if (splitter->GetSplitMode() != wxSPLIT_VERTICAL)
  578. {
  579. if (fromId == 1)
  580. {
  581. *toId = 2;
  582. *toObject = NULL;
  583. return wxACC_OK;
  584. }
  585. else if (fromId == 2)
  586. {
  587. *toId = 3;
  588. *toObject = splitter->GetWindow2()->GetAccessible();
  589. return wxACC_OK;
  590. }
  591. }
  592. return wxACC_FALSE;
  593. #if 0
  594. // below line is not executed due to earlier return
  595. break;
  596. #endif
  597. }
  598. case wxNAVDIR_FIRSTCHILD:
  599. {
  600. if (fromId == 2)
  601. return wxACC_FALSE;
  602. }
  603. break;
  604. case wxNAVDIR_LASTCHILD:
  605. {
  606. if (fromId == 2)
  607. return wxACC_FALSE;
  608. }
  609. break;
  610. case wxNAVDIR_LEFT:
  611. {
  612. if (splitter->GetSplitMode() != wxSPLIT_HORIZONTAL)
  613. {
  614. if (fromId == 3)
  615. {
  616. *toId = 2;
  617. *toObject = NULL;
  618. return wxACC_OK;
  619. }
  620. else if (fromId == 2)
  621. {
  622. *toId = 1;
  623. *toObject = splitter->GetWindow1()->GetAccessible();
  624. return wxACC_OK;
  625. }
  626. }
  627. return wxACC_FALSE;
  628. }
  629. #if 0
  630. // below line is not executed due to earlier return
  631. break;
  632. #endif
  633. case wxNAVDIR_NEXT:
  634. {
  635. if (fromId == 1)
  636. {
  637. *toId = 2;
  638. *toObject = NULL;
  639. return wxACC_OK;
  640. }
  641. else if (fromId == 2)
  642. {
  643. *toId = 3;
  644. *toObject = splitter->GetWindow2()->GetAccessible();
  645. return wxACC_OK;
  646. }
  647. return wxACC_FALSE;
  648. }
  649. #if 0
  650. // below line is not executed due to earlier return
  651. break;
  652. #endif
  653. case wxNAVDIR_PREVIOUS:
  654. {
  655. if (fromId == 3)
  656. {
  657. *toId = 2;
  658. *toObject = NULL;
  659. return wxACC_OK;
  660. }
  661. else if (fromId == 2)
  662. {
  663. *toId = 1;
  664. *toObject = splitter->GetWindow1()->GetAccessible();
  665. return wxACC_OK;
  666. }
  667. return wxACC_FALSE;
  668. }
  669. #if 0
  670. // below line is not executed due to earlier return
  671. break;
  672. #endif
  673. case wxNAVDIR_RIGHT:
  674. {
  675. if (splitter->GetSplitMode() != wxSPLIT_HORIZONTAL)
  676. {
  677. if (fromId == 1)
  678. {
  679. *toId = 2;
  680. *toObject = NULL;
  681. return wxACC_OK;
  682. }
  683. else if (fromId == 2)
  684. {
  685. *toId = 3;
  686. *toObject = splitter->GetWindow2()->GetAccessible();
  687. return wxACC_OK;
  688. }
  689. }
  690. // Can't go right spatially if split horizontally.
  691. return wxACC_FALSE;
  692. }
  693. #if 0
  694. // below line is not executed due to earlier return
  695. break;
  696. #endif
  697. case wxNAVDIR_UP:
  698. {
  699. if (splitter->GetSplitMode() != wxSPLIT_VERTICAL)
  700. {
  701. if (fromId == 3)
  702. {
  703. *toId = 2;
  704. return wxACC_OK;
  705. }
  706. else if (fromId == 2)
  707. {
  708. *toId = 1;
  709. *toObject = splitter->GetWindow1()->GetAccessible();
  710. return wxACC_OK;
  711. }
  712. }
  713. // Can't go up spatially if split vertically.
  714. return wxACC_FALSE;
  715. #if 0
  716. // below line is not executed due to earlier return
  717. break;
  718. #endif
  719. }
  720. }
  721. }
  722. // Let the framework handle the other cases.
  723. return wxACC_NOT_IMPLEMENTED;
  724. }
  725. // Gets the number of children.
  726. wxAccStatus SplitterWindowAccessible::GetChildCount(int* childCount)
  727. {
  728. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  729. if (splitter)
  730. {
  731. if (splitter->IsSplit())
  732. {
  733. // Two windows, and the sash.
  734. *childCount = 3;
  735. return wxACC_OK;
  736. }
  737. else
  738. {
  739. // No sash -- 1 or 0 windows.
  740. if (splitter->GetWindow1() || splitter->GetWindow2())
  741. {
  742. *childCount = 1;
  743. return wxACC_OK;
  744. }
  745. else
  746. {
  747. *childCount = 0;
  748. return wxACC_OK;
  749. }
  750. }
  751. }
  752. // Let the framework handle the other cases.
  753. return wxACC_NOT_IMPLEMENTED;
  754. }
  755. // Gets the specified child (starting from 1).
  756. // If *child is NULL and return value is wxACC_OK,
  757. // this means that the child is a simple element and
  758. // not an accessible object.
  759. wxAccStatus SplitterWindowAccessible::GetChild(int childId, wxAccessible** child)
  760. {
  761. if (childId == wxACC_SELF)
  762. {
  763. *child = this;
  764. return wxACC_OK;
  765. }
  766. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  767. if (splitter)
  768. {
  769. if (splitter->IsSplit())
  770. {
  771. // Two windows, and the sash.
  772. if (childId == 1)
  773. {
  774. *child = splitter->GetWindow1()->GetAccessible();
  775. }
  776. else if (childId == 2)
  777. {
  778. *child = NULL; // Sash
  779. }
  780. else if (childId == 3)
  781. {
  782. *child = splitter->GetWindow2()->GetAccessible();
  783. }
  784. else
  785. {
  786. return wxACC_FAIL;
  787. }
  788. return wxACC_OK;
  789. }
  790. else
  791. {
  792. // No sash -- 1 or 0 windows.
  793. if (childId == 1)
  794. {
  795. if (splitter->GetWindow1())
  796. {
  797. *child = splitter->GetWindow1()->GetAccessible();
  798. return wxACC_OK;
  799. }
  800. else if (splitter->GetWindow2())
  801. {
  802. *child = splitter->GetWindow2()->GetAccessible();
  803. return wxACC_OK;
  804. }
  805. else
  806. {
  807. return wxACC_FAIL;
  808. }
  809. }
  810. else
  811. return wxACC_FAIL;
  812. }
  813. }
  814. // Let the framework handle the other cases.
  815. return wxACC_NOT_IMPLEMENTED;
  816. }
  817. // Gets the parent, or NULL.
  818. wxAccStatus SplitterWindowAccessible::GetParent(wxAccessible** WXUNUSED(parent))
  819. {
  820. return wxACC_NOT_IMPLEMENTED;
  821. }
  822. // Performs the default action. childId is 0 (the action for this object)
  823. // or > 0 (the action for a child).
  824. // Return wxACC_NOT_SUPPORTED if there is no default action for this
  825. // window (e.g. an edit control).
  826. wxAccStatus SplitterWindowAccessible::DoDefaultAction(int WXUNUSED(childId))
  827. {
  828. return wxACC_NOT_IMPLEMENTED;
  829. }
  830. // Gets the default action for this object (0) or > 0 (the action for a child).
  831. // Return wxACC_OK even if there is no action. actionName is the action, or the empty
  832. // string if there is no action.
  833. // The retrieved string describes the action that is performed on an object,
  834. // not what the object does as a result. For example, a toolbar button that prints
  835. // a document has a default action of "Press" rather than "Prints the current document."
  836. wxAccStatus SplitterWindowAccessible::GetDefaultAction(int childId, wxString* WXUNUSED(actionName))
  837. {
  838. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  839. if (splitter && splitter->IsSplit() && childId == 2)
  840. {
  841. // No default action for the splitter.
  842. return wxACC_FALSE;
  843. }
  844. // Let the framework handle the other cases.
  845. return wxACC_NOT_IMPLEMENTED;
  846. }
  847. // Returns the description for this object or a child.
  848. wxAccStatus SplitterWindowAccessible::GetDescription(int childId, wxString* description)
  849. {
  850. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  851. if (splitter)
  852. {
  853. if (splitter->IsSplit())
  854. {
  855. if (childId == 2)
  856. {
  857. * description = _("The splitter window sash.");
  858. return wxACC_OK;
  859. }
  860. }
  861. }
  862. // Let the framework handle the other cases.
  863. return wxACC_NOT_IMPLEMENTED;
  864. }
  865. // Returns help text for this object or a child, similar to tooltip text.
  866. wxAccStatus SplitterWindowAccessible::GetHelpText(int childId, wxString* helpText)
  867. {
  868. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  869. if (splitter)
  870. {
  871. if (splitter->IsSplit())
  872. {
  873. if (childId == 2)
  874. {
  875. * helpText = _("The splitter window sash.");
  876. return wxACC_OK;
  877. }
  878. }
  879. }
  880. // Let the framework handle the other cases.
  881. return wxACC_NOT_IMPLEMENTED;
  882. }
  883. // Returns the keyboard shortcut for this object or child.
  884. // Return e.g. ALT+K
  885. wxAccStatus SplitterWindowAccessible::GetKeyboardShortcut(int childId, wxString* WXUNUSED(shortcut))
  886. {
  887. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  888. if (splitter && splitter->IsSplit() && childId == 2)
  889. {
  890. // No keyboard shortcut for the splitter.
  891. return wxACC_FALSE;
  892. }
  893. // Let the framework handle the other cases.
  894. return wxACC_NOT_IMPLEMENTED;
  895. }
  896. // Returns a role constant.
  897. wxAccStatus SplitterWindowAccessible::GetRole(int childId, wxAccRole* role)
  898. {
  899. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  900. if (splitter)
  901. {
  902. if (splitter->IsSplit())
  903. {
  904. if (childId == 2)
  905. {
  906. * role = wxROLE_SYSTEM_GRIP;
  907. return wxACC_OK;
  908. }
  909. }
  910. }
  911. // Let the framework handle the other cases.
  912. return wxACC_NOT_IMPLEMENTED;
  913. }
  914. // Returns a state constant.
  915. wxAccStatus SplitterWindowAccessible::GetState(int childId, long* state)
  916. {
  917. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  918. if (splitter && splitter->IsSplit() && childId == 2)
  919. {
  920. // No particular state. Not sure what would be appropriate here.
  921. *state = wxACC_STATE_SYSTEM_UNAVAILABLE;
  922. return wxACC_OK;
  923. }
  924. // Let the framework handle the other cases.
  925. return wxACC_NOT_IMPLEMENTED;
  926. }
  927. // Returns a localized string representing the value for the object
  928. // or child.
  929. wxAccStatus SplitterWindowAccessible::GetValue(int childId, wxString* strValue)
  930. {
  931. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  932. if (splitter && splitter->IsSplit() && childId == 2)
  933. {
  934. // The sash position is the value.
  935. wxString pos;
  936. pos << splitter->GetSashPosition();
  937. *strValue = pos;
  938. return wxACC_OK;
  939. }
  940. // Let the framework handle the other cases.
  941. return wxACC_NOT_IMPLEMENTED;
  942. }
  943. // Selects the object or child.
  944. wxAccStatus SplitterWindowAccessible::Select(int childId, wxAccSelectionFlags WXUNUSED(selectFlags))
  945. {
  946. wxSplitterWindow* splitter = wxDynamicCast(GetWindow(), wxSplitterWindow);
  947. if (splitter && splitter->IsSplit() && childId == 2)
  948. {
  949. // Can't select the sash.
  950. return wxACC_FALSE;
  951. }
  952. // Let the framework handle the other cases.
  953. return wxACC_NOT_IMPLEMENTED;
  954. }
  955. // Gets the window with the keyboard focus.
  956. // If childId is 0 and child is NULL, no object in
  957. // this subhierarchy has the focus.
  958. // If this object has the focus, child should be 'this'.
  959. wxAccStatus SplitterWindowAccessible::GetFocus(int* WXUNUSED(childId), wxAccessible** WXUNUSED(child))
  960. {
  961. return wxACC_NOT_IMPLEMENTED;
  962. }
  963. // Gets a variant representing the selected children
  964. // of this object.
  965. // Acceptable values:
  966. // - a null variant (IsNull() returns true)
  967. // - a list variant (GetType() == wxT("list"))
  968. // - an integer representing the selected child element,
  969. // or 0 if this object is selected (GetType() == wxT("long"))
  970. // - a "void*" pointer to a wxAccessible child object
  971. wxAccStatus SplitterWindowAccessible::GetSelections(wxVariant* WXUNUSED(selections))
  972. {
  973. return wxACC_NOT_IMPLEMENTED;
  974. }
  975. #endif // wxUSE_ACCESSIBILITY