home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xwindrag.cpp < prev    next >
C/C++ Source or Header  |  1998-04-05  |  7KB  |  256 lines

  1. #include "XWindow.h"
  2. #include "XWinDrag.h"
  3. #include "XDragItm.h"
  4. #include "XBitmap.h"
  5. #include "XIcon.h"
  6. #include "xprocess.h"
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10.  
  11. XWindowDrag :: XWindowDrag(const XWindow * owner, const SHORT itemCount)
  12. {
  13.    count = itemCount;
  14.    ownerWindow = (XWindow *) owner;
  15.    pInfo = DrgAllocDraginfo(count);
  16.    imageCount = 0;
  17.    pImage = NULL;
  18. }
  19.  
  20.  
  21. XWindowDrag :: ~XWindowDrag()
  22. {
  23. /*
  24.    free( pImage );
  25.    DrgDeleteDraginfoStrHandles( pInfo );
  26.    DrgFreeDraginfo( pInfo );
  27. */
  28. }
  29.  
  30.  
  31. OOL_WINDOWHANDLE XWindowDrag::PerformDrag(void)
  32. {
  33.    return DrgDrag(ownerWindow->GetHandle(), pInfo, pImage, imageCount, VK_BUTTON2, NULL);
  34. }
  35.  
  36.  
  37. void XWindowDrag::AddImage(const XIcon * icon, const SHORT style, const SHORT xOffset, const SHORT yOffset, const SHORT stretch)
  38. {
  39.    imageCount += 1;
  40.    pImage = (DRAGIMAGE *) realloc(pImage, sizeof(DRAGIMAGE) * imageCount);
  41.    pImage[imageCount - 1].cb = sizeof(DRAGIMAGE);
  42.    pImage[imageCount - 1].cxOffset = xOffset;
  43.    pImage[imageCount - 1].cyOffset = yOffset;
  44.    pImage[imageCount - 1].hImage = icon->GetHandle();
  45.    pImage[imageCount - 1].fl = style | IMG_ICON;
  46.    pImage[imageCount - 1].sizlStretch.cx = pImage[imageCount - 1].sizlStretch.cy = stretch;
  47. }
  48.  
  49.  
  50. void XWindowDrag::AddImage(const XBitmap * bmp, const SHORT style, const SHORT xOffset, const SHORT yOffset, const SHORT stretch)
  51. {
  52.    imageCount += 1;
  53.    pImage = (DRAGIMAGE *) realloc(pImage, sizeof(DRAGIMAGE) * imageCount);
  54.    pImage[imageCount - 1].cb = sizeof(DRAGIMAGE);
  55.    pImage[imageCount - 1].cxOffset = xOffset;
  56.    pImage[imageCount - 1].cyOffset = yOffset;
  57.    pImage[imageCount - 1].hImage = bmp->GetHandle();
  58.    pImage[imageCount - 1].fl = style | IMG_BITMAP;
  59.    pImage[imageCount - 1].sizlStretch.cx = pImage[imageCount - 1].sizlStretch.cy = stretch;
  60. }
  61.  
  62.  
  63. void XWindowDrag::SetDragItem(const XDragItem * item, const SHORT number)
  64. {
  65.    DrgSetDragitem(pInfo, item->item, sizeof(DRAGITEM), number);
  66. }
  67.  
  68.  
  69. void XWindowDrag::GetDragItem(XDragItem * item, const SHORT number)
  70. {
  71. //   DrgQueryDragitem(pInfo, sizeof(DRAGITEM), item->item, number);
  72.    item->item = DrgQueryDragitemPtr(pInfo, number);
  73. }
  74.  
  75.  
  76. XDragItem :: XDragItem(const XWindow * sourceWindow, const SHORT operation, const LONG id, const char *type, const char *mechanism)
  77. {
  78.    trans = NULL;
  79.    item = (DRAGITEM *) malloc(sizeof(DRAGITEM));
  80.    memset(item, 0, sizeof(DRAGITEM));
  81.    allocated = TRUE;
  82.    item->hwndItem = sourceWindow->GetHandle();
  83.    item->ulItemID = (ULONG) id;
  84.    item->hstrType = DrgAddStrHandle((PSZ) type);
  85.    item->hstrRMF = DrgAddStrHandle((PSZ) mechanism);
  86.    item->fsControl = 0;
  87.    item->fsSupportedOps = operation;
  88. }
  89.  
  90.  
  91. BOOL XDragItem :: RenderPrepare( const XWindow * target, const USHORT operation, const USHORT reply, const char * mechanism, const char * container, ULONG& support)
  92. {
  93.    if(trans == NULL)
  94.    {
  95.       trans = DrgAllocDragtransfer(1);
  96.       trans->cb = sizeof(trans);
  97.       trans->hwndClient = target->GetHandle();
  98.       trans->pditem = item;
  99.    }
  100.    else
  101.    {
  102.       DrgDeleteStrHandle( trans->hstrSelectedRMF );
  103.       DrgDeleteStrHandle( trans->hstrRenderToName );
  104.    }
  105.  
  106.    trans->hstrSelectedRMF = DrgAddStrHandle( (char*) mechanism);
  107.    trans->hstrRenderToName = DrgAddStrHandle( (char*) container );
  108.  
  109.    trans->usOperation = operation;
  110.    trans->fsReply = reply;
  111.    BOOL result = (BOOL) DrgSendTransferMsg( trans->pditem->hwndItem, DM_RENDERPREPARE, MPFROMP(trans), 0);
  112.    support = trans->fsReply;
  113.  
  114.    return result;
  115. }
  116.  
  117.  
  118. BOOL XDragItem :: Render( const XWindow * target, const USHORT operation, const USHORT reply, const char * mechanism, const char * container, ULONG& support)
  119. {
  120.    if(trans ==  NULL)
  121.    {
  122.       trans = DrgAllocDragtransfer(1);
  123.       trans->cb = sizeof(trans);
  124.       trans->hwndClient = target->GetHandle();
  125.       trans->pditem = item;
  126.    }
  127.    else
  128.    {
  129.       DrgDeleteStrHandle( trans->hstrSelectedRMF );
  130.       DrgDeleteStrHandle( trans->hstrRenderToName );
  131.    }
  132.  
  133.    trans->hstrSelectedRMF = DrgAddStrHandle( (char*) mechanism);
  134.    trans->hstrRenderToName = DrgAddStrHandle( (char*) container );
  135.    trans->usOperation = operation;
  136.    trans->fsReply = reply;
  137.  
  138.    BOOL result = (BOOL) DrgSendTransferMsg( item->hwndItem, DM_RENDER, MPFROMP(trans), 0);
  139.    support = trans->fsReply;
  140.    return result;
  141. }
  142.  
  143. void XDragItem :: SetControlOps( const USHORT ops)
  144. {
  145.    item->fsControl = ops;
  146. }
  147.  
  148.  
  149. USHORT XDragItem :: GetControlOps( ) const
  150. {
  151.    return item->fsControl;
  152. }
  153.  
  154.  
  155. void XDragItem :: SetSupportedOps( const USHORT ops)
  156. {
  157.    item->fsSupportedOps = ops;
  158. }
  159.  
  160.  
  161. void XDragItem::SetMechanism(const char *m)
  162. {
  163.    item->hstrRMF = DrgAddStrHandle((PSZ) m);
  164. }
  165.  
  166.  
  167. void XDragItem::EndConversation(const BOOL success)
  168. {
  169.    LONG t = DMFL_TARGETSUCCESSFUL;
  170.  
  171.    if (success == FALSE)
  172.       t = DMFL_TARGETFAIL;
  173.    DrgSendTransferMsg(item->hwndItem, DM_ENDCONVERSATION, MPFROMLONG(item->ulItemID), MPFROMLONG(t));
  174. }
  175.  
  176.  
  177. void XDragItem::GetTargetName(XString * target) const
  178. {
  179.    target->ReleaseBuffer(DrgQueryStrName(item->hstrTargetName, 512, (PSZ) target->GetBuffer(512)));
  180. }
  181.  
  182.  
  183. void XDragItem::GetName(XString * sourceName) const
  184. {
  185.    sourceName->ReleaseBuffer(DrgQueryStrName(item->hstrSourceName, 512, (PSZ) sourceName->GetBuffer(512)));
  186. }
  187.  
  188.  
  189. void XDragItem::GetMechanism(XString * mechanism) const
  190. {
  191.    mechanism->ReleaseBuffer(DrgQueryStrName(item->hstrRMF, 512, (PSZ) mechanism->GetBuffer(512)));
  192. }
  193.  
  194.  
  195. void XDragItem::GetType(XString * type) const
  196. {
  197.    type->ReleaseBuffer(DrgQueryStrName(item->hstrType, 512, (PSZ) type->GetBuffer(512)));
  198. }
  199.  
  200.  
  201. void XDragItem::SetType(const char * type)
  202. {
  203.      item->hstrType = DrgAddStrHandle((PSZ) type);
  204. }
  205.  
  206.  
  207. void XDragItem::GetContainerName(XString * containerName) const
  208. {
  209.    containerName->ReleaseBuffer(DrgQueryStrName(item->hstrContainerName, 512, (PSZ) containerName->GetBuffer(512)));
  210. }
  211.  
  212.  
  213. void XDragItem::Accept(const BOOL accept)
  214. {
  215.    if (accept)
  216.       DrgSendTransferMsg(item->hwndItem, DM_ENDCONVERSATION, (MPARAM) item->ulItemID, MPFROMLONG(DMFL_TARGETSUCCESSFUL));
  217.    else
  218.       DrgSendTransferMsg(item->hwndItem, DM_ENDCONVERSATION, (MPARAM) item->ulItemID, MPFROMLONG(DMFL_TARGETFAIL));
  219. }
  220.  
  221.  
  222. BOOL XDragItem::VerifyItemType(const char *mechanism, const char *format)
  223. {
  224.    return DrgVerifyRMF(item, (PSZ) mechanism, (PSZ) format);
  225. }
  226.  
  227.  
  228. void XDragItem::SetContainerName(const char *containerName)
  229. {
  230.    item->hstrContainerName = DrgAddStrHandle((PSZ) containerName);
  231. }
  232.  
  233.  
  234. void XDragItem::SetName(const char *name)
  235. {
  236.    item->hstrSourceName = DrgAddStrHandle((PSZ) name);
  237. }
  238.  
  239.  
  240. void XDragItem::SetTargetName(const char *target)
  241. {
  242.    item->hstrTargetName = DrgAddStrHandle((PSZ) target);
  243. }
  244.  
  245.  
  246. XDragItem :: ~XDragItem()
  247. {
  248. /*
  249.    if(allocated)
  250.       free( item );
  251.  
  252.    if(trans)
  253.       DrgFreeDragtransfer(trans);
  254. */
  255. }
  256.