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: visedit.manrpops 09.08.07 0.0.A.
11 *
12 * Author: Alexander Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15 define {
16 PROP_LOADAFTERCHILD = 0x1 //PropFlags - загрузать данной свойство после создания дочерних элементов
17
18
19 PI_SIMPLE = 0x000
20 PI_UPDOWN = 0x001
21 PI_DLG = 0x002
22 PI_SEL = 0x100
23
24 PI_DEFVAL = 0x1000000
25 PI_LIST = 0x1000
26 }
27 //Описание возможного числового значения
28 type CompEnumVal {
29 str Name //Имя значения
30 uint Val //Непосредственное значение
31 }
32
33 //Описание свойства
34 type CompProp {
35 str PropName //Имя свойства
36 uint PropType //Тип свойства
37 uint PropFlags //Флаги свойства
38 uint AddrGet //Адрес get метода
39 uint AddrSet //Адрес set метода
40 uint Vals //Список возможных значений если нужен - arr of CompEnumVal
41 ustr DefVal //Значение по умолчанию
42 }
43
44 //Описание события
45 type CompEvent {
46 str EventName //Имя события
47 str EventType //Тип события
48 uint EventId
49 }
50
51 //Описание компонента
52 type CompDescr{
53 uint TypeId //Тип компонента
54 str TypeName //Имя типа
55 str File //Имя модуля содержащее данный компонент
56 uint VisComp //Данный компонент будет отображаться в списке добавляемых компонентов
57 arr Props of CompProp //Список свойств
58 arr Events of CompEvent //Список событий
59 }
60
61 //Менеджер свойств
62 type VEManProps{
63 arr Descrs of CompDescr //Список компонентов
64 }
65
66 type EventDescr{
67 //uint idmethod //Идентификатор метода
68 str MethodName //Имя метода
69 str EventType //Тип параметра сообщения
70 uint CompCount //Количество подключенных компонентов
71 }
72 //Менеджер событий
73 type VEManEvents{
74 arr Descrs of EventDescr
75 }
76
77 //Элемент списка свойств/событий
78 type PropItem
79 {
80 ustr Name //Имя свойства/события
81 ustr Value //Значение свойства/события
82 uint Flags //Флаги PI_*
83 }
84
85 global {
86 VEManProps cm
87 VEManEvents ManEvents
88 }
89
90 extern {
91 method str CompProp.GetVal <result> ( vComp comp )
92 }
93
94 //Найти описание компонента по идентификатору типу
95 method CompDescr VEManProps.GetCompDescr( uint typeid )
96 {
97 uint descr
98 uint i
99
100 fornum i = 0, *this.Descrs
101 {
102 descr as this.Descrs[i]
103 if descr.TypeId == typeid
104 {
105 return descr
106 }
107 }
108 return 0->CompDescr
109 }
110
111 func int sortstr( CompProp left, right )
112 {
113
114 //return scmpignore( left.Name.ptr(), right.Name.ptr())
115 return strcmpign( left.PropName.ptr(), right.PropName.ptr() )
116 }
117
118 //Найти событие в данном описании
119 method CompEvent CompDescr.FindEvent( str Name )
120 {
121 uint i
122 fornum i=0, *this.Events
123 {
124 if this.Events[i].EventName == Name
125 {
126 return this.Events[i]
127 }
128 }
129 return 0->CompEvent
130 }
131
132 //Найти свойство в данном описании
133 method CompProp CompDescr.FindProp( str Name )
134 {
135 uint i
136 fornum i=0, *this.Props
137 {
138 if this.Props[i].PropName == Name
139 {
140 return this.Props[i]
141 }
142 }
143 return 0->CompProp
144 }
145
146
147
148 //Добавить новый тип компонента
149 method VEManProps.AddComp( uint typeid, uint viscomp, str group, str file )
150 {
151 uint i
152 uint fnc
153 uint descr as this.Descrs[this.Descrs.expand(1)]
154 uint typedef as gettypedef( typeid )
155 descr.TypeName = typedef.TypeName
156 descr.TypeId = typeid
157 descr.VisComp = viscomp
158 descr.File = file
159
160 //Получение свойств наследуемых свойств объекта
161 while typedef
162 {
163 uint inhtypeid, inh
164 if inhtypeid = typedef.InheritTypeId
165 {
166 uint inh as this.GetCompDescr( inhtypeid )
167 if inh
168 {
169 descr.Props.expand( *inh.Props )
170 fornum i=0, *inh.Props
171 {
172 uint left as descr.Props[i]
173 uint right as inh.Props[i]
174 left.PropName = right.PropName
175 left.PropType = right.PropType
176 left.AddrGet = right.AddrGet
177 left.AddrSet = right.AddrSet
178 left.Vals = right.Vals
179 left.DefVal = right.DefVal
180 }
181 descr.Events.expand( *inh.Events )
182 fornum i=0, *inh.Events
183 {
184 uint left as descr.Events[i]
185 uint right as inh.Events[i]
186 left.EventName = right.EventName
187 left.EventType = right.EventType
188 left.EventId = right.EventId
189 }
190 break
191 }
192 typedef as gettypedef( inhtypeid )
193 }
194 else
195 {
196 break
197 }
198 }
199
200 /*
201 if typedef.InheritTypeId
202 {
203 uint inh as this.GetCompDescr( typedef.InheritTypeId )
204 if inh
205 {
206 descr.Props.expand( *inh.Props )
207 fornum i=0, *inh.Props
208 {
209 uint left as descr.Props[i]
210 uint right as inh.Props[i]
211 left.PropName = right.PropName
212 left.PropType = right.PropType
213 left.AddrGet = right.AddrGet
214 left.AddrSet = right.AddrSet
215 left.Vals = right.Vals
216 left.DefVal = right.DefVal
217 }
218 descr.Events.expand( *inh.Events )
219 fornum i=0, *inh.Events
220 {
221 uint left as descr.Events[i]
222 uint right as inh.Events[i]
223 left.EventName = right.EventName
224 left.EventType = right.EventType
225 left.EventId = right.EventId
226 }
227 }
228
229 }*/
230
231 /*fnc = getid( "mRegProps", 1, %{TypeId, uint, VEManProps} )
232 if fnc : fnc->func( 0, TypeId, this )
233 */
234 //Сортировка
235
236 // fnc = getid( "getevents", 1, %{TypeId, uint, VEManProps} )
237 // if fnc : fnc->func( 0, TypeId, this )
238 // descr.Events.sort(&sortstr)
239
240 //Получение значений свойств по умолчанию
241 uint excomp = new( typeid )//&newcomp( TypeId, 0->vComp ) //создание временного объекта
242 //print( "descr \(typeid) \(*descr.Props )\n" )
243 fornum i = 0, *descr.Props
244 {
245 descr.Props[i].DefVal = descr.Props[i].GetVal( excomp->vComp )
246 }
247 destroy( excomp ) //удаление временного объекта
248
249 }
250
251
252 method VEManProps.AddComp( uint typeid )
253 {
254 this.AddComp( typeid, 0, "", "" )
255 }
256
257 //Добавить свойства
258 method VEManProps.AddProps( uint TypeId, collection col )
259 {
260 uint comp as this.GetCompDescr( TypeId )
261 uint prop
262 uint i
263 if &comp
264 {
265 i = 0
266 while i < *col
267 {
268 prop as comp.Props[comp.Props.expand(1)]
269 prop.PropName = col[i++]->str
270 prop.PropType = col[i++]
271 prop.PropFlags = col[i++]
272 prop.AddrGet = getid( prop.PropName, 1, %{TypeId} )
273 prop.AddrSet = getid( prop.PropName, 1, %{TypeId, prop.PropType} )
274 //print( p.Name + " \(p.TypeId)\n" )
275 }
276 //print( "START SORT \(*descr.Props)\n" )
277 comp.Props.sort(&sortstr)
278 }
279 }
280
281 //Добавить перечисление возможных значений
282 method VEManProps.AddPropVals( uint TypeId, str propName, collection col )
283 {
284
285 uint comp as this.GetCompDescr( TypeId )
286 if &comp
287 {
288 uint prop as comp.FindProp( propName )
289 if &prop
290 {
291 if !prop.Vals
292 {
293 prop.Vals = new( arr )
294 prop.Vals->arr.oftype( CompEnumVal )
295 uint ar = prop.Vals
296 ar as (arr[] of CompEnumVal)
297 ar.expand( *col>>1 )
298 uint i, j
299 while i < *col
300 {
301 //print( "col=\(col.Val(i)->str)\n" )
302 ar[j].Name = col[i++]->str
303 ar[j++].Val = col[i++]
304 }
305 }
306 }
307 }
308 }
309
310
311 //Добавить события
312 method VEManProps.AddEvents( uint TypeId, collection col )
313 {
314 uint comp as this.GetCompDescr( TypeId )
315 uint event
316 uint i
317 if &comp
318 {
319 i = 0
320 uint id = *comp.Events
321 while i < *col
322 {
323 event as comp.Events[comp.Events.expand(1)]
324 event.EventName = col[i++]->str
325 event.EventType = col[i++]->str
326 event.EventId = id++
327 //print( "addevents " + event.Name + " \(event.evtype)\n" )
328 }
329 }
330 }
331
332
333 method CompProp.delete
334 {
335 if this.Vals
336 {
337 destroy( &(this.Vals->arr[] of CompEnumVal) )
338 }
339 }
340
341 //Получить имя значения перечисления
342 method str CompProp.GetEnumName <result>( uint Val )
343 {
344 if this.Vals
345 {
346 uint ar = this.Vals
347 uint i
348 ar as (arr[] of CompEnumVal)
349 fornum i=0, *ar
350 {
351 if ar[i].Val == Val
352 {
353 result = ar[i].Name
354 return
355 }
356 }
357 }
358 }
359
360 //Получить значение перечисления по имени
361 method uint CompProp.GetEnumVal ( str Name, uint res )
362 {
363 if this.Vals
364 {
365 uint ar = this.Vals
366 uint i
367 ar as (arr[] of CompEnumVal)
368 fornum i=0, *ar
369 {
370 if ar[i].Name == Name
371 {
372 res->uint = ar[i].Val
373 return 1
374 }
375 }
376 }
377 return 0
378 }
379
380 //Получить значение свойства
381 method ustr CompProp.GetVal <result> ( vComp comp )
382 {
383 if this.AddrGet
384 {
385 if this.PropType == ustr
386 {
387 result = (this.AddrGet->func( comp, "" ))->ustr
388 }
389 elif this.PropType == uint || this.PropType == int
390 {
391 int z = (this.AddrGet->func( comp ))
392 if this.Vals
393 {
394 result = this.GetEnumName(z)
395 }
396 else
397 {
398 result = "\(z)"
399 }
400 }
401 elif this.PropType == str
402 {
403 result = (this.AddrGet->func( comp, "" ))->str
404 }
405 }
406 }
407
408 //Установить значение свойства
409 method CompProp.SetVal ( vComp comp, ustr val )
410 {
411 if .AddrSet
412 {
413 if .PropType == uint || .PropType == int
414 {
415 uint z = val.str().uint()
416 if .Vals
417 {
418 if .GetEnumVal( val.str(), &z ) : .AddrSet->func( comp, z )
419 }
420 else : .AddrSet->func( comp, z)
421 }
422 elif .PropType == ustr
423 {
424 .AddrSet->func( comp, val )
425 }
426 elif .PropType == str
427 {
428 .AddrSet->func( comp, val.str() )
429 }
430 }
431 }
432
433 method ustr CompEvent.GetVal <result> ( vComp comp )
434 {
435 //print( "event.GetVal 1 \(this.EventId)\n" )
436 uint index = comp.des1->arr of uint[this.EventId]
437 //print( "event.GetVal 2 \(index)\n" )
438 if index
439 {
440 result = ManEvents.Descrs[index].MethodName
441 }
442 //print( "event.GetVal 10\n" )
443 }
444
445 define
446 {
447 EVENT_DEL = 1
448 EVENT_NEW = 2
449 EVENT_RENAME = 4
450 }
451 method uint CompEvent.SetVal( vComp comp, ustr val )
452 {
453 uint setres
454 //print( "event.SetVal 1\n" )
455 if val != .GetVal( comp )
456 {
457 uint newindex = 0
458 uint oldindex
459 uint i
460 fornum i = 1, *ManEvents.Descrs
461 {
462 uint descr as ManEvents.Descrs[i]
463 if descr.MethodName == val.str()
464 {
465 if descr.EventType == .EventType
466 {
467 newindex = i
468 break
469 }
470 return 0
471 }
472 }
473
474 oldindex = comp.des1->arr of uint[this.EventId]
475
476 //index = findevent( val, .EventType )
477 if *val
478 {
479 if !newindex
480 {
481 if oldindex
482 {
483 newindex = oldindex
484 oldindex = 0
485 setres |= $EVENT_RENAME
486 }
487 else
488 {
489 newindex = ManEvents.Descrs.expand( 1 )
490 setres |= $EVENT_NEW
491 //comp.des1->arr of uint[this.EventId] = newindex
492 //ManEvents.Descrs[newindex].CompCount++
493 }
494 ManEvents.Descrs[newindex].MethodName = val
495 ManEvents.Descrs[newindex].EventType = .EventType
496 }
497 //else
498 if !( setres & $EVENT_RENAME )
499 {
500 comp.des1->arr of uint[this.EventId] = newindex
501 ManEvents.Descrs[newindex].CompCount++
502 }
503 }
504 else
505 {
506 comp.des1->arr of uint[this.EventId] = 0
507 }
508 if oldindex
509 {
510 ManEvents.Descrs[oldindex].CompCount--
511 if !ManEvents.Descrs[oldindex].CompCount
512 {
513 setres |= $EVENT_DEL
514 }
515 }
516 }
517 return setres
518 //print( "event.SetVal 10\n" )
519 }
520
521
522 //Получить список свойств для данной компоненты
523 method VEManProps.GetPropList( vComp comp, arr arp of PropItem, are of PropItem )
524 {
525 arp.clear()
526 are.clear()
527 uint descr as this.GetCompDescr( comp.TypeId )
528 if &descr
529 {
530 arp.expand( *descr.Props )
531 uint i
532 foreach item, arp
533 {
534 uint prop as descr.Props[i++]
535 item.Name = prop.PropName
536 item.Value = prop.GetVal( comp )
537 if item.Value == prop.DefVal
538 {
539 item.Flags |= $PI_DEFVAL
540 }
541 if prop.Vals : item.Flags |= $PI_LIST
542
543 }
544 are.expand( *descr.Events )
545 //print( " GETEVENT\n" )
546 i = 0
547 foreach item, are
548 {
549
550 uint event as descr.Events[i]
551 item.Name = event.EventName
552 //print( "eventname = \(event.EventName)\n" )
553
554 item.Value = event.GetVal( comp )
555 /*if item.Value == prop.DefVal
556 {
557 item.Flags |= $PI_DEFVAL
558 }*/
559 item.Flags |= $PI_LIST
560
561 i++
562 }
563 }
564 }
565
566