----Next_Part(Wed_Oct_27_22:28:57_1999_91)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

From: matz / netlab.co.jp (Yukihiro Matsumoto)
Subject: [ruby-ext:00510] Re: [Ruby/Gtk] statusbar messages method
Date: Thu, 28 Oct 1999 08:07:21 +0900

> |# まつもとゆきひろ氏の Ruby本には辺の事もい討△襪里任靴腓Δ
囈鴣笏についてはい討覆い任垢佑─すいません;
さすがに全てについては韻覆った;

いえいえ。README.EXTだけでもりました;

凖祖妖努奠褓ぢに sturctに関するものを付け足してもらいたくてい討澆燭
ですが、「rb_struct_define()の最後の argumentは 0でなければいけない」で
当っていますか?

> |以下の errorがでるのですがどの様に対垢戮でしょうえ凧 咐磔で structすら使ったことがない者がい討い襪里如邸邸
齡癆黷癇鰲艮欝 癇鉗鈑 瘡鱚痲蜴蜚蛛跚繝闔齡瘤 嗟鼇

これはメドの中で rb_define_struct() を呼んでいるのが原因
> です。rb_define_struct() は体クラスを定義するので、
ーチン Init_xxx の中で呼び紘要があります;

なるほど。staticにして Init_gtk_statusbar()の中に移したら覆なりまえ
た。あぅ、ext/etc/etc.cも、様になってますね‥‥。

あとは、bug fix(nil? -> empty?)と変数の名前の変更。

ところで、うちでは問題なく動いているのですが、messages methodの方え
方向的にこれで良いのでしょうか?
--
            yashi

----Next_Part(Wed_Oct_27_22:28:57_1999_91)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="README.EXT.diff"

--- README.EXT.old	Mon Aug 16 11:09:09 1999
+++ README.EXT	Wed Oct 27 22:17:43 1999
@@ -182,6 +182,19 @@
     Array operations.  The first argument to each functions must be an 
     array.  They may dump core if other types given.
 
+  Struct functions
+
+  rb_struct_define(const char *name, ...)
+
+    It works as Struct.new() in Ruby.  It has to be called inside of
+    Init_xxx(). Other argumens are access method names of char
+    pointer. The last argument must be 0.
+
+  rb_struct_new(VALUE klass, ...)
+
+    It works as klass.new in Ruby.  klass is the return value of
+    rb_struct_define().
+
 2. Extend Ruby with C
 
 2.1 Add new features to Ruby

----Next_Part(Wed_Oct_27_22:28:57_1999_91)--
Content-Type: Text/Plain; charset=euc-jp
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="README.EXT.jp.diff"

LS0tIFJFQURNRS5FWFQuanAub2xkCUZyaSBBdWcgMTMgMDE6NDU6MDEgMTk5OQ0KKysrIFJF
QURNRS5FWFQuanAJV2VkIE9jdCAyNyAyMjowMDo0NSAxOTk5DQpAQCAtMTY2LDggKzE2Niw4
IEBADQogudSkpqSzpMikz7SrpOGk6aTspN6ku6TzoaWkx6GkUnVieaTOpcehvKW/pPLB4Lru
pLmk67v+pMukzw0KIFJ1YnmkrM3RsNWkt6TGpKSk67TYv/Sk8s3RpKSkxqSvpMCktaSkoaUN
CiANCi2ks6SzpMekz6TipMOkyKTiu8ik76TspOukx6SipO2kpsq4u/rO86TIx9vO86TOwLjA
ri/B4LrupPK51A0KLaSktNi/9KTypKKksqTepLkowbTJ9KTHpM+kyqSkpMekuSmhpQ0KK6Sz
pLOkx6TPpOKkw6TIpOK7yKTvpOyk66THpKKk7aSmyri7+s7zoaLH287zoaK5vcKkws6kzsC4
wK4vweANCiu67qTyudSkpLTYv/Sk8qSipLKk3qS5KMG0yfSkx6TPpMqkpKTHpLkpoaUNCiAN
CiAgyri7+s7zpMvC0KS5pOu02L/0DQogDQpAQCAtMjExLDYgKzIxMSwxOSBAQA0KIA0KICAg
ICBBcnJheaTOxrHMvqTOpeGlvaXDpcmkyMaxpLjGr6StpPKkuaTrtNi/9KGlwugxsPq/9KTP
yaykug0KICAgICDH287zpMekyqSxpOyk0KTKpOmkyqSkoaUNCisNCisgub3CpMLOpMvC0KS5
pOu02L/0DQorDQorICByYl9zdHJ1Y3RfZGVmaW5lKGNvbnN0IGNoYXIgKm5hbWUsIC4uLikN
CisNCisgICAgU3RydWN0Lm5ld6TIxrGkuMavpK2k8qS5pOsuIEluaXRfeHh4KCmkzsPmpMe4
xqTTvdCkucmszdekrA0KKyAgICCkoqTrLiAuLi6kz6Giub3CpMLOpM6l4aXzpdCky8LQpLmk
66Wipa+lu6W5peGlvaXDpcmkzsy+wbAuDQorICAgILrHuOWkzrD6pK2/9KTPIDAuDQorDQor
ICByYl9zdHJ1Y3RfbmV3KFZBTFVFIGtsYXNzLCAuLi4pDQorDQorICAgIGtsYXNzLm5ld6TI
xrGkuMavpK2k8qS5pOsuIGtsYXNzpM8gcmJfc3RydWN0X2RlZmluZSgppM7K1g0KKyAgICCk
6sPNLiANCiANCiAyoaVSdWJ5pM61oce9pPK7yKSmDQogDQo---Next_Part(Wed_Oct_27_22:28:57_1999_91)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="gtk.patch"

diff -u --new-file --recursive gtk-0.22/sample/testgtk/statusbar.rb gtk/sample/testgtk/statusbar.rb
--- gtk-0.22/sample/testgtk/statusbar.rb	Tue Aug 24 23:21:39 1999
+++ gtk/sample/testgtk/statusbar.rb	Wed Oct 27 21:10:02 1999
@@ -49,8 +49,12 @@
     @statusbar  tatusbar  tk::Statusbar::new()
     box1.pack_end(statusbar, true, true, 0)
     statusbar.show
-    statusbar.signal_connect("text_popped") do popped end
-
+    statusbar.signal_connect("text_popped") do |o, mid, text|
+      popped(mid, text)
+    end
+    statusbar.signal_connect("text_pushed") do |o, mid, text|
+      pushed(mid, text)
+    end
 #
 # GtkWidget* gtk_widget_new  (guint type, ...);
 #
@@ -107,11 +111,14 @@
   def steal
     @statusbar.remove(1, 4)
   end
-  def popped
-    if @statusbar.messages.nil?
+  def popped(mid, text)
+    if @statusbar.messages.empty? then
       @counter  
     end
   end
+  def pushed(mid, text)
+    # do nothing... as of gtk 1.2.6
+  end
   def contexts
     string  any context"
     printf("GtkStatusBar: context%s\", context_id
\n",
@@ -139,17 +146,11 @@
            @statusbar.get_context_id(string))
   end
   def dump_stack
-   print("not implemented.\n")
-   #   GSList *list
-#   for (list  tatusbar.messages; list; list  ist.next)
-#     {
-#       GtkStatusbarMsg *msg
-
-#       msg  ist.data
-#       g_print ("context_id: %d, message_id: %d, status_text: \"%s\"\n",
-#                msg.context_id,
-#                msg.message_id,
-#                msg.text)
-#     }
+    @statusbar.messages.each do |m|
+      printf ("context_id: %d, message_id: %d, status_text: \"%s\"\n",
+	      m.context_id,
+	      m.message_id,
+	      m.text)
+    end
   end
 end
diff -u --new-file --recursive gtk-0.22/sample/testgtk/testgtk.rb gtk/sample/testgtk/testgtk.rb
--- gtk-0.22/sample/testgtk/testgtk.rb	Sun Sep 26 01:54:55 1999
+++ gtk/sample/testgtk/testgtk.rb	Wed Oct 27 21:14:55 1999
@@ -115,7 +115,7 @@
     ["scrolled windows", ScrolledWindowSample],
     ["shapes", ShapesSample],
     ["spinbutton", SpinButtonSample],
-    ["statusbar", nil], #StatusbarSample],   # has BUG
+    ["statusbar", StatusbarSample],
     ["test idle", nil],
     ["test mainloop", nil],
     ["test scrolling", nil],
diff -u --new-file --recursive gtk-0.22/src/rbgtkbox.c gtk/src/rbgtkbox.c
--- gtk-0.22/src/rbgtkbox.c	Tue Aug 24 23:21:44 1999
+++ gtk/src/rbgtkbox.c	Wed Oct 27 21:06:37 1999
@@ -427,6 +427,9 @@
 /*
  * Statusbar
  */
+
+static VALUE sMsg;
+
 static VALUE
 statusbar_initialize(self)
      VALUE self;
@@ -479,6 +482,33 @@
   return Qnil;
 }
 
+static VALUE
+gSMsg2ary(slist)
+    GSList *slist;
+{
+    VALUE msg;
+    VALUE ary  b_ary_new();
+
+    while (slist) {
+	GtkStatusbarMsg *gSMsg  list->data;
+	msg  b_struct_new(sMsg,
+			    rb_tainted_str_new2(gSMsg->text),
+			    INT2FIX(gSMsg->context_id),
+			    INT2FIX(gSMsg->message_id));
+	rb_ary_push(ary, msg);
+	slist  list->next;
+    }
+
+    return ary;
+}
+
+static VALUE
+statusbar_messages(self)
+    VALUE self;
+{
+    return gSMsg2ary(GTK_STATUSBAR(get_widget(self))->messages);
+}
+
 void Init_gtk_statusbar()
 {
     gStatusBar  b_define_class_under(mGtk, "Statusbar", gHBox);
@@ -491,6 +521,9 @@
     rb_define_method(gStatusBar, "pop", statusbar_pop, 1);
     rb_define_method(gStatusBar, "get_context_id", statusbar_get_context_id, 1);
     rb_define_method(gStatusBar, "remove", statusbar_remove, 2);
+    rb_define_method(gStatusBar, "messages", statusbar_messages, 0);
+
+    sMsg  b_struct_define("SMsg", "text", "context_id", "message_id", 0);   
 }
 
 /*

----Next_Part(Wed_Oct_27_22:28:57_1999_91)----