Debian Codegraph @

pTk/mTk/win/tkWinInit.c

raw
1 /*
2 * tkWinInit.c --
3 *
4 * This file contains Windows-specific interpreter initialization
5 * functions.
6 *
7 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
8 *
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 *
12 * RCS: @(#) $Id: tkWinInit.c,v 1.11 2003/02/18 19:18:33 hobbs Exp $
13 */
14
15 #include "tkWinInt.h"
16
17 /*
18 * The Init script (common to Windows and Unix platforms) is
19 * defined in tkInitScript.h
20 */
21 #include "tkInitScript.h"
22
23
24 /*
25 *----------------------------------------------------------------------
26 *
27 * TkpInit --
28 *
29 * Performs Windows-specific interpreter initialization related to the
30 * tk_library variable.
31 *
32 * Results:
33 * A standard Tcl completion code (TCL_OK or TCL_ERROR). Also
34 * leaves information in the interp's result.
35 *
36 * Side effects:
37 * Sets "tk_library" Tcl variable, runs "tk.tcl" script.
38 *
39 *----------------------------------------------------------------------
40 */
41
42 int
43 TkpInit(interp)
44 Tcl_Interp *interp;
45 {
46 /*
47 * This is necessary for static initialization, and is ok otherwise
48 * because TkWinXInit flips a static bit to do its work just once.
49 */
50 TkWinXInit(Tk_GetHINSTANCE());
51 #ifndef _LANG
52 return Tcl_Eval(interp, initScript);
53 #else
54 return TCL_OK;
55 #endif
56 }
57
58 /*
59 *----------------------------------------------------------------------
60 *
61 * TkpGetAppName --
62 *
63 * Retrieves the name of the current application from a platform
64 * specific location. For Windows, the application name is the
65 * root of the tail of the path contained in the tcl variable argv0.
66 *
67 * Results:
68 * Returns the application name in the given Tcl_DString.
69 *
70 * Side effects:
71 * None.
72 *
73 *----------------------------------------------------------------------
74 */
75
76 void
77 TkpGetAppName(interp, namePtr)
78 Tcl_Interp *interp;
79 Tcl_DString *namePtr; /* A previously initialized Tcl_DString. */
80 {
81 int argc, namelength;
82 CONST char *name = NULL;
83
84 #ifndef _LANG
85 CONST char **argv = NULL, *p;
86
87 name = Tcl_GetVar(interp, "argv0", TCL_GLOBAL_ONLY);
88 namelength = -1;
89 if (name != NULL) {
90 Tcl_SplitPath(name, &argc, &argv);
91 if (argc > 0) {
92 name = argv[argc-1];
93 p = strrchr(name, '.');
94 if (p != NULL) {
95 namelength = p - name;
96 }
97 } else {
98 name = NULL;
99 }
100 }
101 #endif
102
103 if ((name == NULL) || (*name == 0)) {
104 name = "tk";
105 namelength = -1;
106 }
107 Tcl_DStringAppend(namePtr, name, namelength);
108 #ifndef _LANG
109 if (argv != NULL) {
110 ckfree((char *)argv);
111 }
112 #endif
113 }
114
115 /*
116 *----------------------------------------------------------------------
117 *
118 * TkpDisplayWarning --
119 *
120 * This routines is called from Tk_Main to display warning
121 * messages that occur during startup.
122 *
123 * Results:
124 * None.
125 *
126 * Side effects:
127 * Displays a message box.
128 *
129 *----------------------------------------------------------------------
130 */
131
132 void
133 TkpDisplayWarning(msg, title)
134 CONST char *msg; /* Message to be displayed. */
135 CONST char *title; /* Title of warning. */
136 {
137 Tcl_DString msgString, titleString;
138 Tcl_Encoding unicodeEncoding = TkWinGetUnicodeEncoding();
139
140 /*
141 * Truncate MessageBox string if it is too long to not overflow
142 * the screen and cause possible oversized window error.
143 */
144 #define TK_MAX_WARN_LEN (1024 * sizeof(WCHAR))
145 Tcl_UtfToExternalDString(unicodeEncoding, msg, -1, &msgString);
146 Tcl_UtfToExternalDString(unicodeEncoding, title, -1, &titleString);
147 if (Tcl_DStringLength(&msgString) > TK_MAX_WARN_LEN) {
148 Tcl_DStringSetLength(&msgString, TK_MAX_WARN_LEN);
149 Tcl_DStringAppend(&msgString, (char *) L" ...", 4 * sizeof(WCHAR));
150 }
151 MessageBoxW(NULL, (WCHAR *) Tcl_DStringValue(&msgString),
152 (WCHAR *) Tcl_DStringValue(&titleString),
153 MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL
154 | MB_SETFOREGROUND | MB_TOPMOST);
155 Tcl_DStringFree(&msgString);
156 Tcl_DStringFree(&titleString);
157 }