void CRichEditCtrlGS::LoadRTF(const CString strFilename) { SCookieFile CookieRTF; CFileStatus fileStatus; CString strRTF = _T(""); CookieRTF.lStart = 0; CookieRTF.pFilename = &strFilename; // Close all filehandles if( CFile::hFileNull != CookieRTF.fileInText.m_hFile ) { CookieRTF.fileInText.Close(); } if( CFile::hFileNull != CookieRTF.fileOutText.m_hFile ) { CookieRTF.fileOutText.Close(); } // Is the filename the name of a file? if( CFile::GetStatus(strFilename, fileStatus) ) { if( (fileStatus.m_attribute & ( CFile::volume | CFile::directory )) ) { AfxMessageBox(AFX_IDP_INVALID_FILENAME); return; // Filename is not the name of a file } } else { AfxMessageBox(AFX_IDP_INVALID_FILENAME); return;// The name is not existing } CookieRTF.lSize = fileStatus.m_size; if( !CookieRTF.fileInText.Open( *CookieRTF.pFilename,CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary ) ) { AfxMessageBox(AFX_IDP_FAILED_TO_OPEN_DOC); return; // File could not be opened } CookieRTF.fileInText.SeekToBegin(); LPTSTR pBuff = strRTF.GetBuffer(15); CookieRTF.fileInText.Read(pBuff,5); pBuff[5] = 0; strRTF.ReleaseBuffer(); EDITSTREAM es; es.dwError = 0; es.pfnCallback = StreamInCFile; // Set the callback es.dwCookie = (DWORD)&CookieRTF; // and the informations if( strRTF.CompareNoCase(_T("{\\rtf")) == 0 ) { StreamIn(SF_RTF,es); } else { StreamIn(SF_TEXT,es); } CookieRTF.fileInText.Close(); }
CBProjectNode::CBProjectNode ( std::istream& input, const JFileVersion vers, CBProjectNode* parent, const CBProjectNodeType type, const JBoolean isOpenable ) : JNamedTreeNode(NULL, "", isOpenable), itsType(type) { if (parent != NULL) { parent->Append(this); } JString name; input >> name; SetName(name); if (vers <= 71) { JSize childCount; input >> childCount; for (JIndex i=1; i<=childCount; i++) { StreamIn(input, vers, this); // connects itself } }
bool CXBMCTinyXML::LoadFile(const CStdString &_filename, TiXmlEncoding encoding) { // There was a really terrifying little bug here. The code: // value = filename // in the STL case, cause the assignment method of the std::string to // be called. What is strange, is that the std::string had the same // address as it's c_str() method, and so bad things happen. Looks // like a bug in the Microsoft STL implementation. // Add an extra string to avoid the crash. CStdString filename(_filename); value = filename; XFILE::CFileStream file; if (!file.Open(value)) { SetError(TIXML_ERROR_OPENING_FILE, NULL, NULL, TIXML_ENCODING_UNKNOWN); return false; } // Delete the existing data: Clear(); location.Clear(); CStdString data; data.reserve(8 * 1000); StreamIn(&file, &data); file.Close(); Parse(data, NULL, encoding); if (Error()) return false; return true; }
void CStatusCtrl::OnOutputcontextClearall() { USES_CONVERSION; CString rtfstr = m_RTFHeader; rtfstr += "} "; char *buffer = new char[rtfstr.GetLength() + 5]; strcpy(buffer + 4, T2CA(rtfstr)); *(int *)buffer = 0; EDITSTREAM es; es.dwCookie = (DWORD)buffer; // 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(); delete [] buffer; m_bEmpty = TRUE; m_nMoveToBottom = 0; }
int CStatusCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CRichEditCtrl::OnCreate(lpCreateStruct) == -1) return -1; USES_CONVERSION; m_RTFHeader = "{\\rtf1\\ansi\\deff0"; HFONT hSysFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONT lf; CFont* pFont = CFont::FromHandle( hSysFont ); pFont->GetLogFont( &lf ); LOGFONT m_lfFont; pFont->GetLogFont(&m_lfFont); int pointsize = (-m_lfFont.lfHeight*72/ GetDeviceCaps(GetDC()->GetSafeHdc(), LOGPIXELSY))*2; CString fontname = m_lfFont.lfFaceName; //if (COptions::GetOptionVal(OPTION_MESSAGELOG_USECUSTOMFONT)) //{ // CString fn = COptions::GetOption(OPTION_MESSAGELOG_FONTNAME); // int pt = COptions::GetOptionVal(OPTION_MESSAGELOG_FONTSIZE); // if (fn != "") // fontname = fn; // if (pt != 0) // pointsize = pt * 2; //} m_RTFHeader += ("{\\fonttbl{\\f0\\fnil "); m_RTFHeader += fontname; m_RTFHeader += (";}}"); m_RTFHeader += "{\\colortbl ;"; for (int i=0; i<16; i++) { CString tmp; tmp.Format(_T("\\red%d\\green%d\\blue%d;"), GetRValue(m_ColTable[i]), GetGValue(m_ColTable[i]), GetBValue(m_ColTable[i])); m_RTFHeader+=tmp; } m_RTFHeader += "}"; CString tmp; tmp.Format(_T("%d"), pointsize); m_RTFHeader += ("\\uc1\\pard\\fi-50\\li50\\tx50\\f0\\fs"); m_RTFHeader += tmp; CString rtfstr = m_RTFHeader; rtfstr += "} "; EDITSTREAM es; string s = Util::ws2s(wstring(rtfstr)); es.dwCookie = (DWORD)&s; // Pass a pointer to the string 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); return 0; }
void CRichEditCtrlX::SetRTFText(const CStringA& rstrTextA) { CMemFile memFile((BYTE*)(LPCSTR)rstrTextA, rstrTextA.GetLength()); EDITSTREAM es = {0}; es.pfnCallback = StreamInCallback; es.dwCookie = (DWORD_PTR)&memFile; StreamIn(SF_RTF, es); }
void CRichInfo::SetText(int format, const CString& text) { CMemFile inFile((BYTE*)((LPCTSTR)text),text.GetLength()); EDITSTREAM stream; stream.dwCookie = (DWORD)&inFile; stream.pfnCallback = RichStreamCB; StreamIn(format,stream); }
void CPickup::SetRotation(const CVector3& vecRotation) { m_vecRotation = vecRotation; // Are we streamed in? if(IsStreamedIn()) { // Stream ourselves out and back in StreamOut(); StreamIn(); } }
void CPickup::SetValue(unsigned int uiValue) { m_uiValue = uiValue; // Are we streamed in? if(IsStreamedIn()) { // Stream ourselves out and back in StreamOut(); StreamIn(); } }
void CAutoRichEditCtrl::SetRTF(CString sRTF) { // Put the RTF string sRTF into the rich edit control. // Read the text in EDITSTREAM es; es.dwError = 0; es.pfnCallback = CBStreamIn; es.dwCookie = (DWORD) &sRTF; StreamIn(SF_RTF, es); // Do it. }
int CStatusCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CRichEditCtrl::OnCreate(lpCreateStruct) == -1) return -1; USES_CONVERSION; m_RTFHeader = "{\\rtf1\\ansi\\deff0"; HFONT hSysFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONT lf; CFont* pFont = CFont::FromHandle( hSysFont ); pFont->GetLogFont( &lf ); LOGFONT m_lfFont; pFont->GetLogFont(&m_lfFont); m_RTFHeader += "{\\fonttbl{\\f0\\fnil "+ CString(m_lfFont.lfFaceName)+";}}"; m_RTFHeader += "{\\colortbl ;"; for (int i=0; i<16; i++) { CString tmp; tmp.Format(_T("\\red%d\\green%d\\blue%d;"), GetRValue(m_ColTable[i]), GetGValue(m_ColTable[i]), GetBValue(m_ColTable[i])); m_RTFHeader+=tmp; } m_RTFHeader += "}"; int pointsize = (-m_lfFont.lfHeight*72/ GetDeviceCaps(GetDC()->GetSafeHdc(), LOGPIXELSY))*2; CString tmp; tmp.Format(_T("%d"), pointsize); m_RTFHeader += "\\uc1\\pard\\fi-200\\li200\\tx200\\f0\\fs"+tmp; //180*m_nAvgCharWidth; CString rtfstr = m_RTFHeader; rtfstr += "} "; char *buffer = new char[rtfstr.GetLength() + 5]; strcpy(buffer + 4, T2CA(rtfstr)); *(int *)buffer = 0; EDITSTREAM es; es.dwCookie = (DWORD)buffer; // 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); delete [] buffer; return 0; }
// Reading and Writing void CRichEditCtrlGS::SetRTF(const CString strText) { SCookieString CookieRTF; CookieRTF.lSize = strText.GetLength(); CookieRTF.lStart = 0; CookieRTF.pInText = &strText; CookieRTF.pOutText = NULL; CString strRTF = _T(""); if( strText.GetLength() > 5 ) { strRTF = strText.Left(5); } // Read the text in EDITSTREAM es; es.dwError = 0; es.pfnCallback = StreamInCString; // Set the callback es.dwCookie = (DWORD)&CookieRTF; // and the informations if( strRTF.CompareNoCase(_T("{\\rtf")) == 0 ) { StreamIn(SF_RTF,es); } else { StreamIn(SF_TEXT,es); } }
bool CScriptEditView::LoadFile( LPCTSTR szFilePath ) { ATLASSERT( szFilePath != NULL && szFilePath[0] != 0 ); DWORD dwFlag = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN; HANDLE hFile = ::CreateFile( szFilePath, GENERIC_READ, 0, NULL, OPEN_EXISTING, dwFlag, NULL ); if( hFile == INVALID_HANDLE_VALUE ) return false; EDITSTREAM es; es.dwCookie = reinterpret_cast<DWORD_PTR>(hFile); es.dwError = 0; es.pfnCallback = StreamReadCallback; StreamIn( SF_TEXT, es ); ::CloseHandle(hFile); return es.dwError == 0; }
bool CClientVehicle::SetModel(int iModelIndex) { // Is the model index different from our current model index? if(iModelIndex != m_pModelInfo->GetIndex()) { // Get the new model info CIVModelInfo * pNewModelInfo = g_pClient->GetGame()->GetModelInfo(iModelIndex); // Is the new model info valid? if(!pNewModelInfo || !pNewModelInfo->IsValid() || !pNewModelInfo->IsVehicle()) { CLogFile::Printf("CClientVehicle::SetModel Failed (Invalid model)!"); return false; } bool bSpawned = IsSpawned(); // Are we spawned? if(bSpawned) { // Destroy the old vehicle StreamOut(); } // Set the new model info m_pModelInfo = pNewModelInfo; // Are we spawned? if(bSpawned) { // Ensure the new model is loaded m_pModelInfo->Load(); // Create the new vehicle StreamIn(); } return true; } return false; }
//加载消息 bool CSkinRichEdit::LoadMessage(LPCTSTR pszFileName) { //效验参数 ASSERT(pszFileName!=NULL); if (pszFileName==NULL) return false; //打开文件 CFile File; if (File.Open(pszFileName,CFile::modeRead,NULL)==FALSE) return false; //构造数据 EDITSTREAM EditStream; EditStream.pfnCallback=LoadCallBack; EditStream.dwCookie=(DWORD)(LONGLONG)(&File); //读取文件 StreamIn(SF_RTF,EditStream); return true; }
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; }
///////////////////////////////////////////////////////////////////////////// // underlying implementation ///////////////////////////////////////////////////////////////////////////// void CChatControl::addString(CString str, BOOL bBold, COLORREF cr) { int iLength; EDITSTREAM es; CHARFORMAT cf; //avoid replacing selected text iLength = GetTextLength(); SetSel(iLength, iLength); //set the "cookie" es.dwCookie = (DWORD) &str; es.pfnCallback = streamIn; //prepare formatting cf.dwMask = CFM_COLOR | CFM_BOLD; cf.dwEffects = bBold ? CFE_BOLD : 0; cf.crTextColor = cr; SetWordCharFormat(cf); //stream in the text StreamIn(SF_TEXT | SFF_SELECTION, es); }
void CStatusCtrl::ShowStatus(CString status, int nType) { USES_CONVERSION; CString rtfstr = m_RTFHeader; status.Replace(_T("\\"), _T("\\\\")); status.Replace(_T("{"), _T("\\{")); status.Replace(_T("}"), _T("\\}")); status.Replace(_T("\r"), _T("")); status.Replace(_T("\n"), _T("\\status")); CString str; switch (nType) { case 0: str = "\\cf2"; break; case 1: str = "\\cf5"; break; case 2: str = "\\cf3"; break; case 3: str = "\\cf4"; break; } status = str + status; if (!m_bEmpty) rtfstr += "\\par " + status; else { m_bEmpty = FALSE; rtfstr += status; } rtfstr += "} "; char *buffer = new char[rtfstr.GetLength() + 5]; //Make it large enough to hold unicode data strcpy(buffer + 4, T2CA(rtfstr)); *(int *)buffer = 0; EDITSTREAM es; es.dwCookie = (DWORD)buffer; // Pass a pointer to the CString to the callback function es.pfnCallback = RichEditStreamInCallback; // Specify the pointer to the callback function. CWnd *pFocusWnd = GetFocus(); if (pFocusWnd && pFocusWnd == this) AfxGetMainWnd()->SetFocus(); long nStart, nEnd; GetSel(nStart, nEnd); BOOL nScrollToEnd = FALSE; int num = 0; //this is the number of visible lines CRect rect; GetRect(rect); int height = rect.Height(); for (int i = GetFirstVisibleLine(); i < GetLineCount() && GetCharPos(LineIndex(i)).y < height; i++) num++; if (GetFirstVisibleLine() + num+m_nMoveToBottom >= GetLineCount()) nScrollToEnd = TRUE; HideSelection(TRUE, FALSE); SetSel(-1, -1); StreamIn(SF_RTF | SFF_SELECTION, es); // Perform the streaming if (GetLineCount() > 1000) { nStart -= LineLength(0) + 2; nEnd -= LineLength(0) + 2; if (nStart < 0) nEnd = 0; if (nEnd < 0) nEnd = 0; SetSel(0, LineLength(0) + 2); ReplaceSel(_T("")); } SetSel(nStart, nEnd); if (pFocusWnd && pFocusWnd == this) SetFocus(); HideSelection(FALSE, FALSE); if (nScrollToEnd) { if (nStart != nEnd && (LineFromChar(nStart) >= GetFirstVisibleLine() && LineFromChar(nStart) <= GetFirstVisibleLine() + num || LineFromChar(nEnd) >= GetFirstVisibleLine() && LineFromChar(nEnd) <= GetFirstVisibleLine() + num)) LineScroll(1); else { m_nMoveToBottom++; if (!m_nTimerID) m_nTimerID = SetTimer(654, 25, NULL); } } delete [] buffer; }
void CUDTSocketSession::Process() { if(!IsValid()) return; UDTSTATUS Value = UDT::getsockstate(m_Client); if(Value == CONNECTING) return; else if(Value != CONNECTED) { m_LastActivity = 0; // timeout now return; } for(;;) // repeat untill all data is read { /*timeval tv; tv.tv_sec = 0; tv.tv_usec = 0; UDT::UDSET readfds; UD_ZERO(&readfds); UD_SET(m_Client, &readfds); int res = UDT::select(0, &readfds, NULL, NULL, &tv); // this is soooo slow if (!((res != UDT::ERROR) && (UD_ISSET(m_Client, &readfds)))) break;*/ const uint64 Size = KB2B(16); char Buffer[Size]; int Recived = UDT::recv(m_Client, (char*)Buffer, Size, 0); if (UDT::ERROR == Recived) { LogLine(LOG_ERROR, L"recv: %S", UDT::getlasterror().getErrorMessage()); break; } else if(Recived == 0) break; // hothing (more) to be read StreamIn((byte*)Buffer, Recived); m_LastActivity = GetCurTick(); } CSocketSession::Process(); for(;m_Sending.GetSize() > 0;) // repeat untill all data is sent { /*timeval tv; tv.tv_sec = 0; tv.tv_usec = 0; UDT::UDSET writefds; UD_ZERO(&writefds); UD_SET(m_Client, &writefds); int res = UDT::select(0, NULL, &writefds, NULL, &tv); if (!((res != UDT::ERROR) && (UD_ISSET(m_Client, &writefds)))) break;*/ /*uint32_t InBuffer = 0; int InSize = sizeof(InBuffer); UDT::getsockopt(m_Client, 0, UDT_SNDDATA, &InBuffer, &InSize); if(InBuffer > 0) break;*/ int ToGo = m_Sending.GetSize(); /*if(ToGo > KB2B(10)) ToGo = KB2B(10);*/ int Sent = UDT::send(m_Client, (char*)m_Sending.GetBuffer(), ToGo, 0); if (UDT::ERROR == Sent) { LogLine(LOG_ERROR, L"recv: %S", UDT::getlasterror().getErrorMessage()); break; } m_Sending.ShiftData(Sent); m_LastActivity = GetCurTick(); if(Sent < ToGo) break; } }
void CUTPSocketSession::PushData(const byte* Buffer, size_t Recived) { StreamIn((byte*)Buffer, Recived); m_LastActivity = GetCurTick(); }
void CStatusCtrl::ShowStatus(CString status, int nType) { USES_CONVERSION; CString rtfstr = m_RTFHeader; status.Replace(_T("\\"), _T("\\\\")); status.Replace(_T("{"), _T("\\{")); status.Replace(_T("}"), _T("\\}")); status.Replace(_T("\r"), _T("")); status.Replace(_T("\n"), _T("\\status")); CString str; switch (nType) { case FZ_LOG_STATUS: //str.LoadString(IDS_STATUSMSG_PREFIX); str += "\\cf2"; break; case FZ_LOG_ERROR: //str.LoadString(IDS_ERRORMSG_PREFIX); str="\\cf5"; break; case FZ_LOG_COMMAND: //str.LoadString(IDS_COMMANDMSG_PREFIX); str="\\cf3"; break; case FZ_LOG_REPLY: //str.LoadString(IDS_RESPONSEMSG_PREFIX); str="\\cf4"; break; case FZ_LOG_LIST: //str.LoadString(IDS_TRACEMSG_TRACE); str="\\cf11"; break; case FZ_LOG_APIERROR: case FZ_LOG_WARNING: case FZ_LOG_INFO: case FZ_LOG_DEBUG: //str.LoadString(IDS_TRACEMSG_TRACE); str="\\cf7"; break; } CString tmp; tmp += str; tmp += "\\tab "; tmp += status; status = tmp; if (!m_bEmpty){ rtfstr += "\\par "; rtfstr += status; }else { m_bEmpty = FALSE; rtfstr += status; } rtfstr += "} "; EDITSTREAM es; string s = Util::ws2s(wstring(rtfstr)); es.dwCookie = (DWORD)&s; // Pass a pointer to the string to the callback function es.pfnCallback = RichEditStreamInCallback; // Specify the pointer to the callback function. CWnd *pFocusWnd = GetFocus(); if (pFocusWnd && pFocusWnd == this) AfxGetMainWnd()->SetFocus(); long nStart, nEnd; GetSel(nStart, nEnd); BOOL nScrollToEnd = FALSE; int num = 0; //this is the number of visible lines CRect rect; GetRect(rect); int height = rect.Height(); for (int i = GetFirstVisibleLine(); i < GetLineCount() && GetCharPos(LineIndex(i)).y < height; i++) num++; if (GetFirstVisibleLine() + num+m_nMoveToBottom >= GetLineCount()) nScrollToEnd = TRUE; HideSelection(TRUE, FALSE); SetSel(-1, -1); StreamIn(SF_RTF | SFF_SELECTION, es); // Perform the streaming if (GetLineCount() > 1000) { nStart -= LineLength(0) + 2; nEnd -= LineLength(0) + 2; if (nStart < 0) nEnd = 0; if (nEnd < 0) nEnd = 0; SetSel(0, LineLength(0) + 2); ReplaceSel(_T("")); } SetSel(nStart, nEnd); if (pFocusWnd && pFocusWnd == this) SetFocus(); HideSelection(FALSE, FALSE); if (nScrollToEnd) { if (nStart != nEnd && (LineFromChar(nStart) >= GetFirstVisibleLine() && LineFromChar(nStart) <= GetFirstVisibleLine() + num || LineFromChar(nEnd) >= GetFirstVisibleLine() && LineFromChar(nEnd) <= GetFirstVisibleLine() + num)) LineScroll(1); else { m_nMoveToBottom++; if (!m_nTimerID) m_nTimerID = SetTimer(654, 25, NULL); } } }