xref: /freebsd/crypto/krb5/src/windows/leash/LeashDebugWindow.cpp (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert //	**************************************************************************************
2*7f2fe78bSCy Schubert //	File:			LeashDebugWindow.cpp
3*7f2fe78bSCy Schubert //	By:				Arthur David Leather
4*7f2fe78bSCy Schubert //	Created:		12/02/98
5*7f2fe78bSCy Schubert //	Copyright		@1998 Massachusetts Institute of Technology - All rights reserved.
6*7f2fe78bSCy Schubert //	Description:	CPP file for LeashDebugWindow.h. Contains variables and functions
7*7f2fe78bSCy Schubert //					for the Leash Debug Window
8*7f2fe78bSCy Schubert //
9*7f2fe78bSCy Schubert //	History:
10*7f2fe78bSCy Schubert //
11*7f2fe78bSCy Schubert //	MM/DD/YY	Inits	Description of Change
12*7f2fe78bSCy Schubert //	12/02/98	ADL		Original
13*7f2fe78bSCy Schubert //	**************************************************************************************
14*7f2fe78bSCy Schubert 
15*7f2fe78bSCy Schubert 
16*7f2fe78bSCy Schubert 
17*7f2fe78bSCy Schubert #include "stdafx.h"
18*7f2fe78bSCy Schubert #include "leash.h"
19*7f2fe78bSCy Schubert #include "LeashDebugWindow.h"
20*7f2fe78bSCy Schubert #include "lglobals.h"
21*7f2fe78bSCy Schubert 
22*7f2fe78bSCy Schubert #ifdef _DEBUG
23*7f2fe78bSCy Schubert #define new DEBUG_NEW
24*7f2fe78bSCy Schubert #undef THIS_FILE
25*7f2fe78bSCy Schubert static char THIS_FILE[] = __FILE__;
26*7f2fe78bSCy Schubert #endif
27*7f2fe78bSCy Schubert 
28*7f2fe78bSCy Schubert /////////////////////////////////////////////////////////////////////////////
29*7f2fe78bSCy Schubert // CLeashDebugWindow dialog
30*7f2fe78bSCy Schubert 
31*7f2fe78bSCy Schubert 
CLeashDebugWindow(CWnd * pParent)32*7f2fe78bSCy Schubert CLeashDebugWindow::CLeashDebugWindow(CWnd* pParent /*=NULL*/)
33*7f2fe78bSCy Schubert 	: CDialog(CLeashDebugWindow::IDD, pParent)
34*7f2fe78bSCy Schubert {
35*7f2fe78bSCy Schubert 	//{{AFX_DATA_INIT(CLeashDebugWindow)
36*7f2fe78bSCy Schubert 	//}}AFX_DATA_INIT
37*7f2fe78bSCy Schubert 
38*7f2fe78bSCy Schubert 	m_pView = NULL;
39*7f2fe78bSCy Schubert }
40*7f2fe78bSCy Schubert 
CLeashDebugWindow(CFormView * pView)41*7f2fe78bSCy Schubert CLeashDebugWindow::CLeashDebugWindow(CFormView* pView)
42*7f2fe78bSCy Schubert {
43*7f2fe78bSCy Schubert 	m_pView = pView;
44*7f2fe78bSCy Schubert }
45*7f2fe78bSCy Schubert 
DoDataExchange(CDataExchange * pDX)46*7f2fe78bSCy Schubert void CLeashDebugWindow::DoDataExchange(CDataExchange* pDX)
47*7f2fe78bSCy Schubert {
48*7f2fe78bSCy Schubert 	CDialog::DoDataExchange(pDX);
49*7f2fe78bSCy Schubert 	//{{AFX_DATA_MAP(CLeashDebugWindow)
50*7f2fe78bSCy Schubert 	DDX_Control(pDX, IDC_DEBUG_LISTBOX, m_debugListBox);
51*7f2fe78bSCy Schubert 	DDX_Control(pDX, IDC_LOG_FILE_LOCATION_TEXT, m_debugFile);
52*7f2fe78bSCy Schubert 	//}}AFX_DATA_MAP
53*7f2fe78bSCy Schubert }
54*7f2fe78bSCy Schubert 
55*7f2fe78bSCy Schubert 
BEGIN_MESSAGE_MAP(CLeashDebugWindow,CDialog)56*7f2fe78bSCy Schubert BEGIN_MESSAGE_MAP(CLeashDebugWindow, CDialog)
57*7f2fe78bSCy Schubert 	//{{AFX_MSG_MAP(CLeashDebugWindow)
58*7f2fe78bSCy Schubert 	ON_WM_SHOWWINDOW()
59*7f2fe78bSCy Schubert 	ON_BN_CLICKED(IDC_COPY_TO_CLIPBOARD, OnCopyToClipboard)
60*7f2fe78bSCy Schubert 	ON_WM_DESTROY()
61*7f2fe78bSCy Schubert 	ON_WM_CLOSE()
62*7f2fe78bSCy Schubert 	//}}AFX_MSG_MAP
63*7f2fe78bSCy Schubert END_MESSAGE_MAP()
64*7f2fe78bSCy Schubert 
65*7f2fe78bSCy Schubert /////////////////////////////////////////////////////////////////////////////
66*7f2fe78bSCy Schubert // CLeashDebugWindow message handlers
67*7f2fe78bSCy Schubert 
68*7f2fe78bSCy Schubert 
69*7f2fe78bSCy Schubert BOOL CLeashDebugWindow::Create(const LPCSTR debugFilePath)
70*7f2fe78bSCy Schubert {
71*7f2fe78bSCy Schubert 	m_debugFilePath = debugFilePath;
72*7f2fe78bSCy Schubert 	return CDialog::Create(CLeashDebugWindow::IDD);
73*7f2fe78bSCy Schubert }
74*7f2fe78bSCy Schubert 
75*7f2fe78bSCy Schubert 
OnCancel()76*7f2fe78bSCy Schubert void CLeashDebugWindow::OnCancel()
77*7f2fe78bSCy Schubert {
78*7f2fe78bSCy Schubert 	if (m_pView != NULL)
79*7f2fe78bSCy Schubert 	{
80*7f2fe78bSCy Schubert 		CWinApp* pApp;
81*7f2fe78bSCy Schubert 		pApp = AfxGetApp();
82*7f2fe78bSCy Schubert 		pApp->WriteProfileInt("Settings", "DebugWindow", FALSE_FLAG);
83*7f2fe78bSCy Schubert 		m_pView->PostMessage(WM_GOODBYE, IDCANCEL);	// modeless case
84*7f2fe78bSCy Schubert ////        pset_krb_debug(OFF);
85*7f2fe78bSCy Schubert ////	    pset_krb_ap_req_debug(OFF);
86*7f2fe78bSCy Schubert     }
87*7f2fe78bSCy Schubert 	else
88*7f2fe78bSCy Schubert 	{
89*7f2fe78bSCy Schubert 		CDialog::OnCancel(); // modal case
90*7f2fe78bSCy Schubert 	}
91*7f2fe78bSCy Schubert }
92*7f2fe78bSCy Schubert 
OnOK()93*7f2fe78bSCy Schubert void CLeashDebugWindow::OnOK()
94*7f2fe78bSCy Schubert {
95*7f2fe78bSCy Schubert 	if (m_pView != NULL)
96*7f2fe78bSCy Schubert 	{
97*7f2fe78bSCy Schubert 		// modeless case
98*7f2fe78bSCy Schubert 		UpdateData(TRUE);
99*7f2fe78bSCy Schubert 		m_pView->PostMessage(WM_GOODBYE, IDOK);
100*7f2fe78bSCy Schubert 	}
101*7f2fe78bSCy Schubert 	else
102*7f2fe78bSCy Schubert 	{
103*7f2fe78bSCy Schubert 		CDialog::OnOK(); // modal case
104*7f2fe78bSCy Schubert 	}
105*7f2fe78bSCy Schubert }
106*7f2fe78bSCy Schubert 
OnInitDialog()107*7f2fe78bSCy Schubert BOOL CLeashDebugWindow::OnInitDialog()
108*7f2fe78bSCy Schubert {
109*7f2fe78bSCy Schubert 	CDialog::OnInitDialog();
110*7f2fe78bSCy Schubert 
111*7f2fe78bSCy Schubert 	// Set Debug flags
112*7f2fe78bSCy Schubert ////	pset_krb_debug(ON); //(int)m_debugListBox.GetSafeHwnd()
113*7f2fe78bSCy Schubert ////    pset_krb_ap_req_debug(ON);
114*7f2fe78bSCy Schubert 
115*7f2fe78bSCy Schubert 	if (*m_debugFilePath != 0)
116*7f2fe78bSCy Schubert 	  SetDlgItemText(IDC_LOG_FILE_LOCATION_TEXT, m_debugFilePath);
117*7f2fe78bSCy Schubert     else
118*7f2fe78bSCy Schubert 	  SetDlgItemText(IDC_LOG_FILE_LOCATION_TEXT, "Not Available");
119*7f2fe78bSCy Schubert 
120*7f2fe78bSCy Schubert 	if (!m_debugListBox.GetCount())
121*7f2fe78bSCy Schubert 	  GetDlgItem(IDC_COPY_TO_CLIPBOARD)->EnableWindow(FALSE);
122*7f2fe78bSCy Schubert 
123*7f2fe78bSCy Schubert 	m_CopyButton = FALSE;
124*7f2fe78bSCy Schubert 
125*7f2fe78bSCy Schubert 	return TRUE;  // return TRUE unless you set the focus to a control
126*7f2fe78bSCy Schubert 	              // EXCEPTION: OCX Property Pages should return FALSE
127*7f2fe78bSCy Schubert }
128*7f2fe78bSCy Schubert 
OnShowWindow(BOOL bShow,UINT nStatus)129*7f2fe78bSCy Schubert void CLeashDebugWindow::OnShowWindow(BOOL bShow, UINT nStatus)
130*7f2fe78bSCy Schubert {
131*7f2fe78bSCy Schubert 	CDialog::OnShowWindow(bShow, nStatus);
132*7f2fe78bSCy Schubert }
133*7f2fe78bSCy Schubert 
OnCopyToClipboard()134*7f2fe78bSCy Schubert void CLeashDebugWindow::OnCopyToClipboard()
135*7f2fe78bSCy Schubert {
136*7f2fe78bSCy Schubert     if (!OpenClipboard())
137*7f2fe78bSCy Schubert 	{
138*7f2fe78bSCy Schubert         MessageBox("Unable to open Clipboard!", "Error", MB_OK);
139*7f2fe78bSCy Schubert 		return;
140*7f2fe78bSCy Schubert 	}
141*7f2fe78bSCy Schubert 
142*7f2fe78bSCy Schubert 	EmptyClipboard();
143*7f2fe78bSCy Schubert 
144*7f2fe78bSCy Schubert     int maxItems = m_debugListBox.GetCount();
145*7f2fe78bSCy Schubert 	const int MAX_MEM = maxItems * 90; // 90 chars per line seems safe like a safe bet
146*7f2fe78bSCy Schubert 
147*7f2fe78bSCy Schubert 	HGLOBAL hDebugText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, MAX_MEM);
148*7f2fe78bSCy Schubert     if (NULL != hDebugText)
149*7f2fe78bSCy Schubert     {
150*7f2fe78bSCy Schubert 		CString listboxItem;
151*7f2fe78bSCy Schubert 		LPSTR pDebugText = (LPSTR) GlobalLock(hDebugText);
152*7f2fe78bSCy Schubert 		if (!pDebugText)
153*7f2fe78bSCy Schubert 		{
154*7f2fe78bSCy Schubert 		    MessageBox("Unable to write to Clipboard!", "Error", MB_OK);
155*7f2fe78bSCy Schubert 			ASSERT(pDebugText);
156*7f2fe78bSCy Schubert 			return;
157*7f2fe78bSCy Schubert 		}
158*7f2fe78bSCy Schubert 
159*7f2fe78bSCy Schubert 		*pDebugText = 0;
160*7f2fe78bSCy Schubert 		for (int xItem = 0; xItem < maxItems; xItem++)
161*7f2fe78bSCy Schubert 		{
162*7f2fe78bSCy Schubert 			m_debugListBox.GetText(xItem, listboxItem);
163*7f2fe78bSCy Schubert 			strcat(pDebugText, listboxItem);
164*7f2fe78bSCy Schubert 			strcat(pDebugText, "\r\n");
165*7f2fe78bSCy Schubert 		}
166*7f2fe78bSCy Schubert 
167*7f2fe78bSCy Schubert 		GlobalUnlock(hDebugText);
168*7f2fe78bSCy Schubert     }
169*7f2fe78bSCy Schubert 
170*7f2fe78bSCy Schubert     if (NULL != hDebugText)
171*7f2fe78bSCy Schubert         SetClipboardData(CF_TEXT, hDebugText);
172*7f2fe78bSCy Schubert 
173*7f2fe78bSCy Schubert 	CloseClipboard();
174*7f2fe78bSCy Schubert 	MessageBox("Copy to Clipboard was Successful!\r\n Paste it in your favorite editor.",
175*7f2fe78bSCy Schubert                 "Note", MB_OK);
176*7f2fe78bSCy Schubert }
177*7f2fe78bSCy Schubert 
PreTranslateMessage(MSG * pMsg)178*7f2fe78bSCy Schubert BOOL CLeashDebugWindow::PreTranslateMessage(MSG* pMsg)
179*7f2fe78bSCy Schubert {
180*7f2fe78bSCy Schubert 	if (!m_CopyButton && m_debugListBox.GetCount())
181*7f2fe78bSCy Schubert 	{
182*7f2fe78bSCy Schubert 		m_CopyButton = TRUE;
183*7f2fe78bSCy Schubert 		GetDlgItem(IDC_COPY_TO_CLIPBOARD)->EnableWindow(TRUE);
184*7f2fe78bSCy Schubert 	}
185*7f2fe78bSCy Schubert 
186*7f2fe78bSCy Schubert 	return CDialog::PreTranslateMessage(pMsg);
187*7f2fe78bSCy Schubert }
188