towards saner frontends. Part I: the toolbar

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7357 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2003-07-25 18:10:34 +00:00
parent 4ba8a4d6f6
commit 3501eef8f8
12 changed files with 135 additions and 136 deletions

View File

@ -13,35 +13,36 @@
#include "Toolbar.h"
#include "ToolbarBackend.h"
#include "Toolbar_pimpl.h"
#include "debug.h"
#include "LyXAction.h"
using std::endl;
Toolbar::Toolbar(LyXView * o, int x, int y)
Toolbar::Toolbar()
: last_textclass_(-1)
{
pimpl_ = new Pimpl(o, x, y);
// extracts the toolbars from the backend
ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
for (; cit != end; ++cit)
pimpl_->add(*cit);
}
Toolbar::~Toolbar()
{
delete pimpl_;
}
void Toolbar::init()
{
// extracts the toolbars from the backend
ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
for (; cit != end; ++cit)
add(*cit);
}
void Toolbar::update(bool in_math, bool in_table)
{
pimpl_->update();
update();
// extracts the toolbars from the backend
ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
@ -49,41 +50,20 @@ void Toolbar::update(bool in_math, bool in_table)
for (; cit != end; ++cit) {
if (cit->flags & ToolbarBackend::MATH)
pimpl_->displayToolbar(*cit, in_math);
displayToolbar(*cit, in_math);
else if (cit->flags & ToolbarBackend::TABLE)
pimpl_->displayToolbar(*cit, in_table);
displayToolbar(*cit, in_table);
}
}
void Toolbar::setLayout(string const & layout)
{
pimpl_->setLayout(layout);
}
bool Toolbar::updateLayoutList(int textclass)
{
// update the layout display
if (last_textclass_ != textclass) {
pimpl_->updateLayoutList(true);
updateLayoutList();
last_textclass_ = textclass;
return true;
} else {
pimpl_->updateLayoutList(false);
} else
return false;
}
}
void Toolbar::openLayoutList()
{
pimpl_->openLayoutList();
}
void Toolbar::clearLayoutList()
{
pimpl_->clearLayoutList();
}

View File

@ -14,10 +14,10 @@
#include "LString.h"
#include "ToolbarBackend.h"
class LyXView;
/**
* The LyX GUI independent toolbar class
*
@ -26,33 +26,43 @@ class LyXView;
class Toolbar {
public:
///
Toolbar(LyXView * o, int x, int y);
Toolbar();
///
~Toolbar();
///
virtual ~Toolbar();
/// Initialize toolbar from backend
void init();
/// update the state of the toolbars
void update(bool in_math, bool in_table);
/// update the layout combox
void setLayout(string const & layout);
virtual void setLayout(string const & layout) = 0;
/**
* Populate the layout combox - returns whether we did a full
* update or not
*/
bool updateLayoutList(int textclass);
/// Drop down the layout list
void openLayoutList();
virtual void openLayoutList() = 0;
/// Erase the layout list
void clearLayoutList();
virtual void clearLayoutList() = 0;
/// Compaq cxx 6.5 requires this to be public
struct Pimpl;
private:
///
friend struct Toolbar::Pimpl;
///
Pimpl * pimpl_;
virtual void add(ToolbarBackend::Toolbar const & tb) = 0;
/// update the state of the icons
virtual void update() = 0;
/// show or hide a toolbar
virtual void displayToolbar(ToolbarBackend::Toolbar const & tb,
bool show) = 0;
/// Populate the layout combox.
virtual void updateLayoutList() = 0;
/**
* The last textclass layout list in the layout choice selector

View File

@ -1,3 +1,13 @@
2003-07-25 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* QLToolbar.h:
* QLToolbar.C: derives from Toolbar (replaces Toolbar::Pimpl)
* Toolbar_pimpl.C:
* Toolbar_pimpl.h: removed
* QtView.C: modified because of changes above
2003-07-24 John Levon <levon@movementarian.org>
* QPrefs.C: make sure to correctly split a default

View File

@ -122,4 +122,4 @@ MOCFILES = \
QURLDialog.C QURLDialog.h \
QVCLogDialog.C QVCLogDialog.h \
QWrapDialog.C QWrapDialog.h \
Toolbar_pimpl.C Toolbar_pimpl.h
QLToolbar.C QLToolbar.h

View File

@ -1,10 +1,11 @@
/**
* \file qt2/Toolbar_pimpl.C
* \file qt2/QLToolbar.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
* \author John Levon
* \author Jean-Marc Lasgouttes
*
* Full author contact details are available in file CREDITS
*/
@ -28,7 +29,7 @@
#include <boost/tuple/tuple.hpp>
#include "QtView.h"
#include "Toolbar_pimpl.h"
#include "QLToolbar.h"
#include <qtoolbar.h>
#include <qcombobox.h>
@ -45,20 +46,15 @@ public:
};
Toolbar::Pimpl::Pimpl(LyXView * o, int, int)
QLToolbar::QLToolbar(LyXView * o)
: owner_(static_cast<QtView *>(o)),
combo_(0)
combo_(0)
{
proxy_.reset(new ToolbarProxy(*this));
}
Toolbar::Pimpl::~Pimpl()
{
}
void Toolbar::Pimpl::displayToolbar(ToolbarBackend::Toolbar const & tb, bool show)
void QLToolbar::displayToolbar(ToolbarBackend::Toolbar const & tb, bool show)
{
QToolBar * qtb = toolbars_[tb.name];
if (show) {
@ -69,7 +65,7 @@ void Toolbar::Pimpl::displayToolbar(ToolbarBackend::Toolbar const & tb, bool sho
}
void Toolbar::Pimpl::update()
void QLToolbar::update()
{
ButtonMap::const_iterator p = map_.begin();
ButtonMap::const_iterator end = map_.end();
@ -95,7 +91,7 @@ void Toolbar::Pimpl::update()
}
void Toolbar::Pimpl::button_selected(QToolButton * button)
void QLToolbar::button_selected(QToolButton * button)
{
ButtonMap::const_iterator cit = map_.find(button);
@ -108,7 +104,7 @@ void Toolbar::Pimpl::button_selected(QToolButton * button)
}
void Toolbar::Pimpl::changed_layout(string const & sel)
void QLToolbar::changed_layout(string const & sel)
{
owner_->centralWidget()->setFocus();
@ -124,12 +120,12 @@ void Toolbar::Pimpl::changed_layout(string const & sel)
return;
}
}
lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
lyxerr << "ERROR (QLToolbar::layoutSelected): layout not found!"
<< endl;
}
void Toolbar::Pimpl::setLayout(string const & layout)
void QLToolbar::setLayout(string const & layout)
{
if (!combo_)
return;
@ -155,15 +151,11 @@ void Toolbar::Pimpl::setLayout(string const & layout)
}
void Toolbar::Pimpl::updateLayoutList(bool force)
void QLToolbar::updateLayoutList()
{
if (!combo_)
return;
// if we don't need an update, don't ...
if (combo_->count() && !force)
return;
LyXTextClass const & tc =
owner_->buffer()->params.getLyXTextClass();
@ -189,7 +181,7 @@ void Toolbar::Pimpl::updateLayoutList(bool force)
}
void Toolbar::Pimpl::clearLayoutList()
void QLToolbar::clearLayoutList()
{
if (!combo_)
return;
@ -198,7 +190,7 @@ void Toolbar::Pimpl::clearLayoutList()
}
void Toolbar::Pimpl::openLayoutList()
void QLToolbar::openLayoutList()
{
if (!combo_)
return;
@ -225,7 +217,7 @@ QMainWindow::ToolBarDock getPosition(ToolbarBackend::Flags const & flags)
};
void Toolbar::Pimpl::add(ToolbarBackend::Toolbar const & tb)
void QLToolbar::add(ToolbarBackend::Toolbar const & tb)
{
QToolBar * qtb = new QToolBar(qt_(tb.name), owner_, getPosition(tb.flags));
// give visual separation between adjacent toolbars
@ -242,7 +234,7 @@ void Toolbar::Pimpl::add(ToolbarBackend::Toolbar const & tb)
}
void Toolbar::Pimpl::add(QToolBar * tb, int action, string const & tooltip)
void QLToolbar::add(QToolBar * tb, int action, string const & tooltip)
{
switch (action) {
case ToolbarBackend::SEPARATOR:

View File

@ -5,16 +5,16 @@
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
* \author John Levon
* \author Jean-Marc Lasgouttes
*
* Full author contact details are available in file CREDITS
*/
#ifndef TOOLBAR_PIMPL_H
#define TOOLBAR_PIMPL_H
#ifndef QLTOOLBAR__H
#define QLTOOLBAR_H
#include "frontends/Toolbar.h"
#include "ToolbarBackend.h"
#include "qt_helpers.h"
@ -30,13 +30,11 @@ class QToolBar;
class QLComboBox;
class ToolbarProxy;
struct Toolbar::Pimpl {
class QLToolbar : public Toolbar {
public:
friend class ToolbarProxy;
Pimpl(LyXView * o, int x, int y);
~Pimpl();
QLToolbar(LyXView * o);
/// add a new toolbar
void add(ToolbarBackend::Toolbar const & tb);
@ -52,8 +50,8 @@ public:
/// select the right layout in the combox
void setLayout(string const & layout);
/// Populate the layout combox; re-do everything if force is true.
void updateLayoutList(bool force);
/// Populate the layout combox.
void updateLayoutList();
/// Drop down the layout list
void openLayoutList();
/// Erase the layout list
@ -81,7 +79,7 @@ private:
class ToolbarProxy : public QObject {
Q_OBJECT
public:
ToolbarProxy(Toolbar::Pimpl & owner)
ToolbarProxy(QLToolbar & owner)
: owner_(owner) {}
public slots:
@ -96,7 +94,7 @@ public slots:
);
}
private:
Toolbar::Pimpl & owner_;
QLToolbar & owner_;
};
#endif

View File

@ -21,7 +21,6 @@
#include "lyxfunc.h"
#include "BufferView.h"
#include "frontends/Toolbar.h"
#include "frontends/Menubar.h"
#include "frontends/Dialogs.h"
#include "frontends/Timeout.h"
@ -29,6 +28,7 @@
#include <boost/bind.hpp>
#include "QtView.h"
#include "QLToolbar.h"
#include "qfont_loader.h"
#include "QCommandBuffer.h"
#include "qt_helpers.h"
@ -62,7 +62,8 @@ QtView::QtView(unsigned int width, unsigned int height)
bufferview_.reset(new BufferView(this, 0, 0, width, height));
menubar_.reset(new Menubar(this, menubackend));
toolbar_.reset(new Toolbar(this, 0, 0));
toolbar_.reset(new QLToolbar(this));
toolbar_->init();
statusBar()->setSizeGripEnabled(false);

View File

@ -1,3 +1,11 @@
2003-07-25 Jean-Marc Lasgouttes <lasgouttes@lyx.org> <lyx@htwm.de>
*
2003-07-25 Jean-Marc Lasgouttes <lasgoutes@lyx.org>
* XFormsToolbar.h:
2003-07-23 Angus Leeming <leeming@lyx.org>
* FormColorpicker.[Ch]

View File

@ -155,8 +155,8 @@ libxforms_la_SOURCES = \
Menubar_pimpl.h \
RadioButtonGroup.C \
RadioButtonGroup.h \
Toolbar_pimpl.C \
Toolbar_pimpl.h \
XFormsToolbar.C \
XFormsToolbar.h \
Tooltips.C \
Tooltips.h \
WorkAreaFactory.C \

View File

@ -1,9 +1,10 @@
/**
* \file xforms/Toolbar_pimpl.C
* \file xforms/XFormsToolbar.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
*
* Full author contact details are available in file CREDITS
*/
@ -13,7 +14,7 @@
#include <config.h>
#include "Toolbar_pimpl.h"
#include "XFormsToolbar.h"
#include "debug.h"
#include "XFormsView.h"
#include "lyxfunc.h"
@ -40,12 +41,12 @@ 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
Toolbar::Pimpl::toolbarItem::toolbarItem()
XFormsToolbar::toolbarItem::toolbarItem()
: action(LFUN_NOACTION), icon(0)
{}
Toolbar::Pimpl::toolbarItem::~toolbarItem()
XFormsToolbar::toolbarItem::~toolbarItem()
{
// Lars said here that ~XFormsView() dealt with the icons.
// This is not true. But enabling this causes crashes,
@ -57,12 +58,12 @@ Toolbar::Pimpl::toolbarItem::~toolbarItem()
/// Display toolbar, not implemented. But moved out of line so that
/// linking will work properly.
void Toolbar::Pimpl::displayToolbar(ToolbarBackend::Toolbar const & /*tb*/,
void XFormsToolbar::displayToolbar(ToolbarBackend::Toolbar const & /*tb*/,
bool /*show*/)
{}
void Toolbar::Pimpl::toolbarItem::kill_icon()
void XFormsToolbar::toolbarItem::kill_icon()
{
if (icon) {
fl_delete_object(icon);
@ -72,8 +73,8 @@ void Toolbar::Pimpl::toolbarItem::kill_icon()
}
Toolbar::Pimpl::toolbarItem &
Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
XFormsToolbar::toolbarItem &
XFormsToolbar::toolbarItem::operator=(toolbarItem const & ti)
{
if (this == &ti)
return *this;
@ -89,14 +90,14 @@ Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
Toolbar::Pimpl::Pimpl(LyXView * o, int x, int y)
XFormsToolbar::XFormsToolbar(LyXView * o, int x, int y)
: owner_(static_cast<XFormsView *>(o)), combox_(0), xpos(x), ypos(y)
{
tooltip_ = new Tooltips();
}
Toolbar::Pimpl::~Pimpl()
XFormsToolbar::~XFormsToolbar()
{
fl_freeze_form(owner_->getForm());
@ -109,7 +110,7 @@ Toolbar::Pimpl::~Pimpl()
}
void Toolbar::Pimpl::update()
void XFormsToolbar::update()
{
ToolbarList::const_iterator p = toollist_.begin();
ToolbarList::const_iterator end = toollist_.end();
@ -156,14 +157,14 @@ void C_layoutSelectedCB(FL_OBJECT * ob, long)
{
if (!ob || !ob->u_vdata)
return;
Toolbar::Pimpl * ptr = static_cast<Toolbar::Pimpl *>(ob->u_vdata);
XFormsToolbar * ptr = static_cast<XFormsToolbar *>(ob->u_vdata);
ptr->layoutSelected();
}
} // namespace anon
void Toolbar::Pimpl::layoutSelected()
void XFormsToolbar::layoutSelected()
{
if (!combox_)
return;
@ -180,12 +181,12 @@ void Toolbar::Pimpl::layoutSelected()
return;
}
}
lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
lyxerr << "ERROR (XFormsToolbar::layoutSelected): layout not found!"
<< endl;
}
void Toolbar::Pimpl::setLayout(string const & layout)
void XFormsToolbar::setLayout(string const & layout)
{
if (!combox_)
return;
@ -204,32 +205,29 @@ void Toolbar::Pimpl::setLayout(string const & layout)
}
void Toolbar::Pimpl::updateLayoutList(bool force)
void XFormsToolbar::updateLayoutList()
{
if (!combox_)
return;
// If textclass is different, we need to update the list
if (fl_get_combox_maxitems(combox_) == 0 || force) {
fl_clear_combox(combox_);
LyXTextClass const & tc =
owner_->buffer()->params.getLyXTextClass();
LyXTextClass::const_iterator end = tc.end();
for (LyXTextClass::const_iterator cit = tc.begin();
cit != end; ++cit) {
// ignore obsolete entries
if ((*cit)->obsoleted_by().empty()) {
string const & name = _((*cit)->name());
fl_addto_combox(combox_, name.c_str());
}
fl_clear_combox(combox_);
LyXTextClass const & tc = owner_->buffer()->params.getLyXTextClass();
LyXTextClass::const_iterator end = tc.end();
for (LyXTextClass::const_iterator cit = tc.begin();
cit != end; ++cit) {
// ignore obsolete entries
if ((*cit)->obsoleted_by().empty()) {
string const & name = _((*cit)->name());
fl_addto_combox(combox_, name.c_str());
}
}
// we need to do this.
fl_redraw_object(combox_);
}
void Toolbar::Pimpl::clearLayoutList()
void XFormsToolbar::clearLayoutList()
{
if (!combox_)
return;
@ -239,7 +237,7 @@ void Toolbar::Pimpl::clearLayoutList()
}
void Toolbar::Pimpl::openLayoutList()
void XFormsToolbar::openLayoutList()
{
if (!combox_)
return;
@ -270,7 +268,7 @@ void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
} // namespace anon
void Toolbar::Pimpl::add(ToolbarBackend::Toolbar const & tb)
void XFormsToolbar::add(ToolbarBackend::Toolbar const & tb)
{
// we can only handle one toolbar
if (!toollist_.empty())
@ -283,7 +281,7 @@ void Toolbar::Pimpl::add(ToolbarBackend::Toolbar const & tb)
}
void Toolbar::Pimpl::add(int action, string const & tooltip)
void XFormsToolbar::add(int action, string const & tooltip)
{
toolbarItem item;
item.action = action;

View File

@ -1,16 +1,17 @@
// -*- C++ -*-
/**
* \file xforms/Toolbar_pimpl.h
* \file xforms/XFormsToolbar.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
*
* Full author contact details are available in file CREDITS
*/
#ifndef TOOLBAR_PIMPL_H
#define TOOLBAR_PIMPL_H
#ifndef XFORMSTOOLBAR_H
#define XFROMSTOOLBAR_H
#include <vector>
#include "forms_fwd.h"
@ -18,18 +19,18 @@
#include "frontends/Toolbar.h"
#include "ToolbarBackend.h"
class XFormsView;
class Tooltips;
/** The LyX xforms toolbar class
*/
struct Toolbar::Pimpl {
class XFormsToolbar : public Toolbar {
public:
/// create an empty toolbar
Pimpl(LyXView * o, int x, int y);
XFormsToolbar(LyXView * o, int x, int y);
~Pimpl();
///
~XFormsToolbar();
/// add a new toolbar
void add(ToolbarBackend::Toolbar const & tb);
@ -45,8 +46,8 @@ public:
/// select the right layout in the combox
void setLayout(string const & layout);
/// Populate the layout combox; re-do everything if force is true.
void updateLayoutList(bool force);
/// Populate the layout combox.
void updateLayoutList();
/// Drop down the layout list
void openLayoutList();
/// Erase the layout list
@ -88,4 +89,4 @@ public:
int ypos;
};
#endif // TOOLBAR_PIMPL_H
#endif

View File

@ -15,11 +15,11 @@
#include "lyx_forms.h"
#include "XMiniBuffer.h"
#include "XFormsToolbar.h"
#include "debug.h"
#include "intl.h"
#include "lyxrc.h"
#include "support/filetools.h" // OnlyFilename()
#include "frontends/Toolbar.h"
#include "frontends/Menubar.h"
#include "frontends/Timeout.h"
#include "frontends/Dialogs.h"
@ -142,7 +142,8 @@ void XFormsView::create_form_form_main(int width, int height)
menubar_.reset(new Menubar(this, menubackend));
toolbar_.reset(new Toolbar(this, air, 30 + air + bw));
toolbar_.reset(new XFormsToolbar(this, air, 30 + air + bw));
toolbar_->init();
int const ywork = 60 + 2 * air + bw;
int const workheight = height - ywork - (25 + 2 * air);