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

📄 gwcommand.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 5 页
字号:
				pgpAssert(m_dwCmdUiInfo & CUIO_IS_AN_OPTION);
				if((lpMsgInfo->dwState)&MIS_AUTO_ENCRYPT_ON_SEND)
					*plValidate=eGW_CMDVAL_CHECKED;//TODO:dont read msginfo directly-claim the mutex
				else
					*plValidate=0;//just enabled otherwise
			}
			else//ie. if the command is in old mail context
			{
				pgpAssert(0 != (m_dwCmdUiInfo&CUIO_OLDMAIL_CONTEXT));
				*plValidate=eGW_CMDVAL_DISABLED;//disable it
			}
			//unlock the hash table
			g_pccihCmdHash->UnLock();
			break;

		case IDM_AUTO_SIGN_ONSEND:
			pgpAssert(0 != (m_dwCmdUiInfo&CUIO_MAIL_CONTEXT));
			//lock the hash table			
			g_pccihCmdHash->Lock();

			//if the command is in the context of a discussion/note then disable it
			if(m_dwCmdUiInfo&CUIO_DISCUSSION_CONTEXT)
			{
				pgpAssert(m_dwCmdUiInfo & CUIO_IS_AN_OPTION);//should be an option
				pgpAssert(m_dwCmdUiInfo & CUIO_MAIL_CONTEXT);//discussion context is also a mail context
				
				*plValidate=eGW_CMDVAL_DISABLED;//disable it
			}
			//if the command is in the context of a new mail
			else if(m_dwCmdUiInfo&CUIO_NEWMAIL_CONTEXT)
			{
				pgpAssert(m_dwCmdUiInfo & CUIO_IS_AN_OPTION);
				if((lpMsgInfo->dwState)&MIS_AUTO_SIGN_ON_SEND)
					*plValidate=eGW_CMDVAL_CHECKED;
				else
					*plValidate=0;//just enabled otherwise
			}
			else//ie. if the command is in old mail context
			{
				pgpAssert(0 != (m_dwCmdUiInfo&CUIO_OLDMAIL_CONTEXT));
				*plValidate=eGW_CMDVAL_DISABLED;//disable it
			}

			//unlock the hash table
			g_pccihCmdHash->UnLock();

			break;

		case IDM_CONVERT_TO_PLAIN_TEXT:
			pgpAssert(0 != (m_dwCmdUiInfo&CUIO_MAIL_CONTEXT));
			//lock the hash table			
			g_pccihCmdHash->Lock();

			//if the command is in the context of a discussion/note then disable it
			if(m_dwCmdUiInfo&CUIO_DISCUSSION_CONTEXT)
			{
				pgpAssert(m_dwCmdUiInfo & CUIO_IS_AN_OPTION);//should be an option
				pgpAssert(m_dwCmdUiInfo & CUIO_MAIL_CONTEXT);//discussion context is also a mail context
				
				*plValidate=eGW_CMDVAL_DISABLED;//disable it
			}
			//if the command is in the context of a new mail
			else if(m_dwCmdUiInfo&CUIO_NEWMAIL_CONTEXT)
			{
				pgpAssert(m_dwCmdUiInfo & CUIO_IS_AN_OPTION);
				if((lpMsgInfo->dwState)&MIS_CONV_TO_PLAIN_TEXT)
					*plValidate=eGW_CMDVAL_CHECKED;//TODO:dont read msginfo directly-claim the mutex
				else
					*plValidate=0;//just enabled otherwise
			}
			else//ie. if the command is in old mail context
			{
				pgpAssert(0 != (m_dwCmdUiInfo&CUIO_OLDMAIL_CONTEXT));
				*plValidate=eGW_CMDVAL_DISABLED;//disable it
			}

			//unlock the hash table
			g_pccihCmdHash->UnLock();
			break;

		case IDM_DECRYPT_VERIFY://decrypt/verify 
			pgpAssert(m_dwCmdUiInfo & CUIO_IS_AN_OPERATION);//should be an operation
			//if the command is in the context of a discussion/note then disable it
			if(m_dwCmdUiInfo&CUIO_DISCUSSION_CONTEXT)
			{
				pgpAssert(m_dwCmdUiInfo & CUIO_MAIL_CONTEXT);//discussion context is also a mail context
				
				*plValidate=eGW_CMDVAL_DISABLED;//disable it
			}
			else if((m_dwCmdUiInfo&CUIO_OLDMAIL_CONTEXT) || (m_dwCmdUiInfo&CUIO_MAINWND_CONTEXT))
			{
				if(m_dwCmdUiInfo&CUIO_OLDMAIL_CONTEXT)
				{
					//if in the old mail context
					if((NULL != lpMsgInfo->hNewMsgTxtWnd) && //if there is an overlapping window we have created
					   (IsWindowVisible(lpMsgInfo->hNewMsgTxtWnd)))//and it is the one being shown to the user now
						*plValidate=eGW_CMDVAL_DISABLED;
					else
						*plValidate=0;//enabled
				}
				else//must be from the main window 
				{
					pgpAssert(m_dwCmdUiInfo&CUIO_MAINWND_CONTEXT);

					//we disable the decrypt/verify button on main window toolbar
					//remove the following lines to reenable the logic of disabling
					//if multiple messages are selected
					*plValidate=eGW_CMDVAL_DISABLED;

#if 0 
					IDispatch *pDispTemp=NULL;
					IGWClientState *pClientState=NULL;
					IGWMessageList *pMsgs=NULL;
					LONG lMsgCount=0;


					//check if any message is selected or multiple messages are

					//get the client state
					hrRet=m_pIMgr->get_ClientState(&pDispTemp);
					pgpAssert(SUCCEEDED(hrRet) && (NULL != pDispTemp));
					if(FAILED(hrRet) || (NULL == pDispTemp))
						goto decrypt_verify_end;

					hrRet=pDispTemp->QueryInterface(IID_IClientState, (void **)&pClientState);
					pgpAssert(SUCCEEDED(hrRet) && (NULL != pClientState));
					if(FAILED(hrRet) || (NULL == pClientState))
						goto decrypt_verify_end;

					pgpAssert(NULL != pDispTemp);
					pDispTemp->Release();
					pDispTemp=NULL;

					//get the selected message list
					hrRet=pClientState->get_SelectedMessages(&pDispTemp);
					pgpAssert(SUCCEEDED(hrRet) && (NULL != pDispTemp));
					if(FAILED(hrRet) || (NULL == pDispTemp))
						goto decrypt_verify_end;

					hrRet=pDispTemp->QueryInterface(IID_IGWMessageList, (void **)&pMsgs);
					pgpAssert(SUCCEEDED(hrRet) && (NULL != pMsgs));
					if(FAILED(hrRet) || (NULL == pMsgs))
						goto decrypt_verify_end;

					
					//get the count of selected messages
					hrRet=pMsgs->get_Count(&lMsgCount);

					decrypt_verify_end:
					if(NULL != pClientState)
					{
						pClientState->Release();
						pClientState=NULL;
					}

					if(NULL != pDispTemp)
					{
						pDispTemp->Release();
						pDispTemp=NULL;
					}

					if(NULL != pMsgs)
					{
						pMsgs->Release();
						pMsgs=NULL;
					}

					
					if (1 == lMsgCount)//if exactly one msg is selected
						*plValidate=0;
					else//if any error happened or no msgs are selected or multiple
						//messages are selected
						*plValidate=eGW_CMDVAL_DISABLED;
#endif //#if 0
					
				}
			}
			else if(m_dwCmdUiInfo&CUIO_ATTVIEW_CONTEXT)
			{
				*plValidate=0;//enable it always in the attachment window
			}
			else
				*plValidate=eGW_CMDVAL_DISABLED;
			break;

		case IDM_SHOW_ORIGINAL://show original message
			//if the command is in the context of a discussion/note then disable it
			if(m_dwCmdUiInfo&CUIO_DISCUSSION_CONTEXT)
			{
				pgpAssert(m_dwCmdUiInfo & CUIO_MAIL_CONTEXT);//discussion context is also a mail context
				
				*plValidate=eGW_CMDVAL_DISABLED;//disable it
			}
			else if(m_dwCmdUiInfo&CUIO_OLDMAIL_CONTEXT)
			{
				//lock the hash table			
				g_pccihCmdHash->Lock();
				
				pgpAssert(m_dwCmdUiInfo & CUIO_IS_AN_OPERATION);
				if((NULL != lpMsgInfo->hNewMsgTxtWnd) && //if there is an overlapping window we have created
				   (IsWindowVisible(lpMsgInfo->hNewMsgTxtWnd)))//and it is the one being shown to the user now
					*plValidate=0;
				else
					*plValidate=eGW_CMDVAL_DISABLED;
				
				//unlock the hash table
				g_pccihCmdHash->UnLock();
			}
			else
				*plValidate=eGW_CMDVAL_DISABLED;
			break;

		default:
			break;
	}

cleanup:
	return S_OK;//we return success always hoping gw does not reject the 
				//command status we filled in on the basis of error return
}

//////////////////////////////////////////////////////////////////
//	Name:CGWCommand::SetTextOfReadOnlyMail				
//
//  Description:This is called to show the decrypted text of the 
//      message. Since GW wound not allow us to change the message
//		and the control is set read only(violation of which leads
//		to other problems plus save prompt at close) we create a 
//		control identical to GW's and show it on top of it and 
//		resize it and all the other jugglery that is necessary
//
//  In:	pszMailTextToWrite -pointing to ANSI decrypted text
//  In/Out:hPlainTxtMsgWnd  -passed null if we have not already got 
//				an overlapped window. on return it has the orig 
//				window handle. MUST have the original window handle
//				if the caller has called this function once before
//				for the mail message and was passed back a not null
//				pointer. so caller MUST save if fn returns not null
//				handle in this parameter and caller plans to call 
//				this function again in future.
//
//	In/Out:hHtmlTxtMsgWnd - passed null if we dont know any html text
//				window in existence yet, for this message. we only
//				try to dig for this window if plain text window is 
//				found to be hidden.
//
//	In/Out:hOverlappingWnd -similar use as hPlainTxtMsgWnd. it is
//				technically possible that this window is same as
//				the original window.
//
//  Out:hTrackedMsgWnd - the message window we are tracking currently
//				depending on the html/plain text view this could be
//				either the browser control or the richedit control
//
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::SetTextOfReadOnlyMail(char *pszMailTextToWrite,
											   HWND &hPlainTxtMsgWnd,
											   HWND &hHtmlTxtMsgWnd,
											   HWND &hOverlappingWnd,
											   HWND &hTrackedMsgWnd)
{
	HRESULT hrRet=S_OK;
	HWND hVisibleMsgWindow=NULL;
	LONG lWndData=0;
	RECT rcCtrlRect={0};
	POINT ptTmpPoint={0};
	BOOL bRet=FALSE;
	DWORD dwStyle=0, dwExStyle=0;
	LPSUBCLASSINFO lpSubClassInfo=NULL;
	CHARFORMAT cfCharFmt;
	ZeroMemory(&cfCharFmt, sizeof(CHARFORMAT));
	cfCharFmt.cbSize=sizeof(CHARFORMAT);

	
	//check parameters
	//pszMailTextToWrite can be NULL when it is a blank message

	//check object state
	pgpAssert(0 < (m_dwCmdUiInfo&CUIO_OLDMAIL_CONTEXT));
	pgpAssert(NULL != m_hCtxtWindow);
	if(NULL == m_hCtxtWindow)//if we dont have the context window
	{
		hrRet=E_FAIL;//we cannot do much yet !!
		goto cleanup;
	}

	//if the message body window was not passed to us
	if(NULL == hPlainTxtMsgWnd)
	{
		//try to get the plain text message window
		PgpGwTrace("trying to get plain text message window\n");
		_VERIFY(TRUE == GetPlainTxtMsgWnd(hPlainTxtMsgWnd));
		pgpAssert(NULL != hPlainTxtMsgWnd);
		pgpAssert((0x2717 == GetDlgCtrlID(hPlainTxtMsgWnd)) || (0x2718 == GetDlgCtrlID(hPlainTxtMsgWnd)));
		PgpGwTrace("got plain text message window\n");
	}

	//if the plain text message window is visible then it is the visible message window
	if((NULL != hPlainTxtMsgWnd) && IsWindowVisible(hPlainTxtMsgWnd))
	{
		PgpGwTrace("setting visible message window to the plain text message window\n");
		hVisibleMsgWindow=hPlainTxtMsgWnd;
	}

	//if the plain text message window is not visible and htmltxt window
	//was not passed to us, let us find out what the html window handle is
	if((!IsWindowVisible(hPlainTxtMsgWnd)) && (NULL == hHtmlTxtMsgWnd))
	{
		PgpGwTrace("trying to get html text message window\n");
		_VERIFY(TRUE == GetHtmlMsgWnd(hHtmlTxtMsgWnd));
		pgpAssert(NULL != hHtmlTxtMsgWnd);
		pgpAssert(IsWindowVisible(hHtmlTxtMsgWnd));//should be visible
		PgpGwTrace("got html text message window\n");

	}

	//if the html window is visible, it is the visible message window
	if((NULL != hHtmlTxtMsgWnd) && IsWindowVisible(hHtmlTxtMsgWnd))
	{
		pgpAssert(!IsWindowVisible(hPlainTxtMsgWnd));//plain txt window should be hidden
		hVisibleMsgWindow=hHtmlTxtMsgWnd;
	}
	
	
	pgpAssert(NULL != hVisibleMsgWindow);//we should have known the visible message window by now

	//get the position of the visible message window

	//get the window rect in screen coords
	bRet=GetWindowRect(hVisibleMsgWindow, &rcCtrlRect);
	pgpAssert(TRUE == bRet);

	//convert to client coords
	ptTmpPoint.x=rcCtrlRect.left;
	ptTmpPoint.y=rcCtrlRect.top;
	bRet=ScreenToClient(m_hCtxtWindow, &ptTmpPoint); 
	pgpAssert(TRUE == bRet);
	rcCtrlRect.left=ptTmpPoint.x;
	rcCtrlRect.top=ptTmpPoint.y;

	ptTmpPoint.x=rcCtrlRect.right;
	ptTmpPoint.y=rcCtrlRect.bottom;
	bRet=ScreenToClient(m_hCtxtWindow, &ptTmpPoint); 
	pgpAssert(TRUE == bRet);
	rcCtrlRect.right=ptTmpPoint.x;
	rcCtrlRect.bottom=ptTmpPoint.y;

	if(NULL == hOverlappingWnd)//if there is no overlapping window already
	{
		//create a control identical to the original plain text control
		//positioned exactly like the currently visible message control

		//get the control styles
		dwStyle=GetWindowLong(hPlainTxtMsgWnd, GWL_STYLE); 
		dwExStyle=GetWindowLong(hPlainTxtMsgWnd, GWL_EXSTYLE);

		//create a control in the same place
		hOverlappingWnd=CreateWindowEx(dwExStyle, "RICHEDIT", NULL, 
			dwStyle, rcCtrlRect.left, rcCtrlRect.top, abs(rcCtrlRect.right-rcCtrlRect.left), 
			abs(rcCtrlRect.bottom - rcCtrlRect.top), m_hCtxtWindow, NULL, 
			g_hInstance, NULL);
		pgpAssert(NULL != hOverlappingWnd);
		if(NULL == hOverlappingWnd)//if we could not create
		{
			//we cheat groupwise by setting it to write allowed, changing text
			//and setting it back to read only
			PgpGwTrace("WARNING! setting text directly to the readonly control\n");
			SendMessage(hPlainTxtMsgWnd, EM_SETOPTIONS, ECOOP_XOR, ECO_READONLY);
			SendMessage(hPlainTxtMsgWnd, WM_SETTEXT, 0, (LPARAM)pszMailTextToWrite);
			SendMessage(hPlainTxtMsgWnd, EM_SETOPTIONS, ECOOP_XOR, ECO_READONLY);
			SendMessage(hPlainTxtMsgWnd, EM_SETMODIFY, FALSE, 0);//does not work !
			hrRet=S_OK;
			goto cleanup;
		}

		//control comes here only if the new window was created

#if(_WIN32_WINNT >= 0x0500)
		dwExStyle|=WS_EX_LAYERED;
		SetWindowLong(hOverlappingWnd, GWL_EXSTYLE, dwExStyle);
		SetLayeredWindowAttributes(hOverlappingWnd, 0, (255*70)/100, LWA_ALPHA);
#endif

		//set the control in the tab order after the visible msg text control
		SetWindowPos(hOverlappingWnd, hVisibleMsgWindow, 0, 0, 0, 0, 
				SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);

		//set the font of the control to the font of the original
		SendMessage(hPlainTxtMsgWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cfCharFmt);
		pgpAssert(NULL != cfCharFmt.szFaceName[0]);
		cfCharFmt.dwMask = CFM_FACE|CFM_SIZE|CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_COLOR;
		_VERIFY(0 != SendMessage(hOverlappingWnd, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cfCharFmt));


		pgpAssert(NULL == lpSubClassInfo);
		lpSubClassInfo=(LPSUBCLASSINFO)calloc(sizeof(SUBCLASSINFO), 1);
		if(NULL != lpSubClassInfo)
		{
			//fill up the struct with the new control window and groupwise's
			//original window proc of the message body richedit control 
			lpSubClassInfo->hWndOther=hPlainTxtMsgWnd;
			lpSubClassInfo->wpOrigProc=(WNDPROC)GetWindowLong(hOverlappingWnd, GWL_WNDPROC);
			pgpAssert(NULL != lpSubClassInfo->wpOrigProc);

			//store the info in our property for the msg text control.
			_VERIFY(0 != SetProp(hOverlappingWnd, MODULENAME, lpSubClassInfo));
			lpSubClassInfo=NULL;

			//subclass now - since the subclass proc can get the details from subclassinfo
			SetWindowLong(hOverlappingWnd, GWL_WNDPROC, (LONG)DecryptVerifyWndProc);
		}
	}
	else
	{
		//the overlapping window is already created. we just want to move it
		//to the rectangle of current visible window.
		bRet=MoveWindow(hOverlappingWnd, rcCtrlRect.left, rcCtrlRect.top, 
			abs(rcCtrlRect.right-rcCtrlRect.left), 
			abs(rcCtrlRect.bottom - rcCtrlRect.top), FALSE);
		pgpAssert(TRUE == bRet);

	}

	//if the visible window has not got our property already
	if(NULL == GetProp(hVisibleMsgWindow, MODULENAME))
	{
		//subclass the visible control so that we can resize and do our mimicry as far
		//as practicable.but before that let us store the info in our window prop
		pgpAssert(NULL == lpSubClassInfo);

⌨️ 快捷键说明

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