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 : "";
106 if (hist_iter != history_->end()) {
109 if (hist_iter == history_->end()) {
110 // no further history
111 show_information(_("[End of history]"), input);
113 set_input((*hist_iter));
117 if (hist_iter == history_->begin()) {
118 // no further history
119 show_information(_("[Beginning of history]"),
123 set_input((*hist_iter));
129 // Completion handling.
132 lyx::copy_if(completion_.begin(),
134 back_inserter(comp), prefix(input));
138 string const tmp = input + _(" [no match]");
139 show_information(tmp, input);
140 } else if (comp.size() == 1) {
143 comp[0] + _(" [sole completion]");
144 show_information(tmp, comp[0] + " ");
146 // More that one match
147 // Find maximal avaliable prefix
148 string const tmp = comp[0];
150 if (tmp.length() > test.length())
151 test += tmp[test.length()];
152 while (test.length() < tmp.length()) {
154 lyx::copy_if(comp.begin(),
158 if (vtmp.size() != comp.size()) {
159 test.erase(test.length() - 1);
162 test += tmp[test.length()];
167 fl_get_wingeometry(fl_get_real_object_window(the_buffer),
170 // asynchronous completion
171 int const air = the_buffer->x;
173 y += h - (the_buffer->h + air);
175 dropdown_->select(comp, x, y, w);
183 owner_->view()->focus(true);
193 // This will go in again in a little while
194 // we need to be able to declare what types
195 // of argumetns LFUN's should have first. (Lgb)
196 // First check for match
197 vector<string>::const_iterator cit =
198 find(completion_.begin(),
201 if (cit == completion_.end()) {
203 string const tmp = input + _(" [no match]");
204 show_information(tmp, input);
207 // Return the inputted string
210 owner_->view()->focus(true);
212 if (!input.empty()) {
213 history_->push_back(input);
226 //lyxerr << "Unhandled minibuffer event!" << endl;
237 int C_XMiniBuffer_peek_event(FL_OBJECT * ob, int event,
241 XMiniBuffer * mini = static_cast<XMiniBuffer*>(ob->u_vdata);
242 return mini->peek_event(ob, event, key,
243 static_cast<XEvent *>(xev));
249 FL_OBJECT * XMiniBuffer::create_input_box(int type, FL_Coord x, FL_Coord y,
250 FL_Coord w, FL_Coord h)
254 the_buffer = obj = fl_add_input(type, x, y, w, h, text.c_str());
255 fl_set_object_boxtype(obj, FL_DOWN_BOX);
256 fl_set_object_resize(obj, FL_RESIZE_ALL);
257 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
258 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
259 fl_set_object_lsize(obj, FL_NORMAL_SIZE);
261 // To intercept Up, Down, Table for history
262 fl_set_object_prehandler(obj, C_XMiniBuffer_peek_event);
264 obj->wantkey = FL_KEY_TAB;
272 bool XMiniBuffer::isEditingMode() const
274 return the_buffer->focus;
278 void XMiniBuffer::editingMode()
280 fl_activate_object(the_buffer);
281 fl_set_focus_object(static_cast<XFormsView *>(owner_)->getForm(),
287 void XMiniBuffer::messageMode()
289 fl_deactivate_object(the_buffer);
294 void XMiniBuffer::redraw()
296 fl_redraw_object(the_buffer);
301 void XMiniBuffer::append_char(char c)
303 if (!c || !isprint(c))
306 char const * tmp = fl_get_input(the_buffer);
307 string str = tmp ? tmp : "";
311 fl_set_input(the_buffer, str.c_str());
315 void XMiniBuffer::set_input(string const & str)
317 fl_set_input(the_buffer, str.c_str());