also for obrw nheight

also for obrw nheight

Postby Silvio.Falconi » Wed May 15, 2024 11:03 am

on this video I put the nheight of obrw on -140 to show the boxes becuase not run ok the function ChangeBrw(n,oBrw,oBox)

Image


function ChangeBrw(n,oBrw,oBox)


Code: Select all  Expand view
Function ChangeBrw(n,oBrw,oBox)
   local nHeight
      Do case
      Case n= 1

      Case n= 2
         oBox[2]:show()
         nHeight:= -40
      Case n= 3
         oBox[3]:show()
      Endcase
      oBrw:setsize(,nheight)
      oBrw:refresh()
  return nil


how I can resolve ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: also for obrw nheight

Postby nageswaragunupudi » Wed May 15, 2024 3:09 pm

Code: Select all  Expand view
nHeight:= -40

????
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: also for obrw nheight

Postby nageswaragunupudi » Wed May 15, 2024 3:12 pm

Code: Select all  Expand view
Function ChangeBrw(n,oBrw,oBox)
   local nHeight
      Do case
      Case n= 1

      Case n= 2
         oBox[2]:show()
//         nHeight:= -40
         oBrw:nBottomMargin += 40
      Case n= 3
         oBox[3]:show()
      Endcase
//      oBrw:setsize(,nheight)
      oBrw:refresh()
  return nil
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10643
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: also for obrw nheight

Postby Silvio.Falconi » Wed May 15, 2024 8:45 pm

nageswaragunupudi wrote:
Code: Select all  Expand view
Function ChangeBrw(n,oBrw,oBox)
   local nHeight
      Do case
      Case n= 1

      Case n= 2
         oBox[2]:show()
//         nHeight:= -40
         oBrw:nBottomMargin += 40
      Case n= 3
         oBox[3]:show()
      Endcase
//      oBrw:setsize(,nheight)
      oBrw:refresh()
  return nil



to show the combobox or radiomenu I activate the obox[2] and change the height of obrw
Code: Select all  Expand view
IF  aFilters[ nIndex, 1 ]
          oBox[2]:show()
          oDlgx:= oBox[2]
          oBrw:nBottomMargin += 45
           for n= 1 to len (oDlgx:aControls)
               oDlgx:aControls[n]:hide()
            Next
       else
          oBox[2]:Hide()
          oBrw:nBottomMargin -= 45
       endif


Image

But if I have two heckboxes activated Inot Know how make

any solution ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: also for obrw nheight

Postby Silvio.Falconi » Thu May 16, 2024 6:47 am

I explain that I mean

I have 4 panels created with the tslines class (in reality they shouldn't be panels but they behave as if they were panels)


Image



in the first Box[1] I inserted 3 checkboxes (age, state, married) and this box is fix

while from the second box[2] to the fourth box[4] they must be shown if the others are not active

for example if the user clicks the first checkbox (age) the second box[2] must be activated if it has not already been activated otherwise the box[3] will be activated and so on for the other checkboxes

When the user clicks a checkboxes I have to raise the xbrowse in the line above the open box for example if Box[2] has been opened the xbrowse must be

raised to obox[2]:ntop-2 and so on for the other chechboxes


I made this but not run

Code: Select all  Expand view
IF  oBox[2]:show()
           oBox[3]:show()
           oDlgx:= oBox[3]
           oBrw:nBottomMargin += oBox[3]:nTop-2
        elseif  oBox[3]:show()
              oBox[4]:show()
              oDlgx:= oBox[4]
              oBrw:nBottomMargin += oBox[4]:nTop-2
         elseif  oBox[4]:show()
              oBox[3]:show()
              oDlgx:= oBox[3]
           else
              oBox[2]:show()
              oDlgx:= oBox[2]
              oBrw:nBottomMargin += oBox[2]:nTop-2
           Endif





chapGpt tell me this

For n= 1 to Len(aFilters)
IF aFilters[ nIndex, 1 ]
IF nBox <= len(oBox)
oBox[nIndex+1]:show()
oDlgx:= oBox[nIndex+1]
nbox++
Endif
Endif
next

but not run ok
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: also for obrw nheight

Postby Silvio.Falconi » Thu May 16, 2024 9:18 am

Now the xbrowse change good the nheight but when I desactivate a checkbox the xbrowse not return to initial state

Image


// Calculate the total height of the activated boxes
for nIndex := 1 to Len(aFilters)
if aFilters[nIndex, 1]
nVisibleBoxHeight += nBoxHeight
endif
next


// Adjust the height of the XBROWSE based on the height of the activated boxes
oBrw:nBottomMargin+= nBoxHeight
oBrw:refresh()
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: also for obrw nheight

Postby Silvio.Falconi » Fri May 17, 2024 9:50 am

Someone can help me ?

the new release use Tpanel, customer.dbf states.dbf


At first it works correctly then it makes an error and I haven't found the error

if the user activates a checkbox the procedure automatically activates a panel, the one that is free and displays it and inserts the controls for searching on xbrowse

if the user deactivates a checkbox the procedure deactivates the corresponding panel (at the time of activation an array is created where the number of the panel activated for that checkbox is stored)

When the procedure deactivates a panel it scrolls through the other remaining panels without leaving a void


the error occurs when the end user reactivates a previously deactivated checkbox


Image







Code: Select all  Expand view
#include "fivewin.ch"
#include "constant.ch"

#define DLG_nColorDlg     RGB(245,245,235)
#define DLG_nColortitle1  RGB(219,230,244)
#define DLG_nColortitle2  RGB(207,221,239)
#define DLG_nColorBar1    RGB(250,250,245)
#define DLG_nColorBar2    RGB(245,245,235)
#define DLG_nColorBtn1    RGB(245,245,235)
#define DLG_nColorBtn2    RGB(250,250,245)
#define DLG_nColorBtnB    RGB(195,195,185)

REQUEST DBFCDX

static l2Box,l3Box,l4Box
static nBoxNumber
STATIC aCheckboxPanelMap

function Main()

    local oDlg, oBrw, oFont, oBold
    local nBottom := 32.4
    local nRight := 95
    local nHt := nBottom * DLG_CHARPIX_H
    local nWd := Max(nRight * DLG_CHARPIX_W, 180)
    local oBox := Array(4) // 3+1
    local oDbf, oState
    local nRow
    local aState := {}




           l2Box := .F.
           l3Box := .F.
           l4Box := .F.
           aCheckboxPanelMap:=array(3)








    oFont := TFont():New("TAHOMA", 0, 14)
     oBold := TFont():New( "TAHOMA", 0, 14,,.t. )

    oState := TDataBase():Open(nil, "STATES", "DBFCDX", .T.)
    oState:gotop()
    Do While !oState:eof()
        AADD(aState, {oState:CODE, oState:NAME})
        oState:skip()
    enddo
    oState:close()

    oDbf := TDataBase():Open(nil, "CUSTOMER", "DBFCDX", .T.)

    DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL TRUEPIXEL;
        FONT oFont COLOR CLR_BLACK, RGB(245,245,235);
        STYLE nOR(DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, WS_MINIMIZEBOX)

    @ 40, 10 XBROWSE oBrw SIZE -10,-60 PIXEL OF oDlg;
        DATASOURCE oDbf;
        COLUMNS "ID", "CITY", "STATE", "MARRIED", "AGE";
        CELL LINES NOBORDER UPDATE

    WITH OBJECT oBrw
        :nRowHeight := 25
        :l2007 := .F.
        :l2015 := .T.
        :lRecordSelector := .F.
        :nColDividerStyle := LINESTYLE_LIGHTGRAY
        :nRowDividerStyle := LINESTYLE_LIGHTGRAY
        :nStretchCol := STRETCHCOL_WIDEST
        :nMarqueeStyle := MARQSTYLE_HIGHLROW
        :SetChecks()
        :lHScroll := .F.
        :CreateFromCode()
     END

    nRow := 440
    oBox[1] := PanelBox(nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2,oDlg)
    nRow -= 31
    oBox[2] := PanelBox(nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2,oDlg)
    nRow -= 31
    oBox[3] := PanelBox(nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2,oDlg)
    nRow -= 31
    oBox[4] := PanelBox(nRow, 10, 30, oDlg:nWidth - 20,DLG_nColorBar1, DLG_nColorBar2,oDlg)

    ACTIVATE DIALOG oDlg CENTERED;
        ON INIT (oBox[2]:hide(), oBox[3]:hide(), oBox[4]:hide(),;
        Form_Check(oBox, oDbf, oBrw, oDlg, aState))

    return nil

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

Function Form_Check(oBox, oDbf, oBrw, oDlg, aState)
    local cFilter := ""
    local aFilters := { { .F., "AGE>20" }, { .F., "STATE='NY'" }, { .F., "MARRIED" } }
    local aCheck[3], n
    local nRow := 8
    local nCol := 120
    local oSay

    @ 8, 40 SAY { || "FILTER : " + cFilter } SIZE 400, 25 PIXEL OF oDlg CENTER UPDATE TRANSPARENT

    @ nRow, 5 SAY oSay PROMPT "Filter by" SIZE 80, 20 PIXEL OF oBox[1];
        COLOR CLR_BLACK, Rgb(250,250,245)
    oSay:lTransparent := .T.

    for n := 1 to Len(aFilters)
        aCheck[n] := CreateChk(nRow, nCol, oBox, aFilters, n, oDbf, @cFilter, oBrw, oDlg, aState)
        aCheck[n]:lTransparent := .T.
        aCheck[n]:setcolor(CLR_BLACK, rgb(210,210,205))
        nCol += 160
        if n == 3
            EXIT
        endif
    next

    return nil

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

static function CreateChk(nRow, nCol, oBox, aFilters, nIndex, oDbf, cFilter, oBrw, oDlg, aState)
    local oChk

    @ nRow, nCol CHECKBOX oChk VAR aFilters[nIndex, 1];
        PROMPT aFilters[nIndex, 2] SIZE 150, 15 PIXEL OF oBox[1];
        ON CHANGE (cFilter := ResetFilter(aFilters, oDbf, oBox, oBrw, aState, nIndex ), oDlg:Update())

    return oChk


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

Function Refresh_Filter(oDbf, oBrw, cFilter, aFilters)
    local af := {}

    AEVAL(aFilters, { |a| If(a[1], AAdd(af, a[2]), nil) })
    cFilter := FW_ArrayAsList(af, " .AND. ")

    oDbf:SetFilter(cFilter)
    oDbf:GoTop()
    oBrw:Refresh()

    return nil

//-----------------------------------------------------------------------------//
function PanelBox(nTop, nLeft, nBottom, nRight, nClrLite, nClrDark,oDlg)
  local oPanel,oBrush
  Local aGrad := { nClrLite,nClrDark}
  DEFINE BRUSH oBrush GRADIENT aGrad
     oPanel:=Tpanel():New( nTop, nLeft,nTop+nBottom, nRight, oDlg)
     oPanel:SetBrush( oBrush )
   *  oPanel:bPainted := { || oPanel:Box( 1,1,oPanel:nHeight-1,oPanel:nWidth-1 ) }
return oPanel
//-----------------------------------------------------------------------------//

  FUNCTION ActivateNextBox( oBox, l2Box, l3Box, l4Box, oDlgx )
     local nPanel
     IF l2Box
        IF l3Box
            IF l4Box
                // All boxes are already active, do nothing
            ELSE
                oBox[4]:Show()
                oDlgx := oBox[4]
                l4Box := .T.
                nPanel:= 4
            ENDIF
        ELSE
            oBox[3]:Show()
            oDlgx := oBox[3]
            l3Box := .T.
            nPanel:= 3
        ENDIF
    ELSE
        oBox[2]:Show()
        oDlgx := oBox[2]
        l2Box := .T.
        nPanel:= 2
    ENDIF
    RETURN nPanel
//--------------------------------------------------------------------------//

FUNCTION DeactivateBox( oBox, nIndex, l2Box, l3Box, l4Box, oDlgx )
    DO CASE
        CASE nIndex == 2
            IF l2Box
                oBox[2]:Hide()
                l2Box := .F.
                oDlgx := NIL
                AdjustPanelPosition(oBox, 2)
            ENDIF
        CASE nIndex == 3
            IF l3Box
                oBox[3]:Hide()
                l3Box := .F.
                oDlgx := NIL
                AdjustPanelPosition(oBox, 3)
            ENDIF
        CASE nIndex == 4
            IF l4Box
                oBox[4]:Hide()
                l4Box := .F.
                oDlgx := NIL
                AdjustPanelPosition(oBox, 4)
            ENDIF
    ENDCASE
RETURN NIL
//--------------------------------------------------------------------------//
// When a checkbox activates a panel, we add the mapping to our array
FUNCTION ActivatePanel(nCheckboxIndex, nPanelIndex)
   aCheckboxPanelMap[nCheckboxIndex] := nPanelIndex
RETURN NIL
//--------------------------------------------------------------------------//
// When we want to deactivate a panel, we use mapping to find the panel
FUNCTION DeactivatePanel(nCheckboxIndex, oBox,oBrw)
   LOCAL nPanelIndex := aCheckboxPanelMap[nCheckboxIndex]
    IF nPanelIndex != NIL
        oBox[nPanelIndex]:Hide()
        aCheckboxPanelMap[nCheckboxIndex] := NIL
        // Spostiamo gli altri pannelli
        AdjustPanelPosition(oBox,oBrw)
    ENDIF
RETURN NIL
//--------------------------------------------------------------------------//
// Function to move the remaining panels when one is deactivated
FUNCTION AdjustPanelPosition(oBox, oBrw)
    LOCAL nDesiredTop := 440
    LOCAL nPanelHeight := 30  // Height of the single panel
    LOCAL nCurrentTop := nDesiredTop

    // Calculate the number of active panels
    LOCAL nActivePanels := 0
    FOR nIndex := 2 TO LEN(oBox)
        IF !Empty(oBox[nIndex])
            nActivePanels++
        ENDIF
    NEXT

    // Calculate the new position of the active panels
    IF nActivePanels > 0
        nCurrentTop -= nPanelHeight * nActivePanels
    ENDIF

    FOR nIndex := 2 TO LEN(oBox)
        IF !Empty(oBox[nIndex])
            oBox[nIndex]:nTop := nCurrentTop
            nCurrentTop += nPanelHeight
        ENDIF
    NEXT
RETURN NIL
//--------------------------------------------------------------------------//

STATIC FUNCTION ResetFilter(aFilters, oDbf, oBox, oBrw, aState, nIndex)
    LOCAL cFilter := ""
    LOCAL af := {}
    LOCAL cState := SPACE(25)
    LOCAL lMarried := .F.
    LOCAL nAge := 0
    LOCAL oCmb, nState := 1
    LOCAL nRow := 8
    LOCAL oSay, oRadio, nRadio := 1, cMarried := ""
    LOCAL oDlgx, i
    LOCAL aAge := {"20", "40", "60"}
    LOCAL nBoxHeight := 30
    LOCAL nVisibleBoxHeight := 0
    LOCAL oCtrl
    LOCAL nPanel

    oDlgx := NIL


    IF aFilters[nIndex, 1]

        // We use ActivateNextBox to get the number of the activated panel
        nPanel := ActivateNextBox(oBox, @l2Box, @l3Box, @l4Box, @oDlgx)

        nVisibleBoxHeight := 30

        // We hide the controls if they are there in oDlgx
        IF !Empty(oDlgx:acontrols)
            FOR EACH oCtrl IN oDlgx:acontrols
                oCtrl:hide()
            NEXT
        ENDIF

        // We activate the panel corresponding to the checkbox
        ActivatePanel(nIndex, nPanel)

        DO CASE
        CASE nIndex == 1   // Age

                @ nRow, 5 SAY oSay PROMPT "Age:" SIZE 80, 20 PIXEL OF oDlgx;
                        COLOR CLR_BLACK, Rgb(250,250,245)
                    oSay:lTransparent := .T.
                    @ 0.4, 10 COMBOBOX oCmb VAR nAge ITEMS aAge;
                        SIZE 600, 90 OF oDlgx;
                        ON CHANGE (cFilter := 'AGE<' + LTrim(Str(nAge)),;
                                   aFilters[1, 2] := cFilter,;
                                   Refresh_Filter(oDbf, oBrw, @cFilter, aFilters))

                 CASE nIndex == 2   // State

                  @ nRow, 5 SAY oSay PROMPT "State:" SIZE 80, 20 PIXEL OF oDlgx;
                        COLOR CLR_BLACK, Rgb(250,250,245)
                    oSay:lTransparent := .T.
                    @ 0.4, 10 COMBOBOX oCmb VAR nState ITEMS ArrTranspose(aState)[2];
                        SIZE 600, 90 OF oDlgx;
                        ON CHANGE (cState := aState[nState][1],;
                                   cFilter := 'STATE=' + "'" + cState + "'",;
                                   aFilters[2, 2] := cFilter,;
                                   Refresh_Filter(oDbf, oBrw, @cFilter, aFilters))

                 CASE nIndex == 3   // Married

                 @ nRow, 5 SAY oSay PROMPT "Married:" SIZE 80, 20 PIXEL OF oDlgx;
                        COLOR CLR_BLACK, Rgb(250,250,245)
                    oSay:lTransparent := .T.
                    @ 1, 80 RADIO oRadio VAR nRadio OF oDlgx UPDATE SIZE 80, 25 PIXEL;
                        PROMPT "Married";
                        ON CHANGE (IF(nRadio == 1, cMarried := ".T.", cMarried := ".F."),;
                                   cFilter := 'MARRIED=' + cMarried,;
                                   aFilters[3, 2] := cFilter,;
                                   Refresh_Filter(oDbf, oBrw, @cFilter, aFilters))

                    @ 1, 400 RADIOITEM "Not Married" RADIOMENU oRadio;
                        OF oDlgx PIXEL SIZE 80, 20
            ENDCASE


    ELSE
        // We deactivate the panel corresponding to the checkbox
        DeactivatePanel(nIndex, oBox,oBrw)
        nVisibleBoxHeight -= 30 // Let's remove the height of the deactivated panel
    ENDIF

    // Let's update the smaller browser size
    oBrw:nBottomMargin += nVisibleBoxHeight

    // Let's update the filter and browser
    AEVAL(aFilters, { |a| If(a[1], AAdd(af, a[2]), NIL) })
    cFilter := FW_ArrayAsList(af, " .AND. ")
    oDbf:SetFilter(cFilter)
    oDbf:GoTop()
    oBrw:Refresh()

    RETURN cFilter
//--------------------------------------------------------------------------//

 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: also for obrw nheight

Postby karinha » Fri May 17, 2024 11:26 am

Incluso lo intento, pero no puedo entender esta lógica. ¿QUIÉN ES NINDEX?
I even try, but I can't understand this logic. WHO IS NINDEX?

Code: Select all  Expand view

SILVMARR.prg(275) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(275) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(277) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(283) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(283) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(292) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(292) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(294) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(296) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(302) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(302) Warning W0001  Ambiguous reference: 'NINDEX'
 


Code: Select all  Expand view

// C:\FWH\SILVMARR.PRG

#include "fivewin.ch"
#include "constant.ch"

#define DLG_nColorDlg     RGB(245,245,235)
#define DLG_nColortitle1  RGB(219,230,244)
#define DLG_nColortitle2  RGB(207,221,239)
#define DLG_nColorBar1    RGB(250,250,245)
#define DLG_nColorBar2    RGB(245,245,235)
#define DLG_nColorBtn1    RGB(245,245,235)
#define DLG_nColorBtn2    RGB(250,250,245)
#define DLG_nColorBtnB    RGB(195,195,185)

REQUEST DBFCDX

STATIC l2Box, l3Box, l4Box, nBoxNumber, aCheckboxPanelMap

FUNCTION Main()

   LOCAL oDlg, oBrw, oFont, oBold
   LOCAL nBottom := 32.4
   LOCAL nRight := 95
   LOCAL nHt := nBottom * DLG_CHARPIX_H
   LOCAL nWd := Max( nRight * DLG_CHARPIX_W, 180 )
   LOCAL oBox := Array( 4 ) // 3+1
   LOCAL oDbf, oState
   LOCAL nRow
   LOCAL aState := {}

   l2Box := .F.
   l3Box := .F.
   l4Box := .F.

   aCheckboxPanelMap := Array( 3 )

   oFont := TFont():New( "TAHOMA", 0, 14 )
   oBold := TFont():New( "TAHOMA", 0, 14,, .T. )

   oState := TDataBase():Open( NIL, "STATES", "DBFCDX", .T. )
   oState:gotop()

   WHILE .NOT. oState:Eof()

      SYSREFRESH()

      AAdd( aState, { oState:CODE, oState:NAME } )

      oState:skip()

   ENDDO

   oState:close()

   oDbf := TDataBase():Open( NIL, "CUSTOMER", "DBFCDX", .T. )

   DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL TRUEPIXEL    ;
      FONT oFont COLOR CLR_BLACK, RGB( 245, 245, 235 ) ;
      STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, WS_MINIMIZEBOX )

   @ 40, 10 XBROWSE oBrw SIZE - 10, - 60 PIXEL OF oDlg ;
      DATASOURCE oDbf                                  ;
      COLUMNS "ID", "CITY", "STATE", "MARRIED", "AGE"  ;
      CELL LINES NOBORDER UPDATE

   WITH OBJECT oBrw

      :nRowHeight := 25
      :l2007 := .F.
      :l2015 := .T.
      :lRecordSelector := .F.
      :nColDividerStyle := LINESTYLE_LIGHTGRAY
      :nRowDividerStyle := LINESTYLE_LIGHTGRAY
      :nStretchCol := STRETCHCOL_WIDEST
      :nMarqueeStyle := MARQSTYLE_HIGHLROW
      :SetChecks()
      :lHScroll := .F.
      :CreateFromCode()

   END

   nRow := 440

   oBox[ 1 ] := PanelBox( nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2, oDlg )

   nRow -= 31

   oBox[ 2 ] := PanelBox( nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2, oDlg )

   nRow -= 31

   oBox[ 3 ] := PanelBox( nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2, oDlg )

   nRow -= 31

   oBox[ 4 ] := PanelBox( nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2, oDlg )

   ACTIVATE DIALOG oDlg CENTERED;
      ON INIT ( oBox[ 2 ]:hide(), oBox[ 3 ]:hide(), oBox[ 4 ]:hide(), ;
      Form_Check( oBox, oDbf, oBrw, oDlg, aState ) )

RETURN NIL

FUNCTION Form_Check( oBox, oDbf, oBrw, oDlg, aState )

   LOCAL cFilter := ""
   LOCAL aFilters := { { .F., "AGE>20" }, { .F., "STATE='NY'" }, { .F., "MARRIED" } }
   LOCAL aCheck[ 3 ], n
   LOCAL nRow := 8
   LOCAL nCol := 120
   LOCAL oSay

   @ 8, 40 SAY {|| "FILTER : " + cFilter } SIZE 400, 25 PIXEL OF oDlg CENTER UPDATE TRANSPARENT

   @ nRow, 5 SAY oSay PROMPT "Filter by" SIZE 80, 20 PIXEL OF oBox[ 1 ];
      COLOR CLR_BLACK, Rgb( 250, 250, 245 )

   oSay:lTransparent := .T.

   FOR n := 1 TO Len( aFilters )

      IF n == 3
         EXIT
      ENDIF

      aCheck[ n ] := CreateChk( nRow, nCol, oBox, aFilters, n, oDbf, @cFilter, oBrw, oDlg, aState )
      aCheck[ n ]:lTransparent := .T.
      aCheck[ n ]:SetColor( CLR_BLACK, rgb( 210, 210, 205 ) )

      nCol += 160

   NEXT

RETURN NIL

STATIC FUNCTION CreateChk( nRow, nCol, oBox, aFilters, nIndex, oDbf, cFilter, oBrw, oDlg, aState )

   LOCAL oChk

   @ nRow, nCol CHECKBOX oChk VAR aFilters[ nIndex, 1 ];
      PROMPT aFilters[ nIndex, 2 ] SIZE 150, 15 PIXEL OF oBox[ 1 ];
      ON CHANGE ( cFilter := ResetFilter( aFilters, oDbf, oBox, oBrw, aState, nIndex ), oDlg:Update() )

RETURN( oChk )

FUNCTION Refresh_Filter( oDbf, oBrw, cFilter, aFilters )

   LOCAL af := {}

   AEval( aFilters, {| a | If( a[ 1 ], AAdd( af, a[ 2 ] ), nil ) } )

   cFilter := FW_ArrayAsList( af, " .AND. " )

   oDbf:SetFilter( cFilter )
   oDbf:GoTop()

   oBrw:Refresh()

RETURN NIL

FUNCTION PanelBox( nTop, nLeft, nBottom, nRight, nClrLite, nClrDark, oDlg )

   LOCAL oPanel, oBrush
   LOCAL aGrad := { nClrLite, nClrDark }

   DEFINE BRUSH oBrush GRADIENT aGrad

   oPanel := Tpanel():New( nTop, nLeft, nTop + nBottom, nRight, oDlg )
   oPanel:SetBrush( oBrush )

RETURN( oPanel )

FUNCTION ActivateNextBox( oBox, l2Box, l3Box, l4Box, oDlgx )

   LOCAL nPanel

   IF l2Box

      IF l3Box

         IF l4Box
            // All boxes are already active, do nothing
         ELSE
            oBox[ 4 ]:Show()
            oDlgx := oBox[ 4 ]
            l4Box := .T.
            nPanel := 4
         ENDIF

      ELSE

         oBox[ 3 ]:Show()

         oDlgx  := oBox[ 3 ]
         l3Box  := .T.
         nPanel := 3

      ENDIF

   ELSE

      oBox[ 2 ]:Show()

      oDlgx  := oBox[ 2 ]
      l2Box  := .T.
      nPanel := 2

   ENDIF

RETURN( nPanel )

FUNCTION DeactivateBox( oBox, nIndex, l2Box, l3Box, l4Box, oDlgx )

   DO CASE
   CASE nIndex == 2

      IF l2Box
         oBox[ 2 ]:Hide()
         l2Box := .F.
         oDlgx := NIL
         AdjustPanelPosition( oBox, 2 )
      ENDIF

   CASE nIndex == 3

      IF l3Box
         oBox[ 3 ]:Hide()
         l3Box := .F.
         oDlgx := NIL
         AdjustPanelPosition( oBox, 3 )
      ENDIF

   CASE nIndex == 4

      IF l4Box
         oBox[ 4 ]:Hide()
         l4Box := .F.
         oDlgx := NIL
         AdjustPanelPosition( oBox, 4 )
      ENDIF

   ENDCASE

RETURN NIL
// When a checkbox activates a panel, we add the mapping to our array
FUNCTION ActivatePanel( nCheckboxIndex, nPanelIndex )

   aCheckboxPanelMap[ nCheckboxIndex ] := nPanelIndex

RETURN NIL
// When we want to deactivate a panel, we use mapping to find the panel
FUNCTION DeactivatePanel( nCheckboxIndex, oBox, oBrw )

   LOCAL nPanelIndex := aCheckboxPanelMap[ nCheckboxIndex ]

   IF nPanelIndex != NIL

      oBox[ nPanelIndex ]:Hide()

      aCheckboxPanelMap[ nCheckboxIndex ] := NIL

      // Spostiamo gli altri pannelli
      AdjustPanelPosition( oBox, oBrw )

   ENDIF

RETURN NIL
// Function to move the remaining panels when one is deactivated
FUNCTION AdjustPanelPosition( oBox, oBrw )

   LOCAL nDesiredTop := 440
   LOCAL nPanelHeight := 30  // Height of the single panel
   LOCAL nCurrentTop := nDesiredTop
   // Calculate the number of active panels
   LOCAL nActivePanels := 0

   FOR nIndex := 2 TO Len( oBox )

      IF .NOT. Empty( oBox[ nIndex ] )

         nActivePanels++

      ENDIF

   NEXT

   // Calculate the new position of the active panels
   IF nActivePanels > 0

      nCurrentTop -= nPanelHeight * nActivePanels

   ENDIF

   FOR nIndex := 2 TO Len( oBox )

      IF .NOT. Empty( oBox[ nIndex ] )

         oBox[ nIndex ]:nTop := nCurrentTop

         nCurrentTop += nPanelHeight

      ENDIF

   NEXT

RETURN NIL

STATIC FUNCTION ResetFilter( aFilters, oDbf, oBox, oBrw, aState, nIndex )

   LOCAL cFilter := ""
   LOCAL af := {}
   LOCAL cState := Space( 25 )
   LOCAL lMarried := .F.
   LOCAL nAge := 0
   LOCAL oCmb, nState := 1
   LOCAL nRow := 8
   LOCAL oSay, oRadio, nRadio := 1, cMarried := ""
   LOCAL oDlgx, i
   LOCAL aAge := { "20", "40", "60" }
   LOCAL nBoxHeight := 30
   LOCAL nVisibleBoxHeight := 0
   LOCAL oCtrl
   LOCAL nPanel

   oDlgx := NIL

   IF aFilters[ nIndex, 1 ]

      // We use ActivateNextBox to get the number of the activated panel
      nPanel := ActivateNextBox( oBox, @l2Box, @l3Box, @l4Box, @oDlgx )

      nVisibleBoxHeight := 30

      // We hide the controls if they are there in oDlgx
      IF .NOT. Empty( oDlgx:acontrols )

         FOR EACH oCtrl IN oDlgx:acontrols

            oCtrl:hide()

         NEXT

      ENDIF

      // We activate the panel corresponding to the checkbox
      ActivatePanel( nIndex, nPanel )

      DO CASE
      CASE nIndex == 1   // Age

         @ nRow, 5 SAY oSay PROMPT "Age:" SIZE 80, 20 PIXEL OF oDlgx;
            COLOR CLR_BLACK, Rgb( 250, 250, 245 )

         oSay:lTransparent := .T.

         @ 0.4, 10 COMBOBOX oCmb VAR nAge ITEMS aAge;
            SIZE 600, 90 OF oDlgx;
            ON CHANGE ( cFilter := 'AGE<' + LTrim( Str( nAge ) ), ;
            aFilters[ 1, 2 ] := cFilter, ;
            Refresh_Filter( oDbf, oBrw, @cFilter, aFilters ) )

      CASE nIndex == 2   // State

         @ nRow, 5 SAY oSay PROMPT "State:" SIZE 80, 20 PIXEL OF oDlgx;
            COLOR CLR_BLACK, Rgb( 250, 250, 245 )

         oSay:lTransparent := .T.

         @ 0.4, 10 COMBOBOX oCmb VAR nState ITEMS ArrTranspose( aState )[ 2 ];
            SIZE 600, 90 OF oDlgx;
            ON CHANGE ( cState := aState[ nState ][ 1 ], ;
            cFilter := 'STATE=' + "'" + cState + "'", ;
            aFilters[ 2, 2 ] := cFilter, ;
            Refresh_Filter( oDbf, oBrw, @cFilter, aFilters ) )

      CASE nIndex == 3   // Married

         @ nRow, 5 SAY oSay PROMPT "Married:" SIZE 80, 20 PIXEL OF oDlgx;
            COLOR CLR_BLACK, Rgb( 250, 250, 245 )

         oSay:lTransparent := .T.

         @ 1, 80 RADIO oRadio VAR nRadio OF oDlgx UPDATE SIZE 80, 25 PIXEL;
            PROMPT "Married";
            ON CHANGE ( IF( nRadio == 1, cMarried := ".T.", cMarried := ".F." ), ;
            cFilter := 'MARRIED=' + cMarried, ;
            aFilters[ 3, 2 ] := cFilter, ;
            Refresh_Filter( oDbf, oBrw, @cFilter, aFilters ) )

         @ 1, 400 RADIOITEM "Not Married" RADIOMENU oRadio;
            OF oDlgx PIXEL SIZE 80, 20

      ENDCASE


   ELSE
      // We deactivate the panel corresponding to the checkbox
      DeactivatePanel( nIndex, oBox, oBrw )

      nVisibleBoxHeight -= 30 // Let's remove the height of the deactivated panel

   ENDIF

   // Let's update the smaller browser size
   oBrw:nBottomMargin += nVisibleBoxHeight

   // Let's update the filter and browser
   AEval( aFilters, {| a | If( a[ 1 ], AAdd( af, a[ 2 ] ), NIL ) } )

   cFilter := FW_ArrayAsList( af, " .AND. " )

   oDbf:SetFilter( cFilter )
   oDbf:GoTop()

   oBrw:Refresh()

RETURN( cFilter )

// FIN / END
 


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

Re: also for obrw nheight

Postby Silvio.Falconi » Fri May 17, 2024 1:06 pm

karinha wrote:Incluso lo intento, pero no puedo entender esta lógica. ¿QUIÉN ES NINDEX?
I even try, but I can't understand this logic. WHO IS NINDEX?

Code: Select all  Expand view

SILVMARR.prg(275) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(275) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(277) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(283) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(283) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(292) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(292) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(294) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(296) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(302) Warning W0001  Ambiguous reference: 'NINDEX'

SILVMARR.prg(302) Warning W0001  Ambiguous reference: 'NINDEX'
 


Code: Select all  Expand view

// C:\FWH\SILVMARR.PRG

#include "fivewin.ch"
#include "constant.ch"

#define DLG_nColorDlg     RGB(245,245,235)
#define DLG_nColortitle1  RGB(219,230,244)
#define DLG_nColortitle2  RGB(207,221,239)
#define DLG_nColorBar1    RGB(250,250,245)
#define DLG_nColorBar2    RGB(245,245,235)
#define DLG_nColorBtn1    RGB(245,245,235)
#define DLG_nColorBtn2    RGB(250,250,245)
#define DLG_nColorBtnB    RGB(195,195,185)

REQUEST DBFCDX

STATIC l2Box, l3Box, l4Box, nBoxNumber, aCheckboxPanelMap

FUNCTION Main()

   LOCAL oDlg, oBrw, oFont, oBold
   LOCAL nBottom := 32.4
   LOCAL nRight := 95
   LOCAL nHt := nBottom * DLG_CHARPIX_H
   LOCAL nWd := Max( nRight * DLG_CHARPIX_W, 180 )
   LOCAL oBox := Array( 4 ) // 3+1
   LOCAL oDbf, oState
   LOCAL nRow
   LOCAL aState := {}

   l2Box := .F.
   l3Box := .F.
   l4Box := .F.

   aCheckboxPanelMap := Array( 3 )

   oFont := TFont():New( "TAHOMA", 0, 14 )
   oBold := TFont():New( "TAHOMA", 0, 14,, .T. )

   oState := TDataBase():Open( NIL, "STATES", "DBFCDX", .T. )
   oState:gotop()

   WHILE .NOT. oState:Eof()

      SYSREFRESH()

      AAdd( aState, { oState:CODE, oState:NAME } )

      oState:skip()

   ENDDO

   oState:close()

   oDbf := TDataBase():Open( NIL, "CUSTOMER", "DBFCDX", .T. )

   DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL TRUEPIXEL    ;
      FONT oFont COLOR CLR_BLACK, RGB( 245, 245, 235 ) ;
      STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, WS_MINIMIZEBOX )

   @ 40, 10 XBROWSE oBrw SIZE - 10, - 60 PIXEL OF oDlg ;
      DATASOURCE oDbf                                  ;
      COLUMNS "ID", "CITY", "STATE", "MARRIED", "AGE"  ;
      CELL LINES NOBORDER UPDATE

   WITH OBJECT oBrw

      :nRowHeight := 25
      :l2007 := .F.
      :l2015 := .T.
      :lRecordSelector := .F.
      :nColDividerStyle := LINESTYLE_LIGHTGRAY
      :nRowDividerStyle := LINESTYLE_LIGHTGRAY
      :nStretchCol := STRETCHCOL_WIDEST
      :nMarqueeStyle := MARQSTYLE_HIGHLROW
      :SetChecks()
      :lHScroll := .F.
      :CreateFromCode()

   END

   nRow := 440

   oBox[ 1 ] := PanelBox( nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2, oDlg )

   nRow -= 31

   oBox[ 2 ] := PanelBox( nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2, oDlg )

   nRow -= 31

   oBox[ 3 ] := PanelBox( nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2, oDlg )

   nRow -= 31

   oBox[ 4 ] := PanelBox( nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2, oDlg )

   ACTIVATE DIALOG oDlg CENTERED;
      ON INIT ( oBox[ 2 ]:hide(), oBox[ 3 ]:hide(), oBox[ 4 ]:hide(), ;
      Form_Check( oBox, oDbf, oBrw, oDlg, aState ) )

RETURN NIL

FUNCTION Form_Check( oBox, oDbf, oBrw, oDlg, aState )

   LOCAL cFilter := ""
   LOCAL aFilters := { { .F., "AGE>20" }, { .F., "STATE='NY'" }, { .F., "MARRIED" } }
   LOCAL aCheck[ 3 ], n
   LOCAL nRow := 8
   LOCAL nCol := 120
   LOCAL oSay

   @ 8, 40 SAY {|| "FILTER : " + cFilter } SIZE 400, 25 PIXEL OF oDlg CENTER UPDATE TRANSPARENT

   @ nRow, 5 SAY oSay PROMPT "Filter by" SIZE 80, 20 PIXEL OF oBox[ 1 ];
      COLOR CLR_BLACK, Rgb( 250, 250, 245 )

   oSay:lTransparent := .T.

   FOR n := 1 TO Len( aFilters )

      IF n == 3
         EXIT
      ENDIF

      aCheck[ n ] := CreateChk( nRow, nCol, oBox, aFilters, n, oDbf, @cFilter, oBrw, oDlg, aState )
      aCheck[ n ]:lTransparent := .T.
      aCheck[ n ]:SetColor( CLR_BLACK, rgb( 210, 210, 205 ) )

      nCol += 160

   NEXT

RETURN NIL

STATIC FUNCTION CreateChk( nRow, nCol, oBox, aFilters, nIndex, oDbf, cFilter, oBrw, oDlg, aState )

   LOCAL oChk

   @ nRow, nCol CHECKBOX oChk VAR aFilters[ nIndex, 1 ];
      PROMPT aFilters[ nIndex, 2 ] SIZE 150, 15 PIXEL OF oBox[ 1 ];
      ON CHANGE ( cFilter := ResetFilter( aFilters, oDbf, oBox, oBrw, aState, nIndex ), oDlg:Update() )

RETURN( oChk )

FUNCTION Refresh_Filter( oDbf, oBrw, cFilter, aFilters )

   LOCAL af := {}

   AEval( aFilters, {| a | If( a[ 1 ], AAdd( af, a[ 2 ] ), nil ) } )

   cFilter := FW_ArrayAsList( af, " .AND. " )

   oDbf:SetFilter( cFilter )
   oDbf:GoTop()

   oBrw:Refresh()

RETURN NIL

FUNCTION PanelBox( nTop, nLeft, nBottom, nRight, nClrLite, nClrDark, oDlg )

   LOCAL oPanel, oBrush
   LOCAL aGrad := { nClrLite, nClrDark }

   DEFINE BRUSH oBrush GRADIENT aGrad

   oPanel := Tpanel():New( nTop, nLeft, nTop + nBottom, nRight, oDlg )
   oPanel:SetBrush( oBrush )

RETURN( oPanel )

FUNCTION ActivateNextBox( oBox, l2Box, l3Box, l4Box, oDlgx )

   LOCAL nPanel

   IF l2Box

      IF l3Box

         IF l4Box
            // All boxes are already active, do nothing
         ELSE
            oBox[ 4 ]:Show()
            oDlgx := oBox[ 4 ]
            l4Box := .T.
            nPanel := 4
         ENDIF

      ELSE

         oBox[ 3 ]:Show()

         oDlgx  := oBox[ 3 ]
         l3Box  := .T.
         nPanel := 3

      ENDIF

   ELSE

      oBox[ 2 ]:Show()

      oDlgx  := oBox[ 2 ]
      l2Box  := .T.
      nPanel := 2

   ENDIF

RETURN( nPanel )

FUNCTION DeactivateBox( oBox, nIndex, l2Box, l3Box, l4Box, oDlgx )

   DO CASE
   CASE nIndex == 2

      IF l2Box
         oBox[ 2 ]:Hide()
         l2Box := .F.
         oDlgx := NIL
         AdjustPanelPosition( oBox, 2 )
      ENDIF

   CASE nIndex == 3

      IF l3Box
         oBox[ 3 ]:Hide()
         l3Box := .F.
         oDlgx := NIL
         AdjustPanelPosition( oBox, 3 )
      ENDIF

   CASE nIndex == 4

      IF l4Box
         oBox[ 4 ]:Hide()
         l4Box := .F.
         oDlgx := NIL
         AdjustPanelPosition( oBox, 4 )
      ENDIF

   ENDCASE

RETURN NIL
// When a checkbox activates a panel, we add the mapping to our array
FUNCTION ActivatePanel( nCheckboxIndex, nPanelIndex )

   aCheckboxPanelMap[ nCheckboxIndex ] := nPanelIndex

RETURN NIL
// When we want to deactivate a panel, we use mapping to find the panel
FUNCTION DeactivatePanel( nCheckboxIndex, oBox, oBrw )

   LOCAL nPanelIndex := aCheckboxPanelMap[ nCheckboxIndex ]

   IF nPanelIndex != NIL

      oBox[ nPanelIndex ]:Hide()

      aCheckboxPanelMap[ nCheckboxIndex ] := NIL

      // Spostiamo gli altri pannelli
      AdjustPanelPosition( oBox, oBrw )

   ENDIF

RETURN NIL
// Function to move the remaining panels when one is deactivated
FUNCTION AdjustPanelPosition( oBox, oBrw )

   LOCAL nDesiredTop := 440
   LOCAL nPanelHeight := 30  // Height of the single panel
   LOCAL nCurrentTop := nDesiredTop
   // Calculate the number of active panels
   LOCAL nActivePanels := 0

   FOR nIndex := 2 TO Len( oBox )

      IF .NOT. Empty( oBox[ nIndex ] )

         nActivePanels++

      ENDIF

   NEXT

   // Calculate the new position of the active panels
   IF nActivePanels > 0

      nCurrentTop -= nPanelHeight * nActivePanels

   ENDIF

   FOR nIndex := 2 TO Len( oBox )

      IF .NOT. Empty( oBox[ nIndex ] )

         oBox[ nIndex ]:nTop := nCurrentTop

         nCurrentTop += nPanelHeight

      ENDIF

   NEXT

RETURN NIL

STATIC FUNCTION ResetFilter( aFilters, oDbf, oBox, oBrw, aState, nIndex )

   LOCAL cFilter := ""
   LOCAL af := {}
   LOCAL cState := Space( 25 )
   LOCAL lMarried := .F.
   LOCAL nAge := 0
   LOCAL oCmb, nState := 1
   LOCAL nRow := 8
   LOCAL oSay, oRadio, nRadio := 1, cMarried := ""
   LOCAL oDlgx, i
   LOCAL aAge := { "20", "40", "60" }
   LOCAL nBoxHeight := 30
   LOCAL nVisibleBoxHeight := 0
   LOCAL oCtrl
   LOCAL nPanel

   oDlgx := NIL

   IF aFilters[ nIndex, 1 ]

      // We use ActivateNextBox to get the number of the activated panel
      nPanel := ActivateNextBox( oBox, @l2Box, @l3Box, @l4Box, @oDlgx )

      nVisibleBoxHeight := 30

      // We hide the controls if they are there in oDlgx
      IF .NOT. Empty( oDlgx:acontrols )

         FOR EACH oCtrl IN oDlgx:acontrols

            oCtrl:hide()

         NEXT

      ENDIF

      // We activate the panel corresponding to the checkbox
      ActivatePanel( nIndex, nPanel )

      DO CASE
      CASE nIndex == 1   // Age

         @ nRow, 5 SAY oSay PROMPT "Age:" SIZE 80, 20 PIXEL OF oDlgx;
            COLOR CLR_BLACK, Rgb( 250, 250, 245 )

         oSay:lTransparent := .T.

         @ 0.4, 10 COMBOBOX oCmb VAR nAge ITEMS aAge;
            SIZE 600, 90 OF oDlgx;
            ON CHANGE ( cFilter := 'AGE<' + LTrim( Str( nAge ) ), ;
            aFilters[ 1, 2 ] := cFilter, ;
            Refresh_Filter( oDbf, oBrw, @cFilter, aFilters ) )

      CASE nIndex == 2   // State

         @ nRow, 5 SAY oSay PROMPT "State:" SIZE 80, 20 PIXEL OF oDlgx;
            COLOR CLR_BLACK, Rgb( 250, 250, 245 )

         oSay:lTransparent := .T.

         @ 0.4, 10 COMBOBOX oCmb VAR nState ITEMS ArrTranspose( aState )[ 2 ];
            SIZE 600, 90 OF oDlgx;
            ON CHANGE ( cState := aState[ nState ][ 1 ], ;
            cFilter := 'STATE=' + "'" + cState + "'", ;
            aFilters[ 2, 2 ] := cFilter, ;
            Refresh_Filter( oDbf, oBrw, @cFilter, aFilters ) )

      CASE nIndex == 3   // Married

         @ nRow, 5 SAY oSay PROMPT "Married:" SIZE 80, 20 PIXEL OF oDlgx;
            COLOR CLR_BLACK, Rgb( 250, 250, 245 )

         oSay:lTransparent := .T.

         @ 1, 80 RADIO oRadio VAR nRadio OF oDlgx UPDATE SIZE 80, 25 PIXEL;
            PROMPT "Married";
            ON CHANGE ( IF( nRadio == 1, cMarried := ".T.", cMarried := ".F." ), ;
            cFilter := 'MARRIED=' + cMarried, ;
            aFilters[ 3, 2 ] := cFilter, ;
            Refresh_Filter( oDbf, oBrw, @cFilter, aFilters ) )

         @ 1, 400 RADIOITEM "Not Married" RADIOMENU oRadio;
            OF oDlgx PIXEL SIZE 80, 20

      ENDCASE


   ELSE
      // We deactivate the panel corresponding to the checkbox
      DeactivatePanel( nIndex, oBox, oBrw )

      nVisibleBoxHeight -= 30 // Let's remove the height of the deactivated panel

   ENDIF

   // Let's update the smaller browser size
   oBrw:nBottomMargin += nVisibleBoxHeight

   // Let's update the filter and browser
   AEval( aFilters, {| a | If( a[ 1 ], AAdd( af, a[ 2 ] ), NIL ) } )

   cFilter := FW_ArrayAsList( af, " .AND. " )

   oDbf:SetFilter( cFilter )
   oDbf:GoTop()

   oBrw:Refresh()

RETURN( cFilter )

// FIN / END
 


Regards, saludos.











imposible, lo compilé con el aviso /2 como puedes ver en el vídeo

impossible, I compiled with warning /2 as you can see in the video




Image




this test

Code: Select all  Expand view
#include "fivewin.ch"
#include "constant.ch"

#define DLG_nColorDlg     RGB(245,245,235)
#define DLG_nColortitle1  RGB(219,230,244)
#define DLG_nColortitle2  RGB(207,221,239)
#define DLG_nColorBar1    RGB(250,250,245)
#define DLG_nColorBar2    RGB(245,245,235)
#define DLG_nColorBtn1    RGB(245,245,235)
#define DLG_nColorBtn2    RGB(250,250,245)
#define DLG_nColorBtnB    RGB(195,195,185)

REQUEST DBFCDX

static l2Box,l3Box,l4Box
static nBoxNumber
STATIC aCheckboxPanelMap

function Main()

    local oDlg, oBrw, oFont, oBold
    local nBottom := 32.4
    local nRight := 95
    local nHt := nBottom * DLG_CHARPIX_H
    local nWd := Max(nRight * DLG_CHARPIX_W, 180)
    local oBox := Array(4) // 3+1
    local oDbf, oState
    local nRow
    local aState := {}




           l2Box := .F.
           l3Box := .F.
           l4Box := .F.
           aCheckboxPanelMap:=array(3)








    oFont := TFont():New("TAHOMA", 0, 14)
     oBold := TFont():New( "TAHOMA", 0, 14,,.t. )

    oState := TDataBase():Open(nil, "STATES", "DBFCDX", .T.)
    oState:gotop()
    Do While !oState:eof()
        AADD(aState, {oState:CODE, oState:NAME})
        oState:skip()
    enddo
    oState:close()

    oDbf := TDataBase():Open(nil, "CUSTOMER", "DBFCDX", .T.)

    DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL TRUEPIXEL;
        FONT oFont COLOR CLR_BLACK, RGB(245,245,235);
        STYLE nOR(DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, WS_MINIMIZEBOX)

    @ 40, 10 XBROWSE oBrw SIZE -10,-60 PIXEL OF oDlg;
        DATASOURCE oDbf;
        COLUMNS "ID", "CITY", "STATE", "MARRIED", "AGE";
        CELL LINES NOBORDER UPDATE

    WITH OBJECT oBrw
        :nRowHeight := 25
        :l2007 := .F.
        :l2015 := .T.
        :lRecordSelector := .F.
        :nColDividerStyle := LINESTYLE_LIGHTGRAY
        :nRowDividerStyle := LINESTYLE_LIGHTGRAY
        :nStretchCol := STRETCHCOL_WIDEST
        :nMarqueeStyle := MARQSTYLE_HIGHLROW
        :SetChecks()
        :lHScroll := .F.
        :CreateFromCode()
     END

    nRow := 440
    oBox[1] := PanelBox(nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2,oDlg)
    nRow -= 31
    oBox[2] := PanelBox(nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2,oDlg)
    nRow -= 31
    oBox[3] := PanelBox(nRow, 10, 30, oDlg:nWidth - 20, DLG_nColorBar1, DLG_nColorBar2,oDlg)
    nRow -= 31
    oBox[4] := PanelBox(nRow, 10, 30, oDlg:nWidth - 20,DLG_nColorBar1, DLG_nColorBar2,oDlg)

    ACTIVATE DIALOG oDlg CENTERED;
        ON INIT (oBox[2]:hide(), oBox[3]:hide(), oBox[4]:hide(),;
        Form_Check(oBox, oDbf, oBrw, oDlg, aState))

    return nil

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

Function Form_Check(oBox, oDbf, oBrw, oDlg, aState)
    local cFilter := ""
    local aFilters := { { .F., "AGE>20" }, { .F., "STATE='NY'" }, { .F., "MARRIED" } }
    local aCheck[3], n
    local nRow := 8
    local nCol := 120
    local oSay

    @ 8, 40 SAY { || "FILTER : " + cFilter } SIZE 400, 25 PIXEL OF oDlg CENTER UPDATE TRANSPARENT

    @ nRow, 5 SAY oSay PROMPT "Filter by" SIZE 80, 20 PIXEL OF oBox[1];
        COLOR CLR_BLACK, Rgb(250,250,245)
    oSay:lTransparent := .T.

    for n := 1 to Len(aFilters)
        aCheck[n] := CreateChk(nRow, nCol, oBox, aFilters, n, oDbf, @cFilter, oBrw, oDlg, aState)
        aCheck[n]:lTransparent := .T.
        aCheck[n]:setcolor(CLR_BLACK, rgb(210,210,205))
        nCol += 160
        if n == 3
            EXIT
        endif
    next

    return nil

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

static function CreateChk(nRow, nCol, oBox, aFilters, nIndex, oDbf, cFilter, oBrw, oDlg, aState)
    local oChk

    @ nRow, nCol CHECKBOX oChk VAR aFilters[nIndex, 1];
        PROMPT aFilters[nIndex, 2] SIZE 150, 15 PIXEL OF oBox[1];
        ON CHANGE (cFilter := ResetFilter(aFilters, oDbf, oBox, oBrw, aState, nIndex ), oDlg:Update())

    return oChk


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

Function Refresh_Filter(oDbf, oBrw, cFilter, aFilters)
    local af := {}

    AEVAL(aFilters, { |a| If(a[1], AAdd(af, a[2]), nil) })
    cFilter := FW_ArrayAsList(af, " .AND. ")

    oDbf:SetFilter(cFilter)
    oDbf:GoTop()
    oBrw:Refresh()

    return nil

//-----------------------------------------------------------------------------//
function PanelBox(nTop, nLeft, nBottom, nRight, nClrLite, nClrDark,oDlg)
  local oPanel,oBrush
  Local aGrad := { nClrLite,nClrDark}
  DEFINE BRUSH oBrush GRADIENT aGrad
     oPanel:=Tpanel():New( nTop, nLeft,nTop+nBottom, nRight, oDlg)
     oPanel:SetBrush( oBrush )
   *  oPanel:bPainted := { || oPanel:Box( 1,1,oPanel:nHeight-1,oPanel:nWidth-1 ) }
return oPanel
//-----------------------------------------------------------------------------//

  FUNCTION ActivateNextBox( oBox, l2Box, l3Box, l4Box, oDlgx )
     local nPanel
     IF l2Box
        IF l3Box
            IF l4Box
                // All boxes are already active, do nothing
            ELSE
                oBox[4]:Show()
                oDlgx := oBox[4]
                l4Box := .T.
                nPanel:= 4
            ENDIF
        ELSE
            oBox[3]:Show()
            oDlgx := oBox[3]
            l3Box := .T.
            nPanel:= 3
        ENDIF
    ELSE
        oBox[2]:Show()
        oDlgx := oBox[2]
        l2Box := .T.
        nPanel:= 2
    ENDIF
    RETURN nPanel
//--------------------------------------------------------------------------//

FUNCTION DeactivateBox( oBox, nIndex, l2Box, l3Box, l4Box, oDlgx )
    DO CASE
        CASE nIndex == 2
            IF l2Box
                oBox[2]:Hide()
                l2Box := .F.
                oDlgx := NIL

            ENDIF
        CASE nIndex == 3
            IF l3Box
                oBox[3]:Hide()
                l3Box := .F.
                oDlgx := NIL

            ENDIF
        CASE nIndex == 4
            IF l4Box
                oBox[4]:Hide()
                l4Box := .F.
                oDlgx := NIL

            ENDIF
    ENDCASE
RETURN NIL
//--------------------------------------------------------------------------//
// When a checkbox activates a panel, we add the mapping to our array
FUNCTION ActivatePanel(nCheckboxIndex, nPanelIndex)
   aCheckboxPanelMap[nCheckboxIndex] := nPanelIndex
RETURN NIL
//--------------------------------------------------------------------------//
// When we want to deactivate a panel, we use mapping to find the panel
FUNCTION DeactivatePanel(nCheckboxIndex, oBox)
   LOCAL nPanelIndex := aCheckboxPanelMap[nCheckboxIndex]
    IF nPanelIndex != NIL
        oBox[nPanelIndex]:Hide()
        aCheckboxPanelMap[nCheckboxIndex] := NIL
      *  adel(aCheckboxPanelMap,nCheckboxIndex,.t.)
        // Spostiamo gli altri pannelli
        AdjustPanelPosition(oBox)
    ENDIF
RETURN NIL
//--------------------------------------------------------------------------//
// Function to move the remaining panels when one is deactivated
FUNCTION AdjustPanelPosition(oBox)
    LOCAL nDesiredTop := 440
    LOCAL nPanelHeight := 30  // Height of the single panel
    LOCAL nCurrentTop := nDesiredTop
    local  nIndex

    // Calculate the number of active panels
    LOCAL nActivePanels := 0
    FOR nIndex := 2 TO LEN(oBox)
        IF !Empty(oBox[nIndex])
            nActivePanels++
        ENDIF
    NEXT

    // Calculate the new position of the active panels
    IF nActivePanels > 0
        nCurrentTop -= nPanelHeight * nActivePanels
    ENDIF

    FOR nIndex := 2 TO LEN(oBox)
        IF !Empty(oBox[nIndex])
            oBox[nIndex]:nTop := nCurrentTop
            nCurrentTop += nPanelHeight
        ENDIF
    NEXT
RETURN NIL
//--------------------------------------------------------------------------//

STATIC FUNCTION ResetFilter(aFilters, oDbf, oBox, oBrw, aState, nIndex)
    LOCAL cFilter := ""
    LOCAL af := {}
    LOCAL cState := SPACE(25)
    LOCAL lMarried := .F.
    LOCAL nAge := 0
    LOCAL oCmb, nState := 1
    LOCAL nRow := 8
    LOCAL oSay, oRadio, nRadio := 1, cMarried := ""
    LOCAL oDlgx
    LOCAL aAge := {"20", "40", "60"}
    LOCAL nBoxHeight := 30
    LOCAL nVisibleBoxHeight := 0
    LOCAL oCtrl
    LOCAL nPanel

    oDlgx := NIL

    xbrowser aCheckboxPanelMap

    IF aFilters[nIndex, 1]

        // We use ActivateNextBox to get the number of the activated panel
        nPanel := ActivateNextBox(oBox, @l2Box, @l3Box, @l4Box, @oDlgx)

        nVisibleBoxHeight := 30
        // We activate the panel corresponding to the checkbox
        ActivatePanel(nIndex, nPanel)

        // We hide the controls if they are there in oDlgx
        IF !Empty(oDlgx:acontrols)
            FOR EACH oCtrl IN oDlgx:acontrols
                oCtrl:hide()
            NEXT
        ENDIF



        DO CASE
        CASE nIndex == 1   // Age

                @ nRow, 5 SAY oSay PROMPT "Age:" SIZE 80, 20 PIXEL OF oDlgx;
                        COLOR CLR_BLACK, Rgb(250,250,245)
                    oSay:lTransparent := .T.
                    @ 0.4, 10 COMBOBOX oCmb VAR nAge ITEMS aAge;
                        SIZE 600, 90 OF oDlgx;
                        ON CHANGE (cFilter := 'AGE<' + LTrim(Str(nAge)),;
                                   aFilters[1, 2] := cFilter,;
                                   Refresh_Filter(oDbf, oBrw, @cFilter, aFilters))

                 CASE nIndex == 2   // State

                  @ nRow, 5 SAY oSay PROMPT "State:" SIZE 80, 20 PIXEL OF oDlgx;
                        COLOR CLR_BLACK, Rgb(250,250,245)
                    oSay:lTransparent := .T.
                    @ 0.4, 10 COMBOBOX oCmb VAR nState ITEMS ArrTranspose(aState)[2];
                        SIZE 600, 90 OF oDlgx;
                        ON CHANGE (cState := aState[nState][1],;
                                   cFilter := 'STATE=' + "'" + cState + "'",;
                                   aFilters[2, 2] := cFilter,;
                                   Refresh_Filter(oDbf, oBrw, @cFilter, aFilters))

                 CASE nIndex == 3   // Married

                 @ nRow, 5 SAY oSay PROMPT "Married:" SIZE 80, 20 PIXEL OF oDlgx;
                        COLOR CLR_BLACK, Rgb(250,250,245)
                    oSay:lTransparent := .T.
                    @ 1, 80 RADIO oRadio VAR nRadio OF oDlgx UPDATE SIZE 80, 25 PIXEL;
                        PROMPT "Married";
                        ON CHANGE (IF(nRadio == 1, cMarried := ".T.", cMarried := ".F."),;
                                   cFilter := 'MARRIED=' + cMarried,;
                                   aFilters[3, 2] := cFilter,;
                                   Refresh_Filter(oDbf, oBrw, @cFilter, aFilters))

                    @ 1, 400 RADIOITEM "Not Married" RADIOMENU oRadio;
                        OF oDlgx PIXEL SIZE 80, 20
            ENDCASE


    ELSE
        // We deactivate the panel corresponding to the checkbox
       DeactivateBox( oBox, nIndex, @l2Box, @l3Box, @l4Box, @oDlgx )
       DeactivatePanel(nIndex, oBox)
        nVisibleBoxHeight -= 30 // Let's remove the height of the deactivated panel
    ENDIF

    // Let's update the smaller browser size
    oBrw:nBottomMargin += nVisibleBoxHeight

    // Let's update the filter and browser
    AEVAL(aFilters, { |a| If(a[1], AAdd(af, a[2]), NIL) })
    cFilter := FW_ArrayAsList(af, " .AND. ")
    oDbf:SetFilter(cFilter)
    oDbf:GoTop()
    oBrw:Refresh()

    RETURN cFilter
//--------------------------------------------------------------------------//

 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: also for obrw nheight

Postby karinha » Fri May 17, 2024 1:15 pm

I like everything correct: How do I declare, NINDEX?

Me gusta todo correcto: ¿Cómo declaro, NINDEX?

Gracias, tks.

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

Re: also for obrw nheight

Postby Silvio.Falconi » Sat May 18, 2024 7:56 am

The procedure not run ok
At init run ok then when you reselect a checkbox It crash
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 28 guests

cron