#.====================================================================
# [incr Tk] File
#.====================================================================
#. $Revision:
#. $Date:
#.====================================================================
#. File Name:     euidlwm.tk
#. Author:        Eric Teagle
#. Description:   Wraps tk's wm function
#.
#.====================================================================
#. Copyright 1999 SAS IP, Inc. Proprietary Data.
#. Unauthorized use, distribution, or duplication is prohibited.
#. All Rights Reserved.
#.====================================================================

# --------------------------------------------------------------------
# PUBLIC PROC:    wm ?option? args
#
# Purpose:        Added new functionality to the "wm" command so we
#                 can get window borderwidth and title height information.
#
# Arguments:      option    - the option for the wm command
#                 args      - arguments for the option
#
# Return Value:   information based on the option
#
# Comments:       
#
# See Also:       N/A
#
# --------------------------------------------------------------------
proc ::euidl::wm {option args} {

   switch -- $option {
      borderwidth {
         if { [llength $args] > 1 } {
            return -code error \
               "wrong # args: should be \"wm borderwidth window\""
         }

         if { ![winfo exists $args] } {
            return -code error "bad window path name \"$args\""
         }

         if { ![string match [winfo toplevel $args] $args] } {
            return -code error "window \"$args\" isn't a top-level window"
         }

         set window $args

         set rootX [wm rootx $window]
         set interiorX [winfo rootx $window]

         return [expr $interiorX - $rootX]
      }
      titleheight {
         if { [llength $args] > 1 } {
            return -code error \
               "wrong # args: should be \"winfo titleheight window\""
         }

         if { ![winfo exists $args] } {
            return -code error "bad window path name \"$args\""
         }

         if { ![string match [winfo toplevel $args] $args] } {
            return -code error "window \"$args\" isn't a top-level window"
         }

         set win $args

         set rootY [wm rooty $win]
         set interiorY [winfo rooty $win]

         return [expr $interiorY - $rootY - [wm borderwidth $win]]
      }
      rootx {
         if { [llength $args] > 1 } {
            return -code error \
               "wrong # args: should be \"wm rootx window\""
         }

         if { ![winfo exists $args] } {
            return -code error "bad window path name \"$args\""
         }

         if { ![string match [winfo toplevel $args] $args] } {
            return -code error "window \"$args\" isn't a top-level window"
         }

         set win $args

         set geom [wm geom $win]

         regexp {([0-9]*)x([0-9]*)([-+]*[0-9]*)([-+]*[0-9]*)} $geom match \
            width height windowX windowY

         return [expr $windowX]
      }
      rooty {
         if { [llength $args] > 1 } {
            return -code error \
               "wrong # args: should be \"wm rooty window\""
         }

         if { ![winfo exists $args] } {
            return -code error "bad window path name \"$args\""
         }

         if { ![string match [winfo toplevel $args] $args] } {
            return -code error "window \"$args\" isn't a top-level window"
         }

         set win $args

         set geom [wm geom $win]

         regexp {([0-9]*)x([0-9]*)([-+]*[0-9]*)([-+]*[0-9]*)} $geom match \
            width height windowX windowY

         return [expr $windowY]
      }
      menuheight {
         if { [llength $args] > 1 } {
            return -code error \
               "wrong # args: should be \"wm menuheight window\""
         }
         set mnuHeight 0
         if {![string match {} [$args cget -menu]]} {
            set mnuName [file extension [$args cget -menu]]
            regsub {.} $mnuName {} mnuName
            regsub {.} $args {} mnuParent
            set mnuHeight \
                  [winfo height $args.#$mnuParent#$mnuName]
         }
         return $mnuHeight
      }
      default {
         return [eval ::wm $option $args]
      }
   }
}
