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 string 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
134 string const str = current_branch + ' ' + x11hexname;
135 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
138 // Open insets of selected branches, close deselected ones
139 kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
142 // update the bufferview
143 kernel().bufferview()->update();
147 void ControlDocument::setLanguage() const
149 Language const * const newL = bp_->language;
150 if (kernel().buffer().params().language == newL)
153 string const lang_name = newL->lang();
154 kernel().dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
158 bool ControlDocument::loadTextclass(textclass_type tc) const
160 string const name = textclasslist[tc].name();
161 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
163 // Report back whether we were able to change the class.
164 bool const success = textclasslist[tc].loaded();
169 void ControlDocument::saveAsDefault() const
171 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
175 bool const ControlDocument::isFontAvailable(std::string const & font) const
177 OutputParams runparams;
178 LaTeXFeatures features(kernel().buffer(), kernel().buffer().params(), runparams);
179 if (font == "default" || font == "cmr"
180 || font == "cmss" || font == "cmtt")
181 // these are standard
183 else if (font == "lmodern" || font == "lmss" || font == "lmtt")
184 return features.isAvailable("lmodern");
185 else if (font == "times" || font == "palatino"
186 || font == "helvet" || font == "courier")
187 return (features.isAvailable("psnfss"));
188 else if (font == "cmbr" || font == "cmtl")
189 return features.isAvailable("cmbright");
190 else if (font == "utopia")
191 return (features.isAvailable("utopia")
192 || features.isAvailable("fourier"));
193 else if (font == "beraserif" || font == "berasans"
194 || font == "beramono")
195 return features.isAvailable("bera");
197 return features.isAvailable(font);
201 bool const ControlDocument::providesOSF(std::string const & font) const
204 return isFontAvailable("eco");
205 else if (font == "palatino")
206 return isFontAvailable("mathpazo");
212 bool const ControlDocument::providesSC(std::string const & font) const
214 if (font == "palatino")
215 return isFontAvailable("mathpazo");
216 else if (font == "utopia")
217 return isFontAvailable("fourier");
223 bool const ControlDocument::providesScale(std::string const & font) const
225 return (font == "helvet" || font == "luximono"
226 || font == "berasans" || font == "beramono");
230 } // namespace frontend