cleanup minibuffer and enhance Timeout a bit

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1159 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2000-10-26 00:07:20 +00:00
parent d597ece5e7
commit 45933fac0c
4 changed files with 61 additions and 48 deletions

View File

@ -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;
}

View File

@ -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;
};

View File

@ -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<MiniBuffer*>(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,11 +68,14 @@ 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<MiniBuffer*>(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,
@ -89,7 +83,8 @@ int MiniBuffer::peek_event(FL_OBJECT * ob, int event, FL_Coord, FL_Coord,
{
MiniBuffer * mini = static_cast<MiniBuffer*>(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)
@ -169,10 +172,6 @@ FL_OBJECT * MiniBuffer::add(int type, FL_Coord x, FL_Coord y,
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());
return obj;
@ -182,9 +181,12 @@ 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);
@ -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);
}

View File

@ -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; }
///
@ -49,8 +56,6 @@ public:
///
static void ExecutingCB(FL_OBJECT * ob, long);
///
static void TimerCB(FL_OBJECT *ob, long);
///
static int peek_event(FL_OBJECT *, int, FL_Coord, FL_Coord,
int, void *);
private:
@ -63,7 +68,7 @@ private:
///
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