Checkin for Gabe Yoder
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1590 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// ClipboardHandler.cpp
|
||||
|
||||
#include <Message.h>
|
||||
#include <RegistrarDefs.h>
|
||||
|
||||
#include "ClipboardHandler.h"
|
||||
|
||||
@@ -32,10 +33,142 @@ ClipboardHandler::~ClipboardHandler()
|
||||
void
|
||||
ClipboardHandler::MessageReceived(BMessage *message)
|
||||
{
|
||||
BString name;
|
||||
BMessage reply;
|
||||
switch (message->what) {
|
||||
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;
|
||||
default:
|
||||
BHandler::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#define CLIPBOARD_HANDLER_H
|
||||
|
||||
#include <Handler.h>
|
||||
#include <Message.h>
|
||||
#include "ClipboardTree.h"
|
||||
|
||||
class ClipboardHandler : public BHandler {
|
||||
public:
|
||||
@@ -11,6 +13,9 @@ public:
|
||||
virtual ~ClipboardHandler();
|
||||
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
private:
|
||||
ClipboardTree fClipboardTree;
|
||||
};
|
||||
|
||||
#endif // CLIPBOARD_HANDLER_H
|
||||
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
// ClipboardTree.cpp
|
||||
|
||||
#include <Message.h>
|
||||
#include <Clipboard.h>
|
||||
|
||||
#include "ClipboardTree.h"
|
||||
|
||||
/*!
|
||||
\class ClipboardTree
|
||||
\brief Implements a tree containing clipboards and their data
|
||||
*/
|
||||
|
||||
// constructor
|
||||
/*! \brief Creates and initializes a ClipboardTree.
|
||||
*/
|
||||
ClipboardTree::ClipboardTree()
|
||||
{
|
||||
fName = "";
|
||||
fCount = 0;
|
||||
fLeftChild = NULL;
|
||||
fRightChild = NULL;
|
||||
}
|
||||
|
||||
// destructor
|
||||
/*! \brief Frees all resources associate with this object.
|
||||
*/
|
||||
ClipboardTree::~ClipboardTree()
|
||||
{
|
||||
if ( fLeftChild )
|
||||
delete fLeftChild;
|
||||
if ( fRightChild )
|
||||
delete fRightChild;
|
||||
}
|
||||
|
||||
void ClipboardTree::AddNode(BString name)
|
||||
{
|
||||
if ( fName == "" )
|
||||
{
|
||||
fName = name;
|
||||
return;
|
||||
}
|
||||
if ( fName == name )
|
||||
return;
|
||||
if ( name < fName )
|
||||
{
|
||||
if ( !fLeftChild )
|
||||
fLeftChild = new ClipboardTree;
|
||||
fLeftChild->AddNode(name);
|
||||
return;
|
||||
}
|
||||
if ( !fRightChild )
|
||||
fRightChild = new ClipboardTree;
|
||||
fRightChild->AddNode(name);
|
||||
}
|
||||
|
||||
ClipboardTree* ClipboardTree::GetNode(BString name)
|
||||
{
|
||||
if ( fName == "" )
|
||||
return NULL;
|
||||
if ( fName == name )
|
||||
return this;
|
||||
if ( name < fName )
|
||||
{
|
||||
if ( !fLeftChild )
|
||||
return NULL;
|
||||
return fLeftChild->GetNode(name);
|
||||
}
|
||||
if ( !fRightChild )
|
||||
return NULL;
|
||||
return fRightChild->GetNode(name);
|
||||
}
|
||||
|
||||
uint32 ClipboardTree::GetCount()
|
||||
{
|
||||
return fCount;
|
||||
}
|
||||
|
||||
uint32 ClipboardTree::IncrementCount()
|
||||
{
|
||||
fCount++;
|
||||
return fCount;
|
||||
}
|
||||
|
||||
BMessage* ClipboardTree::GetData()
|
||||
{
|
||||
return &fData;
|
||||
}
|
||||
|
||||
void ClipboardTree::SetData(BMessage *data)
|
||||
{
|
||||
fData = *data;
|
||||
}
|
||||
|
||||
BMessenger* ClipboardTree::GetDataSource()
|
||||
{
|
||||
return &fDataSource;
|
||||
}
|
||||
|
||||
void ClipboardTree::SetDataSource(BMessenger *dataSource)
|
||||
{
|
||||
fDataSource = *dataSource;
|
||||
}
|
||||
|
||||
bool ClipboardTree::AddWatcher(BMessenger *watcher)
|
||||
{
|
||||
return fWatchingService.AddWatcher(*watcher);
|
||||
}
|
||||
|
||||
bool ClipboardTree::RemoveWatcher(BMessenger *watcher)
|
||||
{
|
||||
return fWatchingService.RemoveWatcher(*watcher,true);
|
||||
}
|
||||
|
||||
void ClipboardTree::NotifyWatchers()
|
||||
{
|
||||
BMessage message(B_CLIPBOARD_CHANGED);
|
||||
fWatchingService.NotifyWatchers(&message,NULL);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// ClipboardTree.h
|
||||
|
||||
#ifndef CLIPBOARD_TREE_H
|
||||
#define CLIPBOARD_TREE_H
|
||||
|
||||
#include <String.h>
|
||||
#include <Message.h>
|
||||
#include <Messenger.h>
|
||||
#include "WatchingService.h"
|
||||
|
||||
class ClipboardTree {
|
||||
public:
|
||||
ClipboardTree();
|
||||
~ClipboardTree();
|
||||
void AddNode(BString name);
|
||||
ClipboardTree* GetNode(BString name);
|
||||
uint32 GetCount();
|
||||
uint32 IncrementCount();
|
||||
BMessage *GetData();
|
||||
void SetData(BMessage *data);
|
||||
BMessenger *GetDataSource();
|
||||
void SetDataSource(BMessenger *dataSource);
|
||||
bool AddWatcher(BMessenger *watcher);
|
||||
bool RemoveWatcher(BMessenger *watcher);
|
||||
void NotifyWatchers();
|
||||
private:
|
||||
BString fName;
|
||||
BMessage fData;
|
||||
BMessenger fDataSource;
|
||||
ClipboardTree *fLeftChild;
|
||||
ClipboardTree *fRightChild;
|
||||
uint32 fCount;
|
||||
WatchingService fWatchingService;
|
||||
};
|
||||
|
||||
#endif // CLIPBOARD_TREE_H
|
||||
|
||||
@@ -7,6 +7,7 @@ UsePrivateHeaders storage ;
|
||||
Server obos_registrar :
|
||||
AppInfoList.cpp
|
||||
ClipboardHandler.cpp
|
||||
ClipboardTree.cpp
|
||||
Event.cpp
|
||||
EventMaskWatcher.cpp
|
||||
EventQueue.cpp
|
||||
|
||||
Reference in New Issue
Block a user