X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FXMiniBuffer.C;h=a6b228aa998282939e94cb690ed968520edf594f;hb=37e82a546392d43f787826b85481a11f2a27af15;hp=5b72dc0605b4ab8be8869024ec80514403ac1c0a;hpb=92c15c86a5fa16004f7a6a6eb77eed1f0af5526d;p=lyx.git diff --git a/src/frontends/xforms/XMiniBuffer.C b/src/frontends/xforms/XMiniBuffer.C index 5b72dc0605..a6b228aa99 100644 --- a/src/frontends/xforms/XMiniBuffer.C +++ b/src/frontends/xforms/XMiniBuffer.C @@ -1,47 +1,69 @@ -// -*- 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 -#ifdef __GNUG__ -#pragma implementation -#endif +#include "XMiniBuffer.h" +#include "XFormsView.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 -#include +using boost::shared_ptr; -#ifndef CXX_GLOBAL_CSTD -using std::isprint; -#endif - -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_FREEBROWSER * create_freebrowser(void * parent); -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) +} // namespace anon + + +XMiniBuffer::XMiniBuffer(XFormsView & owner, + ControlCommandBuffer & control) + : 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); + 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)); @@ -56,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(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 + ' '); + } + } } @@ -128,22 +172,36 @@ int XMiniBuffer::peek_event(FL_OBJECT * ob, int event, 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::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(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: @@ -173,46 +231,11 @@ int XMiniBuffer::peek_event(FL_OBJECT * ob, int event, } -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(ob->u_vdata); - return mini->peek_event(ob, event, key, - static_cast(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); } @@ -221,7 +244,7 @@ void XMiniBuffer::show_info(string const & info, string const & input, bool appe stored_input_ = input; info_shown_ = true; if (append) - set_input(input + " " + info); + set_input(input + ' ' + info); else set_input(info); info_timer_->start(); @@ -230,7 +253,7 @@ void XMiniBuffer::show_info(string const & info, string const & input, bool appe void XMiniBuffer::idle_timeout() { - set_input(currentState(view_->view())); + set_input(controller_.getCurrentState()); } @@ -243,7 +266,7 @@ void XMiniBuffer::info_timeout() bool XMiniBuffer::isEditingMode() const { - return the_buffer_->focus; + return input_->focus; } @@ -251,14 +274,14 @@ void XMiniBuffer::messageMode(bool on) { 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(); } } @@ -267,43 +290,74 @@ void XMiniBuffer::messageMode(bool on) 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 (!isEditingMode()) + set_input(str); +} + + +void XMiniBuffer::set_input(string const & str) { - if (!c || !isprint(c)) - return; + fl_set_input(input_, str.c_str()); +} - char const * tmp = fl_get_input(the_buffer_); - string str = tmp ? tmp : ""; - str += c; +namespace { - fl_set_input(the_buffer_, str.c_str()); +extern "C" +int C_XMiniBuffer_peek_event(FL_OBJECT * ob, int event, + FL_Coord, FL_Coord, + int key, void * xev) +{ + XMiniBuffer * mini = static_cast(ob->u_vdata); + return mini->peek_event(ob, event, key, static_cast(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(fb->parent); + ptr->freebrowserCB(action); } -void XMiniBuffer::message(string const & str) +FL_OBJECT * create_input_box(void * parent, int type) { - if (!isEditingMode()) - set_input(str); + 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); + 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 + +} // namespace frontend +} // namespace lyx