Top Level Namespace

Includes:
ParseDate

Defined Under Namespace

Modules: DemoBasic, DemoDialog, DemoDnD, DemoManager, DemoSelect, DemoTree, DemoVar, MultiTkIp_PseudoToplevel_Evaluable, TclTk, Tk, TkBgError, TkBindCore, TkCanvasItemConfig, TkClipboard, TkComm, TkComposite, TkConfigMethod, TkConsole, TkCore, TkEvent, TkGrid, TkItemConfigMethod, TkItemConfigOptkeys, TkItemFontOptkeys, TkKinput, TkListItemConfig, TkManageFocus, TkMenuEntryConfig, TkMenuSpec, TkOptionDB, TkPack, TkPackage, TkPalette, TkPlace, TkSelection, TkTextTagConfig, TkTreatFont, TkTreatItemFont, TkTreatTagFont, TkUtil, TkValidation, TkWinfo, TkXIM, TkcTagAccess Classes: AnimatedImageLabel, AnimatedTextLabel, AnimatedWaveDemo, BLT_Calendar_sample, BLT_Graph_Demo, BWidget_Demo, BtnFrame, Button_clone, Button_with_Frame, Clock, Hash, Knights_Tour, Mail, MultiTkIp, MultiTkIp_OK, Object, Othello, PendulumAnimationDemo, PhotoCanvas, RemoteTkIp, ScrListbox, Spinner_demo, TclTkCallback, TclTkCommand, TclTkImage, TclTkInterpreter, TclTkIp, TclTkLib, TclTkLibCommand, TclTkObject, TclTkVariable, TclTkWidget, Test1, TkBindTag, TkBindTagAll, TkBitmapImage, TkCallbackBreak, TkCallbackContinue, TkCallbackEntry, TkCallbackRedo, TkCallbackRetry, TkCallbackReturn, TkCallbackThrow, TkDatabaseClass, TkDialog, TkDialogObj, TkDialog_Demo1, TkDialog_Demo2, TkFont, TkGoldberg_Demo, TkHTML_File_Viewer, TkImage, TkImg_demo, TkKernel, TkLocalJumpError, TkMenubar, TkMsgCatalog, TkMultiColumnList, TkMultiListFrame, TkMultiListbox, TkNamedFont, TkNamespace, TkObject, TkPhotoImage, TkPixmapImage, TkRTTimer, TkScrollbox, TkScrolledCanvas, TkTextFrame, TkTextIO, TkTextImage, TkTextMark, TkTextMarkAnchor, TkTextMarkCurrent, TkTextMarkInsert, TkTextNamedMark, TkTextNamedTag, TkTextTag, TkTextTagSel, TkTextWin, TkTextWindow, TkTimer, TkTree, TkTreeCtrl_demo, TkValidateCommand, TkVarAccess, TkVariable, TkVirtualEvent, TkWarning, TkWarningObj, TkWindow, TkcArc, TkcBitmap, TkcGroup, TkcImage, TkcItem, TkcLine, TkcOval, TkcPolygon, TkcRectangle, TkcTag, TkcTagAll, TkcTagCurrent, TkcTagString, TkcText, TkcWindow, Unicodeout_SampleFrame, ViewIcons

Constant Summary collapse

TkLib_Config =
{}
TclConfig_Info =

{}
TkConfig_Info =
{}
TkSystemMenu =
Tk::SystemMenu
TopLevel =
TkToplevel
Frame =
TkFrame
Label =
TkLabel
Button =
TkButton
Radiobutton =
TkRadioButton
Checkbutton =
TkCheckButton
Message =
TkMessage
Entry =
TkEntry
Spinbox =
TkSpinbox
Text =
TkText
Scale =
TkScale
Scrollbar =
TkScrollbar
Listbox =
TkListbox
TkMenu
TkMenubutton
Canvas =
TkCanvas
Arc =
TkcArc
Bitmap =
TkcBitmap
Line =
TkcLine
Oval =
TkcOval
Polygon =
TkcPolygon
Rectangle =
TkcRectangle
TextItem =
TkcText
WindowItem =
TkcWindow
BitmapImage =
TkBitmapImage
PhotoImage =
TkPhotoImage
Selection =
TkSelection
Winfo =
TkWinfo
Pack =
TkPack
Grid =
TkGrid
Place =
TkPlace
Variable =
TkVariable
Font =
TkFont
VirtualEvent =
TkVirtualEvent
TkRoot =
Tk::Root
TkAfter =
TkTimer
TkMsgCat =
TkMsgCatalog
TkDialog2 =
TkDialogObj
TkWarning2 =
TkWarningObj
TktTag =
TkTextTag
TktNamedTag =
TkTextNamedTag
TktTagSel =
TkTextTagSel
TktMark =
TkTextMark
TktNamedMark =
TkTextNamedMark
TktMarkInsert =
TkTextMarkInsert
TktMarkCurrent =
TkTextMarkCurrent
TktMarkAnchor =
TkTextMarkAnchor
TkOption =
TkOptionDB
TkResourceDB =
TkOptionDB
TkNamedVirtualEvent =
TkVirtualEvent::PreDefVirtEvent
TktImage =
TkTextImage
TkcNamedTag =
TkcTagString
Ttk =
Tk::Tile
TktWindow =
TkTextWindow
OPTS =
{}
ImgFile =
[File.dirname(__FILE__), 'images','tcllogo.gif'].join(File::Separator)
DEFAULT_TK_ENCODING =
'UTF-8'
TkWidget =
TkWindow

Instance Method Summary collapse

Instance Method Details

#anyUnreadDescendants(t, i) ⇒ Object



434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'sample/tkextlib/treectrl/outlook-newgroup.rb', line 434

def anyUnreadDescendants(t, i)
  itemList = []
  item = t.item_firstchild(i)
  itemList.push(item) if item != ''

  while item = itemList.pop
    return true unless @Message[:read][item]

    item2 = t.item_nextsibling(item)
    itemList.push(item2) if item2 != ''
    item2 = t.item_firstchild(item)
    itemList.push(item2) if item2 != ''
  end
  false
end

#arrowMove1(c, x, y) ⇒ Object

arrowMove1 – This method is called for each mouse motion event on box1 (the one at the vertex of the arrow). It updates the controlling parameters for the line and arrowhead.

Arguments: c - The name of the canvas window. x, y - The coordinates of the mouse.



195
196
197
198
199
200
201
202
203
204
# File 'sample/demos-en/arrow.rb', line 195

def arrowMove1(c,x,y)
  v = $demo_arrowInfo
  newA = (v.x2+5-c.canvasx(x).round)/10
  newA = 0 if newA < 0
  newA = 25 if newA > 25
  if newA != v.a
    c.move('box1', 10*(v.a-newA), 0)
    v.a = newA
  end
end

#arrowMove2(c, x, y) ⇒ Object

arrowMove2 – This method is called for each mouse motion event on box2 (the one at the trailing tip of the arrowhead). It updates the controlling parameters for the line and arrowhead.

Arguments: c - The name of the canvas window. x, y - The coordinates of the mouse.



215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'sample/demos-en/arrow.rb', line 215

def arrowMove2(c,x,y)
  v = $demo_arrowInfo
  newB = (v.x2+5-c.canvasx(x).round)/10
  newB = 0 if newB < 0
  newB = 25 if newB > 25
  newC = (v.y+5-c.canvasy(y).round-5*v.width)/10
  newC = 0 if newC < 0
  newC = 20 if newC > 20
  if newB != v.b || newC != v.c
    c.move('box2', 10*(v.b-newB), 10*(v.c-newC))
    v.b = newB
    v.c = newC
  end
end

#arrowMove3(c, x, y) ⇒ Object

arrowMove3 – This method is called for each mouse motion event on box3 (the one that controls the thickness of the line). It updates the controlling parameters for the line and arrowhead.

Arguments: c - The name of the canvas window. x, y - The coordinates of the mouse.



239
240
241
242
243
244
245
246
247
248
# File 'sample/demos-en/arrow.rb', line 239

def arrowMove3(c,x,y)
  v = $demo_arrowInfo
  newWidth = (v.y+2-c.canvasy(y).round)/5
  newWidth = 0 if newWidth < 0
  newWidth = 20 if newWidth > 20
  if newWidth != v.width
    c.move('box3', 0, 5*(v.width-newWidth))
    v.width = newWidth
  end
end

#arrowSetup(c) ⇒ Object

arrowSetup – This method regenerates all the text and graphics in the canvas window. It’s called when the canvas is initially created, and also whenever any of the parameters of the arrow head are changed interactively.

Arguments: c - Name of the canvas widget.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'sample/demos-en/arrow.rb', line 18

def arrowSetup(c)
  v = $demo_arrowInfo

  # Remember the current box, if there is one.
  tags = c.gettags('current')
  if tags != []
    cur = tags.find{|t| t.kind_of?(String) && t =~ /^box[1-3]$/ }
  else
    cur = nil
  end

  # Create the arrow and outline.
  c.delete('all')
  TkcLine.new(c, v.x1, v.y, v.x2, v.y,
              { 'width'=>10 * v.width,
                'arrowshape'=>[10*v.a, 10*v.b, 10*v.c],
                'arrow'=>'last'
              }.update(v.bigLineStyle) )
  xtip = v.x2 - 10*v.b
  deltaY = 10*v.c + 5*v.width
  TkcLine.new(c, v.x2, v.y, xtip, v.y + deltaY,
              v.x2 - 10*v.a, v.y, xtip, v.y - deltaY, v.x2, v.y,
              'width'=>2, 'capstyle'=>'round', 'joinstyle'=>'round')

  # Create the boxes for reshaping the line and arrowhead.
  TkcRectangle.new(c, v.x2-10*v.a-5, v.y-5, v.x2-10*v.a+5, v.y+5,
                   {'tags'=>['box1', $arrowTag_box]}.update(v.boxStyle) )
  TkcRectangle.new(c, xtip-5, v.y-deltaY-5, xtip+5, v.y-deltaY+5,
                   {'tags'=>['box2', $arrowTag_box]}.update(v.boxStyle) )
  TkcRectangle.new(c, v.x1-5, v.y-5*v.width-5, v.x1+5, v.y-5*v.width+5,
                   {'tags'=>['box3', $arrowTag_box]}.update(v.boxStyle) )
  c.itemconfigure cur, v.activeStyle if cur

  # Create three arrows in actual size with the same parameters
  TkcLine.new(c, v.x2+50, 0, v.x2+50, 1000, 'width'=>2)
  tmp = v.x2+100
  TkcLine.new(c, tmp, v.y-125, tmp, v.y-75, 'width'=>v.width,
              'arrow'=>'both', 'arrowshape'=>[v.a, v.b, v.c])
  TkcLine.new(c, tmp-25, v.y, tmp+25, v.y, 'width'=>v.width,
              'arrow'=>'both', 'arrowshape'=>[v.a, v.b, v.c])
  TkcLine.new(c, tmp-25, v.y+75, tmp+25, v.y+125, 'width'=>v.width,
              'arrow'=>'both', 'arrowshape'=>[v.a, v.b, v.c])

  # Create a bunch of other arrows and text items showing the
  # current dimensions.
  tmp = v.x2+10
  TkcLine.new(c, tmp, v.y-5*v.width, tmp, v.y-deltaY,
              'arrow'=>'both', 'arrowshape'=>v.smallTips)
  TkcText.new(c, v.x2+15, v.y-deltaY+5*v.c, 'text'=>v.c, 'anchor'=>'w')
  tmp = v.x1-10
  TkcLine.new(c, tmp, v.y-5*v.width, tmp, v.y+5*v.width,
              'arrow'=>'both', 'arrowshape'=>v.smallTips)
  TkcText.new(c, v.x1-15, v.y, 'text'=>v.width, 'anchor'=>'e')
  tmp = v.y+5*v.width+10*v.c+10
  TkcLine.new(c, v.x2-10*v.a, tmp, v.x2, tmp,
              'arrow'=>'both', 'arrowshape'=>v.smallTips)
  TkcText.new(c, v.x2-5*v.a, tmp+5, 'text'=>v.a, 'anchor'=>'n')
  tmp = tmp+25
  TkcLine.new(c, v.x2-10*v.b, tmp, v.x2, tmp,
              'arrow'=>'both', 'arrowshape'=>v.smallTips)
  TkcText.new(c, v.x2-5*v.b, tmp+5, 'text'=>v.b, 'anchor'=>'n')

  if $tk_version =~ /^4.*/
    TkcText.new(c, v.x1, 310, 'text'=>"'width'=>#{v.width}", 'anchor'=>'w',
                'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
    TkcText.new(c, v.x1, 330,
                'text'=>"'arrowshape'=>[#{v.a}, #{v.b}, #{v.c}]",'anchor'=>'w',
                'font'=>'-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*')
  else
    TkcText.new(c, v.x1, 310, 'text'=>"'width'=>#{v.width}", 'anchor'=>'w',
                'font'=>'Helvetica 18')
    TkcText.new(c, v.x1, 330,
                'text'=>"'arrowshape'=>[#{v.a}, #{v.b}, #{v.c}]",
                'anchor'=>'w', 'font'=>'Helvetica 18')
  end

  v.count += 1
end

#base_frameObject

See Code / Dismiss buttons



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'sample/demos-en/tree.rb', line 37

Ttk::Frame.new(base_frame) {|frame|
  sep = Ttk::Separator.new(frame)
  Tk.grid(sep, :columnspan=>4, :row=>0, :sticky=>'ew', :pady=>2)
  TkGrid('x',
         Ttk::Button.new(frame, :text=>'See Code',
                         :image=>$image['view'], :compound=>:left,
                         :command=>proc{showCode 'tree'}),
         Ttk::Button.new(frame, :text=>'Dismiss',
                         :image=>$image['delete'], :compound=>:left,
                         :command=>proc{
                           $tree_demo.destroy
                           $tree_demo = nil
                         }),
         :padx=>4, :pady=>4)
  grid_columnconfigure(0, :weight=>1)
  pack(:side=>:bottom, :fill=>:x)
}

#bitmapRow(w, *args) ⇒ Object

bitmapRow – Create a row of bitmap items in a window.

Arguments: w - The parent window that is to contain the row. args - The names of one or more bitmaps, which will be displayed

in a new row across the bottom of w along with their
names.


17
18
19
20
21
22
23
24
25
26
27
28
# File 'sample/demos-en/bitmap.rb', line 17

def bitmapRow(w,*args)
  TkFrame.new(w){|row|
    pack('side'=>'top', 'fill'=>'both')
    for bitmap in args
      TkFrame.new(row){|base|
        pack('side'=>'left', 'fill'=>'both', 'pady'=>'.25c', 'padx'=>'.25c')
        TkLabel.new(base, 'text'=>bitmap, 'width'=>9).pack('side'=>'bottom')
        Tk::Label.new(base, 'bitmap'=>bitmap).pack('side'=>'bottom')
      }
    end
  }
end

#browse(dir, file) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'sample/tkbrowse.rb', line 52

def browse (dir, file)
  file="#{dir}/#{file}"
  if File.directory? file
    browsedir(file)
  else
    if File.file? file
      if ENV['EDITOR']
        system format("%s %s&", ENV['EDITOR'], file)
      else
        system "xedit #{file}&"
      end
    else
      STDERR.print "\"#{file}\" isn't a directory or regular file"
    end
  end
end

#browsedir(dir) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'sample/tkbrowse.rb', line 19

def browsedir (dir)
  if $dirlist.key? dir
    $dirlist[dir]
  else
    top = if $dirlist.size > 0 then TkToplevel.new else nil end
    list = TkScrollbox.new(top) {
      relief 'raised'
      width 20
      height 20
      setgrid 'yes'
      pack
    }
    list.insert 'end', *`ls #{dir}`.split

    # Set up bindings for the browser.

    list.focus
    list.bind "Control-q", proc{exit}
    list.bind "Control-c", proc{exit}
    list.bind "Control-p", proc{
      print "selection <", TkSelection.get, ">\n"
    }

    list.bind "Double-Button-1", proc{
      for i in TkSelection.get.split
        print "clicked ", i, "\n"
        browse dir, i
      end
    }
    $dirlist[dir] = list
  end
end

#butPress(w, color) ⇒ Object

Method that’s invoked when the button embedded in the canvas is invoked.



375
376
377
378
379
# File 'sample/demos-jp/items.rb', line 375

def butPress(w,color)
  i = TkcText.new(w, '25c', '18.1c',
                  'text'=>'いてて!!', 'fill'=>color, 'anchor'=>'n')
  Tk.after(500, proc{w.delete i})
end

#changepage(tbl_list, tbl, ent, col, var, elem, op) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'sample/tkextlib/tktable/spreadsheet.rb', line 44

def changepage(tbl_list, tbl, ent, col, var, elem, op)
  if elem != ''
    page = var[elem]
  else
    page = var.value
  end
  if tbl[:variable] != tbl_list[page].id
    tbl.selection_clear_all
    tbl.variable(tbl_list[page])
    ent.textvariable(tbl_list[page].ref('active'))
    tbl.activate('origin')
    tbl.tag_configure('colored', :bg=>col[page])
    tbl.see('active')
  end
end

#changeState(st) ⇒ Object



945
946
947
948
949
950
951
952
953
# File 'sample/tkextlib/tile/demo.rb', line 945

def changeState(st)
  if $Widget.value != ''
    if $State.bool_element(st)
      $Widget.window.ttk_state(st)
    else
      $Widget.window.ttk_state("!#{st}")
    end
  end
end

#changeToolbarsObject



291
292
293
294
295
296
297
298
299
# File 'sample/tkextlib/tile/demo.rb', line 291

def changeToolbars
  foreachWidget($TOOLBARS,
                proc{|w|
                  begin
                    w.compound($V[:COMPOUND])
                  rescue
                  end
                })
end

#checkObject



100
101
102
103
104
105
106
107
108
# File 'sample/tkbiff.rb', line 100

def check
  $check_time = Time.now
  size = File.size($spool)
  if size and size != $spool_size
    $spool_size = size
    pop_up if size > 0
  end
  Tk.after 5000, proc{check}
end

#check_NG_path(path_list) ⇒ Object



984
985
986
987
988
989
# File 'extconf.rb', line 984

def check_NG_path(path_list)
  path_list.find_all{|path|
    not (TkLib_Config["tcl-NG-path"].include?(path) &&
         TkLib_Config["tk-NG-path"].include?(path))
  }
end

#check_pkg(file, verbose = false) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/tkextlib/pkg_checker.rb', line 91

def check_pkg(file, verbose=false)
  pkg_list = get_pkg_list(file)

  error_list = []
  success_list = {}

  pkg_list.each{|name, type|
    next if success_list[name]

    begin
      case type
      when :package
        ver = TkPackage.require(name)
        success_list[name] = ver
        error_list.delete_if{|n, t| n == name}

      when :library
        Tk.load_tcllibrary(name)
        success_list[name] = :library
        error_list.delete_if{|n, t| n == name}

      when :script
        Tk.load_tclscript(name)
        success_list[name] = :script
        error_list.delete_if{|n, t| n == name}

      when :require_ruby_lib
        require name

      end
    rescue => e
      if verbose
        error_list << [name, type, e.message]
      else
        error_list << [name, type]
      end
    end
  }

  success_list.dup.each{|name, ver|
    unless ver.kind_of?(String)
      begin
        ver = TkPackage.require(name)
        sccess_list[name] = ver
      rescue
      end
    end
  }

  [success_list, error_list]
end

#check_shlib_search_path(paths) ⇒ Object



991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
# File 'extconf.rb', line 991

def check_shlib_search_path(paths)
  if !paths || paths.empty?
    path_list = []

    #if TkLib_Config["ActiveTcl"]
    #  path_list.concat Dir.glob(TkLib_Config["ActiveTcl"], File::FNM_CASEFOLD).sort.reverse
    #end
    if TkLib_Config["ActiveTcl"].kind_of?(String)  # glob path
      path_list.concat Dir.glob(TkLib_Config["ActiveTcl"], File::FNM_CASEFOLD).sort.reverse
    end

    vers = get_shlib_versions
    path_head, path_dirs = get_shlib_path_head

    path_list.concat vers.map{|ver|
      path_head.map{|head|
        if ver.empty?
          head + "/lib"
        else
          dirs = []

          if Dir.glob(head, File::FNM_CASEFOLD).find{|dir| dir == head}
            dirs << head + "/lib"
          end

          if !Dir.glob(head + "-*", File::FNM_CASEFOLD).empty?
            dirs << head + "-#{ver}/lib" if !Dir.glob(head + "-[89].*", File::FNM_CASEFOLD).empty?
            dirs << head + "-#{ver.delete('.')}/lib" if !Dir.glob(head + "-[89][0-9]*", File::FNM_CASEFOLD).empty?
          end

          if !Dir.glob(head + "[_-]*", File::FNM_CASEFOLD).empty?
            dirs << head + "_#{ver}/lib" if !Dir.glob(head + "_[89].*", File::FNM_CASEFOLD).empty?
            dirs << head + "-#{ver}/lib" if !Dir.glob(head + "-[89].*", File::FNM_CASEFOLD).empty?
            dirs << head + "_#{ver.delete('.')}/lib" if !Dir.glob(head + "_[89][0-9]*", File::FNM_CASEFOLD).empty?
            dirs << head + "-#{ver.delete('.')}/lib" if !Dir.glob(head + "-[89][0-9]*", File::FNM_CASEFOLD).empty?
          end

          dirs
        end
      }
    }.flatten!

    path_list.concat path_dirs

  else
    # paths is a string with PATH environment style
    path_list = paths.split((is_win32?)? ';': ':')
  end

  path_list = check_NG_path(path_list)
  path_list.map!{|path| path.strip}

  if !CROSS_COMPILING and (is_win32? || is_macosx?)
    # exist-dir only
    path_list.delete_if{|path| Dir.glob(File.join(path, "*.{a,so,dll,lib}")).empty?}
  end

  # keep paths for searching dynamic libs
  #$LIBPATH |= path_list
  path_list.uniq
end

#check_tcl_NG_path(path_list) ⇒ Object



976
977
978
# File 'extconf.rb', line 976

def check_tcl_NG_path(path_list)
  path_list.find_all{|path| not TkLib_Config["tcl-NG-path"].include?(path) }
end

#check_tcltk_version(version) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'extconf.rb', line 129

def check_tcltk_version(version)
  return [nil, nil] unless version.kind_of? String

  tclver, tkver = version.split(',')
  tclver = tclver.strip
  return [tclver, tkver.strip] if tkver

  dot = major = minor_dot = minor = plvl_dot = plvl = ext = nil
  if tclver =~ /^(\d)(\.?)(\d)(\.?)(\d*)(.*)$/
    major = $1; minor_dot = $2; minor = $3; plvl_dot = $4; plvl = $5; ext = $6
    dot = ! minor_dot.empty?
    if plvl_dot.empty? && ! plvl.empty?
      minor << plvl
    end
  elsif tclver =~ /^(\d)(\.?)(\d?)(.*)$/
    major = $1; minor_dot = $2; minor = $3; ext = $4
    dot = ! minor_dot.empty?
  else # unknown -> believe user
    return [tclver, tkver]
  end

  # check Tcl7.6 / Tk4.2 ?
  if major == "7" # Tcl7.6 ( not support Tclversion < 7.6 )
    # Tk4.2
    tkver  = "4" + ((dot)? ".": "") + ((minor.empty)? "": "2") + ext
  elsif major == "4" # Tk4.2 ( not support Tkversion < 4.2 )
    # Tcl7.6
    tkver = tclver
    tclver = "7" + ((dot)? ".": "") + ((minor.empty)? "": "6") + ext
  end

  tkver = tclver unless tkver

  [tclver, tkver]
end

#check_tk_NG_path(path_list) ⇒ Object



980
981
982
# File 'extconf.rb', line 980

def check_tk_NG_path(path_list)
  path_list.find_all{|path| not TkLib_Config["tk-NG-path"].include?(path) }
end

#collect_tcltk_defs(tcl_defs_str, tk_defs_str) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'extconf.rb', line 336

def collect_tcltk_defs(tcl_defs_str, tk_defs_str)
  conflicts = [
    'PACKAGE_NAME', 'PACKAGE_TARNAME', 'PACKAGE_VERSION',
    'PACKAGE_STRING', 'PACKAGE_BUGREPORT'
  ]

  begin
    # Ruby 1.9.x or later
    arch_config_h = RbConfig.expand($arch_hdrdir + "/ruby/config.h")
    if File.exist?(arch_config_h)
      keys = []
      IO.foreach(arch_config_h){|line|
        if line =~ /^#define +([^ ]+)/
            keys << $1
        end
      }
      conflicts = keys
    end
  rescue
    # ignore, use default
  end

  if tcl_defs_str
    tcl_defs = tcl_defs_str.split(/ ?-D/).map{|s|
      s =~ /^([^=]+)(.*)$/
      [$1, $2]
    }
  else
    tcl_defs = []
  end

  if tk_defs_str
    tk_defs = tk_defs_str.split(/ ?-D/).map{|s|
      s =~ /^([^=]+)(.*)$/
      [$1, $2]
    }
  else
    tk_defs = []
  end

  defs = tcl_defs | tk_defs

  defs.delete_if{|name,value|
    conflicts.include?(name) ||
      ( (vtcl = tcl_defs.assoc(name)) && (vtk = tk_defs.assoc(name)) &&
          vtcl != vtk )
  }

  defs.map{|ary| s = ary.join(''); (s.strip.empty?)? "": "-D" << s}
end

#colorize(num) ⇒ Object



16
17
18
19
# File 'sample/tkextlib/tktable/valid.rb', line 16

def colorize(num)
  num = Integer(num)
  return 'colored' if (num > 0 && num % 2 == 1)
end

#compareOnOff(w, c, item1, item2) ⇒ Object

TreeCtrl 1.0



258
259
260
261
262
263
264
265
266
267
268
# File 'sample/tkextlib/treectrl/mailwasher.rb', line 258

def compareOnOff(w, c, item1, item2)
  s1 = w.item_state_forcolumn(item1, c)
  s2 = w.item_state_forcolumn(item2, c)
  if (s1 == s2)
    0
  elsif (s1 == 'CHECK')
    -1
  else
    1
  end
end

#countObject

Now set up the GUI



65
# File 'sample/demos-jp/textpeer.rb', line 65

makeClone(count, base_frame, first)

#cursor_window(top = nil) ⇒ Object



1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
# File 'sample/tkextlib/treectrl/demo.rb', line 1146

def cursor_window(top = nil)
  top.destroy if top.kind_of?(TkWindow) && top.winfo_exist?
  top = TkToplevel.new(:title=>'Cursor Window')

  c = TkCanvas.new(top, :background=>'white',
                   :width=>50*10, :highlightthickness=>0,
                   :borderwidth=>0).pack(:expand=>true, :fill=>:both)
  cursors = %w(
	X_cursor
	arrow
	based_arrow_down
	based_arrow_up
	boat
	bogosity
	bottom_left_corner
	bottom_right_corner
	bottom_side
	bottom_tee
	box_spiral
	center_ptr
	circle
	clock
	coffee_mug
	cross
	cross_reverse
	crosshair
	diamond_cross
	dot
	dotbox
	double_arrow
	draft_large
	draft_small
	draped_box
	exchange
	fleur
	gobbler
	gumby
	hand1
	hand2
	heart
	icon
	iron_cross
	left_ptr
	left_side
	left_tee
	leftbutton
	ll_angle
	lr_angle
	man
	middlebutton
	mouse
	pencil
	pirate
	plus
	question_arrow
	right_ptr
	right_side
	right_tee
	rightbutton
	rtl_logo
	sailboat
	sb_down_arrow
	sb_h_double_arrow
	sb_left_arrow
	sb_right_arrow
	sb_up_arrow
	sb_v_double_arrow
	shuttle
	sizing
	spider
	spraycan
	star
	target
	tcross
	top_left_arrow
	top_left_corner
	top_right_corner
	top_side
	top_tee
	trek
	ul_angle
	umbrella
	ur_angle
	watch
	xterm
    )

  orig_cursor = c.cursor
  col = 0
  row = 0

  cursors.each{|cur|
    x = col * 50
    y = row * 40

    begin
      c.cursor = cur

      r = TkcRectangle.new(c, x, y, x+50, y+40,
                           :fill=>'gray90', :outline=>'black', :width=>2)
      t = TkcText.new(c, x+50/2, y+4, :text=>cur, :anchor=>:n, :width=>42)

      col += 1
      if col >= 10
        col = 0
        row += 1
      end

      r.bind('Enter', proc{c.cursor = cur; r.fill = 'linen'})
      r.bind('Leave', proc{c.cursor = ''; r.fill = 'gray90'})

      t.bind('Enter', proc{c.cursor = cur})
      t.bind('Leave', proc{c.cursor = ''})
    rescue
      c.cursor = orig_cursor
    end
  }

  c.cursor = orig_cursor
  c.height = (row + 1) * 40
end

#def_puzzleswitch_proc(w, num) ⇒ Object

proc のスコープを閉じるため,proc 生成メソッドを用意 こうしておかねば,ループ中で値が変化する num の影響を受けて puzzleSwitch の第 2 引数が変化してしまい,期待通りにはならない.



87
88
89
# File 'sample/demos-jp/puzzle.rb', line 87

def def_puzzleswitch_proc(w, num)
  proc{puzzleSwitch w, num}
end

#demoBitmaps(t) ⇒ Object

Demo: Bitmaps



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'sample/tkextlib/treectrl/bitmaps.rb', line 4

def demoBitmaps(t)
  #if $Version_1_1_OrLater
  if @has_bgimg
    t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
                :selectmode=>:browse, :orient=>:horizontal, :wrap=>'5 items',
                :showheader=>false, :backgroundimage=>@images['sky'])
  else
    t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
                :selectmode=>:browse, :orient=>:horizontal, :wrap=>'5 items',
                :showheader=>false)
  end

  if $HasColumnCreate
    t.column_create(:itembackground=>['gray90', []])
  else
    t.column_configure(0, :itembackground=>['gray90', []])
  end

  t.element_create('elemTxt', :text,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']])
  t.element_create('elemSelTxt', :rect, :showfocus=>true,
                   :fill=>[@SystemHighlight, ['selected', 'focus']])
  t.element_create('elemSelBmp', :rect, :outlinewidth=>4,
                   :outline=>[@SystemHighlight, ['selected', 'focus']])
  t.element_create('elemBmp', :bitmap,
                   :foreground=>[@SystemHighlight, ['selected', 'focus']],
                   :background=>'linen',
                   :bitmap=>['question' ['selected']])

  s = t.style_create('STYLE', :orient=>:vertical)
  t.style_elements(s, ['elemSelBmp', 'elemBmp', 'elemSelTxt', 'elemTxt'])
  t.style_layout(s, 'elemSelBmp', :union=>'elemBmp', :ipadx=>6, :ipady=>6)
  t.style_layout(s, 'elemBmp',    :pady=>[0, 6], :expand=>:we)
  t.style_layout(s, 'elemSelTxt', :union=>'elemTxt', :ipadx=>2)
  t.style_layout(s, 'elemTxt',    :expand=>:we)

  # Set default item style
  if $Version_1_1_OrLater
    t.defaultstyle = [s]
  end

  bitmap_names = %w(error gray75 gray50 gray25 gray12
                    hourglass info questhead question warning)

  bitmap_names.each{|name|
    i = t.item_create
    unless $Version_1_1_OrLater
      t.item_style_set(i, 0, s)
    end
    t.item_text(i, 0, name)
    t.item_element_configure(i, 0, 'elemBmp', :bitmap=>name)
    t.item_lastchild(:root, i)
  }

  bitmap_names.each{|name|
    i = t.item_create
    t.item_style_set(i, 0, s)
    t.item_text(i, 0, name)
    if true
      t.item_element_configure(i, 0, 'elemBmp', :bitmap=>name,
                               :foreground=>['brown', ''],
                               :background=>['', ''])
    else
      t.item_element_configure(i, 0, 'elemBmp', :bitmap=>name,
                               :foreground=>[
                                 @SystemHighlight, ['selected', 'focus'],
                                 'brown', []
                               ],
                               :background=>['', []])
    end
    t.item_lastchild(:root, i)
  }
end

#demoExplorerAux(t, dir_proc, file_proc) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'sample/tkextlib/treectrl/explorer.rb', line 2

def demoExplorerAux(t, dir_proc, file_proc)
  base_dir = File.dirname(File.dirname(@ScriptDir))

  clicks = Tk::Clock.clicks
  globDirs = Dir.glob(File.join(base_dir, '*')).find_all{|file|
    FileTest.directory?(file)
  }
  clickGlobDirs = Tk::Clock.clicks - clicks

  clicks = Tk::Clock.clicks
  list = globDirs.sort
  clickSortDirs = Tk::Clock.clicks - clicks

  clicks = Tk::Clock.clicks
  list.each{|file| dir_proc.call(file)}
  clickAddDirs = Tk::Clock.clicks - clicks

  clicks = Tk::Clock.clicks
  globFiles = Dir.glob(File.join(base_dir, '*')).find_all{|file|
    FileTest.file?(file)
  }
  clickGlobFiles = Tk::Clock.clicks - clicks

  clicks = Tk::Clock.clicks
  list = globFiles.sort
  clickSortFiles = Tk::Clock.clicks - clicks

  clicks = Tk::Clock.clicks
  list.each{|file| file_proc.call(file)}
  clickAddFiles = Tk::Clock.clicks - clicks

  gd = '%.2g' % (clickGlobDirs / 1000000.0)
  sd = '%.2g' % (clickSortDirs / 1000000.0)
  ad = '%.2g' % (clickAddDirs  / 1000000.0)
  gf = '%.2g' % (clickGlobFiles / 1000000.0)
  sf = '%.2g' % (clickSortFiles / 1000000.0)
  af = '%.2g' % (clickAddFiles  / 1000000.0)

  puts "dirs(#{globDirs.length}) glob/sort/add #{gd}/#{sd}/#{ad}    files(#{globFiles.length}) glob/sort/add #{gf}/#{sf}/#{af}"

  @Priv[:DirCnt, t] = globDirs.length
end

#demoExplorerDetails(t) ⇒ Object

Demo: explorer files



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'sample/tkextlib/treectrl/explorer.rb', line 48

def demoExplorerDetails(t)
  height = t.font.metrics(:linespace)
  height = 18 if height < 18

  t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
              :itemheight=>height, :selectmode=>:extended,
              :xscrollincrement=>20, :scrollmargin=>16,
              :xscrolldelay=>[500, 50], :yscrolldelay=>[500, 50])

  init_pics('small-*')

  if $HasColumnCreate
    t.column_create(:text=>'Name', :tag=>'name',
                    :width=>200, :arrow=>:up, :arrowpad=>6)
    t.column_create(:text=>'Size', :tag=>'size', :justify=>:right,
                    :width=>60, :arrowside=>:left, :arrowgravity=>:right)
    t.column_create(:text=>'Type', :tag=>'type', :width=>120)
    t.column_create(:text=>'Modified', :tag=>'modified', :width=>130)
  else
    t.column_configure(0, :text=>'Name', :tag=>'name',
                       :width=>200, :arrow=>:up, :arrowpad=>6)
    t.column_configure(1, :text=>'Size', :tag=>'size', :justify=>:right,
                       :width=>60, :arrowside=>:left, :arrowgravity=>:right)
    t.column_configure(2, :text=>'Type', :tag=>'type', :width=>120)
    t.column_configure(3, :text=>'Modified', :tag=>'modified', :width=>130)
  end

  t.element_create('e1', :image,
                   :image=>[
                     @sel_images['small-folder'], ['selected'],
                     @images['small-folder'], []
                   ])
  t.element_create('e2', :text, :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']])
  t.element_create('txtType', :text, :lines=>1)
  t.element_create('txtSize', :text, :lines=>1,
                   :datatype=>:integer, :format=>'%dKB')
  t.element_create('txtDate', :text, :lines=>1,
                   :datatype=>:time, :format=>'%d/%m/%y %I:%M %p')
  t.element_create('e4', :rect, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray', ['selected', '!focus']
                   ])

  # image + text
  s = t.style_create('styName', :orient=>:horizontal)
  t.style_elements(s, ['e4', 'e1', 'e2'])
  t.style_layout(s, 'e1', :expand=>:ns)
  t.style_layout(s, 'e2', :padx=>[2,0], :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'e4', :union=>['e2'], :iexpand=>:ns, :ipadx=>2)

  # column 1: text
  s = t.style_create('stySize')
  t.style_elements(s, ['txtSize'])
  t.style_layout(s, 'txtSize', :padx=>6, :squeeze=>:x, :expand=>:ns)

  # column 2: text
  s = t.style_create('styType')
  t.style_elements(s, ['txtType'])
  t.style_layout(s, 'txtType', :padx=>6, :squeeze=>:x, :expand=>:ns)

  # column 3: text
  s = t.style_create('styDate')
  t.style_elements(s, ['txtDate'])
  t.style_layout(s, 'txtDate', :padx=>6, :squeeze=>:x, :expand=>:ns)

  @Priv[:edit, t] = ['e2']
  @Priv[:sensitive, t] = [ ['name', 'styName', 'e1', 'e2'] ]
  @Priv[:dragimage, t] = [ ['name', 'styName', 'e1', 'e2'] ]

  t.notify_bind(t, 'Edit-accept',
                proc{|w, i, tt| w.item_text(i, 0, tt)}, '%T %I %t')

  dir_proc = proc{|file|
    item = t.item_create
    t.item_style_set(item, 0, 'styName', 2, 'styType', 3, 'styDate')
    t.item_complex(item,
                   [['e2', {:text=>File.basename(file)}]],
                   [],
                   [['txtType', {:text=>'Folder'}]],
                   [['txtDate', {:data=>File.mtime(file).tv_sec}]])
    t.item_lastchild(:root, item)
  }

  file_proc = proc{|file|
    item = t.item_create
    t.item_style_set(item, 0, 'styName', 1, 'stySize',
                           2, 'styType', 3, 'styDate')

    ext = File.extname(file)
    case ext
    when '.dll'
      img = 'small-dll'
    when '.exe'
      img = 'small-exe'
    when '.txt'
      img = 'small-txt'
    else
      img = 'small-file'
    end

    type = ext.upcase
    type = type[1..-1] << ' ' unless type.empty?
    type << 'File'

    t.item_complex(item,
                   [
                     ['e1', {:image=>[@sel_images[img], ['selected'],
                                      @images[img], []]}],
                     ['e2', {:text=>File.basename(file)}]
                   ],
                   [ ['txtSize', {:data=>File.size(file)/1024 + 1}] ],
                   [ ['txtType', {:text=>type}] ],
                   [ ['txtDate', {:data=>File.mtime(file).tv_sec}] ]
                   )
    t.item_lastchild(:root, item)
  }

  demoExplorerAux(t, dir_proc, file_proc)

  @SortColumn = 0
  t.notify_bind(t, 'Header-invoke',
                proc{|w, c| explorerHeaderInvoke(t, w, c)}, '%T %C')

  t.bindtags = [ t, 'TreeCtrlFileList', Tk::TreeCtrl, t.winfo_toplevel, :all ]
end

#demoExplorerLargeIcons(t) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'sample/tkextlib/treectrl/explorer.rb', line 240

def demoExplorerLargeIcons(t)
  # Item height is 32 for icon, 4 padding, 3 lines of text
  itemHeight = 32 + 4 + t.font.metrics(:linespace) * 3

  t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
              :selectmode=>:extended, :wrap=>:window, :orient=>:horizontal,
              :itemheight=>itemHeight, :showheader=>false, :scrollmargin=>16,
              :xscrolldelay=>[500, 50], :yscrolldelay=>[500, 50])

  init_pics('big-*')

  if $HasColumnCreate
    t.column_create(:width=>75)
  else
    t.column_configure(0, :width=>75)
  end

  t.element_create('elemImg', :image,
                   :image=>[
                     @sel_images['big-folder'], ['selected'],
                     @images['big-folder'], []
                   ])
  t.element_create('elemTxt', :text, :justify=>:center,
                   :lines=>1, :width=>71, :wrap=>:word,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']])
  t.element_create('elemSel', :rect, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray', ['selected']
                   ])

  # image + text
  s = t.style_create('STYLE', :orient=>:vertical)
  t.style_elements(s, ['elemSel', 'elemImg', 'elemTxt'])
  t.style_layout(s, 'elemImg', :expand=>:we)
  t.style_layout(s, 'elemTxt',
                 :pady=>[4,0], :padx=>2, :squeeze=>:x, :expand=>:we)
  t.style_layout(s, 'elemSel', :union=>['elemTxt'])

  @Priv[:edit, t] = ['elemTxt']
  @Priv[:sensitive, t] = [ [0, 'STYLE', 'elemImg', 'elemTxt'] ]
  @Priv[:dragimage, t] = [ [0, 'STYLE', 'elemImg', 'elemTxt'] ]

  t.notify_bind(t, 'Edit-accept',
                proc{|w, i, tt| w.item_text(i, 0, tt)}, '%T %I %t')

  dir_proc = proc{|file|
    item = t.item_create
    t.item_style_set(item, 0, 'STYLE')
    t.item_text(item, 0, File.basename(file))
    t.item_lastchild(:root, item)
  }

  file_proc = proc{|file|
    item = t.item_create
    t.item_style_set(item, 0, 'STYLE')

    ext = File.extname(file)
    case ext
    when '.dll'
      img = 'big-dll'
    when '.exe'
      img = 'big-exe'
    when '.txt'
      img = 'big-txt'
    else
      img = 'big-file'
    end

    type = ext.upcase
    type = type[1..-1] << ' ' unless type.empty?
    type << 'File'

    t.item_complex(item,
                   [
                     ['elemImg', {:image=>[@sel_images[img], ['selected'],
                                           @images[img], []]}],
                     ['elemTxt', {:text=>File.basename(file)}]
                   ])
    t.item_lastchild(:root, item)
  }

  demoExplorerAux(t, dir_proc, file_proc)

  t.activate(t.index('root firstchild'))

  t.notify_bind(t, 'ActiveItem',
                proc{|w, a, c|
                  w.item_element_configure(a, 0, 'elemTxt', :lines=>'')
                  w.item_element_configure(c, 0, 'elemTxt', :lines=>3)
                }, '%T %p %c')

  t.bindtags = [ t, 'TreeCtrlFileList', Tk::TreeCtrl, t.winfo_toplevel, :all ]
end

#demoExplorerList(t) ⇒ Object

Tree is vertical, wrapping occurs at bottom of window, each range has the same width (as wide as the longest item), xscrollincrement is by range



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'sample/tkextlib/treectrl/explorer.rb', line 345

def demoExplorerList(t)
  height = t.font.metrics(:linespace) + 2
  height = 18 if height < 18

  t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
              :itemheight=>height, :selectmode=>:extended, :wrap=>:window,
              :showheader=>false, :scrollmargin=>16,
              :xscrolldelay=>[500, 50], :yscrolldelay=>[500, 50])

  init_pics('small-*')

  if $HasColumnCreate
    t.column_create(:widthhack=>true)
  else
    t.column_configure(0, :widthhack=>true)
  end

  t.element_create('elemImg', :image,
                   :image=>[
                     @sel_images['small-folder'], ['selected'],
                     @images['small-folder'], []
                   ])
  t.element_create('elemTxt', :text, :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']])
  t.element_create('elemSel', :rect, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray', ['selected', '!focus']
                   ])

  # image + text
  s = t.style_create('STYLE')
  t.style_elements(s, ['elemSel', 'elemImg', 'elemTxt'])
  t.style_layout(s, 'elemImg', :expand=>:ns)
  t.style_layout(s, 'elemTxt', :squeeze=>:x, :expand=>:ns, :padx=>[2,0])
  t.style_layout(s, 'elemSel', :union=>['elemTxt'], :iexpand=>:ns, :ipadx=>2)

  @Priv[:edit, t] = ['elemTxt']
  @Priv[:sensitive, t] = [ [0, 'STYLE', 'elemImg', 'elemTxt'] ]
  @Priv[:dragimage, t] = [ [0, 'STYLE', 'elemImg', 'elemTxt'] ]

  t.notify_bind(t, 'Edit-accept',
                proc{|w, i, tt| w.item_text(i, 0, tt)}, '%T %I %t')

  dir_proc = proc{|file|
    item = t.item_create
    t.item_style_set(item, 0, 'STYLE')
    t.item_text(item, 0, File.basename(file))
    t.item_lastchild(:root, item)
  }

  file_proc = proc{|file|
    item = t.item_create
    t.item_style_set(item, 0, 'STYLE')

    ext = File.extname(file)
    case ext
    when '.dll'
      img = 'small-dll'
    when '.exe'
      img = 'small-exe'
    when '.txt'
      img = 'small-txt'
    else
      img = 'small-file'
    end

    type = ext.upcase
    type = type[1..-1] << ' ' unless type.empty?
    type << 'File'

    t.item_complex(item,
                   [
                     ['elemImg', {:image=>[@sel_images[img], ['selected'],
                                           @images[img], []]}],
                     ['elemTxt', {:text=>File.basename(file)}]
                   ])
    t.item_lastchild(:root, item)
  }

  demoExplorerAux(t, dir_proc, file_proc)

  t.activate(t.item_firstchild(:root))

  t.bindtags = [ t, 'TreeCtrlFileList', Tk::TreeCtrl, t.winfo_toplevel, :all ]
end

#demoExplorerSmallIcons(t) ⇒ Object

Tree is horizontal, wrapping occurs at right edge of window, each item is as wide as the smallest needed multiple of 110 pixels



337
338
339
340
341
# File 'sample/tkextlib/treectrl/explorer.rb', line 337

def demoExplorerSmallIcons(t)
  demoExplorerList(t)
  t.configure(:orient=>:horizontal, :xscrollincrement=>0)
  t.column_configure(0, :width=>'', :stepwidth=>110, :widthhack=>false)
end

#demoHelpContents(t) ⇒ Object

Demo: Help contents



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'sample/tkextlib/treectrl/help.rb', line 4

def demoHelpContents(t)
  height = t.font.metrics(:linespace)
  height = 18 if height < 18
  t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
              :itemheight=>height, :selectmode=>:browse)

  init_pics('help-*')

  if $Version_1_1_OrLater
    t.column_create(:text=>'Help Contents')
  else # TreeCtrl 1.0
    t.column_configure(0, :text=>'Help Contents')
  end

  # Define a new item state
  t.state_define('mouseover')

  t.element_create('e1', :image, :image=>@images['help-page'])
  t.element_create('e2', :image, :image=>[
                     @images['help-book-open'], ['open'],
                     @images['help-book-closed'], [],
                   ])
  t.element_create('e3', :text,
                   :font=>[t.font.dup.underline(true), ['mouseover']],
                   :fill=>[
                     @SystemHighlightText, ['selected', 'focus'],
                     'blue', ['mouseover']
                   ])
  t.element_create('e4', :rect, :showfocus=>true,
                   :fill=>[@SystemHighlight, ['selected', 'focus']])

  # book
  s = t.style_create('s1')
  t.style_elements(s, ['e4', 'e1', 'e3'])
  t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e3', :expand=>:ns)
  t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)

  # page
  s = t.style_create('s2')
  t.style_elements(s, ['e4', 'e2', 'e3'])
  t.style_layout(s, 'e2', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e3', :expand=>:ns)
  t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)

  parentList = [:root, '', '', '', '', '', '']
  parent = :root
  [
     [0, 's1', "Welcome to Help"],
     [0, 's2', "Introducing Windows 98"],
        [1, 's2', "How to Use Help"],
           [2, 's1', "Find a topic"],
           [2, 's1', "Get more out of help"],
        [1, 's2', "Register Your Software"],
           [2, 's1', "Registering Windows 98 online"],
        [1, 's2', "What's New in Windows 98"],
           [2, 's1', "Innovative, easy-to-use features"],
           [2, 's1', "Improved reliability"],
           [2, 's1', "A faster operating system"],
           [2, 's1', "True Web integration"],
           [2, 's1', "More entertaining and fun"],
        [1, 's2', "If You're New to Windows 98"],
           [2, 's2', "Tips for Macintosh Users"],
              [3, 's1', "Why does the mouse have two buttons?"]
  ].each{|depth, style, text|
    item = t.item_create
    t.item_style_set(item, 0, style)
    t.item_element_configure(item, 0, 'e3', :text=>text)
    if $Version_1_1_OrLater
      t.item_collapse(item)
    else # TreeCtrl 1.0
      t.collapse(item)
    end
    t.item_lastchild(parentList[depth], item)
    depth += 1
    parentList[depth] = item
  }

  treeCtrlHelp = TkBindTag.new

  treeCtrlHelp.bind('Double-ButtonPress-1',
                    proc{|w, x, y|
                      if w.identify(x, y)[0] == 'header'
                        Tk::TreeCtrl::BindCallback.doubleButton1(w, x, y)
                      else
                        helpButton1(w, x, y)
                      end
                      Tk.callback_break
                    }, '%W %x %y')

  treeCtrlHelp.bind('ButtonPress-1',
                    proc{|w, x, y|
                      helpButton1(w, x, y)
                      Tk.callback_break
                    }, '%W %x %y')

  treeCtrlHelp.bind('Button1-Motion',
                    proc{|w, x, y|
                      helpMotion1(w, x, y)
                      Tk.callback_break
                    }, '%W %x %y')

  treeCtrlHelp.bind('Button1-Leave',
                    proc{|w, x, y|
                      helpLeave1(w, x, y)
                      Tk.callback_break
                    }, '%W %x %y')

  treeCtrlHelp.bind('ButtonRelease-1',
                    proc{|w, x, y|
                      helpRelease1(w, x, y)
                      Tk.callback_break
                    }, '%W %x %y')

  treeCtrlHelp.bind('Motion', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y')

  treeCtrlHelp.bind('Leave', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y')

  treeCtrlHelp.bind('KeyPress-Return',
                    proc{|w, x, y|
                      if w.selection_get.length == 1
                        if $Version_1_1_OrLater
                          w.item_toggle(w.selection_get[0])
                        else # TreeCtrl 1.0
                          w.toggle(w.selection_get[0])
                        end
                      end
                      Tk.callback_break
                    }, '%W %x %y')

  @Priv[:help, :prev] = ''

  t.bindtags = [ t, treeCtrlHelp, Tk::TreeCtrl, t.winfo_toplevel, :all ]
end

#demoHelpContents2(t) ⇒ Object

This is an alternate implementation that does not define a new item state to change the appearance of the item under the cursor.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'sample/tkextlib/treectrl/help.rb', line 141

def demoHelpContents2(t)
  height = t.font.metrics(:linespace)
  height = 18 if height < 18
  t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
              :itemheight=>height, :selectmode=>:browse)

  init_pics('help-*')

  if $Version_1_1_OrLater
    t.column_create(:text=>'Help Contents')
  else # TreeCtrl 1.0
    t.column_configure(0, :text=>'Help Contents')
  end

  t.element_create('e1', :image, :image=>@images['help-page'])
  t.element_create('e2', :image, :image=>[
                     @images['help-book-open'], ['open'],
                     @images['help-book-closed'], [],
                   ])
  t.element_create('e3', :text,
                   :fill=>[
                     @SystemHighlightText, ['selected', 'focus'],
                     'blue', []
                   ])
  t.element_create('e4', :rect, :showfocus=>true,
                   :fill=>[@SystemHighligh, ['selected', 'focus']])
  t.element_create('e5', :text, :font=>t.font.dup.underline(true),
                   :fill=>[
                     @SystemHighlightText, ['selected', 'focus'],
                     'blue', []
                   ])

  # book
  s = t.style_create('s1')
  t.style_elements(s, ['e4', 'e1', 'e3'])
  t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e3', :expand=>:ns)
  t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)

  # page
  s = t.style_create('s2')
  t.style_elements(s, ['e4', 'e2', 'e3'])
  t.style_layout(s, 'e2', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e3', :expand=>:ns)
  t.style_layout(s, 'e4', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)

  # book (focus)
  s = t.style_create('s1.f')
  t.style_elements(s, ['e4', 'e1', 'e5'])
  t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e5', :expand=>:ns)
  t.style_layout(s, 'e4', :union=>['e5'], :iexpand=>:ns, :ipadx=>2)

  # page (focus)
  s = t.style_create('s2')
  t.style_elements(s, ['e4', 'e2', 'e5'])
  t.style_layout(s, 'e2', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e5', :expand=>:ns)
  t.style_layout(s, 'e4', :union=>['e5'], :iexpand=>:ns, :ipadx=>2)

  parentList = [:root, '', '', '', '', '', '']
  parent = :root
  [
     [0, 's1', "Welcome to Help"],
     [0, 's2', "Introducing Windows 98"],
        [1, 's2', "How to Use Help"],
           [2, 's1' "Find a topic"],
           [2, 's1', "Get more out of help"],
        [1, 's2', "Register Your Software"],
           [2, 's1', "Registering Windows 98 online"],
        [1, 's2', "What's New in Windows 98"],
           [2, 's1', "Innovative, easy-to-use features"],
           [2, 's1', "Improved reliability"],
           [2, 's1', "A faster operating system"],
           [2, 's1', "True Web integration"],
           [2, 's1', "More entertaining and fun"],
        [1, 's2', "If You're New to Windows 98"],
           [2, 's2', "Tips for Macintosh Users"],
              [3, 's1', "Why does the mouse have two buttons?"]
  ].each{|depth, style, text|
    item = t.item_create
    t.item_style_set(item, 0, style)
    t.item_element_configure(item, 0, 'e3', :text=>text)
    if $Version_1_1_OrLater
      t.item_collapse(item)
    else # TreeCtrl 1.0
      t.collapse(item)
    end
    t.item_lastchild(parentList[depth], item)
    depth += 1
    parentList[depth] = item
  }

  treeCtrlHelp = TkBindTag.new

  treeCtrlHelp.bind('Double-ButtonPress-1',
                    proc{|w, x, y|
                      if w.identify(x, y)[0] == 'header'
                        Tk::TreeCtrl::BindCallback.doubleButton1(w, x, y)
                      else
                        helpButton1(w, x, y)
                      end
                      Tk.callback_break
                    }, '%W %x %y')

  treeCtrlHelp.bind('ButtonPress-1',
                    proc{|w, x, y|
                      helpButton1(w, x, y)
                      Tk.callback_break
                    }, '%W %x %y')

  treeCtrlHelp.bind('Button1-Motion',
                    proc{|w, x, y|
                      helpMotion1(w, x, y)
                      Tk.callback_break
                    }, '%W %x %y')

  treeCtrlHelp.bind('Button1-Leave',
                    proc{|w, x, y|
                      helpLeave1(w, x, y)
                      Tk.callback_break
                    }, '%W %x %y')

  treeCtrlHelp.bind('ButtonRelease-1',
                    proc{|w, x, y|
                      helpRelease1(w, x, y)
                      Tk.callback_break
                    }, '%W %x %y')

  treeCtrlHelp.bind('Motion', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y')

  treeCtrlHelp.bind('Leave', proc{|w, x, y| helpMotion(w, x, y) }, '%W %x %y')

  treeCtrlHelp.bind('KeyPress-Return',
                    proc{|w, x, y|
                      if w.selection_get.length == 1
                        w.item_toggle(w.selection_get[0])
                      end
                      Tk.callback_break
                    }, '%W %x %y')

  @Priv[:help, :prev] = ''

  t.bindtags = [ t, treeCtrlHelp, Tk::TreeCtrl, t.winfo_toplevel, :all ]
end

#demoIMovie(t) ⇒ Object

Demo: iMovie



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'sample/tkextlib/treectrl/imovie.rb', line 4

def demoIMovie(t)
  t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
              :selectmode=>:browse, :orient=>:horizontal, :wrap=>:window,
              :showheader=>false, :background=>'#dcdcdc')

  if $HasColumnCreate
    t.column_create
  end

  init_pics('imovie-*')

  case @thisPlatform
  when 'macintosh', 'macosx'
    font1 = TkFont.new(['Geneva', 9])
    font2 = TkFont.new(['Geneva', 10])
  when 'unix'
    font1 = TkFont.new(['Helvetica', -12])
    font2 = TkFont.new(['Helvetica', -14])
  else
    font1 = TkFont.new(['Helvetica', 8])
    font2 = TkFont.new(['Helvetica', 10])
  end

  t.element_create('elemTime', :text, :font=>font1)
  t.element_create('elemName', :text, :font=>font2, :lines=>1, :width=>80)
  t.element_create('elemRect', :rect, :outline=>'#827878', :outlinewidth=>1,
                   :fill=>['#ffdc5a', ['selected'], 'white', []])
  t.element_create('elemImg', :image)
  t.element_create('elemShadow', :rect, :outline=>'gray', :outlinewidth=>1,
                   :open=>:wn)

  s = t.style_create('STYLE', :orient=>:vertical)
  t.style_elements(s, [
                     'elemShadow', 'elemRect', 'elemTime',
                     'elemImg', 'elemName'
                   ])
  t.style_layout(s, 'elemShadow', :detach=>true,
                 :padx=>[1,2], :pady=>[1,2], :iexpand=>:es)
  t.style_layout(s, 'elemTime', :padx=>[2,0])
  t.style_layout(s, 'elemImg', :pady=>[0,1])
  t.style_layout(s, 'elemName', :expand=>:we, :ipady=>[0,2], :padx=>[0,3],
                 :squeeze=>:x)
  t.style_layout(s, 'elemRect', :union=>['elemTime', 'elemImg', 'elemName'],
                 :ipadx=>6, :padx=>[0,3], :pady=>[0,3])

  # Set default item style
  if $Version_1_1_OrLater
    t.defaultstyle([s])
  end

  (0..4).each{|i|
    [
      ['15:20', 'Clip 1', @images['imovie-01']],
      ['19:18', 'Clip 2', @images['imovie-02']],
      ['07:20', 'Clip 3', @images['imovie-03']],
      ['07:20', 'Clip 4', @images['imovie-04']],
      ['07:20', 'Clip 5', @images['imovie-05']],
      ['07:20', 'Clip 6', @images['imovie-06']],
      ['07:20', 'Clip 7', @images['imovie-07']]
    ].each{|time, name, image|
      item = t.item_create
      unless $Version_1_1_OrLater
        t.item_style_set(item, 0, s)
      end
      t.item_element_configure(item, 0, 'elemTime', :text=>time)
      t.item_element_configure(item, 0, 'elemName', :text=>name)
      t.item_element_configure(item, 0, 'elemImg', :image=>image)
      t.item_lastchild(:root, item)
    }
  }

  t.notify_bind(t, 'Edit-accept', proc{|w, i, c, e, tt|
                  w.item_element_configure(i, c, e, :text=>tt)
                }, '%T %I %C %E %t')

  iMovie = TkBindTag.new
  iMovie.bind('ButtonPress-1', proc{|w, x, y|
                iMovieButton1(w, x, y)
              }, '%W %x %y')

  t.bindtags = [t, iMovie, Tk::TreeCtrl, t.winfo_toplevel, TkBindTag::ALL]
end

#demoInternetOptions(t) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'sample/tkextlib/treectrl/www-options.rb', line 1

def demoInternetOptions (t)
  @Option = TkVarAccess.new_hash('::Option')

  height = t.font.metrics(:linespace) + 2
  height = 18 if height < 18
  t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
              :itemheight=>height, :selectmode=>:browse)

  init_pics('internet-*')

  if $HasColumnCreate
    t.column_create(:text=>'Internet Options')
  else
    t.column_configure(0, :text=>'Internet Options')
  end

  t.state_define('check')
  t.state_define('radio')
  t.state_define('on')

  t.element_create('e1', :image, :image=>[
                     @images['internet-check-on'],  ['check', 'on'],
                     @images['internet-check-off'], ['check'],
                     @images['internet-radio-on'],  ['radio', 'on'],
                     @images['internet-radio-off'], ['radio']
                   ])
  t.element_create('e2', :text,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']])
  t.element_create('e3', :rect, :showfocus=>true,
                   :fill=>[@SystemHighlight, ['selected', 'focus']])

  s = t.style_create('s1')
  t.style_elements(s, ['e3', 'e1', 'e2'])
  t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e2', :expand=>:ns)
  t.style_layout(s, 'e3', :union=>['e2'], :iexpand=>:ns, :ipadx=>2)

  parentList = [:root, '', '', '', '', '', '']
  parent = :root
  [
    [0, :print, "Printing", "", ""],
        [1, :off, "Print background colors and images", "o1", ""],
    [0, :search, "Search from Address bar", "", ""],
        [1, :search, "When searching", "", ""],
            [2, :off, "Display results, and go to the most likely sites",
                                                                 "o2", "r1"],
            [2, :off, "Do not search from the Address bar", "o3", "r1"],
            [2, :off, "Just display the results in the main window",
                                                                 "o4", "r1"],
            [2, :on, "Just go to the most likely site", "o5", "r1"],
    [0, :security, "Security", "", ""],
        [1, :on, "Check for publisher's certificate revocation", "o5", ""],
        [1, :off, "Check for server certificate revocation (requires restart)",
                                                                 "o6", ""]
  ].each{|depth, setting, text, option, group|
    item = t.item_create()
    t.item_style_set(item, 0, 's1')
    t.item_element_configure(item, 0, 'e2', :text=>text)
    @Option[:option, item] = option
    @Option[:group, item] = group
    if setting == :on || setting == :off
      @Option[:setting, item] = setting
      if group == ''
        t.item_state_set(item, 'check')
        if setting == :on
          t.item_state_set(item, 'on')
        end
      else
        if setting == :on
          @Option[:current, group] = item
          t.item_state_set(item, 'on')
        end
        t.item_state_set(item, 'radio')
      end
    else
      t.item_element_configure(item, 0, 'e1',
                               :image=>@images["internet-#{setting}"])
    end
    t.item_lastchild(parentList[depth], item)
    depth += 1
    parentList[depth] = item
  }

  treeCtrlOption = TkBindTag.new
  treeCtrlOption.bind('Double-ButtonPress-1', proc{|w, x, y|
                        Tk::TreeCtrl::BindCallback.doubleButton1(w, x, y)
                      }, '%W %x %y')
  treeCtrlOption.bind('ButtonPress-1', proc{|w, x, y|
                        optionButton1(w, x, y)
                        Tk.callback_break
                      }, '%W %x %y')
  treeCtrlOption.bind('Button1-Motion', proc{|w, x, y|
                        optionMotion1(w, x, y)
                        Tk.callback_break
                      }, '%W %x %y')
  treeCtrlOption.bind('Button1-Leave', proc{|w, x, y|
                        optionLeave1(w, x, y)
                        Tk.callback_break
                      }, '%W %x %y')
  treeCtrlOption.bind('ButtonRelease-1', proc{|w, x, y|
                        optionRelease1(w, x, y)
                        Tk.callback_break
                      }, '%W %x %y')

  t.bindtags = [
    t, treeCtrlOption, Tk::TreeCtrl, t.winfo_toplevel, TkBindTag::ALL
  ]
end

#demoInternetOptions_2(t) ⇒ Object

Alternate implementation that doesn’t rely on run-time styles



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'sample/tkextlib/treectrl/www-options.rb', line 146

def demoInternetOptions_2(t)
  height = t.font.metrics(:linespace) + 2
  height = 18 if height < 18
  t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
              :itemheight=>height, :selectmode=>:browse)

  init_pics('internet-*')

  t.column_configure(0, :text=>'Internet Options')

  t.element_create('e1', :image)
  t.element_create('e2', :text,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']])
  t.element_create('e3', :rect, :showfocus=>true,
                   :fill=>[@SystemHighlight, ['selected', 'focus']])

  s = t.style_create('s1')
  t.style_elements('s1', ['e3', 'e1', 'e2'])
  t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e2', :expand=>:ns)
  t.style_layout(s, 'e3', :union=>['e2'], :iexpand=>:ns, :ipadx=>2)

  parentList = [:root, '', '', '', '', '', '']
  parent = :root
  [
    [0, :print, "Printing", "", ""],
        [1, :off, "Print background colors and images", "o1", ""],
    [0, :search, "Search from Address bar", "", ""],
        [1, :search, "When searching", "", ""],
            [2, :off, "Display results, and go to the most likely sites",
                                                                 "o2", "r1"],
            [2, :off, "Do not search from the Address bar", "o3", "r1"],
            [2, :off, "Just display the results in the main window",
                                                                 "o4", "r1"],
            [2, :on, "Just go to the most likely site", "o5", "r1"],
    [0, :security, "Security", "", ""],
        [1, :on, "Check for publisher's certificate revocation", "o5", ""],
        [1, :off, "Check for server certificate revocation (requires restart)",
                                                                 "o6", ""]
  ].each{|depth, setting, text, option, group|
    item = t.item_create()
    t.item_style_set(item, 0, 's1')
    t.item_element_configure(item, 0, 'e2', :text=>text)
    @Option[:option, item] = option
    @Option[:group, item] = group
    if setting == :on || setting == :off
      @Option[:setting, item] = setting
      if group == ''
        img = @images["internet-check-#{setting}"]
        t.item_element_configure(item, 0, 'e1', :image=>img)
      else
        if setting == :on
          @Option[:current, group] = item
        end
        img = @images["internet-radio-#{setting}"]
        t.item_element_configure(item, 0, 'e1', :image=>img)
      end
    else
      t.item_element_configure(item, 0, 'e1',
                               :image=>@images["internet-#{setting}"])
    end
    t.item_lastchild(parentList[depth], item)
    depth += 1
    parentList[depth] = item
  }

  treeCtrlOption = TkBindTag.new
  treeCtrlOption.bind('Double-ButtonPress-1', proc{|w, x, y|
                        Tk::TreeCtrl::BindCallback.doubleButton1(w, x, y)
                      }, '%W %x %y')
  treeCtrlOption.bind('ButtonPress-1', proc{|w, x, y|
                        optionButton1(w, x, y)
                        Tk.callback_break
                      }, '%W %x %y')
  treeCtrlOption.bind('Button1-Motion', proc{|w, x, y|
                        optionMotion1(w, x, y)
                        Tk.callback_break
                      }, '%W %x %y')
  treeCtrlOption.bind('Button1-Leave', proc{|w, x, y|
                        optionLeave1(w, x, y)
                        Tk.callback_break
                      }, '%W %x %y')
  treeCtrlOption.bind('ButtonRelease-1', proc{|w, x, y|
                        optionRelease1(w, x, y)
                        Tk.callback_break
                      }, '%W %x %y')

  t.bindtags = [
    t, treeCtrlOption, Tk::TreeCtrl, t.winfo_toplevel, TkBindTag::ALL
  ]
end

#demoLayout(t) ⇒ Object

Demo: Layout



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'sample/tkextlib/treectrl/layout.rb', line 4

def demoLayout(t)
  t.configure(:showroot=>false, :showrootbutton=>true, :showbuttons=>true,
              :showlines=>true, :itemheight=>0, :selectmode=>:browse)

  if $HasColumnCreate
    t.column_create(:text=>'Layout')
  else
    t.column_configure(0, :text=>'Layout')
  end

  t.element_create('e1', :rect, :width=>30, :height=>30, :fill=>'gray20')
  t.element_create('e2', :rect, :width=>30, :height=>30, :fill=>'gray40',
                   :outline=>'blue', :outlinewidth=>3)
  t.element_create('e3', :rect, :fill=>'gray60')
  t.element_create('e4', :rect, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'], 'gray80', []
                   ])
  t.element_create('e5', :rect, :fill=>'{sky blue}', :width=>20, :height=>20)
  t.element_create('e6', :rect, :fill=>'{sea green}', :width=>30, :height=>16)
  t.element_create('e7', :rect, :fill=>'{sky blue}', :width=>30, :height=>16)
  t.element_create('e8', :rect, :fill=>'gray70', :height=>1)

  s = t.style_create('s1')
  t.style_elements(s, ['e4', 'e3', 'e1', 'e2', 'e5', 'e6', 'e7'])
  t.style_layout(s, 'e1', :padx=>[28, 4], :pady=>4)
  t.style_layout(s, 'e2', :expand=>:es, :padx=>[0, 38])
  t.style_layout(s, 'e3', :union=>['e1', 'e2'], :ipadx=>4, :ipady=>4, :pady=>2)
  t.style_layout(s, 'e4', :detach=>true, :iexpand=>:es)
  t.style_layout(s, 'e5', :detach=>true, :padx=>[2,0], :pady=>2, :iexpand=>:s)
  t.style_layout(s, 'e6', :detach=>true, :expand=>:ws,
                 :padx=>[0,2], :pady=>[2,0])
  t.style_layout(s, 'e7', :detach=>true, :expand=>:wn,
                 :padx=>[0,2], :pady=>[0,2])

  if $Version_1_1_OrLater
    i = t.item_create(:button=>true)
  else
    i = t.item_create
    t.item_hasbutton(i, true)
  end
  t.item_style_set(i, 0, s)
  t.item_lastchild(:root, i)
  parent = i

  i = t.item_create()
  unless $Version_1_1_OrLater
    t.item_hasbutton(i, false)
  end
  t.item_style_set(i, 0, s)
  t.item_lastchild(parent, i)

  ###

  s = t.style_create('s2')
  t.style_elements(s, ['e4', 'e3', 'e1'])
  t.style_layout(s, 'e1', :padx=>8, :pady=>8, :iexpand=>:e)
  t.style_layout(s, 'e3', :union=>['e1'], :ipadx=>[20,4], :ipady=>[4,12])
  t.style_layout(s, 'e4', :detach=>true, :iexpand=>:es)

  if $Version_1_1_OrLater
    i = t.item_create(:button=>true)
  else
    i = t.item_create
    t.item_hasbutton(i, true)
  end
  t.item_style_set(i, 0, s)
  t.item_lastchild(:root, i)

  i2 = t.item_create()
  unless $Version_1_1_OrLater
    t.item_hasbutton(i2, false)
  end
  t.item_style_set(i2, 0, s)
  t.item_lastchild(i, i2)

  ###

  s = t.style_create('s3')
  t.style_elements(s, ['e4', 'e3', 'e1', 'e5', 'e6'])
  t.style_layout(s, 'e4', :union=>['e1', 'e6'], :ipadx=>8, :ipady=>[8,0])
  t.style_layout(s, 'e3', :union=>['e1', 'e5'], :ipadx=>4, :ipady=>4)
  t.style_layout(s, 'e5', :ipady=>[0,20])

  if $Version_1_1_OrLater
    i = t.item_create(:button=>true)
  else
    i = t.item_create
    t.item_hasbutton(i, true)
  end
  t.item_style_set(i, 0, s)
  t.item_lastchild(:root, i)

  i2 = t.item_create()
  unless $Version_1_1_OrLater
    t.item_hasbutton(i2, false)
  end
  t.item_style_set(i2, 0, s)
  t.item_lastchild(i, i2)

  ###

  t.element_create('eb', :border, :background=>@SystemButtonFace,
                   :relief=>[:sunken, ['selected'], :raised, []],
                   :thickness=>2, :filled=>true)
  t.element_create('et', :text)

  text = "Here is a text element surrounded by a border element.\nResize the column to watch me wrap."

  s = t.style_create('e4')
  t.style_elements(s, ['eb', 'et'])
  t.style_layout(s, 'eb', :union=>['et'], :ipadx=>2, :ipady=>2)
  t.style_layout(s, 'et', :squeeze=>:x)

  if $Version_1_1_OrLater
    i = t.item_create(:button=>true)
  else
    i = t.item_create
    t.item_hasbutton(i, true)
  end
  t.item_style_set(i, 0, s)
  t.item_text(i, 0, text)
  t.item_lastchild(:root, i)
  parent = i

  i = t.item_create()
  unless $Version_1_1_OrLater
    t.item_hasbutton(i, false)
  end
  t.item_style_set(i, 0, s)
  t.item_text(i, 0, text)
  t.item_lastchild(parent, i)

  ###

  styleNum = 5
  [
    [:horizontal, [:s, :ns, :n]],
    [:vertical,   [:e, :we, :w]]
  ].each{|orient, expandList|
    expandList.each{|expand|
      s = t.style_create("s#{styleNum}", :orient=>orient)
      t.style_elements(s, ['e4', 'e8', 'e2', 'e5', 'e6'])
      t.style_layout(s, 'e4', :detach=>true, :iexpand=>:es)
      t.style_layout(s, 'e8', :detach=>true, :expand=>:n, :iexpand=>:e)
      t.style_layout(s, 'e2', :expand=>expand)
      t.style_layout(s, 'e5', :expand=>expand)
      t.style_layout(s, 'e6', :expand=>expand)
      styleNum += 1

      i = t.item_create()
      t.item_style_set(i, 0, s)
      t.item_lastchild(:root, i)
    }
  }
end

#demoMailWasher(t) ⇒ Object

Demo: MailWasher



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'sample/tkextlib/treectrl/mailwasher.rb', line 4

def demoMailWasher(t)
  init_pics('*checked')

  height = t.font.metrics(:linespace) + 2
  height = 18 if height < 18

  t.configure(:showroot=>false, :showrootbutton=>false, :showbuttons=>false,
              :showlines=>false, :itemheight=>height, :selectmode=>:browse,
              :xscrollincrement=>1)

  pad = 4

  if $Version_1_1_OrLater
    t.column_create(:text=>'Delete', :textpadx=>pad, :tag=>'delete')
    t.column_create(:text=>'Bounce', :textpadx=>pad, :tag=>'bounce')
    t.column_create(:text=>'Status', :width=>80, :textpadx=>pad,
                    :tag=>'status')
    t.column_create(:text=>'Size', :width=>40, :textpadx=>pad,
                    :justify=>:right, :tag=>'size')
    t.column_create(:text=>'From', :width=>140, :textpadx=>pad, :tag=>'from')
    t.column_create(:text=>'Subject', :width=>240, :textpadx=>pad,
                    :tag=>'subject')
    t.column_create(:text=>'Received', :textpadx=>pad, :arrow=>:up,
                    :arrowpad=>[4,0], :tag=>'received')
    t.column_create(:text=>'Attachments', :textpadx=>pad, :tag=>'attachments')

    t.state_define('CHECK')

    t.element_create('imgCheck', :image, :image=>[
                       @images['checked'], ['CHECK'], @images['unchecked'], []
                     ])

  else # TreeCtrl 1.0
    t.column_configure(0, :text=>'Delete', :textpadx=>pad, :tag=>'delete')
    t.column_configure(1, :text=>'Bounce', :textpadx=>pad, :tag=>'bounce')
    t.column_configure(2, :text=>'Status', :width=>80, :textpadx=>pad,
                       :tag=>'status')
    t.column_configure(3, :text=>'Size', :width=>40, :textpadx=>pad,
                       :justify=>:right, :tag=>'size')
    t.column_configure(4, :text=>'From', :width=>140, :textpadx=>pad,
                       :tag=>'from')
    t.column_configure(5, :text=>'Subject', :width=>240, :textpadx=>pad,
                       :tag=>'subject')
    t.column_configure(6, :text=>'Received', :textpadx=>pad, :arrow=>:up,
                       :arrowpad=>[4,0], :tag=>'received')
    t.column_configure(7, :text=>'Attachments', :textpadx=>pad,
                       :tag=>'attachments')

    t.element_create('imgOff', :image, :image=>@images['unchecked'])
    t.element_create('imgOn', :image, :image=>@images['checked'])
  end

  t.element_create('border', :rect, :open=>:nw, :outline=>'gray',
                   :outlinewidth=>1, :fill=>[@SystemHighlight, ['selected']])
  t.element_create('txtAny', :text, :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected']])
  t.element_create('txtNone', :text, :text=>'none', :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected']])
  t.element_create('txtYes', :text, :text=>'yes', :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected']])
  t.element_create('txtNormal', :text, :text=>'Normal', :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected'], '#006800', []])
  t.element_create('txtPossSpam', :text, :text=>'Possible Spam', :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected'], '#787800', []])
  t.element_create('txtProbSpam', :text, :text=>'Probably Spam', :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected'], '#FF9000', []])
  t.element_create('txtBlacklist', :text, :text=>'Blacklisted', :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected'], '#FF5800', []])

  if $Version_1_1_OrLater
    s = t.style_create('styCheck')
    t.style_elements(s, ['border', 'imgCheck'])
    t.style_layout(s, 'border', :detach=>true, :iexpand=>:es)
    t.style_layout(s, 'imgCheck', :expand=>:news)
  else
    ['Off', 'On'].each{|name|
      s = t.style_create('sty' << name)
      i = 'img' << name
      t.style_elements(s, ['border', i])
      t.style_layout(s, 'border', :detach=>true, :iexpand=>:es)
      t.style_layout(s, i, :expand=>:news)
    }
  end

  pad = 4

  %w(Any None Yes Normal PossSpam ProbSpam Blacklist).each{|name|
    s = t.style_create('sty' << name)
    e = 'txt' << name
    t.style_elements(s, ['border', e])
    t.style_layout(s, 'border', :detach=>true, :iexpand=>:es)
    t.style_layout(s, e, :padx=>pad, :squeeze=>:x, :expand=>:ns)
  }

  [
    ['[email protected]',  "Your hair is thinning"],
    ['[email protected]', "Your breasts are too small"],
    ['[email protected]',  "Your penis is too small"],
    ['[email protected]', "You are not very smart"],
    ['[email protected]', "You need more money"],
    ['[email protected]', "You need better friends"],
    ['[email protected]', "Find out what your coworkers think about you"],
    ['[email protected]', "Find out what you think about yourself"],
    ['[email protected]', "You need a better job"],
    ['[email protected]', "Your mortgage is a joke"],
    ['[email protected]', "You need more spam"]
  ].each{|frm, subj|
    item = t.item_create
    status = ['styNormal','styPossSpam','styProbSpam','styBlacklist'][rand(4)]
    attachments = ['styNone','styYes'][rand(2)]

    if $Version_1_1_OrLater
      delete = [false, true][rand(2)]
      bounce = [false, true][rand(2)]
      t.item_style_set(item,
                       0, 'styCheck', 1, 'styCheck', 2, status, 3, 'styAny',
                       4, 'styAny', 5, 'styAny', 6, 'styAny', 7, attachments)
      t.item_state_forcolumn(item, 'delete', 'CHECK') if delete
      t.item_state_forcolumn(item, 'bounce', 'CHECK') if bounce

    else # TreeCtrl 1.0
      delete = ['styOn', 'styOff'][rand(2)]
      bounce = ['styOn', 'styOff'][rand(2)]
      t.item_style_set(item,
                       0, delete, 1, bounce, 2, status, 3, 'styAny',
                       4, 'styAny', 5, 'styAny', 6, 'styAny', 7, attachments)
    end

    bytes = 512 + rand(1024 * 12)
    size = "#{bytes / 1024 + 1}KB"
    seconds = Tk::Clock.seconds - rand(100000)
    received = Tk::Clock.format(seconds, '%d/%m/%y %I:%M %p')
    t.item_text(item, 3, size, 4, frm, 5, subj, 6, received)
    t.item_lastchild(:root, item)
  }

  sortColumn = 6
  t.notify_bind(t, 'Header-invoke',
                proc{|c, w|
                  if c == sortColumn
                    if w.column_cget(sortColumn, :arrow) == 'down'
                      order = :increasing
                      arrow = :up
                    else
                      order = :decreasing
                      arrow = :down
                    end
                  else
                    if w.column_cget(sortColumn, :arrow) == 'down'
                      order = :decreasing
                      arrow = :down
                    else
                      order = :increasing
                      arrow = :up
                    end
                    w.column_configure(sortColumn, :arrow=>:none)
                    sortColumn = c
                  end
                  w.column_configure(c, :arrow=>arrow)
                  case w.column_cget(c, :tag)
                  when 'bounce', 'delete'
                    w.item_sort(:root, order,
                                {
                                  :column=>c,
                                  :command=>proc{|item1, item2|
                                    compareOnOff(w, c, item1, item2)
                                  }
                                },
                                { :column=>'subject', :dictionary=>true })
                  when 'status'
                    w.item_sort(:root, order,
                                { :column=>c, :dictionary=>true })
                  when 'from'
                    w.item_sort(:root, order,
                                { :column=>c, :dictionary=>true },
                                { :column=>'subject', :dictionary=>true })
                  when 'subject'
                    w.item_sort(:root, order,
                                { :column=>c, :dictionary=>true })
                  when 'size'
                    w.item_sort(:root, order,
                                { :column=>c, :dictionary=>true },
                                { :column=>'subject', :dictionary=>true })
                  when 'received'
                    w.item_sort(:root, order,
                                { :column=>c, :dictionary=>true },
                                { :column=>'subject', :dictionary=>true })
                  when 'attachments'
                    w.item_sort(:root, order,
                                { :column=>c, :dictionary=>true },
                                { :column=>'subject', :dictionary=>true })
                  end
                }, '%C %T')

  mailWasher = TkBindTag.new

  if $Version_1_1_OrLater
    mailWasher.bind('ButtonPress-1',
                    proc{|w, x, y|
                      id = w.identify(x, y)
                      if id.empty?
                      elsif id[0] == 'header'
                      else
                        what, item, where, arg1, arg2, arg3 = id
                        if where == 'column'
                          tag = w.column_cget(arg1, :tag)
                          if tag == 'delete' || tag == 'bounce'
                            w.item_state_forcolumn(item, arg1, '~CHECK')
                          end
                        end
                      end
                    }, '%W %x %y')
  else # TreeCtrl 1.0
    mailWasher.bind('ButtonPress-1',
                    proc{|w, x, y|
                      id = w.identify(x, y)
                      if id.empty?
                      elsif id[0] == 'header'
                      else
                        what, item, where, arg1, arg2, arg3 = id
                        if where == 'column'
                          tag = w.column_cget(arg1, :tag)
                          if tag == 'delete' || tag == 'bounce'
                            style = w.item_style_set(item, arg1)
                            if style == 'styOn'
                              style = 'styOff'
                            else
                              style = 'styOn'
                            end
                            w.item_style_set(item, arg1, style)
                            @display_styles_in_item.call(item)
                          end
                        end
                      end
                    }, '%W %x %y')
  end

  t.bindtags = [t, mailWasher, Tk::TreeCtrl, t.winfo_toplevel, TkBindTag::ALL]
end

#demoOutlookFolders(t) ⇒ Object

Demo: Outlook Express folder list



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'sample/tkextlib/treectrl/outlook-folders.rb', line 4

def demoOutlookFolders(t)
  init_pics('outlook-*')

  height = t.font.metrics(:linespace) + 2
  height = 18 if height < 18

  t.configure(:itemheight=>height, :selectmode=>:browse, :showlines=>true,
              :showroot=>true, :showrootbutton=>false, :showbuttons=>true)

  if $HasColumnCreate
    t.column_create(:text=>'Folders')
  else
    t.column_configure(0, :text=>'Folders')
  end

  t.element_create('e1', :image)
  t.element_create('e2', :text, :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']])
  t.element_create('e3', :text, :lines=>1, :font=>t.font.dup.weight(:bold),
                   :fill=>[@SystemHighlightText, ['selected', 'focus']])
  t.element_create('e4', :text, :fill=>'blue')
  t.element_create('e5', :image, :image=>@images['outlook-folder'])
  t.element_create('e6', :rect, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray', ['selected', '!focus']
                   ])

  # image + text
  s = t.style_create('s1')
  t.style_elements(s, ['e6', 'e1', 'e2'])
  t.style_layout(s, 'e1', :expand=>:ns)
  t.style_layout(s, 'e2', :padx=>[4,0], :expand=>:ns, :squeeze=>:x)
  t.style_layout(s, 'e6', :union=>['e2'], :iexpand=>:ns, :ipadx=>2)

  # image + text + text
  s = t.style_create('s2')
  t.style_elements(s, ['e6', 'e1', 'e3', 'e4'])
  t.style_layout(s, 'e1', :expand=>:ns)
  t.style_layout(s, 'e3', :padx=>4, :expand=>:ns, :squeeze=>:x)
  t.style_layout(s, 'e4', :expand=>:ns)
  t.style_layout(s, 'e6', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)

  # folder + text
  s = t.style_create('s3')
  t.style_elements(s, ['e6', 'e5', 'e2'])
  t.style_layout(s, 'e5', :expand=>:ns)
  t.style_layout(s, 'e2', :padx=>[4,0], :expand=>:ns, :squeeze=>:x)
  t.style_layout(s, 'e6', :union=>['e2'], :iexpand=>:ns, :ipadx=>2)

  # folder + text + text
  s = t.style_create('s4')
  t.style_elements(s, ['e6', 'e5', 'e3', 'e4'])
  t.style_layout(s, 'e5', :expand=>:ns)
  t.style_layout(s, 'e3', :padx=>4, :expand=>:ns, :squeeze=>:x)
  t.style_layout(s, 'e4', :expand=>:ns)
  t.style_layout(s, 'e6', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)

  t.item_style_set(:root, 0, 's1')
  t.item_complex(:root,
                 [
                   ['e1', {:image=>@images['outlook-main']}],
                   ['e2', {:text=>'Outlook Express'}]
                 ])

  parentList = [:root, '', '', '', '', '', '']
  parent = :root
  [
     [0, :local, "Local Folders", true, 0],
        [1, :inbox, 'Inbox', false, 5],
        [1, :outbox, 'Outbox', false, 0],
        [1, :sent, "Sent Items", false, 0],
        [1, :deleted, "Deleted Items", false, 50],
        [1, :draft, 'Drafts', false, 0],
        [1, :folder, "Messages to Dad", false, 0],
        [1, :folder, "Messages to Sis", false, 0],
        [1, :folder, "Messages to Me", false, 0],
           [2, :folder, "2001", false, 0],
           [2, :folder, "2000", false, 0],
           [2, :folder, "1999", false, 0],
     [0, :server, "news.gmane.org", true, 0],
        [1, :group, "gmane.comp.lang.lua.general", false, 498]
  ].each{|depth, img, text, button, unread|
    if $Version_1_1_OrLater
      item = t.item_create(:button=>button)
    else
      item = t.item_create
      t.item_hasbutton(item, button)
    end
    if img == :folder
      if unread != 0
        t.item_style_set(item, 0, 's4')
        t.item_complex(item,
                       [['e3', {:text=>text}], ['e4', {:text=>"(#{unread})"}]])
      else
        t.item_style_set(item, 0, 's3')
        t.item_complex(item, [['e2', {:text=>text}]])
      end
    else
      if unread != 0
        t.item_style_set(item, 0, 's2')
        t.item_complex(item,
                       [
                         ['e1', {:image=>@images["outlook-#{img}"]}],
                         ['e3', {:text=>text}],
                         ['e4', {:text=>"(#{unread})"}]
                       ])
      else
        t.item_style_set(item, 0, 's1')
        t.item_complex(item,
                       [
                         ['e1', {:image=>@images["outlook-#{img}"]}],
                         ['e2', {:text=>text}]
                       ])
      end
    end
    t.item_lastchild(parentList[depth], item)
    depth += 1
    parentList[depth] = item
  }
end

#demoOutlookNewsgroup(t) ⇒ Object

Demo: Outlook Express newsgroup messages



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'sample/tkextlib/treectrl/outlook-newgroup.rb', line 4

def demoOutlookNewsgroup(t)
  init_pics('outlook-*')

  height = t.font.metrics(:linespace)
  height = 18 if height < 18
  t.configure(:itemheight=>height, :selectmode=>:browse, :showlines=>false,
              :showroot=>false, :showrootbutton=>false, :showbuttons=>true)

  if $Version_1_1_OrLater
    t.column_create(:image=>@images['outlook-clip'], :tag=>'clip')
    t.column_create(:image=>@images['outlook-arrow'], :tag=>'arrow')
    t.column_create(:image=>@images['outlook-watch'], :tag=>'watch')
    t.column_create(:text=>'Subject', :width=>250, :tag=>'subject')
    t.column_create(:text=>'From', :width=>150, :tag=>'from')
    t.column_create(:text=>'Sent', :width=>150, :tag=>'sent')
    t.column_create(:text=>'Size', :width=>60, :justify=>:right, :tag=>'size')
  else # TreeCtrl 1.0
    t.column_configure(0, :image=>@images['outlook-clip'], :tag=>'clip')
    t.column_configure(1, :image=>@images['outlook-arrow'], :tag=>'arrow')
    t.column_configure(2, :image=>@images['outlook-watch'], :tag=>'watch')
    t.column_configure(3, :text=>'Subject', :width=>250, :tag=>'subject')
    t.column_configure(4, :text=>'From', :width=>150, :tag=>'from')
    t.column_configure(5, :text=>'Sent', :width=>150, :tag=>'sent')
    t.column_configure(6, :text=>'Size', :width=>60, :justify=>:right,
                       :tag=>'size')
  end

  # Would be nice if I could specify a column -tag too
  t.treecolumn = 3

  # State for a read message
  t.state_define('read')

  # State for a message with unread descendants
  t.state_define('unread')

  t.element_create('elemImg', :image,
                   :image=>[
                     @sel_images['outlook-read-2'],
                          ['selected', 'read', 'unread', '!open'],
                     @images['outlook-read-2'], ['read', 'unread', '!open'],
                     @sel_images['outlook-read'], ['selected', 'read'],
                     @images['outlook-read'], ['read'],
                     @sel_images['outlook-unread'], ['selected'],
                     @images['outlook-unread'], []
                   ])
  t.element_create('elemTxt', :text, :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']],
                   :font=>[
                     t.font.dup.weight(:bold), ['read', 'unread', '!open'],
                     t.font.dup.weight(:bold), ['!read']
                   ])
  t.element_create('sel.e', :rect, :open=>:e, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray',  ['selected', '!focus']
                   ])
  t.element_create('sel.w', :rect, :open=>:w, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray',  ['selected', '!focus']
                   ])
  t.element_create('sel.we', :rect, :open=>:we, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray',  ['selected', '!focus']
                   ])

  # Image + text
  s = t.style_create('s1')
  t.style_elements(s, ['sel.e', 'elemImg', 'elemTxt'])
  t.style_layout(s, 'elemImg', :expand=>:ns)
  t.style_layout(s, 'elemTxt', :padx=>[2,6], :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'sel.e', :union=>['elemTxt'],
                 :iexpand=>:nes, :ipadx=>[2,0])

  # Text
  s = t.style_create('s2.we')
  t.style_elements(s, ['sel.we', 'elemTxt'])
  t.style_layout(s, 'elemTxt', :padx=>6, :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'sel.we', :detach=>true, :iexpand=>:es)

  # Text
  s = t.style_create('s2.w')
  t.style_elements(s, ['sel.w', 'elemTxt'])
  t.style_layout(s, 'elemTxt', :padx=>6, :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'sel.w', :detach=>true, :iexpand=>:es)

  # Set default item style
  if $Version_1_1_OrLater
    t.defaultstyle = ['', '', '', 's1', 's2.we', 's2.we', 's2.w']
  end

  msgCnt = 100
  thread = 0

  @Message = Hash.new{|k, v| k[v] = Hash.new}
  @Message[:count][0] = 0

  items = [t.index(:root)]

  (1...(msgCnt)).each{|i|
    item_i = t.item_create
    item_j = nil
    j = nil
    loop {
      j = rand(i)
      item_j = items[j]
      break if j == 0
      next if t.depth(item_j) == 5
      next if @Message[:count][@Message[:thread][item_j]] == 15
      break
    }
    t.item_lastchild(item_j, item_i)

    @Message[:read][item_i] = (rand(2) == 0)
    if j == 0
      thread += 1
      @Message[:thread][item_i] = thread
      @Message[:seconds][item_i] = (Tk::Clock.seconds - rand(500000))
      @Message[:seconds2][item_i] = @Message[:seconds][item_i]
      @Message[:count][thread] = 1
    else
      @Message[:thread][item_i] = @Message[:thread][item_j]
      @Message[:seconds][item_i] = (@Message[:seconds2][item_j] + rand(10000))
      @Message[:seconds2][item_i] = @Message[:seconds][item_i]
      @Message[:seconds2][item_j] = @Message[:seconds][item_i]
      @Message[:count][@Message[:thread][item_j]] += 1
    end
    items << item_i
  }

  (1...(msgCnt)).each{|i|
    item_i = items[i]
    subject = "This is thread number #{@Message[:thread][item_i]}"
    from = '[email protected]'
    sent = Tk::Clock.format(@Message[:seconds][item_i], "%d/%m/%y %I:%M %p")
    size = "#{1 + rand(10)}KB"

    # This message has been read
    t.item_state_set(item_i, 'read') if @Message[:read][item_i]

    # This message has unread descendants
    t.item_state_set(item_i, 'unread')  if anyUnreadDescendants(t, item_i)

    if t.item_numchildren(item_i) > 0
      if $Version_1_1_OrLater
        t.item_configure(item_i, :button=>true)
      else # TreeCtrl 1.0
        t.item_hasbutton(item_i, true)
      end

      # Collapse some messages
      if $Version_1_1_OrLater
        t.item_collapse(item_i) if rand(2) == 0
      else # TreeCtrl 1.0
        t.collapse(item_i) if rand(2) == 0
      end
    end

    unless $Version_1_1_OrLater
      t.item_style_set(item_i, 3, 's1', 4, 's2.we', 5, 's2.we', 6, 's2.w')
    end
    t.item_text(item_i, 3, subject, 4, from, 5, sent, 6, size)
  }

  # Do something when the selection changes
  t.notify_bind(t, 'Selection',
                proc{|w|
                  if w.selection_count == 1
                    # One item is selected
                    if @Message[:afterId][:id]
                      Tk.after_cancel(@Message[:afterId][:id])
                    end
                    @Message[:afterId][:item] = w.selection_get[0]
                    @Message[:afterId][:id] = Tk.after(500, proc{
                                                         messageReadDelayed(w)
                                                       })
                  end
                }, '%T')
end

#demoOutlookNewsgroup2(t) ⇒ Object

Alternate implementation which does not rely on run-time states



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'sample/tkextlib/treectrl/outlook-newgroup.rb', line 206

def demoOutlookNewsgroup2(t)
  init_pics('outlook-*')

  height = t.font.metrics(:linespace)
  height = 18 if height < 18
  t.configure(:itemheight=>height, :selectmode=>:browse, :showlines=>false,
              :showroot=>false, :showrootbutton=>false, :showbuttons=>true)

  if $Version_1_1_OrLater
    t.column_create(:image=>@images['outlook-clip'], :tag=>'clip')
    t.column_create(:image=>@images['outlook-arrow'], :tag=>'arrow')
    t.column_create(:image=>@images['outlook-watch'], :tag=>'watch')
    t.column_create(:text=>'Subject', :width=>250, :tag=>'subject')
    t.column_create(:text=>'From', :width=>150, :tag=>'from')
    t.column_create(:text=>'Sent', :width=>150, :tag=>'sent')
    t.column_create(:text=>'Size', :width=>60, :justify=>:right, :tag=>'size')
  else # TreeCtrl 1.0
    t.column_configure(0, :image=>@images['outlook-clip'], :tag=>'clip')
    t.column_configure(1, :image=>@images['outlook-arrow'], :tag=>'arrow')
    t.column_configure(2, :image=>@images['outlook-watch'], :tag=>'watch')
    t.column_configure(3, :text=>'Subject', :width=>250, :tag=>'subject')
    t.column_configure(4, :text=>'From', :width=>150, :tag=>'from')
    t.column_configure(5, :text=>'Sent', :width=>150, :tag=>'sent')
    t.column_configure(6, :text=>'Size', :width=>60, :justify=>:right,
                       :tag=>'size')
  end

  t.treecolumn = 3

  t.element_create('image.unread', :image, :image=>@images['outlook-unread'])
  t.element_create('image.read', :image, :image=>@images['outlook-read'])
  t.element_create('image.read2', :image, :image=>@images['outlook-read-2'])
  t.element_create('text.read', :text, :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']])
  t.element_create('text.unread', :text, :lines=>1,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']],
                   :font=>t.font.dup.weight(:bold))
  t.element_create('sel.e', :rect, :open=>:e, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray',  ['selected', '!focus']
                   ])
  t.element_create('sel.w', :rect, :open=>:w, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray',  ['selected', '!focus']
                   ])
  t.element_create('sel.we', :rect, :open=>:we, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray',  ['selected', '!focus']
                   ])

  # Image + text
  s = t.style_create('unread')
  t.style_elements(s, ['sel.e', 'image.unread', 'text.unread'])
  t.style_layout(s, 'image.unread', :expand=>:ns)
  t.style_layout(s, 'text.unread', :padx=>[2,6], :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'sel.e', :union=>['text.unread'],
                 :iexpand=>:nes, :ipadx=>[2,0])

  # Image + text
  s = t.style_create('read')
  t.style_elements(s, ['sel.e', 'image.read', 'text.read'])
  t.style_layout(s, 'image.read', :expand=>:ns)
  t.style_layout(s, 'text.read', :padx=>[2,6], :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'sel.e', :union=>['text.read'],
                 :iexpand=>:nes, :ipadx=>[2,0])

  # Image + text
  s = t.style_create('read2')
  t.style_elements(s, ['sel.e', 'image.read2', 'text.unread'])
  t.style_layout(s, 'image.read2', :expand=>:ns)
  t.style_layout(s, 'text.unread', :padx=>[2,6], :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'sel.e', :union=>['text.unread'],
                 :iexpand=>:nes, :ipadx=>[2,0])

  # Text
  s = t.style_create('unread.we')
  t.style_elements(s, ['sel.we', 'text.unread'])
  t.style_layout(s, 'text.unread', :padx=>6, :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'sel.we', :detach=>true, :iexpand=>:es)

  # Text
  s = t.style_create('read.we')
  t.style_elements(s, ['sel.we', 'text.read'])
  t.style_layout(s, 'text.read', :padx=>6, :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'sel.we', :detach=>true, :iexpand=>:es)

  # Text
  s = t.style_create('unread.w')
  t.style_elements(s, ['sel.w', 'text.unread'])
  t.style_layout(s, 'text.unread', :padx=>6, :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'sel.w', :detach=>true, :iexpand=>:es)

  # Text
  s = t.style_create('read.w')
  t.style_elements(s, ['sel.w', 'text.read'])
  t.style_layout(s, 'text.read', :padx=>6, :squeeze=>:x, :expand=>:ns)
  t.style_layout(s, 'sel.w', :detach=>true, :iexpand=>:es)

  msgCnt = 100
  thread = 0

  @Message = Hash.new{|k, v| k[v] = Hash.new}
  @Message[:count][0] = 0

  (1...(msgCnt)).each{|i|
    t.item_create
    j = nil
    loop {
      j = rand(i)
      break if j == 0
      next if t.depth(j) == 5
      next if @Message[:count][@Message[:thread][j]] == 15
      break
    }
    t.item_lastchild(j, i)

    @Message[:read][i] = (rand(2) == 0)
    if j == 0
      thread += 1
      @Message[:thread][i] = thread
      @Message[:seconds][i] = (Tk::Clock.seconds - rand(500000))
      @Message[:seconds2][i] = @Message[:seconds][i]
      @Message[:count][thread] = 1
    else
      @Message[:thread][i] = @Message[:thread][j]
      @Message[:seconds][i] = (@Message[:seconds2][j] + rand(10000))
      @Message[:seconds2][i] = @Message[:seconds][i]
      @Message[:seconds2][j] = @Message[:seconds][i]
      @Message[:count][@Message[:thread][j]] += 1
    end
  }

  (1...(msgCnt)).each{|i|
    subject = "This is thread number #{@Message[:thread][i]}"
    from = '[email protected]'
    sent = Tk::Clock.format(@Message[:seconds][i], "%d/%m/%y %I:%M %p")
    size = "#{1 + rand(10)}KB"
    if @Message[:read][i]
      style = 'read'
      style2 = 'read2'
    else
      style = 'unread'
      style2 = 'unread2'
    end
    t.item_style_set(i, 3, style, 4, "#{style2}.we", 5, "#{style2}.we",
                     6, "#{style2}.w")
    t.item_text(i, 3, subject, 4, from, 5, sent, 6, size)
    if t.item_numchildren(i) > 0
      t.item_configure(item_i, :button=>true)
    end
  }

  # Do something when the selection changes
  t.notify_bind(t, 'Selection',
                proc{|w|
                  if w.selection_count == 1
                    i = t.selection_get[0]
                    unless @Message[:read][i]
                      if t.item_isopen(i) || !anyUnreadDescendants(t, i)
                        # unread -> read
                        t.item_style_map(i, 'subject', 'read',
                                         ['text.unread', 'text.read'])
                        t.item_style_map(i, 'from', 'read.we',
                                         ['text.unread', 'text.read'])
                        t.item_style_map(i, 'sent', 'read.we',
                                         ['text.unread', 'text.read'])
                        t.item_style_map(i, 'size', 'read.w',
                                         ['text.unread', 'text.read'])
                      else
                        # unread -> read2
                        t.item_style_map(i, 'subject', 'read2',
                                         ['text.unread', 'text.unread'])
                      end

                      @Message[:read][i] = true
                      @display_styles_in_item.call(i)
                    end
                  end
                }, '%T')

  t.notify_bind(t, 'Expand-after',
                proc{|w, i|
                  if @Messge[:read][i] && anyUnreadDescendants(t, i)
                    # read2 -> read
                    t.item_style_map(i, 'subject', 'read',
                                     ['text.unread', 'text.read'])
                    # unread -> read
                    t.item_style_map(i, 'from', 'read.we',
                                     ['text.unread', 'text.read'])
                    t.item_style_map(i, 'sent', 'read.we',
                                     ['text.unread', 'text.read'])
                    t.item_style_map(i, 'size', 'read.w',
                                     ['text.unread', 'text.read'])
                  end
                }, '%T %I')

  t.notify_bind(t, 'Collapse-after',
                proc{|w, i|
                  if @Messge[:read][i] && anyUnreadDescendants(t, i)
                    # read -> read2
                    t.item_style_map(i, 'subject', 'read2',
                                     ['text.read', 'text.unread'])
                    # read -> unread
                    t.item_style_map(i, 'from', 'unread.we',
                                     ['text.read', 'text.unread'])
                    t.item_style_map(i, 'sent', 'unread.we',
                                     ['text.read', 'text.unread'])
                    t.item_style_map(i, 'size', 'unread.w',
                                     ['text.read', 'text.unread'])
                  end
                }, '%T %I')

  (1...(msgCnt)).each{|i|
    if rand(2) == 0
      if t.item_numchildren(i) > 0
        if $Version_1_1_OrLater
          t.item_collapse(i)
        else # TreeCtrl 1.0
          t.collapse(i)
        end
      end
    end
  }
end

#demoRandom(t) ⇒ Object

Demo: random N items



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'sample/tkextlib/treectrl/random.rb', line 9

def demoRandom(t)
  init_pics('folder-*', 'small-*')

  height = t.font.metrics(:linespace)
  height = 18 if height < 18
  t.configure(:itemheight=>height, :selectmode=>:extended,
              :showroot=>true, :showrootbutton=>true, :showbuttons=>true,
              :showlines=>true, :scrollmargin=>16,
              :xscrolldelay=>[500, 50], :yscrolldelay=>[500, 50])

  if $Version_1_1_OrLater
    t.column_create(:expand=>true, :text=>'Item',
                    :itembackground=>['#e0e8f0', []], :tag=>'item')
    t.column_create(:text=>'Parent', :justify=>:center,
                    :itembackground=>['gray90', []], :tag=>'parent')
    t.column_create(:text=>'Depth', :justify=>:center,
                    :itembackground=>['linen', []], :tag=>'depth')
  else # TreeCtrl 1.0
    t.column_configure(0, :expand=>true, :text=>'Item',
                       :itembackground=>['#e0e8f0', []], :tag=>'item')
    t.column_configure(1, :text=>'Parent', :justify=>:center,
                       :itembackground=>['gray90', []], :tag=>'parent')
    t.column_configure(2, :text=>'Depth', :justify=>:center,
                       :itembackground=>['linen', []], :tag=>'depth')
  end

  t.element_create('e1', :image, :image=>[
                     @images['folder-open'], ['open'],
                     @images['folder-closed'], []
                   ])
  t.element_create('e2', :image, :image=>@images['small-file'])
  t.element_create('e3', :text,
                   :fill=>[@SystemHighlightText, ['selected', 'focus']])
  t.element_create('e4', :text, :fill=>'blue')
  t.element_create('e6', :text)
  t.element_create('e5', :rect, :showfocus=>true,
                   :fill=>[
                     @SystemHighlight, ['selected', 'focus'],
                     'gray', ['selected', '!focus']
                   ])

  s = t.style_create('s1')
  t.style_elements(s, ['e5', 'e1', 'e3', 'e4'])
  t.style_layout(s, 'e1', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e3', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e4', :padx=>[0,6], :expand=>:ns)
  t.style_layout(s, 'e5', :union=>['e3'], :iexpand=>:ns, :ipadx=>2)

  s = t.style_create('s2')
  t.style_elements(s, ['e5', 'e2', 'e3'])
  t.style_layout(s, 'e2', :padx=>[0,4], :expand=>:ns)
  t.style_layout(s, 'e3', :padx=>