1 include {
2 "gena.g"
3 }
4
5 method vComp.GetCompInclude ( hash h )
6 {
7 uint descr as cm.GetCompDescr( this.TypeId )
8 if &descr
9 {
10 h.create( descr.File )
11 }
12 uint i
13 fornum i=0, *this.Comps
14 {
15 if this.Comps[i]->vComp.p_designing
16 {
17 this.Comps[i]->vComp.GetCompInclude( h )
18 }
19 }
20 }
21
22
23 method str myform.GetInclude <result> ()
24 {
25 hash h
26 .edform->vComp.GetCompInclude( h )
27 result@"include {\n\t\"app.g\"\n"
28 h.del( "" )
29 foreach key, h.keys
30 {
31 //print( key + "\n" )
32 result@"\t\""@key@".g\"\n"
33 }
34 /* result = "include {
35 $\"btn.g\"
36 $\"panel.g\"
37 $\"edit.g\"
38 $\"menu.g\"
39 $\"scrollbox.g\"
40 $\"tab.g\"
41 "*/
42 }
43
44 method str vComp.GetListComps <result>
45 {
46 uint i
47 fornum i=0, *this.Comps
48 {
49 if this.Comps[i]->vComp.p_designing
50 {
51 result@"\t"@this.Comps[i]->vComp.TypeName@"\t"@this.Comps[i]->vComp.Name@"\n"
52 result@this.Comps[i]->vComp.GetListComps()
53 }
54 }
55 }
56
57 method str myform.GetForm <result> ()
58 {
59 result = "type v\(.edform->vComp.Name) <inherit=vForm> {
60 \(.edform->vComp.GetListComps()) "
61 }
62
63 method myform.checkgffile
64 {
65 //print( "PREPRECHECK \n" )
66
67 if .flgsaved && !.flggfchanged
68 {
69 file f
70 filetime ft
71 //print( "PRECHECK \n" )
72 if f.open( .filename + ".gf", 1/*$OP_READONLY*/ )
73 {
74 f.gettime( ft )
75 f.close()
76 //print( "CHECK \n" )
77 if ft != .ftgf
78 {
79 //print( "CHECK READ \n" )
80 .gffile.read( .filename + ".gf" )
81 .ftgf = ft
82 }
83 }
84 }
85 }
86
87 method myform.GFSetHeader( str src )
88 {
89
90 //print( "set1\n" )
91 //src.read( /*this.srcfile + ".gf"*/"\(.edform->vComp.Name).gf" )
92 if !replcode( src, "include", this.GetInclude() ) : print( "ERROR\n" )
93 if !replcode( src, "form", this.GetForm() ) : print( "ERROR\n" )
94 //if !replcode( src, "includeinit", "include { $\"\(.filename).gi" ) : print( "ERROR\n" )
95 //print( "set10\n" )
96 //src.write( /*this.srcfile + ".gf"*/"\(.edform->vComp.Name).gf" )
97 }
98
99 method myform.GFSetHeaderf()
100 {
101 .checkgffile()
102 .flgchanged = 1
103 .flggfchanged = 1
104 //str src
105 //src.read( /*this.srcfile + ".gf"*/"\(.edform->vComp.Name).gf" )
106 this.GFSetHeader( .gffile )
107
108 //src.write( /*this.srcfile + ".gf"*/"\(.edform->vComp.Name).gf" )
109 }
110
111 method myform.GFSetInit( str src )
112 {
113 delcode( src, "includeinit" )
114 inscode( src, "includeinit", "include { $\"\(.filename).gi\" \l}", "" )
115 }
116
117 method myform.GFSetMethod( str src, str oldname, newname, typename )
118 {
119 str labo = "method \( oldname ) \( typename )"
120 str labn = "method \( newname ) \( typename )"
121 str code = "method uint v\(.edform->vComp.Name).\(newname) <alias=\(.edform->vComp.Name)_\(newname)>( \(typename) evn )"
122 if !replcode( src, labo, labn, code )
123 {
124 inscode( src, labn, code, "{\l\lreturn 0\l}\l" )
125 }
126 }
127
128 method myform.GFSetMethodf( str oldname, newname, typename )
129 {
130 //str src
131 //src.read( /*this.srcfile + ".gf"*/"\(.edform->vComp.Name).gf" )
132 .checkgffile()
133 .flgchanged = 1
134 .flggfchanged = 1
135 this.GFSetMethod( .gffile, oldname, newname, typename )
136 //src.write( /*this.srcfile + ".gf"*/"\(.edform->vComp.Name).gf" )
137 }
138
139 /*method myform.GFSetAll
140 {
141 str src
142 src.read( this.srcfile + ".gf" )
143
144 this.GFSetHeader( src )
145 fornum
146 {
147 setmethod( )
148 }
149 src.write( this.srcfile + ".gf" )
150 }
151 */
152 method myform.GFSetNew
153 {
154 // str src
155 .gffile = "/*
156 //!GFG и //!\\GFG are commentary attributes generated by
157 the Gentee form editor. You should neither delete them
158 nor make any changes into the source code from the beginning
159 of the commentary attribute //!GFG to its end //!\\GFG
160 */
161 "
162 inscode( .gffile, "include", this.GetInclude(), "\l}\l" )
163 inscode( .gffile, "form", this.GetForm(), "\l}\l" )
164 //inscode( .gffile, "includeinit", "include { $\"\(.filename).gi\" \l}", "" )
165 //src.write( /*this.srcfile + ".gf"*/"\(.filename).gf" )
166 }
167
168 method str vComp.GetListProps <result>( str ownername, str formname, str indent/*, myform mf*/ )
169 {
170 //uint x as inspm->vcompman
171 uint i
172 str afterchild
173
174 if *ownername
175 {
176 result@indent@"comp as this."@this.Name@"\l"
177 result@indent@"comp.Owner = "@ownername@"\l"
178 }
179 else : result@indent@"comp as this\l"
180 result@indent@"with comp\l"@indent@"{\l"
181 uint descr as cm.GetCompDescr( this.TypeId )
182 if &descr
183 {
184 foreach prop, descr.Props
185 {
186 str curprop
187 //if !( prop.D & $PI_DEFVAL )
188 {
189 curprop@indent@"\t."@prop.PropName
190 if prop.AddrGet
191 {
192 if prop.PropType == ustr
193 {
194 curprop@"=ustmp.fromutf8(\""@(prop.AddrGet->func( this, "" ))->ustr.toutf8("")@"\")"
195 }
196 elif prop.PropType == uint || prop.PropType == int
197 {
198 int z = (prop.AddrGet->func( this ))
199 if prop.Vals
200 {
201 curprop@"=$"@prop.GetEnumName(z)
202 }
203 else
204 {
205 curprop@"=\(z)"
206 }
207 }
208 elif prop.PropType == str
209 {
210 curprop@"=\""@(prop.AddrGet->func( this, "" ))->str@"\""
211 }
212 }
213 curprop@"\l"
214 if prop.PropFlags & $PROP_LOADAFTERCHILD
215 {
216 afterchild@curprop
217 }
218 else
219 {
220 result@curprop
221 }
222 }
223
224 }
225
226 foreach event, descr.Events
227 {
228
229 str meth = event.GetVal( this )
230 if *meth
231 {
232 result@indent@"\t.\(event.EventName).Set( this, \(formname)_\(meth) )\l"
233 }
234 /*print( "eventname = \(event.EventName)\n" )
235
236 item.Value =
237
238 item.Flags |= $PI_LIST*/
239 }
240 if *this.Comps
241 {
242 result@"\l"@indent@"\tuint comp\l"
243 fornum i=0, *this.Comps
244 {
245 if this.Comps[i]->vComp.p_designing
246 {
247 result@this.Comps[i]->vComp.GetListProps(?(*ownername,"this."@this.Name, "this" ), formname, indent + "\t"/*, mf*/)
248 }
249 }
250 }
251 result@afterchild
252 result@indent@"}\l"
253 }
254
255 //uint c as cm.FindCOmp( this.typeid )
256 //if &c
257 {
258 //fornum i=0, *c.props
259 {
260 /*if c.props[i].getval(this) != c.props[i].defval
261 {
262 if c.props[i].addrget
263 {
264 result@"ctrl."@c.props[i].name@"="
265 //print( c.props[i].name+"\n" )
266 if c.props[i].typeid == str
267 {
268 result@(c.props[i].addrget->func( this,"" ))->str.quoted()
269 }
270 elif c.props[i].typeid == uint || c.props[i].typeid == int
271 {
272 str r
273 int2str( r, "0x%X", (c.props[i].addrget->func( this )))
274 //print( r+"\n" )
275 result@r
276 }
277 result@"\l"
278 }
279 }*/
280 }
281 /*uint arev as this.des1->arr of uint
282 uint desc
283 fornum i=0, *c.events
284 {
285 if arev[i]
286 {
287 desc as mf.evlist[mf.finddesc( arev[i] )]
288 result@"ctrl."@c.events[i].name@".set(this,\""@desc.name@"\")\l"
289 }
290 }*/
291 }
292 }
293
294 method vComp.Save( gtitem gi, uint level )
295 {
296 str slevel
297 uint i
298 fornum i, level
299 {
300 slevel@" "
301 }
302 gi.set( "TypeName", this.TypeName )
303 uint descr as cm.GetCompDescr( this.TypeId )
304 if &descr
305 {
306 uint gp as gi.appendchild( "Properties" )
307 uint gpa as gi.appendchild( "PropertiesAfter" )
308 uint ge as gi.appendchild( "Events" )
309 uint i
310 ustr val
311 fornum i, *descr.Props
312 {
313 uint prop as descr.Props[i]
314 val = prop.GetVal( this )
315 if val != prop.DefVal
316 {
317 if prop.PropFlags & $PROP_LOADAFTERCHILD
318 {
319 val.toutf8(gpa.appendchild( prop.PropName ).value)
320 }
321 else
322 {
323 val.toutf8(gp.appendchild( prop.PropName ).value)
324 }
325 }
326 }
327 fornum i = 0, *descr.Events
328 {
329 uint event as descr.Events[i]
330 val = event.GetVal( this )
331 val.toutf8(ge.appendchild( event.EventName ).value)
332 }
333 }
334
335 uint gc as gi.appendchild( "Children" )
336 foreach comp, .Comps
337 {
338 comp as vComp
339 if comp.p_designing
340 {
341 comp.Save( gc.appendchild(""), level + 1 )
342 }
343 }
344 }
345 method myform.GFSave( uint flgsaveas )
346 {
347 if !.flggfchanged
348 {
349 .checkgffile()
350 }
351 if !.flgchanged /*&& !flgsaveas*/
352 {
353 return
354 }
355 if !.flgsaved || flgsaveas
356 {
357 .dlgOpen.FileName = ?( *.filename, .filename.ustr(), .edform->vForm.Name.ustr())
358 .dlgOpen.DefExt = ".gf".ustr()
359 if !.dlgOpen.ShowSaveFile()
360 {
361 return
362 }
363 str dir, fname
364 this.dlgOpen.FileName.str().fgetparts( dir, fname, 0->str )
365 .filename = dir + "\\" + fname
366 }
367 //print( "s10\n" )
368
369 gt g
370 g.utf8 = 1
371 //print( "s11\n" )
372 .edform->vForm.Save( g.root().appendchild(""), 0 )
373 ///print( "s12\n" )
374 str stemp
375 gtsave gts
376 gts.offstep = 1
377 gts.inside = 1
378 gts.endname = 1
379 //print( "s13\n" )
380 g.root().save( stemp, gts )
381 //print( "s14\n" )
382 stemp.write( .filename + ".frm" )
383 //print( "s15\n" )
384
385
386 str r = .edform->vComp.GetListProps( "", .edform->vComp.Name, "\t" )
387 r ="method v\(.edform->vComp.Name) v\(.edform->vComp.Name).mLoad <alias=v\(.edform->vComp.Name)_mLoad>( )
388 {
389 //\tthis->vForm.mCreateWin()
390 \tustr ustmp
391 \tuint comp
392 "@r@"
393 \treturn this
394 }
395
396 method v\(.edform->vComp.Name) v\(.edform->vComp.Name).init( )
397 {
398 this.pTypeId = v\(.edform->vComp.Name)
399 return this
400 }
401 func init_v\(.edform->vComp.Name) <entry>()
402 {
403
404 regcomp( v\(.edform->vComp.Name), \"v\(.edform->vComp.Name)\", vForm, $vForm_last,
405 %{ %{$mLoad, v\(.edform->vComp.Name)_mLoad}},
406 0->collection )
407
408 }
409 "
410
411 r.write( "\(.filename).gi" )
412
413 "#!gentee.exe -s -p default \"%1\"
414 define
415 {
416 DESIGNING = 0
417 COMP = 0
418 }
419 include {
420 $\"\(.filename).gf\"
421 //$\"\(.filename).gi\"
422 }
423 global {
424 v\(.edform->vComp.Name) \(.edform->vComp.Name)
425 }
426
427 func run<main>
428 {
429 \(.edform->vComp.Name).Owner = App
430 App.Run()
431 }
432 ".write( "\(.filename).g" )
433 //.checkgffile()
434 .GFSetInit( .gffile )
435 .gffile.write( "\(.filename).gf" )
436 .flgchanged = 0
437 file f
438 if f.open( .filename + ".gf", 1/*$OP_READONLY*/ )
439 {
440 f.gettime( .ftgf )
441 f.close()
442 .flgsaved = 1
443 .flggfchanged = 0
444 }
445 .Caption = .filename.ustr() + ".gf"
446 }
447