chiark / gitweb /
wip subwindow
[chiark-tcl-applet.git] / applet.tcl
index e660bce7acbba766981b75cf9a68ab5052ee2c6c..4cf6e119545be2ea6783199e7316e6e2eebd6ee5 100644 (file)
@@ -36,9 +36,16 @@ package require tktray
 #      applet::setimage IMAGE
 #  as necessary.
 #
-# Inner window subprocess:
+# Alternatively, instead of icon, it may arrange to run (repeatedly
+# if necessary) a subprocess.
 #
-#  Caller that needs access to inner window should define
+#  Caller that needs access to inner window should call
+#      applet::setup-subwindow WIDTH ON-DESTROYING ON-READY
+#  Then the main code will call ON-DESTROYING just before
+#  destroying the inner window and recreating it, and ON-READY
+#  just after.  Afterwards, theh inner window is called
+#      .
+#     
 #     proc innerwindow {} { ... }
 #  and run
 #     innerwindow
@@ -174,23 +181,27 @@ proc setimage {image} {
     .i configure -image $image
 }
 
-}
+#----- subwindow -----
 
+variable subwindow_on_destroying
+variable subwindow_on_ready
 
 proc innerwindow-resetup-required {why} {
     variable innerwindow_after
 puts "IW-EVENT $why"
     if {[info exists innerwindow_after]} return
-    set innerwindow_after [after idle innerwindow-resetup]
+    set innerwindow_after [after idle applet::innerwindow-resetup]
 }
 
 proc innerwindow-resetup {} {
     variable innerwindow_after
+    variable subwindow_on_destroying
+    variable subwindow_on_ready
     unset innerwindow_after
 
 puts RESETUP
 
-    innerwindow-destroying
+    uplevel #0 $subwindow_on_destroying
 
     catch { destroy .i.i.c }
     if {![winfo exists .i.i]} return
@@ -211,19 +222,28 @@ puts RESETUP
 #      set inner_lastw $w
 #      set inner_lasth $h
 #      innerwindow-ph-dummy configure -width $w -height 2
-       innerwindow-ready
+
+    uplevel #0 $subwindow_on_ready
 #    }
 }
 
-proc setupinnerwindow {w} {
+proc setup-subwindow {w on_destroying on_ready} {
+    foreach v {destroying ready} {
+       variable subwindow_on_$v [set on_$v]
+    }
+
     global inner_lastw inner_lasth
     set inner_lastw -2
     set inner_lasth -2
 
-    image create photo innerwindow-ph-dummy -width $w -height 2
-    .i configure -image innerwindow-ph-dummy
+    image create photo applet::innerwindow-ph-dummy -width $w -height 2
+    .i configure -image applet::innerwindow-ph-dummy
 
     destroy [frame .i.make-exist]
     destroy [frame .i.i.make-exist]
-    bind .i <<IconConfigure>> { innerwindow-resetup-required IconConfigure }
+    bind .i <<IconConfigure>> { 
+       applet::innerwindow-resetup-required IconConfigure
+    }
+}
+
 }