<?xml version="1.0" encoding="utf-8"?>
<Resource>
  <Folder name="GacGenConfig">
    <Xml name="Metadata">
      <ResourceMetadata Name="DataGridBase" Version="1.0"/>
    </Xml>
    <Folder name="ResX86">
      <Text name="Resource">..\..\UIRes\32bits\control_datagrid_base.bin</Text>
    </Folder>
    <Folder name="ResX64">
      <Text name="Resource">..\..\UIRes\64bits\control_datagrid_base.bin</Text>
    </Folder>
  </Folder>
  <Image content="File">Book16.png</Image>
  <Image content="File">Book32.png</Image>
  <Image content="File">Open16.png</Image>
  <Image content="File">Open32.png</Image>
  <Folder name="MainWindow">
    <Script name="ViewModel">
      <Workflow><![CDATA[
        module viewmodel;
        using system::*;
        using presentation::*;

        namespace sample
        {
          class BookItem
          {
            prop Title : string = Sys::LoremIpsumTitle(24) {}
            prop Author : string = Sys::LoremIpsumTitle(16) {}
            prop DatePublished : DateTime = {} {}
            prop Summary : string = Sys::LoremIpsumTitle(64) {}
            prop Content : string = Sys::LoremIpsumTitle(512) {not observe}
            prop SmallImage : GuiImageData^ = null {not observe}
            prop LargeImage : GuiImageData^ = null {not observe}
          }
        }
      ]]></Workflow>
    </Script>
    <Instance name="MainWindowResource">
      <Instance ref.Class="sample::DataGridWindowBase">
        <ref.Members><![CDATA[
          @cpp:Private
          var books: observe BookItem^[] = {};
          @cpp:Private
          var lastSelectedCell: GridPos = {row:-1 column:-1};

          @cpp:Private
          var iconBook16: ImageData^ = null;
          @cpp:Private
          var iconBook32: ImageData^ = null;
          @cpp:Private
          var iconOpen16: ImageData^ = null;
          @cpp:Private
          var iconOpen32: ImageData^ = null;

          prop DataGrid : BindableDataGrid* = null {const, not observe}
          prop TitleColumn : DataColumn^ = null {const, not observe}
          prop AuthorColumn : DataColumn^ = null {const, not observe}
          prop DatePublishedColumn : DataColumn^ = null {const, not observe}
          prop SummaryColumn : DataColumn^ = null {const, not observe}

          func FormatDate(date: DateTime): string
          {
            var locale = Application::GetApplication().Locale;
            var formats = Localization::GetLongDateFormats(locale).CreateEnumerator();
            formats.Next(); 
            var format = cast string formats.Current;
            return Localization::FormatDate(locale, format, date);
          }
        ]]></ref.Members>
        <ref.Ctor><![CDATA[
          {
            self.iconBook16 = cast (ImageData^) self.ResolveResource("res", "Book16.png", true);
            self.iconBook32 = cast (ImageData^) self.ResolveResource("res", "Book32.png", true);
            self.iconOpen16 = cast (ImageData^) self.ResolveResource("res", "Open16.png", true);
            self.iconOpen32 = cast (ImageData^) self.ResolveResource("res", "Open32.png", true);

            for (i in range [0, 24))
            {
              var book = new BookItem^();
              book.DatePublished = Sys::CreateDateTime(2010 + i / 3, 1 + i / 2, 1 + i);
              book.SmallImage = self.iconBook16;
              book.LargeImage = self.iconBook32;
              self.books.Add(book);
            }

            SetDataGrid(datagrid);
            SetTitleColumn(columnTitle);
            SetAuthorColumn(columnAuthor);
            SetDatePublishedColumn(columnDatePublished);
            SetSummaryColumn(columnSummary);
          }
        ]]></ref.Ctor>
        <Window ref.Name="self" ClientSize="x:800 y:600">
          <Table AlignmentToParent="left:0 top:0 right:0 bottom:0" CellPadding="5" BorderVisible="false" MinSizeLimitation="LimitToElementAndChildren">
            <att.Rows>
              <CellOption>composeType:MinSize</CellOption>
              <CellOption>composeType:MinSize</CellOption>
              <CellOption>composeType:MinSize</CellOption>
              <CellOption>composeType:MinSize</CellOption>
              <CellOption>composeType:Percentage percentage:1.0</CellOption>
            </att.Rows>
            <att.Columns>
              <CellOption>composeType:Absolute absolute:540</CellOption>
              <CellOption>composeType:MinSize</CellOption>
              <CellOption>composeType:Percentage percentage:1.0</CellOption>
            </att.Columns>

            <ColumnSplitter ColumnsToTheLeft ="1"/>

            <Cell Site="row:0 column:0 rowSpan:5">
              <BindableDataGrid ref.Name="datagrid" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false" env.ItemType="sample::BookItem^" env.ItemName="item">
                <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
                <att.ItemSource-eval>self.books</att.ItemSource-eval>
                <att.LargeImageProperty>SmallImage</att.LargeImageProperty>
                <att.SmallImageProperty>LargeImage</att.SmallImageProperty>
                <att.Columns>
                  <DataColumn ref.Name="columnTitle" Text="Title" TextProperty="Title" ValueProperty="Title"/>
                  <DataColumn ref.Name="columnAuthor" Text="Author" TextProperty="Author" ValueProperty="Author"/>
                  <DataColumn ref.Name="columnDatePublished" Text="Date Published" TextProperty="self.FormatDate(item.DatePublished)" ValueProperty="DatePublished"/>
                  <DataColumn ref.Name="columnSummary" Text="Summary" TextProperty="Summary" ValueProperty="Summary"/>
                </att.Columns>
                <att.DataColumns>
                  <_>0</_>
                  <_>1</_>
                </att.DataColumns>

                <ev.SelectedCellChanged-eval><![CDATA[
                  {
                    var last = self.lastSelectedCell;
                    var current = datagrid.SelectedCell;
                    if (last.row != current.row)
                    {
                      self.lastSelectedCell = current;

                      Application::GetApplication().InvokeInMainThread(self, func():void
                      {
                        if (last.row != -1)
                        {
                          self.books[last.row].SmallImage = self.iconBook16;
                          self.books[last.row].LargeImage = self.iconBook32;
                          self.books.ItemChanged(last.row, 1, 1);
                        }
                        if (current.row != -1)
                        {
                          self.books[current.row].SmallImage = self.iconOpen16;
                          self.books[current.row].LargeImage = self.iconOpen32;
                          self.books.ItemChanged(current.row, 1, 1);
                        }
                        self.datagrid.SelectCell(current, false);
                      });
                    }
                  }
                ]]></ev.SelectedCellChanged-eval>
              </BindableDataGrid>
            </Cell>

            <Cell Site="row:0 column:1">
              <Label Text-eval="columnTitle.Text"/>
            </Cell>
            <Cell Site="row:1 column:1">
              <Label Text-eval="columnAuthor.Text"/>
            </Cell>
            <Cell Site="row:2 column:1">
              <Label Text-eval="columnDatePublished.Text"/>
            </Cell>
            <Cell Site="row:3 column:1">
              <Label Text-eval="columnSummary.Text"/>
            </Cell>

            <Cell Site="row:0 column:2">
              <DocumentTextBox EditMode="Selectable" Text-bind="(cast (BookItem^) datagrid.SelectedRowValue).Title ?? ''">
                <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
              </DocumentTextBox>
            </Cell>
            <Cell Site="row:1 column:2">
              <DocumentTextBox EditMode="Selectable" Text-bind="(cast (BookItem^) datagrid.SelectedRowValue).Author ?? ''">
                <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
              </DocumentTextBox>
            </Cell>
            <Cell Site="row:2 column:2">
              <DocumentTextBox EditMode="Selectable" Text-bind="self.FormatDate((cast (BookItem^) datagrid.SelectedRowValue).DatePublished) ?? ''">
                <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
              </DocumentTextBox>
            </Cell>
            <Cell Site="row:3 column:2">
              <DocumentTextBox EditMode="Selectable" Text-bind="(cast (BookItem^) datagrid.SelectedRowValue).Summary ?? ''">
                <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
              </DocumentTextBox>
            </Cell>
            <Cell Site="row:4 column:1 columnSpan:2">
              <DocumentViewer EditMode="Selectable" HorizontalAlwaysVisible="false" VerticalAlwaysVisible="false" Text-bind="(cast (BookItem^) datagrid.SelectedRowValue).Content ?? ''">
                <att.BoundsComposition-set AlignmentToParent="left:0 top:0 right:0 bottom:0"/>
              </DocumentViewer>
            </Cell>
          </Table>
        </Window>
      </Instance>
    </Instance>
  </Folder>
</Resource>