4 * Copyright 1995-2002 the LyX Team
5 * Read the file COPYING
8 * \author Asger and Juergen
14 #pragma implementation
17 #include "frontends/xforms/DropDown.h"
18 #include "frontends/xforms/XFormsView.h"
19 #include "frontends/Timeout.h"
21 #include "XMiniBuffer.h"
22 #include "BufferView.h"
23 #include "LyXAction.h"
25 #include "support/lyxalgo.h"
26 #include "support/lstrings.h"
28 #include <boost/bind.hpp>
33 #ifndef CXX_GLOBAL_CSTD
44 prefix(string const & s)
46 bool operator()(string const & s) const {
47 return prefixIs(s, p);
51 } // end of anon namespace
54 XMiniBuffer::XMiniBuffer(LyXView * o, FL_Coord x, FL_Coord y,
55 FL_Coord h, FL_Coord w)
58 create_input_box(FL_NORMAL_INPUT, x, y, h, w);
63 // thanks for nothing, xforms (recursive creation not allowed)
64 void XMiniBuffer::dd_init()
66 dropdown_ = new DropDown(owner_, the_buffer);
67 dropdown_->result.connect(boost::bind(&XMiniBuffer::set_complete_input, this, _1));
68 dropdown_->keypress.connect(boost::bind(&XMiniBuffer::append_char, this, _1));
72 XMiniBuffer::~XMiniBuffer()
78 int XMiniBuffer::peek_event(FL_OBJECT * ob, int event,
79 int key, XEvent * /*xev*/)
82 if (dropdown_->isVisible()) {
83 return dropdown_->peek(xev);
94 if (information_displayed_) {
95 information_timer_->stop();
99 char const * tmp = fl_get_input(ob);
100 input = tmp ? tmp : "";
109 if (hist_iter != history_->end()) {
112 if (hist_iter == history_->end()) {
113 // no further history
114 show_information(_("[End of history]"), input);
116 set_input((*hist_iter));
123 if (hist_iter == history_->begin()) {
124 // no further history
125 show_information(_("[Beginning of history]"),
129 set_input((*hist_iter));
135 // Completion handling.
138 lyx::copy_if(completion_.begin(),
140 back_inserter(comp), prefix(input));
144 string const tmp = input + _(" [no match]");
145 show_information(tmp, input);
146 } else if (comp.size() == 1) {
149 comp[0] + _(" [sole completion]");
150 show_information(tmp, comp[0] + " ");
152 // More that one match
153 // Find maximal avaliable prefix
154 string const tmp = comp[0];
156 if (tmp.length() > test.length())
157 test += tmp[test.length()];
158 while (test.length() < tmp.length()) {
160 lyx::copy_if(comp.begin(),
164 if (vtmp.size() != comp.size()) {
165 test.erase(test.length() - 1);
168 test += tmp[test.length()];
173 fl_get_wingeometry(fl_get_real_object_window(the_buffer),
176 // asynchronous completion
177 int const air = the_buffer->x;
179 y += h - (the_buffer->h + air);
181 dropdown_->select(comp, x, y, w);
189 owner_->view()->focus(true);
202 // This will go in again in a little while
203 // we need to be able to declare what types
204 // of argumetns LFUN's should have first. (Lgb)
205 // First check for match
206 vector<string>::const_iterator cit =
207 find(completion_.begin(),
210 if (cit == completion_.end()) {
212 string const tmp = input + _(" [no match]");
213 show_information(tmp, input);
216 // Return the inputted string
219 owner_->view()->focus(true);
221 if (!input.empty()) {
222 history_->push_back(input);
235 //lyxerr << "Unhandled minibuffer event!" << endl;
246 int C_XMiniBuffer_peek_event(FL_OBJECT * ob, int event,
250 XMiniBuffer * mini = static_cast<XMiniBuffer*>(ob->u_vdata);
251 return mini->peek_event(ob, event, key,
252 static_cast<XEvent *>(xev));
258 FL_OBJECT * XMiniBuffer::create_input_box(int type, FL_Coord x, FL_Coord y,
259 FL_Coord w, FL_Coord h)
263 the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
264 fl_set_object_boxtype(obj, FL_DOWN_BOX);
265 fl_set_object_resize(obj, FL_RESIZE_ALL);
266 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
267 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
268 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
270 // To intercept Up, Down, Table for history
271 fl_set_object_prehandler(obj, C_XMiniBuffer_peek_event);
273 obj->wantkey = FL_KEY_TAB;
281 bool XMiniBuffer::isEditingMode() const
283 return the_buffer->focus;
287 void XMiniBuffer::editingMode()
289 fl_activate_object(the_buffer);
290 fl_set_focus_object(static_cast<XFormsView *>(owner_)->getForm(),
296 void XMiniBuffer::messageMode()
298 fl_deactivate_object(the_buffer);
303 void XMiniBuffer::redraw()
305 fl_redraw_object(the_buffer);
310 void XMiniBuffer::append_char(char c)
312 if (!c || !isprint(c))
315 char const * tmp = fl_get_input(the_buffer);
316 string str = tmp ? tmp : "";
320 fl_set_input(the_buffer, str.c_str());
324 void XMiniBuffer::set_input(string const & str)
326 fl_set_input(the_buffer, str.c_str());