]> git.lyx.org Git - features.git/blob - src/lyxfunc.h
f8a8e906e0d8c78705c54453c2943841e19acc9a
[features.git] / src / lyxfunc.h
1 // -*- C++ -*-
2 #ifndef LYXFUNC_H
3 #define LYXFUNC_H
4
5 #ifdef __GNUG__
6 #pragma interface
7 #endif
8
9 #include "commandtags.h"
10 #include "kbsequence.h"
11 #include "insets/lyxinset.h"
12 #include "LString.h"
13
14 class LyXView;
15
16 /** This class encapsulates all the LyX command operations. 
17     This is the class of the LyX's "high level event handler".
18     Every user command is processed here, either invocated from
19     keyboard or from the GUI. All GUI objects, including buttons and
20     menus should use this class and never call kernel functions directly.
21 */
22 class LyXFunc {
23 public:
24         /// The status of a function.
25         enum func_status {
26                 OK = 0, // No problem
27                 Unknown = 1,
28                 Disabled = 2, // Command cannot be executed
29                 ToggleOn = 4,
30                 ToggleOff = 8
31         };
32         ///
33         explicit
34         LyXFunc(LyXView *);
35     
36         /// LyX dispatcher, executes lyx actions.
37         string Dispatch(int action, char const * arg = 0);
38                          
39         /// The same but uses the name of a lyx command.
40         string Dispatch(string const & cmd);
41
42         /// A keyboard event is processed to execute a lyx action. 
43         int  processKeyEvent(XEvent * ev);
44
45         ///
46         func_status getStatus(int ac) const;
47         
48         /// The last key was meta
49         bool wasMetaKey() const;
50
51         // These can't be global because are part of the
52         // internal state (ale970227)
53         /// Get the current keyseq string
54         string keyseqStr() const;
55
56         /// Is the key sequence uncomplete?
57         bool keyseqUncomplete() const;
58
59         /// get options for the current keyseq
60         string keyseqOptions() const;
61
62         /// True if lyxfunc reports an error
63         bool errorStat() const { return errorstat; }
64         /// Buffer to store result messages
65         void setMessage(string const & m);
66         /// Buffer to store result messages
67         void setErrorMessage(string const &) const; 
68         /// Buffer to store result messages
69         string getMessage() const { return dispatch_buffer; }
70         /// Get next inset of this class from current cursor position  
71         Inset * getInsetByCode(Inset::Code);
72         
73         /// Should a hint message be displayed?
74         void setHintMessage(bool);
75
76 private:
77         ///
78         LyXView * owner;
79         ///
80         static int psd_idx;
81         ///
82         kb_sequence keyseq;
83         ///
84         kb_sequence cancel_meta_seq;
85         ///
86         unsigned meta_fake_bit;
87         ///
88         void moveCursorUpdate(bool selecting = false);
89         ///
90         void setupLocalKeymap();
91         ///
92         kb_action lyx_dead_action;
93         ///
94         kb_action lyx_calling_dead_action;
95         /// Error status, only Dispatch can change this flag
96         mutable bool errorstat;
97
98         /** Buffer to store messages and result data. Is there a
99             good reason to have this one as static in Dispatch? (Ale)
100         */
101         mutable string dispatch_buffer;
102         /// Command name and shortcut information
103         string commandshortcut;
104
105         // I think the following should be moved to BufferView. (Asger)
106
107         ///
108         void MenuNew(bool fromTemplate);
109
110         ///
111         void MenuOpen();
112
113         ///
114         void doImport(string const &);
115         void doImportHelper(string const &, string const &, string const &,
116                 bool func(BufferView *, string const &) );
117
118         ///
119         void MenuInsertLyXFile(string const &);
120
121         ///
122         void CloseBuffer();
123         ///
124         void reloadBuffer();
125         /// This is the same for all lyxfunc objects
126         static bool show_sc;
127 };
128      
129      
130 /*--------------------  inlines  --------------------------*/
131
132 inline
133 bool LyXFunc::wasMetaKey() const 
134
135         return (meta_fake_bit != 0);
136 }
137      
138
139 inline
140 string LyXFunc::keyseqStr() const
141 {
142         // Why not just remove this function
143         string text;
144         keyseq.print(text, true);
145         return text;
146
147
148
149 inline
150 string LyXFunc::keyseqOptions() const
151 {
152         // Why not just remove this function
153         string text;
154         keyseq.printOptions(text);
155         return text;
156
157
158
159 inline
160 bool LyXFunc::keyseqUncomplete() const
161
162         return (keyseq.length > 0);
163 }
164
165
166 inline
167 void LyXFunc::setHintMessage(bool hm) 
168
169         show_sc = hm;
170 }
171
172
173 inline
174 void operator|=(LyXFunc::func_status & fs, LyXFunc::func_status f)
175 {
176         fs = static_cast<LyXFunc::func_status>(fs | f);
177 }
178
179 #endif