home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xwindrag.cpp < prev   
C/C++ Source or Header  |  1997-02-23  |  5KB  |  181 lines

  1. #include "XWindow.h"
  2. #include "XWinDrag.h"
  3. #include "XDragItm.h"
  4. #include "XBitmap.h"
  5. #include "XIcon.h"
  6.  
  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.  
  64. void XWindowDrag::SetDragItem(const XDragItem * item, const SHORT number)
  65. {
  66.     DrgSetDragitem(pInfo, item->item, sizeof(DRAGITEM), number);
  67. }
  68.  
  69.  
  70. void XWindowDrag::GetDragItem(XDragItem * item, const SHORT number)
  71. {
  72.     DrgQueryDragitem(pInfo, sizeof(DRAGITEM), item->item, number);
  73. }
  74.  
  75.  
  76. XDragItem :: XDragItem(const XWindow * sourceWindow, const SHORT operation, const LONG id, const char *type, const char *mechanism)
  77. {
  78.     item = (DRAGITEM *) malloc(sizeof(DRAGITEM));
  79.     memset(item, 0, sizeof(DRAGITEM));
  80.     allocated = TRUE;
  81.     item->hwndItem = sourceWindow->GetHandle();
  82.     item->ulItemID = (ULONG) id;
  83.     item->hstrType = DrgAddStrHandle((PSZ) type);
  84.     item->hstrRMF = DrgAddStrHandle((PSZ) mechanism);
  85.     item->fsControl = 0;
  86.     item->fsSupportedOps = operation;
  87. }
  88.  
  89.  
  90. void XDragItem::SetMechanism(const char *m)
  91. {
  92.     item->hstrRMF = DrgAddStrHandle((PSZ) m);
  93. }
  94.  
  95.  
  96. void XDragItem::EndConversation(const BOOL success)
  97. {
  98.     LONG t = DMFL_TARGETSUCCESSFUL;
  99.  
  100.     if (success == FALSE)
  101.         t = DMFL_TARGETFAIL;
  102.     DrgSendTransferMsg(item->hwndItem, DM_ENDCONVERSATION, MPFROMLONG(item->ulItemID), MPFROMLONG(t));
  103. }
  104.  
  105.  
  106. void XDragItem::GetTargetName(XString * target)
  107. {
  108.     DrgQueryStrName(item->hstrTargetName, 512, (PSZ) target->GetBuffer(512));
  109.     target->ReleaseBuffer();
  110. }
  111.  
  112.  
  113. void XDragItem::GetName(XString * sourceName)
  114. {
  115.     DrgQueryStrName(item->hstrSourceName, 512, (PSZ) sourceName->GetBuffer(512));
  116.     sourceName->ReleaseBuffer();
  117. }
  118.  
  119.  
  120. void XDragItem::GetMechanism(XString * mechanism)
  121. {
  122.     DrgQueryStrName(item->hstrRMF, 512, (PSZ) mechanism->GetBuffer(512));
  123.     mechanism->ReleaseBuffer();
  124. }
  125.  
  126.  
  127. void XDragItem::GetType(XString * type)
  128. {
  129.     DrgQueryStrName(item->hstrType, 512, (PSZ) type->GetBuffer(512));
  130.     type->ReleaseBuffer();
  131. }
  132.  
  133.  
  134. void XDragItem::GetContainerName(XString * containerName)
  135. {
  136.     DrgQueryStrName(item->hstrContainerName, 512, (PSZ) containerName->GetBuffer(512));
  137.     containerName->ReleaseBuffer();
  138. }
  139.  
  140.  
  141. void XDragItem::Accept(const BOOL accept)
  142. {
  143.     if (accept)
  144.         DrgSendTransferMsg(item->hwndItem, DM_ENDCONVERSATION, (MPARAM) item->ulItemID, MPFROMLONG(DMFL_TARGETSUCCESSFUL));
  145.     else
  146.         DrgSendTransferMsg(item->hwndItem, DM_ENDCONVERSATION, (MPARAM) item->ulItemID, MPFROMLONG(DMFL_TARGETFAIL));
  147. }
  148.  
  149.  
  150. BOOL XDragItem::VerifyItemType(const char *mechanism, const char *format)
  151. {
  152.     return DrgVerifyRMF(item, (PSZ) mechanism, (PSZ) format);
  153. }
  154.  
  155.  
  156. void XDragItem::SetContainerName(const char *containerName)
  157. {
  158.     item->hstrContainerName = DrgAddStrHandle((PSZ) containerName);
  159. }
  160.  
  161.  
  162. void XDragItem::SetName(const char *name)
  163. {
  164.     item->hstrSourceName = DrgAddStrHandle((PSZ) name);
  165. }
  166.  
  167.  
  168. void XDragItem::SetTargetName(const char *target)
  169. {
  170.     item->hstrTargetName = DrgAddStrHandle((PSZ) target);
  171. }
  172.  
  173.  
  174. XDragItem :: ~XDragItem()
  175. {
  176. /*
  177.     if(allocated)
  178.         free( item );
  179. */
  180. }
  181.