EnglishРусский  

   ..

   addustr.g

   app.g

   btn.g

   btnpic.g

   comp.g

   ctrl.g

   ctrlci.g

   dialogs.g

   dlgbtns.g

   edit.g

   events.g

   fonts.g

   form.g

   gray.g

   grey.g

   header.g

   images.g

   label.g

   labeled.g

   locustr.g

   menu.g

   panel.g

   picture.g

   styles.g

   tab.g

   tabitem.g

   tabpage.g

   timer.g

   toolbar.g

   tray.g

   url.g

   vis.g

   viswin.g

Реклама

Инсталлятор CreateInstall
Бесплатные и коммерческие инсталляторы

source\lib\vis\ctrlci.g
  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.btnpic 22.07.08 0.0.A.
 11 *
 12 * Author: Alexander Krivonogov ( gentee )
 13 *
 14 ******************************************************************************/
 15 
 16 type PicText
 17 {
 18    uint  pCtrl
 19    
 20    ustr  pLangCaption    
 21    uint  pPtrImage   
 22    uint  pLayout
 23    uint  pSpacing
 24    uint  pIndent
 25    uint  pWidth
 26    uint  pHeight
 27    
 28    uint  pWordWrap
 29    uint  pAutoSize
 30    uint  pContHorzAlign
 31    uint  pContVertAlign   
 32    
 33    uint  imgleft 
 34    uint  imgtop
 35    uint  txtleft
 36    uint  txttop
 37    uint  hFont
 38 }
 39 
 40 define <export>{
 41 //Расположение картинки и текста
 42    lPicLeft     = 0 
 43    lPicTop      = 1
 44    lPicRight    = 2
 45    lPicBottom   = 3
 46    lPicBack     = 4
 47    lPicSimple   = 5
 48    
 49    ptLeft       = 0
 50    ptCenter     = 1   
 51    ptRight      = 2
 52    
 53    ptTop        = 0
 54    ptVertCenter = 1
 55    ptBottom     = 2         
 56 } 
 57 
 58 method PicText.iCalc
 59 {
 60    if .pCtrl
 61    {      
 62        //if .pCtrl->vCtrl.TypeName == "vBtnPic" : print( "iCalc\n" )
 63       //if !.hFont : .hFont = .pCtrl->vCtrl.WinMsg( $WM_GETFONT )
 64       int pw, ph, pt, pl
 65       int tw, th, tt, tl
 66       int cw, ch
 67       int hoff, voff
 68       int maxw, maxh
 69       
 70       int spc = .pSpacing
 71       int off = .pIndent
 72       
 73       RECT r
 74       uint dc = GetDC( 0 )
 75       
 76       if .pPtrImage
 77       {   
 78          pw = .pPtrImage->Image.Width
 79          ph = .pPtrImage->Image.Height                  
 80       }
 81       if !.pPtrImage || !*this.pLangCaption
 82       {
 83          spc = 0
 84       }
 85       
 86       hoff = voff = off * 2
 87       if pw && ph
 88       {
 89          switch .pLayout 
 90          {
 91             case $lPicTop, $lPicBottom:  voff += ph + spc    
 92             case $lPicBack: 
 93             default : hoff += pw + spc
 94          }
 95       }
 96                                     
 97       r.right = maxw = max( .pWidth - hoff, 10 )
 98       r.bottom = maxh = max( .pHeight - voff, 10 )
 99       
100       SelectObject( dc, .hFont )
101       DrawText( dc, .pLangCaption.ptr(), *this.pLangCaption, r, 
102             $DT_TOP | $DT_LEFT | $DT_CALCRECT | ?( .pWordWrap, $DT_WORDBREAK, 0 ) |
103             $DT_NOPREFIX )
104       
105       ReleaseDC( 0, dc )
106       tw = r.right
107       th = r.bottom
108       
109       switch .pLayout
110       {
111          case $lPicTop
112          {
113             pt = 0
114             if ph : tt = ph + spc
115             cw = min( max( tw, pw ), maxw )
116             ch = tt + th 
117             pl = (cw - pw) / 2
118             tl = (cw - tw) / 2        
119          }
120          case $lPicBottom
121          {         
122             tt = 0
123             if th : pt = th + spc
124             cw = min( max( tw, pw ), maxw )
125             ch = pt + ph
126             pl = (cw - pw) / 2
127             tl = (cw - tw) / 2          
128          }
129          case $lPicLeft
130          {
131             pl = 0 
132             if pw : tl = pw + spc
133             cw = tl + tw 
134             ch = min( max( th, ph ), maxh )  
135             tt = (ch - th) / 2
136             pt = (ch - ph) / 2
137          }
138          case $lPicRight
139          {  
140             tl = 0 
141             if tw : pl = tw + spc         
142             cw = pl + pw
143             ch = min( max( th, ph ), maxh )
144             tt = (ch - th) / 2
145             pt = (ch - ph) / 2      
146          }          
147          case $lPicBack
148          {         
149             cw = min( max( tw, pw ), maxw )
150             ch = min( max( th, ph ), maxh )
151             pl = (cw - pw) / 2
152             pt = (ch - ph) / 2
153             tl = (cw - tw) / 2
154             tt = (ch - th) / 2         
155          }
156          default
157          {   
158             pl = 0
159             if pw : tl = pw + spc
160             pt = 0 
161             tt = 0
162             cw = tl + tw
163             ch = max( th, ph )                  
164          }
165       }
166       
167       if .pAutoSize
168       {
169          .pCtrl->vCtrl.Width = cw + 2 * off //tw + hoff
170          .pCtrl->vCtrl.Height = ch + 2 * off //th + voff
171       }
172       switch .pContHorzAlign
173       {
174          case $ptRight : hoff = .pWidth - cw - off
175          case $ptCenter : hoff = ( .pWidth - cw )/2
176          default : hoff = off 
177       }
178       switch .pContVertAlign
179       {
180          case $ptBottom : voff = .pHeight - ch - off
181          case $ptVertCenter : voff = ( .pHeight - ch )/2
182          default : voff = off
183       }   
184       hoff = max( hoff, off )
185       voff = max( voff, off )
186       //print( "tw \(tw) \(th) \(pw) \(ph) \n" )
187       //print( "i \(pl) \(pt) \(tl) \(tt ) \(hoff ) \(voff)\n" )
188       .imgleft = max( pl + hoff, 0 )
189       .imgtop = max( pt + voff, 0 )
190       .txtleft = max( tl + hoff, 0 )
191       .txttop = max( tt + voff, 0 )
192       
193       .pCtrl->vCtrl.Invalidate()
194    }
195 }
196 
197 property PicText.Ctrl( vCtrl val )
198 {
199    .pCtrl = &val
200    .iCalc()   
201 }
202 
203 property PicText.LangCaption( ustr val )
204 {
205    if .pLangCaption != val
206    {
207       .pLangCaption = val
208       .iCalc()
209    }
210 }
211    
212 property PicText.PtrImage( uint val )
213 {
214    if .pPtrImage != val
215    {
216       .pPtrImage = val
217       .iCalc()
218    }
219 }
220 
221 property PicText.Width( uint val )
222 {
223    if .pWidth != val
224    {
225       .pWidth = val
226       .iCalc()
227    }
228 }
229 
230 property PicText.Height( uint val )
231 {  
232    if .pHeight != val
233    {
234       .pHeight = val
235       .iCalc()
236    }
237 }
238 
239 
240 property PicText.Layout( uint val ) 
241 {
242    if .pLayout != val
243    {
244       .pLayout = val
245       .iCalc()
246    }
247 }
248 
249 property uint PicText.Layout
250 {
251    return .pLayout
252 }
253 
254 property PicText.Spacing( uint val ) 
255 {
256    if .pSpacing != val 
257    {
258       .pSpacing = val
259       .iCalc()
260    }
261 }
262 
263 property uint PicText.Spacing
264 {
265    return .pSpacing
266 }
267 
268 property PicText.Indent( uint val ) 
269 {
270    if .pIndent != val
271    {
272       .pIndent = val
273       .iCalc()
274    }
275 }
276 
277 property uint PicText.Indent
278 {
279    return .pIndent
280 }
281    
282 property PicText.WordWrap( uint val ) 
283 {
284    if .pWordWrap != val 
285    {
286       .pWordWrap = val
287       .iCalc()
288    }
289 }
290 
291 property uint PicText.WordWrap
292 {
293    return .pWordWrap
294 }   
295 
296 property PicText.AutoSize( uint val ) 
297 {
298    if .pAutoSize != val
299    {
300       .pAutoSize = val
301       .iCalc()
302    }
303 }
304 
305 property uint PicText.AutoSize
306 {
307    return .pAutoSize
308 }
309 
310 property PicText.ContHorzAlign( uint val ) 
311 {
312    if .pContHorzAlign != val
313    {   
314       .pContHorzAlign = val
315       .iCalc()
316    }
317 }
318 
319 property uint PicText.ContHorzAlign
320 {
321    return .pContHorzAlign
322 }
323 
324 property PicText.ContVertAlign( uint val ) 
325 {
326    if .pContVertAlign != val
327    {
328       .pContVertAlign = val
329       .iCalc()
330    }
331 } 
332 
333 property uint PicText.ContVertAlign
334 {
335    return .pContVertAlign
336 }
337  
338 method PicText.FontChanged()
339 {   
340    .hFont = .pCtrl->vCtrl.WinMsg( $WM_GETFONT )
341    .iCalc()
342 } 
343  
344 method PicText.Draw( uint hdc, uint left, uint top )
345 {
346    RECT r
347    
348    SetBkMode( hdc, $TRANSPARENT )
349    if .pPtrImage
350    {  
351       DrawIconEx( hdc, left + .imgleft, top + .imgtop , 
352          ?( .pCtrl->vCtrl.Enabled, .pPtrImage->Image.hImage, .pPtrImage->Image.hDisImage ),
353          .pPtrImage->Image.Width, .pPtrImage->Image.Height, 0, 0,
354          $DI_COMPAT | $DI_NORMAL )      
355    }
356    
357    r.left = left + .txtleft 
358    r.top = top + .txttop 
359    r.right = left + .pWidth 
360    r.bottom = top + .pHeight     
361    if !.pCtrl->vCtrl.Enabled
362    {
363       SetTextColor( hdc, GetSysColor(16) )
364    }
365    DrawText(hdc, .pLangCaption.ptr(), *.pLangCaption, r, $DT_TOP | $DT_LEFT | 
366                ?( .pWordWrap, $DT_WORDBREAK, 0 ) | $DT_NOPREFIX )
367    
368 }
369 
370 /*Системный метод vHeader vHeader.init - Инициализация объекта
371 */   
372 method PicText PicText.init( )
373 {      
374    .pIndent = 5
375    .pSpacing = 5
376    .pContHorzAlign = $ptCenter
377    .pContVertAlign = $ptVertCenter
378    return this 
379 }
380 
381 /* Компонента vCtrlCI, порождена от vCtrl
382 События
383 */
384 type vCtrlCI <inherit = vCtrl>
385 {
386 //Hidden Fields
387    PicText    pPicText
388    
389    locustr pCaption
390    //ustr    pLangCaption
391    ustr    pImage   
392    //uint    ptrImage
393 //Events      
394 }
395 
396 
397 /*------------------------------------------------------------------------------
398    Internal Methods
399 */
400 /*Внутренний метод vCtrlCI.iUpdateImage()
401 Обновить картинку
402 */
403 method vCtrlCI.iUpdateImage()
404 {  
405    .pPicText.PtrImage = &this.GetImage( .pImage )
406    /*uint oldimage = .ptrImage   
407    .ptrImage = &this.GetImage( .pImage )
408    if oldimage != .ptrImage : .Virtual( $mSetImage, .ptrImage )*/ 
409 }
410 
411 /*Внутренний метод vCtrlCI.iUpdateImage()
412 Обновить заголовок
413 */
414 method vCtrlCI.iUpdateCaption()
415 {  
416    .pPicText.LangCaption = this.pCaption.Text( this )
417    /*ustr oldcaption = .pLangCaption
418    .pLangCaption = this.pCaption.Text( this )
419    if oldcaption != .pLangCaption : .Virtual( $mSetCaption, &.pLangCaption )*/ 
420 }
421 
422 /*------------------------------------------------------------------------------
423    Properties
424 */
425 /* Свойство ustr vCtrlCI.Image - Get Set
426 Устанавливает или получает картинку
427 */
428 property ustr vCtrlCI.Image <result>
429 {
430    result = this.pImage
431 }
432 
433 property vCtrlCI.Image( ustr val )
434 {
435    if val != this.pImage
436    {    
437       this.pImage = val      
438       .iUpdateImage()
439    } 
440 }
441 
442 /* Свойство str vCtrlCI.Caption - Get Set
443 Усотанавливает или получает заколовок
444 */
445 property ustr vCtrlCI.Caption <result>
446 {
447    result = this.pCaption.Value
448 }
449 
450 property vCtrlCI.Caption( ustr val )
451 {
452    if val != this.pCaption.Value
453    { 
454       this.pCaption.Value = val
455       .iUpdateCaption()
456    } 
457 }
458 
459 /*------------------------------------------------------------------------------
460    Virtual Methods
461 */
462 /*Виртуальный метод uint vCtrlCI.mLangChanged 
463 Изменение текущего языка
464 */
465 method vCtrlCI.mLangChanged <alias=vCtrlCI_mLangChanged>()
466 {   
467    this->vCtrl.mLangChanged()
468    .iUpdateCaption()  
469    .iUpdateImage()
470 }
471 
472 /*Виртуальный метод vLabel.mSetName
473 Установка заголовка в режиме проектирования
474 */
475 method uint vCtrlCI.mSetName <alias=vCtrlCI_mSetName>( str newname )
476 {
477 ifdef $DESIGNING {   
478    if !.p_loading && .Caption == .Name
479    {
480       .Caption = newname.ustr()
481    }
482 }   
483    return 1 
484 }
485 
486 /*Виртуальный метод vCtrlCI vCtrlCI.mFontChanged - изменение шрифта окна
487 */
488 /*method vCtrlCI.mFontChanged <alias=vCtrlCI_mFontChanged> ()
489 { 
490    this->vCtrl.mFontChanged()
491    .pPicText.hFont = .WinMsg( $WM_GETFONT )
492 }*/
493 
494 /*------------------------------------------------------------------------------
495    Registration
496 */
497 /*Системный метод vCtrlCI vCtrlCI.init - Инициализация объекта
498 */   
499 method vCtrlCI vCtrlCI.init( )
500 {   
501    this.pTypeId = vCtrlCI        
502    return this 
503 }  
504 
505 
506 func init_vCtrlCI <entry>()
507 {  
508    regcomp( vCtrlCI, "vCtrlCI", vCtrl, $vCtrl_last, 
509       %{ 
510          %{$mSetName,        vCtrlCI_mSetName }, 
511          %{$mLangChanged,    vCtrlCI_mLangChanged }/*,
512          %{$mFontChanged,    vCtrlCI_mFontChanged }*/
513       }, 
514       0->collection )
515 }
516 
517 
518 
519 
520 
Редактировать