#ifndef __WB_COLUMN_PAGE_HANDLING_H__
#define __WB_COLUMN_PAGE_HANDLING_H__

#include "grt/tree_model.h"

class MySQLTableEditorBE;
class MGGladeXML;
class ListModelWrapper;
class DbMySQLTableEditor;
class AutoCompletable;

namespace Gtk
{
  class ScrolledWindow;
}

//==============================================================================
//
//==============================================================================
class DbMySQLTableEditorColumnPage
{
  public:
    DbMySQLTableEditorColumnPage(DbMySQLTableEditor *owner, MySQLTableEditorBE* be, MGGladeXML* xml);
	~DbMySQLTableEditorColumnPage();
	
    void refresh();
    void partial_refresh(const int what);

    void switch_be(MySQLTableEditorBE* be);

  private:
    grt::StringListRef get_types_for_table(const db_TableRef table); //!< T

    bool process_event(GdkEvent* event);
    void type_column_event(GdkEvent* e);
    void cursor_changed();

    void update_column_details(const ::bec::NodeId &node);
    
    void set_comment(const std::string& comment);
    void set_collation();
    void update_collation();

    void check_resize(Gtk::Allocation& r);
    bool do_on_visible(GdkEventVisibility*);

    bec::NodeId get_selected();
  private:
    void refill_completions();
    void refill_columns_tv();

    DbMySQLTableEditor                       *_owner;
    MySQLTableEditorBE                       *_be;
    MGGladeXML                               *_xml;

    Glib::RefPtr<ListModelWrapper>            _model;
    Gtk::TreeView                            *_tv;
    Gtk::ScrolledWindow                      *_tv_holder;

    Gtk::ComboBoxText                        *_collation_combo;

    gulong                                    _edit_conn;
    GtkCellEditable                          *_ce;

    // Auto completion of types and related functions
    static AutoCompletable                    _types_completion;
    static AutoCompletable                    _names_completion;
    static void type_cell_editing_started(GtkCellRenderer* cr, GtkCellEditable* ce, gchar* path, gpointer udata);
    static void cell_editing_done(GtkCellEditable* ce, gpointer udata);

    bool                                      _editing;
};

#endif
