// ************************************************************************** // OnChar () // // Description: // Handle keyboard input. Switch view on tab, etc. // // Parameters: // UINT nChar Character code // UINT nRepCnt repeat count // UINT nFlags Flags // // Returns: // void // ************************************************************************** void CKListEdit::OnChar (UINT nChar, UINT nRepCnt, UINT nFlags) { // Filter escape and return: if (nChar == VK_ESCAPE || nChar == VK_RETURN) { if (nChar == VK_ESCAPE) m_bESC = TRUE; GetParent ()->SetFocus (); return; } // Perform default processing: CEdit::OnChar (nChar, nRepCnt, nFlags); // Get text extent: CString strText; GetWindowText (strText); CWindowDC dc (this); CFont *pFont = GetParent ()->GetFont (); CFont *pFontDC = dc.SelectObject (pFont); CSize size = dc.GetTextExtent (strText); dc.SelectObject (pFontDC); // add some extra buffer size.cx += 5; // Get client rectangle: CRect rect; CRect parentrect; GetClientRect (&rect); GetParent ()->GetClientRect (&parentrect); // Transform rectangle to parent coordinates: ClientToScreen (&rect); GetParent ()->ScreenToClient (&rect); // Check whether control needs to be resized and whether there is space to grow: if (size.cx > rect.Width ()) { if (size.cx + rect.left < parentrect.right) rect.right = rect.left + size.cx; else rect.right = parentrect.right; MoveWindow (&rect); } // Send notification to parent of the list control that edit was made: GetParent ()->GetParent ()->SendMessage (UM_LISTEDIT_ITEMCHANGE, m_iSubItem, m_iItem); }
//********************************************************************************** CSize CBCGPAutoHideButton::GetTextSize () const { CSize size (0, 0); if (m_pAutoHideWindow != NULL && m_pParentBar != NULL) { CString strText; m_pAutoHideWindow->GetWindowText (strText); if (!strText.IsEmpty ()) { CWindowDC dc (m_pParentBar); CFont* pFontOld = (CFont*) dc.SelectObject (IsHorizontal () ? &globalData.fontRegular : &globalData.fontVert); ASSERT (pFontOld != NULL); size = dc.GetTextExtent (strText); size.cx += m_nMarginSize; size.cy += m_nMarginSize; dc.SelectObject (pFontOld); if (!IsHorizontal ()) { int n = size.cy; size.cy = size.cx; size.cx = n; } } if (!m_pParentBar->m_bActiveInGroup && m_bOverlappingTabs) { IsHorizontal () ? size.cx = 0 : size.cy = 0; } } return size; }
CSize GetWindowTextExtent (CWnd* pControl, const CString& strText, CFont* pFont = NULL) { if (pFont == NULL && pControl != NULL) { ASSERT (pControl != NULL); pFont = pControl->GetFont (); } CWindowDC dc (pControl); CFont* pOldFont = NULL; if (pFont != NULL) { dc.SelectObject (pFont); } CSize szText = dc.GetTextExtent (strText); if (pFont != NULL) { dc.SelectObject (pOldFont); } return szText; }
void CEditCell::OnChar (UINT nChar, UINT nRepCnt, UINT nFlags) { BOOL Shift = GetKeyState(VK_SHIFT) < 0; switch (nChar) { case VK_ESCAPE : { if (Shift) // Shift+Escape -> disable autocomplete m_DoSuggest = FALSE; else { m_bEscape = TRUE; GetParent()->SetFocus(); } return; } case VK_RETURN : { SetListText(); if (m_SubItem == 0) m_pListCtrl->EditSubItem (m_Item, 1); else m_pListCtrl->EditSubItem (m_Item + 1, 0); return; } case VK_TAB : { if (Shift) { if (m_SubItem > 0) m_pListCtrl->EditSubItem (m_Item, m_SubItem - 1); else { if (m_Item > 0) m_pListCtrl->EditSubItem (m_Item - 1, 2); } } else { if (m_SubItem == 0) m_pListCtrl->EditSubItem (m_Item, 1); else if (m_SubItem < 2) m_pListCtrl->EditSubItem (m_Item, m_SubItem + 1); else m_pListCtrl->EditSubItem (m_Item + 1, 0); } return; } } CEdit::OnChar (nChar, nRepCnt, nFlags); // Get text CString Text; GetWindowText(Text); // Make some suggestion if (m_DoSuggest && nChar != 8 && m_AutoComplete != NULL) { int iSelStart; int iSelEnd; GetSel(iSelStart, iSelEnd); CString sugg = GetSuggestion(Text); if (!sugg.IsEmpty()) { Text = sugg; SetWindowText(Text); SetSel(iSelStart, Text.GetLength()); } } // Resize edit control if needed CWindowDC DC (this); CFont *pFont = GetParent()->GetFont(); CFont *pFontDC = DC.SelectObject (pFont); CSize Size = DC.GetTextExtent (Text); DC.SelectObject (pFontDC); Size.cx += 5; // add some extra buffer // Get client rect CRect Rect, ParentRect; GetClientRect (&Rect); GetParent()->GetClientRect (&ParentRect); // Transform rect to parent coordinates ClientToScreen (&Rect); GetParent()->ScreenToClient (&Rect); // Check whether control needs to be resized and whether there is space to grow if (Size.cx > Rect.Width()) { if (Size.cx + Rect.left < ParentRect.right ) Rect.right = Rect.left + Size.cx; else Rect.right = ParentRect.right; MoveWindow (&Rect); } }
void gxEditCell::OnChar (UINT nChar, UINT nRepCnt, UINT nFlags) { BOOL Shift = GetKeyState (VK_SHIFT) < 0; switch (nChar) { case VK_ESCAPE : { if (nChar == VK_ESCAPE) bEscape = TRUE; GetParent()->SetFocus(); return; } case VK_RETURN : { SetListText(); pListCtrl->EditSubItem (Item + 1, 0); return; } case VK_TAB : { /* if (Shift) { if (SubItem > 0) pListCtrl->EditSubItem (Item, SubItem - 1); else { if (Item > 0) pListCtrl->EditSubItem (Item - 1, 2); } } else { if (SubItem < 2) pListCtrl->EditSubItem (Item, SubItem + 1); else pListCtrl->EditSubItem (Item + 1, 0); }*/ return; } } CEdit::OnChar (nChar, nRepCnt, nFlags); // Resize edit control if needed // Get text extent CString Text; GetWindowText (Text); CWindowDC DC (this); CFont *pFont = GetParent()->GetFont(); CFont *pFontDC = DC.SelectObject (pFont); CSize Size = DC.GetTextExtent (Text); DC.SelectObject (pFontDC); Size.cx += 5; // add some extra buffer // Get client rect CRect Rect, ParentRect; GetClientRect (&Rect); GetParent()->GetClientRect (&ParentRect); // Transform rect to parent coordinates ClientToScreen (&Rect); GetParent()->ScreenToClient (&Rect); // Check whether control needs to be resized and whether there is space to grow if (Size.cx > Rect.Width()) { if (Size.cx + Rect.left < ParentRect.right ) Rect.right = Rect.left + Size.cx; else Rect.right = ParentRect.right; MoveWindow (&Rect); } }