Skip to content

Commit

Permalink
add text widget and rework a bit the testgtk example
Browse files Browse the repository at this point in the history
  • Loading branch information
NotFound committed May 24, 2011
1 parent 538d469 commit b49cfb2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
32 changes: 25 additions & 7 deletions examples/testgtk.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Window;
class Label;
class Button;
class Entry;
class Text;
class Image;
class Tree;
class TreeItem;
Expand All @@ -21,6 +22,12 @@ class TreeItem;

using namespace WinxedGtk;

function show(widget)
{
widget.show();
return widget;
}

class SimpleTestWindow : Window
{
var entry;
Expand All @@ -36,15 +43,13 @@ class SimpleTestWindow : Window
gtk_main_quit();
}
);
var vbox = new VBox(1, 4);
var label = new Label('This is a simple dialog');
var vbox = new VBox(0, 4);


var image = new Image('parrot_small.png');
image.show();

self.entry = new Entry();
label.show();
self.entry.show();
var hbox = new HBox(1, 4);

Expand All @@ -61,6 +66,11 @@ class SimpleTestWindow : Window
subitem.show();
item2.show();

var text = new Text();
text.insert('Some text...');
text.set_editable(true);
text.show();

var button = new Button('say hello');
button.signal_connect('clicked',
function ()
Expand All @@ -70,6 +80,9 @@ class SimpleTestWindow : Window
say('hello, ', t);
else
say('hello');
t = text.get_chars(0, -1);
if (t != null && t != '')
say("Here is some text:\n", t);
}
);
var buttonclose = new Button('close');
Expand All @@ -81,14 +94,19 @@ class SimpleTestWindow : Window
);
button.show();
buttonclose.show();
hbox.add(button);
hbox.add(buttonclose);
hbox.pack_start(button, 0, 0, 0);
hbox.pack_start(buttonclose, 0, 0, 0);

vbox.add(show(new Label('This is a simple Window example')));
vbox.add(image);
vbox.add(label);
vbox.add(show(new Label('A Tree widget')));
vbox.add(tree);
vbox.add(show(new Label('A Entry widget')));
vbox.add(self.entry);
vbox.add(hbox);
vbox.add(show(new Label('A Text widget')));
vbox.add(text);

vbox.pack_start(hbox, 0, 0, 0);

self.add(vbox);
hbox.show();
Expand Down
40 changes: 37 additions & 3 deletions src/WinxedGtk.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,20 @@ class Label : Widget
}
}

class Entry : Widget
class Editable : Widget {
function get_chars(int start_pos, int end_pos)
{
var func = dlfunc(getlib(), "gtk_editable_get_chars", "ppii");
var p = func(self.gtkw, start_pos, end_pos);
string r;
if (p != null)
r = string_from_nci(p);
//TODO: free the GtkEditable allocated string
return r;
}
}

class Entry : Editable
{
function Entry()
{
Expand All @@ -177,6 +190,27 @@ class Entry : Widget
}
}

class Text : Editable
{
function Text()
{
var func = dlfunc(getlib(), "gtk_text_new", "ppp");
self.__gtkset(func(null, null));
}
function set_editable(int editable)
{
var func = dlfunc(getlib(), "gtk_text_set_editable", "vpi");
func(self.gtkw, editable);
}
function insert(string text)
{
var func = dlfunc(getlib(), "gtk_text_insert", "vpppppi");
var p = str_to_cstring(text);
func(self.gtkw, null, null, null, p, -1);
str_free_cstring(p);
}
}

class Container : Widget
{
function set_border_width(int width)
Expand Down Expand Up @@ -232,12 +266,12 @@ class ScrolledWindow : Bin
function add_with_viewport(child)
{
var func = dlfunc(getlib(), "gtk_scrolled_window_add_with_viewport", "vpp");
func(self.gtkw, child.gtkw);
func(self.gtkw, child.gtkw);
}
function set_policy(int hpolicy, int vpolicy)
{
var func = dlfunc(getlib(), "gtk_scrolled_window_set_policy", "vpii");
func(self.gtkw, hpolicy, vpolicy);
func(self.gtkw, hpolicy, vpolicy);
}
}

Expand Down

0 comments on commit b49cfb2

Please sign in to comment.