<Resource>
  <Folder name="GacGenConfig">
    <Folder name="Cpp">
      <Text name="SourceFolder">Source</Text>
      <Text name="Resource">..\..\UIRes\DataGrid.bin</Text>
      <Text name="NormalInclude">GacUI.h</Text>
      <Text name="ReflectionInclude">GacUIReflection.h</Text>
      <Text name="Name">Demo</Text>
    </Folder>
  </Folder>
  
  <Instance name="MainWindowResource">
    <Instance ref.CodeBehind="false" ref.Class="demo::MainWindow" xmlns:demo="demo::*">
      <ref.Ctor>
        <![CDATA[
          {
            var tempData : observe MyDataItem^[] = 
            {
              new MyDataItem^("涼宮 春日",     Female, Lime,  (cast DateTime "1988-08-08 00:00:00.000"),  "http://www.haruhi.tv/")
              new MyDataItem^("キョン",        Male,   Black, (cast DateTime "1988-08-08 00:00:00.000"),  "http://www.haruhi.tv/")
              new MyDataItem^("长门 有希",     Female, White, (cast DateTime "2000-08-06 00:00:00.000"),  "http://www.haruhi.tv/")
              new MyDataItem^("朝比奈 实玖瑠", Female, Red,   (cast DateTime "1987-08-30 00:00:00.000"),  "http://www.haruhi.tv/")
              new MyDataItem^("古泉 一树",     Male,   Blue,  (cast DateTime "1986-08-12 00:00:00.000"),  "http://www.haruhi.tv/")
            };

            var largeImage = cast (GuiImageData^) (ResolveResource("res", "Images/Large", true));
            var smallImage = cast (GuiImageData^) (ResolveResource("res", "Images/Small", true));
            for(item in tempData)
            {
              item.LargeImage = largeImage;
              item.SmallImage = smallImage;
            }
            dataGrid.ItemSource = tempData;
          }
        ]]>
      </ref.Ctor>
      <Window ref.Name="self" Text="DataGrid" ClientSize="x:640 y:480">
        <att.BoundsComposition-set PreferredMinSize="x:640 y:480"/>
        <Table AlignmentToParent="left:0 top:0 right:0 bottom:0" CellPadding="5">
          <att.Rows>
            <_>composeType:MinSize</_>
            <_>composeType:Percentage percentage:1.0</_>
          </att.Rows>
          <att.Columns>
            <_>composeType:Percentage percentage:1.0</_>
          </att.Columns>

          <Cell Site="row:0 column:0">
            <ComboBox ref.Name="comboView" Alt="V" SelectedIndex="6">
              <att.BoundsComposition-set PreferredMinSize="x:120"/>
              <att.ListControl>
                <TextList HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false">
                  <att.Items>
                    <TextItem Text="BigIcon"/>
                    <TextItem Text="SmallIcon"/>
                    <TextItem Text="List"/>
                    <TextItem Text="Tile"/>
                    <TextItem Text="Information"/>
                    <TextItem Text="Detail"/>
                    <TextItem Text="DataGrid"/>
                  </att.Items>
                </TextList>
              </att.ListControl>
              <ev.SelectedIndexChanged-eval>
                <![CDATA[
                  {
                    switch (comboView.SelectedIndex)
                    {
                    case 0:
                      {
                        dataGrid.View = BigIcon;
                      }
                    case 1:
                      {
                        dataGrid.View = SmallIcon;
                      }
                    case 2:
                      {
                        dataGrid.View = ListViewView::List;
                      }
                    case 3:
                      {
                        dataGrid.View = Tile;
                      }
                    case 4:
                      {
                        dataGrid.View = Information;
                      }
                    case 5:
                      {
                        dataGrid.View = Detail;
                      }
                    case 6:
                      {
                        dataGrid.SetViewToDefault();
                      }
                    }
                  }
                ]]>
              </ev.SelectedIndexChanged-eval>
            </ComboBox>
          </Cell>

          <Cell Site="row:1 column:0">
            <BindableDataGrid ref.Name="dataGrid" Alt="L" env.ItemType="demo::MyDataItem^" env.ItemName="itemToBind" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false">
              <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
              <att.LargeImageProperty>LargeImage</att.LargeImageProperty>
              <att.SmallImageProperty>SmallImage</att.SmallImageProperty>

              <att.Columns>
                <DataColumn Text="Name" Size="120">
                  <att.TextProperty>Name</att.TextProperty>
                  <att.ValueProperty>Name</att.ValueProperty>
                  <att.EditorFactory>demo:TextEditor</att.EditorFactory>
                  <att.Sorter>[Sys::Compare($1.Name, $2.Name)]</att.Sorter>
                </DataColumn>

                <DataColumn Text="Gender" Size="80">
                  <att.TextProperty>demo::ToString(itemToBind.Gender)</att.TextProperty>
                  <att.ValueProperty>Gender</att.ValueProperty>
                  <att.VisualizerFactory>demo:GenderVisualizer;CellBorderVisualizerTemplate</att.VisualizerFactory>
                  <att.EditorFactory>demo:GenderEditor</att.EditorFactory>
                  <att.Sorter>[Sys::Compare(cast UInt64 ($1.Gender), cast UInt64 ($2.Gender))]</att.Sorter>
                </DataColumn>

                <DataColumn Text="Category" Size="80">
                  <att.TextProperty>demo::ToString(itemToBind.Category)</att.TextProperty>
                  <att.ValueProperty>Category</att.ValueProperty>
                  <att.VisualizerFactory>demo:CategoryVisualizer;CellBorderVisualizerTemplate</att.VisualizerFactory>
                  <att.EditorFactory>demo:CategoryEditor</att.EditorFactory>
                  <att.Sorter>[Sys::Compare(cast UInt64 ($1.Category), cast UInt64 ($2.Category))]</att.Sorter>
                </DataColumn>

                <DataColumn Text="Birthday" Size="80">
                  <att.TextProperty>demo::ToString(itemToBind.Birthday)</att.TextProperty>
                  <att.ValueProperty>Birthday</att.ValueProperty>
                  <att.EditorFactory>demo:DateEditor</att.EditorFactory>
                  <att.Sorter>[Sys::Compare($1.Birthday, $2.Birthday)]</att.Sorter>
                  <att.Filter-eval>dateFilter.Filter</att.Filter-eval>
                  <att.Popup>
                    <ToolstripMenu>
                      <demo:DateFilter ref.Name="dateFilter">
                        <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
                      </demo:DateFilter>
                    </ToolstripMenu>
                  </att.Popup>
                </DataColumn>

                <DataColumn Text="Website" Size="160">
                  <att.TextProperty>Website</att.TextProperty>
                  <att.ValueProperty>Website</att.ValueProperty>
                  <att.VisualizerFactory>HyperlinkVisualizerTemplate;CellBorderVisualizerTemplate</att.VisualizerFactory>
                  <att.EditorFactory>demo:TextEditor</att.EditorFactory>
                  <att.Sorter>[Sys::Compare($1.Website, $2.Website)]</att.Sorter>
                </DataColumn>
              </att.Columns>

              <att.DataColumns>
                <_>0</_>
              </att.DataColumns>
            </BindableDataGrid>
          </Cell>
        </Table>
      </Window>
    </Instance>
  </Instance>

  <Folder name="DataGridComponents" content="Link">DataGridComponents.xml</Folder>
  <Folder name="Images">
    <Image name="Large" content="File">Large.png</Image>
    <Image name="Small" content="File">Small.png</Image>
    <Image name="Male" content="File">Male.png</Image>
    <Image name="Female" content="File">Female.png</Image>
  </Folder>

  <Script name="ViewModelResource">
    <Workflow>
      <![CDATA[
        module viewmodel;
        
        using system::*;
        using presentation::*;
        
        namespace demo
        {          
          enum MyCategory
          {
            Black = 0,
            Red = 1,
            Lime = 2,
            Blue = 3,
            White = 4,
          }
          
          enum MyGender
          {
            Male = 0,
            Female = 1,
          }
          
          class MyDataItem
          {
            prop Name : string = "" {not observe}
            prop Gender : MyGender = Male {not observe}
            prop Category : MyCategory = White {not observe}
            prop Birthday : DateTime = (cast DateTime "2000-01-01 00:00:00.000") {not observe}
            prop Website : string = "" {not observe}
            prop LargeImage : GuiImageData^ = null {not observe}
            prop SmallImage : GuiImageData^ = null {not observe}
            
            new()
            {
            }
            
            new(name : string, gender : MyGender, category : MyCategory, birthday : DateTime, website : string)
            {
              Name = name;
              Gender = gender;
              Category = category;
              Birthday = birthday;
              Website = website;
            }
          }
          
          func ToString(value : MyCategory) : string
          {
            switch (value)
            {
              case Black:   { return "Black";  }
              case Red:     { return "Red";    }
              case Lime:    { return "Lime";   }
              case Blue:    { return "Blue";   }
              case White:   { return "White";  }
            }
            return "";
          }
          
          func ToColor(value : MyCategory) : Color
          {
            switch (value)
            {
              case Red:     { return cast Color "#FF0000"; }
              case Lime:    { return cast Color "#00FF00"; }
              case Blue:    { return cast Color "#0000FF"; }
              case White:   { return cast Color "#FFFFFF"; }
            }
            return cast Color "#000000";
          }
          
          func ToString(value : MyGender) : string
          {
            switch (value)
            {
              case Male:    { return "Male";   }
              case Female:  { return "Female"; }
            }
            return "";
          }
          
          func ToString(value : DateTime) : string
          {
            return $"$(value.month)/$(value.day)/$(value.year)";
          }
        }
      ]]>
    </Workflow>
  </Script>
</Resource>