]> git.lyx.org Git - lyx.git/blob - src/LyX.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / LyX.h
1 // -*- C++ -*-
2 /**
3  * \file LyX.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef LYX_H
15 #define LYX_H
16
17 #include "support/strfwd.h"
18
19 #include <vector>
20
21 namespace lyx {
22
23 class BufferList;
24 class CmdDef;
25 class Converters;
26 class DispatchResult;
27 class ErrorItem;
28 class Formats;
29 class FuncRequest;
30 class FuncStatus;
31 class KeyMap;
32 class LaTeXFonts;
33 class Messages;
34 class Mover;
35 class Movers;
36 class Server;
37 class ServerSocket;
38 class Session;
39 class SpellChecker;
40
41 enum RunMode {
42         NEW_INSTANCE,
43         USE_REMOTE,
44         PREFERRED
45 };
46
47 enum OverwriteFiles {
48         NO_FILES,
49         MAIN_FILE,
50         ALL_FILES,
51         UNSPECIFIED
52 };
53
54 extern bool use_gui;
55 extern bool verbose;
56 extern bool ignore_missing_glyphs;
57 extern RunMode run_mode;
58 extern OverwriteFiles force_overwrite;
59
60 namespace frontend {
61 class Application;
62 }
63
64 /// initial startup
65 class LyX {
66         friend class LyXConsoleApp;
67 public:
68         LyX();
69         ~LyX();
70
71         /// Execute LyX.
72         int exec(int & argc, char * argv[]);
73
74 private:
75         /// noncopyable
76         LyX(LyX const &);
77         void operator=(LyX const &);
78
79         /// Do some cleanup in preparation of an exit.
80         void prepareExit();
81
82         /// Early exit during the initialisation process.
83         void earlyExit(int status);
84
85         /// Initialise LyX and fills-in the vector of files to be loaded.
86         /**
87         \return exit code failure if any.
88         */
89         int init(int & argc, char * argv[]);
90
91         /// Execute commandline commands if no GUI was requested.
92         int execWithoutGui(int & argc, char * argv[]);
93
94         /// Execute batch commands if available.
95         void execCommands();
96
97         /// initial LyX set up
98         bool init();
99         /** Check for the existence of the user's support directory and,
100          *  if not present, create it. Exits the program if the directory
101          *  cannot be created.
102          *  \returns true if the user-side configuration script
103          *  (lib/configure) should be re-run in this directory.
104          */
105         bool queryUserLyXDir(bool explicit_userdir);
106         /// read lyxrc/preferences
107         /// \param check_format: whether to try to convert the format of
108         /// the file, if there is a mismatch.
109         bool readRcFile(std::string const & name, bool check_format = false);
110         /// read the given languages file
111         bool readLanguagesFile(std::string const & name);
112         /// read the encodings.
113         /// \param enc_name encodings definition file
114         /// \param symbols_name unicode->LaTeX mapping file
115         bool readEncodingsFile(std::string const & enc_name,
116                                std::string const & symbols_name);
117         /// parsing of non-gui LyX options.
118         void easyParse(int & argc, char * argv[]);
119         /// shows up a parsing error on screen
120         void printError(ErrorItem const &);
121
122         ///
123         Messages & messages(std::string const & language);
124
125         /// Use the Pimpl idiom to hide the internals.
126         // Mostly used for singletons.
127         struct Impl;
128         Impl * pimpl_;
129
130         /// has this user started lyx for the first time?
131         bool first_start;
132
133         friend FuncStatus getStatus(FuncRequest const & action);
134         friend DispatchResult const & dispatch(FuncRequest const & action);
135         friend void dispatch(FuncRequest const & action, DispatchResult & dr);
136         friend std::vector<std::string> & theFilesToLoad();
137         friend BufferList & theBufferList();
138         friend Server & theServer();
139         friend ServerSocket & theServerSocket();
140         friend Converters & theConverters();
141         friend Converters & theSystemConverters();
142         friend Formats & theFormats();
143         friend Formats & theSystemFormats();
144         friend Messages const & getMessages(std::string const & language);
145         friend Messages const & getGuiMessages();
146         friend KeyMap & theTopLevelKeymap();
147         friend Movers & theMovers();
148         friend Mover const & getMover(std::string const & fmt);
149         friend void setMover(std::string const & fmt, std::string const & command);
150         friend Movers & theSystemMovers();
151         friend frontend::Application * theApp();
152         friend Session & theSession();
153         friend LaTeXFonts & theLaTeXFonts();
154         friend CmdDef & theTopLevelCmdDef();
155         friend SpellChecker * theSpellChecker();
156         friend void setSpellChecker();
157         friend void emergencyCleanup();
158         friend void execBatchCommands();
159         friend void lyx_exit(int exit_code);
160 };
161
162
163 /// in the case of failure
164 void emergencyCleanup();
165 /// Try to exit LyX properly.
166 /// \p exit_code is 0 by default, if a non zero value is passed,
167 /// emergencyCleanup() will be called before exiting.
168 void lyx_exit(int exit_code);
169 /// Execute batch commands if available.
170 void execBatchCommands();
171
172 ///
173 FuncStatus getStatus(FuncRequest const & action);
174
175 ///
176 DispatchResult const & dispatch(FuncRequest const & action);
177
178 ///
179 void dispatch(FuncRequest const & action, DispatchResult & dr);
180
181 } // namespace lyx
182
183 #endif // LYX_H