xbrowse column nHeadBmpNo called too late

Post Reply
AntoninoP
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

xbrowse column nHeadBmpNo called too late

Post by AntoninoP »

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

     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

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

#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
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: xbrowse column nHeadBmpNo called too late

Post by nageswaragunupudi »

Please add this

Code: Select all | Expand

oBrwTipiDoc:aCols[1]:bOnChange := {|o|o:oBrw:RefreshHeaders()}
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: xbrowse column nHeadBmpNo called too late

Post by nageswaragunupudi »

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


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
Post Reply