From d8f8c8972aecd96d9b2ec552f21421087dd7828c Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 5 Jul 2022 18:11:54 +0100 Subject: [PATCH] Make HelpCtx a per-platform type, not an intorptr. Partly, this just seems more sensible, since it may well vary per platform beyond the ability of intorptr to specify. But more immediately it means the definition of the HELPCTX macro doesn't have to use the P() function from dialog.h, which isn't defined in any circumstances outside the config subsystem. And I'm about to want to put a help context well outside that subsystem. --- config.c | 2 +- dialog.c | 28 ++++++++++++++-------------- dialog.h | 24 ++++++++++++------------ unix/platform.h | 4 +++- utils/ctrlset_normalise.c | 1 + windows/controls.c | 6 +++--- windows/help.h | 4 +++- 7 files changed, 37 insertions(+), 32 deletions(-) diff --git a/config.c b/config.c index cca76b29..a2537dbb 100644 --- a/config.c +++ b/config.c @@ -1588,7 +1588,7 @@ static void clipboard_selector_handler(dlgcontrol *ctrl, dlgparam *dlg, } static void clipboard_control(struct controlset *s, const char *label, - char shortcut, int percentage, intorptr helpctx, + char shortcut, int percentage, HelpCtx helpctx, int setting, int strsetting) { #ifdef NAMED_CLIPBOARDS diff --git a/dialog.c b/dialog.c index ce2d0eb2..26a0ff49 100644 --- a/dialog.c +++ b/dialog.c @@ -205,7 +205,7 @@ void *ctrl_alloc(struct controlbox *b, size_t size) } static dlgcontrol *ctrl_new(struct controlset *s, int type, - intorptr helpctx, handler_fn handler, + HelpCtx helpctx, handler_fn handler, intorptr context) { dlgcontrol *c = snew(dlgcontrol); @@ -228,7 +228,7 @@ static dlgcontrol *ctrl_new(struct controlset *s, int type, /* `ncolumns' is followed by that many percentages, as integers. */ dlgcontrol *ctrl_columns(struct controlset *s, int ncolumns, ...) { - dlgcontrol *c = ctrl_new(s, CTRL_COLUMNS, P(NULL), NULL, P(NULL)); + dlgcontrol *c = ctrl_new(s, CTRL_COLUMNS, NULL_HELPCTX, NULL, P(NULL)); assert(s->ncolumns == 1 || ncolumns == 1); c->columns.ncols = ncolumns; s->ncolumns = ncolumns; @@ -248,7 +248,7 @@ dlgcontrol *ctrl_columns(struct controlset *s, int ncolumns, ...) dlgcontrol *ctrl_editbox(struct controlset *s, const char *label, char shortcut, int percentage, - intorptr helpctx, handler_fn handler, + HelpCtx helpctx, handler_fn handler, intorptr context, intorptr context2) { dlgcontrol *c = ctrl_new(s, CTRL_EDITBOX, helpctx, handler, context); @@ -263,7 +263,7 @@ dlgcontrol *ctrl_editbox(struct controlset *s, const char *label, dlgcontrol *ctrl_combobox(struct controlset *s, const char *label, char shortcut, int percentage, - intorptr helpctx, handler_fn handler, + HelpCtx helpctx, handler_fn handler, intorptr context, intorptr context2) { dlgcontrol *c = ctrl_new(s, CTRL_EDITBOX, helpctx, handler, context); @@ -283,7 +283,7 @@ dlgcontrol *ctrl_combobox(struct controlset *s, const char *label, * is NO_SHORTCUT. */ dlgcontrol *ctrl_radiobuttons_fn(struct controlset *s, const char *label, - char shortcut, int ncolumns, intorptr helpctx, + char shortcut, int ncolumns, HelpCtx helpctx, handler_fn handler, intorptr context, ...) { va_list ap; @@ -329,7 +329,7 @@ dlgcontrol *ctrl_radiobuttons_fn(struct controlset *s, const char *label, } dlgcontrol *ctrl_pushbutton(struct controlset *s, const char *label, - char shortcut, intorptr helpctx, + char shortcut, HelpCtx helpctx, handler_fn handler, intorptr context) { dlgcontrol *c = ctrl_new(s, CTRL_BUTTON, helpctx, handler, context); @@ -341,7 +341,7 @@ dlgcontrol *ctrl_pushbutton(struct controlset *s, const char *label, } dlgcontrol *ctrl_listbox(struct controlset *s, const char *label, - char shortcut, intorptr helpctx, + char shortcut, HelpCtx helpctx, handler_fn handler, intorptr context) { dlgcontrol *c = ctrl_new(s, CTRL_LISTBOX, helpctx, handler, context); @@ -358,7 +358,7 @@ dlgcontrol *ctrl_listbox(struct controlset *s, const char *label, } dlgcontrol *ctrl_droplist(struct controlset *s, const char *label, - char shortcut, int percentage, intorptr helpctx, + char shortcut, int percentage, HelpCtx helpctx, handler_fn handler, intorptr context) { dlgcontrol *c = ctrl_new(s, CTRL_LISTBOX, helpctx, handler, context); @@ -375,7 +375,7 @@ dlgcontrol *ctrl_droplist(struct controlset *s, const char *label, } dlgcontrol *ctrl_draglist(struct controlset *s, const char *label, - char shortcut, intorptr helpctx, + char shortcut, HelpCtx helpctx, handler_fn handler, intorptr context) { dlgcontrol *c = ctrl_new(s, CTRL_LISTBOX, helpctx, handler, context); @@ -393,7 +393,7 @@ dlgcontrol *ctrl_draglist(struct controlset *s, const char *label, dlgcontrol *ctrl_filesel(struct controlset *s, const char *label, char shortcut, const char *filter, bool write, - const char *title, intorptr helpctx, + const char *title, HelpCtx helpctx, handler_fn handler, intorptr context) { dlgcontrol *c = ctrl_new(s, CTRL_FILESELECT, helpctx, handler, context); @@ -406,7 +406,7 @@ dlgcontrol *ctrl_filesel(struct controlset *s, const char *label, } dlgcontrol *ctrl_fontsel(struct controlset *s, const char *label, - char shortcut, intorptr helpctx, + char shortcut, HelpCtx helpctx, handler_fn handler, intorptr context) { dlgcontrol *c = ctrl_new(s, CTRL_FONTSELECT, helpctx, handler, context); @@ -417,13 +417,13 @@ dlgcontrol *ctrl_fontsel(struct controlset *s, const char *label, dlgcontrol *ctrl_tabdelay(struct controlset *s, dlgcontrol *ctrl) { - dlgcontrol *c = ctrl_new(s, CTRL_TABDELAY, P(NULL), NULL, P(NULL)); + dlgcontrol *c = ctrl_new(s, CTRL_TABDELAY, NULL_HELPCTX, NULL, P(NULL)); c->tabdelay.ctrl = ctrl; return c; } dlgcontrol *ctrl_text(struct controlset *s, const char *text, - intorptr helpctx) + HelpCtx helpctx) { dlgcontrol *c = ctrl_new(s, CTRL_TEXT, helpctx, NULL, P(NULL)); c->label = dupstr(text); @@ -432,7 +432,7 @@ dlgcontrol *ctrl_text(struct controlset *s, const char *text, } dlgcontrol *ctrl_checkbox(struct controlset *s, const char *label, - char shortcut, intorptr helpctx, + char shortcut, HelpCtx helpctx, handler_fn handler, intorptr context) { dlgcontrol *c = ctrl_new(s, CTRL_CHECKBOX, helpctx, handler, context); diff --git a/dialog.h b/dialog.h index fad78d16..ab933b9a 100644 --- a/dialog.h +++ b/dialog.h @@ -161,7 +161,7 @@ struct dlgcontrol { * platform-specific driver can use to ensure it brings up the * right piece of help text. */ - intorptr helpctx; + HelpCtx helpctx; /* * Setting this to non-NULL coerces two or more controls to have * their y-coordinates adjusted so that they can sit alongside @@ -519,11 +519,11 @@ void *ctrl_alloc_with_free(struct controlbox *b, size_t size, /* `ncolumns' is followed by that many percentages, as integers. */ dlgcontrol *ctrl_columns(struct controlset *, int ncolumns, ...); dlgcontrol *ctrl_editbox(struct controlset *, const char *label, - char shortcut, int percentage, intorptr helpctx, + char shortcut, int percentage, HelpCtx helpctx, handler_fn handler, intorptr context, intorptr context2); dlgcontrol *ctrl_combobox(struct controlset *, const char *label, - char shortcut, int percentage, intorptr helpctx, + char shortcut, int percentage, HelpCtx helpctx, handler_fn handler, intorptr context, intorptr context2); /* @@ -533,33 +533,33 @@ dlgcontrol *ctrl_combobox(struct controlset *, const char *label, * is NO_SHORTCUT. */ dlgcontrol *ctrl_radiobuttons_fn(struct controlset *, const char *label, - char shortcut, int ncolumns, intorptr helpctx, + char shortcut, int ncolumns, HelpCtx helpctx, handler_fn handler, intorptr context, ...); #define ctrl_radiobuttons(...) \ ctrl_radiobuttons_fn(__VA_ARGS__, (const char *)NULL) dlgcontrol *ctrl_pushbutton(struct controlset *, const char *label, - char shortcut, intorptr helpctx, + char shortcut, HelpCtx helpctx, handler_fn handler, intorptr context); dlgcontrol *ctrl_listbox(struct controlset *, const char *label, - char shortcut, intorptr helpctx, + char shortcut, HelpCtx helpctx, handler_fn handler, intorptr context); dlgcontrol *ctrl_droplist(struct controlset *, const char *label, - char shortcut, int percentage, intorptr helpctx, + char shortcut, int percentage, HelpCtx helpctx, handler_fn handler, intorptr context); dlgcontrol *ctrl_draglist(struct controlset *, const char *label, - char shortcut, intorptr helpctx, + char shortcut, HelpCtx helpctx, handler_fn handler, intorptr context); dlgcontrol *ctrl_filesel(struct controlset *, const char *label, char shortcut, const char *filter, bool write, - const char *title, intorptr helpctx, + const char *title, HelpCtx helpctx, handler_fn handler, intorptr context); dlgcontrol *ctrl_fontsel(struct controlset *, const char *label, - char shortcut, intorptr helpctx, + char shortcut, HelpCtx helpctx, handler_fn handler, intorptr context); dlgcontrol *ctrl_text(struct controlset *, const char *text, - intorptr helpctx); + HelpCtx helpctx); dlgcontrol *ctrl_checkbox(struct controlset *, const char *label, - char shortcut, intorptr helpctx, + char shortcut, HelpCtx helpctx, handler_fn handler, intorptr context); dlgcontrol *ctrl_tabdelay(struct controlset *, dlgcontrol *); diff --git a/unix/platform.h b/unix/platform.h index 6a8c7ba3..31da1294 100644 --- a/unix/platform.h +++ b/unix/platform.h @@ -78,7 +78,9 @@ extern const struct BackendVtable pty_backend; /* * Under GTK, there is no context help available. */ -#define HELPCTX(x) P(NULL) +typedef void *HelpCtx; +#define NULL_HELPCTX ((HelpCtx)NULL) +#define HELPCTX(x) NULL #define FILTER_KEY_FILES NULL /* FIXME */ #define FILTER_DYNLIB_FILES NULL /* FIXME */ diff --git a/utils/ctrlset_normalise.c b/utils/ctrlset_normalise.c index 46f5f19f..3d922ebb 100644 --- a/utils/ctrlset_normalise.c +++ b/utils/ctrlset_normalise.c @@ -2,6 +2,7 @@ * Helper function from the dialog.h mechanism. */ +#include "putty.h" #include "misc.h" #include "dialog.h" diff --git a/windows/controls.c b/windows/controls.c index 7065b7be..22b70c93 100644 --- a/windows/controls.c +++ b/windows/controls.c @@ -2131,12 +2131,12 @@ bool winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id) /* * This is the Windows front end, so we're allowed to assume - * `helpctx.p' is a context string. + * `helpctx' is a context string. */ - if (!c->ctrl || !c->ctrl->helpctx.p) + if (!c->ctrl || !c->ctrl->helpctx) return false; /* no help available for this ctrl */ - launch_help(hwnd, c->ctrl->helpctx.p); + launch_help(hwnd, c->ctrl->helpctx); return true; } diff --git a/windows/help.h b/windows/help.h index 0ab0e050..d0f76496 100644 --- a/windows/help.h +++ b/windows/help.h @@ -9,7 +9,9 @@ /* These are used in the cross-platform configuration dialog code. */ -#define HELPCTX(x) P(WINHELP_CTX_ ## x) +typedef const char *HelpCtx; +#define NULL_HELPCTX NULL +#define HELPCTX(x) WINHELP_CTX_ ## x #define WINHELP_CTX_no_help NULL