]> git.lyx.org Git - lyx.git/blob - src/lyx_main.h
MacOSX compile fix.
[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 #include <vector>
24
25 class Buffer;
26 class BufferList;
27 class ErrorItem;
28 class InsetBase;
29 class LyXView;
30 class kb_keymap;
31
32 namespace lyx {
33 extern bool use_gui;
34 class Session;
35 namespace frontend {
36 class Application;
37 }
38 }
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(bool noask);
70
71         ///
72         BufferList & bufferList();
73         BufferList const & bufferList() const;
74         ///
75         lyx::Session & session();
76         lyx::Session const & session() const;
77
78         void addLyXView(LyXView * lyxview);
79
80         /** redraw \c inset in all the BufferViews in which it is currently
81          *  visible. If successful return a pointer to the owning Buffer.
82          */
83         Buffer const * const updateInset(InsetBase const *) const;
84
85 private:
86         static boost::scoped_ptr<LyX> singleton_;
87
88         LyX();
89         int priv_exec(int & argc, char * argv[]);
90
91         /// Do some cleanup in preparation of an exit.
92         void prepareExit();
93
94         /// Early exit during the initialisation process.
95         void earlyExit(int status);
96
97         /// Initialise LyX and execute batch commands if available.
98         /**
99         \param files is filled in with the command-line file names.
100         \return exit code failure if any.
101         */
102         int execBatchCommands(int & argc, char * argv[],
103                 std::vector<std::string> & files);
104
105         /// Create a View and restore GUI Session.
106         void restoreGuiSession(std::vector<std::string> const & files);
107
108         /// Initialize RC font for the GUI.
109         void initGuiFont();
110
111         /// initial LyX set up
112         bool init();
113         /// set up the default key bindings
114         void defaultKeyBindings(kb_keymap * kbmap);
115         /// set up the default dead key bindings if requested
116         void deadKeyBindings(kb_keymap * kbmap);
117         /** Check for the existence of the user's support directory and,
118          *  if not present, create it. Exits the program if the directory
119          *  cannot be created.
120          *  \returns true if the user-side configuration script
121          *  (lib/configure) should be re-run in this directory.
122          */
123         bool queryUserLyXDir(bool explicit_userdir);
124         /// read lyxrc/preferences
125         bool readRcFile(std::string const & name);
126         /// read the given ui (menu/toolbar) file
127         bool readUIFile(std::string const & name);
128         /// read the given languages file
129         bool readLanguagesFile(std::string const & name);
130         /// read the given encodings file
131         bool readEncodingsFile(std::string const & name);
132         /// parsing of non-gui LyX options.
133         void easyParse(int & argc, char * argv[]);
134         /// shows up a parsing error on screen
135         void printError(ErrorItem const &);
136
137         /// has this user started lyx for the first time?
138         bool first_start;
139         /// the parsed command line batch command if any
140         std::string batch_command;
141
142         ///
143         boost::scoped_ptr<BufferList> buffer_list_;
144         /// lyx session, containing lastfiles, lastfilepos, and lastopened
145         boost::scoped_ptr<lyx::Session> session_;
146         ///
147         typedef std::list<LyXView *> ViewList;
148         ViewList views_;
149
150         ///
151         bool geometryOption_;
152
153         ///
154         boost::scoped_ptr<lyx::frontend::Application> application_;
155 };
156
157 #endif // LYX_MAIN_H