//------------------------------------------------------------------------ //! Returns the proper rectangle, which an editor should fit in //------------------------------------------------------------------------ CRect CGridColumnTraitText::GetCellEditRect(CGridListCtrlEx& owner, int nRow, int nCol) { // Find the required height according to font int requiredHeight = GetCellFontHeight(owner); // Get position of the cell to edit CRect rectCell; VERIFY( owner.GetCellRect(nRow, nCol, LVIR_LABEL, rectCell) ); // Adjust position to font height if (!owner.UsingVisualStyle()) { if ((requiredHeight + 2*::GetSystemMetrics(SM_CXEDGE)) > rectCell.Height()) { rectCell.top -= ::GetSystemMetrics(SM_CXEDGE); rectCell.bottom += ::GetSystemMetrics(SM_CXEDGE); } } if (owner.GetExtendedStyle() & LVS_EX_GRIDLINES) { if ((requiredHeight + 2*::GetSystemMetrics(SM_CXEDGE) + ::GetSystemMetrics(SM_CXBORDER)) < rectCell.Height()) rectCell.bottom -= ::GetSystemMetrics(SM_CXBORDER); } if (owner.GetExtendedStyle() & LVS_EX_SUBITEMIMAGES) { if (owner.GetImageList(LVSIL_SMALL)!=NULL && owner.GetCellImage(nRow,nCol)>=0) rectCell.left += ::GetSystemMetrics(SM_CXBORDER); } return rectCell; }
//------------------------------------------------------------------------ //! Returns the proper rectangle, which a cell value editor should fit in //! //! @param owner The list control for the inplace cell value editor //! @param nRow The index of the row //! @param nCol The index of the column //! @return Rectangle where the inplace cell value editor should be placed. //------------------------------------------------------------------------ CRect CGridColumnTraitText::GetCellEditRect(CGridListCtrlEx& owner, int nRow, int nCol) { // Get position of the cell to edit CRect rectCell; VERIFY( owner.GetCellRect(nRow, nCol, LVIR_LABEL, rectCell) ); // Adjust cell rectangle according to grid-lines if (owner.GetExtendedStyle() & LVS_EX_GRIDLINES) rectCell.bottom -= ::GetSystemMetrics(SM_CXBORDER); if (owner.GetExtendedStyle() & LVS_EX_SUBITEMIMAGES) { // Add margin to cell image if (owner.GetImageList(LVSIL_SMALL)!=NULL && owner.GetCellImage(nRow,nCol)!=I_IMAGECALLBACK) rectCell.left += ::GetSystemMetrics(SM_CXBORDER); } // Check if there is enough room for normal margin int requiredHeight = GetCellFontHeight(owner); requiredHeight += 2*::GetSystemMetrics(SM_CXEDGE); if (requiredHeight > rectCell.Height()) rectCell.bottom = rectCell.top + requiredHeight; return rectCell; }
//------------------------------------------------------------------------ //! Create a CEdit as cell value editor //! //! @param owner The list control starting a cell edit //! @param nRow The index of the row //! @param nCol The index of the column //! @param dwStyle The windows style to use when creating the CEdit //! @param rect The rectangle where the inplace cell value editor should be placed //! @return Pointer to the cell editor to use //------------------------------------------------------------------------ CEdit* CGridColumnTraitMultilineEdit::CreateEdit(CGridListCtrlEx& owner, int nRow, int nCol, DWORD dwStyle, const CRect& rect) { CGridMultilineEditorText* pEdit = new CGridMultilineEditorText(nRow, nCol); CRect limitRect(rect); if (m_EditMaxLines > 1 && GetStyle() & ES_MULTILINE) { // Calculate the number of lines in the cell text, expand the CEdit to match this CString cellText = owner.GetItemText(nRow, nCol); int nLineHeight = GetCellFontHeight(owner); int nLineCount = CharacterCount(cellText, _T("\n")); if (nLineCount > 0) { if ((UINT)nLineCount > m_EditMaxLines - 1) nLineCount = m_EditMaxLines - 1; limitRect.bottom += nLineHeight*nLineCount; } pEdit->SetMaxLines(m_EditMaxLines); pEdit->SetLineHeight(nLineHeight); } VERIFY(pEdit->Create(WS_CHILD | dwStyle, limitRect, &owner, 0)); return pEdit; }