home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
DRAG2
/
DMSAMP2.CPP
< prev
next >
Wrap
Text File
|
1995-05-01
|
12KB
|
263 lines
#ifndef _IBASE_ //Make sure ibase.hpp is included
#include <ibase.hpp> // since that is where IC_<environ>
#endif // is defined.
#include <iframe.hpp>
#include <ibmpctl.hpp>
#include <idmhndlr.hpp>
#include <igbitmap.hpp>
#include <igrafctx.hpp>
#include <igbundle.hpp>
#include <igrect.hpp>
#include <istring.hpp>
#include "dmsamp2.hpp"
#include "dmsamp2.h"
Boolean ABitmapProvider::bAlreadyDrawn(false);
/*------------------------------------------------------------------------------
| main |
------------------------------------------------------------------------------*/
int main()
{
/***********************************************************************/
/* Create a generic frame window. */
/***********************************************************************/
IFrameWindow
frame ( "Direct Manipulation Sample 2", WND_MAIN );
/***********************************************************************/
/* Create an empty bitmap control. */
/***********************************************************************/
IBitmapControl
bmpControl ( 0, &frame, &frame );
/***********************************************************************/
/* Create a target handler for the bitmap control and use default */
/* renderers. */
/***********************************************************************/
IDMHandler::enableDropOn( &bmpControl );
/***********************************************************************/
/* Create bitmap drag item provider. */
/***********************************************************************/
ABitmapProvider
itemProvider;
/***********************************************************************/
/* Attach provider to the bitmap control. */
/***********************************************************************/
bmpControl.setItemProvider( &itemProvider );
/***********************************************************************/
/* Set the bitmap's control as the frame's client */
/* and display the frame. */
/***********************************************************************/
bmpControl.setText( "Drop .bmp files here." );
bmpControl.setFocus();
frame.sizeTo( ISize( 400, 350 ) );
frame.setIcon( frame.id() )
.setClient( &bmpControl )
.show();
IApplication::current().run();
return 0;
}
/*------------------------------------------------------------------------------
| ABitmapItem::ABitmapItem |
| |
| Constructor. |
------------------------------------------------------------------------------*/
ABitmapItem :: ABitmapItem ( const IDMItem::Handle& item )
: IDMItem( item )
{
}
/*------------------------------------------------------------------------------
| ABitmapItem::targetDrop |
| |
| Take the dropped file, create a PM bitmap object, |
| and set it into the target window. |
------------------------------------------------------------------------------*/
Boolean ABitmapItem :: targetDrop ( IDMTargetDropEvent& event )
{
/***********************************************************************/
/* Get pointer to the target bitmap control. */
/***********************************************************************/
IBitmapControl
*bmpControl = (IBitmapControl *)targetOperation()->targetWindow();
/***********************************************************************/
/* Turn off target emphasis. */
/***********************************************************************/
ABitmapProvider
*provider = (ABitmapProvider *)bmpControl->itemProvider();
provider->drawEmphasis( bmpControl, event, false );
/***********************************************************************/
/* Construct dropped .BMP file name from this drag item and attempt to */
/* load the bitmap from a system file */
/***********************************************************************/
IString
fname = containerName() + sourceName();
IGBitmap
bitMap( fname );
/***********************************************************************/
/* If bitmap was successfully loaded, then set it. Note that the old */
/* one will be automatically deleted. */
/***********************************************************************/
if (bitMap.handle())
{
bmpControl->setBitmap( bitMap.handle() );
/********************************************************************/
/* Indicate name of dropped file. */
/********************************************************************/
bmpControl->setText( fname );
}
else
{
bmpControl->setText( "Couldn't create bitmap!" );
}
return( true );
}
/*------------------------------------------------------------------------------
| ABitmapProvider::provideEnterSupport |
| |
| Verify that we're dealing with a bitmap object before |
| allowing a drop, as well as draw the target emphasis. |
------------------------------------------------------------------------------*/
Boolean ABitmapProvider :: provideEnterSupport ( IDMTargetEnterEvent& event )
{
/***********************************************************************/
/* Get handle to the drag target operation */
/***********************************************************************/
IDMTargetOperation::Handle targetOp = IDMTargetOperation::targetOperation();
/***********************************************************************/
/* Get pointer to the target bitmap control. */
/***********************************************************************/
IBitmapControl
*bmpControl = (IBitmapControl *)event.window();
/***********************************************************************/
/* Draw the target emphasis. */
/***********************************************************************/
drawEmphasis( bmpControl, event );
/***********************************************************************/
/* Filter the types of items that we allow to be dropped. */
/***********************************************************************/
IDMItem::Handle pTgtDIH = targetOp->item(1);
IString strTypes = pTgtDIH->types();
/***********************************************************************/
/* If type is either "Bitmap" or "Plain Text" (used by WPS), we can */
/* display the drag item. If type is "Plain Text", then filter based */
/* upon the ".bmp" extension. */
/***********************************************************************/
if (strTypes.indexOf( IDM::bitmap ))
{
return( true );
}
else
{
if ((strTypes.includes( IDM::plainText )) &&
(pTgtDIH->sourceName().lowerCase().includes( ".bmp" )))
{
return( true );
}
}
/***********************************************************************/
/* Type is not recognized - set the drop indicator to prevent a drop! */
/***********************************************************************/
event.setDropIndicator( IDM::neverOk );
return( false );
}
/*------------------------------------------------------------------------------
| ABitmapProvider::provideLeaveSupport |
| |
| Remove the target emphasis. |
------------------------------------------------------------------------------*/
Boolean ABitmapProvider :: provideLeaveSupport ( IDMTargetLeaveEvent& event )
{
/***********************************************************************/
/* Get pointer to the target bitmap control. */
/***********************************************************************/
IBitmapControl
*bmpControl = (IBitmapControl *)event.window();
/***********************************************************************/
/* Remove the target emphasis. */
/***********************************************************************/
drawEmphasis( bmpControl, event, false );
return(true);
}
/*------------------------------------------------------------------------------
| ABitmapProvider::drawEmphasis |
| |
| Draw/remove the target emphasis |
------------------------------------------------------------------------------*/
ABitmapProvider& ABitmapProvider::drawEmphasis ( IBitmapControl* bmpControl,
IDMTargetEvent& event,
Boolean bDraw )
{
/***********************************************************************/
/* Return if the request is to draw the emphasis, and its already */
/* drawn. */
/***********************************************************************/
if (bDraw && bAlreadyDrawn)
return( *this );
if (bDraw)
bAlreadyDrawn = true;
else
bAlreadyDrawn = false;
/***********************************************************************/
/* Create the graphic context and set the mix mode to cause the pen */
/* color to be the inverse of the drawing surface. Also, set the draw */
/* operation, so that only the frame of the rectangle is drawn. */
/***********************************************************************/
IGraphicContext
graphicContext( event.presSpace() );
graphicContext.setMixMode( IGraphicBundle::invert )
.setDrawOperation( IGraphicBundle::frame );
/***********************************************************************/
/* Define the points for the emphasis rectangle and adjust their */
/* position so the rectangle will fit within the control window. */
/***********************************************************************/
IPoint
origin ( bmpControl->rect().left(), bmpControl->rect().bottom() ),
topRight( bmpControl->rect().width(), bmpControl->rect().height() );
origin -= 2;
topRight -= 4;
/***********************************************************************/
/* Create an IRectangle object based upon the points defined and use */
/* it to construct a 2-Dimensional rectangle object: IGRectangle. */
/* Draw the emphasis rectangle using the IGRectangle object. */
/***********************************************************************/
IGRectangle
graphicRectangle( IRectangle( origin, topRight ) );
graphicRectangle.drawOn( graphicContext );
/***********************************************************************/
/* Release presentation space and return. */
/***********************************************************************/
event.releasePresSpace();
return( *this );
}