⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commandfactory.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	hrRet = pIMenu->get_MenuItems(&pIDispTemp);
	pgpAssert(SUCCEEDED(hrRet) && (NULL != pIDispTemp));
	if(FAILED(hrRet) || (NULL == pIDispTemp))
		goto cleanup;
	TraceRefCount(pIMenu);//***
	TraceRefCount(pIDispTemp);//***

	//ask that disp interface to give us IGWMenuItems iface if we go 
	//directly ask for this interface from the original disp passed 
	//to us there will be E_NOINTERFACE (ssd)
	pgpAssert(NULL == pIMenuItems);
	hrRet = pIDispTemp->QueryInterface(IID_IGWMenuItems, (void**)&pIMenuItems);
	pgpAssert(SUCCEEDED(hrRet) && (NULL != pIMenuItems));
	if(FAILED(hrRet) || (NULL == pIMenuItems))
		goto cleanup;
	TraceRefCount(pIMenu);//***
	TraceRefCount(pIDispTemp);//***
	TraceRefCount(pIMenuItems);//***
	
	//we dont need the disp iface anymore
	if(NULL != pIDispTemp)
	{
		pIDispTemp->Release();
		pIDispTemp=NULL;
	}

	if(dwCmdUiOptions&CUIO_MAIL_CONTEXT)
	{
		//find whether send is enabled in the menu somewhere. if it is so this is 
		//an unsent mail otherwise this is a recieved mail
		VariantInit(&vTmpOne);
		V_VT(&vTmpOne) = VT_I4;
		V_I4(&vTmpOne) = BFTKN_SEND;
		hrRet = pIMenuItems->FindByID(vTmpOne, &pIDispTemp);
		if(SUCCEEDED(hrRet) && (NULL != pIDispTemp))//if we did find the send menu
			dwCmdUiOptions |= CUIO_NEWMAIL_CONTEXT;//this must be treated as a new mail context
		else if(SUCCEEDED(hrRet) && (NULL == pIDispTemp))
			dwCmdUiOptions |= CUIO_OLDMAIL_CONTEXT;//this must be treated as old mail being opened

		//free this up for the next operation (if any)
		if(NULL != pIDispTemp)
		{
			pIDispTemp->Release();
			pIDispTemp = NULL;
		}
	}

	//get the string for the main menu before which we put our menu
	//this string is "Tools" in english version of GroupWise
	pgpAssert(NULL == pszPrependMenuString);
	bRet=SafeLoadString(IDS_PREPEND_GWMAINMENU_CMD, &pszPrependMenuString);
	if((FALSE == bRet) || (NULL == pszPrependMenuString))
	{
		hrRet=E_OUTOFMEMORY;
		goto cleanup;
	}

	//we intend to put "PGP" menu just before the tools menu so prepare a 
	//variant for the "Tools" menu string 
	VariantInit(&vTmpOne);
	VariantInit(&vTmpTwo);
	V_VT(&vTmpOne) = VT_BSTR;
	V_BSTR(&vTmpOne) = A2WBSTR(pszPrependMenuString);
	if(NULL == V_BSTR(&vTmpOne))
	{
		hrRet=E_OUTOFMEMORY;
		goto cleanup;
	}

	//get the string for the groupwise plug-in main menu. this string shall be
	//[ surprise :) ] "PGP" in english version of GroupWise
	pgpAssert(NULL == pszMainMenuString);
	bRet=SafeLoadString(IDS_GWPLUGIN_MAIN_MENU_NAME, &pszMainMenuString);
	if((FALSE == bRet) || (NULL == pszMainMenuString))
	{
		hrRet=E_OUTOFMEMORY;
		goto cleanup;
	}

	//allocate for the new main menu string which is "PGP" in english
	pgpAssert(NULL == bstrCaption);
	bstrCaption = A2WBSTR(pszMainMenuString);
	pgpAssert(NULL != bstrCaption);
	if(NULL == bstrCaption)
	{
		hrRet=E_OUTOFMEMORY;
		goto cleanup;
	}

	//add PGP menu
	pgpAssert(NULL == pIDispTemp);
	hrRet=pIMenuItems->AddMenu(bstrCaption, vTmpTwo,//no command object is relevant here(ssd)
				vTmpOne, &pIDispTemp);
	pgpAssert(SUCCEEDED(hrRet) && (NULL != pIDispTemp));
	if(FAILED(hrRet) || (NULL == pIDispTemp))
		goto cleanup;
	TraceRefCount(pIDispTemp);//***
	TraceRefCount(pIMenuItems);//***


	//free up the stuff that we needed only for this call
	if(NULL != bstrCaption)
	{
		SysFreeString(bstrCaption);
		bstrCaption=NULL;
	}
	SysFreeString(V_BSTR(&vTmpOne));
	VariantInit(&vTmpOne);


	//free up before overwriting
	if(NULL != pIMenu)
	{
		pIMenu->Release();
		pIMenu=NULL;
	}

	//get the menu iface of this newly added menu
	pgpAssert(NULL == pIMenu);
	hrRet=pIDispTemp->QueryInterface(IID_IGWMenu, (void**)&pIMenu);
	pgpAssert(SUCCEEDED(hrRet) && (NULL != pIMenu));
	if(FAILED(hrRet) || (NULL == pIMenu))
		goto cleanup;
	TraceRefCount(pIDispTemp);//***
	TraceRefCount(pIMenu);//***

	//free up before overwriting
	if(NULL != pIDispTemp)
	{
		pIDispTemp->Release();
		pIDispTemp=NULL;
	}

	//query for the read only property MenuItems (of the menu object)
	pgpAssert(NULL == pIDispTemp);
	hrRet = pIMenu->get_MenuItems(&pIDispTemp);
	pgpAssert(SUCCEEDED(hrRet) && (NULL != pIDispTemp));
	if(FAILED(hrRet) || (NULL == pIDispTemp))
		goto cleanup;
	TraceRefCount(pIDispTemp);//***
	TraceRefCount(pIMenu);//***


	//free up before overwriting
	if(NULL != pIMenuItems)
	{
		pIMenuItems->Release();
		pIMenuItems=NULL;
	}

	//ask that disp interface to give us IGWMenuItems iface 
	pgpAssert(NULL == pIMenuItems);
	hrRet = pIDispTemp->QueryInterface(IID_IGWMenuItems, (void**)&pIMenuItems);
	pgpAssert(SUCCEEDED(hrRet) && (NULL != pIMenuItems));
	if(FAILED(hrRet) || (NULL == pIMenuItems))
		goto cleanup;
	TraceRefCount(pIDispTemp);//***
	TraceRefCount(pIMenuItems);//***

		
	if(NULL != pIDispTemp)
	{
		pIDispTemp->Release();
		pIDispTemp=NULL;
	}
		
	//add the decrypt/verify menu
	hrRet = InternalAddMenuItem(IDS_COMMAND_DECRYPT, pIMenuItems, 
			IDM_DECRYPT_VERIFY, 
			dwCmdUiOptions|CUIO_IS_AN_OPERATION,
			IDS_HLPCMD_DECRYPT);
	pgpAssert(SUCCEEDED(hrRet));
	if(FAILED(hrRet))
		goto cleanup;
	TraceRefCount(pIMenuItems);//***
	
	if(dwCmdUiOptions&CUIO_MAIL_CONTEXT)//a message window
	{
		//add the show original menu
		hrRet = InternalAddMenuItem(IDS_COMMAND_SHOWORIG, pIMenuItems, 
						IDM_SHOW_ORIGINAL, 
						dwCmdUiOptions|CUIO_IS_AN_OPERATION,
						IDS_HLPCMD_SHOWORIG);
		pgpAssert(SUCCEEDED(hrRet));
		if(FAILED(hrRet))
			goto cleanup;

		//add the encrypt on send menu
		hrRet = InternalAddMenuItem(IDS_COMMAND_ENCRYPT_ONSEND, pIMenuItems, 
						IDM_AUTO_ENCRYPT_ONSEND, 
						dwCmdUiOptions|CUIO_IS_AN_OPTION|CUIO_PREPEND_MENU_SEPARATOR,
						IDS_HLPCMD_ENCRYPT_ONSEND);
		pgpAssert(SUCCEEDED(hrRet));
		if(FAILED(hrRet))
			goto cleanup;

		//add the sign on send menu
		hrRet = InternalAddMenuItem(IDS_COMMAND_SIGN_ONSEND, pIMenuItems, 
						IDM_AUTO_SIGN_ONSEND, 
						dwCmdUiOptions|CUIO_IS_AN_OPTION,
						IDS_HLPCMD_SIGN_ONSEND);
		pgpAssert(SUCCEEDED(hrRet));
		if(FAILED(hrRet))
			goto cleanup;

		//we do not support anything other than plain text in the mail body
		//uncomment these when we do the enhancements for RTF and/or HTML
		//add the convert to plain text menu
		//hrRet = InternalAddMenuItem(IDS_COMMAND_CONVTO_PLAINTXT, pIMenuItems, 
		//				IDM_CONVERT_TO_PLAIN_TEXT, 
		//				dwCmdUiOptions|CUIO_IS_AN_OPTION,
		//				IDS_HLPCMD_CONVTO_PLAINTXT);
		//pgpAssert(SUCCEEDED(hrRet));
		//if(FAILED(hrRet))
		//	goto cleanup;
	}

	//add the pgpkeys launch menu
	hrRet = InternalAddMenuItem(IDS_COMMAND_LAUNCH_PGPKEYS, pIMenuItems, 
			IDM_LAUNCH_PGPKEYS, dwCmdUiOptions|CUIO_IS_AN_OPERATION|CUIO_PREPEND_MENU_SEPARATOR,
			IDS_HLPCMD_LAUNCH_PGPKEYS);
	pgpAssert(SUCCEEDED(hrRet));
	if(FAILED(hrRet))
		goto cleanup;

	//add the options menu
	hrRet = InternalAddMenuItem(IDS_COMMAND_PGP_OPTIONS, pIMenuItems, 
			IDM_SHOW_PREFS, dwCmdUiOptions|CUIO_IS_AN_OPERATION,
			IDS_HLPCMD_PGP_OPTIONS);
	pgpAssert(SUCCEEDED(hrRet));
	if(FAILED(hrRet))
		goto cleanup;

cleanup:
	if(NULL != pIDispTemp)
	{
		pIDispTemp->Release();
		pIDispTemp=NULL;
	}
	if(NULL != pIDispTempTwo)
	{
		pIDispTempTwo->Release();
		pIDispTempTwo=NULL;
	}

	if(NULL != pIMenuItems)
	{
		pIMenuItems->Release();
		pIMenuItems=NULL;
	}
	if(NULL != pIMenu)
	{
		pIMenu->Release();
		pIMenu=NULL;
	}
	if(NULL != bstrCaption)
	{
		SysFreeString(bstrCaption);
		bstrCaption=NULL;
	}
	if(NULL != pszPrependMenuString)
	{
		free(pszPrependMenuString);
		pszPrependMenuString=NULL;
	}
	if(NULL != pszMainMenuString)
	{
		free(pszMainMenuString);
		pszMainMenuString=NULL;
	}
	return hrRet;
}

//////////////////////////////////////////////////////////////////
//  Name:CCommandFactory::CustomizeToolbar				
//
//  Description:Method to customize the toolbar. The C3po must assume 
//		that its commands are absebt from the toolbar. For example, 
//		when a toolbar has been saved and restored in another session 
//		of GroupWise, the commands can be put back onto the toolbar 
//		w/out any intervening calls to CustomizeToolbar. For that 
//		reason, the C3po should query, the toolbar first before adding 
//		anything to the toolbar window.
//	
//
//  In:BSTR bstrContext - Contains the class of the containing window.
//	   IDispatch * pIDispGWToolbar - Contains the GWToolbar object to 
//			be modified.
//
//  Out:VARIANT_BOOL FAR* pbChanged - Returning TRUE from this method 
//				indicates that the toolbar modifications were 'volatile'. 
//				In that case, each time the toolbar is validated in the 
//				UI, the	CommandFactory::CustomizeToolbar method will be 
//				called.
//
//
//  Comments:
////////////////////////////////////////////////////////////////////
STDMETHODIMP CCommandFactory::CustomizeToolbar(BSTR bstrContext,
						IDispatch * pIDispGWToolbar,
						VARIANT_BOOL FAR* pbChanged)
{
	PgpGwTrace("CCommandFactory::CustomizeToolbar(%S)\n", bstrContext);
	WORD wSize=0;
	IGWToolbar *pIToolbar=NULL;
	IGWToolbarItems *pIToolbarItems=NULL;
	IDispatch *pIDisp=NULL;
	
	HRESULT hrRet=S_OK;
	VARIANT vrTmp={0};
	DWORD dwCmdUiOptions=CUIO_IS_TOOLBAR_ITEM;
	HWND hWndReBar=NULL, hWndTBar=NULL;
	LPSUBCLASSINFO lpSubClassInfo=NULL;

	//determine the correct window context for this toolbar item
	//if it is the attachment viewer
	if (0 != wcsstr(bstrContext, ATTCHVIEWERCONTEXTW))
		dwCmdUiOptions |= CUIO_ATTVIEW_CONTEXT;
	else if(0 != wcsstr(bstrContext, MAINWINDOWCONTEXTW))//if it is the main browser window
		dwCmdUiOptions |= CUIO_MAINWND_CONTEXT;
	else if(0 != wcsstr(bstrContext, MAILMESSAGECONTEXTW))//or if it is a mail message
	{
		dwCmdUiOptions |= CUIO_MAIL_CONTEXT;

		//additionally if it is a discussion post
		if(0 != wcsstr(bstrContext, DISCUSSIONCONTEXTW))
			dwCmdUiOptions |= CUIO_DISCUSSION_CONTEXT;
	}
	else
	{
		pgpAssert(FALSE);//incorrect hooking ?
		hrRet=E_FAIL;
		goto cleanup;
	}

    //request the GWToolbar iface from dispatch
	pgpAssert(NULL == pIToolbar);
	hrRet = pIDispGWToolbar->QueryInterface(IID_IGWToolbar, (void**)&pIToolbar);
	pgpAssert(SUCCEEDED(hrRet) && (NULL != pIToolbar));
	if(FAILED(hrRet) || (NULL == pIToolbar))
		goto cleanup;

    //get the read only ToolbarItems property of the toolbar
	pgpAssert(NULL == pIDisp);
    hrRet = pIToolbar->get_ToolbarItems(&pIDisp);
	pgpAssert(SUCCEEDED(hrRet) && (NULL != pIDisp));
	if(FAILED(hrRet) || (NULL == pIDisp))
		goto cleanup;

    //request the GWToolbarItems iface of the dispatch
	pgpAssert(NULL == pIToolbarItems);
	hrRet = pIDisp->QueryInterface(IID_IGWToolbarItems, (void**)&pIToolbarItems);
	pgpAssert(SUCCEEDED(hrRet) && (NULL != pIToolbarItems));
	if(FAILED(hrRet) || (NULL == pIToolbarItems))
		goto cleanup;

    if((CUIO_MAINWND_CONTEXT&dwCmdUiOptions) ||
	   (CUIO_ATTVIEW_CONTEXT&dwCmdUiOptions))
	{
		//add the decrypt message button
		hrRet = InternalAddToolbarItem(pIToolbarItems,"IDB_ALT_DECRYPT", 
				IDS_HLPCMD_DECRYPT, dwCmdUiOptions|CUIO_IS_AN_OPERATION, 
				IDM_DECRYPT_VERIFY);

		//add the pgp keys launch button
		hrRet = InternalAddToolbarItem(pIToolbarItems,"IDB_PGPKEYS", 
				IDS_HLPCMD_LAUNCH_PGPKEYS, dwCmdUiOptions|CUIO_IS_AN_OPERATION,
				IDM_LAUNCH_PGPKEYS);
	}
	else
	{
		BOOL bAddButtons=TRUE;//whether to add buttons. this is necessary to fix a bug when HTML
							  //is the default compose view, our icons dont show in the toolbar
		BOOL bOpenMailView=FALSE;//whether this view is a mail open view as against a compose view
		int iIndex=0, iBtnCount=0;
		TBBUTTON tbbInfo={0};

		//NOTE:we reuse pIDisp here
		if(NULL != pIDisp)
		{
			pIDisp->Release();
			pIDisp=NULL;
		}
		
		//search for send button in the toolbar
		VariantInit(&vrTmp);
		V_VT(&vrTmp) = VT_I4;
		V_I4(&vrTmp) = BFTKN_SEND;
		hrRet = pIToolbarItems->FindByID(vrTmp, &pIDisp);
		if(SUCCEEDED(hrRet) && (NULL == pIDisp))//if we did not find the send menu
		{
			bOpenMailView = TRUE;//this must be treated as old mail being opened
			goto addbuttons; //let's add buttons since this is not a compose view
		}

		//get the rebar window
		hWndReBar=GetWindow(GWO_CURRENTREBAR_WINDOW);
		pgpAssert(NULL != hWndReBar);
		if(NULL == hWndReBar)
			goto addbuttons;//if we cant figure out things let's add the buttons anyway

		//the control comes here only if a mail is being composed.
		pgpAssert(FALSE == bOpenMailView);

		//for all the toolbars under the rebar
		while(NULL != (hWndTBar=FindWindowEx(hWndReBar, hWndTBar, TOOLBARCLASSNAME, NULL)))
		{
			//get the property associated with this toolbar
			LONG lOurData=(LONG)GetProp(hWndTBar, MODULENAME);

			//if we have never been called to modify this toolbar before
			if(0 == lOurData)
			{
				DWORD dwRet=0, dwHtmlComposeDisabled=0;
				DWORD dwBufSize=sizeof(DWORD);

				//check what compose view is enabled for this user
				dwRet=SHGetValue(HKEY_CURRENT_USER, "Software\\Novell\\GroupWise\\Client\\Setup",
					"DoNotCreateHTMLMessages", NULL, &dwHtmlComposeDisabled, &dwBufSize);
				pgpAssert(ERROR_SUCCESS == dwRet);

				//we store no of times we have been called in low word and the view option
				//in the high word of the property long value. so we remember we have been
				//called once and this was the compose view option when we were called.
				_VERIFY(0 != SetProp(hWndTBar, MODULENAME, 
						(HANDLE)MAKELONG(1, ((WORD)dwHtmlComposeDisabled))));

				//if we could not find the value, as far as we know it is safe to add the buttons 
				if(ERROR_SUCCESS != dwRet) 
					goto addbuttons; 

				//if the default compose view is html
				if(0 == dwHtmlComposeDisabled)
					bAddButtons=FALSE;//dont do anything. we will be called later
			}
			else if(1 == LOWORD(lOurData))//if we are being called for the second time
			{
				//remember that we have been called for the second time
				_VERIFY(0 != SetProp(hWndTBar, MODULENAME, 
						(HANDLE)MAKELONG(2, HIWORD(lOurData))));
			}
		}

		addbuttons:	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -