|
/*
Copyright (c) 2004, Marc Clifton
All rights reserved.
Usage restricted under the terms of the BSD License conditions:
http://opensource.org/licenses/bsd-license.php
*/
using System;
using System.Drawing;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
using System.Xml;
/*
This code needs to be refactored. Compare to ControlCollectionModel.
There's a bit too much redundancy here.
*/
namespace XmlGuiGenerator
{
/// <summary>
/// Manage the TabPageCollection data type.
/// </summary>
public class TabPageCollectionModel : PropertyModelBase
{
/// <summary>
/// Add a tab page to the control's TabPages collection.
/// </summary>
/// <param name="obj">The Control instance with a TabPages property.</param>
/// <param name="pi">The PropertyInfo instance.</param>
/// <param name="val">The tab page name, used as the form name to load the page's controls.</param>
/// <param name="target">Passed to the sub-form creation process.</param>
/// <returns>The TabPage instance.</returns>
public override object SetValue(object obj, PropertyInfo pi, string val, object target)
{
TabPage page=null;
bool inline=false;
try
{
// the parent is set to null, otherwise the page is automatically
// added to the page list (that's OK, but I like to do it more
// explicitly!)
XmlAttribute attr=currentNode.Attributes["Canvas"];
if (attr != null)
{
// the tab page is defined by a canvas!
page=(TabPage)generator.CreateForm(attr.InnerText, null, target, null);
}
else
{
// the tab page is inlined!
page=new TabPage();
generator.ProcessAttributes(page, currentNode.Attributes, target);
inline=true;
}
generator.ProcessCollections(page, currentNode, target);
// nothing fancy here. Since the TabPageCollection is only ever
// a member of TabControl, there is no reason to make this a
// generic setter.
((TabControl)obj).TabPages.Add(page);
if (inline)
{
// when inlined, still invoke the Load event method
generator.InvokeLoadEvent(currentNode, target, page);
}
}
catch(Exception e)
{
Trace.WriteLine("TabPageCollection: Setter failed for: "+pi.ToString()+" val="+val+" "+e.Message);
}
return page;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.