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