From 781e0ef62e262a633b094917eb40a5b840fea913 Mon Sep 17 00:00:00 2001 From: Martin Vermeer Date: Thu, 4 Sep 2003 14:02:05 +0000 Subject: [PATCH] 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 --- src/ChangeLog | 12 ++++++++++++ src/LyXAction.C | 1 + src/box.C | 7 +++++-- src/box.h | 2 ++ src/insets/ChangeLog | 12 ++++++++++++ src/insets/insetbibtex.C | 12 +++++++++--- src/insets/insetbibtex.h | 3 --- src/insets/insetcommand.h | 4 +++- src/insets/insetfloatlist.C | 15 ++++++++++++--- src/insets/insetfloatlist.h | 3 --- src/insets/insetinclude.C | 19 ++++++++++++------- src/insets/insetinclude.h | 1 - src/insets/insettoc.C | 15 ++++++++++++--- src/insets/insettoc.h | 3 --- src/insets/renderers.h | 7 +++++++ src/lfuns.h | 1 + src/lyxfunc.C | 24 ++++++++++++++++++++++++ src/text3.C | 5 +++-- 18 files changed, 115 insertions(+), 31 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 79d7f54bf7..37e4989ef8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2003-09-03 Martin Vermeer + + * 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 * bufferview_funcs.C (currentState): output paragraph position diff --git a/src/LyXAction.C b/src/LyXAction.C index 4a5bf1a023..57790a4568 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -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 }, diff --git a/src/box.C b/src/box.C index 9c2213ef93..4ee0b2afb0 100644 --- a/src/box.C +++ b/src/box.C @@ -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) { diff --git a/src/box.h b/src/box.h index 156833f75a..55eb980896 100644 --- a/src/box.h +++ b/src/box.h @@ -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_); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 2bd75886a1..df8d6fafe2 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,15 @@ +2003-09-03 Martin Vermeer + + * 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 * insetgraphics.C: #include "support/os.h" diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index 64188f9e03..3687af8b63 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -58,7 +58,9 @@ std::auto_ptr 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; diff --git a/src/insets/insetbibtex.h b/src/insets/insetbibtex.h index 9911bf48a5..7f1db0de00 100644 --- a/src/insets/insetbibtex.h +++ b/src/insets/insetbibtex.h @@ -50,9 +50,6 @@ public: bool addDatabase(string const &); /// bool delDatabase(string const &); -private: - /// - mutable unsigned int center_indent_; }; #endif // INSET_BIBTEX_H diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index 489c68e7a7..8eb2bc268b 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -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(); } diff --git a/src/insets/insetfloatlist.C b/src/insets/insetfloatlist.C index c4abb64f39..6800c53351 100644 --- a/src/insets/insetfloatlist.C +++ b/src/insets/insetfloatlist.C @@ -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); } diff --git a/src/insets/insetfloatlist.h b/src/insets/insetfloatlist.h index b4d14e035c..50d7de189d 100644 --- a/src/insets/insetfloatlist.h +++ b/src/insets/insetfloatlist.h @@ -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 diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 7e1af317bb..b647952c05 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -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())); } diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 4e90013fdd..7e0ee9fdd3 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -138,7 +138,6 @@ private: /// cache mutable bool set_label_; mutable ButtonRenderer button_; - mutable unsigned int center_indent_; }; diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index f68649a009..74273ce85e 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -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); } diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index 81a1aaa75a..b53a550181 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -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 diff --git a/src/insets/renderers.h b/src/insets/renderers.h index fd23de1d17..e74f7ca491 100644 --- a/src/insets/renderers.h +++ b/src/insets/renderers.h @@ -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_; }; diff --git a/src/lfuns.h b/src/lfuns.h index c06047b7e1..8dab45e776 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -322,6 +322,7 @@ enum kb_action { LFUN_EXTERNAL_EDIT, // 245 LFUN_INSERT_BRANCH, + LFUN_INSET_DIALOG_SHOW, LFUN_LASTACTION // end of the table }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index c7de612436..e2eb5b683d 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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 diff --git a/src/text3.C b/src/text3.C index 2203305b57..14c40bd71f 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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(); -- 2.39.2