Hi, Mathsmatrix dialog attached. I'm deeply unhappy with the whole "ccrlrl|c" thing for setting horizontal alignments, but it's not a big enough priority right now. Some kind of table of radio buttons would be in order if/when I eventually revisit this.
Lars: you suggested to cvs add new files and then include them in the diff, but when I try this: $touch foo $cvs add foo $cvs diff cvs server: foo is a new entry, no comparison available John
Index: ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/ChangeLog,v
retrieving revision 1.67
diff -u -3 -p -r1.67 ChangeLog
--- ChangeLog 2004/10/04 11:32:34 1.67
+++ ChangeLog 2004/10/04 13:59:28
@@ -1,5 +1,10 @@
2004-10-04 John Spray <[EMAIL PROTECTED]>
+ * The MathsMatrix dialog
+ * Dialogs.C, GMathsMatrix.C, GMathsMatrix.h, Makefile.am
+
+2004-10-04 John Spray <[EMAIL PROTECTED]>
+
* GMenubar.C: use item->submenu() instead of
getMenu(item->submenuname) where item->submenuname is empty.
Fixes crash with "Figures" submenu.
Index: Dialogs.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/Dialogs.C,v
retrieving revision 1.23
diff -u -3 -p -r1.23 Dialogs.C
--- Dialogs.C 2004/10/02 16:17:21 1.23
+++ Dialogs.C 2004/10/04 13:59:28
@@ -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
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));
Index: Makefile.am
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/Makefile.am,v
retrieving revision 1.21
diff -u -3 -p -r1.21 Makefile.am
--- Makefile.am 2004/10/02 16:17:21 1.21
+++ Makefile.am 2004/10/04 13:59:28
@@ -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 \
/**
* \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 <config.h>
#include "GMathsMatrix.h"
#include "ControlMath.h"
#include "GViewBase.h"
#include "ghelpers.h"
#include <sstream>
using std::ostringstream;
using std::string;
namespace lyx {
namespace frontend {
GMathsMatrix::GMathsMatrix(Dialog & parent)
: GViewCB<ControlMath, GViewGladeB>(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<int>(columnsspin_->get_adjustment()->get_value());
int const ny =
static_cast<int>(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
// -*- 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<ControlMath, GViewGladeB> {
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
mathMatrix.glade
Description: application/glade
