| 1 |
# Copyright (c) 1990 The Regents of the University of California. |
| 2 |
# Copyright (c) 1994 Sun Microsystems, Inc. |
| 3 |
# See the file "license.terms" for information on usage and redistribution |
| 4 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 5 |
# |
| 6 |
# @(#) CrtMainWin.3 1.20 95/05/06 15:29:16 |
| 7 |
# |
| 8 |
|
| 9 |
=head1 NAME |
| 10 |
|
| 11 |
Tk_CreateMainWindow, Tk_CreateWindow, Tk_CreateWindowFromPath, Tk_DestroyWindow, Tk_MakeWindowExist - create or delete window |
| 12 |
|
| 13 |
=for category C Programming |
| 14 |
|
| 15 |
=head1 SYNOPSIS |
| 16 |
|
| 17 |
B<#include E<lt>tk.hE<gt>> |
| 18 |
|
| 19 |
Tk_Window |
| 20 |
B<Tk_CreateMainWindow>(I<interp, screenName, baseName, className>) |
| 21 |
|
| 22 |
Tk_Window |
| 23 |
B<Tk_CreateWindow>(I<interp, parent, name, topLevScreen>) |
| 24 |
|
| 25 |
Tk_Window |
| 26 |
B<Tk_CreateWindowFromPath>(I<interp, tkwin, pathName, topLevScreen>) |
| 27 |
|
| 28 |
B<Tk_DestroyWindow>(I<tkwin>) |
| 29 |
|
| 30 |
B<Tk_MakeWindowExist>(I<tkwin>) |
| 31 |
|
| 32 |
=head1 ARGUMENTS |
| 33 |
|
| 34 |
=over 4 |
| 35 |
|
| 36 |
=item Tcl_Interp *interp (out) |
| 37 |
|
| 38 |
Tcl interpreter to use for error reporting. If no error occurs, |
| 39 |
then I<*interp> isn't modified. For B<Tk_CreateMainWindow>, |
| 40 |
this interpreter is associated permanently with the created window, |
| 41 |
and Tk-related commands are bound into the interpreter. |
| 42 |
|
| 43 |
=item char *screenName (in) |
| 44 |
|
| 45 |
String name of screen on which to create window. Has the form |
| 46 |
I<displayName>B<.>I<screenNum>, where I<displayName> is the |
| 47 |
name of a display and I<screenNum> is a screen number. If |
| 48 |
the dot and I<screenNum> are omitted, the screen number defaults |
| 49 |
to 0. If I<screenName> is NULL or empty string, defaults to |
| 50 |
contents of DISPLAY environment variable. |
| 51 |
|
| 52 |
=item char *baseName (in) |
| 53 |
|
| 54 |
Name to use for this main window. See below for details. |
| 55 |
|
| 56 |
=item char *className (in) |
| 57 |
|
| 58 |
Class to use for application and for main window. |
| 59 |
|
| 60 |
=item Tk_Window parent (in) |
| 61 |
|
| 62 |
Token for the window that is to serve as the logical parent of |
| 63 |
the new window. |
| 64 |
|
| 65 |
=item char *name (in) |
| 66 |
|
| 67 |
Name to use for this window. Must be unique among all children of |
| 68 |
the same I<parent>. |
| 69 |
|
| 70 |
=item char *topLevScreen (in) |
| 71 |
|
| 72 |
Has same format as I<screenName>. If NULL, then new window is |
| 73 |
created as an internal window. If non-NULL, new window is created as |
| 74 |
a top-level window on screen I<topLevScreen>. If I<topLevScreen> |
| 75 |
is an empty string (``'') then new |
| 76 |
window is created as top-level window of I<parent>'s screen. |
| 77 |
|
| 78 |
=item Tk_Window tkwin (in) |
| 79 |
|
| 80 |
Token for window. |
| 81 |
|
| 82 |
=item char *pathName (in) |
| 83 |
|
| 84 |
Name of new window, specified as path name within application |
| 85 |
(e.g. B<.a.b.c>). |
| 86 |
|
| 87 |
=back |
| 88 |
|
| 89 |
=head1 DESCRIPTION |
| 90 |
|
| 91 |
The three procedures B<Tk_CreateMainWindow>, B<Tk_CreateWindow>, |
| 92 |
and B<Tk_CreateWindowFromPath> are used to create new windows for |
| 93 |
use in Tk-based applications. Each of the procedures returns a token |
| 94 |
that can be used to manipulate the window in other calls to the Tk |
| 95 |
library. If the window couldn't be created successfully, then NULL |
| 96 |
is returned and I<interp-E<gt>result> is modified to hold an error |
| 97 |
message. |
| 98 |
|
| 99 |
Tk supports three different kinds of windows: main windows, internal |
| 100 |
windows, and top-level windows. |
| 101 |
A main window is the outermost window corresponding to an application. |
| 102 |
Main windows correspond to the independent units of an application, |
| 103 |
such as a view on a file that is part of an editor, or a clock, or |
| 104 |
a terminal emulator. A main window is created as a child of the root |
| 105 |
window of the screen indicated by the I<screenName>. Each main |
| 106 |
window, and all its descendants, are typically associated with a |
| 107 |
single Tcl command interpreter. |
| 108 |
An internal window is an interior window of a Tk application, such as a |
| 109 |
scrollbar or menu bar or button. A top-level window is one that is |
| 110 |
created as a child of a screen's root window, rather than as an |
| 111 |
interior window, but which is logically part of some existing main |
| 112 |
window. Examples of top-level windows are pop-up menus and dialog boxes. |
| 113 |
|
| 114 |
B<Tk_CreateMainWindow> creates a new main window and associates |
| 115 |
its I<interp> argument with that window and all its eventual |
| 116 |
descendants. |
| 117 |
B<Tk_CreateMainWindow> also carries out several other actions to |
| 118 |
set up the new application. |
| 119 |
First, it adds all the Tk commands to those already defined |
| 120 |
for I<interp>. |
| 121 |
Second, it turns the new window into a B<toplevel> widget, which |
| 122 |
will cause the X window to be created and mapped as soon as the |
| 123 |
application goes idle. |
| 124 |
Third, B<Tk_CreateMainWindow> registers I<interp> so that it |
| 125 |
can be accessed remotely by other Tk applications using the B<send> |
| 126 |
command and the name I<baseName>. Normally, I<baseName> consists |
| 127 |
of the name of the application followed by a space and an identifier for this |
| 128 |
particular main window (if such an identifier is relevant). For example, |
| 129 |
an editor named B<mx> displaying the file B<foo.c> would use |
| 130 |
``mx foo.c'' as the basename. An application that doesn't usually |
| 131 |
have multiple instances, such as a clock program, would just use the |
| 132 |
name of the application, e.g. ``xclock''. If I<baseName> is already |
| 133 |
in use by some other registered interpreter, then B<Tk_CreateMainWindow> |
| 134 |
extends I<baseName> with a number to produce a unique name like |
| 135 |
``mx foo.c #2'' or ``xclock #12''. This name is used both as the name |
| 136 |
of the window (returned by B<Tk_Name>) and as the registered name |
| 137 |
of the interpreter. |
| 138 |
Fourth, B<Tk_CreateMainWindow> sets I<className> as the class of |
| 139 |
the application (among other things, this is used for lookups in |
| 140 |
the option database), and also as the class of the main widget. |
| 141 |
|
| 142 |
Either internal or top-level windows may be created by calling |
| 143 |
B<Tk_CreateWindow>. If the I<topLevScreen> argument is |
| 144 |
NULL, then the new window will be an internal window. If |
| 145 |
I<topLevScreen> is non-NULL, then the new window will be a |
| 146 |
top-level window: I<topLevScreen> indicates the name of |
| 147 |
a screen and the new window will be created as a child of the |
| 148 |
root window of I<topLevScreen>. In either case Tk will |
| 149 |
consider the new window to be the logical child of I<parent>: |
| 150 |
the new window's path name will reflect this fact, options may |
| 151 |
be specified for the new window under this assumption, and so on. |
| 152 |
The only difference is that new X window for a top-level window |
| 153 |
will not be a child of I<parent>'s X window. For example, a pull-down |
| 154 |
menu's I<parent> would be the button-like window used to invoke it, |
| 155 |
which would in turn be a child of the menu bar window. A dialog box might |
| 156 |
have the application's main window as its parent. This approach |
| 157 |
means that all the windows of an application fall into a hierarchical |
| 158 |
arrangement with a single logical root: the application's main window. |
| 159 |
|
| 160 |
B<Tk_CreateWindowFromPath> offers an alternate way of specifying |
| 161 |
new windows. In B<Tk_CreateWindowFromPath> the new |
| 162 |
window is specified with a token for any window in the target |
| 163 |
application (I<tkwin>), plus a path name for the new window. |
| 164 |
It produces the same effect as B<Tk_CreateWindow> and allows |
| 165 |
both top-level and internal windows to be created, depending on |
| 166 |
the value of I<topLevScreen>. In calls to B<Tk_CreateWindowFromPath>, |
| 167 |
as in calls to B<Tk_CreateWindow>, the parent of the new window |
| 168 |
must exist at the time of the call, but the new window must not |
| 169 |
already exist. |
| 170 |
|
| 171 |
In truth, the window-creation procedures don't |
| 172 |
actually issue the command to X to create a window. |
| 173 |
Instead, they create a local data structure associated with |
| 174 |
the window and defer the creation of the X window. |
| 175 |
The window will actually be created by the first call to |
| 176 |
B<Tk_MapWindow>. Deferred window creation allows various |
| 177 |
aspects of the window (such as its size, background color, |
| 178 |
etc.) to be modified after its creation without incurring |
| 179 |
any overhead in the X server. When the window is finally |
| 180 |
mapped all of the window attributes can be set while creating |
| 181 |
the window. |
| 182 |
|
| 183 |
The value returned by a window-creation procedure is not the |
| 184 |
X token for the window (it can't be, since X hasn't been |
| 185 |
asked to create the window yet). Instead, it is a token |
| 186 |
for Tk's local data structure for the window. Most |
| 187 |
of the Tk library procedures take Tk_Window tokens, rather |
| 188 |
than X identifiers. The actual |
| 189 |
X window identifier can be retrieved from the local |
| 190 |
data structure using the B<Tk_WindowId> macro; |
| 191 |
see the L<Tk::WindowId> documentation for details. |
| 192 |
|
| 193 |
B<Tk_DestroyWindow> deletes a window and all the data |
| 194 |
structures associated with it, including any event handlers |
| 195 |
created with B<Tk_CreateEventHandler>. In addition, |
| 196 |
B<Tk_DestroyWindow> will delete any children of I<tkwin> |
| 197 |
recursively (where children are defined in the Tk sense, consisting |
| 198 |
of all windows that were created with the given window as I<parent>). |
| 199 |
If I<tkwin> was created by B<Tk_CreateInternalWindow> then event |
| 200 |
handlers interested in destroy events |
| 201 |
are invoked immediately. If I<tkwin> is a top-level or main window, |
| 202 |
then the event handlers will be invoked later, after X has seen |
| 203 |
the request and returned an event for it. |
| 204 |
|
| 205 |
If a window has been created |
| 206 |
but hasn't been mapped, so no X window exists, it is |
| 207 |
possible to force the creation of the X window by |
| 208 |
calling B<Tk_MakeWindowExist>. This procedure issues |
| 209 |
the X commands to instantiate the window given by I<tkwin>. |
| 210 |
|
| 211 |
=head1 KEYWORDS |
| 212 |
|
| 213 |
create, deferred creation, destroy, display, internal window, main window, |
| 214 |
register, screen, top-level window, window |