]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrefs.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / controllers / ControlPrefs.C
1 /**
2  * \file ControlPrefs.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "ControlPrefs.h"
14
15 #include "helper_funcs.h"
16 #include "Kernel.h"
17
18 #include "bufferlist.h"
19 #include "gettext.h"
20 #include "funcrequest.h"
21 #include "paper.h"
22 #include "LColor.h"
23
24 #include "frontends/Application.h"
25
26 #include "support/filefilterlist.h"
27
28 #include <sstream>
29
30 using std::ostringstream;
31 using std::pair;
32 using std::string;
33 using std::vector;
34
35
36 namespace lyx {
37
38 using support::FileFilterList;
39
40 namespace frontend {
41
42
43 ControlPrefs::ControlPrefs(Dialog & parent)
44         : Dialog::Controller(parent),
45           update_screen_font_(false)
46 {}
47
48
49 bool ControlPrefs::initialiseParams(std::string const &)
50 {
51         rc_ = lyxrc;
52         formats_ = ::formats;
53         converters_ = ::converters;
54         converters_.update(formats_);
55         movers_ = ::movers;
56         colors_.clear();
57         update_screen_font_ = false;
58
59         return true;
60 }
61
62
63 void ControlPrefs::dispatchParams()
64 {
65         ostringstream ss;
66         rc_.write(ss, true);
67         kernel().dispatch(FuncRequest(LFUN_LYXRC_APPLY, ss.str()));
68
69         // FIXME: these need lfuns
70         theApp->bufferList().setCurrentAuthor(rc_.user_name, rc_.user_email);
71
72         ::formats = formats_;
73
74         ::converters = converters_;
75         ::converters.update(::formats);
76         ::converters.buildGraph();
77
78         ::movers = movers_;
79
80         vector<string>::const_iterator it = colors_.begin();
81         vector<string>::const_iterator const end = colors_.end();
82         for (; it != end; ++it)
83                 kernel().dispatch(FuncRequest(LFUN_SET_COLOR, *it));
84         colors_.clear();
85
86         if (update_screen_font_) {
87                 kernel().dispatch(FuncRequest(LFUN_SCREEN_FONT_UPDATE));
88                 update_screen_font_ = false;
89         }
90
91         // The Save button has been pressed
92         if (dialog().isClosing()) {
93                 kernel().dispatch(FuncRequest(LFUN_PREFERENCES_SAVE));
94         }
95 }
96
97
98 void ControlPrefs::setColor(LColor_color col, string const & hex)
99 {
100         colors_.push_back(lcolor.getLyXName(col) + ' ' + hex);
101 }
102
103
104 void ControlPrefs::updateScreenFonts()
105 {
106         update_screen_font_ = true;
107 }
108
109
110 string const ControlPrefs::browsebind(string const & file) const
111 {
112         // FIXME UNICODE
113         return browseLibFile("bind", file, "bind",
114                              lyx::to_utf8(_("Choose bind file")),
115                              FileFilterList(lyx::to_utf8(_("LyX bind files (*.bind)"))));
116 }
117
118
119 string const ControlPrefs::browseUI(string const & file) const
120 {
121         // FIXME UNICODE
122         return browseLibFile("ui", file, "ui",
123                              lyx::to_utf8(_("Choose UI file")),
124                              FileFilterList(lyx::to_utf8(_("LyX UI files (*.ui)"))));
125 }
126
127
128 string const ControlPrefs::browsekbmap(string const & file) const
129 {
130         // FIXME UNICODE
131         return browseLibFile("kbd", file, "kmap",
132                              lyx::to_utf8(_("Choose keyboard map")),
133                              FileFilterList(lyx::to_utf8(_("LyX keyboard maps (*.kmap)"))));
134 }
135
136
137 string const ControlPrefs::browsedict(string const & file) const
138 {
139         // FIXME UNICODE
140         return browseFile(file,
141                           lyx::to_utf8(_("Choose personal dictionary")),
142                           FileFilterList(lyx::to_utf8(_("*.ispell"))));
143 }
144
145
146 string const ControlPrefs::browse(string const & file,
147                                   string const & title) const
148 {
149         return browseFile(file, title, FileFilterList(), true);
150 }
151
152
153 string const ControlPrefs::browsedir(string const & path,
154                                      string const & title) const
155 {
156         return browseDir(path, title);
157 }
158
159
160 // We support less paper sizes than the document dialog
161 // Therefore this adjustment is needed.
162 PAPER_SIZE const ControlPrefs::toPaperSize(int i) const
163 {
164         switch (i) {
165         case 0:
166                 return PAPER_DEFAULT;
167         case 1:
168                 return PAPER_USLETTER;
169         case 2:
170                 return PAPER_USLEGAL;
171         case 3:
172                 return PAPER_USEXECUTIVE;
173         case 4:
174                 return PAPER_A3;
175         case 5:
176                 return PAPER_A4;
177         case 6:
178                 return PAPER_A5;
179         case 7:
180                 return PAPER_B5;
181         default:
182                 // should not happen
183                 return PAPER_DEFAULT;
184         }
185 }
186
187
188 int const ControlPrefs::fromPaperSize(PAPER_SIZE papersize) const
189 {
190         switch (papersize) {
191         case PAPER_DEFAULT:
192                 return 0;
193         case PAPER_USLETTER:
194                 return 1;
195         case PAPER_USLEGAL:
196                 return 2;
197         case PAPER_USEXECUTIVE:
198                 return 3;
199         case PAPER_A3:
200                 return 4;
201         case PAPER_A4:
202                 return 5;
203         case PAPER_A5:
204                 return 6;
205         case PAPER_B5:
206                 return 7;
207         default:
208                 // should not happen
209                 return 0;
210         }
211 }
212
213 } // namespace frontend
214 } // namespace lyx