TCBrowse: clicking on headers

Post Reply
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

TCBrowse: clicking on headers

Post by Enrico Maria Giordano »

In the following sample nothing happens when the headers are clicked. Why? How can I trap this event?

Code: Select all

#include "Fivewin.ch"
#include "Tcbrowse.ch"


FUNCTION MAIN()

    LOCAL oDlg, oBrw, oCol

    USE TEST

    DEFINE DIALOG oDlg SIZE 300, 300

    @ 0, 0 BROWSE oBrw

    ADD COLUMN TO oBrw;
               DATA TEST -> last;
               HEADER "LAST";
               COLOR CLR_RED, CLR_GREEN

    ADD COLUMN TO oBrw;
               DATA TEST -> first;
               HEADER "FIRST";
               COLOR CLR_RED, CLR_GREEN

    oBrw:lCellStyle = .T.

    oBrw:aActions = { { || MsgInfo( "Hello!" ) }, { || MsgInfo( "Hello!" ) } }

    ACTIVATE DIALOG oDlg;
             ON INIT oDlg:SetControl( oBrw );
             CENTER

    CLOSE

    RETURN NIL
EMG
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

As I expect you know, TCBrowse is a subclass of TWBrowse. aAction is eval'd in method lButtonDown in TWBrowse. In TCBrowse, the method has been completely rewritten and aAction is not used anywhere in the method. So, it looks like it will require a significant rewrite of this method to get actions working.

You might consider using TSBrowse instead. I does everything TCBrowse does and a lot more including header actions. You can get a copy at my website.

James
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

James Bott wrote:As I expect you know, TCBrowse is a subclass of TWBrowse. aAction is eval'd in method lButtonDown in TWBrowse. In TCBrowse, the method has been completely rewritten and aAction is not used anywhere in the method. So, it looks like it will require a significant rewrite of this method to get actions working.

You might consider using TSBrowse instead. I does everything TCBrowse does and a lot more including header actions. You can get a copy at my website.

James
Thank you but I would prefer to not use TSBrowse. Anyway, are you saying that TCBrowse doesn't offer header clicking actions? It would be weird as when the pointer moves over headers it becomes the hand icon and there would be no reason for this.

EMG
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: TCBrowse: clicking on headers

Post by Enrico Maria Giordano »

A partial fix could be (TCBrowse:LButtonDown() method):

Code: Select all

   if ::nLen < 1
      return nil
   endif
//EMG
   if nClickRow == 0 .and. Valtype(nKeyFlags) == "N"
      if ::aActions != nil .and. ;
         ( nAtCol := ::nAtCol( nColPix ) ) <= Len( ::aActions )
            if ::aActions[ nAtCol ] != nil
               Eval( ::aActions[ nAtCol ], Self, nRowPix, nColPix )
            else
               MsgBeep()
            endif
      else
         MsgBeep()
      endif
   endif
//EMG
   if nClickRow > 0 .and. nClickRow != ::nRowPos .and. ;
and comment out

Code: Select all

//   Super:LButtonDown( nRowPix, nColPix, nKeyFlags )

return 0
EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

I have implemented a quick fix this way:

Code: Select all

METHOD LButtonUp( nRowPix, nColPix, nFlags ) CLASS TCBrowse

   local nClickRow, nDestCol, nAtCol

   if ::lDrag
     if ::lColDrag
        ::lDrag := .f.
     else
        return Super:LButtonUp( nRowPix, nColPix, nFlags )
     endif
   endif

   if ::lCaptured
      ::lCaptured = .f.
      ReleaseCapture()
      if ::lLineDrag
        ::lLineDrag := .f.
        ::VertLine()
      else
        ::lColDrag := .f.
        nClickRow = nTCWRow( ::hWnd, ::hDC, nRowPix,;
                      If( ::oFont != nil, ::oFont:hFont, 0 ) )

        nDestCol := ::nAtCol(nColPix)
        // we gotta be on header row within listbox and not same colm
        if nClickRow == 0 .and. nColPix > ::nLeft .and. ;
           nColPix < ::nRight - 16 .and. ::nDragCol != nDestCol
             ::Exchange( ::nDragCol, nDestCol)
        else 
          if ::aActions != nil .and. ;
             ( nAtCol := ::nAtCol( nColPix ) ) <= Len( ::aActions )
             if ::aActions[ nAtCol ] != nil
                Eval( ::aActions[ nAtCol ], Self, nRowPix, nColPix )
             endif
          endif
        endif
      endif
   endif

   Super:LButtonUp( nRowPix, nColPix, nFlags )

return nil
regards, saludos

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

Post by Antonio Linares »

Enrico,

Please try fwh\samples\enrico.prg :)

Its working fine :)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Antonio Linares wrote:Enrico,

Please try fwh\samples\enrico.prg :)

Its working fine :)
Ok, but try this enrico2.prg:

Code: Select all

#include "Fivewin.ch" 
#include "Tcbrowse.ch" 


FUNCTION MAIN() 

    LOCAL oDlg, oBrw, oCol 

    USE Customer ALIAS Test 

    DEFINE DIALOG oDlg SIZE 300, 300 

    @ 0, 0 BROWSE oBrw 

    ADD COLUMN TO oBrw; 
               DATA TEST -> last; 
               HEADER "LAST"; 
               COLOR CLR_RED, CLR_GREEN 

    ADD COLUMN TO oBrw; 
               DATA TEST -> first; 
               HEADER "FIRST"; 
               COLOR CLR_RED, CLR_GREEN 

    oBrw:lCellStyle = .T. 
    oBrw:lMChange = .F.

    oBrw:aActions = { { || MsgInfo( "One!" ) }, { || MsgInfo( "Two!" ) } } 

    ACTIVATE DIALOG oDlg; 
             ON INIT oDlg:SetControl( oBrw ); 
             CENTER ;
             VALID MsgYesNo( "Want to exit ?" )

    CLOSE 

    RETURN NIL
:lol:

EMG
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Enrico,

This line is causing the problem:

oBrw:lMChange = .f.

but here you have a modified Class TCBrowse that works ok with your sample: http://hyperupload.com/download/a4efe52 ... e.prg.html :)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply