home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff398.lzh / DClock / DClockMenu.rexx < prev    next >
OS/2 REXX Batch file  |  1990-11-01  |  13KB  |  450 lines

  1. /* DClockMenu.rexx by Stefan Sticht  PUBLIC DOMAIN
  2.  
  3.    DClockMenu is a short ARexx program which allows you to change
  4.    the options of DClock v1.20+ easily via requesters.
  5. */
  6.  
  7. VERSION = "v1.24"
  8.  
  9. SIGNAL ON HALT      /* tell arexx to signal us that the HI */
  10. SIGNAL ON BREAK_C   /* command has been used and trap also */
  11. SIGNAL ON BREAK_D   /* break signals */
  12. SIGNAL ON BREAK_E
  13. SIGNAL ON BREAK_F
  14.  
  15. OPTIONS FAILAT 20
  16. OPTIONS RESULTS     /* Allow DClock to send results */
  17. ADDRESS "DCLOCK"    /* DClock shall be our host     */
  18.  
  19. PARSE ARG argument  /* get command line arguments   */
  20. IF argument = "?" THEN EXIT(info())
  21.  
  22. /* we require the rexxsupport.library; is it available ? */
  23. IF ~SHOW(LIBRARIES,"rexxsupport.library") THEN DO
  24.     IF EXISTS("libs:rexxsupport.library") THEN DO
  25.         CALL ADDLIB("rexxsupport.library",0,-30)
  26.         END
  27.     ELSE DO
  28.         SAY "DClockMenu requires the rexxsupport.library!"
  29.         SAY "It can be found on your ARexx Disk. Please copy the"
  30.         SAY "library to your 'libs:' directory!"
  31.         EXIT
  32.         END
  33.     END
  34.  
  35. /* we require the rexxarplib.library; is it available ? */
  36. IF ~SHOW(LIBRARIES,"rexxarplib.library") THEN DO
  37.     IF EXISTS("libs:rexxarplib.library") THEN DO
  38.         CALL ADDLIB("rexxarplib.library",0,-30)
  39.         END
  40.     ELSE DO
  41.         SAY "DClockMenu requires the rexxarplib.library v2.3 or later!"
  42.         SAY "It can be found on your ARexx Disk. Please copy the"
  43.         SAY "library to your 'libs:' directory!"
  44.         EXIT
  45.         END
  46.     END
  47.  
  48. dclock.on = SHOW("PORTS","DCLOCK") /* is DClock already running ? */
  49. IF ~dclock.on THEN DO
  50.     CALL req("DClock has to be started first!")
  51.     EXIT
  52.     END
  53.  
  54. /*
  55.  * Get all current settings from DClock
  56.  */
  57.  
  58. STATUS
  59.  
  60. /* remove comment for debugging */
  61. SAY RESULT
  62.  
  63. PARSE VAR RESULT . dclock.beep . dclock.click . dclock.clickvolume,
  64.                  . dclock.priority . dclock.textcolor . dclock.backcolor,
  65.                  . dclock.alarm . dclock.alarmtime . dclock.setenv,
  66.                  . dclock.version . dclock.countdown . dclock.hour,
  67.                  . dclock.seconds . dclock.sound . dclock.page . dclock.speech,
  68.                  . dclock.line
  69.  
  70.  
  71. IF dclock.beep ~= "ON" & dclock.beep ~= "OFF" THEN DO
  72.     CALL req("Sorry, error in DClock's STATUS!")
  73.     EXIT
  74.     END
  75.  
  76. ADDRESS AREXX "'CALL CreateHost(DCHOST,DCPORT,)'" /* create     */
  77. DO FOR 50 WHILE ~SHOW("PORTS","DCHOST")           /* a new host */
  78.     CALL DELAY(10)                                /* for us     */
  79.     END
  80.  
  81. IF ~SHOW("PORTS","DCHOST") THEN DO     /* did the host really open ? */
  82.     CALL req("Can't create a new host!")              /* no, so quit */
  83.     EXIT
  84.     END
  85.  
  86. CALL SETREQCOLOR(DCHOST, BLOCKPEN, 1)      /* change color of window */
  87. CALL SETREQCOLOR(DCHOST, DETAILPEN, 0)
  88.  
  89. idcmp    = "CLOSEWINDOW GADGETUP MENUPICK"
  90. flags    = "ACTIVATE WINDOWDRAG WINDOWDEPTH WINDOWCLOSE"
  91. width    = 415
  92. height   = 150
  93. leftedge = (SCREENCOLS() - width) % 2
  94. topedge  = 20
  95.  
  96. ok = OPENWINDOW(DCHOST,leftedge,topedge,width,height,idcmp,flags,,
  97.                 "DClock Menu")
  98. IF ~ok THEN DO
  99.     CALL req("Can't open window!")
  100.     CALL QUIT(DCHOST)
  101.     EXIT
  102.     END
  103.  
  104. ok = OPENPORT(DCPORT)                       /* open the message port */
  105. IF ~ok THEN DO
  106.     CALL req("Can't open new message port!")
  107.     CALL QUIT(DCHOST)
  108.     EXIT
  109.     END
  110.  
  111.  
  112. /*
  113.  * Menus
  114.  */
  115.  
  116. CALL SETAPEN(DCHOST,2)                          /* change detail pen */
  117. CALL ADDMENU(DCHOST,"DClock Menu")              /* add a menu        */
  118. CALL ADDITEM(DCHOST,"Version","VERSION","V",,)  /* and two items     */
  119. CALL ADDITEM(DCHOST,"Quit","CLOSEWINDOW","Q",,)
  120.  
  121. /*
  122.  * Gadgets:
  123.  */
  124.  
  125. ontext  = " ON  "
  126. offtext = " OFF "
  127. fontB = 7        /* Baseline offset                         */
  128. x   = 20         /* LeftEdge of first gadget                */
  129. y   = 20         /* TopEdge of first gadget                 */
  130. dx  = 100        /* horizontal offset of second gadget row  */
  131. dy  = 18         /* vertical offset of next gadget          */
  132. gadhsize = 45    /* horizontal size of simple string gadget */
  133.  
  134. /*
  135.  * Switches:
  136.  */
  137.  
  138. gid.beep = 1
  139. CALL ADDGADGET(DCHOST, x, y, gid.beep, "  BEEP   ", "BEEP")
  140. CALL SETGADGET(DCHOST, gid.beep, dclock.beep)
  141. gid.click = gid.beep + 1
  142. CALL ADDGADGET(DCHOST, x + dx, y, gid.click, "  CLICK  ", "CLICK")
  143. CALL SETGADGET(DCHOST, gid.click, dclock.click)
  144. gid.alarm = gid.click + 1
  145. CALL ADDGADGET(DCHOST, x + dx + dx, y, gid.alarm, "  ALARM  ", "ALARM")
  146. CALL SETGADGET(DCHOST, gid.alarm, dclock.alarm)
  147. gid.setenv = gid.alarm + 1
  148. CALL ADDGADGET(DCHOST, x + dx + dx + dx, y, gid.setenv, " SETENV  ", "SETENV")
  149. CALL SETGADGET(DCHOST, gid.setenv, dclock.setenv)
  150. y = y + dy
  151. gid.hour = gid.setenv + 1
  152. CALL ADDGADGET(DCHOST, x, y, gid.hour, "  HOUR   ", "HOUR")
  153. CALL SETGADGET(DCHOST, gid.hour, dclock.hour)
  154. gid.seconds = gid.hour + 1
  155. CALL ADDGADGET(DCHOST, x + dx, y, gid.seconds, " SECONDS ", "SECONDS")
  156. CALL SETGADGET(DCHOST, gid.seconds, dclock.seconds)
  157.  
  158. /*
  159.  * Stringgadgets: these definitions are repeated below!
  160.  */
  161.  
  162. y1 = y + dy
  163.  
  164.  
  165. CALL MOVE(DCHOST, x, y1 + fontB)
  166. CALL TEXT(DCHOST,"ALARMTIME:")
  167. gid.alarmtime = gid.seconds + 1
  168. CALL ADDGADGET(DCHOST, x + dx, y1, gid.alarmtime, " " ||, 
  169.                dclock.alarmtime, "ALARMTIME %g", 80)
  170.  
  171. /* this isn't a string gadget! */
  172. CALL MOVE(DCHOST, x + dx + dx, y1 + fontB)
  173. CALL TEXT(DCHOST,"SOUNDFILE:")
  174. gid.sound = gid.alarmtime + 1
  175. CALL ADDGADGET(DCHOST, x + 3 * dx, y1, gid.sound, CENTER(dclock.sound, 5),,
  176.                "SOUND")
  177.  
  178. y2 = y1 + dy;
  179.  
  180. CALL MOVE(DCHOST, x, y2 + fontB)
  181. CALL TEXT(DCHOST,"COUNTDOWN:")
  182. gid.countdown = gid.sound + 1
  183. CALL ADDGADGET(DCHOST, x + dx, y2, gid.countdown, CENTER(dclock.countdown, 7),,
  184.                "COUNTDOWN %g", gadhsize)
  185.  
  186. CALL MOVE(DCHOST, x + dx + dx, y2 + fontB)
  187. CALL TEXT(DCHOST,"PRIORITY:")
  188. gid.priority = gid.countdown + 1
  189. CALL ADDGADGET(DCHOST, x + 3 * dx, y2, gid.priority, CENTER(dclock.priority, 7),,
  190.                "PRIORITY %g", gadhsize)
  191.  
  192. y3 = y2 + dy;
  193.  
  194. CALL MOVE(DCHOST, x, y3 + fontB)
  195. CALL TEXT(DCHOST,"TEXTCOLOUR:")
  196. gid.textcolour = gid.priority + 1
  197. CALL ADDGADGET(DCHOST, x + dx, y3, gid.textcolor, CENTER(dclock.textcolor, 7),,
  198.                "TEXTCOLOR %g", gadhsize)
  199.  
  200. CALL MOVE(DCHOST, x + dx + dx, y3 + fontB)
  201. CALL TEXT(DCHOST,"BACKCOLOUR:")
  202. gid.backcolour = gid.textcolour + 1
  203. CALL ADDGADGET(DCHOST, x + 3 * dx, y3, gid.backcolor,,
  204.                CENTER(dclock.backcolor, 7), "BACKCOLOR %g", gadhsize)
  205.  
  206. y4 = y3 + dy;
  207.  
  208. CALL MOVE(DCHOST, x, y4 + fontB)
  209. CALL TEXT(DCHOST,"CLICKVOLUME:")
  210. gid.clickvol = gid.backcolour + 1
  211. CALL ADDGADGET(DCHOST, x + dx, y4, gid.clickvol, CENTER(dclock.clickvolume, 7),,
  212.                "CLICKVOLUME %g", gadhsize)
  213.  
  214. /*
  215.  * Call the main-routine:
  216.  */
  217.  
  218. CALL lookport()
  219.  
  220. EXIT
  221.  
  222. /*
  223. * lookport: watch our message port for incoming messages
  224. */
  225. lookport:
  226.     quitflag = 0
  227.     DO FOREVER UNTIL quitflag
  228.         CALL WAITPKT(DCPORT)
  229.         pkt = GETPKT(DCPORT)
  230.         IF pkt ~= NULL() THEN DO
  231.             arg = GETARG(pkt)
  232.             CALL REPLY(pkt, 0)
  233.             SELECT
  234.                 WHEN arg = "CLOSEWINDOW" THEN quitflag = 1
  235.                 WHEN arg = "VERSION"    THEN CALL version()
  236.                 WHEN LEFT(arg,9) = "CLICKVOLU" THEN CALL clickvol(arg)
  237.                 WHEN LEFT(arg,9) = "ALARMTIME" THEN CALL alarmtime(arg)
  238.                 WHEN LEFT(arg,9) = "COUNTDOWN" THEN CALL countdown(arg)
  239.                 WHEN LEFT(arg,8) = "PRIORITY"  THEN CALL priority(arg)
  240.                 WHEN LEFT(arg,9) = "TEXTCOLOR" THEN CALL textcolor(arg)
  241.                 WHEN LEFT(arg,9) = "BACKCOLOR" THEN CALL backcolor(arg)
  242.                 WHEN arg = "SOUND"             THEN CALL soundfile
  243.                 WHEN arg = "REMOVE"            THEN NOP
  244.                 WHEN arg = "REFRESH"           THEN NOP
  245.                 OTHERWISE CALL switch(arg)
  246.                 END
  247.             END
  248.         END
  249.     CALL quitcleanup("ok")
  250.     RETURN(0)
  251.  
  252. /*
  253. * quitcleanup: close all opened resources and exit
  254. */
  255. quitcleanup:
  256.     PARSE ARG msg
  257.     CALL CLOSEPORT(DCPORT)
  258.     CALL QUIT(DCHOST)
  259.     IF msg ~= "ok" THEN SAY msg
  260.     EXIT
  261.  
  262.  
  263. /*
  264.  * switch: change the status of a option
  265.  */
  266. switch: PROCEDURE EXPOSE dclock. gid.
  267.     ARG option
  268.  
  269.     IF dclock.option = "ON" THEN dclock.option = "OFF"
  270.     ELSE dclock.option = "ON"
  271.  
  272.     INTERPRET option dclock.option
  273.     CALL SETGADGET(DCHOST, gid.option, dclock.option)
  274.  
  275.     RETURN(0)
  276.  
  277. /*
  278.  * version: display current DClock Version number
  279.  */
  280. version: PROCEDURE
  281.     STATUS VERSION
  282.     text = "DClock V1." || RESULT "is installed."
  283.     CALL req(text)
  284.     RETURN(0)
  285.  
  286. /*
  287. * alarmtime: a new time has been entered, check it
  288. */
  289. alarmtime: PROCEDURE
  290.     PARSE ARG time
  291.     time = SUBWORD(time,2,1)
  292.     IF LENGTH(time) = 8 THEN DO
  293.         ALARMTIME time
  294.         IF RC > 0 THEN DO
  295.             CALL req("Can't change alarmtime!\Perhaps invalid format?")
  296.             END
  297.         END
  298.     ELSE CALL req("Alarm time format has to be in the format HH:MM:SS!")
  299.     RETURN(0)
  300.  
  301. /*
  302. * countdown: a new time has been entered, check it
  303. */
  304. countdown: PROCEDURE EXPOSE dclock.
  305.     PARSE ARG count
  306.     count = SUBWORD(count, 2, 1)
  307.     IF DATATYPE(count, "NUMERIC") THEN DO
  308.         COUNTDOWN count
  309.         dclock.countdown = count
  310.         END
  311.     ELSE CALL req("Countdown has to be a numeric value!")
  312.     RETURN(0)
  313.  
  314. /*
  315. * priority: a new priority has been entered
  316. */
  317. priority: PROCEDURE EXPOSE dclock.
  318.     PARSE ARG pri
  319.     pri = SUBWORD(pri, 2, 1)
  320.     IF DATATYPE(pri, "NUMERIC") THEN DO
  321.         IF (pri >= -127 & pri <= 127) THEN DO
  322.             PRIORITY pri
  323.             dclock.priority = pri
  324.             END
  325.         ELSE DO
  326.             CALL req("Illegal value for handler task priority\" ||,
  327.                      "(must be between -127 and 127)!")
  328.             END
  329.         END
  330.     ELSE CALL req("Priority must be numeric!")
  331.     RETURN(0)
  332.  
  333. /*
  334. * textcolor: textcolour has been changed
  335. */
  336. textcolor: PROCEDURE EXPOSE dclock.
  337.     PARSE ARG col
  338.     col = SUBWORD(col, 2, 1)
  339.     IF DATATYPE(col, "NUMERIC") THEN DO
  340.         TEXTCOLOUR col
  341.         dclock.textcolor = col
  342.         END
  343.     ELSE CALL req("TEXTCOLOR must be numeric!")
  344.     RETURN(0)
  345.  
  346. /*
  347. * backcolor: backcolour has been changed
  348. */
  349. backcolor: PROCEDURE EXPOSE x dx y3 gadhsize
  350.     PARSE ARG col
  351.     col = SUBWORD(col, 2, 1)
  352.     IF DATATYPE(col, "NUMERIC") THEN DO
  353.         BACKCOLOUR col
  354.         IF RC > 0 THEN req("Can't change background colour!")
  355.         END
  356.     ELSE CALL req("BACKCOLOR must be numeric!")
  357.  
  358.     RETURN(0)
  359.  
  360. /*
  361. * clickvol: the clickvolume has been changed
  362. */
  363. clickvol: PROCEDURE EXPOSE x dx y4 gadhsize gid.
  364.     PARSE ARG vol
  365.     error = 0
  366.     vol = SUBWORD(vol, 2, 1)
  367.     IF DATATYPE(vol, "NUMERIC") THEN DO
  368.         IF vol <0 | vol > 64 THEN DO
  369.             CALL req("Illegal value for click volume\" ||,
  370.                      "(must be between 0 and 64)!")
  371.             error = 1
  372.             END
  373.         ELSE DO
  374.             CLICKVOLUME vol
  375.             IF RC > 0 THEN DO
  376.                 req("Can't change clickvolume")
  377.                 error = 1
  378.                 END
  379.             END
  380.         END
  381.     ELSE DO 
  382.         CALL req("CLICKVOLUME must be numeric!")
  383.         error = 1
  384.         END
  385.  
  386.     IF error THEN DO
  387.         CALL REMOVEGADGET(DCHOST, gid.clickvol)
  388.         STATUS CLICKVOLUME
  389.         CALL ADDGADGET(DCHOST, x + dx, y4, gid.clickvol, " " RESULT,,
  390.                    "CLICKVOLUME %g", gadhsize)
  391.         END
  392.  
  393.     RETURN(0)
  394.  
  395. /*
  396.  * soundfile:
  397.  */
  398. soundfile: PROCEDURE EXPOSE dclock.sound x dx y1 gid.
  399.  
  400.     STATUS SOUND
  401.     dclock.sound = RESULT
  402.  
  403.     IF dclock.sound ~= "OFF" THEN SOUND OFF
  404.     ELSE DO
  405.         file = GETFILE(0, 12, , , "Select sound file:")
  406.         IF file ~= "" THEN DO
  407.             IF ~EXISTS(file) THEN req("Can't find that file!")
  408.             ELSE DO
  409.                 SOUND file
  410.                 IF RC > 0 THEN req("Can't load that file!")
  411.                 END
  412.             END
  413.         END
  414.  
  415.     STATUS SOUND
  416.     dclock.sound = RESULT
  417.     CALL REMOVEGADGET(DCHOST, gid.sound)
  418.     CALL ADDGADGET(DCHOST, x + 3 * dx, y1, gid.sound,,
  419.                    CENTER(dclock.sound, 5), "SOUND")
  420.  
  421.     RETURN(0)
  422.  
  423. /*
  424.  * info: display some information about DClockMenu
  425.  */
  426. info: PROCEDURE EXPOSE version
  427.     SAY "DClockMenu " version "by Stefan Sticht"
  428.     SAY "Usage: DClockMenu"
  429.     SAY
  430.     SAY SOURCELINE(3)
  431.     SAY SOURCELINE(4)
  432.     SAY
  433.     RETURN(0)
  434.  
  435. /*
  436. * req: call the requester of the rexxarplib.library with msg
  437. */
  438. req: PROCEDURE
  439.     PARSE ARG msg
  440.     CALL REQUEST(0,12,msg,,," OK ",)
  441.     RETURN(0)
  442.  
  443. BREAK_C:  /* somebody wants to kill us, but before we leave */
  444. BREAK_D:  /* we have to clean up                            */
  445. BREAK_E:
  446. BREAK_F:
  447. HALT:  
  448.     CALL quitcleanup("***user break")
  449.     EXIT
  450.