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.tab 24.07.07 0.0.A.
11 *
12 * Author: Alexander Krivonogov ( gentee )
13 *
14 ******************************************************************************/
15
16 /* Компонента vTabItem, порождена от vCtrl, работает в паре vTab, может
17 находиться только внутри vTab
18 */
19 type vTabItem <inherit = vCtrl>
20 {
21 //Hidden Fields
22 locustr pCaption //Заголовок
23 uint pWinIndex //Индекс закладки в оконном представлении
24 }
25
26 /* Компонента vTab, порождена от vCtrl, работает в паре vTabItem, может содеражть
27 только vTabItem
28 События
29 onChange - вызывается при смене закладки
30 */
31 type vTab <index=vTabItem inherit = vCtrl>
32 {
33 //Hidden Fields
34 vloc pAdjLoc //Координат внутреннего окна
35 uint pCurIndex //Индекс текущего элемента, если пусто -1
36
37 //Events
38 evEvent onChange
39 }
40
41
42 extern {
43 property vTab.CurIndex( uint val )
44 property uint vTab.CurIndex( )
45 method vTab.iCalcAdj()
46 }
47
48 include {
49 "tabitem.g"
50 }
51
52 /*------------------------------------------------------------------------------
53 Internal Methods
54 */
55 /*Метод vTab.iCalcAdj()
56 Пересчитать размеры отводимые для странички
57 */
58 method vTab.iCalcAdj()
59 {
60 RECT r
61 r.left = 0
62 r.top = 0
63 r.right = this.loc.width
64 r.bottom = this.loc.height
65 this.WinMsg( $TCM_ADJUSTRECT, 0, &r )
66 this.pAdjLoc.left = r.left
67 this.pAdjLoc.top = r.top
68 this.pAdjLoc.width = r.right - r.left
69 this.pAdjLoc.height = r.bottom - r.top
70 }
71
72 /*Метод vTab.iSetCurIndex( uint val, flgchangetab )
73 Установить текущую страницу
74 val - номер страницы
75 flgchangetab - 1 - установить соответствующую закладку
76 */
77 method vTab.iSetCurIndex( uint val, flgchangetab )
78 {
79 val = max( int( min( int( val ), int(this.pCtrls)/**this.ctrls*/-1)), int(0) )
80 if val != this.pCurIndex && this.pCtrls
81 {
82 uint i, tabi
83 if this.pCurIndex >= 0 && this.pCurIndex < this.pCtrls/**this.ctrls*/
84 {
85 this./*ctrls*/Comps[this.pCurIndex]->vTabItem.Visible = 0
86 }
87 uint item as this./*ctrls*/Comps[val]->vTabItem
88 if !item.Enabled
89 {
90 fornum val=0, this.pCtrls/**this.ctrls*/
91 {
92 item as this./*ctrls*/Comps[val]->vTabItem
93 if item.Enabled :break
94 }
95 }
96 if item.Enabled
97 {
98 this.pCurIndex = val
99 if flgchangetab: this.WinMsg( $TCM_SETCURSEL, item.pWinIndex )
100 this./*ctrls*/Comps[val]->vTabItem.Visible = 1
101 }
102 else
103 {
104 this.pCurIndex = -1
105 }
106 //.onChange.Run( this.pCurIndex )
107 }
108 }
109
110
111 /*------------------------------------------------------------------------------
112 Properties
113 */
114 /*Количество элементов uint *vTab
115 Возвращает количество закладок
116 */
117 operator uint *( vTab tab )
118 {
119 return tab.pCtrls/**tab.ctrls*/
120 }
121
122 /*Индекс vTabItem vTab[index]
123 Возвращает закладку с текущим номером
124 */
125 method vTabItem vTab.index( uint index )
126 {
127 if index != -1 && index < .pCtrls/**.ctrls*/
128 {
129 return ./*ctrls*/Comps[ index ]->vTabItem
130 }
131 return 0->vTabItem
132 }
133
134 /* Свойство uint CurIndex - Get Set
135 Усотанавливает или определяет номер открытой закладки
136 */
137 property uint vTab.CurIndex()
138 {
139 return this.pCurIndex
140 }
141
142 property vTab.CurIndex( uint val )
143 {
144 this.iSetCurIndex( val, 1 )
145 }
146
147 /* Свойство vTabItem CurItem - Get
148 Получить текущую страницу
149 */
150 property vTabItem vTab.CurItem()
151 {
152 return this[.pCurIndex]->vTabItem
153 }
154
155 /*------------------------------------------------------------------------------
156 Virtual Methods
157 */
158 method vTab.mInsert <alias=vTab_mInsert>( vTabItem item )
159 {
160 if item.TypeIs( vTabItem )
161 {
162 this->vCtrl.mInsert( item )
163 //uint curenabled = item.pEnabled
164 //item.pEnabled = 0
165 //item.Enabled = curenabled
166 item.mSetEnabled()
167 //setxpstyle( item.hwnd )
168 eventpos evp
169 evp.code = $e_poschanging
170 evp.move = 1
171 item.Virtual( $mPosChanging, &evp )
172 if .CurIndex == -1
173 {
174 .CurIndex = 0
175 }
176 }
177 }
178
179 method vTab.mRemove <alias=vTab_mRemove>( vTabItem item )
180 {
181 uint i
182 fornum i = item.cidx + 1, .pCtrls/**(this.Owner->vCtrl.ctrls)*/
183 {
184 uint nextitem as .Comps[i]->vTabItem
185 if nextitem.Enabled
186 {
187 nextitem.pWinIndex--
188 }
189 }
190 this.WinMsg( $TCM_DELETEITEM, item.cidx )
191 this->vCtrl.mRemove( item )
192 this.CurIndex = this.CurIndex
193 }
194
195 method vTab vTab.mCreateWin <alias=vTab_mCreateWin>()
196 {
197 this.CreateWin( "SysTabControl32".ustr(), 0, $WS_CHILD | $WS_VISIBLE | $WS_CLIPSIBLINGS | $WS_CLIPCHILDREN )
198 this->vCtrl.mCreateWin()
199 .WinMsg( $TCM_SETTOOLTIPS, this.GetForm()->vForm.hwndTip )
200 /*uint h = FindWindow( this.hwnd, 0, "msctrls_updown32", 0 )
201 if h
202 {
203 SetWindowPos( this.wdown->vCtrl.hwnd, 0, 0, 0, 0, 0, $SWP_NOACTIVATE | $SWP_NOMOVE | $SWP_NOSIZE | $SWP_TOPMOST )
204 }*/
205 //this.WinMsg( $WM_SETFONT, GetStockObject( $DEFAULT_GUI_FONT ) )
206 return this
207 }
208
209 method uint vTab.mPosChanged <alias=vTab_mPosChanged>( evparEvent ev )
210 {
211 this.iCalcAdj()
212 this->vCtrl.mPosChanged( ev )
213 return 0
214 }
215
216 method uint vTab.mWinNtf <alias=vTab_mWinNtf>( NMHDR ntf )
217 {
218 if ntf.code == $TCN_SELCHANGE
219 {
220 uint i
221 uint tabi = this.WinMsg( $TCM_GETCURSEL )
222 uint curi
223 fornum i, this.pCtrls/**this.ctrls*/
224 {
225 if this./*ctrls*/Comps[i]->vTabItem.Enabled
226 {
227 if curi == tabi : break
228 curi++
229 }
230 }
231 .iSetCurIndex( curi, 0 )
232 }
233 return 0
234 }
235
236 method vTab.mGetHint <alias=vTab_mGetHint>( uint id, lpar, ustr resstr )
237 {
238 uint i, curi
239 fornum i, this.pCtrls
240 {
241 if this.Comps[i]->vTabItem.Enabled
242 {
243 if curi == id
244 {
245 resstr = this.Comps[i]->vTabItem.pHint.Text( this )
246 }
247 curi++
248 }
249 }
250 }
251
252 /*------------------------------------------------------------------------------
253 Registration
254 */
255 method vTab vTab.init( )
256 {
257 this.pTypeId = vTab
258
259 this.pCanContain = 1
260 this.pTabStop = 1
261 this.pCurIndex = -1
262 //this.flgXPStyle = 1
263 return this
264 }
265 /*
266 method vTab.getprops( uint typeid, compMan cm )
267 {
268 this->vCtrl.getprops( typeid, cm)
269 cm.addprops( typeid,
270 %{ "caption" , str, 0})
271 }*/
272
273 /*
274 method vTab.getevents()
275 {
276 %{"onclick"}
277 }
278 */
279 func init_vTab <entry>()
280 {
281 regcomp( vTab, "vTab", vCtrl, $vCtrl_last,
282 %{ %{$mInsert, vTab_mInsert },
283 %{$mRemove, vTab_mRemove },
284 %{$mCreateWin, vTab_mCreateWin },
285 %{$mPosChanged, vTab_mPosChanged },
286 %{$mWinNtf, vTab_mWinNtf },
287 %{$mGetHint, vTab_mGetHint }
288 },
289 0->collection )
290
291 ifdef $DESIGNING {
292 cm.AddComp( vTab, 1, "Windows", "tab" )
293
294 cm.AddProps( vTab, %{
295 "TabOrder", uint, 0,
296 "CurIndex", uint, $PROP_LOADAFTERCHILD
297 })
298
299 cm.AddComp( vTabItem )
300
301 cm.AddProps( vTabItem, %{
302 "Caption", ustr, 0
303 })
304 }
305 }