Click here to Skip to main content
15,896,153 members
Articles / Desktop Programming / MFC

WWhizInterface: Enhancements to the Visual C++ Automation Interface

Rate me:
Please Sign up or sign in to vote.
4.50/5 (5 votes)
28 Jul 2001 150K   2.6K   47  
A C++ interface with a number of Visual C++ automation enhancements, allowing for more robust add-in programming.
///////////////////////////////////////////////////////////////////////////////
// $Workfile: TemplateFileListDialog.cpp $
// $Archive: /WorkspaceWhiz/Src/WorkspaceWhiz/TemplateFileListDialog.cpp $
// $Date:: 1/03/01 12:13a  $ $Revision:: 18   $ $Author: Jjensen $
///////////////////////////////////////////////////////////////////////////////
// This source file is part of the Workspace Whiz! source distribution and
// is Copyright 1997-2001 by Joshua C. Jensen.  (http://workspacewhiz.com/)
//
// The code presented in this file may be freely used and modified for all
// non-commercial and commercial purposes so long as due credit is given and
// this header is left intact.
///////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "WorkspaceWhiz.h"
#include "TemplateFileListDialog.h"
#include "WorkspaceCommands.h"
#include "History.h"
#include "AboutDialog.h"
#include "PreferencesDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTemplateFileListDialog dialog

bool CTemplateFileListDialog::s_autoCloseParent;		// A hack to close the parent.

CTemplateFileListDialog::CTemplateFileListDialog(CWnd* pParent /*=NULL*/)
	: TEMPLATE_FILE_LIST_DIALOG(CTemplateFileListDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTemplateFileListDialog)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	s_autoCloseParent = false;
}


void CTemplateFileListDialog::DoDataExchange(CDataExchange* pDX)
{
	TEMPLATE_FILE_LIST_DIALOG::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTemplateFileListDialog)
	DDX_Control(pDX, IDOK, m_butOK);
	DDX_Control(pDX, IDCANCEL, m_butCancel);
	DDX_Control(pDX, IDC_TFL_REMOVE, m_butRemove);
	DDX_Control(pDX, IDC_TFL_EDIT, m_butEdit);
	DDX_Control(pDX, IDC_TFL_ADD, m_butAdd);
	DDX_Control(pDX, IDC_TFL_LIST, m_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTemplateFileListDialog, TEMPLATE_FILE_LIST_DIALOG)
	//{{AFX_MSG_MAP(CTemplateFileListDialog)
	ON_BN_CLICKED(IDC_TFL_ADD, OnTflAdd)
	ON_BN_CLICKED(IDC_TFL_REMOVE, OnTflRemove)
	ON_BN_CLICKED(IDC_TFL_EDIT, OnTflEdit)
	ON_NOTIFY(NM_DBLCLK, IDC_TFL_LIST, OnDblclkTflList)
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_COM_ABOUT, OnComAbout)
	ON_BN_CLICKED(IDC_COM_PREFERENCES, OnComPreferences)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DYNAMIC_MAP(CTemplateFileListDialog, cdxCDynamicDialog)
	DYNAMIC_MAP_ENTRY(IDOK,					mdRepos,	mdNone)
	DYNAMIC_MAP_ENTRY(IDCANCEL,				mdRepos,	mdNone)
	DYNAMIC_MAP_ENTRY(IDHELP,				mdRepos,	mdNone)
	DYNAMIC_MAP_ENTRY(IDC_COM_ABOUT,		mdRepos,	mdNone)
	DYNAMIC_MAP_ENTRY(IDC_COM_PREFERENCES,	mdRepos,	mdNone)

	DYNAMIC_MAP_ENTRY(IDC_TFL_ADD,			mdRepos,	mdNone)
	DYNAMIC_MAP_ENTRY(IDC_TFL_REMOVE,		mdRepos,	mdNone)
	DYNAMIC_MAP_ENTRY(IDC_TFL_EDIT,			mdRepos,	mdNone)
	
	DYNAMIC_MAP_ENTRY(IDC_TFL_LIST,			mdResize,	mdResize)
END_DYNAMIC_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTemplateFileListDialog message handlers

void CTemplateFileListDialog::OnTflAdd() 
{
	CFileDialog fdlg(TRUE, "WWTpl", "*.WWTpl", OFN_HIDEREADONLY,
		"Code Template Files (*.WWTpl)|*.WWTpl||", NULL);
	fdlg.m_ofn.lpstrTitle = "Find Template Files";
	if(fdlg.DoModal() == IDCANCEL)  
		return;
	if (g_wwhizTemplateManager->Add(fdlg.GetPathName()) != -1)
	{
		Refresh();
	}
}

void CTemplateFileListDialog::OnTflRemove() 
{
	// Remove all selected items.
    int i = m_list.GetNextItem( -1, LVNI_ALL | LVNI_SELECTED);
    while( i != -1 )
    {
		g_wwhizTemplateManager->Remove(m_list.GetItemData(i));
        i = m_list.GetNextItem( i, LVNI_ALL | LVNI_SELECTED);
    }

	Refresh();
}

void CTemplateFileListDialog::OnTflEdit() 
{
	if (m_list.GetItemCount() == 0  ||  m_list.GetSelectedCount() == 0)
	{
		AfxMessageBox("Please select a template file selected to edit first.\n");
	}

	CString filename;
	int curSel = m_list.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
	if (curSel == -1)
		return;  //??

	int whichItem = m_list.GetItemData(curSel);
	WWhizTemplateGroup* file = g_wwhizTemplateManager->GetTemplateGroup(whichItem);

	History::PreAdd();
	
	// Open the document.
	ObjModelHelper objModel;
	if (objModel.OpenDocument(file->GetFilename(), "Auto"))
	{
		History::Add();

		objModel.PutLanguage(DS_CPP);
	}

	s_autoCloseParent = true;

	OnOK();
}

BOOL CTemplateFileListDialog::OnInitDialog() 
{
	TEMPLATE_FILE_LIST_DIALOG::OnInitDialog();
	
	// Set the icon for this dialog.
	HICON hIcon = AfxGetApp()->LoadIcon(IDI_WWHIZ);
	SetIcon(hIcon, TRUE);			// Set big icon
	SetIcon(hIcon, FALSE);		// Set small icon

	// Reload stuff from registry.
	g_wwhizTemplateManager->LoadRegistry();
	
	// Set the column names of the list control.
	CRect rect;
	DWORD dwStyle;
	dwStyle = m_list.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE, 0 ,0);
	dwStyle |= LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES;
	m_list.SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
	m_list.GetClientRect(&rect);
	m_list.InsertColumn(0, "Category", LVCFMT_LEFT, 125, 0);
	m_list.InsertColumn(1, "Path", LVCFMT_LEFT, rect.Width() - 125, 1);
	
	g_wwhizTemplateManager->Refresh();
	Refresh();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CTemplateFileListDialog::Refresh() 
{
	// Turn off any redraw while we fill the list control.
	m_list.SetRedraw(FALSE);
	
	// Remove all items from the list.
	m_list.DeleteAllItems();

	for (int i = 0; i < g_wwhizTemplateManager->GetCount(); i++)
	{
		WWhizTemplateGroup* file = g_wwhizTemplateManager->GetTemplateGroup(i);
		int index = m_list.InsertItem(LVIF_TEXT | LVIF_PARAM, i, file->GetName(), 0, 0, 0, i);
		m_list.SetItem(index, 1, LVIF_TEXT, file->GetFilename(), 0, 0, 0, 0);
		m_list.SetCheck(index, file->IsActive());
	}

	m_list.SetRedraw(TRUE);
}



void CTemplateFileListDialog::OnOK() 
{
	// Set all active states.
	for (int i = 0; i < g_wwhizTemplateManager->GetCount(); i++)
	{
		UINT whichItem = m_list.GetItemData(i);
		WWhizTemplateGroup* file = g_wwhizTemplateManager->GetTemplateGroup(whichItem);
		file->SetActive(m_list.GetCheck(i) != FALSE);
	}

	// Save changes to registry.
	g_wwhizTemplateManager->SaveRegistry();

	TEMPLATE_FILE_LIST_DIALOG::OnOK();
}

void CTemplateFileListDialog::OnDblclkTflList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	OnTflEdit();
	
	*pResult = 0;
}

void CTemplateFileListDialog::OnSize(UINT nType, int cx, int cy) 
{
	TEMPLATE_FILE_LIST_DIALOG::OnSize(nType, cx, cy);
	
	if (::IsWindow(m_list.m_hWnd))
	{
		CRect rect;
		m_list.GetClientRect(rect);
		m_list.SetColumnWidth(0, (int)(rect.Width() * 0.33));
		m_list.SetColumnWidth(1, (int)(rect.Width() * 0.67));
	}
}

void CTemplateFileListDialog::OnComAbout() 
{
	CAboutDialog dlg;
	dlg.DoModal();
}

void CTemplateFileListDialog::OnComPreferences() 
{
	CPreferencesDialog dlg;
	if (dlg.DoModal() == IDOK)
	{
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Joshua Jensen is a gamer at heart and as such, creates games for a living. He has the distinct pleasure of creating titles exclusively for the Xbox.

In his spare time, he maintains a Visual C++ add-in called Workspace Whiz! Find it at http://workspacewhiz.com/.

Comments and Discussions