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