// TestNotificationsDlg.cpp // // (c)1998-2025 Codejock Software, All Rights Reserved. // // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN // CONSENT OF CODEJOCK SOFTWARE. // // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A // SINGLE COMPUTER. // // CONTACT INFORMATION: // support@codejock.com // http://www.codejock.com // ///////////////////////////////////////////////////////////////////////////// #include "StdAfx.h" #include "Resource.h" #include "TestNotificationsDlg.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTestNotificationsDlg dialog CTestNotificationsDlg::CTestNotificationsDlg(CWnd* pParent) : CDialog(CTestNotificationsDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTestNotificationsDlg) m_bCancelFocusChanging = FALSE; m_bCancelLButtonDown = FALSE; m_bCancelLButtonUp = FALSE; m_bCancelSelectionClear = FALSE; m_bCancelSelectionAdd = FALSE; //}}AFX_DATA_INIT } void CTestNotificationsDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTestNotificationsDlg) DDX_Control(pDX, IDC_BEHAVIOR, m_wndBehavior); // Header rows DDX_Check(pDX, IDC_HEADER_ROWS_ENABLE_SELECTION, m_bHeaderRowsEnableSelection); DDX_Check(pDX, IDC_HEADER_ROWS_ALLOW_ACCESS, m_bHeaderRowsAllowAccess); // Options DDX_Check(pDX, IDC_CANCEL_FOCUS_CHANGING, m_bCancelFocusChanging); DDX_Check(pDX, IDC_CANCEL_LBUTTON_DOWN, m_bCancelLButtonDown); DDX_Check(pDX, IDC_CANCEL_LBUTTON_UP, m_bCancelLButtonUp); DDX_Check(pDX, IDC_CANCEL_SELECTION_CLEAR, m_bCancelSelectionClear); DDX_Check(pDX, IDC_CANCEL_SELECTION_ADD, m_bCancelSelectionAdd); DDX_Control(pDX, IDC_GRID, m_wndGrid); DDX_Control(pDX, IDC_NOTIFICATIONS, m_wndNotifications); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CTestNotificationsDlg, CDialog) //{{AFX_MSG_MAP(CTestNotificationsDlg) ON_NOTIFY(NM_CLICK, IDC_GRID, OnGridClick) ON_NOTIFY(NM_RCLICK, IDC_GRID, OnGridRClick) ON_NOTIFY(NM_DBLCLK, IDC_GRID, OnGridDblClick) ON_NOTIFY(XTP_NM_GRID_LBUTTONDOWN, IDC_GRID, OnGridLButtonDown) ON_NOTIFY(XTP_NM_GRID_SELCHANGING, IDC_GRID, OnGridSelChanging) ON_NOTIFY(XTP_NM_GRID_SELCHANGED, IDC_GRID, OnGridSelChanged) ON_NOTIFY(XTP_NM_GRID_FOCUS_CHANGING, IDC_GRID, OnGridFocusChanging) ON_NOTIFY(XTP_NM_GRID_ROWHEIHGTCHANGED, IDC_GRID, OnRowChanged) // Header rows ON_BN_CLICKED(IDC_HEADER_ROWS_ENABLE_SELECTION, OnHeaderRowsEnableSelection) ON_BN_CLICKED(IDC_HEADER_ROWS_ALLOW_ACCESS, OnHeaderRowsAllowAccess) // ON_BN_CLICKED(IDC_REMOVE_ROW_EX, OnRemoveRowEx) ON_BN_CLICKED(IDC_REMOVE_RECORD_EX, OnRemoveRecordEx) ON_BN_CLICKED(IDC_SELECT_FOCUSED_ROW, OnSelectFocusedRow) ON_BN_CLICKED(IDC_CLEAR_NOTIFICATIONS, OnClearNotifications) ON_CBN_SELCHANGE(IDC_BEHAVIOR, OnSelchangeBehavior) //}}AFX_MSG_MAP #if _XTPLIB_VERSION_PREFIX >= 1502 ON_NOTIFY(XTP_NM_GRID_STATECHANGED, IDC_GRID, OnGridStateChanged) #endif #if _XTPLIB_VERSION_PREFIX >= 1520 ON_NOTIFY(XTP_NM_GRID_LBUTTONUP, IDC_GRID, OnGridLButtonUp) // Added 15.2.0 #endif #if _XTPLIB_VERSION_PREFIX >= 1520 ON_NOTIFY(XTP_NM_GRID_HSCROLL, IDC_GRID, OnGridHScroll) // Added 15.2.0 ON_NOTIFY(XTP_NM_GRID_VSCROLL, IDC_GRID, OnGridVScroll) // Added 15.2.0 #endif END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTestNotificationsDlg message handlers #if _XTPLIB_VERSION_PREFIX >= 1520 struct Behavior { XTPGridBehavior behavior; LPCTSTR lpszBehavior; }; static const Behavior behavior[] = { { xtpGridBehaviorCodejockDefault, _T("Codejock Default") }, { xtpGridBehaviorCodejock1502, _T("Codejock 15.0.2") }, { xtpGridBehaviorCodejock1501, _T("Codejock 15.0.1") }, { xtpGridBehaviorCodejock1342, _T("Codejock 13.4.2") }, { xtpGridBehaviorCodejock1341, _T("Codejock 13.4.1") }, { xtpGridBehaviorCodejock1340, _T("Codejock 13.4.0") }, }; #endif BOOL CTestNotificationsDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the default font for all dialog controls. SendMessageToDescendants(WM_SETFONT, (WPARAM)(HFONT)XTPFontManager()->GetFont()); enum Constants { ColumnCount = 5, RecordCount = 20 }; #if _XTPLIB_VERSION_PREFIX >= 1520 for (int nBehavior = 0; nBehavior < _countof(behavior); nBehavior++) { m_wndBehavior.InsertString(nBehavior, behavior[nBehavior].lpszBehavior); } m_wndBehavior.SetCurSel(0); #else m_wndBehavior.EnableWindow(FALSE); #endif // Initialize list control first m_wndNotifications.InsertColumn(0, _T("Notification"), LVCFMT_LEFT, 225); m_wndNotifications.InsertColumn(1, _T("Row index"), LVCFMT_LEFT, 75); m_wndNotifications.InsertColumn(2, _T("Parameter"), LVCFMT_LEFT, 150); CString sName; int nColumn; // Add columns for (nColumn = 0; nColumn < ColumnCount; nColumn++) { sName.Format(_T("Column %d"), nColumn); m_wndGrid.AddColumn(new CXTPGridColumn(nColumn, sName, 100)); } int nRecord; // Add header records for (nRecord = 0; nRecord < 3; nRecord++) { CXTPGridRecord* pRecord = m_wndGrid.GetHeaderRecords()->Add(new CXTPGridRecord()); for (nColumn = 0; nColumn < ColumnCount; nColumn++) { sName.Format(_T("Item %d, %d"), nRecord, nColumn); pRecord->AddItem(new CXTPGridRecordItemText(sName)); } } // Add body records for (nRecord = 0; nRecord < RecordCount; nRecord++) { CXTPGridRecord* pRecord = m_wndGrid.AddRecord(new CXTPGridRecord()); for (nColumn = 0; nColumn < ColumnCount; nColumn++) { sName.Format(_T("Item %d, %d"), nRecord, nColumn); pRecord->AddItem(new CXTPGridRecordItemText(sName)); } } m_wndGrid.m_bFreeHeightMode = TRUE; m_wndGrid.m_nDefaultRowFreeHeight = ::GetSystemMetrics(SM_CYMENU); m_wndGrid.GetGridHeader()->SetAutoColumnSizing(FALSE); m_wndGrid.ShowHeaderRows(TRUE); m_wndGrid.Populate(); m_wndGrid.SetFocus(); // Initialize header row options m_bHeaderRowsEnableSelection = m_wndGrid.IsHeaderRowsSelectionEnabled(); m_bHeaderRowsAllowAccess = m_wndGrid.IsHeaderRowsAllowAccess(); UpdateData(FALSE); return FALSE; } void CTestNotificationsDlg::OnOK() { CDialog::OnOK(); } int CTestNotificationsDlg::AddNotification(LPCTSTR pszNotification, int nRow, LPCTSTR pszParameter) { int nItem = m_wndNotifications.InsertItem(m_wndNotifications.GetItemCount(), pszNotification); CString sRow; sRow.Format(_T("%d"), nRow); VERIFY(m_wndNotifications.SetItemText(nItem, 1, sRow)); VERIFY(m_wndNotifications.SetItemText(nItem, 2, pszParameter)); m_wndNotifications.EnsureVisible(nItem, FALSE); return nItem; } ///////////////////////////////////////////////////////////////////////////// // Notifications ///////////////////////////////////////////////////////////////////////////// void CTestNotificationsDlg::OnGridClick(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_GRIDRECORDITEM* pItemNotify = reinterpret_cast(pNotifyStruct); int nRow = -1; if (pItemNotify->pRow) { nRow = pItemNotify->pRow->GetIndex(); } int nItem = AddNotification(_T("NM_CLICK"), nRow); } void CTestNotificationsDlg::OnGridRClick(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_GRIDRECORDITEM* pItemNotify = reinterpret_cast(pNotifyStruct); int nRow = -1; if (pItemNotify->pRow) { nRow = pItemNotify->pRow->GetIndex(); } int nItem = AddNotification(_T("NM_RCLICK"), nRow); } void CTestNotificationsDlg::OnGridDblClick(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_GRIDRECORDITEM* pItemNotify = reinterpret_cast(pNotifyStruct); int nRow = -1; if (pItemNotify->pRow) { nRow = pItemNotify->pRow->GetIndex(); } int nItem = AddNotification(_T("NM_DBLCLICK"), nRow); } void CTestNotificationsDlg::OnGridLButtonDown(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_GRIDRECORDITEM* pItemNotify = reinterpret_cast(pNotifyStruct); int nRow = -1; if (pItemNotify->pRow) { nRow = pItemNotify->pRow->GetIndex(); } int nItem = AddNotification(_T("XTP_NM_GRID_LBUTTONDOWN"), nRow); UpdateData(); *pResult = m_bCancelLButtonDown; } #if _XTPLIB_VERSION_PREFIX >= 1520 void CTestNotificationsDlg::OnGridLButtonUp(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_GRIDRECORDITEM* pItemNotify = reinterpret_cast(pNotifyStruct); int nRow = -1; if (pItemNotify->pRow) { nRow = pItemNotify->pRow->GetIndex(); } int nItem = AddNotification(_T("XTP_NM_GRID_LBUTTONUP"), nRow); UpdateData(); *pResult = m_bCancelLButtonUp; } #endif static const LPCTSTR XTPGridSelectionChangeTypeString[] = { _T("xtpGridSelectionAdd"), _T("xtpGridSelectionRemove"), _T("xtpGridSelectionClear") }; void CTestNotificationsDlg::OnGridSelChanging(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_SELECTION_CHANGING* pItemNotify = reinterpret_cast( pNotifyStruct); int nRow = -1; if (pItemNotify->pRow) { nRow = pItemNotify->pRow->GetIndex(); } int nItem = AddNotification(_T("XTP_NM_GRID_SELCHANGING"), nRow, XTPGridSelectionChangeTypeString[pItemNotify->nType]); UpdateData(); switch (pItemNotify->nType) { case xtpGridSelectionAdd: *pResult = m_bCancelSelectionAdd; break; case xtpGridSelectionRemove: break; case xtpGridSelectionClear: *pResult = m_bCancelSelectionClear; break; } } void CTestNotificationsDlg::OnGridSelChanged(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); int nItem = AddNotification(_T("XTP_NM_GRID_SELCHANGED"), -1); } void CTestNotificationsDlg::OnGridFocusChanging(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_GRIDREQUESTEDIT* pItemNotify = reinterpret_cast(pNotifyStruct); int nRow = -1; if (pItemNotify->pRow) { nRow = pItemNotify->pRow->GetIndex(); } int nItem = AddNotification(_T("XTP_NM_GRID_FOCUS_CHANGING"), nRow); UpdateData(); pItemNotify->bCancel = m_bCancelFocusChanging; } #if _XTPLIB_VERSION_PREFIX >= 1502 void CTestNotificationsDlg::OnGridStateChanged(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_GRIDSTATECHANGED* pItemNotify = reinterpret_cast( pNotifyStruct); int nItem = AddNotification(_T("XTP_NM_GRID_STATECHANGED"), pItemNotify->nBegin); } #endif #if _XTPLIB_VERSION_PREFIX >= 1520 void CTestNotificationsDlg::OnGridHScroll(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_GRIDSCROLL* pItemNotify = reinterpret_cast(pNotifyStruct); int nItem = AddNotification(_T("XTP_NM_GRID_HSCROLL"), pItemNotify->nPosition); } void CTestNotificationsDlg::OnGridVScroll(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_GRIDSCROLL* pItemNotify = reinterpret_cast(pNotifyStruct); int nItem = AddNotification(_T("XTP_NM_GRID_VSCROLL"), pItemNotify->nPosition); } #endif void CTestNotificationsDlg::OnRemoveRowEx() { CXTPGridSelectedRows* pSelectedRows = m_wndGrid.GetSelectedRows(); CXTPGridSection* pSection = NULL; if (pSelectedRows->GetCount() > 0) { CXTPGridRow* pRow = pSelectedRows->GetAt(0); if (pRow) { pSection = pRow->GetSection(); } } if (!pSection) return; while (pSelectedRows->GetCount() > 0) { pSection->RemoveRowEx(pSelectedRows->GetAt(pSelectedRows->GetCount() - 1), TRUE); } } void CTestNotificationsDlg::OnRemoveRecordEx() { CXTPGridSelectedRows* pSelectedRows = m_wndGrid.GetSelectedRows(); CXTPGridSection* pSection = NULL; if (pSelectedRows->GetCount() > 0) { CXTPGridRow* pRow = pSelectedRows->GetAt(0); if (pRow) { pSection = pRow->GetSection(); } } if (!pSection) return; while (pSelectedRows->GetCount() > 0) { CXTPGridRow* pRow = pSelectedRows->GetAt(pSelectedRows->GetCount() - 1); pSection->RemoveRecordEx(pRow->GetRecord(), TRUE, TRUE); } } void CTestNotificationsDlg::OnSelectFocusedRow() { CXTPGridRow* pRow = m_wndGrid.GetFocusedRow(); if (NULL != pRow) { m_wndGrid.GetSelectedRows()->Select(pRow); } } void CTestNotificationsDlg::OnClearNotifications() { m_wndNotifications.DeleteAllItems(); } void CTestNotificationsDlg::OnSelchangeBehavior() { #if _XTPLIB_VERSION_PREFIX >= 1520 int nCurSel = m_wndBehavior.GetCurSel(); m_wndGrid.GetBehavior()->SetScheme(behavior[nCurSel].behavior); #endif } void CTestNotificationsDlg::OnHeaderRowsEnableSelection() { UpdateData(); m_wndGrid.HeaderRowsEnableSelection(m_bHeaderRowsEnableSelection); } void CTestNotificationsDlg::OnHeaderRowsAllowAccess() { UpdateData(); m_wndGrid.HeaderRowsAllowAccess(m_bHeaderRowsAllowAccess); } void CTestNotificationsDlg::OnRowChanged(NMHDR* pNotifyStruct, LRESULT* pResult) { _ASSERTE(NULL != pNotifyStruct); _ASSERTE(NULL != pResult); XTP_NM_GRIDROWRESIZE* pItemNotify = reinterpret_cast(pNotifyStruct); int nRow = -1; if (pItemNotify->pRow) { nRow = pItemNotify->pRow->GetIndex(); } int nItem = AddNotification(_T("XTP_NM_GRID_ROWHEIHGTCHANGED"), nRow); UpdateData(); *pResult = m_bCancelLButtonUp; }