*
* \author Jürgen Vigna
* \author Rob Lahaye
+ * \author Martin Vermeer
+ * \author Jürgen Spitzmüller
*
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#include "ControlDocument.h"
#include "FormDocument.h"
+#include "ControlDocument.h"
#include "forms/form_document.h"
-#include "xformsBC.h"
-#include "ButtonController.h"
#include "bmtable.h"
#include "checkedwidgets.h"
+#include "ColorHandler.h"
+#include "combox.h"
+#include "FormColorpicker.h"
#include "input_validators.h" // fl_unsigned_float_filter
+#include "Tooltips.h"
#include "xforms_helpers.h"
+#include "xformsBC.h"
-#include "CutAndPaste.h"
-#include "debug.h"
+#include "controllers/ButtonController.h"
+#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 "controllers/frnt_lang.h"
-#include "controllers/helper_funcs.h"
+#include "vspace.h"
#include "support/tostr.h"
#include "support/lstrings.h" // contains_functor, getStringFromVector
#include "support/filetools.h" // LibFileSearch
#include "lyx_xpm.h"
-#include "lyx_forms.h"
-#include "combox.h"
-#include <boost/bind.hpp>
+#include <iomanip>
-#include <functional>
+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::string;
using std::vector;
bool const scalableTabfolders = true;
#endif
+
} // namespace anon
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,
fl_set_bmtable_pixmap_file(bullets_->bmtable_panel, 6, 6,
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);
+ bcview().addReadOnly(branch_->button_select);
+ bcview().addReadOnly(branch_->button_deselect);
+ bcview().addReadOnly(branch_->button_modify);
+ bcview().addReadOnly(branch_->browser_all_branches);
+
+ // set up the tooltips for branches form
+ string str = _("Enter the name of a new branch.");
+ tooltips().init(branch_->input_all_branches, str);
+ str = _("Add a new branch to the document.");
+ tooltips().init(branch_->button_add_branch, str);
+ str = _("Remove the selected branch from the document.");
+ tooltips().init(branch_->button_remove_branch, str);
+ str = _("Activate the selected branch for output.");
+ tooltips().init(branch_->button_select, str);
+ str = _("Deactivate the selected activated branch.");
+ tooltips().init(branch_->button_deselect, str);
+ str = _("Available branches for this document.");
+ tooltips().init(branch_->browser_all_branches, str);
+ str = _("Activated branches. Content will occur in the document\'s output");
+ tooltips().init(branch_->browser_selection, str);
+ str = _("Modify background color of branch inset");
+ tooltips().init(branch_->button_modify, str);
+ str = _("Background color of branch inset");
+ tooltips().init(branch_->button_color, str);
+
+ // Handle middle mouse paint:
+ setPrehandler(branch_->input_all_branches);
+ fl_set_input_return(branch_->input_all_branches, FL_RETURN_CHANGED);
+
// Enable the tabfolder to be rescaled correctly.
if (scalableTabfolders)
fl_set_tabfolder_autofit(dialog_->tabfolder, FL_FIT);
fl_deactivate_object(fbullet);
fl_set_object_lcol(fbullet, FL_INACTIVE);
}
+
+ fl_addto_tabfolder(dialog_->tabfolder,_("Branches").c_str(),
+ branch_->form);
}
language_apply(params);
options_apply(params);
bullets_apply(params);
+ branch_apply(params);
}
language_update(params);
options_update(params);
bullets_update(params);
+ branch_update(params);
}
// Default unit choice is cm if metric, inches if US paper.
// If papersize is default, check the lyxrc-settings
int const paperchoice = fl_get_choice(paper_->choice_papersize);
- bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
+ bool const metric = (paperchoice == 1 && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
|| paperchoice == 2 || paperchoice > 5;
string const default_unit = metric ? "cm" : "in";
if (getString(class_->input_skip).empty())
setEnabled(options_->choice_citation_format,
fl_get_button(options_->check_use_natbib));
+ } else if (ob == branch_->browser_all_branches ||
+ ob == branch_->browser_selection ||
+ ob == branch_->button_add_branch ||
+ ob == branch_->button_remove_branch ||
+ ob == branch_->button_modify ||
+ ob == branch_->button_select ||
+ ob == branch_->button_deselect ||
+ ob == branch_->button_deselect) {
+ branch_input(ob);
} else if (ob == dialog_->button_save_defaults) {
apply();
controller().saveAsDefault();
} else if (ob == paper_->radio_landscape) {
fl_set_choice(paper_->choice_paperpackage,
- BufferParams::PACKAGE_NONE + 1);
+ PACKAGE_NONE + 1);
} else if (ob == paper_->choice_papersize) {
int const paperchoice = fl_get_choice(paper_->choice_papersize);
// Default unit choice is cm if metric, inches if US paper.
// If papersize is default, use the lyxrc-settings
- bool const metric = (defsize && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
+ bool const metric = (defsize && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
|| paperchoice == 2 || paperchoice > 5;
string const default_unit = metric ? "cm" : "in";
if (getString(paper_->input_custom_width).empty())
fl_set_button(paper_->check_use_geometry, 1);
fl_set_choice(paper_->choice_paperpackage,
- BufferParams::PACKAGE_NONE + 1);
+ PACKAGE_NONE + 1);
bool const use_geom = fl_get_button(paper_->check_use_geometry);
setEnabled(paper_->input_top_margin, use_geom);
// either default papersize (preferences) or document
// papersize has to be A4
bool const enable = ( fl_get_choice(paper_->choice_papersize) == 1
- && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER )
+ && lyxrc.default_papersize == PAPER_A4PAPER )
|| fl_get_choice(paper_->choice_papersize) == 7;
if (!enable)
fl_set_choice(paper_->choice_paperpackage,
- BufferParams::PACKAGE_NONE + 1);
+ PACKAGE_NONE + 1);
setEnabled(paper_->choice_paperpackage,
enable && fl_get_button(paper_->radio_portrait));
}
}
+void FormDocument::rebuild_all_branches_browser()
+{
+ 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 const new_branch =
+ getString(branch_->input_all_branches);
+
+ if (!new_branch.empty() && branchlist_.add(new_branch)) {
+
+ fl_set_input(branch_->input_all_branches, "");
+ 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() &&
+ branchlist_.remove(current_branch)) {
+
+ rebuild_all_branches_browser();
+ rebuild_selected_branches_browser();
+ }
+
+ } 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);
+
+ if (branch && branch->setSelected(selected))
+ rebuild_selected_branches_browser();
+
+ } 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);
+
+ 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) {
+ RGBColor rgb =
+ get_current_color(branch_->browser_all_branches,
+ branchlist_);
+
+ fl_mapcolor(GUI_COLOR_CHOICE, rgb.r, rgb.g, rgb.b);
+ fl_redraw_object(branch_->button_color);
+ }
+ setEnabled(branch_->button_select,
+ (fl_get_browser(branch_->browser_all_branches) > 0));
+ setEnabled(branch_->button_deselect,
+ (fl_get_browser(branch_->browser_selection) > 0));
+ setEnabled(branch_->button_remove_branch,
+ (fl_get_browser(branch_->browser_all_branches) > 0));
+ setEnabled(branch_->button_modify,
+ (fl_get_browser(branch_->browser_all_branches) > 0));
+}
+
+
bool FormDocument::class_apply(BufferParams ¶ms)
{
bool redo = false;
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\n";
- params.spacing.set(Spacing::Single);
+ lyxerr[Debug::INFO] << "Spacing: SINGLE" << endl;
+ params.spacing().set(Spacing::Single);
break;
case 2:
- lyxerr[Debug::INFO] << "Spacing: ONEHALF\n";
- params.spacing.set(Spacing::Onehalf);
+ lyxerr[Debug::INFO] << "Spacing: ONEHALF" << endl;
+ params.spacing().set(Spacing::Onehalf);
break;
case 3:
- lyxerr[Debug::INFO] << "Spacing: DOUBLE\n";
- params.spacing.set(Spacing::Double);
+ lyxerr[Debug::INFO] << "Spacing: DOUBLE" << endl;
+ params.spacing().set(Spacing::Double);
break;
case 4:
- lyxerr[Debug::INFO] << "Spacing: OTHER\n";
- params.spacing.set(Spacing::Other,
+ lyxerr[Debug::INFO] << "Spacing: OTHER" << endl;
+ 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);
void FormDocument::paper_apply(BufferParams & params)
{
- params.papersize2 = BufferParams::VMARGIN_PAPER_TYPE(fl_get_choice(paper_->choice_papersize) - 1);
+ params.papersize2 = VMARGIN_PAPER_TYPE(fl_get_choice(paper_->choice_papersize) - 1);
params.paperpackage =
- BufferParams::PAPER_PACKAGES(fl_get_choice(paper_->choice_paperpackage) - 1);
+ PAPER_PACKAGES(fl_get_choice(paper_->choice_paperpackage) - 1);
// set params.papersize from params.papersize2 and params.paperpackage
params.setPaperStuff();
params.use_geometry = fl_get_button(paper_->check_use_geometry);
if (fl_get_button(paper_->radio_landscape))
- params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
+ params.orientation = ORIENTATION_LANDSCAPE;
else
- params.orientation = BufferParams::ORIENTATION_PORTRAIT;
+ params.orientation = ORIENTATION_PORTRAIT;
params.paperwidth =
getLengthFromWidgets(paper_->input_custom_width,
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)
+{
+ params.branchlist() = branchlist_;
+}
+
+
void FormDocument::UpdateClassParams(BufferParams const & params)
{
// These are the params that have to be updated on any class change
fl_set_choice_text(class_->choice_pagestyle,
params.pagestyle.c_str());
+ fl_set_input(class_->input_extra, tclass.options().c_str());
}
void FormDocument::class_update(BufferParams const & params)
bool const length_input = pos == 4;
if (length_input) {
int const paperchoice = fl_get_choice(paper_->choice_papersize);
- bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
+ bool const metric = (paperchoice == 1 && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
|| paperchoice == 2 || paperchoice > 5;
string const default_unit = metric ? "cm" : "in";
string const length = params.getDefSkip().asLyXCommand();
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(paper_->radio_landscape, 0);
setEnabled(paper_->radio_landscape, !useCustom);
- if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
+ if (params.orientation == ORIENTATION_LANDSCAPE)
fl_set_button(paper_->radio_landscape, 1);
else
fl_set_button(paper_->radio_portrait, 1);
//either default papersize (preferences)
//or document papersize has to be A4
(paperchoice == 7
- || paperchoice == 1 && lyxrc.default_papersize == BufferParams::PAPER_A4PAPER)
+ || paperchoice == 1 && lyxrc.default_papersize == PAPER_A4PAPER)
&& fl_get_button(paper_->radio_portrait));
// Default unit choice is cm if metric, inches if US paper.
- bool const metric = (paperchoice == 1 && lyxrc.default_papersize > BufferParams::PAPER_EXECUTIVEPAPER)
+ bool const metric = (paperchoice == 1 && lyxrc.default_papersize > PAPER_EXECUTIVEPAPER)
|| paperchoice == 2 || paperchoice > 5;
string const default_unit = metric ? "cm" : "in";
updateWidgetsFromLengthString(paper_->input_custom_width,
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);
+}
+
+
+void FormDocument::branch_update(BufferParams const & params)
+{
+ if (!branch_.get())
+ return;
+
+ 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...
+ rebuild_selected_branches_browser();
+
+ // display proper colour...
+ RGBColor rgb;
+ string x11hexname;
+ if (current_branch == "none")
+ x11hexname = "none";
+ else {
+ Branch * branch = branchlist_.find(current_branch);
+ if (branch)
+ x11hexname = branch->getColor();
+ }
+
+ 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);
+
+ setEnabled(branch_->button_select,
+ (fl_get_browser(branch_->browser_all_branches) > 0));
+ setEnabled(branch_->button_deselect,
+ (fl_get_browser(branch_->browser_selection) > 0));
+ setEnabled(branch_->button_remove_branch,
+ (fl_get_browser(branch_->browser_all_branches) > 0));
+ setEnabled(branch_->button_modify,
+ (fl_get_browser(branch_->browser_all_branches) > 0));
}
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());
}