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 BufferId ControlDocument::id() const
84 return &kernel().buffer();
88 TextClass const & ControlDocument::textClass() const
90 return textclasslist[bp_->textclass];
96 void dispatch_bufferparams(Kernel const & kernel, BufferParams const & bp,
100 ss << "\\begin_header\n";
102 ss << "\\end_header\n";
103 kernel.dispatch(FuncRequest(lfun, ss.str()));
109 void ControlDocument::dispatchParams()
111 // This must come first so that a language change is correctly noticed
114 // Set the document class.
115 textclass_type const old_class =
116 kernel().buffer().params().textclass;
117 textclass_type const new_class = bp_->textclass;
118 if (new_class != old_class) {
119 string const name = textclasslist[new_class].name();
120 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
123 int const old_secnumdepth = kernel().buffer().params().secnumdepth;
124 int const new_secnumdepth = bp_->secnumdepth;
126 // Apply the BufferParams.
127 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_PARAMS_APPLY);
129 // redo the numbering if necessary
130 if (new_secnumdepth != old_secnumdepth)
131 updateLabels(kernel().buffer());
133 // Generate the colours requested by each new branch.
134 BranchList & branchlist = params().branchlist();
135 if (!branchlist.empty()) {
136 BranchList::const_iterator it = branchlist.begin();
137 BranchList::const_iterator const end = branchlist.end();
138 for (; it != end; ++it) {
139 docstring const & current_branch = it->getBranch();
140 Branch const * branch = branchlist.find(current_branch);
141 string const x11hexname =
142 lyx::X11hexname(branch->getColor());
143 // display the new color
144 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
145 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
148 // Open insets of selected branches, close deselected ones
149 kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
152 // FIXME: If we used an LFUN, we would not need those two lines:
153 kernel().bufferview()->update();
154 kernel().lyxview().currentWorkArea()->redraw();
158 void ControlDocument::setLanguage() const
160 Language const * const newL = bp_->language;
161 if (kernel().buffer().params().language == newL)
164 string const lang_name = newL->lang();
165 kernel().dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
169 bool ControlDocument::loadTextclass(textclass_type tc) const
171 string const name = textclasslist[tc].name();
172 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
174 // Report back whether we were able to change the class.
175 bool const success = textclasslist[tc].loaded();
180 void ControlDocument::saveAsDefault() const
182 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
186 bool const ControlDocument::isFontAvailable(std::string const & font) const
188 if (font == "default" || font == "cmr"
189 || font == "cmss" || font == "cmtt")
190 // these are standard
192 else if (font == "lmodern" || font == "lmss" || font == "lmtt")
193 return LaTeXFeatures::isAvailable("lmodern");
194 else if (font == "times" || font == "palatino"
195 || font == "helvet" || font == "courier")
196 return LaTeXFeatures::isAvailable("psnfss");
197 else if (font == "cmbr" || font == "cmtl")
198 return LaTeXFeatures::isAvailable("cmbright");
199 else if (font == "utopia")
200 return LaTeXFeatures::isAvailable("utopia")
201 || LaTeXFeatures::isAvailable("fourier");
202 else if (font == "beraserif" || font == "berasans"
203 || font == "beramono")
204 return LaTeXFeatures::isAvailable("bera");
206 return LaTeXFeatures::isAvailable(font);
210 bool const ControlDocument::providesOSF(std::string const & font) const
213 return isFontAvailable("eco");
214 else if (font == "palatino")
215 return isFontAvailable("mathpazo");
221 bool const ControlDocument::providesSC(std::string const & font) const
223 if (font == "palatino")
224 return isFontAvailable("mathpazo");
225 else if (font == "utopia")
226 return isFontAvailable("fourier");
232 bool const ControlDocument::providesScale(std::string const & font) const
234 return (font == "helvet" || font == "luximono"
235 || font == "berasans" || font == "beramono");
239 } // namespace frontend