1 jls.loader.provide('jls.win32.TreeView');
  2 
  3 jls.loader.require('jls.win32.Window');
  4 
  5 jls.win32.TreeView = jls.lang.Class.create(jls.win32.Window,
  6 {
  7     initialize : function($super, title, style, x, y, w, h, parent, id, exStyle, param) {
  8         $super(jls.win32.TreeView.CLASSNAME, title, style, x, y, w, h, parent, id, exStyle, param);
  9         this._item = new jls.lang.Struct([
 10             {name: 'hParent', type: 'Pointer'},
 11             {name: 'hInsertAfter', type: 'Pointer'},
 12             {name: 'item.mask', type: 'UnsignedInt'},
 13             {name: 'item.hItem', type: 'Pointer'},
 14             {name: 'item.state', type: 'UnsignedInt'},
 15             {name: 'item.stateMask', type: 'UnsignedInt'},
 16             {name: 'item.pszText', type: 'Pointer'},
 17             {name: 'item.cchTextMax', type: 'SignedInt'},
 18             {name: 'item.iImage', type: 'SignedInt'},
 19             {name: 'item.iSelectedImage', type: 'SignedInt'},
 20             {name: 'item.cChildren', type: 'SignedInt'},
 21             {name: 'item.lParam', type: 'Pointer'}
 22         ]);
 23         this._textBuffer = jls.lang.ByteBuffer.allocate(256);
 24     },
 25     insertRootItem : function(label) {
 26         var item = new jls.win32.TreeView.Item(label);
 27         this.insertItem(item);
 28         return item;
 29     },
 30     insertItem : function(item) {
 31         this._item.put('hParent', item.isRoot() ? jls.win32.TreeView.TVI_ROOT : item.getParent()._handle);
 32         this._item.put('hInsertAfter', 0);
 33         this._item.put('item.mask', jls.win32.TreeView.TVIF_TEXT | jls.win32.TreeView.TVIF_IMAGE);
 34         this._textBuffer.clear();
 35         var label = item.getLabel();
 36         this._textBuffer.putString(label);
 37         this._textBuffer.putByte(0);
 38         this._item.put('item.pszText', this._textBuffer.byteArray().pointer());
 39         this._item.put('item.cchTextMax', label.length + 1);
 40         this._item.put('item.iImage', -1);
 41         this._item.put('item.iSelectedImage', -1);
 42         this._item.put('item.cChildren', 0);
 43         this._item.put('item.lParam', 0);
 44         item._handle = this.sendMessage(jls.win32.TreeView.TVM_INSERTITEMA, 0, this._item.buffer().byteArray());
 45         item._tree = this;
 46         return item;
 47     }
 48 });
 49 
 50 jls.win32.TreeView.Item = jls.lang.Class.create(
 51 {
 52     initialize : function(label) {
 53         this._label = label || '';
 54         this._parent = null;
 55     },
 56     getLabel : function() {
 57         return this._label;
 58     },
 59     getParent : function() {
 60         return this._parent;
 61     },
 62     isRoot : function() {
 63         return this._parent == null;
 64     },
 65     insert : function(item) {
 66         item._parent = this;
 67         this._tree.insertItem(item);
 68         return item;
 69     }
 70 });
 71 
 72 Object.extend(jls.win32.TreeView,
 73 {
 74     TVS_HASBUTTONS           : 0x00000001,
 75     TVS_HASLINES             : 0x00000002,
 76     TVS_LINESATROOT          : 0x00000004,
 77     TVS_EDITLABELS           : 0x00000008,
 78     TVS_DISABLEDRAGDROP      : 0x00000010,
 79     TVS_SHOWSELALWAYS        : 0x00000020,
 80     TVM_INSERTITEMA          : 0x00001100,
 81     TVM_INSERTITEMW          : 0x00001132,
 82     TVM_DELETEITEM           : 0x00001101,
 83     TVM_EXPAND               : 0x00001102,
 84     TVM_GETITEMRECT          : 0x00001104,
 85     TVM_GETCOUNT             : 0x00001105,
 86     TVM_GETINDENT            : 0x00001106,
 87     TVM_SETINDENT            : 0x00001107,
 88     TVM_GETIMAGELIST         : 0x00001108,
 89     TVM_SETIMAGELIST         : 0x00001109,
 90     TVM_GETNEXTITEM          : 0x0000110a,
 91     TVM_SELECTITEM           : 0x0000110b,
 92     TVM_GETITEMA             : 0x0000110c,
 93     TVM_GETITEMW             : 0x0000113e,
 94     TVM_SETITEMA             : 0x0000110d,
 95     TVM_SETITEMW             : 0x0000113f,
 96     TVM_EDITLABELA           : 0x0000110e,
 97     TVM_EDITLABELW           : 0x00001141,
 98     TVM_GETEDITCONTROL       : 0x0000110f,
 99     TVM_GETVISIBLECOUNT      : 0x00001110,
100     TVM_HITTEST              : 0x00001111,
101     TVM_CREATEDRAGIMAGE      : 0x00001112,
102     TVM_SORTCHILDREN         : 0x00001113,
103     TVM_ENSUREVISIBLE        : 0x00001114,
104     TVM_SORTCHILDRENCB       : 0x00001115,
105     TVM_ENDEDITLABELNOW      : 0x00001116,
106     TVM_GETISEARCHSTRINGA    : 0x00001117,
107     TVM_GETISEARCHSTRINGW    : 0x00001140,
108     TVI_ROOT                 : 0xffff0000,
109     TVI_FIRST                : 0xffff0001,
110     TVI_LAST                 : 0xffff0002,
111     TVI_SORT                 : 0xffff0003,
112     TVIF_TEXT                : 0x00000001,
113     TVIF_IMAGE               : 0x00000002,
114     TVIF_PARAM               : 0x00000004,
115     TVIF_STATE               : 0x00000008,
116     TVIF_HANDLE              : 0x00000010,
117     TVIF_SELECTEDIMAGE       : 0x00000020,
118     TVIF_CHILDREN            : 0x00000040,
119     TVIS_FOCUSED             : 0x00000001,
120     TVIS_SELECTED            : 0x00000002,
121     TVIS_CUT                 : 0x00000004,
122     TVIS_DROPHILITED         : 0x00000008,
123     TVIS_BOLD                : 0x00000010,
124     TVIS_EXPANDED            : 0x00000020,
125     TVIS_EXPANDEDONCE        : 0x00000040,
126     TVIS_OVERLAYMASK         : 0x00000f00,
127     TVIS_STATEIMAGEMASK      : 0x0000f000,
128     TVIS_USERMASK            : 0x0000f000,
129 
130     CLASSNAME: 'SysTreeView32'
131 });
132