#region Disclaimer / License
// Copyright (C) 2009, Kenneth Skovhede
// http://www.hexad.dk, opensource@hexad.dk
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace OSGeo.MapGuide.Maestro.ResourceEditors.LayoutControls
{
///
/// Summary description for PrintCommand.
///
public class PrintCommand : System.Windows.Forms.UserControl
{
private System.Windows.Forms.ListBox Layouts;
private System.Windows.Forms.ImageList imageList;
private System.Windows.Forms.Label label1;
private System.ComponentModel.IContainer components;
private OSGeo.MapGuide.MaestroAPI.PrintCommandType m_command;
private OSGeo.MapGuide.MaestroAPI.WebLayout m_layout;
private EditorInterface m_editor;
private bool m_isUpdating = false;
private ToolStrip toolStrip;
private ToolStripButton AddPrintLayout;
private ToolStripButton RemovePrintLayout;
private LayoutEditor m_layoutEditor = null;
public PrintCommand()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
}
public void SetItem(OSGeo.MapGuide.MaestroAPI.PrintCommandType command, OSGeo.MapGuide.MaestroAPI.WebLayout layout, EditorInterface editor, LayoutEditor layoutEditor)
{
m_command = command;
m_layout = layout;
m_layoutEditor = layoutEditor;
m_editor = editor;
UpdateDisplay();
}
public void UpdateDisplay()
{
try
{
m_isUpdating = true;
if (m_command == null)
return;
}
finally
{
m_isUpdating = false;
}
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PrintCommand));
this.Layouts = new System.Windows.Forms.ListBox();
this.imageList = new System.Windows.Forms.ImageList(this.components);
this.label1 = new System.Windows.Forms.Label();
this.toolStrip = new System.Windows.Forms.ToolStrip();
this.AddPrintLayout = new System.Windows.Forms.ToolStripButton();
this.RemovePrintLayout = new System.Windows.Forms.ToolStripButton();
this.toolStrip.SuspendLayout();
this.SuspendLayout();
//
// Layouts
//
resources.ApplyResources(this.Layouts, "Layouts");
this.Layouts.Name = "Layouts";
this.Layouts.SelectedIndexChanged += new System.EventHandler(this.Layouts_SelectedIndexChanged);
//
// imageList
//
this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
this.imageList.TransparentColor = System.Drawing.Color.Transparent;
this.imageList.Images.SetKeyName(0, "");
this.imageList.Images.SetKeyName(1, "");
//
// label1
//
resources.ApplyResources(this.label1, "label1");
this.label1.Name = "label1";
//
// toolStrip
//
this.toolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.AddPrintLayout,
this.RemovePrintLayout});
resources.ApplyResources(this.toolStrip, "toolStrip");
this.toolStrip.Name = "toolStrip";
this.toolStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
//
// AddPrintLayout
//
this.AddPrintLayout.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
resources.ApplyResources(this.AddPrintLayout, "AddPrintLayout");
this.AddPrintLayout.Name = "AddPrintLayout";
this.AddPrintLayout.Click += new System.EventHandler(this.AddPrintLayout_Click);
//
// RemovePrintLayout
//
this.RemovePrintLayout.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
resources.ApplyResources(this.RemovePrintLayout, "RemovePrintLayout");
this.RemovePrintLayout.Name = "RemovePrintLayout";
this.RemovePrintLayout.Click += new System.EventHandler(this.RemovePrintLayout_Click);
//
// PrintCommand
//
resources.ApplyResources(this, "$this");
this.Controls.Add(this.Layouts);
this.Controls.Add(this.toolStrip);
this.Controls.Add(this.label1);
this.Name = "PrintCommand";
this.toolStrip.ResumeLayout(false);
this.toolStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private void Layouts_SelectedIndexChanged(object sender, System.EventArgs e)
{
RemovePrintLayout.Enabled = Layouts.SelectedItems.Count == 1;
}
private void AddPrintLayout_Click(object sender, EventArgs e)
{
string resource = m_editor.BrowseResource("PrintLayout");
if (resource != null)
{
if (m_command.PrintLayout == null)
m_command.PrintLayout = new OSGeo.MapGuide.MaestroAPI.ResourceReferenceTypeCollection();
bool existing = false;
foreach (OSGeo.MapGuide.MaestroAPI.ResourceReferenceType rf in m_command.PrintLayout)
if (rf.ResourceId == resource)
{
existing = true;
break;
}
if (!existing)
{
OSGeo.MapGuide.MaestroAPI.ResourceReferenceType rf = new OSGeo.MapGuide.MaestroAPI.ResourceReferenceType();
rf.ResourceId = resource;
m_command.PrintLayout.Add(rf);
Layouts.Items.Add(resource);
}
}
}
private void RemovePrintLayout_Click(object sender, EventArgs e)
{
if (Layouts.SelectedItems.Count == 1)
{
for (int i = 0; i < m_command.PrintLayout.Count; i++)
if (m_command.PrintLayout[i].ResourceId == (string)Layouts.SelectedItems[0])
{
m_command.PrintLayout.RemoveAt(i);
break;
}
Layouts.Items.Remove(Layouts.SelectedItems[0]);
}
}
}
}