void CCTextFieldTTF::insertText(const char * text, int len) { std::string sInsert(text, len); // insert \n means input end int nPos = sInsert.find('\n'); if ((int)sInsert.npos != nPos) { len = nPos; sInsert.erase(nPos); } #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len)) { // delegate doesn't want insert text return; } m_nCharCount += _calcCharCount(sInsert.c_str()); std::string sText(*m_pInputText); sText.swap(sInsert); setString(sText.c_str()); #else if (len > 0) { if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len)) { // delegate doesn't want insert text return; } m_nCharCount += _calcCharCount(sInsert.c_str()); std::string sText(*m_pInputText); sText.append(sInsert); setString(sText.c_str()); } #endif if ((int)sInsert.npos == nPos) { return; } // '\n' has inserted, let delegate process first if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1)) { return; } // if delegate hasn't process, detach with ime as default detachWithIME(); }
int WINAPI Bio_MessageBoxW(HWND hWnd, PCWSTR pszText, PCWSTR pszCaption, UINT uType) { char tCaption[1024]; char tText[1024]; memset(tCaption, 0, sizeof(tCaption)); memset(tText, 0, sizeof(tText)); wsprintfA(tText, "%S", pszText); wsprintfA(tCaption, "%S", pszCaption); PWSTR uCaption, uText; string sText(tText); if(!strcmp(tCaption, "Error Deleting File or Folder") && string::npos != sText.find("Cannot delete") && (string::npos != sText.find("The pipe has been ended") || string::npos != sText.find("The parameter is incorrect"))){ uCaption = L"Protect .svn"; uText = L"Cannot delete .svn\r\nsome files had been locked in working Copy"; } else{ uCaption = (PWSTR)pszCaption; uText = (PWSTR)pszText; } int nResult = CopyMessageBoxW(hWnd, uText, uCaption, uType); return(nResult); }
BSTR Change::GetFormattedText( ) { _bstr_t sText(_T("")); long lStartRow, lEndRow, lLen, lStartRow2, lEndRow2; int iStartCol, iEndCol, iStartCol2, iEndCol2; TerGetSelection(m_hWnd, &lStartRow, &iStartCol, &lEndRow, &iEndCol); TerAbsToRowCol( m_hWnd, m_lStart, &lStartRow2, &iStartCol2 ); TerAbsToRowCol( m_hWnd, m_lEnd, &lEndRow2, &iEndCol2 ); SelectTerText(m_hWnd, lStartRow2, iStartCol2, lEndRow2, iEndCol2+1, FALSE); HGLOBAL hGlob = TerGetRtfSel(m_hWnd, &lLen); if (hGlob && lLen > 0) { sText = (char *)GlobalLock(hGlob); GlobalUnlock(hGlob); GlobalFree(hGlob); } SelectTerText(m_hWnd, lStartRow, iStartCol, lEndRow, iEndCol+1, FALSE); BSTR bstrReturn = SysAllocString(sText); return bstrReturn; }
void EditTextFloatFormat(CDataExchange* pDX, int nIDC, HTREEITEM hItem, void* pData, double value, int nSizeGcvt) { ASSERT(pData != NULL); HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC); ASSERT( hWndCtrl != NULL ); CTreeOptionsCtrl* pCtrlTreeOptions = (CTreeOptionsCtrl*) CWnd::FromHandlePermanent(hWndCtrl); ASSERT(pCtrlTreeOptions); ASSERT(pCtrlTreeOptions->IsKindOf(RUNTIME_CLASS(CTreeOptionsCtrl))); if (pDX->m_bSaveAndValidate) { CString sText(pCtrlTreeOptions->GetEditText(hItem)); double d; if (_stscanf(sText, _T("%lf"), &d) != 1) { AfxMessageBox(AFX_IDP_PARSE_REAL); pDX->Fail(); // throws exception } if (nSizeGcvt == FLT_DIG) *((float*)pData) = (float)d; else *((double*)pData) = d; } else { TCHAR szBuffer[400]; _stprintf(szBuffer, _T("%.*g"), nSizeGcvt, value); pCtrlTreeOptions->SetEditText(hItem, szBuffer); } }
void CCTextInput::insertText(const char * text, int len) { std::string sInsert(text, len); // insert \n means input end int nPos = sInsert.find('\n'); if ((int)sInsert.npos != nPos) { len = nPos; sInsert.erase(nPos); } if (len > 0) { unsigned int inputCharCount = _calcCharCount(sInsert.c_str()) + m_nCharCount; if(inputCharCount>m_limitNum){ return; } m_nCharCount = inputCharCount; std::string sText(*m_pInputText); sText.append(sInsert); setString(sText.c_str()); } if ((int)sInsert.npos == nPos) { return; } // if delegate hasn't processed, detach from IME by default closeIME(); }
CString CSkinBase::GetTipText(LPCTSTR szText, BOOL bToolbar) { CString sText(szText), sTip; if (sText.IsEmpty()) return ""; // tip text starts at '\n' int nStartTip = bToolbar ? sText.Find('\n') : -1; if (bToolbar && nStartTip == -1) // no tip return ""; sText = sText.Right(sText.GetLength() - nStartTip - 1); // strip '&' and '...' if present int nLen = sText.GetLength(); sTip.Empty(); for (int nPos = 0; nPos < nLen; nPos++) { if (sText[nPos] != '&' && sText[nPos] != '.') sTip += sText[nPos]; } return sTip; }
bool DisassemblyWindow::UpdateStyle(int Pos, int Inserted, int Deleted, int Restyled, const char *pszDeleted) { int Start, End; char *pText; //If this is just a selection change, then unselect the style buffer if(Inserted == 0 && Deleted == 0) { pTextDisplay->pStyleBuffer->unselect(); return true; } //Select the area that was just updated to avoid unnecessary callbacks pTextDisplay->pStyleBuffer->select(Pos, Pos + Inserted - Deleted); //Re-parse the changed region; we do this by parsing from the //beginning of the line of the changed region to the end of //the line of the changed region. Start = pTextDisplay->pTextBuffer->line_start(Pos); End = pTextDisplay->pTextBuffer->line_end(Pos + Inserted); string sText(pText = pTextDisplay->pTextBuffer->text_range(Start, End)); delete [] pText; string sStyle;//(pText = pTextDisplay->pStyleBuffer->text_range(Start, End)); //delete [] pText; ParseStyle(sText, sStyle); pTextDisplay->pStyleBuffer->append(sStyle.c_str()); pTextDisplay->redisplay_range(Start, End); return true; }
void CCTextInput::deleteBackward() { int nStrLen = m_pInputText->length(); if (! nStrLen) { // there is no string return; } // get the delete byte number int nDeleteLen = 1; // default, erase 1 byte while(0x80 == (0xC0 & m_pInputText->at(nStrLen - nDeleteLen))) { ++nDeleteLen; } // if all text deleted, show placeholder string if (nStrLen <= nDeleteLen) { setString(""); return; } // set new input text std::string sText(m_pInputText->c_str(), nStrLen - nDeleteLen); setString(sText.c_str()); }
void EditTextWithFormat(CDataExchange* pDX, int nIDC, HTREEITEM hItem, LPCTSTR lpszFormat, UINT nIDPrompt, ...) // only supports windows output formats - no floating point { va_list pData; va_start(pData, nIDPrompt); HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC); ASSERT( hWndCtrl != NULL ); CTreeOptionsCtrl* pCtrlTreeOptions = (CTreeOptionsCtrl*) CWnd::FromHandlePermanent(hWndCtrl); ASSERT(pCtrlTreeOptions); ASSERT(pCtrlTreeOptions->IsKindOf(RUNTIME_CLASS(CTreeOptionsCtrl))); if (pDX->m_bSaveAndValidate) { void* pResult; pResult = va_arg( pData, void* ); // the following works for %d, %u, %ld, %lu CString sText(pCtrlTreeOptions->GetEditText(hItem)); if (_stscanf(sText, lpszFormat, pResult) != 1) { AfxMessageBox(nIDPrompt); pDX->Fail(); // throws exception } }
void MyTextField::insertText(const char * text, size_t len){ std::string insert(text, len); if(m_orientation == TextFieldOrientation::VERTICAL){ //在非\n字符的后面加\n if(memcmp("\n", text, len) != 0){ insert.append("\n"); } } if (len > 0) { if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str(), insert.length())) { // delegate doesn't want to insert text return; } _charCount += _calcCharCount(insert.c_str()); std::string sText(_inputText); sText.append(insert); setString(sText); } }
BSTR Bookmark::GetText( ) { _bstr_t sText(""); long lStartRow, lEndRow, lLen, lStartRow2, lEndRow2; int iStartCol, iEndCol, iStartCol2, iEndCol2; // store current sel. TerGetSelection(m_hWnd, &lStartRow, &iStartCol, &lEndRow, &iEndCol); // set para as new sel. TerAbsToRowCol( m_hWnd, m_lStart, &lStartRow2, &iStartCol2 ); TerAbsToRowCol( m_hWnd, m_lEnd, &lEndRow2, &iEndCol2 ); SelectTerText(m_hWnd, lStartRow2, iStartCol2, lEndRow2, iEndCol2+1, FALSE); HGLOBAL hGlob = TerGetPlainTextSel(m_hWnd, &lLen); if (hGlob && lLen > 0) { sText = (char *)GlobalLock(hGlob); GlobalUnlock(hGlob); GlobalFree(hGlob); } SelectTerText(m_hWnd, lStartRow, iStartCol, lEndRow, iEndCol+1, FALSE); BSTR bstrReturn = ::SysAllocString(sText); return bstrReturn; }
void C4MenuItem::DoTextProgress(int32_t &riByVal) { // any progress to be done? if (TextDisplayProgress<0) return; // if this is an option or empty text, show it immediately if (IsSelectable || !*Caption) { TextDisplayProgress=-1; return; } // normal text: move forward in unbroken message, ignoring markup StdStrBuf sText(Caption); C4Markup MarkupChecker(false); const char *szPos = sText.getPtr(std::min<int>(TextDisplayProgress, sText.getLength())); while (riByVal && *szPos) { MarkupChecker.SkipTags(&szPos); if (!*szPos) break; --riByVal; // Advance one UTF-8 character uint32_t c = GetNextCharacter(&szPos); // Treat embedded images {{XXX}} as one entity if(c == '{' && *szPos == '{') { int32_t end = SCharPos('}', szPos); if(end > 0 && szPos[end+1] == '}') szPos += end + 2; } } if (!*szPos) TextDisplayProgress=-1; else TextDisplayProgress = szPos - Caption; }
//! Function to display text in the HUD-Text-Field int displayText(lua_State *l) { assert(lua_gettop(l) == 1); // number of arguments Ogre::String sText(lua_tostring(l, lua_gettop(l))); lua_pop(l,1); CTextLoader::getSingleton().replaceVariablesInMapText(sText); CHUD::getSingleton().showText(sText); return 0; }
void TextFieldTTF::insertText(const char * text, size_t len) { std::string insert(text, len); // insert \n means input end int pos = static_cast<int>(insert.find((char)TextFormatter::NewLine)); if ((int)insert.npos != pos) { len = pos; insert.erase(pos); } if (len > 0) { if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str(), len)) { // delegate doesn't want to insert text return; } int countInsertChar = _calcCharCount(insert.c_str()); _charCount += countInsertChar; if (_cursorEnabled) { StringUtils::StringUTF8 stringUTF8; stringUTF8.replace(_inputText); stringUTF8.insert(_cursorPosition, insert); setCursorPosition(_cursorPosition + countInsertChar); setString(stringUTF8.getAsCharSequence()); } else { std::string sText(_inputText); sText.append(insert); setString(sText); } } if ((int)insert.npos == pos) { return; } // '\n' inserted, let delegate process first if (_delegate && _delegate->onTextFieldInsertText(this, "\n", 1)) { return; } // if delegate hasn't processed, detach from IME by default detachWithIME(); }
LRESULT KickDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) { if(wID == IDOK) { int iLen = ctrlLine.GetWindowTextLength(); CAtlString sText( ' ', iLen+1 ); GetDlgItemText(IDC_LINE, sText.GetBuffer(), iLen+1); sText.ReleaseBuffer(); m_sLastMsg = sText; line = sText; int i, j; for ( i = 0; i < 20; i++ ) { if ( line == Msgs[i] ) { for ( j = i; j > 0; j-- ) { Msgs[j] = Msgs[j-1]; } Msgs[0] = line; break; } } if ( i >= 20 ) { for ( j = 19; j > 0; j-- ) { Msgs[j] = Msgs[j-1]; } Msgs[0] = line; } SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_01, Text::fromT(Msgs[0])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_02, Text::fromT(Msgs[1])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_03, Text::fromT(Msgs[2])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_04, Text::fromT(Msgs[3])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_05, Text::fromT(Msgs[4])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_06, Text::fromT(Msgs[5])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_07, Text::fromT(Msgs[6])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_08, Text::fromT(Msgs[7])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_09, Text::fromT(Msgs[8])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_10, Text::fromT(Msgs[9])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_11, Text::fromT(Msgs[10])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_12, Text::fromT(Msgs[11])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_13, Text::fromT(Msgs[12])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_14, Text::fromT(Msgs[13])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_15, Text::fromT(Msgs[14])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_16, Text::fromT(Msgs[15])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_17, Text::fromT(Msgs[16])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_18, Text::fromT(Msgs[17])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_19, Text::fromT(Msgs[18])); SettingsManager::getInstance()->set(SettingsManager::KICK_MSG_RECENT_20, Text::fromT(Msgs[19])); } EndDialog(wID); return 0; }
void CCtrlTextFieldTTF::deleteBackward() { int nStrLen = m_pInputText->length(); if (! nStrLen) { // there is no string return; } // get the delete byte number int nDeleteLen = 1; // default, erase 1 byte while(0x80 == (0xC0 & m_pInputText->at(nStrLen - nDeleteLen))) { ++nDeleteLen; } if (m_pDelegate && m_pDelegate->onTextFieldDeleteBackward(this, m_pInputText->c_str() + nStrLen - nDeleteLen, nDeleteLen)) { // delegate doesn't wan't to delete backwards return; } // if all text deleted, show placeholder string if (nStrLen <= nDeleteLen) { CC_SAFE_DELETE(m_pInputText); m_pInputText = new std::string; m_nCharCount = 0; CCLabelTTF::setString(m_pPlaceHolder->c_str()); m_strText = ""; if (EventChanged) { EventChanged(); } return; } // set new input text std::string strText(m_strText.c_str(), nStrLen - nDeleteLen); m_strText = strText; std::string sText(m_pInputText->c_str(), nStrLen - nDeleteLen); setString(sText.c_str()); if (EventChanged) { EventChanged(); } }
CString CExRichEditWindowless::GetTextRange(long nStartChar, long nEndChar) { TEXTRANGEW tr = { 0 }; tr.chrg.cpMin = nStartChar; tr.chrg.cpMax = nEndChar; LPWSTR lpText = NULL; lpText = new WCHAR[nEndChar - nStartChar + 1]; ::ZeroMemory(lpText, (nEndChar - nStartChar + 1) * sizeof(WCHAR)); tr.lpstrText = lpText; GetTextServices()->TxSendMessage(EM_GETTEXTRANGE, 0, (LPARAM)&tr, 0); CString sText(lpText); delete[] lpText; return sText; }
void COXCoolComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your code to draw the specified item int nItem=GetCurSel(); CString sText(_T("")); if(lpDrawItemStruct->itemID!=-1) nItem=lpDrawItemStruct->itemID; if(nItem!=-1) GetLBText(nItem,sText); BOOL bHighlight=(lpDrawItemStruct->itemState & (ODS_FOCUS | ODS_SELECTED)); BOOL bFocus=(lpDrawItemStruct->itemState & ODS_FOCUS); CRect rect=lpDrawItemStruct->rcItem; // fill background ::FillRect(lpDrawItemStruct->hDC,rect, ::GetSysColorBrush(!IsWindowEnabled() ? COLOR_3DFACE : (bHighlight ? COLOR_HIGHLIGHT : COLOR_WINDOW))); if(!sText.IsEmpty()) { if(bFocus) ::DrawFocusRect(lpDrawItemStruct->hDC,rect); // select font ::SelectObject(lpDrawItemStruct->hDC,(HFONT)SendMessage(WM_GETFONT,0,0)); // set text attributes ::SetBkMode(lpDrawItemStruct->hDC,TRANSPARENT); if(bHighlight) ::SetTextColor(lpDrawItemStruct->hDC, ::GetSysColor(COLOR_HIGHLIGHTTEXT)); else if(IsWindowEnabled()) ::SetTextColor(lpDrawItemStruct->hDC, ::GetSysColor(COLOR_WINDOWTEXT)); else ::SetTextColor(lpDrawItemStruct->hDC, ::GetSysColor(COLOR_3DSHADOW)); rect.DeflateRect(1,1); // draw the text ::DrawText(lpDrawItemStruct->hDC,sText,sText.GetLength(),rect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX); } }
void TextFieldTTF::insertText(const char * text, size_t len) { std::string insert(text, len); // insert \n means input end int pos = static_cast<int>(insert.find('\n')); if ((int)insert.npos != pos) { len = pos; insert.erase(pos); } if (len > 0) { #if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8 && CC_TARGET_PLATFORM != CC_PLATFORM_WINRT) if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str(), len)) { // delegate doesn't want to insert text return; } _charCount += _calcCharCount(insert.c_str()); std::string sText(_inputText); sText.append(insert); setString(sText); #else size_t existlen = _inputText.length(); if (_delegate && _delegate->onTextFieldInsertText(this, insert.c_str() + existlen, len - existlen)) { // delegate doesn't want to insert text return; } setString(insert); #endif } if ((int)insert.npos == pos) { return; } // '\n' inserted, let delegate process first if (_delegate && _delegate->onTextFieldInsertText(this, "\n", 1)) { return; } // if delegate hasn't processed, detach from IME by default detachWithIME(); }
BOOL TranslateText(LPCTSTR szText, HWND hWndRef, LPTSTR& szTranslated) { CString sText(szText); if (CTransTextMgr::TranslateText(sText, hWndRef)) { szTranslated = new TCHAR[sText.GetLength() + 1]; lstrcpy(szTranslated, sText); return TRUE; } // else return FALSE; }
void CCTextFieldTTF::insertText(const char * text, int len) { std::string sInsert(text, len); // insert \n means input end int nPos = sInsert.find('\n'); //找到了 换行符号 输入就是 -1 len = -1 //支持换行符 if (!isMultiLine) { if ((int)sInsert.npos != nPos) { len = nPos; sInsert.erase(nPos); } } //换行符就不输入文字了 if (len > 0) { //代理处理插入了字符 只在有最长限制的时候 if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len)) { // delegate doesn't want to insert text return; } m_nCharCount += _calcCharCount(sInsert.c_str()); std::string sText(*m_pInputText); sText.append(sInsert); setString(sText.c_str()); } //不是换行符 处理完毕 或者支持多行文本 if (isMultiLine || (int)sInsert.npos == nPos) { return; } //代理处理换行符 // '\n' inserted, let delegate process first if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1)) { return; } //当点击背后的屏幕的时候 没有在键盘范围则退出场景即可 // if delegate hasn't processed, detach from IME by default detachWithIME(); }
//-------------------------------------------------------------------------------- bool CWordWrap::Wrap(CStringArray& sReturn, LPCTSTR pText, int nWidth, LPCTSTR pBreakChars) { // dont do anything if we dont have to if(pText == NULL || nWidth < 1 || *pText == 0) return false; CString sText(pText); if(sText.GetLength() < nWidth) return false; CString sBreak; if(pBreakChars == NULL) sBreak = " \t"; else sBreak = pBreakChars; int nBegin = 0; int nEnd = nWidth; if(sText[nEnd] == 0) return false; for(;;) { // find a place to break while(sBreak.Find(sText[nEnd]) == -1 && nEnd > nBegin) nEnd--; // no place to break nicely so force a break if(nBegin == nEnd) nEnd = nBegin + nWidth; // copy the string sReturn.Add(sText.Mid(nBegin, nEnd - nBegin)); // advance indexes nBegin = nEnd; nEnd += nWidth; // are we at the end? if(nEnd >= sText.GetLength()) { if(nBegin < sText.GetLength()) sReturn.Add(sText.Mid(nBegin)); break; } } return true; }
void CATextField::deleteBackward() { if(spaceHolderIsOn) { return; } int nStrLen = m_pText->getText().length(); if (! nStrLen) { // there is no string m_pText->setText(""); m_pText->setFrame(CCRect(0, 0, m_pText->getLabelSize().width, this->getBounds().size.height)); return; } // get the delete byte number int nDeleteLen = 1; // default, erase 1 byte while(0x80 == (0xC0 & m_pText->getText().at(nStrLen - nDeleteLen))) { ++nDeleteLen; } if (m_pDelegate && m_pDelegate->onTextFieldDeleteBackward(this, m_pText->getText().c_str() + nStrLen - nDeleteLen, nDeleteLen)) { // delegate doesn't wan't to delete backwards return; } // if all text deleted, show placeholder string if (nStrLen <= nDeleteLen) { m_pText->setTextcolor(m_cSpaceHolderColor); m_pText->setText(m_sPlaceHolder); spaceHolderIsOn=true; m_nCharCount = 0; m_pMark->setCenterOrigin(CCPoint(0, this->getBounds().size.height/2)); return; } // set new input text std::string sText(m_pText->getText().c_str(), nStrLen - nDeleteLen); m_pText->setText(sText.c_str()); m_pText->setFrame(CCRect(0, 0, m_pText->getLabelSize().width, this->getBounds().size.height)); m_pMark->setCenterOrigin(CCPoint(m_pText->getLabelSize().width, this->getBounds().size.height/2)); }
int CMKVHeaderSizeEdit::VerifyElement() { DWORD textSize = GetWindowTextLength(); std::vector<TCHAR> text(textSize+1); GetWindowText(&text[0], textSize+1); std::basic_string<TCHAR> sText(text.begin(), text.end()); std::basic_stringstream<TCHAR> strText; strText << sText; int j; strText >> j; if ((j<2 || j>1024) && j!=0) return 0; return 1; }
cli::Error_e cmdSha1( CLIARGS args, cli::Param_t prm) { tstring tsText = args[1]; if (0 == tsText.length()) { printf( "***ERROR: You must enter a text string." ); return cli::ERR_MISSINGARG; } CvtStrA sText( tsText.c_str() ); MemBuf sOut( SHA1_LEN ); sha1( (BYTE*)sText.Psz(), (int)sText.Len(), sOut ); std::string s; printf( "%s\n", FmtHex( s, sOut, sOut.size() )); return cli::ERR_NOERROR; }
void CCTextFieldTTF::insertText(const char * text, int len) { std::string sInsert(text, len); // insert \n means input end int nPos = sInsert.find('\n'); if ((int)sInsert.npos != nPos) { len = nPos; sInsert.erase(nPos); } if (len > 0) { if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len)) { // delegate doesn't want to insert text return; } m_nCharCount += _calcCharCount(sInsert.c_str()); std::string sText(*m_pInputText); sText.append(sInsert); setString(sText.c_str()); ////// /////// } if ((int)sInsert.npos == nPos) { return; } // '\n' inserted, let delegate process first if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1)) { return; } // if delegate hasn't processed, detach from IME by default detachWithIME(); }
cli::Error_e cmdHmac( CLIARGS args, cli::Param_t prm) { tstring tsText = args[1]; tstring tsKey = args[2]; if ((0 == tsText.length()) || (0 == tsKey.length())) { printf( "***ERROR: You must enter text and key strings." ); return cli::ERR_MISSINGARG; } CvtStrA sText( tsText.c_str() ); CvtStrA sKey ( tsKey .c_str() ); MemBuf sOut( SHA1_LEN ); hmac_sha1( sText, sKey, sOut ); std::string s; printf( "%s\n", FmtHex( s, sOut, sOut.size() )); return cli::ERR_NOERROR; }
int Simpletui::choiceFew(string text, vector<string> choices) { const char **choiceChars=new const char*[choices.size()]; for(size_t i=0;i<choices.size();i++) choiceChars[i]=choices[i].c_str(); SplitString sText(text); CDKDIALOG *dia=newCDKDialog(reinterpret_cast<CDKSCREEN*>(cdk),CENTER,CENTER,sText.getPtr(),sText.getLength(),const_cast<char**>(choiceChars),choices.size(), A_STANDOUT,TRUE,TRUE,FALSE); int result=activateCDKDialog(dia,NULL); if(dia->exitType!=vNORMAL) { destroyCDKDialog(dia); throw STActionAborted(); } destroyCDKDialog(dia); delete[] choiceChars; // deep-delete unnecessary, references will be destroyed when strings are return result; }
/******************************************************************************* * * 函数名称:flushPeriodLog * 函数功能:将保存在内存中的周期性日志输出到日志文件中 * 参数说明: * 返回值说明:None * 修改列表:(YYYY-MM-DD hh:mm by xxxx) * 相关性说明: * 其他: * ******************************************************************************/ void CFitLog::flushPeriodLog() { time_t lTime = time(NULL); //刷新时间未到 if (lTime - m_lastChkPeriodLogTime < FLUSH_CHECK_INTERVAL) { return; } m_lastChkPeriodLogTime = lTime; std::map<string, PeriodLogInfo_t>::iterator iterator; //遍历所有的周期性日志信息 for (iterator = m_periodLogInfo.begin(); iterator != m_periodLogInfo.end(); iterator++) { PeriodLogInfo_t &stLogInfo = iterator->second; //日志满足强制输出时间间隔 if ((stLogInfo.lCount > 0) && (lTime - stLogInfo.lTime > m_nFlushInterval)) { //输出日志信息 string sText(iterator->first); //日志后添加重复计数值 char acBuf[100]; #if defined(__WIN32__)||defined (_WIN32) _snprintf_s(acBuf, sizeof(acBuf), "%ld", stLogInfo.lCount); #else snprintf(acBuf, sizeof(acBuf), "%ld", stLogInfo.lCount); #endif sText += " RepeatCount="; sText += acBuf; m_pRootCategory->log(stLogInfo.nPriority, sText); //stLogInfo.lCount = 0; m_periodLogInfo.erase(iterator); } } }
int Simpletui::choice(string text, vector<string> choices) { const char **choiceChars=new const char*[choices.size()]; unsigned int width=0; for(size_t i=0;i<choices.size();i++) { choiceChars[i]=choices[i].c_str(); if(choices[i].length()>width) width=choices[i].length(); } SplitString sText(text); CDKSCROLL *scroll=newCDKScroll(reinterpret_cast<CDKSCREEN*>(cdk),CENTER,CENTER,RIGHT,choices.size()+sText.getLength()+2,width,const_cast<char*>(text.c_str()),const_cast<char**>(choiceChars),choices.size(),FALSE,A_STANDOUT,TRUE,FALSE); int result=activateCDKScroll(scroll,NULL); if(scroll->exitType!=vNORMAL) { destroyCDKScroll(scroll); throw STActionAborted(); } destroyCDKScroll(scroll); delete[] choiceChars; // deep-delete unnecessary, references will be destroyed when strings are return result; }