picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.67k stars 333 forks source link

MAC: Problem with ImageTextCell in TreeGridView #45

Closed evgeny-k closed 12 years ago

evgeny-k commented 12 years ago

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Eto; using Eto.Forms; using Eto.Drawing; using System.Threading;

namespace etotest { class Program { [STAThread] static void Main(string[] args) { //var generator = Generator.GetGenerator("Eto.Platform.Wpf.Generator, Eto.Platform.Wpf"); var generator = Generator.GetGenerator("Eto.Platform.Mac.Generator, Eto.Platform.Mac"); var app = new TestApplication(generator); app.Run(args); } }

public class TestApplication : Application
{
    public TestApplication(Generator generator)
        : base(generator)
    {
        this.Name = "Test Application";
    }

    public override void OnInitialized(EventArgs e)
    {
        this.MainForm = new MainForm();
        HandleEvent(Application.TerminatingEvent);

        base.OnInitialized(e);

        // show the main form
        this.MainForm.Show();
    }
}

public class MyTreeGridItem : TreeGridItem
{ 
   public Icon MyImage  { get; set; }
   public String MyCaption { get; set; }
}

public class MainForm : Form
{
    int[] arr = new int[] { 5, 5 };
    TreeGridView tv;
    TreeGridItem it;
    Icon ic;

    void CreateItem(TreeGridItem aParent, string aBaseName, int aLevel)
    {
        var lName = "[" + aLevel + "]" + aBaseName;
        var lItem = new MyTreeGridItem { MyImage = ic, MyCaption = lName };
        //lItem.MyImage = ic;
        //lItem.MyCaption = lName;   
        lItem.Expanded = true;

        if (lName == "[1]Name1") { it = lItem; };
        aParent.Children.Add(lItem);
        if (aLevel < arr.Length)
            for (int i = 0; i < arr[aLevel]; i++)
                CreateItem(lItem, aBaseName + i.ToString(), aLevel + 1);
    }

    void CreateTree()
    {
        TreeGridItem lRoot = new TreeGridItem();
        CreateItem(lRoot, "Name", 0);

        Application.Instance.Invoke(delegate
        {
            tv.DataStore = lRoot;
        });
    }

    public MainForm()
    {
        ic = new Icon("black.ico");
        Size = new Size(900, 800);
        var lp = new Panel();
        this.AddDockedControl(lp, new Padding(5));
        var lPanelLayout = new TableLayout(lp, 1, 1);
        lPanelLayout.Padding = new Padding(0);

        tv = new TreeGridView();
        tv.Columns.Add(new GridColumn { DataCell = new ImageTextCell("MyImage", "MyCaption") });
        lPanelLayout.Add(tv, 0, 0, true, true);
        CreateTree();
    }
}

}

windows: http://screencast.com/t/J6joIgg613o macosx: http://screencast.com/t/2ZAvzEW6MX

cwensley commented 12 years ago

This will happen if the file is not found, it was setting the image width/height to zero which then threw an exception when calculating sizes on the cell. The Mac platform will now throw an exception when the file is not found when creating the icon or bitmap. Also, there are now checks so that the image will just not be shown if the image width or height is zero.