2003-09-02 10:29:05 +00:00
|
|
|
/**
|
|
|
|
* \file GToolbar.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Huang Ying
|
|
|
|
*
|
2003-09-02 17:02:32 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-09-02 10:29:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "GToolbar.h"
|
|
|
|
#include "GView.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
#include "bufferparams.h"
|
2003-09-02 10:29:05 +00:00
|
|
|
#include "debug.h"
|
2004-04-29 09:54:59 +00:00
|
|
|
#include "funcrequest.h"
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
#include "lyxfunc.h"
|
2003-09-02 10:29:05 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
2003-09-02 10:29:05 +00:00
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
namespace {
|
2003-09-02 10:29:05 +00:00
|
|
|
|
2004-04-27 14:48:13 +00:00
|
|
|
GView::Position getPosition(ToolbarBackend::Flags const & flags)
|
2004-04-29 09:54:59 +00:00
|
|
|
{
|
2004-04-27 14:48:13 +00:00
|
|
|
if (flags & ToolbarBackend::TOP)
|
|
|
|
return GView::Top;
|
|
|
|
if (flags & ToolbarBackend::BOTTOM)
|
|
|
|
return GView::Bottom;
|
|
|
|
if (flags & ToolbarBackend::LEFT)
|
|
|
|
return GView::Left;
|
|
|
|
if (flags & ToolbarBackend::RIGHT)
|
|
|
|
return GView::Right;
|
|
|
|
return GView::Top;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXTextClass const & getTextClass(LyXView const & lv)
|
|
|
|
{
|
|
|
|
return lv.buffer()->params().getLyXTextClass();
|
|
|
|
}
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
char const * gToolData = "tool_data";
|
2003-09-02 10:29:05 +00:00
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
} // namespace anon
|
2003-09-02 10:29:05 +00:00
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
GLayoutBox::GLayoutBox(LyXView & owner,
|
|
|
|
Gtk::Toolbar & toolbar,
|
|
|
|
FuncRequest const & func)
|
|
|
|
: owner_(owner),
|
|
|
|
internal_(false)
|
2003-09-02 10:29:05 +00:00
|
|
|
{
|
2004-10-01 18:41:16 +00:00
|
|
|
combo_.signal_changed().connect(
|
2004-09-26 16:48:30 +00:00
|
|
|
sigc::mem_fun(*this,&GLayoutBox::selected));
|
2004-04-29 09:54:59 +00:00
|
|
|
|
2004-10-01 18:41:16 +00:00
|
|
|
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);
|
|
|
|
|
2004-09-26 16:48:30 +00:00
|
|
|
|
|
|
|
combo_.set_data(
|
2004-04-29 09:54:59 +00:00
|
|
|
gToolData,
|
|
|
|
reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
|
2004-09-26 18:36:07 +00:00
|
|
|
|
2004-10-01 18:41:16 +00:00
|
|
|
combo_.show();
|
|
|
|
|
2004-09-26 16:48:30 +00:00
|
|
|
Gtk::ToolItem * toolitem = Gtk::manage(new Gtk::ToolItem);
|
|
|
|
toolitem->add(combo_);
|
2004-10-01 18:41:16 +00:00
|
|
|
toolbar.append(*toolitem);
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GLayoutBox::set(string const & layout)
|
|
|
|
{
|
|
|
|
LyXTextClass const & tc = getTextClass(owner_);
|
2004-10-01 18:41:16 +00:00
|
|
|
string const target = tc[layout]->name();
|
2003-09-02 10:29:05 +00:00
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
internal_ = true;
|
2004-10-01 18:41:16 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2004-04-29 09:54:59 +00:00
|
|
|
internal_ = false;
|
2004-10-01 18:41:16 +00:00
|
|
|
|
|
|
|
lyxerr << "ERROR (GLayoutBox::set): layout not found! name: "
|
|
|
|
<< target << std::endl;
|
2004-04-29 09:54:59 +00:00
|
|
|
}
|
2003-09-02 10:29:05 +00:00
|
|
|
|
2004-04-27 14:48:13 +00:00
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GLayoutBox::update()
|
|
|
|
{
|
2004-10-01 18:41:16 +00:00
|
|
|
clear();
|
2004-04-27 14:48:13 +00:00
|
|
|
|
2004-10-01 18:41:16 +00:00
|
|
|
LyXTextClass const & tc = getTextClass(owner_);
|
2004-04-27 14:48:13 +00:00
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
LyXTextClass::const_iterator it = tc.begin();
|
|
|
|
LyXTextClass::const_iterator const end = tc.end();
|
2004-10-01 18:41:16 +00:00
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
internal_ = true;
|
2004-10-01 18:41:16 +00:00
|
|
|
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());
|
|
|
|
}
|
2004-04-29 09:54:59 +00:00
|
|
|
internal_ = false;
|
2004-10-01 18:41:16 +00:00
|
|
|
|
|
|
|
//now that we've loaded something into the combobox, forget
|
|
|
|
//the initial fixed size and let GTK decide.
|
|
|
|
combo_.set_size_request(-1,-1);
|
2004-04-29 09:54:59 +00:00
|
|
|
}
|
2004-04-27 14:48:13 +00:00
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GLayoutBox::clear()
|
|
|
|
{
|
|
|
|
internal_ = true;
|
2004-10-01 18:41:16 +00:00
|
|
|
model_->clear();
|
2004-04-29 09:54:59 +00:00
|
|
|
internal_ = false;
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GLayoutBox::open()
|
2003-09-02 10:29:05 +00:00
|
|
|
{
|
2004-10-01 18:41:16 +00:00
|
|
|
combo_.popup();
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GLayoutBox::setEnabled(bool sensitive)
|
2003-09-02 10:29:05 +00:00
|
|
|
{
|
2004-04-29 09:54:59 +00:00
|
|
|
combo_.set_sensitive(sensitive);
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GLayoutBox::selected()
|
2003-09-02 10:29:05 +00:00
|
|
|
{
|
|
|
|
if (internal_)
|
|
|
|
return;
|
2004-04-29 09:54:59 +00:00
|
|
|
|
2004-10-01 18:41:16 +00:00
|
|
|
Glib::ustring layoutGuiName = (*(combo_.get_active()))[cols_.name];
|
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
// we get two signal, one of it is empty and useless
|
|
|
|
if (layoutGuiName.empty())
|
|
|
|
return;
|
2004-04-29 09:54:59 +00:00
|
|
|
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),
|
2003-09-02 10:29:05 +00:00
|
|
|
true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-04-29 09:54:59 +00:00
|
|
|
lyxerr << "ERROR (GLayoutBox::selected): layout not found! name: "
|
|
|
|
<< layoutGuiName << std::endl;
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-09-02 10:29:05 +00:00
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
Toolbars::ToolbarPtr make_toolbar(ToolbarBackend::Toolbar const & tbb,
|
|
|
|
LyXView & owner)
|
2003-09-02 10:29:05 +00:00
|
|
|
{
|
2004-05-19 15:11:37 +00:00
|
|
|
using lyx::frontend::GToolbar;
|
2004-04-29 09:54:59 +00:00
|
|
|
return Toolbars::ToolbarPtr(new GToolbar(tbb, owner));
|
|
|
|
}
|
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
GToolbar::GToolbar(ToolbarBackend::Toolbar const & tbb, LyXView & owner)
|
|
|
|
: owner_(dynamic_cast<GView &>(owner))
|
|
|
|
{
|
|
|
|
ToolbarBackend::item_iterator it = tbb.items.begin();
|
|
|
|
ToolbarBackend::item_iterator end = tbb.items.end();
|
|
|
|
for (; it != end; ++it)
|
|
|
|
add(it->first, it->second);
|
|
|
|
|
|
|
|
toolbar_.set_toolbar_style(Gtk::TOOLBAR_ICONS);
|
2004-09-26 16:48:30 +00:00
|
|
|
toolbar_.show_all();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
|
|
|
GView::Position const position = getPosition(tbb.flags);
|
|
|
|
|
|
|
|
if (position == GView::Left || position == GView::Right)
|
|
|
|
toolbar_.set_orientation(Gtk::ORIENTATION_VERTICAL);
|
2004-04-27 14:48:13 +00:00
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
owner_.getBox(position).children().push_back(
|
|
|
|
Gtk::Box_Helpers::Element(toolbar_, Gtk::PACK_SHRINK));
|
2004-09-26 18:36:07 +00:00
|
|
|
|
2004-09-26 16:48:30 +00:00
|
|
|
tooltips_.enable();
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GToolbar::add(FuncRequest const & func, string const & tooltip)
|
2003-09-02 10:29:05 +00:00
|
|
|
{
|
2004-09-26 18:36:07 +00:00
|
|
|
switch (func.action) {
|
2004-09-26 16:48:30 +00:00
|
|
|
case ToolbarBackend::SEPARATOR: {
|
|
|
|
Gtk::SeparatorToolItem * space =
|
|
|
|
Gtk::manage(new Gtk::SeparatorToolItem);
|
2004-10-01 18:41:16 +00:00
|
|
|
toolbar_.append(*space);
|
2004-09-26 18:36:07 +00:00
|
|
|
break;
|
2004-09-26 13:18:29 +00:00
|
|
|
}
|
2004-09-26 16:48:30 +00:00
|
|
|
|
2004-09-26 18:36:07 +00:00
|
|
|
case ToolbarBackend::MINIBUFFER:
|
|
|
|
// Not supported yet.
|
|
|
|
break;
|
2004-09-26 16:48:30 +00:00
|
|
|
|
|
|
|
case ToolbarBackend::LAYOUTS: {
|
|
|
|
layout_.reset(new GLayoutBox(owner_, toolbar_, func));
|
2004-09-26 18:36:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-09-26 16:48:30 +00:00
|
|
|
|
|
|
|
default: {
|
2004-04-29 09:54:59 +00:00
|
|
|
Glib::ustring xpmName =
|
|
|
|
Glib::locale_to_utf8(toolbarbackend.getIcon(func));
|
|
|
|
Glib::ustring tip = Glib::locale_to_utf8(tooltip);
|
2004-09-26 16:48:30 +00:00
|
|
|
Gtk::ToolButton * toolbutton;
|
2004-04-29 09:54:59 +00:00
|
|
|
if (xpmName.size() == 0) {
|
2004-09-26 16:48:30 +00:00
|
|
|
toolbutton = Gtk::manage(new Gtk::ToolButton);
|
2004-04-29 09:54:59 +00:00
|
|
|
} else {
|
2004-09-26 16:48:30 +00:00
|
|
|
Gtk::Image * image = Gtk::manage(new Gtk::Image(xpmName));
|
2004-04-29 09:54:59 +00:00
|
|
|
image->show();
|
2004-09-26 16:48:30 +00:00
|
|
|
toolbutton = Gtk::manage(new Gtk::ToolButton(*image));
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
2004-09-26 16:48:30 +00:00
|
|
|
// This code is putting a function reference into the GObject data field
|
2004-09-26 18:36:07 +00:00
|
|
|
// named gToolData. That's how we know how to update the status of the
|
2004-09-26 16:48:30 +00:00
|
|
|
// toolitem later.
|
|
|
|
toolbutton->set_data(gToolData,
|
2004-04-29 09:54:59 +00:00
|
|
|
reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
|
2004-09-26 16:48:30 +00:00
|
|
|
tooltips_.set_tip(*toolbutton, tip, tip);
|
|
|
|
toolbutton->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
|
2004-09-26 18:36:07 +00:00
|
|
|
>oolbar::clicked), FuncRequest(func)));
|
2004-10-01 18:41:16 +00:00
|
|
|
toolbar_.append(*toolbutton);
|
2004-04-29 09:54:59 +00:00
|
|
|
break;
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
2004-09-26 16:48:30 +00:00
|
|
|
|
|
|
|
}
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GToolbar::clicked(FuncRequest func)
|
2003-09-02 10:29:05 +00:00
|
|
|
{
|
2004-04-29 09:54:59 +00:00
|
|
|
owner_.getLyXFunc().dispatch(func, true);
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GToolbar::hide(bool)
|
2003-09-02 10:29:05 +00:00
|
|
|
{
|
2004-04-29 09:54:59 +00:00
|
|
|
toolbar_.hide();
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GToolbar::show(bool)
|
2003-09-02 10:29:05 +00:00
|
|
|
{
|
2004-04-29 09:54:59 +00:00
|
|
|
toolbar_.show();
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-29 09:54:59 +00:00
|
|
|
void GToolbar::update()
|
2003-09-02 10:29:05 +00:00
|
|
|
{
|
2004-09-27 00:08:33 +00:00
|
|
|
int const items = toolbar_.get_n_items();
|
2004-04-29 09:54:59 +00:00
|
|
|
|
2004-09-26 16:48:30 +00:00
|
|
|
for (int i = 0; i < items; ++i) {
|
|
|
|
Gtk::ToolItem * item = toolbar_.get_nth_item(i);
|
2004-04-29 09:54:59 +00:00
|
|
|
|
2004-09-26 16:48:30 +00:00
|
|
|
FuncRequest const * func = reinterpret_cast<FuncRequest *>(
|
|
|
|
item->get_data(gToolData));
|
|
|
|
if (func) {
|
|
|
|
FuncStatus const status = owner_.getLyXFunc().getStatus(*func);
|
|
|
|
item->set_sensitive(status.enabled());
|
|
|
|
}
|
2004-04-29 09:54:59 +00:00
|
|
|
}
|
2003-09-02 10:29:05 +00:00
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|