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"
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 "TextClassList.h"
29 // FIXME: those two headers are needed because of the
30 // WorkArea::redraw() call below.
31 #include "frontends/LyXView.h"
32 #include "frontends/WorkArea.h"
36 using std::ostringstream;
42 char const * const ControlDocument::fontfamilies[5] = {
43 "default", "rmdefault", "sfdefault", "ttdefault", ""
47 char const * ControlDocument::fontfamilies_gui[5] = {
48 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
52 ControlDocument::ControlDocument(Dialog & parent)
53 : Dialog::Controller(parent)
57 ControlDocument::~ControlDocument()
61 bool ControlDocument::initialiseParams(std::string const &)
63 bp_.reset(new BufferParams);
64 *bp_ = kernel().buffer().params();
69 void ControlDocument::clearParams()
75 BufferParams & ControlDocument::params() const
77 BOOST_ASSERT(bp_.get());
82 TextClass const & ControlDocument::textClass() const
84 return textclasslist[bp_->textclass];
90 void dispatch_bufferparams(Kernel const & kernel, BufferParams const & bp,
94 ss << "\\begin_header\n";
96 ss << "\\end_header\n";
97 kernel.dispatch(FuncRequest(lfun, ss.str()));
103 void ControlDocument::dispatchParams()
105 // This must come first so that a language change is correctly noticed
108 // Set the document class.
109 textclass_type const old_class =
110 kernel().buffer().params().textclass;
111 textclass_type const new_class = bp_->textclass;
112 if (new_class != old_class) {
113 string const name = textclasslist[new_class].name();
114 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
117 int const old_secnumdepth = kernel().buffer().params().secnumdepth;
118 int const new_secnumdepth = bp_->secnumdepth;
120 // Apply the BufferParams.
121 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_PARAMS_APPLY);
123 // redo the numbering if necessary
124 if (new_secnumdepth != old_secnumdepth)
125 updateLabels(kernel().buffer());
127 // Generate the colours requested by each new branch.
128 BranchList & branchlist = params().branchlist();
129 if (!branchlist.empty()) {
130 BranchList::const_iterator it = branchlist.begin();
131 BranchList::const_iterator const end = branchlist.end();
132 for (; it != end; ++it) {
133 docstring const & current_branch = it->getBranch();
134 Branch const * branch = branchlist.find(current_branch);
135 string const x11hexname =
136 lyx::X11hexname(branch->getColor());
137 // display the new color
138 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
139 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
142 // Open insets of selected branches, close deselected ones
143 kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
146 // FIXME: If we used an LFUN, we would not need those two lines:
147 kernel().bufferview()->update();
148 kernel().lyxview().currentWorkArea()->redraw();
152 void ControlDocument::setLanguage() const
154 Language const * const newL = bp_->language;
155 if (kernel().buffer().params().language == newL)
158 string const lang_name = newL->lang();
159 kernel().dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
163 bool ControlDocument::loadTextclass(textclass_type tc) const
165 string const name = textclasslist[tc].name();
166 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
168 // Report back whether we were able to change the class.
169 bool const success = textclasslist[tc].loaded();
174 void ControlDocument::saveAsDefault() const
176 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
180 bool const ControlDocument::isFontAvailable(std::string const & font) const
182 if (font == "default" || font == "cmr"
183 || font == "cmss" || font == "cmtt")
184 // these are standard
186 else if (font == "lmodern" || font == "lmss" || font == "lmtt")
187 return LaTeXFeatures::isAvailable("lmodern");
188 else if (font == "times" || font == "palatino"
189 || font == "helvet" || font == "courier")
190 return LaTeXFeatures::isAvailable("psnfss");
191 else if (font == "cmbr" || font == "cmtl")
192 return LaTeXFeatures::isAvailable("cmbright");
193 else if (font == "utopia")
194 return LaTeXFeatures::isAvailable("utopia")
195 || LaTeXFeatures::isAvailable("fourier");
196 else if (font == "beraserif" || font == "berasans"
197 || font == "beramono")
198 return LaTeXFeatures::isAvailable("bera");
200 return LaTeXFeatures::isAvailable(font);
204 bool const ControlDocument::providesOSF(std::string const & font) const
207 return isFontAvailable("eco");
208 else if (font == "palatino")
209 return isFontAvailable("mathpazo");
215 bool const ControlDocument::providesSC(std::string const & font) const
217 if (font == "palatino")
218 return isFontAvailable("mathpazo");
219 else if (font == "utopia")
220 return isFontAvailable("fourier");
226 bool const ControlDocument::providesScale(std::string const & font) const
228 return (font == "helvet" || font == "luximono"
229 || font == "berasans" || font == "beramono");
233 } // namespace frontend