Tk Source Code

Check-in [3db2e9c6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Implement TkCygwinMainEx for loading Cygwin's Tk_MainEx from the Tk dll
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core-8-5-branch
Files: files | file ages | folders
SHA1: 3db2e9c69fd675120892ac0b0ff204ec1eaf64e7
User & Date: jan.nijtmans 2012-06-08 21:22:17
Context
2012-06-08
22:47
Change XChangeWindowAttributes signature and many others to match Xorg, needed for Cygwin check-in: 5ed597c5 user: jan.nijtmans tags: trunk
22:19
eliminate some ANSI_ARGS check-in: 81bffa40 user: jan.nijtmans tags: core-8-5-branch
21:22
Implement TkCygwinMainEx for loading Cygwin's Tk_MainEx from the Tk dll check-in: 3db2e9c6 user: jan.nijtmans tags: core-8-5-branch
20:53
Implement TkCygwinMainEx for loading Cygwin's Tk_MainEx from the Tk dll check-in: 1a49039b user: jan.nijtmans tags: core-8-4-branch
2012-06-07
09:32
some quoting issues, eliminate TCL_VARARGS_DEFINE check-in: 7b5b2dd5 user: jan.nijtmans tags: core-8-5-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.






1
2
3
4
5
6
7





2012-06-07  Jan Nijtmans  <[email protected]>

	* generic/tkInt.decls:   Change XChangeWindowAttributes signature and
	* generic/tkIntXlibDeclsDecls.h: many others to match Xorg, needed for Cygwin.

2012-06-06  Jan Nijtmans  <[email protected]>

>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
2012-06-08  Jan Nijtmans  <[email protected]>

	* generic/tkMain.c:   Implement TkCygwinMainEx for loading
	* generic/tkWindow.c: Cygwin's Tk_MainEx from the Tk dll.

2012-06-07  Jan Nijtmans  <[email protected]>

	* generic/tkInt.decls:   Change XChangeWindowAttributes signature and
	* generic/tkIntXlibDeclsDecls.h: many others to match Xorg, needed for Cygwin.

2012-06-06  Jan Nijtmans  <[email protected]>

Changes to generic/tkInt.decls.

1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
	    XTextProperty *text_prop_return)
}
declare 80 aqua {
    void XDrawSegments(Display *display, Drawable d, GC gc,
	    XSegment *segments, int nsegments)
}
declare 81 aqua {
    int XForceScreenSaver(Display *display, int mode)
}
declare 82 aqua {
    int XDrawLine(Display *d, Drawable dr, GC g, int x1, int y1,
	    int x2, int y2)
}
declare 83 aqua {
    int XFillRectangle(Display *display, Drawable d, GC gc,







|







1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
	    XTextProperty *text_prop_return)
}
declare 80 aqua {
    void XDrawSegments(Display *display, Drawable d, GC gc,
	    XSegment *segments, int nsegments)
}
declare 81 aqua {
    void XForceScreenSaver(Display *display, int mode)
}
declare 82 aqua {
    int XDrawLine(Display *d, Drawable dr, GC g, int x1, int y1,
	    int x2, int y2)
}
declare 83 aqua {
    int XFillRectangle(Display *display, Drawable d, GC gc,

Changes to generic/tkIntXlibDecls.h.

1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
/* 80 */
EXTERN void		XDrawSegments(Display *display, Drawable d, GC gc,
				XSegment *segments, int nsegments);
#endif
#ifndef XForceScreenSaver_TCL_DECLARED
#define XForceScreenSaver_TCL_DECLARED
/* 81 */
EXTERN int		XForceScreenSaver(Display *display, int mode);
#endif
#ifndef XDrawLine_TCL_DECLARED
#define XDrawLine_TCL_DECLARED
/* 82 */
EXTERN int		XDrawLine(Display *d, Drawable dr, GC g, int x1,
				int y1, int x2, int y2);
#endif







|







1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
/* 80 */
EXTERN void		XDrawSegments(Display *display, Drawable d, GC gc,
				XSegment *segments, int nsegments);
#endif
#ifndef XForceScreenSaver_TCL_DECLARED
#define XForceScreenSaver_TCL_DECLARED
/* 81 */
EXTERN void		XForceScreenSaver(Display *display, int mode);
#endif
#ifndef XDrawLine_TCL_DECLARED
#define XDrawLine_TCL_DECLARED
/* 82 */
EXTERN int		XDrawLine(Display *d, Drawable dr, GC g, int x1,
				int y1, int x2, int y2);
#endif
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
    int (*xSetLineAttributes) (Display *display, GC gc, unsigned int line_width, int line_style, int cap_style, int join_style); /* 74 */
    int (*_XInitImageFuncPtrs) (XImage *image); /* 75 */
    XIC (*xCreateIC) (void); /* 76 */
    XVisualInfo * (*xGetVisualInfo) (Display *display, long vinfo_mask, XVisualInfo *vinfo_template, int *nitems_return); /* 77 */
    void (*xSetWMClientMachine) (Display *display, Window w, XTextProperty *text_prop); /* 78 */
    Status (*xStringListToTextProperty) (char **list, int count, XTextProperty *text_prop_return); /* 79 */
    void (*xDrawSegments) (Display *display, Drawable d, GC gc, XSegment *segments, int nsegments); /* 80 */
    int (*xForceScreenSaver) (Display *display, int mode); /* 81 */
    int (*xDrawLine) (Display *d, Drawable dr, GC g, int x1, int y1, int x2, int y2); /* 82 */
    int (*xFillRectangle) (Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height); /* 83 */
    void (*xClearWindow) (Display *d, Window w); /* 84 */
    void (*xDrawPoint) (Display *display, Drawable d, GC gc, int x, int y); /* 85 */
    void (*xDrawPoints) (Display *display, Drawable d, GC gc, XPoint *points, int npoints, int mode); /* 86 */
    int (*xWarpPointer) (Display *display, Window src_w, Window dest_w, int src_x, int src_y, unsigned int src_width, unsigned int src_height, int dest_x, int dest_y); /* 87 */
    void (*xQueryColor) (Display *display, Colormap colormap, XColor *def_in_out); /* 88 */







|







1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
    int (*xSetLineAttributes) (Display *display, GC gc, unsigned int line_width, int line_style, int cap_style, int join_style); /* 74 */
    int (*_XInitImageFuncPtrs) (XImage *image); /* 75 */
    XIC (*xCreateIC) (void); /* 76 */
    XVisualInfo * (*xGetVisualInfo) (Display *display, long vinfo_mask, XVisualInfo *vinfo_template, int *nitems_return); /* 77 */
    void (*xSetWMClientMachine) (Display *display, Window w, XTextProperty *text_prop); /* 78 */
    Status (*xStringListToTextProperty) (char **list, int count, XTextProperty *text_prop_return); /* 79 */
    void (*xDrawSegments) (Display *display, Drawable d, GC gc, XSegment *segments, int nsegments); /* 80 */
    void (*xForceScreenSaver) (Display *display, int mode); /* 81 */
    int (*xDrawLine) (Display *d, Drawable dr, GC g, int x1, int y1, int x2, int y2); /* 82 */
    int (*xFillRectangle) (Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height); /* 83 */
    void (*xClearWindow) (Display *d, Window w); /* 84 */
    void (*xDrawPoint) (Display *display, Drawable d, GC gc, int x, int y); /* 85 */
    void (*xDrawPoints) (Display *display, Drawable d, GC gc, XPoint *points, int npoints, int mode); /* 86 */
    int (*xWarpPointer) (Display *display, Window src_w, Window dest_w, int src_x, int src_y, unsigned int src_width, unsigned int src_height, int dest_x, int dest_y); /* 87 */
    void (*xQueryColor) (Display *display, Colormap colormap, XColor *def_in_out); /* 88 */

Changes to generic/tkMain.c.

135
136
137
138
139
140
141
142


143
144
145
146
147
148
149

150


151
152
153
154
155
156
157
     * only an issue when Tk is loaded dynamically.
     */

    if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
	abort();
    }

#if defined(__WIN32__) && !defined(STATIC_BUILD)


    if (tclStubsPtr->reserved9) {
	/* We are running win32 Tk under Cygwin, so let's check
	 * whether the env("DISPLAY") variable or the -display
	 * argument is set. If so, we really want to run the
	 * Tk_MainEx function of libtk.dll, not this one. */
 	if (Tcl_GetVar2(interp, "env", "DISPLAY", TCL_GLOBAL_ONLY)) {
	loadCygwinTk:

	    Tcl_Panic("Should load libtk.dll now, not yet implemented");


	} else {
	    int i;

	    for (i = 1; i < argc; ++i) {
		if (!strcmp(argv[i], "-display")) {
		    goto loadCygwinTk;
		}







|
>
>




|
|

>
|
>
>







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
     * only an issue when Tk is loaded dynamically.
     */

    if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
	abort();
    }

#if defined(__WIN32__) && !defined(__WIN64__) && !defined(STATIC_BUILD)
    extern int TkCygwinMainEx(int, char **, Tcl_AppInitProc *, Tcl_Interp *);

    if (tclStubsPtr->reserved9) {
	/* We are running win32 Tk under Cygwin, so let's check
	 * whether the env("DISPLAY") variable or the -display
	 * argument is set. If so, we really want to run the
	 * Tk_MainEx function of libtk8.?.dll, not this one. */
	if (Tcl_GetVar2(interp, "env", "DISPLAY", TCL_GLOBAL_ONLY)) {
	loadCygwinTk:
	    if (TkCygwinMainEx(argc, argv, appInitProc, interp)) {
		/* Should never reach here. */
		return;
	    }
	} else {
	    int i;

	    for (i = 1; i < argc; ++i) {
		if (!strcmp(argv[i], "-display")) {
		    goto loadCygwinTk;
		}

Changes to generic/tkWindow.c.

2827
2828
2829
2830
2831
2832
2833













































2834
2835
2836
2837
2838
2839
2840
    }

    tsdPtr->numMainWindows = 0;
    tsdPtr->mainWindowList = NULL;
    tsdPtr->initialized = 0;
}














































/*
 *----------------------------------------------------------------------
 *
 * Tk_Init --
 *
 *	This function is invoked to add Tk to an interpreter. It incorporates
 *	all of Tk's commands into the interpreter and creates the main window







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
    }

    tsdPtr->numMainWindows = 0;
    tsdPtr->mainWindowList = NULL;
    tsdPtr->initialized = 0;
}

#if defined(__WIN32__) && !defined(__WIN64__)

static HMODULE tkcygwindll = NULL;

/*
 * Run Tk_MainEx from libtk8.?.dll
 *
 * This function is only ever called from wish8.4.exe, the cygwin
 * port of Tcl. This means that the system encoding is utf-8,
 * so we don't have to do any encoding conversions.
 */
int
TkCygwinMainEx(argc, argv, appInitProc, interp)
    int argc;				/* Number of arguments. */
    char **argv;			/* Array of argument strings. */
    Tcl_AppInitProc *appInitProc;	/* Application-specific initialization
					 * procedure to call after most
					 * initialization but before starting
					 * to execute commands. */
    Tcl_Interp *interp;
{
    char name[MAX_PATH];
    int len;
    void (*sym)(int, char **, Tcl_AppInitProc *, Tcl_Interp *);

    /* construct "<path>/libtk8.?.dll", from "<path>/tk8?.dll" */
	len = GetModuleFileName(Tk_GetHINSTANCE(), name, MAX_PATH);
	name[len-2] = '.';
	name[len-1] = name[len-5];
	strcpy(name+len, ".dll");
	memcpy(name+len-8, "libtk8", 6);

	tkcygwindll = LoadLibrary(name);
	if (!tkcygwindll) {
	    /* dll is not present */
	    return 0;
	}
	sym = (void (*)(int, char **, Tcl_AppInitProc *, Tcl_Interp *)) GetProcAddress(tkcygwindll, "Tk_MainEx");
	if (!sym) {
		return 0;
	}
	sym(argc, argv, appInitProc, interp);
    return 1;
}
#endif
/*
 *----------------------------------------------------------------------
 *
 * Tk_Init --
 *
 *	This function is invoked to add Tk to an interpreter. It incorporates
 *	all of Tk's commands into the interpreter and creates the main window
2854
2855
2856
2857
2858
2859
2860










2861
2862
2863
2864
2865
2866
2867
 *----------------------------------------------------------------------
 */

int
Tk_Init(
    Tcl_Interp *interp)		/* Interpreter to initialize. */
{










    return Initialize(interp);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SafeInit --







>
>
>
>
>
>
>
>
>
>







2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
 *----------------------------------------------------------------------
 */

int
Tk_Init(
    Tcl_Interp *interp)		/* Interpreter to initialize. */
{
#if defined(__WIN32__) && !defined(__WIN64__)
    if (tkcygwindll) {
	int (*sym)(Tcl_Interp *);

	sym = (int (*)(Tcl_Interp *)) GetProcAddress(tkcygwindll, "Tk_Init");
	if (sym) {
	    return sym(interp);
	}
    }
#endif
    return Initialize(interp);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SafeInit --
2917
2918
2919
2920
2921
2922
2923










2924
2925
2926
2927
2928
2929
2930
     * - No CPU time limit, no memory allocation limits, no color limits.
     *   CPU time limits can be imposed by an unsafe master interpreter.
     *
     * The actual code called is the same as Tk_Init but Tcl_IsSafe() is
     * checked at several places to differentiate the two initialisations.
     */











    return Initialize(interp);
}

extern TkStubs tkStubs;

/*
 *----------------------------------------------------------------------







>
>
>
>
>
>
>
>
>
>







2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
     * - No CPU time limit, no memory allocation limits, no color limits.
     *   CPU time limits can be imposed by an unsafe master interpreter.
     *
     * The actual code called is the same as Tk_Init but Tcl_IsSafe() is
     * checked at several places to differentiate the two initialisations.
     */

#if defined(__WIN32__) && !defined(__WIN64__)
    if (tkcygwindll) {
	int (*sym)(Tcl_Interp *);

	sym = (int (*)(Tcl_Interp *)) GetProcAddress(tkcygwindll, "Tk_SafeInit");
	if (sym) {
	    return sym(interp);
	}
    }
#endif
    return Initialize(interp);
}

extern TkStubs tkStubs;

/*
 *----------------------------------------------------------------------