2 * \file ControlDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "ControlDocument.h"
15 #include "BranchList.h"
17 #include "BufferParams.h"
18 #include "BufferView.h"
19 #include "buffer_funcs.h"
20 #include "FuncRequest.h"
23 #include "LaTeXFeatures.h"
25 #include "OutputParams.h"
26 #include "TextClassList.h"
28 // FIXME: those two headers are needed because of the
29 // WorkArea::redraw() call below.
30 #include "frontends/LyXView.h"
31 #include "frontends/WorkArea.h"
35 using std::ostringstream;
41 char const * const ControlDocument::fontfamilies[5] = {
42 "default", "rmdefault", "sfdefault", "ttdefault", ""
46 char const * ControlDocument::fontfamilies_gui[5] = {
47 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
51 ControlDocument::ControlDocument(Dialog & parent)
56 ControlDocument::~ControlDocument()
60 bool ControlDocument::initialiseParams(std::string const &)
62 bp_.reset(new BufferParams);
63 *bp_ = buffer().params();
68 void ControlDocument::clearParams()
74 BufferParams & ControlDocument::params() const
76 BOOST_ASSERT(bp_.get());
81 BufferId ControlDocument::id() const
87 TextClass const & ControlDocument::textClass() const
89 return textclasslist[bp_->getBaseClass()];
93 static void dispatch_bufferparams(Controller const & controller,
94 BufferParams const & bp, kb_action lfun)
97 ss << "\\begin_header\n";
99 ss << "\\end_header\n";
100 controller.dispatch(FuncRequest(lfun, ss.str()));
104 void ControlDocument::dispatchParams()
106 // This must come first so that a language change is correctly noticed
109 // Apply the BufferParams. Note that this will set the base class
110 // and then update the buffer's layout.
111 //FIXME Could this be done last? Then, I think, we'd get the automatic
112 //update mentioned in the next FIXME...
113 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
115 // Generate the colours requested by each new branch.
116 BranchList & branchlist = params().branchlist();
117 if (!branchlist.empty()) {
118 BranchList::const_iterator it = branchlist.begin();
119 BranchList::const_iterator const end = branchlist.end();
120 for (; it != end; ++it) {
121 docstring const & current_branch = it->getBranch();
122 Branch const * branch = branchlist.find(current_branch);
123 string const x11hexname =
124 lyx::X11hexname(branch->getColor());
125 // display the new color
126 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
127 dispatch(FuncRequest(LFUN_SET_COLOR, str));
130 // Open insets of selected branches, close deselected ones
131 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
134 // FIXME: If we used an LFUN, we would not need those two lines:
135 bufferview()->update();
136 lyxview().currentWorkArea()->redraw();
140 void ControlDocument::setLanguage() const
142 Language const * const newL = bp_->language;
143 if (buffer().params().language == newL)
146 string const lang_name = newL->lang();
147 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
151 void ControlDocument::saveAsDefault() const
153 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
157 bool const ControlDocument::isFontAvailable(std::string const & font) const
159 if (font == "default" || font == "cmr"
160 || font == "cmss" || font == "cmtt")
161 // these are standard
163 else if (font == "lmodern" || font == "lmss" || font == "lmtt")
164 return LaTeXFeatures::isAvailable("lmodern");
165 else if (font == "times" || font == "palatino"
166 || font == "helvet" || font == "courier")
167 return LaTeXFeatures::isAvailable("psnfss");
168 else if (font == "cmbr" || font == "cmtl")
169 return LaTeXFeatures::isAvailable("cmbright");
170 else if (font == "utopia")
171 return LaTeXFeatures::isAvailable("utopia")
172 || LaTeXFeatures::isAvailable("fourier");
173 else if (font == "beraserif" || font == "berasans"
174 || font == "beramono")
175 return LaTeXFeatures::isAvailable("bera");
177 return LaTeXFeatures::isAvailable(font);
181 bool const ControlDocument::providesOSF(std::string const & font) const
184 return isFontAvailable("eco");
185 else if (font == "palatino")
186 return isFontAvailable("mathpazo");
192 bool const ControlDocument::providesSC(std::string const & font) const
194 if (font == "palatino")
195 return isFontAvailable("mathpazo");
196 else if (font == "utopia")
197 return isFontAvailable("fourier");
203 bool const ControlDocument::providesScale(std::string const & font) const
205 return (font == "helvet" || font == "luximono"
206 || font == "berasans" || font == "beramono");
210 } // namespace frontend