rev 58018 : 8238575: DragSourceEvent.getLocation() returns wrong value on HiDPI screens (Windows)
Reviewed-by: XXX

   1 /*
   2  * Copyright (c) 1997, 2020, 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
  23  * questions.
  24  */
  25 
  26 #ifndef AWT_DND_DS_H
  27 #define AWT_DND_DS_H
  28 
  29 #include <Ole2.h>
  30 
  31 #include <jni.h>
  32 #include <jvm.h>
  33 #include <jni_util.h>
  34 
  35 #include "awt_Object.h"
  36 #include "awt_Component.h"
  37 #include "awt_Window.h"
  38 
  39 class AwtCursor;
  40 
  41 /**
  42  * Drag Source code
  43  */
  44 
  45 class AwtDragSource : virtual public IDropSource, virtual public IDataObject {
  46     public:
  47 
  48         AwtDragSource(JNIEnv* env, jobject peer, jobject component,
  49                       jobject transferable, jobject trigger,
  50                       jint actions, jlongArray formats, jobject formatMap);
  51 
  52         virtual ~AwtDragSource();
  53 
  54         // IUnknown
  55 
  56         virtual HRESULT __stdcall QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject);
  57 
  58         virtual ULONG   __stdcall AddRef(void);
  59         virtual ULONG   __stdcall Release(void);
  60 
  61         // IDropSource
  62 
  63         virtual HRESULT __stdcall QueryContinueDrag(BOOL fEscapeKeyPressed, DWORD grfKeyState);
  64 
  65         virtual HRESULT __stdcall GiveFeedback(DWORD dwEffect);
  66 
  67         // IDataObject
  68 
  69         virtual HRESULT __stdcall GetData(FORMATETC __RPC_FAR *pFormatEtc, STGMEDIUM __RPC_FAR *pmedium);
  70         virtual HRESULT __stdcall GetDataHere(FORMATETC __RPC_FAR *pFormatEtc, STGMEDIUM __RPC_FAR *pmedium);
  71 
  72         virtual HRESULT __stdcall QueryGetData(FORMATETC __RPC_FAR *pFormatEtc);
  73 
  74         virtual HRESULT __stdcall GetCanonicalFormatEtc(FORMATETC __RPC_FAR *pFormatEtcIn, FORMATETC __RPC_FAR *pFormatEtcOut);
  75 
  76         virtual HRESULT __stdcall SetData(FORMATETC __RPC_FAR *pFormatEtc, STGMEDIUM __RPC_FAR *pmedium, BOOL fRelease);
  77 
  78         virtual HRESULT __stdcall EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC *__RPC_FAR *ppenumFormatEtc);
  79 
  80         virtual HRESULT __stdcall DAdvise(FORMATETC __RPC_FAR *pFormatEtc, DWORD advf, IAdviseSink __RPC_FAR *pAdvSink, DWORD __RPC_FAR *pdwConnection);
  81         virtual HRESULT __stdcall DUnadvise(DWORD dwConnection);
  82         virtual HRESULT __stdcall EnumDAdvise(IEnumSTATDATA __RPC_FAR *__RPC_FAR *ppenumAdvise);
  83 
  84 
  85         // AwtDragSource
  86 
  87         static void StartDrag(
  88             AwtDragSource* self,
  89             jobject cursor,
  90             jintArray imageData,
  91             jint imageWidth,
  92             jint imageHeight,
  93             jint x,
  94             jint y);
  95 
  96         HRESULT ChangeCursor();
  97         void SetCursor(jobject cursor);
  98 
  99         INLINE unsigned int getNTypes() { return m_ntypes; }
 100 
 101         INLINE FORMATETC getType(unsigned int i) { return m_types[i]; }
 102 
 103         INLINE jobject GetPeer() { return m_peer; }
 104 
 105         INLINE void Signal() { ::ReleaseMutex(m_mutex); }
 106 
 107         virtual HRESULT __stdcall GetProcessId(FORMATETC __RPC_FAR *pFormatEtc, STGMEDIUM __RPC_FAR *pmedium);
 108 
 109     protected:
 110         INLINE void WaitUntilSignalled(BOOL retain) {
 111             do {
 112                 // nothing ...
 113             } while(::WaitForSingleObject(m_mutex, INFINITE) == WAIT_FAILED);
 114 
 115             if (!retain) ::ReleaseMutex(m_mutex);
 116         }
 117 
 118         static void _DoDragDrop(void* param);
 119 
 120         HRESULT __stdcall MatchFormatEtc(FORMATETC __RPC_FAR *pFormatEtcIn, FORMATETC *cacheEnt);
 121 
 122    private:
 123 
 124         void LoadCache(jlongArray formats);
 125         void UnloadCache();
 126 
 127         static int __cdecl _compar(const void *, const void *);
 128 
 129         static void call_dSCenter(JNIEnv* env, jobject self, jint targetActions,
 130                                   jint modifiers, POINT pt);
 131         static void call_dSCmotion(JNIEnv* env, jobject self,
 132                                    jint targetActions, jint modifiers,
 133                                    POINT pt);
 134         static void call_dSCchanged(JNIEnv* env, jobject self,
 135                                     jint targetActions, jint modifiers,
 136                                     POINT pt);
 137         static void call_dSCmouseMoved(JNIEnv* env, jobject self,
 138                                        jint targetActions, jint modifiers,
 139                                        POINT pt);
 140         static void call_dSCexit(JNIEnv* env, jobject self, POINT pt);
 141         static void call_dSCddfinished(JNIEnv* env, jobject self,
 142                                        jboolean success, jint operations,
 143                                        POINT pt);
 144     protected:
 145 
 146         class ADSIEnumFormatEtc : public virtual IEnumFORMATETC {
 147             public:
 148                 ADSIEnumFormatEtc(AwtDragSource* parent);
 149 
 150                 virtual ~ADSIEnumFormatEtc();
 151 
 152                 // IUnknown
 153 
 154                 virtual HRESULT __stdcall QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject);
 155 
 156                 virtual ULONG   __stdcall AddRef(void);
 157                 virtual ULONG   __stdcall Release(void);
 158 
 159                 // IEnumFORMATETC
 160 
 161                 virtual HRESULT _stdcall Next(ULONG celt, FORMATETC __RPC_FAR *rgelt, ULONG __RPC_FAR *pceltFetched);
 162                 virtual HRESULT _stdcall Skip(ULONG celt);
 163                 virtual HRESULT _stdcall Reset();
 164                 virtual HRESULT _stdcall Clone(IEnumFORMATETC __RPC_FAR *__RPC_FAR *ppenum);
 165 
 166             private:
 167                 AwtDragSource*  m_parent;
 168                 ULONG           m_refs;
 169 
 170                 unsigned int    m_idx;
 171         };
 172 
 173         class ADSIStreamProxy : public virtual IStream {
 174             private:
 175                 ADSIStreamProxy(ADSIStreamProxy* cloneof);
 176 
 177             public:
 178                 ADSIStreamProxy(AwtDragSource* parent, jbyteArray buffer, jint len);
 179 
 180                 virtual ~ADSIStreamProxy();
 181 
 182                 // IUnknown
 183 
 184                 virtual HRESULT __stdcall QueryInterface(REFIID riid, void __RPC_FAR *__RPC_FAR *ppvObject);
 185 
 186                 virtual ULONG   __stdcall AddRef(void);
 187                 virtual ULONG   __stdcall Release(void);
 188 
 189                 // IStream
 190 
 191 
 192                 virtual  HRESULT __stdcall Read(void __RPC_FAR *pv, ULONG cb, ULONG __RPC_FAR *pcbRead);
 193 
 194                 virtual  HRESULT __stdcall Write(const void __RPC_FAR *pv, ULONG cb, ULONG __RPC_FAR *pcbWritten);
 195 
 196                 virtual  HRESULT __stdcall Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER __RPC_FAR *plibNewPosition);
 197 
 198                 virtual HRESULT __stdcall SetSize(ULARGE_INTEGER libNewSize);
 199 
 200                 virtual  HRESULT __stdcall CopyTo(IStream __RPC_FAR *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER __RPC_FAR *pcbRead, ULARGE_INTEGER __RPC_FAR *pcbWritten);
 201 
 202                 virtual HRESULT __stdcall Commit(DWORD grfCommitFlags);
 203 
 204                 virtual HRESULT __stdcall Revert();
 205 
 206                 virtual HRESULT __stdcall LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
 207 
 208                 virtual HRESULT __stdcall UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
 209 
 210                 virtual HRESULT __stdcall Stat(STATSTG __RPC_FAR *pstatstg, DWORD grfStatFlag);
 211 
 212                 virtual HRESULT __stdcall Clone(IStream __RPC_FAR *__RPC_FAR *ppstm);
 213             protected:
 214                 AwtDragSource*   m_parent;
 215 
 216                 signed   char*   m_buffer;
 217                 unsigned int     m_off;
 218                 unsigned int     m_blen;
 219 
 220                 STATSTG          m_statstg;
 221 
 222                 ADSIStreamProxy* m_cloneof;
 223 
 224                 ULONG            m_refs;
 225         };
 226 
 227     public:
 228         static const UINT PROCESS_ID_FORMAT;
 229 
 230     private:
 231 
 232         // instance vars ...
 233 
 234         jobject         m_peer;
 235 
 236         jint            m_initmods;
 237         jint            m_lastmods;
 238 
 239         HWND            m_droptarget;
 240         int             m_enterpending;
 241 
 242         jint            m_actions;
 243 
 244         FORMATETC*      m_types;
 245         unsigned int    m_ntypes;
 246 
 247         ULONG           m_refs;
 248 
 249         AwtCursor*      m_cursor;
 250 
 251         HANDLE          m_mutex;
 252 
 253         jobject         m_component;
 254         jobject         m_transferable;
 255         jobject         m_formatMap;
 256 
 257         POINT           m_dragPoint; // device space (pixels)
 258         POINT           m_dropPoint; // device space (pixels)
 259         BOOL            m_fNC;
 260         BOOL            m_bRestoreNodropCustomCursor;//CR 6480706 - MS Bug on hold
 261 
 262         DWORD           m_dwPerformedDropEffect;
 263 
 264         // static's ...
 265 
 266         static jclass           dSCClazz;
 267         static jclass           awtIEClazz;
 268 
 269         static jmethodID        dSCdragenter;
 270         static jmethodID        dSCdragmotion;
 271         static jmethodID        dSCopschanged;
 272         static jmethodID        dSCdragexit;
 273         static jmethodID        dSCddfinish;
 274 
 275         static jfieldID         awtIEmods;
 276 };
 277 
 278 extern const CLIPFORMAT CF_PERFORMEDDROPEFFECT;
 279 extern const CLIPFORMAT CF_FILEGROUPDESCRIPTORA;
 280 extern const CLIPFORMAT CF_FILEGROUPDESCRIPTORW;
 281 extern const CLIPFORMAT CF_FILECONTENTS;
 282 
 283 #endif /* AWT_DND_DS_H */
--- EOF ---