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, int key, XEvent * xev)
81 if (dropdown_->isVisible()) {
82 return dropdown_->peek(xev);
93 if (information_displayed_) {
94 information_timer_->stop();
98 char const * tmp = fl_get_input(ob);
99 input = tmp ? tmp : "";
105 if (hist_iter != history_->end()) {
108 if (hist_iter == history_->end()) {
109 // no further history
110 show_information(_("[End of history]"), input);
112 set_input((*hist_iter));
116 if (hist_iter == history_->begin()) {
117 // no further history
118 show_information(_("[Beginning of history]"),
122 set_input((*hist_iter));
128 // Completion handling.
131 lyx::copy_if(completion_.begin(),
133 back_inserter(comp), prefix(input));
137 string const tmp = input + _(" [no match]");
138 show_information(tmp, input);
139 } else if (comp.size() == 1) {
142 comp[0] + _(" [sole completion]");
143 show_information(tmp, comp[0] + " ");
145 // More that one match
146 // Find maximal avaliable prefix
147 string const tmp = comp[0];
149 if (tmp.length() > test.length())
150 test += tmp[test.length()];
151 while (test.length() < tmp.length()) {
153 lyx::copy_if(comp.begin(),
157 if (vtmp.size() != comp.size()) {
158 test.erase(test.length() - 1);
161 test += tmp[test.length()];
166 fl_get_wingeometry(fl_get_real_object_window(the_buffer),
169 // asynchronous completion
170 int const air = the_buffer->x;
172 y += h - (the_buffer->h + air);
174 dropdown_->select(comp, x, y, w);
182 owner_->view()->focus(true);
192 // This will go in again in a little while
193 // we need to be able to declare what types
194 // of argumetns LFUN's should have first. (Lgb)
195 // First check for match
196 vector<string>::const_iterator cit =
197 find(completion_.begin(),
200 if (cit == completion_.end()) {
202 string const tmp = input + _(" [no match]");
203 show_information(tmp, input);
206 // Return the inputted string
209 owner_->view()->focus(true);
211 if (!input.empty()) {
212 history_->push_back(input);
225 //lyxerr << "Unhandled minibuffer event!" << endl;
236 int C_XMiniBuffer_peek_event(FL_OBJECT * ob, int event,
240 XMiniBuffer * mini = static_cast<XMiniBuffer*>(ob->u_vdata);
241 return mini->peek_event(ob, event, key,
242 static_cast<XEvent *>(xev));
248 FL_OBJECT * XMiniBuffer::create_input_box(int type, FL_Coord x, FL_Coord y,
249 FL_Coord w, FL_Coord h)
253 the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
254 fl_set_object_boxtype(obj, FL_DOWN_BOX);
255 fl_set_object_resize(obj, FL_RESIZE_ALL);
256 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
257 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
258 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
260 // To intercept Up, Down, Table for history
261 fl_set_object_prehandler(obj, C_XMiniBuffer_peek_event);
263 obj->wantkey = FL_KEY_TAB;
271 bool XMiniBuffer::isEditingMode() const
273 return the_buffer->focus;
277 void XMiniBuffer::editingMode()
279 fl_activate_object(the_buffer);
280 fl_set_focus_object(static_cast<XFormsView *>(owner_)->getForm(),
286 void XMiniBuffer::messageMode()
288 fl_deactivate_object(the_buffer);
293 void XMiniBuffer::redraw()
295 fl_redraw_object(the_buffer);
300 void XMiniBuffer::append_char(char c)
302 if (!c || !isprint(c))
305 char const * tmp = fl_get_input(the_buffer);
306 string str = tmp ? tmp : "";
310 fl_set_input(the_buffer, str.c_str());
314 void XMiniBuffer::set_input(string const & str)
316 fl_set_input(the_buffer, str.c_str());