home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
bgui-1.1a.lha
/
BGUI
/
demos
/
multicol.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-20
|
36KB
|
844 lines
;/*
dcc MultiCol.c -proto -mi -ms -mRR -lbgui
quit
*/
/*
** $RCSfile: multicol.c,v $
** Description: Shows you how to code a multi-column listview
** object using the hooks that the listview class
** provide.
** Copyright: (C) Copyright 1994 Jaba Development.
** (C) Copyright 1994 Jan van den Baard.
** All Rights Reserved.
**
** $Author: jaba $
** $Revision: 1.3 $
** $Date: 1994/11/20 13:06:11 $
**/
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <dos/exall.h>
#include <libraries/bgui.h>
#include <libraries/bgui_macros.h>
#include <utility/hooks.h>
#include <clib/alib_protos.h>
#include <clib/macros.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/dos.h>
#include <proto/bgui.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/*
** SAS<->DICE muck.
**/
#ifdef _DCC
#define SAVEDS __geta4
#define ASM
#define REG(x) __ ## x
#else
#define SAVEDS __saveds
#define ASM __asm
#define REG(x) register __ ## x
#endif
/*
** This is the data were going to add
** to the listview object. It is a simple
** structure in which the file-information
** is stored. This data is created in the
** LISTV_Resource hook from a pointer
** to a ExAllData structure.
**/
typedef struct {
UBYTE fi_FileName[ 108 ];
UBYTE fi_Size[ 11 ];
UBYTE fi_Date[ 32 ];
BOOL fi_IsDir;
} FILEINFO;
/*
** The LISTV_Resource hook is used to create
** the FILEINFO structures from a struct ExAllData
** at create time. At delete time the FILEINFO
** structure is simply deallocated.
**/
SAVEDS ASM APTR ResourceHookFunc( REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct lvResource *lvr )
{
struct ExAllData *ead;
FILEINFO *fi;
struct DateTime dt;
APTR return_code = NULL;
/*
** What must we do?
**/
switch ( lvr->lvr_Command ) {
case LVRC_MAKE:
/*
** Create a FILEINFO structure.
** BGUI has passed us a pointer to a
** ExAllData structure. Here we
** convert it to a FILEINFO structure
** which, eventually, get's added to
** the listview.
**/
if ( fi = ( FILEINFO * )AllocVec( sizeof( FILEINFO ), MEMF_PUBLIC )) {
/*
** Pick up the ExAllData.
**/
ead = ( struct ExAllData * )lvr->lvr_Entry;
/*
** Copy the name.
**/
strcpy( &fi->fi_FileName[ 0 ], ead->ed_Name );
/*
** Format the size text. We can do all sorts of
** fancy stuff here like using the locale.library
** formatting stuff but hey, it's just a demo ;)
**/
if ( ead->ed_Type < 0 ) {
fi->fi_IsDir = FALSE;
sprintf( &fi->fi_Size[ 0 ], "%ld", ead->ed_Size );
} else {
fi->fi_IsDir = TRUE;
strcpy( &fi->fi_Size[ 0 ], "(dir)" );
}
/*
** Convert the date to a string.
**/
dt.dat_Stamp = *(( struct DateStamp * )&ead->ed_Days );
dt.dat_Format = FORMAT_CDN;
dt.dat_Flags = DTF_SUBST | DTF_FUTURE;
dt.dat_StrDay = NULL;
dt.dat_StrDate = &fi->fi_Date[ 0 ];
dt.dat_StrTime = NULL;
/*
** Format date.
**/
DateToStr( &dt );
/*
** Return a pointer to the created
** FILEINFO structure.
**/
return_code = ( APTR )fi;
}
break;
case LVRC_KILL:
/*
** Simply deallocate the FILEINFO
** structure which has been created with
** LVRC_MAKE above.
**/
FreeVec( lvr->lvr_Entry );
break;
}
/*
** Pointer to FILEINFO or NULL.
**/
return( return_code );
}
/*
** The listview will have three columns.
**
** Name Size Date
**
** The following globals will contain the maximum
** width of each of these columns.
**/
UWORD MaxName, MaxSize, MaxDate;
/*
** This global stores the total width of the
** listview drawing area.
**/
UWORD TotalWidth = 0;
/*
** This boolean determines wether the hook must
** re-compute the column sizes.
**/
BOOL ReCompCols = TRUE;
/*
** We use 16 pixels as a minimum inner-column spacing.
**/
#define INNER_SPACE 16
/*
** This routine re-computes the minimum column
** sizes when necessary.
**/
VOID ReComputeColumns( struct RastPort *rp, Object *obj, UWORD list_width )
{
FILEINFO *fi;
UWORD tmp, total;
/*
** A re-computation is necessary when:
**
** 1) The ReCompCols flag is TRUE.
** 2) The with of the listview has changed.
**/
if ( ReCompCols || ( TotalWidth != list_width )) {
/*
** Our listview also has a title entry.
** Here we compute the default column
** sizes accoording to this title.
**/
MaxName = TextLength( rp, "Name:", 6 ) + INNER_SPACE;
MaxSize = TextLength( rp, "Size:", 6 ) + INNER_SPACE;
MaxDate = TextLength( rp, "Date:", 6 );
/*
** Now we loop through the entries to find
** out the largest width of the three columns.
**/
if ( fi = ( FILEINFO * )FirstEntry( obj )) {
/*
** Loop until all are done.
**/
while ( fi ) {
/*
** Compute width of the Name: column
** for this entry.
**/
tmp = TextLength( rp, &fi->fi_FileName[ 0 ], strlen( &fi->fi_FileName[ 0 ] )) + INNER_SPACE;
/*
** Is it bigger than the last one?
** If so store it.
**/
if ( tmp > MaxName ) MaxName = tmp;
/*
** Compute width of the Size: column
** for this entry.
**/
tmp = TextLength( rp, &fi->fi_