all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Cecilio Pardo <cpardo@imayhem.com>
Cc: 20481@debbugs.gnu.org
Subject: bug#20481: 24.5; , Newlines in message-box output don't work on Windows
Date: Mon, 19 Aug 2024 20:44:50 +0300	[thread overview]
Message-ID: <86v7zwwgod.fsf@gnu.org> (raw)
In-Reply-To: <e90b2cad-ce0c-49e4-9481-2be4fbfe5e2f@imayhem.com> (message from Cecilio Pardo on Mon, 19 Aug 2024 18:13:31 +0200)

> Date: Mon, 19 Aug 2024 18:13:31 +0200
> From: Cecilio Pardo <cpardo@imayhem.com>
> 
> This patch adds support on Windows Vista an later for dialog boxes using 
> TaskDialog.

Thanks.

First, to accept a contribution of this size we'll need a
copyright-assignment paperwork from you.  Should I send you the form
to fill with instructions to go with it, so you could start the
paperwork rolling?

A few comments about the patch:

> +  void *task_dialog_indirect =
> +    get_proc_addr (GetModuleHandle ("comctl32.dll"), "TaskDialogIndirect");
> +
> +  if (task_dialog_indirect)

A minor optimization is to call get_proc_addr only once and save the
result in a static variable.  We use this technique in many places in
Emacs, and I see no reason not to do that here.

> +      /* Get the title as a UTF-16 string. */
> +      CHECK_STRING (XCAR (contents));
> +      char *title =  SSDATA (XCAR (contents));
> +      int wide_length = sizeof(WCHAR) *
> +	pMultiByteToWideChar (CP_UTF8, 0, title, -1, NULL, 0);
> +      WCHAR *title_text_wide = alloca (wide_length);
> +      pMultiByteToWideChar (CP_UTF8, 0, title, -1,
> +			    title_text_wide, wide_length);

The text of Lisp strings is stored by Emacs in a super-set of UTF-8,
so it cannot be safely passed to MultiByteToWideChar.  You need to
encode it in UTF-8 first (use ENCODE_UTF_8).

> +	    CHECK_STRING (item_name);
> +
> +	    int wide_length = sizeof(WCHAR) *
> +	      pMultiByteToWideChar (CP_UTF8, 0, SSDATA (item_name), -1,
> +				    NULL, 0);
> +	    buttons[button_count].pszButtonText = alloca (wide_length);
> +	    pMultiByteToWideChar (CP_UTF8, 0, SSDATA (item_name), -1,
> +				  (LPWSTR)
> +				  buttons[button_count].pszButtonText,
> +				  wide_length);

Same here.

> +	else if (NILP (item))
> +	  {
> +	    /* A nil item means to put all following items on the
> +	       right. We ignore this. */
                    ^^              ^^
Our convention is to leave two spaces between sentences in
documentation, comments, and strings.  We also leave two spaces at the
end of C comments, before the closing "*/" (here and elsewhere in the
patch).

> +	else if (STRINGP(item))
                       ^^
Another stylistic nit: please leave one space between the name of a
function/macro and the opening parenthesis that follows it (here and
elsewhere in the patch).

> +	    /* A string item means an unselectable button. We add a
> +	       button, an then need to disable it on the callback.
> +	       We use ids based on 2000 to mark these buttons */
> +	    int wide_length = sizeof(WCHAR) *
> +	      pMultiByteToWideChar (CP_UTF8, 0, SSDATA (item), -1, NULL, 0);
> +	    buttons[button_count].pszButtonText = alloca (wide_length);
> +	    pMultiByteToWideChar (CP_UTF8, 0, SSDATA (item), -1,
> +				  (LPWSTR)
> +				  buttons[button_count].pszButtonText,
> +				  wide_length);

UTF-8 encoding again.





  reply	other threads:[~2024-08-19 17:44 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-01  3:18 bug#20481: 24.5; Newlines in message-box output don't work on Windows Adam Connor
2015-05-01  7:19 ` Eli Zaretskii
     [not found]   ` <CAC_vAoGvLFr--qNihU+MDpyZPhZEysz02hCOOWVE4otubmRJWg@mail.gmail.com>
2015-05-02  6:33     ` Eli Zaretskii
2024-08-19 16:13 ` bug#20481: 24.5; , " Cecilio Pardo
2024-08-19 17:44   ` Eli Zaretskii [this message]
2024-08-19 19:20     ` Cecilio Pardo
2024-09-11 13:44     ` Cecilio Pardo
2024-09-12  2:49       ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-12 13:33         ` Cecilio Pardo
2024-09-14 11:00           ` Eli Zaretskii
     [not found]             ` <28906c5b-0ff1-49a7-990b-50ad95235be2@imayhem.com>
2024-09-14 15:19               ` Eli Zaretskii
2024-09-14 12:05           ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-14 12:17             ` Eli Zaretskii
2024-09-14 14:02               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-14 14:14                 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86v7zwwgod.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=20481@debbugs.gnu.org \
    --cc=cpardo@imayhem.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.