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