/// ****************************************************************************
/// @file   
/// @author Dr.Neeton
/// @date   200X/X/X - 2016/11/28
/// 
/// @brief  ツリービューコントロール
/// 
/// ****************************************************************************

#pragma once

#include "CPL_WIN_Scrollbar.h"
#include "CPL_WIN_Label.h"
#include "../../GObj/CPL_WIN_Graphics.h"
#include "../../GObj/CPL_WIN_DIBitmap.h"
#include "../Frame/CPL_WIN_Window.h"


namespace CPL {
namespace WIN {



class TreeView;

// _____________________________________________________________________________
/// @brief ツリービューアイテムクラス
///
// *****************************************************************************
class TreeViewItem
  : public Core::BaseObject
  , public Core::List::TreeElement
    < TreeViewItem
    , Core::List::DoublyElement<TreeViewItem>
    >
{
  using td_self_ptr  = ptr<TreeViewItem>;
  using td_self_cptr = cptr<TreeViewItem>;
  td_self_cptr getThisConst() const { return static_cast<td_self_cptr>(this); }
protected:
  friend class Core::List::DoublyElement<TreeViewItem>;
  friend class Core::List::TreeElement<TreeViewItem, Core::List::DoublyElement<TreeViewItem> >;
  friend class TreeViewItem;
  friend class TreeView;

//  typedef struct TBI_ListTable : public List::SinglyElement<_TBIList>{
//    TreeViewItem* m_pItem;
//  };

  static LRESULT CALLBACK
    zzf_StaticProcTVI
      ( HWND   in_hdl_window
      , UINT   in_message
      , WPARAM in_wparam
      , LPARAM in_lparam
      );
  CPL_SINGLETON(std::list<TreeViewItem*>, sm_ListTVI) // 全てのアイテムのポインタリストを保存するためのリスト


  TreeView*  m_ptr_tree_view;
  Component* m_ptr_comp;
  void_cptr  m_ptr_data;
  U32        m_flag_expand;   // 子供が展開されているかどうか
  LRESULT    (CALLBACK *zzf_PROC_COMP)
              ( HWND   in_hdl_windown
              , UINT   in_message
              , WPARAM in_wparam
              , LPARAM in_lparam
              );

public:
  cptr<TreeViewItem> FindTreeViewItem( pin<Component> in_ptr_comp ) const;
  ptr<TreeViewItem>  FindTreeViewItem( pin<Component> in_ptr_comp )
  {
    return const_cast<td_self_ptr>(getThisConst()->FindTreeViewItem(in_ptr_comp));
  }
  cptr<TreeViewItem> FindTreeViewItem( pin<void> in_ptr_data_for_TVI ) const;
  ptr<TreeViewItem>  FindTreeViewItem( pin<void> in_ptr_data_for_TVI )
  {
    return const_cast<td_self_ptr>(getThisConst()->FindTreeViewItem(in_ptr_data_for_TVI));
  }

  ptr<Component>  GetComponent()       { return m_ptr_comp; }
  cptr<Component> GetComponent() const { return m_ptr_comp; }
  U32             GetExpand() const { return m_flag_expand; }
  void            SetExpand( _in<U32> expand );
  void            SetData( void_cptr in_ptr_data_for_TVI ){ m_ptr_data = in_ptr_data_for_TVI; }
  template<class T_Type>
  T_Type          GetData() const { return static_cast<T_Type>(m_ptr_data); }

  TreeViewItem
    ( pio<Component> in_ptr_comp
    , pio<TreeView > in_ptr_tree_view_parent
    , pin<void     > in_ptr_data_for_TVI
    );
  virtual ~TreeViewItem();
};


// _____________________________________________________________________________
/// @brief ツリービューアイテム拡張
///
// *****************************************************************************
template<class T_Type>
class TreeViewItemEx
  : public TreeViewItem
{
protected:
  U32  m_flag_delete;

public:
  cptr<TreeViewItem> FindTreeViewItem( pin<T_Type> in_ptr_data_for_TVI ) const
  {
    return FindTreeViewItem( (void_cptr)in_ptr_data_for_TVI );
  }
  void  SetData( T_Type* in_ptr_data_for_TVI )
  {
    TreeViewItem::SetData(in_ptr_data_for_TVI);
  }
  cptr<T_Type> GetData() const
  {
    return TreeViewItem::GetData<cptr<T_Type>>();
  }
  ptr<T_Type> GetData()
  {
    return TreeViewItem::GetData<ptr<T_Type>>();
  }

  TreeViewItemEx
  ( Component* in_ptr_comp,
    TreeView*  in_ptr_tree_view,
    T_Type*    in_ptr_data_for_TVI,
    bool       in_flag_delete )
    : TreeViewItem( in_ptr_comp, in_ptr_tree_view, in_ptr_data_for_TVI )
    , m_flag_delete( in_flag_delete )
  {}
  virtual ~TreeViewItemEx()
  {
    if( m_flag_delete )
    {
      delete (T_Type*)m_ptr_data;
    }
  }
};



// _____________________________________________________________________________
/// @brief ツリービューコントロールクラス
///
// *****************************************************************************
class TreeView
  : public Window
{
private:
  class ItemForm
    : public Container
  {
    SDEF DefaultProc_( _in<UINT> in_message, _in<WPARAM> in_wparam, _in<LPARAM> in_lparam )
    {
      switch( in_message )
      {
      case WM_LBUTTONDOWN:
      case WM_RBUTTONDOWN:
      case WM_MBUTTONDOWN:
      case WM_MOUSEMOVE:
      case WM_MOUSEWHEEL:
        SendParentMessage( in_message, in_wparam, in_lparam );
        break;
      default:
        return Container::DefaultProc_( in_message, in_wparam, in_lparam );
      }
      return 0;
    }
  public:
    ItemForm( _in<HWND> in_hdl_win_parent, _in<td_Coord2> in_size )
      : WIN::Container( in_hdl_win_parent, td_Coord2(0,0), in_size )
    {}
  };

protected:
  friend class TreeViewItem;
//  TCHAR* zzf_GetClassName(){ return WC_TREEVIEW; }

//  static DIBitmap& sm_bitmap(){ static DIBitmap bmp; return bmp; }
  CPL_SINGLETON_INIT( DIBitmap, sm_bitmap, expandImage )

  TreeViewItem*    m_ptr_root;
  TreeViewItem*    m_ptr_select;      // 選択中のアイテム
  TreeViewItem*    m_ptr_moving_item; // D&D先のアイテム
  sdptr<ItemForm>  m_sp_form;         // アイテムを配置するフォーム（スクロールバーと重なるので…）
  sdptr<ScrollBar> m_sp_scroll_h;
  sdptr<ScrollBar> m_sp_scroll_v;
  BOOL             m_flag_scroll_show;

  virtual void SetupViewComponent();
  virtual td_Coord2
            SetupViewComponentItem
              ( pio<TreeViewItem> in_ptr_item_node
              , _in<long> in_left
              , _in<long> in_top
              , _in<BOOL> in_flag_view
              );
  virtual SDEF On_Paint() override;
  virtual SDEF On_Size( _in<eSizeMode> in_size_mode ) override;
  virtual SDEF On_MouseDown( _in<eMouseButton> in_mouse_btn ) override;
  virtual SDEF On_MouseUp  ( _in<eMouseButton> in_mouse_btn ) override;
  virtual SDEF On_MouseMove() override;
  virtual SDEF On_MouseWheel( _in<WORD> in_fw_keys, _in<short> in_z_delta ) override;
  virtual SDEF On_Scroll( pio<ScrollBar> in_ptr_scroll, _in<int> in_scroll_flag ) override;

  virtual SDEF On_ItemDrop  ( pio<TreeViewItem> in_ptr_up_item, _in<int> in_flag ){ return true; }
  virtual SDEF On_ItemSelect( pio<TreeViewItem> in_ptr_item );
  virtual SDEF On_ItemExpand( pio<TreeViewItem> in_ptr_item ){ return true; }

public:
  virtual TreeViewItem*       GetRootItem  ()       { return m_ptr_root; }
  virtual TreeViewItem const* GetRootItem  () const { return m_ptr_root; }
  virtual TreeViewItem*       GetSelectItem()       { return m_ptr_select; }
  virtual TreeViewItem const* GetSelectItem() const { return m_ptr_select; }

  template<class T>
  TreeViewItemEx<T>* GetRootItemEx(){
    return dynamic_cast<TreeViewItemEx<T>*>(m_ptr_root); }
  template<class T>
  TreeViewItemEx<T> const* GetRootItemEx() const {
    return dynamic_cast<TreeViewItemEx<T> const*>(m_ptr_root); }

  template<class T>
  TreeViewItemEx<T>* GetSelectItemEx(){
    return dynamic_cast<TreeViewItemEx<T>*>(m_ptr_select); }
  template<class T>
  TreeViewItemEx<T> const* GetSelectItemEx() const{
    return dynamic_cast<TreeViewItemEx<T> const*>(m_ptr_select); }

  virtual int  GetItemNum() const { return m_ptr_root->GetNodeNum(); }
  virtual void SetSelectItem( pin<TreeViewItem> in_ptr_item );
  virtual void SetSelectItem( pio<Component   > in_ptr_comp );
  virtual void SetSelectItem( pin<void        > in_ptr_data_for_TVI );

  virtual TreeViewItem*
    AddItemChild
      ( pio<TreeViewItem> in_ptr_TVI_parent
      , pio<TreeViewItem> in_ptr_TVI_add
      , _in<int         > in_index = -1
      );
  virtual TreeViewItem*
    AddItemChild
      ( pio<TreeViewItem> in_ptr_TVI_parent
      , pio<Component   > in_ptr_comp_for_TVI
      , pin<void        > in_ptr_data_for_TVI = nullptr
      , _in<int         > in_index    = -1
      );
  virtual TreeViewItem*
    AddItemChild
      ( pio<TreeViewItem> in_ptr_TVI_parent
      , pin<str_type    > in_string_for_TVI
      , pin<void        > in_ptr_data_for_TVI = nullptr
      , _in<int         > in_index    = -1
      );
  virtual TreeViewItem*
    AddItemPrev
      ( pio<TreeViewItem> in_ptr_TVI_base
      , pio<TreeViewItem> in_ptr_TVI_add
      );
  virtual TreeViewItem*
    AddItemPrev
      ( pio<TreeViewItem> in_ptr_TVI_base
      , pio<Component   > in_ptr_comp_for_TVI
      , pin<void        > in_ptr_data_for_TVI = nullptr
      );
  virtual TreeViewItem*
    AddItemPrev
      ( pio<TreeViewItem> in_ptr_TVI_base
      , pin<str_type    > in_string_for_TVI
      , pin<void        > in_ptr_data_for_TVI = nullptr
      );
  virtual TreeViewItem*
    AddItemNext
      ( pio<TreeViewItem> in_ptr_TVI_base
      , pio<TreeViewItem> in_ptr_item
      );
  virtual TreeViewItem*
    AddItemNext
      ( pio<TreeViewItem> in_ptr_TVI_base
      , pio<Component   > in_ptr_comp_for_TVI
      , pin<void        > in_ptr_data_for_TVI = nullptr
      );
  virtual TreeViewItem*
    AddItemNext
      ( pio<TreeViewItem> in_ptr_TVI_base
      , pin<str_type    > in_string_for_TVI
      , pin<void        > in_ptr_data_for_TVI = nullptr
      );
  template<class T_Type> TreeViewItemEx<T_Type>*
    AddItemChildEx
      ( pio<TreeViewItem> in_ptr_TVI_parent
      , pio<Component   > in_ptr_comp_for_TVI
      , pin<T_Type      > in_ptr_data_for_TVI
      , _in<int         > in_index = -1
      , _in<bool        > in_flag_delete = true
      )
  {
    return
      dynamic_cast<TreeViewItemEx<T_Type>*>
      ( AddItemChild
          ( in_ptr_TVI_parent
          , CPL_NEW(TreeViewItemEx<T_Type>)( in_ptr_comp_for_TVI, this, in_ptr_data_for_TVI, in_flag_delete )
          , in_index
          )
      );
  }
  template<class T_Type> TreeViewItemEx<T_Type>*
    AddItemChildEx
      ( pio<TreeViewItem> in_ptr_TVI_parent
      , pin<str_type    > in_string_for_TVI
      , pin<T_Type      > in_ptr_data_for_TVI
      , _in<int         > in_index = -1
      , _in<bool        > in_flag_delete = true
      )
  {
    return AddItemChildEx<T_Type>
      ( in_ptr_TVI_parent
      , (Component*)CPL_NEW(Label)( GetWindowHandle(), in_string_for_TVI )
      , in_ptr_data_for_TVI
      , in_index
      , in_flag_delete
      );
  }
  template<class T_Type> TreeViewItemEx<T_Type>*
    AddItemPrevEx
      ( pio<TreeViewItem> in_ptr_TVI_base
      , pio<Component   > in_ptr_comp_for_TVI
      , pin<T_Type      > in_ptr_data_for_TVI
      , _in<bool        > in_flag_delete = true
      )
  {
    return dynamic_cast<TreeViewItemEx<T_Type>*>
      ( AddItemPrev
        ( in_ptr_TVI_base
        , CPL_NEW(TreeViewItemEx<T_Type>)( in_ptr_comp_for_TVI, this, in_ptr_data_for_TVI, in_flag_delete )
        )
      );
  }
  template<class T_Type> TreeViewItemEx<T_Type>*
    AddItemPrevEx
      ( pio<TreeViewItem> in_ptr_TVI_base
      , pin<str_type    > in_string_for_TVI
      , pin<T_Type      > in_ptr_data_for_TVI
      , _in<bool        > in_flag_delete = true
      )
  {
    return AddItemPrevEx
      ( in_ptr_TVI_base
      , (Component*)CPL_NEW(Label)( GetWindowHandle(), in_string_for_TVI )
      , in_ptr_data_for_TVI
      , in_flag_delete
      );
  }
  template<class T_Type> TreeViewItemEx<T_Type>*
    AddItemNextEx
      ( pio<TreeViewItem> in_ptr_TVI_base
      , pio<Component   > in_ptr_comp_for_TVI
      , pin<T_Type      > in_ptr_data_for_TVI
      , _in<bool        > in_flag_delete = true
      )
  {
    return dynamic_cast<TreeViewItemEx<T_Type>*>
    ( AddItemNext
      ( in_ptr_TVI_base
      , CPL_NEW(TreeViewItemEx<T_Type>)( in_ptr_comp_for_TVI, this, in_ptr_data_for_TVI, in_flag_delete )
      )
    );
  }
  template<class T_Type> TreeViewItemEx<T_Type>*
    AddItemNextEx
    ( pio<TreeViewItem> in_ptr_TVI_base
    , pin<str_type    > in_string_for_TVI
    , pin<T_Type      > in_ptr_data_for_TVI
    , _in<bool        > in_flag_delete = true
    )
  {
    return AddItemNextEx
      ( in_ptr_TVI_base
      , (Component*)CPL_NEW(Label)( GetWindowHandle(), in_string_for_TVI )
      , in_ptr_data_for_TVI
      , in_flag_delete
      );
  }

  virtual void
    MoveItemPrev
      ( pio<TreeViewItem> in_ptr_TVI_move
      , pio<TreeViewItem> in_ptr_TVI_base = nullptr
      );
  virtual void
    MoveItemNext
      ( pio<TreeViewItem> in_ptr_TVI_move
      , pio<TreeViewItem> in_ptr_TVI_base = nullptr
      );
  virtual void MoveItemParent( pio<TreeViewItem> in_ptr_TVI_move );
  virtual void
    MoveItemChild
      ( pio<TreeViewItem> in_ptr_TVI_move
      , pio<TreeViewItem> in_ptr_TVI_parent
      );
  virtual bool
    SwapItem
      ( pio<TreeViewItem> in_ptr_TVI0
      , pio<TreeViewItem> in_ptr_TVI1
      );
  virtual bool DeleteItem( pio<TreeViewItem> in_ptr_TVI_del );
  virtual void ReleaseItem();
  virtual TreeViewItem*
    FindTreeViewItem( pin<Component> in_ptr_comp )
  {
    return m_ptr_root->FindTreeViewItem( in_ptr_comp );
  }
  virtual TreeViewItem*
    FindTreeViewItem( pin<void> in_ptr_data_for_TVI )
  {
    return m_ptr_root->FindTreeViewItem( in_ptr_data_for_TVI );
  }
  virtual void
    SetScrollShow( _in<bool> in_ptr_show )
  {
    m_flag_scroll_show = in_ptr_show;
  }

  TreeView
  ( _in<HWND     > in_hdl_win_parent
  , _in<td_Coord2> in_pos  = kPOS_DEFAULT
  , _in<td_Coord2> in_size = kSIZE_DEFAULT
  , _in<int      > in_ID = -1
  , _in<LONG_PTR > in_win_style = WS_CHILD | WS_BORDER
  );
  virtual ~TreeView();

  
  // _____________________________________________________________________________
  /// @brief ツリービューコントロールクラス　Pimpl実装用
  ///
  // *****************************************************************************
  class Binder
    : public Window::Binder
  {
  private:
    TreeView*       getEntity()       { return dynamic_cast<TreeView*>(&*impl); }
    TreeView const* getEntity() const { return dynamic_cast<TreeView const*>(&*impl); }

  public:
    TreeViewItem*       GetRootItem  ()       { return getEntity()->GetRootItem(); }
    TreeViewItem const* GetRootItem  () const { return getEntity()->GetRootItem(); }
    TreeViewItem*       GetSelectItem()       { return getEntity()->GetSelectItem(); }
    TreeViewItem const* GetSelectItem() const { return getEntity()->GetSelectItem(); }

    template<class T> TreeViewItemEx<T>*       GetRootItemEx()       { return getEntity()->GetRootItemEx<T>(); }
    template<class T> TreeViewItemEx<T> const* GetRootItemEx() const { return getEntity()->GetRootItemEx<T>(); }

    template<class T> TreeViewItemEx<T>*       GetSelectItemEx()      { return getEntity()->GetSelectItemEx<T>(); }
    template<class T> TreeViewItemEx<T> const* GetSelectItemEx() const{ return getEntity()->GetSelectItemEx<T>(); }

    int           GetItemNum() const { return getEntity()->GetItemNum(); }

    void          SetSelectItem( pin<TreeViewItem> in_ptr_item ){ getEntity()->SetSelectItem( in_ptr_item ); }
    void          SetSelectItem( pio<Component   > in_ptr_comp ){ getEntity()->SetSelectItem( in_ptr_comp ); }
    void          SetSelectItem( pin<void        > in_ptr_data_for_TVI ){ getEntity()->SetSelectItem( in_ptr_data_for_TVI ); }

    TreeViewItem*
      AddItemChild
        ( pio<TreeViewItem> in_ptr_TVI_parent
        , pio<TreeViewItem> in_ptr_TVI_add
        , _in<int         > in_index = -1
        )
    {
      return getEntity()->AddItemChild( in_ptr_TVI_parent, in_ptr_TVI_add, in_index );
    }
    TreeViewItem*
      AddItemChild
        ( pio<TreeViewItem> in_ptr_TVI_parent
        , pio<Component   > in_ptr_comp_for_TVI
        , pin<void        > in_ptr_data_for_TVI = nullptr
        , _in<int         > in_index = -1
        )
    {
      return getEntity()->AddItemChild( in_ptr_TVI_parent, in_ptr_comp_for_TVI, in_ptr_data_for_TVI, in_index );
    }
    TreeViewItem*
      AddItemChild
        ( pio<TreeViewItem> in_ptr_TVI_parent
        , pin<str_type    > in_string_for_TVI
        , pin<void        > in_ptr_data_for_TVI = nullptr
        , _in<int         > in_index = -1
        )
    {
      return getEntity()->AddItemChild( in_ptr_TVI_parent, in_string_for_TVI, in_ptr_data_for_TVI, in_index );
    }
    TreeViewItem*
      AddItemPrev
        ( pio<TreeViewItem> in_ptr_TVI_base
        , pio<TreeViewItem> in_ptr_TVI_add
        )
    {
      return getEntity()->AddItemPrev( in_ptr_TVI_base, in_ptr_TVI_add );
    }
    TreeViewItem*
      AddItemPrev
        ( pio<TreeViewItem> in_ptr_TVI_base
        , pio<Component   > in_ptr_comp_for_TVI
        , pin<void        > in_ptr_data_for_TVI = nullptr
        )
    {
      return getEntity()->AddItemPrev( in_ptr_TVI_base, in_ptr_comp_for_TVI, in_ptr_data_for_TVI );
    }
    TreeViewItem*
      AddItemPrev
        ( pio<TreeViewItem> in_ptr_TVI_base
        , pin<str_type    > in_string_for_TVI
        , pin<void        > in_ptr_data_for_TVI = nullptr
        )
    {
      return getEntity()->AddItemPrev( in_ptr_TVI_base, in_string_for_TVI, in_ptr_data_for_TVI );
    }
    TreeViewItem*
      AddItemNext
        ( pio<TreeViewItem> in_ptr_TVI_base
        , pio<TreeViewItem> in_ptr_TVI_add
        )
    {
      return getEntity()->AddItemNext( in_ptr_TVI_base, in_ptr_TVI_add );
    }
    TreeViewItem*
      AddItemNext
        ( pio<TreeViewItem> in_ptr_TVI_base
        , pio<Component   > in_ptr_comp_for_TVI
        , pin<void        > in_ptr_data_for_TVI = nullptr
        )
    {
      return getEntity()->AddItemNext( in_ptr_TVI_base, in_ptr_comp_for_TVI, in_ptr_data_for_TVI );
    }
    TreeViewItem*
      AddItemNext
        ( pio<TreeViewItem> in_ptr_TVI_base
        , pin<str_type    > in_string_for_TVI
        , pin<void        > in_ptr_data_for_TVI = nullptr
        )
    {
      return getEntity()->AddItemNext( in_ptr_TVI_base, in_string_for_TVI, in_ptr_data_for_TVI );
    }
    template<class T_Type> TreeViewItemEx<T_Type>*
      AddItemChildEx
        ( pio<TreeViewItem> in_ptr_TVI_parent
        , pio<Component   > in_ptr_comp_for_TVI
        , pin<T_Type      > in_ptr_data_for_TVI
        , _in<int         > in_index = -1
        , _in<bool        > in_flag_delete = true
        )
    {
      return getEntity()->AddItemChildEx<T_Type>( in_ptr_TVI_parent, in_ptr_comp_for_TVI, in_ptr_data_for_TVI, in_index, in_flag_delete );
    }
    template<class T_Type> TreeViewItemEx<T_Type>*
      AddItemChildEx
        ( pio<TreeViewItem> in_ptr_TVI_parent
        , pin<str_type    > in_string_for_TVI
        , pin<T_Type      > in_ptr_data_for_TVI
        , _in<int         > in_index       = -1
        , _in<bool        > in_flag_delete = true
        )
    {
      return getEntity()->AddItemChildEx<T_Type>( in_ptr_TVI_parent, in_string_for_TVI, in_ptr_data_for_TVI, in_index, in_flag_delete );
    }
    template<class T_Type> TreeViewItemEx<T_Type>*
      AddItemPrevEx
        ( pio<TreeViewItem> in_ptr_TVI_base
        , pio<Component   > in_ptr_comp_for_TVI
        , pin<T_Type      > in_ptr_data_for_TVI
        , _in<bool        > in_flag_delete = true
        )
    {
      return
        getEntity()->AddItemPrevEx<T_Type>
          ( in_ptr_TVI_base, in_ptr_comp_for_TVI, in_ptr_data_for_TVI, in_flag_delete
          );
    }
    template<class T_Type> TreeViewItemEx<T_Type>*
      AddItemPrevEx
        ( pio<TreeViewItem> in_ptr_TVI_base
        , pin<str_type    > in_string_for_TVI
        , pin<T_Type      > in_ptr_data_for_TVI
        , _in<bool        > in_flag_delete = true
        )
    {
      return getEntity()-AddItemPrevEx<T_Type>( in_ptr_TVI_base, in_string_for_TVI, in_ptr_data_for_TVI, in_flag_delete );
    }
    template<class T_Type> TreeViewItemEx<T_Type>*
      AddItemNextEx
        ( pio<TreeViewItem> in_ptr_TVI_base
        , pio<Component   > in_ptr_comp_for_TVI
        , pin<T_Type      > in_ptr_data_for_TVI
        , _in<bool        > in_flag_delete = true
        )
    {
      return getEntity()->AddItemNextEx<T_Type>( in_ptr_TVI_base, in_ptr_comp_for_TVI, in_ptr_data_for_TVI, in_flag_delete );
    }
    template<class T_Type> TreeViewItemEx<T_Type>*
      AddItemNextEx
        ( pio<TreeViewItem> in_ptr_TVI_base
        , pin<str_type    > in_string_for_TVI
        , pin<T_Type      > in_ptr_data_for_TVI
        , _in<bool        > in_flag_delete = true
        )
    {
      return getEntity()->AddItemNextEx<T_Type>( in_ptr_TVI_base, in_string_for_TVI, in_ptr_data_for_TVI, in_flag_delete );
    }

    void          MoveItemPrev    ( pio<TreeViewItem> in_ptr_TVI_move, pio<TreeViewItem> in_ptr_TVI_base = nullptr ){        getEntity()->MoveItemPrev( in_ptr_TVI_move, in_ptr_TVI_base );    }
    void          MoveItemNext    ( pio<TreeViewItem> in_ptr_TVI_move, pio<TreeViewItem> in_ptr_TVI_base = nullptr ){        getEntity()->MoveItemNext( in_ptr_TVI_move, in_ptr_TVI_base );    }
    void          MoveItemParent  ( pio<TreeViewItem> in_ptr_TVI_move )                                             {        getEntity()->MoveItemParent( in_ptr_TVI_move );             }
    void          MoveItemChild   ( pio<TreeViewItem> in_ptr_TVI_move, pio<TreeViewItem> in_ptr_TVI_parent )        {        getEntity()->MoveItemChild( in_ptr_TVI_move, in_ptr_TVI_parent ); }
    bool          SwapItem        ( pio<TreeViewItem> in_ptr_item0, pio<TreeViewItem> in_ptr_item1 )                { return getEntity()->SwapItem( in_ptr_item0, in_ptr_item1 );                }
    void          DeleteItem      ( pio<TreeViewItem> in_ptr_TVI_del )                                              {        getEntity()->DeleteItem( in_ptr_TVI_del );                         }
    void          ReleaseItem     ()                            {        getEntity()->ReleaseItem();                   }
    TreeViewItem* FindTreeViewItem( pin<Component> in_ptr_comp ){ return getEntity()->FindTreeViewItem( in_ptr_comp ); }
    TreeViewItem* FindTreeViewItem( pin<void     > in_ptr_data_for_TVI ){ return getEntity()->FindTreeViewItem( in_ptr_data_for_TVI ); }
    void          SetScrollShow   ( _in<bool> in_flag_show )    {        getEntity()->SetScrollShow( in_flag_show );   }

    Binder
    ( _in<HWND     > in_hdl_win_parent
    , _in<td_Coord2> in_pos  = kPOS_DEFAULT
    , _in<td_Coord2> in_size = kSIZE_DEFAULT
    , _in<int      > in_ID = -1
    , _in<LONG_PTR > in_win_style = WS_CHILD | WS_BORDER
    ) : Window::Binder
        ( CPL_NEW(TreeView)
          ( in_hdl_win_parent
          , in_pos
          , in_size
          , in_ID
          , in_win_style
          )
        )
    {}
  protected:
    // 継承用
    Binder( TreeView* in_ptr_tree_view )
      : Window::Binder( in_ptr_tree_view )
    {}
  };

};


} // namespace WIN
} // namespace CPL
