home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
SAMPLES
/
ICLUI
/
DRAG4
/
DMSAMP4.HPP
< prev
next >
Wrap
Text File
|
1993-10-21
|
7KB
|
206 lines
#include "dmsamp3.hpp"
#include <idmprov.hpp>
#include <idmcnrit.hpp>
#include <idmevent.hpp>
#include <idmimage.hpp>
#include <ititle.hpp>
#include <itrace.hpp>
#include <istring.hpp>
class CustomerItem : public IDMCnrItem {
typedef IDMCnrItem
Inherited;
public:
CustomerItem ( const IDMItem::Handle &item )
: IDMCnrItem( item )
{
IString
rmf1 = IDMItem::rmfFrom( IDM::rmLibrary, IDM::rfSharedMem ),
rmf2 = IDMItem::rmfFrom( IDM::rmDiscard, IDM::rfUnknown );
// Get pointer to the associated Customer container object...
Customer
*customer = (Customer*)this->object();
// Build and set contents. We can only do this on the source
// side. Note that since we call this ctor on both source
// and target sides, we must distinguish them. That is done
// here by checking the "object" pointer. If this ctor was
// called from within our generateSourceItems, then this value
// will be non-zero. If called from with the template provider's
// provideTargetItemFor, then it will be zero.
if ( customer )
{
IString
contents,
delim = '\x01';
contents += customer -> iconText() + delim;
contents += customer -> name() + delim;
contents += customer -> address() + delim;
contents += customer -> phone() + delim;
contents += customer -> iconId();
this -> setContents( contents );
// Add RMFs supported by this class (IDMCnrItem will have
// already specified others)...
this -> addRMF( rmf1 );
this -> addRMF( rmf2 );
}
else
// On target side, add in <rmLibrary,rfSharedMem> if source concurs
// (and it's not already in there)...
if ( item -> supportsRMF( rmf1 )
&&
!( this -> supportsRMF( rmf1 ) ) )
this -> addRMF( rmf1 );
}
~CustomerItem ( )
{
}
static Boolean
generateSourceItems ( const IDMSourceOperation::Handle &srcOp )
{
// Get generic container items. Note that we call the inherited
// function since it already has smarts to deal with multi-selection,
// etc...
Boolean
result = Inherited::generateSourceItems( srcOp );
// Now, replace each IDMCnrItem with a customer item...
for ( unsigned i = 1; i <= srcOp->numberOfItems(); i++ )
srcOp -> replaceItem( i, new CustomerItem( srcOp -> item( i ) ) );
// Set stack3AndFade as the default image style ...
srcOp -> setImageStyle( IDM::stack3AndFade );
return result;
}
virtual Boolean
sourceDiscard ( IDMSourceDiscardEvent &event )
{
// Remove the object from the container...
IContainerControl
*cnr = (IContainerControl*)( event.sourceOperation()->sourceWindow() );
IContainerObject
*obj = (IContainerObject*)( this->object() );
cnr -> removeObject( obj );
return true;
}
virtual Boolean
targetDrop ( IDMTargetDropEvent &event )
{
Boolean
result = true;
// Check if using rfSharedMem...
IString
myRMF = IDMItem::rmfFrom( IDM::rmLibrary, IDM::rfSharedMem );
if ( this->selectedRMF() == myRMF )
{
// Yes, construct new Customer from passed data...
IString
contents = this->contents(),
delim = '\x01',
text = contents.subString( 1, contents.indexOf( delim ) - 1 );
contents = contents.subString( contents.indexOf( delim ) + 1 );
IString
name = contents.subString( 1, contents.indexOf( delim ) - 1 );
contents = contents.subString( contents.indexOf( delim ) + 1 );
IString
addr = contents.subString( 1, contents.indexOf( delim ) - 1 );
contents = contents.subString( contents.indexOf( delim ) + 1 );
IString
phone = contents.subString( 1, contents.indexOf( delim ) - 1 ),
iconId = contents.subString( contents.indexOf( delim ) + 1 );
IContainerControl
*cnr = event.container();
Customer
*pNewCustomer = new Customer( text,
iconId.asUnsigned(),
name,
addr,
phone,
(MyWindow*)( cnr->parent() ) );
// ...and insert the new Customer into the container...
cnr -> setRefreshOff();
cnr -> addObject( pNewCustomer );
Handle
thisHandle;
thisHandle = this;
IPoint
pos = this->targetOperation()->dropPosition( thisHandle, event );
cnr -> moveObjectTo( pNewCustomer,
0,
cnr,
0,
pos );
cnr -> setRefreshOn();
cnr -> refresh();
}
else
// Some other RMF, base class must support it...
result = Inherited::targetDrop( event );
return result;
}
virtual unsigned long
supportedOperationsFor ( const IString &rmf ) const
{
if ( rmf == IDMItem::rmfFrom( IDM::rmLibrary, IDM::rfSharedMem ) )
// If using <rmLibrary,rfSharedMem> then only copy is supported...
return IDMItem::copyable & this->supportedOperations();
else
// Else, whatever base class supports...
return Inherited::supportedOperationsFor( rmf );
}
}; // Class CustomerItem
class DMSample4Window : public MyWindow {
/*******************************************************************************
* These windows are similar to those from dmsamp3 but use icon view and *
* permit dragging/dropping within the same window. Note that sometimes it *
* is necessary to restrict target support so if the window title include *
* "source only" or "target only" we only permit drag/drop, respectively. *
*******************************************************************************/
public:
DMSample4Window ( const char *aTitle )
: MyWindow( 0 ),
title( this )
{
// Set title... /
if ( aTitle )
title.setTitleText( aTitle );
else
title.setTitleText( "Direct Manipulation Sample 4" );
// Tailor the container...
this->cnrCtl -> hideTitle();
this->cnrCtl -> showIconView();
this->cnrCtl -> arrangeIconView();
this->cnrCtl -> setExtendedSelection();
// Use appropriate item provider...
this->cnrCtl -> setItemProvider( &this->provider );
// Enable drag/drop...
IString
sTitle = aTitle;
if ( sTitle.includes( "source only" ) )
IDMHandler::enableDragFrom( this->cnrCtl );
else if ( sTitle.includes( "target only" ) )
IDMHandler::enableDropOn( this->cnrCtl );
else
IDMHandler::enableDragDropFor( this->cnrCtl );
// Make size more reasonable...
this->sizeTo( ISize( 250, 250 ) );
}
IDMItemProviderFor< CustomerItem >
provider;
ITitle
title;
}; // class DMSample4Window