Exemple #1
0
STDMETHODIMP CTextOverlay::clone(IOverlay * * pRet)
{
	if (pRet == NULL)
		return E_POINTER;
		
	SimpleOverlayImpl2<ITextOverlay>::clone(pRet);

	CTextOverlay *o = (CTextOverlay*) *pRet;

	o->put_Radius(radius);
	float fs;
	get_FontSize(&fs);
	o->put_FontSize(fs);
	int fStyle;
	get_FontStyle(&fStyle);
	o->put_FontStyle(fStyle);
	BSTR fName;
	get_FontName(&fName);
	o->put_FontName(fName);
	// We now own fName, so free it:
	::SysFreeString(fName);
	long fColor;
	get_FontColor(&fColor);
	o->put_FontColor(fColor);
	o->put_Format(format);
	o->put_BlurColor(blurColor);

	o->put_AlternateRender(alternateRender);
	o->put_Wrap(wrap);
	o->put_TextRenderingHint(textRenderingHint);
	o->put_TextContrast(textContrast);
	o->put_Width(width);
	o->put_Height(height);

	return S_OK;
}
Exemple #2
0
void Window::OnComputedPropertyValueChanged(PropertyValue* pPropertyVal, bool handled)
{
	if (pPropertyVal->m_dp == get_IsActiveProperty())
	{
		if (m_platformWindow)
		{
			bool isActive = get_IsActive();

			if (isActive)
			{
				SetForegroundWindow(m_platformWindow->get_Handle());
				//::SetWindowPos(m_platformWindow->get_Handle(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE/* | SWP_NOZORDER*/);
			}
		}
	}
	else if (pPropertyVal->m_dp == get_OpacityProperty())
	{
		if (m_platformWindow)
		{
			m_platformWindow->OnOpacityChanged();
		}
	}
	else if (pPropertyVal->m_dp == get_ClipProperty())
	{
		if (m_platformWindow)
		{
			m_platformWindow->OnClipChanged();
		}
	}
	else if (pPropertyVal->m_dp == get_TitleTextProperty())
	{
		if (m_platformWindow)
		{
			m_platformWindow->OnTitleTextChanged();
		}
	}
	else if (pPropertyVal->m_dp == get_CanMinimizeProperty())
	{
		if (m_platformWindow)
		{
			bool has = get_CanMaximize();

			DWORD style = GetWindowLongW(m_platformWindow->get_Handle(), GWL_STYLE);
			if (has)
				style |= WS_MINIMIZEBOX;
			else
				style &= ~WS_MINIMIZEBOX;

			SetWindowLongW(m_platformWindow->get_Handle(), GWL_STYLE, style);
		}
	}
	else if (pPropertyVal->m_dp == get_CanMaximizeProperty())
	{
		if (m_platformWindow)
		{
			bool has = get_CanMaximize();

			DWORD style = GetWindowLongW(m_platformWindow->get_Handle(), GWL_STYLE);
			if (has)
				style |= WS_MAXIMIZEBOX;
			else
				style &= ~WS_MAXIMIZEBOX;

			SetWindowLongW(m_platformWindow->get_Handle(), GWL_STYLE, style);
		}
	}
	else if (pPropertyVal->m_dp == get_HasContextHelpProperty())
	{
		if (m_platformWindow)
		{
			bool has = get_HasContextHelp();

			DWORD exstyle = GetWindowLongW(m_platformWindow->get_Handle(), GWL_EXSTYLE);
			if (has)
				exstyle |= WS_EX_CONTEXTHELP;
			else
				exstyle &= ~WS_EX_CONTEXTHELP;

			SetWindowLongW(m_platformWindow->get_Handle(), GWL_EXSTYLE, exstyle);
		}
	}
	else if (pPropertyVal->m_dp == get_ShowInTaskbarProperty())
	{
		if (m_platformWindow)
		{
			bool show = get_ShowInTaskbar();

			/*
			DWORD exstyle = GetWindowLongW(m_platformWindow->get_Handle(), GWL_EXSTYLE);
			if (show)
			{
				exstyle |= WS_EX_APPWINDOW;
				exstyle &= ~WS_EX_TOOLWINDOW;
			}
			else
			{
				exstyle &= ~WS_EX_APPWINDOW;
				exstyle |= WS_EX_TOOLWINDOW;
			}

			SetWindowLongW(m_platformWindow->get_Handle(), GWL_EXSTYLE, exstyle);
			*/

			if (show)
			{
				MS::Windows::Shell::Private::pTaskbarList->AddTab(m_platformWindow->get_Handle());
			}
			else
			{
				MS::Windows::Shell::Private::pTaskbarList->DeleteTab(m_platformWindow->get_Handle());
			}
		}
	}

	else if (pPropertyVal->m_dp == get_FontFamilyProperty() ||
			pPropertyVal->m_dp == get_FontSizeProperty() ||
			pPropertyVal->m_dp == get_FontWeightProperty() ||
			pPropertyVal->m_dp == get_FontStyleProperty())
	{
		if (m_platformWindow)
		{
			LOGFONT lf = {0};
			// TODO: Copy16
			wcscpy_s(lf.lfFaceName, get_FontFamily().c_strw_flen<LF_FACESIZE>());
			lf.lfHeight = -get_FontSize();
			lf.lfWeight = get_FontWeight();

			HFONT hFont = CreateFontIndirect(&lf);
			ASSERT(hFont);

			SendMessageW(m_platformWindow->get_Handle(), WM_SETFONT, (WPARAM)hFont, TRUE/*bRedraw*/);

			/*
			String titleText = get_TitleText();

			SetWindowTextW(m_platformWindow->get_Handle(), CStringw(titleText).c_str());
			*/
		}
	}
	else if (pPropertyVal->m_dp == get_TopmostProperty())
	{
		if (m_platformWindow)
		{
			bool topmost = get_Topmost();
			if (topmost)
				SetWindowPos(m_platformWindow->get_Handle(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
			else
				SetWindowPos(m_platformWindow->get_Handle(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
		}
	}
	else if (pPropertyVal->m_dp == get_StateProperty())
	{
		if (m_platformWindow)
		{
			int state = GetPropertyValueInt(get_StateProperty());
			switch (state)
			{
			case 0:
				::ShowWindow(m_platformWindow->get_Handle(), SW_RESTORE);
				break;

			case 1:
				::ShowWindow(m_platformWindow->get_Handle(), SW_MINIMIZE);
				break;

			case 2:
				::ShowWindow(m_platformWindow->get_Handle(), SW_MAXIMIZE);
				break;
			}
		}
	}
	else if (pPropertyVal->m_dp == get_IsEnabledProperty())
	{
		if (m_platformWindow)
		{
			bool isEnabled = get_IsEnabled();
			::EnableWindow(m_platformWindow->get_Handle(), isEnabled);
		}
	}
	else if (pPropertyVal->m_dp == get_CanCloseProperty())
	{
		if (m_platformWindow)
		{
			if (get_CanClose())
			{
			//	SetWindowLongPtr(m_platformWindow->get_Handle(), 
			}
			else
			{
			}
			/*
			ULONG_PTR classStyle = ::GetClassLongPtr(m_platformWindow->get_Handle(), GCL_STYLE);

			if (get_CanClose()) classStyle &= ~CS_NOCLOSE;
			else classStyle |= CS_NOCLOSE;

			::SetClassLongPtr(m_platformWindow->get_Handle(), GCL_STYLE, classStyle);
			*/
		}
	}
	else if (pPropertyVal->m_dp == get_LeftProperty() ||
			pPropertyVal->m_dp == get_TopProperty())
	{
		if (m_platformWindow)
		{
			int x = int(get_Left());
			int y = int(get_Top());
			int cx = int(get_ActualWidth());	// ceil??
			int cy = int(get_ActualHeight());	// ceil??

			if (!get_InSizeMove() && !m_inSizeMove)
			{
				::SetWindowPos(m_platformWindow->get_Handle(), nullptr, x, y, cx, cy,
					SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE/* |
					SWP_ASYNCWINDOWPOS	// ??*/
					);
			}
		}
	}
	else if (pPropertyVal->m_dp == get_ActualWidthProperty() ||
			pPropertyVal->m_dp == get_ActualHeightProperty())
	{
		if (m_platformWindow)
		{
			int x = int(get_Left());
			int y = int(get_Top());
			int cx = int(get_ActualWidth());	// ceil??
			int cy = int(get_ActualHeight());	// ceil??

			if (!get_InSizeMove() && !m_inSizeMove)
			{
				::SetWindowPos(m_platformWindow->get_Handle(), nullptr, x, y, cx, cy,
					SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE/* |
					SWP_ASYNCWINDOWPOS	// ??*/
					);
			}
		}
	}
	else if (pPropertyVal->m_dp == get_RTProperty())
	{
		if (m_platformWindow)
		{
			m_platformWindow->ChangeTech();
		}
	}
#if 0
	else if (pPropertyVal->m_dp == get_ChildProperty())
	{
		/*
		MessageBeep(-1);
		if (m_platformWindow)
		{
		}
		*/
		InvalidateVisual();
	}
#endif
	else if (pPropertyVal->m_dp == get_ShadowTreeProperty())
	{
		UIElement* uielement = get_ShadowTree();

		if (uielement)
		{
			uielement->SetRoot(this);	// This is different from default UIElement implementation
			uielement->set_ParentWindow(this);	// This is different from default UIElement implementation

			uielement->set_Parent(this);
			uielement->set_TemplatedOwner(this);	// ??

			InvalidateMeasure();
		//	// ??
		//	uielement->ArrangeCore(gm::SizeF(get_ActualWidth(), get_ActualHeight()));
		}

		handled = true;
	}
	else if (pPropertyVal->m_dp == get_OwnerProperty())
	{
		Window* owner = get_Owner();

		if (m_platformWindow && m_platformWindow->get_Handle())
		{
			if (owner)
			{
				if (owner->m_platformWindow && owner->m_platformWindow->get_Handle())
				{
					::SetParent(m_platformWindow->get_Handle(), owner->m_platformWindow->get_Handle());
				}
			}
			else
			{
				::SetParent(m_platformWindow->get_Handle(), nullptr);
			}
		}
	}
	else if (pPropertyVal->m_dp == get_TaskbarItemInfoProperty())
	{
		MS::Windows::Shell::TaskbarItemInfo* info = get_TaskbarItemInfo();

		if (m_platformWindow)
		{
			HWND hWnd = m_platformWindow->get_Handle();
			if (hWnd)
			{
				double progress = info->get_ProgressValue();
				const ULONGLONG totalProgress = 1000000ULL;

			//	TBPFLAG tbFlags;
			//	MS::Windows::Shell::Private::pTaskbarList3->SetProgressState(hWnd, tbpFlags);
				MS::Windows::Shell::Private::pTaskbarList3->SetProgressValue(hWnd, progress*totalProgress, totalProgress);
			}
		}
	}

	baseClass::OnComputedPropertyValueChanged(pPropertyVal, handled);
}
Exemple #3
0
STDMETHODIMP CTextOverlay::Render(LONG hdc)
{
	PointF zero(0.0, 0.0);

	// Get the text we want to draw!
	BSTR text;

	IMeter *iMeter = 0;
	get_meter(&iMeter);
	if (!iMeter)
	{
		text = format.copy();
	}
	else
	{
		_bstr_t tmp("");
		BSTR tCopy = tmp.copy();
		text = tCopy;
		iMeter->GetAsString(format, selector, &text);
		if (text != tCopy)
			::SysFreeString(tCopy);
	}

	// Create graphics object
	Graphics graphics((HDC)hdc);
	graphics.SetInterpolationMode(InterpolationModeHighQuality);
	graphics.SetPixelOffsetMode(PixelOffsetModeHalf);
	graphics.SetSmoothingMode(SmoothingModeAntiAlias);
	
	graphics.SetTextRenderingHint(getDefaultRenderingHint(textRenderingHint));
	graphics.SetCompositingMode(CompositingModeSourceOver);
	graphics.SetTextContrast(textContrast);

	// Calculate world transformation
	REAL el[6];
	CumulativeTransform(el);
	Matrix matrix(el[0], el[1], el[2], el[3], el[4], el[5]);
//	matrix.Invert();
	graphics.SetTransform(&matrix);

	// Create fontFamily for path-based font rendering
	BSTR fName;
	get_FontName(&fName);
	FontFamily  fontFamily(fName);
	::SysFreeString(fName);

	// Get some extra stuff for path-based rendering
	int fStyle;
	get_FontStyle(&fStyle);
	float fSize;
	get_FontSize(&fSize);

	// Set font for alternate rendering
//	Font font((HDC)hdc, &logFont);
	Font font(&fontFamily, fSize, fStyle, UnitPixel);

	// Set font color
	SolidBrush  fg(color);

	// Set up string format
	StringFormat format(vertical ? StringFormatFlagsDirectionVertical : 0, LANG_NEUTRAL);
	if (!wrap)
		format.SetFormatFlags(format.GetFormatFlags() |  StringFormatFlagsNoWrap);
	format.SetAlignment((StringAlignment)hAlign);
	format.SetLineAlignment((StringAlignment)vAlign);

	// Calculate clipping rectangle
	RectF clipRect(0.0, 0.0, (float)width, (float)height);
	if (hAlign == 1)	// Center
		clipRect.X = (float)-width/2;
	else if (hAlign == 2)	// Right
		clipRect.X = (float)-width;

	if (vAlign == 1)	// Center
		clipRect.Y = (float)-height/2;
	else if (vAlign == 2)	// Right
		clipRect.Y = (float)-height;

	// Draw blur
	if (radius > 0)
	{
		GraphicsPath blurPath;
		if (width > -1 && height > -1)
		{
			blurPath.AddString(text, -1, &fontFamily, fStyle, fSize, clipRect, &format);
		}
		else
		{
			blurPath.AddString(text, -1, &fontFamily, fStyle, fSize, zero, &format);
		}
		BYTE alpha;
		get_Alpha(&alpha);
		for (int i=radius; i>0; i--)
		{
			Color _blurColor((BYTE)(alpha/radius), (BYTE)(blurColor >> Color::BlueShift), (BYTE)(blurColor >> Color::GreenShift), (BYTE)(blurColor >> Color::RedShift));
			if (blurColor == -1)
			{
				_blurColor = Color(alpha/radius, color.GetRed(), color.GetGreen(), color.GetBlue());
			}
			Pen blurPen(_blurColor, (float)2*i);
			blurPen.SetEndCap(LineCapRound);
			blurPen.SetMiterLimit(1);

			graphics.DrawPath(&blurPen, &blurPath);
		}

		GraphicsState state = graphics.Save();
		graphics.SetClip(&blurPath);
		Color trans(0, 0, 0, 0);
		SolidBrush brush(trans);
		graphics.FillPath(&brush, &blurPath);
		graphics.Restore(state);
	}