Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2106 lines
61 KiB

  1. //
  2. //
  3. //
  4. #include "private.h"
  5. #include "immxutil.h"
  6. #include "candacc.h"
  7. //
  8. //
  9. //
  10. static BOOL fMSAAAvail = FALSE;
  11. static HMODULE hLibUser32 = NULL;
  12. static HMODULE hLibOleAcc = NULL;
  13. static HMODULE hLibOle32 = NULL;
  14. static HMODULE hLibOleAut32 = NULL;
  15. typedef void (*LPFN_NOTIFYWINEVENT)( DWORD, HWND, LONG, LONG );
  16. typedef HRESULT (*LPFN_LOADREGTYPELIB)( REFGUID, unsigned short, unsigned short, LCID, ITypeLib FAR* FAR* );
  17. typedef HRESULT (*LPFN_LOADTYPELIB)( OLECHAR FAR*, ITypeLib FAR* FAR* );
  18. typedef HRESULT (*LPFN_CREATESTDACCESSIBLEOBLECT)( HWND, LONG, REFIID, void** );
  19. typedef LRESULT (*LPFN_LRESULTFROMOBJECT)( REFIID, WPARAM, LPUNKNOWN );
  20. static LPFN_NOTIFYWINEVENT lpfnNotifyWinEvent = NULL;
  21. static LPFN_LOADREGTYPELIB lpfnLoadRegTypeLib = NULL;
  22. static LPFN_LOADTYPELIB lpfnLoadTypeLib = NULL;
  23. static LPFN_CREATESTDACCESSIBLEOBLECT lpfnCreateStdAccessibleObject = NULL;
  24. static LPFN_LRESULTFROMOBJECT lpfnLresultFromObject = NULL;
  25. /* I N I T C A N D A C C */
  26. /*------------------------------------------------------------------------------
  27. ------------------------------------------------------------------------------*/
  28. void InitCandAcc( void )
  29. {
  30. if (fMSAAAvail) {
  31. return;
  32. }
  33. //
  34. // load libs
  35. //
  36. hLibUser32 = GetSystemModuleHandle( "user32.dll" );
  37. hLibOleAcc = LoadSystemLibrary( "oleacc.dll" );
  38. hLibOle32 = LoadSystemLibrary( "ole32.dll" );
  39. hLibOleAut32 = LoadSystemLibrary( "oleaut32.dll" );
  40. if (hLibUser32 == NULL || hLibOle32 == NULL || hLibOleAut32 == NULL || hLibOleAcc == NULL) {
  41. return;
  42. }
  43. //
  44. // get proc address
  45. //
  46. lpfnNotifyWinEvent = (LPFN_NOTIFYWINEVENT)GetProcAddress( hLibUser32, "NotifyWinEvent" );
  47. lpfnLoadRegTypeLib = (LPFN_LOADREGTYPELIB)GetProcAddress( hLibOleAut32, "LoadRegTypeLib" );
  48. lpfnLoadTypeLib = (LPFN_LOADTYPELIB)GetProcAddress( hLibOleAut32, "LoadTypeLib" );
  49. lpfnCreateStdAccessibleObject = (LPFN_CREATESTDACCESSIBLEOBLECT)GetProcAddress( hLibOleAcc, "CreateStdAccessibleObject" );
  50. lpfnLresultFromObject = (LPFN_LRESULTFROMOBJECT)GetProcAddress( hLibOleAcc, "LresultFromObject" );
  51. if( lpfnNotifyWinEvent == NULL ||
  52. lpfnLoadRegTypeLib == NULL ||
  53. lpfnLoadTypeLib == NULL ||
  54. lpfnCreateStdAccessibleObject == NULL ||
  55. lpfnLresultFromObject == NULL) {
  56. return;
  57. }
  58. fMSAAAvail = TRUE;
  59. }
  60. /* D O N E C A N D A C C */
  61. /*------------------------------------------------------------------------------
  62. ------------------------------------------------------------------------------*/
  63. void DoneCandAcc( void )
  64. {
  65. if (hLibOleAut32 != NULL) {
  66. FreeLibrary( hLibOleAut32 );
  67. }
  68. if (hLibOle32 != NULL) {
  69. FreeLibrary( hLibOle32 );
  70. }
  71. if (hLibOleAcc != NULL) {
  72. FreeLibrary( hLibOleAcc );
  73. }
  74. lpfnNotifyWinEvent = NULL;
  75. lpfnLoadRegTypeLib = NULL;
  76. lpfnLoadTypeLib = NULL;
  77. lpfnCreateStdAccessibleObject = NULL;
  78. lpfnLresultFromObject = NULL;
  79. fMSAAAvail = FALSE;
  80. }
  81. /* O U R N O T I F Y W I N E V E N T */
  82. /*------------------------------------------------------------------------------
  83. ------------------------------------------------------------------------------*/
  84. static __inline void OurNotifyWinEvent( DWORD event, HWND hWnd, LONG idObject, LONG idChild )
  85. {
  86. if (fMSAAAvail) {
  87. lpfnNotifyWinEvent( event, hWnd, idObject, idChild );
  88. }
  89. }
  90. /* O U R C R E A T E S T D A C C E S S I B L E O B J E C T */
  91. /*------------------------------------------------------------------------------
  92. ------------------------------------------------------------------------------*/
  93. static __inline HRESULT OurCreateStdAccessibleObject( HWND hWnd, LONG idObject, REFIID riid, void** ppvObject )
  94. {
  95. if (fMSAAAvail) {
  96. return lpfnCreateStdAccessibleObject( hWnd, idObject, riid, ppvObject );
  97. }
  98. return S_FALSE;
  99. }
  100. /* O U R L R E S U L T F R O M O B J E C T */
  101. /*------------------------------------------------------------------------------
  102. ------------------------------------------------------------------------------*/
  103. static __inline LRESULT OurLresultFromObject( REFIID riid, WPARAM wParam, LPUNKNOWN punk )
  104. {
  105. if (fMSAAAvail) {
  106. return lpfnLresultFromObject(riid,wParam,punk);
  107. }
  108. return 0;
  109. }
  110. /* O U R L O A D R E G T Y P E L I B */
  111. /*------------------------------------------------------------------------------
  112. ------------------------------------------------------------------------------*/
  113. static __inline HRESULT OurLoadRegTypeLib( REFGUID rguid, unsigned short wVerMajor, unsigned short wVerMinor, LCID lcid, ITypeLib FAR* FAR* pptlib )
  114. {
  115. if (fMSAAAvail) {
  116. return lpfnLoadRegTypeLib( rguid, wVerMajor, wVerMinor, lcid, pptlib );
  117. }
  118. return S_FALSE;
  119. }
  120. /* O U R L O A D T Y P E L I B */
  121. /*------------------------------------------------------------------------------
  122. ------------------------------------------------------------------------------*/
  123. static __inline HRESULT OurLoadTypeLib( OLECHAR FAR *szFile, ITypeLib FAR* FAR* pptlib )
  124. {
  125. if (fMSAAAvail) {
  126. return lpfnLoadTypeLib( szFile, pptlib );
  127. }
  128. return S_FALSE;
  129. }
  130. //
  131. //
  132. //
  133. /* C C A N D A C C I T E M */
  134. /*------------------------------------------------------------------------------
  135. ------------------------------------------------------------------------------*/
  136. CCandAccItem::CCandAccItem( void )
  137. {
  138. m_pCandAcc = NULL;
  139. m_iItemID = 0;
  140. }
  141. /* ~ C C A N D A C C I T E M */
  142. /*------------------------------------------------------------------------------
  143. ------------------------------------------------------------------------------*/
  144. CCandAccItem::~CCandAccItem( void )
  145. {
  146. }
  147. /* I N I T */
  148. /*------------------------------------------------------------------------------
  149. ------------------------------------------------------------------------------*/
  150. void CCandAccItem::Init( CCandAccessible *pCandAcc, int iItemID )
  151. {
  152. m_pCandAcc = pCandAcc;
  153. m_iItemID = iItemID;
  154. }
  155. /* G E T I D */
  156. /*------------------------------------------------------------------------------
  157. ------------------------------------------------------------------------------*/
  158. int CCandAccItem::GetID( void )
  159. {
  160. return m_iItemID;
  161. }
  162. /* G E T A C C N A M E */
  163. /*------------------------------------------------------------------------------
  164. ------------------------------------------------------------------------------*/
  165. BSTR CCandAccItem::GetAccName( void )
  166. {
  167. return SysAllocString( L"" );
  168. }
  169. /* G E T A C C V A L U E */
  170. /*------------------------------------------------------------------------------
  171. ------------------------------------------------------------------------------*/
  172. BSTR CCandAccItem::GetAccValue( void )
  173. {
  174. return NULL;
  175. }
  176. /* G E T A C C R O L E */
  177. /*------------------------------------------------------------------------------
  178. ------------------------------------------------------------------------------*/
  179. LONG CCandAccItem::GetAccRole( void )
  180. {
  181. return ROLE_SYSTEM_CLIENT;
  182. }
  183. /* G E T A C C S T A T E */
  184. /*------------------------------------------------------------------------------
  185. ------------------------------------------------------------------------------*/
  186. LONG CCandAccItem::GetAccState( void )
  187. {
  188. return STATE_SYSTEM_DEFAULT;
  189. }
  190. /* G E T A C C L O C A T I O N */
  191. /*------------------------------------------------------------------------------
  192. ------------------------------------------------------------------------------*/
  193. void CCandAccItem::GetAccLocation( RECT *prc )
  194. {
  195. SetRect( prc, 0, 0, 0, 0 );
  196. }
  197. /* N O T I F Y W I N E V E N T */
  198. /*------------------------------------------------------------------------------
  199. ------------------------------------------------------------------------------*/
  200. void CCandAccItem::NotifyWinEvent( DWORD dwEvent )
  201. {
  202. if (m_pCandAcc != NULL) {
  203. m_pCandAcc->NotifyWinEvent( dwEvent, this );
  204. }
  205. }
  206. //
  207. // CCandAccessible
  208. //
  209. /* C C A N D A C C E S S I B L E */
  210. /*------------------------------------------------------------------------------
  211. Constructor of CCandAccessible
  212. ------------------------------------------------------------------------------*/
  213. CCandAccessible::CCandAccessible( CCandAccItem *pAccItemSelf )
  214. {
  215. m_cRef = 1;
  216. m_hWnd = NULL;
  217. m_pTypeInfo = NULL;
  218. m_pDefAccClient = NULL;
  219. m_fInitialized = FALSE;
  220. m_nAccItem = 0;
  221. // register itself
  222. pAccItemSelf->Init( this, CHILDID_SELF );
  223. m_rgAccItem[0] = pAccItemSelf;
  224. m_nAccItem = 1;
  225. }
  226. /* ~ C C A N D A C C E S S I B L E */
  227. /*------------------------------------------------------------------------------
  228. Destructor of CCandAccessible
  229. ------------------------------------------------------------------------------*/
  230. CCandAccessible::~CCandAccessible( void )
  231. {
  232. SafeReleaseClear( m_pTypeInfo );
  233. SafeReleaseClear( m_pDefAccClient );
  234. }
  235. /* S E T W I N D O W */
  236. /*------------------------------------------------------------------------------
  237. ------------------------------------------------------------------------------*/
  238. void CCandAccessible::SetWindow( HWND hWnd )
  239. {
  240. m_hWnd = hWnd;
  241. }
  242. /* I N I T I A L I Z E */
  243. /*------------------------------------------------------------------------------
  244. //-----------------------------------------------------------------------
  245. // Initialize()
  246. //
  247. // DESCRIPTION:
  248. //
  249. // Initializes the state of the CCandAccessible object, performing
  250. // tasks that might normally be done in a class constructor but
  251. // are done here to trap any errors.
  252. //
  253. // PARAMETERS:
  254. //
  255. // hWnd Handle to the HWND object with which this
  256. // Accessible object is associated. This
  257. // is the handle to our main window.
  258. //
  259. // hInst Instance handle for this instance of the
  260. // application.
  261. //
  262. // RETURNS:
  263. //
  264. // HRESULT NOERROR if the CCandAccessible object is
  265. // initialized successfully, a COM error
  266. // code otherwise.
  267. //
  268. // NOTES:
  269. //
  270. // It is assumed that this method will be called for the object
  271. // immediately after and only after the object is constructed.
  272. //
  273. // ----------------------------------------------------------------------
  274. ------------------------------------------------------------------------------*/
  275. HRESULT CCandAccessible::Initialize( void )
  276. {
  277. HRESULT hr;
  278. ITypeLib *piTypeLib;
  279. m_fInitialized = TRUE;
  280. //-----------------------------------------------------
  281. // For our client window, create a system provided
  282. // Accessible object which implements the default
  283. // client window Accessibility behavior.
  284. //
  285. // Our implementation of CCandAccessible will use the
  286. // default object's implementation as needed. In
  287. // essence, CCandAccessible "inherits" its functionality
  288. // from the standard object, "customizing" or
  289. // "overriding" various methods for which the
  290. // standard implementation is insufficent for the
  291. // specifics of the window for which CCandAccessible
  292. // provides Accessibility.
  293. //-----------------------------------------------------
  294. hr = OurCreateStdAccessibleObject( m_hWnd,
  295. OBJID_CLIENT,
  296. IID_IAccessible,
  297. (void **) &m_pDefAccClient );
  298. if (FAILED( hr )) {
  299. return hr;
  300. }
  301. //-----------------------------------------------------
  302. // Obtain an ITypeInfo pointer to our type library.
  303. // The ITypeInfo pointer is used to implement the
  304. // IDispatch interface.
  305. //-----------------------------------------------------
  306. //-----------------------------------------------------
  307. // First, attempt to load the Accessibility type
  308. // library version 1.0 using the registry.
  309. //-----------------------------------------------------
  310. hr = LoadRegTypeLib( LIBID_Accessibility, 1, 0, 0, &piTypeLib );
  311. //-----------------------------------------------------
  312. // If we fail to load the type library from the
  313. // registry information, explicitly try to load
  314. // it from the MSAA system DLL.
  315. //-----------------------------------------------------
  316. if (FAILED( hr )) {
  317. static OLECHAR szOleAcc[] = L"OLEACC.DLL";
  318. hr = LoadTypeLib( szOleAcc, &piTypeLib );
  319. }
  320. //-----------------------------------------------------
  321. // If we successfully load the type library, attempt
  322. // to get the IAccessible type description
  323. // (ITypeInfo pointer) from the type library.
  324. //-----------------------------------------------------
  325. if (SUCCEEDED( hr )) {
  326. hr = piTypeLib->GetTypeInfoOfGuid( IID_IAccessible, &m_pTypeInfo );
  327. piTypeLib->Release();
  328. }
  329. return hr;
  330. }
  331. /* Q U E R Y I N T E R F A C E */
  332. /*------------------------------------------------------------------------------
  333. //-----------------------------------------------------------------------
  334. // QueryInterface()
  335. //
  336. // DESCRIPTION:
  337. //
  338. // Implements the IUnknown interface method QueryInterface().
  339. //
  340. // PARAMETERS:
  341. //
  342. // riid [in] The requested interface's IID.
  343. // ppv [out] If the requested interface is supported,
  344. // ppv points to the location of a pointer
  345. // to the requested interface. If the
  346. // requested interface is not supported,
  347. // ppv is set to NULL.
  348. //
  349. // RETURNS:
  350. //
  351. // HRESULT S_OK if the interface is supported,
  352. // E_NOINTERFACE if the interface is not
  353. // supported, or some other COM error
  354. // if the IEnumVARIANT interface is requested
  355. // but cannot be delivered.
  356. //
  357. // NOTES:
  358. //
  359. // CCandAccessible correctly supports the IUnknown, IDispatch and
  360. // IAccessible interfaces. CCandAccessible also incorrectly supports
  361. // the IEnumVARIANT interface (to return a VARIANT enumerator
  362. // containing all its children). When the IEnumVARIANT
  363. // interface is requested, an enumerator is created and a
  364. // pointer to its IEnumVARIANT interface is returned.
  365. //
  366. // The support for IEnumVARIANT is incorrect because the
  367. // interface pointer returned is not symmetric with respect
  368. // to the interface from which it was obtained. For example,
  369. // assume that pIA is a pointer to an IAccessible interface.
  370. // Then, even though pIA->QueryInterface(IID_IEnumVARIANT)
  371. // succeeds and returns pIEV,
  372. // pIEV->QueryInterface(IID_Accessibility) will fail because
  373. // the enumerator has no knowledge of any interface except
  374. // itself (and IUnknown).
  375. //
  376. // The original design of MSAA called for IAccessible
  377. // objects to also be enumerators of their children. But
  378. // this design doesn't allow for different clients of the
  379. // Accessible object to have different enumerations of its
  380. // children and that is a potentially hazardous situation.
  381. // (Assume there is an Accessible object that is also a
  382. // VARIANT enumerator, A, and two clients, C1 and C2.
  383. // Since C1 and C2 each may be pre-empted will using A,
  384. // the following is a one of many examples that would pose
  385. // a problem for at least one client:
  386. //
  387. // C1: A->Reset()
  388. // C1: A->Skip( 5 )
  389. // C2: A->Reset()
  390. // C1: A->Next() ! C1 does not get the child it expects
  391. //
  392. // So, although it breaks the rules of COM, QueryInterface()
  393. // as implemented below obtains a distinct VARIANT enumerator
  394. // for each request. A better solution to this issue would
  395. // be if the IAccessible interface provided a method to get
  396. // the child enumeration or if MSAA provided an exported API
  397. // to perform this task.
  398. //
  399. // ----------------------------------------------------------------------
  400. ------------------------------------------------------------------------------*/
  401. STDMETHODIMP CCandAccessible::QueryInterface( REFIID riid, void** ppv )
  402. {
  403. *ppv = NULL;
  404. //-----------------------------------------------------
  405. // If the IUnknown, IDispatch, or IAccessible
  406. // interface is desired, simply cast the this
  407. // pointer appropriately.
  408. //-----------------------------------------------------
  409. if ( riid == IID_IUnknown ) {
  410. *ppv = (LPUNKNOWN) this;
  411. }
  412. else if ( riid == IID_IDispatch ) {
  413. *ppv = (IDispatch *) this;
  414. }
  415. else if ( riid == IID_IAccessible ) {
  416. *ppv = (IAccessible *)this;
  417. }
  418. #ifdef NEVER
  419. //-----------------------------------------------------
  420. // If the IEnumVARIANT interface is desired, create
  421. // a new VARIANT enumerator which contains all
  422. // the Accessible object's children.
  423. //-----------------------------------------------------
  424. else if (riid == IID_IEnumVARIANT)
  425. {
  426. CEnumVariant* pcenum;
  427. HRESULT hr;
  428. hr = CreateVarEnumOfAllChildren( &pcenum );
  429. if ( FAILED( hr ) )
  430. return hr;
  431. *ppv = (IEnumVARIANT *) pcenum;
  432. }
  433. #endif /* NEVER */
  434. //-----------------------------------------------------
  435. // If the desired interface isn't one we know about,
  436. // return E_NOINTERFACE.
  437. //-----------------------------------------------------
  438. else {
  439. return E_NOINTERFACE;
  440. }
  441. //-----------------------------------------------------
  442. // Increase the reference count of any interface
  443. // returned.
  444. //-----------------------------------------------------
  445. ((LPUNKNOWN) *ppv)->AddRef();
  446. return S_OK;
  447. }
  448. /* A D D R E F */
  449. /*------------------------------------------------------------------------------
  450. //-----------------------------------------------------------------------
  451. // AddRef()
  452. //
  453. // DESCRIPTION:
  454. //
  455. // Implements the IUnknown interface method AddRef().
  456. //
  457. // PARAMETERS:
  458. //
  459. // None.
  460. //
  461. // RETURNS:
  462. //
  463. // ULONG Current reference count.
  464. //
  465. // NOTES:
  466. //
  467. // The lifetime of the Accessible object is governed by the
  468. // lifetime of the HWND object for which it provides
  469. // Accessibility. The object is created in response to the
  470. // first WM_GETOBJECT message that the server application
  471. // is ready to process and is destroyed when the server's
  472. // main window is destroyed. Since the object's lifetime
  473. // is not dependent on a reference count, the object has no
  474. // internal mechanism for tracking reference counting and
  475. // AddRef() and Release() always return one.
  476. //
  477. //-----------------------------------------------------------------------
  478. ------------------------------------------------------------------------------*/
  479. STDMETHODIMP_(ULONG) CCandAccessible::AddRef( void )
  480. {
  481. return InterlockedIncrement( &m_cRef );
  482. }
  483. /* R E L E A S E */
  484. /*------------------------------------------------------------------------------
  485. //-----------------------------------------------------------------------
  486. // Release()
  487. //
  488. // DESCRIPTION:
  489. //
  490. // Implements the IUnknown interface method Release().
  491. //
  492. // PARAMETERS:
  493. //
  494. // None.
  495. //
  496. // RETURNS:
  497. //
  498. // ULONG Current reference count.
  499. //
  500. // NOTES:
  501. //
  502. // The lifetime of the Accessible object is governed by the
  503. // lifetime of the HWND object for which it provides
  504. // Accessibility. The object is created in response to the
  505. // first WM_GETOBJECT message that the server application
  506. // is ready to process and is destroyed when the server's
  507. // main window is destroyed. Since the object's lifetime
  508. // is not dependent on a reference count, the object has no
  509. // internal mechanism for tracking reference counting and
  510. // AddRef() and Release() always return one.
  511. //
  512. //-----------------------------------------------------------------------
  513. ------------------------------------------------------------------------------*/
  514. STDMETHODIMP_(ULONG) CCandAccessible::Release( void )
  515. {
  516. ULONG l = InterlockedDecrement( &m_cRef );
  517. if (0 < l) {
  518. return l;
  519. }
  520. delete this;
  521. return 0;
  522. }
  523. /* G E T T Y P E I N F O C O U N T */
  524. /*------------------------------------------------------------------------------
  525. //-----------------------------------------------------------------------
  526. // GetTypeInfoCount()
  527. //
  528. // DESCRIPTION:
  529. //
  530. // Implements the IDispatch interface method GetTypeInfoCount().
  531. //
  532. // Retrieves the number of type information interfaces that an
  533. // object provides (either 0 or 1).
  534. //
  535. // PARAMETERS:
  536. //
  537. // pctInfo [out] Points to location that receives the
  538. // number of type information interfaces
  539. // that the object provides. If the object
  540. // provides type information, this number
  541. // is set to 1; otherwise it's set to 0.
  542. //
  543. // RETURNS:
  544. //
  545. // HRESULT S_OK if the function succeeds or
  546. // E_INVALIDARG if pctInfo is invalid.
  547. //
  548. //-----------------------------------------------------------------------
  549. ------------------------------------------------------------------------------*/
  550. STDMETHODIMP CCandAccessible::GetTypeInfoCount( UINT *pctInfo )
  551. {
  552. if (!pctInfo) {
  553. return E_INVALIDARG;
  554. }
  555. *pctInfo = (m_pTypeInfo == NULL ? 1 : 0);
  556. return S_OK;
  557. }
  558. /* G E T T Y P E I N F O */
  559. /*------------------------------------------------------------------------------
  560. //-----------------------------------------------------------------------
  561. // GetTypeInfo()
  562. //
  563. // DESCRIPTION:
  564. //
  565. // Implements the IDispatch interface method GetTypeInfo().
  566. //
  567. // Retrieves a type information object, which can be used to
  568. // get the type information for an interface.
  569. //
  570. // PARAMETERS:
  571. //
  572. // itinfo [in] The type information to return. If this value
  573. // is 0, the type information for the IDispatch
  574. // implementation is to be retrieved.
  575. //
  576. // lcid [in] The locale ID for the type information.
  577. //
  578. // ppITypeInfo [out] Receives a pointer to the type information
  579. // object requested.
  580. //
  581. // RETURNS:
  582. //
  583. // HRESULT S_OK if the function succeeded (the TypeInfo
  584. // element exists), TYPE_E_ELEMENTNOTFOUND if
  585. // itinfo is not equal to zero, or
  586. // E_INVALIDARG if ppITypeInfo is invalid.
  587. //
  588. //-----------------------------------------------------------------------
  589. ------------------------------------------------------------------------------*/
  590. STDMETHODIMP CCandAccessible::GetTypeInfo( UINT itinfo, LCID lcid, ITypeInfo** ppITypeInfo )
  591. {
  592. if (!ppITypeInfo) {
  593. return E_INVALIDARG;
  594. }
  595. *ppITypeInfo = NULL;
  596. if (itinfo != 0) {
  597. return TYPE_E_ELEMENTNOTFOUND;
  598. }
  599. else if (m_pTypeInfo == NULL) {
  600. return E_NOTIMPL;
  601. }
  602. *ppITypeInfo = m_pTypeInfo;
  603. m_pTypeInfo->AddRef();
  604. return S_OK;
  605. }
  606. /* G E T I D S O F N A M E S */
  607. /*------------------------------------------------------------------------------
  608. //-----------------------------------------------------------------------
  609. // GetIDsOfNames()
  610. //
  611. // DESCRIPTION:
  612. //
  613. // Implements the IDispatch interface method GetIDsOfNames().
  614. //
  615. // Maps a single member and an optional set of argument names
  616. // to a corresponding set of integer DISPIDs, which may be used
  617. // on subsequent calls to IDispatch::Invoke.
  618. //
  619. // PARAMETERS:
  620. //
  621. // riid [in] Reserved for future use. Must be NULL.
  622. //
  623. // rgszNames [in] Passed-in array of names to be mapped.
  624. //
  625. // cNames [in] Count of the names to be mapped.
  626. //
  627. // lcid [in] The locale context in which to interpret
  628. // the names.
  629. //
  630. // rgdispid [out] Caller-allocated array, each element of
  631. // which contains an ID corresponding to
  632. // one of the names passed in the rgszNames
  633. // array. The first element represents the
  634. // member name; the subsequent elements
  635. // represent each of the member's parameters.
  636. //
  637. // RETURNS:
  638. //
  639. // HRESULT S_OK if the function succeeded,
  640. // E_OUTOFMEMORY if there is not enough
  641. // memory to complete the call,
  642. // DISP_E_UNKNOWNNAME if one or more of
  643. // the names were not known, or
  644. // DISP_E_UNKNOWNLCID if the LCID was
  645. // not recognized.
  646. //
  647. // NOTES:
  648. //
  649. // This method simply delegates the call to
  650. // ITypeInfo::GetIDsOfNames().
  651. //-----------------------------------------------------------------------
  652. ------------------------------------------------------------------------------*/
  653. STDMETHODIMP CCandAccessible::GetIDsOfNames( REFIID riid, OLECHAR ** rgszNames, UINT cNames, LCID lcid, DISPID * rgdispid )
  654. {
  655. if (m_pTypeInfo == NULL) {
  656. return E_NOTIMPL;
  657. }
  658. return m_pTypeInfo->GetIDsOfNames( rgszNames, cNames, rgdispid );
  659. }
  660. /* I N V O K E */
  661. /*------------------------------------------------------------------------------
  662. //-----------------------------------------------------------------------
  663. // Invoke()
  664. //
  665. // DESCRIPTION:
  666. //
  667. // Implements the IDispatch interface method Invoke().
  668. //
  669. // Provides access to properties and methods exposed by the
  670. // Accessible object.
  671. //
  672. // PARAMETERS:
  673. //
  674. // dispidMember [in] Identifies the dispatch member.
  675. //
  676. // riid [in] Reserved for future use. Must be NULL.
  677. //
  678. // lcid [in] The locale context in which to interpret
  679. // the names.
  680. //
  681. // wFlags [in] Flags describing the context of the
  682. // Invoke call.
  683. //
  684. // pdispparams [in,] Pointer to a structure containing an
  685. // [out] array of arguments, array of argument
  686. // dispatch IDs for named arguments, and
  687. // counts for number of elements in the
  688. // arrays.
  689. //
  690. // pvarResult [in,] Pointer to where the result is to be
  691. // [out] stored, or NULL if the caller expects
  692. // no result. This argument is ignored
  693. // if DISPATCH_PROPERTYPUT or
  694. // DISPATCH_PROPERTYPUTREF is specified.
  695. //
  696. // pexcepinfo [out] Pointer to a structure containing
  697. // exception information. This structure
  698. // should be filled in if DISP_E_EXCEPTION
  699. // is returned.
  700. //
  701. // puArgErr [out] The index within rgvarg of the first
  702. // argument that has an error. Arguments
  703. // are stored in pdispparams->rgvarg in
  704. // reverse order, so the first argument
  705. // is the one with the highest index in
  706. // the array.
  707. //
  708. // RETURNS:
  709. //
  710. // HRESULT S_OK on success, dispatch error (DISP_E_*)
  711. // or E_NOTIMPL otherwise.
  712. //
  713. // NOTES:
  714. //
  715. // This method simply delegates the call to ITypeInfo::Invoke().
  716. //-----------------------------------------------------------------------
  717. ------------------------------------------------------------------------------*/
  718. STDMETHODIMP CCandAccessible::Invoke( DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr )
  719. {
  720. if (m_pTypeInfo == NULL) {
  721. return E_NOTIMPL;
  722. }
  723. return m_pTypeInfo->Invoke( (IAccessible *)this,
  724. dispid,
  725. wFlags,
  726. pdispparams,
  727. pvarResult,
  728. pexcepinfo,
  729. puArgErr );
  730. }
  731. /* G E T _ A C C P A R E N T */
  732. /*------------------------------------------------------------------------------
  733. //-----------------------------------------------------------------------
  734. // get_accParent()
  735. //
  736. // DESCRIPTION:
  737. //
  738. // Implements the IAccessible interface method get_accParent().
  739. //
  740. // Retrieves the IDispatch interface of the current object's
  741. // parent.
  742. //
  743. // PARAMETERS:
  744. //
  745. // ppdispParent [out] Pointer to the variable that will
  746. // contain a pointer to the IDispatch
  747. // interface of CCandAccessible's parent.
  748. //
  749. // RETURNS:
  750. //
  751. // HRESULT The value returned by the standard object's
  752. // implementation of get_accParent().
  753. //
  754. //-----------------------------------------------------------------------
  755. ------------------------------------------------------------------------------*/
  756. STDMETHODIMP CCandAccessible::get_accParent( IDispatch ** ppdispParent )
  757. {
  758. //
  759. // Use the default client window implementation to obtain the parent
  760. // of our Accessible object.
  761. //
  762. return m_pDefAccClient->get_accParent( ppdispParent );
  763. }
  764. /* G E T _ A C C C H I L D C O U N T */
  765. /*------------------------------------------------------------------------------
  766. //-----------------------------------------------------------------------
  767. // get_accChildCount()
  768. //
  769. // DESCRIPTION:
  770. //
  771. // Implements the IAccessible interface method get_accChildCount().
  772. //
  773. // Retrieves the number of children belonging to CCandAccessible.
  774. //
  775. // PARAMETERS:
  776. //
  777. // pChildCount [out] Pointer to the variable that will
  778. // be filled with the number of children
  779. // belonging to the CCandAccessible object.
  780. //
  781. // RETURNS:
  782. //
  783. // HRESULT S_OK on success, E_INVALIDARG if pChildCount
  784. // is invalid.
  785. //
  786. //-----------------------------------------------------------------------
  787. ------------------------------------------------------------------------------*/
  788. STDMETHODIMP CCandAccessible::get_accChildCount( long* pChildCount )
  789. {
  790. if (!pChildCount) {
  791. return E_INVALIDARG;
  792. }
  793. Assert( 0 < m_nAccItem );
  794. *pChildCount = (m_nAccItem - 1);
  795. return S_OK;
  796. }
  797. /* G E T _ A C C C H I L D */
  798. /*------------------------------------------------------------------------------
  799. //-----------------------------------------------------------------------
  800. // get_accChild()
  801. //
  802. // DESCRIPTION:
  803. //
  804. // Implements the IAccessible interface method get_accChild().
  805. //
  806. // Retrieve an IDispatch interface pointer to the child object
  807. // that has the given child ID or name.
  808. //
  809. // PARAMETERS:
  810. //
  811. // varChild [in] VARIANT structure that identifies the
  812. // child to be retrieved. Since
  813. // CCandAccessible only supports child IDs,
  814. // the vt member of this structure must
  815. // equal VT_I4.
  816. //
  817. // ppdispChild [out] Pointer to the variable that will
  818. // contain a pointer to the IDispatch
  819. // interface of specified child object
  820. // of CCandAccessible.
  821. //
  822. // RETURNS:
  823. //
  824. // HRESULT E_INVALIDARG if ppdispChild is invalid, S_FALSE
  825. // otherwise because none of CCandAccessible's
  826. // children are objects.
  827. //
  828. //-----------------------------------------------------------------------
  829. ------------------------------------------------------------------------------*/
  830. STDMETHODIMP CCandAccessible::get_accChild( VARIANT varChild, IDispatch ** ppdispChild )
  831. {
  832. if (!ppdispChild) {
  833. return E_INVALIDARG;
  834. }
  835. //-----------------------------------------------------
  836. // None of the children of CCandAccessible are objects,
  837. // so none have IDispatch pointers. Thus, in all
  838. // cases, set the IDispatch pointer to NULL and
  839. // return S_FALSE.
  840. //-----------------------------------------------------
  841. *ppdispChild = NULL;
  842. return S_FALSE;
  843. }
  844. /* G E T _ A C C N A M E */
  845. /*------------------------------------------------------------------------------
  846. //-----------------------------------------------------------------------
  847. // get_accName()
  848. //
  849. // DESCRIPTION:
  850. //
  851. // Implements the IAccessible interface method get_accName().
  852. //
  853. // Retrieve the name property for the specified child.
  854. //
  855. // PARAMETERS:
  856. //
  857. // varChild [in] VARIANT structure that identifies the
  858. // child to be retrieved. Since
  859. // CCandAccessible only supports child IDs,
  860. // the vt member of this structure must
  861. // equal VT_I4.
  862. //
  863. // pszName [out] Pointer to the BSTR that will contain
  864. // the child's name property string.
  865. //
  866. // RETURNS:
  867. //
  868. // HRESULT E_INVALIDARG if either parameter is invalid
  869. // or the return value from the private method
  870. // HrLoadString().
  871. //
  872. //-----------------------------------------------------------------------
  873. ------------------------------------------------------------------------------*/
  874. STDMETHODIMP CCandAccessible::get_accName( VARIANT varChild, BSTR *pbstrName )
  875. {
  876. CCandAccItem *pAccItem;
  877. if (pbstrName == NULL) {
  878. return E_INVALIDARG;
  879. }
  880. // get acc item
  881. pAccItem = AccItemFromID( (int)varChild.lVal );
  882. if (pAccItem == NULL) {
  883. return E_INVALIDARG;
  884. }
  885. // get name of acc item
  886. *pbstrName = pAccItem->GetAccName();
  887. return (*pbstrName != NULL) ? S_OK : DISP_E_MEMBERNOTFOUND;
  888. }
  889. /* G E T _ A C C V A L U E */
  890. /*------------------------------------------------------------------------------
  891. //-----------------------------------------------------------------------
  892. // get_accValue()
  893. //
  894. // DESCRIPTION:
  895. //
  896. // Implements the IAccessible interface method get_accValue().
  897. //
  898. // Retrieves the value property for the specified child.
  899. //
  900. // PARAMETERS:
  901. //
  902. // varChild [in] VARIANT structure that identifies the
  903. // child to be retrieved. Since
  904. // CCandAccessible only supports child IDs,
  905. // the vt member of this structure must
  906. // equal VT_I4.
  907. //
  908. // pszValue [out] Pointer to the BSTR that will contain
  909. // the child's value property string.
  910. //
  911. // RETURNS:
  912. //
  913. // HRESULT E_INVALIDARG if either parameter is invalid,
  914. // DISP_E_MEMBERNOTFOUND if VarChild refers
  915. // to any child other than the status bar,
  916. // or S_OK.
  917. //
  918. //-----------------------------------------------------------------------
  919. ------------------------------------------------------------------------------*/
  920. STDMETHODIMP CCandAccessible::get_accValue( VARIANT varChild, BSTR *pbstrValue )
  921. {
  922. CCandAccItem *pAccItem;
  923. if (pbstrValue == NULL) {
  924. return E_INVALIDARG;
  925. }
  926. // get acc item
  927. pAccItem = AccItemFromID( (int)varChild.lVal );
  928. if (pAccItem == NULL) {
  929. return E_INVALIDARG;
  930. }
  931. // get value of acc item
  932. *pbstrValue = pAccItem->GetAccValue();
  933. return (*pbstrValue != NULL) ? S_OK : DISP_E_MEMBERNOTFOUND;
  934. }
  935. /* G E T _ A C C D E S C R I P T I O N */
  936. /*------------------------------------------------------------------------------
  937. //-----------------------------------------------------------------------
  938. // get_accDescription()
  939. //
  940. // DESCRIPTION:
  941. //
  942. // Implements the IAccessible interface method get_accDescription().
  943. //
  944. // Retrieves the description property for the specified child.
  945. //
  946. // PARAMETERS:
  947. //
  948. // varChild [in] VARIANT structure that identifies the
  949. // child to be retrieved. Since
  950. // CCandAccessible only supports child IDs,
  951. // the vt member of this structure must
  952. // equal VT_I4.
  953. //
  954. // pszDesc [out] Pointer to the BSTR that will contain
  955. // the child's description property string.
  956. //
  957. // RETURNS:
  958. //
  959. // HRESULT E_INVALIDARG if either parameter is invalid
  960. // or the return value from either the
  961. // standard client window implementation of
  962. // get_accDescription() or the private method
  963. // HrLoadString().
  964. //
  965. //-----------------------------------------------------------------------
  966. ------------------------------------------------------------------------------*/
  967. STDMETHODIMP CCandAccessible::get_accDescription( VARIANT varChild, BSTR *pbstrDesc )
  968. {
  969. if (pbstrDesc == NULL) {
  970. return E_INVALIDARG;
  971. }
  972. return m_pDefAccClient->get_accDescription( varChild, pbstrDesc );
  973. }
  974. /* G E T _ A C C R O L E */
  975. /*------------------------------------------------------------------------------
  976. //-----------------------------------------------------------------------
  977. // get_accRole()
  978. //
  979. // DESCRIPTION:
  980. //
  981. // Implements the IAccessible interface method get_accRole().
  982. //
  983. // Retrieves the role property for the specified child.
  984. //
  985. // PARAMETERS:
  986. //
  987. // varChild [in] VARIANT structure that identifies the
  988. // child to be retrieved. Since
  989. // CCandAccessible only supports child IDs,
  990. // the vt member of this structure must
  991. // equal VT_I4.
  992. //
  993. // pVarRole [out] Pointer to the VARIANT structure that
  994. // will contain the specified child's
  995. // role property. This property may
  996. // either be in the form of a standard
  997. // role constant or a custom description
  998. // string.
  999. //
  1000. // RETURNS:
  1001. //
  1002. // HRESULT E_INVALIDARG if either parameter is invalid,
  1003. // S_OK if the specified child is the button
  1004. // or status bar, or the return value from
  1005. // either the standard client window implementation
  1006. // of get_accRole() or the private method
  1007. // HrLoadString().
  1008. //
  1009. //-----------------------------------------------------------------------
  1010. ------------------------------------------------------------------------------*/
  1011. STDMETHODIMP CCandAccessible::get_accRole( VARIANT varChild, VARIANT *pVarRole )
  1012. {
  1013. CCandAccItem *pAccItem;
  1014. if (pVarRole == NULL) {
  1015. return E_INVALIDARG;
  1016. }
  1017. // get acc item
  1018. pAccItem = AccItemFromID( (int)varChild.lVal );
  1019. if (pAccItem == NULL) {
  1020. return E_INVALIDARG;
  1021. }
  1022. // get role of acc item
  1023. pVarRole->vt = VT_I4;
  1024. pVarRole->lVal = pAccItem->GetAccRole();
  1025. return S_OK;
  1026. }
  1027. //-----------------------------------------------------------------------
  1028. // get_accState()
  1029. //
  1030. // DESCRIPTION:
  1031. //
  1032. // Implements the IAccessible interface method get_accState().
  1033. //
  1034. // Retrieves the current state for the specified object or child.
  1035. //
  1036. // PARAMETERS:
  1037. //
  1038. // varChild [in] VARIANT structure that identifies the
  1039. // child to be retrieved. Since
  1040. // CCandAccessible only supports child IDs,
  1041. // the vt member of this structure must
  1042. // equal VT_I4.
  1043. //
  1044. // pVarState [out] Pointer to the VARIANT structure that
  1045. // will contain information describing
  1046. // the specified child's current state.
  1047. // This information may either be in the
  1048. // form of one or more object state
  1049. // constants or a custom description
  1050. // string.
  1051. //
  1052. // RETURNS:
  1053. //
  1054. // HRESULT E_INVALIDARG if either parameter is invalid or
  1055. // S_OK.
  1056. //
  1057. // NOTES:
  1058. //
  1059. // Since the icons are HWND based objects, they can never truly
  1060. // have the input focus. However, if the user clicks one, the main
  1061. // window treats the icon as if it had the focus. So, the state
  1062. // of the client area should not indicate "focused" when an icon
  1063. // is said to have the focus.
  1064. //
  1065. // The push button can have the focus, but it cannot be selected.
  1066. //
  1067. //-----------------------------------------------------------------------
  1068. STDMETHODIMP CCandAccessible::get_accState( VARIANT varChild, VARIANT * pVarState )
  1069. {
  1070. CCandAccItem *pAccItem;
  1071. if (pVarState == NULL) {
  1072. return E_INVALIDARG;
  1073. }
  1074. // get acc item
  1075. pAccItem = AccItemFromID( (int)varChild.lVal );
  1076. if (pAccItem == NULL) {
  1077. return E_INVALIDARG;
  1078. }
  1079. // get state of acc item
  1080. pVarState->vt = VT_I4;
  1081. pVarState->lVal = pAccItem->GetAccState();
  1082. return S_OK;
  1083. }
  1084. /* G E T _ A C C H E L P */
  1085. /*------------------------------------------------------------------------------
  1086. //-----------------------------------------------------------------------
  1087. // get_accHelp()
  1088. //
  1089. // DESCRIPTION:
  1090. //
  1091. // Implements the IAccessible interface method get_accHelp().
  1092. //
  1093. // Retrieves the help property string for the specified child.
  1094. //
  1095. // PARAMETERS:
  1096. //
  1097. // varChild [in] VARIANT structure that identifies the
  1098. // child to be retrieved. Since
  1099. // CCandAccessible only supports child IDs,
  1100. // the vt member of this structure must
  1101. // equal VT_I4.
  1102. //
  1103. // pszHelp [out] Pointer to the BSTR that will contain
  1104. // the child's help property string.
  1105. //
  1106. // RETURNS:
  1107. //
  1108. // HRESULT E_INVALIDARG if either parameter is invalid,
  1109. // DISP_E_MEMBERNOTFOUND if VarChild refers
  1110. // to any icon child, or the return value from
  1111. // either the standard client window implementation
  1112. // of get_accHelp() or the private method
  1113. // HrLoadString().
  1114. //
  1115. //-----------------------------------------------------------------------
  1116. ------------------------------------------------------------------------------*/
  1117. STDMETHODIMP CCandAccessible::get_accHelp( VARIANT varChild, BSTR *pbstrHelp )
  1118. {
  1119. return DISP_E_MEMBERNOTFOUND; /* no support in candidate UI */
  1120. }
  1121. /* G E T _ A C C H E L P T O P I C */
  1122. /*------------------------------------------------------------------------------
  1123. //-----------------------------------------------------------------------
  1124. // get_accHelpTopic()
  1125. //
  1126. // DESCRIPTION:
  1127. //
  1128. // Implements the IAccessible interface method get_accHelpTopic().
  1129. //
  1130. // Retrieves the fully qualified path name of the help file
  1131. // associated with the specified object, as well as a pointer
  1132. // to the appropriate topic with in that file.
  1133. //
  1134. // PARAMETERS:
  1135. //
  1136. // pszHelpFile [out] Pointer to the BSTR that will contain
  1137. // the fully qualified path name of the
  1138. // help file associated with the child.
  1139. //
  1140. // varChild [in] VARIANT structure that identifies the
  1141. // child to be retrieved. Since
  1142. // CCandAccessible only supports child IDs,
  1143. // the vt member of this structure must
  1144. // equal VT_I4.
  1145. //
  1146. // pidTopic [out] Pointer to the value identifying the
  1147. // help file topic associated with the
  1148. // object.
  1149. //
  1150. // RETURNS:
  1151. //
  1152. // HRESULT DISP_E_MEMBERNOTFOUND because the help topic
  1153. // property is not supported for the Accessible
  1154. // object or any of its children.
  1155. //
  1156. //-----------------------------------------------------------------------
  1157. ------------------------------------------------------------------------------*/
  1158. STDMETHODIMP CCandAccessible::get_accHelpTopic( BSTR* pszHelpFile, VARIANT varChild, long* pidTopic )
  1159. {
  1160. return DISP_E_MEMBERNOTFOUND; /* no support in candidate UI */
  1161. }
  1162. /* G E T _ A C C K E Y B O A R D S H O R T C U T */
  1163. /*------------------------------------------------------------------------------
  1164. //-----------------------------------------------------------------------
  1165. // get_accKeyboardShortcut()
  1166. //
  1167. // DESCRIPTION:
  1168. //
  1169. // Implements the IAccessible interface method
  1170. // get_accKeyboardShortcut().
  1171. //
  1172. // Retrieves the specified object's keyboard shortcut property.
  1173. //
  1174. // PARAMETERS:
  1175. //
  1176. // varChild [in] VARIANT structure that identifies the
  1177. // child to be retrieved. Since
  1178. // CCandAccessible only supports child IDs,
  1179. // the vt member of this structure must
  1180. // equal VT_I4.
  1181. //
  1182. // pszShortcut [out] Pointer to the BSTR that will contain
  1183. // the keyboard shortcut string, or NULL
  1184. // if no keyboard shortcut is associated
  1185. // with this item.
  1186. //
  1187. //
  1188. // RETURNS:
  1189. //
  1190. // HRESULT DISP_E_MEMBERNOTFOUND because the keyboard
  1191. // shortcut property is not supported for the
  1192. // Accessible object or any of its children.
  1193. //
  1194. //-----------------------------------------------------------------------
  1195. ------------------------------------------------------------------------------*/
  1196. STDMETHODIMP CCandAccessible::get_accKeyboardShortcut( VARIANT varChild, BSTR *pbstrShortcut )
  1197. {
  1198. return DISP_E_MEMBERNOTFOUND; /* no support in candidate UI */
  1199. }
  1200. /* G E T _ A C C F O C U S */
  1201. /*------------------------------------------------------------------------------
  1202. //-----------------------------------------------------------------------
  1203. // get_accFocus()
  1204. //
  1205. // DESCRIPTION:
  1206. //
  1207. // Implements the IAccessible interface method get_accFocus().
  1208. //
  1209. // Retrieves the child object that currently has the input focus.
  1210. // Only one object or item within a container can have the current
  1211. // focus at any one time.
  1212. //
  1213. // PARAMETERS:
  1214. //
  1215. // pVarFocus [out] Pointer to the VARIANT structure that
  1216. // will contain information describing
  1217. // the specified child's current state.
  1218. // This information may either be in the
  1219. // form of one or more object state
  1220. // constants or a custom description
  1221. // string.
  1222. //
  1223. // RETURNS:
  1224. //
  1225. // HRESULT E_INVALIDARG if the pVarFocus parameter is
  1226. // invalid or S_OK.
  1227. //
  1228. //-----------------------------------------------------------------------
  1229. ------------------------------------------------------------------------------*/
  1230. STDMETHODIMP CCandAccessible::get_accFocus( VARIANT *pVarFocus )
  1231. {
  1232. if (pVarFocus == NULL) {
  1233. return E_INVALIDARG;
  1234. }
  1235. pVarFocus->vt = VT_EMPTY;
  1236. pVarFocus->vt = VT_I4;
  1237. pVarFocus->lVal = 2;
  1238. return S_OK;
  1239. }
  1240. /* G E T _ A C C S E L E C T I O N */
  1241. /*------------------------------------------------------------------------------
  1242. //-----------------------------------------------------------------------
  1243. // get_accSelection()
  1244. //
  1245. // DESCRIPTION:
  1246. //
  1247. // Implements the IAccessible interface method get_accSelection().
  1248. //
  1249. // Retrieves the selected children of this object.
  1250. //
  1251. // PARAMETERS:
  1252. //
  1253. // pVarSel [out] Pointer to the VARIANT structure that
  1254. // will be filled with information about
  1255. // the selected child object or objects.
  1256. //
  1257. // RETURNS:
  1258. //
  1259. // HRESULT E_INVALIDARG if the pVarSel parameter is
  1260. // invalid or S_OK.
  1261. //
  1262. // NOTES:
  1263. //
  1264. // Refer to the MSAA SDK documentation for a full description
  1265. // of this method and the possible settings of pVarSel.
  1266. //
  1267. //-----------------------------------------------------------------------
  1268. ------------------------------------------------------------------------------*/
  1269. STDMETHODIMP CCandAccessible::get_accSelection( VARIANT * pVarSel )
  1270. {
  1271. if (pVarSel == NULL) {
  1272. return E_INVALIDARG;
  1273. }
  1274. pVarSel->vt = VT_EMPTY;
  1275. pVarSel->vt = VT_I4;
  1276. pVarSel->lVal = 2;
  1277. return S_OK;
  1278. }
  1279. /* G E T _ A C C D E F A U L T A C T I O N */
  1280. /*------------------------------------------------------------------------------
  1281. //-----------------------------------------------------------------------
  1282. // get_accDefaultAction()
  1283. //
  1284. // DESCRIPTION:
  1285. //
  1286. // Implements the IAccessible interface method get_accDefaultAction().
  1287. //
  1288. // Retrieves a string containing a localized, human-readable sentence
  1289. // that describes the object's default action.
  1290. //
  1291. // PARAMETERS:
  1292. //
  1293. // varChild [in] VARIANT structure that identifies the
  1294. // child whose default action string is
  1295. // to be retrieved. Since CCandAccessible
  1296. // only supports child IDs, the vt member
  1297. // of this structure must equal VT_I4.
  1298. //
  1299. // pszDefAct [out] Pointer to the BSTR that will contain
  1300. // the child's default action string,
  1301. // or NULL if there is no default action
  1302. // for this object.
  1303. //
  1304. // RETURNS:
  1305. //
  1306. // HRESULT E_INVALIDARG if either parameter is invalid,
  1307. // DISP_E_MEMBERNOTFOUND if VarChild refers
  1308. // to any icon child or the status bar child,
  1309. // or the return value from either the standard
  1310. // client window implementation of
  1311. // get_accDefaultAction() or the private method
  1312. // HrLoadString().
  1313. //
  1314. // NOTES:
  1315. //
  1316. // The only CCandAccessible child that has a default action is
  1317. // the push button.
  1318. //
  1319. //-----------------------------------------------------------------------
  1320. ------------------------------------------------------------------------------*/
  1321. STDMETHODIMP CCandAccessible::get_accDefaultAction( VARIANT varChild, BSTR *pbstrDefAct )
  1322. {
  1323. if (pbstrDefAct == NULL) {
  1324. return E_INVALIDARG;
  1325. }
  1326. *pbstrDefAct = NULL;
  1327. return DISP_E_MEMBERNOTFOUND; /* no support in candidate UI */
  1328. }
  1329. /* A C C D O D E F A U L T A C T I O N */
  1330. /*------------------------------------------------------------------------------
  1331. //-----------------------------------------------------------------------
  1332. // accDoDefaultAction()
  1333. //
  1334. // DESCRIPTION:
  1335. //
  1336. // Implements the IAccessible interface method accDoDefaultAction().
  1337. //
  1338. // Performs the object's default action.
  1339. //
  1340. // PARAMETERS:
  1341. //
  1342. // varChild [in] VARIANT structure that identifies the
  1343. // child whose default action will be
  1344. // invoked. Since CCandAccessible only
  1345. // supports child IDs, the vt member of
  1346. // this structure must equal VT_I4.
  1347. //
  1348. // RETURNS:
  1349. //
  1350. // HRESULT E_INVALIDARG if the in-parameter is invalid,
  1351. // DISP_E_MEMBERNOTFOUND if VarChild refers
  1352. // to any icon child or the status bar child,
  1353. // S_OK if VarChild refers to the push button,
  1354. // or the return value from the standard
  1355. // client window implementation of
  1356. // accDoDefaultAction().
  1357. //
  1358. // NOTES:
  1359. //
  1360. // The only CCandAccessible child that has a default action is
  1361. // the push button.
  1362. //
  1363. //-----------------------------------------------------------------------
  1364. ------------------------------------------------------------------------------*/
  1365. STDMETHODIMP CCandAccessible::accDoDefaultAction( VARIANT varChild )
  1366. {
  1367. return DISP_E_MEMBERNOTFOUND; /* no support in candidate UI */
  1368. }
  1369. /* A C C S E L E C T */
  1370. /*------------------------------------------------------------------------------
  1371. //-----------------------------------------------------------------------
  1372. // accSelect()
  1373. //
  1374. // DESCRIPTION:
  1375. //
  1376. // Implements the IAccessible interface method accSelect().
  1377. //
  1378. // Modifies the selection or moves the keyboard focus according
  1379. // to the specified flags.
  1380. //
  1381. // PARAMETERS:
  1382. //
  1383. // flagsSel [in] Value specifying how to change the
  1384. // the current selection. This parameter
  1385. // can be a combination of the values
  1386. // from the SELFLAG enumerated type.
  1387. //
  1388. // varChild [in] VARIANT structure that identifies the
  1389. // child to be selected. Since
  1390. // CCandAccessible only supports child IDs,
  1391. // the vt member of this structure must
  1392. // equal VT_I4.
  1393. //
  1394. // RETURNS:
  1395. //
  1396. // HRESULT E_INVALIDARG if either of the parameters
  1397. // is invalid, S_FALSE if the selection
  1398. // and/or focus cannot be placed at the
  1399. // requested location, or S_OK if the
  1400. // selection and/or focus can be placed
  1401. // at the requested location.
  1402. //
  1403. // NOTES:
  1404. //
  1405. // For more information on selected objects, please see the
  1406. // MSAA SDK Documentation.
  1407. //
  1408. //-----------------------------------------------------------------------
  1409. ------------------------------------------------------------------------------*/
  1410. STDMETHODIMP CCandAccessible::accSelect( long flagsSel, VARIANT varChild )
  1411. {
  1412. //-----------------------------------------------------
  1413. // Validate the requested selection.
  1414. // SELFLAG_ADDSELECTION may not be combined
  1415. // with SELFLAG_REMOVESELECTION.
  1416. //-----------------------------------------------------
  1417. if ((flagsSel & SELFLAG_ADDSELECTION) && (flagsSel & SELFLAG_REMOVESELECTION)) {
  1418. return E_INVALIDARG;
  1419. }
  1420. return S_FALSE;
  1421. }
  1422. /* A C C L O C A T I O N */
  1423. /*------------------------------------------------------------------------------
  1424. //-----------------------------------------------------------------------
  1425. // accLocation()
  1426. //
  1427. // DESCRIPTION:
  1428. //
  1429. // Implements the IAccessible interface method accLocation().
  1430. //
  1431. // Retrieves the specified child's current screen location in
  1432. // screen coordinates.
  1433. //
  1434. // PARAMETERS:
  1435. //
  1436. // pxLeft [out] Address of the child's left most
  1437. // boundary.
  1438. //
  1439. // pyTop [out] Address of the child's upper most
  1440. // boundary.
  1441. //
  1442. // pcxWid [out] Address of the child's width.
  1443. //
  1444. // pcyHt [out] Address of the child's height.
  1445. //
  1446. // varChild [in] VARIANT structure that identifies the
  1447. // child whose screen location is to be
  1448. // retrieved. Since CCandAccessible only
  1449. // supports child IDs, the vt member
  1450. // of this structure must equal VT_I4.
  1451. //
  1452. // RETURNS:
  1453. //
  1454. // HRESULT E_INVALIDARG if any of the parameters
  1455. // are invalid, E_UNEXPECTED if we are for
  1456. // some reason unable to determine the
  1457. // window rect of the button or status bar,
  1458. // S_OK if the screen coordinates of the
  1459. // child are successfully determined, or
  1460. // the return value from the standard client
  1461. // window implementation of accLocation().
  1462. //
  1463. //-----------------------------------------------------------------------
  1464. ------------------------------------------------------------------------------*/
  1465. STDMETHODIMP CCandAccessible::accLocation( long* pxLeft, long* pyTop, long* pcxWid, long* pcyHt, VARIANT varChild )
  1466. {
  1467. CCandAccItem *pAccItem;
  1468. RECT rc;
  1469. if (pxLeft == NULL || pyTop == NULL || pcxWid == NULL || pcyHt == NULL) {
  1470. return E_INVALIDARG;
  1471. }
  1472. //-----------------------------------------------------
  1473. // If the child ID is CHILDID_SELF, we are being
  1474. // asked to retrieve the current screen location
  1475. // of the Accessible object itself. Delegate
  1476. // this request to the standard implementation.
  1477. //-----------------------------------------------------
  1478. if (varChild.lVal == CHILDID_SELF) {
  1479. return m_pDefAccClient->accLocation( pxLeft, pyTop, pcxWid, pcyHt, varChild );
  1480. }
  1481. // get acc item
  1482. pAccItem = AccItemFromID( (int)varChild.lVal );
  1483. if (pAccItem == NULL) {
  1484. return E_INVALIDARG;
  1485. }
  1486. // get location of acc item
  1487. pAccItem->GetAccLocation( &rc );
  1488. *pxLeft = rc.left;
  1489. *pyTop = rc.top;
  1490. *pcxWid = rc.right - rc.left;
  1491. *pcyHt = rc.bottom - rc.top;
  1492. return S_OK;
  1493. }
  1494. /* A C C N A V I G A T E */
  1495. /*------------------------------------------------------------------------------
  1496. //-----------------------------------------------------------------------
  1497. // accNavigate()
  1498. //
  1499. // DESCRIPTION:
  1500. //
  1501. // Implements the IAccessible interface method accNavigate().
  1502. //
  1503. // Retrieves the next or previous sibling or child object in a
  1504. // specified direction. This direction can be spatial order
  1505. // (such as Left and Right) or in navigational order (such as
  1506. // Next and Previous).
  1507. //
  1508. // PARAMETERS:
  1509. //
  1510. // navDir [in] A navigational constant specifying
  1511. // the direction in which to move.
  1512. //
  1513. // varStart [in] VARIANT structure that identifies the
  1514. // child from which the navigational
  1515. // change will originate. Since
  1516. // CCandAccessible only supports child IDs,
  1517. // the vt member of this structure must
  1518. // equal VT_I4.
  1519. //
  1520. // pVarEndUpAt [out] Pointer to the VARIANT structure that
  1521. // will contain information describing
  1522. // the destination child or object.
  1523. // If the vt member is VT_I4, then the
  1524. // lVal member is a child ID. If the
  1525. // vt member is VT_EMPTY, then the
  1526. // navigation failed.
  1527. //
  1528. // RETURNS:
  1529. //
  1530. // HRESULT E_INVALIDARG if the varStart parameter is
  1531. // invalid, or the return value from the
  1532. // default implementation of the window client
  1533. // area default Accessible object,
  1534. // DISP_E_MEMBERNOTFOUND if the combination
  1535. // of the navigation flag and the varStart
  1536. // setting is invalid, S_FALSE if the
  1537. // navigation fails, or S_OK.
  1538. //
  1539. // NOTES:
  1540. //
  1541. // Since the CCandAccessible object has no child objects (only child
  1542. // elements), pVarEndUpAt will never be a pointer to a IDispatch
  1543. // interface of a child object.
  1544. //
  1545. //-----------------------------------------------------------------------
  1546. ------------------------------------------------------------------------------*/
  1547. STDMETHODIMP CCandAccessible::accNavigate( long navDir, VARIANT varStart, VARIANT* pVarEndUpAt )
  1548. {
  1549. pVarEndUpAt->vt = VT_EMPTY;
  1550. return S_FALSE; /* no support in candidate UI */
  1551. }
  1552. /* A C C H I T T E S T */
  1553. /*------------------------------------------------------------------------------
  1554. //-----------------------------------------------------------------------
  1555. // accHitTest()
  1556. //
  1557. // DESCRIPTION:
  1558. //
  1559. // Implements the IAccessible interface method accHitTest().
  1560. //
  1561. // Retrieves the ID of the a child at a given point on the screen.
  1562. //
  1563. // PARAMETERS:
  1564. //
  1565. // xLeft and yTop [in] The screen coordinates of the point
  1566. // to be hit tested.
  1567. //
  1568. // pVarHit [out] Pointer to the VARIANT structure that
  1569. // will contain information describing
  1570. // the hit child. If the vt member is
  1571. // VT_I4, then the lVal member is a child
  1572. // ID. If the vt member is VT_EMPTY,
  1573. // then the navigation failed.
  1574. //
  1575. // RETURNS:
  1576. //
  1577. // HRESULT E_INVALIDARG if the pVarHit parameter is
  1578. // invalid, or S_OK.
  1579. //
  1580. // NOTES:
  1581. //
  1582. // Since the CCandAccessible object has no child objects (only child
  1583. // elements), pVarHit will never be a pointer to a IDispatch
  1584. // interface of a child object.
  1585. //
  1586. //-----------------------------------------------------------------------
  1587. ------------------------------------------------------------------------------*/
  1588. STDMETHODIMP CCandAccessible::accHitTest( long xLeft, long yTop, VARIANT *pVarHit )
  1589. {
  1590. int i;
  1591. POINT pt;
  1592. RECT rcWnd;
  1593. if (!pVarHit) {
  1594. return E_INVALIDARG;
  1595. }
  1596. // check point is inside of window
  1597. pt.x = xLeft;
  1598. pt.y = yTop;
  1599. ScreenToClient( m_hWnd, &pt );
  1600. GetClientRect( m_hWnd, &rcWnd );
  1601. if (!PtInRect( &rcWnd, pt )) {
  1602. pVarHit->vt = VT_EMPTY;
  1603. }
  1604. else {
  1605. pVarHit->vt = VT_I4;
  1606. pVarHit->lVal = CHILDID_SELF;
  1607. for (i = 1; i < m_nAccItem; i++) {
  1608. RECT rc;
  1609. Assert( m_rgAccItem[i] != NULL );
  1610. m_rgAccItem[i]->GetAccLocation( &rc );
  1611. if (PtInRect( &rc, pt )) {
  1612. pVarHit->lVal = m_rgAccItem[i]->GetID();
  1613. break;
  1614. }
  1615. }
  1616. }
  1617. return S_OK;
  1618. }
  1619. /* P U T _ A C C N A M E */
  1620. /*------------------------------------------------------------------------------
  1621. //-----------------------------------------------------------------------
  1622. // put_accName()
  1623. //
  1624. // DESCRIPTION:
  1625. //
  1626. // Implements the IAccessible interface method put_accName().
  1627. //
  1628. // Sets the name property for the specified child.
  1629. //
  1630. // PARAMETERS:
  1631. //
  1632. // varChild [in] VARIANT structure that identifies the
  1633. // child whose name property is to be
  1634. // set. Since CCandAccessible only supports
  1635. // child IDs, the vt member of this
  1636. // structure must equal VT_I4.
  1637. //
  1638. // szName [in] String that specifies the new name for
  1639. // this child.
  1640. //
  1641. // RETURNS:
  1642. //
  1643. // HRESULT S_FALSE because the name property for any
  1644. // child may not be changed.
  1645. //
  1646. //-----------------------------------------------------------------------
  1647. ------------------------------------------------------------------------------*/
  1648. STDMETHODIMP CCandAccessible::put_accName( VARIANT varChild, BSTR szName )
  1649. {
  1650. //-----------------------------------------------------
  1651. // We don't allow clients to change the name
  1652. // property of any child so we simply return
  1653. // S_FALSE.
  1654. //-----------------------------------------------------
  1655. return S_FALSE;
  1656. }
  1657. /* P U T _ A C C V A L U E */
  1658. /*------------------------------------------------------------------------------
  1659. //-----------------------------------------------------------------------
  1660. // put_accValue()
  1661. //
  1662. // DESCRIPTION:
  1663. //
  1664. // Implements the IAccessible interface method put_accValue().
  1665. //
  1666. // Sets the value property for the specified child.
  1667. //
  1668. // PARAMETERS:
  1669. //
  1670. // varChild [in] VARIANT structure that identifies the
  1671. // child whose value property is to be
  1672. // set. Since CCandAccessible only supports
  1673. // child IDs, the vt member of this
  1674. // structure must equal VT_I4.
  1675. //
  1676. // szValue [in] String that specifies the new value for
  1677. // this child.
  1678. //
  1679. // RETURNS:
  1680. //
  1681. // HRESULT S_FALSE because the value property for any
  1682. // child may not be changed.
  1683. //
  1684. //-----------------------------------------------------------------------
  1685. ------------------------------------------------------------------------------*/
  1686. STDMETHODIMP CCandAccessible::put_accValue( VARIANT varChild, BSTR szValue )
  1687. {
  1688. //-----------------------------------------------------
  1689. // We don't allow clients to change the value
  1690. // property of the status bar (the only child that
  1691. // has a value property) so we simply return S_FALSE.
  1692. //-----------------------------------------------------
  1693. return S_FALSE;
  1694. }
  1695. //
  1696. //
  1697. //
  1698. /* I S V A L I D C H I L D V A R I A N T */
  1699. /*------------------------------------------------------------------------------
  1700. ------------------------------------------------------------------------------*/
  1701. BOOL CCandAccessible::IsValidChildVariant( VARIANT * pVar )
  1702. {
  1703. return (pVar->vt == VT_I4) && (0 <= pVar->lVal) && (pVar->lVal < m_nAccItem);
  1704. }
  1705. /* A C C I T E M F R O M I D */
  1706. /*------------------------------------------------------------------------------
  1707. ------------------------------------------------------------------------------*/
  1708. CCandAccItem *CCandAccessible::AccItemFromID( int iID )
  1709. {
  1710. int i;
  1711. for (i = 0; i < m_nAccItem; i++) {
  1712. if (m_rgAccItem[i]->GetID() == iID) {
  1713. return m_rgAccItem[i];
  1714. }
  1715. }
  1716. return NULL;
  1717. }
  1718. /* C L E A R A C C I T E M */
  1719. /*------------------------------------------------------------------------------
  1720. ------------------------------------------------------------------------------*/
  1721. void CCandAccessible::ClearAccItem( void )
  1722. {
  1723. m_nAccItem = 0;
  1724. }
  1725. /* A D D A C C I T E M */
  1726. /*------------------------------------------------------------------------------
  1727. ------------------------------------------------------------------------------*/
  1728. BOOL CCandAccessible::AddAccItem( CCandAccItem *pAccItem )
  1729. {
  1730. if (CANDACCITEM_MAX <= m_nAccItem) {
  1731. Assert( FALSE ); /* need more buffer */
  1732. return FALSE;
  1733. }
  1734. m_rgAccItem[ m_nAccItem++ ] = pAccItem;
  1735. pAccItem->Init( this, m_nAccItem /* start from 1 */ );
  1736. return TRUE;
  1737. }
  1738. /* N O T I F Y W I N E V E N T */
  1739. /*------------------------------------------------------------------------------
  1740. ------------------------------------------------------------------------------*/
  1741. void CCandAccessible::NotifyWinEvent( DWORD dwEvent, CCandAccItem *pAccItem )
  1742. {
  1743. Assert( pAccItem != NULL );
  1744. OurNotifyWinEvent( dwEvent, m_hWnd, OBJID_CLIENT, pAccItem->GetID() );
  1745. }
  1746. /* C R E A T E R E F T O A C C O B J */
  1747. /*------------------------------------------------------------------------------
  1748. ------------------------------------------------------------------------------*/
  1749. LRESULT CCandAccessible::CreateRefToAccObj( WPARAM wParam )
  1750. {
  1751. return OurLresultFromObject( IID_IAccessible, wParam, (IAccessible *)this );
  1752. }