From b6c3478eda7703baff04c4e885f810a523cf283b Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 7 May 2006 10:51:19 +0000 Subject: [PATCH] Implement GUI for fixed size math delimiters (by Enrico Forestieri and me): * src/lfuns.h (enum kb_action): New lfun LFUN_MATH_BIGDELIM * src/LyXAction.C (void LyXAction::init): New lfun LFUN_MATH_BIGDELIM * src/mathed/math_nestinset.C (void MathNestInset::doDispatch): remove debug message (void MathNestInset::doDispatch): remove LFUN_MATH_DELIM test for multiple cells (now in getStatus) (void MathNestInset::doDispatch): Handle LFUN_MATH_BIGDELIM (bool MathNestInset::getStatus): Disable LFUN_MATH_DELIM and LFUN_MATH_BIGDELIM when the selection spans multiple cells * src/frontends/qt3/ui/QDelimiterDialogBase.ui Added a combobox for selecting delimiter size. * src/frontends/qt3/QDelimiterDialog.[Ch] (fix_name, QDelimiterDialog, insertClicked, size_selected): Allow for fixed size delimiters. * src/frontends/gtk/GMathDelim.C: Add FIXME commnent for fixed size delimiters * src/frontends/qt4/QDelimiterDialog.C: ditto * src/frontends/xforms/FormMathsDelim.C: ditto * src/frontends/controllers/ControlMath.[Ch]: Added dispatchBigDelim() to deal with fixed size delimiters. * src/text3.C (void LyXText::dispatch): Handle LFUN_MATH_BIGDELIM (bool LyXText::getStatus): ditto * src/ToolbarBackend.C (string const ToolbarBackend::getIcon): Handle LFUN_MATH_BIGDELIM git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13806 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/LyXAction.C | 1 + src/ToolbarBackend.C | 10 +++-- src/frontends/controllers/ControlMath.C | 6 +++ src/frontends/controllers/ControlMath.h | 6 ++- src/frontends/gtk/GMathDelim.C | 2 + src/frontends/qt3/QDelimiterDialog.C | 43 +++++++++++++++++-- src/frontends/qt3/QDelimiterDialog.h | 4 ++ src/frontends/qt3/ui/QDelimiterDialogBase.ui | 16 +++++++ src/frontends/qt4/QDelimiterDialog.C | 2 + src/frontends/xforms/FormMathsDelim.C | 2 + src/lfuns.h | 3 +- src/mathed/math_nestinset.C | 44 +++++++++++++++++--- src/text3.C | 4 +- 13 files changed, 128 insertions(+), 15 deletions(-) diff --git a/src/LyXAction.C b/src/LyXAction.C index b202825855..4e1f779025 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -212,6 +212,7 @@ void LyXAction::init() { LFUN_MARK_ON, "mark-on", ReadOnly }, { LFUN_MARK_TOGGLE, "mark-toggle", ReadOnly }, { LFUN_MATH_DELIM, "math-delim", Noop }, + { LFUN_MATH_BIGDELIM, "math-bigdelim", Noop }, { LFUN_MATH_DISPLAY, "math-display", Noop }, { LFUN_MATH_INSERT, "math-insert", Noop }, { LFUN_MATH_SUBSCRIPT, "math-subscript", Noop }, diff --git a/src/ToolbarBackend.C b/src/ToolbarBackend.C index dce01ff063..6521d5369d 100644 --- a/src/ToolbarBackend.C +++ b/src/ToolbarBackend.C @@ -217,12 +217,16 @@ string const ToolbarBackend::getIcon(FuncRequest const & f) string fullname; - if (f.action == LFUN_MATH_INSERT) { + switch (f.action) { + case LFUN_MATH_INSERT: if (!f.argument.empty()) fullname = find_xpm(f.argument.substr(1)); - } else if (f.action == LFUN_MATH_DELIM) { + break; + case LFUN_MATH_DELIM: + case LFUN_MATH_BIGDELIM: fullname = find_xpm(f.argument); - } else { + break; + default: string const name = lyxaction.getActionName(f.action); string xpm_name(name); diff --git a/src/frontends/controllers/ControlMath.C b/src/frontends/controllers/ControlMath.C index ad68b092d9..081333d7b0 100644 --- a/src/frontends/controllers/ControlMath.C +++ b/src/frontends/controllers/ControlMath.C @@ -79,6 +79,12 @@ void ControlMath::dispatchDelim(string const & str) const } +void ControlMath::dispatchBigDelim(string const & str) const +{ + dispatchFunc(LFUN_MATH_BIGDELIM, str); +} + + void ControlMath::dispatchToggleDisplay() const { dispatchFunc(LFUN_MATH_DISPLAY); diff --git a/src/frontends/controllers/ControlMath.h b/src/frontends/controllers/ControlMath.h index 0f220775ae..b843f75574 100644 --- a/src/frontends/controllers/ControlMath.h +++ b/src/frontends/controllers/ControlMath.h @@ -43,9 +43,11 @@ public: void dispatchCubeRoot() const; /// Insert a matrix void dispatchMatrix(std::string const & str) const; - /// Insert a delimiter + /// Insert a variable size delimiter void dispatchDelim(std::string const & str) const; - /// Wwitch between display and inline + /// Insert a big delimiter + void dispatchBigDelim(std::string const & str) const; + /// Switch between display and inline void dispatchToggleDisplay() const; /** A request to the kernel to launch a dialog. * \param name the dialog identifier. diff --git a/src/frontends/gtk/GMathDelim.C b/src/frontends/gtk/GMathDelim.C index 1213c239a3..d94e4acf5a 100644 --- a/src/frontends/gtk/GMathDelim.C +++ b/src/frontends/gtk/GMathDelim.C @@ -36,6 +36,8 @@ using std::string; namespace lyx { namespace frontend { +// FIXME: Implement fixed size delimiters (see qt3 frontend) + namespace { diff --git a/src/frontends/qt3/QDelimiterDialog.C b/src/frontends/qt3/QDelimiterDialog.C index c3e7fd27fa..9a32674a2f 100644 --- a/src/frontends/qt3/QDelimiterDialog.C +++ b/src/frontends/qt3/QDelimiterDialog.C @@ -18,9 +18,14 @@ #include "controllers/ControlMath.h" +#include "gettext.h" + #include #include #include +#include + +#include using std::string; @@ -38,6 +43,12 @@ char const * delim[] = { }; +char const * const bigleft[] = {"bigl", "Bigl", "biggl", "Biggl", ""}; +char const * const bigright[] = {"bigr", "Bigr", "biggr", "Biggr", ""}; +char const * const biggui[] = {N_("big size"), N_("Big size"), + N_("bigg size"), N_("Bigg size"), ""}; + + string do_match(const string & str) { if (str == "(") return ")"; @@ -59,7 +70,7 @@ string do_match(const string & str) } -string fix_name(const string & str) +string fix_name(const string & str, bool big) { if (str == "slash") return "/"; @@ -67,7 +78,10 @@ string fix_name(const string & str) return "\\"; if (str == "empty") return "."; - return str; + if (!big || str == "(" || str == ")" || str == "[" || str == "]") + return str; + + return "\\" + str; } } // namespace anon @@ -89,11 +103,17 @@ QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form) leftIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty"); rightIP->add(QPixmap(toqstr(empty_xpm)), "empty", "empty"); + delimSize->insertItem(qt_("Variable size")); + for (int i = 0; *biggui[i]; ++i) + delimSize->insertItem(qt_(biggui[i])); + size_ = 0; // Leave these std:: qualifications alone ! connect(leftIP, SIGNAL(button_clicked(const std::string &)), this, SLOT(ldelim_clicked(const std::string &))); connect(rightIP, SIGNAL(button_clicked(const std::string &)), this, SLOT(rdelim_clicked(const std::string &))); + connect(delimSize, SIGNAL(activated(int)), + this, SLOT(size_selected(int)) ); ldelim_clicked("("); rdelim_clicked(")"); } @@ -101,7 +121,18 @@ QDelimiterDialog::QDelimiterDialog(QMathDelimiter * form) void QDelimiterDialog::insertClicked() { - form_->controller().dispatchDelim(fix_name(left_) + ' ' + fix_name(right_)); + if (size_ == 0) { + form_->controller().dispatchDelim( + fix_name(left_, false) + ' ' + + fix_name(right_, false)); + } else { + std::ostringstream os; + os << '"' << bigleft[size_ - 1] << "\" \"" + << fix_name(left_, true) << "\" \"" + << bigright[size_ - 1] << "\" \"" + << fix_name(right_, true) << '"'; + form_->controller().dispatchBigDelim(os.str()); + } } @@ -137,5 +168,11 @@ void QDelimiterDialog::rdelim_clicked(const string & str) } } + +void QDelimiterDialog::size_selected(int index) +{ + size_ = index; +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt3/QDelimiterDialog.h b/src/frontends/qt3/QDelimiterDialog.h index 53b2324e24..9bab95b05f 100644 --- a/src/frontends/qt3/QDelimiterDialog.h +++ b/src/frontends/qt3/QDelimiterDialog.h @@ -30,6 +30,7 @@ public: public slots: void ldelim_clicked(const std::string & str); void rdelim_clicked(const std::string & str); + void size_selected(int); void insertClicked(); protected: //needed ? virtual void closeEvent(QCloseEvent * e); @@ -42,6 +43,9 @@ private: /// symbol of right delimiter std::string right_; + /// size of delimiters + int size_; + /// owning form QMathDelimiter * form_; }; diff --git a/src/frontends/qt3/ui/QDelimiterDialogBase.ui b/src/frontends/qt3/ui/QDelimiterDialogBase.ui index 2711f9b219..8e32dc0a7b 100644 --- a/src/frontends/qt3/ui/QDelimiterDialogBase.ui +++ b/src/frontends/qt3/ui/QDelimiterDialogBase.ui @@ -307,6 +307,22 @@ + + + delimSize + + + + 7 + 0 + 0 + 0 + + + + Choose delimiter size + + diff --git a/src/frontends/qt4/QDelimiterDialog.C b/src/frontends/qt4/QDelimiterDialog.C index bdb9842a4f..e78c4b2fc5 100644 --- a/src/frontends/qt4/QDelimiterDialog.C +++ b/src/frontends/qt4/QDelimiterDialog.C @@ -28,6 +28,8 @@ using std::string; namespace lyx { namespace frontend { +// FIXME: Implement fixed size delimiters (see qt3 frontend) + namespace { char const * delim[] = { diff --git a/src/frontends/xforms/FormMathsDelim.C b/src/frontends/xforms/FormMathsDelim.C index 26a5beb559..14624dc008 100644 --- a/src/frontends/xforms/FormMathsDelim.C +++ b/src/frontends/xforms/FormMathsDelim.C @@ -33,6 +33,8 @@ using std::ostringstream; namespace lyx { namespace frontend { +// FIXME: Implement fixed size delimiters (see qt3 frontend) + namespace { int const delim_rversion[] = { diff --git a/src/lfuns.h b/src/lfuns.h index 3a4ce8116b..d287f5d952 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -362,10 +362,11 @@ enum kb_action { LFUN_OUTLINE_DOWN, LFUN_OUTLINE_IN, LFUN_OUTLINE_OUT, - // 275 LFUN_PARAGRAPH_MOVE_DOWN, // Edwin 20060408 LFUN_PARAGRAPH_MOVE_UP, // Edwin 20060408 + // 280 LFUN_BUFFER_TOGGLE_COMPRESSION, // bpeng 20060427 + LFUN_MATH_BIGDELIM, LFUN_LASTACTION // end of the table }; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 7b26042f2c..f86acb25de 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -848,7 +848,6 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd) } case LFUN_MATH_DELIM: { - lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl; string ls; string rs = lyx::support::split(cmd.argument, ls, ' '); // Reasonable default values @@ -857,9 +856,37 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd) if (rs.empty()) rs = ')'; recordUndo(cur, Undo::ATOMIC); - // Don't do this with multi-cell selections - if (cur.selBegin().idx() == cur.selEnd().idx()) - cur.handleNest(MathAtom(new MathDelimInset(ls, rs))); + cur.handleNest(MathAtom(new MathDelimInset(ls, rs))); + break; + } + + case LFUN_MATH_BIGDELIM: { + string const lname = cmd.getArg(0); + string const ldelim = cmd.getArg(1); + string const rname = cmd.getArg(2); + string const rdelim = cmd.getArg(3); + latexkeys const * l = in_word_set(lname); + bool const have_l = l && l->inset == "big" && + MathBigInset::isBigInsetDelim(ldelim); + l = in_word_set(rname); + bool const have_r = l && l->inset == "big" && + MathBigInset::isBigInsetDelim(rdelim); + // We mimic LFUN_MATH_DELIM in case we have an empty left + // or right delimiter. + if (have_l || have_r) { + recordUndo(cur, Undo::ATOMIC); + string const selection = grabAndEraseSelection(cur); + selClearOrDel(cur); + if (have_l) + cur.insert(MathAtom(new MathBigInset(lname, + ldelim))); + cur.niceInsert(selection); + if (have_r) + cur.insert(MathAtom(new MathBigInset(rname, + rdelim))); + } + // Don't call cur.undispatched() if we did nothing, this would + // lead to infinite recursion via LyXText::dispatch(). break; } @@ -917,7 +944,7 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd) } -bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd, +bool MathNestInset::getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { // the font related toggles @@ -993,6 +1020,13 @@ bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd, case LFUN_MATH_MATRIX: flag.enabled(currentMode() == MATH_MODE); break; + + case LFUN_MATH_DELIM: + case LFUN_MATH_BIGDELIM: + // Don't do this with multi-cell selections + flag.enabled(cur.selBegin().idx() == cur.selEnd().idx()); + break; + default: ret = false; break; diff --git a/src/text3.C b/src/text3.C index 5dfb32b086..31db8bf99b 100644 --- a/src/text3.C +++ b/src/text3.C @@ -1311,7 +1311,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) case LFUN_MATH_INSERT: case LFUN_MATH_MATRIX: - case LFUN_MATH_DELIM: { + case LFUN_MATH_DELIM: + case LFUN_MATH_BIGDELIM: { cur.insert(new MathHullInset("simple")); cur.dispatch(FuncRequest(LFUN_CHAR_FORWARD)); cur.dispatch(cmd); @@ -1878,6 +1879,7 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd, case LFUN_MATH_INSERT: case LFUN_MATH_MATRIX: case LFUN_MATH_DELIM: + case LFUN_MATH_BIGDELIM: case LFUN_MATH_SUBSCRIPT: case LFUN_MATH_SUPERSCRIPT: case LFUN_FONT_DEFAULT: