File: StdMenuBar.tcl

package info (click to toggle)
roleplaying 2.0-8
  • links: PTS
  • area: main
  • in suites: woody
  • size: 16,620 kB
  • ctags: 1,039
  • sloc: tcl: 7,155; cpp: 2,709; ansic: 2,227; makefile: 559; sh: 330; csh: 3
file content (297 lines) | stat: -rw-r--r-- 9,872 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#* 
#* ------------------------------------------------------------------
#* Role PlayingDB V2.0 by Deepwoods Software
#* ------------------------------------------------------------------
#* StdMenuBar.tcl - Standardized Menubar support code.
#* Created by Robert Heller on Sat Aug  8 09:41:22 1998
#* ------------------------------------------------------------------
#* Modification History: 
#* $Log: StdMenuBar.tcl,v $
#* Revision 1.5  1999/07/13 01:30:12  heller
#* Fix documentation: spelling, punctuation, etc.
#*
#* Revision 1.4  1999/04/20 13:15:09  heller
#* Final changes
#*
#* Revision 1.3  1999/03/28 06:20:44  heller
#* Update on-line help.
#*
#* Revision 1.2  1998/12/27 20:49:36  heller
#* Fix spelling errors
#*
#* Revision 1.1  1998/12/27 17:17:54  heller
#* Initial revision
#*
#* ------------------------------------------------------------------
#* Contents:
#* ------------------------------------------------------------------
#*  
#*     Role Playing DB -- A database package that creates and maintains
#* 		       a database of RPG characters, monsters, treasures,
#* 		       spells, and playing environments.
#* 
#*     Copyright (C) 1995,1998  Robert Heller D/B/A Deepwoods Software
#* 			51 Locke Hill Road
#* 			Wendell, MA 01379-9728
#* 
#*     This program is free software; you can redistribute it and/or modify
#*     it under the terms of the GNU General Public License as published by
#*     the Free Software Foundation; either version 2 of the License, or
#*     (at your option) any later version.
#* 
#*     This program is distributed in the hope that it will be useful,
#*     but WITHOUT ANY WARRANTY; without even the implied warranty of
#*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#*     GNU General Public License for more details.
#* 
#*     You should have received a copy of the GNU General Public License
#*     along with this program; if not, write to the Free Software
#*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#* 
#*  
#* 

#@Chapter:StdMenuBar.tcl -- Create standard menubars
#@Label:StdMenuBar.tcl
#$Id: StdMenuBar.tcl,v 1.5 1999/07/13 01:30:12 heller Rel1 $
# This file contains code to create a standard Motif style menubar.
# A standard menubar contains ``File'', ``Edit'', ``View'', ``Options'',
# and ``Help'' pulldown menus.  The ``File'', ``Edit'', and ``Help'' menus
# have standard menu items.
#
# The menubars and menus generated by the procedures in this file fill the
# standards set forth in the Motif Style Guide.

proc MakePullDown {menu args} {
# This procedure creates a pulldown menu and adds the items specified
# in its argument list.
# <in> menu -- the menu to create.
# <in> args -- the items to place in the menu.
# [index] MakePullDown!procedure

  menu $menu -tearoff {0}
  foreach a $args {
    eval [concat $menu add $a]
  }
}

proc MakeFilePullDown {menu} {
# This procedure creates a standard File menu.
# <in> menu -- the menu to create.
# [index] MakeFilePullDown!procedure

 MakePullDown $menu \
	{command -label {New} -underline {0}} \
        {command -label {Open...} -underline {0}} \
        {command -label {Save} -underline {0}} \
        {command -label {Save As...} -underline {5}} \
        {command -label {Print...} -underline {0}} \
	{command -label {Close} -underline {0}} \
	{command -label {Exit} -underline {1}}
}

proc MakeEditPullDown {menu} {
# This procedure creates a standard Edit menu.
# <in> menu -- the menu to create.
# [index] MakeEditPullDown!procedure

    MakePullDown $menu \
	{command -label {Undo} -underline {0}} \
	{command -label {Cut} -underline {2}} \
	{command -label {Copy} -underline {0}} \
	{command -label {Paste} -underline {0}} \
	{command -label {Clear} -underline {1}} \
	{command -label {Delete} -underline {0}} \
	{command -label {Select All}} \
	{command -label {De-select All}}
}

proc MakeHelpPullDown {menu} {
# This procedure creates a standard Help menu.
# <in> menu -- the menu to create.
# [index] MakeHelpPullDown!procedure

    MakePullDown $menu \
	[list command -label {On Context...} -state {active} -underline {3} -command "HelpContext \[GetTopLevelOfFocus $menu\]"] \
	{command -label {On Help...} -underline {3} -command {HelpTopic Help}} \
	[list command -label {On Window...} -underline {3} -command "HelpWindow \[GetTopLevelOfFocus $menu\]"] \
	{command -label {On Keys...} -underline {3} -command {HelpTopic Keys}} \
	{command -label {Index...} -underline {0} -command {HelpTopic Index}} \
	{command -label {Tutorial...} -underline {0} -command {HelpTopic Tutorial}} \
	{command -label {On Version...} -underline {3} -command {HelpTopic Version}} \
	{command -label {Warranty...} -command {HelpTopic Warranty}} \
	{command -label {Copying...} -command {HelpTopic Copying}} \
	{command -label {Registering...} -command {HelpTopic Registering}}
}

proc MakeStandardMenuBar {{name .menuBar} {toplevel .}} {
# This procedure creates a standard Motif style menu bar.  If this is run under
# Tcl/Tk 8.0, then the menu -type menubar / .toplevel config -menu .menu hack
# is used.  For older versions of Tcl/Tk, a conventional horizontal frame of
# menubuttons is packed into the top of the toplevel.
# <in> name -- the name of the menu bar.
# <in> toplevel -- the name of the toplevel to pack the menu into.
# [index] MakeStandardMenuBar!procedure


  global tk_version
  if {$tk_version < 8.0} {
# Pre 8.0 systems: create a frame of menubuttons
    frame $name -borderwidth {2} -relief {raised}
    pack $name -in $toplevel -fill x
    menubutton $name.fileMb \
	 -menu $name.fileMb.menu \
	 -padx {4} \
	 -pady {3} \
	 -text {File} \
	 -underline {0}
    pack $name.fileMb -side left
    MakeFilePullDown $name.fileMb.menu

    menubutton $name.editMb \
	 -menu $name.editMb.menu \
	 -padx {4} \
	 -pady {3} \
	 -text {Edit} \
	 -underline {0}
    pack $name.editMb -side left
    MakeEditPullDown $name.editMb.menu

    menubutton $name.viewMb \
	    -menu $name.viewMb.menu \
	    -padx {4} \
	    -pady {3} \
	    -text {View} \
	    -underline {0}
    pack $name.viewMb -side left

    MakePullDown $name.viewMb.menu

    menubutton $name.optionsMb \
	    -menu $name.optionsMb.menu \
	    -padx {4} \
	    -pady {3} \
	    -text {Options} \
	    -underline {0}
    pack $name.optionsMb -side left

    MakePullDown $name.optionsMb.menu

    menubutton $name.helpMb \
	    -menu $name.helpMb.menu \
	    -padx {4} \
	    -pady {3} \
	    -text {Help} \
	    -underline {0}
    pack $name.helpMb -side right

    MakeHelpPullDown $name.helpMb.menu 
  } else {
# 8.0 or later: create a menu bar menu and configure it into the toplevel
    menu $name -tearoff 0 -type menubar
    $toplevel configure -menu $name    
    $name add cascade -label {File} -menu $name.file -underline {0}
    MakeFilePullDown $name.file
    $name add cascade -label {Edit} -menu $name.edit -underline {0}
    MakeEditPullDown $name.edit
    $name add cascade -label {View} -menu $name.view -underline {0}
    MakePullDown $name.view
    $name add cascade -label {Options} -menu $name.options -underline {0}
    MakePullDown $name.options
    $name add cascade -label {Help} -menu $name.help -underline {0}
    MakeHelpPullDown $name.help
# Special platform dependent menu items:
    global tcl_platform
    if {$tcl_platform(platform) == "macintosh"} {
#     MacOS gets an "apple" menu.
      $name add cascade -label {Apple} -menu $name.apple
      MakePullDown $name.apple
    }
    if {$tcl_platform(platform) == "windows"} {
#     MS-Windows gets a "system" menu.
      $name add cascade -label {System} -menu $name.system
      MakePullDown $name.system
    }
  }
}

proc remoSp {string} {
# Procedure to remove random whitespace characters.
# <in> string -- the string to remove space from.
# [index] remoSp!procedure

  if {[regsub "\[ \t\]" "$string" {} newstring] > 0} {
    return "$newstring"  } else {
    return "$string"  }
}

proc AddExtraMenuButton {buttonLabel {mbar .menuBar}} {
# Procedure to add an extra menu button to a menu bar.  Typically this would be
# something like a ``Windows'' or ``Special'' menu.
# <in> buttonLabel -- the menu button label.
# <in> mbar -- the menubar to add the menu button to.
# [index] AddExtraMenuButton!procedure

  set menu "[string tolower [remoSp $buttonLabel]]"
  global tk_version
  if {$tk_version < 8.0} {
    set mbName $menu
    append mbName "Mb"
    menubutton $mbar.$mbName \
	-menu $mbar.$mbName.menu \
	-text "$buttonLabel"
    pack $mbar.$mbName -side left
    MakePullDown $mbar.$mbName.menu
  } else {
    $mbar add cascade -label "$buttonLabel" -menu $mbar.$menu
    MakePullDown $mbar.$menu
  }
}

proc GetMenuByName {label {mbar .menuBar}} {
# Procedure to fetch the menu associated with the named label.
# <in> label -- the label to look for.
# <in> mbar -- the menu bar to search.
# [index] GetMenuByName!procedure

  global tk_version
  if {$tk_version < 8.0} {
    foreach c [winfo children $mbar] {
      if {[string compare "$label" "[$c cget -text]"] == 0} {
        return "[$c cget -menu]"
      }
    }
    return {}
  } else {
    if {[catch [list $mbar entrycget "$label" -menu] menu]} {
      return {}
    } else {
      return $menu
    }
  }
}

proc DeleteMenuByName {label {mbar .menuBar}} {
# Procedure to delete a menu button from a menu bar.
# <in> label -- the menu button to delete.
# <in> mbar -- the menubar to delete the menu button from.
# [index] DeleteMenuByName!procedure

  global tk_version
  if {$tk_version < 8.0} {
    foreach c [winfo children $mbar] {
      if {[string compare "$label" "[$c cget -text]"] == 0} {
        catch [list destroy "[$c cget -menu]"]
	catch [list destroy $c]
	return 1
      }
    }
    return 0
  } else {
    catch [list destroy "[$mbar entrycget $label -menu]"]
    catch [list $mbar delete $label]
    return 1
  }
}

package provide StdMenuBar 1.0