/*
 *    SCCS ID: %Z%%M% %I% %E% SST
 *
 *    Copyright (c) 1992 Mark Soloway.  All rights reserved.
 *    See SST_LEGAL_NOTICE file for terms of the license.
 */

#include "AlphanumericInput.h"
#include "Slider.h"
#include "TTC.h"

void scope_handler (UIObject *object)
{
  char *file = (char *)NULL;

  AlphanumericInput *scope = (AlphanumericInput *)object;
  (void)scope->getValue (file);

  if (file && strlen (file)) {
    TTSession *session = (TTSession *)scope->getObjectData ("TT_SESSION");
    (void)session->quitAllFiles ();
    Tt_status status = session->joinFile (file);
	
    if (status != TT_OK)
      printf ("Pattern not scoped to file: TT error %d\n", status);
  }
  else {
    printf ("Pattern not scoped to file: Illegal scope value\n");
  }

  if (file) delete file;
  return;
}

void send_target_handler (UIObject *event_object, UIObject *target_object)
{
  char *file = (char *)NULL;

  AlphanumericInput *scope = (AlphanumericInput *)target_object;
  (void)scope->getValue (file);

  if (file && strlen (file)) {
    TTSession *session = (TTSession *)scope->getObjectData ("TT_SESSION");
    Tt_status  status;

    TTMessage message ("ExampleMessage", TT_NOTICE, TT_FILE, status);
    status = message.setFile (file);

    if (status == TT_OK) {
      int value = event_object->getValue (value);
      status = message.addArg (TT_IN, "value", value);
    }

    if (status == TT_OK)
      status = session->sendAsynchronousMessage (message);

    if (status != TT_OK)
      printf ("No message sent: TT error %d\n", status);
  }
  else {
    printf ("No message sent: Illegal scope value\n");
  }

  if (file) delete file;
  return;
}
