/******************************************************************************* Function Name : OnHeaderEndDrag Input(s) : pNMHDR, pResult Output : BOOL Functionality : Event is fired after column Drag is ended. Member of : CRxMsgList Author(s) : Arunkumar K Date Created : 20-05-2010 Modifications : *******************************************************************************/ BOOL CRxMsgList::OnHeaderEndDrag(UINT, NMHDR* pNMHDR, LRESULT* /*pResult*/) { NMHEADER* pNMH = (NMHEADER*)pNMHDR; if (pNMH->pitem->mask & HDI_ORDER) { // Correct iOrder so it is just after the last hidden column int nColCount = GetHeaderCtrl()->GetItemCount(); int* pOrderArray = new int[nColCount]; VERIFY( GetColumnOrderArray(pOrderArray, nColCount) ); if(pNMH->iItem == 0 ) { pNMH->pitem->iOrder = 0; return FALSE; } for(int i = 0; i < nColCount ; ++i) { if (IsColumnVisible(pOrderArray[i])) { pNMH->pitem->iOrder = max(pNMH->pitem->iOrder,i); if(pNMH->pitem->iOrder == 0) pNMH->pitem->iOrder++; break; } } delete [] pOrderArray; } return FALSE; }
// Handle context-menu event for showing / hiding columns BOOL CRxMsgList::OnCommand(WPARAM wParam, LPARAM /*lParam*/) { if (HIWORD(wParam) == 0) { int nCol = LOWORD(wParam); ShowColumn(nCol, !IsColumnVisible(nCol)); } return TRUE; }
/******************************************************************************* Function Name : vShowHideBlankcolumn Input(s) : bInterpretON Output : - Functionality : Shows/Hides the Blank Column based on the input 'bInterpretON'. Member of : CRxMsgList Author(s) : Arunkumar K Date Created : 20-05-2010 Modifications : *******************************************************************************/ void CRxMsgList::vShowHideBlankcolumn(BOOL bInterpretON) { if(bInterpretON) ShowColumn(0,TRUE); else if(IsColumnVisible(0) ) { ShowColumn(0,FALSE); } }
/******************************************************************************* Function Name : OnContextMenu Input(s) : pWnd, point Output : - Functionality : Show the context menu with a list of column names as menu items. Member of : CRxMsgList Author(s) : Arunkumar K Date Created : 20-05-2010 Modifications : *******************************************************************************/ void CRxMsgList::OnContextMenu(CWnd* /*pWnd*/, CPoint point) { if (point.x==-1 && point.y==-1) { // OBS! point is initialized to (-1,-1) if using SHIFT+F10 or VK_APPS } else { CPoint pt = point; ScreenToClient(&pt); CRect headerRect; GetHeaderCtrl()->GetClientRect(&headerRect); if (headerRect.PtInRect(pt)) { // Show context-menu with the option to show hide columns CMenu menu; if (menu.CreatePopupMenu()) { for( int i = GetColumnStateCount()-1 ; i >= 0; --i) { UINT uFlags = MF_BYPOSITION | MF_STRING; // Put check-box on context-menu if (IsColumnVisible(i)) { uFlags |= MF_CHECKED; } else { uFlags |= MF_UNCHECKED; } if(i == 0) //Disable 'Time' column { break; } // Retrieve column-title LVCOLUMN lvc = {0}; lvc.mask = LVCF_TEXT; char sColText[256]; lvc.pszText = sColText; lvc.cchTextMax = 30; //Set the Width of Menu Items here //lvc.cchTextMax = sizeof(sColText)-1; VERIFY( GetColumn(i, &lvc) ); menu.InsertMenu(0, uFlags, i, lvc.pszText); } menu.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this, 0); } } } }
/******************************************************************************* Function Name : OnSetColumnWidth Input(s) : wParam, lParam Output : LRESULT Functionality : Handle the event for checking whether column is allowed to resize. Member of : CRxMsgList Author(s) : Arunkumar K Date Created : 20-05-2010 Modifications : *******************************************************************************/ LRESULT CRxMsgList::OnSetColumnWidth(WPARAM wParam, LPARAM lParam) { // Check that column is allowed to be resized int nCol = (int)wParam; if (!IsColumnVisible(nCol)) { return FALSE; } // Let the CListCtrl handle the event return DefWindowProc(LVM_SETCOLUMNWIDTH, wParam, lParam); }
/******************************************************************************* Function Name : OnHeaderBeginResize Input(s) : pNMHDR, pResult Output : BOOL Functionality : Handle the event for blocking resize of hidden columns. Member of : CRxMsgList Author(s) : Arunkumar K Date Created : 20-05-2010 Modifications : *******************************************************************************/ BOOL CRxMsgList::OnHeaderBeginResize(UINT, NMHDR* pNMHDR, LRESULT* pResult) { // Check that column is allowed to be resized NMHEADER* pNMH = (NMHEADER*)pNMHDR; int nCol = (int)pNMH->iItem; if (!IsColumnVisible(nCol) || nCol == 0) //If Column is not visible or if it is Zeroth Column { *pResult = TRUE; // Block resize return TRUE; // Block event } return FALSE; }
/******************************************************************************* Function Name : GetFirstVisibleColumn Input(s) : - Output : int Functionality : Returns an integer valuie of the index of first visible column. Member of : CRxMsgList Author(s) : Arunkumar K Date Created : 20-05-2010 Modifications : *******************************************************************************/ int CRxMsgList::GetFirstVisibleColumn() { int nColCount = GetHeaderCtrl()->GetItemCount(); for(int i = 0; i < nColCount; ++i) { int nCol = GetHeaderCtrl()->OrderToIndex(i); if (IsColumnVisible(nCol)) { return nCol; } } return -1; }
/******************************************************************************* Function Name : ShowColumn Input(s) : nCol, bShow Output : BOOL Functionality : Shows/Hides a Column nCol based on boolean bShow. Member of : CRxMsgList Author(s) : Arunkumar K Date Created : 20-05-2010 Modifications : *******************************************************************************/ BOOL CRxMsgList::ShowColumn(int nCol, bool bShow) { SetRedraw(FALSE); ColumnState& columnState = GetColumnState(nCol); int nColCount = GetHeaderCtrl()->GetItemCount(); int* pOrderArray = new int[nColCount]; VERIFY( GetColumnOrderArray(pOrderArray, nColCount) ); if (bShow) { // Restore the position of the column int nCurIndex = -1; for(int i = 0; i < nColCount ; ++i) { if (pOrderArray[i]==nCol) { nCurIndex = i; } else if (nCurIndex!=-1) { // We want to move it to the original position, // and after the last hidden column if ( (i <= columnState.m_OrgPosition) || !IsColumnVisible(pOrderArray[i]) ) { pOrderArray[nCurIndex] = pOrderArray[i]; pOrderArray[i] = nCol; nCurIndex = i; } } } } else { // Move the column to the front of the display order list int nCurIndex(-1); for(int i = nColCount-1; i >=0 ; --i) { if (pOrderArray[i]==nCol) { // Backup the current position of the column columnState.m_OrgPosition = i; nCurIndex = i; } else if (nCurIndex!=-1) { pOrderArray[nCurIndex] = pOrderArray[i]; pOrderArray[i] = nCol; nCurIndex = i; } } } VERIFY( SetColumnOrderArray(nColCount, pOrderArray) ); delete [] pOrderArray; if (bShow) { // Restore the column width columnState.m_Visible = true; VERIFY( SetColumnWidth(nCol, columnState.m_OrgWidth) ); } else { // Backup the column width if(GetColumnWidth(nCol) == 0) { columnState.m_Visible = false; } else { int orgWidth = GetColumnWidth(nCol); VERIFY( SetColumnWidth(nCol, 0) ); columnState.m_Visible = false; columnState.m_OrgWidth = orgWidth; } } SetRedraw(TRUE); Invalidate(FALSE); return TRUE; }
//------------------------------------------------------------------------ //! Override this method to change the context menu when activating context //! menu for the column headers //! //! @param pWnd Handle to the window in which the user right clicked the mouse //! @param point Position of the cursor, in screen coordinates, at the time of the mouse click. //! @param nCol The index of the column //------------------------------------------------------------------------ void CGridListCtrlGroups::OnContextMenuHeader(CWnd* pWnd, CPoint point, int nCol) { // Only Windows XP and above supports groups if (!IsCommonControlsEnabled()) { CGridListCtrlEx::OnContextMenuHeader(pWnd, point, nCol); return; } // Show context-menu with the option to show hide columns CMenu menu; VERIFY( menu.CreatePopupMenu() ); if (nCol!=-1) { // Retrieve column-title const CString& columnTitle = GetColumnHeading(nCol); menu.AppendMenu(MF_STRING, 3, CString(_T("Group by: ")) + columnTitle); } if (IsGroupViewEnabled()) { menu.AppendMenu(MF_STRING, 4, _T("Disable grouping")); } CString title_editor; if (HasColumnEditor(nCol, title_editor)) { menu.AppendMenu(MF_STRING, 1, static_cast<LPCTSTR>(title_editor)); } CString title_picker; if (HasColumnPicker(title_picker)) { menu.AppendMenu(MF_STRING, 2, static_cast<LPCTSTR>(title_picker)); } else { if (menu.GetMenuItemCount()>0) menu.AppendMenu(MF_SEPARATOR, 0, _T("")); InternalColumnPicker(menu, 6); } CSimpleArray<CString> profiles; InternalColumnProfileSwitcher(menu, GetColumnCount() + 7, profiles); CString title_resetdefault; if (HasColumnDefaultState(title_resetdefault)) { if (profiles.GetSize()==0) menu.AppendMenu(MF_SEPARATOR, 0, _T("")); menu.AppendMenu(MF_STRING, 5, title_resetdefault); } // Will return zero if no selection was made (TPM_RETURNCMD) int nResult = menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RETURNCMD, point.x, point.y, this, 0); switch(nResult) { case 0: break; case 1: OpenColumnEditor(nCol); break; case 2: OpenColumnPicker(); break; case 3: GroupByColumn(nCol); break; case 4: { // Very strange problem when disabling group mode, then scrollbars are not updated // If placed in the bottom and disables group mode, then suddenly there is a strange offset // - Quick fix scroll to top, and then fix scroll bars afterwards int pos = GetScrollPos(SB_VERT); EnsureVisible(0,FALSE); RemoveAllGroups(); EnableGroupView(FALSE); Scroll(CSize(0,pos)); } break; case 5: ResetColumnDefaultState(); break; default: { int nCol = nResult-6; if (nCol < GetColumnCount()) { ShowColumn(nCol, !IsColumnVisible(nCol)); } else { int nProfile = nResult-GetColumnCount()-7; SwichColumnProfile(profiles[nProfile]); } } break; } }
void CTDLMultiSortDlg::BuildCombos() { CComboBox* COMBOS[3] = { &m_cbSortBy1, &m_cbSortBy2, &m_cbSortBy3 }; const TDC_COLUMN* SORTBY[3] = { &m_sort.col1.nBy, &m_sort.col2.nBy, &m_sort.col3.nBy }; int nCol; // regular columns for (nCol = 0; nCol < NUM_COLUMNS; nCol++) { TDCCOLUMN& col = COLUMNS[nCol]; TDC_COLUMN nColID = col.nColID; if (IsColumnVisible(nColID)) { CEnString sColumn(col.nIDLongName); for (int nSort = 0; nSort < 3; nSort++) { int nIndex = COMBOS[nSort]->AddString(sColumn); COMBOS[nSort]->SetItemData(nIndex, nColID); if (*(SORTBY[nSort]) == nColID) COMBOS[nSort]->SetCurSel(nIndex); } } } // custom columns for (nCol = 0; nCol < m_aAttribDefs.GetSize(); nCol++) { const TDCCUSTOMATTRIBUTEDEFINITION& attribDef = m_aAttribDefs.GetData()[nCol]; if (attribDef.bEnabled && attribDef.SupportsFeature(TDCCAF_SORT)) { TDC_COLUMN nColID = attribDef.GetColumnID(); CEnString sColumn(IDS_CUSTOMCOLUMN, attribDef.sLabel); for (int nSort = 0; nSort < 3; nSort++) { int nIndex = COMBOS[nSort]->AddString(sColumn); COMBOS[nSort]->SetItemData(nIndex, nColID); if (*(SORTBY[nSort]) == nColID) COMBOS[nSort]->SetCurSel(nIndex); } } } // add blank item at top of 2nd and 3rd combo for (int nSort = 1; nSort < 3; nSort++) { int nIndex = COMBOS[nSort]->InsertString(0, _T("")); COMBOS[nSort]->SetItemData(nIndex, TDCC_NONE); if (*(SORTBY[nSort]) == TDCC_NONE) COMBOS[nSort]->SetCurSel(nIndex); } // set selection to first item if first combo selection is not set if (m_cbSortBy1.GetCurSel() == -1) { m_cbSortBy1.SetCurSel(0); m_sort.col1.nBy = (TDC_COLUMN)m_cbSortBy1.GetItemData(0); } }