////////////////////////////////////////////////////////////////////////////////////////////
// StylesControl Styles client-side script
////////////////////////////////////////////////////////////////////////////////////////////

addNamespace("Styles");

////////////////////////////////////////////////////////////////////////////////////////////

Styles.FontFaceStyleClass = Class.inherit(Core.Enum, 
{
	Normal: 1,
	Italic: 2
});
Styles.FontFaceStyle = new Styles.FontFaceStyleClass("Styles.FontFaceStyleClass");

Styles.FontWeightClass = Class.inherit(Core.Enum, 
{
	Normal: 1,
	Bold: 2
});
Styles.FontWeight = new Styles.FontWeightClass("Styles.FontWeightClass");

Styles.TextCaseClass = Class.inherit(Core.Enum, 
{
	Default: 1,
	AllCaps: 2
});
Styles.TextCase = new Styles.TextCaseClass("Styles.TextCaseClass");

Styles.TextDecorationClass = Class.inherit(Core.Enum, 
{
	None: 1,
	Underline: 2,
	Strikeout: 3,
	All: 4
});
Styles.TextDecoration = new Styles.TextDecorationClass("Styles.TextDecorationClass");

Styles.TextEffectClass = Class.inherit(Core.Enum, 
{
	None: 1,
	Box: 2,
	Halo: 3
});
Styles.TextEffect = new Styles.TextEffectClass("Styles.TextEffectClass");

Styles.LineWidthUnitClass = Class.inherit(Core.Enum, 
{
	Pixel: 1,
	Point: 2
});
Styles.LineWidthUnit = new Styles.LineWidthUnitClass("Styles.LineWidthUnitClass");

Styles.BitmapStylesClass = Class.inherit(Core.Enum, 
{
	All: 7,
	ApplyColor: 2,
	NativeSize: 4,
	None: 0,
	ShowWhiteBackground: 1
});
Styles.BitmapStyles = new Styles.BitmapStylesClass("Styles.BitmapStylesClass");

////////////////////////////////////////////////////////////////////////////////////////////

Styles.LineWidth = Class.create();
Styles.LineWidth.prototype =
{
	initialize: function(value, unit)
	{
		this.value = 1;
		this.unit = Styles.LineWidthUnit.Pixel;
		
		if (value) this.value = value;
		if (unit) this.unit = unit;
	},
	
	toString: function()
	{
		return "MapInfo.Styles.LineWidth: " + this.value + " " + this.unit.toString();
	}
};

////////////////////////////////////////////////////////////////////////////////////////////

Styles.Style = Class.create();
Styles.Style.prototype =
{
	toString: function()
	{
		return "";
	},
	
	toJSON: function()
	{
		return "{\"__type\":\"Torbay.GIS.MappingService.Styles.Style, Torbay.GIS.MappingService, Version=2006.11.1.0, Culture=neutral, PublicKeyToken=0e8421ff7ecab46a\",\"MapInfo\":\"" + this.toString() + "\"}";
	}
};

////////////////////////////////////////////////////////////////////////////////////////////
Styles.Font = Class.inherit(Styles.Style, 
{
	initialize: function(name, faceStyle, weight)
	{
		this.backColor = Drawing.Colors.White;
		this.expanded = false;
		this.faceStyle = Styles.FontFaceStyle.Normal;
		this.weight = Styles.FontWeight.Normal;
		this.foreColor = Drawing.Colors.Black;
		this.name = "Arial";
		this.shadow = false;
		this.textCase = Styles.TextCase.Default;
		this.textDecoration = Styles.TextDecoration.None;
		this.textEffect = Styles.TextEffect.None;
		this.size = 14;
		
		if (name) this.name = name;
		if (faceStyle) this.faceStyle = faceStyle;
		if (weight) this.weight = weight;
	},
	
	toString: function()
	{
		return "MapInfo.Styles.Font\n" +
			"Name: " + this.name + "\n" +
			"Size: " + this.size + "\n" +
			"ForeColor: " + this.foreColor.toArgb() + "\n" +
			"BackColor: " + this.backColor.toArgb() + "\n" +
			"FontFaceStyle: " + this.faceStyle.toString() + "\n" +
			"FontWeight: " + this.weight.toString() + "\n" +
			"TextEffect: " + this.textEffect.toString() + "\n" +
			"TextDecoration: " + this.textDecoration.toString() + "\n" +
			"TextCase: " + this.textCase.toString() + "\n" +
			"Shadow: " + this.shadow + "\n" +
			"DblSpace: " + this.expanded + "\n";
	}
});

////////////////////////////////////////////////////////////////////////////////////////////

Styles.AreaStyle = Class.inherit(Styles.Style, 
{
	initialize: function(border, interior)
	{
		this.border = new Styles.LineStyle();
		this.interior = new Styles.InteriorStyle();
		
		if (border) this.border = border;
		if (interior) this.interior = interior;
	},
	
	toString: function()
	{
		return "MapInfo.Styles.AreaStyle\n" +
			this.interior.toString() + "\n" +
			this.border.toString() + "\n";
	}
});

////////////////////////////////////////////////////////////////////////////////////////////

Styles.InteriorStyle = Class.inherit(Styles.Style, 
{
	initialize: function(backColor, foreColor, pattern)
	{
		this.backColor = Drawing.Colors.Red;
		this.foreColor = Drawing.Colors.Black;
		this.pattern = 0;
		this.transparent = false;
		
		if (backColor) this.backColor = backColor;
		if (foreColor) this.foreColor = foreColor;
		if (pattern) this.pattern = pattern;
	},
	
	toString: function()
	{
		return "MapInfo.Styles.SimpleInterior\n" +
			"Pattern: " + this.pattern + "\n" +
			"ForeColor: " + this.foreColor.toArgb() + "\n" +
			"BackColor: " + this.backColor.toArgb() + "\n" +
			"Transparent: " + this.transparent + "\n";
	}
});

////////////////////////////////////////////////////////////////////////////////////////////

Styles.LineStyle = Class.inherit(Styles.Style, 
{
	initialize: function(width, pattern, color)
	{
		this.interleaved = false;
		this.pattern = 0;
		this.width = new Styles.LineWidth();
		this.color = Drawing.Colors.Black;
		
		if (pattern) this.pattern = pattern;
		if (width) this.width = width;
		if (color) this.color = color;
	},
	
	toString: function()
	{
		return "MapInfo.Styles.SimpleLineStyle\n" +
			"Pattern: " + this.pattern + "\n" +
			"Color: " + this.color.toArgb() + "\n" +
			this.width.toString() + "\n" +
			"Interleaved: " + this.interleaved + "\n";
	}
});

////////////////////////////////////////////////////////////////////////////////////////////

Styles.PointStyle = Class.inherit(Styles.Style, 
{
	initialize: function(code, pointSize, color)
	{
		this.code = 35;
		this.color = Drawing.Colors.Red;
		this.pointSize = 14;
		
		if (code) this.code = code;
		if (color) this.color = color;
		if (pointSize) this.pointSize = pointSize;
	},
	
	toString: function()
	{
		return "MapInfo.Styles.SimpleVectorPointStyle\n" +
			"Code: " + this.code + "\n" +
			"Color: " + this.color.toArgb() + "\n" +
			"PointSize: " + this.pointSize + "\n";
	}
});

////////////////////////////////////////////////////////////////////////////////////////////

Styles.BitmapPointStyle = Class.inherit(Styles.PointStyle, 
{
	initialize: function(name, pointSize, color)
	{
		this.name = "";
		this.color = Drawing.Colors.Transparent;
		this.pointSize = 20;
		this.nativeSize = true;
		this.showWhiteBackground = false;
		
		if (name) this.name = name;
		if (color) this.color = color;
		if (pointSize) this.pointSize = pointSize;
	},
	
	_getStyle: function()
	{
		var value = Number(Styles.BitmapStyles.None.__value);
		
		if (this.color != Drawing.Colors.Transparent)
			value += Number(Styles.BitmapStyles.ApplyColor.__value);
		if (this.nativeSize)
			value += Number(Styles.BitmapStyles.NativeSize.__value);
		if (this.showWhiteBackground)
			value += Number(Styles.BitmapStyles.ShowWhiteBackground.__value);
		
		return value;
	},
	
	toString: function()
	{
		return "MapInfo.Styles.BitmapPointStyle\n" +
			"Name: " + this.name + "\n" +
			"Style: " + this._getStyle() + "\n" +
			"Color: " + this.color.toArgb() + "\n" +
			"PointSize: " + this.pointSize + "\n";
	}
});

////////////////////////////////////////////////////////////////////////////////////////////

Styles.FontPointStyle = Class.inherit(Styles.PointStyle, 
{
	initialize: function(font, code, pointSize, color)
	{
		this.font = new Styles.Font("Map Symbols");
		this.code = 35;
		this.angle = 0;
		this.color = Drawing.Colors.Red;
		this.pointSize = 14;
		
		if (font) this.font = font;
		if (code) this.code = code;
		if (color) this.color = color;
		if (pointSize) this.pointSize = pointSize;
	},
	
	toString: function()
	{
		return "MapInfo.Styles.FontPointStyle\n" +
			"Code: " + this.code + "\n" +
			"Angle: " + this.angle + " tenths of a degree\n" +
			"Color: " + this.color.toArgb() + "\n" +
			"PointSize: " + this.pointSize + "\n" +
			this.font.toString() + "\n";
	}
});

////////////////////////////////////////////////////////////////////////////////////////////

Styles.TextStyle = Class.inherit(Styles.Style, 
{
	initialize: function(font)
	{
		this.font = new Styles.Font();
		
		if (font) this.font = font;
	},
	
	toString: function()
	{
		return "MapInfo.Styles.TextStyle\n" +
			this.font.toString() + "\n";
	}
});




