]> git.lyx.org Git - lyx.git/blob - src/lyx_main.h
8f51d818b2d645bdbc38539a460d16e4dfd0f316
[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/shared_ptr.hpp>
19 #include <boost/utility.hpp>
20
21 #include <list>
22 #include <string>
23
24 class Buffer;
25 class BufferList;
26 class ErrorItem;
27 class InsetBase;
28 class LyXView;
29 class kb_keymap;
30
31 namespace lyx {
32 class Session;
33 namespace frontend {
34 class Application;
35 }
36 }
37
38
39 /// initial startup
40 class LyX : boost::noncopyable {
41 public:
42         /**
43          * Execute LyX. The startup sequence is as follows:
44          * -# LyX::exec()
45          * -# LyX::priv_exec()
46          * -# lyx::createApplication()
47          * -# LyX::exec2()
48          * Step 3 is omitted if no gui is wanted. We need lyx::createApplication()
49          * only to create the QApplication object in the qt frontend. All
50          * attempts with static and dynamically allocated QApplication
51          * objects lead either to harmless error messages on exit
52          * ("Mutex destroy failure") or crashes (OS X).
53          */
54         static int exec(int & argc, char * argv[]);
55         /// Execute LyX (inner execution loop, \sa exec)
56         int exec2(int & argc, char * argv[]);
57         static LyX & ref();
58         static LyX const & cref();
59
60         /// in the case of failure
61         void emergencyCleanup() const;
62
63         ///
64         BufferList & bufferList();
65         BufferList const & bufferList() const;
66         ///
67         lyx::Session & session();
68         lyx::Session const & session() const;
69
70         void addLyXView(LyXView * lyxview);
71
72         /** redraw \c inset in all the BufferViews in which it is currently
73          *  visible. If successful return a pointer to the owning Buffer.
74          */
75         Buffer const * const updateInset(InsetBase const *) const;
76
77 private:
78         static boost::scoped_ptr<LyX> singleton_;
79
80         LyX();
81         int priv_exec(int & argc, char * argv[]);
82
83         /// initial LyX set up
84         bool init();
85         /// set up the default key bindings
86         void defaultKeyBindings(kb_keymap * kbmap);
87         /// set up the default dead key bindings if requested
88         void deadKeyBindings(kb_keymap * kbmap);
89         /** Check for the existence of the user's support directory and,
90          *  if not present, create it. Exits the program if the directory
91          *  cannot be created.
92          *  \returns true if the user-side configuration script
93          *  (lib/configure) should be re-run in this directory.
94          */
95         bool queryUserLyXDir(bool explicit_userdir);
96         /// read lyxrc/preferences
97         bool readRcFile(std::string const & name);
98         /// read the given ui (menu/toolbar) file
99         bool readUIFile(std::string const & name);
100         /// read the given languages file
101         bool readLanguagesFile(std::string const & name);
102         /// read the given encodings file
103         bool readEncodingsFile(std::string const & name);
104         /// parsing of non-gui LyX options.
105         void easyParse(int & argc, char * argv[]);
106         /// shows up a parsing error on screen
107         void printError(ErrorItem const &);
108
109         /// has this user started lyx for the first time?
110         bool first_start;
111         /// the parsed command line batch command if any
112         std::string batch_command;
113
114         ///
115         boost::scoped_ptr<BufferList> buffer_list_;
116         /// lyx session, containing lastfiles, lastfilepos, and lastopened
117         boost::scoped_ptr<lyx::Session> session_;
118         ///
119         typedef std::list<LyXView *> ViewList;
120         ViewList views_;
121
122         ///
123         bool geometryOption_;
124
125         ///
126         boost::scoped_ptr<lyx::frontend::Application> application_;
127 };
128
129 #endif // LYX_MAIN_H