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