Skip to content

Commit

Permalink
Add TextBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Oct 19, 2011
1 parent 6638653 commit e4a3b1d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/impl_glue_gtk.h
Expand Up @@ -29,6 +29,7 @@ inline v8::Handle<v8::Object> glue (void *widget) {
}

v8::Handle<v8::Object> glue (void *widget);
v8::Handle<v8::Object> glue (GtkTextBuffer *widget);

// From c type to v8::Value
inline v8::Handle<v8::Value> glue (int i) {
Expand Down Expand Up @@ -62,7 +63,9 @@ inline v8::Handle<v8::Value> glue (double i) {

// Convert GValue to its raw state
template<class T>
T raw (const GValue* value);
T raw (const GValue* value) {
return static_cast<T> (g_value_get_pointer (value));
}

template<class T*>
inline T* raw (const GValue* value) {
Expand Down
2 changes: 2 additions & 0 deletions src/node_gui.cc
Expand Up @@ -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"
Expand Down Expand Up @@ -40,6 +41,7 @@ void Init (Handle<v8::Object> 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);
Expand Down
11 changes: 11 additions & 0 deletions src/node_gui.h
Expand Up @@ -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<v8::Object> glue (Gtk##Type *widget) {\
v8::HandleScope scope;\
\
v8::Local<v8::Value> external = v8::External::New (widget);\
v8::Handle<v8::Object> obj = Type::constructor_template->GetFunction ()->NewInstance (1, &external);\
\
return scope.Close (obj);\
}

namespace clip {
using namespace v8;

Expand Down
5 changes: 1 addition & 4 deletions src/node_gui_object.h
Expand Up @@ -212,10 +212,7 @@ DECLARE_NODE_OBJECT (Object);

ReturnType result = function (obj);

// TODO
// return glue (static_cast<ReturnType> (result));
// And then overload all `glue`s in individual Classes
return scope.Close (glue (result));
return scope.Close (glue (static_cast<ReturnType> (result)));
}

template<class ReturnType, class GtkType, ReturnType function (const GtkType*)>
Expand Down
17 changes: 17 additions & 0 deletions src/node_gui_text_buffer.cc
@@ -0,0 +1,17 @@
#include "node_gui_text_buffer.h"

namespace clip {
Persistent<FunctionTemplate> TextBuffer::constructor_template;
DEFINE_GLUE (TextBuffer);

void TextBuffer::Init (Handle<v8::Object> 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<const gchar*, gint, GtkTextBuffer, gtk_text_buffer_insert_at_cursor>));

END_CONSTRUCTOR ();
}
} /* clip */
12 changes: 12 additions & 0 deletions 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 */
7 changes: 3 additions & 4 deletions tests/download.js
Expand Up @@ -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 () {
Expand Down

0 comments on commit e4a3b1d

Please sign in to comment.