campo-sirio/al/cpp_ui.win/listwin.cpp
alex 714dd74636 Archive Library versione 2.00
git-svn-id: svn://10.65.10.50/trunk@5350 c028cbd2-c16b-5b4b-a496-9718f37d4682
1997-10-09 16:09:54 +00:00

427 lines
13 KiB
C++
Executable File

//
// LISTWIN.CPP
//
// Source file for ArchiveLib 2.0
//
// Copyright (c) Greenleaf Software, Inc. 1994-1996
// All Rights Reserved
//
// CONTENTS
//
// ALEntryList::FillListBox()
// ALEntryListFillListBox()
// ALEntryList::SetMarksFromListBox()
// ALEntryListSetMarksFromListBox()
// ALEntryList::MakeEntriesFromListBox()
// ALEntryListMakeEntriesFromListBox()
//
// DESCRIPTION
//
// A batch of functions that perform UI stuff for ALEntryList under
// the Windows GUI.
//
// REVISION HISTORY
//
// February 14, 1996 2.0A : New release
#include "arclib.h"
#if !defined( AL_IBM )
#pragma hdrstop
#endif
//
// NAME
//
// ALEntryList::FillListBox()
//
// PLATFORMS/ENVIRONMENTS
//
// Windows
// C++ C PM VB
//
// SHORT DESCRIPTION
//
// Fill a list box with the object names from an ALEntryList.
//
// C++ SYNOPSIS
//
// #include "arclib.h"
//
// int ALEntryList::FillListBox( HWND hDlg,
// int list_box_id = -1 );
//
// C SYNOPSIS
//
// #include "arclib.h"
//
// int ALEntryListFillListBox( hALEntryList this_object,
// HWND hDlg,
// int list_box_id );
//
// VB SYNOPSIS
//
// Declare Function ALEntryListFillListBox Lib "AL20LW"
// (ByVal this_object&, ByVal hDlg%, ByVal list_box_id% ) as Integer
//
// DELPHI SYNOPSIS
//
// function ALEntryListFillListBox( this_object : hALEntryList;
// hDlg : HDlg;
// list_box_id : Integer ) : Integer;
//
// ARGUMENTS
//
// this_object : A reference or pointer to the ALEntryList object that
// is going to supply all the entry names that are going
// to be displayed in the list box.
//
// hDlg : This argument is a window handle. If the next parameter,
// list_box_id, is set to -1, it means this is the handle of
// the list box. If list_box_id is not -1, it means this
// argument is the window handle of a dialog box that
// contains the list box.
//
// list_box_id : The id of the list box. If set to -1, it means the list
// box is not in a dialog box, and the hDlg parameter is the
// actual handle of the list box.
//
// DESCRIPTION
//
// This function is a handy helper when writing Windows plications. It goes
// through an ALEntryList, and finds all the marked entries. For every
// marked entry, it stuffs the name of the storage object into the list box.
// This means that if you are planning on letting the user select a list
// of storage objects, you can initialize the list with just one
// function call.
//
// RETURNS
//
// The number of entries that were stuffed in the list box.
//
// EXAMPLE
//
// SEE ALSO
//
// REVISION HISTORY
//
// February 14, 1996 2.0A : New release
//
int AL_PROTO
ALEntryList::FillListBox( HWND hDlg, /* Tag public function */
int list_box_id /* = -1 */ )
{
HWND window;
if ( list_box_id != -1 )
window = GetDlgItem( hDlg, (short int) list_box_id );
else
window = hDlg;
SendMessage( window, LB_RESETCONTENT, 0, 0 );
ALEntry *job = GetFirstEntry();
int count = 0;
while ( job ) {
if ( job->GetMark() ) {
count++;
SendMessage( window,
LB_ADDSTRING,
0,
(LPARAM)( (LPSTR) job->mpStorageObject->mName ) );
}
job = job->GetNextEntry();
}
if ( count == 0 )
SendMessage( window,
LB_ADDSTRING,
0,
(LPARAM)( (LPSTR) "<none>" ) );
return count;
}
#if !defined( AL_NO_C )
extern "C" AL_LINKAGE int AL_FUNCTION
ALEntryListFillListBox( hALEntryList this_object, /* Tag public function */
HWND hDlg,
int list_box_id )
{
AL_ASSERT_OBJECT( this_object, ALEntryList, "ALEntryListFillListBox" );
return ( (ALEntryList *) this_object )->FillListBox( hDlg, list_box_id );
}
#endif
//
// NAME
//
// ALEntryList::SetMarksFromListBox()
//
// PLATFORMS/ENVIRONMENTS
//
// Windows
// C++ C VB Delphi
//
// SHORT DESCRIPTION
//
// Set marks in an ALEntryList based on selections in a list box.
//
// C++ SYNOPSIS
//
// #include "arclib.h"
//
// int ALEntryList::SetMarksFromListBox( HWND hDlg,
// int list_box_id = -1 );
//
// C SYNOPSIS
//
// #include "arclib.h"
//
// int ALEntryListSetMarksFromListBox( hALEntryList this_object,
// HWND hDlg,
// int list_box_id );
//
// VB SYNOPSIS
//
// Declare Function ALEntryListSetMarksFromListBox Lib "AL20LW"
// (ByVal this_object&, ByVal hDlg%, ByVal list_box_id%) As Integer
//
// DELPHI SYNOPSIS
//
// function ALEntryListSetMarksFromListBox( this_object : hALEntryList;
// hDlg : HWnd;
// list_box_id : Integer ) : Integer;
//
// ARGUMENTS
//
// this_object : A reference or pointer to the ALEntryList object that
// is have some marks set. Note that the C++ member function
// version of this call doesn't have an explicit argument
// here, since it has access to 'this' implicitly.
//
// hDlg : This argument is a window handle. If the next parameter,
// list_box_id, is set to -1, it means this is the handle of
// the list box. If list_box_id is not -1, it means this
// argument is the window handle of a dialog box that
// contains the list box.
//
// list_box_id : The id of the list box. If set to -1, it means the list
// box is not in a dialog box, and the hDlg parameter is the
// actual handle of the list box.
//
// DESCRIPTION
//
// This function is called after you have given a user the opportunity
// to set and clear items in a multiselection list box. Once the user
// has done so, you can call this function, which will go through the
// list and set all the marks that have been set in the list box by the
// user. Note that it will not clear the marks on any of the ALEntry
// objects in the list, you might want to do that first.
//
// RETURNS
//
// A count of the items that have had their marks set.
//
// EXAMPLE
//
// SEE ALSO
//
// REVISION HISTORY
//
// February 14, 1996 2.0A : New release
//
int AL_PROTO
ALEntryList::SetMarksFromListBox( HWND hDlg, /* Tag public function */
int list_box /* = -1 */ )
{
HWND window;
if ( list_box != -1 )
window = GetDlgItem( hDlg, (short int) list_box );
else
window = hDlg;
WORD count = (WORD) SendMessage( window, LB_GETSELCOUNT, 0, 0L );
int *items = new int[ count ];
if ( items == 0 )
return mStatus.SetError( AL_CANT_ALLOCATE_MEMORY,
"Memory allocation failure in SetMarksFromListBox()" );
#ifdef AL_FLAT_MODEL
if ( count != (WORD) SendMessage( window, LB_GETSELITEMS, count, (LPARAM) ( items ) ) ) {
#else
if ( count != (WORD) SendMessage( window, LB_GETSELITEMS, count, (LPARAM) ( (int _far * ) items ) ) ) {
#endif
mStatus.SetError( AL_LOGIC_ERROR,
"Logic error in SetMarksFromListBox()."
"Mismatch in select count from list box." );
delete[] items;
return AL_LOGIC_ERROR;
}
for ( WORD i = 0 ; i < count ; i++ ) {
WORD length = (WORD) SendMessage( window, LB_GETTEXTLEN, (short int) items[ i ], 0L );
AL_ASSERT( length != (WORD) LB_ERR, "SetMarksFromListBox: LB_ERR returned from list box" );
if ( length > 0 ) {
char *name = new char[ length + 1 ];
if ( name ) {
if ( SendMessage( window, LB_GETTEXT, (short int) items[ i ], (LPARAM)( (LPSTR) name ) ) >= 0 )
SetMarks( name );
delete[] name;
}
}
}
delete[] items;
return count;
}
#if !defined( AL_NO_C )
extern "C" AL_LINKAGE int AL_FUNCTION
ALEntryListSetMarksFromListBox( hALEntryList this_object, /* Tag public function */
HWND hDlg,
int list_box_id )
{
AL_ASSERT_OBJECT( this_object, ALEntryList, "ALEntryListSetMarksFromListBox" );
return ( (ALEntryList *) this_object)->SetMarksFromListBox( hDlg, list_box_id );
}
#endif
//
// NAME
//
// ALEntryList::MakeEntriesFromListBox()
//
// PLATFORMS/ENVIRONMENTS
//
// Windows
// C++ C VB Delphi
//
// SHORT DESCRIPTION
//
// Create new entries in a list based on selected items in a list box.
//
// C++ SYNOPSIS
//
// #include "arclib.h"
//
// int ALEntryList::MakeEntriesFromListBox( HWND hDlg,
// int list_box_id = -1 );
//
// C SYNOPSIS
//
// #include "arclib.h"
//
// int ALEntryListMakeEntriesFromListBox( hALEntryList this_object,
// HWND hDlg,
// int list_box_id );
//
// VB SYNOPSIS
//
// Declare Function ALEntryListMakeEntriesFromlistBox Lib "AL20LW"
// (ByVal this_object&, ByVal hDlg%, ByVal list_box_id% ) As Integer
//
// DELPHI SYNOPSIS
//
// function ALEntryListMakeEntriesFromlistBox( this_object : hALEntryList;
// hDlg : HWnd;
// list_box_id : Integer );
//
// ARGUMENTS
//
// this_object : A reference or pointer to the ALEntryList object that
// is going to have new entries added. Note that the C++
// member function version of this call doesn't have an
// an explicit argument here, since it has access to 'this'
// implicitly.
//
// hDlg : This argument is a window handle. If the next parameter,
// list_box_id, is set to -1, it means this is the handle of
// the list box. If list_box_id is not -1, it means this
// argument is the window handle of a dialog box that
// contains the list box.
//
// list_box_id : The id of the list box. If set to -1, it means the list
// box is not in a dialog box, and the hDlg parameter is the
// actual handle of the list box.
//
// DESCRIPTION
//
// This function goes through a list box, and picks out all the
// highlighted entries. It creates a new ALEntry object for each
// of the marked entires, using the storage objects and engines that
// are present in the toolkit owned by this ALEntryList.
//
// RETURNS
//
// The number of new entries created from the list box.
//
// EXAMPLE
//
// SEE ALSO
//
// REVISION HISTORY
//
// November 13, 1995 2.00A : First release.
//
int AL_PROTO
ALEntryList::MakeEntriesFromListBox( HWND hDlg, /* Tag public function */
int list_box_id /* = -1 */ )
{
HWND window;
if ( list_box_id != -1 )
window = GetDlgItem( hDlg, (short int) list_box_id );
else
window = hDlg;
int count = (WORD) SendMessage( window, LB_GETSELCOUNT, 0, 0L );
if ( count == LB_ERR )
return AL_GETSEL_ERROR;
int *items = new int[ count ];
if ( items == 0 )
return AL_CANT_ALLOCATE_MEMORY;
#ifdef AL_FLAT_MODEL
if ( count != SendMessage( window, LB_GETSELITEMS, (short int) count, (LPARAM) items ) ) {
#else
if ( count != SendMessage( window, LB_GETSELITEMS, (short int) count, (LPARAM)(int _far *) items ) ) {
#endif
delete items;
return AL_GETSEL_ERROR;
}
for ( WORD i = 0 ; i < (WORD) count ; i++ ) {
WORD length = (WORD) SendMessage( window, LB_GETTEXTLEN, (short int) items[ i ], 0L );
if ( length > 0 ) {
char *name = new char[ length + 1 ];
if ( name ) {
if ( SendMessage( window, LB_GETTEXT, (short int) items[ i ], (LPARAM)( (LPSTR) name ) ) >= 0 ) {
new ALEntry( *this,
mToolKit.CreateStorageObject( name, AL_STORAGE_DEFAULT ),
mToolKit.CreateCompressor( AL_COMPRESSION_DEFAULT ),
mToolKit.CreateDecompressor( AL_COMPRESSION_DEFAULT ) );
}
delete name;
SendMessage( window,
LB_SETSEL,
0,
items[ i ] );
}
}
}
delete items;
return count;
}
#if !defined( AL_NO_C )
extern "C" AL_LINKAGE int AL_FUNCTION
ALEntryListMakeEntriesFromListBox( hALEntryList this_object, /* Tag public function */
HWND hDlg,
int list_box_id )
{
AL_ASSERT_OBJECT( this_object, ALEntryList, "ALEntryListMakeEntriesFromListBox" );
return ( (ALEntryList *) this_object )->MakeEntriesFromListBox( hDlg, list_box_id );
}
#endif