]> git.lyx.org Git - lyx.git/blob - src/lyx_main.h
* InsetMathNest.C (handleFont): avoid crash on undo when
[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
22 namespace lyx {
23
24 class Buffer;
25 class BufferList;
26 class ErrorItem;
27 class IconvProcessor;
28 class InsetBase;
29 class LyXFunc;
30 class LyXServer;
31 class LyXServerSocket;
32 class LyXView;
33 class Session;
34 class kb_keymap;
35
36 extern bool use_gui;
37
38 namespace frontend { class Application; }
39
40 /// initial startup
41 class LyX : boost::noncopyable {
42 public:
43
44         LyX();
45         ~LyX();
46
47         /// Execute LyX.
48         int exec(int & argc, char * argv[]);
49
50         static LyX & ref();
51         static LyX const & cref();
52
53         /// in the case of failure
54         void emergencyCleanup() const;
55
56         ///
57         BufferList & bufferList();
58         BufferList const & bufferList() const;
59         ///
60         Session & session();
61         Session const & session() const;
62         ///
63         LyXFunc & lyxFunc();
64         LyXFunc const & lyxFunc() const;
65         ///
66         LyXServer & server();
67         LyXServer const & server() const;
68         ///
69         LyXServerSocket & socket();
70         LyXServerSocket const & socket() const;
71
72         ///
73         frontend::Application & application();
74         frontend::Application const & application() const;
75
76         ///
77         kb_keymap & topLevelKeymap();
78         kb_keymap const & topLevelKeymap() const;
79
80         ///
81         IconvProcessor & iconvProcessor();
82
83         LyXView * newLyXView();
84
85         /** redraw \c inset in all the BufferViews in which it is currently
86          *  visible. If successful return a pointer to the owning Buffer.
87          */
88         Buffer const * const updateInset(InsetBase const *) const;
89
90         /// Execute batch commands if available.
91         void execBatchCommands();
92
93 private:
94         /// Do some cleanup in preparation of an exit.
95         void prepareExit();
96
97         /// Early exit during the initialisation process.
98         void earlyExit(int status);
99
100         /// Initialise LyX and fills-in the vector of files to be loaded.
101         /**
102         \return exit code failure if any.
103         */
104         int init(int & argc, char * argv[]);
105
106         /// Load files passed at command-line.
107         /**
108         This method is used only in non-GUI mode.
109         */
110         void loadFiles();
111
112         /// Create a View, load files and restore GUI Session.
113         void restoreGuiSession();
114
115         /// Initialize RC font for the GUI.
116         void initGuiFont();
117
118         /// initial LyX set up
119         bool init();
120         /// set up the default key bindings
121         void defaultKeyBindings(kb_keymap * kbmap);
122         /// set up the default dead key bindings if requested
123         void deadKeyBindings(kb_keymap * kbmap);
124         /** Check for the existence of the user's support directory and,
125          *  if not present, create it. Exits the program if the directory
126          *  cannot be created.
127          *  \returns true if the user-side configuration script
128          *  (lib/configure) should be re-run in this directory.
129          */
130         bool queryUserLyXDir(bool explicit_userdir);
131         /// read lyxrc/preferences
132         bool readRcFile(std::string const & name);
133         /// read the given ui (menu/toolbar) file
134         bool readUIFile(std::string const & name);
135         /// read the given languages file
136         bool readLanguagesFile(std::string const & name);
137         /// read the given encodings file
138         bool readEncodingsFile(std::string const & name);
139         /// parsing of non-gui LyX options.
140         void easyParse(int & argc, char * argv[]);
141         /// shows up a parsing error on screen
142         void printError(ErrorItem const &);
143
144         /// has this user started lyx for the first time?
145         bool first_start;
146         /// the parsed command line batch command if any
147         std::string batch_command;
148
149         /// Use the Pimpl idiom to hide the internals.
150         struct Singletons;
151         boost::scoped_ptr<Singletons> pimpl_;
152 };
153
154 } // namespace lyx
155
156 #endif // LYX_MAIN_H