Archive: nsDialogs suggestion


nsDialogs suggestion
I wanted to use a variation of an EDIT box, that limits input to numbers only. There is a style bit (ES_NUMBER) to do that, but no macros have been provided to allow adding styles to existing controls. So I modified nsDialogs.nsh (around line 248) from this:


!macro __NSD_DefineControl NAME
!define NSD_Create${NAME} "nsDialogs::CreateControl /NOUNLOAD ${__NSD_${Name}_CLASS} ${__NSD_${Name}_STYLE} ${__NSD_${Name}_EXSTYLE}"
!macroend
to this:
!macro __NSD_CreateControl Name X Y H W TXT
!ifndef NSD_ADD_STYLE
!define NSD_ADD_STYLE 0
!endif
!ifndef NSD_ADD_EXSTYLE
!define NSD_ADD_EXSTYLE 0
!endif
nsDialogs::CreateControl /NOUNLOAD ${__NSD_${Name}_CLASS} ${__NSD_${Name}_STYLE}|${NSD_ADD_STYLE} ${__NSD_${Name}_EXSTYLE}|${NSD_ADD_EXSTYLE} ${X} ${Y} ${H} ${W} "${TXT}"
!undef NSD_ADD_STYLE
!undef NSD_ADD_EXSTYLE
!macroend

!macro __NSD_DefineControl NAME
!define NSD_Create${NAME} "!insertmacro __NSD_CreateControl ${Name} "
!macroend

The programmer (me) needs to !define the style they want to add before each call to NSD_CreateText, like this
  !define NSD_ADD_STYLE ${ES_NUMBER}
${NSD_CreateText} 110u 48u 30u 11u "1000"
You can also add EXSTYLE (!define NSD_ADD_EXSTYLE ... ), and buttons as well as text boxes are good candidates.


@kichik, what do you think about including a similar change to the next version of nsDialogs.nsh?

Don

I was trying to think of a good solution for this problem for a while. A solution involving insertion of a macro which parameters' are passed through to a plug-in call has one major flaw - quotes. In your macro's case, it's enough to include a single double quote to kill the macro. That's why I went with direct plug-in calls in the first place.

I was also thinking of creating defines that the NSD_Create* define will use by concatenating them to the styles. But then the user will have to undefine those after each call because we can't do it for him.

There were a bunch of other ideas, but none was good enough. If you have a good idea that solves all of this, I'd be very happy to hear about it and include it in the next version.


I see what you are saying. This macro could use the back-quote (`), which would allow user text to have single or double quotes. It's not a total solution, but maybe a small improvement. I'll keep thinking about this...

Don