home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxcliser.zip / VXREXX.3 / SAMPLES / PRINTING / WINDOW1.VRX < prev    next >
Text File  |  1994-12-23  |  5KB  |  218 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         EnableButtons
  67. */
  68. EnableButtons:
  69.     /* Only enable the buttons if there is an available printer.
  70.     */
  71.     filename = VRGet( "Filename", "Value" )
  72.     selected = VRGet( "Printers", "Selected" )
  73.     enabled = ( filename \= "" ) & ( selected \= 0 )
  74.     call VRSet "PB_Print", "Enabled", enabled
  75. return
  76.  
  77. /*:VRX         Filename_Change
  78. */
  79. Filename_Change:
  80.     call EnableButtons
  81. return
  82.  
  83. /*:VRX         Fini
  84. */
  85. Fini:
  86.     /* Destroy the window
  87.     */
  88.  
  89.     window = VRWindow()
  90.     call VRSet window, "Visible", 0
  91.     drop window
  92. return 0
  93.  
  94. /*:VRX         Halt
  95. */
  96. Halt:
  97.     signal _VREHalt
  98. return
  99.  
  100. /*:VRX         Init
  101. */
  102. Init:
  103.     /*  Build the list of printers
  104.     */
  105.     call VRMethod "Application", "ListPrinters", "printer."
  106.     do i = 1 to printer.0
  107.         parse var printer.i queue ";" printer ";" driver
  108.         call VRMethod "Printers", "AddString", queue,,printer
  109.     end
  110.     
  111.     /*  Select the first printer
  112.     */
  113.     call VRSet "Printers", "Selected", 1
  114.  
  115.     /* Create the window
  116.     */   
  117.     window = VRWindow()
  118.     call VRMethod window, "CenterWindow"
  119.     call VRSet window, "Visible", 1
  120.     call VRMethod window, "Activate"
  121.     drop window
  122. return
  123.  
  124. /*:VRX         PB_Cancel_Click
  125. */
  126. PB_Cancel_Click:
  127.     call Quit
  128. return
  129.  
  130. /*:VRX         PB_CancelPrint_Click
  131. */
  132. PB_CancelPrint_Click:   
  133.     call VRMethod "Application", "HaltThread", WorkerTID
  134.     call Progress_Close
  135.     call VRMessage "Window1", "Print job cancelled.", "Note", "Information"
  136. return
  137.  
  138. /*:VRX         PB_Find_Click
  139. */
  140. PB_Find_Click:
  141.     /* Find the file to print.
  142.     */
  143.  
  144.     fileName = VRFileDialog( VRWindow(), "File to print", "Open" )
  145.     if fileName \= "" then do
  146.         call VRSet "FileName", "Value", fileName
  147.     end
  148. return
  149.  
  150. /*:VRX         PB_Print_Click
  151. */
  152. PB_Print_Click:
  153.     /*  Get the printer name from the item data stored in the list
  154.     */
  155.     selection = VRGet( "Printers", "Selected" )
  156.     printer = VRMethod( "Printers", "GetItemData", selection )
  157.  
  158.     /*  Get the name of the file to print, then print it from
  159.         another thread.
  160.     */
  161.     filename = VRGet( "Filename", "Value" )
  162.     cancelled = 0
  163.     workerTID = VRMethod( "Application", "StartThread",,
  164.                   "Worker", printer, filename )
  165.  
  166.     /*  Disable the main window while the "progress" window is open
  167.     */
  168.     call VRSet "Window1", "Enabled", 0
  169.     call VRLoadSecondary "Progress"
  170. return
  171.  
  172. /*:VRX         PrintDone
  173. */
  174. PrintDone: procedure
  175.     parse arg ok
  176.  
  177.     call Progress_Close
  178.  
  179.     if ok = 1 then do 
  180.         call VRMessage "Window1", "File printed OK.",,
  181.                        "Note", "Information"
  182.     end
  183.     else do
  184.         call VRMessage "Window1", "Could not print the file.",,
  185.                        "Error", "Error"
  186.     end
  187. return
  188. /*:VRX         Printers_Click
  189. */
  190. Printers_Click:
  191.     call EnableButtons
  192. return
  193.  
  194. /*:VRX         Progress_Close
  195. */
  196. Progress_Close:
  197.     call VRDestroy "Progress"
  198.     call VRSet "Window1", "Enabled", 1
  199.     call VRMethod "Window1", "Activate"
  200. return
  201. /*:VRX         Quit
  202. */
  203. Quit:
  204.     /* Close the application
  205.     */
  206.  
  207.     window = VRWindow()
  208.     call VRSet window, "Shutdown", 1
  209.     drop window
  210. return
  211.  
  212. /*:VRX         Window1_Close
  213. */
  214. Window1_Close:
  215.     call Quit
  216. return
  217.  
  218.