]> git.lyx.org Git - lyx.git/blob - src/lyx_main.h
bdbef3b30251f2e70ad0cfb687165542d0abfb28
[lyx.git] / src / lyx_main.h
1 // -*- C++ -*-
2 /**
3  * \file lyx_main.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_MAIN_H
15 #define LYX_MAIN_H
16
17 #include "support/filename.h"
18
19 #include <boost/scoped_ptr.hpp>
20 #include <boost/utility.hpp>
21
22 #include <string>
23 #include <vector>
24
25 namespace lyx {
26
27 class Buffer;
28 class BufferList;
29 class ErrorItem;
30 class IconvProcessor;
31 class InsetBase;
32 class LyXFunc;
33 class LyXServer;
34 class LyXServerSocket;
35 class LyXView;
36 class Session;
37 class kb_keymap;
38
39 extern bool use_gui;
40
41 namespace frontend { class Application; }
42
43 /// initial startup
44 class LyX : boost::noncopyable {
45 public:
46
47         LyX();
48         ~LyX();
49
50         /**
51          * Execute LyX. The startup sequence is as follows:
52          * -# LyX::exec()
53          * -# LyX::priv_exec()
54          * -# lyx::createApplication()
55          * Step 3 is omitted if no gui is wanted. We need lyx::createApplication()
56          * only to create the QApplication object in the qt frontend. All
57          * attempts with static and dynamically allocated QApplication
58          * objects lead either to harmless error messages on exit
59          * ("Mutex destroy failure") or crashes (OS X).
60          */
61         int exec(int & argc, char * argv[]);
62
63         static LyX & ref();
64         static LyX const & cref();
65
66         /// in the case of failure
67         void emergencyCleanup() const;
68
69         /// Ask the LyX class to exit.
70         /**
71         In GUI mode, after this function has been called, application_ leaves
72         the main event loop and returns from the call to Application::start().
73         */
74         void quit();
75
76         ///
77         BufferList & bufferList();
78         BufferList const & bufferList() const;
79         ///
80         Session & session();
81         Session const & session() const;
82         ///
83         LyXFunc & lyxFunc();
84         LyXFunc const & lyxFunc() const;
85         ///
86         LyXServer & server();
87         LyXServer const & server() const;
88         ///
89         LyXServerSocket & socket();
90         LyXServerSocket const & socket() const;
91
92         ///
93         frontend::Application & application();
94         frontend::Application const & application() const;
95
96         ///
97         kb_keymap & topLevelKeymap();
98         kb_keymap const & topLevelKeymap() const;
99
100         ///
101         IconvProcessor & iconvProcessor();
102
103         LyXView * newLyXView();
104
105         /** redraw \c inset in all the BufferViews in which it is currently
106          *  visible. If successful return a pointer to the owning Buffer.
107          */
108         Buffer const * const updateInset(InsetBase const *) const;
109
110         /// Execute batch commands if available.
111         void execBatchCommands();
112
113 private:
114         /// Do some cleanup in preparation of an exit.
115         void prepareExit();
116
117         /// Early exit during the initialisation process.
118         void earlyExit(int status);
119
120         /// Initialise LyX and load files if asked.
121         /**
122         \param files is filled in with the command-line file names.
123         \return exit code failure if any.
124         */
125         int loadFiles(int & argc, char * argv[],
126                 std::vector<support::FileName> & files);
127
128         /// Create a View and restore GUI Session.
129         void restoreGuiSession(std::vector<support::FileName> const & files);
130
131         /// Initialize RC font for the GUI.
132         void initGuiFont();
133
134         /// initial LyX set up
135         bool init();
136         /// set up the default key bindings
137         void defaultKeyBindings(kb_keymap * kbmap);
138         /// set up the default dead key bindings if requested
139         void deadKeyBindings(kb_keymap * kbmap);
140         /** Check for the existence of the user's support directory and,
141          *  if not present, create it. Exits the program if the directory
142          *  cannot be created.
143          *  \returns true if the user-side configuration script
144          *  (lib/configure) should be re-run in this directory.
145          */
146         bool queryUserLyXDir(bool explicit_userdir);
147         /// read lyxrc/preferences
148         bool readRcFile(std::string const & name);
149         /// read the given ui (menu/toolbar) file
150         bool readUIFile(std::string const & name);
151         /// read the given languages file
152         bool readLanguagesFile(std::string const & name);
153         /// read the given encodings file
154         bool readEncodingsFile(std::string const & name);
155         /// parsing of non-gui LyX options.
156         void easyParse(int & argc, char * argv[]);
157         /// shows up a parsing error on screen
158         void printError(ErrorItem const &);
159
160         /// has this user started lyx for the first time?
161         bool first_start;
162         /// the parsed command line batch command if any
163         std::string batch_command;
164
165         /// Use the Pimpl idiom to hide the internals.
166         struct Singletons;
167         boost::scoped_ptr<Singletons> pimpl_;
168 };
169
170 } // namespace lyx
171
172 #endif // LYX_MAIN_H