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 ustr pImageId
25 int pImageIndex
26 }
27
28 /* Компонента vTab, порождена от vCtrl, работает в паре vTabItem, может содеражть
29 только vTabItem
30 События
31 onChange - вызывается при смене закладки
32 */
33 type vTab <index=vTabItem inherit = vCtrl>
34 {
35 //Hidden Fields
36 vloc pAdjLoc //Координат внутреннего окна
37 uint pCurIndex //Индекс текущего элемента, если пусто -1
38 ustr pImageList
39 uint ptrImageList
40 uint iNumIml
41 uint pTabStyle
42
43 //Events
44 evValUint OnChange
45 }
46
47
48 extern {
49 property vTab.CurIndex( uint val )
50 property uint vTab.CurIndex( )
51 method vTab.iCalcAdj()
52 }
53
54 include {
55 "tabitem.g"
56 }
57
58
59 define <export>{
60 //Стили закладок TabStyle
61 tsTab = 0
62 tsButtons = 1
63 tsFlatButtons = 2
64 tsNone = 3
65 }
66
67 /*------------------------------------------------------------------------------
68 Internal Methods
69 */
70 /*Метод vTab.iCalcAdj()
71 Пересчитать размеры отводимые для странички
72 */
73 method vTab.iCalcAdj()
74 {
75 RECT r
76 r.left = 0
77 r.top = 0
78 r.right = this.loc.width
79 r.bottom = this.loc.height
80 this.WinMsg( $TCM_ADJUSTRECT, 0, &r )
81 this.pAdjLoc.left = r.left
82 this.pAdjLoc.top = r.top
83 this.pAdjLoc.width = r.right - r.left
84 this.pAdjLoc.height = r.bottom - r.top
85 }
86
87 /*Метод vTab.iSetCurIndex( uint val, flgchangetab )
88 Установить текущую страницу
89 val - номер страницы
90 flgchangetab - 1 - установить соответствующую закладку
91 */
92 method vTab.iSetCurIndex( uint val, uint flgchangetab )
93 {
94 val = max( int( min( int( val ), int(this.pCtrls)/**this.ctrls*/-1)), int(0) )
95 if /*val != this.pCurIndex &&*/ this.pCtrls
96 {
97 uint i, tabi
98 if this.pCurIndex >= 0 && this.pCurIndex < this.pCtrls/**this.ctrls*/
99 {
100 this./*ctrls*/Comps[this.pCurIndex]->vTabItem.Visible = 0
101 }
102 uint item as this./*ctrls*/Comps[val]->vTabItem
103 if !item.Enabled
104 {
105 fornum val=0, this.pCtrls/**this.ctrls*/
106 {
107 item as this./*ctrls*/Comps[val]->vTabItem
108 if item.Enabled :break
109 }
110 }
111 if item.Enabled
112 {
113 this.pCurIndex = val
114 if flgchangetab: this.WinMsg( $TCM_SETCURSEL, item.pWinIndex )
115 this./*ctrls*/Comps[val]->vTabItem.Visible = 1
116 }
117 else
118 {
119 this.pCurIndex = -1
120 }
121 evparValUint evp
122 evp.val = this.pCurIndex
123 .OnChange.Run( evp, this )
124 }
125 }
126
127 /*Метод vTab.iUpdateImageList()
128 Обновить ImageList
129 */
130 method vTab.iUpdateImageList()
131 {
132 .ptrImageList = &.GetImageList( .pImageList, &.iNumIml )
133 if .hwnd
134 {
135 if .ptrImageList
136 {//print( "xxxx \(.ptrImageList->ImageList.arrIml[.iNumIml].hIml)\n" )
137 .WinMsg( $TCM_SETIMAGELIST, 0, .ptrImageList->ImageList.arrIml[.iNumIml].hIml )
138 .WinMsg( $TCM_SETMINTABWIDTH, 1, 1 )
139 }
140 else
141 {
142 .WinMsg( $TCM_SETIMAGELIST, 0, 0 )
143 }
144 .Invalidate()
145 }
146 }
147
148 /*------------------------------------------------------------------------------
149 Properties
150 */
151 /*Количество элементов uint *vTab
152 Возвращает количество закладок
153 */
154 operator uint *( vTab tab )
155 {
156 return tab.pCtrls/**tab.ctrls*/
157 }
158
159 /*Индекс vTabItem vTab[index]
160 Возвращает закладку с текущим номером
161 */
162 method vTabItem vTab.index( uint index )
163 {
164 if index != -1 && index < .pCtrls/**.ctrls*/
165 {
166 return ./*ctrls*/Comps[ index ]->vTabItem
167 }
168 return 0->vTabItem
169 }
170
171 /* Свойство uint CurIndex - Get Set
172 Усотанавливает или определяет номер открытой закладки
173 */
174 property uint vTab.CurIndex()
175 {
176 return this.pCurIndex
177 }
178
179 property vTab.CurIndex( uint val )
180 {
181 if val != .pCurIndex
182 {
183 this.iSetCurIndex( val, 1 )
184 }
185 }
186
187 /* Свойство vTabItem CurItem - Get
188 Получить текущую страницу
189 */
190 property vTabItem vTab.CurItem()
191 {
192 return this[.pCurIndex]->vTabItem
193 }
194
195 /* Свойство str vTab.ImageList - Get Set
196 Устанавливает или получает имя списка картинок
197 */
198 property ustr vTab.ImageList <result>
199 {
200 result = this.pImageList
201 }
202
203 property vTab.ImageList( ustr val )
204 {
205 if val != this.pImageList
206 {
207 this.pImageList = val
208 .Virtual( $mLangChanged )
209 }
210 }
211
212 /* Свойство uint TabStyle - Get Set
213 Усотанавливает или определяет вид закладок
214 */
215 property uint vTab.TabStyle()
216 {
217 return this.pTabStyle
218 }
219
220 property vTab.TabStyle( uint val )
221 {
222 if val != .pTabStyle
223 {
224 .pTabStyle = val
225 .Virtual( $mReCreateWin )
226 }
227 }
228
229 /*------------------------------------------------------------------------------
230 Virtual Methods
231 */
232 method vTab.mInsert <alias=vTab_mInsert>( vTabItem item )
233 {
234 if item.TypeIs( vTabItem )
235 {
236 this->vCtrl.mInsert( item )
237 //uint curenabled = item.pEnabled
238 //item.pEnabled = 0
239 //item.Enabled = curenabled
240 item.mSetEnabled()
241 //setxpstyle( item.hwnd )
242 /*eventpos evp
243 evp.code = $e_poschanging
244 evp.move = 1
245 item.Virtual( $mPosChanging, &evp )*/
246 evparValUint evu
247 evu.val = 1
248 .Virtual( $mPosChanged, evu )
249 if .CurIndex == -1
250 {
251 .CurIndex = 0
252 }
253 }
254 }
255
256 method vTab.mRemove <alias=vTab_mRemove>( vTabItem item )
257 {
258 uint i
259 fornum i = item.pIndex + 1, .pCtrls//cidx + 1, .pCtrls
260 {
261 uint nextitem as .Comps[i]->vTabItem
262 if nextitem.Enabled
263 {
264 nextitem.pWinIndex--
265 }
266 }
267 this.WinMsg( $TCM_DELETEITEM, item.pIndex )//item.cidx )
268 this->vCtrl.mRemove( item )
269 this.CurIndex = this.CurIndex
270 }
271
272 method vTab vTab.mCreateWin <alias=vTab_mCreateWin>()
273 {
274 uint style = $WS_CHILD | $WS_CLIPSIBLINGS | $WS_CLIPCHILDREN
275 switch .pTabStyle
276 {
277 case $tsButtons : style |= $TCS_BUTTONS
278 case $tsFlatButtons : style |= $TCS_BUTTONS | $TCS_FLATBUTTONS
279 }
280 ifdef !$DESIGNING {
281 if .pTabStyle == $tsNone
282 {
283 this.CreateWin( "GVForm".ustr(), 0, style )
284 this.prevwndproc = -1
285 }
286 else
287 }
288 {
289 this.CreateWin( "SysTabControl32".ustr(), 0, style )
290 }
291 this->vCtrl.mCreateWin()
292 .iUpdateImageList()
293 .WinMsg( $TCM_SETTOOLTIPS, this.GetForm()->vForm.hwndTip )
294 uint i
295 fornum i = 0, this.pCtrls
296 {
297 uint item as .Comps[i]->vTabItem
298 if item.Enabled
299 {
300 item.mSetEnabled()
301 }
302 }
303 evparValUint evu
304 evu.val = 1
305 .Virtual( $mPosChanged, evu )
306 .iSetCurIndex( .pCurIndex, 1 )
307 return this
308 }
309
310 method uint vTab.mPosChanged <alias=vTab_mPosChanged>( evparEvent ev )
311 {
312 this.iCalcAdj()
313 this->vCtrl.mPosChanged( ev )
314 uint i
315 fornum i = 0, this.pCtrls
316 {
317 uint item as .Comps[i]->vTabItem
318 uint loc as .pAdjLoc
319 item.SetLocation( loc.left, loc.top, loc.width, loc.height )
320 }
321 return 0
322 }
323
324 method uint vTab.mWinNtf <alias=vTab_mWinNtf>( winmsg wmsg )//NMHDR ntf )
325 {
326 uint ntf as wmsg.lpar->NMHDR
327 if ntf.code == $TCN_SELCHANGE
328 {
329 uint i
330 uint tabi = this.WinMsg( $TCM_GETCURSEL )
331 uint curi
332 fornum i, this.pCtrls/**this.ctrls*/
333 {
334 if this./*ctrls*/Comps[i]->vTabItem.Enabled
335 {
336 if curi == tabi : break
337 curi++
338 }
339 }
340 .iSetCurIndex( curi, 0 )
341 }
342 return 0
343 }
344
345 method vTab.mGetHint <alias=vTab_mGetHint>( uint id, uint lpar, ustr resstr )
346 {
347 uint i, curi
348
349 fornum i, this.pCtrls
350 {
351 if this.Comps[i]->vTabItem.Enabled
352 {
353 if curi == id
354 {
355 resstr = this.Comps[i]->vTabItem.pHint.Text( this )
356 break
357 }
358 curi++
359 }
360 }
361 }
362
363 /*Виртуальный метод vTab.mLangChanged - Изменение текущего языка
364 */
365 method vTab.mLangChanged <alias=vTab_mLangChanged>()
366 {
367 .iUpdateImageList()
368 this->vCtrl.mLangChanged()
369 }
370
371 /*------------------------------------------------------------------------------
372 Registration
373 */
374 method vTab vTab.init( )
375 {
376 this.pTypeId = vTab
377
378 this.pCanContain = 1
379 this.pTabStop = 1
380 this.pCurIndex = -1
381 //this.flgXPStyle = 1
382 return this
383 }
384 /*
385 method vTab.getprops( uint typeid, compMan cm )
386 {
387 this->vCtrl.getprops( typeid, cm)
388 cm.addprops( typeid,
389 %{ "caption" , str, 0})
390 }*/
391
392 /*
393 method vTab.getevents()
394 {
395 %{"onclick"}
396 }
397 */
398 func init_vTab <entry>()
399 {
400 regcomp( vTab, "vTab", vCtrl, $vCtrl_last,
401 %{ %{$mInsert, vTab_mInsert },
402 %{$mRemove, vTab_mRemove },
403 %{$mCreateWin, vTab_mCreateWin },
404 %{$mPosChanged, vTab_mPosChanged },
405 %{$mWinNtf, vTab_mWinNtf },
406 %{$mGetHint, vTab_mGetHint },
407 %{$mLangChanged, vTab_mLangChanged }
408 },
409 0->collection )
410
411 ifdef $DESIGNING {
412 cm.AddComp( vTab, 1, "Windows", "tab" )
413
414 cm.AddProps( vTab, %{
415 //"TabOrder", uint, 0,
416 "CurIndex", uint, $PROP_LOADAFTERCHILD,
417 "ImageList", ustr, 0,
418 "TabStyle", uint, 0
419 })
420
421 cm.AddEvents( vTab, %{
422 "OnChange" , "evparValUint"
423 })
424
425 cm.AddPropVals( vTab, "TabStyle", %{
426 "tsTab", $tsTab,
427 "tsButtons", $tsButtons,
428 "tsFlatButtons", $tsFlatButtons,
429 "tsNone", $tsNone
430 })
431
432 cm.AddComp( vTabItem )
433
434 cm.AddProps( vTabItem, %{
435 "Caption", ustr, 0,
436 "ImageId", ustr, 0
437 })
438
439
440
441 }
442 }