Am 06.09.2010 05:09, schrieb Uwe Stöhr:
Attached is a revised patch
That patch was corrupted, attached is a working one. regards Uwe
Index: development/FORMAT =================================================================== --- development/FORMAT (revision 35287) +++ development/FORMAT (working copy) @@ -7,6 +7,11 @@ ----------------------- +2010-09-06 Uwe Stöhr <uwesto...@web.de> + * Format incremented to 400: support for the LaTeX-command + \rule; + new CommandInset named "line" + 2010-08-31 Uwe Stöhr <uwesto...@web.de> * Format incremented to 399: support for the LaTeX-package mathdots; Index: development/scons/scons_manifest.py =================================================================== --- development/scons/scons_manifest.py (revision 35287) +++ development/scons/scons_manifest.py (working copy) @@ -742,6 +742,7 @@ GuiInfo.h GuiKeySymbol.h GuiLabel.h + GuiLine.h GuiListings.h GuiLog.h GuiMathMatrix.h @@ -843,6 +844,7 @@ GuiInfo.cpp GuiKeySymbol.cpp GuiLabel.cpp + GuiLine.cpp GuiListings.cpp GuiLog.cpp GuiMathMatrix.cpp @@ -938,6 +940,7 @@ LabelUi.ui LaTeXUi.ui LanguageUi.ui + LineUi.ui ListingsUi.ui ListingsSettingsUi.ui LocalLayoutUi.ui Index: lib/lyx2lyx/lyx_2_0.py =================================================================== --- lib/lyx2lyx/lyx_2_0.py (revision 35287) +++ lib/lyx2lyx/lyx_2_0.py (working copy) @@ -2078,6 +2078,90 @@ break +def convert_rule(document): + " Convert \\lyxline to CommandInset line " + i = 0 + while True: + i = find_token(document.body, "\\lyxline" , i) + if i != -1: + j = find_token(document.body, "\\color" , i - 2) + if j == i - 2: + color = document.body[j] + '\n' + else: + color = '' + k = find_token(document.body, "\\begin_layout Standard" , i - 4) + # we need to handle the case that \lyxline is in a separate paragraph and that it is colored + # the result is then an extra empty paragraph which we get by adding an empty ERT inset + if k == i - 4 and j == i - 2 and document.body[i - 1] == '': + layout = '\\begin_inset ERT\nstatus collapsed\n\n\\begin_layout Plain Layout\n\n\n\\end_layout\n\n\\end_inset\n' \ + + '\\end_layout\n\n' \ + + '\\begin_layout Standard\n' + elif k == i - 2 and document.body[i - 1] == '': + layout = '' + else: + layout = '\\end_layout\n\n' \ + + '\\begin_layout Standard\n' + l = find_token(document.body, "\\begin_layout Standard" , i + 4) + if l == i + 4 and document.body[i + 1] == '': + layout2 = '' + else: + layout2 = '\\end_layout\n' \ + + '\n\\begin_layout Standard\n' + subst = layout \ + + '\\noindent\n\n' \ + + color \ + + '\\begin_inset CommandInset line\n' \ + + 'LatexCommand rule\n' \ + + 'offset "0.5ex"\n' \ + + 'width "100line%"\n' \ + + 'height "1pt"\n' \ + + '\n\\end_inset\n\n\n' \ + + layout2 + document.body[i] = subst + i += 1 + else: + return + + +def revert_rule(document): + " Revert line insets to Tex code " + i = 0 + while 1: + i = find_token(document.body, "\\begin_inset CommandInset line" , i) + if i != -1: + # find end of inset + j = find_token(document.body, "\\end_inset" , i) + # assure we found the end_inset of the current inset + if j > i + 6 or j == -1: + document.warning("Malformed LyX document: Can't find end of line inset.") + return + # determine the optional offset + k = find_token(document.body, 'offset', i) + if k != -1 and k < j: + offset = document.body[k][8:] + else: + offset = '0"' + # determine the width + l = find_token(document.body, 'width', k + 1) + width = document.body[l][7:] + # determine the height + m = find_token(document.body, 'height', l + 1) + height = document.body[m][8:] + # remove trailing '"' + offset = offset[:-1] + width = width[:-1] + height = height[:-1] + # output the \rule command + if offset <> "0": + subst = "\\rule[" + offset + "]{" + width + "}{" + height + "}" + else: + subst = "\\rule{" + width + "}{" + height + "}" + document.body[i:j + 1] = put_cmd_in_ert(subst) + i += 1 + else: + return + + ## # Conversion hub # @@ -2136,10 +2220,12 @@ [396, []], [397, [remove_Nameref]], [398, []], - [399, [convert_mathdots]] + [399, [convert_mathdots]], + [400, [convert_rule]] ] -revert = [[398, [revert_mathdots]], +revert = [[399, [revert_rule]], + [398, [revert_mathdots]], [397, [revert_mathrsfs]], [396, []], [395, [revert_nameref]], Index: src/Buffer.cpp =================================================================== --- src/Buffer.cpp (revision 35287) +++ src/Buffer.cpp (working copy) @@ -127,7 +127,7 @@ // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -int const LYX_FORMAT = 399; // uwestoehr: support for package mathdots +int const LYX_FORMAT = 400; // uwestoehr: support for \rule typedef map<string, bool> DepClean; typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache; Index: src/BufferView.cpp =================================================================== --- src/BufferView.cpp (revision 35287) +++ src/BufferView.cpp (working copy) @@ -1027,6 +1027,7 @@ case LFUN_FONT_STATE: case LFUN_LABEL_INSERT: + case LFUN_LINE_INSERT: case LFUN_INFO_INSERT: case LFUN_PARAGRAPH_GOTO: case LFUN_NOTE_NEXT: Index: src/factory.cpp =================================================================== --- src/factory.cpp (revision 35287) +++ src/factory.cpp (working copy) @@ -82,9 +82,6 @@ switch (cmd.action()) { - case LFUN_LINE_INSERT: - return new InsetLine; - case LFUN_NEWPAGE_INSERT: { string const name = cmd.getArg(0); InsetNewpageParams inp; @@ -292,6 +289,12 @@ return new InsetLabel(buf, icp); } + case LINE_CODE: { + InsetCommandParams icp(code); + InsetCommand::string2params(name, to_utf8(cmd.argument()), icp); + return new InsetLine(buf, icp); + } + case LISTINGS_CODE: { InsetListingsParams par; InsetListings::string2params(to_utf8(cmd.argument()), par); @@ -490,6 +493,9 @@ case LABEL_CODE: inset.reset(new InsetLabel(buf, inscmd)); break; + case LINE_CODE: + inset.reset(new InsetLine(buf, inscmd)); + break; case NOMENCL_CODE: inset.reset(new InsetNomencl(buf, inscmd)); break; Index: src/frontends/qt4/GuiLine.cpp =================================================================== --- src/frontends/qt4/GuiLine.cpp (revision 0) +++ src/frontends/qt4/GuiLine.cpp (revision 0) @@ -0,0 +1,150 @@ +/** + * \file GuiLine.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Uwe Stöhr + * + * Full author contact details are available in file CREDITS. + */ + +#include <config.h> + +#include "GuiLine.h" + +#include "LengthCombo.h" +#include "qt_helpers.h" +#include "Validator.h" + +#include "FuncRequest.h" + +#include "insets/InsetLine.h" + +#include "support/debug.h" +#include "support/gettext.h" +#include "support/lstrings.h" + +#include <QLineEdit> +#include <QPushButton> +#include <QValidator> + +using namespace std; + +namespace lyx { +namespace frontend { + +GuiLine::GuiLine(GuiView & lv) + : GuiDialog(lv, "line", qt_("Horizontal line")), + params_(insetCode("line")) +{ + setupUi(this); + + connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); + connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply())); + connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); + + connect(OffsetLE, SIGNAL(textChanged(QString)), + this, SLOT(change_adaptor())); + connect(OffsetUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)), + this, SLOT(change_adaptor())); + connect(WidthLE, SIGNAL(textChanged(QString)), + this, SLOT(change_adaptor())); + connect(WidthUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)), + this, SLOT(change_adaptor())); + connect(HeightLE, SIGNAL(textChanged(QString)), + this, SLOT(change_adaptor())); + connect(HeightUnitCO, SIGNAL(selectionChanged(lyx::Length::UNIT)), + this, SLOT(change_adaptor())); + + // Manage the ok, apply, restore and cancel/close buttons + bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy); + bc().setOK(okPB); + bc().setApply(applyPB); + bc().setCancel(closePB); + + // disable for read-only documents + bc().addReadOnly(OffsetLE); + bc().addReadOnly(OffsetUnitCO); + bc().addReadOnly(WidthLE); + bc().addReadOnly(WidthUnitCO); + bc().addReadOnly(HeightLE); + bc().addReadOnly(HeightUnitCO); + + // initialize the length validator + bc().addCheckedLineEdit(OffsetLE, OffsetValueL); + bc().addCheckedLineEdit(WidthLE, WidthValueL); + bc().addCheckedLineEdit(HeightLE, HeightValueL); + + OffsetLE->setValidator(unsignedGlueLengthValidator(OffsetLE)); + WidthLE->setValidator(unsignedGlueLengthValidator(WidthLE)); + HeightLE->setValidator(unsignedGlueLengthValidator(HeightLE)); +} + + +void GuiLine::change_adaptor() +{ + changed(); +} + + +void GuiLine::paramsToDialog(InsetCommandParams const & /*icp*/) +{ + lengthToWidgets(OffsetLE, + OffsetUnitCO, + params_["offset"], + Length::defaultUnit()); + lengthToWidgets(WidthLE, + WidthUnitCO, + params_["width"], + Length::defaultUnit()); + lengthToWidgets(HeightLE, + HeightUnitCO, + params_["height"], + Length::defaultUnit()); + + bc().setValid(isValid()); +} + + +void GuiLine::applyView() +{ + docstring offset = from_utf8(widgetsToLength(OffsetLE, OffsetUnitCO)); + params_["offset"] = offset; + docstring width = from_utf8(widgetsToLength(WidthLE, WidthUnitCO)); + params_["width"] = width; + docstring height = from_utf8(widgetsToLength(HeightLE, HeightUnitCO)); + params_["height"] = height; + params_.setCmdName("rule"); +} + + +bool GuiLine::isValid() const +{ + return true; +} + + +bool GuiLine::initialiseParams(std::string const & data) +{ + InsetCommand::string2params("line", data, params_); + paramsToDialog(params_); + return true; +} + + +void GuiLine::dispatchParams() +{ + std::string const lfun = InsetCommand::params2string("line", params_); + dispatch(FuncRequest(getLfun(), lfun)); +} + + + +Dialog * createGuiLine(GuiView & lv) { return new GuiLine(lv); } + + +} // namespace frontend +} // namespace lyx + + +#include "moc_GuiLine.cpp" Property changes on: src\frontends\qt4\GuiLine.cpp ___________________________________________________________________ Added: svn:eol-style + native Index: src/frontends/qt4/GuiLine.h =================================================================== --- src/frontends/qt4/GuiLine.h (revision 0) +++ src/frontends/qt4/GuiLine.h (revision 0) @@ -0,0 +1,57 @@ +// -*- C++ -*- +/** + * \file GuiLine.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Uwe Stöhr + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef GUILINE_H +#define GUILINE_H + +#include "GuiDialog.h" +#include "ui_LineUi.h" + +#include "insets/InsetCommandParams.h" + + +namespace lyx { +namespace frontend { + +class GuiLine : public GuiDialog, public Ui::LineUi +{ + Q_OBJECT + +public: + GuiLine(GuiView & lv); + +private Q_SLOTS: + void change_adaptor(); + +private: + /// Apply changes + void applyView(); + /// Update dialog before showing it + bool initialiseParams(std::string const & data); + /// + void paramsToDialog(InsetCommandParams const & icp); + /// + void clearParams() { params_.clear(); } + /// + void dispatchParams(); + /// + bool isBufferDependent() const { return true; } + /// + bool isValid() const; + + /// + InsetCommandParams params_; +}; + +} // namespace frontend +} // namespace lyx + +#endif // GUILINE_H Property changes on: src\frontends\qt4\GuiLine.h ___________________________________________________________________ Added: svn:eol-style + native Index: src/frontends/qt4/GuiView.cpp =================================================================== --- src/frontends/qt4/GuiView.cpp (revision 35287) +++ src/frontends/qt4/GuiView.cpp (working copy) @@ -3457,13 +3457,14 @@ char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character", -"citation", "compare", "document", "errorlist", "ert", "external", "file", -"findreplace", "findreplaceadv", "float", "graphics", "href", "include", -"index", "index_print", "info", "listings", "label", "log", "mathdelimiter", -"mathmatrix", "mathspace", "nomenclature", "nomencl_print", "note", -"paragraph", "phantom", "prefs", "print", "ref", "sendto", "space", -"spellchecker", "symbols", "tabular", "tabularcreate", "thesaurus", "texinfo", -"toc", "view-source", "vspace", "wrap", "progress"}; +"citation", "compare", "document", "errorlist", "ert", "external", +"file", "findreplace", "findreplaceadv", "float", "graphics", "href", +"include", "index", "index_print", "info", "listings", "label", "line", +"log", "mathdelimiter", "mathmatrix", "mathspace", "nomenclature", +"nomencl_print", "note", "paragraph", "phantom", "prefs", "print", "ref", +"sendto", "space", "spellchecker", "symbols", "tabular", "tabularcreate", +"thesaurus", "texinfo", "toc", "view-source", "vspace", "wrap", +"progress"}; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -3650,6 +3651,7 @@ Dialog * createGuiInclude(GuiView & lv); Dialog * createGuiIndex(GuiView & lv); Dialog * createGuiLabel(GuiView & lv); +Dialog * createGuiLine(GuiView & lv); Dialog * createGuiListings(GuiView & lv); Dialog * createGuiLog(GuiView & lv); Dialog * createGuiMathMatrix(GuiView & lv); @@ -3723,6 +3725,8 @@ return createGuiPrintindex(*this); if (name == "label") return createGuiLabel(*this); + if (name == "line") + return createGuiLine(*this); if (name == "listings") return createGuiListings(*this); if (name == "log") Index: src/frontends/qt4/Makefile.am =================================================================== --- src/frontends/qt4/Makefile.am (revision 35287) +++ src/frontends/qt4/Makefile.am (working copy) @@ -95,6 +95,7 @@ GuiInfo.cpp \ GuiKeySymbol.cpp \ GuiLabel.cpp \ + GuiLine.cpp \ GuiListings.cpp \ GuiLog.cpp \ GuiMathMatrix.cpp \ @@ -199,6 +200,7 @@ GuiIndices.h \ GuiInfo.h \ GuiLabel.h \ + GuiLine.h \ GuiListings.h \ GuiLog.h \ GuiMathMatrix.h \ @@ -280,6 +282,7 @@ LabelUi.ui \ LanguageUi.ui \ LaTeXUi.ui \ + LineUi.ui \ ListingsUi.ui \ ListingsSettingsUi.ui \ LocalLayoutUi.ui \ Index: src/frontends/qt4/ui/LineUi.ui =================================================================== --- src/frontends/qt4/ui/LineUi.ui (revision 0) +++ src/frontends/qt4/ui/LineUi.ui (revision 0) @@ -0,0 +1,188 @@ +<ui version="4.0"> + <class>LineUi</class> + <widget class="QWidget" name="LineUi"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>325</width> + <height>126</height> + </rect> + </property> + <property name="windowTitle"> + <string/> + </property> + <property name="sizeGripEnabled" stdset="0"> + <bool>true</bool> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="OffsetValueL"> + <property name="text"> + <string>Offset:</string> + </property> + </widget> + </item> + <item row="0" column="1" colspan="2"> + <widget class="QLineEdit" name="OffsetLE"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="toolTip"> + <string>Value of the vertical line offset.</string> + </property> + </widget> + </item> + <item row="0" column="3"> + <widget class="LengthCombo" name="OffsetUnitCO"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>150</width> + <height>20</height> + </size> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="WidthValueL"> + <property name="text"> + <string>Width:</string> + </property> + <property name="buddy"> + <cstring>WidthLE</cstring> + </property> + </widget> + </item> + <item row="1" column="1" colspan="2"> + <widget class="QLineEdit" name="WidthLE"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="toolTip"> + <string>Value of the line width.</string> + </property> + </widget> + </item> + <item row="1" column="3"> + <widget class="LengthCombo" name="WidthUnitCO"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>150</width> + <height>20</height> + </size> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="HeightValueL"> + <property name="text"> + <string>Height:</string> + </property> + </widget> + </item> + <item row="2" column="1" colspan="2"> + <widget class="QLineEdit" name="HeightLE"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="toolTip"> + <string>Value of the line height.</string> + </property> + </widget> + </item> + <item row="2" column="3"> + <widget class="LengthCombo" name="HeightUnitCO"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>150</width> + <height>20</height> + </size> + </property> + </widget> + </item> + <item row="3" column="0" colspan="2"> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>59</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="3" column="2" colspan="2"> + <layout class="QHBoxLayout"> + <item> + <widget class="QPushButton" name="okPB"> + <property name="text"> + <string>&OK</string> + </property> + <property name="autoDefault"> + <bool>false</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="applyPB"> + <property name="text"> + <string>&Apply</string> + </property> + <property name="autoDefault"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="closePB"> + <property name="text"> + <string>&Close</string> + </property> + <property name="autoDefault"> + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>LengthCombo</class> + <extends>QComboBox</extends> + <header>LengthCombo.h</header> + </customwidget> + </customwidgets> + <tabstops> + <tabstop>WidthLE</tabstop> + </tabstops> + <includes> + <include location="local">qt_i18n.h</include> + </includes> + <resources/> + <connections/> +</ui> Property changes on: src\frontends\qt4\ui\LineUi.ui ___________________________________________________________________ Added: svn:eol-style + native Index: src/insets/InsetCommand.cpp =================================================================== --- src/insets/InsetCommand.cpp (revision 35287) +++ src/insets/InsetCommand.cpp (working copy) @@ -29,6 +29,7 @@ #include "insets/InsetFloat.h" #include "insets/InsetGraphics.h" #include "insets/InsetInclude.h" +#include "insets/InsetLine.h" #include "insets/InsetListings.h" #include "insets/InsetNote.h" #include "insets/InsetPhantom.h" @@ -260,6 +261,7 @@ case BIBTEX_CODE: case INDEX_CODE: case LABEL_CODE: + case LINE_CODE: case NOMENCL_CODE: case NOMENCL_PRINT_CODE: case REF_CODE: Index: src/insets/InsetCommand.h =================================================================== --- src/insets/InsetCommand.h (revision 35287) +++ src/insets/InsetCommand.h (working copy) @@ -55,6 +55,8 @@ /// void setParam(std::string const & name, docstring const & value); /// + Dimension const dimension(BufferView const &) const { return button_.dimension(); } + /// docstring const & getParam(std::string const & name) const; /// FIXME Remove docstring const getFirstNonOptParam() const { return p_.getFirstNonOptParam(); } @@ -87,8 +89,6 @@ /// void metrics(MetricsInfo &, Dimension &) const; /// - Dimension const dimension(BufferView const &) const { return button_.dimension(); } - /// void draw(PainterInfo & pi, int x, int y) const; /// int latex(odocstream &, OutputParams const &) const; Index: src/insets/InsetCommandParams.cpp =================================================================== --- src/insets/InsetCommandParams.cpp (revision 35287) +++ src/insets/InsetCommandParams.cpp (working copy) @@ -23,6 +23,7 @@ #include "InsetInclude.h" #include "InsetIndex.h" #include "InsetLabel.h" +#include "InsetLine.h" #include "InsetNomencl.h" #include "InsetRef.h" #include "InsetTOC.h" @@ -70,6 +71,8 @@ return InsetPrintIndex::findInfo(cmdName); case LABEL_CODE: return InsetLabel::findInfo(cmdName); + case LINE_CODE: + return InsetLine::findInfo(cmdName); case NOMENCL_CODE: return InsetNomencl::findInfo(cmdName); case NOMENCL_PRINT_CODE: @@ -200,6 +203,8 @@ return InsetPrintIndex::defaultCommand(); case LABEL_CODE: return InsetLabel::defaultCommand(); + case LINE_CODE: + return InsetLine::defaultCommand(); case NOMENCL_CODE: return InsetNomencl::defaultCommand(); case NOMENCL_PRINT_CODE: @@ -234,6 +239,8 @@ return InsetPrintIndex::isCompatibleCommand(s); case LABEL_CODE: return InsetLabel::isCompatibleCommand(s); + case LINE_CODE: + return InsetLine::isCompatibleCommand(s); case NOMENCL_CODE: return InsetNomencl::isCompatibleCommand(s); case NOMENCL_PRINT_CODE: Index: src/insets/InsetLine.cpp =================================================================== --- src/insets/InsetLine.cpp (revision 35287) +++ src/insets/InsetLine.cpp (working copy) @@ -4,6 +4,7 @@ * Licence details can be found in the file COPYING. * * \author André Pönitz + * \author Uwe Stöhr * * Full author contact details are available in file CREDITS. */ @@ -12,21 +13,26 @@ #include "InsetLine.h" +#include "Buffer.h" #include "Dimension.h" -#include "Font.h" +#include "DispatchResult.h" +#include "FuncRequest.h" +#include "FuncStatus.h" #include "LaTeXFeatures.h" +#include "Length.h" #include "MetricsInfo.h" #include "OutputParams.h" #include "output_xhtml.h" #include "Text.h" +#include "frontends/FontMetrics.h" #include "frontends/Painter.h" #include "support/debug.h" #include "support/docstream.h" +#include "support/gettext.h" +#include "support/lstrings.h" - - using namespace std; namespace lyx { @@ -34,24 +40,83 @@ using frontend::Painter; -void InsetLine::read(Lexer &) +InsetLine::InsetLine(Buffer * buf, InsetCommandParams const & p) + : InsetCommand(buf, p, "line") +{} + + +ParamInfo const & InsetLine::findInfo(string const & /* cmdName */) { - /* Nothing to read */ + static ParamInfo param_info_; + if (param_info_.empty()) { + param_info_.add("offset", ParamInfo::LYX_INTERNAL); + param_info_.add("width", ParamInfo::LYX_INTERNAL); + param_info_.add("height", ParamInfo::LYX_INTERNAL); + } + return param_info_; } -void InsetLine::write(ostream & os) const +docstring InsetLine::screenLabel() const { - os << "\n\\lyxline\n"; + return _("Horizontal line"); } +void InsetLine::doDispatch(Cursor & cur, FuncRequest & cmd) +{ + switch (cmd.action()) { + + case LFUN_INSET_MODIFY: { + InsetCommandParams p(LINE_CODE); + // FIXME UNICODE + InsetCommand::string2params("line", + to_utf8(cmd.argument()), p); + if (p.getCmdName().empty()) { + cur.noScreenUpdate(); + break; + } + setParams(p); + break; + } + + default: + InsetCommand::doDispatch(cur, cmd); + break; + } +} + + +bool InsetLine::getStatus(Cursor & cur, FuncRequest const & cmd, + FuncStatus & status) const +{ + switch (cmd.action()) { + case LFUN_INSET_DIALOG_UPDATE: + case LFUN_INSET_MODIFY: + status.setEnabled(true); + return true; + default: + return InsetCommand::getStatus(cur, cmd, status); + } +} + + void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const { - dim.asc = 3; - dim.des = 3; - dim.wid = mi.base.textwidth; - // Cache the inset dimension. + frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); + dim.asc = fm.maxAscent(); + dim.des = fm.maxDescent(); + + Length width = Length(to_ascii(getParam("width"))); + int const w = + width.inPixels(mi.base.textwidth, + fm.width(char_type('M'))); + + // set a minimal width + int const minw = (w < 0) ? 3 * 8 : 4; + dim.wid = max(minw, abs(w)); + + // Cache the inset dimension setDimCache(mi, dim); } @@ -60,18 +125,53 @@ { Dimension const dim = dimension(*pi.base.bv); + frontend::FontMetrics const & fm = theFontMetrics(pi.base.font); + + Length offset = Length(to_ascii(getParam("offset"))); + int const o = + offset.inPixels(pi.base.textwidth, + fm.width(char_type('M'))); + + Length width = Length(to_ascii(getParam("width"))); + int const w = + width.inPixels(pi.base.textwidth, + fm.width(char_type('M'))); + + Length height = Length(to_ascii(getParam("height"))); + int const h = + height.inPixels(pi.base.textwidth, + fm.width(char_type('M'))); + + // get the surrounding text color FontInfo f = pi.base.font; Color Line_color = f.realColor(); - pi.pain.line(x, y, x + dim.wid, y, Line_color, - Painter::line_solid, 1); + // the offset is a vertical one + pi.pain.line(x + h/2 + 1, y - o - h/2, x + w - h/2 - 2, y - o - h/2, + Line_color, Painter::line_solid, h); } int InsetLine::latex(odocstream & os, OutputParams const & runparams) const { - os << "\\lyxline{\\" - << from_ascii(runparams.local_font->latexSize()) << '}'; + bool have_offset = true; + Length offset_len = Length(to_ascii(getParam("offset"))); + if (offset_len.value() == 0) + have_offset = false; + + string const offset = + Length(to_ascii(getParam("offset"))).asLatexString(); + string const width = + Length(to_ascii(getParam("width"))).asLatexString(); + string const height = + Length(to_ascii(getParam("height"))).asLatexString(); + + os << "\\rule"; + // only output the optional parameter if the offset is not 0 + if (have_offset) + os << "[" << from_ascii(offset) << "]"; + os << "{" << from_ascii(width) << "}{" << from_ascii(height) << '}'; + return 0; } @@ -98,10 +198,4 @@ } -void InsetLine::validate(LaTeXFeatures & features) const -{ - features.require("lyxline"); -} - - } // namespace lyx Index: src/insets/InsetLine.h =================================================================== --- src/insets/InsetLine.h (revision 35287) +++ src/insets/InsetLine.h (working copy) @@ -5,6 +5,7 @@ * Licence details can be found in the file COPYING. * * \author André Pönitz + * \author Uwe Stöhr * * Full author contact details are available in file CREDITS. */ @@ -14,17 +15,37 @@ #include "Inset.h" +#include "InsetCommand.h" namespace lyx { -class InsetLine : public Inset { +class LaTeXFeatures; + +class InsetLine : public InsetCommand { public: /// - InsetLine() : Inset(0) {} + InsetLine(Buffer * buf, InsetCommandParams const &); /// + int docbook(odocstream &, OutputParams const &) const; + /// Does nothing at the moment. + docstring xhtml(XHTMLStream &, OutputParams const &) const; + /// InsetCode lyxCode() const { return LINE_CODE; } /// + bool hasSettings() const { return true; } + /// + docstring screenLabel() const; + /// + static ParamInfo const & findInfo(std::string const &); + /// + static std::string defaultCommand() { return "rule"; }; + /// + static bool isCompatibleCommand(std::string const & s) + { return s == "rule"; } + +private: + /// void metrics(MetricsInfo &, Dimension &) const; /// void draw(PainterInfo & pi, int x, int y) const; @@ -33,20 +54,10 @@ /// int plaintext(odocstream &, OutputParams const &) const; /// - int docbook(odocstream &, OutputParams const &) const; + void doDispatch(Cursor & cur, FuncRequest & cmd); /// - docstring xhtml(XHTMLStream &, OutputParams const &) const; + bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; /// - void read(Lexer & lex); - /// - void write(std::ostream & os) const; - /// We don't need \begin_inset and \end_inset - bool directWrite() const { return true; } - /// - DisplayType display() const { return AlignCenter; } - /// - void validate(LaTeXFeatures & features) const; -private: Inset * clone() const { return new InsetLine(*this); } }; Index: src/LaTeXFeatures.cpp =================================================================== --- src/LaTeXFeatures.cpp (revision 35287) +++ src/LaTeXFeatures.cpp (working copy) @@ -60,11 +60,6 @@ static docstring const lyx_def = from_ascii( "\\providecommand{\\lyx}{l\\kern-.1667em\\lower.25em\\hbox{y}\\kern-.125em...@}"); -static docstring const lyxline_def = from_ascii( - "\\newcommand{\\lyxline}[1][1pt]{%\n" - " \\par\\noindent%\n" - " \\rule[.5ex]{\\linewidth}{#1}\\par}"); - static docstring const noun_def = from_ascii( "\\newcommand{\\noun}[1]{\\textsc{#1}}"); @@ -805,9 +800,6 @@ if (mustProvide("LyX")) macros << lyx_def << '\n'; - if (mustProvide("lyxline")) - macros << lyxline_def << '\n'; - if (mustProvide("noun")) macros << noun_def << '\n'; Index: src/LyXAction.cpp =================================================================== --- src/LyXAction.cpp (revision 35287) +++ src/LyXAction.cpp (working copy) @@ -2378,12 +2378,12 @@ * \var lyx::FuncCode lyx::LFUN_INSET_SETTINGS * \li Action: Open the inset's properties dialog. * \li Notion: Used for bibitem, bibtex, box, branch, citation, ert, external, - float, graphics, href, include, index, index_print, label, listings, - note, phantom, ref, space, tabular, vspace, wrap insets. + float, graphics, href, include, index, index_print, label, line, + listings, note, phantom, ref, space, tabular, vspace, wrap insets. * \li Syntax: inset-settings <INSET> * \li Params: <INSET>: <bibitem|bibtex|box|branch|citation|ert|external|float| - graphics|href|include|index|index_print|label|listings| - note|phantom|ref|space|tabular|vspace|wrap>. + graphics|href|include|index|index_print|label|line| + listings|note|phantom|ref|space|tabular|vspace|wrap>. * \endvar */ { LFUN_INSET_SETTINGS, "inset-settings", ReadOnly | AtPoint, Edit }, @@ -2663,7 +2663,7 @@ * \li Syntax: dialog-show <NAME> [<DATA>] * \li Params: <NAME>: aboutlyx|bibitem|bibtex|box|branch|changes|character|citation|\n compare|document|errorlist|ert|external|file|findreplace|findreplaceadv|float|\n - graphics|href|include|index|index_print|info|label|listings|log|mathdelimiter|\n + graphics|href|include|index|index_print|info|label|line|listings|log|mathdelimiter|\n mathmatrix|mathspace|nomenclature|nomencl_print|note|paragraph|phantom|prefs|\n print|ref|sendto|space|spellchecker|symbols|tabular|tabularcreate|\n thesaurus|texinfo|toc|view-source|vspace|wrap|<SPECIAL> \n Index: src/Text.cpp =================================================================== --- src/Text.cpp (revision 35287) +++ src/Text.cpp (working copy) @@ -53,7 +53,6 @@ #include "insets/InsetText.h" #include "insets/InsetBibitem.h" #include "insets/InsetCaption.h" -#include "insets/InsetLine.h" #include "insets/InsetNewline.h" #include "insets/InsetNewpage.h" #include "insets/InsetArgument.h" @@ -452,11 +451,6 @@ auto_ptr<Inset> inset(new InsetTabular(buf)); inset->read(lex); par.insertInset(par.size(), inset.release(), font, change); - } else if (token == "\\lyxline") { - auto_ptr<Inset> inset; - inset.reset(new InsetLine); - inset->setBuffer(*buf); - par.insertInset(par.size(), inset.release(), font, change); } else if (token == "\\change_unchanged") { change = Change(Change::UNCHANGED); } else if (token == "\\change_inserted" || token == "\\change_deleted") { Index: src/Text3.cpp =================================================================== --- src/Text3.cpp (revision 35287) +++ src/Text3.cpp (working copy) @@ -1548,6 +1548,22 @@ break; } + case LFUN_LINE_INSERT: { + InsetCommandParams p(LINE_CODE); + p["offset"] = from_ascii(".5ex"); + p["width"] = from_ascii("100col%"); + p["height"] = from_ascii("1pt"); + string const data = InsetCommand::params2string("line", p); + + if (cmd.argument().empty()) { + bv->showDialog("line", data); + } else { + FuncRequest fr(LFUN_INSET_INSERT, data); + dispatch(cur, fr); + } + break; + } + case LFUN_INFO_INSERT: { Inset * inset; if (cmd.argument().empty() && cur.selection()) { @@ -1672,7 +1688,6 @@ case LFUN_NOMENCL_PRINT: case LFUN_TOC_INSERT: - case LFUN_LINE_INSERT: case LFUN_NEWPAGE_INSERT: // do nothing fancy doInsertInset(cur, this, cmd, false, false); @@ -2229,6 +2244,8 @@ code = NOMENCL_PRINT_CODE; else if (cmd.argument() == "label") code = LABEL_CODE; + else if (cmd.argument() == "line") + code = LINE_CODE; else if (cmd.argument() == "note") code = NOTE_CODE; else if (cmd.argument() == "phantom")