Click here to Skip to main content
15,891,567 members
Articles / Desktop Programming / MFC

Be Sweet - a set of visual source code browsers

Rate me:
Please Sign up or sign in to vote.
4.85/5 (35 votes)
1 Jul 20038 min read 184.1K   4.9K   122  
A set of source code and project browsers to compliment Visual Studio.
/**
/*   Copyright (c) 2003by  Marco Welti
/*
/*   This document is  bound by the  QT Public License
/*   (http://www.trolltech.com/licenses/qpl.html).
/*   See License.txt for more information.
/*
/*
/*
/*   ALL RIGHTS RESERVED.  
/* 
/*   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
/*   OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
/*   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
/*   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
/*   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
/*   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
/*   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
/*   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
/*   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
/*   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
/*   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* 
/***********************************************************************/

// ESBServerCtrlPanel.cpp : implementation file
//

#include "stdafx.h"
#include "resource.h"


#include "ESBServerCtrlPanel.h"
#include "ESBServer.h"

#include "Properties.h"
#include "Workspace.h"

#include "StringTokenizer.h"

#include <algorithm>
#include <sstream>
#include <fstream>
#include <map>
#include <set>
#include <memory>


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

using namespace std;



/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	public:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// ESBServerControlPanel dialog

string make_name(ESBServer *c)
{
  return c ? file_name_is::nameof(c->getName()) : string("???");
}

ESBServerControlPanel::ESBServerControlPanel(ESBServer *c, CWnd* pParent /*=NULL*/)
: ESBParent(ESBServerControlPanel::IDD, make_name(c).c_str()), mController(c)
{
	//{{AFX_DATA_INIT(ESBServerControlPanel)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDI_ESBSERVER_MANAGER);
  mName = make_name(c);
}

ESBServerControlPanel::~ESBServerControlPanel()
{
//  if(!getController()) {
//    message_box("destroying with null controller");
//  } else {
//    message_box("destroying controller" + getController()->getName());
//    
//  }
}

void ESBServerControlPanel::DoDataExchange(CDataExchange* pDX)
{
	ESBParent::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(ESBServerControlPanel)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(ESBServerControlPanel, ESBParent)
	//{{AFX_MSG_MAP(ESBServerControlPanel)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_TYPE_BROWSER, onTypeBrowser)
	ON_BN_CLICKED(IDC_OUTLINE_BROWSER, onOutlineBrowser)
	ON_COMMAND(ID_ESBSERVER_REPARSE, onReparseWorkspace)
	ON_BN_CLICKED(IDC_WORKSPACE, onWorkspaceBrowser)
	ON_COMMAND(ID_ESBSERVER_METHODBROWSER, onMethodBrowser)
	ON_BN_CLICKED(IDC_HIERARCHY_BROWSER, onHierarchyBrowser)
	ON_BN_CLICKED(IDC_PACKAGES_BROWSER, onPackagesBrowser)
	ON_COMMAND(ID_ESBSERVER_TYPEBROWSER, onTypeBrowser)
	ON_COMMAND(ID_ESBSERVER_WORKSPACEBROWSER, onWorkspaceBrowser)
	ON_BN_CLICKED(IDC_METHOD_BROWSER, onMethodBrowser)
  ON_BN_CLICKED(IDOK, onExit)
	//}}AFX_MSG_MAP

  ON_MESSAGE(WM_SHOW_FILEOUTLINE, onShowFileOutline)
  ON_MESSAGE(WM_OPEN_WORKSPACE, onOpenWorkspace)
  ON_MESSAGE(WM_REPARSE_FILE, onReparseFile)
  ON_MESSAGE(WM_SHOW_BROWSER, onShowBrowser)
 
//  ON_MESSAGE(WM_SYSTRAY_NOTIFY, onSystemTrayNotification)
//	ON_COMMAND(ID_ESBSERVER_MAXIMIZE, onMaximize)
//	ON_COMMAND(ID_ESBSERVER_MINIMIZE, onMinimize)
//	ON_COMMAND(ID_ESBSERVER_EXIT, onExit)
//	ON_BN_CLICKED(IDC_MINIMIZE, onMinimize)


END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// ESBServerControlPanel message handlers

BOOL ESBServerControlPanel::OnInitDialog()
{
	ESBParent::OnInitDialog();
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog	
  CString name;
  GetCaption(name);
  SetDlgItemText(IDC_MOUSE_POS, name);
	return TRUE;
}

void ESBServerControlPanel::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void ESBServerControlPanel::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR ESBServerControlPanel::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}



void ESBServerControlPanel::onTypeBrowser() 
{
 	const static string function = "ESBServerControlPanel::onTypeBrowser(): ";
  try {
    message_box(getController()->getName());
    getController()->showBrowser("types", "");

  } catch(std::exception &e) {
    message_box(function + e.what());

  } catch(...) {
    message_box(function + "unknown exception occured");
  }
}

void ESBServerControlPanel::onWorkspaceBrowser() 
{
  const static string function = "ESBServerControlPanel::onWorkspaceBrowser";
  try {
    getController()->showBrowser("workspace", "");
    
  } catch(std::exception &e) {
    message_box(function + e.what());
    
  } catch(...) {
    message_box(function + "unknown exception occured");
  }
}

void ESBServerControlPanel::onMethodBrowser() 
{
  const static string function = "ESBServerControlPanel::onMethodBrowser";
  try {
    getController()->showBrowser("methods", "");
    
  } catch(std::exception &e) {
    message_box(function + e.what());
    
  } catch(...) {
    message_box(function + "unknown exception occured");
  }
}

void ESBServerControlPanel::onOutlineBrowser() 
{
 	const static string function = "ESBServerControlPanel::onOutlineBrowser(): ";
  try {
	  getController()->showBrowser("outline", "");

  } catch(std::exception &e) {
    message_box(function + e.what());

  } catch(...) {
    message_box(function + "unknown exception occured");
  }
}

#include "HierarchyBrowser.h"
#include "HierarchyLoaderSimulator.h"
void ESBServerControlPanel::onHierarchyBrowser() 
{
 	const static string function = "ESBServerControlPanel::onHierarchyBrowser(): ";
  try {
    /*Simulators::HierarchyLoader hierarchyLoader;
    smart_ptr<Inheritable> hierarchy(new Class("TestClass", ePublic, TagLocation()));
    hierarchy->setExtendors(hierarchyLoader.loadSubtypeHierarchy(*hierarchy));
    hierarchy->setParents(hierarchyLoader.loadSupertypeHierarchy(*hierarchy));
  
    HierarchyBrowser hierarchyBrowser;
    hierarchyBrowser.setModel(hierarchy);
    hierarchyBrowser.show(true);*/
    getController()->showBrowser("hierarchy", "");

  } catch(std::exception &e) {
    message_box(function + e.what());

  } catch(...) {
    message_box(function + "unknown exception occured");
  }

}

#include "PackageBrowserRenderer.h"
void ESBServerControlPanel::onPackagesBrowser() 
{
 	const static string function = "ESBServerControlPanel::onPackagesBrowser(): ";
  try {
    PackageBrowserRenderer dlg;
    dlg.DoModal();

  } catch(std::exception &e) {
    message_box(function + e.what());

  } catch(...) {
    message_box(function + "unknown exception occured");
  }
}

LRESULT ESBServerControlPanel::onShowFileOutline(WPARAM wParam, LPARAM lParam)
{
 	const static string function = "ESBServerControlPanel::onShowFileOutline(): ";
  try {
    auto_ptr<string> file((string*)lParam);
    getController()->showFileOutline(*file);
    return S_OK;

  } catch(std::exception &e) {
    message_box(function + e.what());

  } catch(...) {
    message_box(function + "unknown exception occured");
  }
  return E_FAIL;
}

LRESULT ESBServerControlPanel::onReparseFile(WPARAM wParam, LPARAM lParam)
{
 	const static string function = "ESBServerControlPanel::onReparseFile(): ";
  try {
    auto_ptr<string> file((string*)lParam);
    getController()->reparseFile(*file);
    return S_OK;

  } catch(std::exception &e) {
    message_box(function + e.what());

  } catch(...) {
    message_box(function + "unknown exception occured");
  }
  return E_FAIL;
}

LRESULT ESBServerControlPanel::onOpenWorkspace(WPARAM wParam, LPARAM lParam)
{
 	const static string function = "ESBServerControlPanel::onOpenWorkspace(): ";
  try {
    getController()->openWorkspace(*auto_ptr<Workspace>((Workspace*)lParam));
    return S_OK;

  } catch(std::exception &e) {
    message_box(function + e.what());

  } catch(...) {
    message_box(function + "unknown exception occured");
  }
  return E_FAIL;
}

LRESULT ESBServerControlPanel::onShowBrowser(WPARAM wParam, LPARAM lParam)
{
 	const static string function = "ESBServerControlPanel::onShowBrowser(): ";
  try {
    auto_ptr<pair<string, string> > browser((pair<string, string>*)lParam);
    getController()->showBrowser(browser->first, browser->second);
    return S_OK;

  } catch(std::exception &e) {
    message_box(function + e.what());

  } catch(...) {
    message_box(function + "unknown exception occured");
  }
  return E_FAIL;
}

void ESBServerControlPanel::mouseAt(CPoint &point)
{
	std::stringstream ss;
	ss << point.x << ":" << point.y;
	SetDlgItemText(IDC_MOUSE_POS, ss.str().c_str());
}

void ESBServerControlPanel::onReparseWorkspace() 
{
  const static string function = "ESBServerControlPanel::onReparseWorkspace";
  try {
    getController()->reparseWorkspace();

  } catch(std::exception &e) {
    message_box(function + e.what());

  } catch(...) {
    message_box(function + "unknown exception occured");
  }
}


void ESBServerControlPanel::onExit() 
{
  const static string function = "ESBServerControlPanel::onExit(): ";
  try {
    string name = getController()->getName();
    AfxGetApp()->GetMainWnd()->PostMessage(WM_CLOSE_WORKSPACE, 0, reinterpret_cast<LPARAM>(new string(name)));
    
  } catch(std::exception &e) {
    message_box(function + e.what());
    
  } catch(...) {
    message_box(function + "unknown exception occured");
  }
}

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
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions