Nueva utilidad REDEFINE.prg libre

Nueva utilidad REDEFINE.prg libre

Postby Antonio Linares » Sun Jul 13, 2014 2:13 pm

Se que al usar FWH una de las tareas más tediosas es codificar los REDEFINEs :-)

Recientemente mientras chateaba con Ariel me hizo darme cuenta de que dicha dificultad sigue ahí, asi que hoy que tenía algo de tiempo libre, he escrito esta utilidad REDEFINE.prg que escribe los REDEFINEs para vosotros :-)

Aún no está terminado, lo completaré en los próximos dias, pero ya podeis empezar a utilizarlo :-)

redefine.prg
Code: Select all  Expand view
// Automatic REDEFINEs generator

#include "FiveWin.ch"

static cRCSrcCode, aDialogs := {}

function Main()

   local oDlg, oGet, cRCFileName := Space( 250 )
   local oLbx, cDlgName := Space( 50 ), oMemo1, cCode := ""
   local oFont, oMemo2, cPrg := ""

   SetDlgGradient( { { 1, RGB( 199, 216, 237 ), RGB( 237, 242, 248 ) } } )
   
   DEFINE FONT oFont NAME "Courier New" SIZE 0, -14
   
   DEFINE DIALOG oDlg TITLE "RCs REDEFINEs builder" ;
      SIZE 900, 700

   @ 0.7, 1.5 SAY "RC filename:" OF oDlg SIZE 80, 9
   
   @ 0.8, 6 GET oGet VAR cRCFileName OF oDlg SIZE 200, 12 ;
      ACTION ( cRCFileName := cGetFile( "*.rc", "Please select a RC file" ),;
               oGet:oBtn:Refresh(), oGet:SetFocus(),;
               aDialogs := {}, ListDialogs( cRCFileName, oLbx ) )

   @ 2, 1.5 SAY "Dialogs in the RC file:" OF oDlg SIZE 80, 9

   @ 3, 1 LISTBOX oLbx VAR cDlgName ITEMS {} OF oDlg SIZE 80, 164 ;
      ON CHANGE ShowCode( cDlgName, oMemoRC, oMemoPrg )

   @ 2, 16.4 SAY "RC dialog source:" OF oDlg SIZE 80, 9

   @ 3.3, 12 GET oMemoRC VAR cCode MEMO OF oDlg SIZE 345, 157 ;
      FONT oFont HSCROLL

   @ 16, 1 GET oMemoPrg VAR cPrg MEMO OF oDlg SIZE 433, 135 ;
      FONT oFont HSCROLL

   ACTIVATE DIALOG oDlg CENTERED

   oFont:End()

return nil

function ListDialogs( cRCFileName, oLbx )

   local n, cDlgName, lDone

   if ! File( cRCFileName )
      MsgAlert( cRCFileName + " does not exist" )
      return nil
   endif  
   
   cRCSrcCode = MemoRead( cRCFileName )
   oLbx:Reset()
   
   for n = 1 to MLCount( cRCSrcCode )
      cLine = MemoLine( cRCSrcCode,, n )
      SysRefresh()
      if ! SubStr( cLine, 1, 2 ) $ "//,/*"
         if Upper( StrToken( MemoLine( cRCSrcCode,, n ), 2 ) ) == "DIALOG"
            oLbx:Add( cDlgName := StrToken( MemoLine( cRCSrcCode,, n ), 1 ) )
            AAdd( aDialogs, { cDlgName, { cLine } } )
            lDone = .F.
         else
            if ! Empty( aDialogs )
               if Len( AllTrim( cLine ) ) == 1 .and. SubStr( cLine, 1, 1 ) == "}"
                  AAdd( ATail( aDialogs )[ 2 ], "}" )  
                  lDone = .T.
               else  
                  if ! lDone
                     AAdd( ATail( aDialogs )[ 2 ], cLine )  
                  endif  
               endif  
            endif  
         endif
      endif  
   next
   
   oLbx:GoTop()
   
return nil        

function ShowCode( cDlgName, oMemoRC, oMemoPrg )

   local nAt := AScan( aDialogs, { | aDlg | aDlg[ 1 ] == cDlgName } )
   
   if nAt != 0
      oMemoRC:SetText( ArrayToText( aDialogs[ nAt ][ 2 ] ) )
      oMemoPrg:SetText( RcToPrg( cDlgName, aDialogs[ nAt ][ 2 ] ) )
   endif  
   
return nil  

function ArrayToText( aArray )

   local n, cText := ""
   
   for n = 1 to Len( aArray )
      cText += aArray[ n ] + CRLF
   next
   
return cText

function RcToPrg( cDlgName, aRCSource )

   local cFuncName := "function " + cDlgName + "()" + CRLF + CRLF
   local n, cCode := "", aTokens, cToken
   local nSay := 0, nGet := 0, cVars := "   local "
   
   for n = 1 to Len( aRCSource )
      aTokens = hb_ATokens( aRCSource[ n ] )
      cToken = AllTrim( aTokens[ 1 ] )
      // MsgInfo( aTokens[ 1 ] )
      do case
         case cToken == "EDITTEXT"
            cCode += "   REDEFINE GET oGet" + AllTrim( Str( ++nGet ) ) + ;
                     " ID " + StrTran( aTokens[ 2 ], ",", "" ) + ;
                     " OF oDlg" + CRLF + CRLF
            cVars += "oGet" + AllTrim( Str( nGet ) ) + ", "      
                     
         case cToken == "LTEXT"
            cCode += "   REDEFINE SAY oSay" + AllTrim( Str( ++nSay ) ) + ;
                     " ID " + StrTran( aTokens[ 3 ], ",", "" ) + ;
                     " OF oDlg" + " // " + StrTran( aTokens[ 2 ], ",", "" ) + CRLF + CRLF
            cVars += "oSay" + AllTrim( Str( nSay ) ) + ", "      
      endcase
     
   next
   
return cFuncName + cVars + CRLF + CRLF + cCode + "return nil"            


redefine.rc
Code: Select all  Expand view
ico  ICON "./../ICONS/fivewin.ico"

#ifdef __FLAT__
  1 24 "WinXP/WindowsXP.Manifest"
#endif

#ifdef __64__
  1 24 "WinXP/WindowsXP.Manifest64"
#endif


Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Nueva utilidad REDEFINE.prg libre

Postby Antonio Linares » Sun Jul 13, 2014 2:21 pm

Versión mejorada que muestra el DEFINE DIALOG y el ACTIVATE DIALOG.

redefine.prg
Code: Select all  Expand view
// Automatic REDEFINEs generator

#include "FiveWin.ch"

static cRCSrcCode, aDialogs := {}

function Main()

   local oDlg, oGet, cRCFileName := Space( 250 )
   local oLbx, cDlgName := Space( 50 ), oMemo1, cCode := ""
   local oFont, oMemo2, cPrg := ""

   SetDlgGradient( { { 1, RGB( 199, 216, 237 ), RGB( 237, 242, 248 ) } } )
   
   DEFINE FONT oFont NAME "Courier New" SIZE 0, -14
   
   DEFINE DIALOG oDlg TITLE "RCs REDEFINEs builder" ;
      SIZE 900, 700

   @ 0.7, 1.5 SAY "RC filename:" OF oDlg SIZE 80, 9
   
   @ 0.8, 6 GET oGet VAR cRCFileName OF oDlg SIZE 200, 12 ;
      ACTION ( cRCFileName := cGetFile( "*.rc", "Please select a RC file" ),;
               oGet:oBtn:Refresh(), oGet:SetFocus(),;
               aDialogs := {}, ListDialogs( cRCFileName, oLbx ) )

   @ 2, 1.5 SAY "Dialogs in the RC file:" OF oDlg SIZE 80, 9

   @ 3, 1 LISTBOX oLbx VAR cDlgName ITEMS {} OF oDlg SIZE 80, 164 ;
      ON CHANGE ShowCode( cDlgName, oMemoRC, oMemoPrg )

   @ 2, 16.4 SAY "RC dialog source:" OF oDlg SIZE 80, 9

   @ 3.3, 12 GET oMemoRC VAR cCode MEMO OF oDlg SIZE 345, 157 ;
      FONT oFont HSCROLL

   @ 16, 1 GET oMemoPrg VAR cPrg MEMO OF oDlg SIZE 433, 135 ;
      FONT oFont HSCROLL

   ACTIVATE DIALOG oDlg CENTERED

   oFont:End()

return nil

function ListDialogs( cRCFileName, oLbx )

   local n, cDlgName, lDone

   if ! File( cRCFileName )
      MsgAlert( cRCFileName + " does not exist" )
      return nil
   endif  
   
   cRCSrcCode = MemoRead( cRCFileName )
   oLbx:Reset()
   
   for n = 1 to MLCount( cRCSrcCode )
      cLine = MemoLine( cRCSrcCode,, n )
      SysRefresh()
      if ! SubStr( cLine, 1, 2 ) $ "//,/*"
         if Upper( StrToken( MemoLine( cRCSrcCode,, n ), 2 ) ) == "DIALOG"
            oLbx:Add( cDlgName := StrToken( MemoLine( cRCSrcCode,, n ), 1 ) )
            AAdd( aDialogs, { cDlgName, { cLine } } )
            lDone = .F.
         else
            if ! Empty( aDialogs )
               if Len( AllTrim( cLine ) ) == 1 .and. SubStr( cLine, 1, 1 ) == "}"
                  AAdd( ATail( aDialogs )[ 2 ], "}" )  
                  lDone = .T.
               else  
                  if ! lDone
                     AAdd( ATail( aDialogs )[ 2 ], cLine )  
                  endif  
               endif  
            endif  
         endif
      endif  
   next
   
   oLbx:GoTop()
   
return nil        

function ShowCode( cDlgName, oMemoRC, oMemoPrg )

   local nAt := AScan( aDialogs, { | aDlg | aDlg[ 1 ] == cDlgName } )
   
   if nAt != 0
      oMemoRC:SetText( ArrayToText( aDialogs[ nAt ][ 2 ] ) )
      oMemoPrg:SetText( RcToPrg( cDlgName, aDialogs[ nAt ][ 2 ] ) )
   endif  
   
return nil  

function ArrayToText( aArray )

   local n, cText := ""
   
   for n = 1 to Len( aArray )
      cText += aArray[ n ] + CRLF
   next
   
return cText

function RcToPrg( cDlgName, aRCSource )

   local cFuncName := "function " + cDlgName + "()" + CRLF + CRLF
   local n, cCode := "", aTokens, cToken
   local nSay := 0, nGet := 0, cVars := "   local "
   local cDlgDefine := CRLF + CRLF + "   DEFINE DIALOG oDlg RESOURCE " + '"' + ;
                       cDlgName + '"'
   local cDlgActivate := "   ACTIVATE DIALOG oDlg CENTERED" + CRLF + CRLF                    
   
   for n = 1 to Len( aRCSource )
      aTokens = hb_ATokens( aRCSource[ n ] )
      cToken = AllTrim( aTokens[ 1 ] )
      // MsgInfo( aTokens[ 1 ] )
      do case
         case cToken == "EDITTEXT"
            cCode += "   REDEFINE GET oGet" + AllTrim( Str( ++nGet ) ) + ;
                     " ID " + StrTran( aTokens[ 2 ], ",", "" ) + ;
                     " OF oDlg" + CRLF + CRLF
            cVars += "oGet" + AllTrim( Str( nGet ) ) + ", "      
                     
         case cToken == "LTEXT"
            cCode += "   REDEFINE SAY oSay" + AllTrim( Str( ++nSay ) ) + ;
                     " ID " + StrTran( aTokens[ 3 ], ",", "" ) + ;
                     " OF oDlg" + " // " + StrTran( aTokens[ 2 ], ",", "" ) + CRLF + CRLF
            cVars += "oSay" + AllTrim( Str( nSay ) ) + ", "      
      endcase
     
   next
   
return cFuncName + cVars + cDlgDefine + CRLF + CRLF + cCode + ;
       cDlgActivate + "return nil"            
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Nueva utilidad REDEFINE.prg libre

Postby lucasdebeltran » Sun Jul 13, 2014 2:53 pm

Antonio,

Muy bueno . Si permites la sugerencia se podrían usar hashes para las variables de los controles y además en los says se puede poner el prompt como valor del hash. Que te parece ?.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: Nueva utilidad REDEFINE.prg libre

Postby Antonio Linares » Sun Jul 13, 2014 6:41 pm

Lucas,

Anímate y ayudame a mejorarlo, no solo con ideas sino programándolo :-) Me refiero a que escribas el código de cómo lo harias.

Versión mejorada ya soportando los Push Buttons:

redefine.prg
Code: Select all  Expand view
// Automatic REDEFINEs generator

#include "FiveWin.ch"

static cRCSrcCode, aDialogs := {}

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oGet, cRCFileName := Space( 250 )
   local oLbx, cDlgName := Space( 50 ), oMemo1, cCode := ""
   local oFont, oMemo2, cPrg := ""

   SetDlgGradient( { { 1, RGB( 199, 216, 237 ), RGB( 237, 242, 248 ) } } )
   
   DEFINE FONT oFont NAME "Courier New" SIZE 0, -14
   
   DEFINE DIALOG oDlg TITLE "RCs REDEFINEs builder" ;
      SIZE 900, 700

   @ 0.7, 1.5 SAY "RC filename:" OF oDlg SIZE 80, 9
   
   @ 0.8, 6 GET oGet VAR cRCFileName OF oDlg SIZE 200, 12 ;
      ACTION ( cRCFileName := cGetFile( "*.rc", "Please select a RC file" ),;
               oGet:oBtn:Refresh(), oGet:SetFocus(),;
               aDialogs := {}, ListDialogs( cRCFileName, oLbx ) )

   @ 2, 1.5 SAY "Dialogs in the RC file:" OF oDlg SIZE 80, 9

   @ 3, 1 LISTBOX oLbx VAR cDlgName ITEMS {} OF oDlg SIZE 80, 164 ;
      ON CHANGE ShowCode( cDlgName, oMemoRC, oMemoPrg )

   @ 2, 16.4 SAY "RC dialog source:" OF oDlg SIZE 80, 9

   @ 3.3, 12 GET oMemoRC VAR cCode MEMO OF oDlg SIZE 345, 157 ;
      FONT oFont HSCROLL

   @ 16, 1 GET oMemoPrg VAR cPrg MEMO OF oDlg SIZE 433, 135 ;
      FONT oFont HSCROLL

   ACTIVATE DIALOG oDlg CENTERED

   oFont:End()

return nil

//----------------------------------------------------------------------------//

function ListDialogs( cRCFileName, oLbx )

   local n, cDlgName, lDone

   if ! File( cRCFileName )
      MsgAlert( cRCFileName + " does not exist" )
      return nil
   endif  
   
   cRCSrcCode = MemoRead( cRCFileName )
   oLbx:Reset()
   
   for n = 1 to MLCount( cRCSrcCode )
      cLine = MemoLine( cRCSrcCode,, n )
      SysRefresh()
      if ! SubStr( cLine, 1, 2 ) $ "//,/*"
         if Upper( StrToken( MemoLine( cRCSrcCode,, n ), 2 ) ) == "DIALOG"
            oLbx:Add( cDlgName := StrToken( MemoLine( cRCSrcCode,, n ), 1 ) )
            AAdd( aDialogs, { cDlgName, { cLine } } )
            lDone = .F.
         else
            if ! Empty( aDialogs )
               if Len( AllTrim( cLine ) ) == 1 .and. SubStr( cLine, 1, 1 ) == "}"
                  AAdd( ATail( aDialogs )[ 2 ], "}" )  
                  lDone = .T.
               else  
                  if ! lDone
                     AAdd( ATail( aDialogs )[ 2 ], cLine )  
                  endif  
               endif  
            endif  
         endif
      endif  
   next
   
   oLbx:GoTop()
   
return nil        

//----------------------------------------------------------------------------//

function ShowCode( cDlgName, oMemoRC, oMemoPrg )

   local nAt := AScan( aDialogs, { | aDlg | aDlg[ 1 ] == cDlgName } )
   
   if nAt != 0
      oMemoRC:SetText( ArrayToText( aDialogs[ nAt ][ 2 ] ) )
      oMemoPrg:SetText( RcToPrg( cDlgName, aDialogs[ nAt ][ 2 ] ) )
   endif  
   
return nil  

//----------------------------------------------------------------------------//

function ArrayToText( aArray )

   local n, cText := ""
   
   for n = 1 to Len( aArray )
      cText += aArray[ n ] + CRLF
   next
   
return cText

//----------------------------------------------------------------------------//

function RcToPrg( cDlgName, aRCSource )

   local cFuncName := "function " + cDlgName + "()" + CRLF + CRLF
   local n, cCode := "", aTokens, cToken
   local nSay := 0, nGet := 0, nBtn := 0
   local cVars := "   local "
   local cDlgDefine := CRLF + CRLF + "   DEFINE DIALOG oDlg RESOURCE " + '"' + ;
                       cDlgName + '"'
   local cDlgActivate := "   ACTIVATE DIALOG oDlg CENTERED" + CRLF + CRLF                    
   
   for n = 1 to Len( aRCSource )
      aTokens = hb_ATokens( aRCSource[ n ] )
      cToken = AllTrim( aTokens[ 1 ] )
      // MsgInfo( aTokens[ 1 ] )
      do case
         case cToken == "EDITTEXT"
            cCode += "   REDEFINE GET oGet" + AllTrim( Str( ++nGet ) ) + ;
                     " ID " + StrTran( aTokens[ 2 ], ",", "" ) + ;
                     " OF oDlg" + CRLF + CRLF
            cVars += "oGet" + AllTrim( Str( nGet ) ) + ", "      
                     
         case cToken == "LTEXT"
            cCode += "   REDEFINE SAY oSay" + AllTrim( Str( ++nSay ) ) + ;
                     " ID " + StrTran( aTokens[ 3 ], ",", "" ) + ;
                     " OF oDlg" + " // " + StrTran( aTokens[ 2 ], ",", "" ) + CRLF + CRLF
            cVars += "oSay" + AllTrim( Str( nSay ) ) + ", "      

         case cToken == "PUSHBUTTON"
            // MsgInfo( aRcSource[ n ] )
            cCode += "   REDEFINE BUTTON oBtn" + AllTrim( Str( ++nBtn ) ) + ;
                     " ID " + AllTrim( StrToken( aRcSource[ n ], 2, ',' ) ) + ;
                     " OF oDlg ; // " + ;
                     '"' + StrToken( aRcSource[ n ], 2, '"' ) + '"' + CRLF + ;
                     "      ACTION MsgInfo( " + '"PushButton ' + ;
                     AllTrim( Str( nBtn ) ) + '"' + " )" + CRLF + CRLF
            cVars += "oBtn" + AllTrim( Str( nBtn ) ) + ", "      
      endcase
     
   next
   
   cVars = SubStr( cVars, 1, Len( cVars ) - 2 )
   
return cFuncName + cVars + cDlgDefine + CRLF + CRLF + cCode + ;
       cDlgActivate + "return nil"            
       
//----------------------------------------------------------------------------//      


Este código ha sido automaticamente generado con esta utilidad, fijaros que práctico es :-)

Code: Select all  Expand view
  REDEFINE BUTTON oBtn5 ID 4380 OF oDlg ; // "&Top"
      ACTION MsgInfo( "PushButton 5" )

   REDEFINE BUTTON oBtn6 ID 4390 OF oDlg ; // "&Prev"
      ACTION MsgInfo( "PushButton 6" )

   REDEFINE BUTTON oBtn7 ID 4400 OF oDlg ; // "&Next"
      ACTION MsgInfo( "PushButton 7" )

   REDEFINE BUTTON oBtn8 ID 4410 OF oDlg ; // "&Bottom"
      ACTION MsgInfo( "PushButton 8" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Nueva utilidad REDEFINE.prg libre

Postby D.Fernandez » Sun Jul 13, 2014 7:52 pm

IMPRESIONANTE!!!!!!

Gracias.
Dario Fernandez
FWH 22.12, Harbour, MVS2022 Community, BCC, MySql & MariaDB, Dbf/Cdx VSCode.
Maldonado - Uruguay
D.Fernandez
 
Posts: 455
Joined: Wed Jul 31, 2013 1:14 pm
Location: Maldonado - Uruguay

Re: Nueva utilidad REDEFINE.prg libre

Postby Antonio Linares » Mon Jul 14, 2014 1:44 am

Versión mejorada (variables locales agrupadas según el tipo de objetos):

redefine.prg
Code: Select all  Expand view
// Automatic REDEFINEs generator

#include "FiveWin.ch"

static cRCSrcCode, aDialogs := {}

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oGet, cRCFileName := Space( 250 )
   local oLbx, cDlgName := Space( 50 ), oMemoRC, cCode := ""
   local oFont, oMemoPrg, cPrg := ""

   SetDlgGradient( { { 1, RGB( 199, 216, 237 ), RGB( 237, 242, 248 ) } } )
   
   DEFINE FONT oFont NAME "Courier New" SIZE 0, -14
   
   DEFINE DIALOG oDlg TITLE "RCs REDEFINEs builder" ;
      SIZE 900, 700

   @ 0.7, 1.5 SAY "RC filename:" OF oDlg SIZE 80, 9
   
   @ 0.8, 6 GET oGet VAR cRCFileName OF oDlg SIZE 200, 12 ;
      ACTION ( cRCFileName := cGetFile( "*.rc", "Please select a RC file" ),;
               oGet:oBtn:Refresh(), oGet:SetFocus(),;
               aDialogs := {}, ListDialogs( cRCFileName, oLbx ) )

   @ 2, 1.5 SAY "Dialogs in the RC file:" OF oDlg SIZE 80, 9

   @ 3, 1 LISTBOX oLbx VAR cDlgName ITEMS {} OF oDlg SIZE 80, 164 ;
      ON CHANGE ShowCode( cDlgName, oMemoRC, oMemoPrg )

   @ 2, 16.4 SAY "RC dialog source:" OF oDlg SIZE 80, 9

   @ 3.3, 12 GET oMemoRC VAR cCode MEMO OF oDlg SIZE 345, 157 ;
      FONT oFont HSCROLL

   @ 16, 1 GET oMemoPrg VAR cPrg MEMO OF oDlg SIZE 433, 135 ;
      FONT oFont HSCROLL

   ACTIVATE DIALOG oDlg CENTERED

   oFont:End()

return nil

//----------------------------------------------------------------------------//

function ListDialogs( cRCFileName, oLbx )

   local n, cDlgName, lDone, cLine

   if ! File( cRCFileName )
      MsgAlert( cRCFileName + " does not exist" )
      return nil
   endif  
   
   cRCSrcCode = MemoRead( cRCFileName )
   oLbx:Reset()
   
   for n = 1 to MLCount( cRCSrcCode )
      cLine = MemoLine( cRCSrcCode,, n )
      SysRefresh()
      if ! SubStr( cLine, 1, 2 ) $ "//,/*"
         if Upper( StrToken( MemoLine( cRCSrcCode,, n ), 2 ) ) == "DIALOG"
            oLbx:Add( cDlgName := StrToken( MemoLine( cRCSrcCode,, n ), 1 ) )
            AAdd( aDialogs, { cDlgName, { cLine } } )
            lDone = .F.
         else
            if ! Empty( aDialogs )
               if Len( AllTrim( cLine ) ) == 1 .and. SubStr( cLine, 1, 1 ) == "}"
                  AAdd( ATail( aDialogs )[ 2 ], "}" )  
                  lDone = .T.
               else  
                  if ! lDone
                     AAdd( ATail( aDialogs )[ 2 ], cLine )  
                  endif  
               endif  
            endif  
         endif
      endif  
   next
   
   oLbx:GoTop()
   
return nil        

//----------------------------------------------------------------------------//

function ShowCode( cDlgName, oMemoRC, oMemoPrg )

   local nAt := AScan( aDialogs, { | aDlg | aDlg[ 1 ] == cDlgName } )
   
   if nAt != 0
      oMemoRC:SetText( ArrayToText( aDialogs[ nAt ][ 2 ] ) )
      oMemoPrg:SetText( RcToPrg( cDlgName, aDialogs[ nAt ][ 2 ] ) )
   endif  
   
return nil  

//----------------------------------------------------------------------------//

function ArrayToText( aArray )

   local n, cText := ""
   
   for n = 1 to Len( aArray )
      cText += aArray[ n ] + CRLF
   next
   
return cText

//----------------------------------------------------------------------------//

function RcToPrg( cDlgName, aRCSource )

   local cFuncName := "function " + cDlgName + "()" + CRLF + CRLF
   local n, cCode := "", aTokens, cToken
   local nSay := 0, nGet := 0, nBtn := 0
   local cVarsSays := "   local "
   local cVarsGets := "   local "
   local cVarsButtons := "   local "
   local cDlgDefine := "   DEFINE DIALOG oDlg RESOURCE " + '"' + ;
                       cDlgName + '"'
   local cId                  
   local cDlgActivate := "   ACTIVATE DIALOG oDlg CENTERED" + CRLF + CRLF
   
   for n = 1 to Len( aRCSource )
      aTokens = hb_ATokens( aRCSource[ n ] )
      cToken = AllTrim( aTokens[ 1 ] )
      do case
         case cToken == "EDITTEXT"
            cId = AllTrim( StrTran( aTokens[ 2 ], ",", "" ) )
            cCode += "   REDEFINE GET oGet" + AllTrim( Str( ++nGet ) ) + ;
                     " ID " + cId + " OF oDlg" + CRLF + CRLF
            cVarsGets += "oGet" + AllTrim( Str( nGet ) ) + ", "      
                     
                     
         case cToken == "LTEXT"
            cId = AllTrim( StrToken( aRCSource[ n ], 2, ',' ) )
            if ! cId $ "0,-1" // We don't redefine 0 and -1 IDs
               cCode += "   REDEFINE SAY oSay" + AllTrim( Str( ++nSay ) ) + ;
                        " ID " + cId + " OF oDlg" + " // " + ;
                        StrTran( aTokens[ 2 ], ",", "" ) + CRLF + CRLF
               cVarsSays += "oSay" + AllTrim( Str( nSay ) ) + ", "      
            endif  

         case cToken == "PUSHBUTTON"
            cId = AllTrim( StrToken( aRcSource[ n ], 2, ',' ) )
            cCode += "   REDEFINE BUTTON oBtn" + AllTrim( Str( ++nBtn ) ) + ;
                     " ID " + cId + " OF oDlg ; // " + ;
                     '"' + StrToken( aRcSource[ n ], 2, '"' ) + '"' + CRLF + ;
                     "      ACTION MsgInfo( " + ;
                     '"' + StrToken( aRcSource[ n ], 2, '"' ) + '"' + " )" + ;
                     CRLF + CRLF
            cVarsButtons += "oBtn" + AllTrim( Str( nBtn ) ) + ", "      
      endcase
     
   next
   
   if Len( cVarsSays ) > Len( "   local " )
      cVarsSays = SubStr( cVarsSays, 1, Len( cVarsSays ) - 2 )
   else
      cVarsSays = ""
   endif
   
   if Len( cVarsGets ) > Len( "   local " )      
      cVarsGets = SubStr( cVarsGets, 1, Len( cVarsGets ) - 2 )
   else
      cVarsGets = ""
   endif
   
   if Len( cVarsButtons ) > Len( "   local " )
      cVarsButtons = SubStr( cVarsButtons, 1, Len( cVarsButtons ) - 2 )
   else  
      cVarsButtons = ""
   endif
         
return cFuncName + ;
       If( ! Empty( cVarsSays ), cVarsSays + CRLF, "" ) + ;
       If( ! Empty( cvarsGets ), cVarsGets + CRLF, "" ) + ;
       If( ! Empty( cVarsButtons ), cVarsButtons + CRLF, "" ) + ;
       If( ! Empty( cVarsSays ) .or. ! Empty( cVarsGets ) .or. ;
           ! Empty( cVarsButtons ), CRLF, "" ) + cDlgDefine + CRLF + ;
       CRLF + cCode + ;
       cDlgActivate + "return nil"            
       
//----------------------------------------------------------------------------//      


Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Nueva utilidad REDEFINE.prg libre

Postby Biel EA6DD » Mon Jul 14, 2014 9:12 am

Interesante, el primer problema que he encontrado es que veo que el formato del los ficheros RC, varia según el editor usado.
Por ejemplo en PellesC tienen este aspecto.
Code: Select all  Expand view
USR DIALOGEX DISCARDABLE 6, 18, 210, 142
STYLE DS_SHELLFONT|WS_POPUP|DS_MODALFRAME|DS_3DLOOK|WS_CAPTION|WS_SYSMENU|WS_VISIBLE
CAPTION "Ficha de usuarios"
FONT 8, "MS Shell Dlg", 0, 0, 1
{
  CONTROL "Edit", 600, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 60, 8, 40, 12
  CONTROL "Edit", 601, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 60, 24, 40, 12
  CONTROL "Edit", 602, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 60, 40, 120, 12
  CONTROL "Edit", 603, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 60, 56, 120, 12
  CONTROL "OK", IDOK, "Button", WS_TABSTOP, 48, 120, 45, 15
  CONTROL "Cancel", IDCANCEL, "Button", WS_TABSTOP, 100, 120, 45, 15
  CONTROL "UsrName", -1, "Static", WS_GROUP, 8, 12, 40, 8
  CONTROL "Password", -1, "Static", WS_GROUP, 8, 28, 40, 8
  CONTROL "Desc.", -1, "Static", WS_GROUP, 8, 44, 40, 8
  CONTROL "e-mail", -1, "Static", WS_GROUP, 8, 60, 40, 8
}

Aunque en el fondo tienen la misma información, la tienen en posiciones diferentes con lo cual apuntar a la posición fija del Array obtenido con hb_Atokens() no nos sirve.
Es facil adaptarlo para pellesc, pero lo que no se me ocurre ahora mismo es una solución única y valida para cualquier fichero RC sea cual sea el editor usado.
P.D. Parece que el que se sale del estandar es PellesC.
Saludos desde Mallorca
Biel Maimó
http://bielsys.blogspot.com/
User avatar
Biel EA6DD
 
Posts: 682
Joined: Tue Feb 14, 2006 9:48 am
Location: Mallorca

Re: Nueva utilidad REDEFINE.prg libre

Postby Antonio Linares » Mon Jul 14, 2014 11:50 am

Biel,

Creo que podemos eliminar el uso de hb_atokens(), tengo que revisarlo (no me ha dado tiempo a más desde ayer) :-)

Se me ocurre que podríamos usar DIALOGEX para identificar a PellesC. De todas formas, creo que a poco que empecemos a usar esta aplicación, seremos capaces de ir adaptándola a los editores de recursos más populares.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Nueva utilidad REDEFINE.prg libre

Postby karinha » Mon Jul 14, 2014 2:34 pm

Maestro, cuando el archivo de recursos és muy grande, no genera los controles(Redefines/ID).

Yo enviaré mi archivo para que usted vea.

Gracias,

Saludos.
Last edited by karinha on Mon Jul 14, 2014 2:46 pm, edited 1 time in total.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Nueva utilidad REDEFINE.prg libre

Postby csincuir » Mon Jul 14, 2014 2:44 pm

Hola Antonio.
He hecho las pruebas con un archivo .rc generado con ResEdit http://www.resedit.net/
Y me ha funcionado correctamente al generar el codigo fuente del dialogo.

Solo me di cuenta que al generar el código, no define la varialbe "oDlg" del dialogo, por lo que yo lo agregue en esta linea:
Code: Select all  Expand view
local cVarsGets := "   local oDlg, "


Y ahora si, están definidas todas las variables de los controles, en el código generado.

Gracias por esta utilidad, esta muy buena.

Saludos.-

Carlos.
csincuir
 
Posts: 396
Joined: Sat Feb 03, 2007 6:36 am
Location: Guatemala

Re: Nueva utilidad REDEFINE.prg libre

Postby Antonio Linares » Mon Jul 14, 2014 3:50 pm

João,

Aqui si abre tu RC, lo que ocurre es que va lento posiblemente debido al uso de MemoLine().

Podemos facilmente reemplazar MemoLine() para que vaya mucho más rápido con ficheros RC muy grandes, como el tuyo :-)

No problem :-) Ya lo haremos pronto, gracias!

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Nueva utilidad REDEFINE.prg libre

Postby karinha » Mon Jul 14, 2014 4:51 pm

Muy buen maestro. En ansiosa espera. :D

Gracias, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Nueva utilidad REDEFINE.prg libre

Postby Antonio Linares » Mon Jul 14, 2014 4:56 pm

Nueva versión con soporte para ListBoxes y otras mejoras:

redefine.prg
Code: Select all  Expand view
// Automatic REDEFINEs generator

#include "FiveWin.ch"

static cRCSrcCode, aDialogs := {}

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oGet, cRCFileName := Space( 250 )
   local oLbx, cDlgName := Space( 50 ), oMemoRC, cCode := ""
   local oFont, oMemoPrg, cPrg := ""

   SetDlgGradient( { { 1, RGB( 199, 216, 237 ), RGB( 237, 242, 248 ) } } )
   
   DEFINE FONT oFont NAME "Courier New" SIZE 0, -14
   
   DEFINE DIALOG oDlg TITLE "RCs REDEFINEs builder" ;
      SIZE 900, 700

   @ 0.7, 1.5 SAY "RC filename:" OF oDlg SIZE 80, 9
   
   @ 0.8, 6 GET oGet VAR cRCFileName OF oDlg SIZE 200, 12 ;
      ACTION ( cRCFileName := cGetFile( "*.rc", "Please select a RC file" ),;
               oGet:oBtn:Refresh(), oGet:SetFocus(),;
               aDialogs := {}, ListDialogs( cRCFileName, oLbx ) )

   @ 2, 1.5 SAY "Dialogs in the RC file:" OF oDlg SIZE 80, 9

   @ 3, 1 LISTBOX oLbx VAR cDlgName ITEMS {} OF oDlg SIZE 80, 164 ;
      ON CHANGE ShowCode( cDlgName, oMemoRC, oMemoPrg )

   @ 2, 16.4 SAY "RC dialog source:" OF oDlg SIZE 80, 9

   @ 3.3, 12 GET oMemoRC VAR cCode MEMO OF oDlg SIZE 345, 157 ;
      FONT oFont HSCROLL

   @ 16, 1 GET oMemoPrg VAR cPrg MEMO OF oDlg SIZE 433, 135 ;
      FONT oFont HSCROLL

   ACTIVATE DIALOG oDlg CENTERED

   oFont:End()

return nil

//----------------------------------------------------------------------------//

function ListDialogs( cRCFileName, oLbx )

   local n, cDlgName, lDone, cLine

   if ! File( cRCFileName )
      MsgAlert( cRCFileName + " does not exist" )
      return nil
   endif  
   
   cRCSrcCode = MemoRead( cRCFileName )
   oLbx:Reset()
   
   for n = 1 to MLCount( cRCSrcCode )
      cLine = MemoLine( cRCSrcCode,, n )
      SysRefresh()
      if ! SubStr( cLine, 1, 2 ) $ "//,/*"
         if Upper( StrToken( MemoLine( cRCSrcCode,, n ), 2 ) ) == "DIALOG"
            oLbx:Add( cDlgName := StrToken( MemoLine( cRCSrcCode,, n ), 1 ) )
            AAdd( aDialogs, { cDlgName, { cLine } } )
            lDone = .F.
         else
            if ! Empty( aDialogs )
               if Len( AllTrim( cLine ) ) == 1 .and. SubStr( cLine, 1, 1 ) == "}"
                  AAdd( ATail( aDialogs )[ 2 ], "}" )  
                  lDone = .T.
               else  
                  if ! lDone
                     AAdd( ATail( aDialogs )[ 2 ], cLine )  
                  endif  
               endif  
            endif  
         endif
      endif  
   next
   
   oLbx:GoTop()
   
return nil        

//----------------------------------------------------------------------------//

function ShowCode( cDlgName, oMemoRC, oMemoPrg )

   local nAt := AScan( aDialogs, { | aDlg | aDlg[ 1 ] == cDlgName } )
   
   if nAt != 0
      oMemoRC:SetText( ArrayToText( aDialogs[ nAt ][ 2 ] ) )
      oMemoPrg:SetText( RcToPrg( cDlgName, aDialogs[ nAt ][ 2 ] ) )
   endif  
   
return nil  

//----------------------------------------------------------------------------//

function ArrayToText( aArray )

   local n, cText := ""
   
   for n = 1 to Len( aArray )
      cText += aArray[ n ] + CRLF
   next
   
return cText

//----------------------------------------------------------------------------//

function RcToPrg( cDlgName, aRCSource )

   local cFuncName := "function " + cDlgName + "()" + CRLF + CRLF
   local n, cCode := "", aTokens, cToken
   local nSay := 0, nGet := 0, nBtn := 0, nLbx := 0
   local cVarsSays := "   local "
   local cVarsGets := "   local "
   local cVarsButtons := "   local "
   local cVarsLbxs := "   local "
   local cDlgDefine := "   DEFINE DIALOG oDlg RESOURCE " + '"' + ;
                       cDlgName + '"'
   local cId                  
   local cDlgActivate := "   ACTIVATE DIALOG oDlg CENTERED" + CRLF + CRLF
   
   for n = 1 to Len( aRCSource )
      aTokens = hb_ATokens( aRCSource[ n ] )
      cToken = AllTrim( aTokens[ 1 ] )
      do case
         case cToken == "EDITTEXT"
            cId = AllTrim( StrTran( aTokens[ 2 ], ",", "" ) )
            cCode += "   REDEFINE GET oGet" + AllTrim( Str( ++nGet ) ) + ;
                     " ID " + cId + " OF oDlg" + CRLF + CRLF
            cVarsGets += "oGet" + AllTrim( Str( nGet ) ) + ", "      

         case cToken == "LISTBOX"
            cId = AllTrim( StrTran( aTokens[ 2 ], ",", "" ) )
            cCode += "   REDEFINE LISTBOX oLbx" + AllTrim( Str( ++nLbx ) ) + ;
                     " ITEMS {}" + ;
                     " ID " + cId + " OF oDlg" + CRLF + CRLF
            cVarsLbxs += "oLbx" + AllTrim( Str( nLbx ) ) + ", "      
                     
         case cToken == "LTEXT"
            cId = AllTrim( StrToken( aRCSource[ n ], 2, ',' ) )
            if ! cId $ "0,-1" // We don't redefine 0 and -1 IDs
               cCode += "   REDEFINE SAY oSay" + AllTrim( Str( ++nSay ) ) + ;
                        " ID " + cId + " OF oDlg" + " // " + ;
                        StrTran( aTokens[ 2 ], ",", "" ) + CRLF + CRLF
               cVarsSays += "oSay" + AllTrim( Str( nSay ) ) + ", "      
            endif  

         case cToken == "PUSHBUTTON"
            cId = AllTrim( StrToken( aRcSource[ n ], 2, ',' ) )
            cCode += "   REDEFINE BUTTON oBtn" + AllTrim( Str( ++nBtn ) ) + ;
                     " ID " + cId + " OF oDlg ; // " + ;
                     '"' + StrToken( aRcSource[ n ], 2, '"' ) + '"' + CRLF + ;
                     "      ACTION MsgInfo( " + ;
                     '"' + StrToken( aRcSource[ n ], 2, '"' ) + '"' + " )" + ;
                     CRLF + CRLF
            cVarsButtons += "oBtn" + AllTrim( Str( nBtn ) ) + ", "      
      endcase
     
   next
   
   if Len( cVarsSays ) > Len( "   local " )
      cVarsSays = SubStr( cVarsSays, 1, Len( cVarsSays ) - 2 )
   else
      cVarsSays = ""
   endif
   
   if Len( cVarsGets ) > Len( "   local " )      
      cVarsGets = SubStr( cVarsGets, 1, Len( cVarsGets ) - 2 )
   else
      cVarsGets = ""
   endif
   
   if Len( cVarsButtons ) > Len( "   local " )
      cVarsButtons = SubStr( cVarsButtons, 1, Len( cVarsButtons ) - 2 )
   else  
      cVarsButtons = ""
   endif

   if Len( cVarsLbxs ) > Len( "   local " )
      cVarsLbxs = SubStr( cVarsLbxs, 1, Len( cVarsLbxs ) - 2 )
   else  
      cVarsLbxs = ""
   endif
         
return cFuncName + ;
       "   local oDlg" + CRLF + ;
       If( ! Empty( cVarsSays ), cVarsSays + CRLF, "" ) + ;
       If( ! Empty( cVarsGets ), cVarsGets + CRLF, "" ) + ;
       If( ! Empty( cVarsButtons ), cVarsButtons + CRLF, "" ) + ;
       If( ! Empty( cVarsLbxs ), cVarsLbxs + CRLF, "" ) + ;
       If( ! Empty( cVarsSays ) .or. ! Empty( cVarsGets ) .or. ;
           ! Empty( cVarsButtons ) .or. ! Empty( cVarsLbxs ), CRLF, "" ) + ;
       If( Empty( cVarsSays ) .and. Empty( cVarsGets ) .and. ;
           Empty( cVarsButtons ) .and. Empty( cVarsLbxs ),;
       CRLF, "" ) + cDlgDefine + CRLF + ;
       CRLF + cCode + ;
       cDlgActivate + "return nil"            
       
//----------------------------------------------------------------------------//      


Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41314
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Nueva utilidad REDEFINE.prg libre

Postby wilsongamboa » Mon Jul 14, 2014 5:42 pm

gracias Maestro por tan execlente trabajo ( como siempre )

podria haber la posibilidad que se pueda tambien generar el codigo PRG con las coordenadas en pixels ? y ya no depender del .RC ?

saludos y gracias
Wilson 'W' Gamboa A
Wilson.josenet@gmail.com
User avatar
wilsongamboa
 
Posts: 548
Joined: Wed Oct 19, 2005 6:41 pm
Location: Quito - Ecuador

Re: Nueva utilidad REDEFINE.prg libre

Postby karinha » Mon Jul 14, 2014 6:09 pm

Maestro podría realizar esta modificación?

Code: Select all  Expand view

   local cFuncName := "#Include "+'"FiveWin.ch"'+CRLF+CRLF+"FUNCTION " + ;
         cDlgName + "()" + CRLF + CRLF
 


Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Next

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 69 guests