BOOL CFreeCoolDlg::PreTranslateMessage(MSG* pMsg)
{
	
	if(pMsg->message == WM_KEYDOWN  )
	{		
		if(pMsg->wParam == VK_RETURN )
		{
			CButton * pbutton = (CButton *)GetDlgItem(IDCANCEL);
			pbutton->SetFocus();

			return TRUE;
		}

	}
	return CDialog::PreTranslateMessage(pMsg);
}
示例#2
0
LRESULT EmoticonsDlg::onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	ShowWindow(SW_HIDE);
	WNDPROC temp = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(EmoticonsDlg::m_hWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(NewWndProc)));
	if (!g_MFCWndProc)
		g_MFCWndProc = temp;
	g_pDialog = this;
	::EnableWindow(WinUtil::g_mainWnd, true);
	
	bool bUseAnimation = BOOLSETTING(SMILE_SELECT_WND_ANIM_SMILES);
	
	if (CAGEmotionSetup::g_pEmotionsSetup)
	{
		const CAGEmotion::Array& Emoticons = CAGEmotionSetup::g_pEmotionsSetup->getEmoticonsArray();
		unsigned int pocet = 0;
		int l_count_emotion = 0;
		string lastEmotionPath, lastAnimEmotionPath;
		for (auto pEmotion = Emoticons.cbegin();
		        pEmotion != Emoticons.cend() && l_count_emotion < CAGEmotionSetup::g_pEmotionsSetup->m_CountSelEmotions;
		        ++pEmotion, ++l_count_emotion)
		{
			if (bUseAnimation)
			{
				if ((*pEmotion)->getEmotionBmpPath() != lastEmotionPath || (*pEmotion)->getEmotionGifPath() != lastAnimEmotionPath)
					pocet++;
					
				lastEmotionPath = (*pEmotion)->getEmotionBmpPath();
				lastAnimEmotionPath = (*pEmotion)->getEmotionGifPath();
			}
			else
			{
				if ((*pEmotion)->getEmotionBmpPath() != lastEmotionPath)
					pocet++;
				lastEmotionPath = (*pEmotion)->getEmotionBmpPath();
			}
		}
		
		// x, y jen pro for cyklus
		const unsigned int l_Emoticons_size = CAGEmotionSetup::g_pEmotionsSetup->m_CountSelEmotions;
		unsigned int i = (unsigned int)sqrt(double(l_Emoticons_size));
		unsigned int nXfor = i;
		unsigned int nYfor = i;
		
		if ((i * i) != l_Emoticons_size) //[+]PPA
		{
			nXfor = i + 1;
			if ((i * nXfor) < l_Emoticons_size) nYfor = i + 1;
			else nYfor = i;
		}
		// x, y pro korektni vkladani ikonek za sebou
		i = (unsigned int)sqrt((double)pocet);
		unsigned int nX = i;
		unsigned int nY = i;
		if ((i * i) != pocet) //[+]PPA
		{
			nX = i + 1;
			if ((i * nX) < pocet) nY = i + 1;
			else nY = i;
		}
		if (Emoticons.empty() || !*Emoticons.begin()) //[+]PPA
			return 0;
			
		// [~] brain-ripper
		// If first icon failed to load, h_bm will be zero, and all icons will be drawn extremely small.
		// So cycle through Emoticons and find first loaded icon.
		//HBITMAP h_bm = (*Emoticons.begin())->getEmotionBmp(GetSysColor(COLOR_BTNFACE));
		
		DWORD iSW = 0, iSH = 0, dwCount = 0;
		l_count_emotion = 0;
		for (auto i = Emoticons.cbegin(); i != Emoticons.cend() && l_count_emotion < CAGEmotionSetup::g_pEmotionsSetup->m_CountSelEmotions; ++i, ++l_count_emotion)
		{
			int w = 0, h = 0;
			CGDIImage *pImage = nullptr;
			
			if (bUseAnimation)
				pImage = (*i)->getAnimatedImage(MainFrame::getMainFrame()->m_hWnd, WM_ANIM_CHANGE_FRAME);
				
			if (pImage)
			{
				w = pImage->GetWidth();
				h = pImage->GetHeight();
				dwCount++;
			}
			else
			{
				if ((*i)->getDimensions(&w, &h))
				{
					if (bUseAnimation)
						dwCount++;
					else
					{
						iSW = w;
						iSH = h;
						break;
					}
				}
			}
			
			iSW += w * w;
			iSH += h * h;
		}
		
		if (bUseAnimation && dwCount)
		{
			// Get mean square of all icon dimensions
			iSW = DWORD(sqrt(float(iSW / dwCount)));
			iSH = DWORD(sqrt(float(iSH / dwCount)));
		}
		
		pos.bottom = pos.top - 3;
		pos.left = pos.right - nX * (iSW + EMOTICONS_ICONMARGIN) - 2;
		pos.top = pos.bottom - nY * (iSH + EMOTICONS_ICONMARGIN) - 2;
		
		// [+] brain-ripper
		// Fit window in screen's work area
		RECT rcWorkArea;
		SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0);
		if (pos.right > rcWorkArea.right)
		{
			pos.left -= pos.right - rcWorkArea.right;
			pos.right = rcWorkArea.right;
		}
		if (pos.bottom > rcWorkArea.bottom)
		{
			pos.top -= pos.bottom - rcWorkArea.bottom;
			pos.bottom = rcWorkArea.bottom;
		}
		if (pos.left < rcWorkArea.left)
		{
			pos.right += rcWorkArea.left - pos.left;
			pos.left = rcWorkArea.left;
		}
		if (pos.top < rcWorkArea.top)
		{
			pos.bottom += rcWorkArea.top - pos.top;
			pos.top = rcWorkArea.top;
		}
		
		MoveWindow(pos);
		
		lastEmotionPath.clear();
		lastAnimEmotionPath.clear();
		
		m_ctrlToolTip.Create(EmoticonsDlg::m_hWnd, rcDefault, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON, WS_EX_TOPMOST);
		m_ctrlToolTip.SetDelayTime(TTDT_AUTOMATIC, 1000);
		
		pos.left = 0;
		pos.right = iSW + EMOTICONS_ICONMARGIN;
		pos.top = 0;
		pos.bottom = iSH + EMOTICONS_ICONMARGIN;
		
		cleanHandleList();
		auto l_Emotion = Emoticons.begin();
		for (unsigned int iY = 0; iY < nYfor; iY++)
			for (unsigned int iX = 0; iX < nXfor; iX++)
			{
				if (l_Emotion != Emoticons.end()) // TODO - merge
				{
				
					const auto i = *l_Emotion;
					if ((iY * nXfor) + iX + 1 > l_Emoticons_size) break;
					
					bool bNotDuplicated = (bUseAnimation ?
					                       (i->getEmotionBmpPath() != lastEmotionPath ||
					                        i->getEmotionGifPath() != lastAnimEmotionPath) :
					                       i->getEmotionBmpPath() != lastEmotionPath);
					                       
					                       
					// dve stejne emotikony za sebou nechceme
					if (bNotDuplicated)
					{
						bool bCreated = false;
						CGDIImage *pImage = nullptr;
						
						if (bUseAnimation)
							pImage = i->getAnimatedImage(MainFrame::getMainFrame()->m_hWnd, WM_ANIM_CHANGE_FRAME);
							
						if (pImage)
						{
							const tstring smajl = i->getEmotionText();
							CAnimatedButton *pemoButton = new CAnimatedButton(pImage);
							m_BtnList.push_back(pemoButton);
							pemoButton->Create(EmoticonsDlg::m_hWnd, pos, smajl.c_str(), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | BS_FLAT | BS_BITMAP, WS_EX_TRANSPARENT);
							m_ctrlToolTip.AddTool(*pemoButton, smajl.c_str());
							bCreated = true;
						}
						else
						{
							if (const HBITMAP l_h_bm = i->getEmotionBmp(GetSysColor(COLOR_BTNFACE)))
							{
								CButton emoButton;
								const tstring smajl = i->getEmotionText();
								emoButton.Create(EmoticonsDlg::m_hWnd, pos, smajl.c_str(), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | BS_FLAT | BS_BITMAP | BS_CENTER);
								m_HandleList.push_back(l_h_bm);
								emoButton.SetBitmap(l_h_bm);
								m_ctrlToolTip.AddTool(emoButton, smajl.c_str());
								DeleteObject((HGDIOBJ)emoButton);
								bCreated = true;
							}
						}
						
						if (bCreated)
						{
							// Calculate position of next button
							pos.left = pos.left + iSW + EMOTICONS_ICONMARGIN;
							pos.right = pos.left + iSW + EMOTICONS_ICONMARGIN;
							if (pos.left >= (LONG)(nX * (iSW + EMOTICONS_ICONMARGIN)))
							{
								pos.left = 0;
								pos.right = iSW + EMOTICONS_ICONMARGIN;
								pos.top = pos.top + iSH + EMOTICONS_ICONMARGIN;
								pos.bottom = pos.top + iSH + EMOTICONS_ICONMARGIN;
							}
						}
					}
					
					lastEmotionPath = i->getEmotionBmpPath();
					
					if (bUseAnimation)
						lastAnimEmotionPath = i->getEmotionGifPath();
					++l_Emotion;
				}
			}
			
		pos.left = -128;
		pos.right = pos.left;
		pos.top = -128;
		pos.bottom = pos.top;
		CButton emoButton;
		emoButton.Create(EmoticonsDlg::m_hWnd, pos, _T(""), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | BS_FLAT);
		emoButton.SetFocus();
		DeleteObject((HGDIOBJ)emoButton);
		ShowWindow(SW_SHOW);
		
		for (auto i = m_BtnList.cbegin(); i != m_BtnList.cend(); ++i)
		{
			(*i)->Update();
		}
	}
	else PostMessage(WM_CLOSE);
	
	return 0;
}