1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/tk/lib/tkextlib/tcllib/ico.rb
nagai ed6ce8b43b * ext/tk/extconf.rb: New strategy for searching Tcl/Tk libraries.
* ext/tk/*: Support new features of Tcl/Tk8.6b1 and minor bug fixes.
     ( [KNOWN BUG] Ruby/Tk on Ruby 1.9 will not work on Cygwin. )
* ext/tk/*: Unify sources between Ruby 1.8 & 1.9.
            Improve default_widget_set handling.
* ext/tk/*: Multi-TkInterpreter (multi-tk.rb) works on Ruby 1.8 & 1.9.
     ( [KNOWN BUG] On Ruby 1.8, join to a long term Thread on Tk
       callbacks may freeze. On Ruby 1.9, cannot create a second 
       master interpreter (creating slaves are OK); supported master
       interpreter is the default master interpreter only. )
* ext/tk/lib/tkextlib/*: Update supported versions of Tk extensions.
         Tcllib 1.8/Tklib 0.4.1  ==>  Tcllib 1.11.1/Tklib 0.5
         BWidgets 1.7            ==>  BWidgets 1.8
         TkTable 2.9             ==>  TkTable 2.10
         TkTreeCtrl 2005-12-02   ==>  TkTreeCtrl 2.2.9
         Tile 0.8.0/8.5.1        ==>  Tile 0.8.3/8.6b1
         IncrTcl 2005-02-14      ==>  IncrTcl 2008-12-15
         TclX 2005-02-07         ==>  TclX 2008-12-15
         Trofs 0.4.3             ==>  Trofs 0.4.4


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-12 23:08:32 +00:00

146 lines
3.9 KiB
Ruby

#
# tkextlib/tcllib/ico.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
# * Part of tcllib extension
# * Reading and writing windows icons
#
require 'tk'
require 'tk/image'
#require 'tkextlib/tcllib.rb'
# TkPackage.require('ico', '0.3')
TkPackage.require('ico')
module Tk
module Tcllib
class ICO < TkImage
PACKAGE_NAME = 'ico'.freeze
def self.package_name
PACKAGE_NAME
end
def self.package_version
begin
TkPackage.require('ico')
rescue
''
end
end
end
end
end
class Tk::Tcllib::ICO
def self.list(file, keys=nil)
tk_split_list(tk_call_without_enc('::ico::getIconList', file,
*hash_kv(keys, true)))
end
def self.icons(file, keys=nil)
tk_split_simplelist(tk_call_without_enc('::ico::icons', file,
*hash_kv(keys, true))).map{|elem|
num_or_str(elem)
}
end
def self.get_members(file, name, keys=nil)
tk_split_simplelist(tk_call_without_enc('::ico::getMembers', file, name,
*hash_kv(keys, true))).map{|elem|
name, width, height, bpp = tk_split_simplelist(elem)
[name, number(width), number(height), number(bpp)]
}
end
def self.get(file, index, keys=nil)
tk_call_without_enc('::ico::getIcon', file, index, *hash_kv(keys, true))
end
def self.get_icon(*args)
get(*args)
end
def self.get_by_name(file, name, keys=nil)
tk_call_without_enc('::ico::getIconByName', file, name,
*hash_kv(keys, true))
end
def self.get_icon_by_name(*args)
get_by_name(*args)
end
def self.get_fileicon(file, keys=nil)
tk_call_without_enc('::ico::getFileIcon', file, *hash_kv(keys, true))
end
def self.get_image(file, index, keys={})
keys = _symbolkey2str(keys)
keys.delete('format')
self.new(file, index, keys)
end
def self.get_data(file, index, keys={})
keys['format'] = 'data'
tk_split_list(tk_call_without_enc('::ico::getIcon', file, index,
*hash_kv(keys, true)))
end
def self.write(file, index, depth, data, keys=nil)
tk_call_without_enc('::ico::writeIcon', file, index, depth, data,
*hash_kv(keys, true))
end
def self.copy(from_file, from_index, to_file, to_index, keys=nil)
tk_call_without_enc('::ico::copyIcon',
from_file, from_index, to_file, to_index,
*hash_kv(keys, true))
end
def self.exe_to_ico(exe_file, ico_file, keys=nil)
tk_call_without_enc('::ico::copyIcon', exe_file, ico_file,
*hash_kv(keys, true))
end
def self.clear_cache(file=None)
tk_call_without_enc('::ico::clearCache', file)
end
def self.transparent_color(image, color)
if image.kind_of?(Array)
tk_split_list(tk_call_without_enc('::ico::transparentColor',
image, color))
else
tk_call_without_enc('::ico::transparentColor', image, color)
end
end
def self.show(file, keys=nil)
tk_call_without_enc('::ico::Show', file, *hash_kv(keys, true))
end
###########################
def initialize(file, index, keys=nil)
keys = _symbolkey2str(keys)
if keys.key?('name')
@path = keys['name'].to_s
else
Tk_Image_ID.mutex.synchronize{
@path = Tk_Image_ID.join(TkCore::INTERP._ip_id_)
Tk_Image_ID[1].succ!
}
end
tk_call_without_enc('::ico::getIcon', file, index, '-name', @path,
'-format', 'image', *hash_kv(keys, true))
Tk_IMGTBL[@path] = self
end
def write(file, index, depth, keys=nil)
Tk::Tcllib::ICO.write(file, index, depth, @path, keys=nil)
self
end
def transparent_color(color)
tk_call_without_enc('::ico::transparentColor', @path, color)
self
end
end