personal toolbar d&d now in JavaScript.

This commit is contained in:
pinkerton%netscape.com 1999-09-02 23:16:37 +00:00
Родитель d997687f34
Коммит 59cb646f50
5 изменённых файлов: 182 добавлений и 81 удалений

Просмотреть файл

@ -368,84 +368,7 @@ nsToolbarDragListener::DragExit(nsIDOMEvent* aDragEvent)
nsresult
nsToolbarDragListener::DragDrop(nsIDOMEvent* aMouseEvent)
{
mToolbar->SetDropfeedbackLocation(-1); // clears drawing of marker
// XXX At the moment toolbar drags contain "text"
// in the future they will probably contain some form of content
// that will be translated into some RDF form
ForceDrawFrame(mToolbar);
// 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 toolbar item flavor to the transferable,
// because that is the only type of data we are looking for at the moment.
trans->AddDataFlavor(TOOLBARITEM_MIME);
// 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. This obviously needs to be rewritten ;)
PRUint32 len;
char* toolbarItemMime;
nsCOMPtr<nsISupports> genericDataObj;
trans->GetAnyTransferData(&toolbarItemMime, getter_AddRefs(genericDataObj), &len);
if ( genericDataObj ) {
nsCOMPtr<nsISupportsWString> dataObj ( do_QueryInterface(genericDataObj) );
if ( dataObj ) {
// If the string was not empty then paste it in
PRUnichar* buf;
dataObj->ToString(&buf);
if ( buf ) {
nsAutoString converter(buf);
char* lame = converter.ToNewCString();
printf("Dropped Data: %s\n", lame);
//XXX do real stuff here
dragSession->SetCanDrop(PR_TRUE);
delete [] lame;
}
delete [] buf;
}
}
delete [] toolbarItemMime;
}
} // foreach drag item
// this clear the active state of the button that was pressed to do the drag
// if the drag came from outside the app then make this call should have no effect
nsIEventStateManager *stateManager;
if (NS_OK == mPresContext->GetEventStateManager(&stateManager)) {
//stateManager->SetContentState(nsnull, NS_EVENT_STATE_DRAGOVER);
stateManager->SetContentState(nsnull, NS_EVENT_STATE_ACTIVE);
NS_RELEASE(stateManager);
}
}
} // if valid transferable
} // if valid drag session
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
} // if valid drag service
return NS_ERROR_BASE; // consumes the event
// this code should all be in JS.
return NS_OK;
}

Просмотреть файл

@ -23,6 +23,94 @@
var defaultStatus = "default status text";
var explicitURL = false;
function BeginDragPersonalToolbar ( event )
{
//XXX we rely on a capturer to already have determined which item the mouse was over
//XXX and have set an attribute.
// if the click is on the toolbar proper, ignore it. We only care about clicks on
// items.
var toolbar = document.getElementById("PersonalToolbar");
if ( event.target == toolbar )
return true; // continue propagating the event
var dragStarted = false;
var dragService = Components.classes["component://netscape/widget/dragservice"].getService();
if ( dragService ) dragService = dragService.QueryInterface(Components.interfaces.nsIDragService);
if ( dragService ) {
var trans = Components.classes["component://netscape/widget/transferable"].createInstance();
if ( trans ) trans = trans.QueryInterface(Components.interfaces.nsITransferable);
if ( trans ) {
trans.addDataFlavor("moz/toolbaritem");
var genData = Components.classes["component://netscape/supports-wstring"].createInstance();
if ( genData ) data = genData.QueryInterface(Components.interfaces.nsISupportsWString);
if ( data ) {
//XXX replace with the real data when rdf is hooked up.
data.data = "toolbar item, baby!";
trans.setTransferData ( "moz/toolbaritem", genData, 38 ); // double byte data (19*2)
var transArray = Components.classes["component://netscape/supports-array"].createInstance();
if ( transArray ) transArray = transArray.QueryInterface(Components.interfaces.nsISupportsArray);
if ( transArray ) {
// put it into the transferable as an |nsISupports|
var genTrans = trans.QueryInterface(Components.interfaces.nsISupports);
transArray.AppendElement(genTrans);
var nsIDragService = Components.interfaces.nsIDragService;
dragService.invokeDragSession ( transArray, null, nsIDragService.DRAGDROP_ACTION_COPY +
nsIDragService.DRAGDROP_ACTION_MOVE );
dragStarted = true;
}
} // if data object
} // if transferable
} // if drag service
return !dragStarted; // don't propagate the event if a drag has begun
} // BeginDragPersonalToolbar
function DropPersonalToolbar ( event )
{
var dropAccepted = false;
var dragService = Components.classes["component://netscape/widget/dragservice"].getService();
if ( dragService ) dragService = dragService.QueryInterface(Components.interfaces.nsIDragService);
if ( dragService ) {
var dragSession = dragService.getCurrentSession();
if ( dragSession ) {
var trans = Components.classes["component://netscape/widget/transferable"].createInstance();
if ( trans ) trans = trans.QueryInterface(Components.interfaces.nsITransferable);
if ( trans ) {
trans.addDataFlavor("moz/toolbaritem");
for ( var i = 0; i < dragSession.numDropItems; ++i ) {
dragSession.getData ( trans, i );
var dataObj = new Object();
var bestFlavor = new Object();
var len = new Object();
trans.getAnyTransferData ( bestFlavor, dataObj, len );
if ( dataObj ) dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsWString);
if ( dataObj ) {
//XXX do something real here! remember len is in bytes, not chars
dataObj.data[len.value / 2] = null;
dump ( "!!! got data len = " + len.value + " |" + dataObj.data + "|\n" );
dragSession.canDrop = true;
var dropAccepted = true;
}
} // foreach drag item
} // if transferable
} // if dragsession
} // if dragservice
return !dropAccepted; // don't propagate the event if a drag was accepted
} // DropPersonalToolbar
function UpdateHistory(event)
{
// This is registered as a capturing "load" event handler. When a

Просмотреть файл

@ -513,7 +513,8 @@ Contributor(s): ______________________________________. -->
</titledbutton>
</toolbar>
<toolbar class="main-bar" chromeclass="toolbar" datasources="rdf:bookmarks" id="PersonalToolbar" ref="NC:PersonalToolbarFolder">
<toolbar class="main-bar" chromeclass="toolbar" datasources="rdf:bookmarks" id="PersonalToolbar" ref="NC:PersonalToolbarFolder"
ondraggesture="return BeginDragPersonalToolbar(event);" ondragdrop="return DropPersonalToolbar(event);">
<template>
<rule iscontainer="true">
<titledbutton uri="..." src="resource:/res/rdf/folder-closed.gif" value="rdf:http://home.netscape.com/NC-rdf#Name" align="left" popup="bookmark-popup" />

Просмотреть файл

@ -23,6 +23,94 @@
var defaultStatus = "default status text";
var explicitURL = false;
function BeginDragPersonalToolbar ( event )
{
//XXX we rely on a capturer to already have determined which item the mouse was over
//XXX and have set an attribute.
// if the click is on the toolbar proper, ignore it. We only care about clicks on
// items.
var toolbar = document.getElementById("PersonalToolbar");
if ( event.target == toolbar )
return true; // continue propagating the event
var dragStarted = false;
var dragService = Components.classes["component://netscape/widget/dragservice"].getService();
if ( dragService ) dragService = dragService.QueryInterface(Components.interfaces.nsIDragService);
if ( dragService ) {
var trans = Components.classes["component://netscape/widget/transferable"].createInstance();
if ( trans ) trans = trans.QueryInterface(Components.interfaces.nsITransferable);
if ( trans ) {
trans.addDataFlavor("moz/toolbaritem");
var genData = Components.classes["component://netscape/supports-wstring"].createInstance();
if ( genData ) data = genData.QueryInterface(Components.interfaces.nsISupportsWString);
if ( data ) {
//XXX replace with the real data when rdf is hooked up.
data.data = "toolbar item, baby!";
trans.setTransferData ( "moz/toolbaritem", genData, 38 ); // double byte data (19*2)
var transArray = Components.classes["component://netscape/supports-array"].createInstance();
if ( transArray ) transArray = transArray.QueryInterface(Components.interfaces.nsISupportsArray);
if ( transArray ) {
// put it into the transferable as an |nsISupports|
var genTrans = trans.QueryInterface(Components.interfaces.nsISupports);
transArray.AppendElement(genTrans);
var nsIDragService = Components.interfaces.nsIDragService;
dragService.invokeDragSession ( transArray, null, nsIDragService.DRAGDROP_ACTION_COPY +
nsIDragService.DRAGDROP_ACTION_MOVE );
dragStarted = true;
}
} // if data object
} // if transferable
} // if drag service
return !dragStarted; // don't propagate the event if a drag has begun
} // BeginDragPersonalToolbar
function DropPersonalToolbar ( event )
{
var dropAccepted = false;
var dragService = Components.classes["component://netscape/widget/dragservice"].getService();
if ( dragService ) dragService = dragService.QueryInterface(Components.interfaces.nsIDragService);
if ( dragService ) {
var dragSession = dragService.getCurrentSession();
if ( dragSession ) {
var trans = Components.classes["component://netscape/widget/transferable"].createInstance();
if ( trans ) trans = trans.QueryInterface(Components.interfaces.nsITransferable);
if ( trans ) {
trans.addDataFlavor("moz/toolbaritem");
for ( var i = 0; i < dragSession.numDropItems; ++i ) {
dragSession.getData ( trans, i );
var dataObj = new Object();
var bestFlavor = new Object();
var len = new Object();
trans.getAnyTransferData ( bestFlavor, dataObj, len );
if ( dataObj ) dataObj = dataObj.value.QueryInterface(Components.interfaces.nsISupportsWString);
if ( dataObj ) {
//XXX do something real here! remember len is in bytes, not chars
dataObj.data[len.value / 2] = null;
dump ( "!!! got data len = " + len.value + " |" + dataObj.data + "|\n" );
dragSession.canDrop = true;
var dropAccepted = true;
}
} // foreach drag item
} // if transferable
} // if dragsession
} // if dragservice
return !dropAccepted; // don't propagate the event if a drag was accepted
} // DropPersonalToolbar
function UpdateHistory(event)
{
// This is registered as a capturing "load" event handler. When a

Просмотреть файл

@ -513,7 +513,8 @@ Contributor(s): ______________________________________. -->
</titledbutton>
</toolbar>
<toolbar class="main-bar" chromeclass="toolbar" datasources="rdf:bookmarks" id="PersonalToolbar" ref="NC:PersonalToolbarFolder">
<toolbar class="main-bar" chromeclass="toolbar" datasources="rdf:bookmarks" id="PersonalToolbar" ref="NC:PersonalToolbarFolder"
ondraggesture="return BeginDragPersonalToolbar(event);" ondragdrop="return DropPersonalToolbar(event);">
<template>
<rule iscontainer="true">
<titledbutton uri="..." src="resource:/res/rdf/folder-closed.gif" value="rdf:http://home.netscape.com/NC-rdf#Name" align="left" popup="bookmark-popup" />