/********************************************************************
This file is part of the abs 0.907 distribution.  abs is a spreadsheet
with graphical user interface.

Copyright (C) 1998-2001  André Bertin (Andre.Bertin@ping.be) 

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
(at your option) any later version if in the same spirit as version 2.

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.

Concact: abs@pi.be
         http://home.pi.be/bertin/abs.shtml

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































#include "callback_app.h"
			  
extern void stopedit ();
extern int setcursor (int r, int c);
extern int xrepaint (char *message);

		     
extern int resetselect (int ii, int jj, int k);
extern int insertcolumn ();
extern int insertline ();
extern int delcolumn ();
extern int delline ();


#include "application.h"
#include "finite_state.h"

#include <stdio.h>


void
m_openfile (char *filename)
{
  stopedit ();
  state_reset_levels ();
  FS->l1 = StBatch;
  state_print ("before open");
  openfile (filename);
  state_print ("after open");
  state_reset_levels ();
  xrepaint ("m_openfile");
  setcursor (1, 1);
}

void
m_newfile (Widget w, XtPointer client_data, XtPointer call_data)
{
  stopedit ();
  state_reset_levels ();
  new_doc (NULL);
  setcursor (1, 1);
}

void
m_savefile (Widget w, XtPointer client_data, XtPointer call_data)
{
  stopedit ();
  savefile ();
}

void
m_saveasfile (char *buf)
{
  stopedit ();
  saveasfile (buf);
}

void
m_closefile (Widget w, XtPointer client_data, XtPointer call_data)
{
  stopedit ();
  resetselect (0, 0, 0);
  state_reset_levels ();
  close_doc ();
}


void
m_printfile (Widget w, XtPointer client_data, XtPointer call_data)
{

}

void
m_addsheet (Widget w, XtPointer client_data, XtPointer call_data)
{
  stopedit ();
  resetselect (0, 0, 0);
  workbook_addsheet (ActiveWorkbook, NULL);
  setcursor (1, 1);
}

void
m_delsheet (Widget w, XtPointer client_data, XtPointer call_data)
{
  stopedit ();
  resetselect (0, 0, 0);
  workbook_delactivesheet (ActiveWorkbook);
}

void
m_delline (Widget w, XtPointer client_data, XtPointer call_data)
{
  stopedit ();
  delline ();
}

void
m_delcolumn (Widget w, XtPointer client_data, XtPointer call_data)
{
  stopedit ();
  delcolumn ();
}

void
m_insertline (Widget w, XtPointer client_data, XtPointer call_data)
{
  stopedit ();
  insertline ();
}

void
m_insertcolumn (Widget w, XtPointer client_data, XtPointer call_data)
{
  stopedit ();
  insertcolumn ();
}

void
m_find (Widget w, XtPointer client_data, XtPointer call_data)
{
  fprintf (stderr, "find\n");
}

void
m_replace (Widget w, XtPointer client_data, XtPointer call_data)
{
  fprintf (stderr, "replace\n");
}

void
m_goto (Widget w, XtPointer client_data, XtPointer call_data)
{
  fprintf (stderr, "goto\n");
}

void
m_changewin (Widget w, XtPointer client_data, XtPointer call_data)
{
  stopedit ();
  resetselect (0, 0, 0);
  Activate_workbook2 (XtName (w));

}
