1#!/bin/sh
2# the next line restarts using tclsh \
3exec tclsh "$0" "$@"
4
5# $Id: test-window.tcl,v 1.13 2005/02/26 23:01:32 baum Exp $
6
7# ensure that "." is the decimal point
8unset -nocomplain env(LC_ALL)
9set ::env(LC_NUMERIC) "C"
10
11set auto_path [linsert $auto_path 0 [file join [file dirname [info script]] ../src]]
12package require Gnocl
13
14proc assert { opt val } {
15   set val2 [$::win cget $opt]
16   if { $val != $val2 } {
17      error "$opt: $val != $val2"
18   }
19   puts "$opt: $val == $val2"
20}
21
22set win [gnocl::window]
23
24set child [gnocl::label -text "Hello"]
25$win configure -child $child
26assert -child $child
27
28foreach opt {-defaultWidth -defaultHeight} {
29   foreach val {100 200 300 100} {
30      $win configure $opt $val
31      assert $opt $val
32   }
33}
34
35foreach opt {-allowGrow -allowShrink -modal -resizable -sensitive} {
36   foreach val {0 1 0 1} {
37      $win configure $opt $val
38      assert $opt $val
39   }
40}
41
42# FIXME -dragTargets does not work
43foreach opt {-data -dropTargets \
44      -onDelete -onDestroy -onDragData -onDropData -onKeyPress \
45      -onKeyRelease -onPopupMenu -onShowHelp -title -tooltip} {
46   foreach val {"aaa" "bbb ccc" "" "" "ccc" "" "ddd" ""} {
47      $win configure $opt $val
48      assert $opt $val
49   }
50}
51
52foreach opt { -x -y -width -height } {
53   foreach val {100 200 300 100} {
54      $win configure $opt $val
55      gnocl::update
56      after 200
57      gnocl::update
58      assert $opt $val
59   }
60}
61
62$win delete
63
64puts "----- automatic tests done ------------"
65
66gnocl::configure -defaultIcon "%/./one.png"
67set noUpdates 0
68
69proc onDelete { win } {
70   set ret [gnocl::dialog -type question -text "Really close window?" \
71         -buttons "%#Cancel %#Close"]
72   if { [string compare $ret Cancel] == 0 } {
73      return 0
74   }
75   return 1
76}
77
78set box [gnocl::box -orientation vertical]
79set testWindow [gnocl::window -child $box -title "Test Window" \
80      -onShowHelp {puts "show help %w %h"} \
81      -onPopupMenu {puts "%w popup menu"} -tooltip "tooltip" \
82      -onKeyPress {puts [list KeyPress: %w %k %K %a]} \
83      -onKeyRelease {puts [list KeyRelease: %w %k %K %a]} \
84      -onDestroy { puts "destroying %w" } \
85      -onDelete { onDelete %w } \
86      -icon "%/./c.png" \
87      -defaultWidth 300 -defaultHeight 200 ]
88
89$box add [gnocl::checkButton -text "allowShrink"  \
90      -onToggled "$testWindow configure -allowShrink %v"]
91$box add [gnocl::checkButton -text "allowGrow"  \
92      -onToggled "$testWindow configure -allowGrow %v"]
93$box add [gnocl::checkButton -text "resizable" -active 1 \
94      -onToggled "$testWindow configure -resizable %v"]
95$box add [gnocl::checkButton -text "modal" \
96      -onToggled "$testWindow configure -modal %v"]
97
98set box [gnocl::box -orientation vertical]
99$box add [gnocl::checkButton -text "visible" -active 1 \
100      -onToggled "$testWindow configure -visible %v"]
101$box add [gnocl::checkButton -text "iconify" -active 0 \
102      -onToggled "$testWindow iconify %v"]
103$box add [gnocl::checkButton -text "sensitive" -active 1 \
104      -onToggled "$testWindow configure -sensitive %v"]
105$box add [gnocl::box -orientation horizontal -borderWidth 0 -children [list \
106      [gnocl::label -text "x" -widthGroup labelGroup] \
107      [gnocl::spinButton -lower 0 -upper 400 -stepInc 10 -digits 0 \
108            -value 10 \
109            -onValueChanged "$testWindow configure -x %v"]]]
110$box add [gnocl::box -orientation horizontal -borderWidth 0 -children [list \
111      [gnocl::label -text "y" -widthGroup labelGroup] \
112      [gnocl::spinButton -lower 0 -upper 400 -stepInc 10 -digits 0 \
113            -value 10 \
114            -onValueChanged "$testWindow configure -y %v"]]]
115$box add [gnocl::box -orientation horizontal -borderWidth 0 -children [list \
116      [gnocl::label -text "width" -widthGroup labelGroup] \
117      [gnocl::spinButton -lower 10 -upper 400 -stepInc 10 -digits 0 \
118            -value 200 \
119            -onValueChanged "$testWindow configure -width %v"]]]
120$box add [gnocl::box -orientation horizontal -borderWidth 0 -children [list \
121      [gnocl::label -text "height" -widthGroup labelGroup] \
122      [gnocl::spinButton -lower 10 -upper 400 -stepInc 10 -digits 0 \
123            -value 200 \
124            -onValueChanged "$testWindow configure -height %v"]]]
125
126if { $argc == 1 } {
127   set win [gnocl::plug -socketID [lindex $argv 0] -child $box -onDestroy exit]
128} else {
129   set win [gnocl::window -child $box -onDestroy exit]
130}
131
132gnocl::mainLoop
133
134