summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2021-07-14 07:50:36 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2021-07-14 07:50:36 (GMT)
commit339b9903f1039dc566f9661f8f3ef6597a6ca244 (patch)
tree253ce6f6e43e19afbba12c19f079bcd9894b425a /win
parent53881f906ac49f98ad4dc1061eac424f55fde3af (diff)
downloadtk-339b9903f1039dc566f9661f8f3ef6597a6ca244.zip
tk-339b9903f1039dc566f9661f8f3ef6597a6ca244.tar.gz
tk-339b9903f1039dc566f9661f8f3ef6597a6ca244.tar.bz2
Rewrite to use an actual ensemble instead of a homebrew version.
Diffstat (limited to 'win')
-rw-r--r--win/tkWinGDI.c209
-rw-r--r--win/tkWinInit.c1
-rw-r--r--win/tkWinInt.h7
3 files changed, 85 insertions, 132 deletions
diff --git a/win/tkWinGDI.c b/win/tkWinGDI.c
index 1b95eff..9f04187 100644
--- a/win/tkWinGDI.c
+++ b/win/tkWinGDI.c
@@ -38,10 +38,6 @@ typedef BOOL WINAPI (*DrawFunc) (
HDC, int, int, int, int, int, int, int, int); /* Arc, Chord, Pie. */
#endif
-/* Main dispatcher for commands. */
-static int TkWinGDI(ClientData clientData, Tcl_Interp *interp,
- int argc, const char **argv);
-
/* Real functions. */
static int GdiArc(ClientData clientData, Tcl_Interp *interp,
int argc, const char **argv);
@@ -127,11 +123,6 @@ static int PrintClosePage(ClientData clientData,
Tcl_Interp *interp, int argc,
Tcl_Obj *const objv[]);
-static const char gdi_usage_message[] =
- "::tk::print::_gdi [arc|characters|copybits|line|map|oval|"
- "photo|polygon|rectangle|text|version]\n"
- "\thdc parameters can be generated by the printer extension";
-
/*
* Global state.
*/
@@ -170,45 +161,6 @@ static const struct gdi_command {
/*
*----------------------------------------------------------------------
*
- * TkWinGDI --
- *
- * Top-level routine for the ::tk::print::_gdi command.
- *
- * Results:
- * It strips off the first two words of the command (::tk::print::_gdi
- * subcommand) and dispatches to a subcommand implementation.
- *
- *----------------------------------------------------------------------
- */
-
-static int TkWinGDI(
- ClientData clientData,
- Tcl_Interp *interp,
- int argc,
- const char **argv)
-{
- size_t i;
- static const size_t numCommands =
- sizeof(gdi_commands) / sizeof(struct gdi_command);
-
- /* EXACT command name check? REALLY? */
-
- if (argc > 1 && strcmp(argv[0], "::tk::print::_gdi") == 0) {
- for (i=0; i<numCommands; i++) {
- if (strcmp(argv[1], gdi_commands[i].command_string) == 0) {
- return (*gdi_commands[i].command)(
- clientData, interp, argc - 2, argv + 2);
- }
- }
- }
-
- Tcl_AppendResult(interp, gdi_usage_message, NULL);
- return TCL_ERROR;
-}
-
-/*
- *----------------------------------------------------------------------
- *
* GdiArc --
*
* Map canvas arcs to GDI context.
@@ -249,20 +201,20 @@ static int GdiArc(
drawfunc = Pie;
/* Verrrrrry simple for now.... */
- if (argc < 5) {
+ if (argc < 6) {
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
hDC = printDC;
- x1 = atoi(argv[1]);
- y1 = atoi(argv[2]);
- x2 = atoi(argv[3]);
- y2 = atoi(argv[4]);
+ x1 = atoi(argv[2]);
+ y1 = atoi(argv[3]);
+ x2 = atoi(argv[4]);
+ y2 = atoi(argv[5]);
- argc -= 5;
- argv += 5;
+ argc -= 6;
+ argv += 6;
while (argc >= 2) {
if (strcmp(argv[0], "-extent") == 0) {
extent = atof(argv[1]);
@@ -379,7 +331,8 @@ static int GdiBitmap(
TCL_UNUSED(int),
TCL_UNUSED(const char **))
{
- static const char usage_message[] = "::tk::print::_gdi bitmap hdc x y "
+ static const char usage_message[] =
+ "::tk::print::_gdi bitmap hdc x y "
"-anchor [center|n|e|s|w] -background color "
"-bitmap bitmap -foreground color\n"
"Not implemented yet. Sorry!";
@@ -471,7 +424,7 @@ static int GdiPhoto(
*/
/* HDC is required. */
- if (argc < 1) {
+ if (argc < 2) {
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
@@ -486,12 +439,12 @@ static int GdiPhoto(
if ((GetDeviceCaps(dst, RASTERCAPS) & RC_STRETCHDIB) == 0) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"::tk::print::_gdi photo not supported on device context (0x%s)",
- argv[0]));
+ argv[1]));
return TCL_ERROR;
}
/* Parse the command line arguments. */
- for (j = 1; j < argc; j++) {
+ for (j = 2; j < argc; j++) {
if (strcmp(argv[j], "-destination") == 0) {
double x, y, w, h;
int count = 0;
@@ -742,23 +695,24 @@ static int GdiLine(
arrowshape[2] = 3;
/* Verrrrrry simple for now.... */
- if (argc < 5) {
+ if (argc < 6) {
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
hDC = printDC;
- if ((polypoints = (POINT *) Tcl_AttemptAlloc(argc * sizeof(POINT))) == 0) {
+ polypoints = (POINT *) Tcl_AttemptAlloc((argc - 1) * sizeof(POINT));
+ if (polypoints == 0) {
Tcl_AppendResult(interp, "Out of memory in GdiLine", NULL);
return TCL_ERROR;
}
- polypoints[0].x = atol(argv[1]);
- polypoints[0].y = atol(argv[2]);
- polypoints[1].x = atol(argv[3]);
- polypoints[1].y = atol(argv[4]);
- argc -= 5;
- argv += 5;
+ polypoints[0].x = atol(argv[2]);
+ polypoints[0].y = atol(argv[3]);
+ polypoints[1].x = atol(argv[4]);
+ polypoints[1].y = atol(argv[5]);
+ argc -= 6;
+ argv += 6;
npoly = 2;
while (argc >= 2) {
@@ -1018,17 +972,17 @@ static int GdiOval(
const char *dashdata = 0;
/* Verrrrrry simple for now.... */
- if (argc < 5) {
+ if (argc < 6) {
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
hDC = printDC;
- x1 = atol(argv[1]);
- y1 = atol(argv[2]);
- x2 = atol(argv[3]);
- y2 = atol(argv[4]);
+ x1 = atol(argv[2]);
+ y1 = atol(argv[3]);
+ x2 = atol(argv[4]);
+ y2 = atol(argv[5]);
if (x1 > x2) {
int x3 = x1;
x1 = x2;
@@ -1039,8 +993,8 @@ static int GdiOval(
y1 = y2;
y2 = y3;
}
- argc -= 5;
- argv += 5;
+ argc -= 6;
+ argv += 6;
while (argc > 0) {
/* Now handle any other arguments that occur. */
@@ -1140,24 +1094,25 @@ static int GdiPolygon(
const char *dashdata = 0;
/* Verrrrrry simple for now.... */
- if (argc < 5) {
+ if (argc < 6) {
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
hDC = printDC;
- if ((polypoints = (POINT *) Tcl_AttemptAlloc(argc * sizeof(POINT))) == 0) {
+ polypoints = (POINT *) Tcl_AttemptAlloc((argc - 1) * sizeof(POINT));
+ if (polypoints == 0) {
/* TODO: unreachable */
Tcl_AppendResult(interp, "Out of memory in GdiLine", NULL);
return TCL_ERROR;
}
- polypoints[0].x = atol(argv[1]);
- polypoints[0].y = atol(argv[2]);
- polypoints[1].x = atol(argv[3]);
- polypoints[1].y = atol(argv[4]);
- argc -= 5;
- argv += 5;
+ polypoints[0].x = atol(argv[2]);
+ polypoints[0].y = atol(argv[3]);
+ polypoints[1].x = atol(argv[4]);
+ polypoints[1].y = atol(argv[5]);
+ argc -= 6;
+ argv += 6;
npoly = 2;
while (argc >= 2) {
@@ -1304,17 +1259,17 @@ static int GdiRectangle(
const char *dashdata = 0;
/* Verrrrrry simple for now.... */
- if (argc < 5) {
+ if (argc < 6) {
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
hDC = printDC;
- x1 = atol(argv[1]);
- y1 = atol(argv[2]);
- x2 = atol(argv[3]);
- y2 = atol(argv[4]);
+ x1 = atol(argv[2]);
+ y1 = atol(argv[3]);
+ x2 = atol(argv[4]);
+ y2 = atol(argv[5]);
if (x1 > x2) {
int x3 = x1;
x1 = x2;
@@ -1325,8 +1280,8 @@ static int GdiRectangle(
y1 = y2;
y2 = y3;
}
- argc -= 5;
- argv += 5;
+ argc -= 6;
+ argv += 6;
/* Now handle any other arguments that occur. */
while (argc > 1) {
@@ -1429,15 +1384,15 @@ static int GdiCharWidths(
int widths[256];
int retval;
- if (argc < 1) {
+ if (argc < 2) {
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
hDC = printDC;
- argc--;
- argv++;
+ argc -= 2;
+ argv += 2;
while (argc > 0) {
if (strcmp(argv[0], "-font") == 0) {
@@ -1564,10 +1519,10 @@ int GdiText(
hDC = printDC;
- x = atol(argv[1]);
- y = atol(argv[2]);
- argc -= 3;
- argv += 3;
+ x = atol(argv[2]);
+ y = atol(argv[3]);
+ argc -= 4;
+ argv += 4;
sizerect.left = sizerect.right = x;
sizerect.top = sizerect.bottom = y;
@@ -1904,7 +1859,8 @@ static int GdiMap(
int argc,
const char **argv)
{
- static const char usage_message[] = "::tk::print::_gdi map hdc "
+ static const char usage_message[] =
+ "::tk::print::_gdi map hdc "
"[-logical x[y]] [-physical x[y]] "
"[-offset {x y} ] [-default] [-mode mode]";
HDC hdc;
@@ -1924,7 +1880,7 @@ static int GdiMap(
int use_mode = 0;
/* Required parameter: HDC for printer. */
- if (argc < 1) {
+ if (argc < 2) {
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
@@ -1938,7 +1894,7 @@ static int GdiMap(
}
/* Parse remaining arguments. */
- for (argno = 1; argno < argc; argno++) {
+ for (argno = 2; argno < argc; argno++) {
if (strcmp(argv[argno], "-default") == 0) {
vextent.cx = vextent.cy = wextent.cx = wextent.cy = 1;
vorigin.x = vorigin.y = worigin.x = worigin.y = 0;
@@ -1970,6 +1926,7 @@ static int GdiMap(
need_usage = 1;
} else {
int count;
+
argno++;
/* In "real-life", this should parse units as well.. */
if ((count = sscanf(argv[argno], "%ld%ld",
@@ -2144,7 +2101,7 @@ static int GdiCopyBits(
* Parse the arguments.
*/
/* HDC is required. */
- if (argc < 1) {
+ if (argc < 2) {
Tcl_AppendResult(interp, usage_message, NULL);
return TCL_ERROR;
}
@@ -2162,7 +2119,7 @@ static int GdiCopyBits(
}
/* Loop through the remaining arguments. */
- for (k=1; k<argc; k++) {
+ for (k=2; k<argc; k++) {
if (strcmp(argv[k], "-window") == 0) {
if (argv[k+1] && argv[k+1][0] == '.') {
do_window = 1;
@@ -2777,7 +2734,7 @@ static int GdiMakePen(
if (dashstyle != 0 && dashstyledata != 0) {
const char *cp;
size_t i;
- char *dup = (char *)Tcl_Alloc(strlen(dashstyledata) + 1);
+ char *dup = (char *) Tcl_Alloc(strlen(dashstyledata) + 1);
strcpy(dup, dashstyledata);
/* DEBUG. */
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
@@ -4418,27 +4375,6 @@ static int PalEntriesOnDevice(
}
/*
- *--------------------------------------------------------------
- *
- * Gdi_Init --
- *
- * Initializes the Gdi package.
- *
- * Results:
- * Gdi commands initialized.
- *
- *--------------------------------------------------------------
- */
-
-int Gdi_Init(
- Tcl_Interp *interp)
-{
- Tcl_CreateCommand(interp, "::tk::print::_gdi", TkWinGDI,
- (ClientData) 0, (Tcl_CmdDeleteProc *) 0);
- return TCL_OK;
-}
-
-/*
* --------------------------------------------------------------------------
*
* Winprint_Init--
@@ -4454,6 +4390,32 @@ int Gdi_Init(
int Winprint_Init(
Tcl_Interp * interp)
{
+ size_t i;
+ Tcl_Namespace *namespacePtr;
+ static const char *gdiName = "::tk::print::_gdi";
+ static const size_t numCommands =
+ sizeof(gdi_commands) / sizeof(struct gdi_command);
+
+ /*
+ * Set up the low-level [_gdi] command.
+ */
+
+ namespacePtr = Tcl_CreateNamespace(interp, gdiName,
+ (ClientData) NULL, (Tcl_NamespaceDeleteProc *) NULL);
+ for (i=0; i<numCommands; i++) {
+ char buffer[100];
+
+ sprintf(buffer, "%s::%s", gdiName, gdi_commands[i].command_string);
+ Tcl_CreateCommand(interp, buffer, gdi_commands[i].command,
+ (ClientData) 0, (Tcl_CmdDeleteProc *) 0);
+ Tcl_Export(interp, namespacePtr, gdi_commands[i].command_string, 0);
+ }
+ Tcl_CreateEnsemble(interp, gdiName, namespacePtr, 0);
+
+ /*
+ * The other printing-related commands.
+ */
+
Tcl_CreateObjCommand(interp, "::tk::print::_selectprinter",
PrintSelectPrinter, NULL, NULL);
Tcl_CreateObjCommand(interp, "::tk::print::_openprinter",
@@ -4996,7 +4958,6 @@ int PrintCloseDoc(
int argc,
Tcl_Obj *const objv[])
{
-
(void) clientData;
(void) argc;
(void) objv;
diff --git a/win/tkWinInit.c b/win/tkWinInit.c
index c96a963..42ff46f 100644
--- a/win/tkWinInit.c
+++ b/win/tkWinInit.c
@@ -44,7 +44,6 @@ TkpInit(
WinIcoInit(interp);
Winprint_Init(interp);
- Gdi_Init(interp);
TkWinXInit(Tk_GetHINSTANCE());
return TCL_OK;
}
diff --git a/win/tkWinInt.h b/win/tkWinInt.h
index 6ab1ee3..30e8c88 100644
--- a/win/tkWinInt.h
+++ b/win/tkWinInt.h
@@ -227,13 +227,6 @@ MODULE_SCOPE int WinIcoInit (Tcl_Interp* interp);
MODULE_SCOPE int Winprint_Init(Tcl_Interp* interp);
/*
- * The following is implemented in tkWinGDI.c
- */
-
-
-MODULE_SCOPE int Gdi_Init(Tcl_Interp* interp);
-
-/*
* The following is implemented in tkWinSysTray.c
*/