Changeset 8553 for trunk/src/user32
- Timestamp:
- Jun 2, 2002, 9:34:36 PM (23 years ago)
- Location:
- trunk/src/user32
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/dragdrop.cpp
r8542 r8553 1 /* $Id: dragdrop.cpp,v 1. 1 2002-06-02 10:08:09sandervl Exp $ */1 /* $Id: dragdrop.cpp,v 1.2 2002-06-02 19:34:25 sandervl Exp $ */ 2 2 3 3 /* … … 11 11 #include <windows.h> 12 12 #include <dbglog.h> 13 #include <oledd.h> 13 14 14 15 #define DBG_LOCALLOG DBG_dragdrop 15 16 #include "dbglocal.h" 16 17 18 static PFN_DRAGENTER pfnDragEnter = NULL; 19 static PFN_DRAGLEAVE pfnDragLeave = NULL; 20 static PFN_DROPFILES pfnDropFiles = NULL; 21 static PFN_DRAGOVER pfnDragOver = NULL; 22 static PFN_ACCEPTSDRAGDROP pfnAcceptsDragDrop = NULL; 23 static HANDLE hOLE32 = 0; 24 17 25 //****************************************************************************** 18 26 //****************************************************************************** 19 ULONG DragDropFiles(HWND hwnd, UINT cFiles, POINT point, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient)27 ULONG DragDropFiles(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient) 20 28 { 21 29 DROPFILES *pDropFile; 22 30 HGLOBAL hDropFile; 23 31 DWORD dwExStyle; 32 HWND orghwnd = hwnd; 24 33 25 34 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE); 26 35 27 // Is it correct if the window or parent accepts files or must we check the topparentparent?36 //TODO: Is it correct if the window or parent accepts files or must we check the top parent? 28 37 hwnd = (dwExStyle & WS_EX_ACCEPTFILES) ? hwnd : GetParent(hwnd); 38 39 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE); 40 if(!(dwExStyle & WS_EX_ACCEPTFILES)) { 41 if(pfnDropFiles) { 42 return pfnDropFiles(hwnd); 43 } 44 return FALSE; 45 } 29 46 cbszFiles++; //extra terminating 0 30 31 if(IsWindowUnicode(hwnd)) {32 dprintf(("unicode dropfiles"));33 cbszFiles *= 2;34 }35 36 47 hDropFile = GlobalAlloc(0, sizeof(DROPFILES)+cbszFiles); 37 48 pDropFile = (DROPFILES *)GlobalLock(hDropFile); … … 42 53 pDropFile->pFiles = sizeof(DROPFILES); 43 54 pDropFile->fNC = fNonClient; 44 pDropFile->fWide = ::IsWindowUnicode(hwnd);55 pDropFile->fWide = FALSE; 45 56 pDropFile->pt = point; 46 if(IsWindowUnicode(hwnd)) { 47 LPWSTR lpszFilesW = (LPWSTR)(pDropFile+1); 48 while(*pszFiles) { 49 int len = strlen(pszFiles); 50 MultiByteToWideChar(CP_ACP, 0, pszFiles, -1, lpszFilesW, len); 51 pszFiles += len + 1; 52 lpszFilesW += len + 1; 53 } 54 *lpszFilesW = 0; 55 } 56 else { 57 //copy strings (excluding terminating 0) 58 memcpy((pDropFile+1), pszFiles, cbszFiles-1); 59 } 57 //copy strings (excluding terminating 0) 58 memcpy((pDropFile+1), pszFiles, cbszFiles-1); 60 59 GlobalUnlock(hDropFile); 61 60 SendMessageA(hwnd, WM_DROPFILES, hDropFile, 0); 62 61 return 0; 62 } 63 //****************************************************************************** 64 //****************************************************************************** 65 BOOL DragDropDragOver(HWND hwnd, DWORD dwEffect) 66 { 67 if(pfnDragOver) { 68 return pfnDragOver(hwnd, dwEffect); 69 } 70 return TRUE; //ignore 71 } 72 //****************************************************************************** 73 //****************************************************************************** 74 BOOL DragDropDragEnter(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles, 75 DWORD dwEffect, BOOL fNonClient) 76 { 77 DROPFILES *pDropFile; 78 HGLOBAL hDropFile; 79 80 if(pfnDragEnter) { 81 cbszFiles++; //extra terminating 0 82 hDropFile = GlobalAlloc(0, sizeof(DROPFILES)+cbszFiles); 83 pDropFile = (DROPFILES *)GlobalLock(hDropFile); 84 if(pDropFile == NULL) { 85 DebugInt3(); 86 return FALSE; 87 } 88 pDropFile->pFiles = sizeof(DROPFILES); 89 pDropFile->fNC = fNonClient; 90 pDropFile->fWide = FALSE; 91 pDropFile->pt = point; 92 //copy strings (excluding terminating 0) 93 memcpy((pDropFile+1), pszFiles, cbszFiles-1); 94 GlobalUnlock(hDropFile); 95 96 return pfnDragEnter(hwnd, hDropFile, dwEffect); 97 } 98 return TRUE; //ignore 99 } 100 //****************************************************************************** 101 //****************************************************************************** 102 BOOL DragDropDragLeave(HWND hwnd) 103 { 104 if(pfnDragLeave) { 105 return pfnDragLeave(hwnd); 106 } 107 return TRUE; //ignore 63 108 } 64 109 //****************************************************************************** … … 75 120 DWORD dwStyle = GetWindowLongA(GetParent(hwnd), GWL_EXSTYLE); 76 121 if(!(dwStyle & WS_EX_ACCEPTFILES)) { 122 if(pfnAcceptsDragDrop == NULL) { 123 //check for OLE drag & drop 124 125 hOLE32 = GetModuleHandleA("OLE32.DLL"); 126 if(hOLE32 == 0) { 127 //if ole32.dll isn't loaded, then ole drag and drop can't be active 128 return FALSE; 129 } 130 //make sure the dll doesn't get unloaded 131 hOLE32 = LoadLibraryA("OLE32.DLL"); 132 133 pfnAcceptsDragDrop = (PFN_ACCEPTSDRAGDROP)GetProcAddress(hOLE32, "OLEDD_AcceptsDragDrop"); 134 pfnDragOver = (PFN_DRAGOVER)GetProcAddress(hOLE32, "OLEDD_DragOver"); 135 pfnDragLeave = (PFN_DRAGLEAVE)GetProcAddress(hOLE32, "OLEDD_DragLeave"); 136 pfnDragEnter = (PFN_DRAGENTER)GetProcAddress(hOLE32, "OLEDD_DragEnter"); 137 pfnDropFiles = (PFN_DROPFILES)GetProcAddress(hOLE32, "OLEDD_DropFiles"); 138 if(!pfnAcceptsDragDrop || !pfnDragOver || !pfnDragLeave || !pfnDragEnter || !pfnDropFiles) { 139 dprintf(("OLE DD functions not found!!")); 140 DebugInt3(); 141 return FALSE; 142 } 143 } 144 if(pfnAcceptsDragDrop) { 145 return pfnAcceptsDragDrop(hwnd); 146 } 77 147 return FALSE; 78 148 } -
trunk/src/user32/dragdrop.h
r8542 r8553 1 /* $Id: dragdrop.h,v 1. 1 2002-06-02 10:08:10sandervl Exp $ */1 /* $Id: dragdrop.h,v 1.2 2002-06-02 19:34:27 sandervl Exp $ */ 2 2 3 3 /* … … 13 13 14 14 BOOL DragDropAccept(HWND hwnd); 15 ULONG DragDropFiles(HWND hwnd, UINT cFiles, POINT point, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient = FALSE); 15 BOOL DragDropDragOver(HWND hwnd, DWORD dwEffect); 16 BOOL DragDropDragLeave(HWND hwnd); 17 BOOL DragDropFiles(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles, BOOL fNonClient = FALSE); 18 BOOL DragDropDragEnter(HWND hwnd, POINT point, UINT cFiles, LPSTR pszFiles, UINT cbszFiles, DWORD dwEffect, BOOL fNonClient = FALSE); 16 19 17 20 #endif //__DRAGDROP_H__ -
trunk/src/user32/pmwindow.cpp
r8542 r8553 1 /* $Id: pmwindow.cpp,v 1.17 5 2002-06-02 10:07:57sandervl Exp $ */1 /* $Id: pmwindow.cpp,v 1.176 2002-06-02 19:34:28 sandervl Exp $ */ 2 2 /* 3 3 * Win32 Window Managment Code for OS/2 … … 84 84 85 85 86 static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes); 87 static BOOL PMDragValidate(PDRAGINFO pDragInfo); 86 88 87 89 MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2); … … 787 789 USHORT sxDrop = SHORT1FROMMP(mp2); 788 790 USHORT syDrop = SHORT2FROMMP(mp2); 789 USHORT usIndicator, usOp;790 ULONG ulBytes;791 int i, cItems;792 BOOL ret;793 char szFileName[CCHMAXPATH];794 char szContainerName[CCHMAXPATH];795 791 796 792 dprintf(("OS2: DM_DRAGOVER %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop)); … … 801 797 break; 802 798 } 803 /* Get access to the DRAGINFO data structure */ 804 if( !DrgAccessDraginfo(pDragInfo)) {805 rc = (MRFROM2SHORT (DOR_N ODROP, 0));799 800 if(PMDragValidate(pDragInfo) == FALSE) { 801 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0)); 806 802 break; 807 803 } 808 809 /* Can we accept this drop? */ 810 switch (pDragInfo->usOperation) { 811 /* Return DOR_NODROPOP if current operation */ 812 /* is link or unknown */ 813 case DO_LINK: 814 case DO_COPY: 815 case DO_UNKNOWN: 816 DrgFreeDraginfo(pDragInfo); 817 rc = (MRFROM2SHORT (DOR_NODROPOP, 0)); 818 break; 819 820 /* Our default operation is Move */ 821 case DO_MOVE: 822 case DO_DEFAULT: 823 pDragItem = DrgQueryDragitemPtr(pDragInfo, 0); 824 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName, 825 sizeof(szContainerName), 826 szContainerName); 827 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName, 828 sizeof(szFileName), 829 szFileName); 830 if (!ulBytes) { 831 rc = (MRFROM2SHORT (DOR_NODROPOP, 0)); 832 break; 833 } 834 else usOp = DO_MOVE; 835 836 dprintf(("dropped file %s%s", szContainerName, szFileName)); 837 break; 838 } 839 if(rc == MRFROM2SHORT (DOR_NODROPOP, 0)) { 840 break; 841 } 842 843 usIndicator = (USHORT)DOR_DROP; 844 cItems = DrgQueryDragitemCount(pDragInfo); 845 846 /* Now, we need to look at each item in turn */ 847 for (i = 0; i < cItems; i++) { 848 pDragItem = DrgQueryDragitemPtr(pDragInfo, i); 849 850 /* Make sure we can move for a Move request */ 851 if ((pDragItem->fsSupportedOps & DO_MOVEABLE) && 852 (usOp == (USHORT)DO_MOVE)) 853 { 854 usIndicator = DOR_DROP; 804 if(win32wnd->isDragDropActive() == FALSE) { 805 ULONG ulBytes, cItems; 806 char *pszFiles; 807 808 win32wnd->setDragDropActive(TRUE); 809 810 pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes); 811 if(pszFiles) { 812 POINT point = {sxDrop, syDrop}; 813 if(DragDropDragEnter(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes, DROPEFFECT_COPY_W) == FALSE) { 814 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0)); 815 } 816 else rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE)); 817 free(pszFiles); 855 818 } 856 819 else { 857 dprintf(("item %d not accepted", i)); 858 usIndicator = DOR_NODROPOP; 859 break; 860 } 861 } 862 /* Release the draginfo data structure */ 863 DrgFreeDraginfo(pDragInfo); 864 865 dprintf(("return %x", MRFROM2SHORT(usIndicator, usOp))); 866 rc = (MRFROM2SHORT(usIndicator, usOp)); 820 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0)); 821 } 822 } 823 else { 824 if(DragDropDragOver(win32wnd->getWindowHandle(), DROPEFFECT_COPY_W) == FALSE) { 825 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0)); 826 } 827 else rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE)); 828 } 867 829 break; 868 830 } … … 871 833 { 872 834 dprintf(("OS2: DM_DRAGLEAVE %x", win32wnd->getWindowHandle())); 835 DragDropDragLeave(win32wnd->getWindowHandle()); 836 win32wnd->setDragDropActive(FALSE); 873 837 break; 874 838 } … … 881 845 USHORT syDrop = SHORT2FROMMP(mp2); 882 846 USHORT usIndicator, usOp; 883 ULONG ulBytes;884 int i, cItems;885 BOOL ret;886 char szFileName[CCHMAXPATH];887 char szContainerName[CCHMAXPATH];888 847 889 848 dprintf(("OS2: DM_DROP %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop)); 849 850 rc = (MRFROM2SHORT (DOR_NODROP, 0)); 890 851 891 852 //does this window accept dropped files? 892 853 if(!DragDropAccept(win32wnd->getWindowHandle())) { 893 rc = 0;894 854 break; 895 855 } 896 /* Get access to the DRAGINFO data structure */897 if(!DrgAccessDraginfo(pDragInfo)) {898 rc = 0;899 break;900 }901 902 usIndicator = (USHORT)DOR_DROP;903 cItems = DrgQueryDragitemCount(pDragInfo);904 856 905 //computer memory required to hold all filenames 906 int bufsize = 0; 907 for (i = 0; i < cItems; i++) { 908 pDragItem = DrgQueryDragitemPtr(pDragInfo, i); 909 910 bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName); 911 bufsize++; //0 terminator 912 bufsize++; //+ potential missing backslash 913 } 914 //copy all filenames 915 char *pszFiles = (char *)malloc(bufsize); 916 if(pszFiles == NULL) { 917 dprintf(("Out of memory!!")); 918 DebugInt3(); 919 break; 920 } 921 char *pszCurFile = pszFiles; 922 923 for (i = 0; i < cItems; i++) { 924 char *pszTemp = pszCurFile; 925 926 pDragItem = DrgQueryDragitemPtr(pDragInfo, i); 927 928 ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName); 929 930 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName, 931 ulBytes, pszCurFile); 932 if(pszCurFile[ulBytes-1] != '\\') { 933 pszCurFile[ulBytes] = '\\'; 934 pszCurFile++; 935 } 936 pszCurFile += ulBytes; 937 938 ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName); 939 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName, 940 ulBytes+1, pszCurFile); 941 pszCurFile += ulBytes + 1; //+ terminator 942 943 dprintf(("dropped file %s", pszTemp)); 944 } 945 POINT point = {sxDrop, syDrop}; 946 DragDropFiles(win32wnd->getWindowHandle(), cItems, point, pszFiles, bufsize); 947 free(pszFiles); 948 949 /* Release the draginfo data structure */ 950 DrgFreeDraginfo(pDragInfo); 951 952 rc = 0; 857 ULONG ulBytes, cItems; 858 char *pszFiles; 859 860 pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes); 861 if(pszFiles) { 862 POINT point = {sxDrop, syDrop}; 863 if(DragDropFiles(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes) == FALSE) { 864 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0)); 865 } 866 else rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE)); 867 free(pszFiles); 868 } 869 else { 870 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0)); 871 } 953 872 break; 954 873 } … … 2050 1969 //****************************************************************************** 2051 1970 //****************************************************************************** 1971 static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes) 1972 { 1973 PDRAGITEM pDragItem; 1974 int i, cItems; 1975 BOOL ret; 1976 char szFileName[CCHMAXPATH]; 1977 char szContainerName[CCHMAXPATH]; 1978 ULONG ulBytes; 1979 char *pszCurFile = NULL; 1980 1981 /* Get access to the DRAGINFO data structure */ 1982 if(!DrgAccessDraginfo(pDragInfo)) { 1983 return NULL; 1984 } 1985 1986 cItems = DrgQueryDragitemCount(pDragInfo); 1987 1988 //computer memory required to hold all filenames 1989 int bufsize = 0; 1990 for (i = 0; i < cItems; i++) { 1991 pDragItem = DrgQueryDragitemPtr(pDragInfo, i); 1992 1993 bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName); 1994 bufsize++; //0 terminator 1995 bufsize++; //+ potential missing backslash 1996 } 1997 bufsize++; //extra 0 terminator 1998 char *pszFiles = (char *)malloc(bufsize); 1999 if(pszFiles == NULL) { 2000 dprintf(("Out of memory!!")); 2001 DebugInt3(); 2002 goto failure; 2003 } 2004 memset(pszFiles, 0, bufsize); 2005 2006 pszCurFile = pszFiles; 2007 2008 //copy all filenames 2009 for (i = 0; i < cItems; i++) { 2010 char *pszTemp = pszCurFile; 2011 2012 pDragItem = DrgQueryDragitemPtr(pDragInfo, i); 2013 2014 ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName); 2015 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName, 2016 ulBytes, pszCurFile); 2017 if(pszCurFile[ulBytes-1] != '\\') { 2018 pszCurFile[ulBytes] = '\\'; 2019 pszCurFile++; 2020 } 2021 pszCurFile += ulBytes; 2022 2023 ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName); 2024 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName, 2025 ulBytes+1, pszCurFile); 2026 pszCurFile += ulBytes + 1; //+ terminator 2027 2028 dprintf(("dropped file %s", pszTemp)); 2029 } 2030 2031 /* Release the draginfo data structure */ 2032 DrgFreeDraginfo(pDragInfo); 2033 2034 *pulBytes = bufsize; 2035 *pcItems = cItems; 2036 2037 return pszFiles; 2038 2039 failure: 2040 /* Release the draginfo data structure */ 2041 DrgFreeDraginfo(pDragInfo); 2042 if(pszFiles) { 2043 free(pszFiles); 2044 } 2045 return NULL; 2046 } 2047 //****************************************************************************** 2048 //****************************************************************************** 2049 static BOOL PMDragValidate(PDRAGINFO pDragInfo) 2050 { 2051 PDRAGITEM pDragItem; 2052 ULONG ulBytes; 2053 int i, cItems; 2054 BOOL ret; 2055 char szFileName[CCHMAXPATH]; 2056 char szContainerName[CCHMAXPATH]; 2057 USHORT usOp = DO_MOVE; 2058 2059 /* Get access to the DRAGINFO data structure */ 2060 if(!DrgAccessDraginfo(pDragInfo)) { 2061 return FALSE; 2062 } 2063 2064 /* Can we accept this drop? */ 2065 switch (pDragInfo->usOperation) { 2066 /* Return DOR_NODROPOP if current operation */ 2067 /* is link or unknown */ 2068 case DO_LINK: 2069 case DO_COPY: 2070 case DO_UNKNOWN: 2071 goto failure; 2072 2073 /* Our default operation is Move */ 2074 case DO_MOVE: 2075 case DO_DEFAULT: 2076 pDragItem = DrgQueryDragitemPtr(pDragInfo, 0); 2077 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName, 2078 sizeof(szContainerName), 2079 szContainerName); 2080 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName, 2081 sizeof(szFileName), 2082 szFileName); 2083 if (!ulBytes) { 2084 goto failure; 2085 } 2086 2087 dprintf(("dropped file %s%s", szContainerName, szFileName)); 2088 break; 2089 } 2090 2091 cItems = DrgQueryDragitemCount(pDragInfo); 2092 2093 /* Now, we need to look at each item in turn */ 2094 for (i = 0; i < cItems; i++) { 2095 pDragItem = DrgQueryDragitemPtr(pDragInfo, i); 2096 2097 /* Make sure we can move for a Move request */ 2098 if (!((pDragItem->fsSupportedOps & DO_MOVEABLE) && 2099 (usOp == (USHORT)DO_MOVE))) 2100 { 2101 dprintf(("item %d not accepted", i)); 2102 goto failure; 2103 } 2104 } 2105 /* Release the draginfo data structure */ 2106 DrgFreeDraginfo(pDragInfo); 2107 return TRUE; 2108 2109 failure: 2110 DrgFreeDraginfo(pDragInfo); 2111 return FALSE; 2112 } 2113 //****************************************************************************** 2114 //****************************************************************************** 2115 -
trunk/src/user32/win32wbase.cpp
r8542 r8553 1 /* $Id: win32wbase.cpp,v 1.32 6 2002-06-02 10:07:58sandervl Exp $ */1 /* $Id: win32wbase.cpp,v 1.327 2002-06-02 19:34:31 sandervl Exp $ */ 2 2 /* 3 3 * Win32 Window Base Class for OS/2 … … 179 179 fEraseBkgndFlag = TRUE; 180 180 fFakeWindow = FALSE; 181 fIsDragDropActive= FALSE; 181 182 182 183 state = STATE_INIT; -
trunk/src/user32/win32wbase.h
r8542 r8553 1 /* $Id: win32wbase.h,v 1.14 2 2002-06-02 10:07:59sandervl Exp $ */1 /* $Id: win32wbase.h,v 1.143 2002-06-02 19:34:36 sandervl Exp $ */ 2 2 /* 3 3 * Win32 Window Base Class for OS/2 … … 183 183 void setLastActive(HWND _hwndLastActive) 184 184 { hwndLastActive = _hwndLastActive; }; 185 BOOL isDragDropActive() { return fIsDragDropActive; }; 186 void setDragDropActive(BOOL fActive) { fIsDragDropActive = fActive; }; 185 187 186 188 Win32WndClass *getWindowClass() { return windowClass; }; … … 422 424 fVisibleRegionChanged:1, //set when visible region has changed -> erase background must be sent during next BeginPaint 423 425 fEraseBkgndFlag:1, 426 fIsDragDropActive:1, 424 427 fFakeWindow:1; 425 428
Note:
See TracChangeset
for help on using the changeset viewer.