]> git.lyx.org Git - features.git/commitdiff
The Box patch
authorMartin Vermeer <martin.vermeer@hut.fi>
Tue, 7 Oct 2003 07:42:15 +0000 (07:42 +0000)
committerMartin Vermeer <martin.vermeer@hut.fi>
Tue, 7 Oct 2003 07:42:15 +0000 (07:42 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7865 a592a061-630c-0410-9148-cb99ea01b6c8

26 files changed:
lib/ChangeLog
lib/ui/stdmenus.ui
po/POTFILES.in
src/ChangeLog
src/LaTeXFeatures.C
src/LyXAction.C
src/factory.C
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlBox.C [new file with mode: 0644]
src/frontends/controllers/ControlBox.h [new file with mode: 0644]
src/frontends/controllers/Makefile.am
src/frontends/xforms/ChangeLog
src/frontends/xforms/Dialogs.C
src/frontends/xforms/FormBox.C [new file with mode: 0644]
src/frontends/xforms/FormBox.h [new file with mode: 0644]
src/frontends/xforms/Makefile.am
src/frontends/xforms/forms/Makefile.am
src/frontends/xforms/forms/form_box.fd [new file with mode: 0644]
src/insets/ChangeLog
src/insets/Makefile.am
src/insets/inset.h
src/insets/insetbox.C [new file with mode: 0644]
src/insets/insetbox.h [new file with mode: 0644]
src/lfuns.h
src/lyxfunc.C
src/text3.C

index c1544b9cf92c0646ecc8abebca0e9c9304d148c3..64b14e9b3eab0c4c5ae3141e37beb9eefc731744 100644 (file)
@@ -1,3 +1,8 @@
+2003-10-07  Martin Vermeer  <martin.vermeer@hut.fi>
+
+       * ui/stdmenus.ui: The Box patch. Fancybox support, minipage,
+       parbox
+
 2003-10-06  José Matoa  <jamatos@lyx.org>
 
        * lyxrevert_223.py: finish support for change tracking revert.
index 365d6dd6553b99d0030c003c40ebf528d9af8fed..0fe3ee181a751b99cbdd6efd2692eac18f17de35 100644 (file)
@@ -101,10 +101,10 @@ Menuset
                OptItem "TeX Code Settings...|C" "inset-settings ert"
 # 'a' shortcut to match Insert entry, shouldn't clash with Table Settings
                OptItem "Float Settings...|a" "inset-settings float"
-               OptItem "Minipage Settings...|M" "inset-settings minipage"
                OptItem "Text Wrap Settings...|W" "inset-settings wrap"
                OptItem "Note Settings...|N" "inset-settings note"
                OptItem "Branch Settings...|B" "inset-settings branch"
+               OptItem "Box Settings...|x" "inset-settings box"
 # Hey, guess what's broken ? Surprise surprise, it's tabular stuff
 # This is in the Table submenu instead for now.
 #      OptItem "Table Settings...|a" "inset-settings tabular"
@@ -229,6 +229,7 @@ Menuset
                Submenu "Float|a" "insert_float"
 # YUCK
                Submenu "Note|N" "insert_note"
+               Submenu "Box" "insert_box"
                Submenu "Branch|B" "branches"
                Submenu "File|e" "insert_file"
                Separator
@@ -243,7 +244,6 @@ Menuset
                Item "URL...|U" "url-insert"
                Item "Footnote|F" "footnote-insert"
                Item "Marginal Note|M" "marginalnote-insert"
-               Item "Minipage|p" "minipage-insert"
                Item "Short Title" "optional-insert"
                Item "TeX|X" "ert-insert"
        End
@@ -339,6 +339,15 @@ Menuset
                Item "Greyed Out|G" "note-insert Greyedout"
        End
 
+       Menu "insert_box"
+               Item "Frameless|F" "box-insert Frameless"
+               Item "Boxed|B" "box-insert Boxed"
+               Item "Oval Box|O" "box-insert ovalbox"
+               Item "Oval Box, Thick|T" "box-insert Ovalbox"
+               Item "Shadow Box|S" "box-insert Shadowbox"
+               Item "Double Box|D" "box-insert Doublebox"
+       End
+
        Menu "branches"
                Branches
        End
index db0888f6ce3ffe6d334529f6182f00bc113b144e..ef9083a9b7b5c2dcee8462c1c7d6927ddfbf3e10 100644 (file)
@@ -18,6 +18,7 @@ src/format.C
 src/frontends/LyXView.C
 src/frontends/controllers/ControlAboutlyx.C
 src/frontends/controllers/ControlBibtex.C
+src/frontends/controllers/ControlBox.C
 src/frontends/controllers/ControlDocument.C
 src/frontends/controllers/ControlExternal.C
 src/frontends/controllers/ControlGraphics.C
@@ -93,6 +94,7 @@ src/frontends/xforms/FormAboutlyx.C
 src/frontends/xforms/FormBase.C
 src/frontends/xforms/FormBibitem.C
 src/frontends/xforms/FormBibtex.C
+src/frontends/xforms/FormBox.C
 src/frontends/xforms/FormBranch.C
 src/frontends/xforms/FormChanges.C
 src/frontends/xforms/FormCharacter.C
@@ -142,6 +144,7 @@ src/gettext.h
 src/importer.C
 src/insets/inset.C
 src/insets/insetbibtex.C
+src/insets/insetbox.C
 src/insets/insetbranch.C
 src/insets/insetcaption.C
 src/insets/insetenv.C
@@ -185,6 +188,7 @@ src/mathed/ref_inset.C
 src/paragraph.C
 src/paragraph_funcs.C
 src/rowpainter.C
+src/support/path_defines.C
 src/text.C
 src/text2.C
 src/text3.C
index 894061399f8ef9b0555bd4cf73682eb04210ac14..16ecf46cb1ef8cfa24d2a101111418c5c4cfb773 100644 (file)
@@ -1,4 +1,13 @@
-<<<<<<< ChangeLog
+
+2003-10-07  Martin Vermeer <martin.vermeer@hut.fi>
+
+       * LaTeXFeatures.C:
+       * LyXAction.C:
+       * factory.C:
+       * lfuns.h:
+       * lyxfunc.C:
+       * text3.C: The Box patch. Fancybox support, minipage, parbox
+
 2003-10-07  Martin Vermeer <martin.vermeer@hut.fi>
 
        * CutAndPaste.h:
index b70b7decc3bd2c30121f78351f05b251fbbb4ae7..bd891b5b764b2b3408df0bc77a06f6f6deac638e 100644 (file)
@@ -189,7 +189,9 @@ char const * simplefeatures[] = {
        "prettyref",
        "float",
        "wasy",
-       "dvipost"
+       "dvipost",
+       "fancybox",
+       "calc"
 };
 
 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
index ff0c40e1f24f41d599f21f8f645475930738ac1f..c1845026170ac883a18c36c2539a6c50e99e86fc 100644 (file)
@@ -225,6 +225,7 @@ void LyXAction::init()
                { LFUN_INSET_MINIPAGE, "minipage-insert", Noop },
                { LFUN_INSERT_BRANCH, "branch-insert", Noop },
                { LFUN_INSERT_NOTE, "note-insert", Noop },
+               { LFUN_INSERT_BOX, "box-insert", Noop },
                { LFUN_GOTONOTE, "note-next", ReadOnly },
                { LFUN_INSET_TOGGLE, "inset-toggle", ReadOnly },
                { LFUN_DOWN_PARAGRAPH, "paragraph-down", ReadOnly },
index eca35ef59d489f1e0d3f8900785e73cee1c35ddd..f02653dfbd8a3653930ffee3e83f76ebc7d18fe5 100644 (file)
@@ -39,6 +39,7 @@
 #include "insets/insetmarginal.h"
 #include "insets/insetminipage.h"
 #include "insets/insetnote.h"
+#include "insets/insetbox.h"
 #include "insets/insetbranch.h"
 #include "insets/insetoptarg.h"
 #include "insets/insetref.h"
@@ -82,6 +83,13 @@ InsetOld * createInset(FuncRequest const & cmd)
                                arg = "Note";
                        return new InsetNote(params, arg);
                }
+       case LFUN_INSERT_BOX:
+               {
+                       string arg = cmd.getArg(0);
+                       if (arg.empty())
+                               arg = "Boxed";
+                       return new InsetBox(params, arg);
+               }
        case LFUN_INSERT_BRANCH:
                {
                        string arg = cmd.getArg(0);
@@ -375,6 +383,10 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
                } else if (tmptok == "Note"     || tmptok == "Comment"
                                || tmptok == "Greyedout") {
                        inset = new InsetNote(buf.params(), tmptok);
+               } else if (tmptok == "Boxed" || tmptok == "ovalbox"
+                       || tmptok == "Shadowbox" || tmptok == "Doublebox"
+                       || tmptok == "Ovalbox" || tmptok == "Frameless") {
+                       inset = new InsetBox(buf.params(), tmptok);
                } else if (tmptok == "Branch") {
                        inset = new InsetBranch(buf.params(), string());
                } else if (tmptok == "Include") {
index 59d86fefad0630b3fe381b197fc267ded01850f0..b5fa09f7f99d7ecbc9771734df0e3d089583e92e 100644 (file)
@@ -1,3 +1,9 @@
+2003-10-07  Martin Vermeer  <martin.vermeer@hut.fi>
+
+       * ControlBox.C:
+       * ControlBox.h:
+       * Makefile.am: The Box patch. Fancybox support, minipage, parbox
+
 2003-10-07  Martin Vermeer  <martin.vermeer@hut.fi>
 
        * BCView.h:
diff --git a/src/frontends/controllers/ControlBox.C b/src/frontends/controllers/ControlBox.C
new file mode 100644 (file)
index 0000000..93e4de9
--- /dev/null
@@ -0,0 +1,82 @@
+/**
+ * \file ControlBox.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Martin Vermeer (with useful hints from Angus Leeming)
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "ControlBox.h"
+#include "funcrequest.h"
+#include "insets/insetbox.h"
+#include "gettext.h"
+
+
+using std::string;
+using std::vector;
+
+
+ControlBox::ControlBox(Dialog & parent)
+       : Dialog::Controller(parent)
+{}
+
+
+bool ControlBox::initialiseParams(string const & data)
+{
+       InsetBoxParams params("");
+       InsetBoxMailer::string2params(data, params);
+       params_.reset(new InsetBoxParams(params));
+
+       return true;
+
+}
+
+
+void ControlBox::clearParams()
+{
+       params_.reset();
+}
+
+
+void ControlBox::dispatchParams()
+{
+       string const lfun = InsetBoxMailer::params2string(params());
+       kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
+}
+
+
+void box_gui_tokens(vector<string> & ids, vector<string> & gui_names)
+{
+       char const * const ids_[] = {
+               "Frameless", "Boxed", "ovalbox", 
+               "Ovalbox", "Shadowbox", "Doublebox"};
+       size_t const ids_size = sizeof(ids_) / sizeof(char *);
+       ids = vector<string>(ids_, ids_ + ids_size);
+       gui_names.clear();
+       gui_names.push_back(_("No frame drawn"));
+       gui_names.push_back(_("Rectangular box"));
+       gui_names.push_back(_("Oval box, thin"));
+       gui_names.push_back(_("Oval box, thick"));
+       gui_names.push_back(_("Shadow box"));
+       gui_names.push_back(_("Double box"));
+}
+
+void box_gui_tokens_special_length(vector<string> & ids, 
+       vector<string> & gui_names)
+{
+       char const * const ids_[] = {
+               "none", "height", "depth", 
+               "totalheight", "width"};
+       size_t const ids_size = sizeof(ids_) / sizeof(char *);
+       ids = vector<string>(ids_, ids_ + ids_size);
+       gui_names.clear();
+       gui_names.push_back(_("None"));
+       gui_names.push_back(_("Height"));
+       gui_names.push_back(_("Depth"));
+       gui_names.push_back(_("Total Height"));
+       gui_names.push_back(_("Width"));
+}
diff --git a/src/frontends/controllers/ControlBox.h b/src/frontends/controllers/ControlBox.h
new file mode 100644 (file)
index 0000000..8d9dd97
--- /dev/null
@@ -0,0 +1,49 @@
+// -*- C++ -*-
+/**
+ * \file ControlBox.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Martin Vermeer (with useful hints from Angus Leeming)
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef CONTROLBOX_H
+#define CONTROLBOX_H
+
+
+#include "Dialog.h"
+#include <vector>
+
+class InsetBoxParams;
+
+class ControlBox : public Dialog::Controller {
+public:
+       ///
+       ControlBox(Dialog &);
+       ///
+       virtual bool initialiseParams(std::string const & data);
+       ///
+       virtual void clearParams();
+       ///
+       virtual void dispatchParams();
+       ///
+       virtual bool isBufferDependent() const { return true; }
+       ///
+       InsetBoxParams & params() { return *params_.get(); }
+       ///
+       InsetBoxParams const & params() const { return *params_.get(); }
+       ///
+private:
+       ///
+       boost::scoped_ptr<InsetBoxParams> params_;
+};
+
+///
+void box_gui_tokens(std::vector<std::string> &, std::vector<std::string> &);
+///
+void box_gui_tokens_special_length(std::vector<std::string> &, 
+       std::vector<std::string> &);
+
+#endif // CONTROLBOX_H
index 89fea1c2d903ed4b72afe52799a11217ff352278..770c03de90a351b1bffec5994861a5b45f4f25f4 100644 (file)
@@ -31,6 +31,8 @@ libcontrollers_la_SOURCES= \
        ControlBibtex.h \
        ControlButtons.C \
        ControlButtons.h \
+       ControlBox.C \
+       ControlBox.h \
        ControlBranch.C \
        ControlBranch.h \
        ControlCharacter.C \
index 3ff9055c845e90397d0e34bb6458b686fe5c0f36..6b3b4813f09264c0f8943fd5443529fcbcc135b7 100644 (file)
@@ -1,3 +1,13 @@
+2003-10-07  Martin Vermeer  <martin.vermeer@hut.fi>
+
+       * Dialogs.C:
+       * FormBox.C:
+       * FormBox.h:
+       * Makefile.am:
+       * forms/Makefile.am:
+       * forms/form_box.fd: The Box patch. Fancybox support, minipage,
+       parbox
+
 2003-10-01  Angus Leeming  <leeming@lyx.org>
 
        * FormExternal.C (updateComboChange): changes due to the
index 66d3c43dd40106d910366f9c270f2cb06e42218b..71ee5280de1bd3ed578ae95685744042ca3acd31 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "ControlAboutlyx.h"
 #include "ControlBibtex.h"
+#include "ControlBox.h"
 #include "ControlBranch.h"
 #include "ControlChanges.h"
 #include "ControlCitation.h"
@@ -41,6 +42,7 @@
 #include "FormAboutlyx.h"
 #include "FormBibitem.h"
 #include "FormBibtex.h"
+#include "FormBox.h"
 #include "FormBranch.h"
 #include "FormChanges.h"
 #include "FormCharacter.h"
@@ -109,7 +111,8 @@ FormMathsBitmap * createFormBitmap(Dialog & parent, string const & title,
 }
 
 
-char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "branch", "changes",
+char const * const dialognames[] = { 
+"aboutlyx", "bibitem", "bibtex", "branch", "box", "changes",
 "character", "citation", "error", "errorlist" , "ert", "external", "file",
 "float", "graphics", "include", "index", "label", "latexlog", "mathpanel",
 "mathaccents", "matharrows", "mathoperators", "mathrelations", "mathgreek",
@@ -410,6 +413,10 @@ Dialog * Dialogs::build(string const & name)
                dialog->setController(new ControlNote(*dialog));
                dialog->setView(new FormNote(*dialog));
                dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
+       } else if (name == "box") {
+               dialog->setController(new ControlBox(*dialog));
+               dialog->setView(new FormBox(*dialog));
+               dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
        } else if (name == "branch") {
                dialog->setController(new ControlBranch(*dialog));
                dialog->setView(new FormBranch(*dialog));
diff --git a/src/frontends/xforms/FormBox.C b/src/frontends/xforms/FormBox.C
new file mode 100644 (file)
index 0000000..333e6cd
--- /dev/null
@@ -0,0 +1,288 @@
+/**
+ * \file FormBox.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Jürgen Vigna (Minipage stuff)
+ * \author Martin Vermeer
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "FormBox.h"
+#include "ControlBox.h"
+#include "forms/form_box.h"
+#include "controllers/ButtonPolicies.h"
+#include "controllers/helper_funcs.h"
+#include "support/lstrings.h"
+#include "support/tostr.h"
+
+#include "Tooltips.h"
+#include "xforms_helpers.h"
+#include "xformsBC.h"
+
+#include "insets/insetbox.h"
+
+#include "lyx_forms.h"
+#include "debug.h"
+
+#include <vector>
+
+using lyx::support::getStringFromVector;
+using lyx::support::isStrDbl;
+using lyx::support::subst;
+using std::string;
+
+
+typedef FormController<ControlBox, FormView<FD_box> > base_class;
+
+FormBox::FormBox(Dialog & parent)
+       : base_class(parent, _("Box"))
+{}
+
+
+void FormBox::build()
+{
+       dialog_.reset(build_box(this));
+
+       box_gui_tokens(ids_, gui_names_);
+
+       for (unsigned int i = 0; i < gui_names_.size(); ++i) {
+               fl_addto_choice(dialog_->choice_type, gui_names_[i].c_str());
+       }
+
+       string str = _("Frameless: No border\n"
+                      "Boxed: Rectangular\n"
+                      "ovalbox: Oval, thin border\n"
+                      "Ovalbox: Oval, thick border\n"
+                      "Shadowbox: Box casting shadow\n"
+                      "Doublebox: Double line border");
+       tooltips().init(dialog_->choice_type, str);
+
+       bcview().addReadOnly(dialog_->check_inner_box);
+
+       str = _("The inner box may be a parbox or a minipage,\n"
+               "with appropriate arguments from this dialog.");
+       tooltips().init(dialog_->check_inner_box, str);
+
+       bcview().addReadOnly(dialog_->radio_parbox);
+       bcview().addReadOnly(dialog_->radio_minipage);
+
+       bcview().addReadOnly(dialog_->choice_pos);
+       fl_addto_choice(dialog_->choice_pos, _("top").c_str());
+       fl_addto_choice(dialog_->choice_pos, _("middle").c_str());
+       fl_addto_choice(dialog_->choice_pos, _("bottom").c_str());
+
+       bcview().addReadOnly(dialog_->choice_inner_pos);
+       fl_addto_choice(dialog_->choice_inner_pos, _("top").c_str());
+       fl_addto_choice(dialog_->choice_inner_pos, _("middle").c_str());
+       fl_addto_choice(dialog_->choice_inner_pos, _("bottom").c_str());
+       fl_addto_choice(dialog_->choice_inner_pos, _("stretch").c_str());
+
+       bcview().addReadOnly(dialog_->choice_hor_pos);
+       fl_addto_choice(dialog_->choice_hor_pos, _("left").c_str());
+       fl_addto_choice(dialog_->choice_hor_pos, _("center").c_str());
+       fl_addto_choice(dialog_->choice_hor_pos, _("right").c_str());
+       fl_addto_choice(dialog_->choice_hor_pos, _("stretch").c_str());
+
+       bcview().addReadOnly(dialog_->input_width);
+       bcview().addReadOnly(dialog_->choice_width_unit);
+       bcview().addReadOnly(dialog_->choice_special);
+
+       box_gui_tokens_special_length(ids_spec_, gui_names_spec_);
+       for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) {
+               fl_addto_choice(dialog_->choice_special, gui_names_spec_[i].c_str());
+       }
+
+       string choice = getStringFromVector(getLatexUnits(), "|");
+       fl_addto_choice(dialog_->choice_width_unit, 
+               subst(choice, "%", "%%").c_str());
+
+       bcview().addReadOnly(dialog_->input_height);
+       bcview().addReadOnly(dialog_->choice_height_unit);
+       bcview().addReadOnly(dialog_->choice_height_special);
+       for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) {
+               fl_addto_choice(dialog_->choice_height_special, 
+                       gui_names_spec_[i].c_str());
+       }
+
+       choice = getStringFromVector(getLatexUnits(), "|");
+       fl_addto_choice(dialog_->choice_height_unit, 
+               subst(choice, "%", "%%").c_str());
+
+       bcview().setOK(dialog_->button_ok);
+       bcview().setApply(dialog_->button_apply);
+       bcview().setCancel(dialog_->button_cancel);
+}
+
+
+void FormBox::update()
+{
+       string type(controller().params().type);
+       for (unsigned int i = 0; i < gui_names_.size(); ++i) {
+               if (type == ids_[i])
+                       fl_set_choice_text(dialog_->choice_type, gui_names_[i].c_str());
+               }
+
+       fl_set_button(dialog_->check_inner_box, controller().params().inner_box);
+       if (controller().params().type == "Frameless")
+               setEnabled(dialog_->check_inner_box, false);
+
+       char c = controller().params().pos;
+       fl_set_choice(dialog_->choice_pos, string("tcb").find(c, 0) + 1);
+       c = controller().params().inner_pos;
+       fl_set_choice(dialog_->choice_inner_pos, string("tcbs").find(c, 0) + 1);
+       c = controller().params().hor_pos;
+       fl_set_choice(dialog_->choice_hor_pos, string("lcrs").find(c, 0) + 1);
+       setEnabled(dialog_->choice_pos, controller().params().inner_box);
+       setEnabled(dialog_->choice_inner_pos, controller().params().inner_box);
+       setEnabled(dialog_->choice_hor_pos, !controller().params().inner_box);
+
+       fl_set_button(dialog_->radio_parbox,    controller().params().use_parbox);
+       fl_set_button(dialog_->radio_minipage, !controller().params().use_parbox);
+       setEnabled(dialog_->radio_parbox, controller().params().inner_box);
+       setEnabled(dialog_->radio_minipage, controller().params().inner_box);
+
+       LyXLength len(controller().params().width);
+       fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
+       fl_set_choice(dialog_->choice_width_unit, len.unit() + 1);
+       string special(controller().params().special);
+       for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) {
+               if (special == ids_spec_[i])
+                       fl_set_choice_text(dialog_->choice_special, 
+                               gui_names_spec_[i].c_str());
+               }
+       // Special width unit must be default for general units to be enabled
+       if(controller().params().special != "none")
+               setEnabled(dialog_->choice_width_unit, false);
+       setEnabled(dialog_->choice_special, !controller().params().inner_box);
+
+       LyXLength ht(controller().params().height);
+       fl_set_input(dialog_->input_height, tostr(ht.value()).c_str());
+       fl_set_choice(dialog_->choice_height_unit, ht.unit() + 1);
+       string const height_special(controller().params().height_special);
+       for (unsigned int i = 0; i < gui_names_spec_.size(); ++i) {
+               if (height_special == ids_spec_[i])
+                       fl_set_choice_text(dialog_->choice_height_special, 
+                               gui_names_spec_[i].c_str());
+               }
+       setEnabled(dialog_->input_height, controller().params().inner_box);
+       setEnabled(dialog_->choice_height_unit, controller().params().inner_box);
+       setEnabled(dialog_->choice_height_special, controller().params().inner_box);
+       // Same here
+       if(height_special != "none")
+               setEnabled(dialog_->choice_height_unit, false);
+}
+
+
+void FormBox::apply()
+{
+       int i = fl_get_choice(dialog_->choice_type);
+       controller().params().type = ids_[i - 1];
+
+       controller().params().inner_box = fl_get_button(dialog_->check_inner_box);
+       controller().params().use_parbox = 
+               fl_get_button(dialog_->radio_parbox);
+       controller().params().width =
+               LyXLength(getLengthFromWidgets(dialog_->input_width,
+               dialog_->choice_width_unit));
+       
+       controller().params().pos =
+               "tcb"[fl_get_choice(dialog_->choice_pos) - 1];
+       controller().params().inner_pos =
+               "tcbs"[fl_get_choice(dialog_->choice_inner_pos) - 1];
+       controller().params().hor_pos =
+               "lcrs"[fl_get_choice(dialog_->choice_hor_pos) - 1];
+       
+       i = fl_get_choice(dialog_->choice_special);     
+       controller().params().special = ids_spec_[i - 1];
+       
+       controller().params().height =
+               LyXLength(getLengthFromWidgets(dialog_->input_height,
+               dialog_->choice_height_unit));
+       i = fl_get_choice(dialog_->choice_height_special);      
+       controller().params().height_special = ids_spec_[i - 1];
+}
+
+ButtonPolicy::SMInput FormBox::input(FL_OBJECT * ob, long)
+{
+       if (ob == dialog_->check_inner_box) {
+               setEnabled(dialog_->choice_pos, 
+                       fl_get_button(dialog_->check_inner_box));
+               setEnabled(dialog_->radio_parbox, 
+                       fl_get_button(dialog_->check_inner_box));
+               setEnabled(dialog_->radio_minipage, 
+                       fl_get_button(dialog_->check_inner_box));
+               setEnabled(dialog_->choice_width_unit, true);
+               setEnabled(dialog_->choice_special, 
+                       !fl_get_button(dialog_->check_inner_box));
+               setEnabled(dialog_->input_height,
+                       fl_get_button(dialog_->check_inner_box));
+               setEnabled(dialog_->choice_height_unit,
+                       fl_get_button(dialog_->check_inner_box));
+               setEnabled(dialog_->choice_height_special, 
+                       fl_get_button(dialog_->check_inner_box));
+               setEnabled(dialog_->choice_hor_pos,
+                       !fl_get_button(dialog_->check_inner_box));
+               setEnabled(dialog_->choice_inner_pos,
+                       fl_get_button(dialog_->check_inner_box));
+
+               // Reset to defaults to not confuse users:
+               if (fl_get_button(dialog_->check_inner_box))
+                       fl_set_choice(dialog_->choice_special, NONE);
+               else
+                       fl_set_choice(dialog_->choice_height_special, NONE);
+       }
+
+       if (ob == dialog_->choice_special || ob == dialog_->check_inner_box)
+               setEnabled(dialog_->choice_width_unit, 
+                       fl_get_choice(dialog_->choice_special) == NONE);
+       if (ob == dialog_->choice_height_special || ob == dialog_->check_inner_box)
+               if (fl_get_choice(dialog_->choice_height_special) != NONE)
+                   setEnabled(dialog_->choice_height_unit, false);
+               else
+                   setEnabled(dialog_->choice_height_unit, 
+                               fl_get_button(dialog_->check_inner_box));
+       
+       // An inner box (parbox, minipage) is mandatory if no outer box
+       if (ob == dialog_->choice_type) {
+               int i = fl_get_choice(dialog_->choice_type);
+               if (ids_[i - 1] == "Frameless") {
+                       setEnabled(dialog_->check_inner_box, false);
+                       fl_set_button(dialog_->check_inner_box, true);
+               } else {
+                       setEnabled(dialog_->check_inner_box, true);
+               }
+       }
+       // disallow senseless data, warnings if input is senseless
+       if (ob == dialog_->input_width) {
+               string const input = getString(dialog_->input_width);
+               bool const invalid = !isValidLength(input) && !isStrDbl(input);
+               if (invalid) {
+                       postWarning(_("Invalid Length!"));
+                       return ButtonPolicy::SMI_INVALID;
+               } 
+       }
+       if (ob == dialog_->input_height) {
+               string const input = getString(dialog_->input_height);
+               bool const invalid = !isValidLength(input) && !isStrDbl(input);
+               if (invalid) {
+                       postWarning(_("Invalid Length!"));
+                       return ButtonPolicy::SMI_INVALID;
+               } 
+       }
+       if (ob == dialog_->button_defaults) {
+               fl_set_button(dialog_->check_inner_box, true);  
+               fl_set_button(dialog_->radio_parbox, false);
+               fl_set_input(dialog_->input_width, "100");
+               fl_set_choice(dialog_->choice_width_unit, LyXLength::PCW + 1);
+               fl_set_choice(dialog_->choice_special, NONE);
+               fl_set_input(dialog_->input_height, "1");
+               fl_set_choice(dialog_->choice_height_special, TOTALHEIGHT);
+       }
+       
+       return ButtonPolicy::SMI_VALID;
+}
+
diff --git a/src/frontends/xforms/FormBox.h b/src/frontends/xforms/FormBox.h
new file mode 100644 (file)
index 0000000..0bdc218
--- /dev/null
@@ -0,0 +1,55 @@
+// -*- C++ -*-
+/**
+ * \file FormBox.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Martin Vermeer
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef FORMBOX_H
+#define FORMBOX_H
+
+
+#include "FormDialogView.h"
+
+
+class ControlBox;
+struct FD_box;
+
+/** This class provides an XForms implementation of the Box Dialog.
+ */
+class FormBox : public FormController<ControlBox, FormView<FD_box> > {
+public:
+       /// Constructor
+       FormBox(Dialog &);
+private:
+       ///
+       virtual void apply();
+       /// Build the dialog
+       virtual void build();
+       /// Update dialog before showing it
+       virtual void update();
+       ///
+       virtual ButtonPolicy::SMInput input( FL_OBJECT *, long);
+       ///
+       std::vector<std::string> ids_;
+       ///
+       std::vector<std::string> gui_names_;
+       ///
+       std::vector<std::string> ids_spec_;
+       ///
+       std::vector<std::string> gui_names_spec_;
+       ///
+       enum Specials {
+               NONE = 1,
+               HEIGHT,
+               DEPTH,
+               TOTALHEIGHT,
+               WIDTH
+       };
+};
+
+#endif // FORMBOX_H
index c6dafe8f1b46ddd5b2e09c7885b6712e2a09cdb3..b2cd96fe97bd293273137ee787c1e42035e2a8ce 100644 (file)
@@ -72,6 +72,8 @@ libxforms_la_SOURCES = \
        FormBibitem.h \
        FormBibtex.C \
        FormBibtex.h \
+       FormBox.C \
+       FormBox.h \
        FormBrowser.C \
        FormBrowser.h \
        FormBranch.C \
index 8a835f6b8b32048b93fa1708405f2a0decc1ee81..316f89cd20cef1c61ae3e0364307cae18efa7131 100644 (file)
@@ -12,6 +12,7 @@ noinst_LTLIBRARIES = libfdesign.la
 SRCS =  form_aboutlyx.fd \
        form_bibitem.fd \
        form_bibtex.fd \
+       form_box.fd \
        form_browser.fd \
        form_branch.fd \
        form_changes.fd \
diff --git a/src/frontends/xforms/forms/form_box.fd b/src/frontends/xforms/forms/form_box.fd
new file mode 100644 (file)
index 0000000..e55f6c9
--- /dev/null
@@ -0,0 +1,359 @@
+Magic: 13000
+
+Internal Form Definition File
+    (do not change)
+
+Number of forms: 1
+Unit of measure: FL_COORD_PIXEL
+SnapGrid: 7
+
+=============== FORM ===============
+Name: form_box
+Width: 442
+Height: 379
+Number of Objects: 19
+
+--------------------
+class: FL_BOX
+type: UP_BOX
+box: 0 0 442 379
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_COL1
+alignment: FL_ALIGN_CENTER
+style: FL_NORMAL_STYLE
+size: FL_DEFAULT_SIZE
+lcol: FL_BLACK
+label: 
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: 
+callback: 
+argument: 
+
+--------------------
+class: FL_CHOICE
+type: NORMAL_CHOICE
+box: 175 21 231 28
+boxtype: FL_FRAME_BOX
+colors: FL_COL1 FL_BLACK
+alignment: FL_ALIGN_LEFT
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Box Type|#T
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: choice_type
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_BUTTON
+type: RETURN_BUTTON
+box: 56 322 84 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_COL1
+alignment: FL_ALIGN_CENTER
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: OK
+shortcut: ^M
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: button_ok
+callback: C_FormDialogView_OKCB
+argument: 0
+
+--------------------
+class: FL_BUTTON
+type: RETURN_BUTTON
+box: 147 322 98 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_COL1
+alignment: FL_ALIGN_CENTER
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Apply|#A
+shortcut: ^M
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: button_apply
+callback: C_FormDialogView_ApplyCB
+argument: 0
+
+--------------------
+class: FL_BUTTON
+type: RETURN_BUTTON
+box: 252 322 105 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_COL1
+alignment: FL_ALIGN_CENTER
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Cancel|^[
+shortcut: ^M
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: button_cancel
+callback: C_FormDialogView_CancelCB
+argument: 0
+
+--------------------
+class: FL_CHECKBUTTON
+type: PUSH_BUTTON
+box: 21 70 35 28
+boxtype: FL_NO_BOX
+colors: FL_COL1 FL_YELLOW
+alignment: FL_ALIGN_CENTER
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Has Inner Box
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: check_inner_box
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_CHOICE
+type: NORMAL_CHOICE2
+box: 315 77 91 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_BLACK
+alignment: FL_ALIGN_LEFT
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Vertical Position
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: choice_pos
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_CHOICE
+type: NORMAL_CHOICE2
+box: 203 210 91 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_BLACK
+alignment: FL_ALIGN_TOP
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Width Unit
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: choice_width_unit
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_INPUT
+type: NORMAL_INPUT
+box: 126 210 77 28
+boxtype: FL_DOWN_BOX
+colors: FL_COL1 FL_MCOL
+alignment: FL_ALIGN_TOP
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Width
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: input_width
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_CHOICE
+type: NORMAL_CHOICE2
+box: 294 210 112 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_BLACK
+alignment: FL_ALIGN_TOP
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Special
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: choice_special
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_ROUND3DBUTTON
+type: RADIO_BUTTON
+box: 21 112 35 28
+boxtype: FL_NO_BOX
+colors: FL_COL1 FL_YELLOW
+alignment: FL_ALIGN_CENTER
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Parbox
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: radio_parbox
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_ROUND3DBUTTON
+type: RADIO_BUTTON
+box: 21 140 35 28
+boxtype: FL_NO_BOX
+colors: FL_COL1 FL_YELLOW
+alignment: FL_ALIGN_CENTER
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Minipage
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: radio_minipage
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_FRAME
+type: ENGRAVED_FRAME
+box: 14 112 112 63
+boxtype: FL_NO_BOX
+colors: FL_BLACK FL_COL1
+alignment: FL_ALIGN_CENTER
+style: FL_NORMAL_STYLE
+size: FL_DEFAULT_SIZE
+lcol: FL_BLACK
+label: 
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: 
+callback: 
+argument: 
+
+--------------------
+class: FL_CHOICE
+type: NORMAL_CHOICE2
+box: 315 112 91 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_BLACK
+alignment: FL_ALIGN_LEFT
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Inner Position (Vert.)
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: choice_inner_pos
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_CHOICE
+type: NORMAL_CHOICE2
+box: 315 147 91 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_BLACK
+alignment: FL_ALIGN_LEFT
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Horizontal Position
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: choice_hor_pos
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_INPUT
+type: NORMAL_INPUT
+box: 126 266 77 28
+boxtype: FL_DOWN_BOX
+colors: FL_COL1 FL_MCOL
+alignment: FL_ALIGN_TOP
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Height
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: input_height
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_CHOICE
+type: NORMAL_CHOICE2
+box: 203 266 91 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_BLACK
+alignment: FL_ALIGN_TOP
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Height Unit
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: choice_height_unit
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_CHOICE
+type: NORMAL_CHOICE2
+box: 294 266 112 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_BLACK
+alignment: FL_ALIGN_TOP
+style: FL_NORMAL_STYLE
+size: FL_NORMAL_SIZE
+lcol: FL_BLACK
+label: Special
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: choice_height_special
+callback: C_FormDialogView_InputCB
+argument: 0
+
+--------------------
+class: FL_BUTTON
+type: NORMAL_BUTTON
+box: 28 238 77 28
+boxtype: FL_UP_BOX
+colors: FL_COL1 FL_COL1
+alignment: FL_ALIGN_CENTER
+style: FL_NORMAL_STYLE
+size: FL_DEFAULT_SIZE
+lcol: FL_BLACK
+label: Reset
+shortcut: 
+resize: FL_RESIZE_ALL
+gravity: FL_NoGravity FL_NoGravity
+name: button_defaults
+callback: C_FormDialogView_InputCB
+argument: 0
+
+==============================
+create_the_forms
index 7f0ea9eb921a7e03bdf9f4e09fe95653a2c9469a..449a6e7afa1274a281162e339218fd67e37a6dfc 100644 (file)
@@ -1,3 +1,10 @@
+2003-10-07  Martin Vermeer  <martin.vermeer@hut.fi>
+
+       * Makefile.am:
+       * inset.h:
+       * insetbox.C:
+       * insetbox.h: The Box patch. Fancybox support, minipage, parbox
+
 2003-10-02  André Pönitz  <poenitz@gmx.net>
 
        * insettext.C (read): make sure there is at least one par
index 9b29c5ed9f1521b0ed2fb48a235ead3a56c6a32b..dd9c775da9516d1f8592a57f5d78553b6e74f0a4 100644 (file)
@@ -25,6 +25,8 @@ libinsets_la_SOURCES = \
        insetbibitem.h \
        insetbibtex.C \
        insetbibtex.h \
+       insetbox.C \
+       insetbox.h \
        insetbranch.C \
        insetbranch.h \
        insetcaption.C \
index 670b52390e2a646da247df393664eea4cbab964e..bc653185ea22a6c0032e6adb0a68f51db7aeb230 100644 (file)
@@ -131,7 +131,9 @@ public:
                ///
                NEWLINE_CODE,
                ///
-               BRANCH_CODE
+               BRANCH_CODE,
+               ///
+               BOX_CODE
        };
 
        ///
diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C
new file mode 100644 (file)
index 0000000..147edf5
--- /dev/null
@@ -0,0 +1,590 @@
+/**
+ * \file insetbox.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ * \author Martin Vermeer
+ * \author Jürgen Spitzmüller
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "insetbox.h"
+#include "debug.h"
+
+#include "BufferView.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "LaTeXFeatures.h"
+#include "LColor.h"
+#include "lyxlex.h"
+#include "metricsinfo.h"
+#include "paragraph.h"
+
+#include "support/std_sstream.h"
+
+using std::auto_ptr;
+using std::string;
+using std::istringstream;
+using std::ostream;
+using std::ostringstream;
+using std::endl;
+
+
+namespace {
+
+BoxTranslator const init_boxtranslator() {
+       BoxTranslator translator("Boxed", InsetBox::Boxed);
+       translator.addPair("Frameless", InsetBox::Frameless);
+       translator.addPair("ovalbox", InsetBox::ovalbox);
+       translator.addPair("Ovalbox", InsetBox::Ovalbox);
+       translator.addPair("Shadowbox", InsetBox::Shadowbox);
+       translator.addPair("Doublebox",InsetBox::Doublebox);
+       return translator;
+}
+
+
+BoxTranslator const init_boxtranslator_loc() {
+       BoxTranslator translator(_("Boxed"), InsetBox::Boxed);
+       translator.addPair(_("Frameless"), InsetBox::Frameless);
+       translator.addPair(_("ovalbox"), InsetBox::ovalbox);
+       translator.addPair(_("Ovalbox"), InsetBox::Ovalbox);
+       translator.addPair(_("Shadowbox"), InsetBox::Shadowbox);
+       translator.addPair(_("Doublebox"), InsetBox::Doublebox);
+       return translator;
+}
+
+
+BoxTranslator const & boxtranslator() {
+       static BoxTranslator translator = init_boxtranslator();
+       return translator;
+}
+
+
+BoxTranslator const & boxtranslator_loc() {
+       static BoxTranslator translator = init_boxtranslator_loc();
+       return translator;
+}
+
+} // anon
+
+
+void InsetBox::init()
+{
+       setInsetName("Box");
+       setButtonLabel();
+}
+
+
+InsetBox::InsetBox(BufferParams const & bp, string const & label)
+       : InsetCollapsable(bp), params_(label)
+{
+       init();
+}
+
+
+InsetBox::InsetBox(InsetBox const & in)
+       : InsetCollapsable(in), params_(in.params_)
+{
+       init();
+}
+
+
+InsetBox::~InsetBox()
+{
+       InsetBoxMailer mailer(*this);
+       mailer.hideDialog();
+}
+
+
+auto_ptr<InsetBase> InsetBox::clone() const
+{
+       return auto_ptr<InsetBase>(new InsetBox(*this));
+}
+
+
+string const InsetBox::editMessage() const
+{
+       return _("Opened Box Inset");
+}
+
+
+void InsetBox::write(Buffer const & buf, ostream & os) const
+{
+       params_.write(os);
+       InsetCollapsable::write(buf, os);
+}
+
+
+void InsetBox::read(Buffer const & buf, LyXLex & lex)
+{
+       params_.read(lex);
+       InsetCollapsable::read(buf, lex);
+       setButtonLabel();
+}
+
+
+void InsetBox::setButtonLabel()
+{
+       LyXFont font(LyXFont::ALL_SANE);
+       font.decSize();
+       font.decSize();
+
+       BoxType btype = boxtranslator().find(params_.type);
+       if (btype == Frameless) {
+               if (params_.use_parbox)
+                       setLabel(_("Parbox"));
+               else
+                       setLabel(_("Minipage"));
+       } else
+               setLabel(boxtranslator_loc().find(btype));
+
+       font.setColor(LColor::foreground);
+       setBackgroundColor(LColor::background);
+       setLabelFont(font);
+}
+
+
+void InsetBox::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+       InsetCollapsable::metrics(mi, dim);
+       if (params_.inner_box && isOpen())
+               dim.wid = mi.base.textwidth;
+       dim_ = dim;
+}
+
+
+bool InsetBox::showInsetDialog(BufferView * bv) const
+{
+       InsetBoxMailer(const_cast<InsetBox &>(*this)).showDialog(bv);
+       return true;
+}
+
+
+dispatch_result InsetBox::localDispatch(FuncRequest const & cmd)
+{
+       BufferView * bv = cmd.view();
+
+       switch (cmd.action) {
+
+       case LFUN_INSET_MODIFY: {
+               InsetBoxMailer::string2params(cmd.argument, params_);
+               setButtonLabel();
+               bv->updateInset(this);
+               return DISPATCHED;
+       }
+       case LFUN_INSET_DIALOG_UPDATE:
+               InsetBoxMailer(*this).updateDialog(bv);
+               return DISPATCHED;
+
+       case LFUN_MOUSE_RELEASE:
+               if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
+                       InsetBoxMailer(*this).showDialog(bv);
+                       return DISPATCHED;
+               }
+               // fallthrough:
+
+       default:
+               return InsetCollapsable::localDispatch(cmd);
+       }
+}
+
+
+int InsetBox::latex(Buffer const & buf, ostream & os,
+                               LatexRunParams const & runparams) const
+{
+       BoxType btype = boxtranslator().find(params_.type);
+
+       string width_string = params_.width.asLatexString();
+       bool stdwidth(false);
+       if (params_.inner_box &&
+                       (width_string.find("1.0\\columnwidth") != string::npos
+                       || width_string.find("1.0\\textwidth") != string::npos)) {
+               stdwidth = true;
+               switch (btype) {
+               case Frameless:
+                       break;
+               case Boxed:
+                       width_string += " - 2\\fboxsep - 2\\fboxrule";
+                       break;
+               case ovalbox:
+                       width_string += " - 2\\fboxsep - 0.8pt";
+                       break;
+               case Ovalbox:
+                       width_string += " - 2\\fboxsep - 1.6pt";
+                       break;
+               case Shadowbox:
+                       // Shadow falls outside right margin... opinions?
+                       width_string += " - 2\\fboxsep - 2\\fboxrule"/* "-\\shadowsize"*/;
+                       break;
+               case Doublebox:
+                       width_string += " - 2\\fboxsep - 7.5\\fboxrule - 1.0pt";
+                       break;
+               }
+       }
+       
+       int i = 0;
+       os << "%\n";
+       // Adapt to column/text width correctly also if paragraphs indented:
+       if (stdwidth)
+               os << "\\noindent";
+       
+       switch (btype) {
+       case Frameless:
+               break;
+       case Boxed:
+               os << "\\framebox";
+               if (!params_.inner_box) {
+                       os << "{\\makebox";
+                       // Special widths, see usrguide §3.5
+                       if (params_.special != "none") {
+                               os << "[" << params_.width.value()
+                                  << "\\" << params_.special << "]";
+                       } else
+                               os << "[" << width_string << "]";
+                       if (params_.hor_pos != 'c')
+                               os << "[" << params_.hor_pos << "]";
+               }
+               
+               os << "{";
+               break;
+       case ovalbox:
+               os << "\\ovalbox{";
+               break;
+       case Ovalbox:
+               os << "\\Ovalbox{";
+               break;
+       case Shadowbox:
+               os << "\\shadowbox{";
+               break;
+       case Doublebox:
+               os << "\\doublebox{";
+               break;
+       }
+
+       if (params_.inner_box) {
+               if (params_.use_parbox)
+                       os << "\\parbox";
+               else
+                       os << "\\begin{minipage}";
+
+               os << "[" << params_.pos << "]";
+               if (params_.height_special == "none") {
+                       os << "[" << params_.height.asLatexString() << "]";
+               } else {
+                       // Special heights
+                       os << "[" << params_.height.value()
+                          << "\\" << params_.height_special << "]";
+               }
+               if (params_.inner_pos != params_.pos)
+                       os << "[" << params_.inner_pos << "]";
+
+               os << "{" << width_string << "}";
+
+               if (params_.use_parbox)
+                       os << "{";
+               os << "%\n";
+               i += 1;
+       }
+
+       i += inset.latex(buf, os, runparams);
+
+       if (params_.inner_box) {
+               if (params_.use_parbox)
+                       os << "%\n}";
+               else
+                       os << "%\n\\end{minipage}";
+       }
+       
+       switch (btype) {
+       case Frameless:
+               break;
+       case Boxed:
+               if (!params_.inner_box)
+                       os << "}"; // for makebox
+               os << "}";
+               break;
+       case ovalbox:
+       case Ovalbox:
+       case Doublebox:
+       case Shadowbox:
+               os << "}";
+               break;
+       }       
+       os << "%\n";
+       
+       i += 3;
+
+       return i;
+}
+
+
+int InsetBox::linuxdoc(Buffer const & buf, std::ostream & os) const
+{
+       return inset.linuxdoc(buf, os);
+}
+
+
+int InsetBox::docbook(Buffer const & buf, std::ostream & os, bool mixcont) const
+{
+       return inset.docbook(buf, os, mixcont);
+}
+
+
+int InsetBox::ascii(Buffer const & buf, std::ostream & os, int ll) const
+{
+       int i = 0;
+       string const pt = params_.type;
+       BoxType btype = boxtranslator().find(params_.type);
+       switch (btype) {
+               case Frameless:
+               break;
+               case Boxed:
+               os << "[";
+               break;
+               case ovalbox:
+               os << "(";
+               break;
+               case Ovalbox:
+               os << "((";
+               break;
+               case Shadowbox:
+               os << "[";
+               break;
+               case Doublebox:
+               os << "[[";
+               break;
+       }
+
+       i = inset.ascii(buf, os, ll);
+
+       switch (btype) {
+               case Frameless:
+               break;
+               case Boxed:
+               os << "]";
+               break;
+               case ovalbox:
+               os << ")";
+               break;
+               case Ovalbox:
+               os << "))";
+               break;
+               case Shadowbox:
+               os << "]/";
+               break;
+               case Doublebox:
+               os << "]]";
+               break;
+       }
+
+       return i;
+}
+
+
+void InsetBox::validate(LaTeXFeatures & features) const
+{
+       features.require("calc");
+       BoxType btype = boxtranslator().find(params_.type);
+       switch (btype) {
+       case Frameless:
+       case Boxed:
+               break;
+       case ovalbox:
+       case Ovalbox:
+       case Shadowbox:
+       case Doublebox:
+               features.require("fancybox");
+               break;
+       }
+       inset.validate(features);
+}
+
+
+InsetBoxMailer::InsetBoxMailer(InsetBox & inset)
+       : inset_(inset)
+{
+}
+
+
+string const InsetBoxMailer::name_ = "box";
+
+
+string const InsetBoxMailer::inset2string(Buffer const &) const
+{
+       return params2string(inset_.params());
+}
+
+
+string const InsetBoxMailer::params2string(InsetBoxParams const & params)
+{
+       ostringstream data;
+       data << "box" << ' ';
+       params.write(data);
+       return data.str();
+}
+
+
+void InsetBoxMailer::string2params(string const & in,
+       InsetBoxParams & params)
+{
+       params = InsetBoxParams(string());
+
+       if (in.empty())
+               return;
+
+       istringstream data(in);
+       LyXLex lex(0,0);
+       lex.setStream(data);
+
+       string token;
+       lex.next();
+       token = lex.getString();
+       lex.next();
+
+       params.read(lex);
+}
+
+
+InsetBoxParams::InsetBoxParams(string const & label)
+       : type(label),
+         use_parbox(false),
+         inner_box(true),
+         width(LyXLength("100col%")),
+         special("none"),
+         pos('t'),
+         hor_pos('c'),
+         inner_pos('t'),
+         height(LyXLength("1in")),
+         height_special("totalheight") // default is 1\\totalheight
+{}
+
+
+void InsetBoxParams::write(ostream & os) const
+{
+       os << type << "\n";
+       os << "position \"" << pos << "\"\n";
+       os << "hor_pos \"" << hor_pos << "\"\n";
+       os << "has_inner_box " << inner_box << "\n";
+       os << "inner_pos \"" << inner_pos << "\"\n";
+       os << "use_parbox " << use_parbox << "\n";
+       os << "width \"" << width.asString() << "\"\n";
+       os << "special \"" << special << "\"\n";
+       os << "height \"" << height.asString() << "\"\n";
+       os << "height_special \"" << height_special << "\"\n";
+}
+
+
+void InsetBoxParams::read(LyXLex & lex)
+{
+       if (lex.isOK()) {
+               type = lex.getString();
+       }
+       string token;
+       if (!lex.isOK())
+               return;
+       lex.next();
+       token = lex.getString();
+       if (token == "position") {
+               lex.next();
+               // The [0] is needed. We need the first and only char in
+               // this string -- MV
+               pos = lex.getString()[0];
+       } else {
+               lyxerr << "InsetBox::Read: Missing 'position'-tag!" << token << endl;
+               lex.pushToken(token);
+       }
+       if (!lex.isOK())
+               return;
+       lex.next();
+       token = lex.getString();
+       if (token == "hor_pos") {
+               lex.next();
+               hor_pos = lex.getString()[0];
+       } else {
+               lyxerr << "InsetBox::Read: Missing 'hor_pos'-tag!" << token << endl;
+               lex.pushToken(token);
+       }
+       if (!lex.isOK())
+               return;
+       lex.next();
+       token = lex.getString();
+       if (token == "has_inner_box") {
+               lex.next();
+               inner_box = lex.getInteger();
+       } else {
+               lyxerr << "InsetBox::Read: Missing 'has_inner_box'-tag!" << endl;
+               lex.pushToken(token);
+       }
+
+       if (!lex.isOK())
+               return;
+       lex.next();
+       token = lex.getString();
+       if (token == "inner_pos") {
+               lex.next();
+               inner_pos = lex.getString()[0];
+       } else {
+               lyxerr << "InsetBox::Read: Missing 'inner_pos'-tag!"
+                       << token << endl;
+               lex.pushToken(token);
+       }
+       if (!lex.isOK())
+               return;
+       lex.next();
+       token = lex.getString();
+       if (token == "use_parbox") {
+               lex.next();
+               use_parbox = lex.getInteger();
+       } else {
+               lyxerr << "InsetBox::Read: Missing 'use_parbox'-tag!" << endl;
+               lex.pushToken(token);
+       }
+       if (!lex.isOK())
+               return;
+       lex.next();
+       token = lex.getString();
+       if (token == "width") {
+               lex.next();
+               width = LyXLength(lex.getString());
+       } else {
+               lyxerr << "InsetBox::Read: Missing 'width'-tag!" << endl;
+               lex.pushToken(token);
+       }
+       if (!lex.isOK())
+               return;
+       lex.next();
+       token = lex.getString();
+       if (token == "special") {
+               lex.next();
+               special = lex.getString();
+       } else {
+               lyxerr << "InsetBox::Read: Missing 'special'-tag!" << endl;
+               lex.pushToken(token);
+       }
+       if (!lex.isOK())
+               return;
+       lex.next();
+       token = lex.getString();
+       if (token == "height") {
+               lex.next();
+               height = LyXLength(lex.getString());
+       } else {
+               lyxerr << "InsetBox::Read: Missing 'height'-tag!" << endl;
+               lex.pushToken(token);
+       }
+       if (!lex.isOK())
+               return;
+       lex.next();
+       token = lex.getString();
+       if (token == "height_special") {
+               lex.next();
+               height_special = lex.getString();
+       } else {
+               lyxerr << "InsetBox::Read: Missing 'height_special'-tag!" << endl;
+               lex.pushToken(token);
+       }
+}
diff --git a/src/insets/insetbox.h b/src/insets/insetbox.h
new file mode 100644 (file)
index 0000000..48dbcf2
--- /dev/null
@@ -0,0 +1,148 @@
+// -*- C++ -*-
+/**
+ * \file insetbox.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Angus Leeming
+ * \author Martin Vermeer
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#ifndef INSETBOX_H
+#define INSETBOX_H
+
+
+#include "insetcollapsable.h"
+#include "lyxlength.h"
+#include "support/translator.h"
+
+
+struct InsetBoxParams {
+       ///
+       InsetBoxParams(std::string const &);
+       ///     
+       void write(std::ostream & os) const;
+       ///
+       void read(LyXLex & lex);
+       ///
+       std::string type;
+       /// Use a parbox (true) or minipage (false)
+       bool use_parbox;
+       /// Do we have an inner parbox or minipage to format paragraphs to
+       /// columnwidth?
+       bool inner_box;
+       ///
+       LyXLength width;
+       /// "special" widths, see usrguide.dvi §3.5
+       std::string special;
+       ///
+       char pos;
+       ///
+       char hor_pos;
+       ///
+       char inner_pos;
+       ///
+       LyXLength height;
+       ///
+       std::string height_special;
+};
+
+
+/** The fbox/fancybox inset
+
+*/
+class InsetBox : public InsetCollapsable {
+public:
+       ///
+       InsetBox(BufferParams const &, std::string const &);
+       /// Copy constructor
+       InsetBox(InsetBox const &);
+       ///
+       ~InsetBox();
+       ///
+       virtual std::auto_ptr<InsetBase> clone() const;
+       ///
+       std::string const editMessage() const;
+       ///
+       InsetOld::Code lyxCode() const { return InsetOld::BOX_CODE; }
+       ///
+       void write(Buffer const &, std::ostream &) const;
+       ///
+       void read(Buffer const & buf, LyXLex & lex);
+       ///
+       void setButtonLabel();
+       ///
+       dispatch_result InsetBox::localDispatch(FuncRequest const &);
+       ///
+       void metrics(MetricsInfo &, Dimension &) const;
+       /// show the Box dialog
+       bool showInsetDialog(BufferView * bv) const;
+       ///
+       int latex(Buffer const &, std::ostream &,
+                       LatexRunParams const &) const;
+       ///
+       int linuxdoc(Buffer const &, std::ostream &) const;
+       ///
+       int docbook(Buffer const &, std::ostream &, bool) const;
+       ///
+       int ascii(Buffer const &, std::ostream &, int) const;
+       ///
+       void validate(LaTeXFeatures &) const;
+       ///
+       InsetBoxParams const & params() const { return params_; }
+       ///     
+       enum BoxType {
+               Frameless,
+               Boxed,
+               ovalbox,
+               Ovalbox,
+               Shadowbox,
+               Doublebox
+       };
+
+private:
+       friend class InsetBoxParams;
+
+       /// used by the constructors
+       void init();
+       ///
+       InsetBoxParams params_;
+};
+
+
+namespace {
+
+typedef Translator<std::string, InsetBox::BoxType> BoxTranslator;
+BoxTranslator const & boxtranslator();
+BoxTranslator const & boxtranslator_loc();
+
+} // anon
+
+
+#include "mailinset.h"
+
+class InsetBoxMailer : public MailInset {
+public:
+       ///
+       InsetBoxMailer(InsetBox & inset);
+       ///
+       virtual InsetBase & inset() const { return inset_; }
+       ///
+       virtual std::string const & name() const { return name_; }
+       ///
+       virtual std::string const inset2string(Buffer const &) const;
+       ///
+       static std::string const params2string(InsetBoxParams const &);
+       ///
+       static void string2params(std::string const &, InsetBoxParams &);
+
+private:
+       ///
+       static std::string const name_;
+       ///
+       InsetBox & inset_;
+};
+
+#endif // INSET_BOX_H
index 4b24b321f9b774d4334661662c5a04e7b668eb5a..cb1c7e5d859e9034ed116a5c47348e8947df18f6 100644 (file)
@@ -323,6 +323,7 @@ enum kb_action {
        // 245
        LFUN_INSERT_BRANCH,
        LFUN_INSET_DIALOG_SHOW,
+       LFUN_INSERT_BOX,
 
        LFUN_LASTACTION                  // end of the table
 };
index abe1b46809e77973b076d483f7deda2144be55d9..54df4a3c70d3f3c3488a4c0a78ccee76e8d22bc5 100644 (file)
@@ -525,6 +525,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                        case InsetOld::BRANCH_CODE:
                                disable = ev.argument != "branch";
                                break;
+                       case InsetOld::BOX_CODE:
+                               disable = ev.argument != "box";
+                               break;
                        default:
                                break;
                }
@@ -653,6 +656,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        case LFUN_INSERT_NOTE:
                code = InsetOld::NOTE_CODE;
                break;
+       case LFUN_INSERT_BOX:
+               code = InsetOld::BOX_CODE;
+               break;
        case LFUN_INSERT_BRANCH:
                code = InsetOld::BRANCH_CODE;
                if (buf->params().branchlist().empty())
index b31f5cde5c24efb721f44bdc01a2b669b8e8c980..f0cae29d647bd3ee52f80f368df2846b3ad36d21 100644 (file)
@@ -1505,6 +1505,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_INSET_CAPTION:
 #endif
        case LFUN_INSERT_NOTE:
+       case LFUN_INSERT_BOX:
        case LFUN_INSERT_BRANCH:
        case LFUN_INSERT_BIBITEM:
        case LFUN_INSET_ERT: