X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FXMiniBuffer.C;h=a6b228aa998282939e94cb690ed968520edf594f;hb=37e82a546392d43f787826b85481a11f2a27af15;hp=e032ccc8ef31aca470295924af4f36936b9eb897;hpb=c93bea24494aca57388bd1982b3920b90c2f359c;p=lyx.git diff --git a/src/frontends/xforms/XMiniBuffer.C b/src/frontends/xforms/XMiniBuffer.C index e032ccc8ef..a6b228aa99 100644 --- a/src/frontends/xforms/XMiniBuffer.C +++ b/src/frontends/xforms/XMiniBuffer.C @@ -1,52 +1,69 @@ -// -*- C++ -*- /** * \file XMiniBuffer.C * 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 + * Full author contact details are available in file CREDITS. */ #include #include "XMiniBuffer.h" -#include "DropDown.h" -#include "ControlCommandBuffer.h" +#include "XFormsView.h" -#include "gettext.h" +#include "freebrowser.h" +#include "xforms_helpers.h" + +#include "controllers/ControlCommandBuffer.h" #include "frontends/Timeout.h" -#include +#include "gettext.h" -#include +#include -#ifndef CXX_GLOBAL_CSTD -using std::isprint; -#endif +using boost::shared_ptr; -using std::endl; using std::vector; +using std::string; +namespace lyx { +namespace frontend { 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); +FL_OBJECT * create_input_box(void * parent, int type); + +FL_FREEBROWSER * create_freebrowser(void * parent); } // namespace anon -XMiniBuffer::XMiniBuffer(ControlCommandBuffer & control, - FL_Coord x, FL_Coord y, FL_Coord h, FL_Coord w) +XMiniBuffer::XMiniBuffer(XFormsView & owner, + ControlCommandBuffer & control) : controller_(control), info_shown_(false) { - input_ = create_input_box(this, FL_NORMAL_INPUT, x, y, h, w); + input_ = create_input_box(this, FL_NORMAL_INPUT); + freebrowser_.reset(create_freebrowser(this), fl_free_freebrowser); + + // The minibuffer is 25 pixels high and is embedded inside a + // 2 pixel deep frame. + int const air = 2; + + BoxList & boxlist = owner.getBox(XFormsView::Bottom)->children(); + minibuffer_ = boxlist.push_back(Box(0,0)); + shared_ptr center = embed(input_, minibuffer_->children(), widgets_, air); + center->set(Box::Expand); + center->setMinimumDimensions(0, 25); + + owner.metricsUpdated.connect(boost::bind(&WidgetMap::updateMetrics, + &widgets_)); + info_timer_.reset(new Timeout(1500)); idle_timer_.reset(new Timeout(6000)); info_con = info_timer_->timeout.connect(boost::bind(&XMiniBuffer::info_timeout, this)); @@ -61,12 +78,34 @@ XMiniBuffer::~XMiniBuffer() {} -// thanks for nothing, xforms (recursive creation not allowed) -void XMiniBuffer::dd_init() +void XMiniBuffer::freebrowserCB(int action) { - dropdown_.reset(new DropDown(input_)); - 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 + ' '); + } + } } @@ -139,6 +178,18 @@ int XMiniBuffer::peek_event(FL_OBJECT * ob, int event, set_input(new_input); + // Fill freebrowser_'s browser with the list of + // available completions + FL_OBJECT * browser = freebrowser_->browser; + fl_clear_browser(browser); + vector::const_iterator cit = comp.begin(); + vector::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(input_), &x, &y, &w, &h); @@ -148,7 +199,9 @@ int XMiniBuffer::peek_event(FL_OBJECT * ob, int event, x += air; y += h - (input_->h + air); w = input_->w; - dropdown_->select(comp, x, y, w); + h = 100; + + fl_show_freebrowser(freebrowser_.get(), x, y-h, w, h); return 1; } case 27: @@ -242,30 +295,6 @@ void XMiniBuffer::redraw() } -void XMiniBuffer::append_char(char c) -{ - if (!c || !isprint(c)) - return; - - char const * tmp = fl_get_input(input_); - string str = tmp ? tmp : ""; - - str += c; - - fl_set_input(input_, str.c_str()); -} - - -void XMiniBuffer::set_complete_input(string const & str) -{ - if (!str.empty()) { - // add a space so the user can type - // an argument immediately - set_input(str + ' '); - } -} - - void XMiniBuffer::message(string const & str) { if (!isEditingMode()) @@ -291,10 +320,20 @@ int C_XMiniBuffer_peek_event(FL_OBJECT * ob, int event, } -FL_OBJECT * create_input_box(void * parent, int type, - FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h) +extern "C" +void C_freebrowserCB(FL_FREEBROWSER * fb, int action) +{ + if (!fb || !fb->parent) + return; + + XMiniBuffer * ptr = static_cast(fb->parent); + ptr->freebrowserCB(action); +} + + +FL_OBJECT * create_input_box(void * parent, int type) { - FL_OBJECT * obj = fl_add_input(type, x, y, w, h, ""); + FL_OBJECT * obj = fl_add_input(type, 0, 0, 0, 0, ""); fl_set_object_boxtype(obj, FL_DOWN_BOX); fl_set_object_resize(obj, FL_RESIZE_ALL); fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity); @@ -309,4 +348,16 @@ FL_OBJECT * create_input_box(void * parent, int type, return obj; } + +FL_FREEBROWSER * create_freebrowser(void * parent) +{ + FL_FREEBROWSER * fb = fl_create_freebrowser(parent); + fb->want_printable = 1; + fb->callback = C_freebrowserCB; + return fb; +} + } // namespace anon + +} // namespace frontend +} // namespace lyx