]> git.lyx.org Git - lyx.git/blob - src/lyxfunc.h
Fix configure bug with gettext
[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
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 doImportLinuxDoc();
119
120         ///
121         void MenuInsertLyXFile(string const &);
122
123         ///
124         void CloseBuffer();
125         ///
126         void reloadBuffer();
127         /// This is the same for all lyxfunc objects
128         static bool show_sc;
129 };
130      
131      
132 /*--------------------  inlines  --------------------------*/
133
134 inline
135 bool LyXFunc::wasMetaKey() const 
136
137         return (meta_fake_bit != 0);
138 }
139      
140
141 inline
142 string LyXFunc::keyseqStr() const
143 {
144         // Why not just remove this function
145         string text;
146         keyseq.print(text, true);
147         return text;
148
149
150
151 inline
152 string LyXFunc::keyseqOptions() const
153 {
154         // Why not just remove this function
155         string text;
156         keyseq.printOptions(text);
157         return text;
158
159
160
161 inline
162 bool LyXFunc::keyseqUncomplete() const
163
164         return (keyseq.length > 0);
165 }
166
167
168 inline
169 void LyXFunc::setHintMessage(bool hm) 
170
171         show_sc = hm;
172 }
173
174
175 inline
176 void operator|=(LyXFunc::func_status & fs, LyXFunc::func_status f)
177 {
178         fs = static_cast<LyXFunc::func_status>(fs | f);
179 }
180
181 #endif