std::string XLibWrapper::getWindowName( Window window ) { char* buffer; if( !XFetchName(_display,window,&buffer) ) return std::string().c_str(); std::string windowName(buffer); XFree( buffer ); return windowName; }
void KviQueryWindow::fillCaptionBuffers() { if(!connection()) { QString szDead = __tr2qs("[Dead query]"); m_szPlainTextCaption = windowName(); m_szPlainTextCaption += " : "; m_szPlainTextCaption += szDead; return; } QString szNickOnServer = QChar('['); szNickOnServer += connection()->currentNickName(); szNickOnServer += __tr2qs(" on "); szNickOnServer += connection()->currentServerName(); szNickOnServer += QChar(']'); m_szPlainTextCaption = windowName(); m_szPlainTextCaption += QChar(' '); m_szPlainTextCaption += szNickOnServer; }
bool MainContext::CheckWindow(HWND hWnd) { std::unique_ptr<wchar_t[]> className(new wchar_t[MAX_PATH]); std::unique_ptr<wchar_t[]> windowName(new wchar_t[MAX_PATH]); GetClassNameW(hWnd, className.get(), MAX_PATH); GetWindowTextW(hWnd, windowName.get(), MAX_PATH); PrintLog("HWND 0x%p: ClassName \"%ls\", WindowName: \"%ls\"", hWnd, className.get(), windowName.get()); bool class_found = config.GetWindowClass().compare(className.get()) == 0; bool window_found = config.GetWindowName().compare(windowName.get()) == 0; bool force = config.GetAllWindows(); return class_found || window_found || force; }
void skizImage::TestImage() { skizImage image; string fileName("/home/xuweirong/image/[天使动漫]中二病也要谈恋爱壁纸6.jpg"); string windowName("TestImage"); image.ReadImage(fileName); if(image.IsOk()) { printf("image is ok\n" ) ; /* namedWindow("TrackbarWindow") ; createTrackbar("TrackbarName","TrackbarWindow",&slider,slider_max,on_trackbar) ; namedWindow("Source"); image.ShowImage("Source"); waitKey(0); */ image.NamedWindow("TrackbarWindow"); int slider= 0; int slider_max=100; image.CreateTrackbar("TrackbarName","TrackbarWindow",&slider,slider_max); } }
/* ** Window procedure for the reciever window. ** */ LRESULT CALLBACK PlayerCAD::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static PlayerCAD* player; switch (msg) { case WM_CREATE: { // Get pointer to the PlayerCAD class from the CreateWindow call player = (PlayerCAD*)((CREATESTRUCT*)lParam)->lpCreateParams; return 0; } case WM_DESTROY: { SendMessage(player->m_PlayerWindow, WM_USER, 0, IPC_SHUTDOWN_NOTIFICATION); return 0; } case WM_USER: switch (lParam) { case IPC_TRACK_CHANGED_NOTIFICATION: { PostMessage(player->m_PlayerWindow, WM_USER, 0, IPC_GET_CURRENT_TRACK); break; } case IPC_STATE_CHANGED_NOTIFICATION: { player->m_State = (StateType)wParam; if (player->m_State == STATE_STOPPED) { player->ClearData(false); } break; } case IPC_VOLUME_CHANGED_NOTIFICATION: { player->m_Volume = (UINT)wParam; break; } case IPC_REPEAT_CHANGED_NOTIFICATION: { player->m_Repeat = wParam != 0; break; } case IPC_SHUFFLE_CHANGED_NOTIFICATION: { player->m_Shuffle = wParam != 0; break; } case IPC_RATING_CHANGED_NOTIFICATION: { player->m_Rating = ((UINT)wParam + 1) / 2; // From 0 - 10 to 0 - 5 break; } case IPC_SHUTDOWN_NOTIFICATION: { player->m_Initialized = false; player->ClearData(); break; } } return 0; case WM_COPYDATA: { PCOPYDATASTRUCT cds = (PCOPYDATASTRUCT)lParam; if (cds->dwData == IPC_CURRENT_TRACK_NOTIFICATION) { player->m_Shuffle = SendMessage(player->m_PlayerWindow, WM_USER, 0, IPC_GET_SHUFFLE) != 0; player->m_Repeat = SendMessage(player->m_PlayerWindow, WM_USER, 0, IPC_GET_REPEAT) != 0; // TODO: Sent on track update? ++player->m_TrackCount; WCHAR* data = (WCHAR*)cds->lpData; WCHAR* pos; UINT index = 1; while ((pos = wcschr(data, '\t')) != nullptr) { switch (index) { case 1: player->m_Title.assign(data, pos - data); break; case 2: player->m_Artist.assign(data, pos - data); break; case 3: player->m_Album.assign(data, pos - data); break; case 4: player->m_Genre.assign(data, pos - data); break; case 5: player->m_Year = (UINT)_wtoi(data); break; case 7: player->m_Number = (UINT)_wtoi(data); break; case 8: player->m_Duration = (UINT)_wtoi(data); break; case 9: player->m_FilePath.assign(data, pos - data); break; case 10: player->m_Rating = ((UINT)_wtoi(data) + 1) / 2; // 0 - 10 -> 0 - 5 break; case 11: if (*data == L' ') { player->FindCover(); } else { player->m_CoverPath.assign(data, pos - data); } break; } data = pos + 1; ++index; if (index == 12) { break; } } if (player->m_Measures & MEASURE_LYRICS) { player->FindLyrics(); } } else if (cds->dwData == IPC_NEW_COVER_NOTIFICATION) { WCHAR* data = (WCHAR*)cds->lpData; if (data) { player->m_CoverPath.assign(data); } } else if (cds->dwData == IPC_REGISTER_NOTIFICATION && !player->m_Initialized) { std::wstring data = (WCHAR*)cds->lpData; if (data[0] == L'1') { data.erase(0, 2); // Get rid of the 1\t at the beginning std::wstring::size_type len = data.find_first_of(L'\t'); std::wstring className(data, 0, len); data.erase(0, ++len); len = data.find_first_of(L'\t'); std::wstring windowName(data, 0, len); data.erase(0, ++len); len = data.find_first_of(L'\t'); player->m_PlayerPath.assign(data, 0, len); data.erase(0, ++len); LPCTSTR classSz = className.empty() ? nullptr : className.c_str(); LPCTSTR windowSz = windowName.empty() ? nullptr : windowName.c_str(); LPCTSTR file = RmGetSettingsFile(); WritePrivateProfileString(L"NowPlaying.dll", L"ClassName", classSz, file); WritePrivateProfileString(L"NowPlaying.dll", L"WindowName", windowSz, file); WritePrivateProfileString(L"NowPlaying.dll", L"PlayerPath", player->m_PlayerPath.c_str(), file); player->m_PlayerWindow = FindWindow(classSz, windowSz); if (player->m_PlayerWindow) { player->m_Initialized = true; player->m_ExtendedAPI = (classSz && wcscmp(classSz, L"CD Art Display IPC Class") == 0); player->m_State = (StateType)SendMessage(player->m_PlayerWindow, WM_USER, 0, IPC_GET_STATE); if (player->m_State != STATE_STOPPED) { PostMessage(player->m_PlayerWindow, WM_USER, 0, IPC_GET_CURRENT_TRACK); } if (player->m_Open) { if (windowSz && wcscmp(windowSz, L"foobar2000") == 0) { // Activate foobar2000 in case it starts minimized SendMessage(player->m_PlayerWindow, WM_USER, 0, IPC_SHOW_WINDOW); } player->m_Open = false; } } } } } return 0; default: return DefWindowProc(hwnd, msg, wParam, lParam); } }
bool CSMNativeWindow::init(void) { osx_AllowForeground(); CSMDrawer *pDrawer = this->getParent(); CarbonWindowUnrecPtr pCarbonWindow = OSG::CarbonWindow::create(); AGLPixelFormat pixelFormat = NULL; std::vector<int> pfForm; pfForm.push_back(AGL_RGBA); pfForm.push_back(AGL_DEPTH_SIZE); pfForm.push_back(16); pfForm.push_back(AGL_DOUBLEBUFFER); if(_sfRequestSamples.getValue() > 0) { pfForm.push_back(AGL_SAMPLE_BUFFERS_ARB); pfForm.push_back(1); pfForm.push_back(AGL_SAMPLES_ARB); pfForm.push_back(_sfRequestSamples.getValue()); } if(this->requestStereoVisual() == true) { fprintf(stderr, "Choose stereo format\n"); pfForm.push_back(AGL_STEREO); } pfForm.push_back(AGL_NONE); pixelFormat = aglChoosePixelFormat(NULL, 0, &(pfForm.front())); fprintf(stderr, "Got pf : %p\n", pixelFormat); if(pixelFormat == NULL) { fprintf(stderr, "no RGB visual with depth buffer : :0.0"); exit(0); } _pContext = aglCreateContext(pixelFormat, 0); aglDestroyPixelFormat(pixelFormat); UInt32 uiWidth; UInt32 uiHeight; Int32 iXPos = 0; Int32 iYPos = 0; if(this->getXPos() > 0.f && this->getYPos() > 0.f) { iXPos = Int32(this->getXPos()); iYPos = Int32(this->getYPos()); } if(this->getXSize() >= 1.f) { uiWidth = UInt32(this->getXSize()); } else if(this->getXSize() <= 0.f) { uiWidth = 300; //DisplayWidth(_pDisplay, vi->screen); } else { uiWidth = 300; //UInt32(Real32(DisplayWidth(_pDisplay, vi->screen)) * // this->getXSize()); } if(this->getYSize() >= 1.f) { uiHeight = UInt32(this->getYSize()); } else if(this->getYSize() <= 0.f) { uiHeight = 300; //DisplayHeight(_pDisplay, vi->screen); } else { uiHeight = 300; //UInt32(Real32(DisplayHeight(_pDisplay, vi->screen)) * // this->getYSize()); } WindowAttributes windowAttrs = (kWindowStandardDocumentAttributes | kWindowLiveResizeAttribute | kWindowStandardHandlerAttribute ); Rect contentRect; SetRect(&contentRect, iXPos, iYPos, iXPos + uiWidth, iYPos + uiHeight); CreateNewWindow(kDocumentWindowClass, windowAttrs, &contentRect, &_pLocalWindow); SetWindowTitleWithCFString(_pLocalWindow, CFSTR("OpenSG - CSM")); // Install event handler _pEventHandler = NewEventHandlerUPP(eventHandler); EventTypeSpec eventList[] = { { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseDragged }, { kEventClassWindow, kEventWindowClose }, { kEventClassWindow, kEventWindowDrawContent }, { kEventClassWindow, kEventWindowBoundsChanged } }; InstallWindowEventHandler(_pLocalWindow, _pEventHandler, GetEventTypeCount(eventList), eventList, this, 0); aglSetWindowRef(_pContext, _pLocalWindow); _pCarbWindow = pCarbonWindow; _pCarbWindow->setContext(_pContext); _pCarbWindow->init ( ); _pCarbWindow->resize ( uiWidth, uiHeight); std::string windowName(" OpenSG - CSM - "); _pCarbWindow->activate(); windowName += reinterpret_cast<const char *>(glGetString(GL_VERSION)); windowName += " - "; windowName += reinterpret_cast<const char *>(glGetString(GL_RENDERER)); _pCarbWindow->deactivate(); SetWTitle(_pLocalWindow, reinterpret_cast<const unsigned char *>(windowName.c_str())); // Show window RepositionWindow(_pLocalWindow, 0, kWindowCascadeOnMainScreen); ShowWindow (_pLocalWindow ); if(ComplexSceneManager::the() != NULL) ComplexSceneManager::the()->setMainloop( &CSMNativeWindow::carbonMainLoop); _pWindow = _pCarbWindow; _bRun = true; Inherited::init(); return true; }
bool CSMNativeWindow::init(void) { CSMDrawer *pDrawer = this->getParent(); std::string szDisplayName = ":0.0"; if(pDrawer != NULL) { szDisplayName = pDrawer->getDisplayString(); } _pDisplay = XOpenDisplay(szDisplayName.c_str()); //fprintf(stderr, "Opened Display %p\n", _pDisplay); if(_pDisplay == NULL) { fprintf(stderr, "Error: Could not open display: %s\n", szDisplayName.c_str()); exit(0); } int iDummy; if(!glXQueryExtension(_pDisplay, &iDummy, &iDummy)) { fprintf(stderr, "Error: X server has no OpenGL GLX extension: :0.0\n"); exit(0); } XWindowUnrecPtr pXWindow = OSG::XWindow::create(); XVisualInfo *vi = NULL; pXWindow->setRequestMajor (this->getRequestMajor ()); pXWindow->setRequestMinor (this->getRequestMinor ()); UInt32 uiDrawMode = this->getPartitionDrawMode(); if(ComplexSceneManager::the()->getDrawManager()->getParallel() == true) { uiDrawMode |= Window::ParallelDrawer; } else { uiDrawMode |= Window::StdDrawer; } pXWindow->setPartitionDrawMode(uiDrawMode); pXWindow->setDrawerType (uiDrawMode); Int32 iFlags = 0; if(this->getEnableForwardCompatContext() == true) { if(this->getRequestMajor() >= 3) { iFlags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; } else { FWARNING(("forward compat contexts require OpenGL major " "> 3.0, requested %d\n", this->getRequestMajor())); } } if(this->getEnableDebugContext() == true) { iFlags |= GLX_CONTEXT_DEBUG_BIT_ARB; } if(iFlags != 0) pXWindow->setContextFlags(iFlags); OSGGETGLFUNCBYNAME_EXT(glxChooseFBConfig, osgGlxChooseFBConfig, "glXChooseFBConfig", pXWindow.get()); if(osgGlxChooseFBConfig == NULL) { std::vector<int> viForm; viForm.push_back(GLX_RGBA); viForm.push_back(GLX_DEPTH_SIZE); viForm.push_back(1); viForm.push_back(GLX_DOUBLEBUFFER); if(_sfRequestSamples.getValue() > 0) { viForm.push_back(GLX_SAMPLE_BUFFERS_ARB); viForm.push_back(True); viForm.push_back(GLX_SAMPLES_ARB); viForm.push_back(_sfRequestSamples.getValue()); } if(this->requestStereoVisual() == true) { fprintf(stderr, "Choose stereo visual\n"); viForm.push_back(GLX_DOUBLEBUFFER); viForm.push_back(True); } viForm.push_back(None); #if 0 int dblBuf[] = {GLX_RGBA, GLX_DEPTH_SIZE, 1, GLX_DOUBLEBUFFER, // (_pVSCWindow->stereo() == true) ? GLX_STEREO : None, None}; #endif vi = glXChooseVisual(_pDisplay, DefaultScreen(_pDisplay), &(viForm.front())); } else { int iMatching; #if 0 int fbAttr[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_ALPHA_SIZE, 8, GLX_DEPTH_SIZE, 8, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_DOUBLEBUFFER, True, GLX_X_RENDERABLE, True, None }; #endif std::vector<int> fbAttr; fbAttr.push_back(GLX_RENDER_TYPE); fbAttr.push_back(GLX_RGBA_BIT); fbAttr.push_back(GLX_RED_SIZE); fbAttr.push_back(8); fbAttr.push_back(GLX_GREEN_SIZE); fbAttr.push_back(8); fbAttr.push_back(GLX_BLUE_SIZE); fbAttr.push_back(8); fbAttr.push_back(GLX_ALPHA_SIZE); fbAttr.push_back(8); fbAttr.push_back(GLX_DEPTH_SIZE); fbAttr.push_back(8); fbAttr.push_back(GLX_DRAWABLE_TYPE); fbAttr.push_back(GLX_WINDOW_BIT); fbAttr.push_back(GLX_DOUBLEBUFFER); fbAttr.push_back(True); fbAttr.push_back(GLX_X_RENDERABLE); fbAttr.push_back(True); if(_sfRequestSamples.getValue() > 0) { fbAttr.push_back(GLX_SAMPLE_BUFFERS_ARB); fbAttr.push_back(True); fbAttr.push_back(GLX_SAMPLES_ARB); fbAttr.push_back(_sfRequestSamples.getValue()); } if(this->requestStereoVisual() == true) { fprintf(stderr, "FBConfig stereo\n"); fbAttr.push_back(GLX_STEREO); fbAttr.push_back(True); } fbAttr.push_back(None); GLXFBConfig *fbConfigs = osgGlxChooseFBConfig( _pDisplay, DefaultScreen(_pDisplay), &(fbAttr.front()), & iMatching); if(iMatching > 0) { vi = glXGetVisualFromFBConfig(_pDisplay, fbConfigs[0]); int iId; glXGetFBConfigAttrib( _pDisplay, fbConfigs[0], GLX_FBCONFIG_ID, & iId); pXWindow->setFbConfigId(iId); XFree(fbConfigs); } } if(vi == NULL) { fprintf(stderr, "no RGB visual with depth buffer : :0.0"); exit(0); } Colormap cmap = XCreateColormap(_pDisplay, RootWindow(_pDisplay, vi->screen), vi->visual, AllocNone); XSetWindowAttributes swa; swa.colormap = cmap; swa.border_pixel = 0; swa.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask | StructureNotifyMask; swa.override_redirect = 0; UInt32 uiWidth; UInt32 uiHeight; Int32 iXPos = 0; Int32 iYPos = 0; if(this->getXPos() > 0.f && this->getYPos() > 0.f) { iXPos = Int32(this->getXPos()); iYPos = Int32(this->getYPos()); } if(this->getXSize() >= 1.f) { uiWidth = UInt32(this->getXSize()); } else if(this->getXSize() <= 0.f) { uiWidth = DisplayWidth(_pDisplay, vi->screen); } else { uiWidth = UInt32(Real32(DisplayWidth(_pDisplay, vi->screen)) * this->getXSize()); } if(this->getYSize() >= 1.f) { uiHeight = UInt32(this->getYSize()); } else if(this->getYSize() <= 0.f) { uiHeight = DisplayHeight(_pDisplay, vi->screen); } else { uiHeight = UInt32(Real32(DisplayHeight(_pDisplay, vi->screen)) * this->getYSize()); } // fprintf(stderr, "Win size %d %d at %d %d\n", // uiWidth, uiHeight, iXPos, iYPos); ::Window pHWin = XCreateWindow(_pDisplay, RootWindow(_pDisplay, vi->screen), 0, 0, uiWidth, uiHeight, 0, vi->depth, InputOutput, vi->visual, (CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect), &swa); XFree(vi); Int32 argc = 1; const Char8 *argv[] = { "testCSM" }; XSetStandardProperties(_pDisplay, pHWin, "OpenSG - CSM", None, None, const_cast<Char8 **>(argv), argc, NULL); XMapWindow(_pDisplay, pHWin); if(this->getDecorEnabled() == false) { Atom noDecorAtom = XInternAtom(_pDisplay, "_MOTIF_WM_HINTS", 0); if(noDecorAtom == None) { fprintf(stderr,"Could not intern X atom for _MOTIF_WM_HINTS.\n"); } struct NoDecorHints { long flags; long functions; long decorations; long input_mode; }; NoDecorHints oHints; oHints.flags = 2; oHints.decorations = 0; XChangeProperty(_pDisplay, pHWin, noDecorAtom, noDecorAtom, 32, PropModeReplace, reinterpret_cast<unsigned char *>(&oHints), 4); } XEvent event; XIfEvent (_pDisplay, &event, waitMapNotify, reinterpret_cast<char *>(pHWin)); XSetInputFocus(_pDisplay, pHWin, RevertToParent, CurrentTime); _pXWindow = pXWindow; _pXWindow->setDisplay(_pDisplay); _pXWindow->setWindow ( pHWin ); _pXWindow->init ( ); _pXWindow->resize ( uiWidth, uiHeight); std::string windowName("OpenSG - CSM - "); #if 0 _pXWindow->activate(); windowName += reinterpret_cast<const char *>(glGetString(GL_VERSION)); windowName += " - "; windowName += reinterpret_cast<const char *>(glGetString(GL_RENDERER)); _pXWindow->deactivate(); #endif windowName += _pXWindow->getRendererInfo(); XStoreName(_pDisplay, pHWin, windowName.c_str()); if(ComplexSceneManager::the() != NULL && this->getRegisterMainLoop() == true ) { ComplexSceneManager::the()->setMainloop(&CSMNativeWindow::xMainLoop); } _pWindow = _pXWindow; // _uiCreateNapTime = pNativeWindow->getSFCreateNapTime()->getValue(); _vWindowList.push_back(this); _bRun = true; XMoveResizeWindow(_pDisplay, pHWin, iXPos, iYPos, uiWidth, uiHeight); Inherited::init(); XWindowAttributes oWinAttr; XGetWindowAttributes( _pDisplay, pHWin, & oWinAttr); _pRootWindow = oWinAttr.root; return true; }
void KviQueryWindow::ownAction(const QString & szBuffer) { if(!connection()) return; QString szTmpBuffer; //see bug ticket #220 if(KVI_OPTION_BOOL(KviOption_boolStripMircColorsInUserMessages)) szTmpBuffer = KviControlCodes::stripControlBytes(szBuffer); else szTmpBuffer = szBuffer; //my full mask as seen by other users QString szMyName = connection()->userInfo()->nickName(); QString szMyFullMask = szMyName + "!" + connection()->userInfo()->userName() + "@" + connection()->userInfo()->hostName(); QByteArray myFullMask = connection()->encodeText(szMyFullMask); QByteArray name = connection()->encodeText(windowName()); QByteArray data = encodeText(szTmpBuffer); /* max length of a PRIVMSG text. Max buffer length for our send is 512 byte, but we have to * remember that the server will prepend to the message our full mask and truncate the resulting * at 512 bytes again.. * So we have: * :[email protected] PRIVMSG #channel :text of message(CrLf) * [email protected]#channeltext of message * 512(rfc) -2(CrLf) -2(:) -3(spaces) -7(PRIVMSG) -8(\x01ACTION\x01) = 490 * usable bytes, excluding our full mask and the target name. */ int iMaxMsgLen = 490 - name.length() - myFullMask.length(); if(KVS_TRIGGER_EVENT_2_HALTED(KviEvent_OnMeAction, this, szTmpBuffer, windowName())) return; #ifdef COMPILE_CRYPT_SUPPORT if(cryptSessionInfo() && cryptSessionInfo()->m_bDoEncrypt) { if(szTmpBuffer[0] != KviControlCodes::CryptEscape) { KviCString szEncrypted; cryptSessionInfo()->m_pEngine->setMaxEncryptLen(iMaxMsgLen); switch(cryptSessionInfo()->m_pEngine->encrypt(data.data(), szEncrypted)) { case KviCryptEngine::Encrypted: { if(!connection()->sendFmtData("PRIVMSG %s :%cACTION %s%c", name.data(), 0x01, szEncrypted.ptr(), 0x01)) return; output(KVI_OUT_OWNACTIONCRYPTED, "\r!nc\r%Q\r %Q", &szMyName, &szTmpBuffer); } break; case KviCryptEngine::Encoded: { if(!connection()->sendFmtData("PRIVMSG %s :%cACTION %s%c", name.data(), 0x01, szEncrypted.ptr(), 0x01)) return; // ugly, but we must redecode here QString szRedecoded = decodeText(szEncrypted.ptr()); output(KVI_OUT_OWNACTIONCRYPTED, "\r!nc\r%Q\r %Q", &szMyName, &szRedecoded); } break; default: // also case KviCryptEngine::EncryptError { QString szEngineError = cryptSessionInfo()->m_pEngine->lastError(); output(KVI_OUT_SYSTEMERROR, __tr2qs("The encryption engine was unable to encrypt the current message (%Q): %Q, no data sent to the server"), &szBuffer, &szEngineError); } } userAction(szMyName, KVI_USERACTION_ACTION); return; } else { //eat the escape code szTmpBuffer.remove(0, 1); data = encodeText(szTmpBuffer); } } #endif //COMPILE_CRYPT_SUPPORT if(!connection()->sendFmtData("PRIVMSG %s :%cACTION %s%c", name.data(), 0x01, data.data(), 0x01)) return; output(KVI_OUT_OWNACTION, "\r!nc\r%Q\r %Q", &szMyName, &szTmpBuffer); m_pUserListView->userAction(szMyName, KVI_USERACTION_ACTION); }
void KviQueryWindow::ownMessage(const QString & szBuffer, bool bUserFeedback) { if(!connection()) { outputNoFmt(KVI_OUT_SYSTEMWARNING, __tr2qs("This query has no active targets, no message sent")); return; } //my full mask as seen by other users QString szTmpMask = connection()->userInfo()->nickName() + "!" + connection()->userInfo()->userName() + "@" + connection()->userInfo()->hostName(); QByteArray szMyFullMask = connection()->encodeText(szTmpMask); //target name QByteArray szName = connection()->encodeText(windowName()); //message QByteArray szData = encodeText(szBuffer); const char * pcData = szData.data(); /* max length of a PRIVMSG text. Max buffer length for our sszEnd is 512 byte, but we have to * remember that the server will prepszEnd to the message our full mask and truncate the resulting * at 512 bytes again.. * So we have: * :[email protected] PRIVMSG #channel :text of message(CrLf) * [email protected]#channeltext of message * 512(rfc) -2(CrLf) -2(:) -3(spaces) -7(PRIVMSG) = 498 * usable bytes, excluding our full mask and the target name. */ int iMaxMsgLen = 498 - szName.length() - szMyFullMask.length(); // our copy of the message QString szTmpBuffer(szBuffer); if(!pcData) return; #ifdef COMPILE_CRYPT_SUPPORT if(cryptSessionInfo()) { if(cryptSessionInfo()->m_bDoEncrypt) { if(*pcData != KviControlCodes::CryptEscape) { KviCString szEncrypted; cryptSessionInfo()->m_pEngine->setMaxEncryptLen(500 - szName.length()); switch(cryptSessionInfo()->m_pEngine->encrypt(pcData, szEncrypted)) { case KviCryptEngine::Encrypted: if(!connection()->sendFmtData("PRIVMSG %s :%s", szName.data(), szEncrypted.ptr())) return; if(bUserFeedback) m_pConsole->outputPrivmsg(this, KVI_OUT_OWNPRIVMSGCRYPTED, QString(), QString(), QString(), szBuffer, KviConsoleWindow::NoNotifications); break; case KviCryptEngine::Encoded: { if(!connection()->sendFmtData("PRIVMSG %s :%s", szName.data(), szEncrypted.ptr())) return; if(bUserFeedback) { // ugly,but we must redecode here QString szRedecoded = decodeText(szEncrypted.ptr()); m_pConsole->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, QString(), QString(), QString(), szRedecoded, KviConsoleWindow::NoNotifications); } } break; default: // also case KviCryptEngine::EncryptError { QString szEngineError = cryptSessionInfo()->m_pEngine->lastError(); output(KVI_OUT_SYSTEMERROR, __tr2qs("The encryption engine was unable to encrypt the current message (%Q): %s, no data sent to the server"), &szBuffer, &szEngineError); } break; } userAction(connection()->currentNickName(), KVI_USERACTION_PRIVMSG); return; } else { //eat the escape code pcData++; szTmpBuffer.remove(0, 1); //let the normal function do it } } } #endif if(szData.length() > iMaxMsgLen) { /* Multi message; we want to split the message, preferably on a word boundary, * and sszEnd each message part as a different PRIVMSG * Due to encoding stuff, this is frikin'time eater */ QTextEncoder * pEncoder = makeEncoder(); // our temp encoder QByteArray szTmp; // used to calculate the length of an encoded message int iPos; // contains the index where to truncate szTmpBuffer int iC; // cycles counter (debugging/profiling purpose) float fPosDiff; // optimization internal; aggressivity factor QString szCurSubString; // truncated parts as reported to the user // run until we've something remaining in the message while(szTmpBuffer.length()) { // init counters iPos = szTmpBuffer.length(); iC = 0; // first part (optimization): quickly find an high index that is _surely_lesser_ // than the correct one while(1) { iC++; szTmp = pEncoder->fromUnicode(szTmpBuffer.left(iPos)); if(szTmp.length() <= iMaxMsgLen) break; //if szTmp.length() == 0 we already have break'ed out from here, // so we can safely use it as a divisor fPosDiff = (float)iMaxMsgLen / (float)szTmp.length(); iPos = (int)(iPos * fPosDiff); // cut the string at each cycle //printf("OPTIMIZATION: fPosDiff %f, iPos %d\n", fPosDiff, iPos); } //printf("Multi message: %d optimization cyles", iC); // now, do it the simple way: increment our index until we perfectly fit into the // available space while(1) { iC++; szTmp = pEncoder->fromUnicode(szTmpBuffer.left(iPos)); // perfect match if(iPos == szTmpBuffer.length()) break; if(szTmp.length() > iMaxMsgLen) { // overflowed.. last one was the good one iPos--; szTmp = pEncoder->fromUnicode(szTmpBuffer.left(iPos)); break; } else { //there's still free space.. add another char iPos++; } } //printf(", finished at %d cycles, truncated at pos %d\n", iC, iPos); //prepare the feedback string for the user szCurSubString = szTmpBuffer.left(iPos); //sszEnd the string to the server if(connection()->sendFmtData("PRIVMSG %s :%s", szName.data(), szTmp.data())) { //feeedback the user if(bUserFeedback) m_pConsole->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, QString(), QString(), QString(), szCurSubString, KviConsoleWindow::NoNotifications); userAction(connection()->currentNickName(), KVI_USERACTION_PRIVMSG); } else { // skipped a part in this multi message.. we don't want to continue return; } // remove the sent part of the string szTmpBuffer.remove(0, iPos); //printf("Sent %d chars, %d remaining in the Qstring\n",iPos, szTmpBuffer.length()); } } else { if(connection()->sendFmtData("PRIVMSG %s :%s", szName.data(), pcData)) { if(bUserFeedback) m_pConsole->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, QString(), QString(), QString(), szTmpBuffer, KviConsoleWindow::NoNotifications); userAction(connection()->currentNickName(), KVI_USERACTION_PRIVMSG); } } }
bool RenderWindow::create(const Application* application, const std::string& name, bool windowed, int width, int height) { Window::create (name, windowed, width, height); { _solidBrush = (HBRUSH)(CreateSolidBrush(RGB(0,0,0))); static const WCHAR* const windowClassStr = (L"IBLBaker Render Target Class"); WNDCLASSEX windowClass = { sizeof(WNDCLASSEX), CS_OWNDC, windowProc, 0, 0, application->instance(), 0, LoadCursor(0, IDC_ARROW), _solidBrush, 0, windowClassStr, 0 }; //set the icon instance for this application that we are creating for windowClass.hIcon = LoadIcon (application->instance(), MAKEINTRESOURCE(IDI_DEFAULT)); if (RegisterClassEx (&windowClass)) { // adjust the window size so that the client area matches the arguments RECT size = { 0, 0, Window::width(), Window::height()}; const std::string& windowNameStr = windowName(); std::wstring windowNameW (windowNameStr.begin(), windowNameStr.end()); HINSTANCE instance = application->instance(); AdjustWindowRect(&size, WS_OVERLAPPEDWINDOW, FALSE); DWORD fullWidth = (size.right - size.left); DWORD fullHeight = (size.bottom - size.top); //create window WindowHandle handle = CreateWindow ((WCHAR*)windowClassStr, (WCHAR*)windowNameW.c_str(), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, fullWidth, fullHeight, 0, 0, instance, this); if (handle) { setWindowHandle (handle); ShowWindow (windowHandle(), SW_SHOWNORMAL); updateBounds(); clientResize(handle, width, height); UpdateWindow (windowHandle()); return true; } else { THROW ("Failed to create window handle"); } } } return false; }