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 "LyXTextClassList.h"
28 #include "tex-strings.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;
43 char const * const ControlDocument::fontfamilies[5] = {
44 "default", "rmdefault", "sfdefault", "ttdefault", ""
48 char const * ControlDocument::fontfamilies_gui[5] = {
49 N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
53 ControlDocument::ControlDocument(Dialog & parent)
54 : Dialog::Controller(parent)
58 ControlDocument::~ControlDocument()
62 bool ControlDocument::initialiseParams(std::string const &)
64 bp_.reset(new BufferParams);
65 *bp_ = kernel().buffer().params();
70 void ControlDocument::clearParams()
76 BufferParams & ControlDocument::params() const
78 BOOST_ASSERT(bp_.get());
83 LyXTextClass const & ControlDocument::textClass() const
85 return textclasslist[bp_->textclass];
91 void dispatch_bufferparams(Kernel const & kernel, BufferParams const & bp,
95 ss << "\\begin_header\n";
97 ss << "\\end_header\n";
98 kernel.dispatch(FuncRequest(lfun, ss.str()));
104 void ControlDocument::dispatchParams()
106 // This must come first so that a language change is correctly noticed
109 // Set the document class.
110 textclass_type const old_class =
111 kernel().buffer().params().textclass;
112 textclass_type const new_class = bp_->textclass;
113 if (new_class != old_class) {
114 string const name = textclasslist[new_class].name();
115 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_APPLY, name));
118 int const old_secnumdepth = kernel().buffer().params().secnumdepth;
119 int const new_secnumdepth = bp_->secnumdepth;
121 // Apply the BufferParams.
122 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_PARAMS_APPLY);
124 // redo the numbering if necessary
125 if (new_secnumdepth != old_secnumdepth)
126 updateLabels(kernel().buffer());
128 // Generate the colours requested by each new branch.
129 BranchList & branchlist = params().branchlist();
130 if (!branchlist.empty()) {
131 BranchList::const_iterator it = branchlist.begin();
132 BranchList::const_iterator const end = branchlist.end();
133 for (; it != end; ++it) {
134 docstring const & current_branch = it->getBranch();
135 Branch const * branch = branchlist.find(current_branch);
136 string const x11hexname =
137 lyx::X11hexname(branch->getColor());
138 // display the new color
139 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
140 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
143 // Open insets of selected branches, close deselected ones
144 kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
147 // FIXME: If we used an LFUN, we would not need those two lines:
148 kernel().bufferview()->update();
149 kernel().lyxview().currentWorkArea()->redraw();
153 void ControlDocument::setLanguage() const
155 Language const * const newL = bp_->language;
156 if (kernel().buffer().params().language == newL)
159 string const lang_name = newL->lang();
160 kernel().dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
164 bool ControlDocument::loadTextclass(textclass_type tc) const
166 string const name = textclasslist[tc].name();
167 kernel().dispatch(FuncRequest(LFUN_TEXTCLASS_LOAD, name));
169 // Report back whether we were able to change the class.
170 bool const success = textclasslist[tc].loaded();
175 void ControlDocument::saveAsDefault() const
177 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
181 bool const ControlDocument::isFontAvailable(std::string const & font) const
183 if (font == "default" || font == "cmr"
184 || font == "cmss" || font == "cmtt")
185 // these are standard
187 else if (font == "lmodern" || font == "lmss" || font == "lmtt")
188 return LaTeXFeatures::isAvailable("lmodern");
189 else if (font == "times" || font == "palatino"
190 || font == "helvet" || font == "courier")
191 return LaTeXFeatures::isAvailable("psnfss");
192 else if (font == "cmbr" || font == "cmtl")
193 return LaTeXFeatures::isAvailable("cmbright");
194 else if (font == "utopia")
195 return LaTeXFeatures::isAvailable("utopia")
196 || LaTeXFeatures::isAvailable("fourier");
197 else if (font == "beraserif" || font == "berasans"
198 || font == "beramono")
199 return LaTeXFeatures::isAvailable("bera");
201 return LaTeXFeatures::isAvailable(font);
205 bool const ControlDocument::providesOSF(std::string const & font) const
208 return isFontAvailable("eco");
209 else if (font == "palatino")
210 return isFontAvailable("mathpazo");
216 bool const ControlDocument::providesSC(std::string const & font) const
218 if (font == "palatino")
219 return isFontAvailable("mathpazo");
220 else if (font == "utopia")
221 return isFontAvailable("fourier");
227 bool const ControlDocument::providesScale(std::string const & font) const
229 return (font == "helvet" || font == "luximono"
230 || font == "berasans" || font == "beramono");
234 } // namespace frontend