?? addthemedialog.cpp
字號:
// AddThemeDialog.cpp : implementation file
//
/* This sample application and corresponding sample code is provided
* for example purposes only. It has not undergone rigorous testing
* and as such should not be shipped as part of a final application
* without extensive testing on the part of the organization releasing
* the end-user product.
*/
#include "stdafx.h"
#include "MapX.h"
#include "SerialSample.h"
#include "AddThemeDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAddThemeDialog dialog
CAddThemeDialog::CAddThemeDialog(CMapX* map,CWnd* pParent /*=NULL*/)
: m_pMap(map), CDialog(CAddThemeDialog::IDD, pParent), m_single(true)
{
//{{AFX_DATA_INIT(CAddThemeDialog)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CAddThemeDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddThemeDialog)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAddThemeDialog, CDialog)
//{{AFX_MSG_MAP(CAddThemeDialog)
ON_CBN_SELCHANGE(IDC_DATASET_LIST, OnSelchangeDatasetList)
ON_CBN_SELCHANGE(IDC_TYPE_LIST, OnSelchangeTypeList)
ON_LBN_SELCHANGE(IDC_FIELD_LIST, OnSelchangeFieldList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAddThemeDialog message handlers
void CAddThemeDialog::OnSelchangeDatasetList()
{
CListBox* fieldList = (CListBox*)GetDlgItem(IDC_FIELD_LIST);
CComboBox* datasetList = (CComboBox*)GetDlgItem(IDC_DATASET_LIST);
if(fieldList == NULL || datasetList == NULL || datasetList->GetCurSel() == -1)
return;
try {
CMapXDataset ds;
CString dsName;
datasetList->GetLBText(datasetList->GetCurSel(), dsName);
ds = m_pMap->GetDatasets().Item(dsName);
fieldList->ResetContent();
for(int i = 1; i <= ds.GetFields().GetCount(); i++)
fieldList->AddString(ds.GetFields().Item(i).GetName());
} catch(COleDispatchException* e) {
e->ReportError();
e->Delete();
} catch(COleException* e) {
e->ReportError();
e->Delete();
}
}
BOOL CAddThemeDialog::OnInitDialog()
{
CDialog::OnInitDialog();
CComboBox* datasetList = (CComboBox*)GetDlgItem(IDC_DATASET_LIST);
CComboBox* typeList = (CComboBox*)GetDlgItem(IDC_TYPE_LIST);
if(m_pMap == NULL || datasetList == NULL || typeList == NULL) {
DestroyWindow();
return TRUE;
}
CMapXDatasets sets = m_pMap->GetDatasets();
for(int i = 1; i <= sets.GetCount(); i++)
datasetList->AddString(sets.Item(i).GetName());
datasetList->SetCurSel(0);
typeList->SetCurSel(0);
OnSelchangeDatasetList();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAddThemeDialog::OnSelchangeTypeList()
{
CComboBox* typeList = (CComboBox*)GetDlgItem(IDC_TYPE_LIST);
CWnd* textBox = GetDlgItem(IDC_FIELD_PROMPT);
if(textBox == NULL || typeList == NULL)
return;
switch(typeList->GetCurSel()) {
case 2: case 3: // Bar chart or pie chart
m_single = false;
textBox->SetWindowText("Fields: (press shift or ctrl to select multiple)");
break;
default:
m_single = true;
textBox->SetWindowText("Field:");
OnSelchangeFieldList();
break;
}
}
void CAddThemeDialog::OnSelchangeFieldList()
{
// If single selection is turned on, we need to restrict the selection to
// one item. Unfortunately, we can't do this in the normal fashion because
// the selection state (single or multiple) changes depending on which item
// is selected in the theme type list.
if(m_single) {
CListBox* fieldList = (CListBox*)GetDlgItem(IDC_FIELD_LIST);
if(fieldList == NULL)
return;
int caretIndex = fieldList->GetCaretIndex();
for(int i = 0; i < fieldList->GetCount(); i++) {
fieldList->SetSel(i, FALSE);
}
if(caretIndex != -1)
fieldList->SetSel(caretIndex, TRUE);
}
}
void CAddThemeDialog::OnOK()
{
CListBox* fieldList = (CListBox*)GetDlgItem(IDC_FIELD_LIST);
CComboBox* typeList = (CComboBox*)GetDlgItem(IDC_TYPE_LIST);
CComboBox* datasetList = (CComboBox*)GetDlgItem(IDC_DATASET_LIST);
if(fieldList == NULL || typeList == NULL || datasetList == NULL)
return;
if(fieldList->GetSelCount() == 0) {
AfxMessageBox("Please select one or more fields to theme");
return;
}
if(m_single && fieldList->GetSelCount() != 1) {
AfxMessageBox("You have selected a single-variate theme type; please select exactly one field.");
return;
}
if(typeList->GetCurSel() == -1) {
AfxMessageBox("Please select a theme type from the theme type combo box");
return;
}
if(datasetList->GetCurSel() == -1) {
AfxMessageBox("Please select a dataset from which to theme");
return;
}
CString dsName;
ThemeTypeConstants themeType;
CMapXFields fields;
datasetList->GetLBText(datasetList->GetCurSel(), dsName);
switch(typeList->GetCurSel()) {
case 0: themeType = miThemeAuto; break;
case 1: themeType = miThemeRanged; break;
case 2: themeType = miThemeBarChart; break;
case 3: themeType = miThemePieChart; break;
case 4: themeType = miThemeGradSymbol; break;
case 5: themeType = miThemeDotDensity; break;
case 6: themeType = miThemeIndividualValue; break;
default: AfxMessageBox("Unkown theme type"); break;
}
try {
fields.CreateDispatch(fields.GetClsid());
for(int i = 0; i < fieldList->GetCount(); i++) {
if(fieldList->GetSel(i)) {
CString fldName;
fieldList->GetText(i, fldName);
fields.Add(fldName, fldName);
}
}
COleVariant typeVt((long)themeType),fieldsVt;
COptionalVariant optVt;
fieldsVt.vt = VT_DISPATCH;
fieldsVt.pdispVal = fields.m_lpDispatch;
fieldsVt.pdispVal->AddRef();
m_pMap->GetDatasets().Item(dsName).GetThemes().Add(typeVt, fieldsVt, optVt, optVt);
} catch(COleDispatchException* e) {
e->ReportError();
e->Delete();
} catch(COleException* e) {
e->ReportError();
e->Delete();
}
CDialog::OnOK();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -