Пример #1
0
void CFindPanel::OnCreateFont()
{
	if (!mh_Edit)
		return;

	HFONT hOldFont = mh_Font;
	RECT rcEdit = {};
	GetClientRect(mh_Edit, &rcEdit);

	// CreateFont
	LOGFONT lf = {};
	lf.lfWeight = FW_DONTCARE;
	lf.lfCharSet = gpSet->nTabFontCharSet;
	lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
	wcscpy_c(lf.lfFaceName, gpSet->sTabFontFace);
	lf.lfHeight = -klMax(6,(int)(rcEdit.bottom - gpSetCls->EvalSize(3, esf_Vertical|esf_CanUseDpi)));
	mh_Font = CreateFontIndirect(&lf);

	SendMessage(mh_Edit, WM_SETFONT, (WPARAM)mh_Font, FALSE);

	SafeDeleteObject(hOldFont);
}
Пример #2
0
// Должна вернуть true, если данные изменились (то есть будет isForce при полной перерисовке)
bool CBackground::PrepareBackground(CVirtualConsole* pVCon, HDC&/*OUT*/ phBgDc, COORD&/*OUT*/ pbgBmpSize)
{
	if (!this)
	{
		_ASSERTE(this!=NULL);
		return false;
	}

	_ASSERTE(isMainThread() && "Must be executed in main thread");

	bool bSucceeded = true;
	bool lbForceUpdate = false;
	LONG lBgWidth = 0, lBgHeight = 0;
	BOOL lbVConImage = FALSE;

	if (gpSet->isBgPluginAllowed)
	{
		if (HasPluginBackgroundImage(&lBgWidth, &lBgHeight)
			&& lBgWidth && lBgHeight)
		{
			lbVConImage = TRUE;
		}
	}

	LONG lMaxBgWidth = 0, lMaxBgHeight = 0;
	bool bIsForeground = gpConEmu->isMeForeground(true);


	// Если плагин свой фон не подсунул
	if (!lbVConImage)
	{
		//if (mp_PluginBg)
		//{
		//	delete mp_PluginBg;
		//	mp_PluginBg = NULL;
		//}

		#ifndef APPDISTINCTBACKGROUND
		// То работаем на общих основаниях, через настройки (или AppDistinct)
		return gpSetCls->PrepareBackground(pVCon, &phBgDc, &pbgBmpSize);
		#else

		CBackgroundInfo* pBgFile = pVCon->GetBackgroundObject();
		if (!pBgFile)
		{
			_ASSERTE(FALSE && "Background object must be created in VCon");
			return false;
		}

		if (!mb_NeedBgUpdate)
		{
			if ((hBgDc == NULL)
				|| (mb_BgLastFade == bIsForeground && gpSet->isFadeInactive)
				|| (!gpSet->isFadeInactive && mb_BgLastFade))
			{
				NeedBackgroundUpdate();
			}
		}

		pBgFile->PollBackgroundFile();

		RECT rcWork = {0, 0, pVCon->GetVConWidth(), pVCon->GetVConHeight()};

		// необходимо проверить размер требуемой картинки
		// -- здесь - всегда только файловая подложка
		if ((gpSet->bgOperation == eUpLeft) || (gpSet->bgOperation == eUpRight)
			|| (gpSet->bgOperation == eDownLeft) || (gpSet->bgOperation == eDownRight)
			|| (gpSet->bgOperation == eCenter))
		{
			// MemoryDC создается всегда по размеру картинки, т.е. изменение размера окна - игнорируется
		}
		else
		{
			// Смотрим дальше
			if (gpSet->bgOperation == eStretch)
			{
				// Строго по размеру клиентской (точнее Workspace) области окна
				lMaxBgWidth = rcWork.right - rcWork.left;
				lMaxBgHeight = rcWork.bottom - rcWork.top;
			}
			else if (gpSet->bgOperation == eFit || gpSet->bgOperation == eFill)
			{
				lMaxBgWidth = rcWork.right - rcWork.left;
				lMaxBgHeight = rcWork.bottom - rcWork.top;
				// Correct aspect ratio
				const BITMAPFILEHEADER* pBgImgData = pBgFile->GetBgImgData();
				const BITMAPINFOHEADER* pBmp = pBgImgData ? (const BITMAPINFOHEADER*)(pBgImgData+1) : NULL;
				if (pBmp
					&& (rcWork.bottom - rcWork.top) > 0 && (rcWork.right - rcWork.left) > 0)
				{
					double ldVCon = (rcWork.right - rcWork.left) / (double)(rcWork.bottom - rcWork.top);
					double ldImg = pBmp->biWidth / (double)pBmp->biHeight;
					if (ldVCon > ldImg)
					{
						if (gpSet->bgOperation == eFit)
							lMaxBgWidth = (LONG)(lMaxBgHeight * ldImg);
						else
							lMaxBgHeight = (LONG)(lMaxBgWidth / ldImg);
					}
					else
					{
						if (gpSet->bgOperation == eFill)
							lMaxBgWidth = (LONG)(lMaxBgHeight * ldImg);
						else
							lMaxBgHeight = (LONG)(lMaxBgWidth / ldImg);
					}
				}
			}
			else if (gpSet->bgOperation == eTile)
			{
				// Max между клиентской (точнее Workspace) областью окна и размером текущего монитора
				// Окно может быть растянуто на несколько мониторов, т.е. размер клиентской области может быть больше
				HMONITOR hMon = MonitorFromWindow(ghWnd, MONITOR_DEFAULTTONEAREST);
				MONITORINFO mon = {sizeof(MONITORINFO)};
				GetMonitorInfo(hMon, &mon);
				//
				lMaxBgWidth = klMax(rcWork.right - rcWork.left,mon.rcMonitor.right - mon.rcMonitor.left);
				lMaxBgHeight = klMax(rcWork.bottom - rcWork.top,mon.rcMonitor.bottom - mon.rcMonitor.top);
			}

			if (bgSize.X != lMaxBgWidth || bgSize.Y != lMaxBgHeight)
				NeedBackgroundUpdate();
		}

		if (mb_NeedBgUpdate)
		{
			mb_NeedBgUpdate = false;
			lbForceUpdate = true;
			_ASSERTE(isMainThread());
			//MSectionLock SBG; SBG.Lock(&mcs_BgImgData);
			//BITMAPFILEHEADER* pImgData = mp_BgImgData;
			BackgroundOp op = (BackgroundOp)gpSet->bgOperation;
			const BITMAPFILEHEADER* pBgImgData = pBgFile->GetBgImgData();
			BOOL lbImageExist = (pBgImgData != NULL);
			//BOOL lbVConImage = FALSE;
			//LONG lBgWidth = 0, lBgHeight = 0;
			//CVirtualConsole* pVCon = gpConEmu->ActiveCon();

			////MSectionLock SBK;
			//if (apVCon && gpSet->isBgPluginAllowed)
			//{
			//	//SBK.Lock(&apVCon->csBkImgData);
			//	if (apVCon->HasBackgroundImage(&lBgWidth, &lBgHeight)
			//	        && lBgWidth && lBgHeight)
			//	{
			//		lbVConImage = lbImageExist = TRUE;
			//	}
			//}

			//mb_WasVConBgImage = lbVConImage;

			if (lbImageExist)
			{
				mb_BgLastFade = (!bIsForeground && gpSet->isFadeInactive);
				TODO("Переделать, ориентироваться только на размер картинки - неправильно");
				TODO("DoubleView - скорректировать X,Y");

				//if (lbVConImage)
				//{
				//	if (lMaxBgWidth && lMaxBgHeight)
				//	{
				//		lBgWidth = lMaxBgWidth;
				//		lBgHeight = lMaxBgHeight;
				//	}

				//	if (!mp_Bg->CreateField(lBgWidth, lBgHeight) ||
				//	        !apVCon->PutBackgroundImage(mp_Bg, 0,0, lBgWidth, lBgHeight))
				//	{
				//		delete mp_Bg;
				//		mp_Bg = NULL;
				//	}
				//}
				//else
				{
					const BITMAPINFOHEADER* pBmp = (const BITMAPINFOHEADER*)(pBgImgData+1);

					if (!lMaxBgWidth || !lMaxBgHeight)
					{
						// Сюда мы можем попасть только в случае eUpLeft/eUpRight/eDownLeft/eDownRight
						lMaxBgWidth = pBmp->biWidth;
						lMaxBgHeight = pBmp->biHeight;
					}

					//LONG lImgX = 0, lImgY = 0, lImgW = lMaxBgWidth, lImgH = lMaxBgHeight;

					//if ((gpSet->bgOperation == eFit || gpSet->bgOperation == eFill)
					//	&& (rcWork.bottom - rcWork.top) > 0 && (rcWork.right - rcWork.left) > 0)
					//{
					//	double ldVCon = (rcWork.right - rcWork.left) / (double)(rcWork.bottom - rcWork.top);
					//	double ldImg = pBmp->biWidth / (double)pBmp->biHeight;
					//	if (ldVCon > ldImg)
					//	{
					//		if (gpSet->bgOperation == eFit)
					//			lMaxBgWidth = lMaxBgHeight * ldImg;
					//		else
					//			lMaxBgHeight = lMaxBgWidth / ldImg;
					//	}
					//	else
					//	{
					//		if (gpSet->bgOperation == eFill)
					//			lMaxBgWidth = lMaxBgHeight * ldImg;
					//		else
					//			lMaxBgHeight = lMaxBgWidth / ldImg;
					//	}
					//}

					if (!CreateField(lMaxBgWidth, lMaxBgHeight) ||
						!FillBackground(pBgImgData, 0,0,lMaxBgWidth,lMaxBgHeight, op, mb_BgLastFade))
					{
						bSucceeded = false;
					}
				}
			}
			else
			{
				bSucceeded = false;
			}
		}

		pBgFile->Release();

		#endif
	}
	else
	{
		if (!mb_NeedBgUpdate)
		{
			if ((mb_BgLastFade == bIsForeground && gpSet->isFadeInactive)
				|| (!gpSet->isFadeInactive && mb_BgLastFade))
			{
				NeedBackgroundUpdate();
			}
		}

		//if (mp_PluginBg == NULL)
		//{
		//	NeedBackgroundUpdate();
		//}

		if (mb_NeedBgUpdate)
		{
			mb_NeedBgUpdate = false;
			lbForceUpdate = true;

			//if (!mp_PluginBg)
			//	mp_PluginBg = new CBackground;

			mb_BgLastFade = (!bIsForeground && gpSet->isFadeInactive);
			TODO("Переделать, ориентироваться только на размер картинки - неправильно");
			TODO("DoubleView - скорректировать X,Y");

			if (lMaxBgWidth && lMaxBgHeight)
			{
				lBgWidth = lMaxBgWidth;
				lBgHeight = lMaxBgHeight;
			}

			if (!CreateField(lBgWidth, lBgHeight) ||
				!PutPluginBackgroundImage(0,0, lBgWidth, lBgHeight))
			{
				//delete mp_PluginBg;
				//mp_PluginBg = NULL;
				bSucceeded = false;
			}
		}

		// Check if the bitmap was prepared for the current Far state
		if ((mp_BkImgData && pVCon)
			// Don't use isFilePanel here because it is `false` when any dialog is active in Panels
			&& ((!(pVCon->isEditor || pVCon->isViewer) && !(mp_BkImgData->dwDrawnPlaces & pbp_Panels))
				|| (pVCon->isEditor && !(mp_BkImgData->dwDrawnPlaces & pbp_Editor))
				|| (pVCon->isViewer && !(mp_BkImgData->dwDrawnPlaces & pbp_Viewer))
			))
		{
			lbForceUpdate = false;
			phBgDc = NULL;
			pbgBmpSize = MakeCoord(0, 0);
			goto wrap;
		}
	}

	if (bSucceeded)
	{
		phBgDc = hBgDc;
		pbgBmpSize = bgSize;
	}
	else
	{
		phBgDc = NULL;
		pbgBmpSize = MakeCoord(0,0);
	}

wrap:
	return lbForceUpdate;
}
Пример #3
0
void CSetPgApps::DoFillControls(const AppSettings* pApp)
{
	if (!pApp)
	{
		_ASSERTE(pApp);
		return;
	}

	checkRadioButton(mh_Dlg, rbAppDistinctElevatedOn, rbAppDistinctElevatedIgnore,
		(pApp->Elevated == 1) ? rbAppDistinctElevatedOn :
		(pApp->Elevated == 2) ? rbAppDistinctElevatedOff : rbAppDistinctElevatedIgnore);

	BYTE b;

	checkDlgButton(mh_Child, cbExtendFontsOverride, pApp->OverrideExtendFonts);
	checkDlgButton(mh_Child, cbExtendFonts, pApp->isExtendFonts);

	b = pApp->nFontBoldColor;
	CSetDlgLists::FillListBoxItems(GetDlgItem(mh_Child, lbExtendFontBoldIdx), CSetDlgLists::eColorIdx, b, false);
	b = pApp->nFontItalicColor;
	CSetDlgLists::FillListBoxItems(GetDlgItem(mh_Child, lbExtendFontItalicIdx), CSetDlgLists::eColorIdx, b, false);
	b = pApp->nFontNormalColor;
	CSetDlgLists::FillListBoxItems(GetDlgItem(mh_Child, lbExtendFontNormalIdx), CSetDlgLists::eColorIdx, b, false);

	checkDlgButton(mh_Child, cbCursorOverride, pApp->OverrideCursor);
	CSetPgCursor::InitCursorCtrls(mh_Child, pApp);

	checkDlgButton(mh_Child, cbColorsOverride, pApp->OverridePalette);
	// Don't add unknown palettes in the list!
	int nIdx = SendDlgItemMessage(mh_Child, lbColorsOverride, CB_FINDSTRINGEXACT, -1, (LPARAM)pApp->szPaletteName);
	SendDlgItemMessage(mh_Child, lbColorsOverride, CB_SETCURSEL, klMax(nIdx, 0), 0);

	checkDlgButton(mh_Child, cbClipboardOverride, pApp->OverrideClipboard);
	//
	checkDlgButton(mh_Child, cbCTSDetectLineEnd, pApp->isCTSDetectLineEnd);
	checkDlgButton(mh_Child, cbCTSBashMargin, pApp->isCTSBashMargin);
	checkDlgButton(mh_Child, cbCTSTrimTrailing, pApp->isCTSTrimTrailing);
	b = pApp->isCTSEOL;
	CSetDlgLists::FillListBoxItems(GetDlgItem(mh_Child, lbCTSEOL), CSetDlgLists::eCRLF, b, false);

	//
	PasteLinesMode mode;
	mode = pApp->isPasteAllLines;
	checkRadioButton(mh_Child, rPasteM1MultiLine, rPasteM1Nothing,
		(mode == plm_FirstLine) ? rPasteM1FirstLine
		: (mode == plm_SingleLine) ? rPasteM1SingleLine
		: (mode == plm_Nothing) ? rPasteM1Nothing
		: rPasteM1MultiLine);
	checkDlgButton(mh_Child, cbPasteM1Posix, (pApp->isPosixAllLines != pxm_Intact) ? BST_CHECKED : BST_UNCHECKED);
	mode = pApp->isPasteFirstLine;
	checkRadioButton(mh_Child, rPasteM2MultiLine, rPasteM2Nothing,
		(mode == plm_MultiLine) ? rPasteM2MultiLine
		: (mode == plm_FirstLine) ? rPasteM2FirstLine
		: (mode == plm_Nothing) ? rPasteM2Nothing
		: rPasteM2SingleLine);
	checkDlgButton(mh_Child, cbPasteM2Posix, (pApp->isPosixFirstLine != pxm_Intact) ? BST_CHECKED : BST_UNCHECKED);
	//
	checkDlgButton(mh_Child, cbCTSClickPromptPosition, pApp->isCTSClickPromptPosition);
	//
	checkDlgButton(mh_Child, cbCTSDeleteLeftWord, pApp->isCTSDeleteLeftWord);

}
Пример #4
0
int CFindPanel::GetMinWidth()
{
	if (!this || !mh_Pane)
		return 0;
	return klMax(80,(int)(SearchCtrlWidthMul*mn_RebarHeight));
}
Пример #5
0
LPCWSTR msprintf(LPWSTR lpOut, size_t cchOutMax, LPCWSTR lpFmt, ...)
{
	va_list argptr;
	va_start(argptr, lpFmt);
	
	const wchar_t* pszSrc = lpFmt;
	wchar_t* pszDst = lpOut;
	wchar_t  szValue[16];
	wchar_t* pszValue;

	while (*pszSrc)
	{
		if (*pszSrc == L'%')
		{
			pszSrc++;
			switch (*pszSrc)
			{
			case L'%':
				{
					*(pszDst++) = L'%';
					pszSrc++;
					continue;
				}
			case L'c':
				{
					// GCC: 'wchar_t' is promoted to 'int' when passed through '...'
					wchar_t c = va_arg( argptr, int );
					*(pszDst++) = c;
					pszSrc++;
					continue;
				}
			case L's':
				{
					pszValue = va_arg( argptr, wchar_t* );
					if (pszValue)
					{
						while (*pszValue)
						{
							*(pszDst++) = *(pszValue++);
						}
					}
					pszSrc++;
					continue;
				}
			case L'S':
				{
					char* pszValueA = va_arg( argptr, char* );
					if (pszValueA)
					{
						// по хорошему, тут бы MultiByteToWideChar звать, но
						// эта ветка должна по идее только для отладки использоваться
						while (*pszValueA)
						{
							*(pszDst++) = (wchar_t)*(pszValueA++);
						}
					}
					pszSrc++;
					continue;
				}
			case L'u':
			case L'i':
				{
					UINT nValue = 0;
					if (*pszSrc == L'i')
					{
						int n = va_arg( argptr, int );
						if (n < 0)
						{
							*(pszDst++) = L'-';
							nValue = -n;
						}
						else
						{
							nValue = n;
						}
					}
					else
					{
						nValue = va_arg( argptr, UINT );
					}
					pszSrc++;
					pszValue = szValue;
					while (nValue)
					{
						WORD n = (WORD)(nValue % 10);
						*(pszValue++) = (wchar_t)(L'0' + n);
						nValue = (nValue - n) / 10;
					}
					if (pszValue == szValue)
						*(pszValue++) = L'0';
					// Теперь перекинуть в szGuiPipeName
					while (pszValue > szValue)
					{
						*(pszDst++) = *(--pszValue);
					}
					continue;
				}
			case L'0':
			case L'X':
			case L'x':
				{
					int nLen = 0;
					DWORD nValue;
					wchar_t cBase = L'A';
					if (pszSrc[0] == L'0' && isDigit(pszSrc[1]) && (pszSrc[2] == L'X' || pszSrc[2] == L'x'))
					{
						if (pszSrc[2] == L'x')
							cBase = L'a';
						if (pszSrc[1] == L'8')
						{
							memmove(szValue, L"00000000", 16);
							nLen = 8;
						}
						else if (pszSrc[1] == L'4')
						{
							memmove(szValue, L"0000", 8);
							nLen = 4;
						}
						else if (pszSrc[1] == L'2')
						{
							memmove(szValue, L"00", 4);
							nLen = 2;
						}
						else
						{
							_ASSERTE(FALSE && "Unsupported %0?X format");
						}
						pszSrc += 3;
					}
					else if (pszSrc[0] == L'0' && (pszSrc[1] == L'2' || pszSrc[1] == L'3') && pszSrc[2] == L'u')
					{
						cBase = 0;
						szValue[0] = 0;
						nLen = ((int)pszSrc[1]) - ((int)L'0');
						pszSrc += 3;
					}
					else if (pszSrc[0] == L'X' || pszSrc[0] == L'x')
					{
						if (pszSrc[0] == L'x')
							cBase = L'a';
						pszSrc++;
					}
					else
					{
						_ASSERTE(*pszSrc == L'u' || *pszSrc == L's' || *pszSrc == L'c' || *pszSrc == L'i' || *pszSrc == L'X');
						goto wrap;
					}
					
					
					nValue = va_arg( argptr, UINT );
					pszValue = szValue;
					if (cBase)
					{
						// Hexadecimal branch
						while (nValue)
						{
							WORD n = (WORD)(nValue & 0xF);
							if (n <= 9)
								*(pszValue++) = (wchar_t)(L'0' + n);
							else
								*(pszValue++) = (wchar_t)(cBase + n - 10);
							nValue = nValue >> 4;
						}
						int nCurLen = (int)(pszValue - szValue);
						if (!nLen)
						{
							nLen = nCurLen;
							if (!nLen)
							{
								*(pszValue++) = L'0';
								nLen = 1;
							}
						}
						else
						{
							pszValue = (szValue+klMax(nLen,nCurLen));
						}
						// Теперь перекинуть в Dest
						while (pszValue > szValue)
						{
							*(pszDst++) = *(--pszValue);
						}
					}
					else
					{
						// Decimal branch
						int nGetLen = 0;
						while (nValue)
						{
							WORD n = (WORD)(nValue % 10);
							*(pszValue++) = (wchar_t)(L'0' + n);
							nValue = (nValue - n) / 10;
							nGetLen++;
						}
						while ((nGetLen++) < nLen)
							*(pszDst++) = L'0';
						while ((--pszValue) >= szValue)
							*(pszDst++) = *pszValue;
					}
					continue;
				}