]> git.lyx.org Git - lyx.git/blob - src/lyxfunc.h
b381cab55799c71c7f7ffc5c9dd45b92e768c6ce
[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 "tex-accent.h"
12 #include "LyXAction.h"
13 #include "insets/lyxinset.h"
14 #include "LString.h"
15 class LyXView;
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         ///
26         LyXFunc(LyXView*);
27         ///
28         ~LyXFunc();
29     
30         /// LyX distpatcher, executes lyx actions.
31         string Dispatch(int action, char const* arg = 0);
32                          
33         /// The same but uses the name of a lyx command.
34         string Dispatch(string const &cmd, string const &arg = string());
35
36         
37         /// A keyboard event is processed to execute a lyx action. 
38         int  processKeyEvent(XEvent *ev);
39      
40         /// The last key was meta
41         bool wasMetaKey();
42
43         // These can't be global because are part of the internat state (ale970227)
44         /// Get the current keyseq string
45         string keyseqStr(int l=190);
46
47         /// Is the key sequence uncomplete?
48         bool keyseqUncomplete();
49
50         /// get options for the current keyseq
51         string keyseqOptions(int l=190);
52
53         /// Returns the name of a funcion given a keyseq
54         char const* getFunc(char*) 
55         { /* unimplemented */ return 0; }
56
57         /// Return a string with the keybind to an action, if any
58         char const* getKeybind(int) 
59         { /* unimplemented */ return 0; }
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 &); 
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
75 private:
76         ///
77         string argAsString(char const *const argument);
78         ///
79         LyXView *owner;
80         ///
81         static kb_func_table* lyx_func_table;
82         ///
83         static kb_func_table *lyx_func_args;
84         ///
85         static int psd_idx;
86         ///
87         kb_sequence keyseq;
88         ///
89         kb_sequence cancel_meta_seq;
90         ///
91         unsigned meta_fake_bit;
92         ///
93         void moveCursorUpdate(bool selecting = false);
94         ///
95         void setupLocalKeymap();
96         ///
97         kb_action lyx_dead_action;
98         ///
99         kb_action lyx_calling_dead_action;
100         /// Error status, only Dispatch can change this flag
101         bool errorstat;
102
103         /** Buffer to store messages and result data. Is there a
104           good reason to have this one as static in Dispatch? (Ale)
105          */
106         string dispatch_buffer;
107         /// Command name and shortcut information
108         string commandshortcut;
109
110         // I think the following should be moved to BufferView. (Asger)
111
112         ///
113         void MenuNew(bool fromTemplate);
114
115         ///
116         void MenuOpen();
117
118         ///
119         void doImportLaTeX(bool);
120
121         ///
122         void doImportASCII(bool);
123
124         ///
125         void MenuInsertLyXFile(string const &);
126
127         ///
128         void CloseBuffer();
129         ///
130         void reloadBuffer();
131         /// This is the same for all lyxfunc objects
132         static bool show_sc;
133 };
134      
135      
136 /*--------------------  inlines  --------------------------*/
137
138 inline
139 bool LyXFunc::wasMetaKey() 
140
141         return (meta_fake_bit != 0);
142 }
143      
144
145 inline
146 string LyXFunc::keyseqStr(int l)
147 {
148         char text[200];
149         keyseq.print(text, l, true);
150         string tmp(text);
151         return tmp;
152
153
154
155 inline
156 string LyXFunc::keyseqOptions(int l)
157 {
158         char text[200];
159         keyseq.printOptions(text, l);
160         string tmp(text);
161         return tmp;
162
163
164
165 inline
166 bool LyXFunc::keyseqUncomplete() 
167
168         return (keyseq.length > 0);
169 }
170
171 inline
172 void LyXFunc::setHintMessage(bool hm) 
173
174         show_sc = hm;
175 }
176
177 #endif