home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxdemo.zip / MACROS.$$$ / SETPROPS.VRM < prev    next >
Text File  |  1993-09-04  |  8KB  |  346 lines

  1. /* Custom mainline for macro */
  2.  
  3.     call RXFuncAdd "VRLoadFuncs", "VROBJ", "VRLoadFuncs"
  4.     call VRLoadFuncs
  5.  
  6.     _VREVersion = SubWord( VRVersion( "VRObj" ), 1, 1 )
  7.     if( _VREVersion < 1.01 )then do
  8.         call VRMessage "", "This program requires VX-REXX version 1.01 to run", "Error!"
  9.         _VREReturnValue = 32000
  10.         signal _VRELeaveMain
  11.     end
  12.  
  13.     signal on SYNTAX name _VRESyntax
  14.     signal _VREMain
  15.  
  16. _VRESyntax:
  17.     parse source . . _VRESourceSpec
  18.     call VRMessage "", "Syntax error in" _VRESourceSpec "line" SIGL, "Error!"
  19.     _VREReturnValue = 32000
  20.     signal _VRELeaveMain
  21.  
  22. _VREMain:
  23. /*:VRX         Main
  24. */
  25. /*  Main
  26. */
  27. Main:
  28. /*  Process the arguments.
  29.     Get the parent window.
  30. */
  31.     parse source . calledAs .
  32.     parent = ""
  33.     argCount = arg()
  34.     argOff = 0
  35.     if( calledAs \= "COMMAND" )then do
  36.         if argCount >= 1 then do
  37.             parent = arg(1)
  38.             argCount = argCount - 1
  39.             argOff = 1
  40.         end
  41.     end
  42.     InitArgs.0 = argCount
  43.     if( argCount > 0 )then do i = 1 to argCount
  44.         InitArgs.i = arg( i + argOff )
  45.     end
  46.     drop calledAs argCount argOff
  47.  
  48. /*  Load the windows
  49. */
  50.     call VRInit
  51.     parse source . . spec
  52.     _VREPrimaryWindowPath = ,
  53.         VRParseFileName( spec, "dpn" ) || ".VRW"
  54.     _VREPrimaryWindow = ,
  55.         VRLoad( parent, _VREPrimaryWindowPath )
  56.     drop parent spec
  57.     if( _VREPrimaryWindow == "" )then do
  58.         call VRMessage "", "Cannot load window:" VRError(), ,
  59.             "Error!"
  60.         _VREReturnValue = 32000
  61.         signal _VRELeaveMain
  62.     end
  63.  
  64. /*  Process events
  65. */
  66.     call Init
  67.     signal on halt
  68.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  69.         _VREEvent = VREvent()
  70.         interpret _VREEvent
  71.     end
  72. _VREHalt:
  73.     _VREReturnValue = Fini()
  74.     call VRDestroy _VREPrimaryWindow
  75. _VRELeaveMain:
  76.     call VRFini
  77. exit _VREReturnValue
  78.  
  79. VRLoadSecondary: procedure
  80.     name = arg( 1 )
  81.  
  82.     window = VRLoad( VRWindow(), VRWindowPath(), name )
  83.     call VRMethod window, "CenterWindow"
  84.     call VRSet window, "Visible", 1
  85.     call VRMethod window, "Activate"
  86. return window
  87.  
  88. /*:VRX         DisplayValue
  89. */
  90.  
  91. DisplayValue: procedure
  92.     prop = VRGet( "LB_1", "SelectedString" )
  93.     objline = VRGet( "LB_2", "SelectedString" )
  94.     parse VAR objline . ';' obj
  95.     if obj \= "" & prop \= "" then do
  96.         value = VRGet( obj, prop )
  97.         length = Length( value )
  98.         call VRSet "EF_1", "Value", value,,
  99.                            "SelectedStart", 1,,
  100.                            "SelectedEnd", length+1
  101.         ok = VRMethod( "EF_1", "SetFocus" )
  102.     end
  103. return
  104.  
  105. /*:VRX         FillObjectList
  106. */
  107. FillObjectList: procedure expose selectedList.
  108.     do i = 1 to selectedList.0
  109.         name = VRGet( selectedList.i, "Name" )
  110.         nameList.i = Left( name, 25 ) || ';' || selectedList.i
  111.     end
  112.     nameList.0 = selectedList.0
  113.     call VRMethod "LB_2", "AddStringList", "nameList."
  114.     call VRSet "LB_2", "Selected", 1
  115. return
  116.  
  117. /*:VRX         FillPropList
  118. */
  119. FillPropList: 
  120.     procedure expose AllOneClass LastClass LastSelectedProperty
  121.  
  122. /*  Nothing to do if all same class
  123. */
  124.     if AllOneClass = 1 then return
  125.  
  126. /*  Nothing to do if same class as last selected
  127.     entry
  128. */
  129.     objline = VRGet( "LB_2", "SelectedString" )
  130.     parse VAR objline . ';' obj
  131.     class = VRGet( obj, "ClassName" )
  132.     if class = LastClass then return
  133.     LastClass = class
  134.  
  135. /*  Start with an empty list
  136. */
  137.     call VRMethod "LB_1", "Clear"
  138.  
  139. /*  Only want properties that can be saved
  140. */
  141.     call VRMethod obj, "ListProperties", "propList.", "Saveable" 
  142.     call VRMethod "LB_1", "AddStringList", "propList."
  143.  
  144. /*  Remove events
  145. */
  146.     call VRMethod obj, "ListProperties", "propList.", "Events" 
  147.     do i = 1 to propList.0
  148.         ok = VRMethod( "LB_1", "DeleteString", propList.i )
  149.     end
  150.  
  151. /*  Remove read-only (only use VRSet, no cloning).
  152. */
  153.     call VRMethod obj, "ListProperties", "propList.", "ReadOnly" 
  154.     do i = 1 to propList.0
  155.         ok = VRMethod( "LB_1", "DeleteString", propList.i )
  156.     end
  157.  
  158. /*  Set the selected to the same this as last time.
  159.     Leave LastSelectedProperty alone in case the user
  160.     selects another object right away (browse mode).    
  161. */
  162.     position = VRMethod( "LB_1", "FindString", LastSelectedProperty, 1, "Exact" )
  163.     if position > 0 then do
  164.         call VRSet "LB_1", "Selected", position    
  165.     end
  166.     
  167. return
  168.  
  169. /*:VRX         Fini
  170. */
  171. Fini:
  172.     window = VRWindow()
  173.     call VRSet window, "Visible", 0
  174.     drop window
  175. return 0
  176.  
  177. /*:VRX         Halt
  178. */
  179. Halt:
  180.     signal _VREHalt
  181. return
  182.  
  183. /*:VRX         Init
  184. */
  185.  
  186. Init: procedure expose InitArgs.,
  187.                        selectedList.,
  188.                        AllOneClass LastClass LastSelectedProperty
  189.  
  190. /*  Assume invoked as a VRXEDIT macro so
  191.         InitArgs.0 = 2
  192.         InitArgs.1 = <object>
  193.         InitArgs.2 = <editWindow>
  194. */
  195.     window = VRWindow()
  196.     call VRMethod window, "CenterWindow"
  197.  
  198. /*  Operate on the object under the pop-up, or on 
  199.     all selected items if the pop-up was on a selected  
  200.     item.
  201. */
  202.     target = InitArgs.1
  203.     call VRMethod InitArgs.2, "GetSelectedRoots", "selectedList."
  204.  
  205.     inList = 0
  206.     do i = 1 to selectedList.0      
  207.         if selectedList.i = target then do
  208.             inList = 1 
  209.             leave
  210.         end            
  211.     end
  212.     if inList = 0 then do   
  213.         selectedList.0 = 1
  214.         selectedList.1 = target
  215.     end
  216.  
  217.     call FillObjectList
  218.  
  219. /*  Fill the property list the first time
  220. */
  221.     AllOneClass = 0
  222.     LastClass = ''
  223.     LastSelectedProperty = ''
  224.     call FillPropList
  225.  
  226. /*  Enable the Set all button only if all objects
  227.     are the same class.
  228. */
  229.     AllOneClass = 1
  230.     className = VRGet( selectedList.1, "ClassName" )
  231.     do i = 2 to selectedList.0
  232.         if VRGet( selectedList.i, "ClassName" ) \= className then do
  233.             AllOneClass = 0
  234.         end
  235.     end
  236.  
  237.     if selectedList.0 > 1 & AllOneClass = 1 then do
  238.         ok = VRSet( "PB_3", "Enabled", 1 )
  239.     end
  240.  
  241.     call VRSet window, "Visible", 1
  242.     call VRMethod window, "Activate"
  243.  
  244.     return
  245.  
  246. /*:VRX         LB_1_Click
  247. */
  248. LB_1_Click:
  249.     LastSelectedProperty = VRGet( "LB_1", "SelectedString" )
  250.     call DisplayValue
  251. return
  252.  
  253. /*:VRX         LB_2_Click
  254. */
  255. LB_2_Click:
  256.     call FillPropList
  257.     call DisplayValue
  258. return
  259.  
  260. /*:VRX         PB_1_Click
  261. */
  262. PB_1_Click:
  263.     prop = VRGet( "LB_1", "SelectedString" )
  264.     objline = VRGet( "LB_2", "SelectedString" )
  265.     parse VAR objline . ';' obj
  266.     if obj \= "" & prop \= "" then do
  267.         value = VRGet( "EF_1", "Value" )
  268.         ok = VRSet(  obj, prop, value )
  269.         if ok \= 1 then do
  270.             call VRMessage VRWindow(), 'Unable to set' prop 'to "' || value || '"', "Error"
  271.         end
  272.         else do
  273.             selected = VRGet( "LB_2", "Selected" )
  274.             if selected < selectedList.0 then do
  275.                 selected = selected+1
  276.             end
  277.             else do
  278.                 selected = 1
  279.             end
  280.             ok = VRSet( "LB_2", "Selected", selected )
  281.         end                
  282.     end
  283. return
  284.  
  285. /*:VRX         PB_2_Click
  286. */
  287. PB_2_Click:
  288.     value = VRGet( "EF_1", "Value" )
  289.     call VRLoadSecondary "SW_1"
  290.     call VRSet "MLE_1", "Value", value
  291. return
  292.  
  293. /*:VRX         PB_3_Click
  294. */
  295. PB_3_Click:
  296.     prop = VRGet( "LB_1", "SelectedString" )
  297.     if prop \= "" then do
  298.         value = VRGet( "EF_1", "Value" )
  299.         do i = 1 to selectedList.0
  300.             ok = VRSet(  selectedList.i, prop, value )
  301.             if ok \= 1 then do
  302.                 call VRMessage VRWindow(), 'Unable to set' prop 'to "' || value || '"', "Error"
  303.                 leave
  304.             end
  305.         end
  306.     end
  307. return
  308.  
  309.  
  310. /*:VRX         PB_4_Click
  311. */
  312. PB_4_Click:
  313.     value = VRGet( "MLE_1", "Value" )
  314.     call VRSet "EF_1", "Value", value
  315.         
  316.     call VRDestroy "SW_1"
  317. return
  318.  
  319. /*:VRX         PB_5_Click
  320. */
  321. PB_5_Click:
  322.     call VRDestroy "SW_1"
  323. return
  324.  
  325. /*:VRX         Quit
  326. */
  327. Quit:
  328.     window = VRWindow()
  329.     call VRSet window, "Shutdown", 1
  330.     drop window
  331. return
  332.  
  333. /*:VRX         SW_1_Close
  334. */
  335. SW_1_Close:
  336.     window = VRInfo( "Object" )
  337.     call VRDestroy window
  338.     drop window
  339. return
  340. /*:VRX         Window1_Close
  341. */
  342. Window1_Close:
  343.     call Quit
  344. return
  345.  
  346.