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