From: Angus Leeming Date: Wed, 28 Mar 2001 12:59:29 +0000 (+0000) Subject: Controller-view split of Graphics and Index popups. X-Git-Tag: 1.6.10~21385 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=cda84cbcdfa4e4b0881c7dda6d91862b4356ac0e;p=features.git Controller-view split of Graphics and Index popups. Moved Citation and Character helper functions into their own namespaces. Fixed bugs in Minipage controller. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1843 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 25d23f559c..317cd585ee 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,9 +1,46 @@ +2001-03-28 Angus Leeming + + * ControlInset.h (clearDaughterParams): is empty by default, not pure. + (setDaughterParams): a (by default empty) new method called in show(). + + * ControlBibitem.h: + * ControlBibtex.h: + * ControlError.h: + * ControlInclude.h: + * ControlMinipage.h: + * ControlRef.h: + * ControlSearch.h: + * ControlUrl.h (clearDaughterParams): removed + + * ControlMinipage.C (applyParamsToInset): update the view. + Added namespace minipage containing a helper function getUnits. + + * GUI.h: changed Minipage policy to NoRepeatedApplyReadOnlyPolicy. + + * ControlCharacter.[Ch]: moved out all the helper functions and the + enum into their own file. + * character.[Ch]: new files; contain the character helper functions, + now inside namespace character. + + * ControlCitation.[Ch]: moved out all the helper functions and the + enums into their own file. Simplified interface. + * biblio.[Ch]: new files; contain the citation helper functions, + now inside namespace biblio. Will be of use also to an improved + BibTeX popup. + + * ControlGraphics.[Ch]: + * ControlIndex.[Ch]: new files; controllers for the Graphics and Index + popups, respectively. + + * GUI.h: + * Makefile.am: associated changes. + 2001-03-27 Angus Leeming * ControlMinipage.[Ch]: * ControlPreamble.[Ch]: * ControlPrint.[Ch]: - * ControlSplash.[Ch]: new files; controller for the Minipage, Preamble + * ControlSplash.[Ch]: new files; controllers for the Minipage, Preamble and Print popups and Splash screen, respectively. * ViewBase.h (ViewSplash): new base class for GUI-specific Splash diff --git a/src/frontends/controllers/ControlBibitem.h b/src/frontends/controllers/ControlBibitem.h index ab4cffdffe..2d64b7da2e 100644 --- a/src/frontends/controllers/ControlBibitem.h +++ b/src/frontends/controllers/ControlBibitem.h @@ -23,8 +23,7 @@ /** A controller for Bibitem dialogs. */ -class ControlBibitem : public ControlCommand -{ +class ControlBibitem : public ControlCommand { public: /// ControlBibitem(LyXView &, Dialogs &); @@ -34,8 +33,6 @@ private: virtual void applyParamsToInset(); /// not needed. virtual void applyParamsNoInset() {} - /// not needed. - virtual void clearDaughterParams() {} }; #endif // CONTROLBIBITEM_H diff --git a/src/frontends/controllers/ControlBibtex.h b/src/frontends/controllers/ControlBibtex.h index 392540aaf0..d64fad5c55 100644 --- a/src/frontends/controllers/ControlBibtex.h +++ b/src/frontends/controllers/ControlBibtex.h @@ -35,8 +35,6 @@ private: virtual void applyParamsToInset(); /// virtual void applyParamsNoInset(); - /// not needed. - virtual void clearDaughterParams() {} }; #endif // CONTROLBIBTEX_H diff --git a/src/frontends/controllers/ControlCharacter.C b/src/frontends/controllers/ControlCharacter.C index 445c589de5..ce320474e6 100644 --- a/src/frontends/controllers/ControlCharacter.C +++ b/src/frontends/controllers/ControlCharacter.C @@ -15,13 +15,11 @@ #include #include "ControlCharacter.h" -#include "bufferview_funcs.h" +#include "buffer.h" #include "Dialogs.h" #include "Liason.h" #include "LyXView.h" -#include "buffer.h" -#include "lyxtext.h" -#include "language.h" +#include "bufferview_funcs.h" // ToggleAndShow using Liason::setMinibuffer; using SigC::slot; @@ -86,33 +84,33 @@ void ControlCharacter::setSize(LyXFont::FONT_SIZE val) font_->setSize(val); } -void ControlCharacter::setBar(ControlCharacter::FONT_STATE val) +void ControlCharacter::setBar(character::FONT_STATE val) { switch (val) { - case IGNORE: + case character::IGNORE: font_->setEmph(LyXFont::IGNORE); font_->setUnderbar(LyXFont::IGNORE); font_->setNoun(LyXFont::IGNORE); font_->setLatex(LyXFont::IGNORE); break; - case EMPH_TOGGLE: + case character::EMPH_TOGGLE: font_->setEmph(LyXFont::TOGGLE); break; - case UNDERBAR_TOGGLE: + case character::UNDERBAR_TOGGLE: font_->setUnderbar(LyXFont::TOGGLE); break; - case NOUN_TOGGLE: + case character::NOUN_TOGGLE: font_->setNoun(LyXFont::TOGGLE); break; - case LATEX_TOGGLE: + case character::LATEX_TOGGLE: font_->setLatex(LyXFont::TOGGLE); break; - case INHERIT: + case character::INHERIT: font_->setEmph(LyXFont::INHERIT); font_->setUnderbar(LyXFont::INHERIT); font_->setNoun(LyXFont::INHERIT); @@ -160,172 +158,3 @@ void ControlCharacter::setToggleAll(bool t) { toggleall_ = t; } - - -vector const getFamilyData() -{ - vector family(5); - - ControlCharacter::FamilyPair pr; - pr.first = _("No change"); pr.second = LyXFont::IGNORE_FAMILY; - family[0] = pr; - pr.first = _("Roman"); pr.second = LyXFont::ROMAN_FAMILY; - family[1] = pr; - pr.first = _("Sans Serif"); pr.second = LyXFont::SANS_FAMILY; - family[2] = pr; - pr.first = _("Typewriter"); pr.second = LyXFont::TYPEWRITER_FAMILY; - family[3] = pr; - pr.first = _("Reset"); pr.second = LyXFont::INHERIT_FAMILY; - family[4] = pr; - - return family; -} - - -vector const getSeriesData() -{ - vector series(4); - - ControlCharacter::SeriesPair pr; - pr.first = _("No change"); pr.second = LyXFont::IGNORE_SERIES; - series[0] = pr; - pr.first = _("Medium"); pr.second = LyXFont::MEDIUM_SERIES; - series[1] = pr; - pr.first = _("Bold"); pr.second = LyXFont::BOLD_SERIES; - series[2] = pr; - pr.first = _("Reset"); pr.second = LyXFont::INHERIT_SERIES; - series[3] = pr; - - return series; -} - - -vector const getShapeData() -{ - vector shape(6); - - ControlCharacter::ShapePair pr; - pr.first = _("No change"); pr.second = LyXFont::IGNORE_SHAPE; - shape[0] = pr; - pr.first = _("Upright"); pr.second = LyXFont::UP_SHAPE; - shape[1] = pr; - pr.first = _("Italic"); pr.second = LyXFont::ITALIC_SHAPE; - shape[2] = pr; - pr.first = _("Slanted"); pr.second = LyXFont::SLANTED_SHAPE; - shape[3] = pr; - pr.first = _("Small Caps"); pr.second = LyXFont::SMALLCAPS_SHAPE; - shape[4] = pr; - pr.first = _("Reset"); pr.second = LyXFont::INHERIT_SHAPE; - shape[5] = pr; - - return shape; -} - - -vector const getSizeData() -{ - vector size(14); - - ControlCharacter::SizePair pr; - pr.first = _("No change"); pr.second = LyXFont::IGNORE_SIZE; - size[0] = pr; - pr.first = _("Tiny"); pr.second = LyXFont::SIZE_TINY; - size[1] = pr; - pr.first = _("Smallest"); pr.second = LyXFont::SIZE_SCRIPT; - size[2] = pr; - pr.first = _("Smaller"); pr.second = LyXFont::SIZE_FOOTNOTE; - size[3] = pr; - pr.first = _("Small"); pr.second = LyXFont::SIZE_SMALL; - size[4] = pr; - pr.first = _("Normal"); pr.second = LyXFont::SIZE_NORMAL; - size[5] = pr; - pr.first = _("Large"); pr.second = LyXFont::SIZE_LARGE; - size[6] = pr; - pr.first = _("Larger"); pr.second = LyXFont::SIZE_LARGER; - size[7] = pr; - pr.first = _("Largest"); pr.second = LyXFont::SIZE_LARGEST; - size[8] = pr; - pr.first = _("Huge"); pr.second = LyXFont::SIZE_HUGE; - size[9] = pr; - pr.first = _("Huger"); pr.second = LyXFont::SIZE_HUGER; - size[10] = pr; - pr.first = _("Increase"); pr.second = LyXFont::INCREASE_SIZE; - size[11] = pr; - pr.first = _("Decrease"); pr.second = LyXFont::DECREASE_SIZE; - size[12] = pr; - pr.first = _("Reset"); pr.second = LyXFont::INHERIT_SIZE; - size[13] = pr; - - return size; -} - - -vector const getBarData() -{ - vector bar(6); - - ControlCharacter::BarPair pr; - pr.first = _("No change"); pr.second = ControlCharacter::IGNORE; - bar[0] = pr; - pr.first = _("Emph"); pr.second = ControlCharacter::EMPH_TOGGLE; - bar[1] = pr; - pr.first = _("Underbar"); pr.second = ControlCharacter::UNDERBAR_TOGGLE; - bar[2] = pr; - pr.first = _("Noun"); pr.second = ControlCharacter::NOUN_TOGGLE; - bar[3] = pr; - pr.first = _("LaTeX mode"); pr.second = ControlCharacter::LATEX_TOGGLE; - bar[4] = pr; - pr.first = _("Reset"); pr.second = ControlCharacter::INHERIT; - bar[5] = pr; - - return bar; -} - - -vector const getColorData() -{ - vector color(11); - - ControlCharacter::ColorPair pr; - pr.first = _("No change"); pr.second = LColor::ignore; - color[0] = pr; - pr.first = _("No color"); pr.second = LColor::none; - color[1] = pr; - pr.first = _("Black"); pr.second = LColor::black; - color[2] = pr; - pr.first = _("White"); pr.second = LColor::white; - color[3] = pr; - pr.first = _("Red"); pr.second = LColor::red; - color[4] = pr; - pr.first = _("Green"); pr.second = LColor::green; - color[5] = pr; - pr.first = _("Blue"); pr.second = LColor::blue; - color[6] = pr; - pr.first = _("Cyan"); pr.second = LColor::cyan; - color[7] = pr; - pr.first = _("Magenta"); pr.second = LColor::magenta; - color[8] = pr; - pr.first = _("Yellow"); pr.second = LColor::yellow; - color[9] = pr; - pr.first = _("Reset"); pr.second = LColor::inherit; - color[10] = pr; - - return color; -} - - -vector const getLanguageData() -{ - vector langs(languages.size() + 2); - - langs[0] = _("No change"); - langs[1] = _("Reset"); - - vector::size_type i = 1; - for (Languages::const_iterator cit = languages.begin(); - cit != languages.end(); ++cit) { - langs[++i] = cit->second.lang(); - } - - return langs; -} diff --git a/src/frontends/controllers/ControlCharacter.h b/src/frontends/controllers/ControlCharacter.h index b593c83c52..6266b10f38 100644 --- a/src/frontends/controllers/ControlCharacter.h +++ b/src/frontends/controllers/ControlCharacter.h @@ -14,43 +14,13 @@ #endif #include "ControlDialogs.h" -#include "lyxfont.h" -#include "LColor.h" +#include "character.h" /** A controller for Character dialogs. */ class ControlCharacter : public ControlDialog { public: - /// - enum FONT_STATE { - /// - IGNORE, - /// - EMPH_TOGGLE, - /// - UNDERBAR_TOGGLE, - /// - NOUN_TOGGLE, - /// - LATEX_TOGGLE, - /// - INHERIT - }; - - /// - typedef std::pair FamilyPair; - /// - typedef std::pair SeriesPair; - /// - typedef std::pair ShapePair; - /// - typedef std::pair SizePair; - /// - typedef std::pair BarPair; - /// - typedef std::pair ColorPair; - /// ControlCharacter(LyXView &, Dialogs &); @@ -63,7 +33,7 @@ public: /// void setSize(LyXFont::FONT_SIZE); /// - void setBar(FONT_STATE); + void setBar(character::FONT_STATE); /// void setColor(LColor::color); /// @@ -85,19 +55,4 @@ private: bool toggleall_; }; -/// Helper functions -std::vector const getFamilyData(); -/// -std::vector const getSeriesData(); -/// -std::vector const getShapeData(); -/// -std::vector const getSizeData(); -/// -std::vector const getBarData(); -/// -std::vector const getColorData(); -/// -std::vector const getLanguageData(); - #endif // CONTROLCHARACTER_H diff --git a/src/frontends/controllers/ControlCitation.C b/src/frontends/controllers/ControlCitation.C index b4c711a927..aa929d9410 100644 --- a/src/frontends/controllers/ControlCitation.C +++ b/src/frontends/controllers/ControlCitation.C @@ -1,4 +1,3 @@ -// -*- C++ -*- /* This file is part of * ====================================================== * @@ -24,15 +23,9 @@ #include "buffer.h" #include "Dialogs.h" #include "LyXView.h" -#include "helper_funcs.h" -#include "support/lstrings.h" -#include "support/LRegex.h" -using std::find; -using std::min; using std::pair; using std::vector; -using std::sort; using SigC::slot; ControlCitation::ControlCitation(LyXView & lv, Dialogs & d) @@ -51,291 +44,21 @@ void ControlCitation::clearDaughterParams() } -// A functor for use with std::sort, leading to case insensitive sorting -struct compareNoCase: public std::binary_function +void ControlCitation::setDaughterParams() { - bool operator()(string const & s1, string const & s2) const { - return compare_no_case(s1, s2) < 0; - } -}; - - -vector const ControlCitation::getBibkeys() -{ - vector bibkeys; - bibkeysInfo_.clear(); - vector > blist = lv_.buffer()->getBibkeyList(); + typedef std::map::value_type InfoMapValue; + for (vector >::size_type i=0; isecond, "author"); - if (author.empty()) - author = parseBibTeX(it->second, "editor"); - - string year = parseBibTeX(it->second, "year"); - string title = parseBibTeX(it->second, "title"); - string booktitle = parseBibTeX(it->second, "booktitle"); - string chapter = parseBibTeX(it->second, "chapter"); - string pages = parseBibTeX(it->second, "pages"); - - string media = parseBibTeX(it->second, "journal"); - if (media.empty()) - media = parseBibTeX(it->second, "publisher"); - if (media.empty()) - media = parseBibTeX(it->second, "school"); - if (media.empty()) - media = parseBibTeX(it->second, "institution"); - - result = author; - if (!year.empty()) - result += ", " + year; - if (!title.empty()) - result += ", " + title; - if (!booktitle.empty()) - result += ", in " + booktitle; - if (!chapter.empty()) - result += ", Ch. " + chapter; - if (!media.empty()) - result += ", " + media; - if (!pages.empty()) - result += ", pp. " + pages; - - if (result.empty()) // not a BibTeX record - result = it->second; - } - - return result; -} - - -vector::const_iterator -searchKeys(ControlCitation const & controller, - vector const & keys, - string const & expr, - vector::const_iterator start, - ControlCitation::Search type, - ControlCitation::Direction dir, - bool caseSensitive) -{ - // Preliminary checks - if(start < keys.begin() || start >= keys.end()) - return keys.end(); - - string search_expr = frontStrip(strip(expr)); - if (search_expr.empty()) - return start; - - if (type == ControlCitation::SIMPLE) - return simpleSearch(controller, keys, search_expr, start, dir, - caseSensitive); - - return regexSearch(controller, keys, search_expr, start, dir); -} - - -vector::const_iterator -simpleSearch(ControlCitation const & controller, - vector const & keys, - string const & expr, - vector::const_iterator start, - ControlCitation::Direction dir, - bool caseSensitive) -{ - vector searchwords = getVectorFromString(expr, " "); - - // Loop over all keys from start... - for (vector::const_iterator it = start; - // End condition is direction-dependent. - (dir == ControlCitation::FORWARD) ? - (it=keys.begin()); - // increment is direction-dependent. - (dir == ControlCitation::FORWARD) ? - (++it) : (--it)) { - - string data = (*it); - ControlCitation::InfoMap::const_iterator info = - controller.bibkeysInfo().find(*it); - if (info != controller.bibkeysInfo().end()) - data += " " + info->second; - if (!caseSensitive) - data = lowercase(data); - - bool found = true; - - // Loop over all search words... - if (caseSensitive) { - for (vector::const_iterator sit= - searchwords.begin(); - sit::const_iterator sit= - searchwords.begin(); - sit::const_iterator -regexSearch(ControlCitation const & controller, - vector const & keys, - string const & expr, - vector::const_iterator start, - ControlCitation::Direction dir) -{ - LRegex reg(expr); - - for (vector::const_iterator it = start; - // End condition is direction-dependent. - (dir == ControlCitation::FORWARD) ? - (it=keys.begin()); - // increment is direction-dependent. - (dir == ControlCitation::FORWARD) ? - (++it) : (--it)) { - - string data = (*it); - ControlCitation::InfoMap::const_iterator info = - controller.bibkeysInfo().find(*it); - if (info != controller.bibkeysInfo().end()) - data += " " + info->second; - - if (reg.exec(data).size() > 0) - return it; - } - - return keys.end(); -} - -string const parseBibTeX(string data, string const & findkey) -{ - string keyvalue; - - for (string::iterator it=data.begin(); it1) { - string tmp = data.substr(keypos, - data.length()-1); - while (tmp.find('{') != string::npos && - tmp.find('}') != string::npos && - tmp.find('{') < tmp.find('}') && - tmp.find('{') < tmp.find(enclosing)) { - - keypos += tmp.find('{')+1; - tmp = data.substr(keypos, - data.length()-1); - keypos += tmp.find('}')+1; - tmp = data.substr(keypos, - data.length()-1); - } - - if (tmp.find(enclosing)==string::npos) - return keyvalue; - else { - keypos += tmp.find(enclosing); - tmp = data.substr(keypos, - data.length()-1); - } - - value = data.substr(1, keypos-1); - - if (keypos+1 data.find(',')) - keypos = data.find(','); - - value = data.substr(0, keypos); - - if (keypos+1 InfoMap; - /// - typedef std::map::value_type InfoMapValue; - /// - enum Search { - /// - SIMPLE, - /// - REGEX - }; - /// - enum Direction { - /// - FORWARD, - /// - BACKWARD - }; /// ControlCitation(LyXView &, Dialogs &); - /// A vector of bibliography keys - std::vector const getBibkeys(); + /// Returns a reference to the map of stored keys - InfoMap const & bibkeysInfo() const { return bibkeysInfo_; } - /** Returns the BibTeX data associated with a given key. - Empty if no info exists. */ - string const getBibkeyInfo(string const &); + biblio::InfoMap const & bibkeysInfo() const; + private: - /// clean-up any daughter class-particular data on hide(). + /// create the InfoMap of keys and data + virtual void setDaughterParams(); + /// virtual void clearDaughterParams(); + /// The info associated with each key - InfoMap bibkeysInfo_; + biblio::InfoMap bibkeysInfo_; }; -/** Helper functions, of possible use to all frontends - */ - -/** Search a BibTeX info field for the given key and return the - associated field. */ -string const parseBibTeX(string data, string const & findkey); - -/** Returns an iterator to the first key that meets the search criterion, - or end() if unsuccessful. - - User supplies : - the controller with the map of bibkeys info, - the vector of keys to be searched, - the search criterion, - an iterator defining the starting point of the search, - an enum defining a Simple or Regex search, - an enum defining the search direction. -*/ - -std::vector::const_iterator -searchKeys(ControlCitation const & controller, - std::vector const & keys_to_search, - string const & search_expression, - std::vector::const_iterator start, - ControlCitation::Search, - ControlCitation::Direction, - bool caseSensitive=false); - -/// Do the dirty work for the search. Should use through the function above -std::vector::const_iterator -simpleSearch(ControlCitation const & controller, - std::vector const & keys_to_search, - string const & search_expression, - std::vector::const_iterator start, - ControlCitation::Direction, - bool caseSensitive=false); - -/// Should use through the function above -std::vector::const_iterator -regexSearch(ControlCitation const & controller, - std::vector const & keys_to_search, - string const & search_expression, - std::vector::const_iterator start, - ControlCitation::Direction); #endif // CONTROLCITATION_H - - - diff --git a/src/frontends/controllers/ControlError.h b/src/frontends/controllers/ControlError.h index e296b54a16..dae63426c1 100644 --- a/src/frontends/controllers/ControlError.h +++ b/src/frontends/controllers/ControlError.h @@ -36,8 +36,6 @@ private: virtual void applyParamsToInset() {} /// virtual void applyParamsNoInset() {} - /// - virtual void clearDaughterParams() {} /// get the parameters from the string passed to createInset. virtual string const getParams(string const &) { return string(); } /// get the parameters from the inset passed to showInset. diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C new file mode 100644 index 0000000000..41a60e9a81 --- /dev/null +++ b/src/frontends/controllers/ControlGraphics.C @@ -0,0 +1,66 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2001 The LyX Team. + * + * ====================================================== + * + * \file ControlGraphics.C + * \author Angus Leeming + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "ControlGraphics.h" +#include "buffer.h" +#include "Dialogs.h" +#include "lyxfunc.h" +#include "LyXView.h" + +#include "insets/insetgraphics.h" + +ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d) + : ControlInset(lv, d) +{ + d_.showGraphics.connect(SigC::slot(this, &ControlGraphics::showInset)); +} + + +LyXView * ControlGraphics::lv() const +{ + return &lv_; +} + + +InsetGraphicsParams const ControlGraphics::getParams(string const &) +{ + return InsetGraphicsParams(); +} + + +InsetGraphicsParams const +ControlGraphics::getParams(InsetGraphics const & inset) +{ + return inset.getParams(); +} + + +void ControlGraphics::applyParamsToInset() +{ + // Set the parameters in the inset, it also returns true if the new + // parameters are different from what was in the inset already. + bool changed = inset()->setParams(params()); + // Tell LyX we've got a change, and mark the document dirty, + // if it changed. + lv_.view()->updateInset(inset(), changed); +} + + +void ControlGraphics::applyParamsNoInset() +{} diff --git a/src/frontends/controllers/ControlGraphics.h b/src/frontends/controllers/ControlGraphics.h new file mode 100644 index 0000000000..fac2f28f1a --- /dev/null +++ b/src/frontends/controllers/ControlGraphics.h @@ -0,0 +1,49 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2001 The LyX Team. + * + * ====================================================== + * + * \file ControlGraphics.h + * \author Angus Leeming + */ + +#ifndef CONTROLGRAPHICS_H +#define CONTROLGRAPHICS_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "ControlInset.h" +#include "insets/insetgraphicsParams.h" // need operator!=() + +class InsetGraphics; +class LyXView; + +/** A controller for Graphics dialogs. + */ +class ControlGraphics + : public ControlInset { +public: + /// + ControlGraphics(LyXView &, Dialogs &); + + /// The file dialog popup requires a LyXView * ??? + LyXView * lv() const; + +private: + /// Dispatch the changed parameters to the kernel. + virtual void applyParamsToInset(); + /// + virtual void applyParamsNoInset(); + /// get the parameters from the string passed to createInset. + virtual InsetGraphicsParams const getParams(string const &); + /// get the parameters from the inset passed to showInset. + virtual InsetGraphicsParams const getParams(InsetGraphics const &); +}; + +#endif // CONTROLGRAPHICS_H diff --git a/src/frontends/controllers/ControlInclude.h b/src/frontends/controllers/ControlInclude.h index 06bb86eb42..137db0bb7a 100644 --- a/src/frontends/controllers/ControlInclude.h +++ b/src/frontends/controllers/ControlInclude.h @@ -35,8 +35,6 @@ private: virtual void applyParamsToInset(); /// Should be used but currently isn't virtual void applyParamsNoInset() {} - /// not needed. - virtual void clearDaughterParams() {} /// get the parameters from the string passed to createInset. virtual InsetInclude::Params const getParams(string const &) { return InsetInclude::Params(); } diff --git a/src/frontends/controllers/ControlIndex.C b/src/frontends/controllers/ControlIndex.C new file mode 100644 index 0000000000..176d0ca328 --- /dev/null +++ b/src/frontends/controllers/ControlIndex.C @@ -0,0 +1,32 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2001 The LyX Team. + * + * ====================================================== + * + * \file ControlIndex.C + * \author Angus Leeming + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "ControlIndex.h" +#include "buffer.h" +#include "Dialogs.h" +#include "LyXView.h" + +using SigC::slot; + +ControlIndex::ControlIndex(LyXView & lv, Dialogs & d) + : ControlCommand(lv, d, LFUN_INDEX_INSERT) +{ + d_.showIndex.connect(slot(this, &ControlIndex::showInset)); + d_.createIndex.connect(slot(this, &ControlIndex::createInset)); +} diff --git a/src/frontends/controllers/ControlIndex.h b/src/frontends/controllers/ControlIndex.h new file mode 100644 index 0000000000..54845364a8 --- /dev/null +++ b/src/frontends/controllers/ControlIndex.h @@ -0,0 +1,31 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2001 The LyX Team. + * + * ====================================================== + * + * \file ControlIndex.h + * \author Angus Leeming + */ + +#ifndef CONTROLINDEX_H +#define CONTROLINDEX_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "ControlCommand.h" + +/** A controller for Index dialogs. + */ +class ControlIndex : public ControlCommand { +public: + /// + ControlIndex(LyXView &, Dialogs &); +}; + +#endif // CONTROLINDEX_H diff --git a/src/frontends/controllers/ControlInset.h b/src/frontends/controllers/ControlInset.h index a8859839e2..d7798e4d48 100644 --- a/src/frontends/controllers/ControlInset.h +++ b/src/frontends/controllers/ControlInset.h @@ -36,25 +36,35 @@ protected: /// Slot launching dialog to (possibly) create a new inset. void createInset(string const &); /// Slot launching dialog to an existing inset. - void showInset(Inset * inset); + void showInset(Inset *); /// Allow the daughter methods to access the inset. Inset * inset() const; private: - /** These methods are all that the individual daughter classes + /** These 6 methods are all that the individual daughter classes should need to instantiate. */ /// if the inset exists then do this... virtual void applyParamsToInset() = 0; /// else this... virtual void applyParamsNoInset() = 0; + /// get the parameters from the string passed to createInset. virtual Params const getParams(string const &) = 0; /// get the parameters from the inset passed to showInset. virtual Params const getParams(Inset const &) = 0; + + /** Most derived classes won't need these two, so they default to empty. + */ + + /// set any daughter class-particular data on show(). + virtual void setDaughterParams() {} /// clean-up any daughter class-particular data on hide(). - virtual void clearDaughterParams() = 0; + virtual void clearDaughterParams() {} + + + /// Instantiation of ControlBase virtual methods. /// Get changed parameters and Dispatch them to the kernel. @@ -124,6 +134,8 @@ void ControlInset::show(Params const & params) if (params_) delete params_; params_ = new Params(params); + setDaughterParams(); + bc().readOnly(isReadonly()); view().show(); } diff --git a/src/frontends/controllers/ControlMinipage.C b/src/frontends/controllers/ControlMinipage.C index 14f1741b68..a7d0428542 100644 --- a/src/frontends/controllers/ControlMinipage.C +++ b/src/frontends/controllers/ControlMinipage.C @@ -22,12 +22,17 @@ #include "LyXView.h" #include "buffer.h" +using std::vector; using SigC::slot; ControlMinipage::ControlMinipage(LyXView & lv, Dialogs & d) : ControlInset(lv, d) { d_.showMinipage.connect(slot(this, &ControlMinipage::showInset)); + + // We could have an extra method updateInset that calls + // view().update() rather than view().show(), but I don't see why + // it is really needed. d_.updateMinipage.connect(slot(this, &ControlMinipage::showInset)); } @@ -37,6 +42,8 @@ void ControlMinipage::applyParamsToInset() inset()->width(params().width); inset()->widthp(params().widthp); inset()->pos(params().pos); + + lv_.view()->updateInset(inset(), true); } @@ -68,3 +75,22 @@ bool MinipageParams::operator!=(MinipageParams const & o) const { return !(*this == o); } + +namespace minipage { + +vector const getUnits() +{ + vector units; + units.push_back("mm"); + units.push_back("in"); + units.push_back("em"); + units.push_back("\%"); + units.push_back("\%c"); + units.push_back("\%l"); + units.push_back("\%p"); + + return units; +} + +} // namespace minipage + diff --git a/src/frontends/controllers/ControlMinipage.h b/src/frontends/controllers/ControlMinipage.h index bc7222734d..b5ef4fdca5 100644 --- a/src/frontends/controllers/ControlMinipage.h +++ b/src/frontends/controllers/ControlMinipage.h @@ -15,6 +15,8 @@ #ifndef CONTROLMINIPAGE_H #define CONTROLMINIPAGE_H +#include + #ifdef __GNUG__ #pragma interface #endif @@ -59,8 +61,6 @@ private: virtual void applyParamsToInset(); /// virtual void applyParamsNoInset(); - /// - virtual void clearDaughterParams() {} /// get the parameters from the string passed to createInset. virtual MinipageParams const getParams(string const &) { return MinipageParams(); } @@ -68,4 +68,11 @@ private: virtual MinipageParams const getParams(InsetMinipage const &); }; +/// Helper functions +namespace minipage { + + std::vector const getUnits(); + +} // namespace minipage + #endif diff --git a/src/frontends/controllers/ControlRef.h b/src/frontends/controllers/ControlRef.h index 0a125fbe8d..23e5cb1899 100644 --- a/src/frontends/controllers/ControlRef.h +++ b/src/frontends/controllers/ControlRef.h @@ -33,10 +33,6 @@ public: void gotoRef(string const &) const; /// void gotoBookmark() const; - -private: - /// not needed. - virtual void clearDaughterParams() {} }; #endif // CONTROLREF_H diff --git a/src/frontends/controllers/ControlSearch.h b/src/frontends/controllers/ControlSearch.h index 194f953553..3b625187a0 100644 --- a/src/frontends/controllers/ControlSearch.h +++ b/src/frontends/controllers/ControlSearch.h @@ -38,8 +38,6 @@ public: private: /// not needed. virtual void apply() {} - /// - virtual void clearDaughterParams() {} }; #endif // CONTROLSEARCH_H diff --git a/src/frontends/controllers/ControlUrl.h b/src/frontends/controllers/ControlUrl.h index 6041f021de..d730e7e9da 100644 --- a/src/frontends/controllers/ControlUrl.h +++ b/src/frontends/controllers/ControlUrl.h @@ -27,10 +27,6 @@ class ControlUrl : public ControlCommand public: /// ControlUrl(LyXView &, Dialogs &); - -private: - /// not needed. - virtual void clearDaughterParams() {} }; #endif // CONTROLURL_H diff --git a/src/frontends/controllers/GUI.h b/src/frontends/controllers/GUI.h index 3881ec7564..5cc09a24c6 100644 --- a/src/frontends/controllers/GUI.h +++ b/src/frontends/controllers/GUI.h @@ -140,6 +140,20 @@ public: }; +/** Specialization for Graphics dialog + */ +class ControlGraphics; + +template +class GUIGraphics : + public GUI { +public: + /// + GUIGraphics(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + + /** Specialization for Include dialog */ class ControlInclude; @@ -154,6 +168,20 @@ public: }; +/** Specialization for Index dialog + */ +class ControlIndex; + +template +class GUIIndex : + public GUI { +public: + /// + GUIIndex(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + + /** Specialization for Log dialog */ class ControlLog; @@ -174,11 +202,11 @@ class ControlMinipage; template class GUIMinipage : - public GUI { + public GUI { public: /// GUIMinipage(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} + : GUI(lv, d) {} }; diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 7a6784312d..31fcca7986 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -10,6 +10,10 @@ LIBS = SUBDIRS = ETAGS_ARGS = --lang=c++ libcontrollers_la_SOURCES=\ + biblio.C \ + biblio.h \ + character.C \ + character.h \ ButtonController.C \ ButtonController.h \ ButtonPolicies.C \ @@ -35,8 +39,12 @@ libcontrollers_la_SOURCES=\ ControlDialogs.h \ ControlError.h \ ControlError.C \ + ControlGraphics.h \ + ControlGraphics.C \ ControlInclude.C \ ControlInclude.h \ + ControlIndex.C \ + ControlIndex.h \ ControlInset.h \ ControlLog.C \ ControlLog.h \ diff --git a/src/frontends/controllers/biblio.C b/src/frontends/controllers/biblio.C new file mode 100644 index 0000000000..984bccf442 --- /dev/null +++ b/src/frontends/controllers/biblio.C @@ -0,0 +1,327 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2001 The LyX Team. + * + * ====================================================== + * + * \file biblio.C + * \author Angus Leeming + */ + +#include +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include + +/* +#include "buffer.h" +#include "Dialogs.h" +#include "LyXView.h" +*/ +#include "LString.h" +#include "biblio.h" +#include "helper_funcs.h" +#include "support/lstrings.h" +#include "support/LAssert.h" +#include "support/LRegex.h" + +using std::find; +using std::min; +using std::pair; +using std::vector; +using std::sort; + +namespace biblio +{ + + +// A functor for use with std::sort, leading to case insensitive sorting +struct compareNoCase: public std::binary_function +{ + bool operator()(string const & s1, string const & s2) const { + return compare_no_case(s1, s2) < 0; + } +}; + +vector const getKeys(InfoMap const & map) +{ + vector bibkeys; + + + typedef std::map::value_type InfoMapValue; + + for (InfoMap::const_iterator it = map.begin(); it != map.end(); ++it) { + bibkeys.push_back(it->first); + } + + sort(bibkeys.begin(), bibkeys.end(), compareNoCase()); + return bibkeys; +} + + +string const getInfo(InfoMap const & map, string const & key) +{ + Assert(!map.empty()); + + string result; + + InfoMap::const_iterator it = map.find(key); + if (it != map.end()) { + // Search for all possible "required" keys + string author = parseBibTeX(it->second, "author"); + if (author.empty()) + author = parseBibTeX(it->second, "editor"); + + string year = parseBibTeX(it->second, "year"); + string title = parseBibTeX(it->second, "title"); + string booktitle = parseBibTeX(it->second, "booktitle"); + string chapter = parseBibTeX(it->second, "chapter"); + string pages = parseBibTeX(it->second, "pages"); + + string media = parseBibTeX(it->second, "journal"); + if (media.empty()) + media = parseBibTeX(it->second, "publisher"); + if (media.empty()) + media = parseBibTeX(it->second, "school"); + if (media.empty()) + media = parseBibTeX(it->second, "institution"); + + result = author; + if (!year.empty()) + result += ", " + year; + if (!title.empty()) + result += ", " + title; + if (!booktitle.empty()) + result += ", in " + booktitle; + if (!chapter.empty()) + result += ", Ch. " + chapter; + if (!media.empty()) + result += ", " + media; + if (!pages.empty()) + result += ", pp. " + pages; + + if (result.empty()) // not a BibTeX record + result = it->second; + } + + return result; +} + + +vector::const_iterator +searchKeys(InfoMap const & theMap, + vector const & keys, + string const & expr, + vector::const_iterator start, + Search type, + Direction dir, + bool caseSensitive) +{ + // Preliminary checks + if(start < keys.begin() || start >= keys.end()) + return keys.end(); + + string search_expr = frontStrip(strip(expr)); + if (search_expr.empty()) + return start; + + if (type == SIMPLE) + return simpleSearch(theMap, keys, search_expr, start, dir, + caseSensitive); + + return regexSearch(theMap, keys, search_expr, start, dir); +} + + +vector::const_iterator +simpleSearch(InfoMap const & theMap, + vector const & keys, + string const & expr, + vector::const_iterator start, + Direction dir, + bool caseSensitive) +{ + vector searchwords = getVectorFromString(expr, " "); + + // Loop over all keys from start... + for (vector::const_iterator it = start; + // End condition is direction-dependent. + (dir == FORWARD) ? (it=keys.begin()); + // increment is direction-dependent. + (dir == FORWARD) ? (++it) : (--it)) { + + string data = (*it); + biblio::InfoMap::const_iterator info = theMap.find(*it); + if (info != theMap.end()) + data += " " + info->second; + if (!caseSensitive) + data = lowercase(data); + + bool found = true; + + // Loop over all search words... + if (caseSensitive) { + for (vector::const_iterator sit= + searchwords.begin(); + sit::const_iterator sit= + searchwords.begin(); + sit::const_iterator +regexSearch(InfoMap const & theMap, + vector const & keys, + string const & expr, + vector::const_iterator start, + Direction dir) +{ + LRegex reg(expr); + + for (vector::const_iterator it = start; + // End condition is direction-dependent. + (dir == FORWARD) ? (it=keys.begin()); + // increment is direction-dependent. + (dir == FORWARD) ? (++it) : (--it)) { + + string data = (*it); + biblio::InfoMap::const_iterator info = theMap.find(*it); + if (info != theMap.end()) + data += " " + info->second; + + if (reg.exec(data).size() > 0) + return it; + } + + return keys.end(); +} + +string const parseBibTeX(string data, string const & findkey) +{ + string keyvalue; + + for (string::iterator it=data.begin(); it1) { + string tmp = data.substr(keypos, + data.length()-1); + while (tmp.find('{') != string::npos && + tmp.find('}') != string::npos && + tmp.find('{') < tmp.find('}') && + tmp.find('{') < tmp.find(enclosing)) { + + keypos += tmp.find('{')+1; + tmp = data.substr(keypos, + data.length()-1); + keypos += tmp.find('}')+1; + tmp = data.substr(keypos, + data.length()-1); + } + + if (tmp.find(enclosing)==string::npos) + return keyvalue; + else { + keypos += tmp.find(enclosing); + tmp = data.substr(keypos, + data.length()-1); + } + + value = data.substr(1, keypos-1); + + if (keypos+1 data.find(',')) + keypos = data.find(','); + + value = data.substr(0, keypos); + + if (keypos+1 + */ + +#ifndef BIBLIOHELPERS_H +#define BIBLIOHELPERS_H + +#include + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Functions of use to citation and bibtex GUI controllers and views */ +namespace biblio +{ + /// + enum Search { + /// + SIMPLE, + /// + REGEX + }; + /// + enum Direction { + /// + FORWARD, + /// + BACKWARD + }; + + /// First entry is the bibliography key, second the data + typedef std::map InfoMap; + + /// Returns a vector of bibliography keys + std::vector const getKeys(InfoMap const &); + + /** Returns the BibTeX data associated with a given key. + Empty if no info exists. */ + string const getInfo(InfoMap const &, string const &); + + /** Search a BibTeX info field for the given key and return the + associated field. */ + string const parseBibTeX(string data, string const & findkey); + + /** Returns an iterator to the first key that meets the search + criterion, or end() if unsuccessful. + + User supplies : + the InfoMap of bibkeys info, + the vector of keys to be searched, + the search criterion, + an iterator defining the starting point of the search, + an enum defining a Simple or Regex search, + an enum defining the search direction. + */ + + std::vector::const_iterator + searchKeys(InfoMap const & map, + std::vector const & keys_to_search, + string const & search_expression, + std::vector::const_iterator start, + Search, + Direction, + bool caseSensitive=false); + + /** Do the dirty work for the search. + Should use through the function above */ + std::vector::const_iterator + simpleSearch(InfoMap const & map, + std::vector const & keys_to_search, + string const & search_expression, + std::vector::const_iterator start, + Direction, + bool caseSensitive=false); + + /// Should use through the function above + std::vector::const_iterator + regexSearch(InfoMap const & map, + std::vector const & keys_to_search, + string const & search_expression, + std::vector::const_iterator start, + Direction); + +} // namespace biblio + +#endif // BIBLIOHELPERS_H diff --git a/src/frontends/controllers/character.C b/src/frontends/controllers/character.C new file mode 100644 index 0000000000..750f210040 --- /dev/null +++ b/src/frontends/controllers/character.C @@ -0,0 +1,195 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2001 The LyX Team. + * + * ====================================================== + * + * \file character.h + * \author Angus Leeming + */ + +#include +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "character.h" + +using std::vector; + +namespace character { + +vector const getFamilyData() +{ + vector family(5); + + FamilyPair pr; + pr.first = _("No change"); pr.second = LyXFont::IGNORE_FAMILY; + family[0] = pr; + pr.first = _("Roman"); pr.second = LyXFont::ROMAN_FAMILY; + family[1] = pr; + pr.first = _("Sans Serif"); pr.second = LyXFont::SANS_FAMILY; + family[2] = pr; + pr.first = _("Typewriter"); pr.second = LyXFont::TYPEWRITER_FAMILY; + family[3] = pr; + pr.first = _("Reset"); pr.second = LyXFont::INHERIT_FAMILY; + family[4] = pr; + + return family; +} + + +vector const getSeriesData() +{ + vector series(4); + + SeriesPair pr; + pr.first = _("No change"); pr.second = LyXFont::IGNORE_SERIES; + series[0] = pr; + pr.first = _("Medium"); pr.second = LyXFont::MEDIUM_SERIES; + series[1] = pr; + pr.first = _("Bold"); pr.second = LyXFont::BOLD_SERIES; + series[2] = pr; + pr.first = _("Reset"); pr.second = LyXFont::INHERIT_SERIES; + series[3] = pr; + + return series; +} + + +vector const getShapeData() +{ + vector shape(6); + + ShapePair pr; + pr.first = _("No change"); pr.second = LyXFont::IGNORE_SHAPE; + shape[0] = pr; + pr.first = _("Upright"); pr.second = LyXFont::UP_SHAPE; + shape[1] = pr; + pr.first = _("Italic"); pr.second = LyXFont::ITALIC_SHAPE; + shape[2] = pr; + pr.first = _("Slanted"); pr.second = LyXFont::SLANTED_SHAPE; + shape[3] = pr; + pr.first = _("Small Caps"); pr.second = LyXFont::SMALLCAPS_SHAPE; + shape[4] = pr; + pr.first = _("Reset"); pr.second = LyXFont::INHERIT_SHAPE; + shape[5] = pr; + + return shape; +} + + +vector const getSizeData() +{ + vector size(14); + + SizePair pr; + pr.first = _("No change"); pr.second = LyXFont::IGNORE_SIZE; + size[0] = pr; + pr.first = _("Tiny"); pr.second = LyXFont::SIZE_TINY; + size[1] = pr; + pr.first = _("Smallest"); pr.second = LyXFont::SIZE_SCRIPT; + size[2] = pr; + pr.first = _("Smaller"); pr.second = LyXFont::SIZE_FOOTNOTE; + size[3] = pr; + pr.first = _("Small"); pr.second = LyXFont::SIZE_SMALL; + size[4] = pr; + pr.first = _("Normal"); pr.second = LyXFont::SIZE_NORMAL; + size[5] = pr; + pr.first = _("Large"); pr.second = LyXFont::SIZE_LARGE; + size[6] = pr; + pr.first = _("Larger"); pr.second = LyXFont::SIZE_LARGER; + size[7] = pr; + pr.first = _("Largest"); pr.second = LyXFont::SIZE_LARGEST; + size[8] = pr; + pr.first = _("Huge"); pr.second = LyXFont::SIZE_HUGE; + size[9] = pr; + pr.first = _("Huger"); pr.second = LyXFont::SIZE_HUGER; + size[10] = pr; + pr.first = _("Increase"); pr.second = LyXFont::INCREASE_SIZE; + size[11] = pr; + pr.first = _("Decrease"); pr.second = LyXFont::DECREASE_SIZE; + size[12] = pr; + pr.first = _("Reset"); pr.second = LyXFont::INHERIT_SIZE; + size[13] = pr; + + return size; +} + + +vector const getBarData() +{ + vector bar(6); + + BarPair pr; + pr.first = _("No change"); pr.second = IGNORE; + bar[0] = pr; + pr.first = _("Emph"); pr.second = EMPH_TOGGLE; + bar[1] = pr; + pr.first = _("Underbar"); pr.second = UNDERBAR_TOGGLE; + bar[2] = pr; + pr.first = _("Noun"); pr.second = NOUN_TOGGLE; + bar[3] = pr; + pr.first = _("LaTeX mode"); pr.second = LATEX_TOGGLE; + bar[4] = pr; + pr.first = _("Reset"); pr.second = INHERIT; + bar[5] = pr; + + return bar; +} + + +vector const getColorData() +{ + vector color(11); + + ColorPair pr; + pr.first = _("No change"); pr.second = LColor::ignore; + color[0] = pr; + pr.first = _("No color"); pr.second = LColor::none; + color[1] = pr; + pr.first = _("Black"); pr.second = LColor::black; + color[2] = pr; + pr.first = _("White"); pr.second = LColor::white; + color[3] = pr; + pr.first = _("Red"); pr.second = LColor::red; + color[4] = pr; + pr.first = _("Green"); pr.second = LColor::green; + color[5] = pr; + pr.first = _("Blue"); pr.second = LColor::blue; + color[6] = pr; + pr.first = _("Cyan"); pr.second = LColor::cyan; + color[7] = pr; + pr.first = _("Magenta"); pr.second = LColor::magenta; + color[8] = pr; + pr.first = _("Yellow"); pr.second = LColor::yellow; + color[9] = pr; + pr.first = _("Reset"); pr.second = LColor::inherit; + color[10] = pr; + + return color; +} + + +vector const getLanguageData() +{ + vector langs(languages.size() + 2); + + langs[0] = _("No change"); + langs[1] = _("Reset"); + + vector::size_type i = 1; + for (Languages::const_iterator cit = languages.begin(); + cit != languages.end(); ++cit) { + langs[++i] = cit->second.lang(); + } + + return langs; +} + +} // namespace character diff --git a/src/frontends/controllers/character.h b/src/frontends/controllers/character.h new file mode 100644 index 0000000000..04f2e7bfb9 --- /dev/null +++ b/src/frontends/controllers/character.h @@ -0,0 +1,73 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2001 The LyX Team. + * + * ====================================================== + * + * \file character.h + * \author Angus Leeming + */ + +#ifndef CHARACTERHELPERS_H +#define CHARACTERHELPERS_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "lyxfont.h" +#include "LColor.h" +#include "character.h" + +/** Functions of use to the character GUI controller and view */ +namespace character { + /// + enum FONT_STATE { + /// + IGNORE, + /// + EMPH_TOGGLE, + /// + UNDERBAR_TOGGLE, + /// + NOUN_TOGGLE, + /// + LATEX_TOGGLE, + /// + INHERIT + }; + + /// + typedef std::pair FamilyPair; + /// + typedef std::pair SeriesPair; + /// + typedef std::pair ShapePair; + /// + typedef std::pair SizePair; + /// + typedef std::pair BarPair; + /// + typedef std::pair ColorPair; + + /// + std::vector const getFamilyData(); + /// + std::vector const getSeriesData(); + /// + std::vector const getShapeData(); + /// + std::vector const getSizeData(); + /// + std::vector const getBarData(); + /// + std::vector const getColorData(); + /// + std::vector const getLanguageData(); + +} // namespace character + +#endif // CHARACTERHELPERS