/**
 * Scout - The Amiga System Monitor
 *
 *------------------------------------------------------------------
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * You must not use this source code to gain profit of any kind!
 *
 *------------------------------------------------------------------
 *
 * @author Andreas Gelhausen
 * @author Richard Körber <rkoerber@gmx.de>
 */

#include "system_headers.h"

static ULONG __saveds mNew( struct IClass *cl,
                            Object *obj,
                            struct opSet *msg )
{
    APTR abouttext,okButton;

    if (obj = (Object *)DoSuperNew(cl, obj,
        MUIA_Window_Title, "About Scout",
        WindowContents, VGroup,

            Child, abouttext = MyTextObject(),
            Child, MyVSpace(4),
            Child, HGroup, MUIA_Group_SameWidth, TRUE,
                Child, MyHSpace(0),
                Child, okButton = MakeButton(txtMUIContinue),
                Child, MyHSpace(0),
            End,
        End,
        TAG_MORE, msg->ops_AttrList))
    {
        set(obj, MUIA_Window_ActiveObject, okButton);
        MySetContents(abouttext, txtAboutText, vstring, release, COPYRIGHT, EMAIL, portname);

        DoMethod(obj,      MUIM_Notify, MUIA_Window_CloseRequest, TRUE,  MUIV_Notify_Application, 2, MUIM_Application_ReturnID, 1);
        DoMethod(okButton, MUIM_Notify, MUIA_Pressed,             FALSE, MUIV_Notify_Application, 2, MUIM_Application_ReturnID, 1);
    }

    return (ULONG)obj;
}

static ULONG __saveds mDispose( struct IClass *cl,
                                Object *obj,
                                struct opSet *msg )
{
    set(obj, MUIA_Window_Open, FALSE);

    return (DoSuperMethodA(cl, obj, msg));
}

static ULONG __saveds mAbout( struct IClass *cl,
                              Object *obj,
                              Msg msg )
{
    APTR app;
    BOOL done = FALSE;
    ULONG result = 0;

    get(obj, MUIA_ApplicationObject, &app);
    set(app, MUIA_Application_Sleep, TRUE);
    set(obj, MUIA_Window_Open, TRUE);

    while (!done) {
        ULONG signals;

        switch (DoMethod(app, MUIM_Application_NewInput, &signals)) {
            case MUIV_Application_ReturnID_Quit:
            case 1:
                done = TRUE;
                break;

            default:
                break;
        }

        if (!done && signals != 0) Wait(signals);
    }

    set(obj, MUIA_Window_Open, FALSE);
    set(app, MUIA_Application_Sleep, FALSE);

    return result;
}

ULONG __asm __saveds AboutWinDispatcher( register __a0 struct IClass *cl,
                                         register __a2 Object *obj,
                                         register __a1 Msg msg )
{
    switch (msg->MethodID) {
        case OM_NEW:              return (mNew(cl, obj, (APTR)msg));
        case OM_DISPOSE:          return (mDispose(cl, obj, (APTR)msg));
        case MUIM_AboutWin_About: return (mAbout(cl, obj, (APTR)msg));
    }

    return (DoSuperMethodA(cl, obj, msg));
}

