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.labeled 17.07.07 0.0.A.
11 *
12 * Author: Alexander Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15
16 include {
17 "edit.g"
18 "btnpic.g"
19 "combobox.g"
20 "label.g"
21 }
22
23
24 type vLabelCon <inherit = vLabel>
25 {
26 uint pLabelPos
27 uint pAddColon
28 uint LabeledCtrl
29 uint fConCreate
30 }
31
32 /* Компонента vLabeledEditOld, порождена от vEdit
33 */
34 /*type vLabeledEditOld <inherit = vEdit>
35 {
36 vLabelCon LabelCon
37 }*/
38
39 type vLabeledComboBox <inherit = vComboBox>
40 {
41 vLabelCon LabelCon
42 }
43
44 type vLabeledEdit <inherit = vCtrl>
45 {
46 vLabelCon LabelCon
47 vEdit Edit
48 //vBtnPic Btn1
49 //vBtnPic Btn2
50 ustr pBtn1Image
51 ustr pBtn2Image
52
53 locustr pBtn1Hint
54 locustr pBtn2Hint
55
56 uint pBtn1
57 uint pBtn2
58
59 uint pLEStyle
60
61 evEvent OnBtn1Click
62 evEvent OnBtn2Click
63 evEvent OnChange
64 evEvent OnFocus
65 }
66
67 define <export>{
68 //Положение подписи LabelPos
69 lpLeft = 0
70 lpAbove = 1
71
72 //Стили LabeledEdit.LEStyle
73 lsSimple = 0
74 lsOneBtn = 1
75 lsTwoBtns = 2
76 }
77
78 extern {
79 method vLabelCon.ConPosChanging()
80 }
81
82 /*------------------------------------------------------------------------------
83 Internal Methods
84 */
85 method vLabeledEdit.iUpdateBtns()
86 {
87 uint rightedit
88 uint height
89 if this.pBtn1
90 {
91 if this.Edit.Multiline : height = 25
92 else : height = max( min( this.Edit.Height, 50 ), 20 )
93 this.pBtn1->vBtnPic.Width = height
94 this.pBtn1->vBtnPic.Height = height
95 rightedit = 2 + height
96 if this.pBtn2
97 {
98 this.pBtn2->vBtnPic.Width = height
99 this.pBtn2->vBtnPic.Height = height
100 this.pBtn2->vBtnPic.Right = 0
101 if this.Edit.Multiline &&
102 this.Edit.Height > 50
103 {
104 this.pBtn2->vBtnPic.Top = height
105 this.pBtn1->vBtnPic.Right = 0
106 }
107 else
108 {
109 this.pBtn2->vBtnPic.Top = 0
110 this.pBtn1->vBtnPic.Right = height
111 rightedit += this.pBtn2->vBtnPic.Width
112 }
113 }
114 else
115 {
116 this.pBtn1->vBtnPic.Right = 0
117 }
118 }
119 this.Edit.Width = .Width - rightedit
120 this.LabelCon.ConPosChanging()
121 }
122
123
124 /*------------------------------------------------------------------------------
125 Properties
126 */
127 /* Свойство str vLabeledEditOld.Caption - Get Set
128 Усотанавливает или получает заколовок панели
129 */
130 /*property ustr vLabeledEditOld.Caption <result>
131 {
132 result = .LabelCon.Caption
133 }
134
135 property vLabeledEditOld.Caption( ustr val )
136 {
137 .LabelCon.Caption = val
138 }*/
139
140 property ustr vLabeledComboBox.Caption <result>
141 {
142 result = .LabelCon.Caption
143 }
144
145 property vLabeledComboBox.Caption( ustr val )
146 {
147 .LabelCon.Caption = val
148 }
149
150 property ustr vLabeledEdit.Caption <result>
151 {
152 result = .LabelCon.Caption
153 }
154
155 property vLabeledEdit.Caption( ustr val )
156 {
157 .LabelCon.Caption = val
158 }
159
160 property ustr vLabeledEdit.Hint <result>
161 {
162 result = .Edit.Hint
163 }
164
165 property vLabeledEdit.Hint( ustr val )
166 {
167 .Edit.Hint = val
168 }
169
170 method vLabelCon.mSetCaption <alias=vLabelCon_mSetCaption>( ustr caption )
171 {
172 if *caption && caption[ *caption - 1 ] != ':'
173 {
174 caption += ":"
175 }
176 this->vLabel.mSetCaption( caption )
177 }
178
179 /*Виртуальный метод uint vLabel.mLangChanged - Изменение текущего языка
180 */
181 method vLabelCon.mLangChanged <alias=vLabelCon_mLangChanged>()
182 {
183 this->vLabel.mLangChanged()
184 .ConPosChanging()
185 }
186
187 method vLabelCon.mCreateWin <alias=vLabelCon_mCreateWin>()
188 {
189 this->vLabel.mCreateWin()
190 .ConPosChanging()
191 }
192
193 method vLabelCon.mPreDel <alias=vLabelCon_mPreDel>()
194 {
195 this->vLabel.mPreDel()
196 .LabeledCtrl = 0
197 }
198
199
200 property uint vLabelCon.AddColon
201 {
202 return .pAddColon
203 }
204
205 property vLabelCon.AddColon( uint val )
206 {
207 if .pAddColon != val
208 {
209 .pAddColon = val
210
211 }
212 }
213
214 method vLabelCon.iSetLabelPos
215 {
216 .AutoSize = 0
217 if .pLabelPos == $lpLeft
218 {
219 .HorzAlign = $alhRight
220 }
221 else
222 {
223
224 .HorzAlign = $alhLeft
225 //.iUpdateSize()
226 }
227 .AutoSize = 1
228 .ConPosChanging()
229 }
230
231 property uint vLabelCon.LabelPos
232 {
233 return .pLabelPos
234 }
235
236 property vLabelCon.LabelPos( uint val )
237 {
238 if .pLabelPos != val
239 {
240 .pLabelPos = val
241 .iSetLabelPos()
242 }
243 }
244
245
246 /*property uint vLabeledEditOld.LabelPos
247 {
248 return .LabelCon.LabelPos
249 }
250
251 property vLabeledEditOld.LabelPos( uint val )
252 {
253 .LabelCon.LabelPos = val
254 }*/
255
256 property uint vLabeledComboBox.LabelPos
257 {
258 return .LabelCon.LabelPos
259 }
260
261 property vLabeledComboBox.LabelPos( uint val )
262 {
263 .LabelCon.LabelPos = val
264 }
265
266 property uint vLabeledEdit.LabelPos
267 {
268 return .LabelCon.LabelPos
269 }
270
271 property vLabeledEdit.LabelPos( uint val )
272 {
273 .LabelCon.LabelPos = val
274 }
275
276
277 property uint vLabeledComboBox.AddColon
278 {
279 return .LabelCon.AddColon
280 }
281
282 property vLabeledComboBox.AddColon( uint val )
283 {
284 .LabelCon.AddColon = val
285 }
286
287 property uint vLabeledEdit.AddColon
288 {
289 return .LabelCon.AddColon
290 }
291
292 property vLabeledEdit.AddColon( uint val )
293 {
294 .LabelCon.AddColon = val
295 }
296
297 property ustr vLabeledEdit.Text <result>
298 {
299 result = .Edit.Text
300 }
301
302 property vLabeledEdit.Text( ustr val )
303 {
304 .Edit.Text = val
305 }
306
307
308 property vLabeledEdit.Enabled( uint val )
309 {
310 .Edit.Enabled = val
311 if .pBtn1 : .pBtn1->vBtnPic.Enabled = val
312 if .pBtn2 : .pBtn2->vBtnPic.Enabled = val
313 }
314
315 property uint vLabeledEdit.ReadOnly
316 {
317 return .Edit.ReadOnly
318 }
319
320 property vLabeledEdit.ReadOnly( uint val )
321 {
322 .Edit.ReadOnly = val
323 }
324
325 property uint vLabeledEdit.Password
326 {
327 return .Edit.pPassword
328 }
329
330 property vLabeledEdit.Password( uint val )
331 {
332 .Edit.Password = val
333 }
334
335 property uint vLabeledEdit.Multiline
336 {
337 return .Edit.Multiline
338 }
339
340 property vLabeledEdit.Multiline( uint val )
341 {
342 .Edit.Multiline = val
343 .iUpdateBtns()
344 }
345
346 property uint vLabeledEdit.ScrollBars
347 {
348 return .Edit.ScrollBars
349 }
350
351 property vLabeledEdit.ScrollBars( uint val )
352 {
353 .Edit.ScrollBars = val
354 }
355
356 property uint vLabeledEdit.MaxLen
357 {
358 return .Edit.MaxLen
359 }
360
361 property vLabeledEdit.MaxLen( uint val )
362 {
363 .Edit.MaxLen = val
364 }
365
366 property ustr vLabeledEdit.Btn1Image <result>
367 {
368 result = .pBtn1Image
369 }
370
371 property vLabeledEdit.Btn1Image( ustr val )
372 {
373 if .pBtn1Image != val
374 {
375 .pBtn1Image = val
376 if .pBtn1
377 {
378 .pBtn1->vBtnPic.Image = val
379 }
380 }
381 }
382
383 property ustr vLabeledEdit.Btn2Image <result>
384 {
385 result = .pBtn2Image
386 }
387
388 property vLabeledEdit.Btn2Image( ustr val )
389 {
390 if .pBtn2Image != val
391 {
392 .pBtn2Image = val
393 if .pBtn2
394 {
395 .pBtn2->vBtnPic.Image = val
396 }
397 }
398 }
399
400
401
402 property ustr vLabeledEdit.Btn1Hint <result>
403 {
404 result = .pBtn1Hint
405 }
406
407 property vLabeledEdit.Btn1Hint( ustr val )
408 {
409 if .pBtn1Hint != val
410 {
411 .pBtn1Hint = val
412 if .pBtn1
413 {
414 .pBtn1->vBtnPic.Hint = val
415 }
416 }
417 }
418
419 property ustr vLabeledEdit.Btn2Hint <result>
420 {
421 result = .pBtn2Hint
422 }
423
424 property vLabeledEdit.Btn2Hint( ustr val )
425 {
426 if .pBtn2Hint != val
427 {
428 .pBtn2Hint = val
429 if .pBtn2
430 {
431 .pBtn2->vBtnPic.Hint = val
432 }
433 }
434 }
435
436 property uint vLabeledEdit.LEStyle()
437 {
438 return .pLEStyle
439 }
440
441 property vLabeledEdit.LEStyle( uint val )
442 {
443 if .pLEStyle != val
444 {
445 .pLEStyle = val
446 .Virtual( $mReCreateWin )
447 }
448 }
449
450 /*------------------------------------------------------------------------------
451 Virtual methods
452 */
453 method vLabelCon.ConCreateWin( vCtrl LabeledCtrl )
454 {
455 if !.fConCreate
456 {
457 .fConCreate = 1
458 .LabeledCtrl = &LabeledCtrl
459 //.Caption = "a".ustr()
460 .AutoSize = 1
461 .TextVertAlign = $talvCenter
462 //.HorzAlign = $alhRight
463 .AddColon = 1
464 .iSetLabelPos()
465 }
466 }
467
468 method vLabelCon.ConSetOwner()
469 {
470 .Owner = .LabeledCtrl->vCtrl.Owner
471 }
472
473 method vLabelCon.ConSetName( str newname )
474 {
475 ifdef $DESIGNING {
476 if .LabeledCtrl && !.LabeledCtrl->vCtrl.p_loading && ( !*.Caption || .Caption == newname.ustr() )
477 {
478 .Caption = newname.ustr()
479 }
480 }
481 return
482 }
483
484 method vLabelCon.ConPosChanging()
485 {
486 if .LabeledCtrl
487 {
488 if .pLabelPos == $lpLeft
489 {
490 .Top = .LabeledCtrl->vCtrl.Top
491 .Height = .LabeledCtrl->vCtrl.Height
492 .Right = .LabeledCtrl->vCtrl.Owner->vCtrl.clloc.width - .LabeledCtrl->vCtrl.Left + 5
493 }
494 else
495 {
496
497 .Left = .LabeledCtrl->vCtrl.Left + 5
498 //.Width = .LabeledCtrl->vCtrl.Width
499 .Top = .LabeledCtrl->vCtrl.Top - .Height - 3
500 }
501 }
502 }
503
504 /*method vLabeledEditOld vLabeledEditOld.mCreateWin <alias=vLabeledEditOld_mCreateWin>()
505 {
506 this->vEdit.mCreateWin()
507 this.LabelCon.ConCreateWin( this )
508 return this
509 }
510
511 method vLabeledEditOld.mSetOwner <alias=vLabeledEditOld_mSetOwner>( vComp newowner )
512 {
513 this->vEdit.mSetOwner( newowner )
514 this.LabelCon.ConSetOwner( )
515 }
516
517 method uint vLabeledEditOld.mSetName <alias=vLabeledEditOld_mSetName>( str newname )
518 {
519 this.LabelCon.ConSetName( newname )
520 return 1
521 }
522
523 method vLabeledEditOld.mPosChanging <alias=vLabeledEditOld_mPosChanging>( eventpos evp )
524 {
525 this->vEdit.mPosChanging( evp )
526 this.LabelCon.ConPosChanging()
527 }
528 */
529 method vLabeledComboBox vLabeledComboBox.mCreateWin <alias=vLabeledComboBox_mCreateWin>()
530 {
531 this->vComboBox.mCreateWin()
532 this.LabelCon.ConCreateWin( this )
533 return this
534 }
535
536
537 method vLabeledComboBox.mSetOwner <alias=vLabeledComboBox_mSetOwner>( vComp newowner )
538 {
539 if newowner : this.LabelCon.LabeledCtrl = &this
540 else : this.LabelCon.LabeledCtrl = 0
541 this->vComboBox.mSetOwner( newowner )
542 if newowner : this.LabelCon.ConSetOwner( )
543 }
544
545 method uint vLabeledComboBox.mSetName <alias=vLabeledComboBox_mSetName>( str newname )
546 {
547 this.LabelCon.ConSetName( newname )
548 return 1
549 }
550
551 method vLabeledComboBox.mPosChanging <alias=vLabeledComboBox_mPosChanging>( eventpos evp )
552 {
553 this->vComboBox.mPosChanging( evp )
554 this.LabelCon.ConPosChanging()
555 }
556
557 method vLabeledComboBox.mSetVisible <alias=vLabeledComboBox_mSetVisible>( )
558 {
559 this->vCtrl.mSetVisible()
560 .LabelCon.Visible = .Visible
561 }
562
563
564 method uint vLabeledEdit.EditChange <alias=vLabeledEdit_EditChange>( evparEvent evn )
565 {
566 evn.sender = &this
567 return .OnChange.Run( evn )
568 }
569
570 method uint vLabeledEdit.EditFocus <alias=vLabeledEdit_EditFocus>( evparValUint evn )
571 {
572 evn.sender = &this
573 return .OnFocus.Run( evn )
574 }
575
576 method uint vLabeledEdit.EditKey <alias=vLabeledEdit_EditKey>( evparValUint evn )
577 {
578 evn.sender = &this
579 return .OnKey.Run( evn )
580 }
581
582
583
584 method uint vLabeledEdit.Btn1Click <alias=vLabeledEdit_Btn1Click>( evparEvent evn )
585 {
586 evn.sender = &this
587 return .OnBtn1Click.Run( evn )
588 }
589
590 method uint vLabeledEdit.Btn2Click <alias=vLabeledEdit_Btn2Click>( evparEvent evn )
591 {
592 evn.sender = &this
593 return .OnBtn2Click.Run( evn )
594 }
595
596 method vLabeledEdit vLabeledEdit.mCreateWin <alias=vLabeledEdit_mCreateWin>()
597 {
598 .CreateWin( "STATIC".ustr(), 0,
599 $SS_NOTIFY | $WS_CHILD | $WS_CLIPCHILDREN | $WS_CLIPSIBLINGS | $WS_OVERLAPPED )
600 this->vCtrl.mCreateWin()
601
602 this.LabelCon.ConCreateWin( this )
603 this.pCanContain = 1
604 /*if !&this.Edit.Owner
605 {*/
606 this.Edit.Owner = this
607 this.Edit.Virtual( $mReCreateWin )
608 this.Edit.Visible = 1
609 this.Edit.Left = 0
610 this.Edit.Top = 0
611 this.Edit.VertAlign = $alvClient
612 this.Edit.Width = 100
613 this.Edit.OnChange.Set( this, vLabeledEdit_EditChange )
614 this.Edit.OnFocus.Set( this, vLabeledEdit_EditFocus )
615 this.Edit.OnKey.Set( this, vLabeledEdit_EditKey )
616 //}
617 if this.pBtn1
618 {
619 this.pBtn1->vBtnPic.DestroyComp()
620 this.pBtn1 = 0
621 }
622 if this.pBtn2
623 {
624 this.pBtn2->vBtnPic.DestroyComp()
625 this.pBtn2 = 0
626 }
627
628 uint i
629 fornum i = 0, min( .pLEStyle, $lsTwoBtns )
630 {
631 uint btn
632 btn as this.CreateComp( vBtnPic )->vBtnPic
633 btn.Top = 0
634 btn.VertAlign = $alvTop
635 btn.HorzAlign = $alhRight
636 btn.Width = 100
637 btn.Right = 0
638 btn.pCanContain = 0
639 btn.Flat = 1
640 if i
641 {
642 btn.OnClick.Set( this, vLabeledEdit_Btn2Click )
643 btn.Image = .pBtn2Image
644 btn.Hint = .pBtn2Hint
645 this.pBtn2 = &btn
646 }
647 else
648 {
649 btn.OnClick.Set( this, vLabeledEdit_Btn1Click )
650 btn.Image = .pBtn1Image
651 btn.Hint = .pBtn1Hint
652 this.pBtn1 = &btn
653 }
654
655 }
656
657 eventpos evp
658 evp.loc = this.loc
659 evp.move = 0
660 .Virtual( $mPosChanging, evp )
661 return this
662 }
663
664 method vLabeledEdit.mSetOwner <alias=vLabeledEdit_mSetOwner>( vComp newowner )
665 {
666 /* this.LabelCon.LabeledCtrl = &this
667 this->vCtrl.mSetOwner( newowner )
668 this.LabelCon.ConSetOwner( )*/
669 if newowner : this.LabelCon.LabeledCtrl = &this
670 else : this.LabelCon.LabeledCtrl = 0
671 this->vCtrl.mSetOwner( newowner )
672 if newowner : this.LabelCon.ConSetOwner( )
673 }
674
675 method uint vLabeledEdit.mSetName <alias=vLabeledEdit_mSetName>( str newname )
676 {
677 this.LabelCon.ConSetName( newname )
678 return 1
679 }
680
681 method vLabeledEdit.mPosChanging <alias=vLabeledEdit_mPosChanging>( eventpos evp )
682 {
683 this->vCtrl.mPosChanging( evp )
684 .iUpdateBtns()
685 }
686
687 method vLabeledEdit.mSetVisible <alias=vLabeledEdit_mSetVisible>( )
688 {
689 this->vCtrl.mSetVisible()
690 .LabelCon.Visible = .Visible
691 }
692 /*------------------------------------------------------------------------------
693 Registration
694 */
695 /*method vLabeledEditOld vLabeledEditOld.init( )
696 {
697 this.pTypeId = vLabeledEditOld
698 return this
699 }*/
700
701 method vLabelCon vLabelCon.init( )
702 {
703 this.pTypeId = vLabelCon
704 return this
705 }
706
707 method vLabeledComboBox vLabeledComboBox.init( )
708 {
709 this.pTypeId = vLabeledComboBox
710 return this
711 }
712
713 method vLabeledEdit vLabeledEdit.init( )
714 {
715 this.flgXPStyle = 1
716 this.pTypeId = vLabeledEdit
717 return this
718 }
719
720 func init_vLabeledEditOld <entry>()
721 {
722 /*regcomp( vLabeledEditOld, "vLabeledEditOld", vEdit, $vCtrl_last,
723 %{ %{ $mCreateWin, vLabeledEditOld_mCreateWin },
724 %{ $mSetOwner, vLabeledEditOld_mSetOwner },
725 %{ $mSetName, vLabeledEditOld_mSetName },
726 %{ $mPosChanging, vLabeledEditOld_mPosChanging }
727 },
728 0->collection )*/
729 regcomp( vLabelCon, "vLabelCon", vLabel, $vCtrl_last,
730 %{ %{ $mSetCaption, vLabelCon_mSetCaption },
731 %{ $mLangChanged, vLabelCon_mLangChanged },
732 %{ $mCreateWin, vLabelCon_mCreateWin },
733 %{ $mPreDel, vLabelCon_mPreDel } },
734 0->collection )
735
736
737 regcomp( vLabeledEdit, "vLabeledEdit", vCtrl, $vCtrl_last,
738 %{ %{ $mCreateWin, vLabeledEdit_mCreateWin },
739 %{ $mSetOwner, vLabeledEdit_mSetOwner },
740 %{ $mSetName, vLabeledEdit_mSetName },
741 %{ $mPosChanging, vLabeledEdit_mPosChanging },
742 %{ $mSetVisible, vLabeledEdit_mSetVisible }
743 },
744 0->collection )
745
746 regcomp( vLabeledComboBox, "vLabeledComboBox", vComboBox, $vCtrl_last,
747 %{ %{ $mCreateWin, vLabeledComboBox_mCreateWin },
748 %{ $mSetOwner, vLabeledComboBox_mSetOwner },
749 %{ $mSetName, vLabeledComboBox_mSetName },
750 %{ $mPosChanging, vLabeledComboBox_mPosChanging },
751 %{ $mSetVisible, vLabeledComboBox_mSetVisible }
752 },
753 0->collection )
754
755
756 ifdef $DESIGNING {
757 //cm.AddComp( vLabeledEditOld, 1, "Windows", "labeled" )
758 cm.AddComp( vLabeledComboBox, 1, "Windows", "labeled" )
759 cm.AddComp( vLabeledEdit, 1, "Windows", "labeled" )
760
761 uint propcol as %{
762 "Caption" , ustr , 0,
763 "LabelPos" , uint , 0,
764 "AddColon" , uint , 0
765 }
766 uint lpcol as %{
767 "lpLeft", $lpLeft,
768 "lpAbove", $lpAbove
769 }
770
771 //cm.AddProps( vLabeledEditOld, propcol )
772 cm.AddProps( vLabeledComboBox, propcol )
773 cm.AddProps( vLabeledEdit, propcol@
774 %{ "Text" , ustr , 0,
775 "Password" , uint , 0,
776 "MaxLen" , uint , 0,
777 "Btn1Image", ustr , 0,
778 "Btn2Image", ustr , 0,
779 "Btn1Hint", ustr , 0,
780 "Btn2Hint", ustr , 0,
781 "LEStyle", uint, 0,
782 "Multiline", uint, 0,
783 "ScrollBars", uint, 0,
784 "ReadOnly", uint, 0
785 } )
786 cm.AddEvents( vLabeledEdit, %{
787 "OnBtn1Click" , "evparEvent",
788 "OnBtn2Click" , "evparEvent",
789 "OnChange" , "evparEvent"
790 })
791
792 //cm.AddPropVals( vLabeledEditOld, "LabelPos", lpcol )
793 cm.AddPropVals( vLabeledComboBox, "LabelPos", lpcol )
794 cm.AddPropVals( vLabeledEdit, "LabelPos", lpcol )
795
796 cm.AddPropVals( vLabeledEdit, "LEStyle",
797 %{ "lsSimple", $lsSimple,
798 "lsOneBtn", $lsOneBtn,
799 "lsTwoBtns", $lsTwoBtns })
800 }
801 }