forked from tim-smart/node-gtk
/
ngtk_message_dialog.cc
79 lines (56 loc) · 2.18 KB
/
ngtk_message_dialog.cc
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "ngtk_message_dialog.h"
#include <assert.h>
#include <v8.h>
#include <gtk/gtk.h>
#include "ngtk.h"
#include "ngtk_window.h"
namespace ngtk {
using namespace v8;
Persistent<FunctionTemplate> MessageDialog::constructor_template;
// Public constructor
MessageDialog* MessageDialog::New (Window *parent, GtkDialogFlags flags,
GtkMessageType type, GtkButtonsType buttons, char *message) {
HandleScope scope;
Local<Value> argv[5];
argv[0] = *parent->handle_;
argv[1] = Number::New(flags);
argv[2] = Number::New(type);
argv[3] = Number::New(buttons);
argv[4] = String::New(message);
Local<Object> dialog = constructor_template->GetFunction()->NewInstance(5, argv);
return ObjectWrap::Unwrap<MessageDialog>(dialog);
}
// ECMAScript constructor.
Handle<Value> MessageDialog::New (const Arguments &args) {
HandleScope scope;
if (4 > args.Length()) {
return ThrowException(Exception::Error(
String::New("Expects arguments: window or null, dialog flags, message type, button flags[, message]")));
}
GtkWindow *parent;
if (Window::HasInstance(args[0])) {
parent = GTK_WINDOW(Window::Data(args[0]->ToObject()));
} else {
parent = NULL;
}
MessageDialog *dialog = new MessageDialog(parent,
(GtkDialogFlags) args[1]->Int32Value(), (GtkMessageType) args[2]->Int32Value(),
(GtkButtonsType) args[3]->Int32Value(), *String::Utf8Value(args[4]->ToString()));
dialog->Wrap(args.This());
return args.This();
}
MessageDialog::MessageDialog (GtkWindow *parent, GtkDialogFlags flags,
GtkMessageType type, GtkButtonsType buttons, char *message) {
widget_ = gtk_message_dialog_new(parent, flags, type, buttons, "%s", message);
}
// Export.
void MessageDialog::Initialize (Handle<Object> target) {
HandleScope scope;
Local<FunctionTemplate> t = FunctionTemplate::New(MessageDialog::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("MessageDialog"));
Widget::Initialize(constructor_template);
target->Set(String::NewSymbol("MessageDialog"), constructor_template->GetFunction());
}
} // namespace ngtk