forked from nodegui/nodegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqwidget_wrap.cpp
More file actions
43 lines (37 loc) · 1.37 KB
/
qwidget_wrap.cpp
File metadata and controls
43 lines (37 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "qwidget_wrap.h"
#include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h"
#include "src/cpp/Extras/Utils/nutils.h"
Napi::FunctionReference QWidgetWrap::constructor;
Napi::Object QWidgetWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QWidget";
Napi::Function func = DefineClass(env, CLASSNAME, {
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QWidgetWrap)
});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
return exports;
}
NWidget* QWidgetWrap::getInternalInstance() {
return this->instance;
}
QWidgetWrap::QWidgetWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QWidgetWrap>(info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
if(info.Length() == 1) {
if(info[0].IsExternal()){
this->instance = info[0].As<Napi::External<NWidget>>().Data();
} else {
Napi::Object parentObject = info[0].As<Napi::Object>();
QWidgetWrap* parentWidgetWrap = Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
this->instance = new NWidget(parentWidgetWrap->getInternalInstance()); //this sets the parent to current widget
}
} else if (info.Length() == 0){
this->instance = new NWidget();
}else {
Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException();
}
}
QWidgetWrap::~QWidgetWrap() {
delete this->instance;
}