home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / gui / mui / developer / c / examples / mui-exchange.c < prev    next >
C/C++ Source or Header  |  1994-08-08  |  22KB  |  870 lines

  1.  
  2.   /**********************************************\
  3.   *                                              *
  4.   *  MUI-Exchange                                *
  5.   *                                              *
  6.   *  Version: 0.9 (14.6.94)                      *
  7.   *                                              *
  8.   *  Copyright 1993,94 by kMel, Klaus Melchior   *
  9.   *  kmel@eifel.adsp.sub.org, kmel@eifel.fido.de *
  10.   *                                              *
  11.   *                                              *
  12.   *  This isn't a proper replacement             *
  13.   *  for the "Exchange" from Commodore,          *
  14.   *  because it can't use the CX-Command         *
  15.   *  'CXCMD_LIST_CHG'.                           *
  16.   *                                              *
  17.   *  All these broker functions are private      *
  18.   *  and rarely documented.                      *
  19.   *                                              *
  20.   \**********************************************/
  21.  
  22.  
  23. /* DMAKE */
  24.  
  25. /* TAB=4 */
  26.  
  27. /*
  28.  
  29. MUI-Exchange - ReadMe
  30. *********************
  31.  
  32. Copyright
  33. *********
  34.  
  35.    MUI-Exchange (C) 1993-94 kMel, Klaus Melchior
  36.  
  37.    This program is freely distributable, but copyrighted by me. This
  38. means you may freely copy it as long as you do not charge more than a
  39. nominal fee for copying. This program may be put on PD disks,
  40. especially on Fred Fish's AmigaLibDisks and Fred's CDROMs. If you want
  41. to distribute this program you MUST keep this document with it. The
  42. program and the documents must be distributed in their original
  43. unmodified form.
  44.  
  45.    This program cannot be used for commercial purposes without written
  46. permission by the author. The author can not be made responsible for
  47. any damage which is caused by using this program.
  48.  
  49.    Send comments, suggestions or bug reports to:
  50.  
  51.      Klaus Melchior, Schulstrasse 17
  52.      D-52156 Monschau, Germany
  53.      Phone: +49 (0)2472 4710
  54.      
  55.      ADSP: kmel@eifel.adsp.sub.org
  56.      DE:   kmel@eifel.fido.de
  57.      FIDO: 2:242/7.2@fidonet
  58.      FIDO: 2:2452/107.2@fidonet
  59.  
  60.  
  61. ReadMe
  62. ******
  63.  
  64. 'MUI-Exchange' should be a replacement for the commodity 'Exchange' by
  65. Commodore, it manages the commodities in your system.
  66.  
  67. But first you are ougth to change some adjustments.
  68.  
  69. Start the MUI preference program, switch to the application
  70. 'MUI-Exchange', look at the "System" page:
  71.  
  72. - set Hotkey to "lalt ctrl help"
  73. - switch off the "Iconify Icon" checkmark gadget
  74. - switch on the "Start Iconified" checkmark
  75.  
  76. Now you can start MUI-Exchange in your 'wbstartup'.
  77.  
  78.  
  79. History
  80. *******
  81.  
  82.  0.8  13.8.93  * first release in MUI 1.0
  83.  
  84.                + window's close gadget is now a iconified gadget
  85.                + new menu item "Hide"
  86.                + use new menu objects
  87.  0.9  14.6.94  * release for MUI 2.1
  88.  
  89. */
  90.  
  91.  
  92. /*** includes ***/
  93.  
  94. #include "demo.h"
  95.  
  96. #include <exec/memory.h>
  97. #include <proto/commodities.h>
  98.  
  99.  
  100.  
  101.  
  102. /*** private structures & defines ***/
  103.  
  104. struct BrokerCopy    {
  105.     struct Node    bc_Node;
  106.     char        bc_Name[CBD_NAMELEN];
  107.     char        bc_Title[CBD_TITLELEN];
  108.     char        bc_Descr[CBD_DESCRLEN];
  109.     LONG        bc_Task;
  110.     LONG        bc_Dummy1;
  111.     LONG        bc_Dummy2;
  112.     UWORD        bc_Flags;
  113. };
  114.  
  115. #define COF_ACTIVE 2
  116.  
  117.  
  118.  
  119.  
  120. /*** private functions of "commodities.library" ***/
  121.  
  122. #pragma libcall CxBase FindBroker 6c 801
  123. #pragma libcall CxBase CopyBrokerList ba 801
  124. #pragma libcall CxBase FreeBrokerList c0 801
  125. #pragma libcall CxBase BrokerCommand c6 802
  126.  
  127. CxObj *FindBroker(char *);
  128. LONG CopyBrokerList(struct List *);
  129. LONG FreeBrokerList(struct List *);
  130. LONG BrokerCommand(char *, LONG id);
  131.  
  132.  
  133.  
  134. /*** ids ***/
  135.  
  136. enum ids { DUMMY,
  137.     MN_PROJECT,
  138.         ID_ABOUT,
  139.         ID_HIDE, ID_QUIT,
  140.     MN_BROKER,
  141.         ID_INFO,
  142.         ID_ACTIVATE, ID_DEACTIVATE, ID_REMOVE,
  143.         MN_INTERFACE,
  144.             ID_INTERFACE_SHOW, ID_INTERFACE_HIDE,
  145.  
  146.     ID_LV_ACTIVE,
  147. };
  148.  
  149.  
  150.  
  151.  
  152. /*** variables ***/
  153.  
  154. static APTR app;
  155. static APTR mn_main, mn_activate, mn_deactivate, mn_interface;
  156. static APTR wi_main;
  157. static APTR bt_info;
  158. static APTR lv_broker;
  159. static APTR bt_activate, bt_deactivate, bt_remove;
  160. static APTR bt_show, bt_hide;
  161.  
  162. struct Library *CxBase;
  163.  
  164.  
  165.  
  166.  
  167. /*** funcs ***/
  168.  
  169. /*** find name in broker list ***/
  170.  
  171. LONG find_broker_name(char *n)
  172. {
  173.     struct BrokerCopy *bc;
  174.     LONG i;
  175.  
  176.     for (i=0; ; i++)
  177.     {
  178.         DoMethod(lv_broker, MUIM_List_GetEntry, i, &bc);
  179.  
  180.         /*** last line ? ***/
  181.         if (!bc)
  182.             break;
  183.  
  184.         /*** found name ? ***/
  185.         if (stricmp(&bc->bc_Name[0], n) == 0)
  186.             return(i);
  187.     }
  188.  
  189.     return(-1);
  190. }
  191.  
  192.  
  193.  
  194.  
  195. /*** find task in broker list ***/
  196.  
  197. LONG find_broker_task(ULONG t)
  198. {
  199.     struct BrokerCopy *bc;
  200.     LONG i;
  201.  
  202.     for (i=0; ; i++)
  203.     {
  204.         DoMethod(lv_broker, MUIM_List_GetEntry, i, &bc);
  205.  
  206.         /*** last line ? ***/
  207.         if (!bc)
  208.             break;
  209.  
  210.         /*** found task ? ***/
  211.         if (bc->bc_Task == t)
  212.             return(i);
  213.     }
  214.  
  215.     return(-1);
  216. }
  217.  
  218.  
  219.  
  220.  
  221. /*** disable gadgets ***/
  222.  
  223. void check_broker(void)
  224. {
  225.     struct BrokerCopy *bc;
  226.  
  227.     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  228.  
  229.     set(bt_show, MUIA_Disabled, !(bc->bc_Flags & COF_SHOW_HIDE));
  230.     set(bt_hide, MUIA_Disabled, !(bc->bc_Flags & COF_SHOW_HIDE));
  231.  
  232.     set(bt_activate, MUIA_Disabled, bc->bc_Flags & COF_ACTIVE);
  233.     set(bt_deactivate, MUIA_Disabled, !(bc->bc_Flags & COF_ACTIVE));
  234. }
  235.  
  236.  
  237.  
  238.  
  239. /*** insert broker into listview ***/
  240.  
  241. BOOL insert_broker(void)
  242. {
  243.     static UBYTE count;
  244.  
  245.     struct List *l;
  246.     ULONG nr, i;
  247.     struct BrokerCopy *bc;
  248.  
  249.     if (l = AllocMem(sizeof(struct List), MEMF_PUBLIC))
  250.     {
  251.         struct Node *n, *nn;
  252.         LONG pos, curs;
  253.  
  254.         count++;
  255.  
  256.         /*** generate an empty list ***/
  257.         NewList(l);
  258.  
  259.         /*** private function to generate the system broker list ***/
  260.         nr = CopyBrokerList(l);
  261.  
  262.         get(lv_broker, MUIA_List_Active, &curs);
  263.  
  264.         /*** start at head of list ***/
  265.         n = l->lh_Head;
  266.         while (n && (nn = n->ln_Succ))
  267.         {
  268.             if ((pos = find_broker_name((char *)&((struct BrokerCopy *)n)->bc_Name[0])) >= 0)
  269.             {
  270.                 DoMethod(lv_broker, MUIM_List_GetEntry, pos, &bc);
  271.                 bc->bc_Flags = ((struct BrokerCopy *)n)->bc_Flags;
  272.                 bc->bc_Node.ln_Type = count;
  273.  
  274.                 if (curs == pos)
  275.                     check_broker();
  276.             }
  277.             else
  278.             {
  279.                 /*** insert broker ***/
  280.                 ((struct BrokerCopy *)n)->bc_Node.ln_Type = count;
  281.                 DoMethod(lv_broker, MUIM_List_Insert, &n, 1, MUIV_List_Insert_Sorted);
  282.             }
  283.  
  284.             /*** next node ***/
  285.             n = nn;
  286.         }
  287.  
  288.         /*** free list and allocated mem ***/
  289.         FreeBrokerList(l);
  290.         FreeMem(l, sizeof(struct List));
  291.  
  292.         for (i=0; ; i++)
  293.         {
  294.             DoMethod(lv_broker, MUIM_List_GetEntry, i, &bc);
  295.  
  296.             /*** last line ? ***/
  297.             if (!bc)
  298.                 break;
  299.  
  300.             /*** found old broker ? ***/
  301.             if (bc->bc_Node.ln_Type != count)
  302.                 DoMethod(lv_broker, MUIM_List_Remove, i--);
  303.         }
  304.     }
  305.  
  306.     return(TRUE);
  307. }
  308.  
  309.  
  310.  
  311.  
  312. /*** image-stuff ***/
  313.  
  314. /*
  315. DiskObject 'MUI-Exchange_sleep.info': $076bf6b4
  316. Size of DiskObjectStruct: 78  ImageStruct: 20
  317. GadgetRender: $07692038  Size: 560   Width: 54  Height: 35  Depth: 2
  318. */
  319.  
  320.  
  321. static UWORD mui_exchange_sleep_img1_data[] = {
  322.     0x0003,0x8000,0x0000,0x0000,0x0004,0x4000,0x0000,0x0000,
  323.     0x0008,0x4000,0x0000,0x0000,0x0018,0x4de0,0x0000,0x0000,
  324.     0x0020,0x3210,0x0000,0x0000,0x0020,0x0008,0x0000,0x0000,
  325.     0x0020,0x0008,0x0000,0x0000,0x0020,0xf008,0x0000,0x0000,
  326.     0x0020,0x2788,0x0000,0x0000,0x0010,0x4108,0x0000,0x0000,
  327.     0x0010,0xf208,0x0000,0x0000,0x0008,0x0790,0x0000,0x0000,
  328.     0x0008,0x0020,0x0000,0x0000,0x003c,0x00c0,0x0000,0x0400,
  329.     0x0046,0x3f00,0x0000,0x0c00,0x0083,0xe008,0x0000,0x0c00,
  330.     0x0100,0x8038,0x0000,0x0c00,0x0101,0x00fc,0x0000,0x0c00,
  331.     0x0386,0x03fc,0x0000,0x0c00,0x04c8,0x0ff0,0x0000,0x0c00,
  332.     0x08b0,0x3ffc,0xc180,0x2c00,0x0500,0xffc0,0x6300,0x4c00,
  333.     0x0203,0xfd80,0x363c,0x8c00,0x000f,0xf180,0x1c41,0x0c00,
  334.     0x003f,0xc180,0x1c42,0x0c00,0x00ff,0x0180,0x3640,0x0c00,
  335.     0x03fc,0x00c0,0x6340,0x0c00,0x03f0,0x003c,0xc180,0x0c00,
  336.     0x01c0,0x0000,0x0080,0x0c00,0x0102,0x0000,0x0100,0x0c00,
  337.     0x0001,0x0000,0x0600,0x0c00,0x0000,0x9fff,0xf800,0x0c00,
  338.     0x0000,0x6000,0x0000,0x0c00,0x0000,0x2000,0x0000,0x0c00,
  339.     0x7fff,0xffff,0xffff,0xfc00,0x0003,0x8000,0x0000,0x0000,
  340.     0x0007,0xc000,0x0000,0x0000,0x000f,0xc000,0x0000,0x0000,
  341.     0x001f,0xcde0,0x0000,0x0000,0x003f,0xfff0,0x0000,0x0000,
  342.     0x003f,0xfff8,0x0000,0x0000,0x003f,0xfff8,0x0000,0x0000,
  343.     0x003f,0x0ff8,0x0000,0x0000,0x003f,0xd878,0x0000,0x0000,
  344.     0x001f,0xbef8,0x0000,0x0000,0x001f,0x0df8,0x0000,0x0000,
  345.     0x000f,0xf870,0x0000,0x0000,0x000f,0xffe0,0x0000,0x0000,
  346.     0xffff,0xffff,0xffff,0xf800,0xd57f,0xff51,0x5552,0x5000,
  347.     0xd5ff,0xf55f,0x8003,0x5000,0xd5ff,0xd527,0xbfff,0x9000,
  348.     0xd5ff,0x5482,0x7fff,0xd000,0xd7ff,0x5205,0xffff,0xe000,
  349.     0xd7fd,0x4813,0xffff,0xf000,0xdff5,0x2043,0x3e7f,0xd000,
  350.     0xd754,0x813f,0x9cff,0x9000,0xd752,0x047f,0xc9c3,0x5000,
  351.     0xd548,0x107e,0x2392,0x5000,0xd520,0x607e,0x2391,0x5000,
  352.     0xd481,0x3e7f,0xc995,0x5000,0xd204,0xff3f,0x9c95,0x5000,
  353.     0xc413,0xffc3,0x3e55,0x5000,0xde47,0xffff,0xff55,0x5000,
  354.     0xbf11,0xffff,0xfe55,0x5000,0xd854,0xffff,0xf955,0x5000,
  355.     0xc555,0x6000,0x0555,0x5000,0xd555,0x1555,0x5555,0x5000,
  356.     0xd555,0x5555,0x5555,0x5000,0x8000,0x0000,0x0000,0x0000,
  357.  
  358. };
  359.  
  360. static struct Image mui_exchange_sleep_img1 = {
  361.     0x0000,0x0000,0x0036,0x0023,0x0002,
  362.     &mui_exchange_sleep_img1_data[0],
  363.     0x03,0x00,0x00000000,
  364. };
  365.  
  366. static struct DiskObject mui_exchange_sleep_dobj = {
  367.     0xe310,0x0001,
  368.     0x00000000,
  369.     0x00db,0x0050,0x0036,0x0024,0x0004,0x0003,0x0001,
  370.     (APTR)&mui_exchange_sleep_img1,NULL,
  371.     0x00000000,0x00000000,0x00000000,
  372.     0x0000,
  373.     0x00000000,
  374.     0x0003,
  375.     0x00000000,0x00000000,0x80000000,0x80000000,
  376.     0x00000000,0x00000000,0x00000000,
  377. };
  378.  
  379.  
  380.  
  381.  
  382. /*** mui-stuff ***/
  383.  
  384. /*** list hooks ***/
  385.  
  386. SAVEDS ASM struct BrokerCopy *broker_list_confunc(
  387.     REG(a0) struct Hook *hook,
  388.     REG(a2) APTR mem_pool,
  389.     REG(a1) struct BrokerCopy *b)
  390. {
  391.     struct BrokerCopy *bc;
  392.  
  393.     if (bc = AllocMem(sizeof(struct BrokerCopy), MEMF_ANY))
  394.     {
  395.         int i;
  396.         UBYTE *s, *d;
  397.  
  398.         s = (BYTE *)b;
  399.         d = (BYTE *)bc;
  400.  
  401.         for (i=0; i < sizeof(struct BrokerCopy); i++)
  402.             *d++ = *s++;
  403.  
  404.         return(bc);
  405.     }
  406.  
  407.     /*** insert nothing ***/
  408.     return(0);
  409. }
  410.  
  411. static struct Hook broker_list_conhook = {
  412.     {NULL, NULL},
  413.     (void *)broker_list_confunc,
  414.     NULL, NULL
  415. };
  416.  
  417.  
  418. SAVEDS ASM LONG broker_list_desfunc(
  419.     REG(a0) struct Hook *hook,
  420.     REG(a2) APTR mem_pool,
  421.     REG(a1) struct BrokerCopy *bc)
  422. {
  423.     FreeMem(bc, sizeof(struct BrokerCopy));
  424.     return(0);
  425. }
  426.  
  427. static struct Hook broker_list_deshook = {
  428.     {NULL, NULL},
  429.     (void *)broker_list_desfunc,
  430.     NULL, NULL
  431. };
  432.  
  433.  
  434. SAVEDS ASM LONG broker_list_dspfunc(
  435.     REG(a0) struct Hook *hook,
  436.     REG(a2) char **array,
  437.     REG(a1) struct BrokerCopy *bc)
  438. {
  439.     *array = bc->bc_Name;
  440.     return(0);
  441. }
  442.  
  443. static struct Hook broker_list_dsphook = {
  444.     {NULL, NULL},
  445.     (void *)broker_list_dspfunc,
  446.     NULL, NULL
  447. };
  448.  
  449.  
  450. SAVEDS ASM LONG broker_list_cmpfunc(
  451.     REG(a0) struct Hook *hook,
  452.     REG(a2) struct BrokerCopy *bc1,
  453.     REG(a1) struct BrokerCopy *bc2)
  454. {
  455.     return(stricmp(bc2->bc_Name, bc1->bc_Name));
  456. }
  457.  
  458. static struct Hook broker_list_cmphook = {
  459.     {NULL, NULL},
  460.     (void *)broker_list_cmpfunc,
  461.     NULL, NULL
  462. };
  463.  
  464.  
  465.  
  466. /*** broker hook ***/
  467.  
  468. SAVEDS ASM LONG broker_list_brkfunc(
  469.     REG(a0) struct Hook *hook,
  470.     REG(a2) Object obj,
  471.     REG(a1) CxMsg *cm)
  472. {
  473.     if ((CxMsgType(cm) == CXM_COMMAND) && (CxMsgID(cm) == CXCMD_LIST_CHG))
  474.         insert_broker();
  475.  
  476.     return(0);
  477. }
  478.  
  479. static struct Hook broker_list_brkhook = {
  480.     {NULL, NULL},
  481.     (void *)broker_list_brkfunc,
  482.     NULL, NULL
  483. };
  484.  
  485.  
  486.  
  487.  
  488. /*** arexx hooks ***/
  489.  
  490. SAVEDS ASM LONG select_name_rxfunc(
  491.     REG(a0) struct Hook *hook,
  492.     REG(a2) Object *appl,
  493.     REG(a1) ULONG *arg)
  494. {
  495.     char *name;
  496.  
  497.     /*** name valid ? ***/
  498.     if (name = (char *)*arg)
  499.     {
  500.         ULONG pos;
  501.  
  502.         if (pos = find_broker_name(name))
  503.         {
  504.             /*** set cursor & listview ***/
  505.             set(lv_broker, MUIA_List_Active, pos);
  506.             DoMethod(lv_broker, MUIM_List_Jump, pos);
  507.  
  508.             return(RETURN_OK);
  509.         }
  510.     }
  511.  
  512.     return(RETURN_ERROR);
  513. }
  514.  
  515. static const struct Hook select_name_rxhook = {
  516.     {NULL, NULL},
  517.     (void *)select_name_rxfunc,
  518.     NULL,NULL
  519. };
  520.  
  521.  
  522. SAVEDS ASM LONG select_task_rxfunc(
  523.     REG(a0) struct Hook *hook,
  524.     REG(a2) Object *appl,
  525.     REG(a1) ULONG *arg)
  526. {
  527.     ULONG task;
  528.  
  529.     /*** task valid ? ***/
  530.     if (task = *((ULONG *)*arg))
  531.     {
  532.         ULONG pos;
  533.  
  534.         if (pos = find_broker_task(task))
  535.         {
  536.             /*** set cursor & listview ***/
  537.             set(lv_broker, MUIA_List_Active, pos);
  538.             DoMethod(lv_broker, MUIM_List_Jump, pos);
  539.  
  540.             return(RETURN_OK);
  541.         }
  542.     }
  543.  
  544.     return(RETURN_ERROR);
  545. }
  546.  
  547. static const struct Hook select_task_rxhook = {
  548.     {NULL, NULL},
  549.     (void *)select_task_rxfunc,
  550.     NULL,NULL
  551. };
  552.  
  553.  
  554.  
  555.  
  556. /*** arexx list ***/
  557.  
  558. static struct MUI_Command arexx_list[] =
  559. {
  560.     {"select_name",        "NAME/A",            1,                    &select_name_rxhook},
  561.     {"select_task",        "TASKADR/N/A",        1,                    &select_task_rxhook},
  562.  
  563.     {"activate",        MC_TEMPLATE_ID,        ID_ACTIVATE,        NULL},
  564.     {"deactivate",        MC_TEMPLATE_ID,        ID_DEACTIVATE,        NULL},
  565.     {"remove",            MC_TEMPLATE_ID,        ID_REMOVE,            NULL},
  566.  
  567.     {"interface_show",    MC_TEMPLATE_ID,        ID_INTERFACE_SHOW,    NULL},
  568.     {"interface_hide",    MC_TEMPLATE_ID,        ID_INTERFACE_HIDE,    NULL},
  569.  
  570.     {NULL,                NULL,                0,                    NULL}
  571. };
  572.  
  573.  
  574.  
  575.  
  576. /*** menu ***/
  577.  
  578. static struct NewMenu mn_main_data[] =
  579. {
  580.     { NM_TITLE,    "Project",            0,    0,    0,    (APTR) MN_PROJECT            },
  581.  
  582.     { NM_ITEM,    "About...",            "?",0,    0,    (APTR) ID_ABOUT                },
  583.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    (APTR) 0                    },
  584.     { NM_ITEM,    "Hide",                "H",0,    0,    (APTR) ID_HIDE                },
  585.     { NM_ITEM,    "Quit",                "Q",0,    0,    (APTR) ID_QUIT                },
  586.  
  587.  
  588.     { NM_TITLE,    "Broker",            0,    0,    0,    (APTR) MN_BROKER            },
  589.  
  590.     { NM_ITEM,    "Info",                "I",0,    0,    (APTR) ID_INFO                },
  591.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    (APTR) 0                    },
  592.     { NM_ITEM,    "Activate",            "A",0,    0,    (APTR) ID_ACTIVATE            },
  593.     { NM_ITEM,    "Deactivate",        "D",0,    0,    (APTR) ID_DEACTIVATE        },
  594.     { NM_ITEM,    "Remove",            "R",0,    0,    (APTR) ID_REMOVE            },
  595.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    (APTR) 0                    },
  596.     { NM_ITEM,    "Interface",        0,    0,    0,    (APTR) MN_INTERFACE            },
  597.     { NM_SUB,    "Show",                "S",0,    0,    (APTR) ID_INTERFACE_SHOW    },
  598.     { NM_SUB,    "Hide",                "E",0,    0,    (APTR) ID_INTERFACE_HIDE    },
  599.  
  600.     { NM_END,    NULL,                0,    0,    0,    (APTR) 0                    },
  601. };
  602.  
  603.  
  604.  
  605.  
  606. int main(int argc,char *argv[])
  607. {
  608.     /*** variables ***/
  609.     ULONG timer_sig = 0;
  610.  
  611.     /*** init ***/
  612.     BOOL not_end = TRUE;
  613.  
  614.     init();
  615.     if (CxBase = OpenLibrary("commodities.library", 0))
  616.     {
  617.  
  618.         /*** create mui-application ***/
  619.         app = ApplicationObject,
  620.             MUIA_Application_Title,                "MUI-Exchange",
  621.             MUIA_Application_Version,            "$VER: MUI-Exchange 0.9 (14.6.94)",
  622.             MUIA_Application_Copyright,            "© 1993/94 by kMel, Klaus Melchior",
  623.             MUIA_Application_Author,            "Klaus Melchior",
  624.             MUIA_Application_Description,        "Manages the system commodities list",
  625.             MUIA_Application_Base,                "MUIEXCH",
  626.             MUIA_Application_Commands,            arexx_list,
  627.             MUIA_Application_BrokerHook,        &broker_list_brkhook,
  628.             MUIA_Application_SingleTask,        TRUE,
  629.             MUIA_Application_DiskObject,        &mui_exchange_sleep_dobj,
  630.             MUIA_Application_Window, wi_main = WindowObject,
  631.                 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  632.                 MUIA_Window_Title, "MUI-Exchange",
  633.                 MUIA_Window_Menustrip, mn_main = MUI_MakeObject(MUIO_MenustripNM, mn_main_data, 0),
  634.                 WindowContents, VGroup,
  635.                     Child, VGroup,
  636.                         Child, HGroup,
  637.                             Child, bt_info = MUI_MakeObject(MUIO_Button,"_Info"),
  638.                             End,
  639.                         Child, VGroup,
  640.                             Child, lv_broker = ListviewObject,
  641.                                 MUIA_Listview_DoubleClick, TRUE,
  642.                                 MUIA_Listview_List, ListObject,
  643.                                     InputListFrame,
  644.                                     MUIA_List_ConstructHook, &broker_list_conhook,
  645.                                     MUIA_List_DestructHook, &broker_list_deshook,
  646.                                     MUIA_List_CompareHook, &broker_list_cmphook,
  647.                                     MUIA_List_DisplayHook, &broker_list_dsphook,
  648.                                     End,
  649.                                 End,
  650.                             Child, HGroup,
  651.                                 Child, bt_activate        = MUI_MakeObject(MUIO_Button,"_Activate"),
  652.                                 Child, bt_deactivate    = MUI_MakeObject(MUIO_Button,"_Deactivate"),
  653.                                 Child, bt_remove        = MUI_MakeObject(MUIO_Button,"_Remove"),
  654.                                 End,
  655.                             End,
  656.                         Child, HGroup,
  657.                             Child, bt_show    = MUI_MakeObject(MUIO_Button,"_Show Interface"),
  658.                             Child, bt_hide    = MUI_MakeObject(MUIO_Button,"_Hide Interface"),
  659.                             End,
  660.                         End,
  661.                     End,
  662.                 End,
  663.             End;
  664.  
  665.  
  666.         /*** application failed ? ***/
  667.         if (!app)
  668.             fail(app, "Creating application failed !");
  669.  
  670.         /*** menu objects ***/
  671.         mn_activate       = (APTR)DoMethod(mn_main, MUIM_FindUData, ID_ACTIVATE);
  672.         mn_deactivate     = (APTR)DoMethod(mn_main, MUIM_FindUData, ID_DEACTIVATE);
  673.         mn_interface      = (APTR)DoMethod(mn_main, MUIM_FindUData, MN_INTERFACE);
  674.  
  675.         /*** connections & cycle ***/
  676.         DoMethod(app, MUIM_Notify, MUIA_Application_DoubleStart, TRUE,
  677.             app, 2,
  678.             MUIM_Application_ReturnID, ID_QUIT);
  679.         DoMethod(wi_main, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  680.             app, 2,
  681.             MUIM_Application_ReturnID, ID_HIDE);
  682.  
  683.         DoMethod(lv_broker,        MUIM_Notify,    MUIA_Listview_DoubleClick,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_INFO                );
  684.         DoMethod(lv_broker,        MUIM_Notify,    MUIA_Listview_SelectChange,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_LV_ACTIVE        );
  685.  
  686.         DoMethod(lv_broker, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  687.             app, 2,
  688.             MUIM_Application_ReturnID, ID_LV_ACTIVE);
  689.  
  690.         DoMethod(bt_info,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_INFO                );
  691.  
  692.         DoMethod(bt_activate,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_ACTIVATE            );
  693.         DoMethod(bt_deactivate,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_DEACTIVATE        );
  694.         DoMethod(bt_remove,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_REMOVE            );
  695.  
  696.         DoMethod(bt_hide,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_INTERFACE_HIDE    );
  697.         DoMethod(bt_show,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_INTERFACE_SHOW    );
  698.  
  699.         DoMethod(wi_main,        MUIM_Window_SetCycleChain,
  700.             lv_broker,
  701.             bt_activate, bt_deactivate, bt_remove,
  702.             bt_hide, bt_show,
  703.             bt_info,
  704.             NULL);
  705.  
  706.         /*** menu notification ***/
  707.         DoMethod(bt_activate, MUIM_Notify, MUIA_Disabled, MUIV_EveryTime,
  708.             mn_activate, 3,
  709.             MUIM_Set, MUIA_Menuitem_Enabled, MUIV_NotTriggerValue);
  710.         DoMethod(bt_deactivate, MUIM_Notify, MUIA_Disabled, MUIV_EveryTime,
  711.             mn_deactivate, 3,
  712.             MUIM_Set, MUIA_Menuitem_Enabled, MUIV_NotTriggerValue);
  713.         DoMethod(bt_hide, MUIM_Notify, MUIA_Disabled, MUIV_EveryTime,
  714.             mn_interface, 3,
  715.             MUIM_Set, MUIA_Menuitem_Enabled, MUIV_NotTriggerValue);
  716.  
  717.         /*** open window ***/
  718.         set(wi_main, MUIA_Window_Open,            TRUE);
  719.         set(wi_main, MUIA_Window_ActiveObject,    lv_broker);
  720.  
  721.  
  722.         /*** get brokerlist ***/
  723.         insert_broker();
  724.  
  725.         /*** first scan & activate first entry ***/
  726.         set(lv_broker, MUIA_List_Active, 0);
  727.  
  728.         /*** create timer_port to refresh broker_list ***/
  729.         {
  730.             struct timerequest *timer_io;
  731.             struct MsgPort *timer_port;
  732.             struct Message *timer_msg;
  733.             ULONG error;
  734.  
  735.             if (timer_port = CreatePort(0, 0))
  736.             {
  737.                 timer_sig = (1<<(timer_port->mp_SigBit));
  738.  
  739.                 if (timer_io = (struct timerequest *) CreateExtIO(timer_port, sizeof(struct timerequest)))
  740.                 {
  741.                     if (!(error = OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *) timer_io, 0)))
  742.                     {
  743.                         /*** refresh-cycle is 1 second ***/
  744.                         timer_io->tr_node.io_Command = TR_ADDREQUEST;
  745.                         timer_io->tr_time.tv_secs = 1;
  746.                         timer_io->tr_time.tv_micro = 0;
  747.  
  748.                         SendIO((struct IORequest *) timer_io);
  749.  
  750.                         /*** main-loop ***/
  751.                         while (not_end)
  752.                         {
  753.                             ULONG signal, ret_sig, id, ret;
  754.                             char *n;
  755.                             struct BrokerCopy *bc;
  756.  
  757.                             switch (id = DoMethod(app, MUIM_Application_Input, &signal))
  758.                             {
  759.                                 case ID_ABOUT:
  760.                                     MUI_Request(app, wi_main, 0, NULL, "OK",
  761.                                         MUIX_C MUIX_PH "MUI-Exchange\n\n"
  762.                                         MUIX_PT "Version 0.9 (14.6.94)\n"
  763.                                         "Copyright 1993-94 by kMel, Klaus Melchior.\n"
  764.                                         "\nThis is a MUI-Application.\n"
  765.                                         "MUI is copyrighted by Stefan Stuntz.",
  766.                                         TAG_END);
  767.                                 break;
  768.  
  769.                                 case MUIV_Application_ReturnID_Quit:
  770.                                 case ID_QUIT:
  771.                                     not_end = FALSE;
  772.                                 break;
  773.  
  774.                                 case ID_HIDE:
  775.                                     set(app, MUIA_Application_Iconified, TRUE);
  776.                                 break;
  777.  
  778.  
  779.                                 case ID_INFO:
  780.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  781.  
  782.                                     MUI_Request(app, wi_main, 0, NULL, "OK",
  783.                                         MUIX_C MUIX_PH "%s\n\n"
  784.                                         MUIX_PT MUIX_N "%s\n"
  785.                                         "%s",
  786.                                         bc->bc_Name, bc->bc_Title, bc->bc_Descr,
  787.                                     TAG_END);
  788.                                 break;
  789.  
  790.                                 case ID_LV_ACTIVE:
  791.                                     check_broker();
  792.                                 break;
  793.  
  794.  
  795.                                 case ID_ACTIVATE:
  796.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  797.                                     BrokerCommand(n = bc->bc_Name, CXCMD_ENABLE);
  798.                                 break;
  799.  
  800.                                 case ID_DEACTIVATE:
  801.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  802.                                     BrokerCommand(n = bc->bc_Name, CXCMD_DISABLE);
  803.                                 break;
  804.  
  805.                                 case ID_REMOVE:
  806.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  807.                                     BrokerCommand(bc->bc_Name, CXCMD_KILL);
  808.                                 break;
  809.  
  810.                                 case ID_INTERFACE_SHOW:
  811.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  812.                                     ret = BrokerCommand(bc->bc_Name, CXCMD_APPEAR);
  813.                                 break;
  814.  
  815.                                 case ID_INTERFACE_HIDE:
  816.                                     DoMethod(lv_broker, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &bc);
  817.                                     ret = BrokerCommand(bc->bc_Name, CXCMD_DISAPPEAR);
  818.                                 break;
  819.  
  820.  
  821. /*                                default:
  822.                                     if (id)
  823.                                         printf("ID: %d = %08lx\n", id, id);
  824.                                 break;
  825. */                            }
  826.  
  827.                             if (not_end && signal)
  828.                                 ret_sig = Wait(signal | timer_sig);
  829.  
  830.                             /*** timer signal ? ***/
  831.                             if (ret_sig & timer_sig)
  832.                             {
  833.                                 while (timer_msg = GetMsg(timer_port))
  834.                                     ;
  835.  
  836.                                 insert_broker();
  837.  
  838.                                 /*** refresh cycle is 1 second ***/
  839.                                 timer_io->tr_node.io_Command = TR_ADDREQUEST;
  840.                                 timer_io->tr_time.tv_secs = 1;
  841.                                 timer_io->tr_time.tv_micro = 0;
  842.  
  843.                                 SendIO((struct IORequest *) timer_io);
  844.                             }
  845.  
  846.                         }
  847.  
  848.                         /*** clean up & close timer.device ***/
  849.                         if (!(CheckIO((struct IORequest *)timer_io)))
  850.                             AbortIO((struct IORequest *)timer_io);
  851.                         WaitIO((struct IORequest *)timer_io);
  852.                         CloseDevice((struct IORequest *) timer_io);
  853.                     }
  854.  
  855.                     DeleteExtIO((struct IORequest *) timer_io);
  856.                 }
  857.  
  858.                 while (timer_msg = GetMsg(timer_port))
  859.                     ;
  860.                 DeletePort(timer_port);
  861.             }
  862.         }
  863.  
  864.         CloseLibrary(CxBase);
  865.     }
  866.  
  867.     fail(app, NULL);
  868. }
  869.  
  870.