Old 7th August 2020, 00:44   #1
ggarra13
Junior Member
 
Join Date: May 2016
Posts: 7
Adding a check all / uncheck all

I inherited code that lists a bunch of options and allows the user to select them:

code:

!include nsDialogs.nsh
!include WinMessages.nsh
!ifndef LVM_GETITEMTEXT
!define /math LVM_GETITEMTEXTA ${LVM_FIRST} + 45
!define /math LVM_GETITEMTEXTW ${LVM_FIRST} + 115
${_NSIS_DEFAW} LVM_GETITEMTEXT
!endif
Var hListCtl
Page Custom LVPageCreate LVPageLeave

Function AddCheckedListViewItemWith1SubItem
System::Store S
Pop $4
Pop $3
Pop $2
Pop $1
System::Call '*(i ${LVIF_TEXT},i 0x7fffffff,i 0,i,&i${NSIS_PTR_SIZE},tr2,i,i,p)p.r9'
SendMessage $1 ${LVM_INSERTITEM} "" $9 $0
System::Call '*$9(i${LVIF_STATE},i,i,i0x2000,&i${NSIS_PTR_SIZE} ${LVIS_STATEIMAGEMASK},p,i,i,p)'
IntCmpU $4 0 +2
SendMessage $1 ${LVM_SETITEMSTATE} $0 $9 $8
System::Call '*$9(i,i 0x7fffffff,i 1,i,i,tr3,i,i,p)'
SendMessage $1 ${LVM_SETITEMTEXT} $0 $9
System::Free $9
System::Store L
FunctionEnd

!macro AddCheckedListViewItemWith1SubItem hLV txt sub1 checked
Push ${hLV}
Push "${txt}"
Push "${sub1}"
Push "${checked}"
Call AddCheckedListViewItemWith1SubItem
!macroend

Function LVPageCreate
nsDialogs::Create 1018
Pop $0

${NSD_CreateLabel} 0 0 100% 12u "File associations for mrViewer"

nsDialogs::CreateControl "SysListView32" ${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${LVS_REPORT} ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE} 0 20 100% 90% ""
Pop $hListCtl
IntOp $0 ${LVS_EX_FULLROWSELECT} | ${LVS_EX_CHECKBOXES}
SendMessage $hListCtl ${LVM_SETEXTENDEDLISTVIEWSTYLE} 0 $0
System::Call '*(i${LVCF_TEXT}|${LVCF_SUBITEM},i,i,t "Extension",i,i 0)p.r9'
SendMessage $hListCtl ${LVM_INSERTCOLUMN} 0x7fffffff $9
System::Call '*$9(i,i,i,t "Description",i,i 1)'
SendMessage $hListCtl ${LVM_INSERTCOLUMN} 0x7fffffff $9
System::Free $9

# ...the options...

!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".tiff" "TIFF file" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".tga" "Targa file" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".bmp" "Windows/OS2 Bitmap" 1
# ...etc...

SendMessage $hListCtl ${LVM_SETCOLUMNWIDTH} 0 -1
SendMessage $hListCtl ${LVM_SETCOLUMNWIDTH} 1 -1
System::Call 'USER32::PostMessage(p $hwndparent, i ${WM_NEXTDLGCTL}, p $hListCtl, i1)'
nsDialogs::Show
FunctionEnd

# LVLeavePage not shown



I would like to have a checkin button and function that toggles on/off all the listed items.

Can someone help me write it?
ggarra13 is offline   Reply With Quote
Old 7th August 2020, 12:10   #2
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
I guess you could do this with a components page and relevant sections instead:

PHP Code:
!include "Sections.nsh"

RequestExecutionLevel user
ShowInstDetails show

Page Components
Page InstFiles

SectionGroup 
"File associations for mrViewer" SecAssoc

Section 
".tiff (TIFF file)"
  
DetailPrint ".tiff (TIFF file)"
SectionEnd

Section 
".tga (Targa file)"
  
DetailPrint ".tga (Targa file)"
SectionEnd

Section 
".bmp (Windows/OS2 Bitmap)"
  
DetailPrint ".bmp (Windows/OS2 Bitmap)"
SectionEnd

SectionGroupEnd

Function .oninit
  SectionGetFlags 
${SecAssoc} $0
  IntOp 
$$| ${SF_EXPAND}
  
SectionSetFlags ${SecAssoc} $0
FunctionEnd 

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 8th August 2020, 20:10   #3
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,418
PHP Code:
!macro LVCheckAll hLV tempvar
System
::Call '*(i ${LVIF_STATE},i,i 0,i0x2000,&i${NSIS_PTR_SIZE} ${LVIS_STATEIMAGEMASK},p0,i0,i,p)p.s'
Pop ${tempvar}
SendMessage ${hLV} ${LVM_SETITEMSTATE} -${tempvar}
System::Free ${tempvar}
!
macroend

!macro LVUncheckAll hLV tempvar
System
::Call '*(i ${LVIF_STATE},i,i 0,i0x1000,&i${NSIS_PTR_SIZE} ${LVIS_STATEIMAGEMASK},p0,i0,i,p)p.s'
Pop ${tempvar}
SendMessage ${hLV} ${LVM_SETITEMSTATE} -${tempvar}
System::Free ${tempvar}
!
macroend

...

!
insertmacro LVCheckAll $hListCtl $

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 10th April 2021, 14:23   #4
ggarra13
Junior Member
 
Join Date: May 2016
Posts: 7
Adding a check all / uncheck all

I have an installer written by someone else that has a number of checkboxes. I would like to add another checkbox to turn on/off all other checkboxes, but don't know how. Can someone help me?

Here's the code for the current implementation:

code:

!include nsDialogs.nsh
!include WinMessages.nsh


!ifndef LVM_GETITEMTEXT
!define /math LVM_GETITEMTEXTA ${LVM_FIRST} + 45
!define /math LVM_GETITEMTEXTW ${LVM_FIRST} + 115
${_NSIS_DEFAW} LVM_GETITEMTEXT
!endif
Var hListCtl
Page Custom LVPageCreate LVPageLeave


Function AddCheckedListViewItemWith1SubItem
System::Store S
Pop $4
Pop $3
Pop $2
Pop $1
System::Call '*(i ${LVIF_TEXT},i 0x7fffffff,i 0,i,&i${NSIS_PTR_SIZE},tr2,i,i,p)p.r9'
SendMessage $1 ${LVM_INSERTITEM} "" $9 $0
System::Call '*$9(i${LVIF_STATE},i,i,i0x2000,&i${NSIS_PTR_SIZE} ${LVIS_STATEIMAGEMASK},p,i,i,p)'
IntCmpU $4 0 +2
SendMessage $1 ${LVM_SETITEMSTATE} $0 $9 $8
System::Call '*$9(i,i 0x7fffffff,i 1,i,i,tr3,i,i,p)'
SendMessage $1 ${LVM_SETITEMTEXT} $0 $9
System::Free $9
System::Store L
FunctionEnd

!macro AddCheckedListViewItemWith1SubItem hLV txt sub1 checked
Push ${hLV}
Push "${txt}"
Push "${sub1}"
Push "${checked}"
Call AddCheckedListViewItemWith1SubItem
!macroend

Function LVPageCreate
nsDialogs::Create 1018
Pop $0

${NSD_CreateLabel} 0 0 100% 12u "File associations for mrViewer"

nsDialogs::CreateControl "SysListView32" ${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${LVS_REPORT} ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE} 0 20 100% 90% ""
Pop $hListCtl
IntOp $0 ${LVS_EX_FULLROWSELECT} | ${LVS_EX_CHECKBOXES}
SendMessage $hListCtl ${LVM_SETEXTENDEDLISTVIEWSTYLE} 0 $0
System::Call '*(i${LVCF_TEXT}|${LVCF_SUBITEM},i,i,t "Extension",i,i 0)p.r9'
SendMessage $hListCtl ${LVM_INSERTCOLUMN} 0x7fffffff $9
System::Call '*$9(i,i,i,t "Description",i,i 1)'
SendMessage $hListCtl ${LVM_INSERTCOLUMN} 0x7fffffff $9
System::Free $9
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".au" "Solaris Audio file" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".bit" "mental ray Bitmap" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".bmp" "Windows/OS2 Bitmap" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".braw" "Blackmagic RAW Movie" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".cin" "Kodak Cineon" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".ct" "mental ray contour" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".dds" "DirectDraw Surface" 1
!insertmacro AddCheckedListViewItemWith1SubItem $hListCtl ".dib" "Windows Device Independent Bitmap" 1


SendMessage $hListCtl ${LVM_SETCOLUMNWIDTH} 0 -1
SendMessage $hListCtl ${LVM_SETCOLUMNWIDTH} 1 -1
System::Call 'USER32::PostMessage(p $hwndparent, i ${WM_NEXTDLGCTL}, p $hListCtl, i1)'
nsDialogs::Show
FunctionEnd


Function LVPageLeave
System::Call '*(&t${NSIS_MAX_STRLEN},i)p.r8'
System::Call '*(i ${LVIF_TEXT},i,i 0,i,&i${NSIS_PTR_SIZE},pr8,i${NSIS_MAX_STRLEN},i,p)p.r9'
SendMessage $hListCtl ${LVM_GETITEMCOUNT} "" "" $1
StrCpy $0 0
${DoWhile} $0 < $1
SendMessage $hListCtl ${LVM_GETITEMSTATE} $0 ${LVIS_STATEIMAGEMASK} $2
IntOp $2 $2 & 0x2000
${If} $2 <> 0
SendMessage $hListCtl ${LVM_GETITEMTEXT} $0 $9 $2
System::Call '*$8(&t${NSIS_MAX_STRLEN}.r7)'
WriteRegStr HKCR '$7' '' 'mrViewer'
WriteINIStr '$INSTDIR\\fileext.ini' ext '$7' 1
${EndIf}
IntOp $0 $0 + 1
${Loop}
System::Free $8
System::Free $9
FunctionEnd



ggarra13 is offline   Reply With Quote
Old 10th April 2021, 15:56   #5
ggarra13
Junior Member
 
Join Date: May 2016
Posts: 7
Anders,

Thank you for answering. However, your code does not seem to work. There's no "check all" / "uncheck all" buttons in the gui when I add your code.
ggarra13 is offline   Reply With Quote
Old 11th April 2021, 01:39   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,418
Quote:
Originally Posted by ggarra13 View Post
Thank you for answering. However, your code does not seem to work. There's no "check all" / "uncheck all" buttons in the gui when I add your code.
I know it does not add the button, you have to add the button yourself with nsDialogs. The button onclick handler should insert the check/uncheck macros.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump