[GME-commit] GMESRC/Paradigms/MetaGME/BonExtension8/Gui InPlaceEdit.cpp, NONE, 1.1 InPlaceEdit.h, NONE, 1.1 InPlaceList.cpp, NONE, 1.1 InPlaceList.h, NONE, 1.1 OptionsDlg.cpp, NONE, 1.1 OptionsDlg.h, NONE, 1.1 SelConf.cpp, NONE, 1.1 SelConf.h, NONE, 1.1 Table.cpp, NONE, 1.1 Table.h, NONE, 1.1

Log messages of CVS commits gme-commit at list.isis.vanderbilt.edu
Fri Mar 14 16:13:51 CDT 2008


Update of /project/gme-repository/GMESRC/Paradigms/MetaGME/BonExtension8/Gui
In directory escher:/tmp/cvs-serv28536/Gui

Added Files:
	InPlaceEdit.cpp InPlaceEdit.h InPlaceList.cpp InPlaceList.h 
	OptionsDlg.cpp OptionsDlg.h SelConf.cpp SelConf.h Table.cpp 
	Table.h 
Log Message:
Rawcomponent implementation of BonXtender.


CVS User: Zoltan Molnar, ISIS (zolmol)

--- NEW FILE: SelConf.cpp ---
// SelConf.cpp : implementation file
//

#include "stdafx.h"
#include "SelConf.h"
#include "Any.h"
#include "FCO.h"
#include ".\selconf.h"

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

/////////////////////////////////////////////////////////////////////////////
// SelConf dialog
/*static*/ int SelConf::m_lastId = 0;
/*static*/ int SelConf::m_sortOrder = 1;

SelConf::SelConf( unsigned int no_of_configs, CWnd* pParent /*=NULL*/)
	: CDialog(SelConf::IDD, pParent),
		m_numberOfConfigs( no_of_configs)
{
	//{{AFX_DATA_INIT(SelConf)
	//}}AFX_DATA_INIT

}

SelConf::~SelConf()
{
	POSITION pos = m_entries.GetHeadPosition();
	while (pos) {
		delete m_entries.GetNext(pos);
	}
	m_entries.RemoveAll(); 
}

void SelConf::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(SelConf)
	DDX_Control(pDX, IDC_COMBO1, m_config);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(SelConf, CDialog)
	//{{AFX_MSG_MAP(SelConf)
	ON_CBN_EDITUPDATE(IDC_COMBO1, OnEditupdateCombo1)
	ON_CBN_CLOSEUP(IDC_COMBO1, OnCloseupCombo1)
	ON_BN_CLICKED(IDC_DESELECTALLBTN, OnBnClickedDeselectallbtn)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_SELECTALLBTN, OnBnClickedSelectallbtn)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// SelConf message handlers

void SelConf::addConfigs( std::vector< std::string >& configs)
{
	ASSERT( configs.size() == m_numberOfConfigs);
	m_configStrings = configs;
}

int SelConf::findAmongConfigs( std::string& config_name)
{
	for( unsigned int i = 0; i < m_configStrings.size(); ++i)
	{
		if ( m_configStrings[i] == config_name)
			return (int) i;
	}
	return -1;
}


int SelConf::addEntry( const CString& role, char kind, int clique, bool in, const CString& repr, const void * ptr)
{
	entry *f = new entry;
	f->id = m_lastId;
	f->s = role;
	f->kind = kind;
	f->cliqueId = clique;
	f->val = in;
	f->resp = repr;
	f->ptr = ptr;

	m_entries.AddTail( f);
	return m_lastId++;
}

bool SelConf::getEntry( int row, CString& role, bool & in, CString& repr, const void * &ptr)
{
	bool retval = false;

	POSITION pos = m_entries.GetHeadPosition();
	while (pos) {
		entry	*e = m_entries.GetNext(pos);
		if (e->id == row) {
			role = e->s;
			in = e->val;
			ptr = e->ptr;
			repr = e->resp;
			retval = true;
		}
	}
	return retval;

}

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

	CRect loc;
	this->GetClientRect(&loc);
	loc.DeflateRect(15, 50, 15, 50);

	m_table.Create(WS_CHILD|WS_VISIBLE|WS_BORDER/*|LVS_EDITLABELS*/|LVS_REPORT|LVS_SINGLESEL, loc, this, 1);
	m_table.m_parent = this;

	fillUpTable();

	unsigned int len = m_configStrings.size();
	for( unsigned int i = 0; i < len; ++i)
	{
		m_config.AddString( m_configStrings[i].c_str());
		m_config.SetItemData( i, i);
	}

	int nCount = m_config.GetCount();
	if (nCount > 0)
	{
    //m_config.SetCurSel(default_item_data);
		m_config.SelectString( -1, "Default");
		m_currSelConfigStr = "Default";
	}

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

void SelConf::OnOK() 
{
	// TODO: Add extra validation here
	if ( m_currSelConfigStr.empty() || m_currSelConfigStr.find_first_not_of(' ') == std::string::npos )
	{
		AfxMessageBox( "Please select a valid configuration name");
		return;
	}

	getDataFromTable();
	saveUserPref( false);

	/*CString temp_text;
	m_config.GetWindowText( temp_text);
	m_currSelConfigStr = (LPCTSTR) temp_text;

	int sel = m_config.GetCurSel();
	if ( sel != CB_ERR && sel < m_config.GetCount() && sel > 0)
		m_currSelConfigStr = m_configStrings[sel];*/

	CDialog::OnOK();
}

void SelConf::OnCloseupCombo1() 
{
	// TODO: Add your control notification handler code here
	int sel = m_config.GetCurSel();
	if ( sel != CB_ERR && sel < m_config.GetCount() && sel >= 0)
	{
		if( m_currSelConfigStr == m_configStrings[sel]) // upon first dropdown the else branch is selected anyway
			return;
		else
		{
			getDataFromTable();
			saveUserPref( true); // save user pref with the old config name
			m_currSelConfigStr = m_configStrings[sel]; // set the new config name
			refreshTable();
		}
	}
}

void SelConf::OnEditupdateCombo1() 
{
	// TODO: Add your control notification handler code here
	CString temp_text;
	m_config.GetWindowText( temp_text);
	m_currSelConfigStr = (LPCTSTR) temp_text;	
}


void SelConf::refreshTable()
{
	std::string regPath = "/Configs/" + m_currSelConfigStr, regVal;
	int k = findAmongConfigs (m_currSelConfigStr);
	if ( k != -1)
	{
		m_table.DeleteAllItems();

		POSITION pos = m_entries.GetHeadPosition();
		while (pos)
		{
			entry	*e = m_entries.GetNext(pos);
			Any * any_ptr = const_cast<Any *>( static_cast<const Any *>(e->ptr));
			if ( any_ptr)
			{
				regVal = Util::gvbp( any_ptr->getMyRegistry(), regPath);
					if ( regVal == "false")
						e->val = false;
					else
						e->val = true;//m_table.addRow(e->id, e->s, e->cliqueId, true);
			}
			/*else
				m_table.addRow(e->id, e->s, -1, true);*/
		}
		fillUpTable();
		UpdateWindow();
	}
}

/*
Called with true usually
			 with false finally (OnOk)
*/
void SelConf::saveUserPref( bool check)
{
	int k = findAmongConfigs( m_currSelConfigStr);
	if ( check && k == -1) return;
	
	std::string regVal, regPath = "Configs/" + m_currSelConfigStr;
	POSITION pos = m_entries.GetHeadPosition();
	while (pos)
	{
		entry	*e = m_entries.GetNext(pos);
		Any * any_ptr = const_cast<Any *>( static_cast<const Any *>(e->ptr));
		if ( any_ptr)
		{
			if ( !check) // if called from OnOk
			{
				any_ptr->toBeEx( e->val);
				FCO * fco_ptr = dynamic_cast<FCO*>( any_ptr);
				if( any_ptr->isFCO() && fco_ptr)
				{
					// stores into the ExtedAnc var the selected responsible
					fco_ptr->setExtedAnc( fco_ptr->findRspPtr( (LPCTSTR) e->resp));
				}
			}
			if (e->val)	regVal = "true"; else regVal = "false";
			Util::svbp( any_ptr->getMyRegistry(), regPath, regVal);
			Util::svbp( any_ptr->getMyRegistry(), regPath + "/Resp", (LPCTSTR) e->resp);
		}
	}
}

void SelConf::fillUpTable()
{
	POSITION pos = m_entries.GetHeadPosition();
	while (pos) {
		entry	*e = m_entries.GetNext(pos);
		m_table.addRow(e->id, e->s, e->kind, e->cliqueId, e->val, e->resp);
	}
}

void SelConf::getDataFromTable()
{
	POSITION pos = m_entries.GetHeadPosition();
	while (pos) {
		entry	*e = m_entries.GetNext(pos);
		m_table.getRow( e->id, e->s, e->val, e->resp);
	}
}

// appends those class names to list which are samekind extended ancestors
// of the fco identified by 'changed'
bool SelConf::addPossibleAncestors( CStringList& list, int changed)
{
	POSITION pos = m_entries.GetHeadPosition();
	entry	*e = 0;
	while (pos) {
		e = m_entries.GetNext(pos);
		if ( e->id == changed)
			break;
	}

	if ( e && e->id == changed)
	{
		Any * any_ptr = const_cast<Any *>( static_cast<const Any *>(e->ptr));
		if ( any_ptr && any_ptr->isFCO())
		{
			FCO * fco_ptr = dynamic_cast<FCO*>( any_ptr);
			if( fco_ptr)
			{
				std::vector<FCO *> ancestor;
				bool found_same_kind_extd_anc = false; // notifies that extended ancestors of the same kind have been found
				fco_ptr->getIntAncestors( ancestor);
				
				for( unsigned int i = 0; i < ancestor.size(); ++i)
				{
					// check whether ancestor[i] is to be extended
					POSITION pos_d = m_entries.GetHeadPosition();
					entry	*e_d = 0;
					while (pos_d) {
						e_d = m_entries.GetNext(pos_d);
						if ( e_d->ptr == ancestor[i])
						{
							CString role, repr; bool extended = false;
							if( m_table.getRow( e_d->id, role, extended, repr))
							{
								if( extended                                          // it is extended
								  && fco_ptr->getMyKind() == ancestor[i]->getMyKind() // it is the same kind that fco_ptr
								  )
								{
									list.AddTail( ancestor[i]->getLStrictName().c_str());    // put into the option
									found_same_kind_extd_anc = true;
								}
							}
							break; // end the cycle
						}
					}
				}
				
				return found_same_kind_extd_anc; // will notify the user if additional options have been added at all
			}
		}
	}
	return false;
}

// which: true if the user selected NO, false if the user selected YES
void SelConf::getDescsAncs( bool which, int changed, std::vector< int > & res)
{
	POSITION pos = m_entries.GetHeadPosition();
	entry	*e = 0;
	while (pos) {
		e = m_entries.GetNext(pos);
		if ( e->id == changed)
			break;
	}

	if ( e && e->id == changed)
	{
		Any * any_ptr = const_cast<Any *>( static_cast<const Any *>(e->ptr));
		if ( any_ptr && any_ptr->isFCO())
		{
			FCO * fco_ptr = dynamic_cast<FCO*>( any_ptr);
			if( fco_ptr)
			{
				std::vector<FCO *> family;
				if ( which) // means 'no' is selected
				{
					/*if ( fco_ptr->getMyKind() == Any::FCO_REP || !fco_ptr->hasParentOfSameKind()) //if fco_rep is selected for 'no' means no other elements in the hierarchy needed to be extended or if has _not_ the same kind of ancestor means doesn't inherit from a same kind object (inherits from FCO)
						fco_ptr->getAllInMyHierarchy( family);
					else*/
						family = fco_ptr->getAllDescendants();
				}
				else // means 'yes'
				{
					family = fco_ptr->getAllAncestors(); // since fco_rep may exist among the ancestors and that will become yes, we have to make yes all fcoreps and the first nonfcorep leaves
					//fco_ptr->getRootDescsUntilNonFcoRep( family); // get more dependants
				}

				for( unsigned int i = 0; i < family.size(); ++i)
				{
					FCO * dep_ptr = family[i]; // dependant
					POSITION pos_d = m_entries.GetHeadPosition();
					entry	*e_d = 0;
					while (pos_d) {
						e_d = m_entries.GetNext(pos_d);
						if ( e_d->ptr == dep_ptr)
						{
							res.push_back( e_d->id);
							break;
						}
					}
				}
			}
		}
	}
}

/*static*/ bool SelConf::getEntries( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort, entry& e, entry& f)
{
	SelConf * myDlg = reinterpret_cast<SelConf *>((void*)lParamSort);
	bool b1 = myDlg->getEntry( lParam1, e.s, e.val, e.resp, e.ptr); 
	bool b2 = myDlg->getEntry( lParam2, f.s, f.val, f.resp, f.ptr); 
	
	return b1 && b2;
}

/*static*/ int CALLBACK SelConf::MyNameCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	entry e, f;
	if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;

	return m_sortOrder * e.s.Compare( f.s);
}

/*static*/ int CALLBACK SelConf::MyKindCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	entry e, f;
	if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;

	Any * any_ptr1 = reinterpret_cast<Any *>((void*)e.ptr);
	Any * any_ptr2 = reinterpret_cast<Any *>((void*)f.ptr);

	std::string ks1 = any_ptr1->getMyKindStr();
	std::string ks2 = any_ptr2->getMyKindStr();

	return m_sortOrder * ks1.compare( ks2);
}

/*static*/ int CALLBACK SelConf::MyExtdCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	entry e, f;
	if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;

	if( e.val == f.val) return 0;
	else return m_sortOrder * (int)e.val < m_sortOrder * (int)f.val;
}

/*static*/ int CALLBACK SelConf::MyReprCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	entry e, f;
	if( !getEntries( lParam1, lParam2, lParamSort, e, f)) return 0;

	return m_sortOrder * e.resp.Compare( f.resp);
}


void SelConf::selectAll( bool pVal)
{
	m_table.DeleteAllItems();

	POSITION pos = m_entries.GetHeadPosition();
	while( pos) {
		entry *e = m_entries.GetNext(pos);
		e->val = pVal;
		e->resp = "";
	}
	fillUpTable();
}

void SelConf::OnBnClickedDeselectallbtn()
{
	selectAll( false);
}

void SelConf::OnBnClickedSelectallbtn()
{
	selectAll( true);
}

--- NEW FILE: Table.h ---
#if !defined(AFX_ASPECTSPECTBL_H__62A172B9_B4D4_497D_B466_B7BB7BF98B7F__INCLUDED_)
#define AFX_ASPECTSPECTBL_H__62A172B9_B4D4_497D_B466_B7BB7BF98B7F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <AFXCMN.H>

// MyListCtrl.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CMyListCtrl window

class SelConf;

class CTable : public CListCtrl
{
// Construction
public:
	CTable();

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CTable)
	//}}AFX_VIRTUAL
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	virtual BOOL PreCreateWindow(CREATESTRUCT &cs);

// Implementation
public:
	SelConf * m_parent;

	void addRow(int rowID, CString& role, char kind, int clique, bool isPrimary, CString& repr);
	bool getRow(int rowID, CString& role, bool& extend, CString& repr);
	virtual ~CTable();
	int HitTestEx(CPoint &point, int *col) const;
	CEdit* EditSubLabel( int nItem, int nCol );
	CComboBox* ShowInPlaceList( int nItem, int nCol, CStringList &lstItems, int nSel );

protected:
	static LPCTSTR MakeShortString(CDC* pDC, LPCTSTR lpszLong, int nColumnLen, int nOffset);
	int m_cxClient;

	// Generated message map functions
protected:
	//{{AFX_MSG(CTable)
	afx_msg void OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnPaint();
	afx_msg void OnSort(NMHDR* pNMHDR, LRESULT* pResult);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ASPECTSPECTBL_H__62A172B9_B4D4_497D_B466_B7BB7BF98B7F__INCLUDED_)

--- NEW FILE: OptionsDlg.h ---
#if !defined(AFX_OPTIONSDLG_H__0A217994_9D2A_429E_B244_4CD2D8F74A26__INCLUDED_)
#define AFX_OPTIONSDLG_H__0A217994_9D2A_429E_B244_4CD2D8F74A26__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// OptionsDlg.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// OptionsDlg dialog
#include "resource.h"

class OptionsDlg : public CDialog
{
// Construction
public:
	OptionsDlg(CWnd* pParent = NULL);   // standard constructor
	//CString m_defName;
	void doInit();

// Dialog Data
	//{{AFX_DATA(OptionsDlg)
	enum { IDD = IDD_DIALOG2 };
	CButton	m_ctrlVersion60;
	CButton	m_ctrlButton3;
	CButton	m_ctrlButton4;
	CEdit	m_ctrlVisitorSource;
	CEdit	m_ctrlVisitorHeader;
	CButton	m_ctrlButton5;
	CEdit	m_ctrlPrevHeaderName;
	CString	m_headerName;
	CString	m_sourceName;
	CString	m_visitorHeaderName;
	CString	m_visitorSourceName;
	CString	m_prevHeaderName;
	CString m_namespaceName;
	BOOL	m_bVisitor;
	BOOL	m_bParse;
	BOOL	m_bInit;
	BOOL	m_bFinalize;
	BOOL	m_bAcceptTrave;
	BOOL	m_bAcceptSpeci;
	int		m_whichStyle;
	BOOL	m_version60;
	int		m_visitorSignature;
	CButton m_ctrlSpAccRetVoid;
	CButton m_ctrlSpAccRetBool;
	int		m_specAcceptRetVal;
	int		m_methodOfOutput;
	//}}AFX_DATA


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

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(OptionsDlg)
	afx_msg void OnButton1();
	afx_msg void OnButton2();
	afx_msg void OnButton3();
	afx_msg void OnButton4();
	afx_msg void OnButton5();
	virtual BOOL OnInitDialog();
	afx_msg void OnCheck5();
	afx_msg void OnCheck34();
	afx_msg void OnRadio1();
	afx_msg void OnRadio2();
	afx_msg void OnRadio3();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnBnClickedCheck6();
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_OPTIONSDLG_H__0A217994_9D2A_429E_B244_4CD2D8F74A26__INCLUDED_)

--- NEW FILE: InPlaceEdit.h ---
//////////////////////////////////////////////////////////////////////
// InPlaceEdit.h : header file
//
// MFC Grid Control - inplace editing class
//
// Written by Chris Maunder <cmaunder at mail.com>
// Copyright (c) 1998-2002. All Rights Reserved.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is 
// not sold for profit without the authors written consent, and 
// providing that this notice and the authors name and all copyright 
// notices remains intact. 
//
// An email letting me know how you are using it would be nice as well. 
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability for any damage/loss of business that
// this product may cause.
//
// For use with CGridCtrl v2.10+
//
//////////////////////////////////////////////////////////////////////

#define IDC_IPEDIT	1976

/////////////////////////////////////////////////////////////////////////////
// CInPlaceEdit window

class CInPlaceEdit : public CEdit
{
// Construction
public:
	CInPlaceEdit(int iItem, int iSubItem, CString sInitText);

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CInPlaceEdit)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CInPlaceEdit();

	// Generated message map functions
protected:
	//{{AFX_MSG(CInPlaceEdit)
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnNcDestroy();
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
private:
	int m_iItem;
	int m_iSubItem;
	CString m_sInitText;
	BOOL    m_bESC;	 	// To indicate whether ESC key was pressed
};

/////////////////////////////////////////////////////////////////////////////
--- NEW FILE: InPlaceEdit.cpp ---
// InPlaceEdit.cpp : implementation file
//
// Adapted by Chris Maunder <cmaunder at mail.com>
// Copyright (c) 1998-2002. All Rights Reserved.
//
// The code contained in this file is based on the original
// CInPlaceEdit from http://www.codeguru.com/listview/edit_subitems.shtml
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is 
// not sold for profit without the authors written consent, and 
// providing that this notice and the authors name and all copyright 
// notices remains intact. 
//
// An email letting me know how you are using it would be nice as well. 
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability for any damage/loss of business that
// this product may cause.
//
// For use with CGridCtrl v2.10+
//
// History:
//         10 May 1998  Uses GVN_ notifications instead of LVN_,
//                      Sends notification messages to the parent, 
//                      instead of the parent's parent.
//         15 May 1998  There was a problem when editing with the in-place editor, 
//                      there arises a general protection fault in user.exe, with a 
//                      few qualifications:
//                         (1) This only happens with owner-drawn buttons;
//                         (2) This only happens in Win95
//                         (3) This only happens if the handler for the button does not 
//                             create a new window (even an AfxMessageBox will avoid the 
//                             crash)
//                         (4) This will not happen if Spy++ is running.
//                      PreTranslateMessage was added to route messages correctly.
//                      (Matt Weagle found and fixed this problem)
//         26 Jul 1998  Removed the ES_MULTILINE style - that fixed a few probs!
//          6 Aug 1998  Added nID to the constructor param list
//          6 Sep 1998  Space no longer clears selection when starting edit (Franco Bez)
//         10 Apr 1999  Enter, Tab and Esc key prob fixed (Koay Kah Hoe)
//                      Workaround for bizzare "shrinking window" problem in CE
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "inplaceedit.h"


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

/////////////////////////////////////////////////////////////////////////////
// CInPlaceEdit

CInPlaceEdit::CInPlaceEdit(int iItem, int iSubItem, CString sInitText)
:m_sInitText( sInitText )
{
	m_iItem = iItem;
	m_iSubItem = iSubItem;
	m_bESC = FALSE;
}

CInPlaceEdit::~CInPlaceEdit()
{
}


BEGIN_MESSAGE_MAP(CInPlaceEdit, CEdit)
	//{{AFX_MSG_MAP(CInPlaceEdit)
	ON_WM_KILLFOCUS()
	ON_WM_NCDESTROY()
	ON_WM_CHAR()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInPlaceEdit message handlers

BOOL CInPlaceEdit::PreTranslateMessage(MSG* pMsg)
{
	if( pMsg->message == WM_KEYDOWN )
	{
		if(pMsg->wParam == VK_RETURN
				|| pMsg->wParam == VK_DELETE
				|| pMsg->wParam == VK_ESCAPE
				|| GetKeyState( VK_CONTROL)
				)
		{
			::TranslateMessage(pMsg);
			::DispatchMessage(pMsg);
			return TRUE;		    	// DO NOT process further
		}
	}

	return CEdit::PreTranslateMessage(pMsg);
}


void CInPlaceEdit::OnKillFocus(CWnd* pNewWnd)
{
	CEdit::OnKillFocus(pNewWnd);

	CString str;
	GetWindowText(str);

	// Send Notification to parent of ListView ctrl
	LV_DISPINFO dispinfo;
	dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
	dispinfo.hdr.idFrom = GetDlgCtrlID();
	dispinfo.hdr.code = LVN_ENDLABELEDIT;

	dispinfo.item.mask = LVIF_TEXT;
	dispinfo.item.iItem = m_iItem;
	dispinfo.item.iSubItem = m_iSubItem;
	dispinfo.item.pszText = m_bESC ? NULL : LPTSTR((LPCTSTR)str);
	dispinfo.item.cchTextMax = str.GetLength();

	GetParent()->GetParent()->SendMessage( WM_NOTIFY, GetParent()->GetDlgCtrlID(), 
					(LPARAM)&dispinfo );

	DestroyWindow();
}

void CInPlaceEdit::OnNcDestroy()
{
	CEdit::OnNcDestroy();

	delete this;
}


void CInPlaceEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	if( nChar == VK_ESCAPE || nChar == VK_RETURN)
	{
		if( nChar == VK_ESCAPE )
			m_bESC = TRUE;
		GetParent()->SetFocus();
		return;
	}


	CEdit::OnChar(nChar, nRepCnt, nFlags);

	// Resize edit control if needed

	// Get text extent
	CString str;

	GetWindowText( str );
	CWindowDC dc(this);
	CFont *pFont = GetParent()->GetFont();
	CFont *pFontDC = dc.SelectObject( pFont );
	CSize size = dc.GetTextExtent( str );
	dc.SelectObject( pFontDC );
	size.cx += 5;			   	// add some extra buffer

	// Get client rect
	CRect rect, parentrect;
	GetClientRect( &rect );
	GetParent()->GetClientRect( &parentrect );

	// Transform rect to parent coordinates
	ClientToScreen( &rect );
	GetParent()->ScreenToClient( &rect );

	// Check whether control needs to be resized
	// and whether there is space to grow
	if( size.cx > rect.Width() )
	{
		if( size.cx + rect.left < parentrect.right )
			rect.right = rect.left + size.cx;
		else
			rect.right = parentrect.right;
		MoveWindow( &rect );
	}
}

int CInPlaceEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CEdit::OnCreate(lpCreateStruct) == -1)
		return -1;

	// Set the proper font
	CFont* font = GetParent()->GetFont();
	SetFont(font);

	SetWindowText( m_sInitText );
	SetFocus();
	SetSel( 0, -1 );
	return 0;
}
--- NEW FILE: SelConf.h ---
#if !defined(AFX_SELCONF_H__C00FC7AA_4D0A_4DC6_946B_BFFF99DD2CB3__INCLUDED_)
#define AFX_SELCONF_H__C00FC7AA_4D0A_4DC6_946B_BFFF99DD2CB3__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SelConf.h : header file
//
#include "resource.h"
#include "Table.h"
#include <AFXCMN.H>
#include <afxtempl.h>
#include "string"
#include "vector"
#include "map"

typedef struct
{
	int id;
	CString s;
	char kind;
	int cliqueId;
	bool val;
	CString resp;
	const void * ptr;
} entry;

typedef CTypedPtrList<CPtrList, entry*> CEntryList;
/////////////////////////////////////////////////////////////////////////////
// SelConf dialog

class SelConf : public CDialog
{
// Construction
public:
	SelConf( unsigned int configs, CWnd* pParent = NULL);   // standard constructor
	~SelConf();

// Dialog Data
	//{{AFX_DATA(SelConf)
	enum { IDD = IDD_DIALOG1 };
	CComboBox	m_config;
	//}}AFX_DATA


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

// Implementation
public:
	int addEntry( const CString& role, char kind, int clique, bool in, const CString& repr, const void * ptr);
	bool getEntry( int row, CString& role, bool& in, CString& repr, const void * &ptr);

	void addConfigs( std::vector< std::string >& configs);
	int findAmongConfigs( std::string& config_name);

	std::string m_currSelConfigStr;

	void getDescsAncs( bool which, int changed, std::vector< int > & res);
	bool addPossibleAncestors( CStringList& list, int changed);
	
	static int m_sortOrder;
	static bool getEntries( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort, entry& e, entry& f);
	static int CALLBACK MyNameCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	static int CALLBACK MyKindCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	static int CALLBACK MyExtdCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
	static int CALLBACK MyReprCompare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);

protected:
	const int m_numberOfConfigs;
	static int m_lastId;
	CEntryList m_entries;

	void selectAll( bool pVal);
	void fillUpTable(); // copies data to
	void getDataFromTable(); // copies data from m_table
	CTable m_table;

	void saveUserPref( bool check);
	void refreshTable();
	
	std::vector< std::string > m_configStrings;
	// Generated message map functions
	//{{AFX_MSG(SelConf)
	virtual BOOL OnInitDialog();
	virtual void OnOK();
	afx_msg void OnEditupdateCombo1();
	afx_msg void OnCloseupCombo1();
	afx_msg void OnBnClickedDeselectallbtn();
	afx_msg void OnBnClickedSelectallbtn();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SELCONF_H__C00FC7AA_4D0A_4DC6_946B_BFFF99DD2CB3__INCLUDED_)

--- NEW FILE: InPlaceList.cpp ---
// InPlaceList.cpp : implementation file
//

#include "stdafx.h"
#include "inplacelist.h"


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

/////////////////////////////////////////////////////////////////////////////
// CInPlaceList

CInPlaceList::CInPlaceList(int iItem, int iSubItem, CStringList *plstItems, int nSel)
{
	m_iItem = iItem;
	m_iSubItem = iSubItem;

	m_lstItems.AddTail( plstItems );
	m_nSel = nSel;
	m_bESC = FALSE;
}

CInPlaceList::~CInPlaceList()
{
}


BEGIN_MESSAGE_MAP(CInPlaceList, CComboBox)
	//{{AFX_MSG_MAP(CInPlaceList)
	ON_WM_CREATE()
	ON_WM_KILLFOCUS()
	ON_WM_CHAR()
	ON_WM_NCDESTROY()
	ON_CONTROL_REFLECT(CBN_CLOSEUP, OnCloseup)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CInPlaceList message handlers

int CInPlaceList::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CComboBox::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// Set the proper font
	CFont* font = GetParent()->GetFont();
	SetFont(font);

	for( POSITION pos = m_lstItems.GetHeadPosition(); pos != NULL; )
	{
		AddString( (LPCTSTR) (m_lstItems.GetNext( pos )) );
	}
	SetCurSel( m_nSel );
	SetFocus();
	return 0;
}

BOOL CInPlaceList::PreTranslateMessage(MSG* pMsg) 
{
	if( pMsg->message == WM_KEYDOWN )
	{
		if(pMsg->wParam == VK_RETURN 
				|| pMsg->wParam == VK_ESCAPE
				)
		{
			::TranslateMessage(pMsg);
			::DispatchMessage(pMsg);
			return TRUE;				// DO NOT process further
		}
	}
	
	return CComboBox::PreTranslateMessage(pMsg);
}

void CInPlaceList::OnKillFocus(CWnd* pNewWnd) 
{
	CComboBox::OnKillFocus(pNewWnd);
	
	CString str;
	GetWindowText(str);

	// Send Notification to parent of ListView ctrl
	LV_DISPINFO dispinfo;
	dispinfo.hdr.hwndFrom = GetParent()->m_hWnd;
	dispinfo.hdr.idFrom = GetDlgCtrlID();
	dispinfo.hdr.code = LVN_ENDLABELEDIT;

	dispinfo.item.mask = LVIF_TEXT;
	dispinfo.item.iItem = m_iItem;
	dispinfo.item.iSubItem = m_iSubItem;
	dispinfo.item.pszText = m_bESC ? NULL : LPTSTR((LPCTSTR)str);
	dispinfo.item.cchTextMax = str.GetLength();

	GetParent()->GetParent()->SendMessage( WM_NOTIFY, GetParent()->GetDlgCtrlID(), (LPARAM)&dispinfo );

	PostMessage( WM_CLOSE );
}

void CInPlaceList::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if( nChar == VK_ESCAPE || nChar == VK_RETURN)
	{
		if( nChar == VK_ESCAPE )
			m_bESC = TRUE;
		GetParent()->SetFocus();
		return;
	}
	
	CComboBox::OnChar(nChar, nRepCnt, nFlags);
}

void CInPlaceList::OnNcDestroy() 
{
	CComboBox::OnNcDestroy();
	
	delete this;
}

void CInPlaceList::OnCloseup() 
{
	GetParent()->SetFocus();
}

--- NEW FILE: InPlaceList.h ---
// InPlaceList.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CInPlaceList window

class CInPlaceList : public CComboBox
{
// Construction
public:
	CInPlaceList(int iItem, int iSubItem, CStringList *plstItems, int nSel);

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CInPlaceList)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CInPlaceList();

	// Generated message map functions
protected:
	//{{AFX_MSG(CInPlaceList)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnKillFocus(CWnd* pNewWnd);
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnNcDestroy();
	afx_msg void OnCloseup();
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
private:
	int 	m_iItem;
	int 	m_iSubItem;
	CStringList m_lstItems;
	int 	m_nSel;
	BOOL	m_bESC;				// To indicate whether ESC key was pressed
};

/////////////////////////////////////////////////////////////////////////////

--- NEW FILE: OptionsDlg.cpp ---
// OptionsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "OptionsDlg.h"
#include <afxdlgs.h>
#include ".\optionsdlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// OptionsDlg dialog


OptionsDlg::OptionsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(OptionsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(OptionsDlg)
	m_headerName = _T("");
	m_sourceName = _T("");
	m_visitorHeaderName = _T("");
	m_visitorSourceName = _T("");
	m_prevHeaderName = _T("");
	m_namespaceName = _T("");
	m_bVisitor = FALSE;
	m_bParse = FALSE;
	m_bInit = FALSE;
	m_bFinalize = FALSE;
	m_bAcceptTrave = FALSE;
	m_bAcceptSpeci = FALSE;
	m_whichStyle = 0;
	m_version60 = FALSE;
	m_visitorSignature = 0;
	m_specAcceptRetVal = 0;
	m_methodOfOutput = 0;
	//}}AFX_DATA_INIT
}


void OptionsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(OptionsDlg)
	DDX_Control(pDX, IDC_CHECKVERS60, m_ctrlVersion60);
	DDX_Control(pDX, IDC_BUTTON3, m_ctrlButton3);
	DDX_Control(pDX, IDC_BUTTON4, m_ctrlButton4);
	DDX_Control(pDX, IDC_EDIT4, m_ctrlVisitorSource);
	DDX_Control(pDX, IDC_EDIT3, m_ctrlVisitorHeader);
	DDX_Control(pDX, IDC_BUTTON5, m_ctrlButton5);
	DDX_Control(pDX, IDC_EDIT5, m_ctrlPrevHeaderName);
	DDX_Control(pDX, IDC_RADIOSPACCRETURNSVOID, m_ctrlSpAccRetVoid);
	DDX_Control(pDX, IDC_RADIOSPACCRETURNSBOOL, m_ctrlSpAccRetBool);
	DDX_Text(pDX, IDC_EDIT1, m_headerName);
	DDX_Text(pDX, IDC_EDIT2, m_sourceName);
	DDX_Text(pDX, IDC_EDIT3, m_visitorHeaderName);
	DDX_Text(pDX, IDC_EDIT4, m_visitorSourceName);
	DDX_Text(pDX, IDC_EDIT5, m_prevHeaderName);
	DDX_Text(pDX, IDC_EDIT6, m_namespaceName);
	DDX_Check(pDX, IDC_CHECK34, m_bVisitor);
	DDX_Check(pDX, IDC_CHECK5, m_bParse);
	DDX_Check(pDX, IDC_CHECK2, m_bInit);
	DDX_Check(pDX, IDC_CHECK3, m_bFinalize);
	DDX_Check(pDX, IDC_CHECK4, m_bAcceptTrave);
	DDX_Check(pDX, IDC_CHECK6, m_bAcceptSpeci);
	DDX_Radio(pDX, IDC_RADIO1, m_whichStyle);
	DDX_Check(pDX, IDC_CHECKVERS60, m_version60);
	DDX_Radio(pDX, IDC_RADIOVISITSIGN1, m_visitorSignature);
	DDX_Radio(pDX, IDC_RADIOSPACCRETURNSVOID, m_specAcceptRetVal);
	DDX_Radio(pDX, IDC_RADIOSAMEFILE, m_methodOfOutput);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(OptionsDlg, CDialog)
	//{{AFX_MSG_MAP(OptionsDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_BN_CLICKED(IDC_CHECK5, OnCheck5)
	ON_BN_CLICKED(IDC_CHECK34, OnCheck34)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_CHECK6, OnBnClickedCheck6)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// OptionsDlg message handlers

BOOL OptionsDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_ctrlPrevHeaderName.EnableWindow( FALSE);
	m_ctrlButton5.EnableWindow( FALSE);

	m_ctrlVisitorHeader.EnableWindow( m_bVisitor);
	m_ctrlVisitorSource.EnableWindow( m_bVisitor);
	m_ctrlButton3.EnableWindow( m_bVisitor);
	m_ctrlButton4.EnableWindow( m_bVisitor);

	m_ctrlSpAccRetVoid.EnableWindow( m_bAcceptSpeci);
	m_ctrlSpAccRetBool.EnableWindow( m_bAcceptSpeci);

	m_ctrlVersion60.EnableWindow( m_whichStyle >= 1);

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

void OptionsDlg::doInit()
{
	//m_headerName = m_defName + "BonX.h";
	//m_sourceName = m_defName + "BonX.cpp";
	//m_prevHeaderName = m_headerName + ".bak";

	////global_vars.output_directory_name = "";
	////global_vars.err_file_name = proj_name + "BONExt.log";

	//m_visitorHeaderName = m_defName + "Visitor.h";
	//m_visitorSourceName = m_defName + "Visitor.cpp";
}

void OptionsDlg::OnButton1()
{
	UpdateData( TRUE);
	// header file name selection
	try {
		CFileDialog dlg2(FALSE, "h", m_headerName,
			OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
			,"C++ header files (*.h)|*.h|All Files (*.*)|*.*||");
		if( dlg2.DoModal() == IDOK) 
		{
			m_sourceName = m_headerName = dlg2.GetPathName();
			m_prevHeaderName = m_headerName + ".copy";

			int p = m_sourceName.ReverseFind( '.');
			if ( p != -1)
			{
				m_sourceName = m_sourceName.Left(p) + ".cpp";
			}
			else
			{
				m_sourceName = m_sourceName + ".cpp";
			}
			
		}
		else // IDCANCEL , using default name
		{
			return ;
		}
	}	catch (...)	{ }

	UpdateData( FALSE);
	/*if ( existsFile( global_vars.header_file_name.c_str())) // make a copy of the header
	{
		global_vars.header_backup_name = global_vars.header_file_name + ".copy";
		int res = makeFileCopy( global_vars.header_file_name.c_str(), global_vars.header_backup_name.c_str());
		if ( res == 2)
		{
			TO("During backup process could not read file: " + global_vars.header_file_name);
			return 2;
		}
		else if ( res == 3)
		{
			TO("Cannot create backup file: " + global_vars.header_backup_name);
			return 3;
		}

		CString msg = CString("A file with ") + global_vars.header_file_name.c_str() + " name already exists." +
			"\nWould you like the user part extracted from this file?";
		if ( AfxMessageBox( msg, MB_YESNO | MB_ICONQUESTION) != IDYES)
			global_vars.header_backup_name = ""; // notify the dumper NOT to search for UP (user part) declarations
	}*/
}

void OptionsDlg::OnButton2() 
{
	UpdateData( TRUE);
	// source file name selection
	try {
		CFileDialog dlg2(FALSE, "cpp", m_sourceName,
			OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
			,"C++ source files (*.cpp)|*.cpp|All Files (*.*)|*.*||");
		if( dlg2.DoModal() == IDOK) 
		{
			m_sourceName = dlg2.GetPathName();
		}
		else // IDCANCEL , using default name
		{
			return ;
		}
	}	catch (...)	{ }

	UpdateData( FALSE);
}

void OptionsDlg::OnButton3() 
{
	UpdateData( TRUE);
	// visitor header file name selection
	try {
		CFileDialog dlg2(FALSE, "h", m_visitorHeaderName,
			OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
			,"C++ header files (*.h)|*.h|All Files (*.*)|*.*||");

		if( dlg2.DoModal() == IDOK) 
		{
			m_visitorSourceName = m_visitorHeaderName = (LPCTSTR) dlg2.GetPathName();
			int p = m_visitorSourceName.ReverseFind( '.');

			if ( p != -1)
				m_visitorSourceName = m_visitorSourceName.Left( p) + ".cpp";
			else
				m_visitorSourceName = m_visitorSourceName + ".cpp";

		}
		else // IDCANCEL , using default name
		{
			return ;
		}
	}	catch (...)	{ }

	UpdateData( FALSE);
}

void OptionsDlg::OnButton4() 
{
	UpdateData( TRUE);
	// visitor source file name selection
	try {
		CFileDialog dlg2(FALSE, "cpp", m_visitorSourceName,
			OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
			,"C++ source files (*.cpp)|*.cpp|All Files (*.*)|*.*||");
		if(dlg2.DoModal() == IDOK) 
		{
			m_visitorSourceName = dlg2.GetPathName();
		}
	}	catch (...)	{ }

	UpdateData( FALSE);
}

void OptionsDlg::OnButton5() 
{
	UpdateData( TRUE);
	// previous header file name selection
	try {
		CFileDialog dlg2(TRUE, "h.copy", "",
			OFN_EXPLORER | OFN_HIDEREADONLY //| OFN_OVERWRITEPROMPT
			,"Previously generated header files (*.h.copy)|*.h.copy|C++ header files (*.h)|*.h|All Files (*.*)|*.*||");
		if( dlg2.DoModal() == IDOK) 
		{
			m_prevHeaderName = dlg2.GetPathName();
		}
		else // IDCANCEL , using default name
		{
			return ;
		}
	}	catch (...)	{
	}

	UpdateData( FALSE);
}

void OptionsDlg::OnCheck5() 
{
	UpdateData( TRUE);
	m_ctrlPrevHeaderName.EnableWindow( m_bParse);
	m_ctrlButton5.EnableWindow( m_bParse);
	UpdateData( FALSE);
}

void OptionsDlg::OnCheck34() 
{
	UpdateData( TRUE);
	m_ctrlVisitorHeader.EnableWindow( m_bVisitor);
	m_ctrlVisitorSource.EnableWindow( m_bVisitor);
	m_ctrlButton3.EnableWindow( m_bVisitor);
	m_ctrlButton4.EnableWindow( m_bVisitor);
	UpdateData( FALSE);
}

void OptionsDlg::OnRadio1() 
{
	m_ctrlVersion60.EnableWindow( FALSE);
}

void OptionsDlg::OnRadio2() 
{
	m_ctrlVersion60.EnableWindow( TRUE);
}

void OptionsDlg::OnRadio3() 
{
	m_ctrlVersion60.EnableWindow( TRUE);
}

void OptionsDlg::OnBnClickedCheck6()
{
	UpdateData( TRUE);
	m_ctrlSpAccRetVoid.EnableWindow( m_bAcceptSpeci);
	m_ctrlSpAccRetBool.EnableWindow( m_bAcceptSpeci);
	UpdateData( FALSE);
}

--- NEW FILE: Table.cpp ---
// AspectSpecTbl.cpp : implementation file
//

#include "stdafx.h"
#include "inplaceedit.h"
#include "inplacelist.h"
#include "table.h"
#include "SelConf.h"

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

#define OFFSET_FIRST        2       // offsets for first and other columns in owner draw methods 
#define OFFSET_OTHER        6

#define EXT_COLNUM          2       // column of 'Extended?'
#define RSP_COLNUM          3       // column of 'Capture as' or 'Responsible'

/////////////////////////////////////////////////////////////////////////////
// CTable

CTable::CTable()
	: m_parent(0)
	, m_cxClient(0)
{
}

CTable::~CTable()
{
}

BOOL CTable::PreCreateWindow(CREATESTRUCT &cs)
{
	cs.style |= LVS_OWNERDRAWFIXED;
	return CListCtrl::PreCreateWindow( cs);
}


BEGIN_MESSAGE_MAP(CTable, CListCtrl)
	//{{AFX_MSG_MAP(CTable)
	ON_NOTIFY_REFLECT(LVN_ENDLABELEDIT, OnEndlabeledit)
	ON_WM_HSCROLL()
	ON_WM_VSCROLL()
	ON_WM_LBUTTONDOWN()
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_WM_PAINT()
	ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnSort)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTable message handlers

void CTable::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
	// TODO: Add your control notification handler code here

	LV_ITEM	*plvItem = &pDispInfo->item;

	if (plvItem->pszText != NULL)
	{
		// get old value
		LV_ITEM old_lvItem;
		old_lvItem.mask = LVIF_TEXT;
		old_lvItem.iItem = plvItem->iItem;
		
		CString prev_str;
		old_lvItem.iSubItem = plvItem->iSubItem;
		old_lvItem.pszText = prev_str.GetBuffer(255);
		old_lvItem.cchTextMax = 255;
		GetItem(&old_lvItem);

		// if not changed, return
		if( prev_str == plvItem->pszText) { *pResult = TRUE; return; }

		// change the value
		BOOL res = SetItemText(plvItem->iItem, plvItem->iSubItem, plvItem->pszText);
		
		// if 'Extend?' value changed
		if( res && plvItem->iSubItem == EXT_COLNUM)// mod on 3/16/2004 plvItem->iItem >= 0)
		{
			bool bYes = strcmp( plvItem->pszText, "yes") == 0;
			const char* repValArray[] = { "self", "none"};
			const char* repVal = repValArray[bYes?0:1];

			// update the responsible column accordingly
			SetItemText(plvItem->iItem, RSP_COLNUM, repVal);

			// change the extended and responsible column of the relatives
			std::vector< int > res;
			m_parent->getDescsAncs( !bYes, GetItemData( plvItem->iItem), res); // get Descendants if ext == "no", otherwise Ancestors

			// for each relative
			for( unsigned int desc_i = 0; desc_i < res.size(); ++desc_i)
			{
				unsigned int desc_r_id = res[desc_i];
				for (int i=0;i < GetItemCount();i++)
				{
					// if element found
					if ( GetItemData(i) == desc_r_id)
					{
						// change the extended value as for the current one
						// in case of 'yes' all ancestors need 'yes'
						// in case of 'no'  all descendants need 'no'
						SetItemText( i, EXT_COLNUM, plvItem->pszText);

						// update the responsible column accordingly
						SetItemText( i, RSP_COLNUM, repVal);
					}
				}
			}
		}
	}

	*pResult = TRUE;
}





// HitTestEx	- Determine the row index and column index for a point
// Returns	- the row index or -1 if point is not over a row
// point	- point to be tested.
// col		- to hold the column index
int CTable::HitTestEx(CPoint &point, int *col) const
{
	int colnum = 0;
	int row = HitTest( point, NULL );
	
	if( col ) *col = 0;

	// Make sure that the ListView is in LVS_REPORT
	if( (GetWindowLong(m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT )
		return row;

	// Get the top and bottom row visible
	row = GetTopIndex();
	int bottom = row + GetCountPerPage();
	if( bottom > GetItemCount() )
		bottom = GetItemCount();
	
	// Get the number of columns
	CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
	int nColumnCount = pHeader->GetItemCount();

	// Loop through the visible rows
	for( ;row <=bottom;row++)
	{
		// Get bounding rect of item and check whether point falls in it.
		CRect rect;
		GetItemRect( row, &rect, LVIR_BOUNDS );
		if( rect.PtInRect(point) )
		{
			// Now find the column
			for( colnum = 0; colnum < nColumnCount; colnum++ )
			{
				int colwidth = GetColumnWidth(colnum);
				if( point.x >= rect.left 
					&& point.x <= (rect.left + colwidth ) )
				{
					if( col ) *col = colnum;
					return row;
				}
				rect.left += colwidth;
			}
		}
	}
	return -1;
}


// ShowInPlaceList		- Creates an in-place drop down list for any 
//				- cell in the list view control
// Returns			- A temporary pointer to the combo-box control
// nItem			- The row index of the cell
// nCol				- The column index of the cell
// lstItems			- A list of strings to populate the control with
// nSel				- Index of the initial selection in the drop down list
CComboBox* CTable::ShowInPlaceList( int nItem, int nCol, 
					CStringList &lstItems, int nSel )
{
	// The returned pointer should not be saved

	// Make sure that the item is visible
	if( !EnsureVisible( nItem, TRUE ) ) return NULL;

	// Make sure that nCol is valid 
	CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
	int nColumnCount = pHeader->GetItemCount();
	if( nCol >= nColumnCount || GetColumnWidth(nCol) < 10 ) 
		return NULL;

	// Get the column offset
	int offset = 0;
	for( int i = 0; i < nCol; i++ )
		offset += GetColumnWidth( i );

	CRect rect;
	GetItemRect( nItem, &rect, LVIR_BOUNDS );

	// Now scroll if we need to expose the column
	CRect rcClient;
	GetClientRect( &rcClient );
	if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
	{
		CSize size;
		size.cx = offset + rect.left;
		size.cy = 0;
		Scroll( size );
		rect.left -= size.cx;
	}

	rect.left += offset+4;
	rect.right = rect.left + GetColumnWidth( nCol ) - 3 ;
	int height = rect.bottom-rect.top;
	rect.bottom += (lstItems.GetCount()+1)*height;
	if( rect.right > rcClient.right) rect.right = rcClient.right;

	DWORD dwStyle = WS_BORDER|WS_CHILD|WS_VISIBLE
					|CBS_DROPDOWNLIST|CBS_DISABLENOSCROLL;
	CComboBox *pList = new CInPlaceList(nItem, nCol, &lstItems, nSel);
	pList->Create( dwStyle, rect, this, IDC_IPEDIT );
	pList->SetItemHeight( -1, height);
	pList->SetHorizontalExtent( GetColumnWidth( nCol ));

	
	return pList;
}



// EditSubLabel		- Start edit of a sub item label
// Returns		- Temporary pointer to the new edit control
// nItem		- The row index of the item to edit
// nCol			- The column of the sub item.
CEdit* CTable::EditSubLabel( int nItem, int nCol )
{
	// The returned pointer should not be saved

	// Make sure that the item is visible
	if( !EnsureVisible( nItem, TRUE ) ) return NULL;

	// Make sure that nCol is valid
	CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
	int nColumnCount = pHeader->GetItemCount();
	if( nCol >= nColumnCount || GetColumnWidth(nCol) < 5 )
		return NULL;

	// Get the column offset
	int offset = 0;
	for( int i = 0; i < nCol; i++ )
		offset += GetColumnWidth( i );

	CRect rect;
	GetItemRect( nItem, &rect, LVIR_BOUNDS );

	// Now scroll if we need to expose the column
	CRect rcClient;
	GetClientRect( &rcClient );
	if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
	{
		CSize size;
		size.cx = offset + rect.left;
		size.cy = 0;
		Scroll( size );
		rect.left -= size.cx;
	}

	// Get Column alignment
	LV_COLUMN lvcol;
	lvcol.mask = LVCF_FMT;
	GetColumn( nCol, &lvcol );
	DWORD dwStyle ;
	if((lvcol.fmt&LVCFMT_JUSTIFYMASK) == LVCFMT_LEFT)
		dwStyle = ES_LEFT;
	else if((lvcol.fmt&LVCFMT_JUSTIFYMASK) == LVCFMT_RIGHT)
		dwStyle = ES_RIGHT;
	else dwStyle = ES_CENTER;

	rect.left += offset+4;
	rect.right = rect.left + GetColumnWidth( nCol ) - 3 ;
	if( rect.right > rcClient.right) rect.right = rcClient.right;

	dwStyle |= WS_BORDER|WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL;
	CEdit *pEdit = new CInPlaceEdit(nItem, nCol, GetItemText( nItem, nCol ));
	pEdit->Create( dwStyle, rect, this, IDC_IPEDIT );


	return pEdit;
}

void CTable::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	if( GetFocus() != this ) SetFocus();
	CListCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
}



void CTable::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	if( GetFocus() != this ) SetFocus();	
	CListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
}


void CTable::OnLButtonDown(UINT nFlags, CPoint point) 
{
	int index;
	CListCtrl::OnLButtonDown(nFlags, point);

	int colnum;
	if( ( index = HitTestEx( point, &colnum )) != -1 )
	{
		UINT flag = LVIS_FOCUSED;
		if( (GetItemState( index, flag ) & flag) == flag )
		{
			// Add check for LVS_EDITLABELS
			/*if( GetWindowLong(m_hWnd, GWL_STYLE) & LVS_EDITLABELS )*/
			/*if(colnum==1)
			{
				char buff[64];
				LVITEM item;
				item.mask = LVIF_TEXT;
				item.iItem = index;
				item.iSubItem = 1;
				item.pszText = buff;
				item.cchTextMax = 63;
				if (GetItem(&item) &&  CString(item.pszText) != "N/A") {
					CStringList lstItems;
					int rowID = GetItemData( index);
					//mmtheAspectDlg->GetAspects( rowID, lstItems);
					ShowInPlaceList( index, colnum, lstItems, 0 );
				}
			}*/
			if(colnum==EXT_COLNUM)
			{
				CStringList lstItems;
				lstItems.AddTail("yes");
				lstItems.AddTail("no");
				ShowInPlaceList( index, colnum, lstItems, 0 );
			}
			else if(colnum==RSP_COLNUM)
			{
				int rowID = GetItemData( index);
				CString role, repr; bool ext;
				if( getRow( rowID, role, ext, repr) && ext == false) // if not intended for extension
				{
					CStringList lstItems;
					lstItems.AddTail("none");
					if( m_parent->addPossibleAncestors( lstItems, rowID)) // some choices added
						ShowInPlaceList( index, colnum, lstItems, 0 );
					else
						AfxMessageBox("This class does not have a base of the same kind. For BON2 reasons can't be captured by its superclass.");
				}
			}

		}
		else
			SetItemState( index, LVIS_SELECTED | LVIS_FOCUSED , 
					LVIS_SELECTED | LVIS_FOCUSED);
	}
}

int CTable::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CListCtrl::OnCreate(lpCreateStruct) == -1)
		return -1;

	int col0size = 9*GetStringWidth("TipicalLongRolenName")/4;
	int col1size = 4*GetStringWidth("R");
	int col2size = 13*GetStringWidth("Extend")/9;
	int col3size = 3*GetStringWidth("TypicalLongRoleName")/2;

	InsertColumn(0, _T("Class"), LVCFMT_LEFT,  col0size, -1);
	InsertColumn(1, _T("Stereotype"), LVCFMT_LEFT, col1size, -1);
	InsertColumn(EXT_COLNUM, _T("Extend"), LVCFMT_LEFT, col2size, -1);
	InsertColumn(RSP_COLNUM, _T("Capture as"), LVCFMT_LEFT, col3size, -1);

	return 0;
}

void CTable::addRow(int rowID, CString& role, char kind, int clique, bool generate, CString& repr)
{
	LV_ITEM lvItem;
	lvItem.mask = LVIF_TEXT;
	lvItem.iItem = GetItemCount();
	lvItem.iSubItem = 0;
	lvItem.pszText = role.GetBuffer(role.GetLength());
	int index = InsertItem(&lvItem);
	
	char b[2] = { kind, 0 };
	lvItem.iSubItem = 1;
	lvItem.pszText = b;
	SetItem(&lvItem);

	lvItem.iSubItem = EXT_COLNUM;
	lvItem.pszText = generate ? _T("yes"): _T("no");
	SetItem(&lvItem);

	lvItem.iSubItem = RSP_COLNUM;
	lvItem.pszText = generate ?_T("self"): repr.IsEmpty() ? _T("none") : repr;
	SetItem(&lvItem);


	SetItemData(index, rowID);
	
}

bool CTable::getRow(int rowID, CString &role, bool &generate, CString &repr)
{
	LVFINDINFO lvFind;
	lvFind.flags = LVFI_PARAM;
	lvFind.lParam = rowID;
	int idx = FindItem(&lvFind);

	if (idx == -1)
		return false;


	LV_ITEM lvItem;
	lvItem.mask = LVIF_TEXT;
	lvItem.iItem = idx;
	lvItem.pszText = role.GetBuffer(255);
	lvItem.cchTextMax = 255;
	lvItem.iSubItem = 0;
	GetItem(&lvItem);
	
	CString tmpStr;
	lvItem.pszText = tmpStr.GetBuffer(10);
	lvItem.cchTextMax = 10;
	lvItem.iSubItem = EXT_COLNUM;
	GetItem(&lvItem);
	generate = (tmpStr == "yes");

	lvItem.pszText = repr.GetBuffer(255);
	lvItem.cchTextMax = 255;
	lvItem.iSubItem = RSP_COLNUM;
	GetItem(&lvItem);

	return true;
}

void CTable::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CListCtrl& ListCtrl = *this;
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	CRect rcItem(lpDrawItemStruct->rcItem);
	UINT uiFlags = ILD_TRANSPARENT;
	int nItem = lpDrawItemStruct->itemID;
	BOOL bFocus = (GetFocus() == this);
	COLORREF clrTextSave, clrBkSave;
	static _TCHAR szBuff[MAX_PATH];
	static _TCHAR szBuff2[MAX_PATH] = _T("c");
	LPCTSTR pszText;

// get item data

	LV_ITEM lvi;
	lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
	lvi.iItem = nItem;
	lvi.iSubItem = 0;
	lvi.pszText = szBuff;
	lvi.cchTextMax = sizeof(szBuff);
	lvi.stateMask = 0xFFFF;     // get all state flags
	ListCtrl.GetItem(&lvi);

	BOOL bSelected = (bFocus || (GetStyle() & LVS_SHOWSELALWAYS)) && lvi.state & LVIS_SELECTED;
	bSelected = bSelected || (lvi.state & LVIS_DROPHILITED);

// set colors if item is selected

	CRect rcAllLabels;
	ListCtrl.GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);

	CRect rcLabel;
	ListCtrl.GetItemRect(nItem, rcLabel, LVIR_LABEL);

	rcAllLabels.left = rcLabel.left;
	if (rcAllLabels.right<m_cxClient)
		rcAllLabels.right = m_cxClient;

	if (bSelected)
	{
		// the return value is the previous color, so save it
		clrTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
		clrBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));

		pDC->FillRect(rcAllLabels, &CBrush( ::GetSysColor(COLOR_HIGHLIGHT)));
	}
	else
		pDC->FillRect(rcAllLabels, &CBrush( ::GetSysColor(COLOR_WINDOW)));

// draw item label

	ListCtrl.GetItemRect(nItem, rcItem, LVIR_LABEL);

	pszText = MakeShortString(pDC, szBuff, rcItem.right-rcItem.left, 2*OFFSET_FIRST);

	rcLabel = rcItem;
	rcLabel.left += OFFSET_FIRST;
	rcLabel.right -= OFFSET_FIRST;

	pDC->DrawText(pszText,-1,rcLabel,DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);


// draw labels for extra columns

	LV_COLUMN lvc;
	lvc.mask = LVCF_FMT | LVCF_WIDTH;

	for(int nColumn = 1; ListCtrl.GetColumn(nColumn, &lvc); nColumn++)
	{
		rcItem.left = rcItem.right;
		rcItem.right += lvc.cx;

		int nRetLen = ListCtrl.GetItemText(nItem, nColumn,
						szBuff, sizeof(szBuff));
		if (nRetLen == 0)
			continue;

		pszText = MakeShortString(pDC, szBuff,
			rcItem.right - rcItem.left, 2*OFFSET_OTHER);

		UINT nJustify = DT_LEFT;

		if(pszText == szBuff)
		{
			switch(lvc.fmt & LVCFMT_JUSTIFYMASK)
			{
			case LVCFMT_RIGHT:
				nJustify = DT_RIGHT;
				break;
			case LVCFMT_CENTER:
				nJustify = DT_CENTER;
				break;
			default:
				break;
			}
		}

		rcLabel = rcItem;
		rcLabel.left += OFFSET_OTHER;
		rcLabel.right -= OFFSET_OTHER;

		pDC->DrawText(pszText, -1, rcLabel,
			nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
	}

	// draw focus rectangle if item has focus
	//if (lvi.state & LVIS_FOCUSED && bFocus) pDC->DrawFocusRect(rcAllLabels);

	
// set original colors if item was selected

	if (bSelected)
	{
		pDC->SetTextColor(clrTextSave);
		pDC->SetBkColor(clrBkSave);
	}
}

LPCTSTR CTable::MakeShortString(CDC* pDC, LPCTSTR lpszLong, int nColumnLen, int nOffset)
{
	static const _TCHAR szThreeDots[] = _T("...");

	int nStringLen = lstrlen(lpszLong);

	if(nStringLen == 0 ||
		(pDC->GetTextExtent(lpszLong, nStringLen).cx + nOffset) <= nColumnLen)
	{
		return(lpszLong);
	}

	static _TCHAR szShort[MAX_PATH];

	lstrcpy(szShort,lpszLong);
	int nAddLen = pDC->GetTextExtent(szThreeDots,sizeof(szThreeDots)).cx;

	for(int i = nStringLen-1; i > 0; i--)
	{
		szShort[i] = 0;
		if((pDC->GetTextExtent(szShort, i).cx + nOffset + nAddLen)
			<= nColumnLen)
		{
			break;
		}
	}

	lstrcat(szShort, szThreeDots);
	return(szShort);
}

void CTable::OnSize(UINT nType, int cx, int cy)
{
	m_cxClient = cx;
	CListCtrl::OnSize(nType, cx, cy);
}

void CTable::OnPaint()
{
	// full row select mode: need to extend the clipping region
	// so we can paint a selection all the way to the right
	if ((GetStyle() & LVS_TYPEMASK) == LVS_REPORT)
	{
		CRect rcAllLabels;
		GetItemRect(0, rcAllLabels, LVIR_BOUNDS);

		if(rcAllLabels.right < m_cxClient)
		{
			// need to call BeginPaint (in CPaintDC c-tor)
			// to get correct clipping rect
			CPaintDC dc(this);

			CRect rcClip;
			dc.GetClipBox(rcClip);

			rcClip.left = min(rcAllLabels.right-1, rcClip.left);
			rcClip.right = m_cxClient;

			InvalidateRect(rcClip, FALSE);
			// EndPaint will be called in CPaintDC d-tor
		}
	}

	CListCtrl::OnPaint();
}

void CTable::OnSort(NMHDR* pNMHDR, LRESULT* pResult)
{
	NMLISTVIEW* pNMLV = (NMLISTVIEW*) pNMHDR;
	ASSERT( pNMLV->iItem == -1);
	ASSERT( pNMLV->iSubItem >= 0);

	switch( pNMLV->iSubItem) {
		case 0:
			this->SortItems( SelConf::MyNameCompare, (LPARAM) m_parent);
			break;
		case 1:
			this->SortItems( SelConf::MyKindCompare, (LPARAM) m_parent);
			break;
		case 2:
			this->SortItems( SelConf::MyExtdCompare, (LPARAM) m_parent);
			break;
		case 3:
			this->SortItems( SelConf::MyReprCompare, (LPARAM) m_parent);
			break;
		default:
			ASSERT(0);
	};
	
	// after sort is done we revert the direction of the next sort with:
	SelConf::m_sortOrder *= -1;
}



More information about the GME-commit mailing list