context: /* ====================================================================
      Copyright (C) 2004-2006  fyiReporting Software, LLC
  
      This file is part of the fyiReporting RDL project.
  	
      The RDL project is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      (at your option) any later version.
  
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.
  
      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  
      For additional information, email info@fyireporting.com or visit
      the website www.fyiReporting.com.
  */
  using System;
  using System.Collections;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Drawing;
  using System.Data;
  using System.Windows.Forms;
  using System.Xml;
  using System.Globalization;
  
  namespace fyiReporting.RdlDesign
  {
  	/// <summary>
  	/// Summary description for StyleCtl.
  	/// </summary>
  	internal class StyleTextCtl : System.Windows.Forms.UserControl, IProperty
  	{
          private List<XmlNode> _ReportItems;
  		private DesignXmlDraw _Draw;
  		private string _DataSetName;
  		private bool fHorzAlign, fFormat, fDirection, fWritingMode, fTextDecoration;
  		private bool fColor, fVerticalAlign, fFontStyle, fFontWeight, fFontSize, fFontFamily;
  		private bool fValue;
  		private System.Windows.Forms.Label label4;
  		private System.Windows.Forms.Label label5;
  		private System.Windows.Forms.Label label6;
  		private System.Windows.Forms.Label label7;
  		private System.Windows.Forms.Label label8;
  		private System.Windows.Forms.Label lFont;
  		private System.Windows.Forms.Button bFont;
  		private System.Windows.Forms.ComboBox cbHorzAlign;
  		private System.Windows.Forms.ComboBox cbFormat;
  		private System.Windows.Forms.ComboBox cbDirection;
  		private System.Windows.Forms.ComboBox cbWritingMode;
  		private System.Windows.Forms.Label label2;
  		private System.Windows.Forms.ComboBox cbTextDecoration;
  		private System.Windows.Forms.Button bColor;
  		private System.Windows.Forms.Label label9;
  		private System.Windows.Forms.ComboBox cbColor;
  		private System.Windows.Forms.ComboBox cbVerticalAlign;
  		private System.Windows.Forms.Label label3;
  		private System.Windows.Forms.ComboBox cbFontStyle;
  		private System.Windows.Forms.ComboBox cbFontWeight;
  		private System.Windows.Forms.Label label10;
  		private System.Windows.Forms.ComboBox cbFontSize;
  		private System.Windows.Forms.Label label11;
  		private System.Windows.Forms.ComboBox cbFontFamily;
  		private System.Windows.Forms.GroupBox groupBox1;
  		private System.Windows.Forms.Label lblValue;
  		private System.Windows.Forms.ComboBox cbValue;
  		private System.Windows.Forms.Button bValueExpr;
  		private System.Windows.Forms.Button bFamily;
  		private System.Windows.Forms.Button bStyle;
  		private System.Windows.Forms.Button bColorEx;
  		private System.Windows.Forms.Button bSize;
  		private System.Windows.Forms.Button bWeight;
  		private System.Windows.Forms.Button button2;
  		private System.Windows.Forms.Button bAlignment;
  		private System.Windows.Forms.Button bDirection;
  		private System.Windows.Forms.Button bVertical;
  		private System.Windows.Forms.Button bWrtMode;
  		private System.Windows.Forms.Button bFormat;
  		/// <summary> 
  		/// Required designer variable.
  		/// </summary>
  		private System.ComponentModel.Container components = null;
  
          internal StyleTextCtl(DesignXmlDraw dxDraw, List<XmlNode> styles)
  		{
  			_ReportItems = styles;
  			_Draw = dxDraw;
  			// This call is required by the Windows.Forms Form Designer.
  			InitializeComponent();
  
  			// Initialize form using the style node values
  			InitTextStyles();
  		}
  
  		private void InitTextStyles()
  		{
              cbColor.Items.AddRange(StaticLists.ColorList);
  
  			XmlNode sNode = _ReportItems[0];
  			if (_ReportItems.Count > 1)
  			{
  				cbValue.Text = "Group Selected";
  				cbValue.Enabled = false;
  				lblValue.Enabled = false;
  			}
  			else if (sNode.Name == "Textbox")
  			{
  				XmlNode vNode = _Draw.GetNamedChildNode(sNode, "Value");
  				if (vNode != null)
  					cbValue.Text = vNode.InnerText;
  				// now populate the combo box
  				// Find the dataregion that contains the Textbox (if any)
  				for (XmlNode pNode = sNode.ParentNode; pNode != null; pNode = pNode.ParentNode)
  				{
  					if (pNode.Name == "List" ||
  						pNode.Name == "Table" ||
  						pNode.Name == "Matrix" ||
  						pNode.Name == "Chart")
  					{
  						_DataSetName = _Draw.GetDataSetNameValue(pNode);
  						if (_DataSetName != null)	// found it
  						{
  							string[] f = _Draw.GetFields(_DataSetName, true);
  							cbValue.Items.AddRange(f);
  						}
  					}
  				}
  				// parameters
  				string[] ps = _Draw.GetReportParameters(true);
  				if (ps != null)
  					cbValue.Items.AddRange(ps);
  				// globals
  				cbValue.Items.AddRange(StaticLists.GlobalList);
  			}
  			else if (sNode.Name == "Title")
  			{
  				lblValue.Text = "Caption";		// Note: label needs to equal the element name
  				XmlNode vNode = _Draw.GetNamedChildNode(sNode, "Caption");
  				if (vNode != null)
  					cbValue.Text = vNode.InnerText;
  			}
  			else
  			{
  				lblValue.Visible = false;
  				cbValue.Visible = false;
  			}
  
  			sNode = _Draw.GetNamedChildNode(sNode, "Style");
  
  			string sFontStyle="Normal";
  			string sFontFamily="Arial";
  			string sFontWeight="Normal";
  			string sFontSize="10pt";
  			string sTextDecoration="None";
  			string sHorzAlign="General";
  			string sVerticalAlign="Top";
  			string sColor="Black";
  			string sFormat="";
  			string sDirection="LTR";
  			string sWritingMode="lr-tb";
  			foreach (XmlNode lNode in sNode)
  			{
  				if (lNode.NodeType != XmlNodeType.Element)
  					continue;
  				switch (lNode.Name)
  				{
  					case "FontStyle":
  						sFontStyle = lNode.InnerText;
  						break;
  					case "FontFamily":
  						sFontFamily = lNode.InnerText;
  						break;
  					case "FontWeight":
  						sFontWeight = lNode.InnerText;
  						break;
  					case "FontSize":
  						sFontSize = lNode.InnerText;
  						break;
  					case "TextDecoration":
  						sTextDecoration = lNode.InnerText;
  						break;
  					case "TextAlign":
  						sHorzAlign = lNode.InnerText;
  						break;
  					case "VerticalAlign":
  						sVerticalAlign = lNode.InnerText;
  						break;
  					case "Color":
  						sColor = lNode.InnerText;
  						break;
  					case "Format":
  						sFormat = lNode.InnerText;
  						break;
  					case "Direction":
  						sDirection = lNode.InnerText;
  						break;
  					case "WritingMode":
  						sWritingMode = lNode.InnerText;
  						break;
  				}
  			}
  
  			// Population Font Family dropdown
  			foreach (FontFamily ff in FontFamily.Families)
  			{
  				cbFontFamily.Items.Add(ff.Name);
  			}
  
  			this.cbFontStyle.Text = sFontStyle;
  			this.cbFontFamily.Text = sFontFamily;
  			this.cbFontWeight.Text = sFontWeight;
  			this.cbFontSize.Text = sFontSize;
  			this.cbTextDecoration.Text = sTextDecoration;
  			this.cbHorzAlign.Text = sHorzAlign;
  			this.cbVerticalAlign.Text = sVerticalAlign;
  			this.cbColor.Text = sColor;
  			this.cbFormat.Text = sFormat;
  			this.cbDirection.Text = sDirection;
  			this.cbWritingMode.Text = sWritingMode;
  
  			fHorzAlign = fFormat = fDirection = fWritingMode = fTextDecoration =
  				fColor = fVerticalAlign = fFontStyle = fFontWeight = fFontSize = fFontFamily =
  				fValue = false;
  
  			return;
  		}
  
  		/// <summary> 
  		/// Clean up any resources being used.
  		/// </summary>
  		protected override void Dispose( bool disposing )
  		{
  			if( disposing )
  			{
  				if(components != null)
  				{
  					components.Dispose();
  				}
  			}
  			base.Dispose( disposing );
  		}
  
  		#region Component Designer generated code
  		/// <summary> 
  		/// Required method for Designer support - do not modify 
  		/// the contents of this method with the code editor.
  		/// </summary>
  		private void InitializeComponent()
  		{
              this.label4 = new System.Windows.Forms.Label();
              this.label5 = new System.Windows.Forms.Label();
              this.label6 = new System.Windows.Forms.Label();
              this.label7 = new System.Windows.Forms.Label();
              this.label8 = new System.Windows.Forms.Label();
              this.lFont = new System.Windows.Forms.Label();
              this.bFont = new System.Windows.Forms.Button();
              this.cbVerticalAlign = new System.Windows.Forms.ComboBox();
              this.cbHorzAlign = new System.Windows.Forms.ComboBox();
              this.cbFormat = new System.Windows.Forms.ComboBox();
              this.cbDirection = new System.Windows.Forms.ComboBox();
              this.cbWritingMode = new System.Windows.Forms.ComboBox();
              this.label2 = new System.Windows.Forms.Label();
              this.cbTextDecoration = new System.Windows.Forms.ComboBox();
              this.bColor = new System.Windows.Forms.Button();
              this.label9 = new System.Windows.Forms.Label();
              this.cbColor = new System.Windows.Forms.ComboBox();
              this.label3 = new System.Windows.Forms.Label();
              this.cbFontStyle = new System.Windows.Forms.ComboBox();
              this.cbFontWeight = new System.Windows.Forms.ComboBox();
              this.label10 = new System.Windows.Forms.Label();
              this.cbFontSize = new System.Windows.Forms.ComboBox();
              this.label11 = new System.Windows.Forms.Label();
              this.cbFontFamily = new System.Windows.Forms.ComboBox();
              this.lblValue = new System.Windows.Forms.Label();
              this.groupBox1 = new System.Windows.Forms.GroupBox();
              this.button2 = new System.Windows.Forms.Button();
              this.bWeight = new System.Windows.Forms.Button();
              this.bSize = new System.Windows.Forms.Button();
              this.bColorEx = new System.Windows.Forms.Button();
              this.bStyle = new System.Windows.Forms.Button();
  
gt:             this.bFamily = new System.Windows.Forms.Button();