[PATCH] comctl32/taskdialog: Implement nDefaultButton and add tests

Nikolay Sivov bunglehead at gmail.com
Sun Nov 5 02:51:59 CST 2017


On 04.11.2017 18:22, Fabian Maurer wrote:
> Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
> ---
>  dlls/comctl32/taskdialog.c       |  21 +++++--
>  dlls/comctl32/tests/taskdialog.c | 115 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 130 insertions(+), 6 deletions(-)
> 
> diff --git a/dlls/comctl32/taskdialog.c b/dlls/comctl32/taskdialog.c
> index 5c4af2ab03..4f80311a61 100644
> --- a/dlls/comctl32/taskdialog.c
> +++ b/dlls/comctl32/taskdialog.c
> @@ -151,7 +151,7 @@ static void taskdialog_get_text_extent(const struct taskdialog_template_desc *de
>  }
>  
>  static unsigned int taskdialog_add_control(struct taskdialog_template_desc *desc, WORD id, const WCHAR *class,
> -        HINSTANCE hInstance, const WCHAR *text, short x, short y, short cx, short cy)
> +        HINSTANCE hInstance, const WCHAR *text, DWORD style, short x, short y, short cx, short cy)
>  {
>      struct taskdialog_control *control = Alloc(sizeof(*control));
>      unsigned int size, class_size, text_size;
> @@ -178,7 +178,7 @@ static unsigned int taskdialog_add_control(struct taskdialog_template_desc *desc
>      control->template = template = Alloc(size);
>      control->template_size = size;
>  
> -    template->style = WS_VISIBLE;
> +    template->style = WS_VISIBLE | style;
>      template->dwExtendedStyle = 0;
>      template->x = x;
>      template->y = y;
> @@ -206,7 +206,7 @@ static unsigned int taskdialog_add_static_label(struct taskdialog_template_desc
>      taskdialog_get_text_extent(desc, str, TRUE, &sz);
>  
>      desc->dialog_height += DIALOG_SPACING;
> -    size = taskdialog_add_control(desc, id, WC_STATICW, desc->taskconfig->hInstance, str, DIALOG_SPACING,
> +    size = taskdialog_add_control(desc, id, WC_STATICW, desc->taskconfig->hInstance, str, 0, DIALOG_SPACING,
>              desc->dialog_height, sz.cx, sz.cy);
>      desc->dialog_height += sz.cy + DIALOG_SPACING;
>      return size;
> @@ -268,6 +268,7 @@ static unsigned int taskdialog_add_buttons(struct taskdialog_template_desc *desc
>      unsigned int location_x, *line_widths, alignment = ~0u;
>      const TASKDIALOGCONFIG *taskconfig = desc->taskconfig;
>      struct taskdialog_button_desc *buttons;
> +    int default_button;
>  
>      /* Allocate enough memory for the custom and the default buttons. Maximum 6 default buttons possible. */
>      buttons_size = 6;
> @@ -340,18 +341,26 @@ static unsigned int taskdialog_add_buttons(struct taskdialog_template_desc *desc
>              alignment = new_alignment;
>      }
>  
> +    /* Check if the default button is actually valid, if no default to the first created button */
> +    default_button = buttons[0].id;
> +    for (i = 0; i < count; i++)
> +        if (buttons[i].id == taskconfig->nDefaultButton)
> +            default_button = taskconfig->nDefaultButton;
> +

We already iterate over custom buttons and check every common button
flag before this point, so it shouldn't be necessary to have another loop.

> @@ -583,7 +592,7 @@ HRESULT WINAPI TaskDialogIndirect(const TASKDIALOGCONFIG *taskconfig, int *butto
>      Free(template);
>  
>      if (button) *button = ret;
> -    if (radio_button) *radio_button = taskconfig->nDefaultButton;
> +    if (radio_button) *radio_button = FALSE;
>      if (verification_flag_checked) *verification_flag_checked = TRUE;
>  

Same as with verification flag, we don't implement radio buttons
currently so it's better to leave it as is to avoid possible regressions
until we add support for them. Also you're supposed to return button id,
not binary flags.

>  
> +static TASKDIALOG_BUTTON* buttons_make(void)
> +{
> +    static const WCHAR str_format[] = {'%','0','2','d',0};
> +    static TASKDIALOG_BUTTON buttons[TEST_NUM_BUTTONS];
> +    static WCHAR titles[TEST_NUM_BUTTONS * 3]; /* Each button has two digits as title, plus null-terminator */
> +    int i;
> +
> +    for (i = 0; i < TEST_NUM_BUTTONS; i++)
> +    {
> +        WCHAR *text = &titles[i * 3];
> +        wsprintfW(text, str_format, i);
> +
> +        buttons[i].pszButtonText = text;
> +        buttons[i].nButtonID = ID_START_BUTTON + i;
> +    }
> +    return buttons;
> +}
> +

Please merge this to test function.





More information about the wine-devel mailing list