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_ = buffer().params();
72 void ControlDocument::clearParams()
78 BufferId ControlDocument::id() const
84 vector<string> ControlDocument::getModuleNames()
90 vector<string> const & ControlDocument::getSelectedModules()
92 return params().getModules();
96 string ControlDocument::getModuleDescription(string const & modName) const
98 LyXModule const * const mod = moduleList[modName];
100 return string("Module unavailable!");
101 return mod->description;
106 ControlDocument::getPackageList(string const & modName) const
108 LyXModule const * const mod = moduleList[modName];
110 return vector<string>(); //empty such thing
111 return mod->packageList;
115 TextClass const & ControlDocument::textClass() const
117 return textclasslist[bp_.getBaseClass()];
121 static void dispatch_bufferparams(Controller const & controller,
122 BufferParams const & bp, kb_action lfun)
125 ss << "\\begin_header\n";
127 ss << "\\end_header\n";
128 controller.dispatch(FuncRequest(lfun, ss.str()));
132 void ControlDocument::dispatchParams()
134 // This must come first so that a language change is correctly noticed
137 // Apply the BufferParams. Note that this will set the base class
138 // and then update the buffer's layout.
139 //FIXME Could this be done last? Then, I think, we'd get the automatic
140 //update mentioned in the next FIXME...
141 dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
143 // Generate the colours requested by each new branch.
144 BranchList & branchlist = params().branchlist();
145 if (!branchlist.empty()) {
146 BranchList::const_iterator it = branchlist.begin();
147 BranchList::const_iterator const end = branchlist.end();
148 for (; it != end; ++it) {
149 docstring const & current_branch = it->getBranch();
150 Branch const * branch = branchlist.find(current_branch);
151 string const x11hexname =
152 lyx::X11hexname(branch->getColor());
153 // display the new color
154 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
155 dispatch(FuncRequest(LFUN_SET_COLOR, str));
158 // Open insets of selected branches, close deselected ones
159 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
162 // FIXME: If we used an LFUN, we would not need those two lines:
163 bufferview()->update();
164 lyxview().currentWorkArea()->redraw();
168 void ControlDocument::setLanguage() const
170 Language const * const newL = bp_.language;
171 if (buffer().params().language == newL)
174 string const & lang_name = newL->lang();
175 dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
179 void ControlDocument::saveAsDefault() const
181 dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
185 bool ControlDocument::isFontAvailable(string const & font) const
187 if (font == "default" || font == "cmr"
188 || font == "cmss" || font == "cmtt")
189 // these are standard
191 else if (font == "lmodern" || font == "lmss" || font == "lmtt")
192 return LaTeXFeatures::isAvailable("lmodern");
193 else if (font == "times" || font == "palatino"
194 || font == "helvet" || font == "courier")
195 return LaTeXFeatures::isAvailable("psnfss");
196 else if (font == "cmbr" || font == "cmtl")
197 return LaTeXFeatures::isAvailable("cmbright");
198 else if (font == "utopia")
199 return LaTeXFeatures::isAvailable("utopia")
200 || LaTeXFeatures::isAvailable("fourier");
201 else if (font == "beraserif" || font == "berasans"
202 || font == "beramono")
203 return LaTeXFeatures::isAvailable("bera");
205 return LaTeXFeatures::isAvailable(font);
209 bool ControlDocument::providesOSF(string const & font) const
212 return isFontAvailable("eco");
213 else if (font == "palatino")
214 return isFontAvailable("mathpazo");
220 bool ControlDocument::providesSC(string const & font) const
222 if (font == "palatino")
223 return isFontAvailable("mathpazo");
224 else if (font == "utopia")
225 return isFontAvailable("fourier");
231 bool ControlDocument::providesScale(string const & font) const
233 return (font == "helvet" || font == "luximono"
234 || font == "berasans" || font == "beramono");
238 void ControlDocument::loadModuleNames ()
240 moduleNames_.clear();
241 LyXModuleList::const_iterator it = moduleList.begin();
242 for (; it != moduleList.end(); ++it)
243 moduleNames_.push_back(it->name);
244 if (!moduleNames_.empty())
245 sort(moduleNames_.begin(), moduleNames_.end());
249 } // namespace frontend