Page 1 of 1

Long standing bug in FWH

Posted: Fri Nov 07, 2014 8:06 am
by Antonio Linares
Our dear Paco García sent me an email some days ago as he found a bug that has been in FiveWin since its early days and that it is the cause for pixels dimensions used on the dialogs not to work fine:

Code: Select all

METHOD cToChar( cCtrlClass ) CLASS TControl

   local n := GetDlgBaseUnits()

   DEFAULT cCtrlClass := ::ClassName(),;
           ::cCaption := "",;
           ::nId      := ::GetNewId(),;
           ::nStyle   := nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP )

return cCtrl2Chr( Int( 2 * 8 * ::nTop    / nHiWord( n ) ),;
                  Int( 2 * 4 * ::nLeft   / nLoWord( n ) ),;
                  Int( 2 * 8 * ::nBottom / nHiWord( n ) ),;
                  Int( 2 * 4 * ::nRight  / nLoWord( n ) ),;
                  ::nId, ::nStyle, cCtrlClass, ::cCaption )
Those "2" are not needed at all and thats the reason why the pixels dimensions are not respected.

I am very thankfull to Paco for his great help discovering this londstanding bug.

Now we need to decide what to do. We have to keep backwards compatibility, so he proposed me a new clause:

In dialog.ch

Code: Select all

#xcommand DEFINE DIALOG <oDlg> ;
             [ <resource: NAME, RESNAME, RESOURCE> <cResName> ] ;
             [ TITLE <cTitle> ] ;
             [ FROM <nTop>, <nLeft> TO <nBottom>, <nRight> ] ;
             [ SIZE <nWidth>, <nHeight> ] ;
             [ <lib: LIBRARY, DLL> <hResources> ] ;
             [ <vbx: VBX> ] ;
             [ STYLE <nStyle> ] ;
             [ <color: COLOR, COLORS> <nClrText> [,<nClrBack> ] ] ;
             [ BRUSH <oBrush> ] ;
             [ <of: WINDOW, DIALOG, OF> <oWnd> ] ;
             [ <pixel: PIXEL> ] ;
             [ ICON <oIco> ] ;
             [ FONT <oFont> ] ;
             [ <help: HELP, HELPID> <nHelpId> ] ;
             [ <transparent: TRANSPARENT> ] ;
             [ GRADIENT <aGradColors> ] ;
             [ <lTruePixel: TRUEPIXEL>  ] ;
       => ;
          <oDlg> = TDialog():New( <nTop>, <nLeft>, <nBottom>, <nRight>,;
                 <cTitle>, <cResName>, <hResources>, <.vbx.>, <nStyle>,;
                 <nClrText>, <nClrBack>, <oBrush>, <oWnd>, <.pixel.>,;
                 <oIco>, <oFont>, <nHelpId>, <nWidth>, <nHeight>, <.transparent.>,;
                 <aGradColors>, <.lTruePixel.> )
 
and in dialog.prg

Code: Select all

Dialog.prg

   DATA   lTruePixel AS LOGICAL INIT .F.

   METHOD New( nTop, nLeft, nBottom, nRight, cCaption, cResName, hResources,;
               lVbx, nStyle, nClrText, nClrBack, oBrush, oWnd, lPixels,;
               oIco, oFont, nHelpId, nWidth, nHeight, lTransparent, aNewGradColors, lTruePixel ) CONSTRUCTOR

METHOD New( nTop, nLeft, nBottom, nRight, cCaption, cResName, hResources,;
            lVbx, nStyle, nClrText, nClrBack, oBrush, oWnd, lPixels,;
            oIco, oFont, nHelpId, nWidth, nHeight, lTransparent, aNewGradColors, lTruePixel ) CLASS TDialog

   DEFAULT hResources := GetResources(), lVbx := .f.,;
           nClrText   := GetSysColor( COLOR_BTNTEXT ), nClrBack := GetSysColor( COLOR_BTNFACE ),;
           lPixels    := .f., nTop := 0, nLeft := 0, nBottom := 10, nRight := 40,;
           nWidth     := 0, nHeight := 0, lTransparent := .f.,;
           nStyle     := nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU ),;
           lTruePixel := .f.

   ::lTruePixel = lTruePixel
 
In control.prg

Code: Select all

METHOD cToChar( cCtrlClass ) CLASS TControl

   local n := GetDlgBaseUnits()

   DEFAULT cCtrlClass := ::ClassName(),;
           ::cCaption := "",;
           ::nId      := ::GetNewId(),;
           ::nStyle   := nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP )

return cCtrl2Chr( Int( if(::oWnd:lTruePixel,1,2) * 8 * ::nTop    / nHiWord( n ) ),;
                  Int( if(::oWnd:lTruePixel,1,2) * 4 * ::nLeft   / nLoWord( n ) ),;
                  Int( if(::oWnd:lTruePixel,1,2) * 8 * ::nBottom / nHiWord( n ) ),;
                  Int( if(::oWnd:lTruePixel,1,2) * 4 * ::nRight  / nLoWord( n ) ),;
                  ::nId, ::nStyle, cCtrlClass, ::cCaption )
 
I would like to know your opinions before proceeding to implement it, thanks

Re: Long standing bug in FWH

Posted: Fri Nov 07, 2014 9:46 am
by IBTC
o.k. Good solution.

Re: Long standing bug in FWH

Posted: Fri Nov 07, 2014 11:38 am
by Enrico Maria Giordano
+1

EMG

Re: Long standing bug in FWH

Posted: Fri Nov 07, 2014 3:31 pm
by James Bott
I like it.

Re: Long standing bug in FWH

Posted: Tue Nov 11, 2014 7:41 am
by nageswaragunupudi
I suggest a Global setting too.
If I set globally I need not have to write the clause everytime I create a new dialog in my future projects.

Re: Long standing bug in FWH

Posted: Tue Nov 11, 2014 7:47 am
by Silvio.Falconi
I don't understood can you make a sample... perhaps I not see the differences or I not Understood wich are the differences

Re: Long standing bug in FWH

Posted: Wed Nov 12, 2014 3:41 pm
by FiveWiDi
nageswaragunupudi wrote:I suggest a Global setting too.
If I set globally I need not have to write the clause everytime I create a new dialog in my future projects.
I dont agree wiht you.

Sólo sería válido para nuevas aplicaciones, en las existentes os obligaría a tocar todas las ventanas ya existentes.
Una combinación de global y cláusula si que sería válido.
Traducírselo por favor.

Regards,

Re: Long standing bug in FWH

Posted: Thu Nov 13, 2014 7:15 am
by Carles
+1

but CLASSDATA instead DATA