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