From: Yasushi Shoji <yashi / yashi.com>
Subject: [ruby-ext:00579] Re: Gtk: nil label for Notebook#append_page
Date: Sun, 28 Nov 1999 03:56:34 -0500

> Notebook#insert_page* は、どうしましょうか?
> argument達は、self, child, label, positionなんですよね‥。

とりあえず、nilは渡せるけど、省略はできない(つまり最初の patch)ままにし
ておきます。*_menuで labelまで省略すると errorがでるみたいなので 
{append,prepend}_pageでは最後の labelだけ、
{append,prepend}_page_menuでは、最後の menuだけを省略可能にしました。

{append,prepend}_page_menuで、labelに nilを渡すと runtime errorになるは
ずです。(get_widget()にそのまま渡すから)


Index: rbgtknotebook.c =================================================================== RCS file: /home/cvsroot/ruby/ext/gtk/src/rbgtknotebook.c,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 rbgtknotebook.c --- rbgtknotebook.c 1999/11/17 15:14:23 1.1.1.1 +++ rbgtknotebook.c 1999/11/28 10:45:23 @@ -12,44 +12,84 @@ } static VALUE -note_append_page(self, child, label) - VALUE self, child, label; +note_append_page(argc, argv, self) + int argc; + VALUE *argv; + VALUE self; { + VALUE child, label; + GtkWidget *glabel = NULL; + + rb_scan_args(argc, argv, "11", &child, &label); + + if (!NIL_P(label)) + glabel = get_widget(label); + gtk_notebook_append_page(GTK_NOTEBOOK(get_widget(self)), get_widget(child), - get_widget(label)); + glabel); return self; } static VALUE -note_append_page_menu(self, child, tab_label, menu_label) - VALUE self, child, tab_label, menu_label; +note_append_page_menu(argc, argv, self) + int argc; + VALUE *argv; + VALUE self; { + VALUE child, tab_label, menu_label; + GtkWidget *gmenu_label = NULL; + + rb_scan_args(argc, argv, "21", &child, &tab_label, &menu_label); + + if (!NIL_P(menu_label)) + gmenu_label = get_widget(menu_label); + gtk_notebook_append_page_menu(GTK_NOTEBOOK(get_widget(self)), get_widget(child), get_widget(tab_label), - get_widget(menu_label)); + gmenu_label); return self; } static VALUE -note_prepend_page(self, child, label) - VALUE self, child, label; +note_prepend_page(argc, argv, self) + int argc; + VALUE *argv; + VALUE self; { + VALUE child, label; + GtkWidget *glabel = NULL; + + rb_scan_args(argc, argv, "11", &child, &label); + + if (!NIL_P(label)) + glabel = get_widget(label); + gtk_notebook_prepend_page(GTK_NOTEBOOK(get_widget(self)), get_widget(child), - get_widget(label)); + glabel); return self; } static VALUE -note_prepend_page_menu(self, child, tab_label, menu_label) - VALUE self, child, tab_label, menu_label; +note_prepend_page_menu(argc, argv, self) + int argc; + VALUE *argv; + VALUE self; { + VALUE child, tab_label, menu_label; + GtkWidget *gmenu_label = NULL; + + rb_scan_args(argc, argv, "21", &child, &tab_label, &menu_label); + + if (!NIL_P(menu_label)) + gmenu_label = get_widget(menu_label); + gtk_notebook_prepend_page_menu(GTK_NOTEBOOK(get_widget(self)), get_widget(child), get_widget(tab_label), - get_widget(menu_label)); + gmenu_label); return self; } @@ -57,9 +97,14 @@ note_insert_page(self, child, label, pos) VALUE self, child, label, pos; { + GtkWidget *glabel = NULL; + + if (!NIL_P(label)) + glabel = get_widget(label); + gtk_notebook_insert_page(GTK_NOTEBOOK(get_widget(self)), get_widget(child), - get_widget(label), + glabel, NUM2INT(pos)); return self; } @@ -68,10 +113,15 @@ note_insert_page_menu(self, child, tab_label, menu_label, pos) VALUE self, child, tab_label, menu_label, pos; { + GtkWidget *gmenu_label = NULL; + + if (!NIL_P(menu_label)) + gmenu_label = get_widget(menu_label); + gtk_notebook_insert_page_menu(GTK_NOTEBOOK(get_widget(self)), get_widget(child), get_widget(tab_label), - get_widget(menu_label), + gmenu_label, NUM2INT(pos)); return self; } @@ -308,9 +358,14 @@ note_set_menu_label(self, child, label) VALUE self, child, label; { + GtkWidget *glabel = NULL; + + if (!NIL_P(label)) + glabel = get_widget(label); + gtk_notebook_set_menu_label(GTK_NOTEBOOK(get_widget(self)), get_widget(child), - get_widget(label)); + glabel); return self; } @@ -337,9 +392,14 @@ note_set_tab_label(self, child, label) VALUE self, child, label; { + GtkWidget *glabel; + + if (NIL_P(label)) + glabel = get_widget(label); + gtk_notebook_set_tab_label(GTK_NOTEBOOK(get_widget(self)), get_widget(child), - get_widget(label)); + glabel); return self; } @@ -410,10 +470,10 @@ rb_define_const(gNotebook, "SIGNAL_SWITCH_PAGE", rb_str_new2("switch_page")); rb_define_method(gNotebook, "initialize", note_initialize, 0); - rb_define_method(gNotebook, "append_page", note_append_page, 2); - rb_define_method(gNotebook, "append_page_menu", note_append_page_menu, 3); - rb_define_method(gNotebook, "prepend_page", note_prepend_page, 2); - rb_define_method(gNotebook, "prepend_page_menu", note_prepend_page_menu, 3); + rb_define_method(gNotebook, "append_page", note_append_page, -1); + rb_define_method(gNotebook, "append_page_menu", note_append_page_menu, -1); + rb_define_method(gNotebook, "prepend_page", note_prepend_page, -1); + rb_define_method(gNotebook, "prepend_page_menu", note_prepend_page_menu, -1); rb_define_method(gNotebook, "insert_page", note_insert_page, 3); rb_define_method(gNotebook, "insert_page_menu", note_insert_page_menu, 4); rb_define_method(gNotebook, "remove_page", note_remove_page, 1); @@ -456,3 +516,9 @@ rb_define_method(gNotePage, "tab_label", notepage_tab_label, 0); rb_define_method(gNotePage, "menu_label", notepage_menu_label, 0); }