]> git.lyx.org Git - features.git/commitdiff
math stuff
authorAndré Pönitz <poenitz@gmx.net>
Sun, 7 Oct 2007 20:34:09 +0000 (20:34 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sun, 7 Oct 2007 20:34:09 +0000 (20:34 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20826 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/ToolbarBackend.cpp
src/frontends/controllers/ControlMath.cpp [deleted file]
src/frontends/controllers/ControlMath.h [deleted file]
src/frontends/controllers/Makefile.am
src/frontends/qt4/Dialogs.cpp
src/frontends/qt4/GuiDelimiter.cpp
src/frontends/qt4/GuiDelimiter.h
src/frontends/qt4/GuiMath.cpp [new file with mode: 0644]
src/frontends/qt4/GuiMath.h [new file with mode: 0644]
src/frontends/qt4/GuiMathMatrix.cpp
src/frontends/qt4/GuiMathMatrix.h
src/frontends/qt4/GuiParagraph.h
src/frontends/qt4/GuiToolbar.cpp
src/frontends/qt4/Makefile.am

index 8baddc4f54c9dfdeec1d626cfdab4a0b0d7469b9..8dbe44e7257e8b638ce6b16c9f6ac14810553eff 100644 (file)
@@ -22,8 +22,6 @@
 #include <boost/bind.hpp>
 #include <algorithm>
 
-#include "frontends/controllers/ControlMath.h"
-
 namespace lyx {
 
 using support::compare_ascii_no_case;
diff --git a/src/frontends/controllers/ControlMath.cpp b/src/frontends/controllers/ControlMath.cpp
deleted file mode 100644 (file)
index cf2cb4d..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * \file ControlMath.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "ControlMath.h"
-#include "debug.h"
-#include "FuncRequest.h"
-
-using std::string;
-using std::map;
-
-namespace lyx {
-namespace frontend {
-
-ControlMath::ControlMath(Dialog & dialog)
-       : Controller(dialog)
-{
-       // FIXME: Ideally, those unicode codepoints would be defined
-       // in "lib/symbols". Unfortunately, some of those are already
-       // defined with non-unicode ids for use within mathed.
-       // FIXME 2: We should fill-in this map with the parsed "symbols"
-       // file done in MathFactory.cpp.
-       math_symbols_["("] = MathSymbol('(');
-       math_symbols_[")"] = MathSymbol(')');
-       math_symbols_["{"] = MathSymbol('{');
-       math_symbols_["}"] = MathSymbol('}');
-       math_symbols_["["] = MathSymbol('[');
-       math_symbols_["]"] = MathSymbol(']');
-       math_symbols_["|"] = MathSymbol('|');
-       math_symbols_["/"] = MathSymbol('/', 54, Font::CMSY_FAMILY);
-       math_symbols_["backslash"] = MathSymbol('\\', 110, Font::CMSY_FAMILY);
-       math_symbols_["lceil"] = MathSymbol(0x2308, 100, Font::CMSY_FAMILY);
-       math_symbols_["rceil"] = MathSymbol(0x2309, 101, Font::CMSY_FAMILY);
-       math_symbols_["lfloor"] = MathSymbol(0x230A, 98, Font::CMSY_FAMILY);
-       math_symbols_["rfloor"] = MathSymbol(0x230B, 99, Font::CMSY_FAMILY);
-       math_symbols_["langle"] = MathSymbol(0x2329, 104, Font::CMSY_FAMILY);
-       math_symbols_["rangle"] = MathSymbol(0x232A, 105, Font::CMSY_FAMILY);
-       math_symbols_["uparrow"] = MathSymbol(0x2191, 34, Font::CMSY_FAMILY);
-       math_symbols_["Uparrow"] = MathSymbol(0x21D1, 42, Font::CMSY_FAMILY);
-       math_symbols_["updownarrow"] = MathSymbol(0x2195, 108, Font::CMSY_FAMILY);
-       math_symbols_["Updownarrow"] = MathSymbol(0x21D5, 109, Font::CMSY_FAMILY);
-       math_symbols_["downarrow"] = MathSymbol(0x2193, 35, Font::CMSY_FAMILY);
-       math_symbols_["Downarrow"] = MathSymbol(0x21D3, 43, Font::CMSY_FAMILY);
-       math_symbols_["downdownarrows"] = MathSymbol(0x21CA, 184, Font::MSA_FAMILY);
-       math_symbols_["downharpoonleft"] = MathSymbol(0x21C3, 188, Font::MSA_FAMILY);
-       math_symbols_["downharpoonright"] = MathSymbol(0x21C2, 186, Font::MSA_FAMILY);
-       math_symbols_["vert"] = MathSymbol(0x007C, 106, Font::CMSY_FAMILY);
-       math_symbols_["Vert"] = MathSymbol(0x2016, 107, Font::CMSY_FAMILY);
-
-       std::map<string, MathSymbol>::const_iterator it = math_symbols_.begin();
-       std::map<string, MathSymbol>::const_iterator end = math_symbols_.end();
-       for (; it != end; ++it)
-               tex_names_[it->second.unicode] = it->first;
-}
-
-
-void ControlMath::dispatchFunc(kb_action action, string const & arg) const
-{
-       dispatch(FuncRequest(action, arg));
-}
-
-
-void ControlMath::dispatchInsert(string const & name) const
-{
-       dispatchFunc(LFUN_MATH_INSERT, '\\' + name);
-}
-
-
-void ControlMath::dispatchSubscript() const
-{
-       dispatchFunc(LFUN_MATH_INSERT, "_");
-}
-
-
-void ControlMath::dispatchSuperscript() const
-{
-       dispatchFunc(LFUN_MATH_INSERT, "^");
-}
-
-
-void ControlMath::dispatchCubeRoot() const
-{
-       dispatchFunc(LFUN_MATH_INSERT, "\\root");
-       dispatchFunc(LFUN_SELF_INSERT, "3");
-       dispatchFunc(LFUN_CHAR_FORWARD);
-}
-
-
-void ControlMath::dispatchMatrix(string const & str) const
-{
-       dispatchFunc(LFUN_MATH_MATRIX, str);
-}
-
-
-void ControlMath::dispatchDelim(string const & str) const
-{
-       dispatchFunc(LFUN_MATH_DELIM, str);
-}
-
-
-void ControlMath::dispatchBigDelim(string const & str) const
-{
-       dispatchFunc(LFUN_MATH_BIGDELIM, str);
-}
-
-
-void ControlMath::dispatchToggleDisplay() const
-{
-       dispatchFunc(LFUN_MATH_DISPLAY);
-}
-
-
-void ControlMath::showDialog(string const & name) const
-{
-       dispatchFunc(LFUN_DIALOG_SHOW, name);
-}
-
-
-MathSymbol const & ControlMath::mathSymbol(string tex_name) const
-{
-       map<string, MathSymbol>::const_iterator it =
-               math_symbols_.find(tex_name);
-
-       static MathSymbol unknown_symbol;
-       if (it == math_symbols_.end())
-               return unknown_symbol;
-
-       return it->second;
-}
-
-
-std::string const & ControlMath::texName(char_type math_symbol) const
-{
-       map<char_type, string>::const_iterator it =
-               tex_names_.find(math_symbol);
-
-       static string empty_string;
-       if (it == tex_names_.end())
-               return empty_string;
-
-       return it->second;
-}
-
-
-} // namespace frontend
-} // namespace lyx
diff --git a/src/frontends/controllers/ControlMath.h b/src/frontends/controllers/ControlMath.h
deleted file mode 100644 (file)
index 94322dd..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-// -*- C++ -*-
-/**
- * \file ControlMath.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Angus Leeming
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#ifndef CONTROLMATH_H
-#define CONTROLMATH_H
-
-#include "Dialog.h"
-#include "lfuns.h" // for kb_action
-#include "Font.h"
-
-#include <map>
-
-
-namespace lyx {
-namespace frontend {
-
-struct MathSymbol {
-       MathSymbol(char_type uc = '?', unsigned char fc = 0,
-               Font::FONT_FAMILY ff = Font::SYMBOL_FAMILY)
-               : unicode(uc), fontcode(fc), fontfamily(ff)
-       {}
-       char_type unicode;
-       unsigned char fontcode;
-       Font::FONT_FAMILY fontfamily;
-};
-
-
-class ControlMath : public Controller {
-public:
-       ControlMath(Dialog &);
-
-       /// Nothing to initialise in this case.
-       virtual bool initialiseParams(std::string const &) { return true; }
-       virtual void clearParams() {}
-       virtual void dispatchParams() {}
-       virtual bool isBufferDependent() const { return true; }
-
-       /// dispatch an LFUN
-       void dispatchFunc(kb_action action, std::string const & arg = std::string()) const;
-       /// Insert a math symbol into the doc.
-       void dispatchInsert(std::string const & name) const;
-       /// Insert a subscript.
-       void dispatchSubscript() const;
-       /// Insert a superscript.
-       void dispatchSuperscript() const;
-       /// Insert a cube root
-       void dispatchCubeRoot() const;
-       /// Insert a matrix
-       void dispatchMatrix(std::string const & str) const;
-       /// Insert a variable size delimiter
-       void dispatchDelim(std::string const & str) const;
-       /// 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.
-        */
-       void showDialog(std::string const & name) const;
-
-       /// \return the math unicode symbol associated to a TeX name.
-       MathSymbol const & mathSymbol(std::string tex_name) const;
-       /// \return the TeX name associated to a math unicode symbol.
-       std::string const & texName(char_type math_symbol) const;
-
-private:
-       /// TeX-name / Math-symbol map.
-       std::map<std::string, MathSymbol> math_symbols_;
-       /// Math-symbol / TeX-name map.
-       /// This one is for fast search, it contains the same data as
-       /// \c math_symbols_.
-       std::map<char_type, std::string> tex_names_;
-};
-
-
-} // namespace frontend
-} // namespace lyx
-
-#endif // NOT CONTROLMATH
index 0ead9da1337de69bb0270795b9b31557fdea1f69..42b3989eca76615791d41551fc1646b8625d8332 100644 (file)
@@ -9,13 +9,11 @@ noinst_LTLIBRARIES = liblyxcontrollers.la
 SOURCEFILES = \
        Dialog.cpp \
        ButtonPolicy.cpp \
-       ControlMath.cpp \
        frontend_helpers.cpp 
 
 HEADERFILES = \
        Dialog.h \
        ButtonPolicy.h \
-       ControlMath.h \
        frontend_helpers.h
 
 if MONOLITHIC_CONTROLLERS
index 4cc878c1b789df324d38df8efa19d97200e15c2b..415a5fd21aa2a907aec861f28c614b35b1b2cf01 100644 (file)
 #include "Dialogs.h"
 #include "GuiDialog.h"
 
-#include "ButtonController.h"
-#include "DialogView.h"
-#include "DockView.h"
-#include "GuiDelimiter.h"
-#include "GuiIndex.h"
-#include "GuiMathMatrix.h"
-#include "GuiView.h"
-
-// Uncomment this if you prefer dock widget
-//#define USE_DOCK_WIDGET
-
 #include "qt_helpers.h"
 
 #include <boost/assert.hpp>
@@ -90,7 +79,7 @@ Dialog * createGuiIndex(LyXView & lv);
 Dialog * createGuiLabel(LyXView & lv);
 Dialog * createGuiListings(LyXView & lv);
 Dialog * createGuiLog(LyXView & lv);
-Dialog * createGuiMath(LyXView & lv);
+Dialog * createGuiMathMatrix(LyXView & lv);
 Dialog * createGuiNomenclature(LyXView & lv);
 Dialog * createGuiNote(LyXView & lv);
 Dialog * createGuiParagraph(LyXView & lv);
@@ -170,9 +159,9 @@ Dialog * Dialogs::build(string const & name)
        if (name == "view-source")
                return createGuiViewSource(lyxview_);
        if (name == "mathdelimiter")
-               return new GuiDelimiterDialog(lyxview_);
+               return createGuiDelimiter(lyxview_);
        if (name == "mathmatrix")
-               return new GuiMathMatrixDialog(lyxview_);
+               return createGuiMathMatrix(lyxview_);
        if (name == "note")
                return createGuiNote(lyxview_);
        if (name == "paragraph")
index 91c79159819fe769039736ef60e6baf1d477e9d5..fabf3db3bacdf9314ef94b2dbc1a65f142bf2eab 100644 (file)
@@ -69,12 +69,12 @@ namespace lyx {
 namespace frontend {
 
 
-GuiDelimiterDialog::GuiDelimiterDialog(LyXView & lv)
-       : GuiDialog(lv, "mathdelimiter")
+GuiDelimiter::GuiDelimiter(LyXView & lv)
+       : GuiMath(lv, "mathdelimiter")
 {
        setupUi(this);
        setViewTitle(_("Math Delimiter"));
-       setController(new ControlMath(*this));
+       setController(this, false);
 
        connect(closePB, SIGNAL(clicked()), this, SLOT(accept()));
 
@@ -89,7 +89,7 @@ GuiDelimiterDialog::GuiDelimiterDialog(LyXView & lv)
        int const end = nr_latex_delimiters - 1;
        for (int i = 0; i < end; ++i) {
                string const delim = latex_delimiters[i];
-               MathSymbol const & ms = controller().mathSymbol(delim);
+               MathSymbol const & ms = mathSymbol(delim);
                QString symbol(ms.fontcode?
                        QChar(ms.fontcode) : toqstr(docstring(1, ms.unicode)));
                QListWidgetItem * lwi = new QListWidgetItem(symbol);
@@ -103,7 +103,7 @@ GuiDelimiterDialog::GuiDelimiterDialog(LyXView & lv)
        }
 
        for (int i = 0; i != leftLW->count(); ++i) {
-               MathSymbol const & ms = controller().mathSymbol(
+               MathSymbol const & ms = mathSymbol(
                        fromqstr(leftLW->item(i)->toolTip()));
                rightLW->addItem(list_items[doMatch(ms.unicode)]->clone());
        }
@@ -122,15 +122,9 @@ GuiDelimiterDialog::GuiDelimiterDialog(LyXView & lv)
 }
 
 
-ControlMath & GuiDelimiterDialog::controller()
+char_type GuiDelimiter::doMatch(char_type const symbol)
 {
-       return static_cast<ControlMath &>(GuiDialog::controller()); 
-}
-
-
-char_type GuiDelimiterDialog::doMatch(char_type const symbol)
-{
-       string const & str = controller().texName(symbol);
+       string const & str = texName(symbol);
        string match;
        if (str == "(") match = ")";
        else if (str == ")") match = "(";
@@ -149,11 +143,11 @@ char_type GuiDelimiterDialog::doMatch(char_type const symbol)
        else if (str == "/") match = "backslash";
        else return symbol;
 
-       return controller().mathSymbol(match).unicode;
+       return mathSymbol(match).unicode;
 }
 
 
-void GuiDelimiterDialog::updateTeXCode(int size)
+void GuiDelimiter::updateTeXCode(int size)
 {
        bool const bigsize = size != 0;
 
@@ -191,39 +185,39 @@ void GuiDelimiterDialog::updateTeXCode(int size)
 }
 
 
-void GuiDelimiterDialog::on_insertPB_clicked()
+void GuiDelimiter::on_insertPB_clicked()
 {
        if (sizeCO->currentIndex() == 0)
-               controller().dispatchDelim(fromqstr(tex_code_));
+               dispatchDelim(fromqstr(tex_code_));
        else {
                QString command = '"' + tex_code_ + '"';
                command.replace(' ', "\" \"");
-               controller().dispatchBigDelim(fromqstr(command));
+               dispatchBigDelim(fromqstr(command));
        }
  }
 
 
-void GuiDelimiterDialog::on_sizeCO_activated(int index)
+void GuiDelimiter::on_sizeCO_activated(int index)
 {
        updateTeXCode(index);
 }
 
 
-void GuiDelimiterDialog::on_leftLW_itemActivated(QListWidgetItem *)
+void GuiDelimiter::on_leftLW_itemActivated(QListWidgetItem *)
 {
        on_insertPB_clicked();
        accept();
 }
 
 
-void GuiDelimiterDialog::on_rightLW_itemActivated(QListWidgetItem *)
+void GuiDelimiter::on_rightLW_itemActivated(QListWidgetItem *)
 {
        on_insertPB_clicked();
        accept();
 }
 
 
-void GuiDelimiterDialog::on_leftLW_currentRowChanged(int item)
+void GuiDelimiter::on_leftLW_currentRowChanged(int item)
 {
        if (matchCB->isChecked())
                rightLW->setCurrentRow(item);
@@ -232,7 +226,7 @@ void GuiDelimiterDialog::on_leftLW_currentRowChanged(int item)
 }
 
 
-void GuiDelimiterDialog::on_rightLW_currentRowChanged(int item)
+void GuiDelimiter::on_rightLW_currentRowChanged(int item)
 {
        if (matchCB->isChecked())
                leftLW->setCurrentRow(item);
@@ -241,7 +235,7 @@ void GuiDelimiterDialog::on_rightLW_currentRowChanged(int item)
 }
 
 
-void GuiDelimiterDialog::on_matchCB_stateChanged(int state)
+void GuiDelimiter::on_matchCB_stateChanged(int state)
 {
        if (state == Qt::Checked)
                on_leftLW_currentRowChanged(leftLW->currentRow());
@@ -250,6 +244,9 @@ void GuiDelimiterDialog::on_matchCB_stateChanged(int state)
 }
 
 
+Dialog * createGuiDelimiter(LyXView & lv) { return new GuiDelimiter(lv); }
+
+
 } // namespace frontend
 } // namespace lyx
 
index 1edf6248e227e08a6e5e7673a891382bc3b56cbd..9521ffaa3ffec263b80e5eb1839e5da3f2c3122e 100644 (file)
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 /**
- * \file GuiDelimiterDialog.h
+ * \file GuiDelimiter.h
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
@@ -12,8 +12,7 @@
 #ifndef GUIDELIMITERDIALOG_H
 #define GUIDELIMITERDIALOG_H
 
-#include "GuiDialog.h"
-#include "ControlMath.h"
+#include "GuiMath.h"
 #include "ui_DelimiterUi.h"
 
 class QListWidgetItem;
@@ -21,12 +20,12 @@ class QListWidgetItem;
 namespace lyx {
 namespace frontend {
 
-class GuiDelimiterDialog : public GuiDialog, public Ui::DelimiterUi
+class GuiDelimiter : public GuiMath, public Ui::DelimiterUi
 {
        Q_OBJECT
 
 public:
-       GuiDelimiterDialog(LyXView & lv);
+       GuiDelimiter(LyXView & lv);
 
 public Q_SLOTS:
        void on_leftLW_itemActivated(QListWidgetItem *);
@@ -42,8 +41,6 @@ private:
        char_type doMatch(char_type const symbol);
        ///
        void updateTeXCode(int size);
-       /// parent controller
-       ControlMath & controller();
 
        /// TeX code that will be inserted.
        QString tex_code_;
diff --git a/src/frontends/qt4/GuiMath.cpp b/src/frontends/qt4/GuiMath.cpp
new file mode 100644 (file)
index 0000000..07ea4fa
--- /dev/null
@@ -0,0 +1,154 @@
+/**
+ * \file GuiMath.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "GuiMath.h"
+#include "debug.h"
+#include "FuncRequest.h"
+
+using std::string;
+using std::map;
+
+namespace lyx {
+namespace frontend {
+
+GuiMath::GuiMath(LyXView & lv, std::string const & name)
+       : GuiDialog(lv, name), Controller(this)
+{
+       // FIXME: Ideally, those unicode codepoints would be defined
+       // in "lib/symbols". Unfortunately, some of those are already
+       // defined with non-unicode ids for use within mathed.
+       // FIXME 2: We should fill-in this map with the parsed "symbols"
+       // file done in MathFactory.cpp.
+       math_symbols_["("] = MathSymbol('(');
+       math_symbols_[")"] = MathSymbol(')');
+       math_symbols_["{"] = MathSymbol('{');
+       math_symbols_["}"] = MathSymbol('}');
+       math_symbols_["["] = MathSymbol('[');
+       math_symbols_["]"] = MathSymbol(']');
+       math_symbols_["|"] = MathSymbol('|');
+       math_symbols_["/"] = MathSymbol('/', 54, Font::CMSY_FAMILY);
+       math_symbols_["backslash"] = MathSymbol('\\', 110, Font::CMSY_FAMILY);
+       math_symbols_["lceil"] = MathSymbol(0x2308, 100, Font::CMSY_FAMILY);
+       math_symbols_["rceil"] = MathSymbol(0x2309, 101, Font::CMSY_FAMILY);
+       math_symbols_["lfloor"] = MathSymbol(0x230A, 98, Font::CMSY_FAMILY);
+       math_symbols_["rfloor"] = MathSymbol(0x230B, 99, Font::CMSY_FAMILY);
+       math_symbols_["langle"] = MathSymbol(0x2329, 104, Font::CMSY_FAMILY);
+       math_symbols_["rangle"] = MathSymbol(0x232A, 105, Font::CMSY_FAMILY);
+       math_symbols_["uparrow"] = MathSymbol(0x2191, 34, Font::CMSY_FAMILY);
+       math_symbols_["Uparrow"] = MathSymbol(0x21D1, 42, Font::CMSY_FAMILY);
+       math_symbols_["updownarrow"] = MathSymbol(0x2195, 108, Font::CMSY_FAMILY);
+       math_symbols_["Updownarrow"] = MathSymbol(0x21D5, 109, Font::CMSY_FAMILY);
+       math_symbols_["downarrow"] = MathSymbol(0x2193, 35, Font::CMSY_FAMILY);
+       math_symbols_["Downarrow"] = MathSymbol(0x21D3, 43, Font::CMSY_FAMILY);
+       math_symbols_["downdownarrows"] = MathSymbol(0x21CA, 184, Font::MSA_FAMILY);
+       math_symbols_["downharpoonleft"] = MathSymbol(0x21C3, 188, Font::MSA_FAMILY);
+       math_symbols_["downharpoonright"] = MathSymbol(0x21C2, 186, Font::MSA_FAMILY);
+       math_symbols_["vert"] = MathSymbol(0x007C, 106, Font::CMSY_FAMILY);
+       math_symbols_["Vert"] = MathSymbol(0x2016, 107, Font::CMSY_FAMILY);
+
+       std::map<string, MathSymbol>::const_iterator it = math_symbols_.begin();
+       std::map<string, MathSymbol>::const_iterator end = math_symbols_.end();
+       for (; it != end; ++it)
+               tex_names_[it->second.unicode] = it->first;
+}
+
+
+void GuiMath::dispatchFunc(kb_action action, string const & arg) const
+{
+       dispatch(FuncRequest(action, arg));
+}
+
+
+void GuiMath::dispatchInsert(string const & name) const
+{
+       dispatchFunc(LFUN_MATH_INSERT, '\\' + name);
+}
+
+
+void GuiMath::dispatchSubscript() const
+{
+       dispatchFunc(LFUN_MATH_INSERT, "_");
+}
+
+
+void GuiMath::dispatchSuperscript() const
+{
+       dispatchFunc(LFUN_MATH_INSERT, "^");
+}
+
+
+void GuiMath::dispatchCubeRoot() const
+{
+       dispatchFunc(LFUN_MATH_INSERT, "\\root");
+       dispatchFunc(LFUN_SELF_INSERT, "3");
+       dispatchFunc(LFUN_CHAR_FORWARD);
+}
+
+
+void GuiMath::dispatchMatrix(string const & str) const
+{
+       dispatchFunc(LFUN_MATH_MATRIX, str);
+}
+
+
+void GuiMath::dispatchDelim(string const & str) const
+{
+       dispatchFunc(LFUN_MATH_DELIM, str);
+}
+
+
+void GuiMath::dispatchBigDelim(string const & str) const
+{
+       dispatchFunc(LFUN_MATH_BIGDELIM, str);
+}
+
+
+void GuiMath::dispatchToggleDisplay() const
+{
+       dispatchFunc(LFUN_MATH_DISPLAY);
+}
+
+
+void GuiMath::showDialog(string const & name) const
+{
+       dispatchFunc(LFUN_DIALOG_SHOW, name);
+}
+
+
+MathSymbol const & GuiMath::mathSymbol(string tex_name) const
+{
+       map<string, MathSymbol>::const_iterator it =
+               math_symbols_.find(tex_name);
+
+       static MathSymbol unknown_symbol;
+       if (it == math_symbols_.end())
+               return unknown_symbol;
+
+       return it->second;
+}
+
+
+std::string const & GuiMath::texName(char_type math_symbol) const
+{
+       map<char_type, string>::const_iterator it =
+               tex_names_.find(math_symbol);
+
+       static string empty_string;
+       if (it == tex_names_.end())
+               return empty_string;
+
+       return it->second;
+}
+
+
+} // namespace frontend
+} // namespace lyx
diff --git a/src/frontends/qt4/GuiMath.h b/src/frontends/qt4/GuiMath.h
new file mode 100644 (file)
index 0000000..ed57825
--- /dev/null
@@ -0,0 +1,91 @@
+// -*- C++ -*-
+/**
+ * \file GuiMath.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef GUIMATH_H
+#define GUIMATH_H
+
+#include "GuiDialog.h"
+#include "lfuns.h" // for kb_action
+#include "Font.h"
+
+#include <map>
+
+
+namespace lyx {
+namespace frontend {
+
+struct MathSymbol {
+       MathSymbol(char_type uc = '?', unsigned char fc = 0,
+               Font::FONT_FAMILY ff = Font::SYMBOL_FAMILY)
+               : unicode(uc), fontcode(fc), fontfamily(ff)
+       {}
+       char_type unicode;
+       unsigned char fontcode;
+       Font::FONT_FAMILY fontfamily;
+};
+
+
+class GuiMath : public GuiDialog, public Controller
+{
+public:
+       GuiMath(LyXView & lv, std::string const & name);
+
+       /// Nothing to initialise in this case.
+       bool initialiseParams(std::string const &) { return true; }
+       void clearParams() {}
+       void dispatchParams() {}
+       bool isBufferDependent() const { return true; }
+
+       Controller & controller() { return *this; }
+
+       /// dispatch an LFUN
+       void dispatchFunc(kb_action action,
+               std::string const & arg = std::string()) const;
+       /// Insert a math symbol into the doc.
+       void dispatchInsert(std::string const & name) const;
+       /// Insert a subscript.
+       void dispatchSubscript() const;
+       /// Insert a superscript.
+       void dispatchSuperscript() const;
+       /// Insert a cube root
+       void dispatchCubeRoot() const;
+       /// Insert a matrix
+       void dispatchMatrix(std::string const & str) const;
+       /// Insert a variable size delimiter
+       void dispatchDelim(std::string const & str) const;
+       /// 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.
+        */
+       void showDialog(std::string const & name) const;
+
+       /// \return the math unicode symbol associated to a TeX name.
+       MathSymbol const & mathSymbol(std::string tex_name) const;
+       /// \return the TeX name associated to a math unicode symbol.
+       std::string const & texName(char_type math_symbol) const;
+
+private:
+       /// TeX-name / Math-symbol map.
+       std::map<std::string, MathSymbol> math_symbols_;
+       /// Math-symbol / TeX-name map.
+       /// This one is for fast search, it contains the same data as
+       /// \c math_symbols_.
+       std::map<char_type, std::string> tex_names_;
+};
+
+
+} // namespace frontend
+} // namespace lyx
+
+#endif // GUIMATH_H
index e52500375c1a466cac62241c9f981fd926164175..a2c8fea0404072c2fc30f2e9e389420a379b0d39 100644 (file)
@@ -12,7 +12,6 @@
 
 #include "GuiMathMatrix.h"
 
-#include "ControlMath.h"
 #include "EmptyTable.h"
 #include "qt_helpers.h"
 #include "gettext.h"
@@ -29,12 +28,12 @@ using std::string;
 namespace lyx {
 namespace frontend {
 
-GuiMathMatrixDialog::GuiMathMatrixDialog(LyXView & lv)
-       : GuiDialog(lv, "mathmatrix")
+GuiMathMatrix::GuiMathMatrix(LyXView & lv)
+       : GuiMath(lv, "mathmatrix")
 {
        setupUi(this);
        setViewTitle(_("Math Matrix"));
-       setController(new ControlMath(*this));
+       setController(this, false);
 
        table->setMinimumSize(100, 100);
        rowsSB->setValue(5);
@@ -65,13 +64,7 @@ GuiMathMatrixDialog::GuiMathMatrixDialog(LyXView & lv)
 }
 
 
-ControlMath & GuiMathMatrixDialog::controller()
-{
-       return static_cast<ControlMath &>(GuiDialog::controller());
-}
-
-
-void GuiMathMatrixDialog::columnsChanged(int)
+void GuiMathMatrix::columnsChanged(int)
 {
        char h_align_str[80] = "c";
        int const nx = int(columnsSB->value());
@@ -83,18 +76,18 @@ void GuiMathMatrixDialog::columnsChanged(int)
 }
 
 
-void GuiMathMatrixDialog::rowsChanged(int)
+void GuiMathMatrix::rowsChanged(int)
 {
 }
 
 
-void GuiMathMatrixDialog::change_adaptor()
+void GuiMathMatrix::change_adaptor()
 {
        // FIXME: We need a filter for the halign input
 }
 
 
-void GuiMathMatrixDialog::slotOK()
+void GuiMathMatrix::slotOK()
 {
        char v_align_c[] = "tcb";
        char const c = v_align_c[valignCO->currentIndex()];
@@ -104,18 +97,22 @@ void GuiMathMatrixDialog::slotOK()
 
        ostringstream os;
        os << nx << ' ' << ny << ' ' << c << ' ' << sh;
-       controller().dispatchMatrix(os.str().c_str());
+       dispatchMatrix(os.str().c_str());
 
        // close the dialog
        close();
 }
 
 
-void GuiMathMatrixDialog::slotClose()
+void GuiMathMatrix::slotClose()
 {
        close();
 }
 
+
+Dialog * createGuiMathMatrix(LyXView & lv) { return new GuiMathMatrix(lv); }
+
+
 } // namespace frontend
 } // namespace lyx
 
index e7d5aeb11efddf95cb6d81d32a707a44c3297f43..197581b1a9f33407ec2db9ae74c590f6e49e282f 100644 (file)
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 /**
- * \file GuiMathMatrixDialog.h
+ * \file GuiMathMatrix.h
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
  * Full author contact details are available in file CREDITS.
  */
 
-#ifndef GUIMATHMATRIXDIALOG_H
-#define GUIMATHMATRIXDIALOG_H
+#ifndef GUIMATHMATRIX_H
+#define GUIMATHMATRIX_H
 
-#include "GuiDialog.h"
-#include "ControlMath.h"
+#include "GuiMath.h"
 #include "ui_MathMatrixUi.h"
 
 #include <QDialog>
 namespace lyx {
 namespace frontend {
 
-class GuiMathMatrixDialog : public GuiDialog, public Ui::MathMatrixUi
+class GuiMathMatrix : public GuiMath, public Ui::MathMatrixUi
 {
        Q_OBJECT
 
 public:
-       GuiMathMatrixDialog(LyXView & lv);
+       GuiMathMatrix(LyXView & lv);
 
 public Q_SLOTS:
        void slotOK();
@@ -36,9 +35,6 @@ public Q_SLOTS:
        void columnsChanged(int);
        void rowsChanged(int);
        void change_adaptor();
-
-       /// parent controller
-       ControlMath & controller();
 };
 
 } // namespace frontend
index 00cb552ef1300438e95df1f521df720e0327609b..f87f3d4a87666618288612b4a01d8d0c59490dfb 100644 (file)
@@ -14,6 +14,9 @@
 #ifndef GUIPARAGRAPH_H
 #define GUIPARAGRAPH_H
 
+// Uncomment this if you prefer dock widget
+//#define USE_DOCK_WIDGET
+
 #include "Layout.h"
 #include "ui_ParagraphUi.h"
 #include "Dialog.h"
index 2b3d47ef3f31e2e18698d099b6bdec6078353acb..06e3eedc8404727bf6c1257b18e72c66006f0109 100644 (file)
@@ -37,8 +37,6 @@
 #include "support/lstrings.h"
 #include "support/lyxalgo.h" // sorted
 
-#include "controllers/ControlMath.h"
-
 #include <QComboBox>
 #include <QToolBar>
 #include <QToolButton>
index eda396488def6c5217e1fe9cb7ccf76ad5d377e3..8acf27ae8f8248df94ffb003b121f0a8d3dde2bc 100644 (file)
@@ -88,6 +88,7 @@ SOURCEFILES = \
        GuiKeySymbol.cpp \
        GuiListings.cpp \
        GuiLog.cpp \
+       GuiMath.cpp \
        GuiMathMatrix.cpp \
        GuiMenubar.cpp \
        GuiNomencl.cpp \
@@ -175,6 +176,7 @@ MOCHEADER = \
        GuiKeySymbol.h \
        GuiListings.h \
        GuiLog.h \
+       GuiMath.h \
        GuiMathMatrix.h \
        GuiMenubar.h \
        GuiNomencl.h \