Xtreme中 CXTPReportControl 添加行和列
// PageMobileLayout.cpp : implementation file // #include "stdafx.h" #include "aremoteserver.h" #include "PageMobileLayout.h" #include "Global.h" #include "Utility.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // // CXTPCustomDrawReportPaintManager CXTPCustomDrawReportPaintManager::CXTPCustomDrawReportPaintManager(CPageMobileLayout* pParent) : m_pParent(pParent) { } CXTPCustomDrawReportPaintManager::~CXTPCustomDrawReportPaintManager() { } int CXTPCustomDrawReportPaintManager::GetRowHeight(CDC* pDC, CXTPReportRow* pRow) { CRect Rect; m_pParent->m_RptLayout.GetWindowRect(&Rect); m_pParent->ScreenToClient(&Rect); return Rect.Height()/m_pParent->m_Row-1; // return 69; // return CXTPReportPaintManager::GetRowHeight(pDC, pRow); } / // CPageMobileLayout dialog IMPLEMENT_DYNCREATE(CPageMobileLayout, CXTPPropertyPage) CPageMobileLayout::CPageMobileLayout() : CXTPPropertyPage(CPageMobileLayout::IDD) { //{{AFX_DATA_INIT(CPageMobileLayout) //}}AFX_DATA_INIT m_Col = 3; m_Row = 4; m_SelPhoneButton = NULL; } void CPageMobileLayout::DoDataExchange(CDataExchange* pDX) { CXTPPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPageMobileLayout) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPageMobileLayout, CXTPPropertyPage) //{{AFX_MSG_MAP(CPageMobileLayout) ON_WM_SHOWWINDOW() //}}AFX_MSG_MAP ON_NOTIFY(NM_DBLCLK, XTP_ID_REPORT_CONTROL1, OnReportItemDblClick) ON_NOTIFY(NM_CLICK, XTP_ID_REPORT_CONTROL2, OnReportItemlClick) END_MESSAGE_MAP() / // CPageMobileLayout message handlers BOOL CPageMobileLayout::OnInitDialog() { CXTPPropertyPage::OnInitDialog(); CreateCtrl(); ShowData(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CPageMobileLayout::OnReportItemDblClick(NMHDR * pNotifyStruct, LRESULT * /*result*/) { XTP_NM_REPORTRECORDITEM* pItemNotify = (XTP_NM_REPORTRECORDITEM*) pNotifyStruct; if (pItemNotify == NULL || pItemNotify->pColumn == NULL || pItemNotify->pRow == NULL) return; CXTPReportRecord* pRecord = pItemNotify->pRow->GetRecord(); if (pRecord == NULL) return; if (pItemNotify->pColumn->GetIndex() == 0) { CXTPReportRecordItemText* pItem = (CXTPReportRecordItemText*)pRecord->GetItem(0); CXTPReportRecordItemText* pItemLayout = (CXTPReportRecordItemText*)(m_RptLayout.GetActiveItem()); if (pItemLayout) { pItemLayout->SetValue(pItem->GetValue()); pItemLayout->SetItemData(pItem->GetItemData()); m_RptLayout.SetFocusedRow(m_RptLayout.GetFocusedRow()); } } } void CPageMobileLayout::OnReportItemlClick(NMHDR * pNotifyStruct, LRESULT * /*result*/) { XTP_NM_REPORTRECORDITEM* pItemNotify = (XTP_NM_REPORTRECORDITEM*) pNotifyStruct; if (pItemNotify == NULL || pItemNotify->pColumn == NULL || pItemNotify->pRow == NULL) return; if (m_SelPhoneButton) m_SelPhoneButton->SetSelect(FALSE); m_SelPhoneButton = (CRptItemPhoneButton*)pItemNotify->pItem; m_SelPhoneButton->SetSelect(TRUE); m_RptLayout.RedrawControl(); } void CPageMobileLayout::OnOK() { // TODO: Add your specialized code here and/or call the base class SaveData(); CXTPPropertyPage::OnOK(); } void CPageMobileLayout::CreateCtrl() { CRect RectList; GetDlgItem(IDC_STATIC_COMMANDLIST)->GetWindowRect(&RectList); ScreenToClient(&RectList); m_RptCommandList.Create(WS_CHILD|WS_VISIBLE|WS_BORDER, RectList, this, XTP_ID_REPORT_CONTROL1); CXTPReportColumn* pCol; pCol = m_RptCommandList.AddColumn(new CXTPReportColumn(0, _T("命令"), 150, TRUE)); pCol->SetAllowDrag(FALSE); pCol->SetSortable(FALSE); //列表 CRect Rect; GetDlgItem(IDC_STATIC_REPORT)->GetWindowRect(&Rect); ScreenToClient(&Rect); m_RptLayout.Create(WS_CHILD|WS_VISIBLE|WS_BORDER, Rect, this, XTP_ID_REPORT_CONTROL2); m_RptLayout.ShowHeader(FALSE); m_RptLayout.ShowRowFocus(FALSE); m_RptLayout.SelectionEnable(FALSE); // m_RptLayout.ShowScrollBar(SB_VERT, FALSE); CXTPCustomDrawReportPaintManager* pPaintManager = new CXTPCustomDrawReportPaintManager(this); m_RptLayout.SetPaintManager(pPaintManager); pPaintManager->SetGridStyle(TRUE, xtpReportGridSolid); } void CPageMobileLayout::ShowData() { ShowCommandList(); ShowLayout(); } void CPageMobileLayout::SaveData() { CString Layout, cmd; int i, j; for (i = 0; i < m_RptLayout.GetRows()->GetCount(); i++) { if (Layout != "") Layout += ";"; for (j = 0; j < m_RptLayout.GetColumns()->GetCount(); j++) { if (Layout != "" && Layout.Right(1) != ";") Layout += ","; cmd.Format("%d", m_RptLayout.GetRows()->GetAt(i)->GetRecord()->GetItem(j)->GetItemData()); Layout += cmd; } } g_Global.g_IniFile.SetKeyValue("MobileLayout", "Layout", Layout); } void CPageMobileLayout::ShowCommandList() { CString Name[] = { "关机", "重启", "定时关机", "打开播放器", "播放", "停止", "上一首", "下一首", "音量高", "音量低", "静音", "切换窗口", "关闭窗口" }; int Command[] = { Msg_ShutDown, Msg_ReBoot, Msg_ShutDownTimed, Msg_OpenMediaPlayer, Msg_MediaPlayPause, Msg_MediaStop, Msg_MediaPrev, Msg_MediaNext, Msg_VolumeDown, Msg_VolumeUp, Msg_VolumeMute, Msg_SwitchWindow, Msg_CloseWindow, 0 }; CXTPReportRecord *pRecord; CXTPReportRecordItem *pItem; int i; for (i = 0; Command[i] > 0; i++) { pRecord = new CXTPReportRecord(); m_RptCommandList.AddRecord(pRecord); pItem = new CXTPReportRecordItemText(Name[i]); pRecord->AddItem(pItem); pItem->SetItemData(Command[i]); } m_RptCommandList.Populate(); } void CPageMobileLayout::ShowLayout() { SetLayoutGrid(); FillLayoutGrid(); m_RptLayout.Populate(); } void CPageMobileLayout::SetLayoutGrid() { CXTPReportColumn* pCol; int i, j; for (i = m_RptLayout.GetColumns()->GetCount();i < m_Col; i++) { pCol = m_RptLayout.AddColumn(new CXTPReportColumn(i, _T(""), 100, TRUE)); pCol->SetAllowDrag(FALSE); pCol->SetSortable(FALSE); } for (i = m_RptLayout.GetRows()->GetCount();i < m_Row; i++) { CXTPReportRecord *pRecord = new CXTPReportRecord(); CXTPReportRecordItem *pItem; for (j = 0; j < m_Col; j++) { pItem = new CRptItemPhoneButton(""); pItem->SetAlignment(xtpColumnTextVCenter); pRecord->AddItem(pItem); } m_RptLayout.AddRecord(pRecord); } } void CPageMobileLayout::FillLayoutGrid() { int i, j; CString Layoutstr = g_Global.g_IniFile.GetKeyValue("MobileLayout", "Layout", ""); CStringArray RowsArray,ItemArray; CString Rowstr; MStrTok(Layoutstr.GetBuffer(0),";",Layoutstr.GetLength(),1,RowsArray); for (i=0;i<RowsArray.GetSize();i++) { Rowstr=RowsArray.GetAt(i); ItemArray.RemoveAll(); MStrTok(Rowstr.GetBuffer(0),",",Rowstr.GetLength(),1,ItemArray); for (j=0;j<ItemArray.GetSize();j++) { m_RptLayout.GetRecords()->GetAt(i)->GetItem(j)->SetItemData(atoi(ItemArray.GetAt(j))); ((CXTPReportRecordItemText*)(m_RptLayout.GetRecords()->GetAt(i)->GetItem(j)))->SetValue(FindName(atoi(ItemArray.GetAt(j)))); } } } CString CPageMobileLayout::FindName(int Code) { int i; for (i = 0; i < m_RptCommandList.GetRows()->GetCount(); i++) { if (m_RptCommandList.GetRows()->GetAt(i)->GetRecord()->GetItem(0)->GetItemData() == Code) { return ((CXTPReportRecordItemText*)m_RptCommandList.GetRows()->GetAt(i)->GetRecord()->GetItem(0))->GetValue(); } } return ""; }
相关文章