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)
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_->getBaseClass()];
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 // Apply the BufferParams. Note that this will set the base class
115 // and then update the buffer's layout.
116 //FIXME Could this be done last? Then, I think, we'd get the automatic
117 //update mentioned in the next FIXME...
118 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_PARAMS_APPLY);
120 // Generate the colours requested by each new branch.
121 BranchList & branchlist = params().branchlist();
122 if (!branchlist.empty()) {
123 BranchList::const_iterator it = branchlist.begin();
124 BranchList::const_iterator const end = branchlist.end();
125 for (; it != end; ++it) {
126 docstring const & current_branch = it->getBranch();
127 Branch const * branch = branchlist.find(current_branch);
128 string const x11hexname =
129 lyx::X11hexname(branch->getColor());
130 // display the new color
131 docstring const str = current_branch + ' ' + from_ascii(x11hexname);
132 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
135 // Open insets of selected branches, close deselected ones
136 kernel().dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
139 // FIXME: If we used an LFUN, we would not need those two lines:
140 kernel().bufferview()->update();
141 kernel().lyxview().currentWorkArea()->redraw();
145 void ControlDocument::setLanguage() const
147 Language const * const newL = bp_->language;
148 if (kernel().buffer().params().language == newL)
151 string const lang_name = newL->lang();
152 kernel().dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
156 void ControlDocument::saveAsDefault() const
158 dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
162 bool const ControlDocument::isFontAvailable(std::string const & font) const
164 if (font == "default" || font == "cmr"
165 || font == "cmss" || font == "cmtt")
166 // these are standard
168 else if (font == "lmodern" || font == "lmss" || font == "lmtt")
169 return LaTeXFeatures::isAvailable("lmodern");
170 else if (font == "times" || font == "palatino"
171 || font == "helvet" || font == "courier")
172 return LaTeXFeatures::isAvailable("psnfss");
173 else if (font == "cmbr" || font == "cmtl")
174 return LaTeXFeatures::isAvailable("cmbright");
175 else if (font == "utopia")
176 return LaTeXFeatures::isAvailable("utopia")
177 || LaTeXFeatures::isAvailable("fourier");
178 else if (font == "beraserif" || font == "berasans"
179 || font == "beramono")
180 return LaTeXFeatures::isAvailable("bera");
182 return LaTeXFeatures::isAvailable(font);
186 bool const ControlDocument::providesOSF(std::string const & font) const
189 return isFontAvailable("eco");
190 else if (font == "palatino")
191 return isFontAvailable("mathpazo");
197 bool const ControlDocument::providesSC(std::string const & font) const
199 if (font == "palatino")
200 return isFontAvailable("mathpazo");
201 else if (font == "utopia")
202 return isFontAvailable("fourier");
208 bool const ControlDocument::providesScale(std::string const & font) const
210 return (font == "helvet" || font == "luximono"
211 || font == "berasans" || font == "beramono");
215 } // namespace frontend