]> git.lyx.org Git - lyx.git/blob - src/LyXFunc.h
adjust
[lyx.git] / src / LyXFunc.h
1 // -*- C++ -*-
2 /**
3  * \file LyXFunc.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  * \author André Pönitz
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef LYXFUNC_H
16 #define LYXFUNC_H
17
18 #include "KeySequence.h"
19 #include "lfuns.h"
20 #include "TextClass.h"
21
22 #include "support/docstring.h"
23
24 namespace lyx {
25
26 class Buffer;
27 class BufferView;
28 class FuncRequest;
29 class FuncStatus;
30 class KeySymbol;
31 class Text;
32
33 namespace frontend {
34 class LyXView;
35 }
36
37 /** This class encapsulates all the LyX command operations.
38     This is the class of the LyX's "high level event handler".
39     Every user command is processed here, either invocated from
40     keyboard or from the GUI. All GUI objects, including buttons and
41     menus should use this class and never call kernel functions directly.
42 */
43 class LyXFunc
44 {
45 public:
46         ///
47         explicit LyXFunc();
48
49         /// LyX dispatcher, executes lyx actions.
50         void dispatch(FuncRequest const &);
51
52         ///
53         void setLyXView(frontend::LyXView * lv);
54
55         ///
56         void initKeySequences(KeyMap * kb);
57
58         /// return the status bar state string
59         docstring const viewStatusMessage();
60
61         ///
62         void processKeySym(KeySymbol const & key, KeyModifier state);
63
64         ///
65         FuncStatus getStatus(FuncRequest const & action) const;
66
67         /// The last key was meta
68         bool wasMetaKey() const;
69
70         /// True if lyxfunc reports an error
71         bool errorStat() const { return errorstat; }
72         /// Buffer to store result messages
73         void setMessage(docstring const & m) const;
74         /// Buffer to store result messages
75         void setErrorMessage(docstring const &) const;
76         /// Buffer to store result messages
77         docstring const getMessage() const { return dispatch_buffer; }
78         /// Handle a accented char key sequence
79         void handleKeyFunc(kb_action action);
80         /// goto a bookmark
81         /// openFile: whether or not open a file if the file is not opened
82         /// switchToBuffer: whether or not switch to buffer if the buffer is
83         ///             not the current buffer
84         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
85
86 private:
87         ///
88         BufferView * view() const;
89
90         ///
91         frontend::LyXView * lyx_view_;
92
93         /// the last character added to the key sequence, in UCS4 encoded form
94         char_type encoded_last_key;
95
96         ///
97         KeySequence keyseq;
98         ///
99         KeySequence cancel_meta_seq;
100         ///
101         KeyModifier meta_fake_bit;
102
103         /// Error status, only Dispatch can change this flag
104         mutable bool errorstat;
105
106         /** Buffer to store messages and result data. Is there a
107             good reason to have this one as static in Dispatch? (Ale)
108         */
109         mutable docstring dispatch_buffer;
110
111         /// send a post-dispatch status message
112         void sendDispatchMessage(docstring const & msg,
113                 FuncRequest const & ev);
114
115         // I think the following should be moved to BufferView. (Asger)
116         ///
117         void menuNew(std::string const & argument, bool fromTemplate);
118         ///
119         void open(std::string const &);
120         ///
121         void doImport(std::string const &);
122         ///
123         void closeBuffer();
124         ///
125         void reloadBuffer();
126         ///
127         bool ensureBufferClean(BufferView * bv);
128         ///
129         void updateLayout(TextClassPtr const & oldlayout, Buffer * buffer);
130 };
131
132 /// Implementation is in LyX.cpp
133 extern LyXFunc & theLyXFunc();
134
135 /// Implementation is in LyX.cpp
136 extern FuncStatus getStatus(FuncRequest const & action);
137
138 /// Implementation is in LyX.cpp
139 extern void dispatch(FuncRequest const & action);
140
141 } // namespace lyx
142
143 #endif