6
6
*
7
7
*/
8
8
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
-
14
9
#include < Python.h>
15
10
#include < cstdlib>
16
11
#include < cstdio>
17
12
#include < sstream>
18
13
19
14
#include " py_converters.h"
20
15
21
- extern " C"
22
- {
16
+ // Include our own excerpts from the Tcl / Tk headers
23
17
#include " _tkmini.h"
24
- }
25
18
26
19
#if defined(_MSC_VER)
27
20
# define SIZE_T_FORMAT " %Iu"
@@ -35,27 +28,17 @@ typedef struct
35
28
Tcl_Interp *interp;
36
29
} TkappObject;
37
30
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)
59
42
{
60
43
Tk_PhotoHandle photo;
61
44
Tk_PhotoImageBlock block;
@@ -178,7 +161,8 @@ static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int argc,
178
161
block.pitch = deststride;
179
162
block.pixelPtr = destbuffer;
180
163
181
- TK_PHOTO_PUTBLOCK (photo, &block, destx, desty, destwidth, destheight);
164
+ TK_PHOTO_PUT_BLOCK_NO_COMPOSITE (photo, &block, destx, desty,
165
+ destwidth, destheight);
182
166
delete[] destbuffer;
183
167
184
168
} else {
@@ -190,7 +174,8 @@ static int PyAggImagePhoto(ClientData clientdata, Tcl_Interp *interp, int argc,
190
174
/* Clear current contents */
191
175
TK_PHOTO_BLANK (photo);
192
176
/* 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 );
194
179
}
195
180
196
181
return TCL_OK;
@@ -279,11 +264,13 @@ int get_tcl(HMODULE hMod)
279
264
// Try to fill TCL global vars with function pointers. Return 0 for no
280
265
// functions found, 1 for all functions found, -1 for some but not all
281
266
// functions found.
282
- TCL_CREATE_COMMAND = (tcl_cc) GetProcAddress (hMod, " Tcl_CreateCommand" );
267
+ TCL_CREATE_COMMAND = (Tcl_CreateCommand_t)
268
+ GetProcAddress (hMod, " Tcl_CreateCommand" );
283
269
if (TCL_CREATE_COMMAND == NULL ) { // Maybe not TCL module
284
270
return 0 ;
285
271
}
286
- TCL_APPEND_RESULT = (tcl_app_res) _dfunc (hMod, " Tcl_AppendResult" );
272
+ TCL_APPEND_RESULT = (Tcl_AppendResult_t) _dfunc (hMod,
273
+ " Tcl_AppendResult" );
287
274
return (TCL_APPEND_RESULT == NULL ) ? -1 : 1 ;
288
275
}
289
276
@@ -292,15 +279,18 @@ int get_tk(HMODULE hMod)
292
279
// Try to fill Tk global vars with function pointers. Return 0 for no
293
280
// functions found, 1 for all functions found, -1 for some but not all
294
281
// functions found.
295
- TK_MAIN_WINDOW = (tk_mw) GetProcAddress (hMod, " Tk_MainWindow" );
282
+ TK_MAIN_WINDOW = (Tk_MainWindow_t)
283
+ GetProcAddress (hMod, " Tk_MainWindow" );
296
284
if (TK_MAIN_WINDOW == NULL ) { // Maybe not Tk module
297
285
return 0 ;
298
286
}
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)
302
291
_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 ))
304
294
? -1 : 1 ;
305
295
}
306
296
@@ -397,17 +387,17 @@ int _func_loader(void *lib)
397
387
// Fill global function pointers from dynamic lib.
398
388
// Return 1 if any pointer is NULL, 0 otherwise.
399
389
return (
400
- ((TCL_CREATE_COMMAND = (tcl_cc )
390
+ ((TCL_CREATE_COMMAND = (Tcl_CreateCommand_t )
401
391
_dfunc (lib, " Tcl_CreateCommand" )) == NULL ) ||
402
- ((TCL_APPEND_RESULT = (tcl_app_res )
392
+ ((TCL_APPEND_RESULT = (Tcl_AppendResult_t )
403
393
_dfunc (lib, " Tcl_AppendResult" )) == NULL ) ||
404
- ((TK_MAIN_WINDOW = (tk_mw )
394
+ ((TK_MAIN_WINDOW = (Tk_MainWindow_t )
405
395
_dfunc (lib, " Tk_MainWindow" )) == NULL ) ||
406
- ((TK_FIND_PHOTO = (tk_fp )
396
+ ((TK_FIND_PHOTO = (Tk_FindPhoto_t )
407
397
_dfunc (lib, " Tk_FindPhoto" )) == NULL ) ||
408
- ((TK_PHOTO_PUTBLOCK = (tk_ppb_nc )
398
+ ((TK_PHOTO_PUT_BLOCK_NO_COMPOSITE = (Tk_PhotoPutBlock_NoComposite_t )
409
399
_dfunc (lib, " Tk_PhotoPutBlock_NoComposite" )) == NULL ) ||
410
- ((TK_PHOTO_BLANK = (tk_pb )
400
+ ((TK_PHOTO_BLANK = (Tk_PhotoBlank_t )
411
401
_dfunc (lib, " Tk_PhotoBlank" )) == NULL ));
412
402
}
413
403
0 commit comments