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