Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CATGUI/CATAccessible.cpp Source File

CATAccessible.cpp

Go to the documentation of this file.
00001 /// \file CATAccessible.cpp
00002 /// \brief Base class for Microsoft's IAccessible handling
00003 /// \ingroup CATGUI
00004 ///
00005 /// Copyright (c) 2007-2008 by Michael Ellison.
00006 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00007 ///
00008 // $Author: mikeellison $
00009 // $Date: 2008-01-25 05:11:25 -0600 (Fri, 25 Jan 2008) $
00010 // $Revision: $
00011 // $NoKeywords: $
00012 
00013 #include "CATAccessible.h"
00014 #include "CATControl.h"
00015 #include "CATWindow.h"
00016 
00017 // Sorry about the defines, it's just the interface as it originally comes
00018 // from OLEAcc is 100% unreadable to me. Trying to minimize the text to where
00019 // I can get it in a glance.
00020 #define CATACC HRESULT STDMETHODCALLTYPE
00021 
00022 
00023 CATAccessible::CATAccessible(CATGuiObj* object, CATWindow* baseWindow)
00024 {
00025     CATTRACE("CATAccessible");
00026     fObject   = object;    
00027     fWindow   = baseWindow;
00028     fRefCount = 2; 
00029 }
00030 
00031 void CATAccessible::ObjectDeath()
00032 {
00033     CATTRACE("CATAccessible::ObjectDeath");
00034     fObject = 0;
00035     this->Release();
00036 }
00037 
00038 CATAccessible::~CATAccessible()
00039 {
00040     CATTRACE("CATAccessible::~CATAccessible");
00041     CATASSERT(fRefCount == 0, "RefCount should be 0 here...");
00042 }
00043 
00044 CATACC CATAccessible::get_accParent(    IDispatch**     ppdispParent)
00045 {
00046     CATTRACE("CATAccessible::get_accParent");
00047     if (fObject)
00048     {
00049         if (0 == wcscmp(L"Window",fObject->GetType()))
00050         {
00051             *ppdispParent = 0;
00052             return S_FALSE;
00053         }
00054         
00055         *ppdispParent = ((CATGuiObj*)fObject->GetParent())->GetAccessible();
00056         return S_OK;
00057     }
00058     *ppdispParent = 0;
00059     return S_FALSE;
00060 }
00061 
00062 CATACC CATAccessible::get_accChildCount(long *          pcountChildren)
00063 {
00064     CATTRACE("CATAccessible::get_accChildCount");
00065     if (!fObject)
00066     {
00067         *pcountChildren = 0;
00068         return S_FALSE;
00069     }
00070 
00071     long numChildren = (long)fObject->GetNumChildren();
00072     *pcountChildren = numChildren;
00073     return S_OK;
00074 }
00075 
00076 CATACC CATAccessible::get_accChild(     VARIANT         varChild,
00077                                         IDispatch **    ppdispChild)
00078 {
00079     CATTRACE("CATAccessible::get_accChild");
00080     if (!fObject)
00081     {
00082         *ppdispChild = 0;
00083         return S_FALSE;
00084     }
00085 
00086     if (varChild.vt != VT_I4)
00087     {
00088         *ppdispChild = NULL;
00089         return E_INVALIDARG;
00090     }
00091     
00092     if (varChild.lVal == CHILDID_SELF)
00093     {
00094         *ppdispChild = (IDispatch*)this;
00095         return S_OK;
00096     }
00097 
00098     if ((CATUInt32)varChild.lVal < fObject->GetNumChildren())
00099     {
00100         CATGuiObj* obj = (CATGuiObj*)fObject->GetChild((CATUInt32)varChild.lVal);
00101         if (obj)
00102         {
00103             *ppdispChild = (IDispatch*)obj->GetAccessible();
00104             return S_OK;
00105         }
00106     }
00107     *ppdispChild = 0;
00108     return S_FALSE;
00109 }
00110 
00111 CATACC CATAccessible::get_accName(      VARIANT         varChild,
00112                                         BSTR *          pszName)
00113 {
00114     CATTRACE("CATAccessible::get_accName");
00115     if (!fObject)
00116     {
00117         *pszName = 0;
00118         return S_FALSE;
00119     }
00120     if (varChild.vt != VT_I4)
00121     {
00122         *pszName = NULL;
00123         return E_INVALIDARG;
00124     }
00125     
00126     if (varChild.lVal == CHILDID_SELF)
00127     {
00128         *pszName = SysAllocString((const wchar_t*)fObject->GetName());
00129         return S_OK;
00130     }
00131 
00132     if ((CATUInt32)varChild.lVal < fObject->GetNumChildren())
00133     {
00134         CATGuiObj* obj = (CATGuiObj*)fObject->GetChild((CATUInt32)varChild.lVal);
00135         if (obj)
00136         {
00137             *pszName = SysAllocString((const wchar_t*)obj->GetName());
00138             return S_OK;
00139         }
00140     }
00141     
00142     *pszName = 0;
00143     return S_FALSE;
00144 }
00145 
00146 CATACC CATAccessible::get_accValue(     VARIANT         varChild,
00147                                         BSTR *          pszValue)
00148 {
00149     CATTRACE("CATAccessible::get_accValue");
00150     if (!fObject)
00151     {
00152         *pszValue = 0;
00153         return S_FALSE;
00154     }
00155     if (varChild.vt != VT_I4)
00156     {
00157         *pszValue = NULL;
00158         return E_INVALIDARG;
00159     }
00160     
00161     if (fObject == fWindow)
00162     {
00163         *pszValue = 0;
00164         return S_FALSE;
00165     }
00166 
00167     if (varChild.lVal == CHILDID_SELF)
00168     {
00169         *pszValue = SysAllocString( (CATString)(((CATControl*)fObject)->GetValue()));
00170         return S_OK;
00171     }
00172 
00173     if ((CATUInt32)varChild.lVal < fObject->GetNumChildren())
00174     {
00175         CATGuiObj* obj = (CATGuiObj*)fObject->GetChild((CATUInt32)varChild.lVal);
00176         if (obj)
00177         {
00178             *pszValue = SysAllocString( (CATString)(((CATControl*)obj)->GetValue()));
00179             return S_OK;
00180         }
00181     }
00182     
00183     *pszValue = 0;
00184     return S_FALSE;
00185 }
00186 
00187 CATACC CATAccessible::get_accDescription(VARIANT        varChild,
00188                                          BSTR *         pszDescription)
00189 {
00190     CATTRACE("CATAccessible::get_accDescription");
00191 
00192     if (!fObject)
00193     {
00194         *pszDescription = 0;
00195         return S_FALSE;
00196     }
00197     if (varChild.vt != VT_I4)
00198     {
00199         *pszDescription = NULL;
00200         return E_INVALIDARG;
00201     }
00202     
00203     if (varChild.lVal == CHILDID_SELF)
00204     {
00205         *pszDescription = SysAllocString((const wchar_t*)fObject->GetType());
00206         return S_OK;
00207     }
00208 
00209     if ((CATUInt32)varChild.lVal < fObject->GetNumChildren())
00210     {
00211         CATGuiObj* obj = (CATGuiObj*)fObject->GetChild((CATUInt32)varChild.lVal);
00212         if (obj)
00213         {
00214             *pszDescription = SysAllocString((const wchar_t*)obj->GetType());
00215             return S_OK;
00216         }
00217     }
00218     
00219     *pszDescription= 0;
00220     return S_FALSE;
00221 }
00222 
00223 CATACC CATAccessible::get_accRole(      VARIANT         varChild,
00224                                         VARIANT *       pvarRole)
00225 {
00226     if (!fObject)
00227     {
00228         pvarRole->vt = VT_EMPTY;
00229         return S_FALSE;
00230     }
00231     
00232     if (varChild.vt != VT_I4)
00233     {
00234         pvarRole->vt = VT_EMPTY;
00235         return E_INVALIDARG;
00236     }
00237     
00238     if (varChild.lVal == CHILDID_SELF)
00239     {
00240         pvarRole->vt    = VT_I4;
00241         pvarRole->lVal = fObject->GetAccessRole();        
00242         return S_OK;
00243     }
00244 
00245     if ((CATUInt32)varChild.lVal < fObject->GetNumChildren())
00246     {
00247         CATGuiObj* obj = (CATGuiObj*)fObject->GetChild((CATUInt32)varChild.lVal);
00248         if (obj)
00249         {
00250             pvarRole->vt    = VT_I4;
00251             pvarRole->lVal = obj->GetAccessRole();        
00252             return S_OK;
00253         }
00254     }
00255     return S_FALSE;
00256 }
00257 
00258 CATACC CATAccessible::get_accState(     VARIANT         varChild, 
00259                                         VARIANT *       pvarState)
00260 {
00261     CATTRACE("CATAccessible::get_accState");
00262     if (!fObject)
00263     {
00264         pvarState->vt = VT_EMPTY;
00265         return S_FALSE;
00266     }
00267     
00268     if (varChild.vt != VT_I4)
00269     {
00270         pvarState->vt = VT_EMPTY;
00271         return E_INVALIDARG;
00272     }
00273     
00274     if (varChild.lVal == CHILDID_SELF)
00275     {
00276         pvarState->vt    = VT_I4;
00277         pvarState->lVal = fObject->GetAccessState();        
00278         return S_OK;
00279     }
00280 
00281     if ((CATUInt32)varChild.lVal < fObject->GetNumChildren())
00282     {
00283         CATGuiObj* obj = (CATGuiObj*)fObject->GetChild((CATUInt32)varChild.lVal);
00284         if (obj)
00285         {
00286             pvarState->vt    = VT_I4;
00287             pvarState->lVal  = obj->GetAccessState();
00288             return S_OK;
00289         }
00290     }
00291     return S_FALSE;
00292 }
00293 
00294 CATACC CATAccessible::get_accHelp(      VARIANT         varChild,
00295                                         BSTR *          pszHelp)
00296 {
00297     CATTRACE("CATAccessible::get_accHelp");
00298 
00299     if (!fObject)
00300     {
00301         *pszHelp = 0;
00302         return S_FALSE;
00303     }
00304     if (varChild.vt != VT_I4)
00305     {
00306         *pszHelp = NULL;
00307         return E_INVALIDARG;
00308     }
00309     
00310     if (varChild.lVal == CHILDID_SELF)
00311     {
00312         *pszHelp = SysAllocString((const wchar_t*)fObject->GetHint());
00313         return S_OK;
00314     }
00315 
00316     if ((CATUInt32)varChild.lVal < fObject->GetNumChildren())
00317     {
00318         CATGuiObj* obj = (CATGuiObj*)fObject->GetChild((CATUInt32)varChild.lVal);
00319         if (obj)
00320         {
00321             *pszHelp = SysAllocString((const wchar_t*)obj->GetHint());
00322             return S_OK;
00323         }
00324     }
00325     
00326     *pszHelp = 0;
00327     return S_FALSE;
00328 }
00329 
00330 CATACC CATAccessible::get_accHelpTopic (BSTR *          pszHelpFile,
00331                                         VARIANT         varChild,
00332                                         long *          pidTopic)
00333 {
00334     CATTRACE("CATAccessible::get_accHelpTopic");
00335     return S_FALSE;
00336 }
00337 
00338 CATACC CATAccessible::get_accKeyboardShortcut(VARIANT         varChild,
00339                                               BSTR *          pszKeyboardShortcut)
00340 {
00341     CATTRACE("CATAccessible::get_AccKeyboardShortcut");
00342     return S_FALSE;
00343 }
00344 
00345 CATACC CATAccessible::get_accFocus(     VARIANT *       pvarChild)
00346 {
00347     CATTRACE("CATAccessible::get_accFocus");
00348     if (!fObject)
00349     {
00350         pvarChild->vt = VT_EMPTY;
00351         return S_FALSE;
00352     }
00353 
00354     CATControl* control = fWindow->GetFocusControl();
00355     if (control)
00356     {
00357         if (control == fObject)
00358         {
00359             pvarChild->vt = VT_I4;
00360             pvarChild->lVal = CHILDID_SELF;
00361             return S_OK;
00362         }
00363 
00364         pvarChild->vt       = VT_DISPATCH;
00365         pvarChild->pdispVal = control->GetAccessible();
00366     }
00367 
00368     pvarChild->vt = VT_EMPTY;
00369     return S_FALSE;
00370 }
00371 
00372 CATACC CATAccessible::get_accSelection (VARIANT *       pvarChildren)
00373 {
00374     CATTRACE("CATAccessible::get_accSelection");
00375     return S_FALSE;
00376 }
00377 
00378 CATACC CATAccessible::get_accDefaultAction(VARIANT         varChild,
00379                                            BSTR *          pszDefaultAction)
00380 {
00381     CATTRACE("CATAccessible::get_accDefaultAction");
00382     return S_FALSE;
00383 }
00384 
00385 CATACC CATAccessible::accSelect(        long            flagsSelect,
00386                                         VARIANT         varChild)
00387 {
00388     CATTRACE("CATAccessible::accSelect");
00389     if (varChild.vt != VT_I4)
00390     {
00391         return E_INVALIDARG;
00392     }
00393 
00394 
00395     if (varChild.lVal == CHILDID_SELF)
00396     {
00397         if (flagsSelect & SELFLAG_TAKEFOCUS)
00398         {
00399             fWindow->SetFocus((CATControl*)fObject);
00400         }
00401         return S_OK;
00402     }
00403 
00404     if ((CATUInt32)varChild.lVal < fObject->GetNumChildren())
00405     {
00406         CATGuiObj* obj = (CATGuiObj*)fObject->GetChild((CATUInt32)varChild.lVal);
00407         if (obj)
00408         {
00409             if (flagsSelect & SELFLAG_TAKEFOCUS)
00410             {
00411                 fWindow->SetFocus((CATControl*)obj);
00412             }
00413             return S_OK;
00414         }
00415     }
00416 
00417     return S_FALSE;
00418 }
00419 
00420 CATACC CATAccessible::accLocation(      long *          pxLeft,
00421                                         long *          pyTop,
00422                                         long *          pcxWidth,
00423                                         long *          pcyHeight,
00424                                          VARIANT        varChild)
00425 {
00426     CATTRACE("CATAccessible::accLocation");
00427     return S_FALSE;
00428 }
00429 
00430 CATACC CATAccessible::accNavigate(      long            navDir,
00431                                         VARIANT         varStart,
00432                                         VARIANT *       pvarEndUpAt)
00433 {
00434     CATTRACE("CATAccessible::accNavigate");
00435     if (varStart.vt != VT_I4)
00436     {
00437         pvarEndUpAt->vt       = VT_DISPATCH;
00438         pvarEndUpAt->pdispVal = this;
00439         return S_OK;
00440     }
00441 
00442     if (fObject == fWindow)
00443     {
00444         pvarEndUpAt->vt = VT_DISPATCH;
00445         pvarEndUpAt->pdispVal = this;
00446         CATUInt32 numChildren = fWindow->GetNumChildren();        
00447         return S_OK;
00448     }
00449     
00450     
00451     CATControl* curObj = (CATControl*)fObject;
00452     if (varStart.lVal != CHILDID_SELF)
00453     {
00454         if ((CATUInt32)varStart.lVal < fObject->GetNumChildren())
00455         {
00456             curObj = (CATControl*)fObject->GetChild((CATUInt32)varStart.lVal);
00457         }
00458     }   
00459     
00460     CATFINDCONTROLSTRUCT ctrlStruct;
00461     fWindow->GetControlStruct(ctrlStruct,curObj);
00462     
00463     switch (navDir)
00464     {
00465         case NAVDIR_FIRSTCHILD:
00466             pvarEndUpAt->pdispVal = 0;
00467             break;
00468         case NAVDIR_LASTCHILD:
00469             pvarEndUpAt->pdispVal = 0;
00470             break;
00471         case NAVDIR_LEFT:
00472         case NAVDIR_PREVIOUS:
00473         case NAVDIR_UP:
00474             if (ctrlStruct.NextControl)
00475                 pvarEndUpAt->pdispVal = ctrlStruct.NextControl->GetAccessible();
00476             break;
00477         case NAVDIR_RIGHT:
00478         case NAVDIR_DOWN:
00479         case NAVDIR_NEXT:
00480             if (ctrlStruct.PrevControl)
00481                 pvarEndUpAt->pdispVal = ctrlStruct.PrevControl->GetAccessible();
00482             break;
00483     }            
00484 
00485     return S_FALSE;
00486 }
00487 
00488 CATACC CATAccessible::accHitTest(       long            xLeft,
00489                                         long            yTop,
00490                                         VARIANT *       pvarChild)
00491 {
00492     CATTRACE("CATAccessible::accHitTest");
00493     if (!fObject)
00494     {
00495         pvarChild->vt = VT_EMPTY;
00496         return S_FALSE;
00497     }
00498 
00499     CATPOINT point;
00500     point.x = xLeft;
00501     point.y = yTop;
00502     ::ScreenToClient(fWindow->OSGetWnd(),(LPPOINT)&point);
00503     CATControl* control = fWindow->HitTest(point);
00504     if (control)
00505     {
00506         if (control == fObject)
00507         {
00508             pvarChild->vt = VT_I4;
00509             pvarChild->lVal = CHILDID_SELF;
00510             return S_OK;
00511         }
00512 
00513         pvarChild->vt       = VT_DISPATCH;
00514         pvarChild->pdispVal = control->GetAccessible();
00515     }
00516 
00517     pvarChild->vt = VT_EMPTY;
00518     return S_FALSE;
00519 }
00520 
00521 CATACC CATAccessible::accDoDefaultAction(VARIANT        varChild)
00522 {
00523     CATTRACE("CATAccessible::accDoDefaultAction");
00524     return S_FALSE;
00525 }
00526 
00527 CATACC CATAccessible::put_accName(      VARIANT       varChild,
00528                                         BSTR          szName)
00529 {
00530     CATTRACE("CATAccessible::put_accName");
00531     return S_FALSE;
00532 }
00533 
00534 CATACC CATAccessible::put_accValue(VARIANT      varChild,
00535                                    BSTR         szValue)
00536 {
00537     CATTRACE("CATAccessible::put_accValue");
00538     return S_FALSE;
00539 }
00540 
00541 
00542 CATACC CATAccessible::QueryInterface(   REFIID          riid,
00543                                         void **         ppvObject)
00544 {
00545     if (riid == IID_IUnknown)
00546     {
00547         *ppvObject = (IUnknown*)this;
00548         AddRef();
00549         return S_OK;
00550     }
00551 
00552 
00553     if  (riid == IID_IAccessible)
00554     {
00555         *ppvObject = (IAccessible*)this;
00556         AddRef();
00557         return S_OK;
00558     }
00559 
00560     if (riid == IID_IDispatch)
00561     {
00562         *ppvObject = (IDispatch*)this;
00563         AddRef();
00564         return S_OK;
00565     }
00566     return E_NOINTERFACE;
00567 }
00568 
00569 ULONG STDMETHODCALLTYPE CATAccessible::AddRef ( void)
00570 {
00571     CATTRACE("AddRef()");
00572     return ++fRefCount;
00573 }
00574 
00575 ULONG STDMETHODCALLTYPE CATAccessible::Release( void)
00576 {    
00577     CATTRACE("Release()");
00578     fRefCount--;    
00579     
00580     ULONG retVal = fRefCount;
00581     
00582     if (!retVal)
00583         delete this;
00584     
00585     return retVal;    
00586 }
00587 
00588 CATACC CATAccessible::GetTypeInfoCount( UINT *          pctinfo)
00589 {
00590     *pctinfo = 0;
00591     return E_NOTIMPL;
00592 }
00593 
00594 CATACC CATAccessible::GetTypeInfo(      UINT            iTInfo,
00595                                         LCID            lcid,
00596                                         ITypeInfo **    ppTInfo)
00597 {
00598     *ppTInfo = 0;
00599     return E_NOTIMPL;
00600 }
00601 
00602 CATACC CATAccessible::GetIDsOfNames(          REFIID          riid,
00603                                         __RPC__in_ecount_full(cNames) LPOLESTR *rgszNames,
00604                                         UINT            cNames,
00605                                         LCID            lcid,
00606                                         __RPC__out_ecount_full(cNames) DISPID *rgDispId)
00607 {
00608     return E_NOTIMPL;
00609 }
00610 
00611 CATACC CATAccessible::Invoke(    DISPID          dispIdMember,
00612                                  REFIID          riid,
00613                                  LCID            lcid,
00614                                  WORD            wFlags,
00615                                  DISPPARAMS *    pDispParams,
00616                                  VARIANT *       pVarResult,
00617                                  EXCEPINFO *     pExcepInfo,
00618                                  UINT *          puArgErr)
00619 {
00620     return E_NOTIMPL;
00621 }
00622 
00623 
00624 
00625 
00626 #undef CATACC

Generated on Mon Feb 11 04:09:50 2008 for Game Accessibility Suite by doxygen 1.5.4