Skip to content

Commit

Permalink
Fixed OnTraitEditBegin() so it has better control of the cell-editor …
Browse files Browse the repository at this point in the history
…creation
  • Loading branch information
snakefoot committed Apr 7, 2009
1 parent b984335 commit 9ee3429
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
29 changes: 9 additions & 20 deletions CGridListCtrlEx/CGridListCtrlEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,14 +1351,17 @@ BOOL CGridListCtrlEx::OnToolNeedText(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
//! Called when start editing a cell value
//!
//! @param pTrait Pointer to the column trait for the column
//! @param pEditor Pointer to the cell editor created by the column trait
//! @param nRow The index of the row
//! @param nCol The index of the column
//! @return Pointer to the cell editor (If NULL then block cell editing)
//------------------------------------------------------------------------
CWnd* CGridListCtrlEx::OnTraitEditBegin(CGridColumnTrait* pTrait, CWnd* pEditor, int nRow, int nCol)
CWnd* CGridListCtrlEx::OnTraitEditBegin(CGridColumnTrait* pTrait, int nRow, int nCol)
{
return pEditor;
CGridColumnTrait::ColumnState& columnState = pTrait->GetColumnState();
if (!columnState.m_Editable)
return NULL;

return pTrait->OnEditBegin(*this, nRow, nCol);
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -1387,15 +1390,7 @@ CWnd* CGridListCtrlEx::EditCell(int nRow, int nCol)
return NULL;

CGridColumnTrait* pTrait = GetCellColumnTrait(nRow, nCol);
CGridColumnTrait::ColumnState& columnState = pTrait->GetColumnState();
if (!columnState.m_Editable)
return NULL;

m_pEditor = pTrait->OnEditBegin(*this, nRow, nCol);
if (m_pEditor==NULL)
return NULL;

m_pEditor = OnTraitEditBegin(pTrait, m_pEditor, nRow, nCol);
m_pEditor = OnTraitEditBegin(pTrait, nRow, nCol);
if (m_pEditor==NULL)
return NULL;

Expand All @@ -1412,6 +1407,7 @@ CWnd* CGridListCtrlEx::EditCell(int nRow, int nCol)
if (GetParent()->SendMessage(WM_NOTIFY, GetDlgCtrlID(), (LPARAM)&dispinfo)==TRUE)
{
// Parent didn't want to start edit
pTrait->OnEditEnd();
m_pEditor->PostMessage(WM_CLOSE);
m_pEditor = NULL;
return NULL;
Expand Down Expand Up @@ -1454,14 +1450,7 @@ BOOL CGridListCtrlEx::OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult)
int nCol = pDispInfo->item.iSubItem;
int nRow = pDispInfo->item.iItem;
nRow; // Avoid unreferenced variable warning

CGridColumnTrait* pTrait = GetCellColumnTrait(nRow, nCol);
CGridColumnTrait::ColumnState& columnState = pTrait->GetColumnState();
if (!columnState.m_Editable)
{
*pResult = TRUE;// Block for edit
return FALSE; // Allow message to reach parent-dialog
}
nCol; // Avoid unreferenced variable warning

*pResult = FALSE;// Accept editing
return FALSE; // Let parent-dialog get chance
Expand Down
2 changes: 1 addition & 1 deletion CGridListCtrlEx/CGridListCtrlEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class CGridListCtrlEx : public CListCtrl

// Global column trait methods
virtual void OnTraitCustomDraw(CGridColumnTrait* pTrait, NMLVCUSTOMDRAW* pLVCD, LRESULT* pResult);
virtual CWnd* OnTraitEditBegin(CGridColumnTrait* pTrait, CWnd* pEditor, int nRow, int nCol);
virtual CWnd* OnTraitEditBegin(CGridColumnTrait* pTrait, int nRow, int nCol);
virtual bool OnTraitEditComplete(CGridColumnTrait* pTrait, CWnd* pEditor, LV_DISPINFO* pLVDI);

// Context Menu Handlers
Expand Down

0 comments on commit 9ee3429

Please sign in to comment.