1 include {
2 "form.g"
3 "listview.g"
4 }
5
6
7 /*define {
8 mSelectComp = $vForm_last
9
10 vCompEditForm_last
11 }
12 */
13
14 type vTabDesign <inherit=vForm>
15 {
16 vListView lv
17 vBtn bAdd
18 vBtn bAddChild
19 vBtn bDel
20 uint flgnew
21 uint curitem
22 uint flgediting
23
24 uint Tab
25 uint MainForm
26
27 //eventQueryCreate OnQueryCreate
28 oneventpos OnQueryCreate
29 evEvent OnQuerySelect
30 evEvent OnDestroy
31 }
32
33
34 method vTabDesign.NewItem( /*LVItem newitem*/LVItem curitem )
35 {
36 .lv.Selected = .lv.InsertItem( "New".ustr(), 0, curitem )
37 .lv.Selected.Tag = 0
38
39 .flgnew = 1
40 .lv.Edit()
41 uint he = FindWindowEx( .lv.hwnd, 0, "Edit".ustr().ptr(), 0 )
42 if he
43 {
44 .flgediting = 1
45 .lv.WinMsg( $WM_COMMAND, $EN_UPDATE << 16, he )
46 }
47 print( "select \(.lv.Selected.Tag) \(&.lv.Selected())\n" )
48 }
49
50 method vTabDesign.bAdd_click <alias=vTabDesign_bAdd_click> ( evparEvent ev )
51 {
52 /*uint curitem
53 curitem as this.lv.Selected()
54 if &curitem
55 {
56 curitem as curitem.Parent
57 }
58 if !&curitem
59 {
60 curitem as .lv.Root
61 }
62 .NewItem( curitem.AppendChild( "New".ustr(), 0 ) )*/
63 .NewItem( 0xFFFFFFFF->LVItem )
64 }
65
66 method vTabDesign.bIns_click <alias=vTabDesign_bIns_click> ( evparEvent ev )
67 {
68
69
70 uint curitem, previtem as LVItem
71 curitem as this.lv.Selected()
72 if &curitem
73 {
74 curitem as curitem.Prev
75 }
76 .NewItem( curitem )
77 /*.NewItem( curitem.InsertChild( "New".ustr(), 0, previtem ))*/
78 }
79
80
81 method vTabDesign.bDel_click <alias=vTabDesign_bDel_click> ( evparEvent ev )
82 {
83 uint curitem
84 curitem as this.lv.Selected()
85 if &curitem
86 {
87 uint comp as curitem.Tag->vComp
88 curitem.Del()
89 if &comp//curitem.Tag
90 {
91 comp.DestroyComp()
92 //curitem.Tag->vComp.DestroyComp()
93 }
94
95 }
96 }
97
98 method vTabDesign.lv_AfterEdit <alias=vTabDesign_lv_AfterEdit> ( /*vComp sender,*/ evparTVEdit etve )
99 {
100 .flgediting = 0
101 uint curLVItem as .lv.Selected
102
103 if .flgnew
104 {
105
106 .flgnew = 0
107 if etve.flgCancel || !*etve.NewLabel
108 {
109 etve.flgCancel = 1
110 curLVItem.Del()
111 }
112 else
113 {
114
115 /*uint owner as vCustomMenu
116 if (&curLVItem.Parent()) && (&curLVItem.Parent()) != (&.lv.Root())
117 {
118 owner as curLVItem.Parent.Tag
119 }
120 else
121 {
122 owner as .Menu
123 }*/
124
125 evparQueryCreate eQC
126 eQC.Owner = this.Tab
127 eQC.TypeId = vTabItem
128 print( "yes \(this.Tab->vComp.Name)\n" )
129 print( "sssssssssssselect \(.lv.Selected.Tag) \(&.lv.Selected())\n" )
130 .OnQueryCreate.run( eQC )
131 print( "sssssssssssselect \(.lv.Selected.Tag) \(&.lv.Selected())\n" )
132 print( "yes 11\n" )
133 uint cim as eQC.NewComp->vTabItem
134 //uint cim as this.Tab->vTab.CreateComp( vTabItem )->vTabItem
135 print( "yes 12\n" )
136 if &cim
137 {
138 cim.Index = .lv.Selected.Idx
139 print( "yes 13\n" )
140 cim.Caption = etve.NewLabel// curLVItem.Label
141 print( "yes 14 \(curLVItem.Tag) \(&cim) \(&curLVItem)\n" )
142 curLVItem.Tag = &cim
143 print( "yes 15 \(curLVItem.Tag)\n" )
144 .lv.Selected = 0->LVItem
145 .lv.Selected = curLVItem
146 }
147 else
148 {
149 etve.flgCancel = 1
150 curLVItem.Del()
151 }
152 print( "yes 20\n" )
153 }
154 }
155 else
156 {
157 if !etve.flgCancel
158 {
159 uint tabitem as .lv.Selected.Tag->vTabItem
160 if &tabitem
161 {
162 tabitem.Caption = etve.NewLabel
163 evparValUint eu
164 eu.val = &tabitem
165 .OnQuerySelect.run( eu )
166 }
167 }
168 }
169 }
170
171 method vTabDesign.lv_Key <alias=vTabDesign_lv_Key>( /*vComp sender,*/ evparKey ek )
172 {
173 if ek.evktype == $evkDown
174 {
175 switch ek.key
176 {
177 case $VK_INSERT: .bIns_click( 0->evparEvent )
178 case $VK_DELETE: .bDel_click( 0->evparEvent )
179 case $VK_DOWN
180 {
181 if !&(.lv.Selected()) || ( &(.lv.Selected()) == &(.lv.Root.LastChild()))
182 {
183 .bAdd_click( 0->evparEvent )
184 }
185 }
186 }
187 }
188 }
189
190 /*method vTabDesign.lv_BeforeSelect <alias=TabDesign_lv_BeforeSelect>( evparTVBefore etvb )
191 {
192 print( "BeforeSelect \(etvb.CurItem) \(*.lv.gttree.root())\n" )
193 if ( !etvb.CurItem && *.lv.gttree.root() ) ||
194 .flgediting
195 {
196 etvb.flgCancel = 1
197 }
198 }*/
199
200 method vTabDesign.lv_Select <alias=TabDesign_lv_Select>( /*vComp sender,*/ evparTVAfter etva )
201 {
202 print( "sel1\n" )
203 if etva.CurItem
204 {
205 print( "sel2 \(etva.CurItem->LVItem.Idx)\n" )
206 uint comp
207 if comp = etva.CurItem->LVItem.Tag
208 {
209 print( "sel3 \(comp) \( comp->vTabItem.Index)\n" )
210 evparValUint eu
211 eu.val = comp
212 print( "comp \(comp->vComp.Name )\n" )
213 comp->vTabItem.Owner->vTab.CurIndex = comp->vTabItem.Index
214 print( "AAAAAAAAAAAAAAAAAAAAAAAAa\n" )
215 .OnQuerySelect.run( eu )
216 }
217 }
218 }
219
220 method vTabDesign.lv_ItemMoved <alias=TabDesign_lv_ItemMoved>( evparItemMoved evpIM )
221 {
222 uint cur as evpIM.SrcItem->LVItem.Tag->vTabItem
223 switch evpIM.Flag
224 {
225 case $TREE_FIRST :
226 case $TREE_LAST
227 {
228 cur.Index = *cur.Owner->vTab.Comps - 1
229 }
230 case $TREE_AFTER :
231 case $TREE_BEFORE
232 {
233 if evpIM.DestItem
234 {
235 uint next as evpIM.DestItem->LVItem.Tag->vTabItem
236 cur.Index = *cur.Owner->vTab.Comps - 1
237 if next
238 {
239 print( "OLD \(cur.Index ) NEW \( next.Index)\n" )
240 cur.Index = next.Index //- 1
241 }
242 }
243 }
244 }
245 }
246
247 method vTabDesign.CloseQuery <alias=TabDesign_CloseQuery>( evparQuery evpQ )
248 {
249 evpQ.flgCancel = 1
250 this.DestroyComp()
251 }
252
253 method vTabDesign vTabDesign.mCreateWin <alias=vTabDesign_mCreateWin>( )
254 {
255 this->vForm.mCreateWin()
256 ustr ustmp
257 uint comp
258 comp as this
259 with comp
260 {
261 .Caption="Tab Designer".ustr()
262 .Height=300
263 .Visible=0
264 .Width=200
265 .OnCloseQuery.Set( this, TabDesign_CloseQuery )
266 }
267 comp as this.lv
268 comp.Owner = this
269 with comp
270 {
271 .HorzAlign = $alhClient
272 .VertAlign = $alvTopBottom
273 .Bottom = 25
274 .ShowSelection = 1
275 .LabelEdit = 1
276 .OnAfterEdit.Set( this, vTabDesign_lv_AfterEdit )
277 .OnKey.Set( this, vTabDesign_lv_Key )
278 //.OnBeforeSelect.Set( this, TabDesign_lv_BeforeSelect )
279 .OnAfterSelect.Set( this, TabDesign_lv_Select )
280 .OnItemMoved.Set( this, TabDesign_lv_ItemMoved )
281 }
282 uint left = 0
283 uint width = 70
284 comp as this.bAdd
285 comp.Owner = this
286 with comp
287 {
288 .VertAlign = $alvBottom
289 .Caption = "New".ustr()
290 .Bottom = 0
291 .Left = left
292 .Width = width
293 left += .Width
294 .OnClick.Set(this,vTabDesign_bAdd_click)
295 }
296 comp as this.bDel
297 comp.Owner = this
298 with comp
299 {
300 .VertAlign = $alvBottom
301 .Caption = "Delete".ustr()
302 .Bottom = 0
303 .Left = left
304 .Width = width
305 left += .Width
306 .OnClick.Set(this,vTabDesign_bDel_click)
307 }
308 //print( "create des 10\n" )*/
309 return this
310 }
311
312 method vTabDesign vTabDesign.init( )
313 {
314 this.pTypeId = vTabDesign
315 return this
316 }
317
318 method vTabDesign.mSelectComp <alias=vTabDesign_mSelectComp> ( vComp newcomp )
319 {
320 if &newcomp
321 {
322 uint curcomp as newcomp
323 while &curcomp
324 {
325 if &curcomp == this.Tab
326 {
327 uint lvitem as .lv.Root().Child()
328 while &lvitem
329 {
330 if lvitem.Tag == &newcomp
331 {
332 lvitem.Label = newcomp->vTabItem.Caption
333 }
334 lvitem as lvitem.Next()
335 }
336 return
337 }
338 curcomp as curcomp.Owner
339 }
340 this.DestroyComp()
341 }
342 }
343
344 method vTab.ToTabDesign( vTabDesign tdes )
345 {
346 uint i
347 fornum i, *.Comps
348 {
349 uint tabitem as .Comps[i]->vTabItem
350 tdes.lv.Append( tabitem.Caption, &tabitem )
351 }
352 }
353
354
355
356 method vForm vTab.Design( vForm mainform, uint QueryCreate, QuerySelect, CompEditDelete )
357 {
358 uint win
359
360 win as 0->vComp.CreateComp( vTabDesign )->vTabDesign
361 win.flgpopup = 1
362 win.Owner = mainform
363
364 win.OnQueryCreate.Set( mainform, QueryCreate )
365 win.OnQuerySelect.Set( mainform, QuerySelect )
366
367 win.OnDestroy.Set( mainform, CompEditDelete )
368
369 win.Visible = 1
370
371 win.Tab = &this
372
373 this.ToTabDesign( win)
374
375 return win
376 }
377
378 method vTabDesign.mPreDel <alias=vTabDesign_mPreDel>
379 {
380 .OnDestroy.run( )
381 this->vForm.mPreDel()
382
383 }
384
385 func init_vTabDesign <entry>()
386 {
387 regcomp( vTabDesign, "vTabDesign", vForm, $vCompEditForm_last,
388 %{ %{$mCreateWin, vTabDesign_mCreateWin},
389 %{$mSelectComp, vTabDesign_mSelectComp},
390 %{$mPreDel, vTabDesign_mPreDel }},
391 0->collection )
392 }
Edit