home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Include / Sections.nsh < prev    next >
Text File  |  2003-12-24  |  5KB  |  239 lines

  1. ; Sections.nsh
  2. ;
  3. ; Defines and macros for section control
  4. ;
  5. ; Include in your script using:
  6. ; !include "Sections.nsh"
  7.  
  8. ;--------------------------------
  9.  
  10. !ifndef SECTIONS_INCLUDED
  11.  
  12. !define SECTIONS_INCLUDED
  13.  
  14. ;--------------------------------
  15.  
  16. ; Generic section defines
  17.  
  18. !define SF_SELECTED   1
  19. !define SF_SUBSEC     2
  20. !define SF_SUBSECEND  4
  21. !define SF_BOLD       8
  22. !define SF_RO         16
  23. !define SF_EXPAND     32
  24. !define SF_PSELECTED  64
  25.  
  26. !define SECTION_OFF   0xFFFFFFFE
  27.  
  28. ;--------------------------------
  29.  
  30. ; Select / unselect / reserve section
  31.  
  32. !macro SelectSection SECTION
  33.  
  34.   Push $0
  35.     SectionGetFlags "${SECTION}" $0
  36.     IntOp $0 $0 | ${SF_SELECTED}
  37.     SectionSetFlags "${SECTION}" $0
  38.   Pop $0
  39.  
  40. !macroend
  41.  
  42. !macro UnselectSection SECTION
  43.  
  44.   Push $0
  45.     SectionGetFlags "${SECTION}" $0
  46.     IntOp $0 $0 & ${SECTION_OFF}
  47.     SectionSetFlags "${SECTION}" $0
  48.   Pop $0
  49.  
  50. !macroend
  51.  
  52. ; If section selected, will unselect, if unselected, will select
  53.  
  54. !macro ReverseSection SECTION
  55.  
  56.   Push $0
  57.     SectionGetFlags "${SECTION}" $0
  58.     IntOp $0 $0 ^ ${SF_SELECTED}
  59.     SectionSetFlags "${SECTION}" $0
  60.   Pop $0
  61.  
  62. !macroend
  63.  
  64. ;--------------------------------
  65.  
  66. ; Macros for mutually exclusive section selection
  67. ; Written by Tim Gallagher
  68. ;
  69. ; See one-section.nsi for an example of usage
  70.  
  71. ; Starts the Radio Button Block
  72. ; You should pass a variable that keeps the selected section
  73. ; as the first parameter for this macro. This variable should
  74. ; be initialized to the default section's index.
  75. ;
  76. ; As this macro uses $R0 and $R1 you can't use those two as the
  77. ; varible which will keep the selected section.
  78.  
  79. !macro StartRadioButtons var
  80.  
  81.   !define StartRadioButtons_Var "${var}"
  82.  
  83.   Push $R0
  84.   
  85.    SectionGetFlags "${StartRadioButtons_Var}" $R0
  86.    IntOp $R0 $R0 & ${SECTION_OFF}
  87.    SectionSetFlags "${StartRadioButtons_Var}" $R0
  88.    
  89.   Push $R1
  90.   
  91.     StrCpy $R1 "${StartRadioButtons_Var}"
  92.    
  93. !macroend
  94.  
  95. ; A radio button
  96.  
  97. !macro RadioButton SECTION_NAME
  98.  
  99.   SectionGetFlags ${SECTION_NAME} $R0
  100.   IntOp $R0 $R0 & ${SF_SELECTED}
  101.   IntCmp $R0 ${SF_SELECTED} 0 +2 +2
  102.   StrCpy "${StartRadioButtons_Var}" ${SECTION_NAME}
  103.  
  104. !macroend
  105.  
  106. ; Ends the radio button block
  107.  
  108. !macro EndRadioButtons
  109.   
  110.   StrCmp $R1 "${StartRadioButtons_Var}" 0 +4 ; selection hasn't changed
  111.     SectionGetFlags "${StartRadioButtons_Var}" $R0
  112.     IntOp $R0 $R0 | ${SF_SELECTED}
  113.     SectionSetFlags "${StartRadioButtons_Var}" $R0
  114.  
  115.   Pop $R1
  116.   Pop $R0
  117.   
  118.   !undef StartRadioButtons_Var
  119.  
  120. !macroend
  121.  
  122. ;--------------------------------
  123.  
  124. ; These are two macros you can use to set a Section in an InstType
  125. ; or clear it from an InstType.
  126. ;
  127. ; Written by Robert Kehl
  128. ;
  129. ; For details, see http://nsis.sourceforge.net/archive/nsisweb.php?page=287
  130. ;
  131. ; Use the defines below for the WANTED_INSTTYPE paramter.
  132.  
  133. !define INSTTYPE_1 1
  134. !define INSTTYPE_2 2
  135. !define INSTTYPE_3 4
  136. !define INSTTYPE_4 8
  137. !define INSTTYPE_5 16
  138. !define INSTTYPE_6 32
  139. !define INSTTYPE_7 64
  140. !define INSTTYPE_8 128
  141. !define INSTTYPE_9 256
  142. !define INSTTYPE_10 512
  143. !define INSTTYPE_11 1024
  144. !define INSTTYPE_12 2048
  145. !define INSTTYPE_13 4096
  146. !define INSTTYPE_14 8192
  147. !define INSTTYPE_15 16384
  148. !define INSTTYPE_16 32768
  149. !define INSTTYPE_17 65536
  150. !define INSTTYPE_18 131072
  151. !define INSTTYPE_19 262144
  152. !define INSTTYPE_20 524288
  153. !define INSTTYPE_21 1048576
  154. !define INSTTYPE_22 2097152
  155. !define INSTTYPE_23 4194304
  156. !define INSTTYPE_24 8388608
  157. !define INSTTYPE_25 16777216
  158. !define INSTTYPE_26 33554432
  159. !define INSTTYPE_27 67108864
  160. !define INSTTYPE_28 134217728
  161. !define INSTTYPE_29 268435456
  162. !define INSTTYPE_30 536870912
  163. !define INSTTYPE_31 1073741824
  164. !define INSTTYPE_32 2147483648
  165.  
  166. !macro SetSectionInInstType SECTION_NAME WANTED_INSTTYPE
  167.  
  168.   Push $0
  169.     SectionGetInstTypes "${SECTION_NAME}" $0
  170.     IntOp $0 $0 | ${WANTED_INSTTYPE}
  171.     SectionSetInstTypes "${SECTION_NAME}" $0
  172.   Pop $0
  173.  
  174. !macroend
  175.  
  176. !macro ClearSectionInInstType SECTION_NAME WANTED_INSTTYPE
  177.  
  178.   Push $0
  179.   Push $1
  180.     SectionGetInstTypes "${SECTION_NAME}" $0
  181.     StrCpy $1 ${WANTED_INSTTYPE}
  182.     IntOp $1 $1 ~
  183.     IntOp $0 $0 & $1
  184.     SectionSetInstTypes "${SECTION_NAME}" $0
  185.   Pop $1
  186.   Pop $0
  187.  
  188. !macroend
  189.  
  190. ;--------------------------------
  191.  
  192. ; Set / clear / check bits in a section's flags
  193. ; Written by derekrprice
  194.  
  195. ; Set one or more bits in a sections's flags
  196.  
  197. !macro SetSectionFlag SECTION BITS
  198.  
  199.   Push $R0
  200.     SectionGetFlags "${SECTION}" $R0
  201.     IntOp $R0 $R0 | "${BITS}"
  202.     SectionSetFlags "${SECTION}" $R0
  203.   Pop $R0
  204.  
  205. !macroend
  206.  
  207. ; Clear one or more bits in section's flags
  208.  
  209. !macro ClearSectionFlag SECTION BITS
  210.  
  211.   Push $R0
  212.   Push $R1
  213.     SectionGetFlags "${SECTION}" $R0
  214.     IntOp $R1 "${BITS}" ~
  215.     IntOp $R0 $R0 & $R1
  216.     SectionSetFlags "${SECTION}" $R0
  217.   Pop $R1
  218.   Pop $R0
  219.  
  220. !macroend
  221.  
  222. ; Check if one or more bits in section's flags are set
  223. ; If they are, jump to JUMPIFSET
  224. ; If not, jump to JUMPIFNOTSET
  225.  
  226. !macro SectionFlagIsSet SECTION BITS JUMPIFSET JUMPIFNOTSET
  227.     Push $R0
  228.     SectionGetFlags "${SECTION}" $R0
  229.     IntOp $R0 $R0 & "${BITS}"
  230.     IntCmp $R0 "${BITS}" +3
  231.     Pop $R0
  232.     StrCmp "" "${JUMPIFNOTSET}" +3 "${JUMPIFNOTSET}"
  233.     Pop $R0
  234.     Goto "${JUMPIFSET}"
  235. !macroend
  236.  
  237. ;--------------------------------
  238.  
  239. !endif