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