home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Freeware 31 / FreelogHS31.iso / Texte / scribus / scribus-1.3.3.9-win32-install.exe / tcl / tix8.1 / Primitiv.tcl < prev    next >
Text File  |  2001-11-18  |  11KB  |  433 lines

  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. #    $Id: Primitiv.tcl,v 1.2.2.2 2001/11/18 07:18:29 idiscovery Exp $
  4. #
  5. # Primitiv.tcl --
  6. #
  7. #    This is the primitive widget. It is just a frame with proper
  8. #    inheritance wrapping. All new Tix widgets will be derived from
  9. #    this widget
  10. #
  11. # Copyright (c) 1993-1999 Ioi Kim Lam.
  12. # Copyright (c) 2000-2001 Tix Project Group.
  13. #
  14. # See the file "license.terms" for information on usage and redistribution
  15. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  16. #
  17.  
  18.  
  19.  
  20. # No superclass, so the superclass switch is not used
  21. #
  22. #
  23. tixWidgetClass tixPrimitive {
  24.     -virtual true
  25.     -superclass {}
  26.     -classname  TixPrimitive
  27.     -method {
  28.     cget configure subwidget subwidgets
  29.     }
  30.     -flag {
  31.     -background -borderwidth -cursor
  32.     -height -highlightbackground -highlightcolor -highlightthickness
  33.     -options -relief -takefocus -width -bd -bg
  34.     }
  35.     -static {
  36.     -options
  37.     }
  38.     -configspec {
  39.     {-background background Background #d9d9d9} 
  40.     {-borderwidth borderWidth BorderWidth 0} 
  41.     {-cursor cursor Cursor ""} 
  42.     {-height height Height 0}
  43.     {-highlightbackground highlightBackground HighlightBackground #c3c3c3}
  44.     {-highlightcolor highlightColor HighlightColor black}
  45.     {-highlightthickness highlightThickness HighlightThickness 0} 
  46.     {-options options Options ""}
  47.     {-relief relief Relief flat}
  48.     {-takefocus takeFocus TakeFocus 0 tixVerifyBoolean} 
  49.     {-width width Width 0}
  50.     }
  51.     -alias {
  52.     {-bd -borderwidth}
  53.     {-bg -background}
  54.     }
  55. }
  56.  
  57. #----------------------------------------------------------------------
  58. # ClassInitialization:
  59. #----------------------------------------------------------------------
  60.  
  61. # not used
  62. # Implemented in C
  63. #
  64. # Override: never
  65. proc tixPrimitive:Constructor {w args} {
  66.  
  67.     upvar #0 $w data
  68.     upvar #0 $data(className) classRec
  69.  
  70.     # Set up some minimal items in the class record.
  71.     #
  72.     set data(w:root)  $w
  73.     set data(rootCmd) $w:root
  74.  
  75.     # We need to create the root widget in order to parse the options
  76.     # database
  77.     tixCallMethod $w CreateRootWidget
  78.  
  79.     # Parse the default options from the options database
  80.     #
  81.     tixPrimitive:ParseDefaultOptions $w
  82.  
  83.     # Parse the options supplied by the user
  84.     #
  85.     tixPrimitive:ParseUserOptions $w $args
  86.  
  87.     # Rename the widget command so that it can be use to access
  88.     # the methods of this class
  89.  
  90.     tixPrimitive:MkWidgetCmd $w
  91.  
  92.     # Inistalize the Widget Record
  93.     #
  94.     tixCallMethod $w InitWidgetRec
  95.  
  96.     # Construct the compound widget
  97.     #
  98.     tixCallMethod $w ConstructWidget
  99.  
  100.     # Do the bindings
  101.     #
  102.     tixCallMethod $w SetBindings
  103.  
  104.     # Call the configuration methods for all "force call" options
  105.     #
  106.     foreach option $classRec(forceCall) {
  107.     tixInt_ChangeOptions $w $option $data($option)
  108.     }
  109. }
  110.  
  111.  
  112. # Create only the root widget. We need the root widget to query the option
  113. # database.
  114. #
  115. # Override: seldom. (unless you want to use a toplevel as root widget)
  116. # Chain   : never.
  117.  
  118. proc tixPrimitive:CreateRootWidget {w args} {
  119.     upvar #0 $w data
  120.     upvar #0 $data(className) classRec
  121.  
  122.     frame $w -class $data(ClassName)
  123. }
  124.  
  125. proc tixPrimitive:ParseDefaultOptions {w} {
  126.     upvar #0 $w data
  127.     upvar #0 $data(className) classRec
  128.  
  129.     # SET UP THE INSTANCE RECORD ACCORDING TO DEFAULT VALUES IN
  130.     # THE OPTIONS DATABASE
  131.     #
  132.     foreach option $classRec(options) {
  133.     set spec [tixInt_GetOptionSpec $data(className) $option]
  134.  
  135.     if {[lindex $spec 0] == "="} {
  136.         continue
  137.     }
  138.  
  139.     set o_name    [lindex $spec 1]
  140.     set o_class   [lindex $spec 2]
  141.     set o_default [lindex $spec 3]
  142.  
  143.     if {![catch "option get $w $o_name $o_class" db_default]} {
  144.         if {$db_default != ""} {
  145.         set data($option) $db_default
  146.         } else {
  147.         set data($option) $o_default
  148.         }
  149.     } else {
  150.         set data($option) $o_default
  151.     }
  152.     }
  153. }
  154.  
  155. proc tixPrimitive:ParseUserOptions {w arglist} {
  156.     upvar #0 $w data
  157.     upvar #0 $data(className) classRec
  158.  
  159.     # SET UP THE INSTANCE RECORD ACCORDING TO COMMAND ARGUMENTS FROM
  160.     # THE USER OF THE TIX LIBRARY (i.e. Application programmer:)
  161.     #
  162.     tixForEach {option arg} $arglist {
  163.     if {[lsearch $classRec(options) $option] != "-1"} {
  164.         set spec [tixInt_GetOptionSpec $data(className) $option]
  165.  
  166.         if {[lindex $spec 0] != "="} {
  167.         set data($option) $arg
  168.         } else {
  169.         set realOption [lindex $spec 1]
  170.         set data($realOption) $arg
  171.         }
  172.     } else {
  173.         error "unknown option $option. Should be: [tixInt_ListOptions $w]"
  174.     }
  175.     }
  176. }
  177.  
  178. #----------------------------------------------------------------------
  179. # Initialize the widget record
  180. #
  181. # Override: always
  182. # Chain   : always, before
  183. proc tixPrimitive:InitWidgetRec {w} {
  184.     # default: do nothing
  185. }
  186.  
  187. #----------------------------------------------------------------------
  188. # SetBindings
  189. #
  190. # Override: sometimes
  191. # Chain   : sometimes, before
  192. #
  193. bind TixDestroyHandler <Destroy> {
  194.     [tixGetMethod %W [set %W(className)] Destructor] %W
  195. }
  196.  
  197. proc tixPrimitive:SetBindings {w} {
  198.     upvar #0 $w data
  199.  
  200.     if {[winfo toplevel $w] == $w} {
  201.     bindtags $w [concat TixDestroyHandler [bindtags $w]]
  202.     } else {
  203.     bind $data(w:root) <Destroy> \
  204.         "[tixGetMethod $w $data(className) Destructor] $w"
  205.     }
  206. }
  207.  
  208. #----------------------------------------------------------------------
  209. # PrivateMethod: ConstructWidget
  210. # Construct and set up the compound widget
  211. #
  212. # Override: sometimes
  213. # Chain   : sometimes, before
  214. #
  215. proc tixPrimitive:ConstructWidget {w} {
  216.     upvar #0 $w data
  217.  
  218.     $data(rootCmd) config \
  219.     -background  $data(-background) \
  220.     -borderwidth $data(-borderwidth) \
  221.     -cursor      $data(-cursor) \
  222.     -relief      $data(-relief)
  223.  
  224.     if {$data(-width) != 0} {
  225.     $data(rootCmd) config -width $data(-width)
  226.     }
  227.     if {$data(-height) != 0} {
  228.     $data(rootCmd) config -height $data(-height)
  229.     }
  230.  
  231.     set rootname *[string range $w 1 end]
  232.  
  233.     tixForEach {spec value} $data(-options) {
  234.     option add $rootname*$spec $value 100
  235.     }
  236. }
  237.  
  238. #----------------------------------------------------------------------
  239. # PrivateMethod: MkWidgetCmd
  240. # Construct and set up the compound widget
  241. #
  242. # Override: sometimes
  243. # Chain   : sometimes, before
  244. #
  245. proc tixPrimitive:MkWidgetCmd {w} {
  246.     upvar #0 $w data
  247.  
  248.     rename $w $data(rootCmd)
  249.     tixInt_MkInstanceCmd $w
  250. }
  251.  
  252.  
  253. #----------------------------------------------------------------------
  254. # ConfigOptions:
  255. #----------------------------------------------------------------------
  256.  
  257. #----------------------------------------------------------------------
  258. # ConfigMethod: config
  259. #
  260. # Configure one option.
  261. # Override: always
  262. # Chain   : automatic.
  263. #
  264. # Note the hack of [winfo width] in this procedure
  265. #
  266. # The hack is necessary because of the bad interaction between TK's geometry
  267. # manager (the packer) and the frame widget. The packer determines the size
  268. # of the root widget of the ComboBox (a frame widget) according to the
  269. # requirement of the slaves inside the frame widget, NOT the -width
  270. # option of the frame widget.
  271. #
  272. # However, everytime the frame widget is
  273. # configured, it sends a geometry request to the packer according to its
  274. # -width and -height options and the packer will temporarily resize
  275. # the frame widget according to the requested size! The packer then realizes
  276. # something is wrong and revert to the size determined by the slaves. This
  277. # cause a flash on the screen.
  278. #
  279. foreach opt {-height -width -background -borderwidth -cursor
  280.         -highlightbackground -highlightcolor -relief -takefocus -bd -bg} {
  281.  
  282.     set tixPrimOpt($opt) 1
  283. }
  284.  
  285. proc tixPrimitive:config {w option value} {
  286.     global tixPrimOpt
  287.     upvar #0 $w data
  288.  
  289.     if {[info exists tixPrimOpt($option)]} {
  290.     $data(rootCmd) config $option $value
  291.     }
  292. }
  293.  
  294. #----------------------------------------------------------------------
  295. # PublicMethods:
  296. #----------------------------------------------------------------------
  297.  
  298. #----------------------------------------------------------------------
  299. # This method is used to implement the "subwidgets" widget command.
  300. # Will be re-written in C. It can't be used as a public method because
  301. # of the lame substring comparison routines used in tixClass.c
  302. #
  303. #
  304. proc tixPrimitive:subwidgets {w type args} {
  305.     upvar #0 $w data
  306.  
  307.     case $type {
  308.     -class {
  309.         set name [lindex $args 0]
  310.         set args [lrange $args 1 end]
  311.         # access subwidgets of a particular class
  312.         #
  313.         # note: if $name=="Frame", will *not return the root widget as well
  314.         #
  315.         set sub ""
  316.         foreach des [tixDescendants $w] {
  317.         if {[winfo class $des] == $name} {
  318.             lappend sub $des
  319.         }
  320.         }
  321.  
  322.         # Note: if the there is no subwidget of this class, does not
  323.         # cause any error.
  324.         #
  325.         if {$args == ""} {
  326.         return $sub
  327.         } else {
  328.         foreach des $sub {
  329.             eval $des $args
  330.         }
  331.         return ""
  332.         }
  333.     }
  334.     -group {
  335.         set name [lindex $args 0]
  336.         set args [lrange $args 1 end]
  337.         # access subwidgets of a particular group
  338.         #
  339.         if {[info exists data(g:$name)]} {
  340.         if {$args == ""} {
  341.             set ret ""
  342.             foreach item $data(g:$name) {
  343.             lappend ret $w.$item
  344.             }
  345.             return $ret
  346.         } else {
  347.             foreach item $data(g:$name) {
  348.             eval $w.$item $args
  349.             }
  350.             return ""
  351.         }
  352.         } else {
  353.         error "no such subwidget group $name"
  354.         }
  355.     }
  356.     -all {
  357.         set sub [tixDescendants $w]
  358.  
  359.         if {$args == ""} {
  360.         return $sub
  361.         } else {
  362.         foreach des $sub {
  363.             eval $des $args
  364.         }
  365.         return ""
  366.         }
  367.     }
  368.     default {
  369.         error "unknown flag $type, should be -all, -class or -group"
  370.     }
  371.     }
  372. }
  373.  
  374. #----------------------------------------------------------------------
  375. # PublicMethod: subwidget
  376. #
  377. # Access a subwidget withe a particular name 
  378. #
  379. # Override: never
  380. # Chain   : never
  381. #
  382. # This is implemented in native C code in tixClass.c
  383. #
  384. proc tixPrimitive:subwidget {w name args} {
  385.     upvar #0 $w data
  386.  
  387.     if {[info exists data(w:$name)]} {
  388.     if {$args == ""} {
  389.         return $data(w:$name)
  390.     } else {
  391.         return [eval $data(w:$name) $args]
  392.     }
  393.     } else {
  394.     error "no such subwidget $name"
  395.     }
  396. }
  397.  
  398.  
  399. #----------------------------------------------------------------------
  400. # PrivateMethods:
  401. #----------------------------------------------------------------------
  402.  
  403. # delete the widget record and remove the command
  404. #
  405. proc tixPrimitive:Destructor {w} {
  406.     upvar #0 $w data
  407.  
  408.     if {![info exists data(w:root)]} {
  409.     return
  410.     }
  411.  
  412.     if {[info commands $w] != ""} {
  413.     # remove the command
  414.     #
  415.     rename $w ""
  416.     }
  417.  
  418.     if {[info commands $data(rootCmd)] != ""} {
  419.     # remove the command of the root widget
  420.     #
  421.     rename $data(rootCmd) ""
  422.     }
  423.  
  424.     # delete the widget record
  425.     #
  426.     catch {unset data}
  427. }
  428.