summaryrefslogtreecommitdiffstats
path: root/src/windows/leash/LeashDebugWindow.cpp
blob: e8c4553eea37aaed7d6520c66f129d344f4fc237 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//	**************************************************************************************
//	File:			LeashDebugWindow.cpp
//	By:				Arthur David Leather
//	Created:		12/02/98
//	Copyright		@1998 Massachusetts Institute of Technology - All rights reserved.
//	Description:	CPP file for LeashDebugWindow.h. Contains variables and functions
//					for the Leash Debug Window
//
//	History:
//
//	MM/DD/YY	Inits	Description of Change
//	12/02/98	ADL		Original
//	**************************************************************************************



#include "stdafx.h"
#include "leash.h"
#include "LeashDebugWindow.h"
#include "lglobals.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CLeashDebugWindow dialog


CLeashDebugWindow::CLeashDebugWindow(CWnd* pParent /*=NULL*/)
	: CDialog(CLeashDebugWindow::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLeashDebugWindow)
	//}}AFX_DATA_INIT

	m_pView = NULL;
}

CLeashDebugWindow::CLeashDebugWindow(CFormView* pView)
{
	m_pView = pView;
}

void CLeashDebugWindow::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLeashDebugWindow)
	DDX_Control(pDX, IDC_DEBUG_LISTBOX, m_debugListBox);
	DDX_Control(pDX, IDC_LOG_FILE_LOCATION_TEXT, m_debugFile);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLeashDebugWindow, CDialog)
	//{{AFX_MSG_MAP(CLeashDebugWindow)
	ON_WM_SHOWWINDOW()
	ON_BN_CLICKED(IDC_COPY_TO_CLIPBOARD, OnCopyToClipboard)
	ON_WM_DESTROY()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLeashDebugWindow message handlers


BOOL CLeashDebugWindow::Create(const LPCSTR debugFilePath)
{
	m_debugFilePath = debugFilePath;
	return CDialog::Create(CLeashDebugWindow::IDD);
}


void CLeashDebugWindow::OnCancel()
{
	if (m_pView != NULL)
	{
		CWinApp* pApp;
		pApp = AfxGetApp();
		pApp->WriteProfileInt("Settings", "DebugWindow", FALSE_FLAG);
		m_pView->PostMessage(WM_GOODBYE, IDCANCEL);	// modeless case
////        pset_krb_debug(OFF);
////	    pset_krb_ap_req_debug(OFF);
    }
	else
	{
		CDialog::OnCancel(); // modal case
	}
}

void CLeashDebugWindow::OnOK()
{
	if (m_pView != NULL)
	{
		// modeless case
		UpdateData(TRUE);
		m_pView->PostMessage(WM_GOODBYE, IDOK);
	}
	else
	{
		CDialog::OnOK(); // modal case
	}
}

BOOL CLeashDebugWindow::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set Debug flags
////	pset_krb_debug(ON); //(int)m_debugListBox.GetSafeHwnd()
////    pset_krb_ap_req_debug(ON);

	if (*m_debugFilePath != 0)
	  SetDlgItemText(IDC_LOG_FILE_LOCATION_TEXT, m_debugFilePath);
    else
	  SetDlgItemText(IDC_LOG_FILE_LOCATION_TEXT, "Not Available");

	if (!m_debugListBox.GetCount())
	  GetDlgItem(IDC_COPY_TO_CLIPBOARD)->EnableWindow(FALSE);

	m_CopyButton = FALSE;

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CLeashDebugWindow::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDialog::OnShowWindow(bShow, nStatus);
}

void CLeashDebugWindow::OnCopyToClipboard()
{
    if (!OpenClipboard())
	{
        MessageBox("Unable to open Clipboard!", "Error", MB_OK);
		return;
	}

	EmptyClipboard();

    int maxItems = m_debugListBox.GetCount();
	const int MAX_MEM = maxItems * 90; // 90 chars per line seems safe like a safe bet

	HGLOBAL hDebugText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, MAX_MEM);
    if (NULL != hDebugText)
    {
		CString listboxItem;
		LPSTR pDebugText = (LPSTR) GlobalLock(hDebugText);
		if (!pDebugText)
		{
		    MessageBox("Unable to write to Clipboard!", "Error", MB_OK);
			ASSERT(pDebugText);
			return;
		}

		*pDebugText = 0;
		for (int xItem = 0; xItem < maxItems; xItem++)
		{
			m_debugListBox.GetText(xItem, listboxItem);
			strcat(pDebugText, listboxItem);
			strcat(pDebugText, "\r\n");
		}

		GlobalUnlock(hDebugText);
    }

    if (NULL != hDebugText)
        SetClipboardData(CF_TEXT, hDebugText);

	CloseClipboard();
	MessageBox("Copy to Clipboard was Successful!\r\n Paste it in your favorite editor.",
                "Note", MB_OK);
}

BOOL CLeashDebugWindow::PreTranslateMessage(MSG* pMsg)
{
	if (!m_CopyButton && m_debugListBox.GetCount())
	{
		m_CopyButton = TRUE;
		GetDlgItem(IDC_COPY_TO_CLIPBOARD)->EnableWindow(TRUE);
	}

	return CDialog::PreTranslateMessage(pMsg);
}