]> git.lyx.org Git - lyx.git/blob - src/LyX.h
even example code should follow the style conventions
[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 namespace lyx {
20
21 namespace support {
22 class FileName;
23 }
24
25 class Buffer;
26 class BufferList;
27 class Converters;
28 class ErrorItem;
29 class Inset;
30 class LyXFunc;
31 class Server;
32 class ServerSocket;
33 class Messages;
34 class Mover;
35 class Movers;
36 class Session;
37 class KeyMap;
38 class CmdDef;
39
40 extern bool use_gui;
41
42 namespace frontend {
43 class Application;
44 class LyXView;
45 }
46
47 /// initial startup
48 class LyX {
49 public:
50
51         LyX();
52         ~LyX();
53
54         /// Execute LyX.
55         int exec(int & argc, char * argv[]);
56
57         /// Try to exit LyX properly.
58         /// \p exit_code is 0 by default, if a non zero value is passed,
59         /// emergencyCleanup() will be called before exiting.
60         void exit(int exit_code = 0) const;
61
62         static LyX & ref();
63         static LyX const & cref();
64
65         /// in the case of failure
66         void emergencyCleanup() const;
67
68         ///
69         BufferList & bufferList();
70         BufferList const & bufferList() const;
71         ///
72         Session & session();
73         Session const & session() const;
74         ///
75         LyXFunc & lyxFunc();
76         LyXFunc const & lyxFunc() const;
77         ///
78         Server & server();
79         Server const & server() const;
80         ///
81         ServerSocket & socket();
82         ServerSocket const & socket() const;
83
84         ///
85         frontend::Application & application();
86         frontend::Application const & application() const;
87
88         ///
89         KeyMap & topLevelKeymap();
90         KeyMap const & topLevelKeymap() const;
91
92         ///
93         CmdDef & topLevelCmdDef();
94
95         ///
96         Converters & converters();
97         Converters & systemConverters();
98
99         ///
100         Messages & getMessages(std::string const & language);
101         ///
102         Messages & getGuiMessages();
103         ///
104         void setGuiLanguage(std::string const & language);
105
106         ///
107         frontend::LyXView * newLyXView();
108
109         /// Execute batch commands if available.
110         void execBatchCommands();
111
112         ///
113         void addFileToLoad(std::string const &);
114
115 private:
116         /// noncopyable
117         LyX(LyX const &);
118         void operator=(LyX const &);
119
120         /// Do some cleanup in preparation of an exit.
121         void prepareExit();
122
123         /// Early exit during the initialisation process.
124         void earlyExit(int status);
125
126         /// Initialise LyX and fills-in the vector of files to be loaded.
127         /**
128         \return exit code failure if any.
129         */
130         int init(int & argc, char * argv[]);
131
132         /// Load files passed at command-line.
133         /**
134         This method is used only in non-GUI mode.
135         */
136         void loadFiles();
137
138         /// initial LyX set up
139         bool init();
140         /// set up the default dead key bindings if requested
141         void deadKeyBindings(KeyMap * kbmap);
142         /** Check for the existence of the user's support directory and,
143          *  if not present, create it. Exits the program if the directory
144          *  cannot be created.
145          *  \returns true if the user-side configuration script
146          *  (lib/configure) should be re-run in this directory.
147          */
148         bool queryUserLyXDir(bool explicit_userdir);
149         /// read lyxrc/preferences
150         bool readRcFile(std::string const & name);
151         /// read the given ui (menu/toolbar) file
152         bool readUIFile(std::string const & name, bool include = false);
153         /// read the given languages file
154         bool readLanguagesFile(std::string const & name);
155         /// read the encodings.
156         /// \param enc_name encodings definition file
157         /// \param symbols_name unicode->LaTeX mapping file
158         bool readEncodingsFile(std::string const & enc_name,
159                                std::string const & symbols_name);
160         /// parsing of non-gui LyX options.
161         void easyParse(int & argc, char * argv[]);
162         /// shows up a parsing error on screen
163         void printError(ErrorItem const &);
164
165         /// Use the Pimpl idiom to hide the internals.
166         // Mostly used for singletons.
167         struct Impl;
168         Impl * pimpl_;
169
170         /// has this user started lyx for the first time?
171         bool first_start;
172
173         friend Movers & theMovers();
174         friend Mover const & getMover(std::string  const & fmt);
175         friend void setMover(std::string const & fmt, std::string const & command);
176         friend Movers & theSystemMovers();
177         friend frontend::Application * theApp();
178 };
179
180 } // namespace lyx
181
182 #endif // LYX_H