コード例 #1
0
ファイル: TrackerSettings.cpp プロジェクト: AmirAbrams/haiku
void
TrackerSettings::SetWarningSpaceColor(rgb_color color)
{
	gTrackerState.fWarningSpaceColor->ValueChanged(ColorToValue(color));
}
コード例 #2
0
void VSpanTextParser::GenerateSpanText( const VTreeTextStyle& inStyles, const VString& inPlainText, VString& outTaggedText, VTextStyle* inDefaultStyle)
{
	sLONG begin, end;
	bool vhasForecolore, vistransparent;
	VString fontName, defaultfontName;
	sLONG vbold,vitalic,vunderline, vstrikeout, vdefaultbold,vdefaultitalic,vdefaultunderline,vdefaultstrikeout;
	Real fontSize, defaultfontSize;
	RGBAColor vforecolor, vdefaultforecolor, vbackcolor, vdefaultbackcolor;
	justificationStyle justification, defaultjustification;
	VTextStyle* uniformStyle = inStyles.GetData();
	
	justification = defaultjustification = JST_Left;

	uniformStyle->GetRange(begin, end);
	fontName = uniformStyle->GetFontName();
	fontSize = uniformStyle->GetFontSize();
	vbold = uniformStyle->GetBold();
	vitalic = uniformStyle->GetItalic();
	vunderline = uniformStyle->GetUnderline();
	vstrikeout = uniformStyle->GetStrikeout();
	vhasForecolore = uniformStyle->GetHasForeColor();
	vistransparent = uniformStyle->GetTransparent();
	vforecolor = uniformStyle->GetColor();
	vbackcolor = uniformStyle->GetBackGroundColor();
	justification = uniformStyle->GetJustification();
	VTreeTextStyle* parenttree = inStyles.GetParent();
	bool hasDefaultForeColor = false;
	bool hasDefaultBackColor = false;

	if(inDefaultStyle)
	{
		defaultfontName = inDefaultStyle->GetFontName();
		defaultfontSize = inDefaultStyle->GetFontSize();
		defaultjustification = inDefaultStyle->GetJustification();
		vdefaultbold = inDefaultStyle->GetBold();
		vdefaultitalic = inDefaultStyle->GetItalic();
		vdefaultunderline = inDefaultStyle->GetUnderline();
		vdefaultstrikeout = inDefaultStyle->GetStrikeout();
		hasDefaultForeColor = inDefaultStyle->GetHasForeColor();
		hasDefaultBackColor = !inDefaultStyle->GetTransparent();
		vdefaultforecolor = inDefaultStyle->GetColor();
		vdefaultbackcolor = inDefaultStyle->GetBackGroundColor();
	}
	else
	{
		defaultfontName = "";
		defaultfontSize = -1;
		vdefaultbold = 0;
		vdefaultitalic = 0;
		vdefaultunderline = 0;
		vdefaultstrikeout = 0;
		defaultjustification = JST_Notset;
	}

	//as we inherit styles from parent, -1 or default value should be assumed equal (otherwise comparison would trigger a useless tag)
	if (vdefaultbold < 0)
		vdefaultbold = 0;
	if (vdefaultitalic < 0)
		vdefaultitalic = 0;
	if (vdefaultunderline < 0)
		vdefaultunderline = 0;
	if (vdefaultstrikeout < 0)
		vdefaultstrikeout = 0;
	if (defaultjustification < 0)
		defaultjustification = JST_Default;

	bool addfontag, addfonsizetag, addboldtag, additalictag, addunderlinetag, addstrikeouttag, addforecolortag, addbackcolortag, addjustificationtag;
	addfontag = addfonsizetag = addboldtag = additalictag = addunderlinetag = addstrikeouttag =  addforecolortag = addbackcolortag = addjustificationtag = false;

	//we pass inherited default style to children to avoid to redefine style already defined by parent node:
	//so current inDefaultStyle always inherits parent styles
	VTextStyle *defaultStyleInherit = inStyles.GetChildCount() > 0 ? new VTextStyle( inDefaultStyle) : NULL;
	if( fontName.GetLength() > 0 && fontName != defaultfontName)
	{
		addfontag = true;
		if (defaultStyleInherit)
			defaultStyleInherit->SetFontName( fontName);
	}
	if( fontSize != -1 && fontSize != defaultfontSize)
	{
		addfonsizetag = true;
		if (defaultStyleInherit)
			defaultStyleInherit->SetFontSize( fontSize);
	}
	if( justification != JST_Notset && justification != defaultjustification)
	{
		addjustificationtag = true;
		if (defaultStyleInherit)
			defaultStyleInherit->SetJustification( justification);
	}
	if( vbold != UNDEFINED_STYLE && vbold != vdefaultbold)
	{
		addboldtag = true;
		if (defaultStyleInherit)
			defaultStyleInherit->SetBold( vbold);
	}

	if( vitalic != UNDEFINED_STYLE  && vitalic != vdefaultitalic)
	{
		additalictag = true;
		if (defaultStyleInherit)
			defaultStyleInherit->SetItalic( vitalic);
	}

	if( vunderline != UNDEFINED_STYLE && vunderline != vdefaultunderline)
	{
		addunderlinetag = true;
		if (defaultStyleInherit)
			defaultStyleInherit->SetUnderline( vunderline);
	}

	if( vstrikeout != UNDEFINED_STYLE && vstrikeout != vdefaultstrikeout)
	{
		addstrikeouttag = true;
		if (defaultStyleInherit)
			defaultStyleInherit->SetStrikeout( vstrikeout);
	}

	if( vhasForecolore && ((!hasDefaultForeColor) || vforecolor != vdefaultforecolor))
	{
		addforecolortag = true;
		if (defaultStyleInherit)
		{
			defaultStyleInherit->SetHasForeColor( vhasForecolore);
			defaultStyleInherit->SetColor( vforecolor);
		}
	}

	if( !vistransparent && ((!hasDefaultBackColor) || vbackcolor != vdefaultbackcolor))
	{
		addbackcolortag = true;
		if (defaultStyleInherit)
		{
			defaultStyleInherit->SetTransparent( false);
			defaultStyleInherit->SetBackGroundColor( vbackcolor);
		}
	}

	bool addtag = addfontag || addfonsizetag || addboldtag || additalictag || addunderlinetag || addstrikeouttag || addforecolortag || addbackcolortag || addjustificationtag;

	bool isInitialEmpty = outTaggedText.IsEmpty();
	if(addtag)
	{
		bool addcoma = false;
		outTaggedText += "<SPAN STYLE=\"";
	
		if(addfontag)
		{
			outTaggedText += MS_FONT_NAME;
			outTaggedText += ":'";
			outTaggedText += fontName + "'";
			addcoma = true;
		}

		if(addfonsizetag)
		{
			VString strFontSize;
			//we need to convert from 72dpi font size to the desired dpi (screen dpi for v12 compatibility)
#if VERSIONWIN
			strFontSize.FromReal(floor(fontSize*72.0f/VSpanTextParser::Get()->GetDPI()+0.5f));
#else
			strFontSize.FromReal(fontSize);
#endif
			if(addcoma)
				outTaggedText+=";";
			outTaggedText += MS_FONT_SIZE ;
			outTaggedText += ":";
			outTaggedText += strFontSize;
			outTaggedText += "pt";
			addcoma = true;
		}
		
		if(addjustificationtag)
		{
			VString value;
			JustificationToString(justification,value);
			if(addcoma)
				outTaggedText+=";";
			outTaggedText += MS_JUSTIFICATION;
			outTaggedText += ":";
			outTaggedText += value;
			addcoma = true;
		}

		if(addboldtag)
		{
			VString value;
			if(addcoma)
				outTaggedText+=";";
			vbold ? value = "bold" : value = "normal";
			outTaggedText += MS_BOLD ;
			outTaggedText += ":" + value;
			addcoma = true;
		}

		if(additalictag)
		{
			VString value;
			if(addcoma)
				outTaggedText+=";";
			vitalic ? value = "italic" : value = "normal";
			outTaggedText += MS_ITALIC ;
			outTaggedText += ":"+ value;
			addcoma = true;
		}

		if(addunderlinetag && addstrikeouttag)
		{
			VString value;
			if(addcoma)
				outTaggedText+=";";
			if(!vunderline && !vstrikeout)
				value = "none";
			if(vunderline && vstrikeout)
				value = "underline line-through";
			else if(vunderline)
				value = "underline";
			else if(vstrikeout)
				value = "line-through";				
			outTaggedText += MS_UNDERLINE ;
			outTaggedText += ":"+ value;
			addcoma = true;
		}
		else
		{
			if(addunderlinetag)
			{
				VString value;
				if(addcoma)
					outTaggedText+=";";
				vunderline ? value = "underline" : value = "none";
				outTaggedText += MS_UNDERLINE ;
				outTaggedText += ":"+ value;
				addcoma = true;
			}
					
			if(addstrikeouttag)
			{
				VString value;
				if(addcoma)
					outTaggedText+=";";
				vstrikeout ? value = "line-through" : value = "none";
				outTaggedText += MS_UNDERLINE ;
				outTaggedText += ":"+ value;
				addcoma = true;
			}
		}

		if(addforecolortag)
		{
			VString value;
			if(addcoma)
				outTaggedText+=";";
			ColorToValue(vforecolor,value);
			outTaggedText += MS_COLOR;
			outTaggedText += ":"+ value;
			addcoma = true;
		}

		if(addbackcolortag)
		{
			VString value;
			if(addcoma)
				outTaggedText+=";";
			ColorToValue(vbackcolor,value);
			outTaggedText += MS_BACKGROUND;
			outTaggedText += ":"+ value;
			addcoma = true;
		}

		outTaggedText +="\">";				

	}

	
	VString text;
	VString tmp;

	sLONG count = inStyles.GetChildCount();

	//prevent assert in GetSubString
	if (end > inPlainText.GetLength())
		end = inPlainText.GetLength();
	if (begin > inPlainText.GetLength())
		begin = inPlainText.GetLength();

	if(count == 0)
	{
		if(end>begin)
		{
			inPlainText.GetSubString(begin+1, end-begin, text);
			ToXMLCompatibleText(text, tmp);
			outTaggedText += tmp;
		}
	}
	else
	{
		sLONG start = begin;
		for(sLONG i = 1; i <= count; i++)
		{
			VTreeTextStyle* child = inStyles.GetNthChild(i);
			sLONG b,e;
			child->GetData()->GetRange(b,e);

			//prevent assert in GetSubString
			if (e > inPlainText.GetLength())
				e = inPlainText.GetLength();
			if (b > inPlainText.GetLength())
				b = inPlainText.GetLength();

			//if(start < b-1)
			if(start < b)
			{
				inPlainText.GetSubString(start+1, b-start, text);
				ToXMLCompatibleText(text, tmp);
				outTaggedText += tmp;
			}
			
			GenerateSpanText(*child, inPlainText, outTaggedText, defaultStyleInherit);
			start = e;
		}
		
		if(start < end)
		{
			inPlainText.GetSubString(start+1, end-start, text);
			ToXMLCompatibleText(text, tmp);
			outTaggedText += tmp;
		}

	}

	if (addtag)
		outTaggedText +="</SPAN>";
	//JQ 24/12/2012: ensure tagged text is bracketed with SPAN tag
	else if (isInitialEmpty)
	{
		if (!outTaggedText.BeginsWith(CVSTR("<SPAN"), true))
			outTaggedText = CVSTR("<SPAN>")+outTaggedText+CVSTR("</SPAN>");
	}

	if (defaultStyleInherit)
		delete defaultStyleInherit;
}