/
nv_genidwdm_auto_resizer.sru
841 lines (700 loc) · 27.2 KB
/
nv_genidwdm_auto_resizer.sru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
HA$PBExportHeader$nv_genidwdm_auto_resizer.sru
$PBExportComments$Resize handler that can move / resize objects in a container during resizing - Author GeNi
forward
global type nv_genidwdm_auto_resizer from nonvisualobject
end type
type rect from structure within nv_genidwdm_auto_resizer
end type
end forward
type rect from structure
Long left
Long top
Long right
Long bottom
end type
global type nv_genidwdm_auto_resizer from nonvisualobject
event type long resize ( unsignedlong sizetype, integer newwidth, integer newheight )
end type
global nv_genidwdm_auto_resizer nv_genidwdm_auto_resizer
type prototypes
function ulong GetClientRect(ulong hwnd,ref rect lpRect) library "user32.dll"
end prototypes
type variables
powerobject ipo_object
nv_genidwdm_auto_resizer ir_registered_controls[]
nv_genidwdm_auto_resizer inv_parent_resizer
boolean ib_anchor_left
boolean ib_anchor_right
boolean ib_anchor_top
boolean ib_anchor_bottom
boolean ib_center_h
boolean ib_center_v
long il_anchored_left
long il_anchored_right
long il_anchored_top
long il_anchored_bottom
string is_dim_tag
end variables
forward prototypes
public function integer of_scanobject (powerobject apo_obj)
public function long of_get_x (powerobject apo_obj)
public function string of_datatypeof (powerobject apo_object)
public function boolean of_isvisual (powerobject apo_object)
public function long of_get_y (powerobject apo_obj)
public function long of_get_width (powerobject apo_obj)
public function long of_get_height (powerobject apo_obj)
public subroutine of_set_tag (powerobject apo_obj, string as_newtag)
public subroutine of_set_y (powerobject apo_obj, long al_y)
public function integer initialize (powerobject apo_obj, powerobject apo_parent)
public subroutine of_set_x (powerobject apo_obj, long al_x)
public subroutine of_set_width (powerobject apo_obj, long al_w)
public subroutine of_set_height (powerobject apo_obj, long al_h)
public function string of_datatypeofcontainer (powerobject apo_object)
public function powerobject of_findobject (powerobject ado_obj)
public subroutine of_x_changed (long al_newx, long al_newwidth, boolean ab_toleft)
public subroutine of_y_changed (long al_newy, long al_newheight, boolean ab_totop)
protected function long getclientwidth (powerobject apo_obj)
protected function long getclientheight (powerobject apo_obj)
public function boolean of_change_object_behavior (powerobject apo_obj, string as_new_dim_tag)
public function boolean of_register_controller (powerobject apo_obj)
public function boolean of_update_control_dims (powerobject apo_obj)
public subroutine store_ctrl_dims (powerobject apo_obj, powerobject apo_parent)
public function powerobject findobjectcontroller (powerobject apo_obj)
public function string gettag (powerobject apo_obj)
public function string of_get_control_behavior (powerobject apo_obj)
public function boolean of_forget_control (powerobject apo_obj)
public function boolean hasmethod (string as_method, powerobject apo_object)
public function string of_generate_code (string as_output, powerobject apo_thisobj)
public function string getabsoluteobjectname (powerobject apo_obj, powerobject apo_root)
end prototypes
event type long resize(unsignedlong sizetype, integer newwidth, integer newheight);if newwidth = 0 and newheight = 0 then return 0
//debug_message( classname(), ipo_object.classname() + " Resize : " + string( newwidth ) + " x " + string( newheight ) + " - " + string( sizetype ) )
//Now we can do the main Engine here !
long /*ll_x, ll_y,*/ ll_width, ll_height
long /*ll_parent_x, ll_parent_y,*/ ll_parent_width, ll_parent_height
//ll_x = of_get_x( ipo_object )
//ll_y = of_get_y( ipo_object )
if ( ib_anchor_right and not ib_anchor_left and not ib_center_h) or ib_center_h then
ll_width = of_get_width( ipo_object )
end if
if ((ib_anchor_bottom or ib_center_v) and not ib_anchor_top and not ib_center_v) or ib_center_v then
ll_height = of_get_height( ipo_object )
end if
if (ib_anchor_bottom or ib_center_v) and not ib_anchor_top and not ib_center_v then
of_set_y( ipo_object, newheight - il_anchored_bottom - ll_height )
end if
if ib_anchor_right and not ib_anchor_left and not ib_center_h then
of_set_x( ipo_object, newwidth - il_anchored_right - ll_width )
end if
if ib_anchor_left and ib_anchor_right then
of_set_width( ipo_object, newwidth - il_anchored_right - il_anchored_left )
end if
if ib_anchor_top and ib_anchor_bottom then
of_set_height( ipo_object, newheight - il_anchored_top - il_anchored_bottom )
end if
if ib_center_v and isvalid(inv_parent_resizer) then
// ll_parent_y = of_get_y(inv_parent_resizer.ipo_object)
ll_parent_height = of_get_height(inv_parent_resizer.ipo_object)
of_set_y( ipo_object, (ll_parent_height - ll_height)/2 )
end if
if ib_center_h and isvalid(inv_parent_resizer) then
// ll_parent_x = of_get_x(inv_parent_resizer.ipo_object)
ll_parent_width = of_get_width(inv_parent_resizer.ipo_object)
of_set_x( ipo_object, (ll_parent_width - ll_width)/2 )
end if
//Here we ask to all of our child to be resized as we are !
long i
ll_width = of_get_width( ipo_object )
ll_height = of_get_height( ipo_object )
for i = 1 to upperbound( ir_registered_controls[] )
if isvalid(ir_registered_controls[i]) then
ir_registered_controls[i].event resize( sizetype, ll_width, ll_height )
end if
next
return 0
end event
public function integer of_scanobject (powerobject apo_obj);//this scan the current powerobject for it's children...
if isnull( apo_obj ) or not isvalid( apo_obj ) then return -1
long i
//debug_message( classname(), "DataTypeOf = " + of_datatypeof( apo_obj ) )
choose case of_datatypeofcontainer( apo_obj )
case "window"
window l_window
l_window = apo_obj
for i = 1 to upperbound( l_window.control[] )
of_register_controller( l_window.control[i] )
next
case "tab"
tab l_tab
l_tab = apo_obj
for i = 1 to upperbound( l_tab.control[] )
of_register_controller( l_tab.control[i] )
next
case "userobject"
userobject l_userobject
l_userobject = apo_obj
for i = 1 to upperbound( l_userobject.control[] )
of_register_controller( l_userobject.control[i] )
next
case "dragobject", "roundrectangle", "rectangle", "oval", "line"
return 0
case else
//debug_message( classname(), "of_scanobject : unhandled datatype = " + of_datatypeofcontainer( apo_obj ) )
end choose
//choisit les types convenables et regarde leur TAG,
//si le tag est compatible, on l'envoie dans un register...
//of_register_object( apo_obj )
return 0
end function
public function long of_get_x (powerobject apo_obj);
if apo_obj.TypeOf() = line! then
return CWGetField( apo_obj, "BeginX")
else
return CWGetField( apo_obj, "x")
end if
end function
public function string of_datatypeof (powerobject apo_object);classdefinition lcd_classdef
lcd_classdef = apo_object.classdefinition
string ls_datatype
choose case lcd_classdef.datatypeof
case "commandbutton", "vprogressbar", "vtrackbar", "statichyperlink", "singlelineedit", "statictext", &
"picturebutton", "checkbox", "datawindow", "radiobutton", "inkedit", "inkpicture", "animation", &
"groupbox", "datepicker", "olecustomcontrol", "treeview", "listview", "graph", "monthcalendar", &
"listbox", "dropdownlistbox", "picturelistbox", "dropdownpicturelistbox", "picture", "picturehyperlink",&
"hscrollbar", "vscrollbar", "hprogressbar", "htrackbar", "editmask", "richtextedit", "multilineedit"
ls_datatype = "dragobject"
case "tab", "userobject"
ls_datatype = "dragobject"
case else
ls_datatype = lcd_classdef.datatypeof
end choose
return ls_datatype
end function
public function boolean of_isvisual (powerobject apo_object);classdefinition lcd_classdef
lcd_classdef = apo_object.classdefinition
return lcd_classdef.isvisualtype
end function
public function long of_get_y (powerobject apo_obj);
if apo_obj.TypeOf() = line! then
return CWGetField( apo_obj, "BeginY")
else
return CWGetField( apo_obj, "y")
end if
end function
public function long of_get_width (powerobject apo_obj);//return the width of the current object
if apo_obj.TypeOf() = window! then
return getclientwidth(apo_obj)
elseif apo_obj.TypeOf() = line! then
return long(CWGetField( apo_obj, "EndX")) - long(CWGetField( apo_obj, "BeginX"))
else
return CWGetField( apo_obj, "width")
end if
end function
public function long of_get_height (powerobject apo_obj);//return the height of the current object
if apo_obj.TypeOf() = window! then
return getclientheight(apo_obj)
elseif apo_obj.TypeOf() = line! then
return long(CWGetField( apo_obj, "EndY")) - long(CWGetField( apo_obj, "BeginY"))
else
return CWGetField( apo_obj, "height" )
end if
end function
public subroutine of_set_tag (powerobject apo_obj, string as_newtag);CWSetField( apo_obj, "tag", as_newtag)
/*
//return the x value of the currenct object
choose case of_datatypeof( apo_obj )
case "window"
window l_window
l_window = apo_obj
l_window.tag = as_newtag
case "dragobject"
dragobject l_object
l_object = apo_obj
l_object.tag = as_newtag
case "roundrectangle"
roundrectangle l_rr
l_rr = apo_obj
l_rr.tag = as_newtag
case "line"
line l_line
l_line = apo_obj
l_line.tag = as_newtag
case else
//debug_message( classname(), "of_set_tag : type not handled = " + of_datatypeof( apo_obj ) )
end choose
*/
end subroutine
public subroutine of_set_y (powerobject apo_obj, long al_y);
if apo_obj.TypeOf() = line! then
CWSetField( apo_obj, "BeginY", al_y)
else
CWSetField( apo_obj, "y", al_y)
end if
end subroutine
public function integer initialize (powerobject apo_obj, powerobject apo_parent);
//this will parse the full list of control which is compatible with this service.
ipo_object = apo_obj
store_ctrl_dims(apo_obj, apo_parent)
if hasMethod( "setresizer", apo_obj ) then
apo_obj.dynamic setResizer( this ) //allow the control to respond if it want to move
end if
//regarde si cet object contient d'autres objets
of_scanobject( ipo_object )
return upperbound( ir_registered_controls[] )
end function
public subroutine of_set_x (powerobject apo_obj, long al_x);
if apo_obj.TypeOf() = line! then
CWSetField( apo_obj, "BeginX", al_x)
else
CWSetField( apo_obj, "x", al_x)
end if
end subroutine
public subroutine of_set_width (powerobject apo_obj, long al_w);
if apo_obj.TypeOf() = line! then
CWSetField( apo_obj, "EndX", al_w + long(CWGetField( apo_obj, "BeginX")))
else
CWSetField( apo_obj, "width", al_w)
end if
// /!\ for windows, the width is not what you think ;)
end subroutine
public subroutine of_set_height (powerobject apo_obj, long al_h);
if apo_obj.TypeOf() = line! then
CWSetField( apo_obj, "EndY", al_h + long(CWGetField( apo_obj, "BeginY")))
else
CWSetField( apo_obj, "height", al_h)
end if
// /!\ for windows, the height is not what you think ;)
end subroutine
public function string of_datatypeofcontainer (powerobject apo_object);classdefinition lcd_classdef
lcd_classdef = apo_object.classdefinition
string ls_datatype
choose case lcd_classdef.datatypeof
case "commandbutton", "vprogressbar", "vtrackbar", "statichyperlink", "singlelineedit", "statictext", &
"picturebutton", "checkbox", "datawindow", "radiobutton", "inkedit", "inkpicture", "animation", &
"groupbox", "datepicker", "olecustomcontrol", "treeview", "listview", "graph", "monthcalendar", &
"listbox", "dropdownlistbox", "picturelistbox", "dropdownpicturelistbox", "picture", "picturehyperlink",&
"hscrollbar", "vscrollbar", "hprogressbar", "htrackbar", "editmask", "richtextedit", "multilineedit"
ls_datatype = "dragobject"
case else
ls_datatype = lcd_classdef.datatypeof
end choose
return ls_datatype
end function
public function powerobject of_findobject (powerobject ado_obj);//this function look for it's child and return the matching object if any...
powerobject lnv_res
long i
for i = 1 to upperbound( inv_parent_resizer.ir_registered_controls[] )
if isvalid(inv_parent_resizer.ir_registered_controls[i]) then
if inv_parent_resizer.ir_registered_controls[i].ipo_object = ado_obj then
return inv_parent_resizer.ir_registered_controls[i]
end if
end if
next
return lnv_res
end function
public subroutine of_x_changed (long al_newx, long al_newwidth, boolean ab_toleft);if not (ib_anchor_left or ib_anchor_right) then return
if ib_anchor_left and ib_anchor_right then
if ab_toleft then
il_anchored_right = il_anchored_left + al_newwidth
else
il_anchored_left = al_newx
end if
else
if ib_anchor_left then
if ab_toleft then
il_anchored_right = il_anchored_left + al_newwidth
else
il_anchored_left = al_newx
end if
else// if ib_anchor_left then
if ab_toleft then
il_anchored_right = il_anchored_left + al_newwidth
else
il_anchored_left = al_newx
end if
end if
end if
end subroutine
public subroutine of_y_changed (long al_newy, long al_newheight, boolean ab_totop);if not (ib_anchor_top or ib_anchor_bottom) then return
if ib_anchor_top and ib_anchor_bottom then
if ab_totop then
il_anchored_bottom = il_anchored_top + al_newheight
else
il_anchored_top = al_newy
end if
else
if ib_anchor_top then
if ab_totop then
il_anchored_bottom = il_anchored_top + al_newheight
else
il_anchored_top = al_newy
end if
else// if ib_anchor_bottom then
if ab_totop then
il_anchored_bottom = il_anchored_top + al_newheight
else
il_anchored_top = al_newy
end if
end if
end if
end subroutine
protected function long getclientwidth (powerobject apo_obj);
// return the width of the client rectangle of the given object
// the width is in PB units
long ll_pbunits
rect rect
getclientrect( handle(apo_obj), rect)
ll_pbunits = PixelsToUnits(rect.right - rect.left , XPixelsToUnits!)
return ll_pbunits
end function
protected function long getclientheight (powerobject apo_obj);
// return the height of the client rectangle of the given object
// the height is in PB units
long ll_pbunits
rect rect
getclientrect( handle(apo_obj), rect)
ll_pbunits = PixelsToUnits(rect.bottom - rect.top , YPixelsToUnits!)
return ll_pbunits
end function
public function boolean of_change_object_behavior (powerobject apo_obj, string as_new_dim_tag);
// update the object pseudo "tag" then re-memorize the dims
long i
boolean lb_updated
nv_genidwdm_auto_resizer lnv_resizer
//debug_message(classname()+"::of_change_object_behavior()","de l'objet " +ipo_object.classname() + " --> " + as_new_dim_tag, debug_level_parano )
lnv_resizer = findobjectcontroller(apo_obj)
if isvalid(lnv_resizer) then
lnv_resizer.is_dim_tag = as_new_dim_tag
if isvalid(lnv_resizer.inv_parent_resizer) then
lnv_resizer.store_ctrl_dims(apo_obj, lnv_resizer.inv_parent_resizer.ipo_object)
else
lnv_resizer.store_ctrl_dims(apo_obj, ipo_object)
end if
return true
end if
return false
end function
public function boolean of_register_controller (powerobject apo_obj);if true /*of_isvisual( apo_obj ) and match( upper(of_get_tag( apo_obj )), "^[LRTB];?.*$" )*/ then
nv_genidwdm_auto_resizer lnv_resizer
lnv_resizer = create nv_genidwdm_auto_resizer
lnv_resizer.initialize( apo_obj, this.ipo_object )
lnv_resizer.inv_parent_resizer = this
ir_registered_controls[ upperbound(ir_registered_controls[]) +1 ] = lnv_resizer
return true
end if
return false
end function
public function boolean of_update_control_dims (powerobject apo_obj);
// re-memorize the dims of the given object
// useful if the position / dimension was changed by code
long i
boolean lb_updated
nv_genidwdm_auto_resizer lnv_resizer
//debug_message(classname()+"::of_update_object()","de l'objet " +ipo_object.classname())
lnv_resizer = findobjectcontroller( apo_obj)
if isvalid(lnv_resizer) then
if isvalid(lnv_resizer.inv_parent_resizer) then
lnv_resizer.store_ctrl_dims(apo_obj, lnv_resizer.inv_parent_resizer.ipo_object)
else
lnv_resizer.store_ctrl_dims(apo_obj, apo_obj)
end if
return true
end if
return false
end function
public subroutine store_ctrl_dims (powerobject apo_obj, powerobject apo_parent);
// memorize the control attributes
long i
string ls_tag
ls_tag = gettag( apo_obj )
i = pos( ls_tag, ";" )
if i > 0 then
of_set_tag( apo_obj, mid(ls_tag, i+1) )
ls_tag = upper( mid(ls_tag, 1, i -1) )
end if
if is_dim_tag = "" then is_dim_tag = ls_tag
//reset flags
ib_anchor_left = false
ib_anchor_top = false
ib_anchor_right = false
ib_anchor_bottom = false
ib_center_h = false
ib_center_v = false
//debug_message(classname()+"::store_ctrl_dims()", "object : " + apo_obj.classname() + " x="+string(of_get_x(apo_obj))+", y="+string(of_get_y(apo_obj))+", width="+string(of_get_width(apo_obj))+", height="+string(of_get_height(apo_obj)))
//debug_message(classname()+"::store_ctrl_dims()", "tag : " + is_dim_tag)
//debug_message(classname()+"::store_ctrl_dims()", "parent : " + apo_parent.classname() + " width="+string(of_get_width(apo_parent))+", height="+string(of_get_height(apo_parent)))
// centrage ou centrage horizontal
if pos( ls_tag, "H" ) > 0 or pos( ls_tag, "C" ) > 0 then
ib_center_h = true
of_set_x(apo_obj, (of_get_width( apo_parent) - of_get_x( apo_obj )) / 2 )
end if
//centrage ou centrage vertical
if pos( ls_tag, "V" ) > 0 or pos( ls_tag, "C" ) > 0 then
ib_center_v = true
of_set_y(apo_obj, (of_get_height( apo_parent) - of_get_y( apo_obj )) / 2 )
end if
//debug_message( classname(), "initialize: " + apo_obj.classname() +".tag="+ ls_tag )
if pos( is_dim_tag, "L" ) > 0 then
ib_anchor_left = true
il_anchored_left = of_get_x( apo_obj )
// debug_message( classname(), "initialize: " + apo_obj.classname() +".x="+string(il_anchored_left) )
end if
if pos( is_dim_tag, "T" ) > 0 then
ib_anchor_top = true
il_anchored_top = of_get_y( apo_obj )
// debug_message( classname(), "initialize: " + apo_obj.classname() +".y="+string(il_anchored_top) )
end if
if pos( is_dim_tag, "R" ) > 0 then
ib_anchor_right = true
il_anchored_right = of_get_width( apo_parent) - ( of_get_x( apo_obj ) + of_get_width( apo_obj ) )
// debug_message( classname(), "initialize: " + apo_obj.classname() +".x2="+string(il_anchored_right) )
end if
if pos( is_dim_tag, "B" ) > 0 then
ib_anchor_bottom = true
il_anchored_bottom = of_get_height(apo_parent) - ( of_get_height( apo_obj ) + of_get_y( apo_obj ) )
// debug_message( classname(), "initialize: " + apo_obj.classname() +".y2="+string(il_anchored_bottom ) )
end if
//debug_message(classname()+"::store_ctrl_dims()", "object : " + apo_obj.classname() + " ib_anchor_left="+string(ib_anchor_left)+", ib_anchor_top="+string(ib_anchor_top)+", ib_anchor_right="+string(ib_anchor_right)+", ib_anchor_bottom="+string(ib_anchor_bottom)+", ib_center_h="+string(ib_center_h)+", ib_center_v="+string(ib_center_v))
//debug_message(classname()+"::store_ctrl_dims()", "object : " + apo_obj.classname() + " il_anchored_top="+string(il_anchored_top)+", il_anchored_bottom="+string(il_anchored_bottom)+", il_anchored_left="+string(il_anchored_left)+", il_anchored_right="+string(il_anchored_right))
end subroutine
public function powerobject findobjectcontroller (powerobject apo_obj);
// Find an object controller recursively
long i
nv_genidwdm_auto_resizer lnv_res
//debug_message(classname(),ipo_object.classname() + ".findobjectcontroller(" + apo_obj.classname() +")", debug_level_parano)
if ipo_object = apo_obj then
// debug_message(classname()," --> trouve dans " + ipo_object.classname(), debug_level_parano)
lnv_res = this
else
for i = 1 to upperbound(ir_registered_controls[])
if isvalid(ir_registered_controls[i]) and not isnull(ir_registered_controls[i]) then
lnv_res = ir_registered_controls[i].findobjectcontroller(apo_obj)
if isvalid(lnv_res) then exit
end if
next
end if
return lnv_res // attention : peut etre invalide si objet non trouve, utiliser isvalid()
end function
public function string gettag (powerobject apo_obj);return CWGetField( apo_obj, "tag")
/*
//return the tag value of the currenct object
string ls_tag
choose case of_datatypeof( apo_obj )
case "window"
window l_window
l_window = apo_obj
ls_tag = l_window.tag
case "dragobject"
dragobject l_object
l_object = apo_obj
ls_tag = l_object.tag
case "roundrectangle"
roundrectangle l_rr
l_rr = apo_obj
ls_tag = l_rr.tag
case "line"
line l_line
l_line = apo_obj
ls_tag = l_line.tag
case else
//debug_message( classname(), "of_get_tag : type not handled = " + of_datatypeof( apo_obj ) )
end choose
return ls_tag
*/
end function
public function string of_get_control_behavior (powerobject apo_obj);
// return the tag used for moving / redimensionning
nv_genidwdm_auto_resizer lnv_resizer
string ls_ret
lnv_resizer = findobjectcontroller( apo_obj)
if isvalid(lnv_resizer) then
ls_ret = lnv_resizer.is_dim_tag
end if
//debug_message(classname()+"::of_get_object_behavior()","de l'objet " +ipo_object.classname() + " --> " + ls_ret, debug_level_parano )
return ls_ret
end function
public function boolean of_forget_control (powerobject apo_obj);
// does not manage the given object anymore
long i
boolean lb_forgetted
powerobject lpo_null
if ipo_object = apo_obj then
setnull(lpo_null)
ipo_object = lpo_null
return true
else
for i = 1 to upperbound(ir_registered_controls[])
if isnull(ir_registered_controls[i]) or not isvalid(ir_registered_controls[i]) then continue
lb_forgetted = ir_registered_controls[i].of_forget_control(apo_obj)
if lb_forgetted then
setnull(ir_registered_controls[i])
return true
end if
next
end if
return false
end function
public function boolean hasmethod (string as_method, powerobject apo_object);if isnull( apo_object ) or not isvalid( apo_object ) then return false
classdefinition lcd_obj
lcd_obj = apo_object.classdefinition
ScriptDefinition ls_ScriptList[ ]
long i
ls_ScriptList[] = lcd_obj.ScriptList[]
as_method = lower( as_method )
for i = 1 to upperbound (ls_ScriptList[])
if lower(ls_ScriptList[i].name) = as_method then
// debug_message( "", "hasmethod('"+as_method+"',"+ apo_object.classname() + ") return true" )
return true
end if
next
return false
end function
public function string of_generate_code (string as_output, powerobject apo_thisobj);// SYNOPSIS
//
// //Typically called at the end of an open event:
// inv_resize.of_generate_code( "", this )
// //or
// inv_resize.of_generate_code( classname()+"_event_resize.txt", true )
//
// DESCRIPTION
//
// Generate source code for static resizer behaviour, code to be put on the resize event :
//
// resize( /*unsignedlong sizetype*/, /*integer newwidth*/, /*integer newheight */) long
//
// ARGUMENTS
//
// as_output (string)
// if passed an empty string, it will write the code to the clipboard,
// otherwhise write generated code into the given filename.
//
// apo_this (powerobject)
// the root object for resize event.
string ls_code
if as_output <> '*' then
ls_code = "/* Auto generated code from "+classname()+" */~r~n"
ls_code += "/* - does NOT handle dynamic created object */~r~n"
ls_code += "/* - does NOT handle H/V splitters */~r~n"
ls_code += "this.setredraw( false )~r~n"
ls_code +="//inv_resizer.event resize( sizetype, width, height )~r~n"
ls_code +="if newwidth = 0 and newheight = 0 then return 0~r~n"
ls_code +="long /*ll_x, ll_y,*/ ll_width, ll_height~r~n"
ls_code +="long ll_parent_x, ll_parent_y, ll_parent_width, ll_parent_height~r~n"
end if
string ls_objname, ls_parentname
long i
nv_genidwdm_auto_resizer obj
obj = this
ls_objname = getAbsoluteObjectName(obj.ipo_object, apo_thisobj )
if obj.ib_anchor_left or obj.ib_anchor_right or obj.ib_anchor_top or obj.ib_anchor_bottom or obj.ib_center_h or obj.ib_center_v then
ls_code += "/*ll_x = "+ls_objname+".x*/~r~n"
ls_code += "/*ll_y = "+ls_objname+".y*/~r~n"
if obj.TypeOf() = window! then
if ( obj.ib_anchor_right and not obj.ib_anchor_left ) or obj.ib_center_h then
ls_code += "ll_width = getclientwidth("+ls_objname+")~r~n"
else
ls_code += "/*ll_width = getclientwidth("+ls_objname+")*/~r~n"
end if
if ( (obj.ib_anchor_bottom or obj.ib_center_v) and not obj.ib_anchor_top ) or obj.ib_center_v then
ls_code += "ll_height = getclientheight("+ls_objname+")~r~n"
else
ls_code += "/*ll_height = getclientheight("+ls_objname+")*/~r~n"
end if
else
if ( obj.ib_anchor_right and not obj.ib_anchor_left ) or obj.ib_center_h then
ls_code += "ll_width = "+ls_objname+".width~r~n"
else
ls_code += "/*ll_width = "+ls_objname+".width*/~r~n"
end if
if ( (obj.ib_anchor_bottom or obj.ib_center_v) and not obj.ib_anchor_top ) or obj.ib_center_v then
ls_code += "ll_height = "+ls_objname+".height~r~n"
else
ls_code += "/*ll_height = "+ls_objname+".height*/~r~n"
end if
end if
if (obj.ib_anchor_bottom or obj.ib_center_v) and not obj.ib_anchor_top and not obj.ib_center_v then
ls_code += ls_objname + ".y=newheight - "+string(obj.il_anchored_bottom)+" - ll_height~r~n"
end if
if obj.ib_anchor_right and not obj.ib_anchor_left and not obj.ib_center_h then
ls_code += ls_objname + ".x= newwidth - "+string(obj.il_anchored_right)+" - ll_width~r~n"
end if
if obj.ib_anchor_left and obj.ib_anchor_right then
ls_code += ls_objname + ".width = newwidth - "+string(obj.il_anchored_right)+" - "+string(il_anchored_left)+"~r~n"
end if
if obj.ib_anchor_top and obj.ib_anchor_bottom then
ls_code += ls_objname + ".height = newheight - "+string(obj.il_anchored_top)+" - "+string(il_anchored_bottom)+"~r~n"
end if
if isvalid(obj.inv_parent_resizer) then
ls_parentname = getabsoluteobjectname( obj.inv_parent_resizer.ipo_object, apo_thisobj )
if obj.ib_center_v then
ls_code += "/*ll_parent_y = "+ls_parentname+".y*/~r~n"
ls_code += "ll_parent_height = "+ls_parentname+".height~r~n"
ls_code += ls_objname + ".y = (ll_parent_height - ll_height)/2~r~n"
end if
if obj.ib_center_h then
ls_code += "/*ll_parent_x = "+ls_parentname+".x*/~r~n"
ls_code += "ll_parent_width = "+ls_parentname+".width~r~n"
ls_code += ls_objname+".x = (ll_parent_width - ll_width)/2~r~n"
end if
end if
end if
for i = 1 to upperbound( ir_registered_controls[] )
if isvalid(ir_registered_controls[i]) then
//ir_registered_controls[i].event resize( sizetype, of_get_width( ipo_object ), of_get_height( ipo_object ) )
//recursive scan objects
ls_code += "newwidth = "+ls_objname+".width~r~n"
ls_code += "newheight = "+ls_objname+".height~r~n"
ls_code += ir_registered_controls[i].of_generate_code( "*", apo_thisobj )
end if
next
if as_output <> '*' then ls_code += "this.setredraw( true )"
if as_output='' then
clipboard( ls_code )
elseif as_output <> '*' then
int li_handle
li_handle = FileOpen( as_output, linemode!, write!, lockwrite!, replace! )
if li_handle > 0 then
FileWriteEx( li_handle, ls_code )
FileClose( li_handle )
end if
end if
return ls_code
end function
public function string getabsoluteobjectname (powerobject apo_obj, powerobject apo_root);//return the Absolute object name ( contain hierarchical parent's name )
PowerObject lpo_parent
String ls_object
// loop thru parents building object name
if isnull(apo_obj) or not isvalid(apo_obj) then
DebugBreak()
return "(null or invalid object)"
end if
if apo_obj = apo_root then
ls_object = 'this'
else
ls_object = apo_obj.ClassName()
end if
lpo_parent = apo_obj.GetParent()
Do While IsValid (lpo_parent) and Not IsNull( lpo_parent )
if lpo_parent = apo_root then
ls_object = 'this.'+ls_object
else
ls_object = lpo_parent.ClassName() + "." + ls_object
end if
if lpo_parent.TypeOf() = Window! then exit //stop condition
lpo_parent = lpo_parent.GetParent()
Loop
Return ls_object
end function
on nv_genidwdm_auto_resizer.create
call super::create
TriggerEvent( this, "constructor" )
end on
on nv_genidwdm_auto_resizer.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
event destructor;long i
for i = 1 to upperbound( ir_registered_controls[] )
if isvalid( ir_registered_controls[i] ) then destroy ir_registered_controls[i]
next
end event