2001-12-18 17:56:45 +00:00
|
|
|
// PrefEditView.cpp : implementation of the CPrefEditView class
|
|
|
|
//
|
2001-12-28 21:17:11 +00:00
|
|
|
// Reads the prefs from an XML files and display them in a tree control.
|
|
|
|
// Saves back to an XML file.
|
2001-12-18 17:56:45 +00:00
|
|
|
//
|
2001-12-28 21:17:11 +00:00
|
|
|
// Uses Expat XML parser.
|
2001-12-18 17:56:45 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2001-12-28 21:17:11 +00:00
|
|
|
#include "xmlparse.h"
|
|
|
|
#include "PrefsElement.h"
|
2001-12-18 17:56:45 +00:00
|
|
|
#include "PrefEditView.h"
|
|
|
|
#include "DlgEditPrefStr.h"
|
|
|
|
#include "DlgFind.h"
|
|
|
|
#include "DlgAdd.h"
|
2002-04-25 18:43:33 +00:00
|
|
|
#include "Encoding.h"
|
2001-12-18 17:56:45 +00:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
#undef THIS_FILE
|
|
|
|
static char THIS_FILE[] = __FILE__;
|
|
|
|
#endif
|
|
|
|
|
2002-01-24 21:08:29 +00:00
|
|
|
// bitmaps to use for the tree control as defined in IB_TREEIMAGES
|
|
|
|
const int bm_closedFolder = 0;
|
|
|
|
const int bm_openFolder = 1;
|
|
|
|
const int bm_lockedPad = 2;
|
|
|
|
const int bm_unlockedPad = 3;
|
|
|
|
const int bm_unlockedPadGray = 4;
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2002-01-28 19:09:00 +00:00
|
|
|
// submenus
|
|
|
|
const int menu_pref = 0;
|
|
|
|
const int menu_group = 1;
|
|
|
|
const int menu_userAddedPref = 2;
|
2001-12-18 17:56:45 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CPrefEditView
|
|
|
|
|
|
|
|
IMPLEMENT_DYNCREATE(CPrefEditView, CTreeView)
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CPrefEditView, CTreeView)
|
|
|
|
//{{AFX_MSG_MAP(CPrefEditView)
|
|
|
|
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
|
|
|
|
ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
|
2002-07-24 03:04:12 +00:00
|
|
|
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnExpanded)
|
2001-12-18 17:56:45 +00:00
|
|
|
ON_WM_CREATE()
|
|
|
|
ON_WM_DESTROY()
|
|
|
|
ON_COMMAND(ID_EDITPREFITEM, OnEditPrefItem)
|
|
|
|
ON_COMMAND(ID_FINDPREF, OnFindPref)
|
|
|
|
ON_COMMAND(ID_FINDNEXTPREF, OnFindNextPref)
|
|
|
|
ON_COMMAND(ID_ADDPREF, OnAddPref)
|
2002-01-28 19:09:00 +00:00
|
|
|
ON_COMMAND(ID_DELPREF, OnDelPref)
|
2001-12-18 17:56:45 +00:00
|
|
|
ON_WM_KEYDOWN()
|
|
|
|
//}}AFX_MSG_MAP
|
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CPrefEditView construction/destruction
|
|
|
|
|
|
|
|
// Protected.
|
|
|
|
CPrefEditView::CPrefEditView()
|
2001-12-28 21:17:11 +00:00
|
|
|
: m_hgroup(NULL), m_pParsingPrefElement(NULL), m_hNextFind(NULL)
|
2001-12-18 17:56:45 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CPrefEditView::CPrefEditView(CString strXMLFile)
|
2001-12-28 21:17:11 +00:00
|
|
|
: m_strXMLFile(strXMLFile), m_hgroup(NULL), m_pParsingPrefElement(NULL), m_hNextFind(NULL)
|
2001-12-18 17:56:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CPrefEditView::~CPrefEditView()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CPrefEditView::PreCreateWindow(CREATESTRUCT& cs)
|
|
|
|
{
|
|
|
|
cs.style |= TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
|
|
|
|
return CTreeView::PreCreateWindow(cs);
|
|
|
|
}
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
|
|
|
|
|
2001-12-18 17:56:45 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CPrefEditView public operations
|
2001-12-28 21:17:11 +00:00
|
|
|
//
|
|
|
|
// These are for controls outside this view to call, for example, buttons
|
|
|
|
// on the same wizard page as this view.
|
|
|
|
//
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Expand the tree, or open the selected item for edit.
|
2001-12-18 17:56:45 +00:00
|
|
|
void CPrefEditView::DoOpenItem()
|
|
|
|
{
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
HTREEITEM hTreeCtrlItem = treeCtrl.GetSelectedItem();
|
|
|
|
if (!treeCtrl.ItemHasChildren(hTreeCtrlItem)) // no children == leaf node == pref
|
|
|
|
{
|
|
|
|
EditSelectedPrefsItem();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
treeCtrl.Expand(hTreeCtrlItem, TVE_TOGGLE);
|
2002-07-24 03:04:12 +00:00
|
|
|
|
|
|
|
// This doesn't call OnExpanded() as you'd expect. Fix up the images.
|
|
|
|
if (treeCtrl.GetItemState(hTreeCtrlItem, TVIS_EXPANDED) & TVIS_EXPANDED)
|
|
|
|
treeCtrl.SetItemImage(hTreeCtrlItem, bm_openFolder, bm_openFolder);
|
|
|
|
else
|
|
|
|
treeCtrl.SetItemImage(hTreeCtrlItem, bm_closedFolder, bm_closedFolder);
|
2001-12-18 17:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Open the Find Pref dialog.
|
2001-12-18 17:56:45 +00:00
|
|
|
void CPrefEditView::DoFindFirst()
|
|
|
|
{
|
|
|
|
OnFindPref();
|
|
|
|
}
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Find next item.
|
2001-12-18 17:56:45 +00:00
|
|
|
void CPrefEditView::DoFindNext()
|
|
|
|
{
|
|
|
|
OnFindNextPref();
|
|
|
|
}
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Open the Add Pref dialog.
|
2001-12-18 17:56:45 +00:00
|
|
|
void CPrefEditView::DoAdd()
|
|
|
|
{
|
|
|
|
OnAddPref();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CPrefEditView diagnostics
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
void CPrefEditView::AssertValid() const
|
|
|
|
{
|
|
|
|
CTreeView::AssertValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPrefEditView::Dump(CDumpContext& dc) const
|
|
|
|
{
|
|
|
|
CTreeView::Dump(dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //_DEBUG
|
|
|
|
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// ItemData in some tree control element was created with new, so we need to
|
2001-12-18 17:56:45 +00:00
|
|
|
// delete it.
|
|
|
|
void CPrefEditView::DeleteTreeCtrl(HTREEITEM hParent)
|
|
|
|
{
|
|
|
|
ASSERT(hParent);
|
|
|
|
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
|
2005-11-25 21:57:13 +00:00
|
|
|
// Delete the prefelement object we created with new.
|
2001-12-28 21:17:11 +00:00
|
|
|
CPrefElement* pe = (CPrefElement*)treeCtrl.GetItemData(hParent);
|
|
|
|
delete pe;
|
2001-12-18 17:56:45 +00:00
|
|
|
|
|
|
|
// Now call recursively for all children.
|
|
|
|
HTREEITEM hCurrent = treeCtrl.GetNextItem(hParent, TVGN_CHILD);
|
|
|
|
while (hCurrent != NULL)
|
|
|
|
{
|
|
|
|
DeleteTreeCtrl(hCurrent);
|
|
|
|
hCurrent = treeCtrl.GetNextItem(hCurrent, TVGN_NEXT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CPrefEditView message handlers
|
|
|
|
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Given a pref name, returns the tree control item for it.
|
2001-12-18 17:56:45 +00:00
|
|
|
HTREEITEM CPrefEditView::FindTreeItemFromPrefname(HTREEITEM hItem, CString& rstrPrefName)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!hItem)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Get the pref name associated with this tree ctrl item.
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
2001-12-28 21:17:11 +00:00
|
|
|
CPrefElement* pe = (CPrefElement*)treeCtrl.GetItemData(hItem);
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
if (pe && pe->GetPrefName().CompareNoCase(rstrPrefName) == 0)
|
2001-12-18 17:56:45 +00:00
|
|
|
return hItem;
|
|
|
|
|
|
|
|
HTREEITEM hRet = NULL;
|
|
|
|
HTREEITEM hChild = treeCtrl.GetChildItem(hItem);
|
|
|
|
if(hChild)
|
|
|
|
hRet = FindTreeItemFromPrefname(hChild, rstrPrefName);
|
|
|
|
|
|
|
|
if(hRet == NULL)
|
|
|
|
{
|
|
|
|
HTREEITEM hSibling = treeCtrl.GetNextSiblingItem(hItem);
|
|
|
|
if(hSibling)
|
|
|
|
hRet = FindTreeItemFromPrefname(hSibling, rstrPrefName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hRet;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Open a dialog to edit the pref.
|
|
|
|
void CPrefEditView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
|
|
|
|
{
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
HTREEITEM hTreeCtrlItem = treeCtrl.GetSelectedItem();
|
|
|
|
if (!treeCtrl.ItemHasChildren(hTreeCtrlItem)) // no children == leaf node == pref
|
|
|
|
{
|
|
|
|
EditSelectedPrefsItem();
|
|
|
|
*pResult = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Called by the XML parser when a new element is read.
|
|
|
|
// Turn around and call the prefView object.
|
|
|
|
static void startElementC(void *userData, const char *name, const char **atts)
|
|
|
|
{
|
|
|
|
((CPrefEditView*)userData)->startElement(name, atts);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called by the XML parser when new data is read.
|
|
|
|
// Turn around and call the prefView object.
|
|
|
|
static void characterDataC(void *userData, const XML_Char *s, int len)
|
|
|
|
{
|
|
|
|
((CPrefEditView*)userData)->characterData(s, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called by the XML parser when an element close tag is read.
|
|
|
|
// Turn around and call the prefView object.
|
|
|
|
static void endElementC(void *userData, const char *name)
|
|
|
|
{
|
|
|
|
((CPrefEditView*)userData)->endElement(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XML parser helper. Called when start of an element tag is encountered.
|
|
|
|
void CPrefEditView::startElement(const char *name, const char **atts)
|
|
|
|
{
|
|
|
|
// If new prefsgroup, add an item to the tree control to hold other items.
|
|
|
|
if (stricmp(name, "PREFSGROUP") == 0)
|
|
|
|
{
|
|
|
|
// Assumes this element has one tag and that it's the uiname for the group.
|
|
|
|
CString strLabel = atts[1];
|
|
|
|
|
|
|
|
// Open a new level in the tree control.
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
2002-07-24 03:04:12 +00:00
|
|
|
m_hgroup = treeCtrl.InsertItem( strLabel, bm_closedFolder, bm_closedFolder, m_hgroup, TVI_LAST);
|
2001-12-28 21:17:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// If new pref element, create a new pref element, and let it handle its own
|
|
|
|
// initialization from the atts.
|
|
|
|
else if (stricmp(name, "PREF") == 0)
|
|
|
|
{
|
|
|
|
// Can't have nested pref elements.
|
|
|
|
ASSERT(m_pParsingPrefElement == NULL);
|
|
|
|
m_pParsingPrefElement = new CPrefElement;
|
|
|
|
}
|
|
|
|
|
2002-05-21 02:22:23 +00:00
|
|
|
else if (stricmp(name, "METAPREFS") == 0)
|
|
|
|
{
|
|
|
|
ASSERT(atts[2]); // there must be a clientversion and subversion attribute
|
|
|
|
|
|
|
|
// Process the list of attribute/value pairs.
|
|
|
|
int i = 0;
|
|
|
|
while(atts[i])
|
|
|
|
{
|
|
|
|
const char* attrName = atts[i++];
|
|
|
|
const char* attrVal = atts[i++];
|
|
|
|
|
|
|
|
if (stricmp(attrName, "clientversion") == 0)
|
|
|
|
m_strXMLVersion = attrVal;
|
|
|
|
else if (stricmp(attrName, "subversion") == 0)
|
|
|
|
m_strXMLSubVersion = attrVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Pass on all subelements to the pref element object to handle.
|
|
|
|
if (m_pParsingPrefElement)
|
|
|
|
m_pParsingPrefElement->startElement(name, atts);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// XML parser helper. Called when non-tag stuff is encountered.
|
|
|
|
void CPrefEditView::characterData(const XML_Char *s, int len)
|
|
|
|
{
|
|
|
|
// Let the prefs element handle it.
|
|
|
|
if (m_pParsingPrefElement)
|
|
|
|
m_pParsingPrefElement->characterData(s, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XML parser helper. Called when closing tag is found.
|
|
|
|
void CPrefEditView::endElement(const char *name)
|
|
|
|
{
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
|
|
|
|
if (stricmp(name, "PREFSGROUP") == 0)
|
|
|
|
{
|
|
|
|
// back up one level in the tree control
|
|
|
|
ASSERT(m_hgroup);
|
|
|
|
m_hgroup = treeCtrl.GetParentItem(m_hgroup);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (stricmp(name, "PREF") == 0)
|
|
|
|
{
|
|
|
|
ASSERT(m_pParsingPrefElement);
|
|
|
|
|
|
|
|
if (m_pParsingPrefElement)
|
|
|
|
m_pParsingPrefElement->endElement(name);
|
|
|
|
|
|
|
|
// Pref tag is closed. Add this pref to current group in the tree control.
|
|
|
|
InsertPrefElement(m_pParsingPrefElement, m_hgroup);
|
|
|
|
|
|
|
|
m_pParsingPrefElement = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert pref element into the tree control in the specified group.
|
|
|
|
HTREEITEM CPrefEditView::InsertPrefElement(CPrefElement* pe, HTREEITEM group)
|
|
|
|
{
|
|
|
|
ASSERT(pe);
|
|
|
|
ASSERT(group);
|
|
|
|
|
2002-07-24 03:04:12 +00:00
|
|
|
int imageIndex = bm_closedFolder;
|
|
|
|
|
2002-02-14 22:31:23 +00:00
|
|
|
if (pe->IsDefault())
|
2002-07-24 03:04:12 +00:00
|
|
|
imageIndex = bm_unlockedPadGray;
|
2001-12-28 21:17:11 +00:00
|
|
|
else
|
2002-07-24 03:04:12 +00:00
|
|
|
imageIndex = bm_unlockedPad;
|
2001-12-28 21:17:11 +00:00
|
|
|
|
2002-07-24 03:04:12 +00:00
|
|
|
if (pe->IsLocked() && pe->IsLockable())
|
|
|
|
imageIndex = bm_lockedPad;
|
2002-02-14 22:31:23 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
2002-07-24 03:04:12 +00:00
|
|
|
HTREEITEM hNewItem = treeCtrl.InsertItem(ConvertUTF8toANSI(pe->GetPrettyNameValueString()), imageIndex, imageIndex, group, TVI_LAST);
|
2001-12-28 21:17:11 +00:00
|
|
|
|
|
|
|
// Save pointer to this pref element in the tree.
|
|
|
|
treeCtrl.SetItemData(hNewItem, (DWORD)pe);
|
|
|
|
|
|
|
|
return hNewItem;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the tree control with data from the XML file.
|
|
|
|
BOOL CPrefEditView::LoadTreeControl()
|
2001-12-18 17:56:45 +00:00
|
|
|
{
|
2001-12-28 21:17:11 +00:00
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
m_hgroup = treeCtrl.GetRootItem();
|
|
|
|
|
|
|
|
XML_Parser parser = XML_ParserCreate(NULL);
|
|
|
|
XML_SetElementHandler(parser, startElementC, endElementC);
|
|
|
|
XML_SetCharacterDataHandler(parser, characterDataC);
|
|
|
|
XML_SetUserData(parser, this);
|
|
|
|
|
|
|
|
// Load the XML from the file.
|
|
|
|
CString strPrefsXML;
|
|
|
|
FILE* pFile = fopen(m_strXMLFile, "r");
|
|
|
|
if (!pFile)
|
|
|
|
{
|
|
|
|
CString strMsg;
|
|
|
|
strMsg.Format("Can't open the file %s.", m_strXMLFile);
|
|
|
|
AfxMessageBox(strMsg, MB_OK);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// obtain file size.
|
|
|
|
fseek(pFile , 0 , SEEK_END);
|
|
|
|
long lSize = ftell(pFile);
|
|
|
|
rewind(pFile);
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// allocate memory to contain the whole file.
|
|
|
|
char* buffer = (char*) malloc (lSize + 1);
|
|
|
|
if (buffer == NULL)
|
|
|
|
{
|
|
|
|
AfxMessageBox("Memory allocation error.", MB_OK);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
buffer[lSize] = '\0';
|
|
|
|
|
|
|
|
// copy the file into the buffer.
|
|
|
|
size_t len = fread(buffer,1,lSize,pFile);
|
|
|
|
|
|
|
|
// The whole file is loaded in the buffer.
|
|
|
|
|
|
|
|
int done = 0;
|
|
|
|
if (!XML_Parse(parser, buffer, len, done))
|
|
|
|
{
|
|
|
|
CString strMsg;
|
|
|
|
strMsg.Format("%s in file %s at line %d.",XML_ErrorString(XML_GetErrorCode(parser)), m_strXMLFile, XML_GetCurrentLineNumber(parser));
|
|
|
|
AfxMessageBox(strMsg, MB_OK);
|
|
|
|
free(buffer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
XML_ParserFree(parser);
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int CPrefEditView::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
|
|
{
|
2001-12-18 17:56:45 +00:00
|
|
|
if (CTreeView::OnCreate(lpCreateStruct) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// Get the tree control.
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
|
|
|
|
// create the image list for the tree control
|
|
|
|
m_imageList.Create(IDB_TREEIMAGES, 17, 1, RGB(0,255,255));
|
|
|
|
treeCtrl.SetImageList (&m_imageList, TVSIL_NORMAL);
|
|
|
|
|
|
|
|
HTREEITEM hRoot = treeCtrl.GetRootItem();
|
|
|
|
if (hRoot)
|
|
|
|
DeleteTreeCtrl(hRoot);
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Load the tree control so it matches the XML.
|
|
|
|
LoadTreeControl();
|
2001-12-18 17:56:45 +00:00
|
|
|
|
|
|
|
treeCtrl.Expand(treeCtrl.GetRootItem(), TVE_EXPAND);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CPrefEditView::OnDestroy()
|
|
|
|
{
|
|
|
|
// Clean up tree ctrl pref name memory allocations.
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
HTREEITEM hRoot = treeCtrl.GetRootItem();
|
|
|
|
if (hRoot)
|
|
|
|
DeleteTreeCtrl(hRoot);
|
|
|
|
|
|
|
|
CTreeView::OnDestroy();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find a pref containing a string in one of its fields.
|
|
|
|
BOOL CPrefEditView::FindFirst(CString& rstrFind)
|
|
|
|
{
|
2001-12-28 21:17:11 +00:00
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
m_hNextFind = treeCtrl.GetRootItem();
|
2001-12-18 17:56:45 +00:00
|
|
|
m_strFind = rstrFind;
|
|
|
|
|
|
|
|
return FindNext();
|
|
|
|
}
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Returns the next item in the tree control.
|
|
|
|
HTREEITEM CPrefEditView::GetNextItem(HTREEITEM hItem)
|
|
|
|
{
|
|
|
|
HTREEITEM hti;
|
|
|
|
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
if (treeCtrl.ItemHasChildren(hItem))
|
|
|
|
{
|
|
|
|
return treeCtrl.GetChildItem(hItem); // return first child
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// return next sibling item
|
|
|
|
// Go up the tree to find a parent's sibling if needed.
|
|
|
|
while((hti = treeCtrl.GetNextSiblingItem(hItem)) == NULL)
|
|
|
|
{
|
|
|
|
if((hItem = treeCtrl.GetParentItem(hItem)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hti;
|
|
|
|
}
|
|
|
|
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
|
|
|
|
// Find next match. Assumes FindFirst was called first.
|
2001-12-18 17:56:45 +00:00
|
|
|
BOOL CPrefEditView::FindNext()
|
|
|
|
{
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
if ((m_hNextFind == NULL) || m_strFind.IsEmpty())
|
2001-12-18 17:56:45 +00:00
|
|
|
return FALSE;
|
2001-12-28 21:17:11 +00:00
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
while (m_hNextFind)
|
2001-12-18 17:56:45 +00:00
|
|
|
{
|
2001-12-28 21:17:11 +00:00
|
|
|
CPrefElement* pe = (CPrefElement*)treeCtrl.GetItemData(m_hNextFind);
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
if (pe && pe->FindString(m_strFind))
|
2001-12-18 17:56:45 +00:00
|
|
|
{
|
2001-12-28 21:17:11 +00:00
|
|
|
treeCtrl.SelectItem(m_hNextFind);
|
|
|
|
m_hNextFind = GetNextItem(m_hNextFind);
|
2001-12-18 17:56:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
m_hNextFind = GetNextItem(m_hNextFind);
|
|
|
|
|
2001-12-18 17:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AfxMessageBox("No more matches.", MB_OK);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Save this item and all children to a file as XML. Recursive.
|
|
|
|
void CPrefEditView::WriteXMLItem(FILE* fp, int iLevel, HTREEITEM hItem)
|
|
|
|
{
|
|
|
|
ASSERT(fp);
|
|
|
|
ASSERT(iLevel >= 0);
|
|
|
|
ASSERT(hItem != NULL);
|
|
|
|
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
|
|
|
|
const int iIndentSize = 2;
|
|
|
|
int iIndent = iLevel * iIndentSize;
|
|
|
|
|
|
|
|
// for this item and all siblings
|
|
|
|
while (hItem)
|
|
|
|
{
|
|
|
|
// if has children, then it's a PREFSGROUP
|
|
|
|
if (treeCtrl.ItemHasChildren(hItem))
|
|
|
|
{
|
|
|
|
// write the opening group tag
|
|
|
|
CString strTag;
|
|
|
|
strTag.Format("%*s<PREFSGROUP uiname=\"%s\">\n\n", iIndent, " ", treeCtrl.GetItemText(hItem));
|
|
|
|
fwrite(strTag, strTag.GetLength(), 1, fp);
|
|
|
|
|
|
|
|
// call self on first child
|
|
|
|
WriteXMLItem(fp, iLevel+1, treeCtrl.GetChildItem(hItem));
|
|
|
|
|
|
|
|
// write the closing tag
|
|
|
|
strTag.Format("%*s</PREFSGROUP>\n\n", iIndent, " ");
|
|
|
|
fwrite(strTag, strTag.GetLength(), 1, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no children, then it's a PREF
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// write the opening pref tag
|
|
|
|
// write the info
|
|
|
|
// write the closing pref tag
|
|
|
|
|
|
|
|
CPrefElement* pe = (CPrefElement*)treeCtrl.GetItemData(hItem);
|
|
|
|
ASSERT(pe);
|
|
|
|
if (pe)
|
|
|
|
{
|
|
|
|
CString strElement = pe->XML(iIndentSize, iLevel);
|
|
|
|
strElement += "\n";
|
|
|
|
fwrite(strElement, strElement.GetLength(), 1, fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hItem = treeCtrl.GetNextSiblingItem(hItem);
|
|
|
|
}
|
|
|
|
}
|
2001-12-18 17:56:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Save the XML to a file.
|
|
|
|
BOOL CPrefEditView::DoSavePrefsTree(CString strFile)
|
|
|
|
{
|
|
|
|
FILE* fp = fopen(strFile, "w");
|
|
|
|
if (!fp)
|
|
|
|
return FALSE;
|
|
|
|
|
2002-04-25 18:43:33 +00:00
|
|
|
CString strPreamble("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");
|
2001-12-18 17:56:45 +00:00
|
|
|
if (!fwrite(strPreamble, strPreamble.GetLength(), 1, fp))
|
2001-12-28 21:17:11 +00:00
|
|
|
{
|
|
|
|
fclose(fp);
|
2001-12-18 17:56:45 +00:00
|
|
|
return FALSE;
|
2001-12-28 21:17:11 +00:00
|
|
|
}
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2002-05-21 02:22:23 +00:00
|
|
|
// start the outermost tag
|
|
|
|
CString strOuter;
|
|
|
|
strOuter.Format("<METAPREFS clientversion=\"%s\" subversion=\"%s\">\n\n", m_strXMLVersion, m_strXMLSubVersion);
|
|
|
|
fwrite(strOuter, strOuter.GetLength(), 1, fp);
|
|
|
|
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
HTREEITEM hRoot = treeCtrl.GetRootItem();
|
|
|
|
WriteXMLItem(fp, 1, hRoot);
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2002-05-21 02:22:23 +00:00
|
|
|
// close the outermost tag
|
|
|
|
strOuter = "</METAPREFS>";
|
|
|
|
fwrite(strOuter, strOuter.GetLength(), 1, fp);
|
|
|
|
|
2001-12-18 17:56:45 +00:00
|
|
|
fclose(fp);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pop up menu for Pref items.
|
|
|
|
void CPrefEditView::ShowPopupMenu( CPoint& point, int submenu )
|
|
|
|
{
|
|
|
|
if (point.x == -1 && point.y == -1)
|
|
|
|
{
|
|
|
|
//keystroke invocation
|
|
|
|
CRect rect;
|
|
|
|
GetClientRect(rect);
|
|
|
|
ClientToScreen(rect);
|
|
|
|
|
|
|
|
point = rect.TopLeft();
|
|
|
|
point.Offset(5, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
CMenu menu;
|
|
|
|
VERIFY(menu.LoadMenu(IDR_POPUP_PREFTREE_MENU));
|
|
|
|
|
|
|
|
CMenu* pPopup = menu.GetSubMenu(submenu);
|
|
|
|
ASSERT(pPopup != NULL);
|
|
|
|
CWnd* pWndPopupOwner = this;
|
|
|
|
|
|
|
|
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
// "Edit Pref" context menu command selected.
|
|
|
|
void CPrefEditView::OnEditPrefItem()
|
|
|
|
{
|
|
|
|
EditSelectedPrefsItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
// "Find Pref" context menu command selected.
|
|
|
|
void CPrefEditView::OnFindPref()
|
|
|
|
{
|
|
|
|
CDlgFind dlg;
|
|
|
|
if (dlg.DoModal() == IDOK)
|
|
|
|
if (!dlg.m_strFind.IsEmpty())
|
2002-04-25 18:43:33 +00:00
|
|
|
FindFirst(ConvertANSItoUTF8(dlg.m_strFind));
|
2001-12-18 17:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// "Find Next Pref" context menu command selected.
|
|
|
|
void CPrefEditView::OnFindNextPref()
|
|
|
|
{
|
|
|
|
// If FindFirst not done before FindNext, call FindFirst first.
|
2001-12-28 21:17:11 +00:00
|
|
|
if (m_hNextFind == NULL)
|
2001-12-18 17:56:45 +00:00
|
|
|
OnFindPref();
|
|
|
|
else
|
|
|
|
FindNext();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// User added prefs go into the root group.
|
|
|
|
HTREEITEM CPrefEditView::AddPref(CString& rstrPrefName, CString& rstrPrefDesc, CString& rstrPrefType)
|
|
|
|
{
|
2002-01-28 19:09:00 +00:00
|
|
|
// Create it.
|
2001-12-28 21:17:11 +00:00
|
|
|
CPrefElement* newPref = new CPrefElement(rstrPrefName, rstrPrefDesc, rstrPrefType);
|
2002-01-28 19:09:00 +00:00
|
|
|
|
|
|
|
newPref->SetUserAdded(TRUE);
|
2001-12-28 21:17:11 +00:00
|
|
|
|
|
|
|
// Add it to the tree.
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
HTREEITEM hRoot = treeCtrl.GetRootItem();
|
|
|
|
ASSERT(hRoot);
|
|
|
|
if (hRoot)
|
2001-12-18 17:56:45 +00:00
|
|
|
{
|
2001-12-28 21:17:11 +00:00
|
|
|
HTREEITEM hNewItem = InsertPrefElement(newPref, hRoot);
|
|
|
|
treeCtrl.SelectItem(hNewItem);
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
EditSelectedPrefsItem();
|
2001-12-18 17:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open dialog to add a new pref, then open another to edit it.
|
|
|
|
void CPrefEditView::OnAddPref()
|
|
|
|
{
|
|
|
|
CDlgAdd dlg;
|
|
|
|
if (dlg.DoModal() == IDOK)
|
|
|
|
{
|
|
|
|
if (dlg.m_strPrefName.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CString strPrefType;
|
|
|
|
if (dlg.m_intPrefType == 0)
|
|
|
|
strPrefType = "string";
|
|
|
|
else if (dlg.m_intPrefType == 1)
|
|
|
|
strPrefType = "int";
|
|
|
|
else
|
|
|
|
strPrefType = "bool";
|
|
|
|
|
|
|
|
// Disallow if the pref name already exists.
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
HTREEITEM hRoot = treeCtrl.GetRootItem();
|
2002-04-25 18:43:33 +00:00
|
|
|
HTREEITEM hTreeCtrlItem = FindTreeItemFromPrefname(hRoot, ConvertANSItoUTF8(dlg.m_strPrefName));
|
2001-12-18 17:56:45 +00:00
|
|
|
if (hTreeCtrlItem)
|
|
|
|
{
|
|
|
|
MessageBox("A pref of this name already exists.", MB_OK);
|
|
|
|
treeCtrl.SelectItem(hTreeCtrlItem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-04-25 18:43:33 +00:00
|
|
|
// Anything in the XML file must be in UTF-8. User might have entered Hi-ASCII and that would throw off XML parser.
|
|
|
|
AddPref(ConvertANSItoUTF8(dlg.m_strPrefName), ConvertANSItoUTF8(dlg.m_strPrefDesc), ConvertANSItoUTF8(strPrefType));
|
2001-12-18 17:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-01-28 19:09:00 +00:00
|
|
|
// Delete the user-added pref.
|
|
|
|
void CPrefEditView::OnDelPref()
|
|
|
|
{
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
HTREEITEM hTreeCtrlItem = treeCtrl.GetSelectedItem();
|
|
|
|
|
|
|
|
// Can't edit a pref group--only a pref (leaf).
|
|
|
|
if (treeCtrl.ItemHasChildren(hTreeCtrlItem))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If user added-pref, delete the CPrefElement that was created with new.
|
|
|
|
CPrefElement* pe = (CPrefElement*)treeCtrl.GetItemData(hTreeCtrlItem);
|
|
|
|
ASSERT(pe); // There must be a CPrefElement object for each pref in the tree.
|
|
|
|
if ((pe == NULL) || !pe->IsUserAdded())
|
|
|
|
return;
|
|
|
|
|
|
|
|
delete pe;
|
|
|
|
|
|
|
|
// Remove item from the tree.
|
|
|
|
treeCtrl.DeleteItem(hTreeCtrlItem);
|
|
|
|
}
|
|
|
|
|
2001-12-18 17:56:45 +00:00
|
|
|
// Open the edit dialog box for the selected pref item. A pref should be selected,
|
|
|
|
// not a group.
|
|
|
|
void CPrefEditView::EditSelectedPrefsItem()
|
|
|
|
{
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
HTREEITEM hTreeCtrlItem = treeCtrl.GetSelectedItem();
|
|
|
|
|
|
|
|
ASSERT(!treeCtrl.ItemHasChildren(hTreeCtrlItem)); // no children == leaf node == pref
|
|
|
|
|
|
|
|
// Can't edit a pref group--only a pref (leaf).
|
|
|
|
if (treeCtrl.ItemHasChildren(hTreeCtrlItem))
|
|
|
|
return;
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
CPrefElement* pe = (CPrefElement*)treeCtrl.GetItemData(hTreeCtrlItem);
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
ASSERT(pe);
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
if (!pe)
|
2001-12-18 17:56:45 +00:00
|
|
|
return;
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
CDlgEditPrefStr dlg;
|
2002-04-25 18:43:33 +00:00
|
|
|
dlg.m_strType = pe->GetPrefType(); // internal use only -- always ANSI
|
|
|
|
dlg.m_strTitle = ConvertUTF8toANSI(pe->GetUIName());
|
|
|
|
dlg.m_strDescription = ConvertUTF8toANSI(pe->GetPrefDescription());
|
|
|
|
dlg.m_strPrefName = ConvertUTF8toANSI(pe->GetPrefName());
|
|
|
|
dlg.m_strValue = ConvertUTF8toANSI(pe->GetPrefValue());
|
2001-12-28 21:17:11 +00:00
|
|
|
dlg.m_bLocked = pe->IsLocked();
|
2002-04-25 18:43:33 +00:00
|
|
|
dlg.m_pstrChoices = pe->GetChoiceStringArray(); // internal use only -- always ANSI
|
2001-12-28 21:17:11 +00:00
|
|
|
dlg.m_strSelectedChoice = pe->GetSelectedChoiceString();
|
|
|
|
dlg.m_bChoose = pe->IsChoose();
|
2002-02-14 22:31:23 +00:00
|
|
|
dlg.m_bRemoteAdmin = pe->IsRemoteAdmin();
|
2002-01-30 03:21:40 +00:00
|
|
|
dlg.m_bLockable = pe->IsLockable();
|
2002-02-14 22:31:23 +00:00
|
|
|
if (pe->IsChoose())
|
2002-04-25 18:43:33 +00:00
|
|
|
dlg.m_strDefault = pe->GetDefaultChoiceString(); // internal use only -- always ANSI
|
2002-02-14 22:31:23 +00:00
|
|
|
else
|
2002-04-25 18:43:33 +00:00
|
|
|
dlg.m_strDefault = ConvertUTF8toANSI(pe->GetDefaultValue());
|
2001-12-28 21:17:11 +00:00
|
|
|
|
|
|
|
if (dlg.DoModal() == IDOK)
|
2001-12-18 17:56:45 +00:00
|
|
|
{
|
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Adjust the prefs tree to reflect the changes. The dialog always
|
|
|
|
// sets m_strValue to a string which can go directly into the prefs
|
|
|
|
// tree element. For example, bools set 'true' or 'false' and choices
|
|
|
|
// set '0' or '1' or whatever the value for the selected choice.
|
2002-04-25 18:43:33 +00:00
|
|
|
pe->SetPrefValue(ConvertANSItoUTF8(dlg.m_strValue));
|
2001-12-28 21:17:11 +00:00
|
|
|
pe->SetLocked(dlg.m_bLocked);
|
2002-02-14 22:31:23 +00:00
|
|
|
pe->SetRemoteAdmin(dlg.m_bRemoteAdmin);
|
2001-12-18 17:56:45 +00:00
|
|
|
|
2001-12-28 21:17:11 +00:00
|
|
|
// Adjust the tree control to reflect the changes.
|
2002-04-25 18:43:33 +00:00
|
|
|
treeCtrl.SetItemText(hTreeCtrlItem, ConvertUTF8toANSI(pe->GetPrettyNameValueString()));
|
2002-01-24 21:08:29 +00:00
|
|
|
|
|
|
|
int imageIndex = 0; // tree ctrl images
|
|
|
|
|
2002-02-14 22:31:23 +00:00
|
|
|
if (pe->IsDefault())
|
2002-07-24 03:04:12 +00:00
|
|
|
imageIndex = bm_unlockedPadGray;
|
2002-01-24 21:08:29 +00:00
|
|
|
else
|
2002-07-24 03:04:12 +00:00
|
|
|
imageIndex = bm_unlockedPad;
|
2002-01-24 21:08:29 +00:00
|
|
|
|
2002-07-24 03:04:12 +00:00
|
|
|
if (pe->IsLocked() && pe->IsLockable())
|
|
|
|
imageIndex = bm_lockedPad;
|
2002-01-24 21:08:29 +00:00
|
|
|
|
2002-07-24 03:04:12 +00:00
|
|
|
treeCtrl.SetItemImage(hTreeCtrlItem, imageIndex, imageIndex);
|
2002-07-23 17:26:22 +00:00
|
|
|
|
2001-12-18 17:56:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is to make context menus work properly--there is a quirk in
|
|
|
|
// CTreeView where you have to double-right click for context menus
|
|
|
|
// to work.
|
|
|
|
void CPrefEditView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
|
|
|
|
{
|
|
|
|
CTreeCtrl & treeCtrl = GetTreeCtrl();
|
|
|
|
|
|
|
|
// Get the cursor position for this message
|
|
|
|
DWORD dwPos = GetMessagePos();
|
|
|
|
|
|
|
|
// Convert the coords into a CPoint structure
|
|
|
|
CPoint pt(LOWORD( dwPos ), HIWORD( dwPos ));
|
|
|
|
CPoint spt;
|
|
|
|
|
|
|
|
spt = pt;
|
|
|
|
|
|
|
|
// convert to screen coords for the hittesting to work
|
|
|
|
treeCtrl.ScreenToClient( &spt );
|
|
|
|
|
|
|
|
UINT test;
|
|
|
|
HTREEITEM hTreeCtrlItem = treeCtrl.HitTest(spt, &test);
|
|
|
|
|
|
|
|
if (hTreeCtrlItem != NULL)
|
|
|
|
{
|
|
|
|
// Is the click actually *on* the item?
|
|
|
|
if (test & TVHT_ONITEM)
|
|
|
|
{
|
|
|
|
// Select the item.
|
|
|
|
treeCtrl.SelectItem(hTreeCtrlItem);
|
|
|
|
|
|
|
|
int submenu;
|
|
|
|
if (!treeCtrl.ItemHasChildren(hTreeCtrlItem)) // no children == leaf node == pref
|
2002-01-28 19:09:00 +00:00
|
|
|
{
|
|
|
|
CPrefElement* pe = (CPrefElement*)treeCtrl.GetItemData(hTreeCtrlItem);
|
|
|
|
ASSERT(pe); // there must be a CPrefElement object for each leaf node.
|
|
|
|
if (!pe)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pe->IsUserAdded())
|
|
|
|
submenu = menu_userAddedPref;
|
|
|
|
else
|
|
|
|
submenu = menu_pref;
|
|
|
|
}
|
2001-12-18 17:56:45 +00:00
|
|
|
else
|
2002-01-28 19:09:00 +00:00
|
|
|
{
|
|
|
|
submenu = menu_group;
|
|
|
|
}
|
2001-12-18 17:56:45 +00:00
|
|
|
|
|
|
|
ShowPopupMenu(pt, submenu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pResult = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPrefEditView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
|
|
|
|
{
|
|
|
|
if (nChar == VK_F3)
|
|
|
|
{
|
|
|
|
OnFindNextPref();
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ((nChar == 0x46) && GetAsyncKeyState(VK_CONTROL)) // Ctrl+F
|
|
|
|
{
|
|
|
|
OnFindPref();
|
|
|
|
}
|
|
|
|
|
2002-01-28 19:09:00 +00:00
|
|
|
else if (nChar == VK_DELETE)
|
|
|
|
{
|
|
|
|
OnDelPref();
|
|
|
|
}
|
|
|
|
|
2001-12-18 17:56:45 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CTreeView::OnKeyDown(nChar, nRepCnt, nFlags);
|
|
|
|
}
|
|
|
|
}
|
2002-07-23 17:26:22 +00:00
|
|
|
|
|
|
|
// Check to see if any of the prefs were marked for remote admin
|
|
|
|
// if any have, set the global RemoteAdminFound to true
|
|
|
|
|
2002-07-24 03:04:12 +00:00
|
|
|
BOOL CPrefEditView::CheckForRemoteAdmins()
|
2002-07-23 17:26:22 +00:00
|
|
|
{
|
2002-07-30 23:02:39 +00:00
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
HTREEITEM hRoot = treeCtrl.GetRootItem();
|
2002-07-23 17:26:22 +00:00
|
|
|
|
2002-07-30 23:02:39 +00:00
|
|
|
return (IsRemoteAdministered(hRoot) ? TRUE : FALSE);
|
2002-07-23 17:26:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Given a tree item, returns TRUE if it or any children are remote
|
|
|
|
// administered
|
|
|
|
bool CPrefEditView::IsRemoteAdministered(HTREEITEM hItem)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(!hItem)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// Get the pref name associated with this tree ctrl item.
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
CPrefElement* pe = (CPrefElement*)treeCtrl.GetItemData(hItem);
|
|
|
|
|
|
|
|
if (pe && pe->IsRemoteAdmin())
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
bool bRemoted = FALSE;
|
|
|
|
HTREEITEM hChild = treeCtrl.GetChildItem(hItem);
|
|
|
|
|
|
|
|
if(hChild)
|
|
|
|
bRemoted = IsRemoteAdministered(hChild);
|
|
|
|
|
|
|
|
if(bRemoted == FALSE)
|
|
|
|
{
|
|
|
|
HTREEITEM hSibling = treeCtrl.GetNextSiblingItem(hItem);
|
|
|
|
if(hSibling)
|
|
|
|
bRemoted = IsRemoteAdministered(hSibling);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRemoted;
|
|
|
|
|
|
|
|
}
|
2002-07-24 03:04:12 +00:00
|
|
|
|
|
|
|
// Show expanded groups as open folder, collapsed groups as closed folder.
|
|
|
|
void CPrefEditView::OnExpanded(NMHDR* pNMHDR, LRESULT* pResult)
|
|
|
|
{
|
|
|
|
LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)pNMHDR;
|
|
|
|
|
|
|
|
if (pnmtv)
|
|
|
|
{
|
|
|
|
int imageIndex = 0; // tree ctrl images
|
|
|
|
|
|
|
|
HTREEITEM hTreeCtrlItem = pnmtv->itemNew.hItem;
|
|
|
|
if (hTreeCtrlItem)
|
|
|
|
{
|
|
|
|
CTreeCtrl &treeCtrl = GetTreeCtrl();
|
|
|
|
if ((pnmtv->itemNew.state & TVIS_EXPANDED) == TVIS_EXPANDED)
|
|
|
|
treeCtrl.SetItemImage(hTreeCtrlItem, bm_openFolder, bm_openFolder);
|
|
|
|
else
|
|
|
|
treeCtrl.SetItemImage(hTreeCtrlItem, bm_closedFolder, bm_closedFolder);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*pResult = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|