2 * \file ControlDocument.C
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"
16 #include "BranchList.h"
18 #include "bufferparams.h"
19 #include "BufferView.h"
20 #include "buffer_funcs.h"
21 #include "funcrequest.h"
24 #include "LaTeXFeatures.h"
26 #include "outputparams.h"
27 #include "lyxtextclasslist.h"
28 #include "tex-strings.h"
32 using std::ostringstream;
38 char const * const ControlDocument::fontfamilies[5] = {
39 "default", "rmdefault", "sfdefault", "ttdefault", ""
43 char const * ControlDocument::fontfamilies_gui[5] = {
44 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
48 ControlDocument::ControlDocument(Dialog & parent)
49 : Dialog::Controller(parent)
53 ControlDocument::~ControlDocument()
57 bool ControlDocument::initialiseParams(std::string const &)
59 bp_.reset(new BufferParams);
60 *bp_ = kernel().buffer().params();
65 void ControlDocument::clearParams()
71 BufferParams & ControlDocument::params() const
73 BOOST_ASSERT(bp_.get());
78 LyXTextClass const & ControlDocument::textClass() const
80 return textclasslist[bp_->textclass];
86 void dispatch_bufferparams(Kernel const & kernel, BufferParams const & bp,
90 ss << "\\begin_header\n";
92 ss << "\\end_header\n";
93 kernel.dispatch(FuncRequest(lfun, ss.str()));
99 void ControlDocument::dispatchParams()
101 // This must come first so that a language change is correctly noticed
104 // Set the document class.
105 textclass_type const old_class =
106 kernel().buffer().params().textclass;
107 textclass_type const new_class = bp_->textclass;
108 if (new_class != old_class) {
109 string const name = textclasslist[new_class].name();
110 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
113 int const old_secnumdepth = kernel().buffer().params().secnumdepth;
114 int const new_secnumdepth = bp_->secnumdepth;
116 // Apply the BufferParams.
117 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_PARAMS_APPLY);
119 // redo the numbering if necessary
120 if (new_secnumdepth != old_secnumdepth)
121 updateLabels(kernel().buffer());
123 // Generate the colours requested by each new branch.
124 BranchList & branchlist = params().branchlist();
125 if (!branchlist.empty()) {
126 BranchList::const_iterator it = branchlist.begin();
127 BranchList::const_iterator const end = branchlist.end();
128 for (; it != end; ++it) {
129 docstring const & current_branch = it->getBranch();
130 Branch const * branch = branchlist.find(current_branch);
131 string const x11hexname =
132 lyx::X11hexname(branch->getColor());
133 // display the new color
135 string const str = to_utf8(current_branch) + ' ' + x11hexname;
136 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
139 // Open insets of selected branches, close deselected ones
140 kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
143 // update the bufferview
144 // If we used an LFUN, we would not need that
145 kernel().bufferview()->update();
149 void ControlDocument::setLanguage() const
151 Language const * const newL = bp_->language;
152 if (kernel().buffer().params().language == newL)
155 string const lang_name = newL->lang();
156 kernel().dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
160 bool ControlDocument::loadTextclass(textclass_type tc) const
162 string const name = textclasslist[tc].name();
163 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
165 // Report back whether we were able to change the class.
166 bool const success = textclasslist[tc].loaded();
171 void ControlDocument::saveAsDefault() const
173 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
177 bool const ControlDocument::isFontAvailable(std::string const & font) const
179 OutputParams runparams;
180 LaTeXFeatures features(kernel().buffer(), kernel().buffer().params(), runparams);
181 if (font == "default" || font == "cmr"
182 || font == "cmss" || font == "cmtt")
183 // these are standard
185 else if (font == "lmodern" || font == "lmss" || font == "lmtt")
186 return features.isAvailable("lmodern");
187 else if (font == "times" || font == "palatino"
188 || font == "helvet" || font == "courier")
189 return (features.isAvailable("psnfss"));
190 else if (font == "cmbr" || font == "cmtl")
191 return features.isAvailable("cmbright");
192 else if (font == "utopia")
193 return (features.isAvailable("utopia")
194 || features.isAvailable("fourier"));
195 else if (font == "beraserif" || font == "berasans"
196 || font == "beramono")
197 return features.isAvailable("bera");
199 return features.isAvailable(font);
203 bool const ControlDocument::providesOSF(std::string const & font) const
206 return isFontAvailable("eco");
207 else if (font == "palatino")
208 return isFontAvailable("mathpazo");
214 bool const ControlDocument::providesSC(std::string const & font) const
216 if (font == "palatino")
217 return isFontAvailable("mathpazo");
218 else if (font == "utopia")
219 return isFontAvailable("fourier");
225 bool const ControlDocument::providesScale(std::string const & font) const
227 return (font == "helvet" || font == "luximono"
228 || font == "berasans" || font == "beramono");
232 } // namespace frontend