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.listview 9.10.07 0.0.A.
11 *
12 * Author: Alexander Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15 include {
16 // "app.g"
17 "..\\gt\\gt.g"
18 "treeview.g"
19 }
20
21 type LVItem <index=this inherit=gtitem>
22 {
23 }
24
25
26 type listdata
27 {
28 //uint listview
29 uint listview //Объект содержащий данный элемент
30 //uint idx //Номер элемента в окне
31 // uint inselections
32 //uint tag
33 //uint gttree
34 }
35 /*
36 type eventTVEdit <inherit=onevent>
37 {
38 ustr NewLabel
39 uint flgCancel
40 }
41
42 method eventTVEdit eventTVEdit.init
43 {
44 this.eventtypeid = eventTVEdit
45 return this
46 }
47
48 type eventTVBefore <inherit=onevent>
49 {
50 uint CurItem
51 uint flgCancel
52 }
53
54 method eventTVBefore eventTVBefore.init
55 {
56 this.eventtypeid = eventTVBefore
57 return this
58 }
59
60 type eventTVAfter <inherit=onevent>
61 {
62 uint CurItem
63 }
64
65 method eventTVAfter eventTVAfter.init
66 {
67 this.eventtypeid = eventTVAfter
68 return this
69 }*/
70
71 /* Компонента vListView, порождена от vCtrl
72 События
73 onClick - вызывается при нажатии на кнопку
74 */
75 type vListView <inherit = vCtrl>
76 {
77 //Hidden Fields
78 /*uint pShowPlusMinus //Показывать +/-
79 uint pShowLines //Показывать линейки дерева
80 uint pShowRootLines //Показывать корневую линейку*/
81 uint pShowSelection //Всегда показывать выделение
82 /*uint pRowSelect //Выделение элемента в виде строки*/
83 uint pLabelEdit //Возможность редактирования элементов
84 uint pBorder //Показывать рамку
85 /*uint pSorted //Сортировать элементы*/
86 uint pSelected //Текущий выбранный элемент
87 uint fDrag //Флаг, находимся в режиме drag'n'drop
88 uint fOldDestItem //Куда перетаскивать текущий элемент
89
90 gt gttree //Представление в виде gt
91 //Events
92 //onevent onStartEdit
93 evTVEdit OnAfterEdit
94 evTVEdit OnBeforeEdit
95 evTVBefore OnBeforeSelect
96 evTVAfter OnAfterSelect
97 uint flgItemChanging
98 evItemMoved OnItemMoved
99 /*eventTVBefore OnBeforeExpand
100 eventTVAfter OnAfterExpand
101 eventTVBefore OnBeforeCollapse
102 eventTVAfter OnAfterCollapse*/
103 }
104
105
106 extern {
107 //property uint LVItem.InSelections
108 //property LVItem.InSelections( uint val )
109 property LVItem vListView.Selected()
110 property vListView.Selected( LVItem item )
111 /*property ustr LVItem.Label// <result>
112 property LVItem LVItem.Child()*/
113 property LVItem LVItem.Prev()
114 property LVItem LVItem.Next()
115 method LVItem.WinSet( uint mask )
116 property uint LVItem.Idx
117 //property vListView.Selected( LVItem item )
118
119 }
120 /*------------------------------------------------------------------------------
121 Public Methods
122 */
123 method vListView.Clear()
124 {
125 .gttree.clear()
126 .WinMsg( $LVM_DELETEALLITEMS )
127 }
128
129 method vListView.Edit()
130 {
131 if &(.Selected())
132 {
133 .SetFocus()
134 .WinMsg( $LVM_EDITLABELW, .Selected.Idx(), 0)
135 }
136 }
137
138 /*------------------------------------------------------------------------------
139 Properties
140 */
141 /*Свойство ustr Border - Get Set
142 Установить, получить наличие рамки у поля ввода
143 1 - рамка есть
144 0 - рамки нет
145 */
146 property vListView.Border( uint val )
147 {
148 .pBorder = val
149 uint style = GetWindowLong( this.hwnd, $GWL_EXSTYLE )
150 if val : style |= $WS_EX_CLIENTEDGE
151 else : style &= ~$WS_EX_CLIENTEDGE
152 SetWindowLong( this.hwnd, $GWL_EXSTYLE, style )
153 SetWindowPos( this.hwnd, 0, 0, 0, 0, 0, $SWP_FRAMECHANGED |
154 $SWP_NOACTIVATE | $SWP_NOZORDER | $SWP_NOMOVE | $SWP_NOSIZE )
155 }
156
157 property uint vListView.Border
158 {
159 //.pBorder = ?(GetWindowLong( this.hwnd, $GWL_EXSTYLE ) & $WS_EX_CLIENTEDGE,1,0)
160 return .pBorder
161 }
162
163 /*Свойство ustr ShowPlusMinus - Get Set
164 Установить, получить отображение кнопочки с крестиком/минусом отображающим
165 открытие ветки
166 1 - кнопка есть
167 0 - кнопок нет
168 *//*
169 property vListView.ShowPlusMinus( uint val )
170 {
171 .pShowPlusMinus = val
172 .SetStyle( $TVS_HASBUTTONS, val )
173 }
174
175 property uint vListView.ShowPlusMinus
176 {
177 return .pShowPlusMinus//.GetStyle( $TVS_HASBUTTONS )
178 }*/
179
180 /*Свойство ustr ShowLines - Get Set
181 Установить, получить отображение линеек слева от веток
182 1 - есть
183 0 - нет
184 *//*
185 property vListView.ShowLines( uint val )
186 {
187 .pShowLines = val
188 .SetStyle( $TVS_HASLINES , val )
189 }
190
191 property uint vListView.ShowLines
192 {
193 return .pShowLines//.GetStyle( $TVS_HASLINES )
194 }*/
195
196 /*Свойство ustr ShowRootLines - Get Set
197 Установить, получить отображение линеек у корневого элемента
198 открытие ветки
199 1 - есть
200 0 - нет
201 *//*
202 property vListView.ShowRootLines( uint val )
203 {
204 .pShowRootLines = val
205 .SetStyle( $TVS_LINESATROOT, val )
206 }
207
208 property uint vListView.ShowRootLines
209 {
210 return .pShowRootLines//.GetStyle( $TVS_LINESATROOT )
211 }*/
212
213 /*Свойство ustr ShowSelection - Get Set
214 Установить, получить отображение линеек слева от веток
215 1 - есть
216 0 - нет
217 */
218 property vListView.ShowSelection( uint val )
219 {
220 if .pShowSelection != val
221 {
222 .pShowSelection = val
223 .Virtual( $mReCreateWin )
224 }
225 //.SetStyle( $TVS_SHOWSELALWAYS, val )
226 }
227
228 property uint vListView.ShowSelection
229 {
230 return .pShowSelection//.GetStyle( $TVS_HASLINES )
231 }
232
233 /*Свойство ustr RowSelect - Get Set
234 Установить, получить отображение линеек слева от веток
235 1 - есть
236 0 - нет
237 *//*
238 property vListView.RowSelect( uint val )
239 {
240 .pRowSelect = val
241 .SetStyle( $TVS_FULLROWSELECT , val )
242 }
243
244 property uint vListView.RowSelect
245 {
246 return .pRowSelect//.GetStyle( $TVS_HASLINES )
247 }*/
248
249 /*Свойство ustr LabelEdit - Get Set
250 Установить, получить отображение линеек слева от веток
251 1 - есть
252 0 - нет
253 */
254 property vListView.LabelEdit( uint val )
255 {
256 .pLabelEdit = val
257 .SetStyle( $LVS_EDITLABELS , val )
258 }
259
260 property uint vListView.LabelEdit
261 {
262 return .pLabelEdit//.GetStyle( $TVS_HASLINES )
263 }
264
265 property uint LVItem.Idx
266 {
267 uint id
268 uint prev = &this
269 while prev = &prev->LVItem.Prev()
270 {
271 id++
272 }
273 return id
274 }
275
276 method LVItem.Del()
277 {
278
279 if &this == .param->listdata.listview->vListView.pSelected
280 {
281 uint newsel
282 newsel as .Next
283 if !&newsel
284 {
285 newsel as .Prev
286 }
287 //.param->listdata.listview->vListView.pSelected = 0
288 .param->listdata.listview->vListView.Selected = newsel
289 //print( "newsel =\( &newsel )\n" )
290 }
291 /*foreach child, this
292 {
293 child->LVItem.Del()
294 }*/
295 if &this && .param->listdata.listview
296 {
297 print( "DELETED \(.Idx)\n" )
298 .param->listdata.listview->vListView.WinMsg( $LVM_DELETEITEM, .Idx )
299
300 }
301 //if &this != &.param->treedata.treeview->vTreeView.gttree.root()
302 {
303 destroy( .param )
304 this.del()
305 }
306 }
307
308 /* Свойство ustr Label - Get Set
309 Устанавливает или определяет заголовок элемента дерева
310 */
311 property ustr LVItem.Label <result>
312 {
313 result.fromutf8( .get( "name" ) ).ptr()
314 }
315
316 property LVItem.Label( ustr val )
317 {
318 .set( "name", val.toutf8( "" ) )
319 .WinSet( $LVIF_TEXT )
320 }
321
322
323
324 method vListView.WinInsert( LVItem curitem )
325 {
326 uint id
327 LVITEM li
328
329 //uint thisdata as .param->listdata
330 li.pszText = curitem.Label.ptr()
331 li.iItem = curitem.Idx
332 /*uint prev as curitem.Prev()
333 if &prev
334 {
335
336 }*/
337 /**while
338 {
339 id++
340 } */
341 /*uint sorttype = .getuint( "sorttype" )
342 if sorttype & $TVSORT_SORT
343 {
344 print( "sort" )
345 ti.hInsertAfter = $TVI_SORT
346 }
347 else
348 {*/
349 /*uint prev as child.Prev
350 print( "insert prev= \( &prev )\n")
351 ti.hInsertAfter = ?( &prev, prev.param->treedata.handle, $TVI_FIRST )*/
352 //}
353 //ti.hParent = thisdata.handle
354 li.mask = $LVIF_TEXT | $LVIF_PARAM
355 li.lParam = &curitem
356 /*curitem.param->listdata.handle =*/
357 .WinMsg( $LVM_INSERTITEMW, 0, &li )
358
359 //print( "handle =\(curitem.param->listdata.handle)\n" )
360 //child.WinSet( $TVIF_STATE )
361 }
362
363 method LVItem vListView.InsertItem( ustr name, uint tag, LVItem after )
364 {
365 if &this
366 {
367 //uint thisdata as .param->treedata
368
369 uint newitem as .gttree.root()->LVItem.insertchild( "", after )->LVItem
370 uint newitemdata as new( listdata )->listdata
371 newitemdata.listview = &this
372 newitem.param = &newitemdata
373 newitem.set( "name", name.toutf8( "" ) )
374 newitem.setuint( "tag", tag )
375
376 /*uint sorttype = .getuint( "sorttype" )
377 print( "sort = \(sorttype)\n")
378 if sorttype & $TVSORT_SORT
379 {
380 //ti.hInsertAfter = $TVI_SORT
381 if sorttype == $TVSORT_SORTRECURSE
382 {
383 child.setuint( "sorttype", sorttype )
384 }
385 }*/
386 .WinInsert( newitem )
387
388 return newitem->LVItem
389 }
390 return 0->LVItem
391 }
392
393 method LVItem vListView.InsertFirst( ustr name, uint tag )
394 {
395 return this.InsertItem( name, tag, 0->LVItem )
396 }
397
398 method LVItem vListView.Append( ustr name, uint tag )
399 {
400 return this.InsertItem( name, tag, 0xFFFFFFFF->LVItem )
401 }
402
403 /*
404 method LVItem LVItem.index( uint idx )
405 {
406
407 return 0->LVItem
408 }
409 */
410 property LVItem vListView.Root
411 {
412 if &this
413 {
414 return .gttree.root()->LVItem//.items[0]
415 }
416 return 0->LVItem
417 }
418
419
420 method LVItem.WinSet( uint mask )
421 {
422 LVITEM item
423 uint state
424
425
426 item.mask = mask
427 //item.iItem = this.Idx
428 //if .getuint( "expanded" ) : state |= $TVIS_EXPANDED
429 // if .getuint( "bold" ) : state |= $TVIS_BOLD
430 //if .param->treedata.inselections { state |= $TVIS_SELECTED//$TVIS_DROPHILITED //| $TVIS_CUT
431 //item.state = state | $TVIS_EXPANDPARTIAL
432 // item.stateMask = $TVIS_BOLD
433
434 ustr val
435 item.pszText = val.fromutf8( .get( "name" ) ).ptr()
436 .param->listdata.listview->vListView.WinMsg( $LVM_SETITEMTEXTW, this.Idx, &item )
437 }
438
439
440
441 /* Свойство uint Expand - Get Set
442 Устанавливает или определяет открытие ветки
443 0 - ветка закрыта
444 1 - ветка открыта
445 */
446 /*property uint LVItem.Expanded
447 {
448 return .getuint( "expanded" )
449 }
450
451 property LVItem.Expanded( uint val )
452 {
453 if .getuint( "expanded" ) != val
454 {
455 .param->treedata.listview->vListView.WinMsg( $TVM_EXPAND, ?( val, $TVE_EXPAND, $TVE_COLLAPSE ), .param->treedata.handle )
456 .setuint( "expanded", val )
457 }
458 //.WinSet( $TVIF_STATE )
459 }
460 */
461
462 /* Свойство uint Tag - Get Set
463 Устанавливает или определяет пользовательский параметр элемента дерева
464 */
465 property uint LVItem.Tag
466 {
467 return .getuint( "tag" )
468 }
469
470 property LVItem.Tag( uint val )
471 {
472 print( "tag 1 \(val)\n" )
473 .setuint( "tag", val )
474 print( "tag 2\n" )
475 }
476
477 /* Свойство uint Bold - Get Set
478 Устанавливает или определяет пользовательский параметр элемента дерева
479 */
480 /*property uint LVItem.Bold
481 {
482 return .getuint( "bold" )
483 }
484
485 property LVItem.Bold( uint val )
486 {
487 .setuint( "bold", val )
488 .WinSet( $TVIF_STATE )
489 }
490 */
491 /* Свойство uint Checked - Get Set
492 Устанавливает или определяет пользовательский параметр элемента дерева
493 *//*
494 property uint LVItem.Checked
495 {
496 return .getuint( "checked" )
497 }
498
499 property LVItem.Checked( uint val )
500 {
501 .setuint( "checked", val )
502 //.WinSet( $TVIF_STATE )
503 }
504
505 /* Свойство uint SortTYpe - Get Set
506 Устанавливает или определяет пользовательский параметр элемента дерева
507 *//*
508 property uint LVItem.SortType
509 {
510 return .getuint( "sorttype" )
511 }
512
513 property LVItem.SortType( uint val )
514 {
515 .setuint( "sorttype", ?( val & $TVSORT_SORT, val, $TVSORT_NONE ))
516 if val & $TVSORT_SORT
517 {
518 .param->treedata.listview->vListView.WinMsg( $TVM_SORTCHILDREN, 0, .param->treedata.handle )
519 }
520 if val & $TVSORT_RECURSE
521 {
522 foreach child, this
523 {
524 child.SortType = val
525 }
526 }
527
528 //.WinSet( $TVIF_STATE )
529 }
530 */
531 /* Свойство uint Parent - Get
532 Определяет хозяина данной ветки, если ветка в корне то корень, если корень то 0
533 */
534 /*property LVItem LVItem.Parent
535 {
536 return this->gtitem.parent()->LVItem
537 }*/
538
539 /* Свойство uint Prev - Get
540 Определяет предыдущий элемент, если он есть, иначе 0
541 */
542 property LVItem LVItem.Prev
543 {
544 return this->gtitem.getprev()->LVItem
545 //return this->gtitem.getprev()->LVItem
546 }
547
548 /* Свойство uint Next - Get
549 Определяет предыдущий элемент, если он есть, иначе 0
550 */
551 property LVItem LVItem.Next
552 {
553 return this->gtitem.getnext()->LVItem
554 }
555
556 /* Свойство uint LastChild - Get
557 Определяет последний дочерний элемент, если он есть, иначе 0
558 */
559 property LVItem LVItem.LastChild
560 {
561 return this->gtitem.lastchild()->LVItem
562 }
563
564 /* Свойство uint Child - Get
565 Определяет первый дочерний элемент данной ветки, если ветка не имеет дочерних элементов, то 0
566 */
567 property LVItem LVItem.Child
568 {
569 uint res as this.child()
570 return res->LVItem
571 }
572
573
574
575 method LVItem.Update()
576 {
577 //uint owner as this.Parent()
578 //uint after as this.Prev
579
580 /*owner.*/
581 .param->listdata.listview->vListView.WinInsert( this )
582 }
583
584 method LVItem.MoveTo( LVItem dest, uint flag )
585 {
586 print( "idx \( .Idx ) \(dest.Idx)\n" )
587 /*uint root as .param->treedata.listview->vListView.Root
588 //print( "owner= \(?(&this.Parent()!=&root,this.Parent.Label.str(),"")) prev= \(?(&this.Prev(),this.Prev.Label.str(),"")) next= \(?(&this.Next(),this.Next.Label.str(),"")) dest= \(?(&dest,dest.Label.str(),""))\n" )*/
589 if &this.Next() != &dest
590 {
591 uint lv as .param->listdata.listview->vListView
592 lv.WinMsg( $LVM_DELETEITEM, .Idx, 0)
593
594 print( "idx \( .Idx ) \(dest.Idx)\n" )
595
596 this.move( dest, flag )
597 //print( "owner= \(?(&this.Parent()!=&root,this.Parent.Label.str(),"")) prev= \(?(&this.Prev(),this.Prev.Label.str(),"")) next= \(?(&this.Next(),this.Next.Label.str(),"")) \n" )
598 this.Update()
599 evparItemMoved evpIM
600 evpIM.SrcItem = &this
601 evpIM.DestItem = &dest
602 evpIM.Flag = flag
603 lv.OnItemMoved.run( evpIM )
604
605 }
606 }
607
608 /* Свойство uint Selected - Get Set
609 Устанавливает или определяет пользовательский параметр элемента дерева
610 */
611
612 /* Свойство uint Sorted - Get Set
613 Устанавливает или определяет должны ли сортироваться элементы в дереве
614 1 - элементы сортируются
615 0 - элементы не сортируются
616 *//*
617 property uint vListView.Sorted()
618 {
619 return this.pSorted
620 }
621
622 property vListView.Sorted( uint val)
623 {
624 if this.pSorted != val
625 {
626 this.pSorted = val
627 this.Root().SortType = ?( val, $TVSORT_SORTRECURSE, $TVSORT_NONE )
628
629 }
630 }
631 */
632 property LVItem vListView.Selected()
633 {
634 return this.pSelected->LVItem
635 }
636
637 property vListView.Selected( LVItem item )
638 {
639 if this.pSelected != &item
640 {
641
642 if &item
643 {
644
645 this.pSelected = &item
646 LVITEM li
647 //li.mask = $LVIF_STATE
648 //li.iItem = item.Idx
649
650 li.stateMask = $LVIS_SELECTED
651 li.state = $LVIS_SELECTED
652
653
654 //.WinMsg( $LVM_SETSELECTIONMARK, 0, item.param->listdata.idx )
655 .WinMsg( $LVM_SETITEMSTATE, item.Idx, &li )
656 }
657 else
658 {
659 //this.pSelected = &item
660 LVITEM li
661 li.stateMask = $LVIS_SELECTED
662 .WinMsg( $LVM_SETITEMSTATE, this.Selected.Idx, &li )
663 this.pSelected = 0
664 }
665 }
666 }
667
668
669 /*------------------------------------------------------------------------------
670 Virtual Methods
671 */
672 /*Виртуальный метод vListView vListView.mCreateWin - Создание окна
673 */
674 method vListView vListView.mCreateWin <alias=vListView_mCreateWin>()
675 {
676 uint exstyle //= $LVS_EX_FULLROWSELECT | $LVS_EX_GRIDLINES
677 uint style = $WS_CHILD | $WS_VISIBLE | $WS_CLIPSIBLINGS | /*$LVS_ICON*/$LVS_REPORT | $LVS_NOCOLUMNHEADER | $LVS_SINGLESEL
678 /*if .pShowPlusMinus : style |= $TVS_HASBUTTONS
679 if .pShowLines : style |= $TVS_HASLINES
680 if .pShowRootLines : style |= $TVS_LINESATROOT*/
681 if .pShowSelection : style |= $LVS_SHOWSELALWAYS
682 /*if .pRowSelect : style |= $TVS_FULLROWSELECT*/
683 if .pLabelEdit : style |= $LVS_EDITLABELS
684
685 if .pBorder : exstyle |= $WS_EX_CLIENTEDGE
686 this.CreateWin( "SysListView32".ustr(), exstyle, style )
687 this->vCtrl.mCreateWin()
688 // this.WinMsg( $WM_SETFONT, GetStockObject( $DEFAULT_GUI_FONT ) )
689 this.WinMsg( $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT /*| $LVS_EX_GRIDLINES*/, $LVS_EX_FULLROWSELECT )
690 LVCOLUMN col
691 col.mask = $LVCF_SUBITEM
692 this.WinMsg( $LVM_INSERTCOLUMNW, 0, &col )
693 return this
694 }
695
696 /*Виртуальный метод uint vListView.mWinNtf - обработка сообщений
697 */
698 method uint vListView.mWinNtf <alias=vListView_mWinNtf>( NMHDR ntf )
699 {
700 //print("ntf \(ntf.code) \($LVN_ITEMACTIVATE) \($LVN_FIRST)\n")
701 uint nmtv as ntf->NMLISTVIEW
702 switch ntf.code
703 {
704 /*case $LVN_ITEMACTIVATE
705 {
706 nmtv as NMITEMACTIVATE
707 this.pSelected = ?( nmtv.lParam, nmtv.lParam, 0 )//?( nmtv.itemNew, nmtv.itemNew.lParam, 0 )
708 print( "Activate \( this.pSelected )\n" )
709 //.OnSelect.Run( this, etvb )
710 }*/
711 case $LVN_ITEMCHANGED
712 {
713 if !( nmtv.uOldState & $LVIS_SELECTED ) && nmtv.uNewState & $LVIS_SELECTED
714 //if nmtv.uOldState & $LVIS_SELECTED != ( nmtv.uNewState & $LVIS_SELECTED )
715 {
716 //print( "changed \( .WinMsg( $LVM_GETNEXTITEM, -1, $LVNI_SELECTED/*<<16*/ ) )\n" )
717 LVITEM li
718 li.iItem = .WinMsg( $LVM_GETNEXTITEM, -1, $LVNI_SELECTED )
719 li.mask = $LVIF_PARAM
720 .WinMsg( $LVM_GETITEMW, 0, &li )
721 this.pSelected = li.lParam
722 evparTVAfter etva
723 etva.CurItem = this.pSelected
724 etva.sender = &this
725 .OnAfterSelect.Run( /*this,*/ etva )
726 }
727
728 /* this.pSelected = ?( nmtv.itemNew, nmtv.itemNew.lParam, 0 )
729
730 eventTVAfter etva
731 etva.CurItem = this.pSelected
732 .OnBeforeSelect.Run( this, etva )*/
733 }
734 case $LVN_ITEMCHANGING
735 {
736 /*if nmtv.uChanged & $LVIF_STATE
737 {
738 if nmtv.uOldState & $LVIS_SELECTED != ( nmtv.uNewState & $LVIS_SELECTED )
739 {
740 evparTVBefore etvb
741 etvb.CurItem = nmtv.lParam
742 .OnBeforeSelect.Run( etvb )
743 }
744 }*/
745 /* print( "items \(nmtv.iItem ) \(nmtv.uChanged ) \(nmtv.uOldState ) \(nmtv.uNewState ) \(nmtv.uChanged)
746 \n" )
747 LVITEM li
748 li.iItem = .WinMsg( $LVM_GETNEXTITEM, -1, $LVNI_SELECTED )
749 li.mask = $LVIF_PARAM
750 .WinMsg( $LVM_GETITEMW, 0, &li )
751 //print( "cursel= \(li.lParam)\n" )
752 return 0
753 if nmtv.uOldState & $LVIS_FOCUSED && !( nmtv.uNewState & $LVIS_FOCUSED )
754 {
755 .flgItemChanging = 1
756 print( "focus\n" )
757 }
758
759 elif nmtv.uOldState & $LVIS_SELECTED && !( nmtv.uNewState & $LVIS_SELECTED )
760 {
761 print( "pocus\n" )
762 evparTVBefore etvb
763 // print( "item \(nmtv.iItem )\n" )
764 if .flgItemChanging
765 {
766 etvb.CurItem = nmtv.lParam
767 }
768 else
769 {
770 etvb.CurItem = 0
771 }
772 .flgItemChanging = 0
773 .OnBeforeSelect.Run( etvb )
774 return etvb.flgCancel
775 }
776 */
777 }
778 /*case $TVN_ITEMEXPANDEDW
779 {
780 print( "Expanded \(&this) \(&ntf)\n" )
781 if nmtv.action & ( $TVE_COLLAPSE | $TVE_EXPAND )
782 {
783 nmtv.itemNew.lParam->LVItem.setuint( "expanded", nmtv.action & $TVE_EXPAND )
784 print( "Expanded\n" )
785 }
786
787 }
788 case $TVN_ITEMEXPANDINGW
789 {
790 print( "Expanding\n" )
791 }*/
792 case $LVN_BEGINLABELEDITW
793 {
794 evparTVEdit etve
795 etve.sender = &this
796 .OnBeforeEdit.Run( etve )
797 return etve.flgCancel
798 }
799 case $LVN_ENDLABELEDITW
800 {
801 nmtv as NMLVDISPINFO
802
803 evparTVEdit etve
804 //print( "len = \(nmtv.item.cchTextMax )\n" )
805 if nmtv.item.pszText
806 {
807 etve.NewLabel.copy( nmtv.item.pszText )
808 }
809 else
810 {
811 etve.flgCancel = 1
812 }
813
814 //print( "["+etve.NewLabel.str()+ "] \(nmtv.item.pszText) \(etve.flgCancel )\n" )
815
816 etve.sender = &this
817 .OnAfterEdit.Run( /*this,*/ etve )
818 if !etve.flgCancel
819 {
820 uint selected as .Selected
821 if &selected
822 {
823
824 selected.set( "name", etve.NewLabel.toutf8( "" ) )
825 }
826 return 1
827 }
828 }
829 case $LVN_BEGINDRAG
830 {
831 print( "BeginDrag\n" )
832 //.Selected = nmtv.lParam->LVItem
833 LVITEM lvitem
834 lvitem.stateMask = $LVIS_SELECTED
835 .WinMsg( $LVM_SETITEMSTATE, .Selected.Idx, &lvitem )
836 SetCapture( .hwnd );
837 .fDrag = 1
838 }/*
839 case $TVN_DELETEITEMW
840 {
841 print( "DEL\n" )
842 }*/
843 }
844 return 0
845 }
846
847 method uint vListView.mMouse <alias=vListView_mMouse>( evparMouse em )
848 {
849 switch em.evmtype
850 {
851 case $evmMove
852 {
853 if .fDrag
854 {
855
856 POINT point
857 uint destitem
858 LVHITTESTINFO lvht
859
860 lvht.pt.x = point.x = em.x
861 lvht.pt.y = point.y = em.y
862 destitem = .WinMsg( $LVM_HITTEST, 0, &lvht)
863 if destitem != -1 && destitem != .fOldDestItem
864 {
865 print( "DragMOve \(destitem)\n" )
866 LVITEM lvitem
867 //lvitem.mask = $LVIF_STATE
868 lvitem.stateMask = $LVIS_DROPHILITED
869 .WinMsg( $LVM_SETITEMSTATE, .fOldDestItem, &lvitem )
870 lvitem.state = $LVIS_DROPHILITED
871 .fOldDestItem = destitem
872 .WinMsg( $LVM_SETITEMSTATE, .fOldDestItem, &lvitem )
873 //.WinMsg( $TVM_EXPAND, $TVE_EXPAND, destitem )
874 SetCursor( App.cursorDrag )
875 }
876 else
877 {
878 if int( em.x ) > 0 && int( em.y ) > 0 && em.x < .clloc.width && em.y < .clloc.height
879 {
880 SetCursor( App.cursorDrag )
881 }
882 else
883 {
884 SetCursor( App.cursorNoDrag )
885 }
886 }
887 ClientToScreen( .hwnd, point )
888 //ImageList_DragMove( point.x, point.y )
889 }
890 }
891 case $evmLUp
892 {
893 uint dest
894 LVHITTESTINFO lvht
895 if .fDrag
896 {
897 uint destitem as LVItem
898 uint selected as .pSelected->LVItem
899
900 lvht.pt.x = em.x
901 lvht.pt.y = em.y
902 dest = .WinMsg( $LVM_HITTEST, 0, &lvht)
903
904 LVITEM lvitem
905 lvitem.stateMask = $LVIS_DROPHILITED
906 .WinMsg( $LVM_SETITEMSTATE, dest, &lvitem )
907 .WinMsg( $LVM_SETITEMSTATE, .fOldDestItem, &lvitem )
908 .fOldDestItem = -1
909
910 if dest != -1
911 {
912 LVITEM item
913 item.mask = $LVIF_PARAM
914 item.iItem = dest
915 .WinMsg( $LVM_GETITEMW, 0, &item )
916
917 destitem as item.lParam->LVItem
918 if &destitem
919 {
920 print( "listview selected \( selected.Idx ) \(destitem.Idx)\n" )
921 selected.MoveTo( destitem, $TREE_BEFORE )
922 }
923 //.WinMsg( $TVM_SELECTITEM, $TVGN_DROPHILITE, destitem )
924 }
925 elif int( em.x ) > 0 && int( em.y ) > 0 && em.x < .clloc.width && em.y < .clloc.height
926 {
927 selected.MoveTo( .Root, $TREE_LAST )
928 }
929
930 //ImageList_EndDrag( )
931 ReleaseCapture()
932 .Selected = selected
933 //.fDrag = 0
934 }
935 }
936 }
937 return this->vCtrl.mMouse( em )
938 }
939
940 method vListView.mPosChanging <alias=vListView_mPosChanging>( eventpos evp )
941 {
942 this->vCtrl.mPosChanging( evp )
943 LVCOLUMN col
944 col.mask = $LVCF_WIDTH
945 col.cx = this.clloc.width - 10
946 this.WinMsg( $LVM_SETCOLUMNW, 0, &col )
947 }
948 /*------------------------------------------------------------------------------
949 Registration
950 */
951 /*Системный метод vListView vListView.init - Инициализация объекта
952 */
953 method vListView vListView.init( )
954 {
955 this.pTypeId = vListView
956
957 this.pCanFocus = 1
958 this.pTabStop = 1
959 this.loc.width = 100
960 this.loc.height = 25
961 this.pBorder = 1
962 /*this.pShowPlusMinus = 1
963 this.pShowLines = 1
964 this.pShowRootLines = 1
965 uint itemdata as new( treedata )->treedata*/
966 //itemdata.listview = &this
967 //this.gttree.root().param = &itemdata
968
969
970 //this.items[0].listview = &this
971 //this.items[0].gti = &this.gti.root()
972 return this
973 }
974
975 method uint vListView.wmcapturechange <alias=vListView_wmcapturechanged>( winmsg wmsg )
976 {
977 if wmsg.lpar != .hwnd && .fDrag
978 {
979 SetCursor( App.cursorArrow )
980
981 LVITEM lvitem
982 lvitem.stateMask = $LVIS_SELECTED
983 lvitem.state = $LVIS_SELECTED
984 print( " selected \(.Selected.Idx )\n" )
985 .WinMsg( $LVM_SETITEMSTATE, .Selected.Idx, &lvitem )
986 //.WinMsg( $LVM_SELECTITEM, $TVGN_DROPHILITE, 0 )
987 .fDrag = 0
988 }
989 return 0
990 }
991
992 func init_vListView <entry>()
993 {
994 regcomp( vListView, "vListView", vCtrl, $vCtrl_last,
995 %{ %{$mCreateWin, vListView_mCreateWin},
996 %{$mWinNtf, vListView_mWinNtf },
997 %{$mMouse, vListView_mMouse },
998 %{$mPosChanging, vListView_mPosChanging }
999
1000 /*%{$mLangChanged, vListView_mLangChanged },
1001 %{$mSetName, vListView_mSetName}*/
1002 },
1003
1004 %{ %{ $WM_CAPTURECHANGED, vListView_wmcapturechanged }
1005 }
1006 )
1007
1008 ifdef $DESIGNING {
1009 cm.AddComp( vListView, 1, "Windows", "listview" )
1010
1011 cm.AddProps( vListView, %{
1012 /*"TabOrder", uint, 0,
1013 "Border", uint, 0,
1014 "ShowPlusMinus", uint, 0,
1015 "ShowLines", uint, 0,
1016 "ShowRootLines", uint, 0,*/
1017 "ShowSelection", uint, 0/*,
1018 "RowSelect", uint, 0,
1019 "LabelEdit", uint, 0
1020 */
1021 })
1022 cm.AddEvents( vListView, %{
1023 /*"OnBeforeEdit", "eventTVEdit",
1024 "OnAfterEdit", "eventTVEdit",
1025 "OnBeforeSelect", "",*/
1026 "OnAfterSelect", "evparTVAfter"
1027 /*"OnBeforeExpand", "",
1028 "OnAfterExpand", "",
1029 "OnBeforeCollapse", "",
1030 "OnAfterCollapse", ""
1031 */
1032 })
1033 }
1034
1035 }