Next attempt (number VI?) On Wed, Sep 03, 2003 at 12:52:00PM +0000, Angus Leeming spake thusly:
... > Looks good. Some suggestions: ... > Index: insets/insetcommand.h > I think that these should be made part of ButtonRenderer (and called > box())... > + /// > + Box buttonBox() const { return button_box_; } > + /// > + void setButtonBox(Box b) const { button_box_ = b; } > + > mutable ButtonRenderer button_; > + mutable Box button_box_; Yes, this serves to streamline things quite a bit... how did you guess? ;-) > -- > Angus - Martin
Index: LyXAction.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v retrieving revision 1.177 diff -u -p -r1.177 LyXAction.C --- LyXAction.C 23 Aug 2003 00:16:06 -0000 1.177 +++ LyXAction.C 3 Sep 2003 19:06:33 -0000 @@ -321,6 +321,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 }, Index: box.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/box.C,v retrieving revision 1.9 diff -u -p -r1.9 box.C --- box.C 2 Sep 2003 20:42:27 -0000 1.9 +++ box.C 3 Sep 2003 19:06:33 -0000 @@ -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) { Index: box.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/box.h,v retrieving revision 1.9 diff -u -p -r1.9 box.h --- box.h 2 Sep 2003 20:42:27 -0000 1.9 +++ box.h 3 Sep 2003 19:06:33 -0000 @@ -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_); Index: lfuns.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lfuns.h,v retrieving revision 1.17 diff -u -p -r1.17 lfuns.h --- lfuns.h 23 Aug 2003 00:16:08 -0000 1.17 +++ lfuns.h 3 Sep 2003 19:06:33 -0000 @@ -322,6 +322,7 @@ enum kb_action { LFUN_EXTERNAL_EDIT, // 245 LFUN_INSERT_BRANCH, + LFUN_INSET_DIALOG_SHOW, LFUN_LASTACTION // end of the table }; Index: lyxfunc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v retrieving revision 1.481 diff -u -p -r1.481 lyxfunc.C --- lyxfunc.C 2 Sep 2003 17:08:52 -0000 1.481 +++ lyxfunc.C 3 Sep 2003 19:06:33 -0000 @@ -689,6 +689,20 @@ FuncStatus LyXFunc::getStatus(FuncReques 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; } @@ -1460,6 +1474,16 @@ void LyXFunc::dispatch(FuncRequest const } 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 Index: text3.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v retrieving revision 1.127 diff -u -p -r1.127 text3.C --- text3.C 2 Sep 2003 20:42:28 -0000 1.127 +++ text3.C 3 Sep 2003 19:06:33 -0000 @@ -388,8 +388,9 @@ void doInsertInset(LyXText * lt, FuncReq 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(); Index: insets/insetbibtex.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbibtex.C,v retrieving revision 1.22 diff -u -p -r1.22 insetbibtex.C --- insets/insetbibtex.C 2 Sep 2003 17:08:53 -0000 1.22 +++ insets/insetbibtex.C 3 Sep 2003 19:06:34 -0000 @@ -58,7 +58,9 @@ std::auto_ptr<InsetBase> InsetBibtex::cl 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 & 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,8 +76,12 @@ dispatch_result InsetBibtex::localDispat { 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: { Index: insets/insetbibtex.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbibtex.h,v retrieving revision 1.20 diff -u -p -r1.20 insetbibtex.h --- insets/insetbibtex.h 28 Aug 2003 07:41:28 -0000 1.20 +++ insets/insetbibtex.h 3 Sep 2003 19:06:34 -0000 @@ -50,9 +50,6 @@ public: bool addDatabase(string const &); /// bool delDatabase(string const &); -private: - /// - mutable unsigned int center_indent_; }; #endif // INSET_BIBTEX_H Index: insets/insetcommand.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcommand.h,v retrieving revision 1.69 diff -u -p -r1.69 insetcommand.h --- insets/insetcommand.h 28 Aug 2003 07:41:29 -0000 1.69 +++ insets/insetcommand.h 3 Sep 2003 19:06:34 -0000 @@ -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(); } Index: insets/insetfloatlist.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfloatlist.C,v retrieving revision 1.39 diff -u -p -r1.39 insetfloatlist.C --- insets/insetfloatlist.C 28 Aug 2003 07:41:29 -0000 1.39 +++ insets/insetfloatlist.C 3 Sep 2003 19:06:34 -0000 @@ -101,7 +101,10 @@ void InsetFloatList::read(Buffer const & 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; } @@ -109,16 +112,22 @@ void InsetFloatList::metrics(MetricsInfo 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); } Index: insets/insetfloatlist.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetfloatlist.h,v retrieving revision 1.29 diff -u -p -r1.29 insetfloatlist.h --- insets/insetfloatlist.h 28 Aug 2003 07:41:29 -0000 1.29 +++ insets/insetfloatlist.h 3 Sep 2003 19:06:34 -0000 @@ -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 Index: insets/insetinclude.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetinclude.C,v retrieving revision 1.138 diff -u -p -r1.138 insetinclude.C --- insets/insetinclude.C 28 Aug 2003 07:41:29 -0000 1.138 +++ insets/insetinclude.C 3 Sep 2003 19:06:34 -0000 @@ -148,7 +148,11 @@ dispatch_result InsetInclude::localDispa 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 & } 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 { 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())); } Index: insets/insetinclude.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetinclude.h,v retrieving revision 1.79 diff -u -p -r1.79 insetinclude.h --- insets/insetinclude.h 28 Aug 2003 07:41:29 -0000 1.79 +++ insets/insetinclude.h 3 Sep 2003 19:06:34 -0000 @@ -138,7 +138,6 @@ private: /// cache mutable bool set_label_; mutable ButtonRenderer button_; - mutable unsigned int center_indent_; }; Index: insets/insettoc.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettoc.C,v retrieving revision 1.50 diff -u -p -r1.50 insettoc.C --- insets/insettoc.C 28 Aug 2003 07:41:30 -0000 1.50 +++ insets/insettoc.C 3 Sep 2003 19:06:34 -0000 @@ -57,7 +57,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; } @@ -65,16 +68,22 @@ void InsetTOC::metrics(MetricsInfo & mi, 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); } Index: insets/insettoc.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettoc.h,v retrieving revision 1.47 diff -u -p -r1.47 insettoc.h --- insets/insettoc.h 28 Aug 2003 07:41:30 -0000 1.47 +++ insets/insettoc.h 3 Sep 2003 19:06:34 -0000 @@ -46,9 +46,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 Index: insets/renderers.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/renderers.h,v retrieving revision 1.3 diff -u -p -r1.3 renderers.h --- insets/renderers.h 23 Aug 2003 00:16:56 -0000 1.3 +++ insets/renderers.h 3 Sep 2003 19:06:34 -0000 @@ -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_; };
pgp00000.pgp
Description: PGP signature