* Licence details can be found in the file COPYING.
*
* \author Huang Ying
+ * \author John Spray
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#include <gtkmm.h>
+
+// Too hard to make concept checks work with this file
+#ifdef _GLIBCPP_CONCEPT_CHECKS
+#undef _GLIBCPP_CONCEPT_CHECKS
+#endif
#include "GToolbar.h"
#include "GView.h"
+#include "ghelpers.h"
+
#include "buffer.h"
#include "bufferparams.h"
#include "debug.h"
return lv.buffer()->params().getLyXTextClass();
}
-
-void comboClear(Gtk::Combo & combo)
-{
- std::vector<Glib::ustring> strings;
- strings.push_back("");
- combo.set_popdown_strings(strings);
-}
-
-
-bool comboIsEmpty(Gtk::Combo & combo)
-{
- std::vector<Glib::ustring> strings = combo.get_popdown_strings();
- return (strings.empty() || (strings.size() == 1 && strings[0] == ""));
-}
-
char const * gToolData = "tool_data";
} // namespace anon
: owner_(owner),
internal_(false)
{
- combo_.set_value_in_list();
- combo_.get_entry()->set_editable(false);
- combo_.unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
- combo_.get_entry()->unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
- comboClear(combo_);
-
- combo_.get_entry()->signal_changed().connect(
+ combo_.signal_changed().connect(
sigc::mem_fun(*this,&GLayoutBox::selected));
- combo_.show();
+ model_ = Gtk::ListStore::create(cols_);
+ combo_.set_model(model_);
+ Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
+ combo_.pack_start(*cell, true);
+ combo_.add_attribute(*cell,"text",0);
+ combo_.set_wrap_width(2);
+ // Initially there's nothing in the liststore, so set the size
+ // to avoid it jumping too much when the user does something that
+ // causes the first update()
+ combo_.set_size_request(130,-1);
+
combo_.set_data(
gToolData,
reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
-
+
+ combo_.show();
+
Gtk::ToolItem * toolitem = Gtk::manage(new Gtk::ToolItem);
toolitem->add(combo_);
- toolbar.insert(*toolitem,-1);
+ toolbar.append(*toolitem);
}
void GLayoutBox::set(string const & layout)
{
LyXTextClass const & tc = getTextClass(owner_);
+ string const target = tc[layout]->name();
internal_ = true;
- combo_.get_entry()->set_text(tc[layout]->name());
+ Gtk::TreeModel::iterator it = model_->children().begin();
+ Gtk::TreeModel::iterator end = model_->children().end();
+ for (; it != end; ++it) {
+ if ((*it)[cols_.name] == target){
+ combo_.set_active(it);
+ internal_ = false;
+ return;
+ }
+ }
internal_ = false;
+
+ lyxerr << "ERROR (GLayoutBox::set): layout not found! name: "
+ << target << std::endl;
}
void GLayoutBox::update()
{
- LyXTextClass const & tc = getTextClass(owner_);
+ clear();
- std::vector<Glib::ustring> strings;
+ LyXTextClass const & tc = getTextClass(owner_);
LyXTextClass::const_iterator it = tc.begin();
LyXTextClass::const_iterator const end = tc.end();
- for (; it != end; ++it)
- if ((*it)->obsoleted_by().empty())
- strings.push_back(
- Glib::locale_to_utf8((*it)->name()));
+
internal_ = true;
- combo_.set_popdown_strings(strings);
+ for (; it != end; ++it)
+ if ((*it)->obsoleted_by().empty()) {
+ Gtk::TreeModel::iterator iter = model_->append();
+ Gtk::TreeModel::Row row = *iter;
+ row[cols_.name] = Glib::locale_to_utf8((*it)->name());
+ }
internal_ = false;
+
+ // now that we've loaded something into the combobox, forget
+ // the initial fixed size and let GTK decide.
+ combo_.set_size_request(-1,-1);
}
void GLayoutBox::clear()
{
internal_ = true;
- comboClear(combo_);
+ model_->clear();
internal_ = false;
}
void GLayoutBox::open()
{
- combo_.get_list()->activate();
+ combo_.popup();
}
if (internal_)
return;
- string layoutGuiName = combo_.get_entry()->get_text();
- // we get two signal, one of it is empty and useless
+ Glib::ustring layoutGuiName = (*(combo_.get_active()))[cols_.name];
+
+ // we get two signal, one of them is empty and useless
if (layoutGuiName.empty())
return;
- LyXTextClass const & tc = getTextClass(owner_);
- LyXTextClass::const_iterator it = tc.begin();
- LyXTextClass::const_iterator const end = tc.end();
- for (; it != end; ++it) {
- string const & name = (*it)->name();
- if (name == layoutGuiName) {
- owner_.getLyXFunc().dispatch(
- FuncRequest(LFUN_LAYOUT, name),
- true);
- return;
- }
- }
- lyxerr << "ERROR (GLayoutBox::selected): layout not found! name: "
- << layoutGuiName << std::endl;
+ layoutSelected(owner_, layoutGuiName);
}
} // namespace frontend
owner_.getBox(position).children().push_back(
Gtk::Box_Helpers::Element(toolbar_, Gtk::PACK_SHRINK));
-
- tooltips_.enable();
+
+ toolbar_.set_tooltips(true);
}
void GToolbar::add(FuncRequest const & func, string const & tooltip)
{
- switch (func.action) {
+ switch (func.action) {
case ToolbarBackend::SEPARATOR: {
Gtk::SeparatorToolItem * space =
Gtk::manage(new Gtk::SeparatorToolItem);
- toolbar_.insert(*space,-1);
- break;
+ toolbar_.append(*space);
+ break;
}
- case ToolbarBackend::MINIBUFFER:
- // Not supported yet.
- break;
+ case ToolbarBackend::MINIBUFFER:
+ // Not supported yet.
+ break;
case ToolbarBackend::LAYOUTS: {
layout_.reset(new GLayoutBox(owner_, toolbar_, func));
- break;
- }
+ break;
+ }
default: {
- Glib::ustring xpmName =
- Glib::locale_to_utf8(toolbarbackend.getIcon(func));
+ // choose an icon from the funcrequest
+ Gtk::BuiltinStockID stockID = getGTKStockIcon(func);
+
Glib::ustring tip = Glib::locale_to_utf8(tooltip);
+
Gtk::ToolButton * toolbutton;
- if (xpmName.size() == 0) {
- toolbutton = Gtk::manage(new Gtk::ToolButton);
+ if (stockID != Gtk::Stock::MISSING_IMAGE) {
+ // Prefer stock gtk graphics
+ Gtk::IconSize size(Gtk::ICON_SIZE_LARGE_TOOLBAR);
+ Gtk::Image * image = Gtk::manage(new Gtk::Image(stockID, size));
+ image->show();
+ toolbutton = Gtk::manage(new Gtk::ToolButton(*image));
} else {
+ Glib::ustring xpmName =
+ Glib::locale_to_utf8(toolbarbackend.getIcon(func));
Gtk::Image * image = Gtk::manage(new Gtk::Image(xpmName));
image->show();
toolbutton = Gtk::manage(new Gtk::ToolButton(*image));
}
+
// This code is putting a function reference into the GObject data field
- // named gToolData. That's how we know how to update the status of the
+ // named gToolData. That's how we know how to update the status of the
// toolitem later.
toolbutton->set_data(gToolData,
reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
- tooltips_.set_tip(*toolbutton, tip, tip);
+
+ toolbutton->set_tooltip(*toolbar_.get_tooltips_object(),tip);
+
toolbutton->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
- >oolbar::clicked), FuncRequest(func)));
- toolbar_.insert(*toolbutton,-1);
+ >oolbar::clicked), FuncRequest(func)));
+ toolbar_.append(*toolbutton);
break;
}
void GToolbar::clicked(FuncRequest func)
{
- owner_.getLyXFunc().dispatch(func, true);
+ owner_.getLyXFunc().dispatch(func);
}
void GToolbar::update()
{
- int items = toolbar_.get_n_items();
+ int const items = toolbar_.get_n_items();
for (int i = 0; i < items; ++i) {
Gtk::ToolItem * item = toolbar_.get_nth_item(i);