]> git.lyx.org Git - lyx.git/blob - src/lyx_main.h
hopefully fix tex2lyx linking.
[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 IconvProcessor;
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         LyX();
46         ~LyX();
47
48         /**
49          * Execute LyX. The startup sequence is as follows:
50          * -# LyX::exec()
51          * -# LyX::priv_exec()
52          * -# lyx::createApplication()
53          * Step 3 is omitted if no gui is wanted. We need lyx::createApplication()
54          * only to create the QApplication object in the qt frontend. All
55          * attempts with static and dynamically allocated QApplication
56          * objects lead either to harmless error messages on exit
57          * ("Mutex destroy failure") or crashes (OS X).
58          */
59         int exec(int & argc, char * argv[]);
60
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();
73
74         ///
75         BufferList & bufferList();
76         BufferList const & bufferList() const;
77         ///
78         Session & session();
79         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         frontend::Application & application();
92         frontend::Application const & application() const;
93
94         ///
95         kb_keymap & topLevelKeymap();
96         kb_keymap const & topLevelKeymap() const;
97
98         ///
99         IconvProcessor & iconvProcessor();
100
101         LyXView * newLyXView();
102
103         /** redraw \c inset in all the BufferViews in which it is currently
104          *  visible. If successful return a pointer to the owning Buffer.
105          */
106         Buffer const * const updateInset(InsetBase const *) const;
107
108 private:
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         /// Initialize RC font for the GUI.
127         void initGuiFont();
128
129         /// initial LyX set up
130         bool init();
131         /// set up the default key bindings
132         void defaultKeyBindings(kb_keymap * kbmap);
133         /// set up the default dead key bindings if requested
134         void deadKeyBindings(kb_keymap * kbmap);
135         /** Check for the existence of the user's support directory and,
136          *  if not present, create it. Exits the program if the directory
137          *  cannot be created.
138          *  \returns true if the user-side configuration script
139          *  (lib/configure) should be re-run in this directory.
140          */
141         bool queryUserLyXDir(bool explicit_userdir);
142         /// read lyxrc/preferences
143         bool readRcFile(std::string const & name);
144         /// read the given ui (menu/toolbar) file
145         bool readUIFile(std::string const & name);
146         /// read the given languages file
147         bool readLanguagesFile(std::string const & name);
148         /// read the given encodings file
149         bool readEncodingsFile(std::string const & name);
150         /// parsing of non-gui LyX options.
151         void easyParse(int & argc, char * argv[]);
152         /// shows up a parsing error on screen
153         void printError(ErrorItem const &);
154
155         /// has this user started lyx for the first time?
156         bool first_start;
157         /// the parsed command line batch command if any
158         std::string batch_command;
159
160         /// Use the Pimpl idiom to hide the internals.
161         struct Singletons;
162         boost::scoped_ptr<Singletons> pimpl_;
163
164         ///
165         bool geometryOption_;
166 };
167
168 } // namespace lyx
169
170 #endif // LYX_MAIN_H