/************************************************************
**
** Application: TranJPEG
**
** Title:       c.taskwindow
**
*************************************************************/

/*
*
* Copyright (c) 2015, Chris Johnson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*   * Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*   * Redistributions in binary form must reproduce the above
*     copyright notice, this list of conditions and the following
*     disclaimer in the documentation and/or other materials provided
*     with the distribution.
*   * Neither the name of the copyright holder nor the names of their
*     contributors may be used to endorse or promote products derived
*     from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

/* Include files */
/* from standard clib */
#include <stdlib.h>
#include <stdio.h>


/* headers from tasklib */
#include "TaskLib:h.os"
#include "TaskLib:h.wimp"
#include "TaskLib:h.werr"
#include "TaskLib:h.wos"
#include "TaskLib:h.err"
#include "TaskLib:h.poll"
#include "TaskLib:h.etc"

/* headers from app */
#include "h.main"
#include "h.status"
#include "h.process"
#include "h.taskwindow"




/* TaskWindow message IDs */
#define wimp_MTASKWINDOW_INPUT   (wimp_msgaction)0x808C0
#define wimp_MTASKWINDOW_OUTPUT  (wimp_msgaction)0x808C1
#define wimp_MTASKWINDOW_EGO     (wimp_msgaction)0x808C2
#define wimp_MTASKWINDOW_MORIO   (wimp_msgaction)0x808C3
#define wimp_MTASKWINDOW_MORITE  (wimp_msgaction)0x808C4
#define wimp_MTASKWINDOW_SUSPEND (wimp_msgaction)0x808C6
#define wimp_MTASKWINDOW_RESUME  (wimp_msgaction)0x808C7


static int twchild_handle;


/* taskwindow message handlers */

static os_error *taskwindow_msgoutput (wimp_msgstr * msg, int *ack)
{
  if (twchild_handle == msg->hdr.task)
  {
    status_update_taskwindow_message (msg);
  }

  return (NULL);
  USE (ack);
  USE (msg);
}





static os_error *taskwindow_msgego (wimp_msgstr * msg, int *ack)
{

  twchild_handle = msg->hdr.task;

  return (NULL);
  USE (ack);
  USE (msg);
}



/*
*
* This function now does nothing. Its purpose is now subsumed in to
* c.process function.
*
*/

static os_error *taskwindow_msgmorio (wimp_msgstr * msg, int *ack)
{
  if (twchild_handle == msg->hdr.task)
  {
////////    control_transformended();
  }

  return (NULL);
  USE (ack);
  USE (msg);
}





os_error *taskwindow_addmessages (void)
{
  os_error   *err;

  err = addmessage (taskwindow_msgoutput, wimp_MTASKWINDOW_OUTPUT);
  if (!err) err = addmessage (taskwindow_msgego, wimp_MTASKWINDOW_EGO);
  if (!err) err = addmessage (taskwindow_msgmorio, wimp_MTASKWINDOW_MORIO);
  return (err);
}




os_error *taskwindow_removemessages (void)
{
  remmessage (taskwindow_msgoutput, wimp_MTASKWINDOW_OUTPUT);
  remmessage (taskwindow_msgego, wimp_MTASKWINDOW_EGO);
  remmessage (taskwindow_msgmorio, wimp_MTASKWINDOW_MORIO);
  return (NULL);
}




/**************************************/

/* Sending messages to taskwindow child */


static os_error *taskwindow_sendmessage (wimp_msgaction action )
{
  os_error   *err;
  wimp_msgstr msg;

  msg.hdr.size = 20;
  msg.hdr.task = taskhandle;
  msg.hdr.my_ref = 0;
  msg.hdr.your_ref = 0;
  msg.hdr.action = action;
  err = wimp_sendmessage ( wimp_ESEND, &msg, twchild_handle );
  return (err);
}




os_error *taskwindow_suspend (void)
{
  return ( taskwindow_sendmessage ( wimp_MTASKWINDOW_SUSPEND ));
}





os_error *taskwindow_resume (void)
{
  return ( taskwindow_sendmessage ( wimp_MTASKWINDOW_RESUME ));
}




os_error *taskwindow_kill (void)
{
  return ( taskwindow_sendmessage ( wimp_MTASKWINDOW_MORITE ));
}


