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