]> git.lyx.org Git - lyx.git/blob - src/lyxfunc.h
remove CXX_WORKING_NAMESPACES
[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         /// we need one internall which is called from inside LyXAction and
56         /// can contain the string argument.
57         func_status getStatus(int ac) const;
58         func_status getStatus(int ac, string const & not_to_use_arg) const;
59         
60         /// The last key was meta
61         bool wasMetaKey() const;
62
63         // These can't be global because are part of the
64         // internal state (ale970227)
65         /// Get the current keyseq string
66         string const keyseqStr() const;
67
68         /// Is the key sequence uncomplete?
69         bool keyseqUncomplete() const;
70
71         /// get options for the current keyseq
72         string const keyseqOptions() const;
73
74         /// True if lyxfunc reports an error
75         bool errorStat() const { return errorstat; }
76         /// Buffer to store result messages
77         void setMessage(string const & m);
78         /// Buffer to store result messages
79         void setErrorMessage(string const &) const; 
80         /// Buffer to store result messages
81         string const getMessage() const { return dispatch_buffer; }
82         /// Handle a accented char keysequenze
83         void handleKeyFunc(kb_action action);
84         /// Should a hint message be displayed?
85         void setHintMessage(bool);
86 private:
87         ///
88         LyXView * owner;
89         ///
90         static int psd_idx;
91         ///
92         kb_sequence keyseq;
93         ///
94         kb_sequence cancel_meta_seq;
95         ///
96         unsigned meta_fake_bit;
97         ///
98         void moveCursorUpdate(bool flag = true, bool selecting = false);
99         ///
100         void setupLocalKeymap();
101         ///
102         kb_action lyx_dead_action;
103         ///
104         kb_action lyx_calling_dead_action;
105         /// Error status, only Dispatch can change this flag
106         mutable bool errorstat;
107
108         /** Buffer to store messages and result data. Is there a
109             good reason to have this one as static in Dispatch? (Ale)
110         */
111         mutable string dispatch_buffer;
112         /// Command name and shortcut information
113         string commandshortcut;
114
115         // I think the following should be moved to BufferView. (Asger)
116
117         ///
118         void MenuNew(bool fromTemplate);
119
120         ///
121         void Open(string const &);
122
123         ///
124         void doImport(string const &);
125
126         ///
127         void CloseBuffer();
128         ///
129         void reloadBuffer();
130         ///
131         //  This return or directly text (default) of getLyXText()
132         ///
133         LyXText * TEXT(bool) const;
134         ///
135         //  This is the same for all lyxfunc objects
136         static bool show_sc;
137 };
138      
139      
140 /*--------------------  inlines  --------------------------*/
141
142 inline
143 bool LyXFunc::wasMetaKey() const 
144
145         return (meta_fake_bit != 0);
146 }
147      
148
149 inline
150 string const LyXFunc::keyseqStr() const
151 {
152         // Why not just remove this function
153         string text;
154         keyseq.print(text, true);
155         return text;
156
157
158
159 inline
160 string const LyXFunc::keyseqOptions() const
161 {
162         // Why not just remove this function
163         string text;
164         keyseq.printOptions(text);
165         return text;
166
167
168
169 inline
170 bool LyXFunc::keyseqUncomplete() const
171
172         return (keyseq.length > 0);
173 }
174
175
176 inline
177 void LyXFunc::setHintMessage(bool hm) 
178
179         show_sc = hm;
180 }
181
182 ///
183 inline
184 void operator|=(LyXFunc::func_status & fs, LyXFunc::func_status f)
185 {
186         fs = static_cast<LyXFunc::func_status>(fs | f);
187 }
188
189 #endif