]> git.lyx.org Git - features.git/blob - src/frontends/controllers/ControlDocument.cpp
Remove warnings reported with gcc 4.3:
[features.git] / src / frontends / controllers / ControlDocument.cpp
1 /**
2  * \file ControlDocument.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author Richard Heck (modules)
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "ControlDocument.h"
15
16 #include "BranchList.h"
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "BufferView.h"
20 #include "buffer_funcs.h"
21 #include "Color.h"
22 #include "FuncRequest.h"
23 #include "gettext.h"
24 #include "Language.h"
25 #include "LaTeXFeatures.h"
26 #include "ModuleList.h"
27 #include "OutputParams.h"
28 #include "TextClassList.h"
29
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"
34
35 #include <sstream>
36
37 using std::ostringstream;
38 using std::sort;
39 using std::string;
40 using std::vector;
41
42 namespace lyx {
43 namespace frontend {
44
45 char const * const ControlDocument::fontfamilies[5] = {
46         "default", "rmdefault", "sfdefault", "ttdefault", ""
47 };
48
49
50 char const * ControlDocument::fontfamilies_gui[5] = {
51         N_("Default"), N_("Roman"), N_("Sans Serif"), N_("Typewriter"), ""
52 };
53
54
55 ControlDocument::ControlDocument(Dialog & parent)
56         : Controller(parent)
57 {}
58
59
60 ControlDocument::~ControlDocument()
61 {}
62
63
64 bool ControlDocument::initialiseParams(string const &)
65 {
66         bp_.reset(new BufferParams);
67         *bp_ = buffer().params();
68         loadModuleNames();
69         return true;
70 }
71
72
73 void ControlDocument::clearParams()
74 {
75         bp_.reset();
76 }
77
78
79 BufferParams & ControlDocument::params() const
80 {
81         BOOST_ASSERT(bp_.get());
82         return *bp_;
83 }
84
85
86 BufferId ControlDocument::id() const
87 {
88         return &buffer();
89 }
90
91
92 vector<string> ControlDocument::getModuleNames()
93 {
94         return moduleNames_;
95 }
96
97
98 vector<string> const & ControlDocument::getSelectedModules()
99 {
100         return params().getModules();
101 }
102
103
104 string ControlDocument::getModuleDescription(string const & modName) const
105 {
106         LyXModule const * const mod = moduleList[modName];
107         if (!mod)
108                 return string("Module unavailable!");
109         return mod->description;
110 }
111
112
113 vector<string>
114 ControlDocument::getPackageList(string const & modName) const
115 {
116         LyXModule const * const mod = moduleList[modName];
117         if (!mod)
118                 return vector<string>(); //empty such thing
119         return mod->packageList;
120 }
121
122
123 TextClass const & ControlDocument::textClass() const
124 {
125         return textclasslist[bp_->getBaseClass()];
126 }
127
128
129 static void dispatch_bufferparams(Controller const & controller,
130         BufferParams const & bp, kb_action lfun)
131 {
132         ostringstream ss;
133         ss << "\\begin_header\n";
134         bp.writeFile(ss);
135         ss << "\\end_header\n";
136         controller.dispatch(FuncRequest(lfun, ss.str()));
137 }
138
139
140 void ControlDocument::dispatchParams()
141 {
142         // This must come first so that a language change is correctly noticed
143         setLanguage();
144
145         // Apply the BufferParams. Note that this will set the base class
146         // and then update the buffer's layout.
147         //FIXME Could this be done last? Then, I think, we'd get the automatic
148         //update mentioned in the next FIXME...
149         dispatch_bufferparams(*this, params(), LFUN_BUFFER_PARAMS_APPLY);
150
151         // Generate the colours requested by each new branch.
152         BranchList & branchlist = params().branchlist();
153         if (!branchlist.empty()) {
154                 BranchList::const_iterator it = branchlist.begin();
155                 BranchList::const_iterator const end = branchlist.end();
156                 for (; it != end; ++it) {
157                         docstring const & current_branch = it->getBranch();
158                         Branch const * branch = branchlist.find(current_branch);
159                         string const x11hexname =
160                                         lyx::X11hexname(branch->getColor());
161                         // display the new color
162                         docstring const str = current_branch + ' ' + from_ascii(x11hexname);
163                         dispatch(FuncRequest(LFUN_SET_COLOR, str));
164                 }
165
166                 // Open insets of selected branches, close deselected ones
167                 dispatch(FuncRequest(LFUN_ALL_INSETS_TOGGLE,
168                         "assign branch"));
169         }
170         // FIXME: If we used an LFUN, we would not need those two lines:
171         bufferview()->update();
172         lyxview().currentWorkArea()->redraw();
173 }
174
175
176 void ControlDocument::setLanguage() const
177 {
178         Language const * const newL = bp_->language;
179         if (buffer().params().language == newL)
180                 return;
181
182         string const & lang_name = newL->lang();
183         dispatch(FuncRequest(LFUN_BUFFER_LANGUAGE, lang_name));
184 }
185
186
187 void ControlDocument::saveAsDefault() const
188 {
189         dispatch_bufferparams(*this, params(), LFUN_BUFFER_SAVE_AS_DEFAULT);
190 }
191
192
193 bool ControlDocument::isFontAvailable(string const & font) const
194 {
195         if (font == "default" || font == "cmr"
196             || font == "cmss" || font == "cmtt")
197                 // these are standard
198                 return true;
199         else if (font == "lmodern" || font == "lmss" || font == "lmtt")
200                 return LaTeXFeatures::isAvailable("lmodern");
201         else if (font == "times" || font == "palatino"
202                  || font == "helvet" || font == "courier")
203                 return LaTeXFeatures::isAvailable("psnfss");
204         else if (font == "cmbr" || font == "cmtl")
205                 return LaTeXFeatures::isAvailable("cmbright");
206         else if (font == "utopia")
207                 return LaTeXFeatures::isAvailable("utopia")
208                         || LaTeXFeatures::isAvailable("fourier");
209         else if (font == "beraserif" || font == "berasans"
210                 || font == "beramono")
211                 return LaTeXFeatures::isAvailable("bera");
212         else
213                 return LaTeXFeatures::isAvailable(font);
214 }
215
216
217 bool ControlDocument::providesOSF(string const & font) const
218 {
219         if (font == "cmr")
220                 return isFontAvailable("eco");
221         else if (font == "palatino")
222                 return isFontAvailable("mathpazo");
223         else
224                 return false;
225 }
226
227
228 bool ControlDocument::providesSC(string const & font) const
229 {
230         if (font == "palatino")
231                 return isFontAvailable("mathpazo");
232         else if (font == "utopia")
233                 return isFontAvailable("fourier");
234         else
235                 return false;
236 }
237
238
239 bool ControlDocument::providesScale(string const & font) const
240 {
241         return (font == "helvet" || font == "luximono"
242                 || font == "berasans"  || font == "beramono");
243 }
244
245
246 void ControlDocument::loadModuleNames ()
247 {
248         moduleNames_.clear();
249         LyXModuleList::const_iterator it = moduleList.begin();
250         for (; it != moduleList.end(); ++it)
251                 moduleNames_.push_back(it->name);
252         if (!moduleNames_.empty())
253                 sort(moduleNames_.begin(), moduleNames_.end());
254 }
255
256
257 } // namespace frontend
258 } // namespace lyx