66 *
77 */
88
9- /* This is needed for (at least) Tk 8.4.1, otherwise the signature of
10- ** Tk_PhotoPutBlock changes.
11- */
12- #define USE_COMPOSITELESS_PHOTO_PUT_BLOCK
13-
149#include < Python.h>
1510#include < cstdlib>
1611#include < cstdio>
1712#include < sstream>
1813
1914#include " py_converters.h"
2015
21- extern " C"
22- {
16+ // Include our own excerpts from the Tcl / Tk headers
2317#include " _tkmini.h"
24- }
2518
2619#if defined(_MSC_VER)
2720# define SIZE_T_FORMAT " %Iu"
@@ -35,27 +28,17 @@ typedef struct
3528 Tcl_Interp *interp;
3629} TkappObject;
3730
38- // Load TCL / Tk symbols from tkinter extension module at run-time.
39- // Typedefs, global vars for TCL / Tk library functions.
40- typedef Tcl_Command (*tcl_cc)(Tcl_Interp *interp,
41- const char *cmdName, Tcl_CmdProc *proc,
42- ClientData clientData,
43- Tcl_CmdDeleteProc *deleteProc);
44- static tcl_cc TCL_CREATE_COMMAND;
45- typedef void (*tcl_app_res) (Tcl_Interp *interp, ...);
46- static tcl_app_res TCL_APPEND_RESULT;
47- typedef Tk_Window (*tk_mw) (Tcl_Interp *interp);
48- static tk_mw TK_MAIN_WINDOW;
49- typedef Tk_PhotoHandle (*tk_fp) (Tcl_Interp *interp, const char *imageName);
50- static tk_fp TK_FIND_PHOTO;
51- typedef void (*tk_ppb_nc) (Tk_PhotoHandle handle,
52- Tk_PhotoImageBlock *blockPtr, int x, int y,
53- int width, int height);
54- static tk_ppb_nc TK_PHOTO_PUTBLOCK;
55- typedef void (*tk_pb) (Tk_PhotoHandle handle);
56- static tk_pb TK_PHOTO_BLANK;
57-
58- static int PyAggImagePhoto (ClientData clientdata, Tcl_Interp *interp, int argc, char **argv)
31+ // Global vars for Tcl / Tk functions. We load these symbols from the tkinter
32+ // extension module or loaded Tcl / Tk libraries at run-time.
33+ static Tcl_CreateCommand_t TCL_CREATE_COMMAND;
34+ static Tcl_AppendResult_t TCL_APPEND_RESULT;
35+ static Tk_MainWindow_t TK_MAIN_WINDOW;
36+ static Tk_FindPhoto_t TK_FIND_PHOTO;
37+ static Tk_PhotoPutBlock_NoComposite_t TK_PHOTO_PUT_BLOCK_NO_COMPOSITE;
38+ static Tk_PhotoBlank_t TK_PHOTO_BLANK;
39+
40+ static int PyAggImagePhoto (ClientData clientdata, Tcl_Interp *interp, int
41+ argc, char **argv)
5942{
6043 Tk_PhotoHandle photo;
6144 Tk_PhotoImageBlock block;
@@ -178,7 +161,8 @@ static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int argc,
178161 block.pitch = deststride;
179162 block.pixelPtr = destbuffer;
180163
181- TK_PHOTO_PUTBLOCK (photo, &block, destx, desty, destwidth, destheight);
164+ TK_PHOTO_PUT_BLOCK_NO_COMPOSITE (photo, &block, destx, desty,
165+ destwidth, destheight);
182166 delete[] destbuffer;
183167
184168 } else {
@@ -190,7 +174,8 @@ static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int argc,
190174 /* Clear current contents */
191175 TK_PHOTO_BLANK (photo);
192176 /* Copy opaque block to photo image, and leave the rest to TK */
193- TK_PHOTO_PUTBLOCK (photo, &block, 0 , 0 , block.width , block.height );
177+ TK_PHOTO_PUT_BLOCK_NO_COMPOSITE (photo, &block, 0 , 0 , block.width ,
178+ block.height );
194179 }
195180
196181 return TCL_OK;
@@ -279,11 +264,13 @@ int get_tcl(HMODULE hMod)
279264 // Try to fill TCL global vars with function pointers. Return 0 for no
280265 // functions found, 1 for all functions found, -1 for some but not all
281266 // functions found.
282- TCL_CREATE_COMMAND = (tcl_cc) GetProcAddress (hMod, " Tcl_CreateCommand" );
267+ TCL_CREATE_COMMAND = (Tcl_CreateCommand_t)
268+ GetProcAddress (hMod, " Tcl_CreateCommand" );
283269 if (TCL_CREATE_COMMAND == NULL ) { // Maybe not TCL module
284270 return 0 ;
285271 }
286- TCL_APPEND_RESULT = (tcl_app_res) _dfunc (hMod, " Tcl_AppendResult" );
272+ TCL_APPEND_RESULT = (Tcl_AppendResult_t) _dfunc (hMod,
273+ " Tcl_AppendResult" );
287274 return (TCL_APPEND_RESULT == NULL ) ? -1 : 1 ;
288275}
289276
@@ -292,15 +279,18 @@ int get_tk(HMODULE hMod)
292279 // Try to fill Tk global vars with function pointers. Return 0 for no
293280 // functions found, 1 for all functions found, -1 for some but not all
294281 // functions found.
295- TK_MAIN_WINDOW = (tk_mw) GetProcAddress (hMod, " Tk_MainWindow" );
282+ TK_MAIN_WINDOW = (Tk_MainWindow_t)
283+ GetProcAddress (hMod, " Tk_MainWindow" );
296284 if (TK_MAIN_WINDOW == NULL ) { // Maybe not Tk module
297285 return 0 ;
298286 }
299- return ( // -1 if any are NULL
300- ((TK_FIND_PHOTO = (tk_fp) _dfunc (hMod, " Tk_FindPhoto" )) == NULL ) ||
301- ((TK_PHOTO_PUTBLOCK = (tk_ppb_nc)
287+ return ( // -1 if any remaining symbols are NULL
288+ ((TK_FIND_PHOTO = (Tk_FindPhoto_t)
289+ _dfunc (hMod, " Tk_FindPhoto" )) == NULL ) ||
290+ ((TK_PHOTO_PUT_BLOCK_NO_COMPOSITE = (Tk_PhotoPutBlock_NoComposite_t)
302291 _dfunc (hMod, " Tk_PhotoPutBlock_NoComposite" )) == NULL ) ||
303- ((TK_PHOTO_BLANK = (tk_pb) _dfunc (hMod, " Tk_PhotoBlank" )) == NULL ))
292+ ((TK_PHOTO_BLANK = (Tk_PhotoBlank_t)
293+ _dfunc (hMod, " Tk_PhotoBlank" )) == NULL ))
304294 ? -1 : 1 ;
305295}
306296
@@ -397,17 +387,17 @@ int _func_loader(void *lib)
397387 // Fill global function pointers from dynamic lib.
398388 // Return 1 if any pointer is NULL, 0 otherwise.
399389 return (
400- ((TCL_CREATE_COMMAND = (tcl_cc )
390+ ((TCL_CREATE_COMMAND = (Tcl_CreateCommand_t )
401391 _dfunc (lib, " Tcl_CreateCommand" )) == NULL ) ||
402- ((TCL_APPEND_RESULT = (tcl_app_res )
392+ ((TCL_APPEND_RESULT = (Tcl_AppendResult_t )
403393 _dfunc (lib, " Tcl_AppendResult" )) == NULL ) ||
404- ((TK_MAIN_WINDOW = (tk_mw )
394+ ((TK_MAIN_WINDOW = (Tk_MainWindow_t )
405395 _dfunc (lib, " Tk_MainWindow" )) == NULL ) ||
406- ((TK_FIND_PHOTO = (tk_fp )
396+ ((TK_FIND_PHOTO = (Tk_FindPhoto_t )
407397 _dfunc (lib, " Tk_FindPhoto" )) == NULL ) ||
408- ((TK_PHOTO_PUTBLOCK = (tk_ppb_nc )
398+ ((TK_PHOTO_PUT_BLOCK_NO_COMPOSITE = (Tk_PhotoPutBlock_NoComposite_t )
409399 _dfunc (lib, " Tk_PhotoPutBlock_NoComposite" )) == NULL ) ||
410- ((TK_PHOTO_BLANK = (tk_pb )
400+ ((TK_PHOTO_BLANK = (Tk_PhotoBlank_t )
411401 _dfunc (lib, " Tk_PhotoBlank" )) == NULL ));
412402}
413403
0 commit comments