mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
tkmenubar
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@40 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bed68843ab
commit
bc3cc9ceec
5 changed files with 198 additions and 66 deletions
|
@ -1,5 +1,8 @@
|
||||||
Wed Jan 21 01:43:42 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
Wed Jan 21 01:43:42 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||||
|
|
||||||
|
* 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.
|
* regex.c (re_compile_pattern): too many pops for non register subexpr.
|
||||||
|
|
||||||
* parse.y (yylex): open parentheses after identifiers are argument
|
* parse.y (yylex): open parentheses after identifiers are argument
|
||||||
|
|
1
MANIFEST
1
MANIFEST
|
@ -120,6 +120,7 @@ lib/tkcanvas.rb
|
||||||
lib/tkclass.rb
|
lib/tkclass.rb
|
||||||
lib/tkdialog.rb
|
lib/tkdialog.rb
|
||||||
lib/tkentry.rb
|
lib/tkentry.rb
|
||||||
|
lib/tkmenubar.rb
|
||||||
lib/tkscrollbox.rb
|
lib/tkscrollbox.rb
|
||||||
lib/tktext.rb
|
lib/tktext.rb
|
||||||
lib/tracer.rb
|
lib/tracer.rb
|
||||||
|
|
110
eval.c
110
eval.c
|
@ -283,15 +283,15 @@ static struct FRAME *top_frame;
|
||||||
static struct SCOPE *top_scope;
|
static struct SCOPE *top_scope;
|
||||||
|
|
||||||
#define PUSH_FRAME() { \
|
#define PUSH_FRAME() { \
|
||||||
struct FRAME *_frame = ALLOCA_N(struct FRAME,1);\
|
struct FRAME _frame; \
|
||||||
_frame->prev = the_frame; \
|
_frame.prev = the_frame; \
|
||||||
_frame->file = sourcefile; \
|
_frame.file = sourcefile; \
|
||||||
_frame->line = sourceline; \
|
_frame.line = sourceline; \
|
||||||
_frame->iter = the_iter->iter; \
|
_frame.iter = the_iter->iter; \
|
||||||
_frame->cbase = the_frame->cbase; \
|
_frame.cbase = the_frame->cbase; \
|
||||||
the_frame = _frame; \
|
the_frame = &_frame; \
|
||||||
|
|
||||||
#define POP_FRAME() the_frame = _frame->prev; }
|
#define POP_FRAME() the_frame = _frame.prev; }
|
||||||
|
|
||||||
struct BLOCK {
|
struct BLOCK {
|
||||||
NODE *var;
|
NODE *var;
|
||||||
|
@ -310,29 +310,29 @@ struct BLOCK {
|
||||||
} *the_block;
|
} *the_block;
|
||||||
|
|
||||||
#define PUSH_BLOCK(v,b) { \
|
#define PUSH_BLOCK(v,b) { \
|
||||||
struct BLOCK *_block = ALLOCA_N(struct BLOCK,1);\
|
struct BLOCK _block; \
|
||||||
_block->tag = prot_tag; \
|
_block.tag = prot_tag; \
|
||||||
_block->var = v; \
|
_block.var = v; \
|
||||||
_block->body = b; \
|
_block.body = b; \
|
||||||
_block->self = self; \
|
_block.self = self; \
|
||||||
_block->frame = *the_frame; \
|
_block.frame = *the_frame; \
|
||||||
_block->class = the_class; \
|
_block.class = the_class; \
|
||||||
_block->frame.file = sourcefile; \
|
_block.frame.file = sourcefile; \
|
||||||
_block->frame.line = sourceline; \
|
_block.frame.line = sourceline; \
|
||||||
_block->scope = the_scope; \
|
_block.scope = the_scope; \
|
||||||
_block->d_vars = the_dyna_vars; \
|
_block.d_vars = the_dyna_vars; \
|
||||||
_block->prev = the_block; \
|
_block.prev = the_block; \
|
||||||
_block->iter = the_iter->iter; \
|
_block.iter = the_iter->iter; \
|
||||||
the_block = _block;
|
the_block = &_block;
|
||||||
|
|
||||||
#define PUSH_BLOCK2(b) { \
|
#define PUSH_BLOCK2(b) { \
|
||||||
struct BLOCK *_block = ALLOCA_N(struct BLOCK,1);\
|
struct BLOCK _block; \
|
||||||
*_block = *b; \
|
_block = *b; \
|
||||||
_block->prev = the_block; \
|
_block.prev = the_block; \
|
||||||
the_block = _block;
|
the_block = &_block;
|
||||||
|
|
||||||
#define POP_BLOCK() \
|
#define POP_BLOCK() \
|
||||||
the_block = the_block->prev; \
|
the_block = _block.prev; \
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RVarmap *the_dyna_vars;
|
struct RVarmap *the_dyna_vars;
|
||||||
|
@ -417,38 +417,26 @@ static struct iter {
|
||||||
the_iter = _iter.prev; \
|
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 {
|
static struct tag {
|
||||||
jmp_buf buf;
|
jmp_buf buf;
|
||||||
struct FRAME *frame;
|
struct FRAME *frame;
|
||||||
struct iter *iter;
|
struct iter *iter;
|
||||||
ID tag;
|
ID tag;
|
||||||
tag_retval_dcl;
|
VALUE retval;
|
||||||
ID dst;
|
ID dst;
|
||||||
struct tag *prev;
|
struct tag *prev;
|
||||||
} *prot_tag;
|
} *prot_tag;
|
||||||
|
|
||||||
#define PUSH_TAG(ptag) { \
|
#define PUSH_TAG(ptag) { \
|
||||||
struct tag *_tag = ALLOCA_N(struct tag,1);\
|
struct tag _tag; \
|
||||||
tag_retval_init; \
|
_tag.retval = Qnil; \
|
||||||
_tag->frame = the_frame; \
|
_tag.frame = the_frame; \
|
||||||
_tag->iter = the_iter; \
|
_tag.iter = the_iter; \
|
||||||
_tag->prev = prot_tag; \
|
_tag.prev = prot_tag; \
|
||||||
_tag->tag_retval = Qnil; \
|
_tag.retval = Qnil; \
|
||||||
_tag->tag = ptag; \
|
_tag.tag = ptag; \
|
||||||
_tag->dst = 0; \
|
_tag.dst = 0; \
|
||||||
prot_tag = _tag;
|
prot_tag = &_tag;
|
||||||
|
|
||||||
#define PROT_NONE 0
|
#define PROT_NONE 0
|
||||||
#define PROT_FUNC -1
|
#define PROT_FUNC -1
|
||||||
|
@ -463,7 +451,7 @@ static struct tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
#define POP_TAG() \
|
#define POP_TAG() \
|
||||||
prot_tag = _tag->prev; \
|
prot_tag = _tag.prev; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TAG_RETURN 0x1
|
#define TAG_RETURN 0x1
|
||||||
|
@ -1373,7 +1361,7 @@ call_trace_func(event, file, line, self, id)
|
||||||
|
|
||||||
prev = the_frame;
|
prev = the_frame;
|
||||||
PUSH_FRAME();
|
PUSH_FRAME();
|
||||||
*the_frame = *_frame->prev;
|
*the_frame = *_frame.prev;
|
||||||
the_frame->prev = prev;
|
the_frame->prev = prev;
|
||||||
|
|
||||||
the_frame->line = sourceline = line;
|
the_frame->line = sourceline = line;
|
||||||
|
@ -1608,7 +1596,7 @@ rb_eval(self, node)
|
||||||
else if (the_block->tag->dst == state) {
|
else if (the_block->tag->dst == state) {
|
||||||
state &= TAG_MASK;
|
state &= TAG_MASK;
|
||||||
if (state == TAG_RETURN) {
|
if (state == TAG_RETURN) {
|
||||||
result = prot_tag->tag_retval;
|
result = prot_tag->retval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
POP_TAG();
|
POP_TAG();
|
||||||
|
@ -2579,7 +2567,7 @@ f_raise(argc, argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
PUSH_FRAME(); /* fake frame */
|
PUSH_FRAME(); /* fake frame */
|
||||||
*the_frame = *_frame->prev->prev;
|
*the_frame = *_frame.prev->prev;
|
||||||
rb_longjmp(TAG_RAISE, mesg, arg3);
|
rb_longjmp(TAG_RAISE, mesg, arg3);
|
||||||
POP_FRAME();
|
POP_FRAME();
|
||||||
}
|
}
|
||||||
|
@ -2806,7 +2794,7 @@ rb_iterate(it_proc, data1, bl_proc, data2)
|
||||||
if (the_block->tag->dst == state) {
|
if (the_block->tag->dst == state) {
|
||||||
state &= TAG_MASK;
|
state &= TAG_MASK;
|
||||||
if (state == TAG_RETURN) {
|
if (state == TAG_RETURN) {
|
||||||
retval = prot_tag->tag_retval;
|
retval = prot_tag->retval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
POP_TAG();
|
POP_TAG();
|
||||||
|
@ -2979,7 +2967,7 @@ f_missing(argc, argv, obj)
|
||||||
sourcefile = file;
|
sourcefile = file;
|
||||||
sourceline = line;
|
sourceline = line;
|
||||||
PUSH_FRAME(); /* fake frame */
|
PUSH_FRAME(); /* fake frame */
|
||||||
*the_frame = *_frame->prev->prev;
|
*the_frame = *_frame.prev->prev;
|
||||||
|
|
||||||
NameError(format,
|
NameError(format,
|
||||||
rb_id2name(id),
|
rb_id2name(id),
|
||||||
|
@ -3312,7 +3300,7 @@ rb_call(class, recv, mid, argc, argv, scope)
|
||||||
result = rb_eval(recv, body);
|
result = rb_eval(recv, body);
|
||||||
}
|
}
|
||||||
else if (state == TAG_RETURN) {
|
else if (state == TAG_RETURN) {
|
||||||
result = prot_tag->tag_retval;
|
result = prot_tag->retval;
|
||||||
state = 0;
|
state = 0;
|
||||||
}
|
}
|
||||||
POP_VARS();
|
POP_VARS();
|
||||||
|
@ -3655,8 +3643,8 @@ eval_under(under, self, src)
|
||||||
PUSH_CLASS();
|
PUSH_CLASS();
|
||||||
the_class = under;
|
the_class = under;
|
||||||
PUSH_FRAME();
|
PUSH_FRAME();
|
||||||
the_frame->last_func = _frame->last_func;
|
the_frame->last_func = _frame.last_func;
|
||||||
the_frame->last_class = _frame->last_class;
|
the_frame->last_class = _frame.last_class;
|
||||||
the_frame->argc = 1;
|
the_frame->argc = 1;
|
||||||
the_frame->argv = &src;
|
the_frame->argv = &src;
|
||||||
the_frame->cbase = (VALUE)node_newnode(NODE_CREF,under,0,cbase);
|
the_frame->cbase = (VALUE)node_newnode(NODE_CREF,under,0,cbase);
|
||||||
|
@ -5741,7 +5729,7 @@ f_catch(dmy, tag)
|
||||||
val = rb_yield(tag);
|
val = rb_yield(tag);
|
||||||
}
|
}
|
||||||
else if (state == TAG_THROW && prot_tag->tag == prot_tag->dst) {
|
else if (state == TAG_THROW && prot_tag->tag == prot_tag->dst) {
|
||||||
val = prot_tag->tag_retval;
|
val = prot_tag->retval;
|
||||||
state = 0;
|
state = 0;
|
||||||
}
|
}
|
||||||
POP_TAG();
|
POP_TAG();
|
||||||
|
@ -5765,7 +5753,7 @@ f_throw(argc, argv)
|
||||||
while (tt) {
|
while (tt) {
|
||||||
if (tt->tag == t) {
|
if (tt->tag == t) {
|
||||||
tt->dst = t;
|
tt->dst = t;
|
||||||
tt->tag_retval = value;
|
tt->retval = value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef THREAD
|
#ifdef THREAD
|
||||||
|
@ -5793,7 +5781,7 @@ return_value(val)
|
||||||
|
|
||||||
while (tt) {
|
while (tt) {
|
||||||
if (tt->tag == PROT_FUNC) {
|
if (tt->tag == PROT_FUNC) {
|
||||||
tt->tag_retval = val;
|
tt->retval = val;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef THREAD
|
#ifdef THREAD
|
||||||
|
|
13
lib/tk.rb
13
lib/tk.rb
|
@ -972,6 +972,7 @@ class TkRoot<TkWindow
|
||||||
return ROOT[0] if ROOT[0]
|
return ROOT[0] if ROOT[0]
|
||||||
new = super
|
new = super
|
||||||
ROOT[0] = new
|
ROOT[0] = new
|
||||||
|
Tk_WINDOWS["."] = new
|
||||||
end
|
end
|
||||||
def create_self
|
def create_self
|
||||||
@path = '.'
|
@path = '.'
|
||||||
|
@ -1229,12 +1230,12 @@ module TkComposite
|
||||||
@delegates = {}
|
@delegates = {}
|
||||||
@delegates['DEFAULT'] = @frame
|
@delegates['DEFAULT'] = @frame
|
||||||
end
|
end
|
||||||
if option.kind_of?(String)
|
if @delegates[option].kind_of?(Array)
|
||||||
@delegates[option] = wins
|
for i in wins
|
||||||
else
|
@delegates[option].push(i)
|
||||||
for i in option
|
|
||||||
@delegates[i] = wins
|
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
@delegates[option] = wins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1261,3 +1262,5 @@ autoload :TkBitmapImage, 'tkcanvas'
|
||||||
autoload :TkPhotoImage, 'tkcanvas'
|
autoload :TkPhotoImage, 'tkcanvas'
|
||||||
autoload :TkEntry, 'tkentry'
|
autoload :TkEntry, 'tkentry'
|
||||||
autoload :TkText, 'tktext'
|
autoload :TkText, 'tktext'
|
||||||
|
autoload :TkDialog, 'tkdialog'
|
||||||
|
autoload :TkMenubar, 'tkmenubar'
|
||||||
|
|
137
lib/tkmenubar.rb
Normal file
137
lib/tkmenubar.rb
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
#
|
||||||
|
# tkmenubar.rb
|
||||||
|
#
|
||||||
|
# Copyright (C) 1998 maeda shugo. All rights reserved.
|
||||||
|
# This file can be distributed under the terms of the Ruby.
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
#
|
||||||
|
# menu_spec = [
|
||||||
|
# [['File', 0],
|
||||||
|
# ['Open', proc{puts('Open clicked')}, 0],
|
||||||
|
# '---',
|
||||||
|
# ['Quit', proc{exit}, 0]],
|
||||||
|
# [['Edit', 0],
|
||||||
|
# ['Cut', proc{puts('Cut clicked')}, 2],
|
||||||
|
# ['Copy', proc{puts('Copy clicked')}, 0],
|
||||||
|
# ['Paste', proc{puts('Paste clicked')}, 0]]
|
||||||
|
# ]
|
||||||
|
# menubar = TkMenubar.new(nil, menu_spec,
|
||||||
|
# 'tearoff'=>false,
|
||||||
|
# '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<TkFrame
|
||||||
|
|
||||||
|
include TkComposite
|
||||||
|
|
||||||
|
def initialize(parent = nil, spec = nil, options = nil)
|
||||||
|
super(parent, options)
|
||||||
|
|
||||||
|
@menus = []
|
||||||
|
|
||||||
|
if spec
|
||||||
|
for menu_info in spec
|
||||||
|
add_menu(menu_info)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if options
|
||||||
|
for key, value in options
|
||||||
|
configure(key, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_menu(menu_info)
|
||||||
|
btn_info = menu_info.shift
|
||||||
|
mbtn = TkMenubutton.new(@frame)
|
||||||
|
|
||||||
|
if btn_info.kind_of?(Hash)
|
||||||
|
for key, value in btn_info
|
||||||
|
mbtn.configure(key, value)
|
||||||
|
end
|
||||||
|
elsif btn_info.kind_of?(Array)
|
||||||
|
mbtn.configure('text', btn_info[0]) if btn_info[0]
|
||||||
|
mbtn.configure('underline', btn_info[1]) if btn_info[1]
|
||||||
|
mbtn.configure('accelerator', btn_info[2]) if btn_info[2]
|
||||||
|
else
|
||||||
|
mbtn.configure('text', btn_info)
|
||||||
|
end
|
||||||
|
|
||||||
|
menu = TkMenu.new(mbtn)
|
||||||
|
|
||||||
|
for item_info in menu_info
|
||||||
|
if item_info.kind_of?(Hash)
|
||||||
|
menu.add('command', item_info)
|
||||||
|
elsif item_info.kind_of?(Array)
|
||||||
|
options = {}
|
||||||
|
options['label'] = item_info[0] if item_info[0]
|
||||||
|
options['command'] = item_info[1] if item_info[1]
|
||||||
|
options['underline'] = item_info[2] if item_info[2]
|
||||||
|
options['accelerator'] = item_info[3] if item_info[3]
|
||||||
|
menu.add('command', options)
|
||||||
|
elsif /^-+$/ =~ item_info
|
||||||
|
menu.add('sep')
|
||||||
|
else
|
||||||
|
menu.add('command', 'label' => 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
|
Loading…
Add table
Add a link
Reference in a new issue