2 * \file ControlDocument.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Richard Heck (modules)
9 * Full author contact details are available in file CREDITS.
14 #include "ControlDocument.h"
16 #include "BranchList.h"
18 #include "BufferParams.h"
19 #include "BufferView.h"
20 #include "buffer_funcs.h"
22 #include "FuncRequest.h"
25 #include "LaTeXFeatures.h"
26 #include "ModuleList.h"
27 #include "OutputParams.h"
28 #include "TextClassList.h"
30 // FIXME: those two headers are needed because of the
31 // WorkArea::redraw() call below.
32 #include "frontends/LyXView.h"
33 #include "frontends/WorkArea.h"
37 using std::ostringstream;
45 char const * const ControlDocument::fontfamilies[5] = {
46 "default", "rmdefault", "sfdefault", "ttdefault", ""
50 char const * ControlDocument::fontfamilies_gui[5] = {
51 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
55 ControlDocument::ControlDocument(Dialog & parent)
60 ControlDocument::~ControlDocument()
64 bool ControlDocument::initialiseParams(string const &)
66 bp_.reset(new BufferParams);
67 *bp_ = buffer().params();
73 void ControlDocument::clearParams()
79 BufferParams & ControlDocument::params() const
81 BOOST_ASSERT(bp_.get());
86 BufferId ControlDocument::id() const
92 vector<string> ControlDocument::getModuleNames()
98 vector<string> const & ControlDocument::getSelectedModules()
100 return params().getModules();
104 string ControlDocument::getModuleDescription(string const & modName) const
106 LyXModule const * const mod = moduleList[modName];
108 return string("Module unavailable!");
109 return mod->description;
114 ControlDocument::getPackageList(string const & modName) const
116 LyXModule const * const mod = moduleList[modName];
118 return vector<string>(); //empty such thing
119 return mod->packageList;
123 TextClass const & ControlDocument::textClass() const
125 return textclasslist[bp_->getBaseClass()];
129 static void dispatch_bufferparams(Controller const & controller,
130 BufferParams const & bp, kb_action lfun)
133 ss << "\\begin_header\n";
135 ss << "\\end_header\n";
136 controller.dispatch(FuncRequest(lfun, ss.str()));
140 void ControlDocument::dispatchParams()
142 // This must come first so that a language change is correctly noticed
145 // Apply the BufferParams. Note that this will set the base class
146 // and then update the buffer's layout.
147 //FIXME Could this be done last? Then, I think, we'd get the automatic
148 //update mentioned in the next FIXME...
149 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
151 // Generate the colours requested by each new branch.
152 BranchList & branchlist = params().branchlist();
153 if (!branchlist.empty()) {
154 BranchList::const_iterator it = branchlist.begin();
155 BranchList::const_iterator const end = branchlist.end();
156 for (; it != end; ++it) {
157 docstring const & current_branch = it->getBranch();
158 Branch const * branch = branchlist.find(current_branch);
159 string const x11hexname =
160 lyx::X11hexname(branch->getColor());
161 // display the new color
162 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
163 dispatch(FuncRequest(LFUN_SET_COLOR, str));
166 // Open insets of selected branches, close deselected ones
167 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
170 // FIXME: If we used an LFUN, we would not need those two lines:
171 bufferview()->update();
172 lyxview().currentWorkArea()->redraw();
176 void ControlDocument::setLanguage() const
178 Language const * const newL = bp_->language;
179 if (buffer().params().language == newL)
182 string const & lang_name = newL->lang();
183 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
187 void ControlDocument::saveAsDefault() const
189 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
193 bool ControlDocument::isFontAvailable(string const & font) const
195 if (font == "default" || font == "cmr"
196 || font == "cmss" || font == "cmtt")
197 // these are standard
199 else if (font == "lmodern" || font == "lmss" || font == "lmtt")
200 return LaTeXFeatures::isAvailable("lmodern");
201 else if (font == "times" || font == "palatino"
202 || font == "helvet" || font == "courier")
203 return LaTeXFeatures::isAvailable("psnfss");
204 else if (font == "cmbr" || font == "cmtl")
205 return LaTeXFeatures::isAvailable("cmbright");
206 else if (font == "utopia")
207 return LaTeXFeatures::isAvailable("utopia")
208 || LaTeXFeatures::isAvailable("fourier");
209 else if (font == "beraserif" || font == "berasans"
210 || font == "beramono")
211 return LaTeXFeatures::isAvailable("bera");
213 return LaTeXFeatures::isAvailable(font);
217 bool ControlDocument::providesOSF(string const & font) const
220 return isFontAvailable("eco");
221 else if (font == "palatino")
222 return isFontAvailable("mathpazo");
228 bool ControlDocument::providesSC(string const & font) const
230 if (font == "palatino")
231 return isFontAvailable("mathpazo");
232 else if (font == "utopia")
233 return isFontAvailable("fourier");
239 bool ControlDocument::providesScale(string const & font) const
241 return (font == "helvet" || font == "luximono"
242 || font == "berasans" || font == "beramono");
246 void ControlDocument::loadModuleNames ()
248 moduleNames_.clear();
249 LyXModuleList::const_iterator it = moduleList.begin();
250 for (; it != moduleList.end(); ++it)
251 moduleNames_.push_back(it->name);
252 if (!moduleNames_.empty())
253 sort(moduleNames_.begin(), moduleNames_.end());
257 } // namespace frontend