diff --git a/src/impl_glue_gtk.h b/src/impl_glue_gtk.h index e50b621..4d97ed2 100644 --- a/src/impl_glue_gtk.h +++ b/src/impl_glue_gtk.h @@ -29,6 +29,7 @@ inline v8::Handle glue (void *widget) { } v8::Handle glue (void *widget); +v8::Handle glue (GtkTextBuffer *widget); // From c type to v8::Value inline v8::Handle glue (int i) { @@ -62,7 +63,9 @@ inline v8::Handle glue (double i) { // Convert GValue to its raw state template -T raw (const GValue* value); +T raw (const GValue* value) { + return static_cast (g_value_get_pointer (value)); +} template inline T* raw (const GValue* value) { diff --git a/src/node_gui.cc b/src/node_gui.cc index 218484c..538ebda 100644 --- a/src/node_gui.cc +++ b/src/node_gui.cc @@ -4,6 +4,7 @@ #include "node_gui_clipboard.h" #include "node_gui_object.h" #include "node_gui_text_iter.h" +#include "node_gui_text_buffer.h" #include "node_gui_list_store.h" #include "node_gui_widget.h" #include "node_gui_entry.h" @@ -40,6 +41,7 @@ void Init (Handle target) { clip::Type::Init (target); clip::Object::Init (target); clip::TextIter::Init (target); + clip::TextBuffer::Init (target); clip::ListStore::Init (target); clip::Clipboard::Init (target); clip::Widget::Init (target); diff --git a/src/node_gui.h b/src/node_gui.h index 14aa539..990daa8 100644 --- a/src/node_gui.h +++ b/src/node_gui.h @@ -85,6 +85,17 @@ #define END_CONSTRUCTOR() \ target->Set (symbol, t->GetFunction ()) +// Generate javascript type from GTK+ object's type +#define DEFINE_GLUE(Type) \ + v8::Handle glue (Gtk##Type *widget) {\ + v8::HandleScope scope;\ +\ + v8::Local external = v8::External::New (widget);\ + v8::Handle obj = Type::constructor_template->GetFunction ()->NewInstance (1, &external);\ +\ + return scope.Close (obj);\ + } + namespace clip { using namespace v8; diff --git a/src/node_gui_object.h b/src/node_gui_object.h index a8227cd..ea1e440 100644 --- a/src/node_gui_object.h +++ b/src/node_gui_object.h @@ -212,10 +212,7 @@ DECLARE_NODE_OBJECT (Object); ReturnType result = function (obj); - // TODO - // return glue (static_cast (result)); - // And then overload all `glue`s in individual Classes - return scope.Close (glue (result)); + return scope.Close (glue (static_cast (result))); } template diff --git a/src/node_gui_text_buffer.cc b/src/node_gui_text_buffer.cc new file mode 100644 index 0000000..71ba0d6 --- /dev/null +++ b/src/node_gui_text_buffer.cc @@ -0,0 +1,17 @@ +#include "node_gui_text_buffer.h" + +namespace clip { +Persistent TextBuffer::constructor_template; +DEFINE_GLUE (TextBuffer); + +void TextBuffer::Init (Handle target) { + CREATE_CUSTOM_NODE_CONSTRUCTOR ("TextBuffer", TextBuffer, Object, text_buffer); + + SETTER_METHOD (TextBuffer, "getStartIter", gtk_text_buffer_get_start_iter, GtkTextIter *); + SETTER_METHOD (TextBuffer, "getEndIter", gtk_text_buffer_get_end_iter, GtkTextIter *); + + NODE_SET_PROTOTYPE_METHOD (constructor_template, "insertAtCursor", (SetterMethod)); + + END_CONSTRUCTOR (); +} +} /* clip */ diff --git a/src/node_gui_text_buffer.h b/src/node_gui_text_buffer.h new file mode 100644 index 0000000..adf5494 --- /dev/null +++ b/src/node_gui_text_buffer.h @@ -0,0 +1,12 @@ +#ifndef NODE_GUI_TEXT_BUFFER_H +#define NODE_GUI_TEXT_BUFFER_H + +#include "node_gui_object.h" + +namespace clip { +class TextBuffer: public Object { +DECLARE_NODE_OBJECT (TextBuffer); +}; +} /* clip */ + +#endif /* end of NODE_GUI_TEXT_BUFFER_H */ diff --git a/tests/download.js b/tests/download.js index 0678866..acb1e04 100644 --- a/tests/download.js +++ b/tests/download.js @@ -22,10 +22,9 @@ new gui.Builder (__dirname + '/download.glade', function (builder) { var data = ""; var req = http.request (options, function (res) { res.on ('data', function (chunk) { - // TODO - // rewrite after TextBuffer is done - data += String (chunk); - text.getBuffer().setProperty ('text', data); + var buffer = text.getBuffer (); + var str = String (chunk); + buffer.insertAtCursor (str, str.length); }); res.on ('end', function () {