2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-06-29 03:39:35 +04:00
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
#define INCL_DOSMISC
|
|
|
|
#define INCL_DOSERRORS
|
|
|
|
|
1999-06-29 03:39:35 +04:00
|
|
|
#include "nsDragService.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
2002-04-16 02:56:31 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2003-03-26 04:01:27 +03:00
|
|
|
#include "nsIWebBrowserPersist.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2003-03-26 04:01:27 +03:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsNetUtil.h"
|
2003-04-02 02:36:10 +04:00
|
|
|
#include "nsOS2Uni.h"
|
2004-02-25 02:11:25 +03:00
|
|
|
#include "wdgtos2rc.h"
|
2006-06-27 00:40:08 +04:00
|
|
|
#include "nsILocalFileOS2.h"
|
|
|
|
#include "nsIDocument.h"
|
2007-04-22 21:47:28 +04:00
|
|
|
#include "nsGUIEvent.h"
|
2009-06-23 13:28:25 +04:00
|
|
|
#include "nsISelection.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
1999-06-29 03:39:35 +04:00
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
// --------------------------------------------------------------------------
|
2003-11-19 01:39:46 +03:00
|
|
|
// Local defines
|
|
|
|
|
|
|
|
// undocumented(?)
|
|
|
|
#ifndef DC_PREPAREITEM
|
|
|
|
#define DC_PREPAREITEM 0x0040
|
|
|
|
#endif
|
2003-07-08 02:42:44 +04:00
|
|
|
|
|
|
|
// limit URL object titles to a reasonable length
|
|
|
|
#define MAXTITLELTH 31
|
|
|
|
#define TITLESEPARATOR (L' ')
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
#define DTSHARE_NAME "\\SHAREMEM\\MOZ_DND"
|
|
|
|
#define DTSHARE_RMF "<DRM_DTSHARE, DRF_TEXT>"
|
|
|
|
|
|
|
|
#define OS2FILE_NAME "MOZ_TGT.TMP"
|
|
|
|
#define OS2FILE_TXTRMF "<DRM_OS2FILE, DRF_TEXT>"
|
|
|
|
#define OS2FILE_UNKRMF "<DRM_OS2FILE, DRF_UNKNOWN>"
|
|
|
|
|
2010-03-04 21:19:41 +03:00
|
|
|
// not defined in the OS/2 toolkit headers
|
|
|
|
extern "C" {
|
|
|
|
APIRET APIENTRY DosQueryModFromEIP(HMODULE *phMod, ULONG *pObjNum,
|
|
|
|
ULONG BuffLen, PCHAR pBuff,
|
|
|
|
ULONG *pOffset, ULONG Address);
|
|
|
|
}
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Helper functions
|
|
|
|
|
|
|
|
nsresult RenderToOS2File( PDRAGITEM pditem, HWND hwnd);
|
|
|
|
nsresult RenderToOS2FileComplete(PDRAGTRANSFER pdxfer, USHORT usResult,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool content, char** outText);
|
2003-11-19 01:39:46 +03:00
|
|
|
nsresult RenderToDTShare( PDRAGITEM pditem, HWND hwnd);
|
|
|
|
nsresult RenderToDTShareComplete(PDRAGTRANSFER pdxfer, USHORT usResult,
|
|
|
|
char** outText);
|
|
|
|
nsresult RequestRendering( PDRAGITEM pditem, HWND hwnd, PCSZ pRMF, PCSZ pName);
|
|
|
|
nsresult GetAtom( ATOM aAtom, char** outText);
|
|
|
|
nsresult GetFileName(PDRAGITEM pditem, char** outText);
|
|
|
|
nsresult GetFileContents(PCSZ pszPath, char** outText);
|
|
|
|
nsresult GetTempFileName(char** outText);
|
2012-06-06 06:08:30 +04:00
|
|
|
void SaveTypeAndSource(nsIFile *file, nsIDOMDocument *domDoc,
|
2006-06-27 00:40:08 +04:00
|
|
|
PCSZ pszType);
|
2003-11-19 01:39:46 +03:00
|
|
|
int UnicodeToCodepage( const nsAString& inString, char **outText);
|
|
|
|
int CodepageToUnicode( const nsACString& inString, PRUnichar **outText);
|
2005-11-09 19:18:54 +03:00
|
|
|
void RemoveCarriageReturns(char * pszText);
|
2008-10-27 01:02:42 +03:00
|
|
|
MRESULT EXPENTRY nsDragWindowProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
|
2003-07-08 02:42:44 +04:00
|
|
|
|
2003-10-23 01:57:01 +04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Global data
|
|
|
|
|
|
|
|
static HPOINTER gPtrArray[IDC_DNDCOUNT];
|
2003-11-19 01:39:46 +03:00
|
|
|
static char * gTempFile = 0;
|
2003-10-23 01:57:01 +04:00
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// --------------------------------------------------------------------------
|
2003-07-08 02:42:44 +04:00
|
|
|
// --------------------------------------------------------------------------
|
1999-06-29 03:39:35 +04:00
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
nsDragService::nsDragService()
|
1999-06-29 03:39:35 +04:00
|
|
|
{
|
2003-11-19 01:39:46 +03:00
|
|
|
// member initializers and constructor code
|
|
|
|
mDragWnd = WinCreateWindow( HWND_DESKTOP, WC_STATIC, 0, 0, 0, 0, 0, 0,
|
|
|
|
HWND_DESKTOP, HWND_BOTTOM, 0, 0, 0);
|
|
|
|
WinSubclassWindow( mDragWnd, nsDragWindowProc);
|
|
|
|
|
|
|
|
HMODULE hModResources = NULLHANDLE;
|
|
|
|
DosQueryModFromEIP(&hModResources, NULL, 0, NULL, NULL, (ULONG) &gPtrArray);
|
|
|
|
for (int i = 0; i < IDC_DNDCOUNT; i++)
|
|
|
|
gPtrArray[i] = ::WinLoadPointer(HWND_DESKTOP, hModResources, i+IDC_DNDBASE);
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
nsDragService::~nsDragService()
|
1999-06-29 03:39:35 +04:00
|
|
|
{
|
2003-11-19 01:39:46 +03:00
|
|
|
// destructor code
|
2002-04-16 02:56:31 +04:00
|
|
|
WinDestroyWindow(mDragWnd);
|
2003-10-23 01:57:01 +04:00
|
|
|
|
|
|
|
for (int i = 0; i < IDC_DNDCOUNT; i++) {
|
|
|
|
WinDestroyPointer(gPtrArray[i]);
|
|
|
|
gPtrArray[i] = 0;
|
|
|
|
}
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
|
|
|
|
2007-08-07 19:18:36 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsDragService, nsBaseDragService, nsIDragSessionOS2)
|
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
NS_IMETHODIMP nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode,
|
|
|
|
nsISupportsArray *aTransferables,
|
|
|
|
nsIScriptableRegion *aRegion,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aActionType)
|
1999-06-29 03:39:35 +04:00
|
|
|
{
|
2005-03-15 16:56:04 +03:00
|
|
|
if (mDoingDrag)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2008-03-19 23:18:41 +03:00
|
|
|
nsresult rv = nsBaseDragService::InvokeDragSession(aDOMNode, aTransferables,
|
|
|
|
aRegion, aActionType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
mSourceDataItems = aTransferables;
|
|
|
|
WinSetCapture(HWND_DESKTOP, NULLHANDLE);
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// Assume we are only dragging one thing for now
|
2003-07-08 02:42:44 +04:00
|
|
|
PDRAGINFO pDragInfo = DrgAllocDraginfo(1);
|
|
|
|
if (!pDragInfo)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
pDragInfo->usOperation = DO_DEFAULT;
|
2002-04-16 02:56:31 +04:00
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
DRAGITEM dragitem;
|
|
|
|
dragitem.hwndItem = mDragWnd;
|
|
|
|
dragitem.ulItemID = (ULONG)this;
|
|
|
|
dragitem.fsControl = DC_OPEN;
|
|
|
|
dragitem.cxOffset = 2;
|
|
|
|
dragitem.cyOffset = 2;
|
|
|
|
dragitem.fsSupportedOps = DO_COPYABLE|DO_MOVEABLE|DO_LINKABLE;
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// since there is no source file, leave these "blank"
|
2003-07-08 02:42:44 +04:00
|
|
|
dragitem.hstrContainerName = NULLHANDLE;
|
|
|
|
dragitem.hstrSourceName = NULLHANDLE;
|
|
|
|
|
2008-03-19 23:18:41 +03:00
|
|
|
rv = NS_ERROR_FAILURE;
|
2003-10-23 01:57:01 +04:00
|
|
|
ULONG idIcon = 0;
|
2003-07-08 02:42:44 +04:00
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// bracket this to reduce our footprint before the drag begins
|
2002-04-16 02:56:31 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> genericItem;
|
|
|
|
mSourceDataItems->GetElementAt(0, getter_AddRefs(genericItem));
|
2003-07-08 02:42:44 +04:00
|
|
|
nsCOMPtr<nsITransferable> transItem (do_QueryInterface(genericItem));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> genericData;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = 0;
|
2003-07-08 02:42:44 +04:00
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// see if we have a URL or text; if so, the title method
|
|
|
|
// will save the data and mimetype for use with a native drop
|
2003-07-08 02:42:44 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(transItem->GetTransferData(kURLMime,
|
|
|
|
getter_AddRefs(genericData), &len))) {
|
2003-11-19 01:39:46 +03:00
|
|
|
nsXPIDLCString targetName;
|
|
|
|
rv = GetUrlAndTitle( genericData, getter_Copies(targetName));
|
2003-07-08 02:42:44 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// advise PM that we need a DM_RENDERPREPARE msg
|
|
|
|
// *before* it composes a render-to filename
|
|
|
|
dragitem.fsControl |= DC_PREPAREITEM;
|
|
|
|
dragitem.hstrType = DrgAddStrHandle("UniformResourceLocator");
|
2003-11-19 01:39:46 +03:00
|
|
|
dragitem.hstrRMF = DrgAddStrHandle("<DRM_OS2FILE,DRF_TEXT>");
|
|
|
|
dragitem.hstrTargetName = DrgAddStrHandle(targetName.get());
|
2003-10-23 01:57:01 +04:00
|
|
|
idIcon = IDC_DNDURL;
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
2002-04-16 02:56:31 +04:00
|
|
|
}
|
2003-07-08 02:42:44 +04:00
|
|
|
else
|
|
|
|
if (NS_SUCCEEDED(transItem->GetTransferData(kUnicodeMime,
|
|
|
|
getter_AddRefs(genericData), &len))) {
|
2003-11-19 01:39:46 +03:00
|
|
|
nsXPIDLCString targetName;
|
|
|
|
rv = GetUniTextTitle( genericData, getter_Copies(targetName));
|
2003-07-08 02:42:44 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
dragitem.hstrType = DrgAddStrHandle("Plain Text");
|
|
|
|
dragitem.hstrRMF = DrgAddStrHandle("<DRM_OS2FILE,DRF_TEXT>");
|
2003-11-19 01:39:46 +03:00
|
|
|
dragitem.hstrTargetName = DrgAddStrHandle(targetName.get());
|
2003-10-23 01:57:01 +04:00
|
|
|
idIcon = IDC_DNDTEXT;
|
2003-07-08 02:42:44 +04:00
|
|
|
}
|
2002-04-16 02:56:31 +04:00
|
|
|
}
|
2003-07-08 02:42:44 +04:00
|
|
|
}
|
2003-03-26 04:01:27 +03:00
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// if neither URL nor text are available, make this a Moz-only drag
|
|
|
|
// by making it unidentifiable to native apps
|
2003-07-08 02:42:44 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mMimeType = 0;
|
|
|
|
dragitem.hstrType = DrgAddStrHandle("Unknown");
|
|
|
|
dragitem.hstrRMF = DrgAddStrHandle("<DRM_UNKNOWN,DRF_UNKNOWN>");
|
|
|
|
dragitem.hstrTargetName = NULLHANDLE;
|
|
|
|
}
|
|
|
|
DrgSetDragitem(pDragInfo, &dragitem, sizeof(DRAGITEM), 0);
|
2003-03-26 04:01:27 +03:00
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
DRAGIMAGE dragimage;
|
|
|
|
memset(&dragimage, 0, sizeof(DRAGIMAGE));
|
|
|
|
dragimage.cb = sizeof(DRAGIMAGE);
|
|
|
|
dragimage.fl = DRG_ICON;
|
2003-10-23 01:57:01 +04:00
|
|
|
if (idIcon)
|
|
|
|
dragimage.hImage = gPtrArray[idIcon-IDC_DNDBASE];
|
|
|
|
if (dragimage.hImage) {
|
|
|
|
dragimage.cyOffset = 8;
|
|
|
|
dragimage.cxOffset = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dragimage.hImage = WinQuerySysPointer(HWND_DESKTOP, SPTR_FILE, FALSE);
|
2002-04-16 02:56:31 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mDoingDrag = true;
|
2009-06-23 13:28:25 +04:00
|
|
|
LONG escState = WinGetKeyState(HWND_DESKTOP, VK_ESC) & 0x01;
|
2003-07-08 02:42:44 +04:00
|
|
|
HWND hwndDest = DrgDrag(mDragWnd, pDragInfo, &dragimage, 1, VK_BUTTON2,
|
|
|
|
(void*)0x80000000L); // Don't lock the desktop PS
|
2009-06-23 13:28:25 +04:00
|
|
|
|
|
|
|
// determine whether the drag ended because Escape was pressed
|
|
|
|
if (hwndDest == 0 && (WinGetKeyState(HWND_DESKTOP, VK_ESC) & 0x01) != escState)
|
2011-10-17 18:59:28 +04:00
|
|
|
mUserCancelled = true;
|
2007-04-12 08:37:39 +04:00
|
|
|
FireDragEventAtSource(NS_DRAGDROP_END);
|
2011-10-17 18:59:28 +04:00
|
|
|
mDoingDrag = false;
|
1999-06-29 03:39:35 +04:00
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// do clean up; if the drop completed,
|
|
|
|
// the target will delete the string handles
|
2003-07-08 02:42:44 +04:00
|
|
|
if (hwndDest == 0)
|
|
|
|
DrgDeleteDraginfoStrHandles(pDragInfo);
|
|
|
|
DrgFreeDraginfo(pDragInfo);
|
1999-06-29 03:39:35 +04:00
|
|
|
|
2009-06-23 13:28:25 +04:00
|
|
|
// reset nsDragService's members
|
2003-03-26 04:01:27 +03:00
|
|
|
mSourceDataItems = 0;
|
2003-07-08 02:42:44 +04:00
|
|
|
mSourceData = 0;
|
|
|
|
mMimeType = 0;
|
2003-03-26 04:01:27 +03:00
|
|
|
|
2009-06-23 13:28:25 +04:00
|
|
|
// reset nsBaseDragService's members
|
2012-07-30 18:20:58 +04:00
|
|
|
mSourceDocument = nullptr;
|
|
|
|
mSourceNode = nullptr;
|
|
|
|
mSelection = nullptr;
|
|
|
|
mDataTransfer = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mUserCancelled = false;
|
|
|
|
mHasImage = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
mImage = nullptr;
|
2009-06-23 13:28:25 +04:00
|
|
|
mImageX = 0;
|
|
|
|
mImageY = 0;
|
|
|
|
mScreenX = -1;
|
|
|
|
mScreenY = -1;
|
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
return NS_OK;
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
MRESULT EXPENTRY nsDragWindowProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|
|
|
{
|
|
|
|
switch (msg) {
|
|
|
|
|
|
|
|
// if the user requests the contents of a URL be rendered (vs the URL
|
|
|
|
// itself), change the suggested target name from the URL's title to
|
|
|
|
// the name of the file that will be retrieved
|
|
|
|
case DM_RENDERPREPARE: {
|
|
|
|
PDRAGTRANSFER pdxfer = (PDRAGTRANSFER)mp1;
|
|
|
|
nsDragService* dragservice = (nsDragService*)pdxfer->pditem->ulItemID;
|
|
|
|
|
|
|
|
if (pdxfer->usOperation == DO_COPY &&
|
2005-01-28 19:10:31 +03:00
|
|
|
(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000) &&
|
2003-11-19 01:39:46 +03:00
|
|
|
!strcmp(dragservice->mMimeType, kURLMime)) {
|
|
|
|
// QI'ing nsIURL will fail for mailto: and the like
|
|
|
|
nsCOMPtr<nsIURL> urlObject(do_QueryInterface(dragservice->mSourceData));
|
|
|
|
if (urlObject) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString filename;
|
2003-11-19 01:39:46 +03:00
|
|
|
urlObject->GetFileName(filename);
|
|
|
|
if (filename.IsEmpty()) {
|
|
|
|
urlObject->GetHost(filename);
|
|
|
|
filename.Append("/file");
|
|
|
|
}
|
|
|
|
DrgDeleteStrHandle(pdxfer->pditem->hstrTargetName);
|
|
|
|
pdxfer->pditem->hstrTargetName = DrgAddStrHandle(filename.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (MRESULT)TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DM_RENDER: {
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
PDRAGTRANSFER pdxfer = (PDRAGTRANSFER)mp1;
|
|
|
|
nsDragService* dragservice = (nsDragService*)pdxfer->pditem->ulItemID;
|
|
|
|
char chPath[CCHMAXPATH];
|
|
|
|
|
|
|
|
DrgQueryStrName(pdxfer->hstrRenderToName, CCHMAXPATH, chPath);
|
|
|
|
|
|
|
|
// if the user Ctrl-dropped a URL, use the nsIURL interface
|
|
|
|
// to determine if it points to content (i.e. a file); if so,
|
|
|
|
// fetch its contents; if not (e.g. a 'mailto:' url), drop into
|
|
|
|
// the code that uses nsIURI to render a URL object
|
|
|
|
|
|
|
|
if (!strcmp(dragservice->mMimeType, kURLMime)) {
|
2005-01-28 19:10:31 +03:00
|
|
|
if (pdxfer->usOperation == DO_COPY &&
|
|
|
|
(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)) {
|
2003-11-19 01:39:46 +03:00
|
|
|
nsCOMPtr<nsIURL> urlObject(do_QueryInterface(dragservice->mSourceData));
|
|
|
|
if (urlObject)
|
|
|
|
rv = dragservice->SaveAsContents(chPath, urlObject);
|
|
|
|
}
|
|
|
|
if (!NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIURI> uriObject(do_QueryInterface(dragservice->mSourceData));
|
|
|
|
if (uriObject)
|
|
|
|
rv = dragservice->SaveAsURL(chPath, uriObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// if we're dragging text, do NLS conversion then write it to file
|
|
|
|
if (!strcmp(dragservice->mMimeType, kUnicodeMime)) {
|
|
|
|
nsCOMPtr<nsISupportsString> strObject(
|
|
|
|
do_QueryInterface(dragservice->mSourceData));
|
|
|
|
if (strObject)
|
|
|
|
rv = dragservice->SaveAsText(chPath, strObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
DrgPostTransferMsg(pdxfer->hwndClient, DM_RENDERCOMPLETE, pdxfer,
|
|
|
|
(NS_SUCCEEDED(rv) ? DMFL_RENDEROK : DMFL_RENDERFAIL),
|
|
|
|
0, TRUE);
|
|
|
|
DrgFreeDragtransfer(pdxfer);
|
|
|
|
return (MRESULT)TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we don't use these msgs but neither does WinDefWindowProc()
|
|
|
|
case DM_DRAGOVERNOTIFY:
|
|
|
|
case DM_ENDCONVERSATION:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::WinDefWindowProc(hWnd, msg, mp1, mp2);
|
|
|
|
}
|
|
|
|
|
2005-03-28 20:33:50 +04:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// if the versions of Start & EndDragSession in nsBaseDragService
|
|
|
|
// were called (and they shouldn't be), they'd break nsIDragSessionOS2;
|
|
|
|
// they're overridden here and turned into no-ops to prevent this
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDragService::StartDragSession()
|
|
|
|
{
|
2009-08-14 18:09:00 +04:00
|
|
|
NS_ERROR("OS/2 version of StartDragSession() should never be called!");
|
2005-03-28 20:33:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsDragService::EndDragSession(bool aDragDone)
|
2005-03-28 20:33:50 +04:00
|
|
|
{
|
2009-08-14 18:09:00 +04:00
|
|
|
NS_ERROR("OS/2 version of EndDragSession() should never be called!");
|
2005-03-28 20:33:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsDragService::GetNumDropItems(uint32_t *aNumDropItems)
|
1999-06-29 03:39:35 +04:00
|
|
|
{
|
2003-11-19 01:39:46 +03:00
|
|
|
if (mSourceDataItems)
|
|
|
|
mSourceDataItems->Count(aNumDropItems);
|
|
|
|
else
|
|
|
|
*aNumDropItems = 0;
|
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
return NS_OK;
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
NS_IMETHODIMP nsDragService::GetData(nsITransferable *aTransferable,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aItemIndex)
|
1999-06-29 03:39:35 +04:00
|
|
|
{
|
2003-11-19 01:39:46 +03:00
|
|
|
// make sure that we have a transferable
|
2002-04-16 02:56:31 +04:00
|
|
|
if (!aTransferable)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// get flavor list that includes all acceptable flavors (including
|
|
|
|
// ones obtained through conversion). Flavors are nsISupportsCStrings
|
|
|
|
// so that they can be seen from JS.
|
2002-04-16 02:56:31 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsISupportsArray> flavorList;
|
|
|
|
rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// count the number of flavors
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t cnt;
|
2002-04-16 02:56:31 +04:00
|
|
|
flavorList->Count (&cnt);
|
|
|
|
|
|
|
|
for (unsigned int i= 0; i < cnt; ++i ) {
|
|
|
|
nsCOMPtr<nsISupports> genericWrapper;
|
|
|
|
flavorList->GetElementAt(i, getter_AddRefs(genericWrapper));
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> currentFlavor;
|
2002-04-16 02:56:31 +04:00
|
|
|
currentFlavor = do_QueryInterface(genericWrapper);
|
|
|
|
if (currentFlavor) {
|
2002-08-27 07:11:42 +04:00
|
|
|
nsXPIDLCString flavorStr;
|
|
|
|
currentFlavor->ToString(getter_Copies(flavorStr));
|
2002-04-16 02:56:31 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> genericItem;
|
|
|
|
|
|
|
|
mSourceDataItems->GetElementAt(aItemIndex, getter_AddRefs(genericItem));
|
|
|
|
nsCOMPtr<nsITransferable> item (do_QueryInterface(genericItem));
|
|
|
|
if (item) {
|
|
|
|
nsCOMPtr<nsISupports> data;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t tmpDataLen = 0;
|
2003-11-19 01:39:46 +03:00
|
|
|
rv = item->GetTransferData(flavorStr, getter_AddRefs(data),
|
|
|
|
&tmpDataLen);
|
2002-04-16 02:56:31 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2002-08-27 07:11:42 +04:00
|
|
|
rv = aTransferable->SetTransferData(flavorStr, data, tmpDataLen);
|
2002-04-16 02:56:31 +04:00
|
|
|
break;
|
|
|
|
}
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
2002-04-16 02:56:31 +04:00
|
|
|
}
|
|
|
|
}
|
2003-11-19 01:39:46 +03:00
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
return rv;
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// This returns true if any of the dragged items support a specified data
|
|
|
|
// flavor. This doesn't make a lot of sense when dragging multiple items:
|
|
|
|
// all of them ought to match. OTOH, Moz doesn't support multiple drag
|
|
|
|
// items so no problems arise. If they do, use the commented-out code to
|
|
|
|
// switch from "any" to "all".
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDragService::IsDataFlavorSupported(const char *aDataFlavor,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval)
|
1999-06-29 03:39:35 +04:00
|
|
|
{
|
2002-04-16 02:56:31 +04:00
|
|
|
if (!_retval)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2002-04-16 02:56:31 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numDragItems = 0;
|
2003-11-19 01:39:46 +03:00
|
|
|
if (mSourceDataItems)
|
|
|
|
mSourceDataItems->Count(&numDragItems);
|
|
|
|
if (!numDragItems)
|
2002-04-16 02:56:31 +04:00
|
|
|
return NS_OK;
|
2003-11-19 01:39:46 +03:00
|
|
|
|
|
|
|
// return true if all items support this flavor
|
2012-08-22 19:56:38 +04:00
|
|
|
// for (uint32_t itemIndex = 0, *_retval = true;
|
2003-11-19 01:39:46 +03:00
|
|
|
// itemIndex < numDragItems && *_retval; ++itemIndex) {
|
2011-10-17 18:59:28 +04:00
|
|
|
// *_retval = false;
|
2003-11-19 01:39:46 +03:00
|
|
|
|
|
|
|
// return true if any item supports this flavor
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t itemIndex = 0;
|
2003-11-19 01:39:46 +03:00
|
|
|
itemIndex < numDragItems && !(*_retval); ++itemIndex) {
|
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
nsCOMPtr<nsISupports> genericItem;
|
|
|
|
mSourceDataItems->GetElementAt(itemIndex, getter_AddRefs(genericItem));
|
|
|
|
nsCOMPtr<nsITransferable> currItem (do_QueryInterface(genericItem));
|
2003-11-19 01:39:46 +03:00
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
if (currItem) {
|
|
|
|
nsCOMPtr <nsISupportsArray> flavorList;
|
|
|
|
currItem->FlavorsTransferableCanExport(getter_AddRefs(flavorList));
|
2003-11-19 01:39:46 +03:00
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
if (flavorList) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numFlavors;
|
2002-04-16 02:56:31 +04:00
|
|
|
flavorList->Count( &numFlavors );
|
2003-11-19 01:39:46 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t flavorIndex=0; flavorIndex < numFlavors; ++flavorIndex) {
|
2002-04-16 02:56:31 +04:00
|
|
|
nsCOMPtr<nsISupports> genericWrapper;
|
2003-11-19 01:39:46 +03:00
|
|
|
flavorList->GetElementAt(flavorIndex, getter_AddRefs(genericWrapper));
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> currentFlavor;
|
2002-04-16 02:56:31 +04:00
|
|
|
currentFlavor = do_QueryInterface(genericWrapper);
|
2003-11-19 01:39:46 +03:00
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
if (currentFlavor) {
|
2002-08-27 07:11:42 +04:00
|
|
|
nsXPIDLCString flavorStr;
|
|
|
|
currentFlavor->ToString ( getter_Copies(flavorStr) );
|
|
|
|
if (strcmp(flavorStr, aDataFlavor) == 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = true;
|
2003-11-19 01:39:46 +03:00
|
|
|
break;
|
2002-04-16 02:56:31 +04:00
|
|
|
}
|
|
|
|
}
|
2003-11-19 01:39:46 +03:00
|
|
|
} // for each flavor
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
2002-04-16 02:56:31 +04:00
|
|
|
}
|
|
|
|
}
|
2003-11-19 01:39:46 +03:00
|
|
|
|
2002-04-16 02:56:31 +04:00
|
|
|
return NS_OK;
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// use nsIWebBrowserPersist to fetch the contents of a URL
|
|
|
|
|
|
|
|
nsresult nsDragService::SaveAsContents(PCSZ pszDest, nsIURL* aURL)
|
2003-03-26 04:01:27 +03:00
|
|
|
{
|
2006-06-27 00:40:08 +04:00
|
|
|
nsCOMPtr<nsIURI> linkURI(do_QueryInterface(aURL));
|
|
|
|
if (!linkURI)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebBrowserPersist> webPersist(
|
|
|
|
do_CreateInstance("@mozilla.org/embedding/browser/nsWebBrowserPersist;1"));
|
|
|
|
if (!webPersist)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(pszDest), true,
|
2006-06-27 00:40:08 +04:00
|
|
|
getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-11-19 01:39:46 +03:00
|
|
|
|
2006-06-27 00:40:08 +04:00
|
|
|
FILE* fp;
|
|
|
|
if (NS_FAILED(file->OpenANSIFileDesc("wb+", &fp)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-10-04 23:07:51 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
GetSourceDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> document = do_QueryInterface(domDoc);
|
|
|
|
|
2006-06-27 00:40:08 +04:00
|
|
|
fwrite("", 0, 1, fp);
|
|
|
|
fclose(fp);
|
2012-10-04 23:07:51 +04:00
|
|
|
webPersist->SaveURI(linkURI, nullptr, nullptr, nullptr, nullptr, file,
|
|
|
|
document->GetLoadContext());
|
2006-06-27 00:40:08 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2003-11-19 01:39:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// save this URL in a file that the WPS will identify as a WPUrl object
|
2003-03-26 04:01:27 +03:00
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
nsresult nsDragService::SaveAsURL(PCSZ pszDest, nsIURI* aURI)
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString strUri;
|
2003-11-19 01:39:46 +03:00
|
|
|
aURI->GetSpec(strUri);
|
|
|
|
|
2006-06-27 00:40:08 +04:00
|
|
|
if (strUri.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-11-19 01:39:46 +03:00
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(pszDest), true,
|
2006-06-27 00:40:08 +04:00
|
|
|
getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
FILE* fp;
|
|
|
|
if (NS_FAILED(file->OpenANSIFileDesc("wb+", &fp)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
fwrite(strUri.get(), strUri.Length(), 1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
GetSourceDocument(getter_AddRefs(domDoc));
|
|
|
|
SaveTypeAndSource(file, domDoc, "UniformResourceLocator");
|
|
|
|
|
|
|
|
return NS_OK;
|
2003-11-19 01:39:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// save this text to file after conversion to the current codepage
|
|
|
|
|
|
|
|
nsresult nsDragService::SaveAsText(PCSZ pszDest, nsISupportsString* aString)
|
|
|
|
{
|
|
|
|
nsAutoString strData;
|
|
|
|
aString->GetData(strData);
|
|
|
|
|
2006-06-27 00:40:08 +04:00
|
|
|
if (strData.IsEmpty())
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-07-08 02:42:44 +04:00
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(pszDest), true,
|
2006-06-27 00:40:08 +04:00
|
|
|
getter_AddRefs(file));
|
|
|
|
if (!file)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsXPIDLCString textStr;
|
|
|
|
int cnt = UnicodeToCodepage(strData, getter_Copies(textStr));
|
|
|
|
if (!cnt)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
FILE* fp;
|
|
|
|
if (NS_FAILED(file->OpenANSIFileDesc("wb+", &fp)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
fwrite(textStr.get(), cnt, 1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
GetSourceDocument(getter_AddRefs(domDoc));
|
|
|
|
SaveTypeAndSource(file, domDoc, "Plain Text");
|
|
|
|
|
|
|
|
return NS_OK;
|
2003-03-26 04:01:27 +03:00
|
|
|
}
|
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Split a Moz Url/Title into its components, save the Url for use by
|
|
|
|
// a native drop, then compose a title.
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
nsresult nsDragService::GetUrlAndTitle(nsISupports *aGenericData,
|
|
|
|
char **aTargetName)
|
1999-06-29 03:39:35 +04:00
|
|
|
{
|
2003-11-19 01:39:46 +03:00
|
|
|
// get the URL/title string
|
2003-07-08 02:42:44 +04:00
|
|
|
nsCOMPtr<nsISupportsString> strObject ( do_QueryInterface(aGenericData));
|
|
|
|
if (!strObject)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsAutoString strData;
|
|
|
|
strObject->GetData(strData);
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// split string into URL and Title -
|
|
|
|
// if there's a title but no URL, there's no reason to continue
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t lineIndex = strData.FindChar ('\n');
|
2003-07-08 02:42:44 +04:00
|
|
|
if (lineIndex == 0)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// get the URL portion of the text
|
2003-07-08 02:42:44 +04:00
|
|
|
nsAutoString strUrl;
|
|
|
|
if (lineIndex == -1)
|
|
|
|
strUrl = strData;
|
|
|
|
else
|
|
|
|
strData.Left(strUrl, lineIndex);
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// save the URL for later use
|
2003-07-08 02:42:44 +04:00
|
|
|
nsCOMPtr<nsIURI> saveURI;
|
|
|
|
NS_NewURI(getter_AddRefs(saveURI), strUrl);
|
|
|
|
if (!saveURI)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// if there's a bona-fide title & it isn't just a copy of the URL,
|
|
|
|
// limit it to a reasonable length, perform NLS conversion, then return
|
2003-07-08 02:42:44 +04:00
|
|
|
|
|
|
|
if (++lineIndex && lineIndex != (int)strData.Length() &&
|
|
|
|
!strUrl.Equals(Substring(strData, lineIndex, strData.Length()))) {
|
2013-01-15 16:22:03 +04:00
|
|
|
uint32_t strLth = std::min((int)strData.Length()-lineIndex, MAXTITLELTH);
|
2003-07-08 02:42:44 +04:00
|
|
|
nsAutoString strTitle;
|
|
|
|
strData.Mid(strTitle, lineIndex, strLth);
|
|
|
|
if (!UnicodeToCodepage(strTitle, aTargetName))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mSourceData = do_QueryInterface(saveURI);
|
|
|
|
mMimeType = kURLMime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// if the URI can be handled as a URL, construct a title from
|
|
|
|
// the hostname & filename; if not, use the first MAXTITLELTH
|
|
|
|
// characters that appear after the scheme name
|
2003-07-08 02:42:44 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString strTitle;
|
2003-07-08 02:42:44 +04:00
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
nsCOMPtr<nsIURL> urlObj( do_QueryInterface(saveURI));
|
|
|
|
if (urlObj) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString strFile;
|
2003-11-19 01:39:46 +03:00
|
|
|
|
|
|
|
urlObj->GetHost(strTitle);
|
|
|
|
urlObj->GetFileName(strFile);
|
|
|
|
if (!strFile.IsEmpty()) {
|
2004-06-17 04:13:25 +04:00
|
|
|
strTitle.AppendLiteral("/");
|
2003-11-19 01:39:46 +03:00
|
|
|
strTitle.Append(strFile);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
urlObj->GetDirectory(strFile);
|
|
|
|
if (strFile.Length() > 1) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString::const_iterator start, end, curr;
|
2003-11-19 01:39:46 +03:00
|
|
|
strFile.BeginReading(start);
|
|
|
|
strFile.EndReading(end);
|
|
|
|
strFile.EndReading(curr);
|
|
|
|
for (curr.advance(-2); curr != start; --curr)
|
|
|
|
if (*curr == '/')
|
|
|
|
break;
|
|
|
|
strTitle.Append(Substring(curr, end));
|
|
|
|
}
|
|
|
|
}
|
2003-07-08 02:42:44 +04:00
|
|
|
}
|
|
|
|
else {
|
2003-11-19 01:39:46 +03:00
|
|
|
saveURI->GetSpec(strTitle);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = strTitle.FindChar (':');
|
2003-11-19 01:39:46 +03:00
|
|
|
if (index != -1) {
|
|
|
|
if ((strTitle.get())[++index] == '/')
|
|
|
|
if ((strTitle.get())[++index] == '/')
|
|
|
|
++index;
|
|
|
|
strTitle.Cut(0, index);
|
2003-07-08 02:42:44 +04:00
|
|
|
}
|
2003-11-19 01:39:46 +03:00
|
|
|
if (strTitle.Length() > MAXTITLELTH)
|
|
|
|
strTitle.Truncate(MAXTITLELTH);
|
2003-07-08 02:42:44 +04:00
|
|
|
}
|
2003-11-19 01:39:46 +03:00
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
*aTargetName = ToNewCString(strTitle);
|
|
|
|
|
|
|
|
mSourceData = do_QueryInterface(saveURI);
|
|
|
|
mMimeType = kURLMime;
|
|
|
|
return NS_OK;
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
2003-07-08 02:42:44 +04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Construct a title for text drops from the leading words of the text.
|
|
|
|
// Alphanumeric characters are copied to the title; sequences of
|
|
|
|
// non-alphanums are replaced by a single space
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
nsresult nsDragService::GetUniTextTitle(nsISupports *aGenericData,
|
|
|
|
char **aTargetName)
|
2003-07-08 02:42:44 +04:00
|
|
|
{
|
2003-11-19 01:39:46 +03:00
|
|
|
// get the string
|
2003-07-08 02:42:44 +04:00
|
|
|
nsCOMPtr<nsISupportsString> strObject ( do_QueryInterface(aGenericData));
|
|
|
|
if (!strObject)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// alloc a buffer to hold the unicode title text
|
2003-07-08 02:42:44 +04:00
|
|
|
int bufsize = (MAXTITLELTH+1)*2;
|
|
|
|
PRUnichar * buffer = (PRUnichar*)nsMemory::Alloc(bufsize);
|
|
|
|
if (!buffer)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsAutoString strData;
|
|
|
|
strObject->GetData(strData);
|
|
|
|
nsAutoString::const_iterator start, end;
|
|
|
|
strData.BeginReading(start);
|
|
|
|
strData.EndReading(end);
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// skip over leading non-alphanumerics
|
2003-07-08 02:42:44 +04:00
|
|
|
for( ; start != end; ++start)
|
|
|
|
if (UniQueryChar( *start, CT_ALNUM))
|
|
|
|
break;
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// move alphanumerics into the buffer & replace contiguous
|
|
|
|
// non-alnums with a single separator character
|
2003-07-08 02:42:44 +04:00
|
|
|
int ctr, sep;
|
|
|
|
for (ctr=0, sep=0; start != end && ctr < MAXTITLELTH; ++start) {
|
|
|
|
if (UniQueryChar( *start, CT_ALNUM)) {
|
|
|
|
buffer[ctr] = *start;
|
|
|
|
ctr++;
|
|
|
|
sep = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (!sep) {
|
|
|
|
buffer[ctr] = TITLESEPARATOR;
|
|
|
|
ctr++;
|
|
|
|
sep = 1;
|
|
|
|
}
|
|
|
|
}
|
2003-11-19 01:39:46 +03:00
|
|
|
// eliminate trailing separators & lone characters
|
|
|
|
// orphaned when the title is truncated
|
2003-07-08 02:42:44 +04:00
|
|
|
if (sep)
|
|
|
|
ctr--;
|
|
|
|
if (ctr >= MAXTITLELTH - sep && buffer[ctr-2] == TITLESEPARATOR)
|
|
|
|
ctr -= 2;
|
|
|
|
buffer[ctr] = 0;
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// if we ended up with no alnums, call the result "text";
|
|
|
|
// otherwise, do NLS conversion
|
2003-07-08 02:42:44 +04:00
|
|
|
if (!ctr) {
|
|
|
|
*aTargetName = ToNewCString(NS_LITERAL_CSTRING("text"));
|
|
|
|
ctr = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ctr = UnicodeToCodepage( nsDependentString(buffer), aTargetName);
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// free our buffer, then exit
|
2003-07-08 02:42:44 +04:00
|
|
|
nsMemory::Free(buffer);
|
|
|
|
|
|
|
|
if (!ctr)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mSourceData = aGenericData;
|
|
|
|
mMimeType = kUnicodeMime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// nsIDragSessionOS2
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// DragOverMsg() provides minimal handling if a drag session is already
|
|
|
|
// in progress. If not, it assumes this is a native drag that has just
|
|
|
|
// entered the window and calls NativeDragEnter() to start a session.
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDragService::DragOverMsg(PDRAGINFO pdinfo, MRESULT &mr,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t* dragFlags)
|
2003-11-19 01:39:46 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (!&mr || !dragFlags || !pdinfo || !DrgAccessDraginfo(pdinfo))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*dragFlags = 0;
|
|
|
|
mr = MRFROM2SHORT(DOR_NEVERDROP, 0);
|
|
|
|
|
|
|
|
// examine the dragged item & "start" a drag session if OK;
|
|
|
|
// also, signal the need for a dragenter event
|
|
|
|
if (!mDoingDrag)
|
|
|
|
if (NS_SUCCEEDED(NativeDragEnter(pdinfo)))
|
|
|
|
*dragFlags |= DND_DISPATCHENTEREVENT;
|
|
|
|
|
|
|
|
// if we're in a drag, set it up to be dispatched
|
|
|
|
if (mDoingDrag) {
|
2011-10-17 18:59:28 +04:00
|
|
|
SetCanDrop(false);
|
2003-11-19 01:39:46 +03:00
|
|
|
switch (pdinfo->usOperation) {
|
|
|
|
case DO_COPY:
|
|
|
|
SetDragAction(DRAGDROP_ACTION_COPY);
|
|
|
|
break;
|
|
|
|
case DO_LINK:
|
|
|
|
SetDragAction(DRAGDROP_ACTION_LINK);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetDragAction(DRAGDROP_ACTION_MOVE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mSourceNode)
|
|
|
|
*dragFlags |= DND_DISPATCHEVENT | DND_GETDRAGOVERRESULT | DND_MOZDRAG;
|
|
|
|
else
|
|
|
|
*dragFlags |= DND_DISPATCHEVENT | DND_GETDRAGOVERRESULT | DND_NATIVEDRAG;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrgFreeDraginfo(pdinfo);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Evaluates native drag data, and if acceptable, creates & stores
|
|
|
|
// a transferable with the available flavors (but not the data);
|
|
|
|
// if successful, it "starts" the session.
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDragService::NativeDragEnter(PDRAGINFO pdinfo)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isFQFile = FALSE;
|
|
|
|
bool isAtom = FALSE;
|
2003-11-19 01:39:46 +03:00
|
|
|
PDRAGITEM pditem = 0;
|
|
|
|
|
|
|
|
if (pdinfo->cditem != 1)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
pditem = DrgQueryDragitemPtr(pdinfo, 0);
|
|
|
|
|
|
|
|
if (pditem) {
|
2005-01-28 19:10:31 +03:00
|
|
|
if (DrgVerifyRMF(pditem, "DRM_ATOM", 0)) {
|
|
|
|
isAtom = TRUE;
|
2003-11-19 01:39:46 +03:00
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
else
|
2005-01-28 19:10:31 +03:00
|
|
|
if (DrgVerifyRMF(pditem, "DRM_DTSHARE", 0))
|
|
|
|
rv = NS_OK;
|
|
|
|
else
|
2003-11-19 01:39:46 +03:00
|
|
|
if (DrgVerifyRMF(pditem, "DRM_OS2FILE", 0)) {
|
|
|
|
rv = NS_OK;
|
|
|
|
if (pditem->hstrContainerName && pditem->hstrSourceName)
|
|
|
|
isFQFile = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsITransferable> trans(
|
|
|
|
do_CreateInstance("@mozilla.org/widget/transferable;1", &rv));
|
|
|
|
if (trans) {
|
2012-07-30 18:20:58 +04:00
|
|
|
trans->Init(nullptr);
|
2003-11-19 01:39:46 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isUrl = DrgVerifyType(pditem, "UniformResourceLocator");
|
|
|
|
bool isAlt = (WinGetKeyState(HWND_DESKTOP, VK_ALT) & 0x8000);
|
2005-01-28 19:10:31 +03:00
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// if this is a fully-qualified file or the item claims to be
|
|
|
|
// a Url, identify it as a Url & also offer it as html
|
2005-01-28 19:10:31 +03:00
|
|
|
if ((isFQFile && !isAlt) || isUrl) {
|
2003-11-19 01:39:46 +03:00
|
|
|
trans->AddDataFlavor(kURLMime);
|
|
|
|
trans->AddDataFlavor(kHTMLMime);
|
|
|
|
}
|
|
|
|
|
|
|
|
// everything is always "text"
|
|
|
|
trans->AddDataFlavor(kUnicodeMime);
|
|
|
|
|
|
|
|
// if we can create the array, initialize the session
|
|
|
|
nsCOMPtr<nsISupportsArray> transArray(
|
|
|
|
do_CreateInstance("@mozilla.org/supports-array;1", &rv));
|
|
|
|
if (transArray) {
|
|
|
|
transArray->InsertElementAt(trans, 0);
|
|
|
|
mSourceDataItems = transArray;
|
2005-01-28 19:10:31 +03:00
|
|
|
|
|
|
|
// add the dragged data to the transferable if we have easy access
|
|
|
|
// to it (i.e. no need to read a file or request rendering); for
|
|
|
|
// URLs, we'll skip creating a title until the drop occurs
|
|
|
|
nsXPIDLCString someText;
|
|
|
|
if (isAtom) {
|
|
|
|
if (NS_SUCCEEDED(GetAtom(pditem->ulItemID, getter_Copies(someText))))
|
|
|
|
NativeDataToTransferable( someText.get(), 0, isUrl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (isFQFile && !isAlt &&
|
|
|
|
NS_SUCCEEDED(GetFileName(pditem, getter_Copies(someText)))) {
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2011-10-17 18:59:28 +04:00
|
|
|
if (NS_SUCCEEDED(NS_NewNativeLocalFile(someText, true,
|
2005-01-28 19:10:31 +03:00
|
|
|
getter_AddRefs(file)))) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString textStr;
|
2005-01-28 19:10:31 +03:00
|
|
|
NS_GetURLSpecFromFile(file, textStr);
|
|
|
|
if (!textStr.IsEmpty()) {
|
|
|
|
someText.Assign(ToNewCString(textStr));
|
|
|
|
NativeDataToTransferable( someText.get(), 0, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
mSourceNode = 0;
|
|
|
|
mSourceDocument = 0;
|
|
|
|
mDoingDrag = TRUE;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Invoked after a dragover event has been dispatched, this constructs
|
|
|
|
// a reply to DM_DRAGOVER based on the canDrop & dragAction attributes.
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDragService::GetDragoverResult(MRESULT& mr)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
if (!&mr)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (mDoingDrag) {
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canDrop = false;
|
2003-11-19 01:39:46 +03:00
|
|
|
USHORT usDrop;
|
|
|
|
GetCanDrop(&canDrop);
|
|
|
|
if (canDrop)
|
|
|
|
usDrop = DOR_DROP;
|
|
|
|
else
|
|
|
|
usDrop = DOR_NODROP;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t action;
|
2003-11-19 01:39:46 +03:00
|
|
|
USHORT usOp;
|
|
|
|
GetDragAction(&action);
|
|
|
|
if (action & DRAGDROP_ACTION_COPY)
|
|
|
|
usOp = DO_COPY;
|
|
|
|
else
|
|
|
|
if (action & DRAGDROP_ACTION_LINK)
|
|
|
|
usOp = DO_LINK;
|
|
|
|
else {
|
|
|
|
if (mSourceNode)
|
|
|
|
usOp = DO_MOVE;
|
|
|
|
else
|
|
|
|
usOp = DO_UNKNOWN+1;
|
|
|
|
if (action == DRAGDROP_ACTION_NONE)
|
|
|
|
usDrop = DOR_NODROP;
|
|
|
|
}
|
|
|
|
|
|
|
|
mr = MRFROM2SHORT(usDrop, usOp);
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mr = MRFROM2SHORT(DOR_NEVERDROP, 0);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// have the client dispatch the event, then call ExitSession()
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsDragService::DragLeaveMsg(PDRAGINFO pdinfo, uint32_t* dragFlags)
|
2003-11-19 01:39:46 +03:00
|
|
|
{
|
|
|
|
if (!mDoingDrag || !dragFlags)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mSourceNode)
|
|
|
|
*dragFlags = DND_DISPATCHEVENT | DND_EXITSESSION | DND_MOZDRAG;
|
|
|
|
else
|
|
|
|
*dragFlags = DND_DISPATCHEVENT | DND_EXITSESSION | DND_NATIVEDRAG;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// DropHelp occurs when you press F1 during a drag; apparently,
|
|
|
|
// it's like a regular drop in that the target has to do clean up
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsDragService::DropHelpMsg(PDRAGINFO pdinfo, uint32_t* dragFlags)
|
2003-11-19 01:39:46 +03:00
|
|
|
{
|
|
|
|
if (!mDoingDrag)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (pdinfo && DrgAccessDraginfo(pdinfo)) {
|
|
|
|
DrgDeleteDraginfoStrHandles(pdinfo);
|
|
|
|
DrgFreeDraginfo(pdinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dragFlags)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mSourceNode)
|
|
|
|
*dragFlags = DND_DISPATCHEVENT | DND_EXITSESSION | DND_MOZDRAG;
|
|
|
|
else
|
|
|
|
*dragFlags = DND_DISPATCHEVENT | DND_EXITSESSION | DND_NATIVEDRAG;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// for native drags, clean up;
|
|
|
|
// for all drags, signal that Moz is no longer in d&d mode
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsDragService::ExitSession(uint32_t* dragFlags)
|
2003-11-19 01:39:46 +03:00
|
|
|
{
|
|
|
|
if (!mDoingDrag)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (!mSourceNode) {
|
|
|
|
mSourceDataItems = 0;
|
2009-06-23 13:28:25 +04:00
|
|
|
mDataTransfer = 0;
|
2003-11-19 01:39:46 +03:00
|
|
|
mDoingDrag = FALSE;
|
|
|
|
|
|
|
|
// if we created a temp file, delete it
|
|
|
|
if (gTempFile) {
|
|
|
|
DosDelete(gTempFile);
|
|
|
|
nsMemory::Free(gTempFile);
|
|
|
|
gTempFile = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dragFlags)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
*dragFlags = 0;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// If DropMsg() is presented with native data that has to be rendered,
|
|
|
|
// the drop event & cleanup will be defered until the client's window
|
|
|
|
// has received a render-complete msg.
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDragService::DropMsg(PDRAGINFO pdinfo, HWND hwnd,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t* dragFlags)
|
2003-11-19 01:39:46 +03:00
|
|
|
{
|
|
|
|
if (!mDoingDrag || !dragFlags || !pdinfo || !DrgAccessDraginfo(pdinfo))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
switch (pdinfo->usOperation) {
|
|
|
|
case DO_MOVE:
|
|
|
|
SetDragAction(DRAGDROP_ACTION_MOVE);
|
|
|
|
break;
|
|
|
|
case DO_COPY:
|
|
|
|
SetDragAction(DRAGDROP_ACTION_COPY);
|
|
|
|
break;
|
|
|
|
case DO_LINK:
|
|
|
|
SetDragAction(DRAGDROP_ACTION_LINK);
|
|
|
|
break;
|
|
|
|
default: // avoid "moving" (i.e. deleting) native text/objects
|
|
|
|
if (mSourceNode)
|
|
|
|
SetDragAction(DRAGDROP_ACTION_MOVE);
|
|
|
|
else
|
|
|
|
SetDragAction(DRAGDROP_ACTION_COPY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if this is a native drag, move the source data to a transferable;
|
|
|
|
// request rendering if needed
|
|
|
|
nsresult rv = NS_OK;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool rendering = false;
|
2003-11-19 01:39:46 +03:00
|
|
|
if (!mSourceNode)
|
|
|
|
rv = NativeDrop( pdinfo, hwnd, &rendering);
|
|
|
|
|
|
|
|
// note: NativeDrop() sends an end-conversation msg to native
|
|
|
|
// sources but nothing sends them to Mozilla - however, Mozilla
|
|
|
|
// (i.e. nsDragService) doesn't need them, so...
|
|
|
|
|
|
|
|
// if rendering, the action flags are off because we don't want
|
|
|
|
// the client to do anything yet; the status flags are off because
|
|
|
|
// we'll be exiting d&d mode before the next screen update occurs
|
|
|
|
if (rendering)
|
|
|
|
*dragFlags = 0;
|
|
|
|
else {
|
|
|
|
// otherwise, set the flags & free the native drag structures
|
|
|
|
|
|
|
|
*dragFlags = DND_EXITSESSION;
|
2009-06-23 13:28:25 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2003-11-19 01:39:46 +03:00
|
|
|
if (mSourceNode)
|
|
|
|
*dragFlags |= DND_DISPATCHEVENT | DND_INDROP | DND_MOZDRAG;
|
|
|
|
else
|
|
|
|
*dragFlags |= DND_DISPATCHEVENT | DND_INDROP | DND_NATIVEDRAG;
|
2009-06-23 13:28:25 +04:00
|
|
|
}
|
2003-11-19 01:39:46 +03:00
|
|
|
|
|
|
|
DrgDeleteDraginfoStrHandles(pdinfo);
|
|
|
|
DrgFreeDraginfo(pdinfo);
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Invoked by DropMsg to fill a transferable with native data;
|
|
|
|
// if necessary, requests the source to render it.
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDragService::NativeDrop(PDRAGINFO pdinfo, HWND hwnd,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* rendering)
|
2003-11-19 01:39:46 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
*rendering = false;
|
2003-11-19 01:39:46 +03:00
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
PDRAGITEM pditem = DrgQueryDragitemPtr(pdinfo, 0);
|
|
|
|
if (!pditem)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsXPIDLCString dropText;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isUrl = DrgVerifyType(pditem, "UniformResourceLocator");
|
2003-11-19 01:39:46 +03:00
|
|
|
|
|
|
|
// identify format; the order of evaluation here is important
|
|
|
|
|
|
|
|
// DRM_ATOM - DragText stores up to 255 chars in a Drg API atom
|
|
|
|
// DRM_DTSHARE - DragText renders up to 1mb to named shared mem
|
|
|
|
if (DrgVerifyRMF(pditem, "DRM_ATOM", 0))
|
|
|
|
rv = GetAtom(pditem->ulItemID, getter_Copies(dropText));
|
|
|
|
else
|
|
|
|
if (DrgVerifyRMF(pditem, "DRM_DTSHARE", 0)) {
|
|
|
|
rv = RenderToDTShare( pditem, hwnd);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2011-10-17 18:59:28 +04:00
|
|
|
*rendering = true;
|
2003-11-19 01:39:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// DRM_OS2FILE - get the file's path or contents if it exists;
|
|
|
|
// request rendering if it doesn't
|
|
|
|
else
|
|
|
|
if (DrgVerifyRMF(pditem, "DRM_OS2FILE", 0)) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isAlt = (WinGetKeyState(HWND_DESKTOP, VK_ALT) & 0x8000);
|
2003-11-19 01:39:46 +03:00
|
|
|
|
|
|
|
// the file has to be rendered - currently, we only present
|
|
|
|
// its content, not its name, to Moz to avoid conflicts
|
|
|
|
if (!pditem->hstrContainerName || !pditem->hstrSourceName) {
|
|
|
|
rv = RenderToOS2File( pditem, hwnd);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2011-10-17 18:59:28 +04:00
|
|
|
*rendering = true;
|
2003-11-19 01:39:46 +03:00
|
|
|
}
|
|
|
|
// for Url objects and 'Alt+Drop', get the file's contents;
|
|
|
|
// otherwise, convert it's path to a Url
|
|
|
|
else {
|
|
|
|
nsXPIDLCString fileName;
|
|
|
|
if (NS_SUCCEEDED(GetFileName(pditem, getter_Copies(fileName)))) {
|
|
|
|
if (isUrl || isAlt)
|
|
|
|
rv = GetFileContents(fileName.get(), getter_Copies(dropText));
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
isUrl = true;
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2003-11-19 01:39:46 +03:00
|
|
|
if (NS_SUCCEEDED(NS_NewNativeLocalFile(fileName,
|
2011-10-17 18:59:28 +04:00
|
|
|
true, getter_AddRefs(file)))) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString textStr;
|
2003-11-19 01:39:46 +03:00
|
|
|
NS_GetURLSpecFromFile(file, textStr);
|
|
|
|
if (!textStr.IsEmpty()) {
|
|
|
|
dropText.Assign(ToNewCString(textStr));
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // filename as Url
|
|
|
|
} // got filename
|
|
|
|
} // existing files
|
|
|
|
} // DRM_OS2FILE
|
|
|
|
|
|
|
|
// if OK, put what data there is in the transferable; this could be
|
|
|
|
// everything needed or just the title of a Url that needs rendering
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
|
|
|
// for Urls, get the title & remove any linefeeds
|
|
|
|
nsXPIDLCString titleText;
|
|
|
|
if (isUrl &&
|
|
|
|
pditem->hstrTargetName &&
|
|
|
|
NS_SUCCEEDED(GetAtom(pditem->hstrTargetName, getter_Copies(titleText))))
|
2004-04-03 21:16:17 +04:00
|
|
|
for (char* ptr=strchr(titleText.BeginWriting(),'\n'); ptr; ptr=strchr(ptr, '\n'))
|
2003-11-19 01:39:46 +03:00
|
|
|
*ptr = ' ';
|
|
|
|
|
|
|
|
rv = NativeDataToTransferable( dropText.get(), titleText.get(), isUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// except for renderings, tell the source we're done with the data
|
|
|
|
if (!*rendering)
|
|
|
|
DrgSendTransferMsg( pditem->hwndItem, DM_ENDCONVERSATION,
|
|
|
|
(MPARAM)pditem->ulItemID,
|
|
|
|
(MPARAM)DMFL_TARGETSUCCESSFUL);
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Because RenderCompleteMsg() is called after the native (PM) drag
|
|
|
|
// session has ended, all of the drag status flags should be off.
|
|
|
|
//
|
|
|
|
// FYI... PM's asynchronous rendering mechanism is not compatible with
|
|
|
|
// nsIDataFlavorProvider which expects data to be rendered synchronously
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDragService::RenderCompleteMsg(PDRAGTRANSFER pdxfer,
|
2012-08-22 19:56:38 +04:00
|
|
|
USHORT usResult, uint32_t* dragFlags)
|
2003-11-19 01:39:46 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
if (!mDoingDrag || !pdxfer)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// this msg should never come from Moz - if it does, fail
|
|
|
|
if (!mSourceNode)
|
|
|
|
rv = NativeRenderComplete(pdxfer, usResult);
|
|
|
|
|
|
|
|
// DrgQueryDraginfoPtrFromDragitem() doesn't work - this does
|
|
|
|
PDRAGINFO pdinfo = (PDRAGINFO)MAKEULONG(0x2c, HIUSHORT(pdxfer->pditem));
|
|
|
|
|
|
|
|
DrgDeleteStrHandle(pdxfer->hstrSelectedRMF);
|
|
|
|
DrgDeleteStrHandle(pdxfer->hstrRenderToName);
|
|
|
|
DrgFreeDragtransfer(pdxfer);
|
|
|
|
|
|
|
|
// if the source is Moz, don't touch pdinfo - it's been freed already
|
|
|
|
if (pdinfo && !mSourceNode) {
|
|
|
|
DrgDeleteDraginfoStrHandles(pdinfo);
|
|
|
|
DrgFreeDraginfo(pdinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
// this shouldn't happen
|
|
|
|
if (!dragFlags)
|
|
|
|
return (ExitSession(dragFlags));
|
|
|
|
|
|
|
|
// d&d is over, so the DND_DragStatus flags should all be off
|
|
|
|
*dragFlags = DND_EXITSESSION;
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
*dragFlags |= DND_DISPATCHEVENT;
|
|
|
|
|
|
|
|
// lie so the client will honor the exit-session flag
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// this is here to provide a false sense of symmetry with the other
|
|
|
|
// method-pairs - rendered data always comes from a native source
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDragService::NativeRenderComplete(PDRAGTRANSFER pdxfer,
|
|
|
|
USHORT usResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
nsXPIDLCString rmf;
|
|
|
|
|
|
|
|
// identify the rendering mechanism, then get the data
|
|
|
|
if (NS_SUCCEEDED(GetAtom(pdxfer->hstrSelectedRMF, getter_Copies(rmf)))) {
|
|
|
|
nsXPIDLCString dropText;
|
|
|
|
if (!strcmp(rmf.get(), DTSHARE_RMF))
|
|
|
|
rv = RenderToDTShareComplete(pdxfer, usResult, getter_Copies(dropText));
|
|
|
|
else
|
|
|
|
if (!strcmp(rmf.get(), OS2FILE_TXTRMF) ||
|
|
|
|
!strcmp(rmf.get(), OS2FILE_UNKRMF))
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = RenderToOS2FileComplete(pdxfer, usResult, true,
|
2003-11-19 01:39:46 +03:00
|
|
|
getter_Copies(dropText));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isUrl = false;
|
2003-11-19 01:39:46 +03:00
|
|
|
IsDataFlavorSupported(kURLMime, &isUrl);
|
|
|
|
rv = NativeDataToTransferable( dropText.get(), 0, isUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DrgSendTransferMsg(pdxfer->hwndClient, DM_ENDCONVERSATION,
|
|
|
|
(MPARAM)pdxfer->ulTargetInfo,
|
|
|
|
(MPARAM)DMFL_TARGETSUCCESSFUL);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// fills the transferable created by NativeDragEnter with
|
|
|
|
// the set of flavors and data the target will see onDrop
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsDragService::NativeDataToTransferable( PCSZ pszText,
|
2011-09-29 10:19:26 +04:00
|
|
|
PCSZ pszTitle, bool isUrl)
|
2003-11-19 01:39:46 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
// the transferable should have been created on DragEnter
|
|
|
|
if (!mSourceDataItems)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> genericItem;
|
|
|
|
mSourceDataItems->GetElementAt(0, getter_AddRefs(genericItem));
|
|
|
|
nsCOMPtr<nsITransferable> trans (do_QueryInterface(genericItem));
|
|
|
|
if (!trans)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// remove invalid flavors
|
|
|
|
if (!isUrl) {
|
|
|
|
trans->RemoveDataFlavor(kURLMime);
|
|
|
|
trans->RemoveDataFlavor(kHTMLMime);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there's no text, exit - but first see if we have the title of
|
|
|
|
// a Url that needs to be rendered; if so, stash it for later use
|
|
|
|
if (!pszText || !*pszText) {
|
|
|
|
if (isUrl && pszTitle && *pszTitle) {
|
|
|
|
nsXPIDLString outTitle;
|
|
|
|
if (CodepageToUnicode(nsDependentCString(pszTitle),
|
|
|
|
getter_Copies(outTitle))) {
|
|
|
|
nsCOMPtr<nsISupportsString> urlPrimitive(
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
|
|
|
|
if (urlPrimitive ) {
|
|
|
|
urlPrimitive->SetData(outTitle);
|
|
|
|
trans->SetTransferData(kURLDescriptionMime, urlPrimitive,
|
|
|
|
2*outTitle.Length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXPIDLString outText;
|
|
|
|
if (!CodepageToUnicode(nsDependentCString(pszText), getter_Copies(outText)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (isUrl) {
|
|
|
|
|
|
|
|
// if no title was supplied, see if it was stored in the transferable
|
|
|
|
nsXPIDLString outTitle;
|
|
|
|
if (pszTitle && *pszTitle) {
|
|
|
|
if (!CodepageToUnicode(nsDependentCString(pszTitle),
|
|
|
|
getter_Copies(outTitle)))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len;
|
2003-11-19 01:39:46 +03:00
|
|
|
nsCOMPtr<nsISupports> genericData;
|
|
|
|
if (NS_SUCCEEDED(trans->GetTransferData(kURLDescriptionMime,
|
|
|
|
getter_AddRefs(genericData), &len))) {
|
|
|
|
nsCOMPtr<nsISupportsString> strObject(do_QueryInterface(genericData));
|
|
|
|
if (strObject)
|
|
|
|
strObject->GetData(outTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// construct the Url flavor
|
|
|
|
nsCOMPtr<nsISupportsString> urlPrimitive(
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
|
|
|
|
if (urlPrimitive ) {
|
|
|
|
if (outTitle.IsEmpty()) {
|
|
|
|
urlPrimitive->SetData(outText);
|
|
|
|
trans->SetTransferData(kURLMime, urlPrimitive, 2*outText.Length());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsString urlStr( outText + NS_LITERAL_STRING("\n") + outTitle);
|
|
|
|
urlPrimitive->SetData(urlStr);
|
|
|
|
trans->SetTransferData(kURLMime, urlPrimitive, 2*urlStr.Length());
|
|
|
|
}
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-09 19:18:54 +03:00
|
|
|
// construct the HTML flavor - for supported graphics,
|
|
|
|
// use an IMG tag, for all others create a link
|
2003-11-19 01:39:46 +03:00
|
|
|
nsCOMPtr<nsISupportsString> htmlPrimitive(
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
|
|
|
|
if (htmlPrimitive ) {
|
2005-11-09 19:18:54 +03:00
|
|
|
nsString htmlStr;
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(uri), pszText))) {
|
|
|
|
nsCOMPtr<nsIURL> url (do_QueryInterface(uri));
|
|
|
|
if (url) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString extension;
|
2005-11-09 19:18:54 +03:00
|
|
|
url->GetFileExtension(extension);
|
|
|
|
if (!extension.IsEmpty()) {
|
|
|
|
if (extension.LowerCaseEqualsLiteral("gif") ||
|
|
|
|
extension.LowerCaseEqualsLiteral("jpg") ||
|
|
|
|
extension.LowerCaseEqualsLiteral("png") ||
|
|
|
|
extension.LowerCaseEqualsLiteral("jpeg"))
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
htmlStr.Assign(NS_LITERAL_STRING("<img src=\"") +
|
|
|
|
outText +
|
|
|
|
NS_LITERAL_STRING("\" alt=\"") +
|
|
|
|
outTitle +
|
|
|
|
NS_LITERAL_STRING("\"/>") );
|
|
|
|
else
|
|
|
|
htmlStr.Assign(NS_LITERAL_STRING("<a href=\"") +
|
2003-11-19 01:39:46 +03:00
|
|
|
outText +
|
|
|
|
NS_LITERAL_STRING("\">") +
|
|
|
|
(outTitle.IsEmpty() ? outText : outTitle) +
|
|
|
|
NS_LITERAL_STRING("</a>") );
|
2005-11-09 19:18:54 +03:00
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
htmlPrimitive->SetData(htmlStr);
|
|
|
|
trans->SetTransferData(kHTMLMime, htmlPrimitive, 2*htmlStr.Length());
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the Text flavor
|
|
|
|
nsCOMPtr<nsISupportsString> textPrimitive(
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
|
|
|
|
if (textPrimitive ) {
|
|
|
|
textPrimitive->SetData(nsDependentString(outText));
|
|
|
|
trans->SetTransferData(kUnicodeMime, textPrimitive, 2*outText.Length());
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return OK if we put anything in the transferable
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// Helper functions
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
// currently, the same filename is used for every render request;
|
|
|
|
// it is deleted when the drag session ends
|
|
|
|
|
|
|
|
nsresult RenderToOS2File( PDRAGITEM pditem, HWND hwnd)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
nsXPIDLCString fileName;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(GetTempFileName(getter_Copies(fileName)))) {
|
2009-06-23 13:28:25 +04:00
|
|
|
const char * pszRMF;
|
2003-11-19 01:39:46 +03:00
|
|
|
if (DrgVerifyRMF(pditem, "DRM_OS2FILE", "DRF_TEXT"))
|
|
|
|
pszRMF = OS2FILE_TXTRMF;
|
|
|
|
else
|
|
|
|
pszRMF = OS2FILE_UNKRMF;
|
|
|
|
|
|
|
|
rv = RequestRendering( pditem, hwnd, pszRMF, fileName.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// return a buffer with the rendered file's Url or contents
|
|
|
|
|
|
|
|
nsresult RenderToOS2FileComplete(PDRAGTRANSFER pdxfer, USHORT usResult,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool content, char** outText)
|
2003-11-19 01:39:46 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// for now, override content flag & always return content
|
2011-10-17 18:59:28 +04:00
|
|
|
content = true;
|
2003-11-19 01:39:46 +03:00
|
|
|
|
|
|
|
if (usResult & DMFL_RENDEROK) {
|
|
|
|
if (NS_SUCCEEDED(GetAtom( pdxfer->hstrRenderToName, &gTempFile))) {
|
|
|
|
if (content)
|
|
|
|
rv = GetFileContents(gTempFile, outText);
|
|
|
|
else {
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2003-11-19 01:39:46 +03:00
|
|
|
if (NS_SUCCEEDED(NS_NewNativeLocalFile(nsDependentCString(gTempFile),
|
2011-10-17 18:59:28 +04:00
|
|
|
true, getter_AddRefs(file)))) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString textStr;
|
2003-11-19 01:39:46 +03:00
|
|
|
NS_GetURLSpecFromFile(file, textStr);
|
|
|
|
if (!textStr.IsEmpty()) {
|
|
|
|
*outText = ToNewCString(textStr);
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// gTempFile will be deleted when ExitSession() is called
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// DTShare uses 1mb of uncommitted named-shared memory
|
|
|
|
// (next time I'll do it differently - rw)
|
|
|
|
|
|
|
|
nsresult RenderToDTShare( PDRAGITEM pditem, HWND hwnd)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
void * pMem;
|
|
|
|
|
2006-12-10 11:53:03 +03:00
|
|
|
#ifdef MOZ_OS2_HIGH_MEMORY
|
|
|
|
APIRET rc = DosAllocSharedMem( &pMem, DTSHARE_NAME, 0x100000,
|
|
|
|
PAG_WRITE | PAG_READ | OBJ_ANY);
|
|
|
|
if (rc != NO_ERROR &&
|
|
|
|
rc != ERROR_ALREADY_EXISTS) { // Did the kernel handle OBJ_ANY?
|
|
|
|
// Try again without OBJ_ANY and if the first failure was not caused
|
|
|
|
// by OBJ_ANY then we will get the same failure, else we have taken
|
|
|
|
// care of pre-FP13 systems where the kernel couldn't handle it.
|
|
|
|
rc = DosAllocSharedMem( &pMem, DTSHARE_NAME, 0x100000,
|
|
|
|
PAG_WRITE | PAG_READ);
|
|
|
|
}
|
|
|
|
#else
|
2003-11-19 01:39:46 +03:00
|
|
|
APIRET rc = DosAllocSharedMem( &pMem, DTSHARE_NAME, 0x100000,
|
|
|
|
PAG_WRITE | PAG_READ);
|
2006-12-10 11:53:03 +03:00
|
|
|
#endif
|
|
|
|
|
2003-11-19 01:39:46 +03:00
|
|
|
if (rc == ERROR_ALREADY_EXISTS)
|
|
|
|
rc = DosGetNamedSharedMem( &pMem, DTSHARE_NAME,
|
|
|
|
PAG_WRITE | PAG_READ);
|
|
|
|
if (rc)
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
else
|
|
|
|
rv = RequestRendering( pditem, hwnd, DTSHARE_RMF, DTSHARE_NAME);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// return a buffer with the rendered text
|
|
|
|
|
|
|
|
nsresult RenderToDTShareComplete(PDRAGTRANSFER pdxfer, USHORT usResult,
|
|
|
|
char** outText)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
void * pMem;
|
|
|
|
char * pszText = 0;
|
|
|
|
|
|
|
|
APIRET rc = DosGetNamedSharedMem( &pMem, DTSHARE_NAME, PAG_WRITE | PAG_READ);
|
|
|
|
|
|
|
|
if (!rc) {
|
|
|
|
if (usResult & DMFL_RENDEROK) {
|
|
|
|
pszText = (char*)nsMemory::Alloc( ((ULONG*)pMem)[0] + 1);
|
|
|
|
if (pszText) {
|
|
|
|
strcpy(pszText, &((char*)pMem)[sizeof(ULONG)] );
|
2005-11-09 19:18:54 +03:00
|
|
|
RemoveCarriageReturns(pszText);
|
2003-11-19 01:39:46 +03:00
|
|
|
*outText = pszText;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// using DosGetNamedSharedMem() on memory we allocated appears
|
|
|
|
// to increment its usage ctr, so we have to free it 2x
|
|
|
|
DosFreeMem(pMem);
|
|
|
|
DosFreeMem(pMem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// a generic request dispatcher
|
|
|
|
|
|
|
|
nsresult RequestRendering( PDRAGITEM pditem, HWND hwnd, PCSZ pRMF, PCSZ pName)
|
|
|
|
{
|
|
|
|
PDRAGTRANSFER pdxfer = DrgAllocDragtransfer( 1);
|
|
|
|
if (!pdxfer)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
pdxfer->cb = sizeof(DRAGTRANSFER);
|
|
|
|
pdxfer->hwndClient = hwnd;
|
|
|
|
pdxfer->pditem = pditem;
|
|
|
|
pdxfer->hstrSelectedRMF = DrgAddStrHandle( pRMF);
|
|
|
|
pdxfer->hstrRenderToName = 0;
|
|
|
|
pdxfer->ulTargetInfo = pditem->ulItemID;
|
|
|
|
pdxfer->usOperation = (USHORT)DO_COPY;
|
|
|
|
pdxfer->fsReply = 0;
|
|
|
|
|
|
|
|
// send the msg before setting a render-to name
|
|
|
|
if (pditem->fsControl & DC_PREPAREITEM)
|
|
|
|
DrgSendTransferMsg( pditem->hwndItem, DM_RENDERPREPARE, (MPARAM)pdxfer, 0);
|
|
|
|
|
|
|
|
pdxfer->hstrRenderToName = DrgAddStrHandle( pName);
|
|
|
|
|
|
|
|
// send the msg after setting a render-to name
|
|
|
|
if ((pditem->fsControl & (DC_PREPARE | DC_PREPAREITEM)) == DC_PREPARE)
|
|
|
|
DrgSendTransferMsg( pditem->hwndItem, DM_RENDERPREPARE, (MPARAM)pdxfer, 0);
|
|
|
|
|
|
|
|
// ask the source to render the selected item
|
|
|
|
if (!DrgSendTransferMsg( pditem->hwndItem, DM_RENDER, (MPARAM)pdxfer, 0))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// return a ptr to a buffer containing the text associated
|
|
|
|
// with a drag atom; the caller frees the buffer
|
|
|
|
|
|
|
|
nsresult GetAtom( ATOM aAtom, char** outText)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
ULONG ulInLength = DrgQueryStrNameLen(aAtom);
|
|
|
|
if (ulInLength) {
|
|
|
|
char* pszText = (char*)nsMemory::Alloc(++ulInLength);
|
|
|
|
if (pszText) {
|
|
|
|
DrgQueryStrName(aAtom, ulInLength, pszText);
|
2005-11-09 19:18:54 +03:00
|
|
|
RemoveCarriageReturns(pszText);
|
2003-11-19 01:39:46 +03:00
|
|
|
*outText = pszText;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// return a ptr to a buffer containing the file path specified
|
|
|
|
// in the dragitem; the caller frees the buffer
|
|
|
|
|
|
|
|
nsresult GetFileName(PDRAGITEM pditem, char** outText)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
ULONG cntCnr = DrgQueryStrNameLen(pditem->hstrContainerName);
|
|
|
|
ULONG cntSrc = DrgQueryStrNameLen(pditem->hstrSourceName);
|
|
|
|
|
|
|
|
char* pszText = (char*)nsMemory::Alloc(cntCnr+cntSrc+1);
|
|
|
|
if (pszText) {
|
|
|
|
DrgQueryStrName(pditem->hstrContainerName, cntCnr+1, pszText);
|
|
|
|
DrgQueryStrName(pditem->hstrSourceName, cntSrc+1, &pszText[cntCnr]);
|
|
|
|
pszText[cntCnr+cntSrc] = 0;
|
|
|
|
*outText = pszText;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// read the file; if successful, return a ptr to its contents;
|
|
|
|
// the caller frees the buffer
|
|
|
|
|
|
|
|
nsresult GetFileContents(PCSZ pszPath, char** outText)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
char* pszText = 0;
|
|
|
|
|
|
|
|
if (pszPath) {
|
|
|
|
FILE *fp = fopen(pszPath, "r");
|
|
|
|
if (fp) {
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
ULONG filesize = ftell(fp);
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
if (filesize > 0) {
|
|
|
|
size_t readsize = (size_t)filesize;
|
|
|
|
pszText = (char*)nsMemory::Alloc(readsize+1);
|
|
|
|
if (pszText) {
|
|
|
|
readsize = fread((void *)pszText, 1, readsize, fp);
|
|
|
|
if (readsize) {
|
|
|
|
pszText[readsize] = '\0';
|
2005-11-09 19:18:54 +03:00
|
|
|
RemoveCarriageReturns(pszText);
|
2003-11-19 01:39:46 +03:00
|
|
|
*outText = pszText;
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsMemory::Free(pszText);
|
|
|
|
pszText = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// currently, this returns the same path & filename every time
|
|
|
|
|
|
|
|
nsresult GetTempFileName(char** outText)
|
|
|
|
{
|
|
|
|
char * pszText = (char*)nsMemory::Alloc(CCHMAXPATH);
|
|
|
|
if (!pszText)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2006-02-14 01:32:23 +03:00
|
|
|
const char * pszPath;
|
2003-11-19 01:39:46 +03:00
|
|
|
if (!DosScanEnv("TEMP", &pszPath) || !DosScanEnv("TMP", &pszPath))
|
|
|
|
strcpy(pszText, pszPath);
|
|
|
|
else
|
|
|
|
if (DosQueryPathInfo(".\\.", FIL_QUERYFULLNAME, pszText, CCHMAXPATH))
|
|
|
|
pszText[0] = 0;
|
|
|
|
|
|
|
|
strcat(pszText, "\\");
|
|
|
|
strcat(pszText, OS2FILE_NAME);
|
|
|
|
*outText = pszText;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2006-06-27 00:40:08 +04:00
|
|
|
// set the file's .TYPE and .SUBJECT EAs; since this is non-critical
|
|
|
|
// (though highly desirable), errors aren't reported
|
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
void SaveTypeAndSource(nsIFile *file, nsIDOMDocument *domDoc,
|
2006-06-27 00:40:08 +04:00
|
|
|
PCSZ pszType)
|
2003-07-08 02:42:44 +04:00
|
|
|
{
|
2006-06-27 00:40:08 +04:00
|
|
|
if (!file)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFileOS2> os2file(do_QueryInterface(file));
|
|
|
|
if (!os2file ||
|
|
|
|
NS_FAILED(os2file->SetFileTypes(nsDependentCString(pszType))))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// since the filetype has to be saved, this function
|
|
|
|
// may be called even if there isn't any document
|
|
|
|
if (!domDoc)
|
2003-07-08 02:42:44 +04:00
|
|
|
return;
|
|
|
|
|
2006-06-27 00:40:08 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
|
|
|
|
if (!doc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// this gets the top-level content URL when frames are used;
|
|
|
|
// when nextDoc is zero, currDoc is the browser window, and
|
|
|
|
// prevDoc points to the content;
|
|
|
|
// note: neither GetParentDocument() nor GetDocumentURI()
|
|
|
|
// refcount the pointers they return, so nsCOMPtr isn't needed
|
|
|
|
nsIDocument *prevDoc;
|
|
|
|
nsIDocument *currDoc = doc;
|
|
|
|
nsIDocument *nextDoc = doc;
|
|
|
|
do {
|
|
|
|
prevDoc = currDoc;
|
|
|
|
currDoc = nextDoc;
|
|
|
|
nextDoc = currDoc->GetParentDocument();
|
|
|
|
} while (nextDoc);
|
|
|
|
|
|
|
|
nsIURI* srcUri = prevDoc->GetDocumentURI();
|
|
|
|
if (!srcUri)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// identifying content as coming from chrome is none too useful...
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ignore = false;
|
2006-06-27 00:40:08 +04:00
|
|
|
srcUri->SchemeIs("chrome", &ignore);
|
|
|
|
if (ignore)
|
|
|
|
return;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString url;
|
2006-06-27 00:40:08 +04:00
|
|
|
srcUri->GetSpec(url);
|
|
|
|
os2file->SetFileSource(url);
|
|
|
|
|
2003-07-08 02:42:44 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// to do: this needs to take into account the current page's encoding
|
|
|
|
// if it is different than the PM codepage
|
|
|
|
|
2004-04-19 18:46:07 +04:00
|
|
|
int UnicodeToCodepage(const nsAString& aString, char **aResult)
|
2003-07-08 02:42:44 +04:00
|
|
|
{
|
2004-04-19 18:46:07 +04:00
|
|
|
nsAutoCharBuffer buffer;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t bufLength;
|
2004-04-19 18:46:07 +04:00
|
|
|
WideCharToMultiByte(0, PromiseFlatString(aString).get(), aString.Length(),
|
|
|
|
buffer, bufLength);
|
2007-09-20 04:54:03 +04:00
|
|
|
*aResult = ToNewCString(nsDependentCString(buffer.Elements()));
|
2004-04-19 18:46:07 +04:00
|
|
|
return bufLength;
|
1999-06-29 03:39:35 +04:00
|
|
|
}
|
2003-07-08 02:42:44 +04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2004-04-19 18:46:07 +04:00
|
|
|
int CodepageToUnicode(const nsACString& aString, PRUnichar **aResult)
|
2003-11-19 01:39:46 +03:00
|
|
|
{
|
2004-04-19 18:46:07 +04:00
|
|
|
nsAutoChar16Buffer buffer;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t bufLength;
|
2004-04-23 23:08:41 +04:00
|
|
|
MultiByteToWideChar(0, PromiseFlatCString(aString).get(),
|
|
|
|
aString.Length(), buffer, bufLength);
|
2007-09-20 04:54:03 +04:00
|
|
|
*aResult = ToNewUnicode(nsDependentString(buffer.Elements()));
|
2004-04-19 18:46:07 +04:00
|
|
|
return bufLength;
|
2003-11-19 01:39:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2005-11-09 19:18:54 +03:00
|
|
|
// removes carriage returns in-place; it should only be used on
|
|
|
|
// raw text buffers that haven't been assigned to a string object
|
|
|
|
|
|
|
|
void RemoveCarriageReturns(char * pszText)
|
|
|
|
{
|
|
|
|
ULONG cnt;
|
|
|
|
char * next;
|
|
|
|
char * source;
|
|
|
|
char * target;
|
|
|
|
|
|
|
|
target = strchr(pszText, 0x0d);
|
|
|
|
if (!target)
|
|
|
|
return;
|
|
|
|
|
|
|
|
source = target + 1;
|
|
|
|
|
|
|
|
while ((next = strchr(source, 0x0d)) != 0) {
|
|
|
|
|
|
|
|
cnt = next - source;
|
|
|
|
memcpy(target, source, cnt);
|
|
|
|
target += cnt;
|
|
|
|
source = next + 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(target, source);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|