#ifndef _GTK_HELPERS_H_
#define _GTK_HELPERS_H_

#include <gdk/gdk.h>

namespace Gtk
{
class TreeView;
class Widget;
class Entry;
class ListStore;
class EntryCompletion;
class HBox;
class ComboBox;
class ComboBoxText;
class ComboBoxEntryText;
class Window;
}

#include <glibmm/refptr.h>
#include <gtkmm/treemodelcolumn.h>
#include <vector>
#include <string>
#include <grt/tree_model.h>

//!
//! \addtogroup linuxutils Linux utils
//! @{
//!
class TextListColumnsModel;
class TreeModelWrapper;
void expand_tree_nodes_as_in_be(const Glib::RefPtr<TreeModelWrapper> &model, Gtk::TreeView *tv);

Gtk::HBox &create_icon_label(const std::string &icon, const std::string &label);

void open_url(const std::string &url);

Glib::RefPtr<Gtk::ListStore> model_from_string_list(const std::vector<std::string>& list, TextListColumnsModel* columns);
Glib::RefPtr<Gtk::ListStore> model_from_string_list(const std::vector<std::string>& list, TextListColumnsModel** columns = 0);
void recreate_model_from_string_list(Glib::RefPtr<Gtk::ListStore>, const std::vector<std::string>& list);
void setup_combo_for_string_list(Gtk::ComboBox *combo);

//! Wrapper to set string values to a Glib::ValueBase
//! Used in ListModelWrapper
void set_glib_string(Glib::ValueBase& value, const std::string& str);
void set_glib_int(Glib::ValueBase& value, const int i);
void set_glib_bool(Glib::ValueBase& value, const bool b);
void set_glib_double(Glib::ValueBase& value, const double d);

void fill_combo_from_string_list(Gtk::ComboBoxText* combo, const std::vector<std::string>& list);
void fill_combo_from_string_list(Gtk::ComboBoxEntryText* combo, const std::vector<std::string>& list);

//! get_mainwindow is declared here as extern while it is implemented in frontend/linux/workbench/Program.cpp
//! and frontend/linux/shell/shell.cpp. get_mainwindow is needed by some functions/methods to
//! set dialog transient. Returns ptr to Gtk::Window
extern void* get_mainwindow_impl();
inline Gtk::Window* get_mainwindow()
{
  return (Gtk::Window*)get_mainwindow_impl();
}

extern std::string open_file_chooser(const std::string &filter = "*");
extern std::string save_file_chooser(const std::string &filter = "*");

struct GtkAutoLock
{
  GtkAutoLock() {gdk_threads_enter();}
  ~GtkAutoLock() {gdk_threads_leave();}
};

//!
//! }@
//!

#endif /* _GTK_HELPERS_H_ */
