CLASS TGrid() for FiveWin

CLASS TGrid() for FiveWin

Postby Jimmy » Thu Oct 20, 2022 8:06 am

hi,
CLASS TGrid() for FiveWin

i have begin to made Class TGrid() which use Listview like Explorer

it use Style
Code: Select all  Expand view
#define LVS_ICON        0
#define LVS_REPORT      1
#define LVS_SMALLICON   2
#define LVS_LIST        3


Image

Image

Image

last Screenshot show can be used as "Preview Thumbnail"

will be continued ...
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Re: CLASS TGrid() for FiveWin

Postby Antonio Linares » Thu Oct 20, 2022 11:30 am

Dear Jimmy,

great work!

looking forward to test it, thank you so much!
regards, saludos

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

Re: CLASS TGrid() for FiveWin

Postby nageswaragunupudi » Thu Oct 20, 2022 3:24 pm

There is a lookalike TAlbum class of FiveWin in the sample \fwh\samples\album.prg.
This TAlbum class was not included in the main FWH library as it was not considered so important, but any user can take it from the samples folder and use it.

Image
Regards

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

Re: CLASS TGrid() for FiveWin

Postby Jimmy » Fri Oct 21, 2022 6:09 am

hi Antonio,
Antonio Linares wrote:looking forward to test it, thank you so much!

don´t expect too much ... i´m still a Fivewin and "C" Newbie

under Xbase++ i have use my "own" Listview Control so i know the Way
under HMG / MiniGUI Extended Version i saw how they use HB_FUNC() and Listview Macro instead of DllCall ( how under FiveWin ? ) and LVM_ Constant

now i try to use all Parts of Puzzle in CLASS TGrid()
... but still have some nasty Problem to fix before i can release CODE
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CLASS TGrid() for FiveWin

Postby Jimmy » Fri Oct 21, 2022 6:42 am

hi,
nageswaragunupudi wrote:There is a lookalike TAlbum class of FiveWin in the sample \fwh\samples\album.prg.

WOW impressive :D

...

Imagelist() is "limited" to 256 x 256 and normal used for Icon
but you "can" use it to load own Image and show it as Thumbnail when use Style LVS_ICON

Imagelist() is used by Explorer which i want to "simulate" in CLASS TGrid() to show how we can work with Listview
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CLASS TGrid() for FiveWin

Postby nageswaragunupudi » Fri Oct 21, 2022 7:45 am

The point I am trying to make is that with FWH's builtin capabilities we can do anything with images without any limitations.
Regards

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

Re: CLASS TGrid() for FiveWin

Postby Jimmy » Sat Oct 22, 2022 12:36 am

hi,

you know that Listview can handle 100 Million Element ... which other Control can handle so much :?:

as there is only 1 Sample using Listview-Group i think Fivewin User does not know what Listview can do and how fast i can be.

but i have to learn "C" for HB_FUNC() to use this
Code: Select all  Expand view
//This function is called when the list needs data. This is the most
//critical function when working with virtual lists.
void CVirtualListDlg::OnGetdispinfoList(NMHDR* pNMHDR, LRESULT* pResult)
{
    LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;

    //Create a pointer to the item
    LV_ITEM* pItem= &(pDispInfo)->item;

    //Which item number?
    int itemid = pItem->iItem;

    //Do the list need text information?
    if (pItem->mask & LVIF_TEXT)
    {
        CString text;

        //Which column?
        if(pItem->iSubItem == 0)
        {
            //Text is name
            text = m_database[itemid].m_name;
        }
        else if (pItem->iSubItem == 1)
        {
            //Text is slogan
            text = m_database[itemid].m_slogan;
        }

        //Copy the text to the LV_ITEM structure
        //Maximum number of characters is in pItem->cchTextMax
        lstrcpyn(pItem->pszText, text, pItem->cchTextMax);
    }

    //Do the list need image information?
    if( pItem->mask & LVIF_IMAGE)
    {
        //Set which image to use
        pItem->iImage=m_database[itemid].m_image;
       
        //Show check box?
        if(IsCheckBoxesVisible())
        {
            //To enable check box, we have to enable state mask...
            pItem->mask |= LVIF_STATE;
            pItem->stateMask = LVIS_STATEIMAGEMASK;

            if(m_database[itemid].m_checked)
            {
                //Turn check box on..
                pItem->state = INDEXTOSTATEIMAGEMASK(2);
            }
            else
            {
                //Turn check box off
                pItem->state = INDEXTOSTATEIMAGEMASK(1);
            }
        }
    }

    *pResult = 0;
}

as you can see there is "m_database" used but how do i get Array into HB_FUNC() :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CLASS TGrid() for FiveWin

Postby Antonio Linares » Sat Oct 22, 2022 6:00 am

Dear Jimmy,

Here you have an example
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local a := { 1, 2 }
   local aResult := ATest( a )

   MsgInfo( aResult[ 1 ] )
   MsgInfo( aResult[ 2 ] )

return nil

#pragma BEGINDUMP

#include <hbapi.h>

HB_FUNC( ATEST )
{
   int i1 = hb_parvnl( 1, 1 );  // first element in array
   int i2 = hb_parvnl( 1, 2 );  // second element in array

   hb_reta( 2 ); // we create and return an array with two elements
   hb_storvnl( 1, -1, i2 );  // we swap the values into the returned array
   hb_storvnl( 2, -1, i1 );  // -1 means the item that has been returned
}

#pragma ENDDUMP
regards, saludos

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

Re: CLASS TGrid() for FiveWin

Postby Jimmy » Sun Oct 23, 2022 10:51 am

hi Antonio ,
Antonio Linares wrote:Here you have an example

thx for Sample, i will study it
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CLASS TGrid() for FiveWin

Postby Jimmy » Sun Oct 23, 2022 11:01 am

hi,

i got it so far that i can show a working 32 Bit Demo

as i can not upload here in Fivewin Forum i have upload to Dropbox ... hope it work
https://www.dropbox.com/s/lub163c92lio5gx/TGRID01.zip?dl=0
download and save it as ZIP File

---

how to start :

Code: Select all  Expand view
PROCEDURE Main( cPath, cLangCode,cCodepage )
   DEFAULT cPath := hb_Dirbase()
   DEFAULT cLangCode := "DEWIN"
   DEFAULT cCodepage := "DEWIN"

change your Language and Codepage
you can use a different Start Folder for DIRECTORY()
Code: Select all  Expand view
  aDir := DIRECTORY( cPath + "*.*", "DHS" )


on MENU you can switch Listview Style

while it does load IMAGE it can take Time "to load" ... no Animation yet

---

like Explorer
DblClick or ENTER on Item will
Code: Select all  Expand view
  ShellExecute( oWnd:hWnd, "Open", cPath + cRet,,, SW_SHOW )

press CTRL + "Plus of Numpad" will "optimize" TGrid()
press a-z will "jump" to Item. press again for next

---

todo :
vertical Scrollbar does show Position but will not "nagivigate" to new Position
Animation when "load" are missing
CONFIG.INI

Roadmap :
64 Bit
HB_FUNC( DISPINFO )
TABPAGE
...
FW Commander
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CLASS TGrid() for FiveWin

Postby Jimmy » Mon Oct 24, 2022 1:16 am

Antonio Linares wrote:Here you have an example
Code: Select all  Expand view
#include "FiveWin.ch"
function Main()
   local a := { 1, 2 }
   local aResult := ATest( a )
   MsgInfo( aResult[ 1 ] )
   MsgInfo( aResult[ 2 ] )
return nil

#pragma BEGINDUMP
#include <hbapi.h>

HB_FUNC( ATEST )
{
   int i1 = hb_parvnl( 1, 1 );  // first element in array
   int i2 = hb_parvnl( 1, 2 );  // second element in array

   hb_reta( 2 ); // we create and return an array with two elements
   hb_storvnl( 1, -1, i2 );  // we swap the values into the returned array
   hb_storvnl( 2, -1, i1 );  // -1 means the item that has been returned
}

#pragma ENDDUMP

i have change
Code: Select all  Expand view
*     local a :=   {   1,   2   }

into
Code: Select all  Expand view
    local a :=   { "aaa", "bbb" }

and now i got NIL ... :(

so how use your Sample with Array and "String" like from DIRECTORY() :?:
need Help please
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CLASS TGrid() for FiveWin

Postby Jimmy » Mon Oct 24, 2022 9:26 am

hi,

CLASS TGrid() Source CODE with HB_FUNC()

this is 1st "basic" Sample how to use Listview.
Sample have 2 x CLASS
CLASS TExplorer FROM TGrid
CLASS TGrid FROM TControl


1st CLASS is Demo to use Explorer Style
2nd CLASS will be "general" for all Type and "other" CLASS

! Note : a lot HB_FUNCC() are not used in Sample yet, i will need them in Future

Comment Welcome

Code: Select all  Expand view
/*********************************************************************
ListView_GetItemCount               https://learn.microsoft.com/en-us/windo ... titemcount
ListView_InsertItem                 https://learn.microsoft.com/en-us/windo ... insertitem
ListView_SetItemText                https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-listview_setitemtext
ListView_InsertColumn               https://learn.microsoft.com/en-us/windo ... sertcolumn
ListView_GetExtendedListViewStyle   https://learn.microsoft.com/en-us/windo ... tviewstyle
ListView_SetExtendedListViewStyle   https://learn.microsoft.com/en-us/windo ... tviewstyle
ListView_DeleteColumn               https://learn.microsoft.com/en-us/windo ... letecolumn
ListView_EnsureVisible              https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-listview_ensurevisible
ListView_GetBkColor                 https://learn.microsoft.com/en-us/windo ... setbkcolor
ListView_GetCountPerPage            https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-listview_getcountperpage
ListView_GetItemState               https://learn.microsoft.com/en-us/windo ... titemstate
ListView_GetItem                    https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-listview_getitem
ListView_GetNextItem                https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-listview_getnextitem
ListView_GetSelectedCount           https://learn.microsoft.com/de-de/windo ... ectedcount
ListView_GetSelectionMark           https://learn.microsoft.com/en-us/windo ... ectionmark
ListView_GetTextColor               https://learn.microsoft.com/en-us/windo ... ttextcolor
ListView_GetTopIndex                https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-listview_gettopindex
ListView_GetSubItemRect             https://learn.microsoft.com/en-us/windo ... ubitemrect
ListView_GetItemRect                https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-listview_getitemrect
ListView_SubItemHitTest             https://learn.microsoft.com/en-us/windo ... temhittest
ListView_RedrawItems                https://learn.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-listview_redrawitems
ListView_Scroll                     https://learn.microsoft.com/en-us/windo ... iew_scroll
ListView_SetBkColor                 https://learn.microsoft.com/en-us/windo ... setbkcolor
ListView_SetItemCount               https://learn.microsoft.com/en-us/windo ... titemcount
ListView_SetItemState               https://learn.microsoft.com/en-us/windo ... titemstate
ListView_SetTextBkColor             https://learn.microsoft.com/en-us/windo ... extbkcolor
ListView_SetTextColor               https://learn.microsoft.com/en-us/windo ... ttextcolor
ListView_Update                     https://learn.microsoft.com/en-us/windo ... iew_update
*********************************************************************/


******************************** HB_FUNC()      ****************************

#pragma BEGINDUMP

#include <windows.h>
#include <commctrl.h>
#include <hbapi.h>

#define AVOID_COMPILER_WARNING   // by Dr. Claudio Soto (November 2013)

HB_FUNC( IMAGELIST_REMOVEALL )
{
   #ifndef _WIN64
   ImageList_RemoveAll( ( HIMAGELIST ) hb_parnl( 1 ) );
   #else
   ImageList_RemoveAll( ( HIMAGELIST ) hb_parnll( 1 ) );
   #endif
}

HB_FUNC( REDRAWWINDOW )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   RedrawWindow (hWnd, NULL , NULL , RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASENOW | RDW_UPDATENOW );
}

// LV_ADDITEMS ( hWnd, aItem, iImage, [nRow] )
HB_FUNC( LV_ADDITEMS )
{
   LV_ITEM lvi;
   WORD nColumnCount;
   int nCol, nRow;

   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   nColumnCount = ( WORD ) hb_parinfa (2, 0);

   if ( HB_ISNIL(4) )
      nRow = ListView_GetItemCount (hWnd);
   else
      nRow = hb_parni (4);

   lvi.mask       = LVIF_TEXT | LVIF_IMAGE;
   lvi.state      = 0;
   lvi.stateMask  = 0;
   lvi.iImage     = hb_parni (3);
   lvi.iSubItem   = 0;
   lvi.iItem      = nRow;
   lvi.pszText    = (TCHAR*) hb_parvc (2, 1);

   ListView_InsertItem (hWnd, &lvi);

   for (nCol = 1; nCol < nColumnCount; nCol++)
       ListView_SetItemText (hWnd, nRow, nCol, (TCHAR*) hb_parvc (2, nCol+1));

}

// LV_ADDCOLUMN( hWnd, nSubItem, nWeight, cText, nFMT (
HB_FUNC( LV_ADDCOLUMN )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   LV_COLUMN COL;

   COL.mask= LVCF_WIDTH | LVCF_TEXT | LVCF_FMT | LVCF_SUBITEM ;
   COL.cx= hb_parni(3);
   COL.pszText = (TCHAR*) hb_parc(4);
   COL.iSubItem=hb_parni(2)-1;
   COL.fmt = hb_parni(5) ;

   ListView_InsertColumn ( hWnd, hb_parni(2)-1, &COL );
}

// LV_ChangeExtendedStyle ( hWnd, [ nAddStyle ], [ nRemoveStyle ] )
HB_FUNC( LV_CHANGEEXTENDEDSTYLE )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   DWORD Add     = (DWORD) hb_parnl  (2);
   DWORD Remove  = (DWORD) hb_parnl  (3);
   DWORD OldStyle, NewStyle, Style;

   OldStyle = ListView_GetExtendedListViewStyle (hWnd);
   NewStyle = (OldStyle | Add) & ( ~Remove );
   Style = ListView_SetExtendedListViewStyle ( hWnd, NewStyle );
   hb_retnl ((LONG) Style);
}

HB_FUNC( LV_COLUMNEND )
{
   hb_xfree( ( void * ) hb_parptr( 1 ) );
}

HB_FUNC( LV_DELETECOLUMN )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   ListView_DeleteColumn ( hWnd, hb_parni(2)-1 );
}
// LV_ENSUREVISIBLE( hWnd, nItem, lPart)
HB_FUNC( LV_ENSUREVISIBLE)
{
   BOOL lEnablePartialView = HB_ISLOG (3) ? hb_parl (3) : TRUE;
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   ListView_EnsureVisible( hWnd, hb_parni(2)-1 , lEnablePartialView ) ;
}

HB_FUNC( LV_GETBKCOLOR )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   hb_retnl ( ListView_GetBkColor ( hWnd ) ) ;
}

HB_FUNC( LV_GETCOUNTPERPAGE )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   hb_retnl ( ListView_GetCountPerPage ( hWnd ) ) ;
}

HB_FUNC( LV_GETITEMSTATE )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   INT  nRow   = (INT)  hb_parni  (2);
   UINT uMask  = (UINT) hb_parni  (3);

   hb_retni ((INT) ListView_GetItemState ( hWnd, (nRow - 1), uMask ) );
}

// LV_GETITEMTEXT (ControlHandle, nRow, nCol)
HB_FUNC( LV_GETITEMTEXT )
{
   TCHAR buffer [1024] ;
   LV_ITEM lvi;

   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif

   lvi.mask = LVIF_TEXT | LVIF_IMAGE;
   lvi.state = 0;
   lvi.stateMask = 0;
   lvi.iItem = hb_parni( 2 ) - 1;
   lvi.iSubItem = hb_parni( 3 ) - 1; ;
   lvi.cchTextMax = 1022;
   lvi.pszText = buffer;
   buffer[ 0 ] = 0;
   buffer[ 1023 ] = 0;

   ListView_GetItem( hWnd, &lvi );

   hb_retc (lvi.pszText);
}

// LV_GETGRIDDISPINFOINDEX(nPtrNMHDR)
HB_FUNC( LV_GETGRIDDISPINFOINDEX )
{
   #ifndef _WIN64
   LPARAM lParam = (LPARAM) hb_parnl (1);
   #else
   LPARAM lParam = (LPARAM) hb_parnll (1);
   #endif

   LV_DISPINFO* pDispInfo = (LV_DISPINFO*) lParam;
   int iItem = pDispInfo->item.iItem;
   int iSubItem = pDispInfo->item.iSubItem;

   hb_reta( 2 );
   hb_storvni( iItem    + 1, -1, 1 );
   hb_storvni( iSubItem + 1, -1, 2 );
}
// LV_GETGRIDVKEY( nPtrNMHDR )
HB_FUNC( LV_GETGRIDVKEY )
{
   #ifndef _WIN64
      LPARAM lParam = (LPARAM) hb_parnl (1);
   #else
      LPARAM lParam = (LPARAM) hb_parnll (1);
   #endif
   LV_KEYDOWN * LVK = (LV_KEYDOWN *) lParam;
   hb_retni ( LVK->wVKey );
}


HB_FUNC( LV_GETNEXTITEM )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
// hb_retni( ListView_GetNextItem( hWnd, (int) (hb_parni(2)-1) , LVNI_ALL | LVNI_SELECTED ) + 1 );
   hb_retni( ListView_GetNextItem( hWnd, (int) (hb_parni(2)-1) , hb_parni(3) ) );
}

HB_FUNC( LV_GETSELECTEDCOUNT )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   hb_retni( ListView_GetSelectedCount(hWnd) );
}

HB_FUNC( LV_GETSELECTIONMARK )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   hb_retni( ListView_GetSelectionMark(hWnd) );
}

HB_FUNC( LV_GETTEXTCOLOR )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   hb_retnl ( ListView_GetTextColor ( hWnd ) ) ;
}

HB_FUNC( LV_GETTOPINDEX )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   hb_retnl ( ListView_GetTopIndex ( hWnd ) ) ;
}

HB_FUNC( LV_GETSUBITEMRECT )
{
   RECT Rect;
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   int  iItem    = (int)  hb_parni (2);   // Index of the subitem's parent item
   int  iSubItem = (int)  hb_parni (3);   // The one-based index of the subitem
   int  code     = (int)  LVIR_BOUNDS;    // A portion of the list-view subitem for which to retrieve the bounding rectangle information

   #ifdef AVOID_COMPILER_WARNING
      Rect.top  = iSubItem;
      Rect.left = code;
      SendMessage ( hWnd, LVM_GETSUBITEMRECT, (WPARAM) iItem, (LPARAM) &Rect );
   #else
      ListView_GetSubItemRect ( hWnd, iItem, iSubItem, code, &Rect ) ;
   #endif

   hb_reta( 4 );
   hb_storvni( Rect.top  , -1, 1 );
   hb_storvni( Rect.left  , -1, 2 );
   hb_storvni( Rect.right - Rect.left , -1, 3 );
   hb_storvni( Rect.bottom - Rect.top  , -1, 4 );
}


HB_FUNC( LV_GETITEMRECT )
{
   RECT Rect ;
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   int  i    = (int)  hb_parni (2);   // The index of the list-view item
   int  code = (int)  LVIR_LABEL;     // The portion of the list-view item from which to retrieve the bounding rectangle

   #ifdef AVOID_COMPILER_WARNING
      Rect.left = code;
      SendMessage ( hWnd, LVM_GETITEMRECT, (WPARAM) i, (LPARAM) &Rect );
   #else
      ListView_GetItemRect ( hWnd, i, &Rect, code );
   #endif

   hb_reta( 4 );
   hb_storvni( Rect.top  , -1, 1 );
   hb_storvni( Rect.left  , -1, 2 );
   hb_storvni( Rect.right - Rect.left , -1, 3 );
   hb_storvni( Rect.bottom - Rect.top  , -1, 4 );
}

HB_FUNC( LV_HIDEWINDOW )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   hb_retnl( ShowWindow(hWnd, SW_HIDE) );
}

HB_FUNC( LV_HITTEST )
{

   POINT point ;
   LVHITTESTINFO lvhti;

   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   point.y = hb_parni(2) ;
   point.x = hb_parni(3) ;

   lvhti.pt = point;

   ListView_SubItemHitTest ( hWnd, &lvhti ) ;

   if(lvhti.flags & LVHT_ONITEM)
   {
      hb_reta( 2 );
      hb_storvni( lvhti.iItem + 1 , -1, 1 );
      hb_storvni( lvhti.iSubItem + 1 , -1, 2 );
   }
   else
   {
      hb_reta( 2 );
      hb_storvni( 0 , -1, 1 );
      hb_storvni( 0 , -1, 2 );
   }
}

HB_FUNC( LV_INSERTCOLUMN )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif

   LV_COLUMN COL;

   COL.mask= LVCF_WIDTH | LVCF_TEXT | LVCF_FMT | LVCF_SUBITEM ;
   COL.cx= hb_parni(3);
   COL.pszText = (TCHAR*) hb_parc(4);
   COL.iSubItem=hb_parni(2)-1;
   COL.fmt = hb_parni(5) ;

   ListView_InsertColumn ( hWnd, hb_parni(2)-1, &COL );

}

HB_FUNC( LV_REDRAWITEMS )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   hb_retnl ( ListView_RedrawItems ( hWnd, hb_parni(2) , hb_parni(3) ) ) ;
}

// LV_Scroll ( hWnd, nDx, nDy )
HB_FUNC( LV_SCROLL )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   ListView_Scroll( hWnd, hb_parni(2), hb_parni(3) ) ;
}

HB_FUNC( LV_SETBKCOLOR )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   ListView_SetBkColor ( hWnd, (COLORREF) RGB(hb_parni(2), hb_parni(3), hb_parni(4)) ) ;
}
//  LV_SETITEMCOUNT( hWnd, nMax )
HB_FUNC( LV_SETITEMCOUNT )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif

   ListView_SetItemCount ( hWnd , hb_parni (2) );
}

// LV_SETITEMSELECT( hWnd, nPosi )
HB_FUNC( LV_SETITEMSELECT )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif

   ListView_EnsureVisible( hWnd, hb_parnl( 2 ) -1, FALSE );
   ListView_SetItemState( hWnd, -1, 0, LVIS_SELECTED );
   ListView_SetItemState( hWnd, hb_parnl( 2 ) -1, ( LVIS_SELECTED | LVIS_FOCUSED ),
                          ( LVIS_SELECTED | LVIS_FOCUSED ) );
}

HB_FUNC( LV_SETITEMSTATE)
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
// ListView_SetItemState( hWnd, (int) (hb_parni(2)-1) , LVIS_FOCUSED | LVIS_SELECTED , LVIS_FOCUSED | LVIS_SELECTED );
   ListView_SetItemState( hWnd, (int) (hb_parni(2)-1) , hb_parni(3) , hb_parni(4) );
// ListView_SetItemState( hWnd, (int) (hb_parni(2)-1) , hb_parni(3) , LVIS_FOCUSED | LVIS_SELECTED );
}

HB_FUNC( LV_SETTEXTBKCOLOR )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   ListView_SetTextBkColor ( hWnd, (COLORREF) RGB(hb_parni(2), hb_parni(3), hb_parni(4)) ) ;
}

HB_FUNC( LV_SETTEXTCOLOR )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   ListView_SetTextColor ( hWnd, (COLORREF) RGB(hb_parni(2), hb_parni(3), hb_parni(4)) ) ;
}

// LV_SetItemText (hWnd, aItem, nRow)
HB_FUNC( LV_SETITEMTEXT )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   WORD nLen = ( WORD ) hb_parinfa (2, 0);
   int  nRow = hb_parni (3) - 1;
   TCHAR *cText;
   int nCol;

   for (nCol=0 ; nCol < nLen ; nCol++ )
   {
      cText = (TCHAR*) hb_parvc (2 , nCol + 1);
      ListView_SetItemText (hWnd, nRow, nCol, cText);
   }
}

HB_FUNC( LV_SHOWWINDOW )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   hb_retnl( ShowWindow(hWnd, SW_SHOW) );
}

HB_FUNC( LV_UPDATE )
{
   #ifndef _WIN64
      HWND hWnd = ( HWND ) hb_parnl( 1 );
   #else
      HWND hWnd = ( HWND ) hb_parnll( 1 );
   #endif
   hb_retnl( ListView_Update ( hWnd, hb_parni(2) - 1 ) );
}

#pragma ENDDUMP
 

Code: Select all  Expand view
*+--------------------------------------------------------------------
*+
*+ Source Module => c:\fwh\0\Listview\TGRID.PRG
*+
*+    Copyright(C) 1983-2022 by Auge & Ohr
*+
*+    Functions: Procedure Main()
*+               Static Function BUILDMENU()
*+               Static Procedure DoResize()
*+               Procedure SayBar()
*+               Function VAR2CHAR()
*+               Function onDummy()
*+               Class TExplorer
*+               Class TGrid
*+
*+    Reformatted by Click! 2.05.40 on Oct-24-2022 at 10:29 am
*+
*+--------------------------------------------------------------------

#include "FiveWin.ch"
#include "Constant.ch"
#include "Directry.ch"
#include "COMMON.CH"

#include "TGRID.CH"

#define COLOR_WINDOW          5
#define COLOR_WINDOWTEXT      8
#define COLOR_BTNFACE         15
#define COLOR_BTNSHADOW       16
#define COLOR_BTNHIGHLIGHT    20

#define ID_HEADER             1
#define ID_WIDTH              2
#define ID_ALIGN              3
#define ID_TYPE               4

#define SW_SHOW               5

#define isworking

/********************************************
*
* use your HB_LANG_* and HB_CODEPAGE_*
*
********************************************/


REQUEST HB_LANG_ES
REQUEST HB_LANG_EN
REQUEST HB_LANG_FR
REQUEST HB_LANG_PT
REQUEST HB_LANG_DEWIN
REQUEST HB_LANG_RUWIN
REQUEST HB_LANG_IT
REQUEST HB_LANG_PLWIN
REQUEST HB_LANG_EU
REQUEST HB_LANG_HR852
REQUEST HB_LANG_SLWIN
REQUEST HB_LANG_CSWIN

REQUEST HB_CODEPAGE_BG866
REQUEST HB_CODEPAGE_BGISO
REQUEST HB_CODEPAGE_BGMIK
REQUEST HB_CODEPAGE_BGWIN
REQUEST HB_CODEPAGE_CS852
REQUEST HB_CODEPAGE_CS852C
REQUEST HB_CODEPAGE_CSISO
REQUEST HB_CODEPAGE_CSKAMC
REQUEST HB_CODEPAGE_CSWIN
REQUEST HB_CODEPAGE_DE850
REQUEST HB_CODEPAGE_DE850M
REQUEST HB_CODEPAGE_DEISO
REQUEST HB_CODEPAGE_DEWIN
REQUEST HB_CODEPAGE_DK865
REQUEST HB_CODEPAGE_EL437
REQUEST HB_CODEPAGE_EL737
REQUEST HB_CODEPAGE_ELISO
REQUEST HB_CODEPAGE_ELWIN
REQUEST HB_CODEPAGE_EN
REQUEST HB_CODEPAGE_ES850
REQUEST HB_CODEPAGE_ES850C
REQUEST HB_CODEPAGE_ES850M
REQUEST HB_CODEPAGE_ESISO
REQUEST HB_CODEPAGE_ESMWIN
REQUEST HB_CODEPAGE_ESWIN
REQUEST HB_CODEPAGE_FI850
REQUEST HB_CODEPAGE_FR850
REQUEST HB_CODEPAGE_FR850C
REQUEST HB_CODEPAGE_FR850M
REQUEST HB_CODEPAGE_FRISO
REQUEST HB_CODEPAGE_FRWIN
REQUEST HB_CODEPAGE_HE862
REQUEST HB_CODEPAGE_HEWIN
REQUEST HB_CODEPAGE_HR646
REQUEST HB_CODEPAGE_HR852
REQUEST HB_CODEPAGE_HRISO
REQUEST HB_CODEPAGE_HRWIN
REQUEST HB_CODEPAGE_HU852
REQUEST HB_CODEPAGE_HU852C
REQUEST HB_CODEPAGE_HUISO
REQUEST HB_CODEPAGE_HUWIN
REQUEST HB_CODEPAGE_IS850
REQUEST HB_CODEPAGE_IS861
REQUEST HB_CODEPAGE_IT437
REQUEST HB_CODEPAGE_IT850
REQUEST HB_CODEPAGE_IT850M
REQUEST HB_CODEPAGE_ITISB
REQUEST HB_CODEPAGE_ITISO
REQUEST HB_CODEPAGE_ITWIN
REQUEST HB_CODEPAGE_LT775
REQUEST HB_CODEPAGE_LTWIN
REQUEST HB_CODEPAGE_NL850
REQUEST HB_CODEPAGE_NL850M
REQUEST HB_CODEPAGE_NO865
REQUEST HB_CODEPAGE_PL852
REQUEST HB_CODEPAGE_PLISO
REQUEST HB_CODEPAGE_PLMAZ
REQUEST HB_CODEPAGE_PLWIN
REQUEST HB_CODEPAGE_PT850
REQUEST HB_CODEPAGE_PT860
REQUEST HB_CODEPAGE_PTISO
REQUEST HB_CODEPAGE_RO852
REQUEST HB_CODEPAGE_ROISO
REQUEST HB_CODEPAGE_ROWIN
REQUEST HB_CODEPAGE_RU1251
REQUEST HB_CODEPAGE_RU866
REQUEST HB_CODEPAGE_RUISO
REQUEST HB_CODEPAGE_RUKOI8
REQUEST HB_CODEPAGE_SK852
REQUEST HB_CODEPAGE_SK852C
REQUEST HB_CODEPAGE_SKISO
REQUEST HB_CODEPAGE_SKKAMC
REQUEST HB_CODEPAGE_SKWIN
REQUEST HB_CODEPAGE_SL646
REQUEST HB_CODEPAGE_SL852
REQUEST HB_CODEPAGE_SLISO
REQUEST HB_CODEPAGE_SLWIN
REQUEST HB_CODEPAGE_SR646
REQUEST HB_CODEPAGE_SR646C
REQUEST HB_CODEPAGE_SRWIN
REQUEST HB_CODEPAGE_SV437C
REQUEST HB_CODEPAGE_SV850
REQUEST HB_CODEPAGE_SV850M
REQUEST HB_CODEPAGE_SVISO
REQUEST HB_CODEPAGE_SVWIN
REQUEST HB_CODEPAGE_TR857
REQUEST HB_CODEPAGE_TRISO
REQUEST HB_CODEPAGE_TRWIN
REQUEST HB_CODEPAGE_UA1125
REQUEST HB_CODEPAGE_UA1251
REQUEST HB_CODEPAGE_UA866
REQUEST HB_CODEPAGE_UAKOI8
REQUEST HB_CODEPAGE_UTF16LE
REQUEST HB_CODEPAGE_UTF8
REQUEST HB_CODEPAGE_UTF8EX

STATIC lDebug   := .T.
STATIC cVersion := "v0.1.25"

// **********************************************************************
//
//  24.10.2022 v0.1.25 1st Release
//
// **********************************************************************

MEMVAR oWnd, oExplorer, oStatusBar

*+--------------------------------------------------------------------
*+
*+    Procedure Main()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE Main( cPath, cLangCode, cCodepage )

LOCAL oFont
LOCAL nHeight   := 1024
LOCAL nWidth    := 1280
LOCAL nTop      := 0
LOCAL nLeft     := 0
LOCAL nIcoLarge := 256
LOCAL nIcoSmall := 32
LOCAL cLog      := cFileSetExt( ExeName(), "LOG" )

PRIVATE oWnd
PRIVATE oExplorer
PRIVATE oStatusBar

   DEFAULT cPath := hb_Dirbase()
   DEFAULT cLangCode := "DEWIN"
   DEFAULT cCodepage := "DEWIN"

   FW_SetUnicode( .T. )                                               // is this need ?
   hb_LangSelect( cLangCode )
   hb_CDPSELECT( cCodepage )

   FWLOG TIME(), "Start"
   SET DATE GERMAN

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0, - 200
#IFDEF __HMG__
   END FONT
#ENDIF

   DEFINE WINDOW oWnd FROM nTop, nLeft TO nHeight, nWidth PIXEL TITLE "FiveWin TGrid Listview Demo " + cVersion ICON "A1MAIN" MENU BuildMenu()

      oExplorer := TExplorer() :New( oWnd, nTop, nLeft, nWidth - 20, nHeight - 20, cPath, nIcoLarge, nIcoSmall )

      DEFINE STATUSBAR oStatusBar PROMPT "Hello World " OF oWnd SIZES nWidth - 100 CLOCK
         // oStatusBar:SetPartText( 1, "Hello Statusbar" )
         // oStatusBar:ClockOn()

#IFDEF __HMG__
      END STATUSBAR
   END WINDOW
#ENDIF

   ACTIVATE WINDOW oWnd ON RESIZE DoResize( oWnd, oExplorer ) CENTER

   FWLOG TIME(), "Ende"
   //    WinExec( "notepad.exe " + cLog )

   IF !EMPTY( oFont )
      oFont:End()
   ENDIF
   IF !EMPTY( oExplorer )
      oExplorer:Destroy()
   ENDIF
   IF !EMPTY( oStatusBar )
      oStatusBar:End()
   ENDIF
   IF !EMPTY( oWnd )
      oWnd:End()
   ENDIF

RETURN

*+--------------------------------------------------------------------
*+
*+    Static Function BUILDMENU()
*+
*+    Called from ( tgrid.prg )   1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
STATIC FUNCTION BUILDMENU()

LOCAL oMenu

   MENU oMenu

   MENUITEM "ICON     " ACTION oExplorer:oGrid:SetViewStyle( LVS_ICON )
   MENUITEM "SMALLICON" ACTION oExplorer:oGrid:SetViewStyle( LVS_SMALLICON )
   MENUITEM "LIST     " ACTION oExplorer:oGrid:SetViewStyle( LVS_LIST )
   MENUITEM "REPORT   " ACTION oExplorer:oGrid:SetViewStyle( LVS_REPORT )

   ENDMENU

RETURN oMenu

*+--------------------------------------------------------------------
*+
*+    Static Procedure DoResize()
*+
*+    Called from ( tgrid.prg )   1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE DoResize( oWnd, oExplorer )

LOCAL nHeight := oWnd:nHeight
LOCAL nWidth  := oWnd:nWidth

   oExplorer:oGrid:SetSize( nWidth - 20, nHeight - 80 )

RETURN

*+--------------------------------------------------------------------
*+
*+    Procedure SayBar()
*+
*+    Called from ( tgrid.prg )   1 - class texplorer
*+
*+--------------------------------------------------------------------
*+
PROCEDURE SayBar( cText, nPart )

   DEFAULT nPart := 1
   // how does Statusbar work ?
   //
   //   oStatusBar:SetPartText( nPart, cText )
   //   oStatusBar:SetMsg( cText )
   //   oWnd:SetMsg( cText )
RETURN

*+--------------------------------------------------------------------
*+
*+    Function VAR2CHAR()
*+
*+    Called from ( tgrid.prg )   2 - function ondummy()
*+                                   6 - class tgrid
*+
*+--------------------------------------------------------------------
*+
FUNCTION VAR2CHAR( cIn )

LOCAL cOut := hb_valToExp( cIn )
RETURN STRTRAN( cOut, '"', '' )

*+--------------------------------------------------------------------
*+
*+    Function onDummy()
*+
*+--------------------------------------------------------------------
*+
FUNCTION onDummy()

LOCAL iMax   := PCOUNT()
LOCAL i
LOCAL cText  := ""
LOCAL xValue

   IF lDebug = .T.
      FOR i := 1 TO iMax - 1
         cText += Var2Char( PValue( i ) ) + CHR( 9 )
      NEXT
      cText += Var2Char( PValue( iMax ) )

      IF EMPTY( cText )
         cText := TIME() + " no Parameter ? " + CRLF + PROCNAME( 1 ) + STR( PROCLINE( 1 ) ) + CRLF + PROCNAME( 2 ) + STR( PROCLINE( 2 ) )
      ENDIF

      // Fivewin Logfile
      FWLOG cText
   ENDIF

RETURN NIL

// ******************************* CLASS TExplorer    ****************************

*+--------------------------------------------------------------------
*+
*+    Class TExplorer
*+
*+--------------------------------------------------------------------
*+
CLASS TExplorer FROM TGrid

   DATA oGrid

   METHOD New( oWnd, nTop, nLeft, nWidth, nHeight, cPath, nIcoLarge, nIcoSmall ) CONSTRUCTOR
   METHOD DoGetItem( nRow )
   METHOD DoLastFolder( cLastPath )
   METHOD DoNextFolder( cPath )
   METHOD SetStyle( nView )
   METHOD FillGrid()
   METHOD DoSayItem( nItem )

ENDCLASS

METHOD New( oWnd, nTop, nLeft, nWidth, nHeight, cPath, nIcoLarge, nIcoSmall ) CLASS TExplorer

LOCAL nClrFore := GetSysColor( COLOR_WINDOWTEXT )
LOCAL nClrBack := GetSysColor( COLOR_WINDOW )
LOCAL lPixel   := .F.
LOCAL lDesign  := .F.
LOCAL cMsg     := "hello Fivewin"
LOCAL bAction  := nil
LOCAL aHeader  := {}
LOCAL aDir

   DEFAULT nIcoLarge := 32
   DEFAULT nIcoSmall := 16

   AADD( aHeader, { "Name", 200, LVCFMT_LEFT, "C" } )
   AADD( aHeader, { "Size", 150, LVCFMT_RIGHT, "N" } )
   AADD( aHeader, { "Date", 090, LVCFMT_RIGHT, "D" } )
   AADD( aHeader, { "Time", 090, LVCFMT_RIGHT, "C" } )
   AADD( aHeader, { "Attr", 050, LVCFMT_LEFT, "C" } )

   ::oGrid := TGrid() :New( nTop, nLeft, bAction, oWnd, nClrFore, ;
                      nClrBack, lPixel, lDesign, nWidth, nHeight, cMsg, nIcoLarge, nIcoSmall )

   ::oGrid:aHeader := aHeader

   aDir := DIRECTORY( cPath + "*.*", "DHS" )
   // remove "."
   ADEL( aDir, 1 )
   ASIZE( aDir, LEN( aDir ) - 1 )

   ::oGrid:cPath := cPath
   ::oGrid:aSource := aDir

   ::oGrid:InitTheListView()
   ::oGrid:bClick := { | nItem | ::DoGetItem( nItem ) }
   ::oGrid:bAction := { | nItem | ::DoSayItem( nItem ) }

   ::FillGrid()

RETURN Self

METHOD DoSayItem( nRow ) CLASS TExplorer

LOCAL cRet  := ""
LOCAL hWnd  := ::oGrid:hWnd
LOCAL nCol  := 1                                                      // only F_NAME
LOCAL cPath := ::oGrid:cPath

   cRet := LV_GETITEMTEXT( hWnd, nRow, nCol )

   // how does Statusbar work ?
   //
   ::oGrid:cMsg := cPath + cRet


RETURN cRet

METHOD DoGetItem( nRow ) CLASS TExplorer

LOCAL cRet    := ""
LOCAL hWnd    := ::oGrid:hWnd
LOCAL nCol    := 1                                                    // only F_NAME
LOCAL cPath   := ::oGrid:cPath
LOCAL aSource := ::oGrid:aSource
LOCAL nPosi, cAttr

   // when using LVN_GETDISPINFO you NEED Source Array
   // cRet := ::oGrid:aSource[nRow][nCol]

   cRet := LV_GETITEMTEXT( hWnd, nRow, nCol )

   nPosi := ASCAN( aSource, { | x | x[ F_NAME ] = TRIM( cRet ) } )
   IF nPosi > 0
      cAttr := aSource[ nPosi ] [ F_ATTR ]

      DO CASE
         CASE TRIM( cRet ) = ".."
            ::DoLastFolder( TRIM( cPath ) )
         CASE TRIM( cRet ) = "."
         OTHERWISE
            IF "D" $ cAttr
               ::DoNextFolder( TRIM( cPath + cRet ) )
            ELSE
               // MsgInfo( cPath + cRet )
               ShellExecute( oWnd:hWnd, "Open", cPath + cRet,,, SW_SHOW )
            ENDIF
      ENDCASE
   ELSE
      MsgInfo( cRet + " not found in Folder " + cPath )
   ENDIF

RETURN cRet

METHOD DoLastFolder( cLastPath ) CLASS TExplorer

LOCAL cPath
LOCAL nPosi
LOCAL aToken
LOCAL cFolder

   nPosi := hb_RAt( "\", cLastPath, 1, LEN( cLastPath ) - 1 )
   IF nPosi > 0

      cPath := SUBSTR( cLastPath, 1, nPosi - 1 )
      cFolder := SUBSTR( cLastPath, nPosi )
      cFolder := TRIM( STRTRAN( cFolder, "
\", "" ) )

      ::DoNextFolder( cPath, cFolder )
   ENDIF
RETURN nil

METHOD DoNextFolder( cPath, cFolder ) CLASS TExplorer

LOCAL cRet  := "
"
LOCAL aDir
LOCAL nPosi, nMax

   DEFAULT cFolder := "
"

   aDir := DIRECTORY( cPath + "
\*.*", "DHS" )
   // remove "
."
   ADEL( aDir, 1 )
   ASIZE( aDir, LEN( aDir ) - 1 )

   ::oGrid:cPath := cPath + "
\"
   ::oGrid:aSource := aDir

   ::FillGrid()

   nMax := LEN( ::aSource )
   // need for LVS_OWNERDATA / ::OnDISPINFO()
   LV_SETITEMCOUNT( ::hLv, nMax )

   IF !EMPTY( cFolder )
      nPosi := ASCAN( aDir, { | e | LOWER( e[ F_NAME ] ) = LOWER( cFolder ) } )
      IF nPosi > 0
         LV_SETITEMSELECT( ::oGrid:hLv, nPosi )
      ELSE
         msginfo( "
not found Folder " + cFolder )
      ENDIF
   ENDIF
RETURN cRet

METHOD SetStyle( nView ) CLASS TExplorer

   DEFAULT nView := LVS_REPORT

   DO CASE
      CASE nView = LVS_ICON
         ::oGrid:SetViewStyle( LVS_ICON )
      CASE nView = LVS_SMALLICON
         ::oGrid:SetViewStyle( LVS_SMALLICON )
      CASE nView = LVS_LIST
         ::oGrid:SetViewStyle( LVS_LIST )
      CASE nView = LVS_REPORT
         ::oGrid:SetViewStyle( LVS_REPORT )
   ENDCASE
RETURN self

METHOD FillGrid() CLASS TExplorer

LOCAL ii, nMax, aItem, iImage, iImage_0, cFile, hBitMap, aBitmaps, cExt

   LV_HIDEWINDOW( ::oGrid:hLv )

   SendMessage( ::oGrid:hLv, LVM_DELETEALLITEMS, 0, 0 )
   ImageList_RemoveAll( ::oGrid:oImageListSmall )
   ImageList_RemoveAll( ::oGrid:oImageListBig )

   nMax := LEN( ::oGrid:aSource )
   // slow Way i a loop
   FOR ii := 1 TO nmax
      aItem := { ::oGrid:aSource[ ii ] [ F_NAME ], STR( ::oGrid:aSource[ ii ] [ F_SIZE ] ), DTOC( ::oGrid:aSource[ ii ] [ F_DATE ] ), ::oGrid:aSource[ ii ] [ F_TIME ], ::oGrid:aSource[ ii ] [ F_ATTR ] }

      cFile := ::oGrid:aSource[ ii ] [ F_NAME ]

      SayBar( cFile )
      // ::oGrid:cMsg := cFile
      SysRefresh()

      cExt := UPPER( cFileExt( cFile ) )

      IF cExt $ "
BMP,JPG,PNG,GIF,ICO,CUR,DLL,JPEG,TIF,TIFF,EMF,WMF"

         // ******** small Icon ********
         // make it +10 Pixel bigger while RESIZEBMP() do NOT change Aspect Ratio
#IFDEF isworking
         aBitmaps := ::oGrid:oWnd:ReadImage( ::oGrid:cPath + cFile, { ::oGrid:nIcoSmall + 10, ::oGrid:nIcoSmall + 10 } )
         iImage_0 := aBitmaps[ 1 ]
#ELSE
         // return HIMAGELIST
         iImage_0 := ::oGrid:oImageListSmall:ReadBitmap( ::oGrid:cPath + cFile, ::oGrid:nIcoSmall + 10, 10 )
#ENDIF
         // change Aspect Ratio while else might not display
         iImage_0 := RESIZEBMP( iImage_0, ::oGrid:nIcoSmall, ::oGrid:nIcoSmall, .T. )

         ILADD( ::oGrid:oImageListSmall:hImageList, iImage_0 )
         PalBmpFree(aBitmaps)

         // ******** big Icon **********

#IFDEF isworking
         aBitmaps := ::oGrid:oWnd:ReadImage( ::oGrid:cPath + cFile, { ::oGrid:nIcoLarge + ::oGrid:nIcoSmall, ::oGrid:nIcoLarge + ::oGrid:nIcoSmall } )
         iImage := aBitmaps[ 1 ]
#ELSE
         // return HIMAGELIST
         iImage := ::oGrid:oImageListBig:ReadBitmap( ::oGrid:cPath + cFile, ::oGrid:nIcoLarge + ::oGrid:nIcoSmall, 10 )
#ENDIF
         // change Aspect Ratio while else might not display
         iImage := RESIZEBMP( iImage, ::oGrid:nIcoLarge, ::oGrid:nIcoLarge, .T. )

         iImage := MAX( 0, ILADD( ::oGrid:oImageListBig:hImageList, iImage ) )
         PalBmpFree(aBitmaps)

      ELSE
         // search for System Icon
         iImage := Icon_Read( cFile )

         ILADDICON( ::oGrid:oImageListSmall:hImageList, iImage )
         iImage := MAX( 0, ILADDICON( ::oGrid:oImageListBig:hImageList, iImage ) )
      ENDIF

      LV_ADDITEMS( ::oGrid:hLv, aItem, iImage )
   NEXT
   LV_SHOWWINDOW( ::oGrid:hLv )

   // SayBar("
")
   // ::oGrid:cMsg := "
"

   ::oGrid:RefreshAll()

   LV_SETITEMSTATE( ::oGrid:hLv, 1, nOr( LVIS_FOCUSED, LVIS_SELECTED ), nOr( LVIS_SELECTED, LVIS_FOCUSED ) )
   LV_ENSUREVISIBLE( ::oGrid:hLv, 1 )

RETURN self

// ******************************* CLASS TGrid    ****************************

*+--------------------------------------------------------------------
*+
*+    Class TGrid
*+
*+--------------------------------------------------------------------
*+
CLASS TGrid FROM TControl

   CLASSDATA aProperties INIT { "
nAlign", "nClrText", "nClrPane", "nOption", ;
                                "
nTop", "nLeft", "nWidth", "nHeight", "Cargo" }

   DATA aItems INIT {}
   DATA aGroups INIT {}
   DATA bAction, bDisplay
   DATA bClick
   DATA nOption
   DATA nGroups INIT 0

   DATA aSource INIT {}
   DATA aHeader INIT {}
   DATA oLVCol
   DATA oLVItem
   DATA aEvents INIT {}
   DATA bOnEvent
   DATA view
   DATA hLv
   DATA oImageListBig, oImageListSmall
   DATA hFont
   DATA cPath
   DATA nIcoLarge INIT 32
   DATA nIcoSmall INIT 16

   METHOD New( nTop, nLeft, bAction, oWnd, nClrFore, ;
               nClrBack, lPixel, lDesign, nWidth, nHeight, ;
               cMsg, nIcoLarge, nIcoSmall ) CONSTRUCTOR
   METHOD ReDefine( nId, oWnd, bAction ) CONSTRUCTOR
   METHOD Notify( nIdCtrl, nPtrNMHDR )
   METHOD OnEvent( nEvent, aParams, pParams )
   METHOD SetImageList( oImageList, nType )
   METHOD InitTheListView()

   METHOD Destroy()

   METHOD OnDISPINFO()
   METHOD SetViewStyle()
   METHOD HandleEvent( nMsg, nWParam, nLParam )
   METHOD RefreshAll()
   METHOD RefreshCurrent( nRec )
   METHOD UnMarkAll( lAll )

ENDCLASS

METHOD New( nTop, nLeft, bAction, oWnd, nClrFore, ;
               nClrBack, lPixel, lDesign, nWidth, nHeight, cMsg, nIcoLarge, nIcoSmall ) CLASS TGrid

   DEFAULT nTop := 0, nLeft := 0, ;
           oWnd := GetWndDefault(), ;
           nClrFore := oWnd:nClrText, ;
           nClrBack := GetSysColor( COLOR_BTNFACE ), ;
           lPixel := .f., ;
           lDesign := .f., ;
           nWidth := 200, nHeight := 21, ;
           nIcoLarge := 32, nIcoSmall := 16

   ::view := LVS_REPORT
   ::nStyle := nOR( LVS_SHAREIMAGELISTS, WS_CHILD, WS_VISIBLE, IF( lDesign, WS_CLIPSIBLINGS, 0 ), WS_TABSTOP, WS_BORDER, LVS_SHOWSELALWAYS, LVS_AUTOARRANGE , LVS_SINGLESEL, ::view )
   // LVS_OWNERDATA

   ::nId := ::GetNewId()
   ::oWnd := oWnd
   ::bAction := bAction
   ::cMsg := cMsg
   ::nTop := IF( lPixel, nTop, nTop * SAY_CHARPIX_H )
   ::nLeft := IF( lPixel, nLeft, nLeft * SAY_CHARPIX_W )
   ::nBottom := ::nTop + nHeight - 1
   ::nRight := ::nLeft + nWidth - 1
   ::lDrag := lDesign
   ::lCaptured := .f.
   ::oFont := TFont() :New( "
Ms Sans Serif", 0, - 20 )
   ::nClrText := nClrFore
   ::nClrPane := nClrBack
   ::nOption := 1

   ::bDisplay := { | nPtrNMHDR | ::OnDISPINFO( nPtrNMHDR ) }

   ::cPath := hb_Dirbase()

   IF !EMPTY( oWnd:hWnd )
      ::Create( CTRL_CLASS )
      oWnd:AddControl( Self )
   ELSE
      oWnd:DefControl( Self )
   ENDIF

   //    ::Default() ???

   IF lDesign                                                         // what is this ?
      ::CheckDots()
   ENDIF

   // handle of Listview
   ::hLv := ::hWnd

   // set FONT
   ::hFont := ::oFont:hFont
   SendMessage( ::hLv, WM_SETFONT, ::hFont, 0 )

   // set FULLROWSELECT
   LV_CHANGEEXTENDEDSTYLE( ::hLv, nOr( LVS_EX_GRIDLINES, LVS_EX_FULLROWSELECT, LVS_EX_DOUBLEBUFFER ) )

   // Icon Size
   ::nIcoLarge := nIcoLarge
   ::nIcoSmall := nIcoSmall

   ::oImageListBig := TImageList() :New( nIcoLarge, nIcoLarge )
   ::oImageListSmall := TImageList() :New( nIcoSmall, nIcoSmall )

   ::SetImageList( ::oImageListBig, LVSIL_NORMAL )
   ::SetImageList( ::oImageListSmall, LVSIL_SMALL )

RETURN Self

METHOD ReDefine( nId, oWnd, bAction ) CLASS TGrid                     // unknown

   DEFAULT oWnd := GetWndDefault()

   ::nId := nId
   ::oWnd := oWnd
   ::bAction := bAction

   oWnd:DefControl( Self )

RETURN Self

METHOD Destroy() CLASS TGrid

   ::oImageListBig:End()                                              // ILDESTROY ?
   ::oImageListSmall:End()

   ::Super:End()

RETURN Self

METHOD InitTheListView() CLASS TGrid

LOCAL nCol, nMax
LOCAL nWidth, cCaption, nJustify

   FOR nCol := 1 TO LEN( ::aHeader )
      nWidth := ::aHeader[ nCol ] [ ID_WIDTH ]
      cCaption := VAR2CHAR( ::aHeader[ nCol ] [ ID_HEADER ] ) + CHR( 0 )
      nJustify := ::aHeader[ nCol ] [ ID_ALIGN ]

      LV_INSERTCOLUMN( ::hLv, nCol, nWidth, cCaption, nJustify )      // Call C-Level Routine (source c_grid.c)
   NEXT

   nMax := LEN( ::aSource )
   // need for LVS_OWNERDATA / ::OnDISPINFO()
   LV_SETITEMCOUNT( ::hLv, nMax )

RETURN self

METHOD Notify( nIdCtrl, nPtrNMHDR ) CLASS TGrid

LOCAL nCode   := GetNMHDRCode( nPtrNMHDR )
LOCAL nKey

STATIC nOption

   DO CASE
      CASE nCode == NM_DBLCLK
         nOption = GetNMListViewItem( nPtrNMHDR ) + 1
         IF ::bClick != nil
            ::nOption := nOption
            EVAL( ::bClick, ::nOption, Self )
         ENDIF

      CASE nCode == LVN_ITEMCHANGED
         nOption = GetNMListViewItem( nPtrNMHDR ) + 1
         IF ::nOption != nOption
            ::nOption := nOption
            IF ::bAction != nil
               EVAL( ::bAction, ::nOption, Self )
            ENDIF
         ENDIF

      CASE nCode == LVN_GETDISPINFO
         nOption = GetNMListViewItem( nPtrNMHDR ) + 1
         FWLOG TIME(), "
LVN_GETDISPINFO", VAR2CHAR( nOption )

         IF ::bDisplay != nil
            ::nOption := nOption
            EVAL( ::bDisplay, ::nOption, Self )
         ENDIF

      CASE nCode == LVN_KEYDOWN
         //  nOption = GetNMListViewItem( nPtrNMHDR ) + 1
         nKey := LV_GETGRIDVKEY( nPtrNMHDR )
         IF nKey = 13
            IF ::bClick != nil
               //  ::nOption := nOption
               //  use last from LVN_ITEMCHANGED
               EVAL( ::bClick, ::nOption, Self )
            ENDIF
         ENDIF
   ENDCASE

RETURN nil

METHOD OnDISPINFO( nPtrNMHDR ) CLASS TGrid                            // unused

LOCAL st
LOCAL nRec
LOCAL nSub
LOCAL ctext
LOCAL bSaveError, oError
LOCAL aItem

   FWLOG TIME(), "
OnDISPINFO", VAR2CHAR( nPtrNMHDR )

   aItem := LV_GETGRIDDISPINFOINDEX( nPtrNMHDR )
   SysRefresh()
   // aItem := LV_DISPINFO( nPtrNMHDR )

   msgInfo( VAR2CHAR( aItem ) )
   FWLOG TIME(), VAR2CHAR( nPtrNMHDR ), VAR2CHAR( aItem )

   /***************************
   st := LVDISPINFO():New()

   st:item:pszText     := REPLICATE(CHR(0),255)
   st:item:cchTextMax  := 255

   // ZERO-based :iItem and :iSubItem
   //
   nRec := st:item:iItem              // Array ZERO-based+1
   nSub := st:item:iSubItem+1

   // use Array ::aSource
   //
   ctext := ::aSource[nRec+1][nSub]

   bSaveError := ErrorBlock()
   ErrorBlock( {|e|Break(e)} )
   BEGIN SEQUENCE

   DO CASE
      CASE VALTYPE(cText) = "
C" ; cText := TRIM(cText)
      CASE VALTYPE(cText) = "
N" ; cText := Transform(cText, "999,999,999,999" )
      CASE VALTYPE(cText) = "
D" ; cText := DTOC(cText)
      CASE VALTYPE(cText) = "
L" ; cText := IF(cText,"Y","N")
   ENDCASE
   // Assign Array Text to Display
   //
   st:item:pszText := ctext    // +CHR(0)

   RECOVER USING oError
   ErrorBlock( bSaveError )

   END SEQUENCE
   ErrorBlock( bSaveError )

   ***************************/

RETURN 0

METHOD OnEvent( nEvent, aParams, pParams ) CLASS TGrid                // unused

LOCAL nAt    := ASCAN( ::aEvents, { | aEvent | aEvent[ 2 ] == nEvent } )
LOCAL cEvent := IF( nAt != 0, ::aEvents[ nAt ] [ 1 ], "
" )

   IF !EMPTY( ::bOnEvent )
      EVAL( ::bOnEvent, IF( !EMPTY( cEvent ), cEvent, nEvent ), aParams, pParams )
   ENDIF

RETURN nil

METHOD SetImageList( oImageList, nType ) CLASS TGrid

LOCAL nResult

   DEFAULT nType := LVSIL_NORMAL

   nResult = SendMessage( ::hLv, LVM_SETIMAGELIST, nType, oImageList:hImageList )

   SysRefresh()

RETURN nResult

METHOD SetViewStyle( nView ) CLASS TGrid

   DEFAULT nView := LVS_REPORT

   DO CASE
      CASE nView = LVS_ICON
         ::nStyle := nOR( LVS_SHAREIMAGELISTS, WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_BORDER, LVS_SHOWSELALWAYS, LVS_AUTOARRANGE , LVS_SINGLESEL, LVS_ICON )
      CASE nView = LVS_SMALLICON
         ::nStyle := nOR( LVS_SHAREIMAGELISTS, WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_BORDER, LVS_SHOWSELALWAYS, LVS_AUTOARRANGE , LVS_SINGLESEL, LVS_SMALLICON )
      CASE nView = LVS_LIST
         ::nStyle := nOR( LVS_SHAREIMAGELISTS, WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_BORDER, LVS_SHOWSELALWAYS, LVS_AUTOARRANGE , LVS_SINGLESEL, LVS_LIST )
      CASE nView = LVS_REPORT
         ::nStyle := nOR( LVS_SHAREIMAGELISTS, WS_CHILD, WS_VISIBLE, WS_TABSTOP, WS_BORDER, LVS_SHOWSELALWAYS, LVS_AUTOARRANGE , LVS_SINGLESEL, LVS_REPORT )
   ENDCASE

   SetWindowLong( ::hLv, GWL_STYLE, ::nStyle )
   ::view := nView

   REDRAWWINDOW( ::hLv )
   UpdateWindow( ::hLv )

RETURN nView

METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TGrid              // unused

   DO CASE
         //  use for LVS_OWNERDRAWFIXED
      CASE nMsg == WM_MEASUREITEM
      CASE nMsg == WM_DRAWITEM
   ENDCASE

RETURN ::Super:HandleEvent( nMsg, nWParam, nLParam )

METHOD RefreshAll() CLASS TGrid

LOCAL nCount := LV_GetCountPerPage( ::hLv )
LOCAL nTopNo := LV_GetTopIndex( ::hLv )
   LV_RedrawItems( ::hLv, nTopNo, nTopNo + nCount )
RETURN self

METHOD RefreshCurrent( nRec ) CLASS TGrid

   LV_RedrawItems( ::hLv, nRec, nRec )
RETURN self

METHOD UnMarkAll( lAll ) CLASS TGrid

LOCAL iMax   := LV_GETSELECTEDCOUNT( ::hLv )
LOCAL nCount := 0
LOCAL nSel

   DEFAULT lAll := .T.

   // zurest den markierten
   nSel := LV_GetSelectionMark( ::hLv )
   LV_SETITEMSTATE( ::hLv, nSel, 0, nOr( LVIS_SELECTED, LVIS_FOCUSED ) )

   iMax := LV_GETSELECTEDCOUNT( ::hLv )
   IF iMax > 0
      nSel := LV_GETNEXTITEM( ::hLv, - 1, nOr( LVNI_SELECTED ) )

      LV_SETITEMSTATE( ::hLv, nSel, 0, nOr( LVIS_SELECTED, LVIS_FOCUSED ) )

      DO WHILE .T.
         nSel := LV_GETNEXTITEM( ::hLv, nSel, nOr( LVNI_SELECTED ) )
         nCount ++
         IF nSel > 0
            LV_SETITEMSTATE( ::hLv, nSel, 0, nOr( LVIS_SELECTED, LVIS_FOCUSED ) )
         ELSE
            EXIT
         ENDIF
         IF nCount > iMax
            EXIT
         ENDIF
      ENDDO
   ENDIF

RETURN self

//
// how to use Project File and List of *.PRG ?
//
#include "
HB_FUNC.PRG"


Code: Select all  Expand view
#define CTRL_CLASS            "SysListView32"

#define NM_FIRST              0
#define NM_CLICK              (NM_FIRST-2)
#define NM_DBLCLK             (NM_FIRST-3)

#define WM_ERASEBKGND         20
#define WM_SETFONT            0x0030
#define WM_NOTIFY             0x004E
#define WM_DRAWITEM           0x002B
#define WM_MEASUREITEM        0x002C

#define GWL_STYLE             -16

#define CLR_NONE              0xFFFFFFFF
#define CLR_DEFAULT           0xFF000000

#define HDF_OWNERDRAW         0x8000

#define LVCFMT_CENTER         0x02

#define LVM_FIRST             4096 // 0x1000
#define LVM_SETIMAGELIST      ( LVM_FIRST + 3 )
#define LVM_DELETEALLITEMS    ( LVM_FIRST + 9 )

#define LVN_FIRST             -100
#define LVN_ITEMCHANGED       ( LVN_FIRST - 1 )
#define LVN_GETDISPINFO       ( LVN_FIRST - 50)
#define LVN_KEYDOWN           ( LVN_FIRST - 55)

#define LVS_OWNERDATA         0x1000
#define LVS_OWNERDRAWFIXED    0x0400
#define LVS_AUTOARRANGE       0x0100
#define LVS_EX_DOUBLEBUFFER   0x010000
#define LVS_EX_FULLROWSELECT  0x20
#define LVS_EX_GRIDLINES      0x01
#define LVS_SHAREIMAGELISTS   0x040
#define LVS_SINGLESEL         0x04
#define LVS_SORTASCENDING     0x10
#define LVS_SORTDESCENDING    0x20

#define LVS_ICON              0
#define LVS_REPORT            0x01
#define LVS_SMALLICON         0x02
#define LVS_LIST              0x03

#define LV_VIEW_ICON          0
#define LV_VIEW_DETAILS       0x01
#define LV_VIEW_SMALLICON     0x02
#define LV_VIEW_LIST          0x03
#define LV_VIEW_MAX           0x04
#define LV_VIEW_TILE          0x04

#define LVS_SHOWSELALWAYS     0x08

#define LVSIL_NORMAL          0
#define LVSIL_SMALL           1
#define LVSIL_STATE           2

#define LVCFMT_LEFT           0
#define LVCFMT_RIGHT          0x01

#define LVCF_FMT              0x01
#define LVCF_IMAGE            0x10
#define LVCF_ORDER            0x20
#define LVCF_SUBITEM          0x08
#define LVCF_TEXT             0x04
#define LVCF_WIDTH            0x02

#define LVIS_FOCUSED          0x01
#define LVIS_SELECTED         0x02

#define LVNI_FOCUSED          0x01
#define LVNI_SELECTED         0x02
 
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CLASS TGrid() for FiveWin

Postby hua » Tue Oct 25, 2022 2:29 am

Can't seem to find album.prg in FWH19.12

nageswaragunupudi wrote:There is a lookalike TAlbum class of FiveWin in the sample \fwh\samples\album.prg.
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: CLASS TGrid() for FiveWin

Postby nageswaragunupudi » Tue Oct 25, 2022 5:12 am

hua wrote:Can't seem to find album.prg in FWH19.12

nageswaragunupudi wrote:There is a lookalike TAlbum class of FiveWin in the sample \fwh\samples\album.prg.

Yes, it was not in fwh1903. This was created sometime later at the request of some users.
You may be able to find it in the forums.
We can share it with all.
Code: Select all  Expand view
#include "fivewin.ch"

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

function Main()

   local aImages := nil
   local cLog := cFileSetExt( ExeName(), "log" )

   FERASE( cLog )

   aImages  := ImageArray()
   TAlbum():New( aImages ):Activate()

   if File( cLog )
      WinExec( "notepad.exe " + cLog )
   endif


return nil

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

static function ImageArray()

   local aDir

   aDir  := DirectoryRecurse( "c:\fwh\bitmaps\*.*" )
   ASort( aDir, nil, nil, { |x,y| x[ 2 ] > y[ 2 ] } )
   ASize( aDir, 200 )

return aDir

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

CLASS TAlbum

   DATA aPhotos
   DATA oWnd

   DATA nWndWidth  INIT 800
   DATA nWndHeight INIT 800
   DATA nImgWidth  INIT 210
   DATA nGutter    INIT 30
   DATA nImgCols PROTECTED
   DATA nOffset    INIT 0 PROTECTED
   DATA nHeight

   ACCESS oVScroll INLINE ::oWnd:oVScroll

   METHOD New( aPhotos ) CONSTRUCTOR
   METHOD Activate()

PROTECTED:
   METHOD CreateWindow()
   METHOD CreateControls()
   METHOD SetVScroll()
   METHOD GoUp()
   METHOD GoDown()
   METHOD ThumbPos( nPos )
   METHOD MouseWheel()
   METHOD VSetPos() INLINE ::oWnd:oVScroll:SetPos( -::nOffSet )
   METHOD GoTop()
   METHOD GoBottom()
   METHOD KeyDown( nKey )
   METHOD ScrollWnd( nPixels )
   METHOD Resize( nType, nWidth, nHeight )

ENDCLASS

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

METHOD New( aPhotos ) CLASS TAlbum

   ::aPhotos := aPhotos

return Self

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

METHOD Activate() CLASS TAlbum

   ::CreateWindow()
   ::CreateControls()
   ::SetVScroll()
   ::oWnd:bResized := { |t,w,h| ::Resize( t, w, h ) }

   if ::oWnd:IsKindOf( "MDICHILD" )
      ACTIVATE WINDOW ::oWnd
   else
      ACTIVATE WINDOW ::oWnd CENTERED
   endif

return Self

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

METHOD CreateWindow() CLASS TAlbum

   local oMain, x, y

   if ( oMain := WndMain() ) != nil .and. oMain:IsKindOf( "TMDIFRAME" )
      DEFINE WINDOW ::oWnd MDICHILD OF oMain VSCROLL
   else
      x  := Int( ( ScreenWidth() - ::nWndWidth ) / 2 )
      y  := Int( ( ScreenHeight() - ::nWndHeight ) / 2 )
      DEFINE WINDOW ::oWnd FROM y,x TO ::nWndHeight + y, ::nWndWidth + x PIXEL VSCROLL COLOR CLR_BLACK,0xe8e8e8
   endif

return Self

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

METHOD CreateControls() CLASS TAlbum

   local nImgWidth   := ::nImgWidth
   local nImgHeight  := Int( nImgWidth * 4 / 3 )
   local nGutter     := ::nGutter
   local nRows, nCols, nRow, nCol, x, y, nImage, xMax, nImages := Len( ::aPhotos )
   local oImage

   nCols    := Int( ( ::oWnd:nWidth - nGutter ) / ( nImgWidth + nGutter ) )
   nRows    := Ceiling( nImages / nCols )
   xMax     := nCols * ( nImgWidth * nGutter )

   y        := nGutter
   nImage   := 1
   do while nImage <= nImages
      x     := nGutter
      nCol  := 1

      do while nCol <= nCols .and. nImage <= nImages

         @ y, x XIMAGE oImage SIZE nImgWidth, nImgHeight OF ::oWnd NOBORDER
         oImage:SetSource( If( HB_ISARRAY( ::aPhotos[ nImage ] ), ::aPhotos[ nImage, 1 ], ::aPhotos[ nImage ] ) )
         oImage:nUserControl := 0
         oImage:Shadow()
         nImage++
         nCol++
         x  += ( nImgWidth + nGutter )
      enddo
      y  += ( nImgHeight + nGutter )
   enddo

   ::nImgCols  := nCols
   ::nHeight   := y

return Self

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

METHOD Resize( nType, nWidth, nHeight ) CLASS TAlbum

   local nImgHeight  := Int( ::nImgWidth * 4 / 3 )
   local nRows, nCols, nRow, nCol, x, y, nImage, nImages := Len( ::aPhotos )

   if nWidth == nil
      return nil
   endif

   nCols    := Int( ( ::oWnd:nWidth - ::nGutter ) / ( ::nImgWidth + ::nGutter ) )
   if nCols == ::nImgCols
      return nil
   endif
   nRows    := Ceiling( nImages / nCols )

   y        := ::nGutter
   nImage   := 1
   do while nImage <= nImages
      x     := ::nGutter
      nCol  := 1

      do while nCol <= nCols .and. nImage <= nImages

         WITH OBJECT ::oWnd:aControls[ nImage ]
            :nTop      := y
            :nLeft     := x
         END
         nImage++
         x  += ( ::nImgWidth + ::nGutter )
         nCol++
      enddo
      y  += ( nImgHeight + ::nGutter )
   enddo

   ::nImgCols  := nCols
   ::nHeight   := y
   ::oVScroll:SetRange( 0, ::nHeight - ::oWnd:nHeight )
   ::nOffSet   := 0
   ::VSetPos()

return nil

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

METHOD SetVScroll() CLASS TAlbum

   local oSelf    := Self

   WITH OBJECT ::oWnd:oVScroll
      :SetRange( 0, ::nHeight - ::oWnd:nHeight )
      :bGoUp      := { || oSelf:GoUp() }
      :bGoDown    := { || oSelf:GoDown() }
      :bPos       := { |nPos| oSelf:ThumbPos( nPos ) }
      :bGoTop     := { || oSelf:GoTop() }
      :bGoDown    := { || oSelf:GoDown() }
   END

   ::oWnd:bMouseWheel := ;
      { |k,nDelta| oSelf:MouseWheel( k, nDelta ) }

   ::oWnd:bKeyDown := { |k| oSelf:KeyDown( k ) }

return Self

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

METHOD ScrollWnd( nPixels ) CLASS TAlbum

   ScrollWindow( ::oWnd:hWnd, 0,  nPixels, 0, GetClientRect( ::oWnd:hWnd ) )

return Self

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

METHOD GoUp() CLASS TAlbum

   local nPixels  := Min( 20, ::oVScroll:nMin - ::nOffset )

   ::ScrollWnd( nPixels )
   ::nOffSet += nPixels
   ::VSetPos()

return Self

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

METHOD GoDown() CLASS TAlbum

   local nPixels  := Min( 20, ::oVScroll:nMax + ::nOffSet )

   ::ScrollWnd( -nPixels )
   ::nOffSet -= nPixels
   ::VSetPos()

return Self

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

METHOD ThumbPos( nPos ) CLASS TAlbum

   AEval( ::oWnd:aControls, { |o| o:nTop -= ( nPos + ::nOffSet ) } )
   ::nOffSet   := -nPos
   ::VSetPos()

return Self

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

METHOD MouseWheel( k, nDelta ) CLASS TAlbum

   if nDelta > 0
      ::GoUp()
   else
      ::GoDown()
   endif
   ::VSetPos()

return Self

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

METHOD GoTop() CLASS TAlbum

   AEval( ::oWnd:aControls, { |o| o:nTop -= ::nOffSet } )
   ::nOffSet   := 0
   ::VSetPos()

return Self

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

METHOD GoBottom() CLASS TAlbum

   AEval( ::oWnd:aControls, { |o| o:nTop -= ( ::oVScroll:nMax + ::nOffSet ) } )
   ::nOffSet  := -::oVScroll:nMax
   ::VSetPos()

return Self

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

METHOD KeyDown( nKey ) CLASS TAlbum

   SWITCH nKey
   case VK_UP
      if GetKeyState( VK_CONTROL )
         ::GoTop()
      else
         ::GoUp()
      endif
      return 0
      EXIT
   case VK_DOWN
      if GetKeyState( VK_CONTROL )
         ::GoBottom()
      else
         ::GoDown()
      endif
      return 0
      EXIT
   case VK_HOME
      ::GoTop()
      return 0
      EXIT
   case VK_END
      ::GoBottom()
      return 0
      EXIT
   END

return nil

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


I remember we still have to provide clickable PDF thumbnail view. We will soon.
Regards

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

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