Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resize, enter, leave, close events #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions binding.gyp
Expand Up @@ -10,6 +10,9 @@

'src/QtGui/qapplication.cc',
'src/QtGui/qwidget.cc',
'src/QtGui/qevent.cc',
'src/QtGui/qcloseevent.cc',
'src/QtGui/qresizeevent.cc',
'src/QtGui/qmouseevent.cc',
'src/QtGui/qkeyevent.cc',
'src/QtGui/qpixmap.cc',
Expand Down
126 changes: 126 additions & 0 deletions src/QtGui/qcloseevent.cc
@@ -0,0 +1,126 @@
// Copyright (c) 2012, Artur Adib
// All rights reserved.
//
// Author(s): Artur Adib <aadib@mozilla.com>
//
// You may use this file under the terms of the New BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Artur Adib nor the
// names of contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#define BUILDING_NODE_EXTENSION
#include <node.h>
#include "qcloseevent.h"

using namespace v8;

Persistent<Function> QCloseEventWrap::constructor;

QCloseEventWrap::QCloseEventWrap() : q_(NULL) {
// Standalone constructor not implemented
// Use SetWrapped()
}

QCloseEventWrap::~QCloseEventWrap() {
delete q_;
}

void QCloseEventWrap::Initialize(Handle<Object> target) {
// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
tpl->SetClassName(String::NewSymbol("QCloseEvent"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);

tpl->PrototypeTemplate()->Set(String::NewSymbol("accept"),
FunctionTemplate::New(Accept)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("ignore"),
FunctionTemplate::New(Ignore)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("isAccepted"),
FunctionTemplate::New(IsAccepted)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("setAccepted"),
FunctionTemplate::New(SetAccepted)->GetFunction());

constructor = Persistent<Function>::New(tpl->GetFunction());
target->Set(String::NewSymbol("QCloseEvent"), constructor);
}

Handle<Value> QCloseEventWrap::New(const Arguments& args) {
HandleScope scope;

QCloseEventWrap* w = new QCloseEventWrap();
w->Wrap(args.This());

return args.This();
}

Handle<Value> QCloseEventWrap::NewInstance(QCloseEvent q) {
HandleScope scope;

Local<Object> instance = constructor->NewInstance(0, NULL);
QCloseEventWrap* w = node::ObjectWrap::Unwrap<QCloseEventWrap>(instance);
w->SetWrapped(q);

return scope.Close(instance);
}

Handle<Value> QCloseEventWrap::Accept(const Arguments& args) {
HandleScope scope;

QCloseEventWrap* w = node::ObjectWrap::Unwrap<QCloseEventWrap>(args.This());
QCloseEvent* q = w->GetWrapped();

q->accept();

return scope.Close(Undefined());
}

Handle<Value> QCloseEventWrap::Ignore(const Arguments& args) {
HandleScope scope;

QCloseEventWrap* w = node::ObjectWrap::Unwrap<QCloseEventWrap>(args.This());
QCloseEvent* q = w->GetWrapped();

q->ignore();

return scope.Close(Undefined());
}

Handle<Value> QCloseEventWrap::IsAccepted(const Arguments& args) {
HandleScope scope;

QCloseEventWrap* w = node::ObjectWrap::Unwrap<QCloseEventWrap>(args.This());
QCloseEvent* q = w->GetWrapped();

return scope.Close(Boolean::New(q->isAccepted()));
}

Handle<Value> QCloseEventWrap::SetAccepted(const Arguments& args) {
HandleScope scope;

QCloseEventWrap* w = node::ObjectWrap::Unwrap<QCloseEventWrap>(args.This());
QCloseEvent* q = w->GetWrapped();

q->setAccepted(args[0]->BooleanValue());

return scope.Close(Undefined());
}

63 changes: 63 additions & 0 deletions src/QtGui/qcloseevent.h
@@ -0,0 +1,63 @@
// Copyright (c) 2012, Artur Adib
// All rights reserved.
//
// Author(s): Artur Adib <aadib@mozilla.com>
//
// You may use this file under the terms of the New BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Artur Adib nor the
// names of contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef QCLOSEEVENTWRAP_H
#define QCLOSEEVENTWRAP_H

#define BUILDING_NODE_EXTENSION
#include <node.h>
#include <QCloseEvent>

class QCloseEventWrap : public node::ObjectWrap {
public:
static void Initialize(v8::Handle<v8::Object> target);
static v8::Handle<v8::Value> NewInstance(QCloseEvent q);
QCloseEvent* GetWrapped() const { return q_; };
void SetWrapped(QCloseEvent q) {
if (q_) delete q_;
q_ = new QCloseEvent(q);
};

private:
QCloseEventWrap();
~QCloseEventWrap();
static v8::Persistent<v8::Function> constructor;
static v8::Handle<v8::Value> New(const v8::Arguments& args);

// Wrapped methods
static v8::Handle<v8::Value> Accept(const v8::Arguments& args);
static v8::Handle<v8::Value> Ignore(const v8::Arguments& args);
static v8::Handle<v8::Value> IsAccepted(const v8::Arguments& args);
static v8::Handle<v8::Value> SetAccepted(const v8::Arguments& args);

// Wrapped object
QCloseEvent* q_;
};

#endif
126 changes: 126 additions & 0 deletions src/QtGui/qevent.cc
@@ -0,0 +1,126 @@
// Copyright (c) 2012, Artur Adib
// All rights reserved.
//
// Author(s): Artur Adib <aadib@mozilla.com>
//
// You may use this file under the terms of the New BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Artur Adib nor the
// names of contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#define BUILDING_NODE_EXTENSION
#include <node.h>
#include "qevent.h"

using namespace v8;

Persistent<Function> QEventWrap::constructor;

QEventWrap::QEventWrap() : q_(NULL) {
// Standalone constructor not implemented
// Use SetWrapped()
}

QEventWrap::~QEventWrap() {
delete q_;
}

void QEventWrap::Initialize(Handle<Object> target) {
// Prepare constructor template
Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
tpl->SetClassName(String::NewSymbol("QEvent"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);

tpl->PrototypeTemplate()->Set(String::NewSymbol("accept"),
FunctionTemplate::New(Accept)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("ignore"),
FunctionTemplate::New(Ignore)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("isAccepted"),
FunctionTemplate::New(IsAccepted)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("setAccepted"),
FunctionTemplate::New(SetAccepted)->GetFunction());

constructor = Persistent<Function>::New(tpl->GetFunction());
target->Set(String::NewSymbol("QEvent"), constructor);
}

Handle<Value> QEventWrap::New(const Arguments& args) {
HandleScope scope;

QEventWrap* w = new QEventWrap();
w->Wrap(args.This());

return args.This();
}

Handle<Value> QEventWrap::NewInstance(QEvent q) {
HandleScope scope;

Local<Object> instance = constructor->NewInstance(0, NULL);
QEventWrap* w = node::ObjectWrap::Unwrap<QEventWrap>(instance);
w->SetWrapped(q);

return scope.Close(instance);
}

Handle<Value> QEventWrap::Accept(const Arguments& args) {
HandleScope scope;

QEventWrap* w = node::ObjectWrap::Unwrap<QEventWrap>(args.This());
QEvent* q = w->GetWrapped();

q->accept();

return scope.Close(Undefined());
}

Handle<Value> QEventWrap::Ignore(const Arguments& args) {
HandleScope scope;

QEventWrap* w = node::ObjectWrap::Unwrap<QEventWrap>(args.This());
QEvent* q = w->GetWrapped();

q->ignore();

return scope.Close(Undefined());
}

Handle<Value> QEventWrap::IsAccepted(const Arguments& args) {
HandleScope scope;

QEventWrap* w = node::ObjectWrap::Unwrap<QEventWrap>(args.This());
QEvent* q = w->GetWrapped();

return scope.Close(Boolean::New(q->isAccepted()));
}

Handle<Value> QEventWrap::SetAccepted(const Arguments& args) {
HandleScope scope;

QEventWrap* w = node::ObjectWrap::Unwrap<QEventWrap>(args.This());
QEvent* q = w->GetWrapped();

q->setAccepted(args[0]->BooleanValue());

return scope.Close(Undefined());
}

63 changes: 63 additions & 0 deletions src/QtGui/qevent.h
@@ -0,0 +1,63 @@
// Copyright (c) 2012, Artur Adib
// All rights reserved.
//
// Author(s): Artur Adib <aadib@mozilla.com>
//
// You may use this file under the terms of the New BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Artur Adib nor the
// names of contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef QEVENTWRAP_H
#define QEVENTWRAP_H

#define BUILDING_NODE_EXTENSION
#include <node.h>
#include <QEvent>

class QEventWrap : public node::ObjectWrap {
public:
static void Initialize(v8::Handle<v8::Object> target);
static v8::Handle<v8::Value> NewInstance(QEvent q);
QEvent* GetWrapped() const { return q_; };
void SetWrapped(QEvent q) {
if (q_) delete q_;
q_ = new QEvent(q);
};

private:
QEventWrap();
~QEventWrap();
static v8::Persistent<v8::Function> constructor;
static v8::Handle<v8::Value> New(const v8::Arguments& args);

// Wrapped methods
static v8::Handle<v8::Value> Accept(const v8::Arguments& args);
static v8::Handle<v8::Value> Ignore(const v8::Arguments& args);
static v8::Handle<v8::Value> IsAccepted(const v8::Arguments& args);
static v8::Handle<v8::Value> SetAccepted(const v8::Arguments& args);

// Wrapped object
QEvent* q_;
};

#endif