]> git.lyx.org Git - lyx.git/blob - src/lyxfunc.h
065683f54e5687dfd1d92903f665a287797a09a9
[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 "kbmap.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         LyXFunc(LyXView *);
34     
35         /// LyX distpatcher, executes lyx actions.
36         string Dispatch(int action, char const * arg = 0);
37                          
38         /// The same but uses the name of a lyx command.
39         string Dispatch(string const & cmd);
40
41         /// A keyboard event is processed to execute a lyx action. 
42         int  processKeyEvent(XEvent * ev);
43
44         ///
45         func_status getStatus(int ac) const;
46         
47         /// The last key was meta
48         bool wasMetaKey() const;
49
50         // These can't be global because are part of the
51         // internal state (ale970227)
52         /// Get the current keyseq string
53         string keyseqStr() const;
54
55         /// Is the key sequence uncomplete?
56         bool keyseqUncomplete() const;
57
58         /// get options for the current keyseq
59         string keyseqOptions() const;
60
61         /// True if lyxfunc reports an error
62         bool errorStat() const { return errorstat; }
63         /// Buffer to store result messages
64         void setMessage(string const & m);
65         /// Buffer to store result messages
66         void setErrorMessage(string const &) const; 
67         /// Buffer to store result messages
68         string getMessage() const { return dispatch_buffer; }
69         /// Get next inset of this class from current cursor position  
70         Inset * getInsetByCode(Inset::Code);
71         
72         /// Should a hint message be displayed?
73         void setHintMessage(bool);
74 private:
75         ///
76         LyXView * owner;
77         ///
78         static int psd_idx;
79         ///
80         kb_sequence keyseq;
81         ///
82         kb_sequence cancel_meta_seq;
83         ///
84         unsigned meta_fake_bit;
85         ///
86         void moveCursorUpdate(bool selecting = false);
87         ///
88         void setupLocalKeymap();
89         ///
90         kb_action lyx_dead_action;
91         ///
92         kb_action lyx_calling_dead_action;
93         /// Error status, only Dispatch can change this flag
94         mutable bool errorstat;
95
96         /** Buffer to store messages and result data. Is there a
97             good reason to have this one as static in Dispatch? (Ale)
98         */
99         mutable string dispatch_buffer;
100         /// Command name and shortcut information
101         string commandshortcut;
102
103         // I think the following should be moved to BufferView. (Asger)
104
105         ///
106         void MenuNew(bool fromTemplate);
107
108         ///
109         void MenuOpen();
110
111         ///
112         void doImportLaTeX(bool);
113
114         ///
115         void doImportASCII(bool);
116
117         ///
118         void MenuInsertLyXFile(string const &);
119
120         ///
121         void CloseBuffer();
122         ///
123         void reloadBuffer();
124         /// This is the same for all lyxfunc objects
125         static bool show_sc;
126 };
127      
128      
129 /*--------------------  inlines  --------------------------*/
130
131 inline
132 bool LyXFunc::wasMetaKey() const 
133
134         return (meta_fake_bit != 0);
135 }
136      
137
138 inline
139 string LyXFunc::keyseqStr() const
140 {
141         // Why not just remove this function
142         string text;
143         keyseq.print(text, true);
144         return text;
145
146
147
148 inline
149 string LyXFunc::keyseqOptions() const
150 {
151         // Why not just remove this function
152         string text;
153         keyseq.printOptions(text);
154         return text;
155
156
157
158 inline
159 bool LyXFunc::keyseqUncomplete() const
160
161         return (keyseq.length > 0);
162 }
163
164
165 inline
166 void LyXFunc::setHintMessage(bool hm) 
167
168         show_sc = hm;
169 }
170
171
172 inline
173 void operator|=(LyXFunc::func_status & fs, LyXFunc::func_status f)
174 {
175         fs = static_cast<LyXFunc::func_status>(fs | f);
176 }
177
178 #endif