Pragmatic pimpl-ing of BufferParams.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7721 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-09-09 17:00:19 +00:00
parent ccc118437a
commit f9c1cafbe6
24 changed files with 420 additions and 168 deletions

View File

@ -42,6 +42,7 @@
#include "ParagraphParameters.h"
#include "TextCache.h"
#include "undo_funcs.h"
#include "vspace.h"
#include "insets/insetfloatlist.h"
#include "insets/insetref.h"

View File

@ -200,7 +200,7 @@ void InsetList::insetsOpenCloseBranch(BufferView * bv)
for (; it != end; ++it) {
if (it->inset && it->inset->lyxCode() == InsetOld::BRANCH_CODE) {
InsetBranch * inset = static_cast<InsetBranch *>(it->inset);
if (bp.branchlist.selected(inset->params().branch)) {
if (bp.branchlist().selected(inset->params().branch)) {
inset->open(bv);
} else {
inset->close(bv);

View File

@ -259,12 +259,12 @@ string const LaTeXFeatures::getPackages() const
}
// setspace.sty
if ((params.spacing.getSpace() != Spacing::Single
&& !params.spacing.isDefault())
if ((params.spacing().getSpace() != Spacing::Single
&& !params.spacing().isDefault())
|| isRequired("setspace")) {
packages << "\\usepackage{setspace}\n";
}
switch (params.spacing.getSpace()) {
switch (params.spacing().getSpace()) {
case Spacing::Default:
case Spacing::Single:
// we dont use setspace.sty so dont print anything
@ -278,7 +278,7 @@ string const LaTeXFeatures::getPackages() const
break;
case Spacing::Other:
packages << "\\setstretch{"
<< params.spacing.getValue() << "}\n";
<< params.spacing().getValue() << "}\n";
break;
}

View File

@ -16,27 +16,31 @@
#include <config.h>
#include "MenuBackend.h"
#include "bufferparams.h"
#include "lyxlex.h"
#include "LyXAction.h"
#include "debug.h"
#include "gettext.h"
#include "kbmap.h"
#include "lastfiles.h"
#include "lyxfunc.h"
#include "lyx_main.h" // for lastfiles
#include "bufferlist.h"
#include "BranchList.h"
#include "buffer.h"
#include "format.h"
#include "bufferlist.h"
#include "bufferparams.h"
#include "CutAndPaste.h"
#include "debug.h"
#include "exporter.h"
#include "importer.h"
#include "Floating.h"
#include "FloatList.h"
#include "format.h"
#include "gettext.h"
#include "importer.h"
#include "kbmap.h"
#include "lastfiles.h"
#include "LyXAction.h"
#include "lyx_main.h" // for lastfiles
#include "lyxfunc.h"
#include "lyxlex.h"
#include "toc.h"
#include "CutAndPaste.h"
#include "frontends/LyXView.h"
#include "support/LAssert.h"
#include "support/filetools.h"
#include "support/LAssert.h"
#include "support/lyxfunctional.h"
#include "support/lstrings.h"
#include "support/tostr.h"
@ -658,8 +662,8 @@ void expandBranches(Menu & tomenu, LyXView const * view)
BufferParams const & params = view->buffer()->params();
std::list<Branch>::const_iterator cit = params.branchlist.begin();
std::list<Branch>::const_iterator end = params.branchlist.end();
std::list<Branch>::const_iterator cit = params.branchlist().begin();
std::list<Branch>::const_iterator end = params.branchlist().end();
for (int ii = 1; cit != end; ++cit, ++ii) {
string label = cit->getBranch();

View File

@ -12,9 +12,11 @@
#include "buffer.h"
#include "author.h"
#include "buffer_funcs.h"
#include "bufferlist.h"
#include "bufferparams.h"
#include "Bullet.h"
#include "Chktex.h"
#include "debug.h"
#include "errorlist.h"
@ -166,9 +168,6 @@ Buffer::Buffer(string const & file, bool ronly)
: pimpl_(new Impl(*this, file, ronly))
{
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
// set initial author
authors().record(Author(lyxrc.user_name, lyxrc.user_email));
}
@ -333,12 +332,6 @@ void Buffer::setReadonly(bool flag)
}
AuthorList & Buffer::authors()
{
return params().authorlist;
}
void Buffer::setFileName(string const & newfile)
{
pimpl_->filename = MakeAbsPath(newfile);
@ -2071,11 +2064,11 @@ void Buffer::validate(LaTeXFeatures & features) const
// the bullet shapes are buffer level not paragraph level
// so they are tested here
for (int i = 0; i < 4; ++i) {
if (params().user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
int const font = params().user_defined_bullets[i].getFont();
if (params().user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
int const font = params().user_defined_bullet(i).getFont();
if (font == 0) {
int const c = params()
.user_defined_bullets[i]
.user_defined_bullet(i)
.getCharacter();
if (c == 16
|| c == 17

View File

@ -29,7 +29,6 @@
#include <vector>
class AuthorList;
class BufferParams;
class ErrorItem;
class LyXFont;
@ -300,10 +299,6 @@ public:
TexRow & texrow();
TexRow const & texrow() const;
/// the author list for the document
AuthorList & authors();
///
class inset_iterator {
public:
typedef std::input_iterator_tag iterator_category;

View File

@ -12,6 +12,7 @@
#include "bufferlist.h"
#include "author.h"
#include "buffer.h"
#include "bufferparams.h"
#include "debug.h"
@ -329,6 +330,6 @@ void BufferList::setCurrentAuthor(string const & name, string const & email)
BufferStorage::iterator it = bstore.begin();
BufferStorage::iterator end = bstore.end();
for (; it != end; ++it) {
(*it)->authors().record(0, Author(name, email));
(*it)->params().authors().record(0, Author(name, email));
}
}

View File

@ -17,6 +17,8 @@
#include "bufferparams.h"
#include "author.h"
#include "BranchList.h"
#include "Bullet.h"
#include "debug.h"
#include "encoding.h"
@ -28,14 +30,20 @@
#include "lyxrc.h"
#include "lyxtextclasslist.h"
#include "tex-strings.h"
#include "Spacing.h"
#include "texrow.h"
#include "vspace.h"
#include "frontends/Alert.h"
#include "support/LAssert.h"
#include "support/lyxalgo.h" // for lyx::count
#include <boost/array.hpp>
#include "support/std_sstream.h"
namespace support = lyx::support;
using namespace lyx::support;
using std::endl;
@ -46,15 +54,39 @@ using std::ostringstream;
using std::pair;
struct BufferParams::Impl
{
Impl();
AuthorList authorlist;
BranchList branchlist;
boost::array<Bullet, 4> temp_bullets;
boost::array<Bullet, 4> user_defined_bullets;
Spacing spacing;
/** This is the amount of space used for paragraph_separation "skip",
* and for detached paragraphs in "indented" documents.
*/
VSpace defskip;
};
BufferParams::Impl::Impl()
: defskip(VSpace::MEDSKIP)
{
// set initial author
authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
}
BufferParams::BufferParams()
// Initialize textclass to point to article. if `first' is
// true in the returned pair, then `second' is the textclass
// number; if it is false, second is 0. In both cases, second
// is what we want.
: textclass(textclasslist.NumberOfClass("article").second)
: pimpl_(new Impl),
// Initialize textclass to point to article. if `first' is
// true in the returned pair, then `second' is the textclass
// number; if it is false, second is 0. In both cases, second
// is what we want.
textclass(textclasslist.NumberOfClass("article").second)
{
paragraph_separation = PARSEP_INDENT;
defskip = VSpace(VSpace::MEDSKIP);
quotes_language = InsetQuotes::EnglishQ;
quotes_times = InsetQuotes::DoubleQ;
fontsize = "default";
@ -80,12 +112,92 @@ BufferParams::BufferParams()
pagestyle = "default";
compressed = false;
for (int iter = 0; iter < 4; ++iter) {
user_defined_bullets[iter] = ITEMIZE_DEFAULTS[iter];
temp_bullets[iter] = ITEMIZE_DEFAULTS[iter];
user_defined_bullet(iter) = ITEMIZE_DEFAULTS[iter];
temp_bullet(iter) = ITEMIZE_DEFAULTS[iter];
}
}
BufferParams::~BufferParams()
{}
AuthorList & BufferParams::authors()
{
return pimpl_->authorlist;
}
AuthorList const & BufferParams::authors() const
{
return pimpl_->authorlist;
}
BranchList & BufferParams::branchlist()
{
return pimpl_->branchlist;
}
BranchList const & BufferParams::branchlist() const
{
return pimpl_->branchlist;
}
Bullet & BufferParams::temp_bullet(lyx::size_type index)
{
support::Assert(index < 4);
return pimpl_->temp_bullets[index];
}
Bullet const & BufferParams::temp_bullet(lyx::size_type index) const
{
support::Assert(index < 4);
return pimpl_->temp_bullets[index];
}
Bullet & BufferParams::user_defined_bullet(lyx::size_type index)
{
support::Assert(index < 4);
return pimpl_->user_defined_bullets[index];
}
Bullet const & BufferParams::user_defined_bullet(lyx::size_type index) const
{
support::Assert(index < 4);
return pimpl_->user_defined_bullets[index];
}
Spacing & BufferParams::spacing()
{
return pimpl_->spacing;
}
Spacing const & BufferParams::spacing() const
{
return pimpl_->spacing;
}
VSpace const & BufferParams::getDefSkip() const
{
return pimpl_->defskip;
}
void BufferParams::setDefSkip(VSpace const & vs)
{
pimpl_->defskip = vs;
}
string const BufferParams::readToken(LyXLex & lex, string const & token)
{
if (token == "\\textclass") {
@ -128,7 +240,7 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
static_cast<PARSEP>(tmpret);
} else if (token == "\\defskip") {
lex.nextToken();
defskip = VSpace(lex.getString());
pimpl_->defskip = VSpace(lex.getString());
} else if (token == "\\quotes_language") {
// FIXME: should be params.readQuotes()
int tmpret = lex.findToken(string_quotes_language);
@ -200,7 +312,7 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
} else if (token == "\\branch") {
lex.nextToken();
string branch = lex.getString();
branchlist.add(branch);
branchlist().add(branch);
while (true) {
lex.nextToken();
string const tok = lex.getString();
@ -208,13 +320,13 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
break;
if (tok == "\\selected") {
lex.nextToken();
branchlist.setSelected(branch, lex.getInteger());
branchlist().setSelected(branch, lex.getInteger());
}
// not yet operational
if (tok == "\\color") {
lex.nextToken();
string color = lex.getString();
branchlist.setColor(branch, color);
branchlist().setColor(branch, color);
// Update also the LColor table:
if (color == "none")
color = lcolor.getX11Name(LColor::background);
@ -227,7 +339,7 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
istringstream ss(STRCONV(lex.getString()));
Author a;
ss >> a;
author_map.push_back(authorlist.record(a));
author_map.push_back(pimpl_->authorlist.record(a));
} else if (token == "\\paperorientation") {
int tmpret = lex.findToken(string_orientation);
if (tmpret == -1)
@ -283,16 +395,16 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
int const index = lex.getInteger();
lex.nextToken();
int temp_int = lex.getInteger();
user_defined_bullets[index].setFont(temp_int);
temp_bullets[index].setFont(temp_int);
user_defined_bullet(index).setFont(temp_int);
temp_bullet(index).setFont(temp_int);
lex.nextToken();
temp_int = lex.getInteger();
user_defined_bullets[index].setCharacter(temp_int);
temp_bullets[index].setCharacter(temp_int);
user_defined_bullet(index).setCharacter(temp_int);
temp_bullet(index).setCharacter(temp_int);
lex.nextToken();
temp_int = lex.getInteger();
user_defined_bullets[index].setSize(temp_int);
temp_bullets[index].setSize(temp_int);
user_defined_bullet(index).setSize(temp_int);
temp_bullet(index).setSize(temp_int);
lex.nextToken();
string const temp_str = lex.getString();
if (temp_str != "\\end_bullet") {
@ -322,8 +434,8 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
temp_str = lex.getString();
}
user_defined_bullets[index].setText(sum_str);
temp_bullets[index].setText(sum_str);
user_defined_bullet(index).setText(sum_str);
temp_bullet(index).setText(sum_str);
} else if (token == "\\secnumdepth") {
lex.nextToken();
secnumdepth = lex.getInteger();
@ -354,7 +466,7 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
if (first_par)
par->params().spacing(Spacing(tmp_space, tmp_val));
#endif
spacing.set(tmp_space, tmp_val);
spacing().set(tmp_space, tmp_val);
} else if (token == "\\float_placement") {
lex.nextToken();
float_placement = lex.getString();
@ -400,7 +512,7 @@ void BufferParams::writeFile(ostream & os) const
}
os << "\\paperfontsize " << fontsize << '\n';
spacing.writeFile(os);
spacing().writeFile(os);
os << "\\papersize " << string_papersize[papersize2]
<< "\n\\paperpackage " << string_paperpackages[paperpackage]
@ -411,8 +523,8 @@ void BufferParams::writeFile(ostream & os) const
<< "\n\\paperorientation " << string_orientation[orientation]
<< '\n';
std::list<Branch>::const_iterator it = branchlist.begin();
std::list<Branch>::const_iterator end = branchlist.end();
std::list<Branch>::const_iterator it = branchlist().begin();
std::list<Branch>::const_iterator end = branchlist().end();
for (; it != end; ++it) {
os << "\\branch " << it->getBranch()
<< "\n\\selected " << it->getSelected()
@ -452,7 +564,7 @@ void BufferParams::writeFile(ostream & os) const
<< "\n\\tocdepth " << tocdepth
<< "\n\\paragraph_separation "
<< string_paragraph_separation[paragraph_separation]
<< "\n\\defskip " << defskip.asLyXCommand()
<< "\n\\defskip " << getDefSkip().asLyXCommand()
<< "\n\\quotes_language "
<< string_quotes_language[quotes_language] << '\n';
switch (quotes_times) {
@ -466,21 +578,21 @@ void BufferParams::writeFile(ostream & os) const
<< "\n\\papersides " << sides
<< "\n\\paperpagestyle " << pagestyle << '\n';
for (int i = 0; i < 4; ++i) {
if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
if (user_defined_bullets[i].getFont() != -1) {
if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
if (user_defined_bullet(i).getFont() != -1) {
os << "\\bullet " << i
<< "\n\t"
<< user_defined_bullets[i].getFont()
<< user_defined_bullet(i).getFont()
<< "\n\t"
<< user_defined_bullets[i].getCharacter()
<< user_defined_bullet(i).getCharacter()
<< "\n\t"
<< user_defined_bullets[i].getSize()
<< user_defined_bullet(i).getSize()
<< "\n\\end_bullet\n";
}
else {
os << "\\bulletLaTeX " << i
<< "\n\t\""
<< user_defined_bullets[i].getText()
<< user_defined_bullet(i).getText()
<< "\"\n\\end_bullet\n";
}
}
@ -489,8 +601,8 @@ void BufferParams::writeFile(ostream & os) const
os << "\\tracking_changes " << tracking_changes << "\n";
if (tracking_changes) {
AuthorList::Authors::const_iterator it = authorlist.begin();
AuthorList::Authors::const_iterator end = authorlist.end();
AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
AuthorList::Authors::const_iterator end = pimpl_->authorlist.end();
for (; it != end; ++it) {
os << "\\author " << it->second << "\n";
}
@ -765,7 +877,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
}
if (paragraph_separation) {
switch (defskip.kind()) {
switch (getDefSkip().kind()) {
case VSpace::SMALLSKIP:
os << "\\setlength\\parskip{\\smallskipamount}\n";
break;
@ -777,7 +889,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
break;
case VSpace::LENGTH:
os << "\\setlength\\parskip{"
<< defskip.length().asLatexString()
<< getDefSkip().length().asLatexString()
<< "}\n";
break;
default: // should never happen // Then delete it.
@ -830,7 +942,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
// at \begin{document} time -- JMarc
string bullets_def;
for (int i = 0; i < 4; ++i) {
if (user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
if (bullets_def.empty())
bullets_def="\\AtBeginDocument{\n";
bullets_def += " \\renewcommand{\\labelitemi";
@ -849,7 +961,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
break;
}
bullets_def += "}{" +
user_defined_bullets[i].getText()
user_defined_bullet(i).getText()
+ "}\n";
}
}

View File

@ -15,28 +15,29 @@
#ifndef BUFFERPARAMS_H
#define BUFFERPARAMS_H
#include "author.h"
#include "BranchList.h"
#include "Bullet.h"
#include "lyxtextclass.h"
#include "paper.h"
#include "Spacing.h"
#include "vspace.h"
#include "insets/insetquotes.h"
#include "support/cow_ptr.h"
#include "support/types.h"
#include <boost/array.hpp>
#include "support/std_string.h"
#include <vector>
class AuthorList;
class BranchList;
class Bullet;
class LyXLex;
class LatexFeatures;
class Spacing;
class TexRow;
class VSpace;
struct Language;
/** Buffer parameters.
This class contains all the parameters for this a buffer uses. Some
work needs to be done on this class to make it nice. Now everything
@ -53,6 +54,7 @@ public:
};
///
BufferParams();
~BufferParams();
/// read a header token, if unrecognised, return it or an unknown class name
string const readToken(LyXLex & lex, string const & token);
@ -76,10 +78,10 @@ public:
bool hasClassDefaults() const;
///
VSpace const & getDefSkip() const { return defskip; }
VSpace const & getDefSkip() const;
///
void setDefSkip(VSpace const & vs) { defskip = vs; }
void setDefSkip(VSpace const & vs);
/** Wether paragraphs are separated by using a indent like in
articles or by using a little skip like in letters.
@ -132,7 +134,8 @@ public:
///
string fonts;
///
Spacing spacing;
Spacing & spacing();
Spacing const & spacing() const;
///
int secnumdepth;
///
@ -140,7 +143,8 @@ public:
///
Language const * language;
/// BranchList:
BranchList branchlist;
BranchList & branchlist();
BranchList const & branchlist() const;
///
string inputenc;
///
@ -155,10 +159,12 @@ public:
LyXTextClass::PageSides sides;
///
string pagestyle;
///
boost::array<Bullet, 4> temp_bullets;
///
boost::array<Bullet, 4> user_defined_bullets;
/// \param index should lie in the range 0 <= \c index <= 3.
Bullet & temp_bullet(lyx::size_type index);
Bullet const & temp_bullet(lyx::size_type index) const;
/// \param index should lie in the range 0 <= \c index <= 3.
Bullet & user_defined_bullet(lyx::size_type index);
Bullet const & user_defined_bullet(lyx::size_type index) const;
///
void readPreamble(LyXLex &);
///
@ -184,6 +190,10 @@ public:
///
bool compressed;
/// the author list for the document
AuthorList & authors();
AuthorList const & authors() const;
/// map of the file's author IDs to buffer author IDs
std::vector<int> author_map;
///
@ -192,15 +202,11 @@ public:
string const paperSizeName() const;
private:
/// the author list
AuthorList authorlist;
///
friend class Buffer;
/** This is the amount of space used for paragraph_separation "skip",
and for detached paragraphs in "indented" documents.
*/
VSpace defskip;
/** Use the Pimpl idiom to hide those member variables that would otherwise
drag in other header files.
*/
class Impl;
lyx::support::cow_ptr<Impl> pimpl_;
};
#endif

View File

@ -15,6 +15,7 @@
#include "bufferview_funcs.h"
#include "author.h"
#include "buffer.h"
#include "bufferparams.h"
#include "BufferView.h"
@ -306,7 +307,7 @@ string const currentState(BufferView * bv)
if (show_change) {
Change change(c.par()->lookupChangeFull(c.pos()));
Author const & a(bv->buffer()->authors().get(change.author));
Author const & a(bv->buffer()->params().authors().get(change.author));
state << _("Change: ") << a.name();
if (!a.email().empty()) {
state << " (" << a.email() << ")";

View File

@ -11,6 +11,8 @@
#include <config.h>
#include "ControlChanges.h"
#include "author.h"
#include "buffer.h"
#include "bufferparams.h"
#include "BufferView.h"
@ -50,7 +52,7 @@ string const ControlChanges::getChangeAuthor()
if (c.type == Change::UNCHANGED)
return string();
Author const & a(kernel().buffer().authors().get(c.author));
Author const & a(kernel().buffer().params().authors().get(c.author));
string author(a.name());

View File

@ -231,10 +231,10 @@ void QDocument::apply()
params.secnumdepth = dialog_->numberingModule->depthSL->value();
// bullets
params.user_defined_bullets[0] = dialog_->bulletsModule->getBullet(0);
params.user_defined_bullets[1] = dialog_->bulletsModule->getBullet(1);
params.user_defined_bullets[2] = dialog_->bulletsModule->getBullet(2);
params.user_defined_bullets[3] = dialog_->bulletsModule->getBullet(3);
params.user_defined_bullet(0) = dialog_->bulletsModule->getBullet(0);
params.user_defined_bullet(1) = dialog_->bulletsModule->getBullet(1);
params.user_defined_bullet(2) = dialog_->bulletsModule->getBullet(2);
params.user_defined_bullet(3) = dialog_->bulletsModule->getBullet(3);
// packages
params.graphicsDriver =
@ -264,16 +264,16 @@ void QDocument::apply()
switch (dialog_->textLayoutModule->lspacingCO->currentItem()) {
case 0:
params.spacing.set(Spacing::Single);
params.spacing().set(Spacing::Single);
break;
case 1:
params.spacing.set(Spacing::Onehalf);
params.spacing().set(Spacing::Onehalf);
break;
case 2:
params.spacing.set(Spacing::Double);
params.spacing().set(Spacing::Double);
break;
case 3:
params.spacing.set(Spacing::Other,
params.spacing().set(Spacing::Other,
dialog_->textLayoutModule->
lspacingLE->text().toFloat()
);
@ -466,10 +466,10 @@ void QDocument::update_contents()
dialog_->updateNumbering();
// bullets
dialog_->bulletsModule->setBullet(0,params.user_defined_bullets[0]);
dialog_->bulletsModule->setBullet(1,params.user_defined_bullets[1]);
dialog_->bulletsModule->setBullet(2,params.user_defined_bullets[2]);
dialog_->bulletsModule->setBullet(3,params.user_defined_bullets[3]);
dialog_->bulletsModule->setBullet(0,params.user_defined_bullet(0));
dialog_->bulletsModule->setBullet(1,params.user_defined_bullet(1));
dialog_->bulletsModule->setBullet(2,params.user_defined_bullet(2));
dialog_->bulletsModule->setBullet(3,params.user_defined_bullet(3));
// packages
QString text = toqstr(params.graphicsDriver);
@ -487,7 +487,7 @@ void QDocument::update_contents()
dialog_->mathsModule->amsautoCB->setChecked(
params.use_amsmath == BufferParams::AMS_AUTO);
switch (params.spacing.getSpace()) {
switch (params.spacing().getSpace()) {
case Spacing::Other: nitem = 3; break;
case Spacing::Double: nitem = 2; break;
case Spacing::Onehalf: nitem = 1; break;
@ -512,9 +512,9 @@ void QDocument::update_contents()
}
dialog_->textLayoutModule->lspacingCO->setCurrentItem(nitem);
if (params.spacing.getSpace() == Spacing::Other) {
if (params.spacing().getSpace() == Spacing::Other) {
dialog_->textLayoutModule->lspacingLE->setText(
toqstr(tostr(params.spacing.getValue())));
toqstr(tostr(params.spacing().getValue())));
dialog_->setLSpacing(3);
}

View File

@ -31,11 +31,13 @@
#include "controllers/frnt_lang.h"
#include "controllers/helper_funcs.h"
#include "Bullet.h"
#include "bufferparams.h"
#include "language.h"
#include "lyxrc.h"
#include "lyxtextclasslist.h"
#include "tex-strings.h"
#include "vspace.h"
#include "support/tostr.h"
#include "support/lstrings.h" // contains_functor, getStringFromVector
@ -671,10 +673,10 @@ void FormDocument::branch_input(FL_OBJECT * ob)
if (ob == branch_->button_add_branch) {
string new_branch = fl_get_input(branch_->input_all_branches);
if (!new_branch.empty()) {
params.branchlist.add(new_branch);
params.branchlist().add(new_branch);
fl_set_input(branch_->input_all_branches, "");
// Update branch list
string const all_branches = params.branchlist.allBranches();
string const all_branches = params.branchlist().allBranches();
fl_clear_browser(branch_->browser_all_branches);
vec = getVectorFromString(all_branches, "|");
for (unsigned i = 0; i < vec.size(); ++i) {
@ -690,9 +692,9 @@ void FormDocument::branch_input(FL_OBJECT * ob)
string const current_branch =
fl_get_browser_line(branch_->browser_all_branches, i);
if (!current_branch.empty()) {
params.branchlist.remove(current_branch);
params.branchlist().remove(current_branch);
// Update branch list
string const all_branches = params.branchlist.allBranches();
string const all_branches = params.branchlist().allBranches();
fl_clear_browser(branch_->browser_all_branches);
vec = getVectorFromString(all_branches, "|");
for (unsigned i = 0; i < vec.size(); ++i) {
@ -700,7 +702,7 @@ void FormDocument::branch_input(FL_OBJECT * ob)
vec[i].c_str());
}
// Update selected-list...
string const all_selected = params.branchlist.allSelected();
string const all_selected = params.branchlist().allSelected();
fl_clear_browser(branch_->browser_selection);
vec = getVectorFromString(all_selected, "|");
for (unsigned i = 0; i < vec.size(); ++i) {
@ -713,8 +715,8 @@ void FormDocument::branch_input(FL_OBJECT * ob)
fl_get_browser_line(branch_->browser_all_branches, i);
if (!current_branch.empty()) {
fl_clear_browser(branch_->browser_selection);
params.branchlist.setSelected(current_branch, true);
string const all_selected = params.branchlist.allSelected();
params.branchlist().setSelected(current_branch, true);
string const all_selected = params.branchlist().allSelected();
vec = getVectorFromString(all_selected, "|");
for (unsigned i = 0; i < vec.size(); ++i) {
fl_addto_browser(branch_->browser_selection,
@ -727,8 +729,8 @@ void FormDocument::branch_input(FL_OBJECT * ob)
fl_get_browser_line(branch_->browser_selection, i);
if (!current_sel.empty()) {
fl_clear_browser(branch_->browser_selection);
params.branchlist.setSelected(current_sel, false);
string const all_selected = params.branchlist.allSelected();
params.branchlist().setSelected(current_sel, false);
string const all_selected = params.branchlist().allSelected();
vec = getVectorFromString(all_selected, "|");
for (unsigned i = 0; i < vec.size(); ++i) {
fl_addto_browser(branch_->browser_selection,
@ -741,7 +743,7 @@ void FormDocument::branch_input(FL_OBJECT * ob)
fl_get_browser_line(branch_->browser_all_branches, i);
RGBColor before;
string x11hexname = params.branchlist.getColor(current_branch);
string x11hexname = params.branchlist().getColor(current_branch);
if (x11hexname[0] == '#') {
before = RGBColor(x11hexname);
} else{
@ -765,7 +767,7 @@ void FormDocument::branch_input(FL_OBJECT * ob)
lyxColorHandler->updateColor(c);
// what about system_lcolor?
// Here set colour in BranchList:
params.branchlist.setColor(current_branch, x11hexname);
params.branchlist().setColor(current_branch, x11hexname);
}
} else if (ob == branch_->browser_all_branches) {
unsigned i = fl_get_browser(branch_->browser_all_branches);
@ -774,7 +776,7 @@ void FormDocument::branch_input(FL_OBJECT * ob)
// make button_color track selected branch:
RGBColor rgb;
string x11hexname = params.branchlist.getColor(current_branch);
string x11hexname = params.branchlist().getColor(current_branch);
if (x11hexname[0] == '#') {
rgb = RGBColor(x11hexname);
} else {
@ -792,7 +794,7 @@ void FormDocument::branch_input(FL_OBJECT * ob)
setEnabled(branch_->button_modify,
(fl_get_browser(branch_->browser_all_branches) > 0));
branchlist_ = params.branchlist;
branchlist_ = params.branchlist();
}
@ -857,27 +859,27 @@ bool FormDocument::class_apply(BufferParams &params)
else
params.sides = LyXTextClass::OneSide;
Spacing tmpSpacing = params.spacing;
Spacing tmpSpacing = params.spacing();
switch (fl_get_choice(class_->choice_spacing)) {
case 1:
lyxerr[Debug::INFO] << "Spacing: SINGLE" << endl;
params.spacing.set(Spacing::Single);
params.spacing().set(Spacing::Single);
break;
case 2:
lyxerr[Debug::INFO] << "Spacing: ONEHALF" << endl;
params.spacing.set(Spacing::Onehalf);
params.spacing().set(Spacing::Onehalf);
break;
case 3:
lyxerr[Debug::INFO] << "Spacing: DOUBLE" << endl;
params.spacing.set(Spacing::Double);
params.spacing().set(Spacing::Double);
break;
case 4:
lyxerr[Debug::INFO] << "Spacing: OTHER" << endl;
params.spacing.set(Spacing::Other,
params.spacing().set(Spacing::Other,
getString(class_->input_spacing));
break;
}
if (tmpSpacing != params.spacing)
if (tmpSpacing != params.spacing())
redo = true;
params.options = getString(class_->input_extra);
@ -1015,7 +1017,7 @@ void FormDocument::bullets_apply(BufferParams & params)
BufferParams & buf_params = controller().params();
for (int i = 0; i < 4; ++i) {
params.user_defined_bullets[i] = buf_params.temp_bullets[i];
params.user_defined_bullet(i) = buf_params.temp_bullet(i);
}
}
@ -1024,8 +1026,8 @@ void FormDocument::branch_apply(BufferParams & params)
{
BufferParams & prms = controller().params();
if (branchlist_.empty())
branchlist_ = prms.branchlist;
params.branchlist = branchlist_;
branchlist_ = prms.branchlist();
params.branchlist() = branchlist_;
branchlist_.clear();
}
@ -1117,7 +1119,7 @@ void FormDocument::class_update(BufferParams const & params)
fl_set_input(class_->input_extra, params.options.c_str());
switch (params.spacing.getSpace()) {
switch (params.spacing().getSpace()) {
case Spacing::Other:
pos = 4;
break;
@ -1137,7 +1139,7 @@ void FormDocument::class_update(BufferParams const & params)
bool const spacing_input = pos == 4;
setEnabled(class_->input_spacing, spacing_input);
string const input = spacing_input ? tostr(params.spacing.getValue()) : string();
string const input = spacing_input ? tostr(params.spacing().getValue()) : string();
fl_set_input(class_->input_spacing, input.c_str());
}
@ -1289,9 +1291,9 @@ void FormDocument::bullets_update(BufferParams const & params)
fl_set_button(bullets_->radio_depth_1, 1);
fl_set_input(bullets_->input_latex,
params.user_defined_bullets[0].getText().c_str());
params.user_defined_bullet(0).getText().c_str());
fl_set_choice(bullets_->choice_size,
params.user_defined_bullets[0].getSize() + 2);
params.user_defined_bullet(0).getSize() + 2);
}
@ -1300,7 +1302,7 @@ void FormDocument::branch_update(BufferParams const & params)
if (!branch_.get())
return;
string const all_branches = params.branchlist.allBranches();
string const all_branches = params.branchlist().allBranches();
fl_clear_browser(branch_->browser_all_branches);
string current_branch("none");
@ -1318,7 +1320,7 @@ void FormDocument::branch_update(BufferParams const & params)
}
// display proper selection...
string const all_selected = params.branchlist.allSelected();
string const all_selected = params.branchlist().allSelected();
fl_clear_browser(branch_->browser_selection);
if (!all_selected.empty()) {
std::vector<string> vec = getVectorFromString(all_selected, "|");
@ -1332,7 +1334,7 @@ void FormDocument::branch_update(BufferParams const & params)
if (current_branch == "none")
x11hexname = "none";
else
x11hexname = params.branchlist.getColor(current_branch);
x11hexname = params.branchlist().getColor(current_branch);
if (x11hexname[0] == '#') {
rgb = RGBColor(x11hexname);
} else {
@ -1368,9 +1370,9 @@ void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/)
BufferParams & param = controller().params();
// convert from 1-6 range to -1-4
param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2);
param.temp_bullet(current_bullet_depth).setSize(fl_get_choice(ob) - 2);
fl_set_input(bullets_->input_latex,
param.temp_bullets[current_bullet_depth].getText().c_str());
param.temp_bullet(current_bullet_depth).getText().c_str());
}
@ -1378,7 +1380,7 @@ void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
{
BufferParams & param = controller().params();
param.temp_bullets[current_bullet_depth].
param.temp_bullet(current_bullet_depth).
setText(getString(bullets_->input_latex));
}
@ -1408,13 +1410,13 @@ void FormDocument::BulletDepth(FL_OBJECT * ob)
switch (fl_get_button_numb(ob)) {
case 3:
// right mouse button resets to default
param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
param.temp_bullet(data) = ITEMIZE_DEFAULTS[data];
default:
current_bullet_depth = data;
fl_set_input(bullets_->input_latex,
param.temp_bullets[data].getText().c_str());
param.temp_bullet(data).getText().c_str());
fl_set_choice(bullets_->choice_size,
param.temp_bullets[data].getSize() + 2);
param.temp_bullet(data).getSize() + 2);
}
}
@ -1483,10 +1485,10 @@ void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/)
/* try to keep the button held down till another is pushed */
/* fl_set_bmtable(ob, 1, bmtable_button); */
param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel);
param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button);
param.temp_bullet(current_bullet_depth).setFont(current_bullet_panel);
param.temp_bullet(current_bullet_depth).setCharacter(bmtable_button);
fl_set_input(bullets_->input_latex,
param.temp_bullets[current_bullet_depth].getText().c_str());
param.temp_bullet(current_bullet_depth).getText().c_str());
}

View File

@ -40,7 +40,7 @@ InsetBranch::InsetBranch(BufferParams const & bp, string const & label)
params_.branch = label;
// Hack: stash the list of all allowable branch labels from this
// buffer into inset's parm list as a "stowaway":
params_.branchlist = bp.branchlist;
params_.branchlist = bp.branchlist();
init();
}
@ -149,7 +149,7 @@ dispatch_result InsetBranch::localDispatch(FuncRequest const & cmd)
int InsetBranch::latex(Buffer const & buf, ostream & os,
LatexRunParams const & runparams) const
{
string const branch_sel = buf.params().branchlist.allSelected();
string const branch_sel = buf.params().branchlist().allSelected();
if (branch_sel.find(params_.branch, 0) != string::npos)
return inset.latex(buf, os, runparams);
return 0;
@ -165,7 +165,7 @@ int InsetBranch::linuxdoc(Buffer const &, std::ostream &) const
int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
{
// untested - MV
string const branch_sel = buf.params().branchlist.allSelected();
string const branch_sel = buf.params().branchlist().allSelected();
if (branch_sel.find(params_.branch, 0) != string::npos)
return inset.docbook(buf, os, mixcont);
return 0;
@ -174,7 +174,7 @@ int InsetBranch::docbook(Buffer const & buf, std::ostream & os, bool mixcont) co
int InsetBranch::ascii(Buffer const & buf, std::ostream & os, int ll) const
{
string const branch_sel = buf.params().branchlist.allSelected();
string const branch_sel = buf.params().branchlist().allSelected();
if (branch_sel.find(params_.branch, 0) != string::npos) {
return inset.ascii(buf, os, ll);
}
@ -199,14 +199,14 @@ InsetBranchMailer::InsetBranchMailer(string const & name,
string const InsetBranchMailer::inset2string(Buffer const & buf) const
{
InsetBranchParams params = inset_.params();
params.branchlist = buf.params().branchlist;
params.branchlist = buf.params().branchlist();
inset_.setParams(params);
return params2string(name_, params);
}
string const InsetBranchMailer::params2string(string const & name,
InsetBranchParams const & params)
InsetBranchParams const & params)
{
ostringstream data;
data << name << ' ';

View File

@ -18,6 +18,8 @@
#include "paragraph_funcs.h"
#include "texrow.h"
#include "support/std_ostream.h"
using std::auto_ptr;
using std::ostream;

View File

@ -21,6 +21,7 @@
#include "lyxfunc.h"
#include "BranchList.h"
#include "buffer.h"
#include "buffer_funcs.h"
#include "bufferlist.h"
@ -631,7 +632,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
break;
case LFUN_INSERT_BRANCH:
code = InsetOld::BRANCH_CODE;
if (buf->params().branchlist.empty())
if (buf->params().branchlist().empty())
disable = true;
break;
case LFUN_INSERT_LABEL:

View File

@ -30,6 +30,7 @@
#include "lyxrc.h"
#include "lyxrow.h"
#include "texrow.h"
#include "vspace.h"
#include "insets/insetbibitem.h"
#include "insets/insetoptarg.h"

View File

@ -26,6 +26,7 @@
#include "lyxrc.h"
#include "paragraph_pimpl.h"
#include "texrow.h"
#include "vspace.h"
#include "insets/insetbibitem.h"
#include "insets/insethfill.h"

View File

@ -21,6 +21,7 @@
#include "language.h"
#include "LaTeXFeatures.h"
#include "latexrunparams.h"
#include "lyxlength.h"
#include "lyxrc.h"
#include "texrow.h"

View File

@ -25,6 +25,7 @@
#include "metricsinfo.h"
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
#include "vspace.h"
#include "frontends/font_metrics.h"
#include "frontends/Painter.h"
@ -749,7 +750,7 @@ void RowPainter::paintFirst()
if (!parparams.spacing().isDefault()) {
spacing_val = parparams.spacing().getValue();
} else {
spacing_val = buffer.params().spacing.getValue();
spacing_val = buffer.params().spacing().getValue();
}
int const maxdesc =
@ -792,7 +793,7 @@ void RowPainter::paintFirst()
if (!parparams.spacing().isDefault()) {
spacing_val = parparams.spacing().getValue();
} else {
spacing_val = buffer.params().spacing.getValue();
spacing_val = buffer.params().spacing().getValue();
}
int maxdesc =

124
src/support/cow_ptr.h Normal file
View File

@ -0,0 +1,124 @@
// -*- C++ -*-
/**
* \file cow_ptr.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* A pointer with copy-on-write semantics
*
* The original version of this class was written by Yonat Sharon
* and is freely available at http://ootips.org/yonat/
*
* I modified it to use boost::shared_ptr internally, rather than use his
* home-grown equivalent.
*/
#ifndef COW_PTR_H
#define COW_PTR_H
#include <boost/shared_ptr.hpp>
namespace lyx {
namespace support {
template <typename T>
class cow_ptr {
public:
explicit cow_ptr(T * = 0);
cow_ptr(cow_ptr const &);
cow_ptr & operator=(cow_ptr const &);
T const & operator*() const;
T const * operator->() const;
T const * get() const;
T & operator*();
T * operator->();
T * get();
private:
boost::shared_ptr<T> ptr_;
void copy();
};
template <typename T>
cow_ptr<T>::cow_ptr(T * p)
: ptr_(p)
{}
template <typename T>
cow_ptr<T>::cow_ptr(cow_ptr const & other)
: ptr_(other.ptr_)
{}
template <typename T>
cow_ptr<T> & cow_ptr<T>::operator=(cow_ptr const & other)
{
if (&other != this)
ptr_ = other.ptr_;
return *this;
}
template <typename T>
T const & cow_ptr<T>::operator*() const
{
return *ptr_;
}
template <typename T>
T const * cow_ptr<T>::operator->() const
{
return ptr_.get();
}
template <typename T>
T const * cow_ptr<T>::get() const
{
return ptr_.get();
}
template <typename T>
T & cow_ptr<T>::operator*()
{
copy();
return *ptr_;
}
template <typename T>
T * cow_ptr<T>::operator->()
{
copy();
return ptr_.get();
}
template <typename T>
T * cow_ptr<T>::get()
{
copy();
return ptr_.get();
}
template <typename T>
void cow_ptr<T>::copy()
{
if (!ptr_.unique())
ptr_ = boost::shared_ptr<T>(new T(*ptr_.get()));
}
} // namespace support
} // namespace lyx
#endif // NOT COW_PTR_H

View File

@ -26,6 +26,7 @@
#include "funcrequest.h"
#include "gettext.h"
#include "language.h"
#include "lyxlength.h"
#include "lyxrc.h"
#include "lyxrow.h"
#include "lyxrow_funcs.h"
@ -34,6 +35,7 @@
#include "rowpainter.h"
#include "text_funcs.h"
#include "undo_funcs.h"
#include "vspace.h"
#include "WordLangTuple.h"
#include "frontends/font_metrics.h"
@ -909,7 +911,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
if (!pit->params().spacing().isDefault())
spacing_val = pit->params().spacing().getValue();
else
spacing_val = bv()->buffer()->params().spacing.getValue();
spacing_val = bv()->buffer()->params().spacing().getValue();
//lyxerr << "spacing_val = " << spacing_val << endl;
int maxasc = int(font_metrics::maxAscent(font) *
@ -1034,7 +1036,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
if (!pit->params().spacing().isDefault()) {
spacing_val = pit->params().spacing().getValue();
} else {
spacing_val = bufparams.spacing.getValue();
spacing_val = bufparams.spacing().getValue();
}
labeladdon = int(font_metrics::maxDescent(labelfont) *
@ -1056,7 +1058,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, RowList::iterator rit)
if (!pit->params().spacing().isDefault()) {
spacing_val = pit->params().spacing().getValue();
} else {
spacing_val = bufparams.spacing.getValue();
spacing_val = bufparams.spacing().getValue();
}
labeladdon = int(

View File

@ -41,6 +41,7 @@
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
#include "undo_funcs.h"
#include "vspace.h"
#include "frontends/font_metrics.h"
#include "frontends/LyXView.h"

View File

@ -32,6 +32,7 @@
#include "ParagraphParameters.h"
#include "text_funcs.h"
#include "undo_funcs.h"
#include "vspace.h"
#include "frontends/Dialogs.h"
#include "frontends/LyXView.h"