]> git.lyx.org Git - lyx.git/blob - src/lyxfunc.h
8f6738de34dfc014fd5d65c965431c0af4b90a9f
[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 internat state (ale970227)
51         /// Get the current keyseq string
52         string keyseqStr(int l = 190) const;
53
54         /// Is the key sequence uncomplete?
55         bool keyseqUncomplete() const;
56
57         /// get options for the current keyseq
58         string keyseqOptions(int l = 190) const;
59
60         /// True if lyxfunc reports an error
61         bool errorStat() const { return errorstat; }
62         /// Buffer to store result messages
63         void setMessage(string const & m);
64         /// Buffer to store result messages
65         void setErrorMessage(string const &) const; 
66         /// Buffer to store result messages
67         string getMessage() const { return dispatch_buffer; }
68         /// Get next inset of this class from current cursor position  
69         Inset * getInsetByCode(Inset::Code);
70         
71         /// Should a hint message be displayed?
72         void setHintMessage(bool);
73
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(int l) const
140 {
141         char text[200];
142         keyseq.print(text, l, true);
143         string tmp(text);
144         return tmp;
145
146
147
148 inline
149 string LyXFunc::keyseqOptions(int l) const
150 {
151         char text[200];
152         keyseq.printOptions(text, l);
153         string tmp(text);
154         return tmp;
155
156
157
158 inline
159 bool LyXFunc::keyseqUncomplete() const
160
161         return (keyseq.length > 0);
162 }
163
164 inline
165 void LyXFunc::setHintMessage(bool hm) 
166
167         show_sc = hm;
168 }
169
170 inline
171 void operator|=(LyXFunc::func_status & fs, LyXFunc::func_status f)
172 {
173         fs = static_cast<LyXFunc::func_status>(fs | f);
174 }
175
176 #endif