// --------------------------------------------------------------------------------------------------------------
//
//   AmiGnut 0.9.0 Hooks Module
//
//   Copyright (C) 2001 Jay Cornwall <jay@realfantasy.demon.co.uk>
//
//   This is free software distributed under the terms of the GNU Public License. See the file License.txt for
//   details.
//
// --------------------------------------------------------------------------------------------------------------

#include "Hooks.h"

// --------------------------------------------------------------------------------------------------------------

LONG MainGadgetFunc(register __a0 struct Hook *hook, register __a2 APTR obj, register __a1 ULONG *param)
{
    // A gadget of WID_MAIN has been hit

    // Check which gadget was hit

    switch(*param)
    {
        case GID_CONNECT_BUTTON_MAIN:

            // Toggle the Connect/Disconnect button states

            set(Gadgets[GID_CONNECT_BUTTON_MAIN],       MUIA_Disabled,          TRUE);
            set(Gadgets[GID_DISCONNECT_BUTTON_MAIN],    MUIA_Disabled,          FALSE);

            // Disable gadgets/menu items which can't be used whilst connected

            set(Menus[MID_ABOUT_MAIN],                  MUIA_Menuitem_Enabled,  FALSE);
            set(Gadgets[GID_HCHOSTNAME_STRING_SETUP],   MUIA_Disabled,          TRUE);
            set(Gadgets[GID_HCPORT_STRING_SETUP],       MUIA_Disabled,          TRUE);
            set(Gadgets[GID_LISTENPORT_STRING_SETUP],   MUIA_Disabled,          TRUE);
            set(Gadgets[GID_MAXINCOMING_SLIDER_SETUP],  MUIA_Disabled,          TRUE);
            set(Gadgets[GID_MAXOUTGOING_SLIDER_SETUP],  MUIA_Disabled,          TRUE);

            // Tell the network process to begin connecting

            SendIPCMTNMessage(IPCMTNMSG_CONNECT);

            break;

        case GID_DISCONNECT_BUTTON_MAIN:

            // Tell the network process to disconnect

            SendIPCMTNMessage(IPCMTNMSG_DISCONNECT);

            // Interrupt any network activity

            MNInterrupt = TRUE;
            Signal((struct Task *)NetworkProcess, SIGBREAKF_CTRL_C);

            break;
    } /* switch */

    return(0);
} /* MainGadgetFunc() */

// --------------------------------------------------------------------------------------------------------------

LONG MainMenuFunc(register __a0 struct Hook *hook, register __a2 APTR obj, register __a1 ULONG *param)
{
    // A menu item of WID_MAIN has been selected

    // Check which item was selected

    switch(*param)
    {
        case MID_ABOUT_MAIN:

            // Display About message

            About();

            break;

        case MID_DEFAULTS_MAIN:

            // Reset the settings to default

            ResetSettings();

            break;
    } /* switch */

    return(0);
} /* MainMenuFunc() */

// --------------------------------------------------------------------------------------------------------------

LONG SetupGadgetFunc(register __a0 struct Hook *hook, register __a2 APTR obj, register __a1 ULONG *param)
{
    // A gadget of WID_SETUP has been hit

    // Check which gadget was hit

    switch(*param)
    {
        case GID_CANCEL_BUTTON_SETUP:

            // Close the Setup window

            set(Windows[WID_SETUP], MUIA_Window_Open, FALSE);

            // Reject the changed settings

            RejectSettings();

            break;

        case GID_USE_BUTTON_SETUP:

            // Close the Setup window

            set(Windows[WID_SETUP], MUIA_Window_Open, FALSE);

            // Accept the changed settings

            AcceptSettings();

            break;
    } /* switch */

    return(0);
} /* SetupGadgetFunc() */

// --------------------------------------------------------------------------------------------------------------

struct Hook MainGadgetHook =    { {NULL, NULL}, (HOOKFUNC)MainGadgetFunc,   NULL,   NULL };
struct Hook MainMenuHook =      { {NULL, NULL}, (HOOKFUNC)MainMenuFunc,     NULL,   NULL };
struct Hook SetupGadgetHook =   { {NULL, NULL}, (HOOKFUNC)SetupGadgetFunc,  NULL,   NULL };

// --------------------------------------------------------------------------------------------------------------

// End Of Text
