mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
John's completion stuff
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2965 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
38aac55887
commit
9c4d5b9889
@ -1,3 +1,9 @@
|
||||
2001-11-03 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* minibuffer.h:
|
||||
* minibuffer.C:
|
||||
* XFormsView.C: add support for drop-down completion
|
||||
|
||||
2001-11-03 Dekel Tsur <dekelts@tau.ac.il>
|
||||
|
||||
* paragraph.C (TeXOnePar): Correct placement of \selectlanguage
|
||||
|
@ -190,6 +190,8 @@ void XFormsView::create_form_form_main(int width, int height)
|
||||
fl_set_form_minsize(form_, 50, 50);
|
||||
|
||||
fl_end_form();
|
||||
|
||||
minibuffer->dd_init();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,3 +1,13 @@
|
||||
2001-11-03 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* Makefile.am:
|
||||
* DropDown.h:
|
||||
* DropDown.C: drop-down completion
|
||||
|
||||
2001-11-04 John Levon <moz@compsoc.man.ac.uk>
|
||||
|
||||
* forms/form_graphics.fd: change clashing shortcut
|
||||
|
||||
2001-10-24 Juergen Vigna <jug@sad.it>
|
||||
|
||||
* FormTabular.C: changed calls for footer/headers of longtabulars.
|
||||
|
134
src/frontends/xforms/DropDown.C
Normal file
134
src/frontends/xforms/DropDown.C
Normal file
@ -0,0 +1,134 @@
|
||||
/**
|
||||
* \file DropDown.C
|
||||
* Copyright 2001 the LyX Team
|
||||
* Read the file COPYING
|
||||
*
|
||||
* \author John Levon <moz@compsoc.man.ac.uk>
|
||||
*/
|
||||
|
||||
#include "DropDown.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
extern "C" void C_DropDownCompletedCB(FL_OBJECT * ob, long)
|
||||
{
|
||||
DropDown * d = static_cast<DropDown*>(ob->form->u_vdata);
|
||||
d->completed();
|
||||
}
|
||||
|
||||
|
||||
extern "C" int C_DropDownPeekEventCB(FL_FORM * form, void *xev)
|
||||
{
|
||||
DropDown * d = static_cast<DropDown*>(form->u_vdata);
|
||||
return d->peek(static_cast<XEvent*>(xev));
|
||||
}
|
||||
|
||||
|
||||
DropDown::DropDown(LyXView * lv, FL_OBJECT * ob)
|
||||
: lv_(lv)
|
||||
{
|
||||
form_ = fl_bgn_form(FL_NO_BOX, ob->w, 100);
|
||||
fl_add_box(FL_UP_BOX, 0, 0, ob->w, 100, "");
|
||||
browser_ = fl_add_browser(FL_SELECT_BROWSER, 0, 0, ob->w, 100, "");
|
||||
form_->u_vdata = this;
|
||||
fl_set_browser_dblclick_callback(browser_, C_DropDownCompletedCB, 0);
|
||||
fl_register_raw_callback(form_, KeyPressMask|ButtonPressMask, C_DropDownPeekEventCB);
|
||||
fl_end_form();
|
||||
}
|
||||
|
||||
|
||||
DropDown::~DropDown()
|
||||
{
|
||||
if (form_->visible)
|
||||
fl_hide_form(form_);
|
||||
fl_free_form(form_);
|
||||
}
|
||||
|
||||
|
||||
void DropDown::select(std::vector<string> const & choices, int x, int y, int w)
|
||||
{
|
||||
fl_set_form_geometry(form_, x, y, w, 100);
|
||||
fl_clear_browser(browser_);
|
||||
for (std::vector<string>::const_iterator cit = choices.begin();
|
||||
cit != choices.end(); ++cit) {
|
||||
fl_add_browser_line(browser_, cit->c_str());
|
||||
}
|
||||
fl_show_form(form_, FL_PLACE_POSITION, FL_NOBORDER, "");
|
||||
XGrabPointer(fl_get_display(), form_->window, false,
|
||||
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
||||
GrabModeAsync, GrabModeAsync, 0, 0, 0);
|
||||
XFlush(fl_get_display());
|
||||
}
|
||||
|
||||
|
||||
void DropDown::line_up()
|
||||
{
|
||||
if (fl_get_browser(browser_) > 1)
|
||||
fl_select_browser_line(browser_, fl_get_browser(browser_) - 1);
|
||||
if (fl_get_browser(browser_) >= fl_get_browser_topline(browser_) +
|
||||
fl_get_browser_screenlines(browser_))
|
||||
fl_set_browser_topline(browser_, fl_get_browser(browser_)
|
||||
- fl_get_browser_screenlines(browser_) + 1);
|
||||
if (fl_get_browser(browser_) < fl_get_browser_topline(browser_))
|
||||
fl_set_browser_topline(browser_, fl_get_browser(browser_));
|
||||
}
|
||||
|
||||
|
||||
void DropDown::line_down()
|
||||
{
|
||||
if (fl_get_browser(browser_) < fl_get_browser_maxline(browser_))
|
||||
fl_select_browser_line(browser_, fl_get_browser(browser_) + 1);
|
||||
if (fl_get_browser(browser_) >= fl_get_browser_topline(browser_) +
|
||||
fl_get_browser_screenlines(browser_))
|
||||
fl_set_browser_topline(browser_, fl_get_browser(browser_)
|
||||
- fl_get_browser_screenlines(browser_) + 1);
|
||||
if (fl_get_browser(browser_) < fl_get_browser_topline(browser_))
|
||||
fl_set_browser_topline(browser_, fl_get_browser(browser_));
|
||||
}
|
||||
|
||||
|
||||
int DropDown::peek(XEvent * xev)
|
||||
{
|
||||
int x,y;
|
||||
unsigned int keymask;
|
||||
|
||||
fl_get_mouse(&x, &y, &keymask);
|
||||
|
||||
if (xev->type == ButtonPress) {
|
||||
if (!(x >= form_->x && x <= (form_->x + form_->w) &&
|
||||
y >= form_->y && y << (form_->y + form_->h))) {
|
||||
fl_hide_form(form_);
|
||||
return 1;
|
||||
}
|
||||
} else if (xev->type == KeyPress) {
|
||||
char s_r[10]; s_r[9] = '\0';
|
||||
KeySym keysym_return;
|
||||
XLookupString(&xev->xkey, s_r, 10, &keysym_return, 0);
|
||||
switch (keysym_return) {
|
||||
case XK_Down:
|
||||
line_down();
|
||||
return 1;
|
||||
case XK_Up:
|
||||
line_up();
|
||||
return 1;
|
||||
case XK_Return:
|
||||
completed();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void DropDown::completed()
|
||||
{
|
||||
string selection;
|
||||
int i = fl_get_browser(browser_);
|
||||
if (i == -1)
|
||||
selection = "";
|
||||
else
|
||||
selection = fl_get_browser_line(browser_, i);
|
||||
fl_hide_form(form_);
|
||||
|
||||
result.emit(selection);
|
||||
}
|
56
src/frontends/xforms/DropDown.h
Normal file
56
src/frontends/xforms/DropDown.h
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* \file DropDown.h
|
||||
* Copyright 2001 the LyX Team
|
||||
* Read the file COPYING
|
||||
*
|
||||
* \author John Levon <moz@compsoc.man.ac.uk>
|
||||
*/
|
||||
|
||||
#ifndef DROPDOWN_H
|
||||
#define DROPDOWN_H
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "LyXView.h"
|
||||
#include <sigc++/signal_system.h>
|
||||
#include "LString.h"
|
||||
#include FORMS_H_LOCATION
|
||||
#include <vector>
|
||||
|
||||
class DropDown {
|
||||
public:
|
||||
/// constructor
|
||||
DropDown(LyXView * lv, FL_OBJECT * ob);
|
||||
/// destructor
|
||||
~DropDown();
|
||||
|
||||
/// choose from the list of choices.
|
||||
void select(std::vector<string> const & choices, int x, int y, int w);
|
||||
|
||||
/// user completed action
|
||||
void completed();
|
||||
|
||||
/// signal for completion
|
||||
SigC::Signal1<void, string const &> result;
|
||||
|
||||
/// X event
|
||||
int peek(XEvent *);
|
||||
|
||||
private:
|
||||
/// move up a browser line
|
||||
void line_up();
|
||||
|
||||
/// move down a browser line
|
||||
void line_down();
|
||||
|
||||
/// owning lyxview
|
||||
LyXView * lv_;
|
||||
|
||||
/// our form
|
||||
FL_FORM * form_;
|
||||
|
||||
/// the browser
|
||||
FL_OBJECT * browser_;
|
||||
};
|
||||
|
||||
#endif // DROPDOWN_H
|
@ -20,6 +20,8 @@ libxforms_la_SOURCES = \
|
||||
combox.C \
|
||||
combox.h \
|
||||
Dialogs.C \
|
||||
DropDown.h \
|
||||
DropDown.C \
|
||||
FileDialog.C \
|
||||
FormFiledialog.h \
|
||||
FormFiledialog.C \
|
||||
|
@ -72,7 +72,7 @@ FD_form_graphics * FormGraphics::build_graphics()
|
||||
fl_set_object_lalign(obj, FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
|
||||
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 270, 70, 200, 70, _("Rotation"));
|
||||
{
|
||||
char const * const dummy = N_("Angle|#A");
|
||||
char const * const dummy = N_("Angle|#n");
|
||||
fdui->input_rotate_angle = obj = fl_add_input(FL_INT_INPUT, 340, 90, 70, 30, idex(_(dummy)));
|
||||
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ alignment: FL_ALIGN_LEFT
|
||||
style: FL_NORMAL_STYLE
|
||||
size: FL_DEFAULT_SIZE
|
||||
lcol: FL_BLACK
|
||||
label: Angle|#A
|
||||
label: Angle|#n
|
||||
shortcut:
|
||||
resize: FL_RESIZE_ALL
|
||||
gravity: FL_NoGravity FL_NoGravity
|
||||
|
@ -18,6 +18,9 @@
|
||||
#pragma implementation
|
||||
#endif
|
||||
|
||||
// FIXME: temporary
|
||||
#include "frontends/xforms/DropDown.h"
|
||||
|
||||
#include "minibuffer.h"
|
||||
|
||||
#include "support/lyxalgo.h"
|
||||
@ -62,7 +65,21 @@ MiniBuffer::MiniBuffer(LyXView * o, FL_Coord x, FL_Coord y,
|
||||
deactivate();
|
||||
}
|
||||
|
||||
|
||||
// thanks for nothing, xforms (recursive creation not allowed)
|
||||
void MiniBuffer::dd_init()
|
||||
{
|
||||
dropdown_ = new DropDown(owner_, the_buffer);
|
||||
dropdown_->result.connect(slot(this, &MiniBuffer::set_input));
|
||||
}
|
||||
|
||||
|
||||
MiniBuffer::~MiniBuffer()
|
||||
{
|
||||
delete dropdown_;
|
||||
}
|
||||
|
||||
|
||||
void MiniBuffer::stored_slot()
|
||||
{
|
||||
if (stored_) {
|
||||
@ -158,10 +175,12 @@ int MiniBuffer::peek_event(FL_OBJECT * ob, int event, int key)
|
||||
}
|
||||
set_input(test);
|
||||
|
||||
// How should the possible matches
|
||||
// be visualized?
|
||||
std::copy(comp.begin(), comp.end(),
|
||||
std::ostream_iterator<string>(std::cerr, "\n"));
|
||||
int x,y,w,h;
|
||||
fl_get_wingeometry(fl_get_real_object_window(the_buffer),
|
||||
&x, &y, &w, &h);
|
||||
|
||||
// asynchronous completion
|
||||
dropdown_->select(comp, x, y + h, w);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#endif
|
||||
|
||||
class LyXView;
|
||||
class DropDown;
|
||||
|
||||
///
|
||||
class MiniBuffer : public SigC::Object {
|
||||
@ -27,6 +28,12 @@ public:
|
||||
MiniBuffer(LyXView * o,
|
||||
FL_Coord x, FL_Coord y, FL_Coord h, FL_Coord w);
|
||||
|
||||
/// destructor
|
||||
~MiniBuffer();
|
||||
|
||||
/// create drop down
|
||||
void dd_init();
|
||||
|
||||
///
|
||||
void addSet(string const &,
|
||||
string const & = string());
|
||||
@ -87,6 +94,8 @@ private:
|
||||
Timeout timer;
|
||||
///
|
||||
Timeout stored_timer;
|
||||
/// the dropdown menu
|
||||
DropDown * dropdown_;
|
||||
///
|
||||
FL_OBJECT * the_buffer;
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user