зеркало из https://github.com/mozilla/pjs.git
Added D&D to toolbars and toolboxes
This commit is contained in:
Родитель
6ca1a9377a
Коммит
9d0f70febd
|
@ -24,6 +24,8 @@ REQUIRES=xpcom raptor pref
|
|||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
CPPSRCS= \
|
||||
nsToolbarDragListener.cpp \
|
||||
nsToolbarItemFrame.cpp \
|
||||
nsSplitterFrame.cpp \
|
||||
nsGrippyFrame.cpp \
|
||||
nsTabFrame.cpp \
|
||||
|
@ -47,6 +49,8 @@ CPPSRCS= \
|
|||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsToolbarDragListener.obj \
|
||||
.\$(OBJDIR)\nsToolbarItemFrame.obj \
|
||||
.\$(OBJDIR)\nsGrippyFrame.obj \
|
||||
.\$(OBJDIR)\nsSplitterFrame.obj \
|
||||
.\$(OBJDIR)\nsTabFrame.obj \
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "nsToolbarFrame.h"
|
||||
#include "nsIDOMDragListener.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
|
||||
// Drag & Drop, Clipboard
|
||||
#include "nsIServiceManager.h"
|
||||
|
@ -47,6 +48,10 @@ static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
|
|||
static NS_DEFINE_IID(kCDataFlavorCID, NS_DATAFLAVOR_CID);
|
||||
static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
||||
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
/*
|
||||
* nsToolbarDragListener implementation
|
||||
|
@ -57,15 +62,21 @@ NS_IMPL_ADDREF(nsToolbarDragListener)
|
|||
NS_IMPL_RELEASE(nsToolbarDragListener)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsToolbarDragListener::nsToolbarDragListener()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mPresContext = nsnull;
|
||||
mMouseDown = PR_FALSE;
|
||||
mMouseDrag = PR_FALSE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsToolbarDragListener::~nsToolbarDragListener()
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
|
@ -73,13 +84,8 @@ nsToolbarDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsISupports*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIDOMEventListener::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
||||
if (aIID.Equals(kIDOMEventReceiverIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMEventListener*)(nsIDOMMouseMotionListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -88,9 +94,26 @@ nsToolbarDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIDOMMouseMotionListener::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsIDOMMouseMotionListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIDOMMouseListener::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsIDOMMouseListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)(nsIDOMMouseMotionListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
static void ForceDrawFrame(nsIFrame * aFrame)
|
||||
{
|
||||
if (aFrame == nsnull) {
|
||||
|
@ -112,21 +135,21 @@ static void ForceDrawFrame(nsIFrame * aFrame)
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
//printf("nsToolbarDragListener::HandleEvent\n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::DragEnter(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
//printf("nsToolbarDragListener::DragEnter\n");
|
||||
mCurrentDropLoc = -1;
|
||||
|
||||
nsIDragService* dragService;
|
||||
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
||||
nsIDragService::GetIID(),
|
||||
|
@ -134,118 +157,111 @@ nsToolbarDragListener::DragEnter(nsIDOMEvent* aDragEvent)
|
|||
if (NS_OK == rv) {
|
||||
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
|
||||
|
||||
nsAutoString textFlavor(kTextMime);
|
||||
if (dragSession &&
|
||||
(NS_OK == dragSession->IsDataFlavorSupported(&textFlavor))) {
|
||||
nsAutoString toolbarItemFlavor(TOOLBARITEM_MIME);
|
||||
if (dragSession && (NS_OK == dragSession->IsDataFlavorSupported(&toolbarItemFlavor))) {
|
||||
dragSession->SetCanDrop(PR_TRUE);
|
||||
} else {
|
||||
rv = NS_ERROR_BASE; // don't consume event
|
||||
}
|
||||
|
||||
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
|
||||
}
|
||||
//DragOver(aDragEvent);
|
||||
return NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsToolbarDragListener::DragOver(nsIDOMEvent* aDragEvent)
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
PRBool
|
||||
nsToolbarDragListener::IsOnToolbarItem(nsIDOMEvent* aDragEvent, nscoord& aXLoc)
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIDOMUIEvent> uiEvent(do_QueryInterface(aDragEvent));
|
||||
PRInt32 x,y = 0;
|
||||
uiEvent->GetClientX(&x);
|
||||
uiEvent->GetClientY(&y);
|
||||
/*{
|
||||
nsCOMPtr<nsIContent> content;
|
||||
nsresult result = mToolbar->GetContent(getter_AddRefs(content));
|
||||
if (NS_OK == result) {
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
element = do_QueryInterface(content);
|
||||
if (nsnull != element ) {
|
||||
//printf("===================================================Got element\n");
|
||||
nsAutoString value;
|
||||
element->GetAttribute(nsAutoString("naturalorder"), value);
|
||||
printf("---------------------------> [%s]\n", value.ToNewCString());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
nsCOMPtr<nsIDOMNode> contentDOMNode;
|
||||
aDragEvent->GetTarget(getter_AddRefs(contentDOMNode));
|
||||
if (contentDOMNode) {
|
||||
//printf("===================================================Got node\n");
|
||||
if (nsnull == mPresContext) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
float p2t;
|
||||
mPresContext->GetScaledPixelsToTwips(&p2t);
|
||||
nscoord xp = NSIntPixelsToTwips(x, p2t);
|
||||
nscoord yp = NSIntPixelsToTwips(y, p2t);
|
||||
nsPoint pnt(xp,yp);
|
||||
//printf("nsToolbarDragListener::DragOver %d,%d %d,%d\n", xp,yp, x, y);
|
||||
|
||||
nsRect r;
|
||||
mToolbar->GetRect(r);
|
||||
//printf("TB: %d %d %d %d\n", r.x, r.y, r.width, r.height);
|
||||
// get the toolbar's rect
|
||||
nsRect tbRect;
|
||||
mToolbar->GetRect(tbRect);
|
||||
|
||||
nscoord passes = 0;
|
||||
nscoord changedIndex = -1;
|
||||
nscoord count = 0;
|
||||
nscoord count = 0;
|
||||
nsIFrame* childFrame;
|
||||
nsRect rect; // child frame's rect
|
||||
nsRect prevRect(-1, -1, 0, 0);
|
||||
PRBool found = PR_FALSE;
|
||||
|
||||
mToolbar->FirstChild(nsnull, &childFrame);
|
||||
nsRect rect;
|
||||
nsRect prevRect;
|
||||
PRBool found = PR_FALSE;
|
||||
|
||||
nscoord lastChildX = -1;
|
||||
|
||||
while (nsnull != childFrame) {
|
||||
prevRect = rect;
|
||||
|
||||
// The mouse coords are in the toolbar's domain
|
||||
// Get child's rect and adjust to the toolbar's domain
|
||||
childFrame->GetRect(rect);
|
||||
rect.MoveBy(r.x, r.y);
|
||||
//printf("%d %d %d %d\n", rect.x, rect.y, rect.width, rect.height);
|
||||
if (pnt.x < rect.x && lastChildX == -1) {
|
||||
lastChildX = rect.x;
|
||||
rect.MoveBy(tbRect.x, tbRect.y);
|
||||
|
||||
// remember the previous child x location
|
||||
if (pnt.x < rect.x && prevRect.x == -1) {
|
||||
prevRect = rect;
|
||||
}
|
||||
|
||||
// now check to see if the mouse inside an items bounds
|
||||
if (rect.Contains(pnt)) {
|
||||
//printf("**************** Over child %d\n", count);
|
||||
nsCOMPtr<nsIContent> content;
|
||||
nsresult result = childFrame->GetContent(getter_AddRefs(content));
|
||||
if (NS_OK == result) {
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
content->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::titledbutton) {
|
||||
//printf("Got element\n");
|
||||
found = PR_TRUE;
|
||||
if (count == 0) {
|
||||
mToolbar->SetDropfeedbackLocation(rect.x-r.x);
|
||||
|
||||
// for now I am checking for both titlebutton and toolbar items
|
||||
// but the check for titlebutton should be removed in the future
|
||||
if (tag.get() == nsXULAtoms::titledbutton || tag.get() == nsXULAtoms::toolbaritem) {
|
||||
|
||||
// now check for natural order
|
||||
PRBool naturalOrder = PR_FALSE;
|
||||
nsCOMPtr<nsIDOMElement> domElement;
|
||||
domElement = do_QueryInterface(content);
|
||||
if (nsnull != domElement ) {
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
nsAutoString value;
|
||||
domElement->GetAttribute(nsAutoString("naturalorder"), value);
|
||||
naturalOrder = value.Equals("true");
|
||||
|
||||
} else {
|
||||
mToolbar->SetDropfeedbackLocation(rect.x-r.x);
|
||||
printf("Not a DOM element\n");
|
||||
}
|
||||
ForceDrawFrame(mToolbar);
|
||||
break;
|
||||
|
||||
found = PR_TRUE;
|
||||
|
||||
PRInt32 xc = -1;
|
||||
if (naturalOrder) {
|
||||
//printf("%d %d %d\n", pnt.x, rect.x, rect.width);
|
||||
if (pnt.x <= (rect.x + (rect.width / 4))) {
|
||||
xc = rect.x-tbRect.x;
|
||||
//printf("1st\n");
|
||||
} else if (pnt.x >= (rect.x + PRInt32(float(rect.width) *.75))) {
|
||||
xc = rect.x-tbRect.x+rect.width-15;
|
||||
//printf("last\n");
|
||||
} else {
|
||||
//printf("no-op\n");
|
||||
}
|
||||
} else {
|
||||
//printf("no order\n");
|
||||
xc = rect.x-tbRect.x;
|
||||
}
|
||||
//printf("xc = %d\n", xc);
|
||||
aXLoc = xc;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/*nsCOMPtr<nsIDOMNode> domNode;
|
||||
domNode = do_QueryInterface(content);
|
||||
if (nsnull != domNode ) {
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
mContent->GetTag(*getter_AddRefs(tag));
|
||||
if (tag.get() == nsXULAtoms::titlebutton) {
|
||||
printf("===================================================Got element\n");
|
||||
break;
|
||||
}
|
||||
//nsAutoString value;
|
||||
//element->GetAttribute(nsAutoString("naturalorder"), value);
|
||||
//printf("-----> [%s]\n", value.ToNewCString());
|
||||
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
mToolbar->SetDropfeedbackLocation(lastChildX-r.x);
|
||||
ForceDrawFrame(mToolbar);
|
||||
}
|
||||
|
||||
nsresult rv = childFrame->GetNextSibling(&childFrame);
|
||||
|
@ -253,45 +269,93 @@ nsToolbarDragListener::DragOver(nsIDOMEvent* aDragEvent)
|
|||
count++;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
aXLoc = prevRect.x -tbRect.x;
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::DragOver(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
// now tell the drag session whether we can drop here
|
||||
nsIDragService* dragService;
|
||||
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
||||
nsIDragService::GetIID(),
|
||||
(nsISupports **)&dragService);
|
||||
if (NS_OK == rv) {
|
||||
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
|
||||
nsAutoString textFlavor(kTextMime);
|
||||
if (dragSession && NS_OK == dragSession->IsDataFlavorSupported(&textFlavor)) {
|
||||
nsAutoString toolbarItemFlavor(TOOLBARITEM_MIME);
|
||||
if (dragSession && NS_OK == dragSession->IsDataFlavorSupported(&toolbarItemFlavor)) {
|
||||
dragSession->SetCanDrop(PR_TRUE);
|
||||
}
|
||||
|
||||
nscoord xLoc;
|
||||
PRBool onChild = IsOnToolbarItem(aDragEvent, xLoc);
|
||||
|
||||
if (xLoc != mCurrentDropLoc) {
|
||||
#ifdef TOOLBAR_DD
|
||||
mToolbar->SetDropfeedbackLocation(xLoc);
|
||||
#endif
|
||||
// force the toolbar frame to redraw
|
||||
ForceDrawFrame(mToolbar);
|
||||
|
||||
// cache the current drop location
|
||||
mCurrentDropLoc = xLoc;
|
||||
|
||||
rv = NS_OK; // means I am consuming the event
|
||||
}
|
||||
} else {
|
||||
rv = NS_ERROR_BASE; // don't consume event
|
||||
}
|
||||
|
||||
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
// NS_ERROR_xxx means event is NOT consumed
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::DragExit(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
mToolbar->SetDropfeedbackLocation(-1); // clears drawing of marker
|
||||
ForceDrawFrame(mToolbar);
|
||||
//printf("nsToolbarDragListener::DragExit\n");
|
||||
return NS_OK;
|
||||
// now tell the drag session whether we can drop here
|
||||
nsIDragService* dragService;
|
||||
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
||||
nsIDragService::GetIID(),
|
||||
(nsISupports **)&dragService);
|
||||
if (NS_OK == rv) {
|
||||
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
|
||||
nsAutoString toolbarItemFlavor(TOOLBARITEM_MIME);
|
||||
if (dragSession && NS_OK == dragSession->IsDataFlavorSupported(&toolbarItemFlavor)) {
|
||||
#ifdef TOOLBAR_DD
|
||||
mToolbar->SetDropfeedbackLocation(-1); // clears drawing of marker
|
||||
#endif
|
||||
ForceDrawFrame(mToolbar);
|
||||
} else {
|
||||
rv = NS_ERROR_BASE; // don't consume event
|
||||
}
|
||||
|
||||
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::DragDrop(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
#ifdef TOOLBAR_DD
|
||||
mToolbar->SetDropfeedbackLocation(-1); // clears drawing of marker
|
||||
#endif
|
||||
ForceDrawFrame(mToolbar);
|
||||
//printf("nsToolbarDragListener::DragDrop\n");
|
||||
// String for doing paste
|
||||
nsString stuffToPaste;
|
||||
|
||||
|
@ -314,8 +378,8 @@ nsToolbarDragListener::DragDrop(nsIDOMEvent* aMouseEvent)
|
|||
// Add the text Flavor to the transferable,
|
||||
// because that is the only type of data we are
|
||||
// looking for at the moment.
|
||||
nsAutoString textMime (kTextMime);
|
||||
trans->AddDataFlavor(&textMime);
|
||||
nsAutoString toolbarItemMime (TOOLBARITEM_MIME);
|
||||
trans->AddDataFlavor(&toolbarItemMime);
|
||||
//trans->AddDataFlavor(mImageDataFlavor);
|
||||
|
||||
// Fill the transferable with data for each drag item in succession
|
||||
|
@ -332,11 +396,14 @@ nsToolbarDragListener::DragDrop(nsIDOMEvent* aMouseEvent)
|
|||
// Note: the transferable owns the pointer to the data
|
||||
char *str = 0;
|
||||
PRUint32 len;
|
||||
trans->GetAnyTransferData(&textMime, (void **)&str, &len);
|
||||
trans->GetAnyTransferData(&toolbarItemMime, (void **)&str, &len);
|
||||
|
||||
// If the string was not empty then paste it in
|
||||
if (str) {
|
||||
printf("Dropped: %s\n", str);
|
||||
char buf[256];
|
||||
strncpy(buf, str, len);
|
||||
buf[len] = 0;
|
||||
printf("Dropped: %s\n", buf);
|
||||
stuffToPaste.SetString(str, len);
|
||||
//mEditor->InsertText(stuffToPaste);
|
||||
dragSession->SetCanDrop(PR_TRUE);
|
||||
|
@ -356,3 +423,111 @@ nsToolbarDragListener::DragDrop(nsIDOMEvent* aMouseEvent)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::MouseMove(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
//printf("nsToolbarDragListener::MouseMove mMouseDown %d mMouseDrag %d\n", mMouseDown, mMouseDrag);
|
||||
if (mMouseDown && !mMouseDrag) {
|
||||
|
||||
// Ok now check to see if we are dragging a toolbar item
|
||||
// or the toolbar itself
|
||||
nscoord xLoc;
|
||||
PRBool onChild = IsOnToolbarItem(aMouseEvent, xLoc);
|
||||
|
||||
mMouseDrag = PR_TRUE;
|
||||
|
||||
// Start Drag
|
||||
nsIDragService* dragService;
|
||||
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
||||
nsIDragService::GetIID(),
|
||||
(nsISupports **)&dragService);
|
||||
if (NS_OK == rv) {
|
||||
// XXX NOTE!
|
||||
// Here you need to create a special transferable
|
||||
// for handling RDF nodes (instead of this text transferable)
|
||||
nsCOMPtr<nsITransferable> trans;
|
||||
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
|
||||
nsITransferable::GetIID(), getter_AddRefs(trans));
|
||||
if ( trans) {
|
||||
nsString ddFlavor;
|
||||
nsString dragText;
|
||||
if (onChild) {
|
||||
ddFlavor = TOOLBARITEM_MIME;
|
||||
dragText = "toolbar item";
|
||||
} else {
|
||||
ddFlavor = TOOLBAR_MIME;
|
||||
dragText = "toolbar";
|
||||
}
|
||||
trans->AddDataFlavor(&ddFlavor);
|
||||
PRUint32 len = dragText.Length();
|
||||
trans->SetTransferData(&ddFlavor, dragText.ToNewCString(), len); // transferable consumes the data
|
||||
|
||||
nsCOMPtr<nsISupportsArray> items;
|
||||
NS_NewISupportsArray(getter_AddRefs(items));
|
||||
if ( items ) {
|
||||
items->AppendElement(trans);
|
||||
dragService->InvokeDragSession(items, nsnull, nsIDragService::DRAGDROP_ACTION_COPY | nsIDragService::DRAGDROP_ACTION_MOVE);
|
||||
mMouseDown = PR_FALSE;
|
||||
mMouseDrag = PR_FALSE;
|
||||
}
|
||||
}
|
||||
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::DragMove(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_ERROR_BASE; // means I am NOT consuming event
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
mMouseDown = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::MouseUp(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
printf("nsToolbarDragListener::MouseUp\n");
|
||||
mMouseDown = PR_FALSE;
|
||||
mMouseDrag = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_ERROR_BASE; // means I am NOT consuming event
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::MouseDblClick(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_ERROR_BASE; // means I am NOT consuming event
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::MouseOver(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_ERROR_BASE; // means I am NOT consuming event
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolbarDragListener::MouseOut(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
return NS_ERROR_BASE; // means I am NOT consuming event
|
||||
}
|
||||
|
|
|
@ -16,9 +16,12 @@
|
|||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsToolbarDragListener_h__
|
||||
#define nsToolbarDragListener_h__
|
||||
|
||||
#include "nsIDOMDragListener.h"
|
||||
#include "nsIDOMMouseMotionListener.h"
|
||||
#include "nsIDOMMouseListener.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
|
||||
// Drag & Drop, Clipboard
|
||||
|
@ -29,14 +32,15 @@
|
|||
#include "nsIDragSession.h"
|
||||
#include "nsITransferable.h"
|
||||
#include "nsIFormatConverter.h"
|
||||
#include "nscoord.h"
|
||||
|
||||
|
||||
class nsToolbarFrame;
|
||||
class nsIPresContext;
|
||||
|
||||
/** editor Implementation of the MouseListener interface
|
||||
/** editor Implementation of the DragListener interface
|
||||
*/
|
||||
class nsToolbarDragListener : public nsIDOMDragListener
|
||||
class nsToolbarDragListener : public nsIDOMDragListener, public nsIDOMMouseListener, public nsIDOMMouseMotionListener
|
||||
{
|
||||
public:
|
||||
/** default constructor
|
||||
|
@ -64,8 +68,33 @@ public:
|
|||
virtual nsresult DragDrop(nsIDOMEvent* aDragEvent);
|
||||
/*END implementations of dragevent handler interface*/
|
||||
|
||||
/*BEGIN implementations of nsIDOMMouseMotionListener interface*/
|
||||
public:
|
||||
virtual nsresult MouseMove(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult DragMove(nsIDOMEvent* aMouseEvent);
|
||||
/*END implementations of nsIDOMMouseMotionListener interface*/
|
||||
|
||||
/*BEGIN implementations of nsIDOMMouseListener interface*/
|
||||
public:
|
||||
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent);
|
||||
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent);
|
||||
/*END implementations of nsIDOMMouseListener interface*/
|
||||
|
||||
protected:
|
||||
PRBool IsOnToolbarItem(nsIDOMEvent* aDragEvent, nscoord& aXLoc);
|
||||
|
||||
nsToolbarFrame * mToolbar;
|
||||
nsIPresContext * mPresContext;
|
||||
PRInt32 mCurrentDropLoc;
|
||||
|
||||
};
|
||||
PRBool mMouseDown;
|
||||
PRBool mMouseDrag;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -28,7 +28,12 @@
|
|||
#include "nsIStyleContext.h"
|
||||
#include "nsCSSRendering.h"
|
||||
|
||||
|
||||
#include "nsToolbarDragListener.h"
|
||||
#include "nsIDOMDragListener.h"
|
||||
#include "nsIDOMMouseMotionListener.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIPresContext.h"
|
||||
//
|
||||
// NS_NewToolbarFrame
|
||||
//
|
||||
|
@ -60,6 +65,9 @@ NS_NewToolbarFrame ( nsIFrame** aNewFrame )
|
|||
nsToolbarFrame :: nsToolbarFrame ( )
|
||||
{
|
||||
//*** anything?
|
||||
#ifdef TOOLBAR_DD
|
||||
mXDropLoc = -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,6 +83,43 @@ nsToolbarFrame :: ~nsToolbarFrame ( )
|
|||
#endif
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsToolbarFrame::Init(nsIPresContext& aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParent,
|
||||
nsIStyleContext* aContext,
|
||||
nsIFrame* aPrevInFlow)
|
||||
{
|
||||
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
//nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(mContent));
|
||||
nsCOMPtr<nsIContent> content;
|
||||
GetContent(getter_AddRefs(content));
|
||||
|
||||
nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(content));
|
||||
|
||||
mDragListener = new nsToolbarDragListener();
|
||||
mDragListener->SetToolbar(this);
|
||||
|
||||
if (NS_OK == reciever->AddEventListenerByIID((nsIDOMDragListener *)mDragListener, nsIDOMDragListener::GetIID())) {
|
||||
//printf("Toolbar registered as Drag Listener\n");
|
||||
}
|
||||
|
||||
if (NS_OK == reciever->AddEventListenerByIID((nsIDOMMouseListener *)mDragListener, nsIDOMMouseListener::GetIID())) {
|
||||
//printf("Toolbar registered as Mouse Listener\n");
|
||||
}
|
||||
|
||||
if (NS_OK == reciever->AddEventListenerByIID((nsIDOMMouseMotionListener *)mDragListener, nsIDOMMouseMotionListener::GetIID())) {
|
||||
//printf("Toolbar registered as MouseMotion Listener\n");
|
||||
}
|
||||
|
||||
// nsCOMPtr<nsIDOMEventListener> eventListener = do_QueryInterface(popupListener);
|
||||
// AddEventListener("mousedown", eventListener, PR_FALSE, PR_FALSE);
|
||||
#endif
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
//
|
||||
// Paint
|
||||
|
@ -114,12 +159,38 @@ nsToolbarFrame :: Paint ( nsIPresContext& aPresContext,
|
|||
// override the visibility property and display even if their parent is
|
||||
// hidden
|
||||
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
||||
|
||||
|
||||
return NS_OK;
|
||||
|
||||
#endif
|
||||
|
||||
return nsBoxFrame::Paint ( aPresContext, aRenderingContext, aDirtyRect, aWhichLayer );
|
||||
|
||||
nsresult res = nsBoxFrame::Paint ( aPresContext, aRenderingContext, aDirtyRect, aWhichLayer );
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
if (mXDropLoc != -1) {
|
||||
//printf("mXDropLoc: %d\n", mXDropLoc);
|
||||
// XXX this is temporary
|
||||
if (!mMarkerStyle) {
|
||||
nsCOMPtr<nsIAtom> atom ( getter_AddRefs(NS_NewAtom(":-moz-drop-marker")) );
|
||||
aPresContext.ProbePseudoStyleContextFor(mContent, atom, mStyleContext,
|
||||
PR_FALSE,
|
||||
getter_AddRefs(mMarkerStyle));
|
||||
}
|
||||
nscolor color;
|
||||
if (mMarkerStyle) {
|
||||
const nsStyleColor* styleColor = (const nsStyleColor*)mMarkerStyle->GetStyleData(eStyleStruct_Color);
|
||||
color = styleColor->mColor;
|
||||
} else {
|
||||
color = NS_RGB(0,0,0);
|
||||
}
|
||||
//printf("paint %d\n", mXDropLoc);
|
||||
aRenderingContext.SetColor(color);
|
||||
aRenderingContext.DrawLine(mXDropLoc, 0, mXDropLoc, mRect.height);
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
|
||||
} // Paint
|
||||
|
||||
|
||||
|
@ -175,19 +246,34 @@ nsToolbarFrame :: HandleEvent ( nsIPresContext& aPresContext,
|
|||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus)
|
||||
{
|
||||
#ifdef TOOLBAR_DD
|
||||
mDragListener->SetPresContext(&aPresContext); // not ref counted
|
||||
#endif;
|
||||
|
||||
if ( !aEvent )
|
||||
return nsEventStatus_eIgnore;
|
||||
|
||||
switch (aEvent->message) {
|
||||
case NS_DRAGDROP_ENTER:
|
||||
// show drop feedback
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
if (!mMarkerStyle) {
|
||||
nsCOMPtr<nsIAtom> atom ( getter_AddRefs(NS_NewAtom(":-moz-drop-marker")) );
|
||||
aPresContext.ProbePseudoStyleContextFor(mContent, atom, mStyleContext,
|
||||
PR_FALSE,
|
||||
getter_AddRefs(mMarkerStyle));
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case NS_DRAGDROP_OVER:
|
||||
break;
|
||||
|
||||
case NS_DRAGDROP_EXIT:
|
||||
#ifdef TOOLBAR_DD
|
||||
mMarkerStyle = do_QueryInterface(nsnull);
|
||||
// remove drop feedback
|
||||
#endif
|
||||
break;
|
||||
|
||||
case NS_DRAGDROP_DROP:
|
||||
|
@ -199,3 +285,29 @@ nsToolbarFrame :: HandleEvent ( nsIPresContext& aPresContext,
|
|||
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
|
||||
} // HandleEvent
|
||||
|
||||
/**
|
||||
* Call this when styles change
|
||||
*/
|
||||
void
|
||||
nsToolbarFrame::ReResolveStyles(nsIPresContext& aPresContext,
|
||||
PRInt32 aParentChange,
|
||||
nsStyleChangeList* aChangeList,
|
||||
PRInt32* aLocalChange)
|
||||
{
|
||||
|
||||
// style that draw an Marker around the button
|
||||
|
||||
// see if the Marker has changed.
|
||||
/*nsCOMPtr<nsIStyleContext> oldMarker = mMarkerStyle;
|
||||
|
||||
nsCOMPtr<nsIAtom> atom ( getter_AddRefs(NS_NewAtom(":-moz-marker")) );
|
||||
aPresContext.ProbePseudoStyleContextFor(mContent, atom, mStyleContext,
|
||||
PR_FALSE,
|
||||
getter_AddRefs(mMarkerStyle));
|
||||
if ((mMarkerStyle && oldMarker) && (mMarkerStyle != oldMarker)) {
|
||||
nsFrame::CaptureStyleChangeFor(this, oldMarker, mMarkerStyle,
|
||||
aParentChange, aChangeList, aLocalChange);
|
||||
}*/
|
||||
|
||||
}
|
|
@ -39,15 +39,29 @@
|
|||
#ifndef nsToolbarFrame_h__
|
||||
#define nsToolbarFrame_h__
|
||||
|
||||
#define TOOLBARITEM_MIME "moz/toolbaritem"
|
||||
#define TOOLBAR_MIME "moz/toolbar"
|
||||
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsBoxFrame.h"
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
class nsToolbarDragListener;
|
||||
class nsToolbarMouseMotionListener;
|
||||
#endif
|
||||
|
||||
class nsToolbarFrame : public nsBoxFrame
|
||||
{
|
||||
public:
|
||||
friend nsresult NS_NewToolbarFrame(nsIFrame** aNewFrame);
|
||||
|
||||
NS_IMETHOD Init(nsIPresContext& aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParent,
|
||||
nsIStyleContext* aContext,
|
||||
nsIFrame* asPrevInFlow);
|
||||
|
||||
// nsIHTMLReflow overrides
|
||||
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
|
@ -64,6 +78,15 @@ public:
|
|||
nsGUIEvent* aEvent,
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
virtual void ReResolveStyles(nsIPresContext& aPresContext,
|
||||
PRInt32 aParentChange,
|
||||
nsStyleChangeList* aChangeList,
|
||||
PRInt32* aLocalChange);
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
void SetDropfeedbackLocation(nscoord aX) { mXDropLoc = aX; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
nsToolbarFrame();
|
||||
virtual ~nsToolbarFrame();
|
||||
|
@ -73,6 +96,12 @@ protected:
|
|||
nsToolbarFrame ( const nsToolbarFrame& aFrame ) ; // DO NOT IMPLEMENT
|
||||
nsToolbarFrame& operator= ( const nsToolbarFrame& aFrame ) ; // DO NOT IMPLEMENT
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
nsToolbarDragListener * mDragListener;
|
||||
PRInt32 mXDropLoc;
|
||||
nsCOMPtr<nsIStyleContext> mMarkerStyle;
|
||||
#endif
|
||||
|
||||
}; // class nsToolbarFrame
|
||||
|
||||
#endif
|
||||
|
|
|
@ -198,36 +198,11 @@ nsToolbarItemFrame::HandleEvent(nsIPresContext& aPresContext,
|
|||
}
|
||||
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
|
||||
} */
|
||||
|
||||
printf("ToolbarItem %d\n", aEvent->message);
|
||||
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* We can be a nsIBox
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsToolbarItemFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if (aIID.Equals(kIBoxIID)) {
|
||||
*aInstancePtr = (void*)(nsIBox*) this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return nsBoxFrame::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* We are a frame and we do not maintain a ref count
|
||||
*/
|
||||
|
|
|
@ -35,8 +35,6 @@ public:
|
|||
|
||||
friend nsresult NS_NewToolbarItemFrame(nsIFrame** aNewFrame);
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
//
|
||||
|
||||
#include "nsToolboxFrame.h"
|
||||
#include "nsToolbarFrame.h" // needed for MIME definitions
|
||||
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsCSSRendering.h"
|
||||
#include "nsIHTMLReflow.h"
|
||||
|
@ -37,6 +39,30 @@
|
|||
#include "nsIWidget.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsIDragService.h"
|
||||
#include "nsIDragSession.h"
|
||||
#include "nsITransferable.h"
|
||||
#include "nsIFormatConverter.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMUIEvent.h"
|
||||
#include "nsIDOMDragListener.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
|
||||
// Drag & Drop, Clipboard Support
|
||||
static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID);
|
||||
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
|
||||
static NS_DEFINE_IID(kCDataFlavorCID, NS_DATAFLAVOR_CID);
|
||||
static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID);
|
||||
|
||||
#include "nsISupportsArray.h"
|
||||
#endif
|
||||
|
||||
//
|
||||
// NS_NewToolboxFrame
|
||||
|
@ -71,6 +97,7 @@ nsToolboxFrame :: nsToolboxFrame ( )
|
|||
kCollapsedAtom(dont_AddRef( NS_NewAtom("collapsed"))),
|
||||
kHiddenAtom(dont_AddRef( NS_NewAtom("hidden")))
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// we start off vertical
|
||||
mHorizontal = PR_FALSE;
|
||||
}
|
||||
|
@ -86,6 +113,28 @@ nsToolboxFrame :: ~nsToolboxFrame ( )
|
|||
//¥¥¥ walk mGrippies and delete elements
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsToolboxFrame)
|
||||
|
||||
NS_IMPL_RELEASE(nsToolboxFrame)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolboxFrame::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
#ifdef TOOLBAR_DD
|
||||
if (aIID.Equals(kIDOMEventReceiverIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
if (aIID.Equals(nsIDOMDragListener::GetIID())) {
|
||||
*aInstancePtr = (void*)(nsIDOMDragListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return nsBoxFrame::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
//
|
||||
// RefreshStyleContext
|
||||
|
@ -145,6 +194,19 @@ nsToolboxFrame::Init(nsIPresContext& aPresContext,
|
|||
{
|
||||
nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
||||
UpdateStyles(&aPresContext);
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
nsCOMPtr<nsIContent> content;
|
||||
GetContent(getter_AddRefs(content));
|
||||
|
||||
nsCOMPtr<nsIDOMEventReceiver> reciever(do_QueryInterface(content));
|
||||
|
||||
if (NS_OK == reciever->AddEventListenerByIID((nsIDOMDragListener *)this, nsIDOMDragListener::GetIID())) {
|
||||
printf("Toolbar registered as Drag Listener\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -680,3 +742,146 @@ nsToolboxFrame :: ExpandToolbar ( TabInfo & inTab )
|
|||
#endif
|
||||
|
||||
} // ExpandToolbar
|
||||
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolboxFrame::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
//printf("nsToolbarDragListener::HandleEvent\n");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolboxFrame::DragEnter(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
nsIDragService* dragService;
|
||||
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
||||
nsIDragService::GetIID(),
|
||||
(nsISupports **)&dragService);
|
||||
if (NS_OK == rv) {
|
||||
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
|
||||
|
||||
nsAutoString toolbarFlavor(TOOLBAR_MIME);
|
||||
if (dragSession && (NS_OK == dragSession->IsDataFlavorSupported(&toolbarFlavor))) {
|
||||
dragSession->SetCanDrop(PR_TRUE);
|
||||
}
|
||||
|
||||
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolboxFrame::DragOver(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
// now tell the drag session whether we can drop here
|
||||
nsIDragService* dragService;
|
||||
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
||||
nsIDragService::GetIID(),
|
||||
(nsISupports **)&dragService);
|
||||
if (NS_OK == rv) {
|
||||
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
|
||||
nsAutoString toolbarFlavor(TOOLBAR_MIME);
|
||||
if (dragSession && NS_OK == dragSession->IsDataFlavorSupported(&toolbarFlavor)) {
|
||||
|
||||
// Right here you need to figure out where the mouse is
|
||||
// and whether you can drop here
|
||||
|
||||
dragSession->SetCanDrop(PR_TRUE);
|
||||
} else {
|
||||
rv = NS_ERROR_BASE; // event bubbles
|
||||
}
|
||||
|
||||
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
|
||||
}
|
||||
|
||||
// NS_ERROR_xxx means event is NOT consumed
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolboxFrame::DragExit(nsIDOMEvent* aDragEvent)
|
||||
{
|
||||
return NS_OK; // consumes event
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsresult
|
||||
nsToolboxFrame::DragDrop(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
// String for doing paste
|
||||
nsString stuffToPaste;
|
||||
|
||||
// Create drag service for getting state of drag
|
||||
nsIDragService* dragService;
|
||||
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
||||
nsIDragService::GetIID(),
|
||||
(nsISupports **)&dragService);
|
||||
if (NS_OK == rv) {
|
||||
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
|
||||
|
||||
if (dragSession) {
|
||||
|
||||
// Create transferable for getting the drag data
|
||||
nsCOMPtr<nsITransferable> trans;
|
||||
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
|
||||
nsITransferable::GetIID(),
|
||||
(void**) getter_AddRefs(trans));
|
||||
if ( NS_SUCCEEDED(rv) && trans ) {
|
||||
// Add the text Flavor to the transferable,
|
||||
// because that is the only type of data we are
|
||||
// looking for at the moment.
|
||||
nsAutoString toolbarMime (TOOLBAR_MIME);
|
||||
trans->AddDataFlavor(&toolbarMime);
|
||||
//trans->AddDataFlavor(mImageDataFlavor);
|
||||
|
||||
// Fill the transferable with data for each drag item in succession
|
||||
PRUint32 numItems = 0;
|
||||
if (NS_SUCCEEDED(dragSession->GetNumDropItems(&numItems))) {
|
||||
|
||||
//printf("Num Drop Items %d\n", numItems);
|
||||
|
||||
PRUint32 i;
|
||||
for (i=0;i<numItems;++i) {
|
||||
if (NS_SUCCEEDED(dragSession->GetData(trans, i))) {
|
||||
|
||||
// Get the string data out of the transferable
|
||||
// Note: the transferable owns the pointer to the data
|
||||
char *str = 0;
|
||||
PRUint32 len;
|
||||
trans->GetAnyTransferData(&toolbarMime, (void **)&str, &len);
|
||||
|
||||
// If the string was not empty then paste it in
|
||||
if (str) {
|
||||
char buf[256];
|
||||
strncpy(buf, str, len);
|
||||
buf[len] = 0;
|
||||
printf("Dropped: %s\n", buf);
|
||||
stuffToPaste.SetString(str, len);
|
||||
dragSession->SetCanDrop(PR_TRUE);
|
||||
}
|
||||
|
||||
// XXX This is where image support might go
|
||||
//void * data;
|
||||
//trans->GetTransferData(mImageDataFlavor, (void **)&data, &len);
|
||||
}
|
||||
} // foreach drag item
|
||||
}
|
||||
} // if valid transferable
|
||||
} // if valid drag session
|
||||
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
|
||||
} // if valid drag service
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#ifndef nsToolBoxFrame_h___
|
||||
#define nsToolBoxFrame_h___
|
||||
|
||||
#include "nsIDOMDragListener.h"
|
||||
#include "nsHTMLContainerFrame.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIContent.h"
|
||||
|
@ -47,11 +48,17 @@
|
|||
#include "nsBoxFrame.h"
|
||||
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
class nsToolboxFrame : public nsBoxFrame, public nsIDOMDragListener
|
||||
#else
|
||||
class nsToolboxFrame : public nsBoxFrame
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
friend nsresult NS_NewToolboxFrame(nsIFrame** aNewFrame);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIHTMLReflow overrides
|
||||
NS_IMETHOD Reflow(nsIPresContext& aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
|
@ -81,6 +88,17 @@ public:
|
|||
NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint,
|
||||
nsIFrame** aFrame);
|
||||
|
||||
#ifdef TOOLBAR_DD
|
||||
/*BEGIN implementations of dragevent handler interface*/
|
||||
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
|
||||
public:
|
||||
virtual nsresult DragEnter(nsIDOMEvent* aDragEvent);
|
||||
virtual nsresult DragOver(nsIDOMEvent* aDragEvent);
|
||||
virtual nsresult DragExit(nsIDOMEvent* aDragEvent);
|
||||
virtual nsresult DragDrop(nsIDOMEvent* aDragEvent);
|
||||
/*END implementations of dragevent handler interface*/
|
||||
#endif
|
||||
|
||||
protected:
|
||||
enum { kGrippyWidthInPixels = 10, kCollapsedGrippyHeightInPixels = 10, kCollapsedGrippyWidthInPixels = 50 } ;
|
||||
enum { kNoGrippyHilighted = -1 } ;
|
||||
|
|
Загрузка…
Ссылка в новой задаче