From 7f0572d75b8e2814ef6117c9ab6c13bdfc2571b0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 3 Jun 2015 19:39:19 +0000 Subject: code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@13983 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/FloatingContacts/src/filedrop.cpp | 296 +++++++++++++----------------- 1 file changed, 126 insertions(+), 170 deletions(-) (limited to 'plugins/FloatingContacts/src/filedrop.cpp') diff --git a/plugins/FloatingContacts/src/filedrop.cpp b/plugins/FloatingContacts/src/filedrop.cpp index f53edeba5b..38f688381e 100644 --- a/plugins/FloatingContacts/src/filedrop.cpp +++ b/plugins/FloatingContacts/src/filedrop.cpp @@ -1,29 +1,28 @@ #include "stdhdr.h" -static void ProcessDroppedItems ( char **ppDroppedItems, int nCount, char **ppFiles ); -static int CountDroppedFiles ( char **ppDroppedItems, int nCount ); -static BOOL OnDropFiles ( HDROP hDrop, ThumbInfo *pThumb ); +static void ProcessDroppedItems(char **ppDroppedItems, int nCount, char **ppFiles); +static int CountDroppedFiles(char **ppDroppedItems, int nCount); +static BOOL OnDropFiles(HDROP hDrop, ThumbInfo *pThumb); -HRESULT STDMETHODCALLTYPE CDropTarget::QueryInterface(REFIID riid,LPVOID *ppvObj) +HRESULT STDMETHODCALLTYPE CDropTarget::QueryInterface(REFIID riid, LPVOID *ppvObj) { - if ( IsEqualIID( riid, IID_IDropTarget )) - { + if (IsEqualIID(riid, IID_IDropTarget)) { *ppvObj = this; this->AddRef(); return S_OK; } - + *ppvObj = NULL; - return ( E_NOINTERFACE ); + return (E_NOINTERFACE); } -ULONG STDMETHODCALLTYPE CDropTarget::AddRef( ) +ULONG STDMETHODCALLTYPE CDropTarget::AddRef() { return ++this->refCount; } -ULONG STDMETHODCALLTYPE CDropTarget::Release( ) +ULONG STDMETHODCALLTYPE CDropTarget::Release() { int res = --this->refCount; if (!res) delete this; @@ -31,215 +30,190 @@ ULONG STDMETHODCALLTYPE CDropTarget::Release( ) } -HRESULT STDMETHODCALLTYPE CDropTarget::DragOver( DWORD fKeyState, POINTL pt, DWORD *pdwEffect ) +HRESULT STDMETHODCALLTYPE CDropTarget::DragOver(DWORD fKeyState, POINTL pt, DWORD *pdwEffect) { *pdwEffect = 0; - - if ( hwndCurDrag == NULL ) - { + + if (hwndCurDrag == NULL) { *pdwEffect = DROPEFFECT_NONE; } - else - { + else { *pdwEffect |= DROPEFFECT_COPY; } return S_OK; } -HRESULT STDMETHODCALLTYPE CDropTarget::DragEnter( IDataObject *pData, DWORD fKeyState, POINTL pt, DWORD *pdwEffect) +HRESULT STDMETHODCALLTYPE CDropTarget::DragEnter(IDataObject *pData, DWORD fKeyState, POINTL pt, DWORD *pdwEffect) { - FORMATETC feFile = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; - FORMATETC feText = { CF_TEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; + FORMATETC feFile = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; + FORMATETC feText = { CF_TEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; - if ( S_OK == pData->QueryGetData( &feFile ) || - S_OK == pData->QueryGetData( &feText )) - { + if (S_OK == pData->QueryGetData(&feFile) || + S_OK == pData->QueryGetData(&feText)) { POINT shortPt; - shortPt.x = pt.x; + shortPt.x = pt.x; shortPt.y = pt.y; - - HWND hwnd = WindowFromPoint( shortPt ); - + + HWND hwnd = WindowFromPoint(shortPt); + ThumbInfo *pThumb = thumbList.FindThumb(hwnd); - if (pThumb) - { + if (pThumb) { hwndCurDrag = hwnd; - pThumb->ThumbSelect( TRUE ); + pThumb->ThumbSelect(TRUE); } } - return DragOver( fKeyState, pt, pdwEffect); + return DragOver(fKeyState, pt, pdwEffect); } -HRESULT STDMETHODCALLTYPE CDropTarget::DragLeave( ) +HRESULT STDMETHODCALLTYPE CDropTarget::DragLeave() { - ThumbInfo *pThumb = thumbList.FindThumb( hwndCurDrag ); + ThumbInfo *pThumb = thumbList.FindThumb(hwndCurDrag); - if ( NULL != pThumb ) - { - pThumb->ThumbDeselect( TRUE ); + if (NULL != pThumb) { + pThumb->ThumbDeselect(TRUE); } hwndCurDrag = NULL; - + return S_OK; } -HRESULT STDMETHODCALLTYPE CDropTarget::Drop( IDataObject *pData,DWORD fKeyState,POINTL pt,DWORD *pdwEffect) +HRESULT STDMETHODCALLTYPE CDropTarget::Drop(IDataObject *pData, DWORD fKeyState, POINTL pt, DWORD *pdwEffect) { FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; *pdwEffect = DROPEFFECT_NONE; - + if (hwndCurDrag == NULL) return S_OK; - ThumbInfo *pThumb = (ThumbInfo*) GetWindowLongPtr( hwndCurDrag, GWLP_USERDATA ); + ThumbInfo *pThumb = (ThumbInfo*)GetWindowLongPtr(hwndCurDrag, GWLP_USERDATA); if (pThumb == NULL) return S_OK; STGMEDIUM stg; bool bFormatText = false; - if ( S_OK != pData->GetData(&fe,&stg)) - { + if (S_OK != pData->GetData(&fe, &stg)) { fe.cfFormat = CF_UNICODETEXT; - if ( S_OK != pData->GetData(&fe,&stg)) - { + if (S_OK != pData->GetData(&fe, &stg)) { return S_OK; } - else - { + else { bFormatText = true; } } - - if (!bFormatText) - { - HDROP hDrop = (HDROP) stg.hGlobal; - if (hDrop != NULL) - { + + if (!bFormatText) { + HDROP hDrop = (HDROP)stg.hGlobal; + if (hDrop != NULL) { OnDropFiles(hDrop, pThumb); } } - else - { - TCHAR *pText = (TCHAR*) GlobalLock(stg.hGlobal); - if (pText != NULL) - { + else { + TCHAR *pText = (TCHAR*)GlobalLock(stg.hGlobal); + if (pText != NULL) { SendMsgDialog(hwndCurDrag, pText); GlobalUnlock(stg.hGlobal); } } - if (stg.pUnkForRelease != NULL) - { + if (stg.pUnkForRelease != NULL) { stg.pUnkForRelease->Release(); } - else - { + else { GlobalFree(stg.hGlobal); } DragLeave(); - + return S_OK; } /////////////////////////////////////////////////////// // Send files processing -BOOL OnDropFiles( HDROP hDrop, ThumbInfo *pThumb ) +BOOL OnDropFiles(HDROP hDrop, ThumbInfo *pThumb) { - UINT nDroppedItemsCount = DragQueryFile( hDrop, 0xFFFFFFFF, NULL, 0); + UINT nDroppedItemsCount = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); - char **ppDroppedItems = ( char** )malloc( sizeof(char*)*( nDroppedItemsCount + 1)); - - if ( ppDroppedItems == NULL ) - { + char **ppDroppedItems = (char**)malloc(sizeof(char*)*(nDroppedItemsCount + 1)); + + if (ppDroppedItems == NULL) { return FALSE; } - ppDroppedItems[ nDroppedItemsCount ] = NULL; - + ppDroppedItems[nDroppedItemsCount] = NULL; + char szFilename[MAX_PATH]; - for (UINT iItem = 0; iItem < nDroppedItemsCount; ++iItem ) - { - DragQueryFileA( hDrop, iItem, szFilename, sizeof( szFilename )); - ppDroppedItems[ iItem ] = _strdup( szFilename ); + for (UINT iItem = 0; iItem < nDroppedItemsCount; ++iItem) { + DragQueryFileA(hDrop, iItem, szFilename, sizeof(szFilename)); + ppDroppedItems[iItem] = _strdup(szFilename); } - - UINT nFilesCount = CountDroppedFiles( ppDroppedItems, nDroppedItemsCount ); - - char **ppFiles = ( char** )malloc( sizeof( char *)* ( nFilesCount+1)); - + + UINT nFilesCount = CountDroppedFiles(ppDroppedItems, nDroppedItemsCount); + + char **ppFiles = (char**)malloc(sizeof(char *)* (nFilesCount + 1)); + BOOL bSuccess = FALSE; - if (ppFiles != NULL) - { + if (ppFiles != NULL) { ppFiles[nFilesCount] = NULL; ProcessDroppedItems(ppDroppedItems, nDroppedItemsCount, ppFiles); - bSuccess = (BOOL)CallService(MS_CLIST_CONTACTFILESDROPPED, (WPARAM)pThumb->hContact, (LPARAM)ppFiles); + bSuccess = (BOOL)CallService(MS_CLIST_CONTACTFILESDROPPED, (WPARAM)pThumb->hContact, (LPARAM)ppFiles); - for (UINT iItem = 0; iItem < nFilesCount ; ++iItem ) + for (UINT iItem = 0; iItem < nFilesCount; ++iItem) free(ppFiles[iItem]); free(ppFiles); } // Cleanup - for (UINT iItem = 0; ppDroppedItems[ iItem ]; ++iItem ) - { - free( ppDroppedItems[ iItem ] ); + for (UINT iItem = 0; ppDroppedItems[iItem]; ++iItem) { + free(ppDroppedItems[iItem]); } - free( ppDroppedItems ); + free(ppDroppedItems); return bSuccess; } -static int CountFiles( char *szItem ) +static int CountFiles(char *szItem) { int nCount = 0; WIN32_FIND_DATAA fd; - - HANDLE hFind = FindFirstFileA( szItem, &fd ); - - if ( hFind != INVALID_HANDLE_VALUE ) - { - do - { - if ( fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ) - { + + HANDLE hFind = FindFirstFileA(szItem, &fd); + + if (hFind != INVALID_HANDLE_VALUE) { + do { + if (fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { // Skip parent directories - if (( 0 != mir_strcmp( fd.cFileName, "." )) && - ( 0 != mir_strcmp( fd.cFileName, ".." )) ) - { + if ((0 != mir_strcmp(fd.cFileName, ".")) && + (0 != mir_strcmp(fd.cFileName, ".."))) { char szDirName[MAX_PATH]; - strncpy( szDirName, szItem, MAX_PATH - 1); + strncpy(szDirName, szItem, MAX_PATH - 1); - if ( NULL != strstr( szItem, "*.*" )) - { - size_t offset = mir_strlen( szDirName ) - 3; - mir_snprintf(szDirName + offset, SIZEOF( szDirName) - offset, "%s\0", fd.cFileName); + if (NULL != strstr(szItem, "*.*")) { + size_t offset = mir_strlen(szDirName) - 3; + mir_snprintf(szDirName + offset, SIZEOF(szDirName) - offset, "%s\0", fd.cFileName); } - + ++nCount; - mir_strcat( szDirName, "\\*.*" ); - nCount += CountFiles( szDirName ); + mir_strcat(szDirName, "\\*.*"); + nCount += CountFiles(szDirName); } } - else - { + else { ++nCount; } - } - while( FALSE != FindNextFileA( hFind, &fd )); + } while (FALSE != FindNextFileA(hFind, &fd)); } return nCount; @@ -247,78 +221,67 @@ static int CountFiles( char *szItem ) -static void SaveFiles( char *szItem, char **ppFiles, int *pnCount ) +static void SaveFiles(char *szItem, char **ppFiles, int *pnCount) { WIN32_FIND_DATAA fd; - HANDLE hFind = FindFirstFileA( szItem, &fd ); - - if ( hFind != INVALID_HANDLE_VALUE ) - { - do - { - if ( fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ) - { + HANDLE hFind = FindFirstFileA(szItem, &fd); + + if (hFind != INVALID_HANDLE_VALUE) { + do { + if (fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { // Skip parent directories - if (( 0 != mir_strcmp( fd.cFileName, "." )) && - ( 0 != mir_strcmp( fd.cFileName, ".." )) ) - { + if ((0 != mir_strcmp(fd.cFileName, ".")) && + (0 != mir_strcmp(fd.cFileName, ".."))) { char szDirName[MAX_PATH]; - strncpy( szDirName, szItem, MAX_PATH - 1); + strncpy(szDirName, szItem, MAX_PATH - 1); - if ( NULL != strstr( szItem, "*.*" )) - { - size_t offset = mir_strlen( szDirName ) - 3; - mir_snprintf(szDirName + offset, SIZEOF( szDirName) - offset, "%s\0", fd.cFileName); + if (NULL != strstr(szItem, "*.*")) { + size_t offset = mir_strlen(szDirName) - 3; + mir_snprintf(szDirName + offset, SIZEOF(szDirName) - offset, "%s\0", fd.cFileName); } - - ppFiles[ *pnCount ] = _strdup( szDirName ); - ++( *pnCount ); - mir_strcat( szDirName, "\\*.*" ); - SaveFiles( szDirName, ppFiles, pnCount ); - + ppFiles[*pnCount] = _strdup(szDirName); + ++(*pnCount); + + mir_strcat(szDirName, "\\*.*"); + SaveFiles(szDirName, ppFiles, pnCount); + } } - else - { - size_t nSize = sizeof(char) * ( mir_strlen( szItem ) + mir_strlen( fd.cFileName ) + sizeof( char )); - char *szFile = (char*) malloc( nSize ) ; - - strncpy( szFile, szItem, nSize - 1); - - if ( NULL != strstr( szFile, "*.*" )) - { - szFile[ mir_strlen( szFile ) - 3 ] = '\0'; + else { + size_t nSize = sizeof(char) * (mir_strlen(szItem) + mir_strlen(fd.cFileName) + sizeof(char)); + char *szFile = (char*)malloc(nSize); + + strncpy(szFile, szItem, nSize - 1); + + if (NULL != strstr(szFile, "*.*")) { + szFile[mir_strlen(szFile) - 3] = '\0'; mir_strncat(szFile, fd.cFileName, nSize - mir_strlen(szFile)); } - - ppFiles[ *pnCount ] = szFile; - ++( *pnCount ); + + ppFiles[*pnCount] = szFile; + ++(*pnCount); } - } - while( FALSE != FindNextFileA( hFind, &fd )); + } while (FALSE != FindNextFileA(hFind, &fd)); } } -static void ProcessDroppedItems( char **ppDroppedItems, int nCount, char **ppFiles ) +static void ProcessDroppedItems(char **ppDroppedItems, int nCount, char **ppFiles) { int fileCount = 0; - for (int i = 0; i < nCount; ++i ) - { - SaveFiles( ppDroppedItems[ i ], ppFiles, &fileCount ); - } + for (int i = 0; i < nCount; ++i) + SaveFiles(ppDroppedItems[i], ppFiles, &fileCount); } -static int CountDroppedFiles( char **ppDroppedItems, int nCount ) +static int CountDroppedFiles(char **ppDroppedItems, int nCount) { int fileCount = 0; - - for (int i = 0; i < nCount; ++i ) - { - fileCount += CountFiles( ppDroppedItems[ i ] ); + + for (int i = 0; i < nCount; ++i) { + fileCount += CountFiles(ppDroppedItems[i]); } return fileCount; @@ -327,20 +290,13 @@ static int CountDroppedFiles( char **ppDroppedItems, int nCount ) /////////////////////////////////////////////////////////////////////////////// // Init/destroy -void InitFileDropping() -{ -} - -void FreeFileDropping(void) -{ -} -void RegisterFileDropping( HWND hwnd, CDropTarget* pdropTarget ) +void RegisterFileDropping(HWND hwnd, CDropTarget* pdropTarget) { - RegisterDragDrop( hwnd, (IDropTarget*)pdropTarget ); + RegisterDragDrop(hwnd, (IDropTarget*)pdropTarget); } -void UnregisterFileDropping( HWND hwnd ) +void UnregisterFileDropping(HWND hwnd) { - RevokeDragDrop( hwnd ); + RevokeDragDrop(hwnd); } -- cgit v1.2.3