1 /******************************************************************************
2 *
3 * Copyright (C) 2004-2007, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * ID: vis.treeviewitem 25.09.07 0.0.A.
11 *
12 * Author: Alexander Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15
16 extern
17 {
18 property TVItem TVItem.Parent
19 property TVItem TVItem.Next
20 property TVItem TVItem.Prev
21 property TVItem TVItem.LastChild
22
23 method uint TVItem.eof( fordata tfd )
24 method uint TVItem.next( fordata tfd )
25 method uint TVItem.first( fordata tfd )
26
27 method TVSelection.Remove( TVItem item )
28 method uint TVSelection.Find( TVItem item )
29 method TVItem TVSelection.index( uint idx )
30 method TVSelection.iWinUpdate( uint selected )
31 operator uint *( TVSelection obj )
32 }
33
34
35 method TVItem.iItemUpdate( uint mask )
36 {
37 TVITEM item
38 uint state
39 item.mask = mask
40 item.hItem = .param->treedata.handle
41
42
43 if .getuint( "bold" ) : state |= $TVIS_BOLD
44
45 item.iImage = -1
46 item.iSelectedImage = -1
47 if .param->treedata.treeview && .param->treedata.treeview->vTreeView.ptrImageList
48 {
49 uint tname
50 ustr imgname
51 tname as .get( "image" )
52 if &tname
53 {
54 imgname.fromutf8( tname )
55 item.iImage = .param->treedata.treeview->vTreeView.ptrImageList->ImageList.GetImageIdx( .param->treedata.treeview->vTreeView.iNumIml, imgname, uint( .get( "disabled", "" ) ) )
56 }
57 tname as .get( "selectedimage" )
58 if &tname
59 {
60 imgname.fromutf8( tname )
61 item.iSelectedImage = .param->treedata.treeview->vTreeView.ptrImageList->ImageList.GetImageIdx( .param->treedata.treeview->vTreeView.iNumIml, imgname, uint( .get( "disabled", "" ) ) )
62 }
63 }
64 if item.iImage != -1 && item.iSelectedImage = -1
65 {
66 item.iSelectedImage = item.iImage
67 }
68
69 /*if .param->treedata.inselections {
70 state |= $TVIS_SELECTED // $TVIS_DROPHILITED //| $TVIS_CUT
71 }*/
72 item.state = state //| $TVIS_EXPANDPARTIAL
73 item.stateMask = $TVIS_BOLD///*| $TVIS_DROPHILITED*/ | $TVIS_SELECTED //*/| $TVIS_DROPHILITED// | $TVIS_SELECTED | $TVIS_CUT//| $TVIS_EXPANDEDONCE /*| $TVIS_BOLD |/ $TVIS_SELECTED //|$TVIS_DROPHILITED//| $TVIS_CUT | $TVIS_EXPANDPARTIAL*/7
74
75 //.Label
76 item.pszText = .Label->locustr.Text( .param->treedata.treeview->vTreeView ).ptr()
77
78 .param->treedata.treeview->vTreeView.WinMsg( $TVM_SETITEMW, 0, &item )
79 if mask & $TVIF_STATE
80 {
81 //state |= $TVIS_EXPANDEDONCE
82 .param->treedata.treeview->vTreeView.WinMsg( $TVM_EXPAND, ?( .getuint( "expanded" ), $TVE_EXPAND, $TVE_COLLAPSE ), .param->treedata.handle )
83 }
84 }
85
86 method TVItem.iItemInsert( TVItem child )
87 {
88 TVINSERTSTRUCT ti
89 uint thisdata as .param->treedata
90
91 uint sorttype = .getuint( "sorttype" )
92 if sorttype & $TVSORT_SORT
93 {
94 ti.hInsertAfter = $TVI_SORT
95 }
96 else
97 {
98 uint prev as child.Prev
99 ti.hInsertAfter = ?( &prev, prev.param->treedata.handle, $TVI_FIRST )
100 //ti.hInsertAfter = ?( &after, ?( &after==0xFFFFFFFF, $TVI_LAST, after.param->treedata.handle ), $TVI_FIRST )
101 }
102 ti.hParent = thisdata.handle
103 ti.item.mask = $TVIF_PARAM | $TVIF_TEXT
104 ti.item.lParam = &child
105 ti.item.pszText = child.Label->locustr.Text( .param->treedata.treeview->vTreeView ).ptr()
106 child.param->treedata.handle = thisdata.treeview->vTreeView.WinMsg( $TVM_INSERTITEMW, 0, &ti )
107 // child.iItemUpdate( $TVIF_STATE | $TVIF_TEXT | $TVIF_SELECTEDIMAGE | $TVIF_IMAGE)
108 }
109
110
111 property gtitem TVItem.Children
112 {
113 return .findrel( "/children" )
114 }
115
116 method TVItem.iWinClear( uint flgdelitem )
117 {
118 if .param
119 {
120 uint children as .Children
121 if &children
122 {
123 uint prev as children.lastchild()->TVItem
124 while &prev
125 {
126 prev.iWinClear( flgdelitem )
127 //uint pdel as prev
128 prev as prev.Prev
129 //if flgdelitem: pdel.del()
130 }
131 if flgdelitem: children.del()
132 }
133 destroy( .param )
134 .param = 0
135 }
136 }
137
138
139 method TVItem.Release()
140 {
141 /*if this.InSelections
142 {
143 this.InSelections = 0
144 }*/
145 if .param
146 {
147 uint children as .Children
148 if &children
149 {
150 uint prev as children.lastchild()->TVItem
151 while &prev
152 {
153 prev.Release()
154 prev as prev.Prev
155 }
156 //fornum i = 0, children
157 /*foreach child, children
158 {
159 child->TVItem.Release()
160 }*/
161 }
162 if &this && .param->treedata.treeview
163 {
164 .param->treedata.treeview->vTreeView.fReleasing = 1
165 uint inselections
166 uint selection as .param->treedata.treeview->vTreeView.Selection
167 if selection.StartShift == &this
168 {
169 selection.StartShift = 0
170 }
171 if selection.Find( this ) != -1
172 {
173 selection.Remove( this )
174 if *selection
175 {
176 inselections = 1
177 }
178 }
179 if &this == .param->treedata.treeview->vTreeView.pSelected
180 {
181 uint next
182 if inselections
183 {
184 next = &selection[0]
185 }
186 else
187 {
188 if ( (next = &this.Next) && next->TVItem.param ) ||
189 ( (next = &this.Prev) && next->TVItem.param ) ||
190 ( next = &this.Parent )
191 {
192 }
193 }
194 .param->treedata.treeview->vTreeView.Selected = next->TVItem
195 }
196 .param->treedata.treeview->vTreeView.WinMsg( $TVM_DELETEITEM, 0, .param->treedata.handle )
197 .param->treedata.treeview->vTreeView.fReleasing = 0
198 }
199 //if &this != &.param->treedata.treeview->vTreeView.gttree.root()
200 {
201 destroy( .param )
202 .param = 0
203 }
204 }
205 }
206
207 method TVItem.Del()
208 {
209 this.Release()
210 this.del()
211 /*if this.InSelections
212 {
213 this.InSelections = 0
214 }*/
215 /* if .param
216 {
217 if &this == .param->treedata.treeview->vTreeView.pSelected
218 {
219 .param->treedata.treeview->vTreeView.pSelected = 0
220 }
221 uint children as .Children
222 if &children
223 {
224 foreach child, children
225 {
226 child->TVItem.Del()
227 }
228 }
229 if &this && .param->treedata.treeview
230 {
231 .param->treedata.treeview->vTreeView.WinMsg( $TVM_DELETEITEM, 0, .param->treedata.handle )
232 }
233
234 if &this != &.param->treedata.treeview->vTreeView.gttree.root()
235 {
236 destroy( .param )
237 this.del()
238 }
239 }*/
240 }
241
242 /* Свойство ustr Label - Get Set
243 Устанавливает или определяет заголовок элемента дерева
244 */
245 property ustr TVItem.Label <result>
246 {
247 uint name as .get( "label" )
248 //! result.clear()
249 if &name
250 {
251 result.fromutf8( name ).ptr()
252 }
253 }
254
255 property TVItem.Label( ustr val )
256 {
257 .set( "label", val.toutf8( "" ) )
258 .iItemUpdate( $TVIF_TEXT )
259 }
260
261 /* Свойство ustr vToolBarItem.ImageId - Get Set
262 Устанавливает или получает картинку
263 */
264 property ustr TVItem.ImageId <result>
265 {
266 result.fromutf8( .get( "image" ) ).ptr()
267 }
268
269 property TVItem.ImageId( ustr val )
270 {
271 //if val != "".ustr().fromutf8( .get( "image" ) )
272 {
273 .set( "image", val.toutf8( "" ) )
274 .iItemUpdate( $TVIF_IMAGE | $TVIF_SELECTEDIMAGE )
275 }
276 }
277
278
279
280 method TVItem TVItem.InsertChild( ustr name, uint tag, ustr image, TVItem after )
281 {
282
283 if &this && .param->treedata.treeview
284 {
285 //uint children as .findrel( "\children" )
286
287 uint children as .Children
288 if !&children : children as .insertchild( "children", 0->gtitem )
289 uint thisdata as .param->treedata
290 uint child as children.insertchild( "", after )->TVItem
291 uint childdata as new( treedata )->treedata
292 childdata.treeview = thisdata.treeview
293 child.param = &childdata
294 child.set( "label", name.toutf8( "" ) )
295 child.setuint( "tag", tag )
296 if &image && *image
297 {
298 child.set( "image", image.toutf8( "" ) )
299 }
300 //TVINSERTSTRUCT ti
301 //ti.item.pszText = name.ptr()
302 uint sorttype = .getuint( "sorttype" )
303 if sorttype & $TVSORT_SORT
304 {
305 //ti.hInsertAfter = $TVI_SORT
306 if sorttype == $TVSORT_SORTRECURSE
307 {
308 child.setuint( "sorttype", sorttype )
309 }
310 }
311 .iItemInsert( child )
312 child.iItemUpdate( $TVIF_STATE | $TVIF_TEXT | $TVIF_SELECTEDIMAGE | $TVIF_IMAGE)
313 if !&.param->treedata.treeview->vTreeView.Selected
314 {
315 .param->treedata.treeview->vTreeView.Selected = child
316 }
317 /*else
318 {
319 ti.hInsertAfter = ?( &after, ?( &after==0xFFFFFFFF, $TVI_LAST, after.param->treedata.handle ), $TVI_FIRST )
320 }
321 ti.hParent = thisdata.handle
322 ti.item.mask = $TVIF_TEXT | $TVIF_PARAM// | $TVIF_SELECTEDIMAGE | $TVIF_IMAGE
323 //ti.item.stateMask = $TVIS_STATEIMAGEMASK
324 //ti.item.state = 0x2000
325 ti.item.lParam = &child
326 ti.item.iImage = -1
327 ti.item.iSelectedImage = -1
328 childdata.handle = thisdata.treeview->vTreeView.WinMsg( $TVM_INSERTITEMW, 0, &ti )*/
329 return child->TVItem
330 }
331 return 0->TVItem
332 }
333
334 method TVItem TVItem.InsertFirstChild( ustr name, uint tag, ustr image )
335 {
336 return this.InsertChild( name, tag, image, 0->TVItem )
337 }
338
339 method TVItem TVItem.AppendChild( ustr name, uint tag, ustr image )
340 {
341 return this.InsertChild( name, tag, image, 0xFFFFFFFF->TVItem )
342 }
343
344 method TVItem TVItem.InsertFirstChild( ustr name, uint tag )
345 {
346 return this.InsertChild( name, tag, 0->ustr, 0->TVItem )
347 }
348
349 method TVItem TVItem.AppendChild( ustr name, uint tag )
350 {
351 return this.InsertChild( name, tag, 0->ustr, 0xFFFFFFFF->TVItem )
352 }
353
354 /*operator uint *( TVItem item )
355 {
356 uint count
357 if &item && item.TreeView
358 {
359 uint tv as item.TreeView->vTreeView
360 uint cur = tv.WinMsg( $TVM_GETNEXTITEM, $TVGN_CHILD, item.handle )
361 while cur
362 {
363 count++
364 tv.WinMsg( $TVM_GETNEXTITEM, $TVGN_NEXT, cur )
365 }
366 }
367 return count
368 return *item->gtitem
369 }*/
370
371 method TVItem TVItem.index( uint idx )
372 {
373 if &this
374 {
375 uint child as .Child
376 uint i
377 while &child
378 {
379 if i++ == idx : return child
380 child as child.Next
381 }
382 }
383 return 0->TVItem
384 }
385
386 property uint TVItem.IndexInList()
387 {
388 uint num
389
390 if &this
391 {
392 uint parent as this.Parent
393 if &parent
394 {
395 uint child as parent.Child
396 while &child
397 {
398 if &child == &this : return num
399 num++
400 child as child.Next
401 }
402 }
403 }
404 return 0
405 }
406
407 operator uint *( TVItem item )
408 {
409 uint count
410 if &item
411 {
412 uint child as item.Child
413 while &child
414 {
415 count++
416 child as child.Next
417 }
418 }
419 return count
420 }
421
422
423
424 /* Свойство uint Expand - Get Set
425 Устанавливает или определяет открытие ветки
426 0 - ветка закрыта
427 1 - ветка открыта
428 */
429 property uint TVItem.Expanded
430 {
431 return .getuint( "expanded" )
432 }
433
434 property TVItem.Expanded( uint val )
435 {
436 if .getuint( "expanded" ) != val
437 {
438 //.param->treedata.treeview->vTreeView.WinMsg( $TVM_EXPAND, ?( val, $TVE_EXPAND, $TVE_COLLAPSE ), .param->treedata.handle )
439 .setuint( "expanded", val )
440 .iItemUpdate( $TVIF_STATE )
441 }
442 //.iItemUpdate( $TVIF_STATE )
443 }
444
445 method TVItem.ExpandRecurse( uint val )
446 {
447 .Expanded = val
448 foreach item, this
449 {
450 item.ExpandRecurse( val )
451 }
452
453 }
454
455 /* Свойство uint Tag - Get Set
456 Устанавливает или определяет пользовательский параметр элемента дерева
457 */
458 property uint TVItem.Tag
459 {
460 return .getuint( "tag" )
461 }
462
463 property TVItem.Tag( uint val )
464 {
465 .setuint( "tag", val )
466 }
467
468 /* Свойство uint Bold - Get Set
469 Устанавливает или определяет пользовательский параметр элемента дерева
470 */
471 property uint TVItem.Bold
472 {
473 return .getuint( "bold" )
474 }
475
476 property TVItem.Bold( uint val )
477 {
478 .setuint( "bold", val )
479 .iItemUpdate( $TVIF_STATE )
480 }
481
482 /* Свойство uint Checked - Get Set
483 Устанавливает или определяет пользовательский параметр элемента дерева
484 */
485 property uint TVItem.Checked
486 {
487 return .getuint( "checked" )
488 }
489
490 property TVItem.Checked( uint val )
491 {
492 .setuint( "checked", val )
493 //.iItemUpdate( $TVIF_STATE )
494 }
495
496 /* Свойство uint SortTYpe - Get Set
497 Устанавливает или определяет пользовательский параметр элемента дерева
498 */
499 property uint TVItem.SortType
500 {
501 return .getuint( "sorttype" )
502 }
503
504 property TVItem.SortType( uint val )
505 {
506 .setuint( "sorttype", ?( val & $TVSORT_SORT, val, $TVSORT_NONE ))
507 if val & $TVSORT_SORT
508 {
509 .param->treedata.treeview->vTreeView.WinMsg( $TVM_SORTCHILDREN, 0, .param->treedata.handle )
510 }
511 if val & $TVSORT_RECURSE
512 {
513 uint children as .Children
514 if &children
515 {
516 foreach child, children
517 {
518 child->TVItem.SortType = val
519 }
520 }
521 }
522
523 //.iItemUpdate( $TVIF_STATE )
524 }
525
526 /* Свойство uint Parent - Get
527 Определяет хозяина данной ветки, если ветка в корне то корень, если корень то 0
528 */
529 property TVItem TVItem.Parent
530 {
531 return this->gtitem.parent().parent()->TVItem
532
533 // return this->gtitem.parent()->TVItem
534 }
535
536 /* Свойство uint Prev - Get
537 Определяет предыдущий элемент, если он есть, иначе 0
538 */
539 property TVItem TVItem.Prev
540 {
541 uint x = &(this->gtitem.getprev())
542 return x->TVItem
543 //return this->gtitem.getprev()->TVItem
544 }
545
546 /* Свойство uint Next - Get
547 Определяет следующий элемент, если он есть, иначе 0
548 */
549 property TVItem TVItem.Next
550 {
551 return this->gtitem.getnext()->TVItem
552 }
553
554 /* Свойство uint NextInList - Get
555 Определяет следующий элемент в глобальном списке или 0 если больше нет
556 */
557 property TVItem TVItem.NextInList
558 {
559 uint item
560 uint parent
561
562 item as this.Child
563 if &item : return item
564 parent as this
565 do
566 {
567 item as parent.Next
568 if &parent == &(.param->treedata.treeview->vTreeView.Root())
569 {
570 return 0->TVItem
571 }
572 if &item : return item
573 parent as parent.Parent
574 } while &parent
575 return 0->TVItem
576 }
577
578 /* Свойство uint LastChild - Get
579 Определяет последний дочерний элемент, если он есть, иначе 0
580 */
581 property TVItem TVItem.LastChild
582 {
583 uint children as .Children
584 if &children : return children.lastchild()->TVItem
585 return 0->TVItem
586 //return this->gtitem.lastchild()->TVItem
587 }
588
589 /* Свойство uint Child - Get
590 Определяет первый дочерний элемент данной ветки, если ветка не имеет дочерних элементов, то 0
591 */
592 property TVItem TVItem.Child
593 {
594 uint children as .Children
595 if &children : return children.child()->TVItem
596 return 0->TVItem
597 /*
598 uint res as this.child()
599 return res->TVItem*/
600 }
601
602
603
604 method TVItem.Reinsert()
605 {
606 uint owner as this.Parent()
607
608 owner.iItemInsert( this )
609 uint children as .Children
610 if &children
611 {
612 foreach child, children
613 {
614 child->TVItem.Reinsert()
615 }
616 }
617 this.iItemUpdate( $TVIF_STATE | $TVIF_TEXT | $TVIF_SELECTEDIMAGE | $TVIF_IMAGE)
618 }
619
620 method TVItem.Update()
621 {
622 this.iItemUpdate( $TVIF_IMAGE | $TVIF_SELECTEDIMAGE | $TVIF_TEXT | $TVIF_STATE )
623 uint children as .Children
624 if &children
625 {
626 foreach child, children
627 {
628 child->TVItem.Update()
629 }
630 }
631 if .getuint( "sorttype" ) & $TVSORT_SORT
632 {
633 .param->treedata.treeview->vTreeView.WinMsg( $TVM_SORTCHILDREN, 0, .param->treedata.handle )
634 }
635 }
636
637 method TVItem.MoveTo( TVItem dest, uint flag )
638 {
639 uint tv as .param->treedata.treeview->vTreeView
640 uint root as tv.Root
641 //if flag != $TREE_AFTER || ( &this.Next() != &dest )
642 if &dest
643 {
644 uint oldfmoving = tv.fMoving
645 //uint selected as TVItem
646 tv.fMoving = 1
647 //uint tv as .param->treedata.treeview->vTreeView
648 evparBeforeMove evpB
649 evpB.CurItem = &this
650 evpB.DestItem = &dest
651 evpB.Flag = flag
652 //if tv.fMoving:
653 tv.OnBeforeMove.run( evpB )
654 if !evpB.flgCancel
655 {
656 this.move( ?( flag == $TREE_LAST || flag == $TREE_FIRST , dest.Children, dest ), flag )
657 tv.WinMsg( $TVM_DELETEITEM, 0, .param->treedata.handle )
658 this.Reinsert()
659 evparAfterMove evpA
660 evpA.CurItem = &this
661 evpA.DestItem = &dest
662 evpA.Flag = flag
663 //if tv.fMoving :
664 tv.OnAfterMove.run( evpA )
665 }
666 tv.fMoving = oldfmoving
667 if !oldfmoving
668 {
669 //tv.Selected = 0->TVItem
670 //tv.Selected = selected
671 tv.Selection.iWinUpdate( 1 )
672 tv.WinMsg( $TVM_SELECTITEM, $TVGN_CARET, tv.pSelected->TVItem.param->treedata.handle )
673 }
674 }
675 }
676
677 /* Свойство uint Selected - Get Set
678 Устанавливает или определяет пользовательский параметр элемента дерева
679 */
680 /*property uint TVItem.Selected
681 {
682 return .getuint( "Selected" )
683 }
684
685 property TVItem.Selected( uint val )
686 {
687 .setuint( "Selected", ?( val & $TVSORT_SORT, val, $TVSORT_NONE ))
688 if val & $TVSORT_SORT
689 {
690 .param->treedata.treeview->vTreeView.WinMsg( $TVM_SORTCHILDREN, 0, .param->treedata.handle )
691 }
692 if val & $TVSORT_RECURSE
693 {
694 foreach child, this
695 {
696 child.Selected = val
697 }
698 }
699
700 //.iItemUpdate( $TVIF_STATE )
701 }*/
702 method TVSelection.iSelect( TVItem item, uint selected )
703 {
704 TVITEM tvi
705 tvi.mask = $TVIF_STATE
706 tvi.hItem = item.param->treedata.handle
707 if selected : tvi.state |= $TVIS_SELECTED
708 tvi.stateMask = $TVIS_SELECTED
709
710 .pTreeView->vTreeView.WinMsg( $TVM_SETITEMW, 0, &tvi )
711 }
712
713
714 method TVSelection.iWinUpdate( uint selected )
715 {
716 uint i
717 uint treeview as .pTreeView->vTreeView
718 fornum i = 0, *.Items
719 {
720 .iSelect( .Items[i]->TVItem, selected )
721 }
722 }
723
724 method TVItem TVSelection.index( uint idx )
725 {
726 if idx < *.Items : return .Items[idx]->TVItem
727 return 0->TVItem
728 }
729
730 operator uint *( TVSelection obj )
731 {
732 return *(obj.Items)
733 }
734
735
736 method uint TVSelection.eof( fordata tfd )
737 {
738 return tfd.icur >= *.Items
739 }
740
741
742 method uint TVSelection.next( fordata tfd )
743 {
744 if ++tfd.icur >= *.Items : return 0
745 return .Items[tfd.icur]
746 }
747
748
749 method uint TVSelection.first( fordata tfd )
750 {
751 tfd.icur = 0
752 if tfd.icur >= *.Items : return 0
753 return .Items[tfd.icur]
754 }
755
756
757 method uint TVItem.eof( fordata tfd )
758 {
759 return !tfd.icur
760 }
761
762
763 method uint TVItem.next( fordata tfd )
764 {
765 return tfd.icur = &tfd.icur->TVItem.Next()
766 }
767
768
769 method uint TVItem.first( fordata tfd )
770 {
771 return tfd.icur = &.Child()
772 }
773
774 //method uint TVItem.Find( ustr
775 /*method TVSelection.oftype()
776 {
777
778 }*/
779
780 method uint TVSelection.Find( TVItem item )
781 {
782 uint i
783 fornum i = 0, *.Items
784 {
785 if .Items[i] == &item : return i
786 }
787 return -1
788 }
789
790 method TVSelection.Append( TVItem item )
791 {
792 if .Find( item ) == -1
793 {
794 uint idx = .Items.expand( 1 )
795 .Items[idx] = &item
796 .iSelect( item, 1 )
797 }
798 }
799
800 method TVSelection.Remove( TVItem item )
801 {
802 uint idx = .Find( item )
803 if idx != -1
804 {
805 .Items.del( idx )
806 .iSelect( item, 0 )
807 }
808 }
809
810 method TVSelection.Clear()
811 {
812 .iWinUpdate( 0 )
813 .Items.clear()
814 }
815
816 method TVSelection.SelectAll()
817 {
818 .Items.clear()
819 uint curitem as .pTreeView->vTreeView.Root
820 while ( curitem as curitem.NextInList )
821 {
822 .Items[.Items.expand( 1 )] = &curitem
823 }
824 .iWinUpdate( 1 )
825 }
826
827 method TVSelection.RemoveChildren()
828 {
829 int i
830 //foreach item, .tvProject.Selections
831 uint parent, curitem
832 uint root = &.pTreeView->vTreeView.Root
833 for i = *.Items - 1, i >= 0, i--
834 {
835 curitem as .Items[i]->TVItem
836 parent as curitem.Parent
837 while &parent != root
838 {
839 if .Find( parent ) != -1
840 {
841 .Remove( curitem )
842 break
843 }
844 parent as parent.Parent
845 }
846 }
847 curitem as root->TVItem
848 uint index = 0
849 uint curindex
850 while ( curitem as curitem.NextInList )
851 {
852 if ( curindex = .Find( curitem )) != -1
853 {
854 .Items.move( curindex, index++ )
855 }
856 }
857 }
858
859 method TVSelection.MoveTo( TVItem dest, uint flag )
860 {
861 if &dest
862 {
863 uint tv as .pTreeView->vTreeView
864 tv.fMoving = 1
865 .RemoveChildren()
866 foreach item, this
867 {
868 item.MoveTo( dest, flag )
869 }
870 tv.fMoving = 0
871 .iWinUpdate( 1 )
872 tv.WinMsg( $TVM_SELECTITEM, $TVGN_CARET, tv.pSelected->TVItem.param->treedata.handle )
873 }
874 }