1 /******************************************************************************
2 *
3 * Copyright (C) 2004-2009, 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.timer 11.09.09 0.0.A.
11 *
12 * Author: Alexander Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15 /*------------------------------------------------------------------------------
16 Import
17 */
18
19
20 import "user32.dll" {
21 uint SetTimer( uint, uint, uint, uint )
22 uint KillTimer( uint, uint )
23 }
24
25
26 /* Компонент vTimer, порождена от vComp
27 События
28 OnTimer - вызывается при срабатывании таймера
29 */
30
31 type vTimer <inherit = vComp>
32 {
33 //Hidden Fields
34 uint pEnabled
35 uint pInterval
36 uint flgDeleting
37 //Events
38 evEvent OnTimer
39 }
40
41
42 global {
43 uint pTimerProc
44 }
45
46 func TimerProc( uint hwnd, uint msg, uint id, uint time )
47 {
48 if id
49 {
50 id->vTimer.OnTimer.Run( id->vComp )
51 }
52 }
53 /*------------------------------------------------------------------------------
54 Internal Methods
55 */
56 /* Метод iUpdateTray
57 Обновляет настройки иконки
58 */
59 method vTimer.iUpdateTimer( )
60 {
61 uint form as .GetMainForm()->vForm
62 if &form && form.hwnd
63 {
64 if .pEnabled
65 {
66 SetTimer( form.hwnd, &this, .pInterval, pTimerProc )
67 }
68 else
69 {
70 KillTimer( form.hwnd, &this )
71 }
72 }
73 }
74
75 /*------------------------------------------------------------------------------
76 Properties
77 */
78 /* Свойство str vTimer.Interval - Get Set
79 Интервал таймера в миллисекундах
80 */
81 property uint vTimer.Interval
82 {
83 return this.pInterval
84 }
85
86 property vTimer.Interval( uint val )
87 {
88 if val != this.pInterval
89 {
90 this.pInterval = val
91 .iUpdateTimer()
92 }
93 }
94
95 /* Свойство uint vTimer.Enabled - Get Set
96 Включен/выключен таймер
97 */
98 property uint vTimer.Enabled
99 {
100 return .pEnabled
101 }
102
103 property vTimer.Enabled( uint val )
104 {
105 if .pEnabled != val
106 {
107 .pEnabled = val
108 .iUpdateTimer()
109 }
110 }
111
112
113 /*------------------------------------------------------------------------------
114 Virtual Methods
115 */
116
117 method vTimer.mPreDel <alias=vTimer_mPreDel>
118 {
119 .flgDeleting = 1
120 .iUpdateTimer()
121 this->vComp.mPreDel()
122 }
123
124 method vTimer.mOwnerCreateWin <alias=vTimer_mOwnerCreateWin>
125 {
126 .iUpdateTimer()
127 }
128
129 /*------------------------------------------------------------------------------
130 Registration
131 */
132 method vTimer vTimer.init( )
133 {
134 this.pTypeId = vTimer
135 this.pInterval = 1000
136 return this
137 }
138
139 func init_vTimer <entry>()
140 {
141 pTimerProc = callback( &TimerProc, 4 )
142 regcomp( vTimer, "vTimer", vComp, $vComp_last,
143 %{ %{$mPreDel, vTimer_mPreDel },
144 %{$mOwnerCreateWin, vTimer_mOwnerCreateWin }
145 },
146 0->collection )
147
148
149 ifdef $DESIGNING {
150 cm.AddComp( vTimer, 1, "Windows", "timer" )
151
152 cm.AddProps( vTimer, %{
153 "Interval", uint, 0,
154 "Enabled", uint, 0
155 })
156
157 cm.AddEvents( vTimer, %{
158 "OnTimer" , "evparEvent"
159 })
160
161 }
162
163 }
164
Редактировать