2002-03-11 17:00:41 +00:00
|
|
|
|
/**
|
2002-09-26 08:57:43 +00:00
|
|
|
|
* \file xforms/Toolbar_pimpl.C
|
2002-03-11 17:00:41 +00:00
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
|
* Copyright 1996-1998 Lars Gullik Bj<EFBFBD>nnes
|
2002-09-05 15:14:23 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
1999-10-07 18:44:17 +00:00
|
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-03-11 17:00:41 +00:00
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Added pseudo-action handling, asierra 180296
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
2000-07-24 13:53:19 +00:00
|
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
#include "Toolbar_pimpl.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2001-07-03 15:19:04 +00:00
|
|
|
|
#include "XFormsView.h"
|
2001-04-24 17:33:01 +00:00
|
|
|
|
#include "lyxfunc.h"
|
2002-01-09 09:36:35 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2000-07-24 13:53:19 +00:00
|
|
|
|
#include "buffer.h"
|
2002-08-07 08:11:41 +00:00
|
|
|
|
#include "funcrequest.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include "gettext.h"
|
2002-03-11 09:54:42 +00:00
|
|
|
|
#include "Tooltips.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
|
#include FORMS_H_LOCATION
|
2002-07-21 21:21:06 +00:00
|
|
|
|
#include "combox.h"
|
|
|
|
|
#include "ToolbarDefaults.h"
|
2002-08-07 08:11:41 +00:00
|
|
|
|
#include "LyXAction.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2002-03-11 09:54:42 +00:00
|
|
|
|
#include "support/LAssert.h"
|
2000-07-19 10:22:12 +00:00
|
|
|
|
#include "support/filetools.h"
|
2002-03-21 21:21:28 +00:00
|
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2000-02-15 14:28:15 +00:00
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
// some constants
|
|
|
|
|
const int standardspacing = 2; // the usual space between items
|
|
|
|
|
const int sepspace = 6; // extra space
|
|
|
|
|
const int buttonwidth = 30; // the standard button width
|
|
|
|
|
const int height = 30; // the height of all items in the toolbar
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
Toolbar::Pimpl::toolbarItem::toolbarItem()
|
2002-07-22 20:52:40 +00:00
|
|
|
|
: action(LFUN_NOACTION), icon(0)
|
2002-08-14 10:18:33 +00:00
|
|
|
|
{}
|
2000-07-21 18:47:54 +00:00
|
|
|
|
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
Toolbar::Pimpl::toolbarItem::~toolbarItem()
|
|
|
|
|
{
|
2002-07-22 20:52:40 +00:00
|
|
|
|
// Lars said here that ~XFormsView() dealt with the icons.
|
|
|
|
|
// This is not true. But enabling this causes crashes,
|
|
|
|
|
// because somehow we kill the same icon twice :(
|
|
|
|
|
// FIXME
|
|
|
|
|
//kill_icon();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-22 20:52:40 +00:00
|
|
|
|
void Toolbar::Pimpl::toolbarItem::kill_icon()
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2000-07-21 18:47:54 +00:00
|
|
|
|
if (icon) {
|
|
|
|
|
fl_delete_object(icon);
|
|
|
|
|
fl_free_object(icon);
|
|
|
|
|
icon = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
|
Toolbar::Pimpl::toolbarItem &
|
2001-12-28 13:26:54 +00:00
|
|
|
|
Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
|
|
|
|
|
{
|
2000-07-31 12:51:19 +00:00
|
|
|
|
if (this == &ti)
|
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
|
|
// If we already have an icon, release it.
|
2002-07-22 20:52:40 +00:00
|
|
|
|
// But we don't copy the icon from ti
|
|
|
|
|
kill_icon();
|
|
|
|
|
|
2000-07-21 18:47:54 +00:00
|
|
|
|
action = ti.action;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2000-07-21 18:47:54 +00:00
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
|
Toolbar::Pimpl::Pimpl(LyXView * o, int x, int y)
|
2002-07-22 20:52:40 +00:00
|
|
|
|
: owner_(static_cast<XFormsView *>(o)), xpos(x), ypos(y)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-22 20:52:40 +00:00
|
|
|
|
combox_ = 0;
|
2002-08-12 14:28:43 +00:00
|
|
|
|
tooltip_ = new Tooltips();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-11 09:54:42 +00:00
|
|
|
|
Toolbar::Pimpl::~Pimpl()
|
1999-10-25 14:18:30 +00:00
|
|
|
|
{
|
2002-07-22 20:52:40 +00:00
|
|
|
|
fl_freeze_form(owner_->getForm());
|
|
|
|
|
|
|
|
|
|
// G++ vector does not have clear defined
|
|
|
|
|
//toollist.clear();
|
|
|
|
|
toollist_.erase(toollist_.begin(), toollist_.end());
|
|
|
|
|
|
|
|
|
|
delete combox_;
|
|
|
|
|
|
|
|
|
|
fl_unfreeze_form(owner_->getForm());
|
2002-03-11 09:54:42 +00:00
|
|
|
|
delete tooltip_;
|
2001-09-10 08:37:25 +00:00
|
|
|
|
}
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
void Toolbar::Pimpl::update()
|
2000-07-20 11:39:14 +00:00
|
|
|
|
{
|
2002-07-22 20:52:40 +00:00
|
|
|
|
ToolbarList::const_iterator p = toollist_.begin();
|
|
|
|
|
ToolbarList::const_iterator end = toollist_.end();
|
2000-08-03 21:17:52 +00:00
|
|
|
|
for (; p != end; ++p) {
|
2002-07-22 20:52:40 +00:00
|
|
|
|
if (p->action == ToolbarDefaults::LAYOUTS && combox_) {
|
2002-08-13 14:40:38 +00:00
|
|
|
|
if (owner_->getLyXFunc().getStatus(LFUN_LAYOUT).disabled())
|
2002-07-22 20:52:40 +00:00
|
|
|
|
combox_->deactivate();
|
2002-01-20 23:17:17 +00:00
|
|
|
|
else
|
2002-07-22 20:52:40 +00:00
|
|
|
|
combox_->activate();
|
|
|
|
|
continue;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-07-22 20:52:40 +00:00
|
|
|
|
|
|
|
|
|
if (!p->icon)
|
|
|
|
|
continue;
|
|
|
|
|
|
2002-08-13 14:40:38 +00:00
|
|
|
|
FuncStatus const status = owner_->getLyXFunc().getStatus(p->action);
|
2002-07-22 20:52:40 +00:00
|
|
|
|
if (status.onoff(true)) {
|
|
|
|
|
// I'd like to use a different color
|
|
|
|
|
// here, but then the problem is to
|
|
|
|
|
// know how to use transparency with
|
|
|
|
|
// Xpm library. It seems pretty
|
|
|
|
|
// complicated to me (JMarc)
|
|
|
|
|
fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
|
|
|
|
|
fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
|
|
|
|
|
} else {
|
|
|
|
|
fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
|
|
|
|
|
fl_set_object_boxtype(p->icon, FL_UP_BOX);
|
|
|
|
|
}
|
|
|
|
|
if (status.disabled()) {
|
|
|
|
|
// Is there a way here to specify a
|
|
|
|
|
// mask in order to show that the
|
|
|
|
|
// button is disabled? (JMarc)
|
|
|
|
|
fl_deactivate_object(p->icon);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
fl_activate_object(p->icon);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-07 15:41:36 +00:00
|
|
|
|
// this one is not "C" because combox callbacks are really C++ %-|
|
|
|
|
|
void Toolbar::Pimpl::layoutSelectedCB(int, void * arg, Combox *)
|
|
|
|
|
{
|
2002-08-07 08:11:41 +00:00
|
|
|
|
reinterpret_cast<Toolbar::Pimpl *>(arg)->layoutSelected();
|
2001-09-07 15:41:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbar::Pimpl::layoutSelected()
|
|
|
|
|
{
|
2002-07-22 20:52:40 +00:00
|
|
|
|
string const & layoutguiname = combox_->getline();
|
2001-09-07 15:41:36 +00:00
|
|
|
|
LyXTextClass const & tc =
|
2002-07-22 20:52:40 +00:00
|
|
|
|
owner_->buffer()->params.getLyXTextClass();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2001-09-07 15:41:36 +00:00
|
|
|
|
LyXTextClass::const_iterator end = tc.end();
|
|
|
|
|
for (LyXTextClass::const_iterator cit = tc.begin();
|
|
|
|
|
cit != end; ++cit) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (_((*cit)->name()) == layoutguiname) {
|
2002-09-17 12:29:40 +00:00
|
|
|
|
owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()), true);
|
2001-09-07 15:41:36 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2001-09-07 15:41:36 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
void Toolbar::Pimpl::setLayout(string const & layout)
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2002-07-22 20:52:40 +00:00
|
|
|
|
if (combox_) {
|
2001-09-06 12:42:47 +00:00
|
|
|
|
LyXTextClass const & tc =
|
2002-07-22 20:52:40 +00:00
|
|
|
|
owner_->buffer()->params.getLyXTextClass();
|
|
|
|
|
combox_->select(_(tc[layout]->name()));
|
2001-09-06 12:42:47 +00:00
|
|
|
|
}
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Toolbar::Pimpl::updateLayoutList(bool force)
|
|
|
|
|
{
|
|
|
|
|
// Update the layout display
|
2002-07-22 20:52:40 +00:00
|
|
|
|
if (!combox_) return;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
|
|
|
|
// If textclass is different, we need to update the list
|
2002-07-22 20:52:40 +00:00
|
|
|
|
if (combox_->empty() || force) {
|
|
|
|
|
combox_->clear();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
LyXTextClass const & tc =
|
2002-07-22 20:52:40 +00:00
|
|
|
|
owner_->buffer()->params.getLyXTextClass();
|
2000-08-03 21:17:52 +00:00
|
|
|
|
LyXTextClass::const_iterator end = tc.end();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
for (LyXTextClass::const_iterator cit = tc.begin();
|
2000-08-03 21:17:52 +00:00
|
|
|
|
cit != end; ++cit) {
|
2001-09-06 12:42:47 +00:00
|
|
|
|
// ignore obsolete entries
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if ((*cit)->obsoleted_by().empty())
|
2002-07-22 20:52:40 +00:00
|
|
|
|
combox_->addline(_((*cit)->name()));
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// we need to do this.
|
2002-07-22 20:52:40 +00:00
|
|
|
|
combox_->redraw();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
void Toolbar::Pimpl::clearLayoutList()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-22 20:52:40 +00:00
|
|
|
|
if (combox_) {
|
|
|
|
|
combox_->clear();
|
|
|
|
|
combox_->redraw();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
void Toolbar::Pimpl::openLayoutList()
|
|
|
|
|
{
|
2002-07-22 20:52:40 +00:00
|
|
|
|
if (combox_)
|
|
|
|
|
combox_->show();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
void ToolbarCB(FL_OBJECT * ob, long ac)
|
|
|
|
|
{
|
2001-07-03 15:19:04 +00:00
|
|
|
|
XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2002-08-13 14:40:38 +00:00
|
|
|
|
owner->getLyXFunc().dispatch(int(ac), true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
|
extern "C" {
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
|
static
|
|
|
|
|
void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
|
|
|
|
|
{
|
|
|
|
|
ToolbarCB(ob, data);
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
|
2002-08-29 08:28:58 +00:00
|
|
|
|
void setPixmap(FL_OBJECT * obj, int action)
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
|
|
|
|
string xpm_name;
|
2002-08-14 10:16:05 +00:00
|
|
|
|
FuncRequest ev = lyxaction.retrieveActionArg(action);
|
2002-08-08 22:03:30 +00:00
|
|
|
|
|
2002-08-14 10:16:05 +00:00
|
|
|
|
string const name = lyxaction.getActionName(ev.action);
|
|
|
|
|
if (!ev.argument.empty())
|
|
|
|
|
xpm_name = subst(name + ' ' + ev.argument, ' ','_');
|
2002-03-21 21:21:28 +00:00
|
|
|
|
else
|
2000-07-19 10:22:12 +00:00
|
|
|
|
xpm_name = name;
|
|
|
|
|
|
|
|
|
|
string fullname = LibFileSearch("images", xpm_name, "xpm");
|
|
|
|
|
|
2002-08-29 08:28:58 +00:00
|
|
|
|
if (ev.action == LFUN_INSERT_MATH && !ev.argument.empty()) {
|
|
|
|
|
string arg = ev.argument.substr(1);
|
|
|
|
|
fullname = LibFileSearch("images/math/", arg, "xpm");
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-19 10:22:12 +00:00
|
|
|
|
if (!fullname.empty()) {
|
2002-03-21 21:21:28 +00:00
|
|
|
|
lyxerr[Debug::GUI] << "Full icon name is `"
|
2002-03-21 16:59:12 +00:00
|
|
|
|
<< fullname << "'" << endl;
|
2000-07-19 10:22:12 +00:00
|
|
|
|
fl_set_pixmapbutton_file(obj, fullname.c_str());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
|
|
|
|
|
fullname = LibFileSearch("images", "unknown", "xpm");
|
|
|
|
|
if (!fullname.empty()) {
|
2002-03-21 21:21:28 +00:00
|
|
|
|
lyxerr[Debug::GUI] << "Using default `unknown' icon"
|
2002-03-21 16:59:12 +00:00
|
|
|
|
<< endl;
|
2000-07-19 10:22:12 +00:00
|
|
|
|
fl_set_pixmapbutton_file(obj, fullname.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2002-07-22 20:52:40 +00:00
|
|
|
|
void Toolbar::Pimpl::add(int action)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-12-01 00:57:31 +00:00
|
|
|
|
FL_OBJECT * obj;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2002-07-22 20:52:40 +00:00
|
|
|
|
toolbarItem item;
|
|
|
|
|
item.action = action;
|
|
|
|
|
|
|
|
|
|
switch (action) {
|
|
|
|
|
case ToolbarDefaults::SEPARATOR:
|
|
|
|
|
xpos += sepspace;
|
|
|
|
|
break;
|
|
|
|
|
case ToolbarDefaults::NEWLINE:
|
|
|
|
|
// Not supported yet.
|
|
|
|
|
break;
|
|
|
|
|
case ToolbarDefaults::LAYOUTS:
|
|
|
|
|
xpos += standardspacing;
|
|
|
|
|
if (!combox_)
|
|
|
|
|
combox_ = new Combox(FL_COMBOX_DROPLIST);
|
|
|
|
|
combox_->add(xpos, ypos, 135, height, 400);
|
|
|
|
|
combox_->setcallback(layoutSelectedCB, this);
|
|
|
|
|
combox_->resize(FL_RESIZE_ALL);
|
|
|
|
|
combox_->gravity(NorthWestGravity, NorthWestGravity);
|
|
|
|
|
xpos += 135;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
xpos += standardspacing;
|
|
|
|
|
item.icon = obj =
|
|
|
|
|
fl_add_pixmapbutton(FL_NORMAL_BUTTON,
|
|
|
|
|
xpos, ypos,
|
|
|
|
|
buttonwidth,
|
|
|
|
|
height, "");
|
|
|
|
|
fl_set_object_resize(obj, FL_RESIZE_ALL);
|
|
|
|
|
fl_set_object_gravity(obj,
|
|
|
|
|
NorthWestGravity,
|
|
|
|
|
NorthWestGravity);
|
|
|
|
|
fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
|
|
|
|
|
static_cast<long>(action));
|
|
|
|
|
// Remove the blue feedback rectangle
|
|
|
|
|
fl_set_pixmapbutton_focus_outline(obj, 0);
|
|
|
|
|
|
|
|
|
|
// initialise the tooltip
|
|
|
|
|
string const tip = _(lyxaction.helpText(obj->argument));
|
|
|
|
|
tooltip_->init(obj, tip);
|
|
|
|
|
|
|
|
|
|
// The view that this object belongs to.
|
|
|
|
|
obj->u_vdata = owner_;
|
|
|
|
|
|
2002-08-29 08:28:58 +00:00
|
|
|
|
setPixmap(obj, action);
|
2002-07-22 20:52:40 +00:00
|
|
|
|
// we must remember to update the positions
|
|
|
|
|
xpos += buttonwidth;
|
|
|
|
|
// ypos is constant
|
|
|
|
|
/* Here will come a check to see if the new
|
|
|
|
|
* pos is within the bounds of the main frame,
|
|
|
|
|
* and perhaps wrap the toolbar if not.
|
|
|
|
|
*/
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-07-22 20:52:40 +00:00
|
|
|
|
|
|
|
|
|
toollist_.push_back(item);
|
2000-07-24 13:53:19 +00:00
|
|
|
|
}
|