From bc3cc9ceec99317ef798753cef48475cd168e34c Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 22 Jan 1998 03:34:28 +0000 Subject: [PATCH] tkmenubar git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@40 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 3 ++ MANIFEST | 1 + eval.c | 110 +++++++++++++++++-------------------- lib/tk.rb | 13 +++-- lib/tkmenubar.rb | 137 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 198 insertions(+), 66 deletions(-) create mode 100644 lib/tkmenubar.rb diff --git a/ChangeLog b/ChangeLog index f78f96e9fa..4b03cf9a12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ Wed Jan 21 01:43:42 1998 Yukihiro Matsumoto + * eval.c (PUSH_FRAME): do not use ALLOCA_N(). crash on some + platforms (such as HP-UX or mswin32). + * regex.c (re_compile_pattern): too many pops for non register subexpr. * parse.y (yylex): open parentheses after identifiers are argument diff --git a/MANIFEST b/MANIFEST index aa629eeb08..27bb946f50 100644 --- a/MANIFEST +++ b/MANIFEST @@ -120,6 +120,7 @@ lib/tkcanvas.rb lib/tkclass.rb lib/tkdialog.rb lib/tkentry.rb +lib/tkmenubar.rb lib/tkscrollbox.rb lib/tktext.rb lib/tracer.rb diff --git a/eval.c b/eval.c index e4b5feb7f2..ace4cd18f2 100644 --- a/eval.c +++ b/eval.c @@ -283,15 +283,15 @@ static struct FRAME *top_frame; static struct SCOPE *top_scope; #define PUSH_FRAME() { \ - struct FRAME *_frame = ALLOCA_N(struct FRAME,1);\ - _frame->prev = the_frame; \ - _frame->file = sourcefile; \ - _frame->line = sourceline; \ - _frame->iter = the_iter->iter; \ - _frame->cbase = the_frame->cbase; \ - the_frame = _frame; \ + struct FRAME _frame; \ + _frame.prev = the_frame; \ + _frame.file = sourcefile; \ + _frame.line = sourceline; \ + _frame.iter = the_iter->iter; \ + _frame.cbase = the_frame->cbase; \ + the_frame = &_frame; \ -#define POP_FRAME() the_frame = _frame->prev; } +#define POP_FRAME() the_frame = _frame.prev; } struct BLOCK { NODE *var; @@ -310,29 +310,29 @@ struct BLOCK { } *the_block; #define PUSH_BLOCK(v,b) { \ - struct BLOCK *_block = ALLOCA_N(struct BLOCK,1);\ - _block->tag = prot_tag; \ - _block->var = v; \ - _block->body = b; \ - _block->self = self; \ - _block->frame = *the_frame; \ - _block->class = the_class; \ - _block->frame.file = sourcefile; \ - _block->frame.line = sourceline; \ - _block->scope = the_scope; \ - _block->d_vars = the_dyna_vars; \ - _block->prev = the_block; \ - _block->iter = the_iter->iter; \ - the_block = _block; + struct BLOCK _block; \ + _block.tag = prot_tag; \ + _block.var = v; \ + _block.body = b; \ + _block.self = self; \ + _block.frame = *the_frame; \ + _block.class = the_class; \ + _block.frame.file = sourcefile; \ + _block.frame.line = sourceline; \ + _block.scope = the_scope; \ + _block.d_vars = the_dyna_vars; \ + _block.prev = the_block; \ + _block.iter = the_iter->iter; \ + the_block = &_block; #define PUSH_BLOCK2(b) { \ - struct BLOCK *_block = ALLOCA_N(struct BLOCK,1);\ - *_block = *b; \ - _block->prev = the_block; \ - the_block = _block; + struct BLOCK _block; \ + _block = *b; \ + _block.prev = the_block; \ + the_block = &_block; #define POP_BLOCK() \ - the_block = the_block->prev; \ + the_block = _block.prev; \ } struct RVarmap *the_dyna_vars; @@ -417,38 +417,26 @@ static struct iter { the_iter = _iter.prev; \ } -#ifdef C_ALLOCA -/* need to protect retval in struct tag from GC. */ -#define tag_retval_dcl VALUE *dd_retval -#define tag_retval_init VALUE _tag_retval = Qnil;\ - _tag->dd_retval = &_tag_retval; -#define tag_retval dd_retval[0] -#else -#define tag_retval_dcl VALUE retval -#define tag_retval_init _tag->retval = Qnil -#define tag_retval retval -#endif - static struct tag { jmp_buf buf; struct FRAME *frame; struct iter *iter; ID tag; - tag_retval_dcl; + VALUE retval; ID dst; struct tag *prev; } *prot_tag; #define PUSH_TAG(ptag) { \ - struct tag *_tag = ALLOCA_N(struct tag,1);\ - tag_retval_init; \ - _tag->frame = the_frame; \ - _tag->iter = the_iter; \ - _tag->prev = prot_tag; \ - _tag->tag_retval = Qnil; \ - _tag->tag = ptag; \ - _tag->dst = 0; \ - prot_tag = _tag; + struct tag _tag; \ + _tag.retval = Qnil; \ + _tag.frame = the_frame; \ + _tag.iter = the_iter; \ + _tag.prev = prot_tag; \ + _tag.retval = Qnil; \ + _tag.tag = ptag; \ + _tag.dst = 0; \ + prot_tag = &_tag; #define PROT_NONE 0 #define PROT_FUNC -1 @@ -463,7 +451,7 @@ static struct tag { } #define POP_TAG() \ - prot_tag = _tag->prev; \ + prot_tag = _tag.prev; \ } #define TAG_RETURN 0x1 @@ -1373,7 +1361,7 @@ call_trace_func(event, file, line, self, id) prev = the_frame; PUSH_FRAME(); - *the_frame = *_frame->prev; + *the_frame = *_frame.prev; the_frame->prev = prev; the_frame->line = sourceline = line; @@ -1608,7 +1596,7 @@ rb_eval(self, node) else if (the_block->tag->dst == state) { state &= TAG_MASK; if (state == TAG_RETURN) { - result = prot_tag->tag_retval; + result = prot_tag->retval; } } POP_TAG(); @@ -2579,7 +2567,7 @@ f_raise(argc, argv) } PUSH_FRAME(); /* fake frame */ - *the_frame = *_frame->prev->prev; + *the_frame = *_frame.prev->prev; rb_longjmp(TAG_RAISE, mesg, arg3); POP_FRAME(); } @@ -2806,7 +2794,7 @@ rb_iterate(it_proc, data1, bl_proc, data2) if (the_block->tag->dst == state) { state &= TAG_MASK; if (state == TAG_RETURN) { - retval = prot_tag->tag_retval; + retval = prot_tag->retval; } } POP_TAG(); @@ -2979,7 +2967,7 @@ f_missing(argc, argv, obj) sourcefile = file; sourceline = line; PUSH_FRAME(); /* fake frame */ - *the_frame = *_frame->prev->prev; + *the_frame = *_frame.prev->prev; NameError(format, rb_id2name(id), @@ -3312,7 +3300,7 @@ rb_call(class, recv, mid, argc, argv, scope) result = rb_eval(recv, body); } else if (state == TAG_RETURN) { - result = prot_tag->tag_retval; + result = prot_tag->retval; state = 0; } POP_VARS(); @@ -3655,8 +3643,8 @@ eval_under(under, self, src) PUSH_CLASS(); the_class = under; PUSH_FRAME(); - the_frame->last_func = _frame->last_func; - the_frame->last_class = _frame->last_class; + the_frame->last_func = _frame.last_func; + the_frame->last_class = _frame.last_class; the_frame->argc = 1; the_frame->argv = &src; the_frame->cbase = (VALUE)node_newnode(NODE_CREF,under,0,cbase); @@ -5741,7 +5729,7 @@ f_catch(dmy, tag) val = rb_yield(tag); } else if (state == TAG_THROW && prot_tag->tag == prot_tag->dst) { - val = prot_tag->tag_retval; + val = prot_tag->retval; state = 0; } POP_TAG(); @@ -5765,7 +5753,7 @@ f_throw(argc, argv) while (tt) { if (tt->tag == t) { tt->dst = t; - tt->tag_retval = value; + tt->retval = value; break; } #ifdef THREAD @@ -5793,7 +5781,7 @@ return_value(val) while (tt) { if (tt->tag == PROT_FUNC) { - tt->tag_retval = val; + tt->retval = val; break; } #ifdef THREAD diff --git a/lib/tk.rb b/lib/tk.rb index 1a3ae2933d..8bb6c7f842 100644 --- a/lib/tk.rb +++ b/lib/tk.rb @@ -972,6 +972,7 @@ class TkRootfalse, +# 'foreground'=>'grey40', +# 'activeforeground'=>'red', +# 'font'=>'-adobe-helvetica-bold-r-*--12-*-iso8859-1') +# menubar.pack('side'=>'top', 'fill'=>'x') +# +# +# OR +# +# +# menubar = TkMenubar.new +# menubar.add_menu([['File', 0], +# ['Open', proc{puts('Open clicked')}, 0], +# '---', +# ['Quit', proc{exit}, 0]]) +# menubar.add_menu([['Edit', 0], +# ['Cut', proc{puts('Cut clicked')}, 2], +# ['Copy', proc{puts('Copy clicked')}, 0], +# ['Paste', proc{puts('Paste clicked')}, 0]]) +# menubar.configure('tearoff', false) +# menubar.configure('foreground', 'grey40') +# menubar.configure('activeforeground', 'red') +# menubar.configure('font', '-adobe-helvetica-bold-r-*--12-*-iso8859-1') +# menubar.pack('side'=>'top', 'fill'=>'x') + +# The format of the menu_spec is: +# [ +# [ +# [button text, underline, accelerator], +# [menu label, command, underline, accelerator], +# '---', # separator +# ... +# ], +# ... +# ] + +# underline and accelerator are optional parameters. +# Hashes are OK instead of Arrays. + +# To use add_menu, configuration must be done by calling configure after +# adding all menus by add_menu, not by the constructor arguments. + +require "tk" + +class TkMenubar item_info) + end + end + + mbtn.menu(menu) + @menus.push([mbtn, menu]) + delegate('tearoff', menu) + delegate('foreground', mbtn, menu) + delegate('background', mbtn, menu) + delegate('disabledforeground', mbtn, menu) + delegate('activeforeground', mbtn, menu) + delegate('activebackground', mbtn, menu) + delegate('font', mbtn, menu) + delegate('kanjifont', mbtn, menu) + mbtn.pack('side' => 'left') + end + + def [](index) + return @menus[index] + end +end