* \author Jürgen Vigna
* \author Rob Lahaye
* \author Martin Vermeer
- * \author Juergen Spitzmueller
+ * \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#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
#include <iomanip>
-using namespace lyx::support;
+using lyx::support::bformat;
+using lyx::support::contains_functor;
+using lyx::support::getStringFromVector;
+using lyx::support::getVectorFromString;
+using lyx::support::LibFileSearch;
using std::bind2nd;
using std::endl;
-using std::setw;
-using std::setfill;
+using std::string;
using std::vector;
fl_addto_choice(language_->choice_quotes_language,
_(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
- " «text» | »text« ").c_str());
+ " <<text>> | >>text<< ").c_str());
// the document options form
options_.reset(build_document_options(this));
fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
fl_addto_choice(options_->choice_ams_math,
- _("Never | Automatically | Yes ").c_str());
+ _(" Never | Automatically | Yes ").c_str());
for (int n = 0; tex_graphics[n][0]; ++n) {
fl_addto_choice(options_->choice_postscript_driver,
bmtablefile.c_str());
picker_.reset(new FormColorpicker);
-
+
// the document branches form
branch_.reset(build_document_branch(this));
fl_set_object_color(branch_->button_color,
GUI_COLOR_CHOICE, GUI_COLOR_CHOICE);
-
+
bcview().addReadOnly(branch_->input_all_branches);
bcview().addReadOnly(branch_->button_add_branch);
bcview().addReadOnly(branch_->button_remove_branch);
}
-void FormDocument::branch_input(FL_OBJECT * ob)
+void FormDocument::rebuild_all_branches_browser()
{
- BufferParams & params = controller().params();
- std::vector<string> vec;
+ typedef BranchList::const_iterator const_iterator;
+
+ fl_clear_browser(branch_->browser_all_branches);
+
+ const_iterator const begin = branchlist_.begin();
+ const_iterator const end = branchlist_.end();
+ for (const_iterator it = begin; it != end; ++it) {
+ fl_addto_browser(branch_->browser_all_branches,
+ it->getBranch().c_str());
+ }
+}
+
+
+void FormDocument::rebuild_selected_branches_browser()
+{
+ typedef BranchList::const_iterator const_iterator;
+
+ fl_clear_browser(branch_->browser_selection);
+
+ const_iterator const begin = branchlist_.begin();
+ const_iterator const end = branchlist_.end();
+ for (const_iterator it = begin; it != end; ++it) {
+ if (it->getSelected())
+ fl_addto_browser(branch_->browser_selection,
+ it->getBranch().c_str());
+ }
+}
+
+namespace {
+
+RGBColor get_current_color(FL_OBJECT * browser, BranchList const & branchlist)
+{
+ BOOST_ASSERT(browser && browser->objclass == FL_BROWSER);
+
+ RGBColor color;
+
+ int const i = fl_get_browser(browser);
+ string const branch_name = fl_get_browser_line(browser, i);
+ Branch const * branch = branchlist.find(branch_name);
+ if (!branch)
+ return color;
+
+ string const x11hexname = branch->getColor();
+ if (x11hexname[0] == '#') {
+ color = RGBColor(x11hexname);
+ } else{
+ fl_getmcolor(FL_COL1, &color.r, &color.g, &color.b);
+ }
+ return color;
+}
+
+} // namespace anon
+
+
+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);
+ string const new_branch =
+ getString(branch_->input_all_branches);
+
+ if (!new_branch.empty() && branchlist_.add(new_branch)) {
+
fl_set_input(branch_->input_all_branches, "");
- // Update branch list
- 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) {
- fl_addto_browser(branch_->browser_all_branches,
- vec[i].c_str());
- }
- LColor::color c = static_cast<LColor::color>(lcolor.size());
- lcolor.fill(c, new_branch, lcolor.getX11Name(LColor::background));
+ rebuild_all_branches_browser();
}
} else if (ob == branch_->button_remove_branch) {
unsigned i = fl_get_browser(branch_->browser_all_branches);
string const current_branch =
fl_get_browser_line(branch_->browser_all_branches, i);
- if (!current_branch.empty()) {
- params.branchlist.remove(current_branch);
- // Update branch list
- 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) {
- fl_addto_browser(branch_->browser_all_branches,
- vec[i].c_str());
- }
- // Update selected-list...
- 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) {
- fl_addto_browser(branch_->browser_selection, vec[i].c_str());
- }
- }
- } else if (ob == branch_->button_select) {
- unsigned i = fl_get_browser(branch_->browser_all_branches);
- string const current_branch =
- 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();
- vec = getVectorFromString(all_selected, "|");
- for (unsigned i = 0; i < vec.size(); ++i) {
- fl_addto_browser(branch_->browser_selection,
- vec[i].c_str());
- }
- }
- } else if (ob == branch_->button_deselect) {
- unsigned i = fl_get_browser(branch_->browser_selection);
- string const current_sel =
- 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();
- vec = getVectorFromString(all_selected, "|");
- for (unsigned i = 0; i < vec.size(); ++i) {
- fl_addto_browser(branch_->browser_selection,
- vec[i].c_str());
- }
+ if (!current_branch.empty() &&
+ branchlist_.remove(current_branch)) {
+
+ rebuild_all_branches_browser();
+ rebuild_selected_branches_browser();
}
- } else if (ob == branch_->button_modify) {
- unsigned i = fl_get_browser(branch_->browser_all_branches);
+
+ } else if (ob == branch_->button_select ||
+ ob == branch_->button_deselect) {
+
+ bool const selected = ob == branch_->button_select;
+
+ int const i = fl_get_browser(branch_->browser_all_branches);
string const current_branch =
fl_get_browser_line(branch_->browser_all_branches, i);
+
+ Branch * branch = branchlist_.find(current_branch);
- RGBColor before;
- string x11hexname = params.branchlist.getColor(current_branch);
- if (x11hexname[0] == '#') {
- before = RGBColor(x11hexname);
- } else{
- fl_getmcolor(FL_COL1, &before.r, &before.g, &before.b);
- }
+ if (branch && branch->setSelected(selected))
+ rebuild_selected_branches_browser();
- RGBColor col = picker_->requestColor(before);
- if (before != col) {
- fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.b);
+ } else if (ob == branch_->button_modify) {
+ RGBColor const before =
+ get_current_color(branch_->browser_all_branches,
+ branchlist_);
+ RGBColor const after = picker_->requestColor(before);
+ if (before != after) {
+ fl_mapcolor(GUI_COLOR_CHOICE,
+ after.r, after.g, after.b);
fl_redraw_object(branch_->button_color);
- // Figure out here how to stash the new colour into the
- // LyX colour database.
-
- x11hexname = X11hexname(col);
-
- // current_branch already in database
- LColor::color c = lcolor.getFromLyXName(current_branch);
- lcolor.setColor(current_branch, x11hexname);
- // Make sure that new colour is also displayed ;-)
- lyxColorHandler->getGCForeground(c);
- lyxColorHandler->updateColor(c);
- // what about system_lcolor?
- // Here set colour in BranchList:
- params.branchlist.setColor(current_branch, x11hexname);
+
+ string const branch_name =
+ getString(branch_->browser_all_branches);
+ Branch * branch = branchlist_.find(branch_name);
+ if (branch)
+ branch->setColor(X11hexname(after));
}
+
} else if (ob == branch_->browser_all_branches) {
- unsigned i = fl_get_browser(branch_->browser_all_branches);
- string const current_branch =
- fl_get_browser_line(branch_->browser_all_branches, i);
- // make button_color track selected branch:
+ RGBColor rgb =
+ get_current_color(branch_->browser_all_branches,
+ branchlist_);
- RGBColor rgb;
- string x11hexname = params.branchlist.getColor(current_branch);
- if (x11hexname[0] == '#') {
- rgb = RGBColor(x11hexname);
- } else {
- fl_getmcolor(FL_COL1, &rgb.r, &rgb.g, &rgb.b);
- }
fl_mapcolor(GUI_COLOR_CHOICE, rgb.r, rgb.g, rgb.b);
fl_redraw_object(branch_->button_color);
}
(fl_get_browser(branch_->browser_all_branches) > 0));
setEnabled(branch_->button_modify,
(fl_get_browser(branch_->browser_all_branches) > 0));
-
- branchlist_ = params.branchlist;
}
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);
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);
}
}
void FormDocument::branch_apply(BufferParams & params)
{
- BufferParams & prms = controller().params();
- if (branchlist_.empty())
- branchlist_ = prms.branchlist;
- params.branchlist = branchlist_;
- branchlist_.clear();
+ params.branchlist() = branchlist_;
}
-
+
void FormDocument::UpdateClassParams(BufferParams const & params)
{
// These are the params that have to be updated on any class change
fl_set_input(class_->input_extra, params.options.c_str());
- switch (params.spacing.getSpace()) {
+ switch (params.spacing().getSpace()) {
case Spacing::Other:
pos = 4;
break;
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());
}
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);
}
{
if (!branch_.get())
return;
-
- string const all_branches = params.branchlist.allBranches();
- fl_clear_browser(branch_->browser_all_branches);
- string current_branch("none");
-
- if (!all_branches.empty()) {
- std::vector<string> vec = getVectorFromString(all_branches, "|");
- for (unsigned i = 0; i < vec.size(); ++i) {
- fl_addto_browser(branch_->browser_all_branches, vec[i].c_str());
- }
- fl_select_browser_line(branch_->browser_all_branches, 1);
- if (!vec.empty())
- current_branch =
- fl_get_browser_line(branch_->browser_all_branches, 1);
- else
- current_branch = "none";
- }
+
+ branchlist_ = params.branchlist();
+
+ rebuild_all_branches_browser();
+ string const current_branch =
+ fl_get_browser_maxline(branch_->browser_all_branches) == 0 ?
+ "none" :
+ fl_get_browser_line(branch_->browser_all_branches, 1);
// display proper selection...
- string const all_selected = params.branchlist.allSelected();
- fl_clear_browser(branch_->browser_selection);
- if (!all_selected.empty()) {
- std::vector<string> vec = getVectorFromString(all_selected, "|");
- for (unsigned i = 0; i < vec.size(); ++i) {
- fl_addto_browser(branch_->browser_selection, vec[i].c_str());
- }
- }
+ rebuild_selected_branches_browser();
+
// display proper colour...
RGBColor rgb;
string x11hexname;
if (current_branch == "none")
x11hexname = "none";
- else
- x11hexname = params.branchlist.getColor(current_branch);
+ else {
+ Branch * branch = branchlist_.find(current_branch);
+ if (branch)
+ x11hexname = branch->getColor();
+ }
+
if (x11hexname[0] == '#') {
rgb = RGBColor(x11hexname);
} else {
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());
}
{
BufferParams & param = controller().params();
- param.temp_bullets[current_bullet_depth].
+ param.temp_bullet(current_bullet_depth).
setText(getString(bullets_->input_latex));
}
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);
}
}
/* 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());
}