Exemple #1
0
static int CALLBACK DeleteAllEnumCallback(void* pItem, void* pData)
{
    IOleCommandTarget * pOct = reinterpret_cast<IOleCommandTarget *>(pItem);
    TRACE("Releasing SSO %p\n", pOct);
    pOct->Release();
    return TRUE;
}
// @pymethod |PyIDocHostUIHandler|ShowUI|Description of ShowUI.
PyObject *PyIDocHostUIHandler::ShowUI(PyObject *self, PyObject *args)
{
	IDocHostUIHandler *pIDHUIH = GetI(self);
	if ( pIDHUIH == NULL )
		return NULL;
	// @pyparm int|dwID||Description for dwID
	// @pyparm <o PyIOleInPlaceActiveObject>|pActiveObject||Description for pActiveObject
	// @pyparm <o PyIOleCommandTarget>|pCommandTarget||Description for pCommandTarget
	// @pyparm <o PyIOleInPlaceFrame>|pFrame||Description for pFrame
	// @pyparm <o PyIOleInPlaceUIWindow>|pDoc||Description for pDoc
	PyObject *obpActiveObject;
	PyObject *obpCommandTarget;
	PyObject *obpFrame;
	PyObject *obpDoc;
	DWORD dwID;
	if ( !PyArg_ParseTuple(args, "lOOOO:ShowUI", &dwID, &obpActiveObject, &obpCommandTarget, &obpFrame, &obpDoc) )
		return NULL;
	IOleInPlaceActiveObject * pActiveObject;
	IOleCommandTarget * pCommandTarget;
	IOleInPlaceFrame * pFrame;
	IOleInPlaceUIWindow * pDoc;
	BOOL bPythonIsHappy = TRUE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpActiveObject, IID_IOleInPlaceActiveObject, (void **)&pActiveObject, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpCommandTarget, IID_IOleCommandTarget, (void **)&pCommandTarget, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpFrame, IID_IOleInPlaceFrame, (void **)&pFrame, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpDoc, IID_IOleInPlaceUIWindow, (void **)&pDoc, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pIDHUIH->ShowUI( dwID, pActiveObject, pCommandTarget, pFrame, pDoc );
	if (pActiveObject) pActiveObject->Release();
	if (pCommandTarget) pCommandTarget->Release();
	if (pFrame) pFrame->Release();
	if (pDoc) pDoc->Release();
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIDHUIH, IID_IDocHostUIHandler );
	return PyInt_FromLong(hr);
}
// IDocHostUIHandler
STDMETHODIMP IEView::ShowContextMenu(DWORD dwID, POINT *ppt, IUnknown *pcmdTarget, IDispatch *pdispReserved) {
	IOleCommandTarget * pOleCommandTarget;
    IOleWindow * pOleWindow;
	HWND hSPWnd;
	if (builder == NULL) {
   //     return S_OK;
	}
    if (SUCCEEDED(pcmdTarget->QueryInterface(IID_IOleCommandTarget, (void**)&pOleCommandTarget))) {
		if (SUCCEEDED(pOleCommandTarget->QueryInterface(IID_IOleWindow, (void**)&pOleWindow))) {
    		pOleWindow->GetWindow(&hSPWnd);
			HMENU hMenu;
			hMenu = GetSubMenu(LoadMenu(hInstance, MAKEINTRESOURCE(IDR_CONTEXTMENU)),0);
		 	CallService(MS_LANGPACK_TRANSLATEMENU,(WPARAM)hMenu,0);
			if (dwID == 5) { // anchor
				EnableMenuItem(hMenu, ID_MENU_COPYLINK, MF_BYCOMMAND | MF_ENABLED);
			} else if (dwID == 4) { // text select
				EnableMenuItem(hMenu, ID_MENU_COPY, MF_BYCOMMAND | MF_ENABLED);
			} else if (dwID == 1) { // control (image)
				EnableMenuItem(hMenu, ID_MENU_SAVEIMAGE, MF_BYCOMMAND | MF_ENABLED);
			}
            if (builder!=NULL) {

			}
		 	int iSelection = TrackPopupMenu(hMenu,
		                                      TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
		                                      ppt->x,
		                                      ppt->y,
		                                      0,
		                                      hwnd,
		                                      (RECT*)NULL);
			DestroyMenu(hMenu);
			if (iSelection == ID_MENU_CLEARLOG) {
				clear(NULL);
			} else {
		    	SendMessage(hSPWnd, WM_COMMAND, iSelection, (LPARAM) NULL);
			}
    		pOleWindow->Release();
		}
	    pOleCommandTarget->Release();
	}
	return S_OK;
}
STDMETHODIMP	ExplorerBar::SetSite( IUnknown *inPunkSite )
{
	AFX_MANAGE_STATE( AfxGetStaticModuleState() );
	
	HRESULT		err;
	
	// Release the old interfaces.
	
	if( mWebBrowser )
	{
		mWebBrowser->Release();
		mWebBrowser = NULL;
	}
	if( mSite )
	{
		mSite->Release();
		mSite = NULL;
	}
	
	// A non-NULL site means we're setting the site. Otherwise, the site is being released (done above).
	
	if( !inPunkSite )
	{
		err = S_OK;
		goto exit;
	}
	
	// Get the parent window.
	
	IOleWindow *		oleWindow;
		
	mParentWindow = NULL;
	err = inPunkSite->QueryInterface( IID_IOleWindow, (LPVOID *) &oleWindow );
	require( SUCCEEDED( err ), exit );
	
	err = oleWindow->GetWindow( &mParentWindow );
	oleWindow->Release();
	require_noerr( err, exit );
	require_action( mParentWindow, exit, err = E_FAIL );
	
	// Get the IInputObject interface.
	
	err = inPunkSite->QueryInterface( IID_IInputObjectSite, (LPVOID *) &mSite );
	require( SUCCEEDED( err ), exit );
	check( mSite );
	
	// Get the IWebBrowser2 interface.
	
	IOleCommandTarget *		oleCommandTarget;
	
	err = inPunkSite->QueryInterface( IID_IOleCommandTarget, (LPVOID *) &oleCommandTarget );
	require( SUCCEEDED( err ), exit );
	
	IServiceProvider *		serviceProvider;
	
	err = oleCommandTarget->QueryInterface( IID_IServiceProvider, (LPVOID *) &serviceProvider );
	oleCommandTarget->Release();
	require( SUCCEEDED( err ), exit );
	
	err = serviceProvider->QueryService( SID_SWebBrowserApp, IID_IWebBrowser2, (LPVOID *) &mWebBrowser );
	serviceProvider->Release();
	require( SUCCEEDED( err ), exit );
	
	// Create the main window.
	
	err = SetupWindow();
	require_noerr( err, exit );
	
exit:
	return( err );
}
// IDocHostUIHandler
STDMETHODIMP IEView::ShowContextMenu(DWORD dwID, POINT *ppt, IUnknown *pcmdTarget, IDispatch *pdispReserved) {
    IOleCommandTarget * pOleCommandTarget;
    IOleWindow * pOleWindow;
    HWND hSPWnd;
    if (builder == NULL) {
        return S_OK;
    }
    if (SUCCEEDED(pcmdTarget->QueryInterface(IID_IOleCommandTarget, (void**)&pOleCommandTarget))) {
        if (SUCCEEDED(pOleCommandTarget->QueryInterface(IID_IOleWindow, (void**)&pOleWindow))) {
            pOleWindow->GetWindow(&hSPWnd);
            HMENU hMenu;
            hMenu = GetSubMenu(LoadMenu(hInstance, MAKEINTRESOURCE(IDR_CONTEXTMENU)),0);
            CallService(MS_LANGPACK_TRANSLATEMENU,(WPARAM)hMenu,0);
            if (dwID == 5) { // anchor
                EnableMenuItem(hMenu, ID_MENU_COPYLINK, MF_BYCOMMAND | MF_ENABLED);
            }
            if (dwID == 4) { // text select
                EnableMenuItem(hMenu, ID_MENU_COPY, MF_BYCOMMAND | MF_ENABLED);
            }
            if (builder!=NULL) {

            }
            int iSelection = TrackPopupMenu(hMenu,
                                            TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
                                            ppt->x,
                                            ppt->y,
                                            0,
                                            hwnd,
                                            (RECT*)NULL);
            DestroyMenu(hMenu);
            if (iSelection == ID_MENU_CLEARLOG) {
                /*
                IEVIEWEVENT event;
                event.cbSize = sizeof(IEVIEWEVENT);
                event.dwFlags=0;
                event.codepage = CP_ACP;
                BSTR selection = (BSTR)getSelection(&event);
                if (selection == NULL) {
                	MessageBoxW(NULL, L"", L"NULL SELECTION", MB_OK);
                } else if (wcslen(selection)==0) {
                	MessageBoxW(NULL, selection, L"EMPTY SELECTION", MB_OK);
                } else {
                	MessageBoxW(NULL, selection, L"SELECTION", MB_OK);
                }
                event.dwFlags=IEEF_NO_UNICODE;
                char *selectionA = (char *)getSelection(&event);
                if (selectionA == NULL) {
                	MessageBoxA(NULL, "", "NULL SELECTION", MB_OK);
                } else if (strlen(selectionA)==0) {
                	MessageBoxA(NULL, selectionA, "EMPTY SELECTION", MB_OK);
                } else {
                	MessageBoxA(NULL, selectionA, "SELECTION", MB_OK);
                }
                */
                clear();
            } else {
                SendMessage(hSPWnd, WM_COMMAND, iSelection, (LPARAM) NULL);
            }
            pOleWindow->Release();
        }
        pOleCommandTarget->Release();
    }
    return S_OK;
}