/* Copyright (C) 2003 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see .
*/
#include
#include
#include //For SignalProxy_RowSeparator.
#include
namespace Gtk
{
ComboBox::ComboBox(bool has_entry)
:
_CONSTRUCT("has-entry", gboolean(has_entry))
{}
ComboBox::ComboBox(const Glib::RefPtr& model, bool has_entry)
:
_CONSTRUCT("model", Glib::unwrap(model), "has-entry", gboolean(has_entry))
{}
ComboBox::ComboBox(const Glib::RefPtr& cell_area, bool has_entry)
:
_CONSTRUCT("cell-area", Glib::unwrap(cell_area), "has-entry", gboolean(has_entry))
{}
void ComboBox::unset_active()
{
gtk_combo_box_set_active(gobj(), -1 /* see GTK+ docs */);
}
TreeModel::iterator ComboBox::get_active()
{
Gtk::TreeModel::iterator iter;
auto model = get_model();
if(model)
{
gtk_combo_box_get_active_iter(gobj(), iter.gobj());
//It must be given the model, because the C++ wrapper has extra information.
iter.set_model_gobject(model->gobj());
}
return iter;
}
TreeModel::const_iterator ComboBox::get_active() const
{
Gtk::TreeModel::iterator iter;
const auto model = get_model();
if(model)
{
gtk_combo_box_get_active_iter(const_cast(gobj()), iter.gobj());
//It must be given the model, because the C++ wrapper has extra information.
iter.set_model_gobject(const_cast(model->gobj()));
}
return iter;
}
void ComboBox::unset_model()
{
gtk_combo_box_set_model(gobj(), nullptr);
}
void ComboBox::set_row_separator_func(const SlotRowSeparator& slot)
{
//Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
//It will be deleted when SignalProxy_RowSeparator_gtk_callback_destroy() is called.
auto slot_copy = new SlotRowSeparator(slot);
gtk_combo_box_set_row_separator_func(gobj(),
&TreeView_Private::SignalProxy_RowSeparator_gtk_callback, slot_copy,
&TreeView_Private::SignalProxy_RowSeparator_gtk_callback_destroy);
}
void ComboBox::unset_row_separator_func()
{
gtk_combo_box_set_row_separator_func(gobj(), nullptr, nullptr, nullptr /* See C docs. */);
}
Entry* ComboBox::get_entry()
{
auto widget = Glib::wrap(gtk_bin_get_child(GTK_BIN(gobj())));
return dynamic_cast(widget);
}
const Entry* ComboBox::get_entry() const
{
const auto widget = Glib::wrap(gtk_bin_get_child(GTK_BIN(gobj())));
return dynamic_cast(widget);
}
Glib::ustring ComboBox::get_entry_text() const
{
const auto entry = get_entry();
if(!entry)
return Glib::ustring();
else
return entry->get_text();
}
// GtkComboBox:focus-on-click has been removed from gtk+.
// TODO: At ABI-break, remove it from gtkmm.
#ifndef GTKMM_DISABLE_DEPRECATED
Glib::PropertyProxy< bool > ComboBox::property_focus_on_click()
{
return Glib::PropertyProxy< bool >(this, "focus-on-click");
}
Glib::PropertyProxy_ReadOnly< bool > ComboBox::property_focus_on_click() const
{
return Glib::PropertyProxy_ReadOnly< bool >(this, "focus-on-click");
}
#endif // GTKMM_DISABLE_DEPRECATED
} // namespace Gtk