Kouhei Sutou
kous****@users*****
Fri Jan 5 22:35:06 JST 2007
Index: kazehakase/ext/ruby/Makefile.am diff -u kazehakase/ext/ruby/Makefile.am:1.12 kazehakase/ext/ruby/Makefile.am:1.13 --- kazehakase/ext/ruby/Makefile.am:1.12 Sun Dec 31 22:59:19 2006 +++ kazehakase/ext/ruby/Makefile.am Fri Jan 5 22:35:06 2007 @@ -3,66 +3,67 @@ extrubydir = $(extdir)/ruby extruby_LTLIBRARIES = libkzext.la -AM_CPPFLAGS = \ - -DLOCALEDIR=\""$(localedir)"\" \ - -DSYSCONFDIR=\""$(sysconfdir)"\" \ - -DDATADIR=\""$(datadir)"\" \ - -DEXTDIR=\""$(extdir)"\" \ - -DKZ_SYSCONFDIR=\""$(sysconfdir)/$(PACKAGE)"\" \ - -DKZ_DATADIR=\""$(datadir)/$(PACKAGE)"\" \ - -DKZ_BACKENDS=\""$(KZ_BACKENDS)"\" \ - -DKZ_RUBY_EXTDIR=\""$(extrubydir)"\" \ - -DGTK_DISABLE_DEPRECATED=1 \ - -DGDK_DISABLE_DEPRECATED=1 \ +AM_CPPFLAGS = \ + -DLOCALEDIR=\""$(localedir)"\" \ + -DSYSCONFDIR=\""$(sysconfdir)"\" \ + -DDATADIR=\""$(datadir)"\" \ + -DEXTDIR=\""$(extdir)"\" \ + -DKZ_SYSCONFDIR=\""$(sysconfdir)/$(PACKAGE)"\" \ + -DKZ_DATADIR=\""$(datadir)/$(PACKAGE)"\" \ + -DKZ_BACKENDS=\""$(KZ_BACKENDS)"\" \ + -DKZ_RUBY_EXTDIR=\""$(extrubydir)"\" \ + -DGTK_DISABLE_DEPRECATED=1 \ + -DGDK_DISABLE_DEPRECATED=1 \ -DG_DISABLE_DEPRECATED=1 -INCLUDES = \ - $(MOZILLA_COMPONENT_CFLAGS) \ - $(GTK_CFLAGS) \ - $(LIBGNUTLS_CFLAGS) \ - $(RUBY_CFLAGS) \ - -I$(top_builddir)/src \ - -I$(top_builddir)/src/actions \ - -I$(top_builddir)/src/bookmarks \ - -I$(top_builddir)/src/dialogs \ - -I$(top_builddir)/src/libegg/pixbufthumbnail \ - -I$(top_builddir)/src/net \ - -I$(top_builddir)/src/prefs_ui \ - -I$(top_builddir)/src/sidebar \ - -I$(top_builddir)/src/widget \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/src/actions \ - -I$(top_srcdir)/src/bookmarks \ - -I$(top_srcdir)/src/mozilla \ - -I$(top_srcdir)/src/libegg/pixbufthumbnail \ - -I$(top_srcdir)/src/libegg/regex \ - -I$(top_srcdir)/src/libegg/md5 \ - -I$(top_srcdir)/src/net \ - -I$(top_srcdir)/src/sidebar \ - -I$(top_srcdir)/src/utils \ +INCLUDES = \ + $(MOZILLA_COMPONENT_CFLAGS) \ + $(GTK_CFLAGS) \ + $(LIBGNUTLS_CFLAGS) \ + $(RUBY_CFLAGS) \ + -I$(top_builddir)/src \ + -I$(top_builddir)/src/actions \ + -I$(top_builddir)/src/bookmarks \ + -I$(top_builddir)/src/dialogs \ + -I$(top_builddir)/src/libegg/pixbufthumbnail \ + -I$(top_builddir)/src/net \ + -I$(top_builddir)/src/prefs_ui \ + -I$(top_builddir)/src/sidebar \ + -I$(top_builddir)/src/widget \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/actions \ + -I$(top_srcdir)/src/bookmarks \ + -I$(top_srcdir)/src/mozilla \ + -I$(top_srcdir)/src/libegg/pixbufthumbnail \ + -I$(top_srcdir)/src/libegg/regex \ + -I$(top_srcdir)/src/libegg/md5 \ + -I$(top_srcdir)/src/net \ + -I$(top_srcdir)/src/sidebar \ + -I$(top_srcdir)/src/utils \ -I$(top_srcdir)/src/widget -libkzext_la_SOURCES = \ - kz-rb-ext.c kz-rb-ext.h \ - kz-rb-app.c \ - kz-rb-window.c \ - kz-rb-statusbar.c \ - kz-rb-embed.c \ - kz-rb-embed-event.c \ - kz-rb-conf.c \ - kz-rb-downloader.c \ - kz-rb-downloader-group.c \ - kz-rb-bookmark.c \ +libkzext_la_SOURCES = \ + kz-rb-ext.c kz-rb-ext.h \ + kz-rb-app.c \ + kz-rb-window.c \ + kz-rb-notebook.c \ + kz-rb-statusbar.c \ + kz-rb-embed.c \ + kz-rb-embed-event.c \ + kz-rb-conf.c \ + kz-rb-downloader.c \ + kz-rb-downloader-group.c \ + kz-rb-bookmark.c \ kz-rb-sidebar.c -libkzext_la_LDFLAGS = \ - $(RUBY_LDFLAGS) \ +libkzext_la_LDFLAGS = \ + $(RUBY_LDFLAGS) \ $(RUBY_EXT_LDFLAGS) -libkzext_la_LIBADD = \ - $(INTLLIBS) \ - $(GTK_LIBS) \ - $(LIBGNUTLS_LIBS) \ - $(RUBY_LIBS) \ - $(MOZILLA_COMPONENT_LIBS) \ +libkzext_la_LIBADD = \ + $(INTLLIBS) \ + $(GTK_LIBS) \ + $(LIBGNUTLS_LIBS) \ + $(RUBY_LIBS) \ + $(MOZILLA_COMPONENT_LIBS) \ $(top_builddir)/src/libkazehakase.la Index: kazehakase/ext/ruby/kz-rb-app.c diff -u kazehakase/ext/ruby/kz-rb-app.c:1.1 kazehakase/ext/ruby/kz-rb-app.c:1.2 --- kazehakase/ext/ruby/kz-rb-app.c:1.1 Sun Dec 31 22:59:19 2006 +++ kazehakase/ext/ruby/kz-rb-app.c Fri Jan 5 22:35:06 2007 @@ -20,7 +20,22 @@ #include "kz-rb-ext.h" -#define _SELF(obj) (KZ_APP(RVAL2GOBJ(obj))) +#define _SELF(obj) RVAL2KZAPP(obj) + +static KzApp *kz_rb_app = NULL; +static VALUE kz_rb_rb_app = Qnil; + +KzApp * +kz_rb_get_app(void) +{ + return kz_rb_app; +} + +static VALUE +rb_kz_app_s_get_instance(VALUE self) +{ + return kz_rb_rb_app; +} static VALUE rb_kz_app_get_window_list(VALUE self) @@ -31,12 +46,17 @@ } void -Init_kz_rb_app(VALUE mKz) +Init_kz_rb_app(VALUE mKz, KzApp *app) { VALUE cKzApp; cKzApp = G_DEF_CLASS(KZ_TYPE_APP, "App", mKz); + kz_rb_app = app; + kz_rb_rb_app = GOBJ2RVAL(kz_rb_app); + rb_ivar_set(cKzApp, rb_intern("instance"), kz_rb_rb_app); + rb_define_singleton_method(cKzApp, "instance", rb_kz_app_s_get_instance, 0); + rb_define_method(cKzApp, "window_list", rb_kz_app_get_window_list, 0); G_DEF_SETTERS(cKzApp); Index: kazehakase/ext/ruby/kz-rb-embed.c diff -u kazehakase/ext/ruby/kz-rb-embed.c:1.14 kazehakase/ext/ruby/kz-rb-embed.c:1.15 --- kazehakase/ext/ruby/kz-rb-embed.c:1.14 Fri Aug 25 13:05:20 2006 +++ kazehakase/ext/ruby/kz-rb-embed.c Fri Jan 5 22:35:06 2007 @@ -33,7 +33,8 @@ static VALUE rb_kz_embed_get_window(VALUE self) { - return GOBJ2RVAL(kz_window_get_from_tab(RVAL2GOBJ(self))); + return GOBJ2RVAL(kz_app_get_window_from_tab(KZ_RB_GET_APP, + RVAL2GOBJ(self))); } static VALUE Index: kazehakase/ext/ruby/kz-rb-ext.c diff -u kazehakase/ext/ruby/kz-rb-ext.c:1.21 kazehakase/ext/ruby/kz-rb-ext.c:1.22 --- kazehakase/ext/ruby/kz-rb-ext.c:1.21 Sun Dec 31 22:59:19 2006 +++ kazehakase/ext/ruby/kz-rb-ext.c Fri Jan 5 22:35:06 2007 @@ -152,8 +152,9 @@ rb_funcall(Qnil, rb_intern("require"), 1, rb_str_new2(INIT_PRE_RB)); if (RTEST(rb_const_get(mKz, rb_intern("ENABLE")))) { - Init_kz_rb_app(mKz); + Init_kz_rb_app(mKz, app); Init_kz_rb_window(mKz); + Init_kz_rb_notebook(mKz); Init_kz_rb_statusbar(mKz); Init_kz_rb_embed(mKz); Init_kz_rb_embed_event(mKz); @@ -163,8 +164,6 @@ Init_kz_rb_bookmark(mKz); Init_kz_rb_sidebar(mKz); - /* FIXME */ - rb_define_const(mKz, "APP", GOBJ2RVAL(app)); rb_funcall(Qnil, rb_intern("require"), 1, rb_str_new2(INIT_RB)); } } Index: kazehakase/ext/ruby/kz-rb-ext.h diff -u kazehakase/ext/ruby/kz-rb-ext.h:1.13 kazehakase/ext/ruby/kz-rb-ext.h:1.14 --- kazehakase/ext/ruby/kz-rb-ext.h:1.13 Sun Dec 31 22:59:19 2006 +++ kazehakase/ext/ruby/kz-rb-ext.h Fri Jan 5 22:35:06 2007 @@ -12,6 +12,7 @@ #include "kz-app.h" #include "kz-window.h" +#include "kz-notebook.h" #include "kz-statusbar.h" #include "kz-downloader.h" #include "kz-downloader-group.h" @@ -23,7 +24,13 @@ #define EVENTMOUSE2RVAL(obj) \ (BOXED2RVAL(obj, KZ_TYPE_EMBED_EVENT_MOUSE)) +#define RVAL2GTKWIDGET(obj) (GTK_WIDGET(RVAL2GOBJ(obj))) + +#define RVAL2KZAPP(obj) (KZ_APP(RVAL2GOBJ(obj))) #define RVAL2KZWIN(obj) (KZ_WINDOW(RVAL2GOBJ(obj))) +#define RVAL2KZNB(obj) (KZ_NOTEBOOK(RVAL2GOBJ(obj))) +#define RVAL2KZEMB(obj) (KZ_EMBED(RVAL2GOBJ(obj))) +#define RVAL2KZTL(obj) (KZ_TAB_LABEL(RVAL2GOBJ(obj))) #ifndef G_CHILD_ADD #define G_CHILD_ADD(self, child) /* hide when old Ruby-GNOME2 */ @@ -32,8 +39,13 @@ # define RVAL2CSTR2(v) (NIL_P(v) ? NULL : StringValuePtr(v)) #endif -extern void Init_kz_rb_app(VALUE mKz); +#define KZ_RB_GET_APP (kz_rb_get_app()) + +extern KzApp *kz_rb_get_app(void); + +extern void Init_kz_rb_app(VALUE mKz, KzApp *app); extern void Init_kz_rb_window(VALUE mKz); +extern void Init_kz_rb_notebook(VALUE mKz); extern void Init_kz_rb_statusbar(VALUE mKz); extern void Init_kz_rb_embed(VALUE mKz); extern void Init_kz_rb_embed_event(VALUE mKz); Index: kazehakase/ext/ruby/kz-rb-notebook.c diff -u /dev/null kazehakase/ext/ruby/kz-rb-notebook.c:1.1 --- /dev/null Fri Jan 5 22:35:06 2007 +++ kazehakase/ext/ruby/kz-rb-notebook.c Fri Jan 5 22:35:06 2007 @@ -0,0 +1,143 @@ +/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */ + +/* + * Copyright (C) 2006 Kouhei Sutou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "kz-rb-ext.h" + +#define _SELF(obj) RVAL2KZNB(obj) +#define RVAL2GDKSD(obj) RVAL2GENUM(obj, GDK_TYPE_SCROLL_DIRECTION) + +static VALUE +rb_kz_notebook_new(VALUE self, VALUE kz) +{ + GtkWidget *notebook; + + notebook = kz_notebook_new(RVAL2KZWIN(kz)); + RBGTK_INITIALIZE(self, notebook); + return Qnil; +} + +static VALUE +rb_kz_notebook_open_new_tab(int argc, VALUE *argv, VALUE self) +{ + VALUE rb_embed, rb_label, pos; + KzNotebook *notebook; + KzEmbed *embed; + KzTabLabel *label; + KzTabLabel *sibling_label; + + rb_scan_args(argc, argv, "21", &rb_embed, &rb_label, &pos); + + notebook = _SELF(self); + embed = RVAL2KZEMB(rb_embed); + label = RVAL2KZTL(rb_label); + if (NIL_P(pos)) { + sibling_label = kz_notebook_open_new_tab(notebook, embed, label); + } else { + sibling_label = kz_notebook_open_new_tab_at_pos(notebook, embed, label, + NUM2INT(pos)); + } + + return GOBJ2RVAL(sibling_label); +} + +static VALUE +rb_kz_notebook_close_tab(VALUE self, VALUE widget) +{ + gboolean result; + result = kz_notebook_close_tab(_SELF(self), RVAL2GTKWIDGET(widget)); + return CBOOL2RVAL(result); +} + +static VALUE +rb_kz_notebook_close_all_tab(VALUE self) +{ + gboolean result; + result = kz_notebook_close_all_tab(_SELF(self)); + return CBOOL2RVAL(result); +} + +static VALUE +rb_kz_notebook_move_tab(VALUE self, VALUE dest_notebook, VALUE widget) +{ + gboolean result; + result = kz_notebook_move_tab(_SELF(self), + _SELF(dest_notebook), + RVAL2GTKWIDGET(widget)); + return CBOOL2RVAL(result); +} + +static VALUE +rb_kz_notebook_next_tab(VALUE self) +{ + kz_notebook_next_tab(_SELF(self)); + return Qnil; +} + +static VALUE +rb_kz_notebook_prev_tab(VALUE self) +{ + kz_notebook_prev_tab(_SELF(self)); + return Qnil; +} + +static VALUE +rb_kz_notebook_reorder_tab(VALUE self, VALUE rb_widget, VALUE pos) +{ + GtkWidget *widget; + widget = kz_notebook_reorder_tab(_SELF(self), + RVAL2GTKWIDGET(rb_widget), + NUM2INT(pos)); + return GOBJ2RVAL(widget); +} + +static VALUE +rb_kz_notebook_scroll_tab(VALUE self, VALUE direction) +{ + gboolean result; + result = kz_notebook_scroll_tab(_SELF(self), + RVAL2GDKSD(direction)); + return CBOOL2RVAL(result); +} + + +void +Init_kz_rb_notebook(VALUE mKz) +{ + VALUE cKzNotebook; + + cKzNotebook = G_DEF_CLASS(KZ_TYPE_NOTEBOOK, "Notebook", mKz); + + rb_define_method(cKzNotebook, "initialize", rb_kz_notebook_new, 1); + + rb_define_method(cKzNotebook, "open_new_tab", + rb_kz_notebook_open_new_tab, -1); + rb_define_method(cKzNotebook, "close_tab", rb_kz_notebook_close_tab, 1); + rb_define_method(cKzNotebook, "close_all_tab", + rb_kz_notebook_close_all_tab, 0); + rb_define_method(cKzNotebook, "move_tab", rb_kz_notebook_move_tab, 2); + rb_define_method(cKzNotebook, "next_tab", rb_kz_notebook_next_tab, 0); + rb_define_method(cKzNotebook, "prev_tab", rb_kz_notebook_prev_tab, 0); + rb_define_method(cKzNotebook, "reorder_tab", + rb_kz_notebook_reorder_tab, 2); + rb_define_method(cKzNotebook, "scroll_tab", + rb_kz_notebook_scroll_tab, 1); + + G_DEF_SETTERS(cKzNotebook); +} Index: kazehakase/ext/ruby/kz-rb-window.c diff -u kazehakase/ext/ruby/kz-rb-window.c:1.14 kazehakase/ext/ruby/kz-rb-window.c:1.15 --- kazehakase/ext/ruby/kz-rb-window.c:1.14 Sun Dec 31 22:59:19 2006 +++ kazehakase/ext/ruby/kz-rb-window.c Fri Jan 5 22:35:06 2007 @@ -21,7 +21,6 @@ #include "kz-rb-ext.h" #define _SELF(obj) RVAL2KZWIN(obj) -#define RVAL2GTKWIDGET(obj) (GTK_WIDGET(RVAL2GOBJ(obj))) #define RVAL2GTKACTION(obj) (GTK_ACTION(RVAL2GOBJ(obj))) #define RVAL2GNODE(obj) (GTK_GNODE(RVAL2GOBJ(obj))) #define RVAL2KZBOOKMARK(obj) (KZ_BOOKMARK(RVAL2GOBJ(obj))) @@ -62,14 +61,6 @@ } static VALUE -rb_kz_window_open_new_tab_at_tail(VALUE self, VALUE url) -{ - GtkWidget *widget; - widget = kz_window_open_new_tab_at_tail(_SELF(self), RVAL2CSTR(url)); - return GOBJ2RVAL(widget); -} - -static VALUE rb_kz_window_open_new_tab_with_parent(VALUE self, VALUE url, VALUE parent) { GtkWidget *widget; @@ -268,6 +259,13 @@ return statusbar; } +static VALUE +rb_kz_window_notebook(VALUE self) +{ + VALUE notebook = GOBJ2RVAL(_SELF(self)->notebook); + G_CHILD_ADD(self, notebook); + return notebook; +} static VALUE @@ -302,8 +300,6 @@ rb_define_method(cKzWindow, "open_new_tab", rb_kz_window_open_new_tab, 1); - rb_define_method(cKzWindow, "open_new_tab_at_tail", - rb_kz_window_open_new_tab_at_tail, 1); rb_define_method(cKzWindow, "open_new_tab_with_parent", rb_kz_window_open_new_tab_with_parent, 2); rb_define_method(cKzWindow, "close_tab", rb_kz_window_close_tab, 1); @@ -351,6 +347,7 @@ rb_define_method(cKzWindow, "menu_merge", rb_kz_window_menu_merge, 0); rb_define_method(cKzWindow, "sidebar", rb_kz_window_sidebar, 0); rb_define_method(cKzWindow, "statusbar", rb_kz_window_statusbar, 0); + rb_define_method(cKzWindow, "notebook", rb_kz_window_notebook, 0); rb_define_method(cKzWindow, "current_page", rb_kz_window_current_page, 0); rb_define_method(cKzWindow, "nth_page", rb_kz_window_nth_page, 1);