/* $Id: c,v.dataopen 7.2 1998/09/01 19:51:23 stoklund Exp $ */
/* dataopen.c: Load file into an editor with a DataOpen message

   Copyright (C) 1998 Jakob Stoklund Olesen

   This library is free software; you can redistribute it and / or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; if not ,write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 -
   1307, USA. */

#include "config.h"
#include "OS:wimp.h"
#include "kpathsea:riscos.h"
#include "riscos.h"

/* Try to load the file given by FILENAME into an editor. Return true if
   message is broadcast */
boolean
riscos_data_open (const_string filename)
{
  wimp_message msg;
  string fullname = riscos_ensure_prefix (filename);
  int length = strlen (fullname);

  if (length >= 212)
    return false;		/* wimp can't handle longer messages */

  msg.size = 44 + 4 + (length & ~3);
  msg.your_ref = 0;
  msg.action = 5;		/* Message_DataOpen */
  msg.data.data_xfer.w = 0;	/* no window? */
  msg.data.data_xfer.pos.x = 0;
  msg.data.data_xfer.pos.y = 0;
  msg.data.data_xfer.est_size = 0;
  msg.data.data_xfer.file_type = 0xfff;		/* open as text file */
  strcpy (msg.data.data_xfer.file_name, fullname);

  /* Broadcast a User_Message as we can't check the replies anyway */
  return xwimp_send_message (17, &msg, 0) == NULL;
}
