Beispiel #1
0
void
ServerProxy::setClipboard()
{
	// parse
	static String dataCached;
	ClipboardID id;
	UInt32 seq;
	
	int r = ClipboardChunk::assemble(m_stream, dataCached, id, seq);

	if (r == kStart) {
		size_t size = ClipboardChunk::getExpectedSize();
		LOG((CLOG_DEBUG "receiving clipboard %d size=%d", id, size));
	}
	else if (r == kFinish) {
		LOG((CLOG_DEBUG "received clipboard %d size=%d", id, dataCached.size()));
		
		// forward
		Clipboard clipboard;
		clipboard.unmarshall(dataCached, 0);
		m_client->setClipboard(id, &clipboard);

		LOG((CLOG_INFO "clipboard was updated"));
	}
}
Beispiel #2
0
void DeleteFunc::execute() {
  Viewer* viewer = _ed->GetViewer();

  int nf=nargsfixed();
  if (nf==0) {
    reset_stack();
    return;
  }

  Clipboard* delcb = new Clipboard();

  for (int i=0; i<nf; i++) {
    ComValue& obj = stack_arg(i);
    if (obj.object_compview()) {
      ComponentView* comview = (ComponentView*)obj.obj_val();
      OverlayComp* comp = (OverlayComp*)comview->GetSubject();
      if (comp) delcb->Append(comp);
    }
  }

  DeleteCmd* delcmd = new DeleteCmd(GetEditor(), delcb);
  delcmd->Execute();
  unidraw->Update();
  delete delcmd;

  reset_stack();
}
Beispiel #3
0
// TODO: there's some integer -> char encoding going on here. i find it
// hard to believe that the clipboard is the only thing doing this. maybe
// we should refactor this stuff out of the clipboard.
TEST(ClipboardTests, marshall_withTextSize285_sizeCharsValid)
{
    // 285 chars
    String data;
    data.append("Synergy is Free and Open Source Software that lets you ");
    data.append("easily share your mouse and keyboard between multiple ");
    data.append("computers, where each computer has it's own display. No ");
    data.append("special hardware is required, all you need is a local area ");
    data.append("network. Synergy is supported on Windows, Mac OS X and Linux.");

    Clipboard clipboard;
    clipboard.open(0);
    clipboard.add(IClipboard::kText, data);
    clipboard.close();

    String actual = clipboard.marshall();

    // 4 asserts here, but that's ok because we're really just asserting 1
    // thing. the 32-bit size value is split into 4 chars. if the size is 285
    // (29 more than the 8-bit max size), the last char "rolls over" to 29
    // (this is caused by a bit-wise & on 0xff and 8-bit truncation). each
    // char before the last stores a bit-shifted version of the number, each
    // 1 more power than the last, which is done by bit-shifting [0] by 24,
    // [1] by 16, [2] by 8 ([3] is not bit-shifted).
    EXPECT_EQ(0, actual[8]); // 285 >> 24 = 285 / (256^3) = 0
    EXPECT_EQ(0, actual[9]); // 285 >> 16 = 285 / (256^2) = 0
    EXPECT_EQ(1, actual[10]); // 285 >> 8 = 285 / (256^1) = 1(.11328125)
    EXPECT_EQ(29, actual[11]); // 285 - 256 = 29
}
Beispiel #4
0
int main(int argc, char** argv) {
	string options = OPTIONS;
	string base = DEFAULT_BASE;
	string stream = DEFAULT_STREAM;
	
	int opt = getopt(argc,argv,options.c_str());
	while (opt != -1) {
		switch (opt) {
		case ARG_BASE:
			base = optarg;
			break;
		case ARG_STREAM:
			stream = optarg;
			break;
		}
		opt = getopt(argc,argv,options.c_str());
	}
	
	string url = base + stream;
	
	Clipboard cboard;
	cboard.copyTo(url.c_str(), url.length());
	
	Http http(url);
	http.put(&cin,&cout);
	
	return 0;
}
Beispiel #5
0
void
ServerProxy::setClipboard()
{
	// parse
	static String dataCached;
	ClipboardID id;
	UInt32 seq;
	
	int r = ClipboardChunk::assemble(m_stream, dataCached, id, seq);

	if (r == kFinish) {
		LOG((CLOG_DEBUG "received clipboard %d size=%d", id, dataCached.size()));
		
		// forward
		Clipboard clipboard;
		clipboard.unmarshall(dataCached, 0);
		m_client->setClipboard(id, &clipboard);

		LOG((CLOG_NOTIFY "clipboard transmission complete"));
	}
	else if (r == kStart) {
		size_t size = ClipboardChunk::getExpectedSize();
		LOG((CLOG_NOTIFY "clipboard transmission started: start receiving %u bytes of clipboard data", size));
	}
}
Beispiel #6
0
JSValuePtr JSClipboard::setDragImage(ExecState* exec, const ArgList& args)
{
    Clipboard* clipboard = impl();

    if (!clipboard->isForDragging())
        return jsUndefined();

    // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. 
    if (args.size() != 3)
        return throwError(exec, SyntaxError, "setDragImage: Invalid number of arguments");

    int x = args.at(exec, 1)->toInt32(exec);
    int y = args.at(exec, 2)->toInt32(exec);

    // See if they passed us a node
    Node* node = toNode(args.at(exec, 0));
    if (!node)
        return throwError(exec, TypeError);

    // FIXME: This should probably be a TypeError. 
    if (!node->isElementNode())
        return throwError(exec, SyntaxError, "setDragImageFromElement: Invalid first argument");

    if (static_cast<Element*>(node)->hasLocalName(imgTag) && !node->inDocument())
        clipboard->setDragImage(static_cast<HTMLImageElement*>(node)->cachedImage(), IntPoint(x, y));
    else
        clipboard->setDragImageElement(node, IntPoint(x, y));

    return jsUndefined();
}
static void effectAllowedAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
{
    Clipboard* imp = V8Clipboard::toNative(info.Holder());
    V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, v, value);
    imp->setEffectAllowed(v);
    return;
}
void V8Clipboard::setDragImageMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    Clipboard* clipboard = V8Clipboard::toNative(args.Holder());

    if (!clipboard->isForDragAndDrop())
        return;

    if (args.Length() != 3) {
        throwError(v8SyntaxError, "setDragImage: Invalid number of arguments", args.GetIsolate());
        return;
    }

    int x = toInt32(args[1]);
    int y = toInt32(args[2]);

    Node* node = 0;
    if (V8Node::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())))
        node = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0]));

    if (!node || !node->isElementNode()) {
        throwTypeError("setDragImageFromElement: Invalid first argument", args.GetIsolate());
        return;
    }

    if (toElement(node)->hasTagName(HTMLNames::imgTag) && !node->inDocument())
        clipboard->setDragImage(toHTMLImageElement(node)->cachedImage(), IntPoint(x, y));
    else
        clipboard->setDragImageElement(node, IntPoint(x, y));
}
Beispiel #9
0
TEST(ClipboardTests, unmarshall_withTextSize285_getTextIsValid)
{
    Clipboard clipboard;

    // 285 chars
    String text;
    text.append("Synergy is Free and Open Source Software that lets you ");
    text.append("easily share your mouse and keyboard between multiple ");
    text.append("computers, where each computer has it's own display. No ");
    text.append("special hardware is required, all you need is a local area ");
    text.append("network. Synergy is supported on Windows, Mac OS X and Linux.");

    String data;
    data += (char)0;
    data += (char)0;
    data += (char)0;
    data += (char)1; // 1 format added
    data += (char)0;
    data += (char)0;
    data += (char)0;
    data += (char)IClipboard::kText;
    data += (char)0; // 285 >> 24 = 285 / (256^3) = 0
    data += (char)0; // 285 >> 16 = 285 / (256^2) = 0
    data += (char)1; // 285 >> 8 = 285 / (256^1) = 1(.11328125)
    data += (char)29; // 285 - 256 = 29
    data += text;

    clipboard.unmarshall(data, 0);

    clipboard.open(0);
    String actual = clipboard.get(IClipboard::kText);
    EXPECT_EQ(text, actual);
}
JSValue JSClipboard::setDragImage(ExecState* exec)
{
    Clipboard* clipboard = impl();

    if (!clipboard->isForDragAndDrop())
        return jsUndefined();

    // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. 
    if (exec->argumentCount() != 3)
        return throwError(exec, createSyntaxError(exec, "setDragImage: Invalid number of arguments"));

    int x = exec->argument(1).toInt32(exec);
    int y = exec->argument(2).toInt32(exec);

    // See if they passed us a node
    Node* node = toNode(exec->argument(0));
    if (!node)
        return throwTypeError(exec);

    // FIXME: This should probably be a TypeError. 
    if (!node->isElementNode())
        return throwError(exec, createSyntaxError(exec, "setDragImageFromElement: Invalid first argument"));

    if (static_cast<Element*>(node)->hasLocalName(imgTag) && !node->inDocument())
        clipboard->setDragImage(static_cast<HTMLImageElement*>(node)->cachedImage(), IntPoint(x, y));
    else
        clipboard->setDragImageElement(node, IntPoint(x, y));

    return jsUndefined();
}
v8::Handle<v8::Value> V8Clipboard::setDragImageCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.Clipboard.setDragImage()");
    Clipboard* clipboard = V8Clipboard::toNative(args.Holder());

    if (!clipboard->isForDragging())
        return v8::Undefined();

    if (args.Length() != 3)
        return throwError("setDragImage: Invalid number of arguments", V8Proxy::SyntaxError);

    int x = toInt32(args[1]);
    int y = toInt32(args[2]);

    Node* node = 0;
    if (V8Node::HasInstance(args[0]))
        node = V8Node::toNative(v8::Handle<v8::Object>::Cast(args[0]));

    if (!node || !node->isElementNode())
        return throwError("setDragImageFromElement: Invalid first argument");

    if (static_cast<Element*>(node)->hasLocalName(HTMLNames::imgTag) && !node->inDocument())
        clipboard->setDragImage(static_cast<HTMLImageElement*>(node)->cachedImage(), IntPoint(x, y));
    else
        clipboard->setDragImageElement(node, IntPoint(x, y));

    return v8::Undefined();
}
Beispiel #12
0
TEST(ClipboardTests, unmarshall_withTextAndHtml_getHtmlIsValid)
{
    Clipboard clipboard;
    String data;
    data += (char)0;
    data += (char)0;
    data += (char)0;
    data += (char)2; // 2 formats added
    data += (char)0;
    data += (char)0;
    data += (char)0;
    data += (char)IClipboard::kText;
    data += (char)0;
    data += (char)0;
    data += (char)0;
    data += (char)14;
    data += "synergy rocks!";
    data += (char)0;
    data += (char)0;
    data += (char)0;
    data += (char)IClipboard::kHTML;
    data += (char)0;
    data += (char)0;
    data += (char)0;
    data += (char)10;
    data += "html sucks";

    clipboard.unmarshall(data, 0);

    clipboard.open(0);
    String actual = clipboard.get(IClipboard::kHTML);
    EXPECT_EQ("html sucks", actual);
}
Beispiel #13
0
/* virtual */ void ComEditor::ExecuteCmd(Command* cmd) {
  if(!whiteboard()) 

    /* normal Unidraw command execution */
    OverlayEditor::ExecuteCmd(cmd);

  else {

    /* indirect command execution, all by script */
    std::ostrstream sbuf;
    boolean oldflag = OverlayScript::ptlist_parens();
    OverlayScript::ptlist_parens(false);
    switch (cmd->GetClassId()) {
    case PASTE_CMD:
      {
      boolean scripted = false;
      Clipboard* cb = cmd->GetClipboard();
      if (cb) {
	Iterator it;
	for (cb->First(it); !cb->Done(it); cb->Next(it)) {
	  OverlayComp* comp = (OverlayComp*)cb->GetComp(it);
	  if (comp) {
	    Creator* creator = unidraw->GetCatalog()->GetCreator();
	    OverlayScript* scripter = (OverlayScript*)
	      creator->Create(Combine(comp->GetClassId(), SCRIPT_VIEW));
	    if (scripter) {
	      scripter->SetSubject(comp);
	      if (scripted) 
		sbuf << ';';
	      else 
		scripted = true;
	      boolean status = scripter->Definition(sbuf);
	      delete scripter;
	    }
	  }
	}
      }
      if (!scripted)
	sbuf << "print(\"Failed attempt to generate script for a PASTE_CMD\\n\" :err)";
      sbuf.put('\0');
      cout << sbuf.str() << "\n";
      cout.flush();
      GetComTerp()->run(sbuf.str());
      delete cmd;
      }
      break;
    default:
      sbuf << "print(\"Attempt to convert unknown command (id == %d) to interpretable script\\n\" " << cmd->GetClassId() << " :err)";
      cmd->Execute();
      if (cmd->Reversible()) {
	cmd->Log();
      } else {
	delete cmd;
      }
      break;
    }
    OverlayScript::ptlist_parens(oldflag);
  }
}
static void effectAllowedAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
{
    INC_STATS("DOM.Clipboard.effectAllowed._set");
    Clipboard* imp = V8Clipboard::toNative(info.Holder());
    V8Parameter<> v = value;
    imp->setEffectAllowed(v);
    return;
}
Beispiel #15
0
JSValue jsClipboardEffectAllowed(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSClipboard* castedThis = static_cast<JSClipboard*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    Clipboard* imp = static_cast<Clipboard*>(castedThis->impl());
    JSValue result = jsStringOrUndefined(exec, imp->effectAllowed());
    return result;
}
Beispiel #16
0
TEST(ClipboardTests, open_timeIsOne_returnsTrue)
{
    Clipboard clipboard;

    bool actual = clipboard.open(1);

    EXPECT_EQ(true, actual);
}
static v8::Handle<v8::Value> getDataCallback(const v8::Arguments& args)
{
    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    Clipboard* imp = V8Clipboard::toNative(args.Holder());
    V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, type, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
    return v8String(imp->getData(type), args.GetIsolate());
}
Beispiel #18
0
JSValue jsClipboardItems(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSClipboard* castedThis = static_cast<JSClipboard*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    Clipboard* imp = static_cast<Clipboard*>(castedThis->impl());
    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->items()));
    return result;
}
Beispiel #19
0
TEST(ClipboardTests, has_withNoFormats_returnsFalse)
{
    Clipboard clipboard;
    clipboard.open(0);

    bool actual = clipboard.has(IClipboard::kText);

    EXPECT_FALSE(actual);
}
Beispiel #20
0
TEST(ClipboardTests, getTime_openWithNoEmpty_returnsZero)
{
    Clipboard clipboard;
    clipboard.open(1);

    Clipboard::Time actual = clipboard.getTime();

    EXPECT_EQ(0, actual);
}
Beispiel #21
0
TEST(ClipboardTests, close_isOpen_noErrors)
{
    Clipboard clipboard;
    clipboard.open(0);

    clipboard.close();

    // can't assert anything
}
Beispiel #22
0
Clipboard* Clipboard::DeepCopy () {
    Clipboard* cbnew = new Clipboard;
    Iterator i;

    for (First(i); !Done(i); Next(i)) {
        cbnew->Append((GraphicComp*) GetComp(i)->Copy());
    }
    return cbnew;
}
Beispiel #23
0
TEST(ClipboardTests, empty_openCalled_returnsTrue)
{
    Clipboard clipboard;
    clipboard.open(0);

    bool actual = clipboard.empty();

    EXPECT_EQ(true, actual);
}
Beispiel #24
0
Clipboard* Clipboard::Copy () {
    Clipboard* cbnew = new Clipboard;
    Iterator i;

    for (First(i); !Done(i); Next(i)) {
        cbnew->Append(GetComp(i));
    }
    return cbnew;
}
Beispiel #25
0
TEST(ClipboardTests, get_withNoFormats_returnsEmpty)
{
    Clipboard clipboard;
    clipboard.open(0);

    String actual = clipboard.get(IClipboard::kText);

    EXPECT_EQ("", actual);
}
Beispiel #26
0
TEST(ClipboardTests, add_newValue_valueWasStored)
{
    Clipboard clipboard;
    clipboard.open(0);

    clipboard.add(IClipboard::kText, "synergy rocks!");

    String actual = clipboard.get(IClipboard::kText);
    EXPECT_EQ("synergy rocks!", actual);
}
Beispiel #27
0
TEST(ClipboardTests, marshall_addNotCalled_firstCharIsZero)
{
    Clipboard clipboard;

    String actual = clipboard.marshall();

    // seems to return "\0\0\0\0" but EXPECT_EQ can't assert this,
    // so instead, just assert that first char is '\0'.
    EXPECT_EQ(0, (int)actual[0]);
}
static v8::Handle<v8::Value> setDataCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.Clipboard.setData");
    if (args.Length() < 2)
        return v8::Handle<v8::Value>();
    Clipboard* imp = V8Clipboard::toNative(args.Holder());
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, type, args[0]);
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, data, args[1]);
    return v8Boolean(imp->setData(type, data));
}
JSValuePtr JSClipboard::setData(ExecState* exec, const ArgList& args)
{
    Clipboard* clipboard = impl();

    // FIXME: It does not match the rest of the JS bindings to throw on invalid number of arguments. 
    if (args.size() != 2)
        return throwError(exec, SyntaxError, "setData: Invalid number of arguments");

    return jsBoolean(clipboard->setData(args.at(exec, 0).toString(exec), args.at(exec, 1).toString(exec)));
}
Beispiel #30
0
void BackCmd::Unexecute () {
    GetEditor()->GetComponent()->Uninterpret(this);

    Clipboard* cb = GetClipboard();
    Iterator i;

    for (cb->Last(i); !cb->Done(i); cb->Prev(i)) {
        cb->GetComp(i)->Uninterpret(this);
    }
}