2002-07-22 02:40:07 +04:00
|
|
|
// ClipboardHandler.cpp
|
|
|
|
|
|
|
|
#include <Message.h>
|
2002-10-22 04:08:45 +04:00
|
|
|
#include <RegistrarDefs.h>
|
2002-07-22 02:40:07 +04:00
|
|
|
|
|
|
|
#include "ClipboardHandler.h"
|
|
|
|
|
2002-07-28 17:37:26 +04:00
|
|
|
/*!
|
|
|
|
\class ClipboardHandler
|
|
|
|
\brief Handles all clipboard related requests.
|
|
|
|
*/
|
|
|
|
|
2002-07-22 02:40:07 +04:00
|
|
|
// constructor
|
2002-07-28 17:37:26 +04:00
|
|
|
/*! \brief Creates and initializes a ClipboardHandler.
|
|
|
|
*/
|
2002-07-22 02:40:07 +04:00
|
|
|
ClipboardHandler::ClipboardHandler()
|
|
|
|
: BHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// destructor
|
2002-07-28 17:37:26 +04:00
|
|
|
/*! \brief Frees all resources associate with this object.
|
|
|
|
*/
|
2002-07-22 02:40:07 +04:00
|
|
|
ClipboardHandler::~ClipboardHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// MessageReceived
|
2002-07-28 17:37:26 +04:00
|
|
|
/*! \brief Overrides the super class version to handle the clipboard specific
|
|
|
|
messages.
|
|
|
|
\param message The message to be handled
|
|
|
|
*/
|
2002-07-22 02:40:07 +04:00
|
|
|
void
|
|
|
|
ClipboardHandler::MessageReceived(BMessage *message)
|
|
|
|
{
|
2002-10-22 04:08:45 +04:00
|
|
|
BString name;
|
|
|
|
BMessage reply;
|
2002-07-22 02:40:07 +04:00
|
|
|
switch (message->what) {
|
2002-10-22 04:08:45 +04:00
|
|
|
B_REG_ADD_CLIPBOARD:
|
|
|
|
{
|
|
|
|
if ( message->FindString("name",&name) != B_OK )
|
|
|
|
{
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fClipboardTree.AddNode(name);
|
|
|
|
reply.AddInt32("result",1);
|
|
|
|
}
|
|
|
|
reply.what = B_REG_RESULT;
|
|
|
|
message->SendReply(&reply);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
B_REG_GET_CLIPBOARD_COUNT:
|
|
|
|
{
|
|
|
|
if ( message->FindString("name",&name) != B_OK )
|
|
|
|
{
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClipboardTree *node = fClipboardTree.GetNode(name);
|
|
|
|
if ( node )
|
|
|
|
{
|
|
|
|
reply.AddInt32("count",(uint32)(node->GetCount()));
|
|
|
|
reply.AddInt32("result",1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
reply.what = B_REG_RESULT;
|
|
|
|
message->SendReply(&reply);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
B_REG_CLIPBOARD_START_WATCHING:
|
|
|
|
{
|
|
|
|
BMessenger target;
|
|
|
|
if ( (message->FindString("name",&name) != B_OK) ||
|
|
|
|
(message->FindMessenger("target",&target) != B_OK) )
|
|
|
|
{
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClipboardTree *node = fClipboardTree.GetNode(name);
|
|
|
|
if ( node && node->AddWatcher(&target) )
|
|
|
|
reply.AddInt32("result",1);
|
|
|
|
else
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
reply.what = B_REG_RESULT;
|
|
|
|
message->SendReply(&reply);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
B_REG_CLIPBOARD_STOP_WATCHING:
|
|
|
|
{
|
|
|
|
BMessenger target;
|
|
|
|
if ( (message->FindString("name",&name) != B_OK) ||
|
|
|
|
(message->FindMessenger("target",&target) != B_OK) )
|
|
|
|
{
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClipboardTree *node = fClipboardTree.GetNode(name);
|
|
|
|
if ( node && node->RemoveWatcher(&target) )
|
|
|
|
reply.AddInt32("result",1);
|
|
|
|
else
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
reply.what = B_REG_RESULT;
|
|
|
|
message->SendReply(&reply);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
B_REG_DOWNLOAD_CLIPBOARD:
|
|
|
|
{
|
|
|
|
if ( message->FindString("name",&name) != B_OK )
|
|
|
|
{
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClipboardTree *node = fClipboardTree.GetNode(name);
|
|
|
|
if ( node )
|
|
|
|
{
|
|
|
|
reply.AddMessage("data",node->GetData());
|
|
|
|
reply.AddMessenger("data source",*node->GetDataSource());
|
|
|
|
reply.AddInt32("count",(uint32)(node->GetCount()));
|
|
|
|
reply.AddInt32("result",1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
reply.what = B_REG_RESULT;
|
|
|
|
message->SendReply(&reply);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
B_REG_UPLOAD_CLIPBOARD:
|
|
|
|
{
|
|
|
|
BMessage data;
|
|
|
|
BMessenger dataSource;
|
|
|
|
ClipboardTree *node = NULL;
|
|
|
|
if ( (message->FindString("name",&name) != B_OK) ||
|
|
|
|
(message->FindMessage("data",&data) != B_OK) ||
|
|
|
|
(message->FindMessenger("data source",&dataSource) != B_OK) )
|
|
|
|
{
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
node = fClipboardTree.GetNode(name);
|
|
|
|
if ( node )
|
|
|
|
{
|
|
|
|
node->SetData(&data);
|
|
|
|
node->SetDataSource(&dataSource);
|
|
|
|
reply.AddInt32("count",(uint32)(node->IncrementCount()));
|
|
|
|
reply.AddInt32("result",1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
reply.AddInt32("result",0);
|
|
|
|
}
|
|
|
|
reply.what = B_REG_RESULT;
|
|
|
|
message->SendReply(&reply);
|
|
|
|
if ( node )
|
|
|
|
node->NotifyWatchers();
|
|
|
|
}
|
|
|
|
break;
|
2002-07-22 02:40:07 +04:00
|
|
|
default:
|
|
|
|
BHandler::MessageReceived(message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-22 04:08:45 +04:00
|
|
|
|