home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
draglb.zip
/
DRAGLB.CPP
< prev
next >
Wrap
Text File
|
1994-06-08
|
14KB
|
283 lines
#include <ilistbox.hpp>
#include <idmsrcop.hpp>
#include <idmimage.hpp>
#include "draglb.hpp"
#include "operfix.hpp"
/*------------------------------------------------------------------------------
| LBItem::LBItem |
| |
| Constructor for source LB drag item. Note that we only allow moves. |
------------------------------------------------------------------------------*/
LBItem::LBItem( IDMSourceOperation *pSrcOp, IString &strListItem ) :
IDMItem( pSrcOp,
IDM::text,
(IDMItem::moveable | IDMItem::copyable),
none )
{
setContents( strListItem );
/********************************************************************/
/* Set the native rendering mechanism and format for the item */
/* */
/* Note how we always use the process rendering format to optimize */
/* rendering if we're in the same process. */
/********************************************************************/
IString tempStr = generateSourceName();
if( tempStr.size() )
{
/******************************************************************/
/* If the text is less than 255 characters and does not contain */
/* embedded NULL characters, we can use the text rendering */
/* format on an inter-process move/copy operation, which allows */
/* target rendering to occur (i.e. target takes control of the */
/* operation after the drop and does not require intervention */
/* from the source) */
/******************************************************************/
setSourceName(tempStr);
setRMFs( rmfsFrom( IDM::rmLibrary,
rfForThisProcess() + "," + IDM::rfText ) );
}
else
{
/******************************************************************/
/* The text is greater than or equal to 255 characters or contains*/
/* embedded NULL characters. Therefore, we must use the shared */
/* memory rendering format on an inter-process move/copy */
/* operation, whereas source rendering will occur (i.e. target */
/* requires intervention from the source to complete the move/ */
/* copy operation after the drop occurs). Note that we require */
/* rendering preparation to help determine the size of the shared */
/* memory buffer. */
/******************************************************************/
setRMFs( rmfsFrom( IDM::rmLibrary,
rfForThisProcess() + "," + IDM::rfSharedMem ) );
/******************************************************************/
/* Use render prepare event to determine size of transfer buffer */
/******************************************************************/
setRequiresPreparation(true);
}
/********************************************************************/
/* Add rendering mechanism and format for the shredder */
/********************************************************************/
addRMF( IDM::rmDiscard, IDM::rfUnknown );
/********************************************************************/
/* Set the system defined text image as the drag image. */
/********************************************************************/
IDMImage image = IDMImage(ISystemPointerHandle(
ISystemPointerHandle::text));
setImage(image);
}
/*------------------------------------------------------------------------------
| LBItem::LBItem |
| |
| Constructor for target LB drag item |
------------------------------------------------------------------------------*/
LBItem::LBItem( const IDMItem::Handle &item ) :
IDMItem( item )
{
/********************************************************************/
/* Use these rmfs to verify that at least one is supported by the */
/* of the drag operation. */
/********************************************************************/
IString defaultRMFs = rmfsFrom( IDM::rmLibrary, rfForThisProcess() +
"," +
IDM::rfText +
"," +
IDM::rfSharedMem);
IString istrRmf = matchingRMFs( rmfsFrom( rmfs().change(' ', "") ),
defaultRMFs );
/********************************************************************/
/* Therefore, the RMFs that LBItem understands are */
/* (IDM::rmLibrary)x */
/* (IDM::rfProcess=pid,IDM::rfText,IDM::sharedMem) */
/********************************************************************/
setRMFs( istrRmf );
}
/*------------------------------------------------------------------------------
| LBItem::~LBItem |
| |
| Destructor |
------------------------------------------------------------------------------*/
LBItem::~LBItem()
{
}
/*------------------------------------------------------------------------------
| LBItem::generateSourceItems |
| |
| Static function that gives LBItem an opportunity to attach new LBItem's to |
| the argument IDMSourceOperation object. This function is called when a drag |
| operation starts over one of our IListBox objects. Returns true if items |
| were provided, false otherwise. |
------------------------------------------------------------------------------*/
Boolean LBItem::generateSourceItems( IDMSourceOperation *pSrcOp )
{
Boolean bRC = false;
if (pSrcOp)
{
/******************************************************************/
/* Obtain pointer to list box control from the source window */
/******************************************************************/
IListBox *pLB = (IListBox *)pSrcOp->sourceWindow();
if (pLB)
{
/****************************************************************/
/* Do not allow drag if nothing is selected */
/****************************************************************/
if (pLB->numberOfSelections() != 0)
{
/**************************************************************/
/* Note: This logic only supports single selection list */
/* boxes. See the drag4 sample that ships with */
/* C Set++ V2.1 for an example of what needs to */
/* be done to support multiple items (i.e. the */
/* logic is very similar to what we're doing with */
/* a container in drag4). */
/**************************************************************/
IString strListItem = pLB->itemText( pLB->selection() );
/**************************************************************/
/* Create a new list box drag item */
/**************************************************************/
LBItem *pLBItem = new LBItem( pSrcOp, strListItem );
if (pLBItem)
{
/************************************************************/
/* Add it to the source operation object */
/************************************************************/
pSrcOp->addItem( pLBItem );
/************************************************************/
/* Set the drag image style */
/************************************************************/
pSrcOp->setImageStyle(IDM::allStacked);
bRC = true;
}
}
}
}
return( bRC );
}
/*------------------------------------------------------------------------------
| LBItem::object |
| |
| Returns a pointer to the list item text. |
------------------------------------------------------------------------------*/
void *LBItem::object() const
{
return (void *)&(this->strContents);
}
/*------------------------------------------------------------------------------
| LBItem::targetDrop |
| |
| Inserts list box item into the target list box. Note that item is added |
| to the end of the list. |
------------------------------------------------------------------------------*/
Boolean LBItem::targetDrop( IDMTargetDropEvent & )
{
IListBox *pLB = (IListBox *)this->targetOperation()->targetWindow();
if (pLB)
pLB->addAsLast( contents() );
return( true );
}
/*------------------------------------------------------------------------------
| LBItem::sourceEnd |
| |
| Remove source list item to complete the move operation. |
------------------------------------------------------------------------------*/
Boolean LBItem :: sourceEnd(IDMSourceEndEvent &event)
{
if (event.wasTargetSuccessful())
{
if (OperFix::dropOperation( event ) == IDMOperation::move)
return( deleteItem((IListBox *)event.dragItem()->sourceWindow()) );
}
return( true );
}
/*------------------------------------------------------------------------------
| LBItem::sourceDiscard |
| |
| Remove list box item that was dropped on the shredder. |
------------------------------------------------------------------------------*/
Boolean LBItem::sourceDiscard( IDMSourceDiscardEvent &event )
{
return( deleteItem((IListBox *)event.sourceOperation()->sourceWindow()) );
}
/*------------------------------------------------------------------------------
| LBItem::deleteItem |
| |
| Delete selected list box item. |
------------------------------------------------------------------------------*/
Boolean LBItem::deleteItem( IListBox *pLB )
{
if (pLB)
{
long lItem = pLB->selection();
if (lItem == -1)
return( false );
pLB->remove( lItem );
return( true );
}
return( false );
}
/*------------------------------------------------------------------------------
| LBItem::provideEnterSupport |
| |
| Perform 2 checks: |
| 1) Prevent a drop in the same window. |
| 2) Verify that we understand the type of the drag item during target enter |
| event processing. |
------------------------------------------------------------------------------*/
LBProvider::provideEnterSupport( IDMTargetEnterEvent &event )
{
IDMTargetOperation::Handle pTgtOpH = IDMTargetOperation::targetOperation();
/********************************************************************/
/* If the source and target window are the same, we want to */
/* prevent a drop. */
/********************************************************************/
if (pTgtOpH->sourceWindowHandle() == pTgtOpH->targetWindowHandle())
{
event.setDropIndicator( IDM::neverOk );
return( false );
}
/********************************************************************/
/* Verify types. */
/********************************************************************/
IString strTypes = pTgtOpH->item(1)->types();
if ((strTypes.indexOf( IDM::plainText ) == 0) &&
(strTypes.indexOf( IDM::text ) == 0))
{
event.setDropIndicator( IDM::notOk );
return( false );
}
return( true );
}