< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_DnDDS.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 249             sdrp->imageHeight,
 250             sdrp->x,
 251             sdrp->y,
 252             (IDataObject*)dragSource);
 253         env->DeleteGlobalRef(sdrp->imageData);
 254     }
 255     dragSource->SetCursor(sdrp->cursor);
 256     env->DeleteGlobalRef(sdrp->cursor);
 257     delete sdrp;
 258 
 259     HRESULT        res;
 260 
 261     // StartDrag has caused dragSource->m_mutex to be held by our thread now
 262 
 263     AwtDropTarget::SetCurrentDnDDataObject(dragSource);
 264 
 265     ::GetCursorPos(&dragSource->m_dragPoint);
 266 
 267     dragSource->Signal();
 268 


 269     res = ::DoDragDrop(dragSource,
 270                        dragSource,
 271                        convertActionsToDROPEFFECT(dragSource->m_actions),
 272                        &effects
 273           );

 274 
 275     if (effects == DROPEFFECT_NONE && dragSource->m_dwPerformedDropEffect != DROPEFFECT_NONE) {
 276         effects = dragSource->m_dwPerformedDropEffect;
 277     }
 278     dragSource->m_dwPerformedDropEffect = DROPEFFECT_NONE;
 279 
 280     call_dSCddfinished(env, peer, res == DRAGDROP_S_DROP && effects != DROPEFFECT_NONE,
 281                        convertDROPEFFECTToActions(effects),
 282                        dragSource->m_dragPoint.x, dragSource->m_dragPoint.y);
 283 
 284     env->DeleteLocalRef(peer);
 285 
 286     DASSERT(AwtDropTarget::IsCurrentDnDDataObject(dragSource));
 287     AwtDropTarget::SetCurrentDnDDataObject(NULL);
 288 
 289     PictureDragHelper::Destroy();
 290     dragSource->Release();
 291 }
 292 
 293 /**


 609     return (ULONG)++m_refs;
 610 }
 611 
 612 /**
 613  * Release
 614  */
 615 
 616 ULONG __stdcall AwtDragSource::Release() {
 617     int refs;
 618 
 619     if ((refs = --m_refs) == 0) delete this;
 620 
 621     return (ULONG)refs;
 622 }
 623 
 624 /**
 625  * QueryContinueDrag
 626  */
 627 
 628 HRESULT __stdcall  AwtDragSource::QueryContinueDrag(BOOL fEscapeKeyPressed, DWORD grfKeyState) {

 629     TRY;
 630 
 631     JNIEnv* env       = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 632 
 633     if (fEscapeKeyPressed)
 634         return DRAGDROP_S_CANCEL;
 635 
 636     jint modifiers = AwtComponent::GetJavaModifiers();
 637 
 638     POINT dragPoint;
 639 
 640     ::GetCursorPos(&dragPoint);
 641 
 642     if ( (dragPoint.x != m_dragPoint.x || dragPoint.y != m_dragPoint.y) &&
 643          m_lastmods == modifiers) {//cannot move before cursor change
 644         call_dSCmouseMoved(env, m_peer,
 645                            m_actions, modifiers, dragPoint.x, dragPoint.y);
 646         JNU_CHECK_EXCEPTION_RETURN(env, E_UNEXPECTED);
 647         m_dragPoint = dragPoint;
 648     }


 664     //CR 6480706 - MS Bug on hold
 665     HCURSOR hNeedCursor;
 666     if (
 667         m_bRestoreNodropCustomCursor &&
 668         m_cursor != NULL &&
 669         (hNeedCursor = m_cursor->GetHCursor()) != ::GetCursor() )
 670     {
 671         ChangeCursor();
 672         m_bRestoreNodropCustomCursor = FALSE;
 673     }
 674     return S_OK;
 675 
 676    CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
 677 }
 678 
 679 /**
 680  * GiveFeedback
 681  */
 682 
 683 HRESULT __stdcall  AwtDragSource::GiveFeedback(DWORD dwEffect) {

 684     TRY;
 685 
 686     JNIEnv* env       = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 687     jint    modifiers = 0;
 688     SHORT   mods = 0;
 689 
 690     m_actions = convertDROPEFFECTToActions(dwEffect);
 691 
 692     if (::GetKeyState(VK_LBUTTON) & 0xff00) {
 693         mods |= MK_LBUTTON;
 694     } else if (::GetKeyState(VK_MBUTTON) & 0xff00) {
 695         mods |= MK_MBUTTON;
 696     } else if (::GetKeyState(VK_RBUTTON) & 0xff00) {
 697         mods |= MK_RBUTTON;
 698     }
 699 
 700     if (::GetKeyState(VK_SHIFT)   & 0xff00)
 701         mods |= MK_SHIFT;
 702     if (::GetKeyState(VK_CONTROL) & 0xff00)
 703         mods |= MK_CONTROL;


 743     } else {
 744         m_fNC = TRUE;
 745         m_dropPoint.x = 0;
 746         m_dropPoint.y = 0;
 747     }
 748 
 749     m_bRestoreNodropCustomCursor = (dwEffect == DROPEFFECT_NONE);
 750 
 751     return ChangeCursor();
 752 
 753     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
 754 }
 755 
 756 
 757 /**
 758  * GetData
 759  */
 760 
 761 HRESULT __stdcall AwtDragSource::GetData(FORMATETC __RPC_FAR *pFormatEtc,
 762                                          STGMEDIUM __RPC_FAR *pmedium) {

 763     TRY;
 764     STGMEDIUM *pPicMedia = PictureDragHelper::FindData(*pFormatEtc);
 765     if (NULL != pPicMedia) {
 766         *pmedium = *pPicMedia;
 767         //return  outside, so AddRef the instance of pstm or hGlobal!
 768         if (pmedium->tymed == TYMED_ISTREAM) {
 769             pmedium->pstm->AddRef();
 770             pmedium->pUnkForRelease = (IUnknown *)NULL;
 771         } else if (pmedium->tymed == TYMED_HGLOBAL) {
 772             AddRef();
 773             pmedium->pUnkForRelease = (IDropSource *)this;
 774         }
 775         return S_OK;
 776     }
 777 
 778     HRESULT res = GetProcessId(pFormatEtc, pmedium);
 779     if (res == S_OK) {
 780         return res;
 781     }
 782 


 917         pmedium->tymed = TYMED_MFPICT;
 918         pmedium->hMetaFilePict = hmfp;
 919         pmedium->pUnkForRelease = (IUnknown *)NULL;
 920 
 921         env->PopLocalFrame(NULL);
 922         return S_OK;
 923     }
 924 
 925     env->PopLocalFrame(NULL);
 926     return DV_E_TYMED;
 927 
 928     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
 929 }
 930 
 931 /**
 932  * GetDataHere
 933  */
 934 
 935 HRESULT __stdcall AwtDragSource::GetDataHere(FORMATETC __RPC_FAR *pFormatEtc,
 936                                              STGMEDIUM __RPC_FAR *pmedium) {

 937     TRY;
 938 
 939     if (pmedium->pUnkForRelease != (IUnknown *)NULL) {
 940         return E_INVALIDARG;
 941     }
 942 
 943     HRESULT res = GetProcessId(pFormatEtc, pmedium);
 944     if (res == S_OK) {
 945         return res;
 946     }
 947 
 948     FORMATETC matchedFormatEtc;
 949     res = MatchFormatEtc(pFormatEtc, &matchedFormatEtc);
 950     if (res != S_OK) {
 951         return res;
 952     }
 953 
 954     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 955 
 956     if (env->PushLocalFrame(2) < 0) {


1019         }
1020 
1021         env->GetByteArrayRegion(bytes, 0, nBytes, (jbyte *)dataout);
1022         ::GlobalUnlock(pmedium->hGlobal);
1023 
1024         env->PopLocalFrame(NULL);
1025         return S_OK;
1026     }
1027 
1028     env->PopLocalFrame(NULL);
1029     return DV_E_TYMED;
1030 
1031     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
1032 }
1033 
1034 /**
1035  * QueryGetData
1036  */
1037 
1038 HRESULT __stdcall  AwtDragSource::QueryGetData(FORMATETC __RPC_FAR *pFormatEtc) {

1039     TRY;
1040 
1041     return MatchFormatEtc(pFormatEtc, (FORMATETC *)NULL);
1042 
1043     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
1044 }
1045 
1046 
1047 /**
1048  * GetCanonicalFormatEtc
1049  */
1050 
1051 HRESULT __stdcall  AwtDragSource::GetCanonicalFormatEtc(FORMATETC __RPC_FAR *pFormatEtcIn, FORMATETC __RPC_FAR *pFormatEtcOut) {

1052     TRY;
1053 
1054     HRESULT   res = MatchFormatEtc(pFormatEtcIn, (FORMATETC *)NULL);
1055 
1056     if (res != S_OK) return res;
1057 
1058     *pFormatEtcOut = *pFormatEtcIn;
1059 
1060     pFormatEtcOut->ptd = NULL;
1061 
1062     return DATA_S_SAMEFORMATETC;
1063 
1064     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
1065 }
1066 
1067 /**
1068  * SetData
1069  */
1070 
1071 HRESULT __stdcall AwtDragSource::SetData(FORMATETC __RPC_FAR *pFormatEtc, STGMEDIUM __RPC_FAR *pmedium, BOOL fRelease) {

1072     if (pFormatEtc->cfFormat == CF_PERFORMEDDROPEFFECT && pmedium->tymed == TYMED_HGLOBAL) {
1073         m_dwPerformedDropEffect = *(DWORD*)::GlobalLock(pmedium->hGlobal);
1074         ::GlobalUnlock(pmedium->hGlobal);
1075         if (fRelease) {
1076             ::ReleaseStgMedium(pmedium);
1077         }
1078         return S_OK;
1079     }
1080 
1081     if (fRelease) {
1082         //we are copying pmedium as a structure for further use, so no any release!
1083         PictureDragHelper::SetData(*pFormatEtc, *pmedium);
1084         return S_OK;
1085     }
1086     return E_UNEXPECTED;
1087 }
1088 
1089 /**
1090  * EnumFormatEtc
1091  */
1092 
1093 HRESULT __stdcall  AwtDragSource::EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC *__RPC_FAR *ppenumFormatEtc) {

1094     TRY;
1095 
1096     *ppenumFormatEtc = new ADSIEnumFormatEtc(this);
1097     return S_OK;
1098 
1099     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
1100 }
1101 
1102 /**
1103  * DAdvise
1104  */
1105 
1106 HRESULT __stdcall  AwtDragSource::DAdvise(FORMATETC __RPC_FAR *pFormatEtc, DWORD advf, IAdviseSink __RPC_FAR *pAdvSink, DWORD __RPC_FAR *pdwConnection) {

1107     return E_NOTIMPL;
1108 }
1109 
1110 /**
1111  * DUnadvise
1112  */
1113 
1114 HRESULT __stdcall  AwtDragSource::DUnadvise(DWORD dwConnection) {

1115     return OLE_E_ADVISENOTSUPPORTED;
1116 }
1117 
1118 /**
1119  * EnumAdvise
1120  */
1121 
1122 HRESULT __stdcall  AwtDragSource::EnumDAdvise(IEnumSTATDATA __RPC_FAR *__RPC_FAR *ppenumAdvise) {

1123     return OLE_E_ADVISENOTSUPPORTED;
1124 }
1125 
1126 const UINT AwtDragSource::PROCESS_ID_FORMAT =
1127     ::RegisterClipboardFormat(TEXT("_SUNW_JAVA_AWT_PROCESS_ID"));
1128 
1129 HRESULT __stdcall AwtDragSource::GetProcessId(FORMATETC __RPC_FAR *pFormatEtc, STGMEDIUM __RPC_FAR *pmedium) {
1130 
1131     if ((pFormatEtc->tymed & TYMED_HGLOBAL) == 0) {
1132         return DV_E_TYMED;
1133     } else if (pFormatEtc->lindex != -1) {
1134         return DV_E_LINDEX;
1135     } else if (pFormatEtc->dwAspect != DVASPECT_CONTENT) {
1136         return DV_E_DVASPECT;
1137     } else if (pFormatEtc->cfFormat != PROCESS_ID_FORMAT) {
1138         return DV_E_FORMATETC;
1139     }
1140 
1141     DWORD id = ::CoGetCurrentProcess();
1142 
1143     HGLOBAL copy = ::GlobalAlloc(GALLOCFLG, sizeof(id));
1144 
1145     if (copy == NULL) {
1146         throw std::bad_alloc();
1147     }
1148 
1149     char *dataout = (char *)::GlobalLock(copy);
1150 


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 249             sdrp->imageHeight,
 250             sdrp->x,
 251             sdrp->y,
 252             (IDataObject*)dragSource);
 253         env->DeleteGlobalRef(sdrp->imageData);
 254     }
 255     dragSource->SetCursor(sdrp->cursor);
 256     env->DeleteGlobalRef(sdrp->cursor);
 257     delete sdrp;
 258 
 259     HRESULT        res;
 260 
 261     // StartDrag has caused dragSource->m_mutex to be held by our thread now
 262 
 263     AwtDropTarget::SetCurrentDnDDataObject(dragSource);
 264 
 265     ::GetCursorPos(&dragSource->m_dragPoint);
 266 
 267     dragSource->Signal();
 268 
 269     AwtToolkit &toolkit = AwtToolkit::GetInstance();
 270     toolkit.isInDoDragDropLoop = TRUE;
 271     res = ::DoDragDrop(dragSource,
 272                        dragSource,
 273                        convertActionsToDROPEFFECT(dragSource->m_actions),
 274                        &effects
 275           );
 276     toolkit.isInDoDragDropLoop = FALSE;
 277 
 278     if (effects == DROPEFFECT_NONE && dragSource->m_dwPerformedDropEffect != DROPEFFECT_NONE) {
 279         effects = dragSource->m_dwPerformedDropEffect;
 280     }
 281     dragSource->m_dwPerformedDropEffect = DROPEFFECT_NONE;
 282 
 283     call_dSCddfinished(env, peer, res == DRAGDROP_S_DROP && effects != DROPEFFECT_NONE,
 284                        convertDROPEFFECTToActions(effects),
 285                        dragSource->m_dragPoint.x, dragSource->m_dragPoint.y);
 286 
 287     env->DeleteLocalRef(peer);
 288 
 289     DASSERT(AwtDropTarget::IsCurrentDnDDataObject(dragSource));
 290     AwtDropTarget::SetCurrentDnDDataObject(NULL);
 291 
 292     PictureDragHelper::Destroy();
 293     dragSource->Release();
 294 }
 295 
 296 /**


 612     return (ULONG)++m_refs;
 613 }
 614 
 615 /**
 616  * Release
 617  */
 618 
 619 ULONG __stdcall AwtDragSource::Release() {
 620     int refs;
 621 
 622     if ((refs = --m_refs) == 0) delete this;
 623 
 624     return (ULONG)refs;
 625 }
 626 
 627 /**
 628  * QueryContinueDrag
 629  */
 630 
 631 HRESULT __stdcall  AwtDragSource::QueryContinueDrag(BOOL fEscapeKeyPressed, DWORD grfKeyState) {
 632     AwtToolkit::GetInstance().eventNumber++;
 633     TRY;
 634 
 635     JNIEnv* env       = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 636 
 637     if (fEscapeKeyPressed)
 638         return DRAGDROP_S_CANCEL;
 639 
 640     jint modifiers = AwtComponent::GetJavaModifiers();
 641 
 642     POINT dragPoint;
 643 
 644     ::GetCursorPos(&dragPoint);
 645 
 646     if ( (dragPoint.x != m_dragPoint.x || dragPoint.y != m_dragPoint.y) &&
 647          m_lastmods == modifiers) {//cannot move before cursor change
 648         call_dSCmouseMoved(env, m_peer,
 649                            m_actions, modifiers, dragPoint.x, dragPoint.y);
 650         JNU_CHECK_EXCEPTION_RETURN(env, E_UNEXPECTED);
 651         m_dragPoint = dragPoint;
 652     }


 668     //CR 6480706 - MS Bug on hold
 669     HCURSOR hNeedCursor;
 670     if (
 671         m_bRestoreNodropCustomCursor &&
 672         m_cursor != NULL &&
 673         (hNeedCursor = m_cursor->GetHCursor()) != ::GetCursor() )
 674     {
 675         ChangeCursor();
 676         m_bRestoreNodropCustomCursor = FALSE;
 677     }
 678     return S_OK;
 679 
 680    CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
 681 }
 682 
 683 /**
 684  * GiveFeedback
 685  */
 686 
 687 HRESULT __stdcall  AwtDragSource::GiveFeedback(DWORD dwEffect) {
 688     AwtToolkit::GetInstance().eventNumber++;
 689     TRY;
 690 
 691     JNIEnv* env       = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 692     jint    modifiers = 0;
 693     SHORT   mods = 0;
 694 
 695     m_actions = convertDROPEFFECTToActions(dwEffect);
 696 
 697     if (::GetKeyState(VK_LBUTTON) & 0xff00) {
 698         mods |= MK_LBUTTON;
 699     } else if (::GetKeyState(VK_MBUTTON) & 0xff00) {
 700         mods |= MK_MBUTTON;
 701     } else if (::GetKeyState(VK_RBUTTON) & 0xff00) {
 702         mods |= MK_RBUTTON;
 703     }
 704 
 705     if (::GetKeyState(VK_SHIFT)   & 0xff00)
 706         mods |= MK_SHIFT;
 707     if (::GetKeyState(VK_CONTROL) & 0xff00)
 708         mods |= MK_CONTROL;


 748     } else {
 749         m_fNC = TRUE;
 750         m_dropPoint.x = 0;
 751         m_dropPoint.y = 0;
 752     }
 753 
 754     m_bRestoreNodropCustomCursor = (dwEffect == DROPEFFECT_NONE);
 755 
 756     return ChangeCursor();
 757 
 758     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
 759 }
 760 
 761 
 762 /**
 763  * GetData
 764  */
 765 
 766 HRESULT __stdcall AwtDragSource::GetData(FORMATETC __RPC_FAR *pFormatEtc,
 767                                          STGMEDIUM __RPC_FAR *pmedium) {
 768     AwtToolkit::GetInstance().eventNumber++;
 769     TRY;
 770     STGMEDIUM *pPicMedia = PictureDragHelper::FindData(*pFormatEtc);
 771     if (NULL != pPicMedia) {
 772         *pmedium = *pPicMedia;
 773         //return  outside, so AddRef the instance of pstm or hGlobal!
 774         if (pmedium->tymed == TYMED_ISTREAM) {
 775             pmedium->pstm->AddRef();
 776             pmedium->pUnkForRelease = (IUnknown *)NULL;
 777         } else if (pmedium->tymed == TYMED_HGLOBAL) {
 778             AddRef();
 779             pmedium->pUnkForRelease = (IDropSource *)this;
 780         }
 781         return S_OK;
 782     }
 783 
 784     HRESULT res = GetProcessId(pFormatEtc, pmedium);
 785     if (res == S_OK) {
 786         return res;
 787     }
 788 


 923         pmedium->tymed = TYMED_MFPICT;
 924         pmedium->hMetaFilePict = hmfp;
 925         pmedium->pUnkForRelease = (IUnknown *)NULL;
 926 
 927         env->PopLocalFrame(NULL);
 928         return S_OK;
 929     }
 930 
 931     env->PopLocalFrame(NULL);
 932     return DV_E_TYMED;
 933 
 934     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
 935 }
 936 
 937 /**
 938  * GetDataHere
 939  */
 940 
 941 HRESULT __stdcall AwtDragSource::GetDataHere(FORMATETC __RPC_FAR *pFormatEtc,
 942                                              STGMEDIUM __RPC_FAR *pmedium) {
 943     AwtToolkit::GetInstance().eventNumber++;
 944     TRY;
 945 
 946     if (pmedium->pUnkForRelease != (IUnknown *)NULL) {
 947         return E_INVALIDARG;
 948     }
 949 
 950     HRESULT res = GetProcessId(pFormatEtc, pmedium);
 951     if (res == S_OK) {
 952         return res;
 953     }
 954 
 955     FORMATETC matchedFormatEtc;
 956     res = MatchFormatEtc(pFormatEtc, &matchedFormatEtc);
 957     if (res != S_OK) {
 958         return res;
 959     }
 960 
 961     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
 962 
 963     if (env->PushLocalFrame(2) < 0) {


1026         }
1027 
1028         env->GetByteArrayRegion(bytes, 0, nBytes, (jbyte *)dataout);
1029         ::GlobalUnlock(pmedium->hGlobal);
1030 
1031         env->PopLocalFrame(NULL);
1032         return S_OK;
1033     }
1034 
1035     env->PopLocalFrame(NULL);
1036     return DV_E_TYMED;
1037 
1038     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
1039 }
1040 
1041 /**
1042  * QueryGetData
1043  */
1044 
1045 HRESULT __stdcall  AwtDragSource::QueryGetData(FORMATETC __RPC_FAR *pFormatEtc) {
1046     AwtToolkit::GetInstance().eventNumber++;
1047     TRY;
1048 
1049     return MatchFormatEtc(pFormatEtc, (FORMATETC *)NULL);
1050 
1051     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
1052 }
1053 
1054 
1055 /**
1056  * GetCanonicalFormatEtc
1057  */
1058 
1059 HRESULT __stdcall  AwtDragSource::GetCanonicalFormatEtc(FORMATETC __RPC_FAR *pFormatEtcIn, FORMATETC __RPC_FAR *pFormatEtcOut) {
1060     AwtToolkit::GetInstance().eventNumber++;
1061     TRY;
1062 
1063     HRESULT   res = MatchFormatEtc(pFormatEtcIn, (FORMATETC *)NULL);
1064 
1065     if (res != S_OK) return res;
1066 
1067     *pFormatEtcOut = *pFormatEtcIn;
1068 
1069     pFormatEtcOut->ptd = NULL;
1070 
1071     return DATA_S_SAMEFORMATETC;
1072 
1073     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
1074 }
1075 
1076 /**
1077  * SetData
1078  */
1079 
1080 HRESULT __stdcall AwtDragSource::SetData(FORMATETC __RPC_FAR *pFormatEtc, STGMEDIUM __RPC_FAR *pmedium, BOOL fRelease) {
1081     AwtToolkit::GetInstance().eventNumber++;
1082     if (pFormatEtc->cfFormat == CF_PERFORMEDDROPEFFECT && pmedium->tymed == TYMED_HGLOBAL) {
1083         m_dwPerformedDropEffect = *(DWORD*)::GlobalLock(pmedium->hGlobal);
1084         ::GlobalUnlock(pmedium->hGlobal);
1085         if (fRelease) {
1086             ::ReleaseStgMedium(pmedium);
1087         }
1088         return S_OK;
1089     }
1090 
1091     if (fRelease) {
1092         //we are copying pmedium as a structure for further use, so no any release!
1093         PictureDragHelper::SetData(*pFormatEtc, *pmedium);
1094         return S_OK;
1095     }
1096     return E_UNEXPECTED;
1097 }
1098 
1099 /**
1100  * EnumFormatEtc
1101  */
1102 
1103 HRESULT __stdcall  AwtDragSource::EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC *__RPC_FAR *ppenumFormatEtc) {
1104     AwtToolkit::GetInstance().eventNumber++;
1105     TRY;
1106 
1107     *ppenumFormatEtc = new ADSIEnumFormatEtc(this);
1108     return S_OK;
1109 
1110     CATCH_BAD_ALLOC_RET(E_OUTOFMEMORY);
1111 }
1112 
1113 /**
1114  * DAdvise
1115  */
1116 
1117 HRESULT __stdcall  AwtDragSource::DAdvise(FORMATETC __RPC_FAR *pFormatEtc, DWORD advf, IAdviseSink __RPC_FAR *pAdvSink, DWORD __RPC_FAR *pdwConnection) {
1118     AwtToolkit::GetInstance().eventNumber++;
1119     return E_NOTIMPL;
1120 }
1121 
1122 /**
1123  * DUnadvise
1124  */
1125 
1126 HRESULT __stdcall  AwtDragSource::DUnadvise(DWORD dwConnection) {
1127     AwtToolkit::GetInstance().eventNumber++;
1128     return OLE_E_ADVISENOTSUPPORTED;
1129 }
1130 
1131 /**
1132  * EnumAdvise
1133  */
1134 
1135 HRESULT __stdcall  AwtDragSource::EnumDAdvise(IEnumSTATDATA __RPC_FAR *__RPC_FAR *ppenumAdvise) {
1136     AwtToolkit::GetInstance().eventNumber++;
1137     return OLE_E_ADVISENOTSUPPORTED;
1138 }
1139 
1140 const UINT AwtDragSource::PROCESS_ID_FORMAT =
1141     ::RegisterClipboardFormat(TEXT("_SUNW_JAVA_AWT_PROCESS_ID"));
1142 
1143 HRESULT __stdcall AwtDragSource::GetProcessId(FORMATETC __RPC_FAR *pFormatEtc, STGMEDIUM __RPC_FAR *pmedium) {
1144     AwtToolkit::GetInstance().eventNumber++;
1145     if ((pFormatEtc->tymed & TYMED_HGLOBAL) == 0) {
1146         return DV_E_TYMED;
1147     } else if (pFormatEtc->lindex != -1) {
1148         return DV_E_LINDEX;
1149     } else if (pFormatEtc->dwAspect != DVASPECT_CONTENT) {
1150         return DV_E_DVASPECT;
1151     } else if (pFormatEtc->cfFormat != PROCESS_ID_FORMAT) {
1152         return DV_E_FORMATETC;
1153     }
1154 
1155     DWORD id = ::CoGetCurrentProcess();
1156 
1157     HGLOBAL copy = ::GlobalAlloc(GALLOCFLG, sizeof(id));
1158 
1159     if (copy == NULL) {
1160         throw std::bad_alloc();
1161     }
1162 
1163     char *dataout = (char *)::GlobalLock(copy);
1164 


< prev index next >