-// -*- C++ -*-
/**
* \file XMiniBuffer.C
- * Copyright 1995-2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
* \author Lars
- * \author Asger and Juergen
+ * \author Asger and Jürgen
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
+#include "XMiniBuffer.h"
+
+#include "freebrowser.h"
+#include "xforms_helpers.h"
+
+#include "controllers/ControlCommandBuffer.h"
-#include "frontends/xforms/DropDown.h"
-#include "frontends/xforms/XFormsView.h"
-#include "frontends/controllers/ControlCommandBuffer.h"
#include "frontends/Timeout.h"
-#include "XMiniBuffer.h"
#include "gettext.h"
-#include "debug.h"
-#include "bufferview_funcs.h"
#include <boost/bind.hpp>
-#include <vector>
-
-#ifndef CXX_GLOBAL_CSTD
-using std::isprint;
-#endif
-using std::endl;
using std::vector;
+using std::string;
+
+
+namespace {
+/// This creates the input widget for the minibuffer
+FL_OBJECT * create_input_box(void * parent, int type,
+ FL_Coord, FL_Coord, FL_Coord, FL_Coord);
-XMiniBuffer::XMiniBuffer(XFormsView * v, ControlCommandBuffer & control,
- FL_Coord x, FL_Coord y, FL_Coord h, FL_Coord w)
- : controller_(control), view_(v),
- info_shown_(false)
+FL_FREEBROWSER * create_freebrowser(void * parent);
+
+} // namespace anon
+
+
+XMiniBuffer::XMiniBuffer(ControlCommandBuffer & control,
+ FL_Coord x, FL_Coord y, FL_Coord h, FL_Coord w)
+ : controller_(control),
+ info_shown_(false)
{
- input_obj_ = create_input_box(FL_NORMAL_INPUT, x, y, h, w);
+ input_ = create_input_box(this, FL_NORMAL_INPUT, x, y, h, w);
+ freebrowser_.reset(create_freebrowser(this), fl_free_freebrowser);
+
info_timer_.reset(new Timeout(1500));
idle_timer_.reset(new Timeout(6000));
info_con = info_timer_->timeout.connect(boost::bind(&XMiniBuffer::info_timeout, this));
{}
-// thanks for nothing, xforms (recursive creation not allowed)
-void XMiniBuffer::dd_init()
+void XMiniBuffer::freebrowserCB(int action)
{
- dropdown_.reset(new DropDown(the_buffer_));
- result_con = dropdown_->result.connect(boost::bind(&XMiniBuffer::set_complete_input, this, _1));
- keypress_con = dropdown_->keypress.connect(boost::bind(&XMiniBuffer::append_char, this, _1));
+ if (action < 0 || action > 1)
+ // unrecognized action
+ return;
+
+ if (action == 0)
+ // The freebrowser has been hidden
+ return;
+
+ if (freebrowser_->last_printable) {
+ // Append this char to the current input contents
+ string input = getString(input_);
+ input += freebrowser_->last_printable;
+ fl_set_input(input_, input.c_str());
+
+ } else {
+ // Fill the input widget with the selected
+ // browser entry.
+ FL_OBJECT * browser = freebrowser_->browser;
+ string const str = getString(browser);
+
+ if (!str.empty()) {
+ // add a space so the user can type
+ // an argument immediately
+ set_input(str + ' ');
+ }
+ }
}
if (comp.empty()) {
set_input(new_input);
- show_info(("[only completion]"), new_input + " ");
+ show_info(_("[only completion]"), new_input + ' ');
break;
}
set_input(new_input);
+ // Fill freebrowser_'s browser with the list of
+ // available completions
+ FL_OBJECT * browser = freebrowser_->browser;
+ fl_clear_browser(browser);
+ vector<string>::const_iterator cit = comp.begin();
+ vector<string>::const_iterator end = comp.end();
+ for (; cit != end; ++cit) {
+ fl_add_browser_line(browser, cit->c_str());
+ }
+ fl_select_browser_line(browser, 1);
+
+ // Set the position of the freebrowser and display it.
int x,y,w,h;
- fl_get_wingeometry(fl_get_real_object_window(the_buffer_),
+ fl_get_wingeometry(fl_get_real_object_window(input_),
&x, &y, &w, &h);
// asynchronous completion
- int const air = the_buffer_->x;
+ int const air = input_->x;
x += air;
- y += h - (the_buffer_->h + air);
- w = the_buffer_->w;
- dropdown_->select(comp, x, y, w);
+ y += h - (input_->h + air);
+ w = input_->w;
+ h = 100;
+
+ fl_show_freebrowser(freebrowser_.get(), x, y-h, w, h);
return 1;
}
case 27:
}
-extern "C" {
-
- static
- int C_XMiniBuffer_peek_event(FL_OBJECT * ob, int event,
- FL_Coord, FL_Coord,
- int key, void * xev)
- {
- XMiniBuffer * mini = static_cast<XMiniBuffer*>(ob->u_vdata);
- return mini->peek_event(ob, event, key,
- static_cast<XEvent *>(xev));
- }
-}
-
-
-FL_OBJECT * XMiniBuffer::create_input_box(int type, FL_Coord x, FL_Coord y,
- FL_Coord w, FL_Coord h)
-{
- FL_OBJECT * obj;
-
- the_buffer_ = obj = fl_add_input(type, x, y, w, h, "");
- fl_set_object_boxtype(obj, FL_DOWN_BOX);
- fl_set_object_resize(obj, FL_RESIZE_ALL);
- fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
- fl_set_object_color(obj, FL_MCOL, FL_MCOL);
- fl_set_object_lsize(obj, FL_NORMAL_SIZE);
-
- // To intercept Up, Down, Table for history
- fl_set_object_prehandler(obj, C_XMiniBuffer_peek_event);
- obj->u_vdata = this;
- obj->wantkey = FL_KEY_TAB;
-
- return obj;
-}
-
-
void XMiniBuffer::freeze()
{
// we must prevent peek_event, or we get an unfocus() when the
// containing form gets destroyed
- fl_set_object_prehandler(input_obj_, 0);
+ fl_set_object_prehandler(input_, 0);
}
stored_input_ = input;
info_shown_ = true;
if (append)
- set_input(input + " " + info);
+ set_input(input + ' ' + info);
else
set_input(info);
info_timer_->start();
void XMiniBuffer::idle_timeout()
{
- set_input(currentState(view_->view().get()));
+ set_input(controller_.getCurrentState());
}
bool XMiniBuffer::isEditingMode() const
{
- return the_buffer_->focus;
+ return input_->focus;
}
{
set_input("");
if (!on) {
- fl_activate_object(the_buffer_);
- fl_set_focus_object(view_->getForm(), the_buffer_);
+ fl_activate_object(input_);
+ fl_set_focus_object(input_->form, input_);
redraw();
idle_timer_->stop();
} else {
if (isEditingMode()) {
// focus back to the workarea
- fl_set_focus_object(view_->getForm(), 0);
+ fl_set_focus_object(input_->form, 0);
idle_timer_->start();
}
}
void XMiniBuffer::redraw()
{
- fl_redraw_object(the_buffer_);
+ fl_redraw_object(input_);
XFlush(fl_display);
}
-void XMiniBuffer::append_char(char c)
+void XMiniBuffer::message(string const & str)
{
- if (!c || !isprint(c))
- return;
+ if (!isEditingMode())
+ set_input(str);
+}
- char const * tmp = fl_get_input(the_buffer_);
- string str = tmp ? tmp : "";
- str += c;
+void XMiniBuffer::set_input(string const & str)
+{
+ fl_set_input(input_, str.c_str());
+}
+
- fl_set_input(the_buffer_, str.c_str());
+namespace {
+
+extern "C"
+int C_XMiniBuffer_peek_event(FL_OBJECT * ob, int event,
+ FL_Coord, FL_Coord,
+ int key, void * xev)
+{
+ XMiniBuffer * mini = static_cast<XMiniBuffer*>(ob->u_vdata);
+ return mini->peek_event(ob, event, key, static_cast<XEvent *>(xev));
}
-void XMiniBuffer::set_complete_input(string const & str)
+extern "C"
+void C_freebrowserCB(FL_FREEBROWSER * fb, int action)
{
- if (!str.empty()) {
- // add a space so the user can type
- // an argument immediately
- set_input(str + " ");
- }
+ if (!fb || !fb->parent)
+ return;
+
+ XMiniBuffer * ptr = static_cast<XMiniBuffer *>(fb->parent);
+ ptr->freebrowserCB(action);
}
-void XMiniBuffer::message(string const & str)
+FL_OBJECT * create_input_box(void * parent, int type,
+ FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h)
{
- if (!isEditingMode())
- set_input(str);
+ FL_OBJECT * obj = fl_add_input(type, x, y, w, h, "");
+ fl_set_object_boxtype(obj, FL_DOWN_BOX);
+ fl_set_object_resize(obj, FL_RESIZE_ALL);
+ fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
+ fl_set_object_color(obj, FL_MCOL, FL_MCOL);
+ fl_set_object_lsize(obj, FL_NORMAL_SIZE);
+
+ // To intercept Up, Down, Table for history
+ fl_set_object_prehandler(obj, C_XMiniBuffer_peek_event);
+ obj->u_vdata = parent;
+ obj->wantkey = FL_KEY_TAB;
+
+ return obj;
}
-void XMiniBuffer::set_input(string const & str)
+FL_FREEBROWSER * create_freebrowser(void * parent)
{
- fl_set_input(the_buffer_, str.c_str());
+ FL_FREEBROWSER * fb = fl_create_freebrowser(parent);
+ fb->want_printable = 1;
+ fb->callback = C_freebrowserCB;
+ return fb;
}
+
+} // namespace anon