/* This file is part of cardwords
   (c) 1999 Tobias Peters
   see file COPYING for the copyright terms.
   
   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.

   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// cardwords_gtk_cardtable.hh

#ifndef CARDWORDS_GTK_CARDTABLE_HH
#define CARDWORDS_GTK_CARDTABLE_HH

#include "cardwords_gtk_cardtableinfo.hh"
#include <slist.h>

class CardWords_Gtk_CardTable : public Gtk_Table
{
private:
  const CardWords_CardTable * card_table;
  
public:
  const CardWords_CardTable *
  get_card_table(void) const { return card_table; }

  CardWords_Gtk_CardTable( const CardWords_CardTable *,
                           size_t cell_width,
                           size_t cell_height,

                           bool use_digits_for_the_columns,
                           // and chars for the rows, otherwise the other way
                           // round
                          
                           bool column_indices_grow_rightwards,
                           // if true, the rightmost column has the greatest
                           // index
                          
                           bool row_indices_grow_upwards,

                           CardWords_Gtk_CardTableInfo *);
  ~CardWords_Gtk_CardTable();

  // A click on the card cell at this location has been performed:
  Signal1<CardWords_CardTableLocation> cell_clicked;

  // When this method is called, the move has already been added to the
  // CardWords_CardTable. The info is for the display:
  // Automatically calls unpre(). New Cards will be displayed in recent
  // style.
  void
  show_move(const CardWords_Move &);

  // When unrecent() is called, all cards displayed in the special way for
  // recently added cards are converted to be displayed normally:
  void
  unrecent(void);

  // unpre() without args removes all cards that are currently being dis-
  // played but are not yet really on the card-table. This is for the user to
  // try moves out.
  void
  unpre(void);

  // pre (const CardWords_Move &) displays this move, but it is not really on
  // the card-table. Calls unpre() to delete previous pre() moves.
  void
  pre (const CardWords_Move &);

  const CardWords_Gtk_Common_Card_Cell_Styles *
  get_styles(void) const;

  bool
  uses_digits_for_the_columns(void) const;
  // and chars for the rows, otherwise the other way
  // round
                          
  bool
  do_column_indices_grow_rightwards(void) const;
  // if true, the rightmost column has the greatest
  // index
                          
  bool
  do_row_indices_grow_upwards(void) const;

private:
  void
  receive_click_on_cell(const CardWords_Gtk_CardCell *);
  
  slist<CardWords_CardTableLocation> recent_locations;
  slist<CardWords_CardTableLocation> pre_locations;

  CardWords_Matrix<CardWords_Gtk_CardCell *> cells;

  CardWords_Gtk_Common_Card_Cell_Styles * styles;

  vector<Gtk_Label *> upper_labels;
  vector<Gtk_Label *> lower_labels;
  vector<Gtk_Label *> left_labels;
  vector<Gtk_Label *> right_labels;

  // Where to display the info about the cell under the pointer:
  CardWords_Gtk_CardTableInfo * card_table_info;

  bool use_digits_for_the_columns;
  // and chars for the rows, otherwise the other way
  // round
                          
  bool column_indices_grow_rightwards;
  // if true, the rightmost column has the greatest
  // index
                          
  bool row_indices_grow_upwards;
};

#endif

