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