void COptionTreeItemEdit::OnActivate() { // Make sure window is valid if (IsWindow(GetSafeHwnd())) { // -- Show window ShowWindow(SW_SHOW); // -- Set selection SetSel(0, 0); // -- Set window position MoveWindow(m_rcAttribute.left, m_rcAttribute.top, m_rcAttribute.Width(), m_rcAttribute.Height()); // -- Set focus SetFocus(); } }
int CInPlaceEdit::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CEdit::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here // Set the proper font CFont* pFont = GetParent()->GetFont(); SetFont(pFont); ShowWindow(SW_SHOW); SetWindowText(m_strWindowText); SetSel(0, -1); SetFocus(); return 0; }
int CDomainListBox::SelectItem( int nSel, BOOL bSelected ) { if( GetStyle( ) & LBS_MULTIPLESEL ) { return SetSel( nSel, bSelected ); } else { if( bSelected ) return SetCurSel( nSel ); else { if( GetCurSel() == nSel || -1 == nSel ) return SetCurSel( -1 ); } return -1; } }
void CCalcEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { //TRACE("xxxx0 OnChar: sel = %x\r\n", GetSel()); in_edit_ = true; ASSERT(pp_ != NULL && pp_->IsVisible()); clear_result(); // Clear text if previous result is displayed // If editing an integer then make allowances for separator char if (pp_->state_ == CALCINTLIT) { CString ss; // Text from the window (edit control) int start, end; // Current selection in the edit control // Set selection so that arrows/Del work OK in presence of separator chars GetWindowText(ss); GetSel(start, end); char sep_char = ' '; if (pp_->radix_ == 10) sep_char = theApp.dec_sep_char_; if (nChar == '\b' && start > 1 && start == end && ss[start-1] == sep_char) { // If deleting 1st char of group then also delete preceding sep_char SetSel(start-2, end); } } CEdit::OnChar(nChar, nRepCnt, nFlags); // Update internals (state_, current_ etc) from the current edit box text get(); pp_->state_ = update_value(false); pp_->check_for_error(); add_sep(); // fix display of integers in edit box // Update the expression to be displayed get(); pp_->set_right(); pp_->inedit(km_user_str); pp_->ctl_calc_bits_.RedrawWindow(); in_edit_ = false; //TRACE("xxxx1 OnChar: sel = %x\r\n", GetSel()); }
/* ================ CSyntaxRichEditCtrl::FindNext ================ */ bool CSyntaxRichEditCtrl::FindNext(const char *find, bool matchCase, bool matchWholeWords, bool searchForward) { long selStart, selEnd, flags, search, length, start; tom::ITextRange *range; if (find[0] == '\0') { return false; } GetSel(selStart, selEnd); flags = 0; flags |= matchCase ? tom::tomMatchCase : 0; flags |= matchWholeWords ? tom::tomMatchWord : 0; if (searchForward) { m_TextDoc->Range(selEnd, GetTextLength(), &range); search = GetTextLength() - selEnd; } else { m_TextDoc->Range(0, selStart, &range); search = -selStart; } if (range->FindShit(A2BSTR(find), search, flags, &length) == S_OK) { m_TextDoc->Freeze(NULL); range->get_Start(&start); range->Release(); SetSel(start, start + length); int line = Max((int) LineFromChar(start) - 5, 0); LineScroll(line - GetFirstVisibleLine(), 0); UpdateVisibleRange(); m_TextDoc->Unfreeze(NULL); return true; } else { range->Release(); return false; } }
void CListBoxCtrl::ResetSelection() { if (multiSelection) { SetRedraw(false); ClearSelections(); int numSel = m_intValArray.Size(); for (int i = 0; i < numSel; i++) SetSel(m_intValArray[i], true); SetRedraw(true); Invalidate(); UpdateWindow(); } else SetCurSel(*m_pintVal); }
void SMaskEdit::SetMaskState() { ASSERT(m_bUseMask); SStringT strWindowText = GetWindowText(); CorrectWindowText(); GetContainer()->SwndShowCaret(FALSE); if (strWindowText != m_strWindowText) { SetWindowText(S_CT2W(m_strWindowText)); m_bModified = TRUE; } SetSel(MAKELONG(m_nStartChar, m_nEndChar), FALSE); GetContainer()->SwndShowCaret(TRUE); }
void COXMaskedEdit::UpdateInsertionPointForward(int nSelectionStart) { int nNewInsertionPoint=GetNextInputLocation(nSelectionStart); if(m_bAutoTab && nNewInsertionPoint==m_listData.GetCount()) { CWnd* pParentWnd=GetParent(); ASSERT(pParentWnd); CWnd* pNextTabCtrl=pParentWnd->GetNextDlgTabItem(this); if(pNextTabCtrl && pNextTabCtrl!=this) { pNextTabCtrl->SetFocus(); } } else { SetSel(nNewInsertionPoint, nNewInsertionPoint); } }
void CPropTreeItemEdit::OnActivate(int activateType, CPoint point) { // Check if the edit control needs creation if (!IsWindow(m_hWnd)) { DWORD dwStyle; dwStyle = WS_CHILD|ES_AUTOHSCROLL; Create(dwStyle, m_rc, m_pProp->GetCtrlParent(), GetCtrlID()); } SendMessage(WM_SETFONT, (WPARAM)m_pProp->GetNormalFont()->m_hObject); SetPasswordChar((TCHAR)(m_bPassword ? '*' : 0)); SetWindowText(m_sEdit); SetSel(0, -1); SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width(), m_rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW); SetFocus(); }
BOOL CShaderEdit::PreTranslateMessage(MSG* pMsg) { if(m_acdlg.IsWindowVisible() && pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN || pMsg->wParam == VK_PRIOR || pMsg->wParam == VK_NEXT || pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)) { int i = m_acdlg.m_list.GetCurSel(); if(pMsg->wParam == VK_RETURN && i >= 0) { CString str; m_acdlg.m_list.GetText(i, str); i = str.Find('(')+1; if(i > 0) str = str.Left(i); int nStartChar = 0, nEndChar = -1; GetSel(nStartChar, nEndChar); CString text; GetWindowText(text); while(nStartChar > 0 && _istalnum(text.GetAt(nStartChar-1))) nStartChar--; SetSel(nStartChar, nEndChar); ReplaceSel(str, TRUE); } else if(pMsg->wParam == VK_ESCAPE) { m_acdlg.ShowWindow(SW_HIDE); } else { m_acdlg.m_list.SendMessage(pMsg->message, pMsg->wParam, pMsg->lParam); } return TRUE; } return __super::PreTranslateMessage(pMsg); }
void CUrlRichEditCtrl::OnRButtonDown(UINT nFlags, CPoint point) { m_nContextUrl = -1; // move the caret to the pos clicked int nChar = CharFromPoint(point); if (nChar >= 0) { // don't reset the selection if the character // falls within the current selection CHARRANGE crSel; GetSel(crSel); if (nChar < crSel.cpMin || nChar > crSel.cpMax) SetSel(nChar, nChar); } CRichEditBaseCtrl::OnRButtonDown(nFlags, point); }
// ************************************************************************** // OnCreate () // // Description: // The framework calls this member function when an application requests // that the Windows window be created. // // Parameters: // LPCREATESTRUCT lpCreateStruct Contains information about window to be // created. // // Returns: // int - 0 if success, -1 if fail // ************************************************************************** int CKListEdit::OnCreate (LPCREATESTRUCT lpCreateStruct) { // Perform default processing: if (CEdit::OnCreate (lpCreateStruct) == -1) return (-1); // Set the font to our parents current: CFont* font = GetParent ()->GetFont (); SetFont (font); // Initialize edit text: SetWindowText (m_sInitText); // Give the control the focus and select the current text for edit: SetFocus (); SetSel (0, -1); // If we make it here, then return 0 to indicate success: return (0); }
void CStatusCtrl::OnOutputcontextClearall() { USES_CONVERSION; CString rtfstr = m_RTFHeader; rtfstr += "} "; EDITSTREAM es; string s = Util::ws2s(wstring(rtfstr)); es.dwCookie = (DWORD)&s; // Pass a pointer to the CString to the callback function es.pfnCallback = RichEditStreamInCallback; // Specify the pointer to the callback function. StreamIn(SF_RTF, es); // Perform the streaming SetSel(-1, -1); LimitText(1000*1000); int res = GetLimitText(); m_bEmpty = TRUE; m_nMoveToBottom = 0; }
int JHCEdit::DeleteChar(int count) { if (count == 0) return 0; int s, e, ls, le; GetSel(s, e); ls = LineIndex(LineFromChar(s)); le = ls + LineLength(ls); if (count > 0) { e = s + count; if (e > le) e = le; } else { e = s; s = s + count; if (s < ls) s = ls; } SetSel(s, e); Clear(); return e - s + 1; }
void CSecureEditEx::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { if(m_bSecMode == TRUE) { if((nChar == VK_HOME) || (nChar == VK_END)) { SHORT shShift = GetKeyState(VK_SHIFT); shShift |= GetKeyState(VK_LSHIFT); shShift |= GetKeyState(VK_RSHIFT); if((shShift & 0x8000) != 0) { _DeleteAll(); SetWindowText(_T("")); SetSel(0, 0, FALSE); } } } CEdit::OnKeyDown(nChar, nRepCnt, nFlags); _ClearSelection(); }
// Called *after* the content of the edit control has been updated! void CSecureEditEx::OnEnUpdate() { _RegisterDropTarget(); if(m_bSecMode == FALSE) { m_nOldLen = GetWindowTextLength(); return; } // Get information about the *new* contents of the edit control const int iWndLen = GetWindowTextLength(); const int iDiff = iWndLen - m_nOldLen; if(iDiff == 0) return; // No change? const size_t sizeWindowBuffer = iWndLen + 1; LPTSTR lpWnd = new TCHAR[sizeWindowBuffer]; ASSERT(lpWnd != NULL); if(lpWnd == NULL) return; GetWindowText(lpWnd, iWndLen + 1); const DWORD dwPos = (GetSel() & 0xFFFF); // Get the *new* cursor position if(iDiff < 0) { ASSERT(iDiff == -1); _DeleteCharacters(dwPos, static_cast<unsigned int>(-iDiff)); } else _InsertCharacters(dwPos - static_cast<DWORD>(iDiff), &lpWnd[dwPos - static_cast<DWORD>(iDiff)], static_cast<unsigned int>(iDiff)); ASSERT(m_apChars.GetSize() == iWndLen); m_nOldLen = static_cast<int>(m_apChars.GetSize()); _tcsset_s(lpWnd, sizeWindowBuffer, TCH_STDPWCHAR); SetWindowText(lpWnd); SetSel(static_cast<int>(dwPos), static_cast<int>(dwPos), FALSE); DeleteTPtr(lpWnd, TRUE, FALSE); // Memory overwritten already }
LRESULT ChatCtrl::onClientEnLink(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/) { ENLINK* pEL = (ENLINK*)pnmh; if ( pEL->msg == WM_LBUTTONUP ) { long lBegin = pEL->chrg.cpMin, lEnd = pEL->chrg.cpMax; TCHAR* sURLTemp = new TCHAR[(lEnd - lBegin)+1]; if(sURLTemp) { GetTextRange(lBegin, lEnd, sURLTemp); tstring sURL = sURLTemp; if(magnets.find(sURL) == magnets.end()) { WinUtil::openLink(sURL); } else { WinUtil::parseMagnetUri(magnets[sURL]); } delete[] sURLTemp; } } else if(pEL->msg == WM_RBUTTONUP) { selectedURL = Util::emptyStringT; long lBegin = pEL->chrg.cpMin, lEnd = pEL->chrg.cpMax; TCHAR* sURLTemp = new TCHAR[(lEnd - lBegin)+1]; if(sURLTemp) { GetTextRange(lBegin, lEnd, sURLTemp); if(magnets.find(sURLTemp) == magnets.end()) { selectedURL = sURLTemp; } else { selectedURL = magnets[sURLTemp]; } delete[] sURLTemp; } SetSel(lBegin, lEnd); InvalidateRect(NULL); } return 0; }
void CRichEditExtn::OnLButtonDown(UINT nFlags, CPoint point) { // Get the scroll bar position. int nScrollHPos = GetScrollPos(SB_HORZ); int nScrollVPos = GetScrollPos(SB_VERT); int n = CharFromPos(point); m_lastposition = HIWORD(n); m_nStartChar = m_nEndChar = LOWORD(n); CRichEditCtrl::OnLButtonDown(nFlags, point); // Reset the scroll bar position. SetScrollPos(SB_HORZ, nScrollHPos); SetScrollPos(SB_VERT, nScrollVPos); // Reset the display scroll position. SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBTRACK, nScrollHPos), 0); SendMessage(WM_VSCROLL, MAKEWPARAM(SB_THUMBTRACK, nScrollVPos), 0); SetSel(m_nStartChar, m_nEndChar); }
// 增加字符 // CEdit显示内容有限制,当超过该限制时,需要删除原来的内容,再增加内容 void CConsoleEdit::AddTexts(const char* str, int len) { if(len == -1) len = strlen(str); //KDebug("%d %d", m_nLength, len); if ((m_nLength + len) > MAX_DATA_NUM) { SetSel(0, len + 128, TRUE); ReplaceSel(""); if (len > MAX_DATA_NUM) { CString result(str); result = result.Right(MAX_DATA_NUM); ReplaceSel(result); return; } } MoveToEnd(); ReplaceSel(str); if (strcmp(str,m_pretitle)==0) m_last_title_pos = SendMessage( WM_GETTEXTLENGTH ); }
void CDxMaskEdit::SetMaskState() { //if (!m_hWnd) // return; ATLASSERT(m_bUseMask); CString strWindowText = GetWindowText(); CorrectWindowText(); GetContainer()->DxShowCaret(FALSE); if (strWindowText != m_strWindowText) { SetWindowText(m_strWindowText); m_bModified = TRUE; } SetSel(MAKELONG(m_nStartChar, m_nEndChar), FALSE); GetContainer()->DxShowCaret(TRUE); }
LRESULT CFulEditCtrl::onFind(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) { LPFINDREPLACE fr = reinterpret_cast<LPFINDREPLACE>(lParam); if(fr->Flags & FR_DIALOGTERM){ WinUtil::findDialog = NULL; } else if(fr->Flags & FR_FINDNEXT){ //prepare the flags used to search int flags = 0; if(fr->Flags & FR_WHOLEWORD) flags = FR_WHOLEWORD; if(fr->Flags & FR_MATCHCASE) flags |= FR_MATCHCASE; if(fr->Flags & FR_DOWN) flags |= FR_DOWN; //initiate the structure, cpMax -1 means the whole document is searched FINDTEXTEX ft; ft.chrg.cpMax = -1; ft.chrg.cpMin = curFindPos; ft.lpstrText = fr->lpstrFindWhat; //if we find the end of the document, notify the user and return int result = (int)SendMessage(EM_FINDTEXT, (WPARAM)flags, (LPARAM)&ft); if(-1 == result){ MessageBox(CTSTRING(FINISHED_SEARCHING), _T(FULDC) _T(" ") _T(FULVERSIONSTRING), MB_OK | MB_ICONINFORMATION); curFindPos = 0; return 0; } //select the result and scroll it into view curFindPos = result +1 ; SetFocus(); SetSel(result, result + _tcslen(ft.lpstrText)); ScrollCaret(); } return 0; }
LRESULT CFilterEdit::OnPaste(WPARAM, LPARAM) { if (OpenClipboard()) { HANDLE hData = GetClipboardData (CF_TEXT); CString toInsert((const char*)GlobalLock(hData)); GlobalUnlock(hData); CloseClipboard(); // elimate control chars, especially newlines toInsert.Replace(_T('\t'), _T(' ')); // only insert first line toInsert.Replace(_T('\r'), _T('\n')); int pos = 0; toInsert = toInsert.Tokenize(_T("\n"), pos); toInsert.Trim(); // get the current text CString text; GetWindowText(text); // construct the new text int from, to; GetSel(from, to); text.Delete(from, to - from); text.Insert(from, toInsert); from += toInsert.GetLength(); // update & notify controls SetWindowText(text); SetSel(from, from, FALSE); SetModify(TRUE); GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), EN_CHANGE), (LPARAM)GetSafeHwnd()); } return 0; }
void CNumberEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { //Only allow the number 0 - 9 and a the backspace to go through if(((nChar < '0') || (nChar > '9')) && (nChar != VK_BACK)) return; CString csText; GetWindowText(csText); //Save this if the validate fails then these get set back int nStartChar, nEndChar; GetSel(nStartChar, nEndChar); //Set the new number CEdit::OnChar(nChar, nRepCnt, nFlags); //If its not valid set it back to the old number if(!ValidateNumber(GetNumberD())) { SetWindowText(csText); SetSel(nStartChar, nEndChar); } }
void CTWScriptEdit::SetFormatRange(int nStart, int nEnd, BOOL bBold, COLORREF clr) { if (nStart >= nEnd) return; SetSel(nStart, nEnd); DWORD dwEffects = bBold?CFE_BOLD:0; CHARFORMAT cfm; cfm.cbSize = sizeof(cfm); GetSelectionCharFormat(cfm); if ((cfm.dwMask & CFM_COLOR) && cfm.crTextColor == clr && (cfm.dwMask & CFM_BOLD) && (cfm.dwEffects & CFE_BOLD) == dwEffects) return; cfm.dwEffects = dwEffects; cfm.crTextColor = clr; cfm.dwMask = CFM_BOLD | CFM_COLOR; SetSelectionCharFormat(cfm); }
bool CScriptEditView::DoFindText( bool bNext ) { DWORD dwFlags = FR_DOWN; if( m_fro.bMatchCase ) dwFlags |= FR_MATCHCASE; if( m_fro.bWholeWord ) dwFlags |= FR_WHOLEWORD; long nStart, nEnd; GetSel( nStart, nEnd ); FINDTEXTEX ft; ft.chrg.cpMin = bNext ? nEnd : nStart ; ft.chrg.cpMax = -1; ft.lpstrText = m_fro.StrToFind; if( FindText(dwFlags, ft) == -1 ) return false; SetSel( ft.chrgText ); return true; }
void CNumEdit::OnPaste() { LockWindowUpdate(TRUE); DefWindowProc(); int nStart, nEnd; GetSel(nStart, nEnd); TCHAR szValue[64]; GetWindowText(szValue, countof(szValue)); int i = 0, j = 0; for (;;) { TCHAR chValue = szValue[i++]; if (chValue == _T('\0')) { szValue[j] = _T('\0'); break; } switch (m_eNumFormat) { case NF_HEX: if (_istxdigit(chValue)) szValue[j++] = (TCHAR)_totupper(chValue); break; case NF_DEC: if (_istdigit(chValue)) szValue[j++] = chValue; break; } } if (nStart > j) nStart = j; if (nEnd > j) nEnd = j; SetWindowText(szValue); SetSel(nStart, nEnd); LockWindowUpdate(FALSE); }
LRESULT COXMaskedEdit::OnPaste(WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(wParam); UNREFERENCED_PARAMETER(lParam); if(m_listData.GetCount()==0 || GetStyle()&ES_READONLY) { return CEdit::Default(); } int nSelectionStart=0; int nSelectionEnd =0; GetSel(nSelectionStart, nSelectionEnd); CEdit::Default(); // This is a real dump paste routine that expects SetInputData do // do the filtering. There is probably no easy solution to this // task because anything can be pasted. We could try and match // the literals, but maybe we will get to that later. CString csNewString; GetWindowText(csNewString); // It is very important that we do not allow the prompt character // in this scenario. This is because we expect the pasted text // to contain lots of literals and spaces. SetInputData(csNewString, 0, FALSE); Update(-1); // Setting the insertion point after a paste is tricky because the // expected location is after the last valid pasted character. // Try and determine this location by setting the insertion point // to the first empty location after the specified starting point. int nNewInsertionPoint=GetEmptyInputLocation(nSelectionStart); SetSel(nNewInsertionPoint, nNewInsertionPoint); return 0; }
void CArborEditCurrency::DDV_Float() { // check to see if the control was modified at all....if so continue if( GetModify() ) { double dMinVal = 0.0; double dMaxVal = 0.0; // if they didn't set a range, but entered a number, validate with max values // that can be stored in the database..... if( m_bDoubleRangeSet ) { dMinVal = m_dMinValue; dMaxVal = m_dMaxValue; } else { if( m_bNegativeValue ) dMinVal = INT_MIN/100.0; else dMinVal = 0.0; dMaxVal = INT_MAX/100.0; } if( !ValidateDouble( dMinVal, dMaxVal ) ) { CString sMsg; // sMsg.Format( "Number is not valid!\nPlease enter a number between %f - %f.", dMinVal, dMaxVal ); sMsg.Format( GetIntlString(IDS_NUMBER_NOT_VALID_MSG),"%f - %f.", dMinVal, dMaxVal ); AfxMessageBox( sMsg, MB_ICONEXCLAMATION ); SetSel( 0, -1 ); SetFocus(); AfxThrowUserException(); } } }
BOOL CRichEditCtrlX::OnCommand(WPARAM wParam, LPARAM /*lParam*/) { switch (wParam) { case MP_UNDO: Undo(); break; case MP_CUT: Cut(); break; case MP_COPYSELECTED: Copy(); break; case MP_PASTE: Paste(); break; case MP_REMOVESELECTED: Clear(); break; case MP_SELECTALL: SetSel(0, -1); break; } return TRUE; }
/*---------------------------------------------------------------------------------------------- Handle Edit commands @param pcmd @return true if successful ----------------------------------------------------------------------------------------------*/ bool AfDeFeEdBoxBut::DeEdit::CmdEdit(Cmd * pcmd) { AssertObj(pcmd); switch (pcmd->m_cid) { case kcidEditCut: m_ch = VK_DELETE; Cut(); break; case kcidEditCopy: Copy(); break; case kcidEditPaste: m_ch = 0; // Special code to indicate paste. Paste(); break; case kcidEditDel: // ::SendMessage(m_hwnd, WM_CLEAR, 0, 0); // TODO KenZ: We have a problem here since kcidEditDel is used both here for text // deletion as well as in RnDeSplitChild for entry deletions. At this point it hits // this one first and if we return true, it never gets to the other one. We need to // get smarter and ask the user what should be deleted and then do the appropriate // thing. return false; break; case kcidEditSelAll: SetSel(0, -1); m_cchMatched = 0; break; default: Assert(false); // We shouldn't get here. return false; } return true; }