Click here to Skip to main content
15,896,453 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.5K   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.
/* 
/***********************************************************************/

// ESBServerManager.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Resource.h"

#include "ESBServerManager.h"
#include "ESBServerComModule.h"
#include "ESBServer.h"

#include "OptionListBox.h"
#include "OptionPageStaticText.h"
#include <Renderer/MFC/ESBServerCtrlPanel.h>
#include "Stacktrace.h"

#include <initguid.h>
#include "ESBServer_i.c"
//#include "ESBServerImpl.h"

using namespace std;

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

/////////////////////////////////////////////////////////////////////////////
// ESBServerManager

BEGIN_MESSAGE_MAP(ESBServerManager, CWinApp)
	//{{AFX_MSG_MAP(ESBServerManager)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// ESBServerManager construction

ESBServerManager::ESBServerManager()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only ESBServerManager object

struct AppCreator { AppCreator() { ESBServerManager::instance(); }; };
AppCreator theApp;
SEHTranslator theTranslator;

/////////////////////////////////////////////////////////////////////////////
// ESBServerManager initialization
ESBServerManager& ESBServerManager::instance()
{
  static ESBServerManager theInstance;
  return theInstance;
}

template<class T>
struct compare1st : public binary_function<T, typename T::first_type, bool>
{
  result_type operator()(const first_argument_type &p, const second_argument_type &x) const
  { return p.first == x; }
};

ESBServerManager::ServerContainerType::iterator ESBServerManager::find(const std::string &wspace)
{
  return find_if(mWorkspaceServers.begin(), mWorkspaceServers.end(), bind2nd(compare1st<ServerContainerType::value_type>(), wspace));
}

ESBServer& ESBServerManager::getWorkspaceServer(const std::string &wspace)
{
  ServerContainerType::iterator server = find(wspace);
  if(server == mWorkspaceServers.end()) {
    throw runtime_error("no server for workspace <" + wspace + ">");
  }

  return *server->second;
}

ESBServer& ESBServerManager::newWorkspaceServer(const std::string &wspace)
{
  ServerContainerType::iterator server = find(wspace);
  if(server != mWorkspaceServers.end()) {
    throw runtime_error("server already exists for workspace <" + wspace + ">");
  }
  
  mWorkspaceServers.push_back(make_pair(wspace, smart_ptr<ESBServer>(new ESBServer(wspace))));
  mRenderer.AddPage(dynamic_cast<COptionPage*>(mWorkspaceServers.back().second->getRenderer()));
  mRenderer.SetActivePage(mRenderer.GetPageCount()-1);
  
  return *mWorkspaceServers.back().second;
}

bool ESBServerManager::removeWorkspaceServer(std::string wspace)
{
  ServerContainerType::iterator server = find(wspace);
  if(server == mWorkspaceServers.end()) {
   return false;
  }
  int active = mRenderer.GetActiveIndex();
  int index = distance(mWorkspaceServers.begin(), server);

  if(active == index) {
    mRenderer.SetActivePage(0);
  }
  mRenderer.RemovePage(index);
  mWorkspaceServers.erase(server);
  return true;
}

BOOL ESBServerManager::InitInstance()
{
	if (!ESBServerComModule::instance().InitializeATL())
		return FALSE;

  AfxEnableControlContainer();
  
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
	{
		return TRUE;
	}


	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

  ESBServerComModule::instance().UpdateRegistryFromResource(IDR_ESBSERVER_MANAGER, TRUE);
	ESBServerComModule::instance().RegisterServer(TRUE);

	try {

    COptionListBox listbox;
	  mRenderer.SetListControl(&listbox);
    
    //thats a real hack here !!! we are going to remove the dummy page 
    //in TrayableOptionSheet::OnInitDialog()
     ESBServerControlPanel dummy(NULL);
    mRenderer.AddPage(&dummy);

    m_pMainWnd = &mRenderer;
		mRenderer.DoModal();

	} catch(std::exception &e) {
		message_box(string("ESBServerManager::InitInstance():") + e.what());
	
	} catch(...) {
		message_box("ESBServerManager::InitInstance(): unknown exception");
	}

  ESBServerComModule::instance().UpdateRegistryFromResource(IDR_ESBSERVER_MANAGER, FALSE);
  ESBServerComModule::instance().UnregisterServer(TRUE); //TRUE means typelib is unreg'd

  // Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return FALSE;
}

	
int ESBServerManager::ExitInstance()
{
	ESBServerComModule::instance().UninitializeATL();
	return CWinApp::ExitInstance();
}

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