|
// EditCategoryDialog.cpp : implementation file
//
#include "stdafx.h"
#include "exile.h"
#include "EditCategoryDialog.h"
#include "Security.h"
#include "predefined.h"
#include "PasswordGeneratorDialog.h"
#include "ChangeIconDialog.h"
#include "messagebox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEditCategoryDialog dialog
CEditCategoryDialog::CEditCategoryDialog(CWnd* pParent /*=NULL*/)
: CDialog(CEditCategoryDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CEditCategoryDialog)
m_strCategoryName = _T("");
m_strDescription = _T("");
//}}AFX_DATA_INIT
m_cRating = 5;
}
CEditCategoryDialog::~CEditCategoryDialog()
{
}
void CEditCategoryDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEditCategoryDialog)
DDX_Control(pDX, IDC_RATING, m_ctrlRating);
DDX_Control(pDX, IDC_CATEGORYICON, m_ctrlCategoryIcon);
DDX_CBString(pDX, IDC_CATEGORYNAME, m_strCategoryName);
DDX_Text(pDX, IDC_DESCRIPTION, m_strDescription);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEditCategoryDialog, CDialog)
//{{AFX_MSG_MAP(CEditCategoryDialog)
ON_CBN_SELCHANGE(IDC_CATEGORYNAME, OnSelchangeCategoryname)
ON_BN_CLICKED(IDC_CHANGEICON, OnChangeicon)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEditCategoryDialog message handlers
BOOL CEditCategoryDialog::OnInitDialog()
{
CDialog::OnInitDialog();
CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_CATEGORYNAME);
for(int n = 0; n < sizeof(g_aCategories) / sizeof(g_aCategories[0]); ++n)
{
pCombo->AddString(g_aCategories[n].szName);
} // for
// Ratings
for(n = 0; n < sizeof(g_aRatings) / sizeof(g_aRatings[0]); ++n)
{
m_ctrlRating.InsertString(n, g_aRatings[n].szName);
m_ctrlRating.SetItemData(n, (DWORD)g_aRatings[n].cRating);
} // for
m_ctrlCategoryIcon.SetIcon(m_pimgList->ExtractIcon(m_lIconID));
m_ctrlRating.SetCurSel(10 - m_cRating);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CEditCategoryDialog::OnSelchangeCategoryname()
{
CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_CATEGORYNAME);
if(CB_ERR != pCombo->GetCurSel())
{
TCHAR szName[nNameLength];
pCombo->GetLBText(pCombo->GetCurSel(), szName);
// Look in predefined categories
for(int n = 0; n < sizeof(g_aCategories) / sizeof(g_aCategories[0]); ++n)
{
#ifdef _UNICODE
if(0 == wcscmp(szName, g_aCategories[n].szName))
{
m_strDescription = g_aCategories[n].szDescription;
m_strCategoryName = g_aCategories[n].szName;
m_ctrlCategoryIcon.SetIcon(m_pimgList->ExtractIcon(g_aCategories[n].lIconID));
m_lIconID = g_aCategories[n].lIconID;
UpdateData(FALSE);
break;
} // if
#else
if(0 == strcmp(szName, g_aCategories[n].szName))
{
m_strDescription = g_aCategories[n].szDescription;
m_strCategoryName = g_aCategories[n].szName;
m_ctrlCategoryIcon.SetIcon(m_pimgList->ExtractIcon(g_aCategories[n].lIconID));
m_lIconID = g_aCategories[n].lIconID;
UpdateData(FALSE);
break;;
} // if
#endif // _UNICODE
} // for
} // if
}
void CEditCategoryDialog::OnChangeicon()
{
CChangeIconDialog dlgChange;
dlgChange.SetImageList(m_pimgList);
if(IDOK == dlgChange.DoModal())
{
m_lIconID = dlgChange.GetIconID();
m_ctrlCategoryIcon.SetIcon(m_pimgList->ExtractIcon(m_lIconID));
} // if
}
void CEditCategoryDialog::OnOK()
{
UpdateData();
if(m_strCategoryName.IsEmpty())
{
MessageBoxEx(*this, (UINT)IDS_ENTERCATEGORYNAME, (UINT)IDS_TITLE, MB_OK | MB_ICONINFORMATION);
return;
} // if
if(CB_ERR == m_ctrlRating.GetCurSel())
{
MessageBoxEx(*this, IDS_SELECTRATING, IDS_TITLE);
return;
} // if
m_cRating = (BYTE)m_ctrlRating.GetItemData(m_ctrlRating.GetCurSel());
CDialog::OnOK();
}
|
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.
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