home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxdemo.zip / CALC.$$$ / WINDOW1.VRX < prev    next >
Text File  |  1993-08-06  |  9KB  |  388 lines

  1. /*:VRX         Main
  2. */
  3. /*  Main
  4. */
  5. Main:
  6. /*  Process the arguments.
  7.     Get the parent window.
  8. */
  9.     parse source . calledAs .
  10.     parent = ""
  11.     argCount = arg()
  12.     argOff = 0
  13.     if( calledAs \= "COMMAND" )then do
  14.         if argCount >= 1 then do
  15.             parent = arg(1)
  16.             argCount = argCount - 1
  17.             argOff = 1
  18.         end
  19.     end
  20.     InitArgs.0 = argCount
  21.     if( argCount > 0 )then do i = 1 to argCount
  22.         InitArgs.i = arg( i + argOff )
  23.     end
  24.     drop calledAs argCount argOff
  25.  
  26. /*  Load the windows
  27. */
  28.     call VRInit
  29.     parse source . . spec
  30.     _VREPrimaryWindowPath = ,
  31.         VRParseFileName( spec, "dpn" ) || ".VRW"
  32.     _VREPrimaryWindow = ,
  33.         VRLoad( parent, _VREPrimaryWindowPath )
  34.     drop parent spec
  35.     if( _VREPrimaryWindow == "" )then do
  36.         call VRMessage "", "Cannot load window:" VRError(), ,
  37.             "Error!"
  38.         _VREReturnValue = 32000
  39.         signal _VRELeaveMain
  40.     end
  41.  
  42. /*  Process events
  43. */
  44.     call Init
  45.     signal on halt
  46.     do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) )
  47.         _VREEvent = VREvent()
  48.         interpret _VREEvent
  49.     end
  50. _VREHalt:
  51.     _VREReturnValue = Fini()
  52.     call VRDestroy _VREPrimaryWindow
  53. _VRELeaveMain:
  54.     call VRFini
  55. exit _VREReturnValue
  56.  
  57. VRLoadSecondary: procedure
  58.     name = arg( 1 )
  59.  
  60.     window = VRLoad( VRWindow(), VRWindowPath(), name )
  61.     call VRMethod window, "CenterWindow"
  62.     call VRSet window, "Visible", 1
  63.     call VRMethod window, "Activate"
  64. return window
  65.  
  66. /*:VRX         digit_Click
  67. */
  68. digit_Click:
  69.     number = VRGet( VRInfo( "Object" ), "Caption" )
  70.     call number_click number
  71. return
  72. /*:VRX         do_previous_operation
  73. */
  74. do_previous_operation:
  75.  
  76.     /* Check for an error state */
  77.     if( error_is_on = 1 ) then return
  78.  
  79.     /* Check if any numbers have been pressed */
  80.     if( new_number = 0 )then do
  81.         operand = arg( 1 )
  82.         return
  83.       end
  84.  
  85.     /* Get the current number on the screen */
  86.     display_current = VRGet( 'dt_display', 'Caption' )
  87.  
  88.     /* Do the previous operation with the previous number */
  89.     if( operand = '+' ) then
  90.         display = display_previous + display_current
  91.     else if( operand = '-' ) then
  92.         display = display_previous - display_current
  93.     else if( operand = '*' ) then
  94.         display = display_previous * display_current
  95.     else if( operand = '/' ) then do
  96.         if( display_current = 0 ) then do           /* Divide by zero error */
  97.             error_is_on = 1
  98.             call update_memory_display 'e'
  99.             display = 0
  100.           end
  101.         else
  102.             display = display_previous / display_current
  103.       end
  104.     else
  105.         display = display_current
  106.  
  107.     /* Update the operand */
  108.     operand = arg( 1 )
  109.     new_number = 0
  110.  
  111.     /* Update the display */
  112.     display_previous = display
  113.     start_new_display = 1
  114.     call update_display
  115.  
  116. return
  117. /*:VRX         Fini
  118. */
  119. Fini:
  120.     window = VRWindow()
  121.     call VRSet window, 'Visible', '0'
  122.     drop window
  123. return 0
  124. /*:VRX         Halt
  125. */
  126. Halt:
  127.     signal _VREHalt
  128. return
  129.  
  130. /*:VRX         Init
  131. */
  132. Init:
  133.     memory_total = 0
  134.     call pb_c_Click
  135.  
  136.     window = VRWindow()
  137.     call VRMethod window, 'CenterWindow'
  138.     call VRSet window, 'Visible', '1'
  139.     call VRMethod window, 'Activate'
  140.     drop window
  141.  
  142.     ValidKeys.1 = "1"
  143.     ValidKeys.2 = "2"
  144.     ValidKeys.3 = "3"
  145.     ValidKeys.4 = "4"
  146.     ValidKeys.5 = "5"
  147.     ValidKeys.6 = "6"
  148.     ValidKeys.7 = "7"
  149.     ValidKeys.8 = "8"
  150.     ValidKeys.9 = "9"
  151.     ValidKeys.10 = "0"
  152.     ValidKeys.11 = "."
  153.     ValidKeys.12 = "-"
  154.     ValidKeys.13 = "*"
  155.     ValidKeys.14 = "/"
  156.     ValidKeys.15 = "+"
  157.     ValidKeys.16 = "="
  158.     ValidKeys.17 = "%"
  159.     ValidKeys.18 = "{F5}"
  160.     ValidKeys.19 = "{F6}"
  161.     ValidKeys.20 = "{F7}"
  162.     ValidKeys.21 = "{F8}"
  163.     ValidKeys.22 = "c"
  164.     ValidKeys.23 = "C"
  165.     ValidKeys.24 = "e"
  166.     ValidKeys.25 = "E"
  167.     ValidKeys.0 = 25
  168.  
  169.     /* Find the "=" button */
  170.     obj = VRGet( "operator", "Self" )
  171.     do forever
  172.         if VRGet( obj, "Caption" ) = "=" then leave
  173.         obj = VRGet( obj, "Sibling" )
  174.     end
  175.     call VRMethod obj, "SetFocus"
  176.  
  177. return
  178.  
  179.  
  180. /*:VRX         Is_Valid_Key
  181. */
  182. Is_Valid_Key:
  183.  
  184. key = arg( 1 )
  185. do check = 1 to ValidKeys.0
  186.     if key = ValidKeys.Check then do
  187.         select
  188.             when check < 12 then return "number"
  189.             when check > 11 & check < 17 then return "operator"
  190.             when check > 16 then return "other"
  191.         end
  192.     end
  193. end
  194.  
  195. return 0
  196.  
  197. /*:VRX         Key_Handler
  198. */
  199. Key_Handler:
  200.  
  201. keyhit = arg( 1 )
  202. keytype = Is_Valid_Key( keyhit )
  203.  
  204. if (keytype = "operator" | keytype = "number") then do
  205.     if keytype = "number" then do
  206.         call number_click keyhit
  207.     end
  208.     else do
  209.         call do_previous_operation keyhit
  210.     end
  211. end
  212. else do
  213.     select
  214.         when keyhit = "%" then call pb_percent_click
  215.         when keyhit = "{F5}" then call pb_mplus_click
  216.         when keyhit = "{F6}" then call pb_mminus_click
  217.         when keyhit = "{F7}" then call pb_mr_click
  218.         when keyhit = "{F8}" then call pb_mc_click
  219.         when keyhit = "c" then call pb_c_click
  220.         when keyhit = "C" then call pb_c_click
  221.         when keyhit = "e" then call pb_ce_click
  222.         when keyhit = "E" then call pb_ce_click
  223.         otherwise
  224.     end
  225. end
  226.  
  227. return
  228.  
  229. /*:VRX         number_click
  230. */
  231. number_click:
  232.     /* Check for an error state */
  233.     if( error_is_on = 1 ) then
  234.         return
  235.  
  236.     num = arg( 1 )
  237.     new_number = 1
  238.  
  239.     if( start_new_display = 1 ) then do
  240.         start_new_display = 0
  241.         display = num
  242.  
  243.         if( num = '.' ) then  do    /* Check if the first character is a decimal */
  244.             display ='0.'
  245.             decimal_flag = 1
  246.           end
  247.         else
  248.             decimal_flag = 0
  249.  
  250.         if( num = '0' ) then        /* Check if the first character is a zero */
  251.             start_new_display = 1
  252.  
  253.         call update_display
  254.         return
  255.       end
  256.  
  257.     if( num = '.' ) then do
  258.         decimal_flag = 1
  259.         return
  260.       end
  261.  
  262.     if( decimal_flag = 1) then
  263.         display = display || num
  264.     else do
  265.         parse var display display'.'
  266.         display = display || num || '.'
  267.       end
  268.  
  269.     call update_display
  270. return
  271. /*:VRX         operator_Click
  272. */
  273. operator_Click:
  274.     handle = VRInfo( "Object" )
  275.     if handle \= "" then do
  276.         operator = VRGet( handle, "Caption" )
  277.         call do_previous_operation operator
  278.     end
  279. return
  280. /*:VRX         pb_c_Click
  281. */
  282. pb_c_Click:
  283.     display_previous = 0
  284.     display_current = 0
  285.     start_new_display = 1
  286.     operand = ''
  287.     display = 0
  288.     decimal_flag = 0
  289.     new_number = 1
  290.     error_is_on = 0
  291.     call update_display
  292.     call update_memory_display memory_total
  293. return
  294. /*:VRX         pb_ce_Click
  295. */
  296. pb_ce_Click:
  297.     if( error_is_on = 1 ) then return
  298.     display = 0
  299.     start_new_display = 1
  300.     call update_display
  301.     new_number = 1
  302. return
  303. /*:VRX         pb_mc_Click
  304. */
  305. pb_mc_Click:
  306.     if( error_is_on = 1 ) then return
  307.     memory_total = 0
  308.     call update_memory_display memory_total
  309. return
  310. /*:VRX         pb_mminus_Click
  311. */
  312. pb_mminus_Click:
  313.     if( error_is_on = 1 ) then return
  314.     memory_temp = VRGet( 'dt_display', 'Caption' )
  315.     memory_total = memory_total - memory_temp
  316.     call update_memory_display memory_total
  317.     start_new_display = 1
  318. return
  319. /*:VRX         pb_mplus_Click
  320. */
  321. pb_mplus_Click:
  322.     if( error_is_on = 1 ) then return
  323.     memory_temp = VRGet( 'dt_display', 'Caption' )
  324.     memory_total = memory_total + memory_temp
  325.     call update_memory_display memory_total
  326.     start_new_display = 1
  327. return
  328. /*:VRX         pb_mr_Click
  329. */
  330. pb_mr_Click:
  331.     if( error_is_on = 1 ) then return
  332.     display = memory_total
  333.     call update_display
  334.     start_new_display = 1
  335.     new_number = 1
  336. return
  337. /*:VRX         pb_percent_Click
  338. */
  339. pb_percent_Click:
  340.     display = display / 100
  341.     call update_display
  342. return
  343. /*:VRX         Quit
  344. */
  345. Quit:
  346.     window = VRWindow()
  347.     call VRSet window, 'Shutdown', '1'
  348.     drop window
  349. return
  350. /*:VRX         update_display
  351. */
  352. update_display:
  353.     /* Update the display area */
  354.     tmp = POS( 'E', display )
  355.     parse var display whole'.'fraction             /* Split into whole and fraction */
  356.  
  357.     if( new_number = 0 ) then
  358.         if( tmp = 0 ) then
  359.             fraction = strip( fraction, 'T', 0 )   /* Strip the trailing zeros from the fraction */
  360.  
  361.     display = whole || '.' || fraction             /* Concatenate the whole and fraction */
  362.     call VRSet 'dt_display', 'Caption', display
  363. return
  364. /*:VRX         update_memory_display
  365. */
  366. update_memory_display:
  367.     if( arg( 1 ) = 'e' ) then
  368.         call VRSet 'dt_memory', 'caption', 'E'
  369.     else if( arg( 1 ) = 0 ) then
  370.         call VRSet 'dt_memory', 'caption', ''
  371.     else
  372.         call VRSet 'dt_memory', 'caption', 'M'
  373. return
  374. /*:VRX         Window1_Close
  375. */
  376. Window1_Close:
  377.     call Quit
  378. return
  379. /*:VRX         Window1_KeyPress
  380. */
  381. Window1_KeyPress:
  382.  
  383. obj = VRInfo( "object" )
  384. call Key_Handler VRGet( obj, "KeyString" )
  385.  
  386. return
  387.  
  388.