1# 2# Mainwindow 3# ---------------------------------------------------------------------- 4# This class implements a mainwindow containing a menubar, toolbar, 5# mousebar, childsite, status line, and help line. Each item may 6# be filled and configured to suit individual needs. 7# 8# ---------------------------------------------------------------------- 9# AUTHOR: Mark L. Ulferts EMAIL: mulferts@austin.dsccc.com 10# 11# @(#) RCS: $Id: mainwindow.itk,v 1.2 2001/08/07 19:56:48 smithc Exp $ 12# ---------------------------------------------------------------------- 13# Copyright (c) 1997 DSC Technologies Corporation 14# ====================================================================== 15# Permission to use, copy, modify, distribute and license this software 16# and its documentation for any purpose, and without fee or written 17# agreement with DSC, is hereby granted, provided that the above copyright 18# notice appears in all copies and that both the copyright notice and 19# warranty disclaimer below appear in supporting documentation, and that 20# the names of DSC Technologies Corporation or DSC Communications 21# Corporation not be used in advertising or publicity pertaining to the 22# software without specific, written prior permission. 23# 24# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 25# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON- 26# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE 27# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, 28# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL 29# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 30# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 31# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION, 32# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 33# SOFTWARE. 34# ====================================================================== 35 36# ------------------------------------------------------------------ 37# MAINWINDOW 38# ------------------------------------------------------------------ 39itcl::class iwidgets::Mainwindow { 40 inherit iwidgets::Shell 41 42 constructor {args} {} 43 44 itk_option define -helpline helpLine HelpLine 1 45 itk_option define -statusline statusLine StatusLine 1 46 47 public { 48 method childsite {} 49 method menubar {args} 50 method mousebar {args} 51 method msgd {args} 52 method toolbar {args} 53 } 54 55 protected { 56 method _exitCB {} 57 58 common _helpVar 59 common _statusVar 60 } 61} 62 63# 64# Provide a lowercased access method for the ::iwidgets::Mainwindow class. 65# 66proc iwidgets::mainwindow {pathName args} { 67 uplevel ::iwidgets::Mainwindow $pathName $args 68} 69 70# ------------------------------------------------------------------ 71# CONSTRUCTOR 72# ------------------------------------------------------------------ 73itcl::body iwidgets::Mainwindow::constructor {args} { 74 itk_option add hull.width hull.height 75 76 pack propagate $itk_component(hull) no 77 78 wm protocol $itk_component(hull) WM_DELETE_WINDOW [itcl::code $this _exitCB] 79 80 # 81 # Create a menubar, renaming the font, foreground, and background 82 # so they may be separately set. The help variable will be setup 83 # as well. 84 # 85 itk_component add menubar { 86 iwidgets::Menubar $itk_interior.menubar \ 87 -helpvariable [itcl::scope _helpVar($this)] 88 } { 89 keep -disabledforeground -cursor \ 90 -highlightbackground -highlightthickness 91 rename -font \ 92 -menubarfont menuBarFont Font 93 rename -foreground \ 94 -menubarforeground menuBarForeground Foreground 95 rename -background \ 96 -menubarbackground menuBarBackground Background 97 } 98 99 # 100 # Add a toolbar beneath the menubar. 101 # 102 itk_component add toolbar { 103 iwidgets::Toolbar $itk_interior.toolbar -orient horizontal \ 104 -helpvariable [itcl::scope _helpVar($this)] 105 } { 106 keep -balloonbackground -balloondelay1 -balloondelay2 \ 107 -balloonfont -balloonforeground -disabledforeground -cursor \ 108 -highlightbackground -highlightthickness 109 rename -font -toolbarfont toolbarFont Font 110 rename -foreground -toolbarforeground toolbarForeground Foreground 111 rename -background -toolbarbackground toolbarBackground Background 112 } 113 114 # 115 # Add a mouse bar on the left. 116 # 117 itk_component add mousebar { 118 iwidgets::Toolbar $itk_interior.mousebar -orient vertical \ 119 -helpvariable [itcl::scope _helpVar($this)] 120 } { 121 keep -balloonbackground -balloondelay1 -balloondelay2 \ 122 -balloonfont -balloonforeground -disabledforeground -cursor \ 123 -highlightbackground -highlightthickness 124 rename -font -toolbarfont toolbarFont Font 125 rename -foreground -toolbarforeground toolbarForeground Foreground 126 rename -background -toolbarbackground toolbarBackground Background 127 } 128 129 # 130 # Create the childsite window window. 131 # 132 itk_component add -protected mwchildsite { 133 frame $itk_interior.mwchildsite 134 } 135 136 # 137 # Add the help and system status lines 138 # 139 itk_component add -protected lineframe { 140 frame $itk_interior.lineframe 141 } 142 143 itk_component add help { 144 label $itk_component(lineframe).help \ 145 -textvariable [itcl::scope _helpVar($this)] \ 146 -relief sunken -borderwidth 2 -width 10 147 } 148 149 itk_component add status { 150 label $itk_component(lineframe).status \ 151 -textvariable [itcl::scope _statusVar($this)] \ 152 -relief sunken -borderwidth 2 -width 10 153 } 154 155 # 156 # Create the message dialog for use throughout the mainwindow. 157 # 158 itk_component add msgd { 159 iwidgets::Messagedialog $itk_interior.msgd -modality application 160 } { 161 usual 162 ignore -modality 163 } 164 165 # 166 # Use the grid to pack together the menubar, toolbar, mousebar, 167 # childsite, and status area. 168 # 169 grid $itk_component(menubar) -row 0 -column 0 -columnspan 2 -sticky ew 170 grid $itk_component(toolbar) -row 1 -column 0 -columnspan 2 -sticky ew 171 grid $itk_component(mousebar) -row 2 -column 0 -sticky ns 172 grid $itk_component(mwchildsite) -row 2 -column 1 -sticky nsew \ 173 -padx 5 -pady 5 174 grid $itk_component(lineframe) -row 3 -column 0 -columnspan 2 -sticky ew 175 176 grid columnconfigure $itk_interior 1 -weight 1 177 grid rowconfigure $itk_interior 2 -weight 1 178 179 # 180 # Set the interior to be the childsite for derived classes. 181 # 182 set itk_interior $itk_component(mwchildsite) 183 184 # 185 # Initialize all the configuration options. 186 # 187 eval itk_initialize $args 188} 189 190# ------------------------------------------------------------------ 191# OPTIONS 192# ------------------------------------------------------------------ 193 194# ------------------------------------------------------------------ 195# OPTION: -helpline 196# 197# Specifies whether or not to display the help line. The value 198# may be given in any of the forms acceptable to Tk_GetBoolean. 199# ------------------------------------------------------------------ 200itcl::configbody iwidgets::Mainwindow::helpline { 201 if {$itk_option(-helpline)} { 202 pack $itk_component(help) -side left -fill x -expand yes -padx 2 203 } else { 204 pack forget $itk_component(help) 205 } 206} 207 208# ------------------------------------------------------------------ 209# OPTION: -statusline 210# 211# Specifies whether or not to display the status line. The value 212# may be given in any of the forms acceptable to Tk_GetBoolean. 213# ------------------------------------------------------------------ 214itcl::configbody iwidgets::Mainwindow::statusline { 215 if {$itk_option(-statusline)} { 216 pack $itk_component(status) -side right -fill x -expand yes -padx 2 217 } else { 218 pack forget $itk_component(status) 219 } 220} 221 222# ------------------------------------------------------------------ 223# METHODS 224# ------------------------------------------------------------------ 225 226# ------------------------------------------------------------------ 227# METHOD: childsite 228# 229# Return the childsite widget. 230# ------------------------------------------------------------------ 231itcl::body iwidgets::Mainwindow::childsite {} { 232 return $itk_component(mwchildsite) 233} 234 235# ------------------------------------------------------------------ 236# METHOD: menubar ?args? 237# 238# Evaluate the args against the Menubar component. 239# ------------------------------------------------------------------ 240itcl::body iwidgets::Mainwindow::menubar {args} { 241 if {[llength $args] == 0} { 242 return $itk_component(menubar) 243 } else { 244 return [eval $itk_component(menubar) $args] 245 } 246} 247 248# ------------------------------------------------------------------ 249# METHOD: toolbar ?args? 250# 251# Evaluate the args against the Toolbar component. 252# ------------------------------------------------------------------ 253itcl::body iwidgets::Mainwindow::toolbar {args} { 254 if {[llength $args] == 0} { 255 return $itk_component(toolbar) 256 } else { 257 return [eval $itk_component(toolbar) $args] 258 } 259} 260 261# ------------------------------------------------------------------ 262# METHOD: mousebar ?args? 263# 264# Evaluate the args against the Mousebar component. 265# ------------------------------------------------------------------ 266itcl::body iwidgets::Mainwindow::mousebar {args} { 267 if {[llength $args] == 0} { 268 return $itk_component(mousebar) 269 } else { 270 return [eval $itk_component(mousebar) $args] 271 } 272} 273 274# ------------------------------------------------------------------ 275# METHOD: msgd ?args? 276# 277# Evaluate the args against the Messagedialog component. 278# ------------------------------------------------------------------ 279itcl::body iwidgets::Mainwindow::msgd {args} { 280 if {[llength $args] == 0} { 281 return $itk_component(msgd) 282 } else { 283 return [eval $itk_component(msgd) $args] 284 } 285} 286 287# ------------------------------------------------------------------ 288# PRIVATE METHOD: _exitCB 289# 290# Menu callback for the exit option from the file menu. The method 291# confirms the user's request to exit the application prior to 292# taking the action. 293# ------------------------------------------------------------------ 294itcl::body iwidgets::Mainwindow::_exitCB {} { 295 # 296 # Configure the message dialog for confirmation of the exit request. 297 # 298 msgd configure -title Confirmation -bitmap questhead \ 299 -text "Exit confirmation\n\ 300 Are you sure ?" 301 msgd buttonconfigure OK -text Yes 302 msgd buttonconfigure Cancel -text No 303 msgd default Cancel 304 msgd center $itk_component(hull) 305 306 # 307 # Activate the message dialog and given a positive response 308 # proceed to exit the application 309 # 310 if {[msgd activate]} { 311 ::exit 312 } 313} 314