From 45933fac0c917f91423a805c2d18e045823762d4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Thu, 26 Oct 2000 00:07:20 +0000 Subject: [PATCH] cleanup minibuffer and enhance Timeout a bit git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1159 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Timeout.C | 8 +++--- src/Timeout.h | 8 +++--- src/minibuffer.C | 66 +++++++++++++++++++++++++----------------------- src/minibuffer.h | 27 ++++++++++++-------- 4 files changed, 61 insertions(+), 48 deletions(-) diff --git a/src/Timeout.C b/src/Timeout.C index 543d8d2924..5bce1c404b 100644 --- a/src/Timeout.C +++ b/src/Timeout.C @@ -36,7 +36,7 @@ Timeout::Timeout() {} -Timeout::Timeout(int msec, Type t) +Timeout::Timeout(unsigned int msec, Type t) : type(t), timeout_ms(msec), timeout_id(-1) {} @@ -81,13 +81,15 @@ void Timeout::emit() } -void Timeout::setType(Type t) +Timeout & Timeout::setType(Type t) { type = t; + return *this; } -void Timeout::setTimeout(int msec) +Timeout & Timeout::setTimeout(unsigned int msec) { timeout_ms = msec; + return *this; } diff --git a/src/Timeout.h b/src/Timeout.h index 264cef33ef..9cecc49d7a 100644 --- a/src/Timeout.h +++ b/src/Timeout.h @@ -40,7 +40,7 @@ public: /// Timeout(); /// - Timeout(int msec, Type = ONETIME); + Timeout(unsigned int msec, Type = ONETIME); /// ~Timeout(); /// @@ -54,14 +54,14 @@ public: /// void emit(); /// - void setType(Type t); + Timeout & setType(Type t); /// - void setTimeout(int msec); + Timeout & setTimeout(unsigned int msec); private: /// Type type; /// - int timeout_ms; + unsigned int timeout_ms; /// int timeout_id; }; diff --git a/src/minibuffer.C b/src/minibuffer.C index c6da1b797e..01152a1b33 100644 --- a/src/minibuffer.C +++ b/src/minibuffer.C @@ -31,8 +31,8 @@ using std::endl; extern bool keyseqUncomplete(); -extern string keyseqOptions(int l= 190); -extern string keyseqStr(int l= 190); +extern string keyseqOptions(int l = 190); +extern string keyseqStr(int l = 190); extern LyXAction lyxaction; MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y, @@ -43,18 +43,9 @@ MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y, shows_no_match = true; history_idx = history_cnt = 0; add(FL_NORMAL_INPUT, x, y, h, w); + timer.timeout.connect(slot(this, &MiniBuffer::Init)); } -void MiniBuffer::TimerCB(FL_OBJECT * ob, long) -{ - MiniBuffer * obj = static_cast(ob->u_vdata); - obj->Init(); -} - -extern "C" void C_MiniBuffer_TimerCB(FL_OBJECT * ob, long data) -{ - MiniBuffer::TimerCB(ob, data); -} void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long) { @@ -77,19 +68,23 @@ void MiniBuffer::ExecutingCB(FL_OBJECT * ob, long) return ; } -extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long data) + +extern "C" void C_MiniBuffer_ExecutingCB(FL_OBJECT * ob, long) { - MiniBuffer::TimerCB(ob, data); + MiniBuffer * obj = static_cast(ob->u_vdata); + obj->Init(); } + // This is not as dirty as it seems, the hidden buttons removed by this // function were just kludges for an uncomplete keyboard callback (ale) int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord, int key, void */*xev*/) { MiniBuffer * mini = static_cast(ob->u_vdata); - - if (event == FL_KEYBOARD){ + + switch (event) { + case FL_KEYBOARD: switch (key) { case XK_Down: mini->history_idx++; @@ -106,7 +101,7 @@ int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord, case XK_Tab: { // complete or increment the command - string s = lyxaction.getApproxFuncName(fl_get_input(ob)); + string s(lyxaction.getApproxFuncName(fl_get_input(ob))); if (!s.empty()) fl_set_input(ob, s.c_str()); return 1; @@ -126,15 +121,23 @@ int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord, default: return 0; } - } else if (event == FL_PUSH) { + case FL_PUSH: // This actually clears the buffer. mini->PrepareForCommand(); return 1; - } + case FL_DRAW: + lyxerr << "Minibuffer event: DRAW" << endl; + break; + default: + lyxerr << "Unhandled minibuffer event!" << endl; + break; + } + return 0; } + extern "C" int C_MiniBuffer_peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord, int key, void * xev) @@ -168,13 +171,9 @@ FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y, fl_set_object_prehandler(obj, C_MiniBuffer_peek_event); obj->u_vdata = this; obj->wantkey = FL_KEY_TAB; - - // timer - timer = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "Timer"); - fl_set_object_callback(timer, C_MiniBuffer_TimerCB, 0); - timer->u_vdata = this; - fl_set_input(the_buffer, text.c_str()); + fl_set_input(the_buffer, text.c_str()); + return obj; } @@ -182,10 +181,13 @@ FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y, // Added optional arg `delay_secs', defaults to 4. //When 0, no timeout is done. RVDK_PATCH_5 void MiniBuffer::Set(string const& s1, string const& s2, - string const& s3, int delay_secs) + string const& s3, unsigned int delay_secs) { - setTimer(delay_secs); - + if (delay_secs) + timer.setTimeout(delay_secs * 1000).restart(); + else + timer.stop(); + string ntext = strip(s1 + ' ' + s2 + ' ' + s3); if (!the_buffer->focus) { @@ -241,7 +243,9 @@ void MiniBuffer::Init() fl_set_input(the_buffer, text.c_str()); - setTimer(0); + + timer.stop(); + XFlush(fl_get_display()); } @@ -262,15 +266,15 @@ void MiniBuffer::Reset() } } + void MiniBuffer::Activate() { fl_activate_object(the_buffer); fl_redraw_object(the_buffer); } + void MiniBuffer::Deactivate() { fl_deactivate_object(the_buffer); } - - diff --git a/src/minibuffer.h b/src/minibuffer.h index c8495b8f3a..9bdf1c4600 100644 --- a/src/minibuffer.h +++ b/src/minibuffer.h @@ -5,6 +5,7 @@ #include FORMS_H_LOCATION #include "LString.h" #include "gettext.h" +#include "Timeout.h" #ifdef __GNUG__ #pragma interface @@ -12,8 +13,12 @@ class LyXView; +#ifdef SIGC_CXX_NAMESPACES +using SigC::Object; +#endif + /// -class MiniBuffer { +class MiniBuffer : public Object{ public: /// MiniBuffer(LyXView * o, @@ -21,15 +26,17 @@ public: /// bool shows_no_match; + /// - void setTimer(int a) { - fl_set_timer(timer, a); + void setTimer(unsigned int a) { + timer.setTimeout(a * 1000); } + /// void Set(string const & = string(), string const & = string(), string const & = string(), - int delay_secs= 6); + unsigned int delay_secs = 6); /// string const GetText() const { return text; } /// @@ -47,9 +54,7 @@ public: /// void Deactivate(); /// - static void ExecutingCB(FL_OBJECT *ob, long); - /// - static void TimerCB(FL_OBJECT *ob, long); + static void ExecutingCB(FL_OBJECT * ob, long); /// static int peek_event(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *); @@ -62,8 +67,8 @@ private: string text_stored; /// FL_OBJECT * add(int, FL_Coord, FL_Coord, FL_Coord, FL_Coord); - /// - FL_OBJECT * timer; + /// + Timeout timer; /// FL_OBJECT * the_buffer; /// @@ -87,6 +92,8 @@ private: history_idx = history_cnt; } /// - string const getHistory() const { return history[history_idx % MAX_HISTORY]; } + string const getHistory() const { + return history[history_idx % MAX_HISTORY]; + } }; #endif -- 2.39.5