xbrowse column nHeadBmpNo called too late

xbrowse column nHeadBmpNo called too late

Postby AntoninoP » Wed May 05, 2021 6:07 am

Hello,
I am trying to do a xBrowse with a column with checkboxes and header with another check box to check/uncheck all. The code is pretty simple:
Code: Select all  Expand view
     REDEFINE XBROWSE oBrwTipiDoc ID 4009 STYLE 2015
      oBrwTipiDoc:nMarqueeStyle      := MARQSTYLE_HIGHLROW
      oBrwTipiDoc:lFastEdit := .T.
      ADD COLUMN TO oBrwTipiDoc ARRAY TITLE "" ELEMENT 1 EDITABLE
      ADD COLUMN TO oBrwTipiDoc ARRAY TITLE "" ELEMENT 2
      ADD COLUMN TO oBrwTipiDoc ARRAY TITLE "" ELEMENT 3
      with object oBrwTipiDoc:aCols[1]
         :SetCheck( GetCheckBoxes(oDlg), .t.)
         //:nEditType := EDIT_BUTTON
         //:bEditBlock := {|r,c,o,k| oBrwTipiDoc:aArrayData[oBrwTipiDoc:nRowSel,1] := !oBrwTipiDoc:aArrayData[oBrwTipiDoc:nRowSel,1] }
         //:bEditValue := {|r,c,o,k| oBrwTipiDoc:aArrayData[oBrwTipiDoc:nRowSel,1] := !oBrwTipiDoc:aArrayData[oBrwTipiDoc:nRowSel,1] }
         :nHeadBmpNo    := { || GetHeadBmpId(oBrwTipiDoc:aArrayData) }
      end
      oBrwTipiDoc:SetArray( {;
         {.T.,"OF","Ordine fornitore"},;
         {.T.,"SR","Scarti per rottira"},;
         {.T.,"SL","Scarti per lavorazione"};
      })
 

and the GetHeadBmpId is
Code: Select all  Expand view
func GetHeadBmpId(aArrayData)
   if aScan(aArrayData, {|x| !x[1] })==0
      return 1
   endif
   if aScan(aArrayData, {|x| x[1] })==0
      return 2
   endif
return 3

So if there are all checked shows 1-checked, it there are none checked shows 2-unchecked other cases shows 3-indefinite. My problem is that If I change a check box, with double click the header is not updated until the next render.
I did an example gif:
Image
Can I fix it?

PS. There is a possibility to check/uncheck with one click without select the row?
PPS. The GetCheckBoxes is the one I posted some time ago:
Code: Select all  Expand view
#define DFC_BUTTON 4
#define DFCS_BUTTONCHECK        0x0000
#define DFCS_CHECKED            0x0400
#define DFCS_INACTIVE           0x0100
#define BP_CHECKBOX 3
#define CBS_UNCHECKEDNORMAL 1
#define CBS_CHECKEDNORMAL 5
#define CBS_MIXEDNORMAL 9

function GetCheckBoxes(oWnd)
   LOCAL hDCMem, hBmpMem := {Nil,Nil,Nil},i, tmp
   LOCAL FCStates := {DFCS_BUTTONCHECK,nOr(DFCS_BUTTONCHECK,DFCS_CHECKED),nOr(DFCS_BUTTONCHECK,DFCS_INACTIVE)}
   LOCAL TMStates := {CBS_CHECKEDNORMAL,CBS_UNCHECKEDNORMAL,CBS_MIXEDNORMAL}
   LOCAL oTheme := 0
   if IsAppThemed()
      oTheme   = C5_OpenThemeData(oWnd:hWnd,"BUTTON")
   endif

   for i:=1 to 3
      hDCMem := CreateCompatibleDC( oWnd:GetDC() )
      hBmpMem[i] := CreateCompatibleBitmap( oWnd:GetDC(), 16, 16 )
      tmp := SelectObject( hDCMem, hBmpMem[i] )

      FillRect( hDCMem,{0,0,16,16}, GetStockObject( 0 ) )
      if oTheme != 0
         C5_DrawThemeBackground(oTheme, hDCMem, BP_CHECKBOX,TMStates[i],{1,1,15,15})
      else
         DrawFrameControl(hDCMem,{1,1,15,15}, DFC_BUTTON,FCStates[i])
      endif
      SelectObject( hDCMem, tmp )
      DeleteDC( hDCMem )
   next

   if oTheme!=0
      C5_CloseThemeData(oTheme)
   endif

return hBmpMem

PPPS: sorry for italian messages
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: xbrowse column nHeadBmpNo called too late

Postby nageswaragunupudi » Wed May 05, 2021 10:00 am

Please add this
Code: Select all  Expand view
oBrwTipiDoc:aCols[1]:bOnChange := {|o|o:oBrw:RefreshHeaders()}
 
Regards

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

Re: xbrowse column nHeadBmpNo called too late

Postby nageswaragunupudi » Wed May 05, 2021 10:08 am

Recommendations:
Please avoid using ADD COLUMN TO oBrw.
This syntax was created long time back only to help easy migration of already existing code from TCBrowse.
Also we better inform the xbrowse that the datasource is the array while creating the browse.

Recommended syntax:
Code: Select all  Expand view

aData := {;
         {.T.,"OF","Ordine fornitore"},;
         {.T.,"SR","Scarti per rottira"},;
         {.T.,"SL","Scarti per lavorazione"};
      }

REDEFINE XBROWSE oBrwTipiDoc ID 4009 STYLE 2015 ;
   DATASOURCE aData ; // Let xbrowse know that it is dealing with an array
   COLUMNS 1,2,3 ;
   HEADERS "", "", ""
 
Regards

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


Return to FiveWin for Harbour/xHarbour

Who is online

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