]> git.lyx.org Git - lyx.git/blob - src/LyXFunc.h
Fix crash noticed by Bennett:
[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 "FuncCode.h"
19 #include "KeySequence.h"
20
21 #include "support/docstring.h"
22
23 namespace lyx {
24
25 class Buffer;
26 class BufferView;
27 class DocumentClass;
28 class FuncRequest;
29 class FuncStatus;
30 class KeySymbol;
31 class Text;
32
33 namespace support {
34 class FileName;
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 initKeySequences(KeyMap * kb);
54
55         /// return the status bar state string
56         docstring viewStatusMessage();
57
58         ///
59         void processKeySym(KeySymbol const & key, KeyModifier state);
60
61         ///
62         FuncStatus getStatus(FuncRequest const & action) const;
63
64         /// The last key was meta
65         bool wasMetaKey() const;
66
67         /// True if lyxfunc reports an error
68         bool errorStat() const { return errorstat; }
69         /// Buffer to store result messages
70         void setMessage(docstring const & m) const;
71         /// Buffer to store result messages
72         void setErrorMessage(docstring const &) const;
73         /// Buffer to store result messages
74         docstring const getMessage() const { return dispatch_buffer; }
75         /// Handle a accented char key sequence
76         void handleKeyFunc(FuncCode action);
77         /// goto a bookmark
78         /// openFile: whether or not open a file if the file is not opened
79         /// switchToBuffer: whether or not switch to buffer if the buffer is
80         ///             not the current buffer
81         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
82
83         /// cursor x position before dispatch started
84         int cursorBeforeDispatchX() const { return cursorPosBeforeDispatchX_; }
85         /// cursor y position before dispatch started
86         int cursorBeforeDispatchY() const { return cursorPosBeforeDispatchY_; }
87
88 private:
89         /// the last character added to the key sequence, in UCS4 encoded form
90         char_type encoded_last_key;
91
92         ///
93         KeySequence keyseq;
94         ///
95         KeySequence cancel_meta_seq;
96         ///
97         KeyModifier meta_fake_bit;
98
99         /// cursor position before dispatch started
100         int cursorPosBeforeDispatchX_;
101         int cursorPosBeforeDispatchY_;
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
116 /// Implementation is in LyX.cpp
117 extern LyXFunc & theLyXFunc();
118
119 /// Implementation is in LyX.cpp
120 extern FuncStatus getStatus(FuncRequest const & action);
121
122 /// Implementation is in LyX.cpp
123 extern void dispatch(FuncRequest const & action);
124
125 } // namespace lyx
126
127 #endif