From de1937611811f1a99fc05758125b941c0fa83f4a Mon Sep 17 00:00:00 2001 From: John Spray Date: Tue, 5 Oct 2004 12:37:26 +0000 Subject: [PATCH] Add mathsmatrix dialog. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9048 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/ChangeLog | 5 + src/frontends/gtk/Dialogs.C | 7 +- src/frontends/gtk/GMathsMatrix.C | 144 +++++ src/frontends/gtk/GMathsMatrix.h | 51 ++ src/frontends/gtk/Makefile.am | 3 +- src/frontends/gtk/glade/mathMatrix.glade | 648 +++++++++++++++++++++++ 6 files changed, 854 insertions(+), 4 deletions(-) create mode 100644 src/frontends/gtk/GMathsMatrix.C create mode 100644 src/frontends/gtk/GMathsMatrix.h create mode 100644 src/frontends/gtk/glade/mathMatrix.glade diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index cfa7793fdc..367fc5ba19 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,8 @@ +2004-10-04 John Spray + + * The MathsMatrix dialog + * Dialogs.C, GMathsMatrix.C, GMathsMatrix.h, Makefile.am + 2004-10-04 John Spray * GMenubar.C: use item->submenu() instead of diff --git a/src/frontends/gtk/Dialogs.C b/src/frontends/gtk/Dialogs.C index 2ad6be6ea6..1d15cab602 100644 --- a/src/frontends/gtk/Dialogs.C +++ b/src/frontends/gtk/Dialogs.C @@ -69,7 +69,7 @@ #include "FormLog.h" #include "GMathPanel.h" #include "FormMathsBitmap.h" -#include "FormMathsMatrix.h" +#include "GMathsMatrix.h" #include "FormMathsSpace.h" #include "FormMathsStyle.h" #include "FormNote.h" @@ -432,9 +432,10 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new GMathDelim(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "mathmatrix") { + dialog->bc().view(new GBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); - dialog->setView(new FormMathsMatrix(*dialog)); - dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); + dialog->setView(new GMathsMatrix(*dialog)); + dialog->bc().bp(new OkCancelReadOnlyPolicy); } else if (name == "mathspace") { dialog->setController(new ControlMath(*dialog)); dialog->setView(new FormMathsSpace(*dialog)); diff --git a/src/frontends/gtk/GMathsMatrix.C b/src/frontends/gtk/GMathsMatrix.C new file mode 100644 index 0000000000..a968c0b2a8 --- /dev/null +++ b/src/frontends/gtk/GMathsMatrix.C @@ -0,0 +1,144 @@ +/** + * \file GMathsMatrix.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Spray + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "GMathsMatrix.h" +#include "ControlMath.h" + +#include "GViewBase.h" +#include "ghelpers.h" + +#include + + +using std::ostringstream; +using std::string; + +namespace lyx { +namespace frontend { + + +GMathsMatrix::GMathsMatrix(Dialog & parent) + : GViewCB(parent, _("Math Matrix"), false) +{} + + +void GMathsMatrix::doBuild() +{ + string const gladeName = findGladeFile("mathMatrix"); + xml_ = Gnome::Glade::Xml::create(gladeName); + + Gtk::Button * button; + xml_->get_widget("Cancel",button); + setCancel(button); + xml_->get_widget("Insert",button); + setOK(button); + // No inserting matrices into readonly docs! + bcview().addReadOnly(button); + + // Get widget pointers + xml_->get_widget("Top", topradio_); + xml_->get_widget("Bottom", bottomradio_); + xml_->get_widget("Center", centerradio_); + xml_->get_widget("Columns", columnsspin_); + xml_->get_widget("Rows", rowsspin_); + xml_->get_widget("HorzAlign", horzalignentry_); + + // Make center vertical alignment the default + centerradio_->set_active(true); + + // Allow only [clr], keep length as number of cols + ignoreHorzAlign_ = false; + horzalignentry_->signal_changed().connect( + sigc::mem_fun(*this, &GMathsMatrix::updateHorzAlignEntry)); + columnsspin_->signal_value_changed().connect( + sigc::mem_fun(*this, &GMathsMatrix::updateHorzAlignEntry)); +} + + +void GMathsMatrix::apply() +{ + string const h_align = horzalignentry_->get_text(); + int const nx = + static_cast(columnsspin_->get_adjustment()->get_value()); + int const ny = + static_cast(rowsspin_->get_adjustment()->get_value()); + char v_align = 'c'; + if (topradio_->get_active()) + v_align = 't'; + else if (centerradio_->get_active()) + v_align = 'c'; + else if (bottomradio_->get_active()) + v_align = 'b'; + + ostringstream os; + os << nx << ' ' << ny << ' ' << v_align << ' ' << h_align; + controller().dispatchMatrix(os.str()); +} + + +void GMathsMatrix::update() +{ + ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID; + bc().input(activate); +} + + +void GMathsMatrix::updateHorzAlignEntry() +{ + if (ignoreHorzAlign_) return; + + Glib::ustring orig = horzalignentry_->get_text(); + Glib::ustring stripped; + + Glib::ustring::iterator cur; + for (cur = orig.begin(); cur != orig.end(); ++cur) { + if (*cur == 'c' || *cur == 'l' || + *cur == 'r' || *cur == '|') + stripped += *cur; + } + + int barcount = countbars(stripped); + while (stripped.length() - barcount > + columnsspin_->get_adjustment()->get_value()) { + // erase last character of stripped + stripped = stripped.erase(stripped.length() - 1,1); + barcount = countbars(stripped); + } + + while (stripped.length() - barcount < + columnsspin_->get_adjustment()->get_value()) { + stripped = stripped + "c"; + barcount = countbars(stripped); + } + + if (orig.compare(stripped) != 0) { + ignoreHorzAlign_ = true; + horzalignentry_->set_text(stripped); + ignoreHorzAlign_ = false; + } +} + +int GMathsMatrix::countbars(Glib::ustring str) +{ + int barcount = 0; + Glib::ustring::iterator cur = str.begin(); + Glib::ustring::iterator end = str.end(); + for (; cur != end; ++cur) { + if (*cur == '|') + ++barcount; + } + return barcount; +} + + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/gtk/GMathsMatrix.h b/src/frontends/gtk/GMathsMatrix.h new file mode 100644 index 0000000000..643e3e2833 --- /dev/null +++ b/src/frontends/gtk/GMathsMatrix.h @@ -0,0 +1,51 @@ +// -*- C++ -*- +/** + * \file GMathsMatrix.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author John Spray + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef GMATHSMATRIX_H +#define GMATHSMATRIX_H + +#include "GViewBase.h" + +namespace lyx { +namespace frontend { + +class ControlMath; + +/** + * This class provides an GTK implementation of the maths matrix dialog. + */ +class GMathsMatrix + : public GViewCB { +public: + GMathsMatrix(Dialog &); + int AlignFilter(char const *, int); +private: + virtual void apply(); + virtual void doBuild(); + virtual void update(); + + void updateHorzAlignEntry(); + int countbars(Glib::ustring str); + + Gtk::RadioButton * topradio_; + Gtk::RadioButton * bottomradio_; + Gtk::RadioButton * centerradio_; + Gtk::SpinButton * rowsspin_; + Gtk::SpinButton * columnsspin_; + Gtk::Entry * horzalignentry_; + bool ignoreHorzAlign_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // GMATHSMATRIX_H + diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index f7e43aa728..4c14451910 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -32,6 +32,8 @@ libgtk_la_SOURCES = \ GMathDelim.h \ GMathPanel.C \ GMathPanel.h \ + GMathsMatrix.C \ + GMathsMatrix.h \ GMenubar.C \ GMenubar.h \ GMiniBuffer.C \ @@ -109,7 +111,6 @@ xforms_objects = \ ../xforms/FormLog.lo \ ../xforms/FormMathsBitmap.lo \ ../xforms/FormMathsDelim.lo \ - ../xforms/FormMathsMatrix.lo \ ../xforms/FormMathsSpace.lo \ ../xforms/FormMathsStyle.lo \ ../xforms/FormNote.lo \ diff --git a/src/frontends/gtk/glade/mathMatrix.glade b/src/frontends/gtk/glade/mathMatrix.glade new file mode 100644 index 0000000000..bc9779b979 --- /dev/null +++ b/src/frontends/gtk/glade/mathMatrix.glade @@ -0,0 +1,648 @@ + + + + + + + 6 + True + Create Matrix + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + True + GTK_RELIEF_NORMAL + True + 0 + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-new + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Insert Matrix + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + 2 + 3 + False + 6 + 0 + + + + True + C_olumns: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + Columns + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + True + 1 + 0 + True + GTK_UPDATE_ALWAYS + False + False + 2 1 20 1 10 10 + + + 1 + 2 + 1 + 2 + expand + + + + + + + True + True + True + 1 + 0 + True + GTK_UPDATE_ALWAYS + False + False + 2 1 20 1 10 10 + + + 1 + 2 + 0 + 1 + + + + + + + + True + _Rows: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + Rows + + + 0 + 1 + 0 + 1 + fill + + + + + + + + + + + True + <b>Size</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + label_item + + + + + 0 + True + True + + + + + + 4 + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + False + 0 + + + + True + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-goto-top + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Top + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + + 0 + False + False + + + + + + True + True + GTK_RELIEF_NORMAL + True + True + False + True + Top + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-justify-center + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + C_enter + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + + 0 + False + False + + + + + + True + True + GTK_RELIEF_NORMAL + True + False + False + True + Top + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-goto-bottom + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Bottom + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + + 0 + False + False + + + + + + + + + + True + <b>Vertical Alignment</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + label_item + + + + + 0 + True + True + + + + + + 4 + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + 5 + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + True + True + True + 0 + cc + True + * + False + + + + + + + + True + <b>_Horizontal Alignment</b> + True + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + HorzAlign + + + label_item + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + + -- 2.39.2