From fd6cd728a390aeac274f505723c1cdc92a60010a Mon Sep 17 00:00:00 2001 From: Martin Vermeer Date: Sun, 17 Aug 2003 11:28:23 +0000 Subject: [PATCH] The 'Branches' mega-patch. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7560 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 16 ++ lib/ui/stdmenus.ui | 7 + po/POTFILES.in | 4 + src/BranchList.C | 202 ++++++++++++++ src/BranchList.h | 106 +++++++ src/ChangeLog | 25 ++ src/InsetList.C | 23 ++ src/InsetList.h | 3 + src/LColor.C | 107 ++++++-- src/LColor.h | 22 +- src/LyXAction.C | 1 + src/Makefile.am | 2 + src/MenuBackend.C | 30 ++ src/MenuBackend.h | 6 +- src/bufferparams.C | 38 +++ src/bufferparams.h | 3 + src/factory.C | 11 + src/frontends/controllers/ChangeLog | 17 ++ src/frontends/controllers/ControlBranch.C | 44 +++ src/frontends/controllers/ControlBranch.h | 44 +++ src/frontends/controllers/ControlDocument.C | 8 + src/frontends/controllers/Makefile.am | 2 + src/frontends/xforms/ChangeLog | 22 ++ src/frontends/xforms/ColorHandler.C | 58 ++-- src/frontends/xforms/ColorHandler.h | 5 +- src/frontends/xforms/Dialogs.C | 8 +- src/frontends/xforms/FormBranch.C | 63 +++++ src/frontends/xforms/FormBranch.h | 37 +++ src/frontends/xforms/FormDocument.C | 259 ++++++++++++++++++ src/frontends/xforms/FormDocument.h | 26 ++ src/frontends/xforms/Makefile.am | 2 + src/frontends/xforms/forms/Makefile.am | 1 + src/frontends/xforms/forms/form_branch.fd | 107 ++++++++ src/frontends/xforms/forms/form_document.fd | 288 ++++++++++++++++---- src/insets/ChangeLog | 18 ++ src/insets/Makefile.am | 2 + src/insets/inset.h | 28 +- src/insets/insetbranch.C | 277 +++++++++++++++++++ src/insets/insetbranch.h | 115 ++++++++ src/lfuns.h | 3 +- src/lyxfunc.C | 8 + src/text3.C | 1 + 42 files changed, 1936 insertions(+), 113 deletions(-) create mode 100644 src/BranchList.C create mode 100644 src/BranchList.h create mode 100644 src/frontends/controllers/ControlBranch.C create mode 100644 src/frontends/controllers/ControlBranch.h create mode 100644 src/frontends/xforms/FormBranch.C create mode 100644 src/frontends/xforms/FormBranch.h create mode 100644 src/frontends/xforms/forms/form_branch.fd create mode 100644 src/insets/insetbranch.C create mode 100644 src/insets/insetbranch.h diff --git a/lib/ChangeLog b/lib/ChangeLog index f57384b5f4..224b8896f3 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,19 @@ + +2003-08-17 Martin Vermeer + + * ui/stdmenus.ui: implements the 'branch inset' + idea. This allows the output of various versions of a document + from a single source version, selectively outputing or suppressing + output of parts of the text. + This implementation contains a 'branch list editor' in a separate + tab of the document settings dialog. Branches are user definable + and have a "display colour" to distinguish them on-screen. + + ColorHandler was somewhat cleaned up. + (1) make possible a dynamically growing LColor list by allowing + the graphic context cache to grow along (vector); + (2) eliminate an IMHO unnecessary step in colour allocation. + 2003-08-14 John Levon * ui/stdmenus.ui: move Note up to the submenus section diff --git a/lib/ui/stdmenus.ui b/lib/ui/stdmenus.ui index 83f5608d46..091bb87a13 100644 --- a/lib/ui/stdmenus.ui +++ b/lib/ui/stdmenus.ui @@ -93,6 +93,7 @@ Menuset OptItem "Minipage Settings...|M" "inset-settings minipage" OptItem "Text Wrap Settings...|W" "inset-settings wrap" OptItem "Note Settings...|N" "inset-settings note" + OptItem "Branch Settings...|B" "inset-settings branch" # Hey, guess what's broken ? Surprise surprise, it's tabular stuff # This is in the Table submenu instead for now. # OptItem "Table Settings...|a" "inset-settings tabular" @@ -217,6 +218,8 @@ Menuset Submenu "Float|a" "insert_float" Submenu "Note|N" "insert_note" # YUCK + Submenu "Note|N" "insert_note" + Submenu "Branch|B" "branches" Submenu "File|e" "insert_file" Separator Item "Citation Reference...|C" "dialog-show-new-inset citation" @@ -326,6 +329,10 @@ Menuset Item "Greyed Out|G" "note-insert Greyedout" End + Menu "branches" + Branches + End + # # DOCUMENT MENU # diff --git a/po/POTFILES.in b/po/POTFILES.in index ef8ddaab7f..8e758eff0c 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,3 +1,4 @@ +src/BranchList.h src/BufferView.C src/BufferView_pimpl.C src/Chktex.C @@ -90,6 +91,7 @@ src/frontends/xforms/FormAboutlyx.C src/frontends/xforms/FormBase.C src/frontends/xforms/FormBibitem.C src/frontends/xforms/FormBibtex.C +src/frontends/xforms/FormBranch.C src/frontends/xforms/FormChanges.C src/frontends/xforms/FormCharacter.C src/frontends/xforms/FormCitation.C @@ -138,6 +140,7 @@ src/gettext.h src/importer.C src/insets/inset.C src/insets/insetbibtex.C +src/insets/insetbranch.C src/insets/insetcaption.C src/insets/insetenv.C src/insets/insetert.C @@ -180,6 +183,7 @@ src/mathed/ref_inset.C src/paragraph.C src/paragraph_funcs.C src/rowpainter.C +src/support/path_defines.C src/text.C src/text2.C src/text3.C diff --git a/src/BranchList.C b/src/BranchList.C new file mode 100644 index 0000000000..050b1b046c --- /dev/null +++ b/src/BranchList.C @@ -0,0 +1,202 @@ +/** + * \file BranchList.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS + */ + +#include "BranchList.h" +#include "support/LAssert.h" + +#include + +using std::bind2nd; +using std::remove_if; +using std::binary_function; +using namespace lyx::support; + + +string const Branch::getBranch() const +{ + return branch_; +} + + +void Branch::setBranch(string const & s) +{ + branch_ = s; +} + + +bool Branch::getSelected() const +{ + return selected_; +} + + +void Branch::setSelected(bool b) +{ + selected_ = b; +} + + +string const Branch::getColor() const +{ + return color_; +} + + +void Branch::setColor(string const & c) +{ + color_ = c; +} + + +void BranchList::clear() +{ + list.clear(); +} + + +string BranchList::getColor(string const & s) const +{ + List::const_iterator it = list.begin(); + List::const_iterator end = list.end(); + for (; it != end; ++it) { + if (s == it->getBranch()) { + return it->getColor(); + } + } + Assert(false); // Always + return string(); // never gets here +} + + + +void BranchList::setColor(string const & s, string const & val) +{ + List::iterator it = list.begin(); + List::iterator end = list.end(); + for (; it != end; ++it) { + if (s.find(it->getBranch(), 0) != string::npos) { + it->setColor(val); + return; + } + } + Assert(false); +} + + +void BranchList::setSelected(string const & s, bool val) +{ + List::iterator it = list.begin(); + List::iterator end = list.end(); + for (; it != end; ++it) { + if (s.find(it->getBranch(), 0) != string::npos) + it->setSelected(val); + } +} + + +void BranchList::add(string const & s) +{ + string::size_type i = 0; + while (true) { + string::size_type const j = s.find_first_of(separator(), i); + string name; + if (j == string::npos) + name = s.substr(i); + else + name = s.substr(i, j - i); + // Is this name already in the list? + List::const_iterator it = list.begin(); + List::const_iterator end = list.end(); + bool already = false; + for (; it != end; ++it) { + if (it->getBranch() == name) { + already = true; + break; + } + } + if (!already) { + Branch br; + br.setBranch(name); + br.setSelected(false); + br.setColor("none"); + list.push_back(br); + } + if (j == string::npos) + break; + i = j + 1; + } +} + + +namespace { + +struct match : public binary_function { + bool operator()(Branch const & br, string const & s) const { + return (br.getBranch() == s); + } +}; + +} // namespace anon. + + +void BranchList::remove(string const & s) +{ + list.remove_if(bind2nd(match(), s)); +} + + +bool BranchList::selected(string const & s) const +{ + List::const_iterator it = list.begin(); + List::const_iterator end = list.end(); + for (; it != end; ++it) { + if (s == it->getBranch()) + return it->getSelected(); + } + return false; +} + + +string BranchList::allBranches() const +{ + List::const_iterator it = list.begin(); + List::const_iterator end = list.end(); + string ret; + for (; it != end; ++it) { + ret += it->getBranch() + separator(); + } + // remove final '|': + string::size_type i = ret.find_last_of(separator()); + if (i != string::npos) + ret.erase(i); + return ret; +} + + +string BranchList::allSelected() const +{ + List::const_iterator it = list.begin(); + List::const_iterator end = list.end(); + string ret; + for (; it != end; ++it) { + if (it->getSelected()) + ret += it->getBranch() + separator(); + } + // remove final '|': + string::size_type i = ret.find_last_of(separator()); + if (i != string::npos) + ret.erase(i); + return ret; +} + + +string const BranchList::separator() const +{ + return separator_; +} diff --git a/src/BranchList.h b/src/BranchList.h new file mode 100644 index 0000000000..1456e95888 --- /dev/null +++ b/src/BranchList.h @@ -0,0 +1,106 @@ +// -*- C++ -*- +/** + * \file BranchList.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS + * + * + * \class Branch + * + * A class describing a 'branch', i.e., a named alternative for + * selectively outputting some parts of a document while suppressing + * other parts. + * + * A branch has a name, can either be selected or not, and uses a + * user-specifyable background colour. All these can be set and + * queried. + * + * \class BranchList + * + * A class containing a vector of all defined branches within a + * document. Has methods for selecting or deselecting branches by + * name, for outputting a '|'-separated string of all elements or only + * the selected ones, and for adding and removing elements. + */ + + +#ifndef BRANCHES_H +#define BRANCHES_H + +#include "LString.h" +#include + +class Branch { +public: + /// + string const getBranch() const; + /// + void setBranch(string const &); + /// + bool getSelected() const; + /// + void setSelected(bool); + /// + string const getColor() const; + /// + void setColor(string const &); + + +private: + /// + string branch_; + /// + bool selected_; + /// + string color_; +}; + + +class BranchList { +public: + /// + BranchList(): separator_("|") {}; + + /// + typedef std::list List; + + /// + void clear(); + /// + bool empty() { return list.empty(); }; + /// + bool size() const { return list.size(); }; + /// + List::const_iterator begin() const { return list.begin(); }; + /// + List::const_iterator end() const { return list.end(); }; + /// + string getColor(string const &) const; + /// + void setColor(string const &, string const &); + /// Select/deselect multiple branches given in '|'-separated string + void setSelected(string const &, bool); + /// Add multiple branches to list + void add(string const &); + /// remove a branch from list by name + void remove(string const &); + /// return whether this branch is selected + bool selected(string const &) const; + /// return, as a '|'-separated string, all branch names + string allBranches() const; + /// + string allSelected() const; + /// + string const separator() const; + +private: + /// + List list; + /// + string separator_; +}; + +#endif diff --git a/src/ChangeLog b/src/ChangeLog index 4e78662d05..4a7891cba1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,29 @@ +2003-08-17 Martin Vermeer + + * src/BranchList.[Ch]: + * src/InsetList.[Ch]: + * src/LColor.[Ch]: + * src/LyXAction.C: + * src/Makefile.am: + * src/MenuBackend.[Ch]: + * src/bufferparams.[Ch]: + * src/factory.C: + * src/lfuns.h: + * src/lyxfunc.C: + * src/text3.C: implements the 'branch inset' + idea. This allows the output of various versions of a document + from a single source version, selectively outputing or suppressing + output of parts of the text. + This implementation contains a 'branch list editor' in a separate + tab of the document settings dialog. Branches are user definable + and have a "display colour" to distinguish them on-screen. + + ColorHandler was somewhat cleaned up. + (1) make possible a dynamically growing LColor list by allowing + the graphic context cache to grow along (vector); + (2) eliminate an IMHO unnecessary step in colour allocation. + 2003-08-15 Kayvan A. Sylvan * BufferView_pimpl.C: compile fix diff --git a/src/InsetList.C b/src/InsetList.C index 499ab1fea2..6aa4e023d5 100644 --- a/src/InsetList.C +++ b/src/InsetList.C @@ -1,9 +1,12 @@ #include #include "InsetList.h" +#include "BufferView.h" +#include "buffer.h" #include "debug.h" #include "insets/updatableinset.h" +#include "insets/insetbranch.h" #include @@ -176,3 +179,23 @@ void InsetList::deleteInsetsLyXText(BufferView * bv) } } } + + +void InsetList::insetsOpenCloseBranch(BufferView * bv) +{ + BufferParams bp = bv->buffer()->params; + List::iterator it = list.begin(); + List::iterator end = list.end(); + for (; it != end; ++it) { + if (it->inset && it->inset->lyxCode() == InsetOld::BRANCH_CODE) { + InsetBranch * inset = static_cast(it->inset); + if (bp.branchlist.selected(inset->params().branch)) { + inset->open(bv); + } else { + inset->close(bv); + } + } + } +} + + diff --git a/src/InsetList.h b/src/InsetList.h index 27b34b29cf..f7fd23f4e2 100644 --- a/src/InsetList.h +++ b/src/InsetList.h @@ -54,6 +54,9 @@ public: void decreasePosAfterPos(lyx::pos_type pos); /// void deleteInsetsLyXText(BufferView * bv); + /// + void InsetList::insetsOpenCloseBranch(BufferView * bv); + private: /// List list; diff --git a/src/LColor.C b/src/LColor.C index a36d1a7d83..6d88e4e7fb 100644 --- a/src/LColor.C +++ b/src/LColor.C @@ -25,7 +25,7 @@ using std::endl; namespace { struct ColorEntry { - LColor::color lcolor; + int lcolor; char const * guiname; char const * latexname; char const * x11name; @@ -34,6 +34,11 @@ struct ColorEntry { } +struct TransformEntry { + char const * lyxname; + int ncolor; +}; + struct LColor::Pimpl { /// @@ -51,17 +56,24 @@ struct LColor::Pimpl { /// initialise a color entry void fill(ColorEntry const & entry) { - information & in = infotab[entry.lcolor]; - in.guiname = entry.guiname; - in.latexname = entry.latexname; - in.x11name = entry.x11name; - in.lyxname = entry.lyxname; + information in; + in.lyxname = string(entry.lyxname); + in.latexname = string(entry.latexname); + in.x11name = string(entry.x11name); + in.guiname = string(entry.guiname); + infotab[entry.lcolor] = in; + transform[string(entry.lyxname)] = int(entry.lcolor); } /// - typedef std::map InfoTab; + typedef std::map InfoTab; /// the table of color information InfoTab infotab; + + typedef std::map Transform; + /// the transform between colour name string and integer code. + Transform transform; + }; @@ -143,18 +155,31 @@ LColor::LColor(LColor const & c) LColor::~LColor() -{ - delete pimpl_; -} +{} void LColor::operator=(LColor const & c) { LColor tmp(c); - std::swap(pimpl_, tmp.pimpl_); + boost::swap(pimpl_, tmp.pimpl_); } +void LColor::fill(LColor::color c, + string const & lyxname, + string const & x11name, + string const & latexname, + string const & guiname) +{ + ColorEntry ce; + ce.lcolor = c; + ce.guiname = guiname.c_str(); + ce.latexname = latexname.c_str(); + ce.x11name = x11name.c_str(); + ce.lyxname = lyxname.c_str(); + pimpl_->fill(ce); +} + string const LColor::getGUIName(LColor::color c) const { @@ -165,6 +190,19 @@ string const LColor::getGUIName(LColor::color c) const } +string const LColor::getGUIName(string const & s) const +{ + Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s); + if (ici != pimpl_->transform.end()) { + Pimpl::InfoTab::const_iterator + it = pimpl_->infotab.find(ici->second); + if (it != pimpl_->infotab.end()) + return it->second.guiname; + } + return "none"; +} + + string const LColor::getX11Name(LColor::color c) const { Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c); @@ -178,6 +216,22 @@ string const LColor::getX11Name(LColor::color c) const } +string const LColor::getX11Name(string const & s) const +{ + Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s); + if (ici != pimpl_->transform.end()) { + Pimpl::InfoTab::const_iterator + it = pimpl_->infotab.find(ici->second); + if (it != pimpl_->infotab.end()) + return it->second.x11name; + } + lyxerr << "LyX internal error: Missing color" + " entry in LColor.C for " << s << endl; + lyxerr << "Using black." << endl; + return "black"; +} + + string const LColor::getLaTeXName(LColor::color c) const { Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c); @@ -187,6 +241,19 @@ string const LColor::getLaTeXName(LColor::color c) const } +string const LColor::getLaTeXName(string const & s) const +{ + Pimpl::Transform::const_iterator ici = pimpl_->transform.find(s); + if (ici != pimpl_->transform.end()) { + Pimpl::InfoTab::const_iterator + it = pimpl_->infotab.find(ici->second); + if (it != pimpl_->infotab.end()) + return it->second.latexname; + } + return "black"; +} + + string const LColor::getLyXName(LColor::color c) const { Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.find(c); @@ -196,6 +263,12 @@ string const LColor::getLyXName(LColor::color c) const } +size_t LColor::size() const +{ + return pimpl_->infotab.size(); +} + + void LColor::setColor(LColor::color col, string const & x11name) { Pimpl::InfoTab::iterator iti = pimpl_->infotab.find(col); @@ -219,7 +292,7 @@ bool LColor::setColor(string const & lyxname, string const & x11name) " redefined" << endl; return false; } - setColor (col, x11name); + setColor(col, x11name); return true; } @@ -230,7 +303,7 @@ LColor::color LColor::getFromGUIName(string const & guiname) const Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end(); for (; ici != end; ++ici) { if (!compare_ascii_no_case(_(ici->second.guiname), guiname)) - return ici->first; + return static_cast(ici->first); } return LColor::inherit; } @@ -238,13 +311,7 @@ LColor::color LColor::getFromGUIName(string const & guiname) const LColor::color LColor::getFromLyXName(string const & lyxname) const { - Pimpl::InfoTab::const_iterator ici = pimpl_->infotab.begin(); - Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end(); - for (; ici != end; ++ici) { - if (!compare_ascii_no_case(ici->second.lyxname, lyxname)) - return ici->first; - } - return LColor::inherit; + return static_cast(pimpl_->transform[lyxname]); } diff --git a/src/LColor.h b/src/LColor.h index 8b7f669e1e..6768a0615e 100644 --- a/src/LColor.h +++ b/src/LColor.h @@ -12,6 +12,7 @@ #define LCOLOR_H #include "LString.h" +#include /** This is a stateless class. @@ -174,6 +175,7 @@ public: ignore }; + /// LColor(); /// @@ -182,6 +184,14 @@ public: ~LColor(); /// void operator=(LColor const &); + + /// + void LColor::fill(LColor::color c, + string const & lyxname, + string const & x11name = string(), + string const & latexname = string(), + string const & guiname = string()); + /// set the given LyX color to the color defined by the X11 name given void setColor(LColor::color col, string const & x11name); /// set the given LyX color to the color defined by the X11 name given @@ -189,15 +199,25 @@ public: /// Get GUI name of color string const getGUIName(LColor::color c) const; + /// + string const getGUIName(string const & s) const; /// Get X11 name of color string const getX11Name(LColor::color c) const; + /// + string const getX11Name(string const & s) const; /// Get LaTeX name of color string const getLaTeXName(LColor::color c) const; + /// + string const getLaTeXName(string const & s) const; /// Get LyX name of color string const getLyXName(LColor::color c) const; + /// (string-to-string version not needed as it is identity) + + /// + size_t size() const; /// get the color from the GUI name LColor::color getFromGUIName(string const & guiname) const; @@ -207,7 +227,7 @@ private: /// struct Pimpl; /// - Pimpl * pimpl_; + boost::scoped_ptr pimpl_; }; /// the current color definitions diff --git a/src/LyXAction.C b/src/LyXAction.C index aa98a48ba2..42a8a09134 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -222,6 +222,7 @@ void LyXAction::init() { LFUN_MENU_SEPARATOR, "menu-separator-insert", Noop }, { LFUN_META_FAKE, "meta-prefix", NoBuffer }, { LFUN_INSET_MINIPAGE, "minipage-insert", Noop }, + { LFUN_INSERT_BRANCH, "branch-insert", Noop }, { LFUN_INSERT_NOTE, "note-insert", Noop }, { LFUN_GOTONOTE, "note-next", ReadOnly }, { LFUN_INSET_TOGGLE, "inset-toggle", ReadOnly }, diff --git a/src/Makefile.am b/src/Makefile.am index 77e0be4417..4f328f92d1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,6 +60,8 @@ lyx_SOURCES = \ BufferView_pimpl.h \ Bullet.C \ Bullet.h \ + BranchList.C \ + BranchList.h \ Chktex.C \ Chktex.h \ CutAndPaste.C \ diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 52e557a8ee..34207b68fe 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -69,6 +69,7 @@ MenuItem::MenuItem(Kind kind, string const & label, case FloatListInsert: case FloatInsert: case PasteRecent: + case Branches: break; case Command: action_ = lyxaction.LookupFunc(command); @@ -189,6 +190,7 @@ Menu & Menu::read(LyXLex & lex) { enum Menutags { md_item = 1, + md_branches, md_documents, md_endmenu, md_exportformats, @@ -208,6 +210,7 @@ Menu & Menu::read(LyXLex & lex) }; struct keyword_item menutags[md_last - 1] = { + { "branches", md_branches }, { "documents", md_documents }, { "end", md_endmenu }, { "exportformats", md_exportformats }, @@ -293,6 +296,10 @@ Menu & Menu::read(LyXLex & lex) add(MenuItem(MenuItem::PasteRecent)); break; + case md_branches: + add(MenuItem(MenuItem::Branches)); + break; + case md_optsubmenu: optional = true; // fallback to md_submenu @@ -635,6 +642,25 @@ void expandPasteRecent(Menu & tomenu, LyXView const * view) } +void expandBranches(Menu & tomenu, LyXView const * view) +{ + BufferParams const & params = view->buffer()->params; + + std::list::const_iterator cit = params.branchlist.begin(); + std::list::const_iterator end = params.branchlist.end(); + + for (int ii = 1; cit != end; ++cit, ++ii) { + string label = cit->getBranch(); + int const action = lyxaction. + getPseudoAction(LFUN_INSERT_BRANCH, + (cit->getBranch())); + if (ii < 10) + label = tostr(ii) + ". " + label + "|" + tostr(ii); + tomenu.add(MenuItem(MenuItem::Command, label, action), view); + } +} + + } // namespace anon @@ -671,6 +697,10 @@ void MenuBackend::expand(Menu const & frommenu, Menu & tomenu, expandPasteRecent(tomenu, view); break; + case MenuItem::Branches: + expandBranches(tomenu, view); + break; + case MenuItem::Toc: expandToc(tomenu, view); break; diff --git a/src/MenuBackend.h b/src/MenuBackend.h index 5366515f2c..d47968d18e 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -65,7 +65,9 @@ public: FloatInsert, /** This is the list of selections that can be pasted. */ - PasteRecent + PasteRecent, + /** Available branches in document */ + Branches }; /// Create a Command type MenuItem MenuItem(Kind kind, @@ -196,7 +198,7 @@ public: /// Expands some special entries of the menu /** The entries with the following kind are expanded to a sequence of Command MenuItems: Lastfiles, Documents, - ViewFormats, ExportFormats, UpdateFormats + ViewFormats, ExportFormats, UpdateFormats, Branches */ void expand(Menu const & frommenu, Menu & tomenu, LyXView const *) const; diff --git a/src/bufferparams.C b/src/bufferparams.C index 02b6b677ed..837e481f29 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -24,6 +24,8 @@ #include "author.h" #include "gettext.h" +#include "LColor.h" + #include "support/lyxalgo.h" // for lyx::count #include "support/lyxlib.h" #include "support/lstrings.h" @@ -192,6 +194,31 @@ string const BufferParams::readToken(LyXLex & lex, string const & token) } else if (token == "\\tracking_changes") { lex.nextToken(); tracking_changes = lex.getInteger(); + } else if (token == "\\branch") { + lex.nextToken(); + string branch = lex.getString(); + branchlist.add(branch); + while (true) { + lex.nextToken(); + string const tok = lex.getString(); + if (tok == "\\end_branch") + break; + if (tok == "\\selected") { + lex.nextToken(); + branchlist.setSelected(branch, lex.getInteger()); + } + // not yet operational + if (tok == "\\color") { + lex.nextToken(); + string color = lex.getString(); + branchlist.setColor(branch, color); + // Update also the LColor table: + if (color == "none") + color = lcolor.getX11Name(LColor::background); + lcolor.fill(static_cast(lcolor.size()), + branch, color); + } + } } else if (token == "\\author") { lex.nextToken(); istringstream ss(STRCONV(lex.getString())); @@ -380,6 +407,17 @@ void BufferParams::writeFile(ostream & os) const << "\n\\use_numerical_citations " << use_numerical_citations << "\n\\paperorientation " << string_orientation[orientation] << '\n'; + + std::list::const_iterator it = branchlist.begin(); + std::list::const_iterator end = branchlist.end(); + for (; it != end; ++it) { + os << "\\branch " << it->getBranch() + << "\n\\selected " << it->getSelected() + << "\n\\color " << it->getColor() + << "\n\\end_branch" + << "\n"; + } + if (!paperwidth.empty()) os << "\\paperwidth " << VSpace(paperwidth).asLyXCommand() << '\n'; diff --git a/src/bufferparams.h b/src/bufferparams.h index 45bc0fc160..e2ab54e75f 100644 --- a/src/bufferparams.h +++ b/src/bufferparams.h @@ -21,6 +21,7 @@ #include "texrow.h" #include "author.h" #include "paper.h" +#include "BranchList.h" #include "insets/insetquotes.h" @@ -134,6 +135,8 @@ public: int tocdepth; /// Language const * language; + /// BranchList: + BranchList branchlist; /// string inputenc; /// diff --git a/src/factory.C b/src/factory.C index 4474eb1a5e..d89d4aa86d 100644 --- a/src/factory.C +++ b/src/factory.C @@ -37,6 +37,7 @@ #include "insets/insetmarginal.h" #include "insets/insetminipage.h" #include "insets/insetnote.h" +#include "insets/insetbranch.h" #include "insets/insetoptarg.h" #include "insets/insetref.h" #include "insets/insetspace.h" @@ -77,6 +78,14 @@ InsetOld * createInset(FuncRequest const & cmd) arg = "Note"; return new InsetNote(params, arg); } + case LFUN_INSERT_BRANCH: + { + string arg = cmd.getArg(0); + if (arg.empty()) + arg = "none"; + return new InsetBranch(params, arg); + } + case LFUN_INSET_ERT: return new InsetERT(params); @@ -357,6 +366,8 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf) } else if (tmptok == "Note" || tmptok == "Comment" || tmptok == "Greyedout") { inset = new InsetNote(buf.params, tmptok); + } else if (tmptok == "Branch") { + inset = new InsetBranch(buf.params, tmptok); } else if (tmptok == "Include") { InsetCommandParams p("Include"); inset = new InsetInclude(p, buf); diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 08157861f4..fe38f3ed82 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,4 +1,21 @@ +2003-08-16 Martin Vermeer + + * ControlBranch.[Ch]: + * ControlDocument.C: + * Makefile.am: implements the 'branch + inset' idea. This allows the output of various versions of a + document from a single source version, selectively outputing or + suppressing output of parts of the text. + This implementation contains a 'branch list editor' in a separate + tab of the document settings dialog. Branches are user definable + and have a "display colour" to distinguish them on-screen. + + ColorHandler was somewhat cleaned up. + (1) make possible a dynamically growing LColor list by allowing + the graphic context cache to grow along (vector); + (2) eliminate an IMHO unnecessary step in colour allocation. + 2003-08-15 André Pönitz * ControlErrorList.C: diff --git a/src/frontends/controllers/ControlBranch.C b/src/frontends/controllers/ControlBranch.C new file mode 100644 index 0000000000..137203b719 --- /dev/null +++ b/src/frontends/controllers/ControlBranch.C @@ -0,0 +1,44 @@ +/** + * \file ControlBranch.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Angus Leeming + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS + */ + +#include + +#include "ControlBranch.h" +#include "funcrequest.h" +#include "insets/insetbranch.h" +#include "debug.h" + +ControlBranch::ControlBranch(Dialog & parent) + : Dialog::Controller(parent) +{} + + +bool ControlBranch::initialiseParams(string const & data) +{ + InsetBranchParams params; + InsetBranchMailer::string2params(data, params); + params_.reset(new InsetBranchParams(params)); + + return true; +} + + +void ControlBranch::clearParams() +{ + params_.reset(); +} + +void ControlBranch::dispatchParams() +{ + string const lfun = InsetBranchMailer::params2string(string("branch"), params()); + kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun)); +} + diff --git a/src/frontends/controllers/ControlBranch.h b/src/frontends/controllers/ControlBranch.h new file mode 100644 index 0000000000..1c192f4c86 --- /dev/null +++ b/src/frontends/controllers/ControlBranch.h @@ -0,0 +1,44 @@ +// -*- C++ -*- +/** + * \file ControlBranch.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Angus Leeming + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS + */ + +#ifndef CONTROLBRANCH_H +#define CONTROLBRANCH_H + + +#include "Dialog.h" +#include "debug.h" + +class InsetBranchParams; + +class ControlBranch : public Dialog::Controller { +public: + /// + ControlBranch(Dialog &); + /// + virtual bool initialiseParams(string const & data); + /// + virtual void clearParams(); + /// + virtual void dispatchParams(); + /// + virtual bool isBufferDependent() const { return true; } + /// + InsetBranchParams & params() { return *params_.get(); } + /// + InsetBranchParams const & params() const { return *params_.get(); } + /// +private: + /// + boost::scoped_ptr params_; +}; + +#endif // CONTROLBRANCH_H diff --git a/src/frontends/controllers/ControlDocument.C b/src/frontends/controllers/ControlDocument.C index 8e5ae244e1..ca6e3afc4d 100644 --- a/src/frontends/controllers/ControlDocument.C +++ b/src/frontends/controllers/ControlDocument.C @@ -82,6 +82,14 @@ void ControlDocument::apply() buffer()->markDirty(); lv_.message(_("Document settings applied")); + + // Open insets of selected branches, close deselected ones + // Currently only top-level insets in buffer handled (bug). + ParIterator pit = buffer()->par_iterator_begin(); + ParIterator pend = buffer()->par_iterator_end(); + for (; pit != pend; ++pit) { + pit->insetlist.insetsOpenCloseBranch(bufferview()); + } } diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index c34df9e61c..89fea1c2d9 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -31,6 +31,8 @@ libcontrollers_la_SOURCES= \ ControlBibtex.h \ ControlButtons.C \ ControlButtons.h \ + ControlBranch.C \ + ControlBranch.h \ ControlCharacter.C \ ControlCharacter.h \ ControlChanges.C \ diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 3c42fd35d9..09591b944d 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,25 @@ +2003-08-17 Martin Vermeer + + * ColorHandler.[Ch]: + * Dialogs.C: + * FormBranch.[Ch]: + * FormDocument.[Ch]: + * Makefile.am: + * forms/Makefile.am: + * forms/form_branch.fd: + * forms/form_document.fd: implements the + 'branch inset' idea. This allows the output of various versions of + a document from a single source version, selectively outputing or + suppressing output of parts of the text. + This implementation contains a 'branch list editor' in a separate + tab of the document settings dialog. Branches are user definable + and have a "display colour" to distinguish them on-screen. + + ColorHandler was somewhat cleaned up. + (1) make possible a dynamically growing LColor list by allowing + the graphic context cache to grow along (vector); + (2) eliminate an IMHO unnecessary step in colour allocation. + 2003-08-12 Michael Schmitt * FormMathsMatrix.C: rename "Center" to "Middle" diff --git a/src/frontends/xforms/ColorHandler.C b/src/frontends/xforms/ColorHandler.C index 3b5ba5d3f2..4c1865b2d1 100644 --- a/src/frontends/xforms/ColorHandler.C +++ b/src/frontends/xforms/ColorHandler.C @@ -44,6 +44,7 @@ namespace { LyXColorHandler::LyXColorHandler() + : colorGCcache(LColor::ignore + 1) { display = fl_get_display(); drawable = XCreatePixmap(display, @@ -52,7 +53,7 @@ LyXColorHandler::LyXColorHandler() colormap = fl_state[fl_get_vclass()].colormap; // Clear the GC cache - for (int i = 0; i <= LColor::ignore; ++i) { + for (int i = 0; i < colorGCcache.size(); ++i) { colorGCcache[i] = 0; } } @@ -61,7 +62,7 @@ LyXColorHandler::LyXColorHandler() LyXColorHandler::~LyXColorHandler() { // Release all the registered GCs - for (int i = 0; i <= LColor::ignore; ++i) { + for (unsigned i = 0; i < colorGCcache.size(); ++i) { if (colorGCcache[i] != 0) { XFreeGC(display, colorGCcache[i]); } @@ -82,40 +83,28 @@ unsigned long LyXColorHandler::colorPixel(LColor::color c) } -// Gets GC according to color -// Uses caching -GC LyXColorHandler::getGCForeground(LColor::color c) +GC LyXColorHandler::getGCForeground(string const & s) { - if (colorGCcache[c] != 0) - return colorGCcache[c]; - XColor xcol; XColor ccol; - string const s = lcolor.getX11Name(c); XGCValues val; - // Look up the RGB values for the color, and an approximate // color that we can hope to get on this display. if (XLookupColor(display, colormap, s.c_str(), &xcol, &ccol) == 0) { lyxerr << bformat( - _("LyX: Unknown X11 color %1$s for %2$s\n" + _("LyX: Unknown X11 color %1$s\n" " Using black instead, sorry!"), - s, lcolor.getGUIName(c)) << endl; + s) << endl; unsigned long bla = BlackPixel(display, DefaultScreen(display)); val.foreground = bla; // Try the exact RGB values first, then the approximate. } else if (XAllocColor(display, colormap, &xcol) != 0) { if (lyxerr.debugging(Debug::GUI)) { - lyxerr << bformat(_("LyX: X11 color %1$s allocated for %2$s"), - s, lcolor.getGUIName(c)) << endl; + lyxerr << bformat(_("LyX: X11 color %1$s allocated"), + s) << endl; } val.foreground = xcol.pixel; - } else if (XAllocColor(display, colormap, &ccol)) { - lyxerr << bformat( - _("LyX: Using approximated X11 color %1$s allocated for %2$s"), - s, lcolor.getGUIName(c)) << endl; - val.foreground = xcol.pixel; } else { // Here we are traversing the current colormap to find // the color closest to the one we want. @@ -155,8 +144,8 @@ GC LyXColorHandler::getGCForeground(LColor::color c) } lyxerr << bformat( - _("LyX: Couldn't allocate '%1$s' for %2$s with (r,g,b)=%3$s.\n"), - s, lcolor.getGUIName(c), tostr(xcol)); + _("LyX: Couldn't allocate '%1$s' with (r,g,b)=%3$s.\n"), + s, tostr(xcol)); lyxerr << bformat( _(" Using closest allocated color with (r,g,b)=%1$s instead.\n" @@ -165,11 +154,34 @@ GC LyXColorHandler::getGCForeground(LColor::color c) val.foreground = cmap[closest_pixel].pixel; } - val.function = GXcopy; - return colorGCcache[c] = XCreateGC(display, drawable, + return XCreateGC(display, drawable, GCForeground | GCFunction, &val); } + +// Gets GC according to color +// Uses caching +GC LyXColorHandler::getGCForeground(LColor::color c) +{ + if (static_cast(c) >= colorGCcache.size()) { + colorGCcache.resize(c + 1, 0); + } + + if (colorGCcache[c] != 0) { + return colorGCcache[c]; + } + XColor xcol; + XColor ccol; + string const s = lcolor.getX11Name(c); + // Look up the RGB values for the color, and an approximate + // color that we can hope to get on this display. + if (XLookupColor(display, colormap, s.c_str(), &xcol, &ccol) == 0) { + lyxerr << bformat( + _("LyX: Unknown X11 color %1$s for %2$s\n"), + s, lcolor.getGUIName(c)) << endl; + } + return colorGCcache[c] = getGCForeground(s); +} // Gets GC for line diff --git a/src/frontends/xforms/ColorHandler.h b/src/frontends/xforms/ColorHandler.h index a402f22f3e..7f6ccf2e53 100644 --- a/src/frontends/xforms/ColorHandler.h +++ b/src/frontends/xforms/ColorHandler.h @@ -16,6 +16,7 @@ #include "frontends/Painter.h" #include +#include #include // This is only included to provide stuff for the non-public sections @@ -48,8 +49,10 @@ private: Display * display; /// Colormap colormap; + /// + std::vector colorGCcache; /// - GC colorGCcache[LColor::ignore + 1]; + GC getGCForeground(string const & s); /// typedef std::map LineGCCache; /// diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 0e9ee0c52f..4193ab234b 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -17,6 +17,7 @@ #include "ControlAboutlyx.h" #include "ControlBibtex.h" +#include "ControlBranch.h" #include "ControlChanges.h" #include "ControlCharacter.h" #include "ControlCitation.h" @@ -44,6 +45,7 @@ #include "FormAboutlyx.h" #include "FormBibitem.h" #include "FormBibtex.h" +#include "FormBranch.h" #include "FormChanges.h" #include "FormCharacter.h" #include "FormCitation.h" @@ -110,7 +112,7 @@ FormMathsBitmap * createFormBitmap(Dialog & parent, string const & title, } -char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "changes", +char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "branch", "changes", "character", "citation", "error", "errorlist" , "ert", "external", "file", "float", "graphics", "include", "index", "label", "latexlog", "mathpanel", "mathaccents", "matharrows", "mathoperators", "mathrelations", "mathgreek", @@ -411,6 +413,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlNote(*dialog)); dialog->setView(new FormNote(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); + } else if (name == "branch") { + dialog->setController(new ControlBranch(*dialog)); + dialog->setView(new FormBranch(*dialog)); + dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "paragraph") { dialog->setController(new ControlParagraph(*dialog)); dialog->setView(new FormParagraph(*dialog)); diff --git a/src/frontends/xforms/FormBranch.C b/src/frontends/xforms/FormBranch.C new file mode 100644 index 0000000000..3ef6f982a6 --- /dev/null +++ b/src/frontends/xforms/FormBranch.C @@ -0,0 +1,63 @@ +/** + * \file FormBranch.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS + */ + + +#include + +#include "xformsBC.h" +#include "ControlBranch.h" +#include "FormBranch.h" +#include "forms/form_branch.h" +#include "xforms_helpers.h" // formatted +#include "lyx_forms.h" +#include "insets/insetbranch.h" +#include "debug.h" + +typedef FormController > base_class; + +FormBranch::FormBranch(Dialog & parent) + : base_class(parent, _("Branch")) +{} + + +void FormBranch::build() +{ + string all_branches(controller().params().branchlist.allBranches()); + + dialog_.reset(build_branch(this)); + + fl_addto_choice(dialog_->choice_branch, all_branches.c_str()); + + bcview().setOK(dialog_->button_ok); + bcview().setApply(dialog_->button_apply); + bcview().setCancel(dialog_->button_cancel); +} + + +void FormBranch::update() +{ + // Make changes in all_branches propagate within session: + string all_branches(controller().params().branchlist.allBranches()); + fl_clear_choice(dialog_->choice_branch); + fl_addto_choice(dialog_->choice_branch, all_branches.c_str()); + + string branch(controller().params().branch); + if (all_branches.find(branch) != string::npos && branch != "none") + fl_set_choice_text(dialog_->choice_branch, branch.c_str()); +} + + +void FormBranch::apply() +{ + string const type = fl_get_choice_text(dialog_->choice_branch); + + controller().params().branch = type; +} + diff --git a/src/frontends/xforms/FormBranch.h b/src/frontends/xforms/FormBranch.h new file mode 100644 index 0000000000..c1aea79f06 --- /dev/null +++ b/src/frontends/xforms/FormBranch.h @@ -0,0 +1,37 @@ +// -*- C++ -*- +/** + * \file FormBranch.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS + */ + +#ifndef FORMBRANCH_H +#define FORMBRANCH_H + + +#include "FormDialogView.h" + + +class ControlBranch; +struct FD_branch; + +/** This class provides an XForms implementation of the Branch Dialog. + */ +class FormBranch : public FormController > { +public: + /// Constructor + FormBranch(Dialog &); +private: + /// + virtual void apply(); + /// Build the dialog + virtual void build(); + /// Update dialog before showing it + virtual void update(); +}; + +#endif // FORMBRANCH_H diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index 5d0cf46793..1f3d0a4fb3 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -5,6 +5,8 @@ * * \author Jürgen Vigna * \author Rob Lahaye + * \author Martin Vermeer + * \author Juergen Spitzmueller * * Full author contact details are available in file CREDITS */ @@ -17,17 +19,23 @@ #include "xformsBC.h" #include "ButtonController.h" +#include "FormColorpicker.h" +#include "LColor.h" +#include "Lsstream.h" #include "bmtable.h" #include "checkedwidgets.h" +#include "Tooltips.h" #include "input_validators.h" // fl_unsigned_float_filter #include "xforms_helpers.h" +#include "bufferparams.h" #include "CutAndPaste.h" #include "debug.h" #include "language.h" #include "lyxrc.h" #include "lyxtextclasslist.h" #include "tex-strings.h" +#include "ColorHandler.h" #include "controllers/frnt_lang.h" #include "controllers/helper_funcs.h" @@ -43,12 +51,15 @@ #include #include +#include using namespace lyx::support; using std::bind2nd; using std::vector; using std::endl; +using std::setw; +using std::setfill; namespace { @@ -59,6 +70,7 @@ bool const scalableTabfolders = false; bool const scalableTabfolders = true; #endif + } // namespace anon @@ -343,6 +355,46 @@ void FormDocument::build() 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); @@ -366,6 +418,9 @@ void FormDocument::build() fl_deactivate_object(fbullet); fl_set_object_lcol(fbullet, FL_INACTIVE); } + + fl_addto_tabfolder(dialog_->tabfolder,_("Branches").c_str(), + branch_->form); } @@ -378,6 +433,7 @@ void FormDocument::apply() language_apply(params); options_apply(params); bullets_apply(params); + branch_apply(params); } @@ -395,6 +451,7 @@ void FormDocument::update() language_update(params); options_update(params); bullets_update(params); + branch_update(params); } @@ -456,6 +513,15 @@ ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long) 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(); @@ -606,6 +672,139 @@ ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long) } +void FormDocument::branch_input(FL_OBJECT * ob) +{ + BufferParams & params = controller().params(); + std::vector vec; + + 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); + 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.size()); + lcolor.fill(c, new_branch, lcolor.getX11Name(LColor::background)); + } + + } 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()); + } + } + } else if (ob == branch_->button_modify) { + unsigned i = fl_get_browser(branch_->browser_all_branches); + string const current_branch = + fl_get_browser_line(branch_->browser_all_branches, i); + + 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); + } + + RGBColor col = picker_->requestColor(before); + if (before != col) { + fl_mapcolor(GUI_COLOR_CHOICE, col.r, col.g, col.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); + } + } 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; + 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); + } + 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)); + + branchlist_ = params.branchlist; +} + + bool FormDocument::class_apply(BufferParams ¶ms) { bool redo = false; @@ -830,6 +1029,16 @@ void FormDocument::bullets_apply(BufferParams & params) } +void FormDocument::branch_apply(BufferParams & params) +{ + BufferParams & prms = controller().params(); + if (branchlist_.empty()) + branchlist_ = prms.branchlist; + params.branchlist = branchlist_; + branchlist_.clear(); +} + + void FormDocument::UpdateClassParams(BufferParams const & params) { // These are the params that have to be updated on any class change @@ -1094,6 +1303,56 @@ void FormDocument::bullets_update(BufferParams const & params) } +void FormDocument::branch_update(BufferParams const & params) +{ + 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 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); + current_branch = + 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 vec = getVectorFromString(all_selected, "|"); + for (unsigned i = 0; i < vec.size(); ++i) { + fl_addto_browser(branch_->browser_selection, vec[i].c_str()); + } + } + // display proper colour... + 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); + + 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)); +} + + void FormDocument::checkReadOnly() { if (bc().readOnly(controller().bufferIsReadonly())) { diff --git a/src/frontends/xforms/FormDocument.h b/src/frontends/xforms/FormDocument.h index 41d5686e24..370b6cb328 100644 --- a/src/frontends/xforms/FormDocument.h +++ b/src/frontends/xforms/FormDocument.h @@ -17,18 +17,32 @@ #include +#include "lyx_forms.h" #include class ControlDocument; class BufferParams; +class FormColorpicker; + struct FD_document; struct FD_document_paper; struct FD_document_class; struct FD_document_language; struct FD_document_options; struct FD_document_bullet; +struct FD_document_branch; + +namespace { + +enum GuiColors { + GUI_COLOR_CHOICE = FL_FREE_COL15 +}; + + +} + /** This class provides an XForms implementation of the FormDocument dialog. * The table-layout-form here changes values for latex-tabulars @@ -49,6 +63,8 @@ private: /// Apply from dialog virtual void apply(); + /// + void branch_input(FL_OBJECT *); /// void ChoiceBulletSize(FL_OBJECT * ob, long); /// @@ -78,6 +94,8 @@ private: void options_update(BufferParams const &); /// void bullets_update(BufferParams const &); + /// + void branch_update(BufferParams const &); /// void paper_apply(BufferParams &); @@ -89,6 +107,8 @@ private: bool options_apply(BufferParams &); /// void bullets_apply(BufferParams &); + /// + void branch_apply(BufferParams &); /// Real GUI implementation. boost::scoped_ptr paper_; @@ -101,6 +121,10 @@ private: /// boost::scoped_ptr bullets_; /// + boost::scoped_ptr branch_; + /// + boost::scoped_ptr picker_; + /// int ActCell; /// int Confirmed; @@ -112,6 +136,8 @@ private: FL_OBJECT * fbullet; /// std::vector lang_; + /// Contains all legal branches for this doc + BranchList branchlist_; }; #endif diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index b23269f6b8..c6dafe8f1b 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -74,6 +74,8 @@ libxforms_la_SOURCES = \ FormBibtex.h \ FormBrowser.C \ FormBrowser.h \ + FormBranch.C \ + FormBranch.h \ FormChanges.C \ FormChanges.h \ FormCharacter.C \ diff --git a/src/frontends/xforms/forms/Makefile.am b/src/frontends/xforms/forms/Makefile.am index cfffa65b98..1d3ea7aab6 100644 --- a/src/frontends/xforms/forms/Makefile.am +++ b/src/frontends/xforms/forms/Makefile.am @@ -13,6 +13,7 @@ SRCS = form_aboutlyx.fd \ form_bibitem.fd \ form_bibtex.fd \ form_browser.fd \ + form_branch.fd \ form_changes.fd \ form_character.fd \ form_citation.fd \ diff --git a/src/frontends/xforms/forms/form_branch.fd b/src/frontends/xforms/forms/form_branch.fd new file mode 100644 index 0000000000..02bc2a518b --- /dev/null +++ b/src/frontends/xforms/forms/form_branch.fd @@ -0,0 +1,107 @@ +Magic: 13000 + +Internal Form Definition File + (do not change) + +Number of forms: 1 +Unit of measure: FL_COORD_PIXEL +SnapGrid: 7 + +=============== FORM =============== +Name: form_branch +Width: 407 +Height: 113 +Number of Objects: 5 + +-------------------- +class: FL_BOX +type: UP_BOX +box: 0 0 407 113 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + +-------------------- +class: FL_CHOICE +type: NORMAL_CHOICE +box: 154 21 217 28 +boxtype: FL_FRAME_BOX +colors: FL_COL1 FL_BLACK +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Branch:|#B +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: choice_branch +callback: C_FormDialogView_InputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: RETURN_BUTTON +box: 49 70 84 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: OK +shortcut: ^M +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_ok +callback: C_FormDialogView_OKCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: RETURN_BUTTON +box: 154 70 98 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Apply|#A +shortcut: ^M +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_apply +callback: C_FormDialogView_ApplyCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: RETURN_BUTTON +box: 266 70 105 28 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Cancel|^[ +shortcut: ^M +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_cancel +callback: C_FormDialogView_CancelCB +argument: 0 + +============================== +create_the_forms diff --git a/src/frontends/xforms/forms/form_document.fd b/src/frontends/xforms/forms/form_document.fd index 2c38baaed5..25a8c36cfc 100644 --- a/src/frontends/xforms/forms/form_document.fd +++ b/src/frontends/xforms/forms/form_document.fd @@ -3,7 +3,7 @@ Magic: 13000 Internal Form Definition File (do not change) -Number of forms: 6 +Number of forms: 7 Unit of measure: FL_COORD_PIXEL SnapGrid: 5 @@ -178,13 +178,13 @@ argument: 0 =============== FORM =============== Name: form_document_paper Width: 395 -Height: 310 +Height: 320 Number of Objects: 29 -------------------- class: FL_BOX type: FLAT_BOX -box: 0 0 395 310 +box: 0 0 395 320 boxtype: FL_FLAT_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -247,7 +247,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Width:|#W shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_custom_width callback: C_FormBaseInputCB @@ -265,7 +265,7 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_custom_width_units callback: C_FormBaseInputCB @@ -283,7 +283,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Height:|#H shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_custom_height callback: C_FormBaseInputCB @@ -301,7 +301,7 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_custom_height_units callback: C_FormBaseInputCB @@ -328,7 +328,7 @@ argument: -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -400,7 +400,7 @@ argument: -------------------- class: FL_LABELFRAME type: ENGRAVED_FRAME -box: 5 130 385 175 +box: 5 130 385 185 boxtype: FL_NO_BOX colors: FL_BLACK FL_COL1 alignment: FL_ALIGN_TOP_LEFT @@ -463,7 +463,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Top:|#T shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_top_margin callback: C_FormBaseInputCB @@ -481,7 +481,7 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_top_margin_units callback: C_FormBaseInputCB @@ -499,7 +499,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Bottom:|#B shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_bottom_margin callback: C_FormBaseInputCB @@ -517,7 +517,7 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_bottom_margin_units callback: C_FormBaseInputCB @@ -526,7 +526,7 @@ argument: 0 -------------------- class: FL_INPUT type: NORMAL_INPUT -box: 75 240 50 25 +box: 75 250 50 25 boxtype: FL_DOWN_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_LEFT @@ -535,7 +535,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Inner:|#I shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_inner_margin callback: C_FormBaseInputCB @@ -544,7 +544,7 @@ argument: 0 -------------------- class: FL_CHOICE type: NORMAL_CHOICE -box: 125 240 50 25 +box: 125 250 50 25 boxtype: FL_FRAME_BOX colors: FL_COL1 FL_BLACK alignment: FL_ALIGN_LEFT @@ -553,7 +553,7 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_inner_margin_units callback: C_FormBaseInputCB @@ -562,7 +562,7 @@ argument: 0 -------------------- class: FL_INPUT type: NORMAL_INPUT -box: 75 270 50 25 +box: 75 280 50 25 boxtype: FL_DOWN_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_LEFT @@ -571,7 +571,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Outer:|#u shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_outer_margin callback: C_FormBaseInputCB @@ -580,7 +580,7 @@ argument: 0 -------------------- class: FL_CHOICE type: NORMAL_CHOICE -box: 125 270 50 25 +box: 125 280 50 25 boxtype: FL_FRAME_BOX colors: FL_COL1 FL_BLACK alignment: FL_ALIGN_LEFT @@ -589,7 +589,7 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_outer_margin_units callback: C_FormBaseInputCB @@ -607,7 +607,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Headheight:|#H shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_head_height callback: C_FormBaseInputCB @@ -625,7 +625,7 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_head_height_units callback: C_FormBaseInputCB @@ -643,7 +643,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Headsep:|#d shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_head_sep callback: C_FormBaseInputCB @@ -661,7 +661,7 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_head_sep_units callback: C_FormBaseInputCB @@ -679,7 +679,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Footskip:|#F shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_foot_skip callback: C_FormBaseInputCB @@ -697,7 +697,7 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_foot_skip_units callback: C_FormBaseInputCB @@ -865,7 +865,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Spacing:|#g shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_spacing callback: C_FormBaseInputCB @@ -883,7 +883,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Extra Options:|#X shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_extra callback: C_FormBaseInputCB @@ -901,7 +901,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_skip callback: C_FormBaseInputCB @@ -919,7 +919,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Default Skip:|#u shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_skip callback: C_FormBaseInputCB @@ -928,7 +928,7 @@ argument: 0 -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -1000,7 +1000,7 @@ argument: -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -1072,7 +1072,7 @@ argument: -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -1154,7 +1154,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_spacing callback: C_FormBaseInputCB @@ -1172,7 +1172,7 @@ size: FL_DEFAULT_SIZE lcol: FL_BLACK label: shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: choice_skip_units callback: C_FormBaseInputCB @@ -1259,7 +1259,7 @@ argument: 0 -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -1349,13 +1349,13 @@ argument: 0 =============== FORM =============== Name: form_document_options Width: 395 -Height: 310 +Height: 325 Number of Objects: 8 -------------------- class: FL_BOX type: FLAT_BOX -box: 0 0 395 310 +box: 0 0 395 325 boxtype: FL_FLAT_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -1373,7 +1373,7 @@ argument: -------------------- class: FL_INPUT type: NORMAL_INPUT -box: 185 20 120 25 +box: 185 15 120 25 boxtype: FL_DOWN_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_LEFT @@ -1382,7 +1382,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: Float Placement:|#L shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_float_placement callback: C_FormBaseInputCB @@ -1391,7 +1391,7 @@ argument: 0 -------------------- class: FL_COUNTER type: SIMPLE_COUNTER -box: 185 60 80 25 +box: 185 55 80 25 boxtype: FL_UP_BOX colors: FL_COL1 FL_BLUE alignment: FL_ALIGN_LEFT @@ -1413,7 +1413,7 @@ argument: 0 -------------------- class: FL_COUNTER type: SIMPLE_COUNTER -box: 185 100 80 25 +box: 185 90 80 25 boxtype: FL_UP_BOX colors: FL_COL1 FL_BLUE alignment: FL_ALIGN_LEFT @@ -1435,7 +1435,7 @@ argument: 0 -------------------- class: FL_CHOICE type: NORMAL_CHOICE -box: 185 140 140 25 +box: 185 130 140 25 boxtype: FL_FRAME_BOX colors: FL_COL1 FL_BLACK alignment: FL_ALIGN_LEFT @@ -1453,10 +1453,10 @@ argument: 0 -------------------- class: FL_CHECKBUTTON type: PUSH_BUTTON -box: 185 225 25 25 +box: 185 220 140 25 boxtype: FL_NO_BOX colors: FL_COL1 FL_YELLOW -alignment: FL_ALIGN_LEFT +alignment: FL_ALIGN_CENTER style: FL_NORMAL_STYLE size: FL_NORMAL_SIZE lcol: FL_BLACK @@ -1471,7 +1471,7 @@ argument: 0 -------------------- class: FL_CHOICE type: NORMAL_CHOICE -box: 185 265 140 25 +box: 185 260 140 25 boxtype: FL_FRAME_BOX colors: FL_COL1 FL_BLACK alignment: FL_ALIGN_LEFT @@ -1489,7 +1489,7 @@ argument: 0 -------------------- class: FL_CHOICE type: NORMAL_CHOICE -box: 185 185 140 25 +box: 185 170 140 25 boxtype: FL_FRAME_BOX colors: FL_COL1 FL_BLACK alignment: FL_ALIGN_LEFT @@ -1594,7 +1594,7 @@ size: FL_NORMAL_SIZE lcol: FL_BLACK label: LaTeX:|#L shortcut: -resize: FL_RESIZE_ALL +resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_latex callback: C_FormBaseInputCB @@ -1603,7 +1603,7 @@ argument: 0 -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -1712,7 +1712,7 @@ argument: -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -1854,5 +1854,191 @@ name: callback: argument: +=============== FORM =============== +Name: form_document_branch +Width: 395 +Height: 325 +Number of Objects: 10 + +-------------------- +class: FL_BOX +type: UP_BOX +box: 0 0 395 325 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + +-------------------- +class: FL_INPUT +type: NORMAL_INPUT +box: 15 30 150 30 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_TOP_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: New Branch:|#N +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: input_all_branches +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 175 30 100 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Add|#d +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_add_branch +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 15 230 100 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Remove|#e +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_remove_branch +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BROWSER +type: HOLD_BROWSER +box: 15 90 150 125 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_TOP_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Available Branches: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: browser_all_branches +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BROWSER +type: HOLD_BROWSER +box: 220 90 155 125 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_TOP_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Activated Branches: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: browser_selection +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 175 95 35 35 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: @5-> +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_select +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 175 135 35 35 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: @9+ +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_deselect +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 165 275 55 30 +boxtype: FL_FLAT_BOX +colors: FL_WHITE FL_COL1 +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Display Background: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_color +callback: +argument: + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 230 275 85 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Modify +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: button_modify +callback: C_FormBaseInputCB +argument: 0 + ============================== create_the_forms diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 9e516334c2..685fbfd2a0 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,21 @@ + +2003-08-17 Martin Vermeer + + * Makefile.am: + * inset.h: + * insetbranch.[Ch]: implements the 'branch inset' + idea. This allows the output of various versions of a document + from a single source version, selectively outputing or suppressing + output of parts of the text. + This implementation contains a 'branch list editor' in a separate + tab of the document settings dialog. Branches are user definable + and have a "display colour" to distinguish them on-screen. + + ColorHandler was somewhat cleaned up. + (1) make possible a dynamically growing LColor list by allowing + the graphic context cache to grow along (vector); + (2) eliminate an IMHO unnecessary step in colour allocation. + 2003-08-15 André Pönitz * insettext.[Ch]: adjust after rowlist split diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index 0b6a5ef79c..9b29c5ed9f 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -25,6 +25,8 @@ libinsets_la_SOURCES = \ insetbibitem.h \ insetbibtex.C \ insetbibtex.h \ + insetbranch.C \ + insetbranch.h \ insetcaption.C \ insetcaption.h \ insetcite.C \ diff --git a/src/insets/inset.h b/src/insets/inset.h index 780f5ea6d8..9f60c8ab0c 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -51,7 +51,7 @@ public: in a cleaner way. */ enum Code { /// - NO_CODE, + NO_CODE, // 0 /// TOC_CODE, // do these insets really need a code? (ale) /// @@ -59,9 +59,9 @@ public: /// MARK_CODE, /// - REF_CODE, // 5 + REF_CODE, /// - URL_CODE, + URL_CODE, // 5 /// HTMLURL_CODE, /// @@ -69,9 +69,9 @@ public: /// ENDING_CODE, /// - LABEL_CODE, // 10 + LABEL_CODE, /// - NOTE_CODE, + NOTE_CODE, // 10 /// ACCENT_CODE, /// @@ -79,9 +79,9 @@ public: /// INDEX_CODE, /// - INCLUDE_CODE, // 15 + INCLUDE_CODE, /// - GRAPHICS_CODE, + GRAPHICS_CODE, // 15 /// BIBITEM_CODE, /// @@ -89,9 +89,9 @@ public: /// TEXT_CODE, /// - ERT_CODE, // 20 + ERT_CODE, /// - FOOT_CODE, + FOOT_CODE, // 20 /// MARGIN_CODE, /// @@ -101,9 +101,9 @@ public: /// MINIPAGE_CODE, /// - SPACE_CODE, + SPACE_CODE, // 25 /// - SPECIALCHAR_CODE, // 25 + SPECIALCHAR_CODE, /// TABULAR_CODE, /// @@ -125,13 +125,15 @@ public: /// INDEX_PRINT_CODE, /// - OPTARG_CODE, + OPTARG_CODE, // 35 /// ENVIRONMENT_CODE, /// HFILL_CODE, /// - NEWLINE_CODE + NEWLINE_CODE, + /// + BRANCH_CODE }; /// diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C new file mode 100644 index 0000000000..b5115422dc --- /dev/null +++ b/src/insets/insetbranch.C @@ -0,0 +1,277 @@ +/** + * \file insetbranch.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS + */ + +#include + +#include "Lsstream.h" + +#include "insetbranch.h" +#include "gettext.h" +#include "lyxfont.h" +#include "language.h" +#include "buffer.h" +#include "BufferView.h" +#include "LaTeXFeatures.h" +#include "latexrunparams.h" +#include "lyxlex.h" +#include "lyxtext.h" +#include "insets/insettext.h" +#include "support/LOstream.h" +#include "support/lstrings.h" +#include "debug.h" + +using std::ostream; +using std::auto_ptr; + +void InsetBranch::init() +{ + setInsetName("Branch"); + setButtonLabel(); +} + + +InsetBranch::InsetBranch(BufferParams const & bp, string const & label) + : InsetCollapsable(bp) +{ + 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; + init(); +} + + +InsetBranch::InsetBranch(InsetBranch const & in) + : InsetCollapsable(in), params_(in.params_) +{ + init(); +} + + +InsetBranch::~InsetBranch() +{ + InsetBranchMailer mailer("branch", *this); + mailer.hideDialog(); +} + + +auto_ptr InsetBranch::clone() const +{ + return auto_ptr(new InsetBranch(*this)); +} + + +string const InsetBranch::editMessage() const +{ + return _("Opened Branch Inset"); +} + + +void InsetBranch::write(Buffer const * buf, ostream & os) const +{ + params_.write(os); + InsetCollapsable::write(buf, os); +} + + +void InsetBranch::read(Buffer const * buf, LyXLex & lex) +{ + if (lex.isOK()) { + lex.next(); + params_.branch = lex.getString(); + } + InsetCollapsable::read(buf, lex); + setButtonLabel(); +} + + +void InsetBranch::setButtonLabel() +{ + LyXFont font(LyXFont::ALL_SANE); + font.decSize(); + font.decSize(); + + setLabel(params_.branch); + font.setColor(LColor::foreground); + string const color = params_.branchlist.getColor(params_.branch); + if (!color.empty()) { + setBackgroundColor(lcolor.getFromLyXName(params_.branch)); + } else + setBackgroundColor(LColor::background); + setLabelFont(font); +} + + +void InsetBranch::metrics(MetricsInfo & mi, Dimension & dim) const +{ + InsetCollapsable::metrics(mi, dim); + dim_ = dim; +} + + +void InsetBranch::draw(PainterInfo & pi, int x, int y) const +{ + InsetCollapsable::draw(pi, x, y); +} + + +bool InsetBranch::showInsetDialog(BufferView * bv) const +{ + InsetBranchMailer("branch", const_cast(*this)).showDialog(bv); + return true; +} + + +dispatch_result InsetBranch::localDispatch(FuncRequest const & cmd) +{ + BufferView * bv = cmd.view(); + switch (cmd.action) { + case LFUN_INSET_MODIFY: + { + InsetBranchParams params; + InsetBranchMailer::string2params(cmd.argument, params); + params_.branch = params.branch; + setButtonLabel(); + bv->updateInset(); + return DISPATCHED; + } + case LFUN_INSET_EDIT: + if (cmd.button() != mouse_button::button3) + return InsetCollapsable::localDispatch(cmd); + return UNDISPATCHED; + case LFUN_INSET_DIALOG_UPDATE: + InsetBranchMailer("branch", *this).updateDialog(bv); + return DISPATCHED; + case LFUN_MOUSE_RELEASE: + if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { + InsetBranchMailer("branch", *this).showDialog(bv); + return DISPATCHED; + } + // fallthrough: + default: + return InsetCollapsable::localDispatch(cmd); + } +} + + + +int InsetBranch::latex(Buffer const * buf, ostream & os, + LatexRunParams const & runparams) const +{ + 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; +} + + +int InsetBranch::linuxdoc(Buffer const *, std::ostream &) const +{ + return 0; +} + + +int InsetBranch::docbook(Buffer const * buf, std::ostream & os, bool mixcont) const +{ + // untested - MV + 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; +} + + +int InsetBranch::ascii(Buffer const * buf, std::ostream & os, int ll) const +{ + string const branch_sel = buf->params.branchlist.allSelected(); + if (branch_sel.find(params_.branch, 0) != string::npos) { + return inset.ascii(buf, os, ll); + } + return 0; +} + + +void InsetBranch::validate(LaTeXFeatures & features) const +{ + inset.validate(features); +} + + + +InsetBranchMailer::InsetBranchMailer(string const & name, + InsetBranch & inset) + : name_(name), inset_(inset) +{ +} + + +string const InsetBranchMailer::inset2string(Buffer const & buf) const +{ + InsetBranchParams params = inset_.params(); + params.branchlist = buf.params.branchlist; + inset_.setParams(params); + return params2string(name_, params); +} + + +string const InsetBranchMailer::params2string(string const & name, + InsetBranchParams const & params) +{ + ostringstream data; + data << name << ' '; + params.write(data); + // Add all_branches parameter to data: + data << params.branchlist.allBranches() << "\n"; + return STRCONV(data.str()); +} + + +void InsetBranchMailer::string2params(string const & in, + InsetBranchParams & params) +{ + params = InsetBranchParams(); + + if (in.empty()) + return; + + istringstream data(STRCONV(in)); + LyXLex lex(0,0); + lex.setStream(data); + params.read(lex); + // Process all_branches here: + if (lex.isOK()) { + lex.next(); + params.branchlist.add(lex.getString()); + } +} + + +void InsetBranchParams::write(ostream & os) const +{ + os << "Branch" << " " << branch << "\n"; +} + + +void InsetBranchParams::read(LyXLex & lex) +{ + if (lex.isOK()) { + lex.next(); + string token = lex.getString(); + } + if (lex.isOK()) { + lex.next(); + string token = lex.getString(); + } + if (lex.isOK()) { + lex.next(); + branch = lex.getString(); + } +} + diff --git a/src/insets/insetbranch.h b/src/insets/insetbranch.h new file mode 100644 index 0000000000..d4e043bf95 --- /dev/null +++ b/src/insets/insetbranch.h @@ -0,0 +1,115 @@ +// -*- C++ -*- +/** + * \file insetbranch.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Martin Vermeer + * + * Full author contact details are available in file CREDITS + */ + +#ifndef INSETBRANCH_H +#define INSETBRANCH_H + + +#include "insetcollapsable.h" +#include "BranchList.h" + + struct InsetBranchParams { + /// + void write(std::ostream & os) const; + /// + void read(LyXLex & lex); + /// + string branch; + /// Hack -- MV + BranchList branchlist; + }; + + +/** The Branch inset for alternative, conditional output. + +*/ +class InsetBranch : public InsetCollapsable { +public: + /// + + + InsetBranch(BufferParams const &, string const &); + /// Copy constructor + InsetBranch(InsetBranch const &); + /// + ~InsetBranch(); + /// + virtual std::auto_ptr clone() const; + /// + string const editMessage() const; + /// + InsetOld::Code lyxCode() const { return InsetOld::BRANCH_CODE; } + /// + void write(Buffer const *, std::ostream &) const; + /// + void read(Buffer const * buf, LyXLex & lex); + /// + void setButtonLabel(); + /// + void metrics(MetricsInfo & mi, Dimension & dim) const; + /// + void draw(PainterInfo & pi, int x, int y) const; + /// + bool showInsetDialog(BufferView *) const; + /// + dispatch_result localDispatch(FuncRequest const &); + /// + int latex(Buffer const *, std::ostream &, + LatexRunParams const &) const; + /// + int linuxdoc(Buffer const *, std::ostream &) const; + /// + int docbook(Buffer const *, std::ostream &, bool) const; + /// + int ascii(Buffer const *, std::ostream &, int) const; + /// + void validate(LaTeXFeatures &) const; + /// + InsetBranchParams const & params() const { return params_; } + /// + void setParams(InsetBranchParams const & params) { params_ = params; } + +private: + friend class InsetBranchParams; + + /// used by the constructors + void init(); + /// + InsetBranchParams params_; +}; + +#include "mailinset.h" + +class InsetBranchMailer : public MailInset { +public: + /// + InsetBranchMailer(string const & name, InsetBranch & inset); + /// + virtual InsetBase & inset() const { return inset_; } + /// + virtual string const & name() const { return name_; } + /// + virtual string const inset2string(Buffer const &) const; + /// + static string const params2string(string const &, InsetBranchParams const &); + /// + static void string2params(string const &, InsetBranchParams &); + +private: + /// + string const name_; + /// + InsetBranch & inset_; +}; + + + +#endif diff --git a/src/lfuns.h b/src/lfuns.h index f9a979e64a..8e443f6c9f 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -321,7 +321,8 @@ enum kb_action { LFUN_PARAGRAPH_UPDATE, LFUN_EXTERNAL_EDIT, // 245 - + LFUN_INSERT_BRANCH, + LFUN_LASTACTION // end of the table }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 8c6840a288..185600625a 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -505,6 +505,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case InsetOld::NOTE_CODE: disable = ev.argument != "note"; break; + case InsetOld::BRANCH_CODE: + disable = ev.argument != "branch"; + break; default: break; } @@ -633,6 +636,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_INSERT_NOTE: code = InsetOld::NOTE_CODE; break; + case LFUN_INSERT_BRANCH: + code = InsetOld::BRANCH_CODE; + if (buf->params.branchlist.empty()) + disable = true; + break; case LFUN_INSERT_LABEL: code = InsetOld::LABEL_CODE; break; diff --git a/src/text3.C b/src/text3.C index ca471a16f7..f0786b7379 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1494,6 +1494,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd) case LFUN_INSET_CAPTION: #endif case LFUN_INSERT_NOTE: + case LFUN_INSERT_BRANCH: case LFUN_INSERT_BIBITEM: case LFUN_INSET_ERT: case LFUN_INSET_FLOAT: -- 2.39.2