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