The mouse box patch for button-style insets

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7662 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Martin Vermeer 2003-09-04 14:02:05 +00:00
parent 4f8690cc21
commit 781e0ef62e
18 changed files with 115 additions and 31 deletions

View File

@ -1,3 +1,15 @@
2003-09-03 Martin Vermeer <martin.vermeer@hut.fi>
* LyXAction.C:
* box.[Ch]:
* lfuns.h:
* lyxfunc.C:
* text3.C: Restricts the mouse click functionality
of insets like bibtex, include, toc and floatlist to the visible
button, and allows the use of LFUN_INSET_SHOW_DIALOG to bring
up the dialogs. Cursor has to be in front of the inset (i.e.
start of row) for this to function.
2003-09-04 Lars Gullik Bjønnes <larsbj@lyx.org>
* bufferview_funcs.C (currentState): output paragraph position

View File

@ -322,6 +322,7 @@ void LyXAction::init()
{ LFUN_INSET_MODIFY, "", Noop },
{ LFUN_INSET_DIALOG_UPDATE, "", Noop },
{ LFUN_INSET_SETTINGS, "inset-settings", ReadOnly },
{ LFUN_INSET_DIALOG_SHOW, "inset-dialog-show", Noop },
{ LFUN_PARAGRAPH_APPLY, "paragraph-params-apply", Noop },
{ LFUN_PARAGRAPH_UPDATE, "", Noop },
{ LFUN_EXTERNAL_EDIT, "external-edit", Noop },

View File

@ -19,10 +19,13 @@
using std::ostream;
Box::Box(int x1_, int x2_, int y1_, int y2_) :
x1(x1_), x2(x2_), y1(y1_), y2(y2_)
Box::Box(int x1_, int x2_, int y1_, int y2_)
: x1(x1_), x2(x2_), y1(y1_), y2(y2_)
{}
Box::Box()
: x1(0), x2(0), y1(0), y2(0)
{}
bool Box::contains(int x, int y)
{

View File

@ -28,6 +28,8 @@ struct Box {
int y1;
int y2;
/// Zero-initialise the member variables.
Box();
/// Initialise the member variables.
Box(int x1_, int x2_, int y1_, int y2_);

View File

@ -1,3 +1,15 @@
2003-09-03 Martin Vermeer <martin.vermeer@hut.fi>
* insets/insetbibtex.[Ch]:
* insets/insetcommand.h:
* insets/insetfloatlist.[Ch]:
* insets/insetinclude.[Ch]:
* insets/insettoc.[Ch]: Restricts the mouse click functionality
of insets like bibtex, include, toc and floatlist to the visible
button, and allows the use of LFUN_INSET_SHOW_DIALOG to bring
up the dialogs. Cursor has to be in front of the inset (i.e.
start of row) for this to function.
2003-09-04 Angus Leeming <leeming@lyx.org>
* insetgraphics.C: #include "support/os.h"

View File

@ -58,7 +58,9 @@ std::auto_ptr<InsetBase> InsetBibtex::clone() const
void InsetBibtex::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetCommand::metrics(mi, dim);
center_indent_ = (mi.base.textwidth - dim.wid) / 2;
int center_indent = (mi.base.textwidth - dim.wid) / 2;
Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
button().setBox(b);
dim.wid = mi.base.textwidth;
dim_ = dim;
}
@ -66,7 +68,7 @@ void InsetBibtex::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetBibtex::draw(PainterInfo & pi, int x, int y) const
{
InsetCommand::draw(pi, x + center_indent_, y);
InsetCommand::draw(pi, x + button().box().x1, y);
}
@ -74,9 +76,13 @@ dispatch_result InsetBibtex::localDispatch(FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_EDIT:
case LFUN_INSET_DIALOG_SHOW:
InsetCommandMailer("bibtex", *this).showDialog(cmd.view());
return DISPATCHED;
case LFUN_MOUSE_RELEASE:
if (button().box().contains(cmd.x, cmd.y))
InsetCommandMailer("bibtex", *this).showDialog(cmd.view());
return DISPATCHED;
case LFUN_INSET_MODIFY: {
InsetCommandParams p;

View File

@ -50,9 +50,6 @@ public:
bool addDatabase(string const &);
///
bool delDatabase(string const &);
private:
///
mutable unsigned int center_indent_;
};
#endif // INSET_BIBTEX_H

View File

@ -66,7 +66,9 @@ public:
void setContents(string const & c) { p_.setContents(c); }
///
string const & getOptions() const { return p_.getOptions(); }
///
ButtonRenderer & button() const { return button_; }
protected:
///
string const getCommand() const { return p_.getCommand(); }

View File

@ -103,7 +103,10 @@ void InsetFloatList::read(Buffer const & buf, LyXLex & lex)
void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetCommand::metrics(mi, dim);
center_indent_ = (mi.base.textwidth - dim.wid) / 2;
int center_indent = (mi.base.textwidth - dim.wid) / 2;
Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
button().setBox(b);
dim.wid = mi.base.textwidth;
dim_ = dim;
}
@ -111,16 +114,22 @@ void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetFloatList::draw(PainterInfo & pi, int x, int y) const
{
InsetCommand::draw(pi, x + center_indent_, y);
InsetCommand::draw(pi, x + button().box().x1, y);
}
dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_EDIT:
case LFUN_MOUSE_RELEASE:
if (button().box().contains(cmd.x, cmd.y))
InsetCommandMailer("toc", *this).showDialog(cmd.view());
return DISPATCHED;
case LFUN_INSET_DIALOG_SHOW:
InsetCommandMailer("toc", *this).showDialog(cmd.view());
return DISPATCHED;
default:
return InsetCommand::localDispatch(cmd);
}

View File

@ -56,9 +56,6 @@ public:
int ascii(Buffer const &, std::ostream &, int linelen) const;
///
void validate(LaTeXFeatures & features) const;
private:
///
mutable unsigned int center_indent_;
};
#endif

View File

@ -148,7 +148,11 @@ dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
return DISPATCHED;
case LFUN_MOUSE_RELEASE:
case LFUN_INSET_EDIT:
if (button_.box().contains(cmd.x, cmd.y))
InsetIncludeMailer(*this).showDialog(cmd.view());
return DISPATCHED;
case LFUN_INSET_DIALOG_SHOW:
InsetIncludeMailer(*this).showDialog(cmd.view());
return DISPATCHED;
@ -535,10 +539,11 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
}
button_.metrics(mi, dim);
}
if (params_.flag == INPUT)
center_indent_ = 0;
else
center_indent_ = (mi.base.textwidth - dim.wid) / 2;
int center_indent = (params_.flag == INPUT ? 0 :
(mi.base.textwidth - dim.wid) / 2);
Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
button_.setBox(b);
dim.wid = mi.base.textwidth;
dim_ = dim;
}
@ -548,14 +553,14 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
{
cache(pi.base.bv);
if (!preview_->previewReady()) {
button_.draw(pi, x + center_indent_, y);
button_.draw(pi, x + button_.box().x1, y);
return;
}
if (!preview_->monitoring())
preview_->startMonitoring();
pi.pain.image(x + center_indent_, y - dim_.asc, dim_.wid, dim_.height(),
pi.pain.image(x + button_.box().x1, y - dim_.asc, dim_.wid, dim_.height(),
*(preview_->pimage()->image()));
}

View File

@ -138,7 +138,6 @@ private:
/// cache
mutable bool set_label_;
mutable ButtonRenderer button_;
mutable unsigned int center_indent_;
};

View File

@ -59,7 +59,10 @@ InsetOld::Code InsetTOC::lyxCode() const
void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const
{
InsetCommand::metrics(mi, dim);
center_indent_ = (mi.base.textwidth - dim.wid) / 2;
int center_indent = (mi.base.textwidth - dim.wid) / 2;
Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
button().setBox(b);
dim.wid = mi.base.textwidth;
dim_ = dim;
}
@ -67,16 +70,22 @@ void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetTOC::draw(PainterInfo & pi, int x, int y) const
{
InsetCommand::draw(pi, x + center_indent_, y);
InsetCommand::draw(pi, x + button().box().x1, y);
}
dispatch_result InsetTOC::localDispatch(FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_INSET_EDIT:
case LFUN_MOUSE_RELEASE:
if (button().box().contains(cmd.x, cmd.y))
InsetCommandMailer("toc", *this).showDialog(cmd.view());
return DISPATCHED;
case LFUN_INSET_DIALOG_SHOW:
InsetCommandMailer("toc", *this).showDialog(cmd.view());
return DISPATCHED;
default:
return InsetCommand::localDispatch(cmd);
}

View File

@ -48,9 +48,6 @@ public:
int linuxdoc(Buffer const &, std::ostream &) const;
///
int docbook(Buffer const &, std::ostream &, bool mixcont) const;
private:
///
mutable unsigned int center_indent_;
};
#endif

View File

@ -13,6 +13,7 @@
#define RENDERERS_H
#include "dimension.h"
#include "box.h"
#include "graphics/GraphicsLoader.h"
#include "graphics/GraphicsParams.h"
@ -68,10 +69,16 @@ public:
/// draw inset and update (xo, yo)-cache
virtual void draw(PainterInfo & pi, int x, int y) const;
/// The "sensitive area" box, i.e., the button area
Box box() const { return button_box_; }
///
void setBox(Box b) { button_box_ = b; }
private:
/// The stored data.
string text_;
bool editable_;
Box button_box_;
};

View File

@ -322,6 +322,7 @@ enum kb_action {
LFUN_EXTERNAL_EDIT,
// 245
LFUN_INSERT_BRANCH,
LFUN_INSET_DIALOG_SHOW,
LFUN_LASTACTION // end of the table
};

View File

@ -691,6 +691,20 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
if (!mathcursor)
code = InsetOld::SPACE_CODE;
break;
case LFUN_INSET_DIALOG_SHOW: {
LyXText * lt = view()->getLyXText();
InsetOld * inset = lt->getInset();
disable = !inset;
if (!disable) {
code = inset->lyxCode();
if (!(code == InsetOld::INCLUDE_CODE
|| code == InsetOld::BIBTEX_CODE
|| code == InsetOld::FLOAT_LIST_CODE
|| code == InsetOld::TOC_CODE))
disable = true;
}
}
break;
default:
break;
}
@ -1462,6 +1476,16 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
}
break;
case LFUN_INSET_DIALOG_SHOW: {
LyXText * lt = view()->getLyXText();
InsetOld * inset = lt->getInset();
if (inset) {
FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
inset->localDispatch(cmd);
}
}
break;
case LFUN_DIALOG_UPDATE: {
string const & name = argument;
// Can only update a dialog connected to an existing inset

View File

@ -388,8 +388,9 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd,
InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
{
lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
<<"] arg[" << cmd.argument << ']' << endl;
lyxerr[Debug::ACTION] << "LyXText::dispatch: action[" << cmd.action
<<"] arg[" << cmd.argument << ']' << "xy[" <<
cmd.x << ',' << cmd.y << ']' << endl;
BufferView * bv = cmd.view();