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