Path: blob/main/crypto/krb5/src/windows/leash/LeashDebugWindow.cpp
34889 views
// **************************************************************************************1// File: LeashDebugWindow.cpp2// By: Arthur David Leather3// Created: 12/02/984// Copyright @1998 Massachusetts Institute of Technology - All rights reserved.5// Description: CPP file for LeashDebugWindow.h. Contains variables and functions6// for the Leash Debug Window7//8// History:9//10// MM/DD/YY Inits Description of Change11// 12/02/98 ADL Original12// **************************************************************************************13141516#include "stdafx.h"17#include "leash.h"18#include "LeashDebugWindow.h"19#include "lglobals.h"2021#ifdef _DEBUG22#define new DEBUG_NEW23#undef THIS_FILE24static char THIS_FILE[] = __FILE__;25#endif2627/////////////////////////////////////////////////////////////////////////////28// CLeashDebugWindow dialog293031CLeashDebugWindow::CLeashDebugWindow(CWnd* pParent /*=NULL*/)32: CDialog(CLeashDebugWindow::IDD, pParent)33{34//{{AFX_DATA_INIT(CLeashDebugWindow)35//}}AFX_DATA_INIT3637m_pView = NULL;38}3940CLeashDebugWindow::CLeashDebugWindow(CFormView* pView)41{42m_pView = pView;43}4445void CLeashDebugWindow::DoDataExchange(CDataExchange* pDX)46{47CDialog::DoDataExchange(pDX);48//{{AFX_DATA_MAP(CLeashDebugWindow)49DDX_Control(pDX, IDC_DEBUG_LISTBOX, m_debugListBox);50DDX_Control(pDX, IDC_LOG_FILE_LOCATION_TEXT, m_debugFile);51//}}AFX_DATA_MAP52}535455BEGIN_MESSAGE_MAP(CLeashDebugWindow, CDialog)56//{{AFX_MSG_MAP(CLeashDebugWindow)57ON_WM_SHOWWINDOW()58ON_BN_CLICKED(IDC_COPY_TO_CLIPBOARD, OnCopyToClipboard)59ON_WM_DESTROY()60ON_WM_CLOSE()61//}}AFX_MSG_MAP62END_MESSAGE_MAP()6364/////////////////////////////////////////////////////////////////////////////65// CLeashDebugWindow message handlers666768BOOL CLeashDebugWindow::Create(const LPCSTR debugFilePath)69{70m_debugFilePath = debugFilePath;71return CDialog::Create(CLeashDebugWindow::IDD);72}737475void CLeashDebugWindow::OnCancel()76{77if (m_pView != NULL)78{79CWinApp* pApp;80pApp = AfxGetApp();81pApp->WriteProfileInt("Settings", "DebugWindow", FALSE_FLAG);82m_pView->PostMessage(WM_GOODBYE, IDCANCEL); // modeless case83//// pset_krb_debug(OFF);84//// pset_krb_ap_req_debug(OFF);85}86else87{88CDialog::OnCancel(); // modal case89}90}9192void CLeashDebugWindow::OnOK()93{94if (m_pView != NULL)95{96// modeless case97UpdateData(TRUE);98m_pView->PostMessage(WM_GOODBYE, IDOK);99}100else101{102CDialog::OnOK(); // modal case103}104}105106BOOL CLeashDebugWindow::OnInitDialog()107{108CDialog::OnInitDialog();109110// Set Debug flags111//// pset_krb_debug(ON); //(int)m_debugListBox.GetSafeHwnd()112//// pset_krb_ap_req_debug(ON);113114if (*m_debugFilePath != 0)115SetDlgItemText(IDC_LOG_FILE_LOCATION_TEXT, m_debugFilePath);116else117SetDlgItemText(IDC_LOG_FILE_LOCATION_TEXT, "Not Available");118119if (!m_debugListBox.GetCount())120GetDlgItem(IDC_COPY_TO_CLIPBOARD)->EnableWindow(FALSE);121122m_CopyButton = FALSE;123124return TRUE; // return TRUE unless you set the focus to a control125// EXCEPTION: OCX Property Pages should return FALSE126}127128void CLeashDebugWindow::OnShowWindow(BOOL bShow, UINT nStatus)129{130CDialog::OnShowWindow(bShow, nStatus);131}132133void CLeashDebugWindow::OnCopyToClipboard()134{135if (!OpenClipboard())136{137MessageBox("Unable to open Clipboard!", "Error", MB_OK);138return;139}140141EmptyClipboard();142143int maxItems = m_debugListBox.GetCount();144const int MAX_MEM = maxItems * 90; // 90 chars per line seems safe like a safe bet145146HGLOBAL hDebugText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, MAX_MEM);147if (NULL != hDebugText)148{149CString listboxItem;150LPSTR pDebugText = (LPSTR) GlobalLock(hDebugText);151if (!pDebugText)152{153MessageBox("Unable to write to Clipboard!", "Error", MB_OK);154ASSERT(pDebugText);155return;156}157158*pDebugText = 0;159for (int xItem = 0; xItem < maxItems; xItem++)160{161m_debugListBox.GetText(xItem, listboxItem);162strcat(pDebugText, listboxItem);163strcat(pDebugText, "\r\n");164}165166GlobalUnlock(hDebugText);167}168169if (NULL != hDebugText)170SetClipboardData(CF_TEXT, hDebugText);171172CloseClipboard();173MessageBox("Copy to Clipboard was Successful!\r\n Paste it in your favorite editor.",174"Note", MB_OK);175}176177BOOL CLeashDebugWindow::PreTranslateMessage(MSG* pMsg)178{179if (!m_CopyButton && m_debugListBox.GetCount())180{181m_CopyButton = TRUE;182GetDlgItem(IDC_COPY_TO_CLIPBOARD)->EnableWindow(TRUE);183}184185return CDialog::PreTranslateMessage(pMsg);186}187188189