From 5f2e3c4c43f8e1736a2b7654595dfe6c175b4b3b Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Sat, 28 Jul 2001 12:24:16 +0000 Subject: [PATCH] Baruch's graphics patch + some small tweaks to the buttoncontroller stuff Kayvan's footnote patch Added a "Buffer const *" parameter to InsetButton::getScreenLabel and all daughter classes. Labels can now be tuned to suit, although non are yet. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2375 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ui/default.ui | 3 +- src/ChangeLog | 5 ++ src/buffer.C | 9 ++- src/frontends/controllers/ChangeLog | 5 ++ src/frontends/controllers/ControlGraphics.C | 2 +- src/frontends/xforms/ChangeLog | 20 +++++ src/frontends/xforms/FormGraphics.C | 31 +++---- src/frontends/xforms/FormGraphics.h | 2 - src/frontends/xforms/form_graphics.C | 9 +-- src/frontends/xforms/form_graphics.h | 1 - src/frontends/xforms/forms/form_graphics.fd | 40 +-------- src/frontends/xforms/input_validators.C | 30 +++++-- src/frontends/xforms/input_validators.h | 10 ++- src/insets/ChangeLog | 48 +++++++++++ src/insets/insetbib.C | 4 +- src/insets/insetbib.h | 4 +- src/insets/insetbutton.C | 8 +- src/insets/insetbutton.h | 2 +- src/insets/insetcite.C | 4 +- src/insets/insetcite.h | 2 +- src/insets/insetcommand.h | 7 -- src/insets/insetert.C | 4 +- src/insets/insetexternal.C | 2 +- src/insets/insetexternal.h | 2 +- src/insets/insetfloatlist.C | 4 +- src/insets/insetfloatlist.h | 2 +- src/insets/insetfoot.C | 5 ++ src/insets/insetfoot.h | 3 + src/insets/insetgraphics.C | 90 ++++++++++++++++++--- src/insets/insetgraphics.h | 5 ++ src/insets/insetgraphicsParams.C | 22 ++--- src/insets/insetgraphicsParams.h | 5 +- src/insets/insetinclude.C | 2 +- src/insets/insetinclude.h | 2 +- src/insets/insetindex.C | 4 +- src/insets/insetindex.h | 4 +- src/insets/insetlabel.h | 2 +- src/insets/insetparent.C | 2 +- src/insets/insetparent.h | 2 +- src/insets/insetref.C | 2 +- src/insets/insetref.h | 2 +- src/insets/insettoc.C | 4 +- src/insets/insettoc.h | 2 +- src/insets/inseturl.C | 2 +- src/insets/inseturl.h | 2 +- src/support/ChangeLog | 5 ++ src/support/lyxlib.h | 18 +++++ 47 files changed, 291 insertions(+), 154 deletions(-) diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 08feb4807a..c3397dada2 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -203,7 +203,8 @@ Menuset Separator Item "TeX|T" "ert-insert" Item "Minipage|p" "minipage-insert" - Item "Graphics...|G" "figure-insert" + Item "Old-Graphics..." "figure-insert" + Item "Graphics...|G" "graphics-insert" Item "Tabular Material...|b" "dialog-tabular-insert" Submenu "Floats|a" "insert_floats" Separator diff --git a/src/ChangeLog b/src/ChangeLog index 30bbef3549..ee55afb041 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -17,6 +17,11 @@ * text2.C (toggleFree): do selection with WHOLE_WORD_STRICT scheme. +2001-07-26 Baruch Even + + * buffer.C (readInset): Changed to call up InsetGraphics when reading + an InsetFig figure, backwards compatible reading of old figure code. + 2001-07-27 Juergen Vigna * text2.C: font.realize function adaption. diff --git a/src/buffer.C b/src/buffer.C index 3701b77683..e9316c6e3c 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1453,8 +1453,11 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par, inset = new InsetFormulaMacro; } else if (tmptok == "Formula") { inset = new InsetFormula; - } else if (tmptok == "Figure") { - inset = new InsetFig(100, 100, *this); + } else if (tmptok == "Figure") { // Backward compatibility + //inset = new InsetFig(100, 100, *this); + inset = new InsetGraphics; + } else if (tmptok == "GRAPHICS") { + inset = new InsetGraphics; } else if (tmptok == "Info") {// backwards compatibility inset = new InsetNote(this, lex.getLongString("\\end_inset"), @@ -1489,8 +1492,6 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par, #endif } else if (tmptok == "Caption") { inset = new InsetCaption; - } else if (tmptok == "GRAPHICS") { - inset = new InsetGraphics; } else if (tmptok == "FloatList") { inset = new InsetFloatList; } diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index cba478db16..e0b35b4227 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2001-07-26 Baruch Even + + * ControlGraphics.C: changed file search string to cover eps, jpeg, gif + and png. + 2001-07-23 John Levon * ControlInclude.h: diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index c3a2f4779d..ba54e93ad9 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -79,7 +79,7 @@ string const ControlGraphics::Browse(string const & in_name) { string const title = N_("Graphics"); // FIXME: currently we need the second '|' to prevent mis-interpretation - string const pattern = "*.(ps|png)|"; + string const pattern = "*.(eps|png|jpeg|gif)|"; // Does user clipart directory exist? string clipdir = AddName (user_lyxdir, "clipart"); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 8278b4a52b..77f5545b26 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,23 @@ +2001-07-26 Angus Leeming + + * input_validators.[Ch] (fl_int_filter, fl_float_filter): new methods. + + * FormGraphics.C (build): uncommented the fl_set_input_return call for + input_rotate_angle. Set input filter on rotate_angle to make it accept + only floating point numbers. + (input): Browse now activates the Ok button approriately. + +2001-07-26 Baruch Even + + * FormGraphics.h: + * FormGraphics.C: Removed hide method since it was interfering with the + needed work, it cleared several vectors that were needed for proper + functioning. Also changed rotateAngle to float. + + * FormGraphics.C: + * forms/form_graphics.fd: Removed inline option, all InsetGraphics figures + are inlined. + 2001-07-23 John Levon * FormInclude.C: add load file facility back diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index a4ef19ad23..e76973ff00 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -41,17 +41,6 @@ FormGraphics::FormGraphics(ControlGraphics & c) {} -void FormGraphics::hide() -{ - // Remove all associations for the radio buttons - widthButtons.reset(); - heightButtons.reset(); - displayButtons.reset(); - - FormBase::hide(); -} - - void FormGraphics::build() { dialog_.reset(build_graphics()); @@ -67,8 +56,8 @@ void FormGraphics::build() FL_RETURN_CHANGED); fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED); - // fl_set_input_return(dialog_->input_rotate_angle, - // FL_RETURN_CHANGED); + fl_set_input_return (dialog_->input_rotate_angle, + FL_RETURN_CHANGED); // Set the maximum characters that can be written in the input texts. fl_set_input_maxchars(dialog_->input_width, WIDTH_MAXDIGITS); @@ -83,6 +72,9 @@ void FormGraphics::build() fl_set_input_filter(dialog_->input_height, fl_unsigned_int_filter); + // Set input filter on rotate_angle to make it accept only + // floating point numbers. + fl_set_input_filter(dialog_->input_rotate_angle, fl_float_filter); // Add the widgets of the width radio buttons to their group widthButtons.reset(); @@ -133,7 +125,6 @@ void FormGraphics::build() bc().addReadOnly(dialog_->radio_button_group_height); bc().addReadOnly(dialog_->radio_button_group_display); bc().addReadOnly(dialog_->input_rotate_angle); - bc().addReadOnly(dialog_->check_inline); bc().addReadOnly(dialog_->input_subcaption); bc().addReadOnly(dialog_->check_subcaption); } @@ -157,17 +148,17 @@ void FormGraphics::apply() (heightButtons.getButton()); igp.heightSize = strToDbl(fl_get_input(dialog_->input_height)); - igp.rotateAngle = strToInt(fl_get_input(dialog_->input_rotate_angle)); + igp.rotateAngle = strToDbl(fl_get_input(dialog_->input_rotate_angle)); + /* // Need to redo it for floats, but I'm lazy now - BE 20010725 if (igp.rotateAngle >= 360) igp.rotateAngle = igp.rotateAngle % 360; if (igp.rotateAngle <= -360) igp.rotateAngle = - (( -igp.rotateAngle) % 360); + */ igp.subcaption = fl_get_button(dialog_->check_subcaption); igp.subcaptionText = fl_get_input(dialog_->input_subcaption); - igp.inlineFigure = fl_get_button(dialog_->check_inline); - igp.testInvariant(); } @@ -204,10 +195,6 @@ void FormGraphics::update() fl_set_input(dialog_->input_subcaption, igp.subcaptionText.c_str()); - // Update the inline figure check button - fl_set_button(dialog_->check_inline, - igp.inlineFigure); - // Now make sure that the buttons are set correctly. input(0, 0); } @@ -231,7 +218,7 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT *, long data) if (out_name != in_name && !out_name.empty()) { fl_set_input(dialog_->input_filename, out_name.c_str()); - input(0, 0); + activate = input(0, CHECKINPUT); } break; } diff --git a/src/frontends/xforms/FormGraphics.h b/src/frontends/xforms/FormGraphics.h index 4563f3193b..2c6b26ef80 100644 --- a/src/frontends/xforms/FormGraphics.h +++ b/src/frontends/xforms/FormGraphics.h @@ -37,8 +37,6 @@ private: virtual void apply(); /// Build the dialog. virtual void build(); - /// Hide the dialog. - virtual void hide(); /// Update dialog before/whilst showing it. virtual void update(); /// Filter the inputs on callback from xforms diff --git a/src/frontends/xforms/form_graphics.C b/src/frontends/xforms/form_graphics.C index f37e4496cf..ec76c10092 100644 --- a/src/frontends/xforms/form_graphics.C +++ b/src/frontends/xforms/form_graphics.C @@ -28,7 +28,6 @@ FD_form_graphics * FormGraphics::build_graphics() fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_gravity(obj, FL_NorthWest, FL_SouthEast); obj = fl_add_frame(FL_ENGRAVED_FRAME, 20, 310, 138, 30, ""); - obj = fl_add_frame(FL_ENGRAVED_FRAME, 279, 250, 201, 50, ""); { char const * const dummy = N_("Graphics File|#F"); fdui->input_filename = obj = fl_add_input(FL_NORMAL_INPUT, 150, 20, 210, 30, idex(_(dummy))); @@ -109,19 +108,13 @@ FD_form_graphics * FormGraphics::build_graphics() } fl_end_group(); - obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 20, 250, 236, 50, _("Rotate")); + obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 20, 250, 240, 50, _("Rotate")); { char const * const dummy = N_("Angle|#A"); fdui->input_rotate_angle = obj = fl_add_input(FL_INT_INPUT, 91, 260, 94, 30, idex(_(dummy))); fl_set_button_shortcut(obj, scex(_(dummy)), 1); } fl_set_object_callback(obj, C_FormBaseInputCB, CHECKINPUT); - { - char const * const dummy = N_("Inline Figure|#I"); - fdui->check_inline = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 279, 260, 201, 30, idex(_(dummy))); - fl_set_button_shortcut(obj, scex(_(dummy)), 1); - } - fl_set_object_callback(obj, C_FormBaseInputCB, CHECKINPUT); fdui->input_subcaption = obj = fl_add_input(FL_NORMAL_INPUT, 158, 310, 322, 30, ""); fl_set_object_callback(obj, C_FormBaseInputCB, CHECKINPUT); { diff --git a/src/frontends/xforms/form_graphics.h b/src/frontends/xforms/form_graphics.h index 0b33ef9e0d..224f3d1765 100644 --- a/src/frontends/xforms/form_graphics.h +++ b/src/frontends/xforms/form_graphics.h @@ -38,7 +38,6 @@ struct FD_form_graphics { FL_OBJECT *radio_display_color; FL_OBJECT *radio_no_display; FL_OBJECT *input_rotate_angle; - FL_OBJECT *check_inline; FL_OBJECT *input_subcaption; FL_OBJECT *check_subcaption; FL_OBJECT *button_restore; diff --git a/src/frontends/xforms/forms/form_graphics.fd b/src/frontends/xforms/forms/form_graphics.fd index aa6609a3be..0a6543a784 100644 --- a/src/frontends/xforms/forms/form_graphics.fd +++ b/src/frontends/xforms/forms/form_graphics.fd @@ -10,7 +10,7 @@ Unit of measure: FL_COORD_PIXEL Name: form_graphics Width: 490 Height: 390 -Number of Objects: 38 +Number of Objects: 36 -------------------- class: FL_BOX @@ -48,24 +48,6 @@ name: callback: argument: --------------------- -class: FL_FRAME -type: ENGRAVED_FRAME -box: 279 250 201 50 -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_INPUT type: NORMAL_INPUT @@ -540,7 +522,7 @@ argument: -------------------- class: FL_LABELFRAME type: ENGRAVED_FRAME -box: 20 250 236 50 +box: 20 250 240 50 boxtype: FL_NO_BOX colors: FL_BLACK FL_COL1 alignment: FL_ALIGN_TOP_LEFT @@ -573,24 +555,6 @@ name: input_rotate_angle callback: C_FormBaseInputCB argument: CHECKINPUT --------------------- -class: FL_CHECKBUTTON -type: PUSH_BUTTON -box: 279 260 201 30 -boxtype: FL_NO_BOX -colors: FL_COL1 FL_YELLOW -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE -lcol: FL_BLACK -label: Inline Figure|#I -shortcut: -resize: FL_RESIZE_ALL -gravity: FL_NoGravity FL_NoGravity -name: check_inline -callback: C_FormBaseInputCB -argument: CHECKINPUT - -------------------- class: FL_INPUT type: NORMAL_INPUT diff --git a/src/frontends/xforms/input_validators.C b/src/frontends/xforms/input_validators.C index e511e10e59..f22740e67e 100644 --- a/src/frontends/xforms/input_validators.C +++ b/src/frontends/xforms/input_validators.C @@ -14,10 +14,20 @@ extern "C" { #endif +int fl_int_filter(FL_OBJECT * ob, + char const *, char const *, int c) +{ + if (c == 0 /* final test before handing contents to app */ + || strchr("0123456789+-", c)) { + if (isStrInt(fl_get_input(ob))) + return FL_VALID; + } + return FL_INVALID|FL_RINGBELL; +} + + int fl_unsigned_int_filter(FL_OBJECT * /*ob*/, - char const * /*not_used*/, - char const * /*unused*/, - int c) + char const *, char const *, int c) { if (c == 0 /* final test before handing contents to app */ || strchr("0123456789", c)) { @@ -28,6 +38,18 @@ int fl_unsigned_int_filter(FL_OBJECT * /*ob*/, } +int fl_float_filter(FL_OBJECT * ob, + char const *, char const *, int c) +{ + if (c == 0 /* final test before handing contents to app */ + || strchr("0123456789.+-", c)) { + if (isStrDbl(fl_get_input(ob))) + return FL_VALID; + } + return FL_INVALID|FL_RINGBELL; +} + + int fl_unsigned_float_filter(FL_OBJECT * ob, char const * /*not_used*/, char const * /*unused*/, @@ -37,8 +59,6 @@ int fl_unsigned_float_filter(FL_OBJECT * ob, || strchr("0123456789.", c)) { if (isStrDbl(fl_get_input(ob))) return FL_VALID; - else - return FL_INVALID|FL_RINGBELL; } return FL_INVALID|FL_RINGBELL; } diff --git a/src/frontends/xforms/input_validators.h b/src/frontends/xforms/input_validators.h index cb111ba49a..26cb7571b9 100644 --- a/src/frontends/xforms/input_validators.h +++ b/src/frontends/xforms/input_validators.h @@ -25,9 +25,15 @@ extern "C" { #endif - /** Only allow whole numbers no '+' or '-' signs or exponents. */ + /** Only allow integer numbers, + possibly preceeded by a +' or '-' sign */ +int fl_int_filter(FL_OBJECT *, char const *, char const *, int); + /** Only allow integer numbers. No '+' or '-' signs. */ int fl_unsigned_int_filter(FL_OBJECT *, char const *, char const *, int); - /** Only allow whole numbers no '+' or '-' signs or exponents. */ + /** Only allow floating point numbers, + possibly preceeded by a +' or '-' sign */ +int fl_float_filter(FL_OBJECT *, char const *, char const *, int); + /** Only allow floating point numbers. No '+' or '-' signs. */ int fl_unsigned_float_filter(FL_OBJECT *, char const *, char const *, int); /** Only allow lowercase letters. */ diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index fa4c5b4a58..c9763f5527 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,51 @@ +2001-07-28 Angus Leeming + + * insetert.C (get_new_label): int -> Paragraph::size_type to get + std::min working. + + * insetgraphics.C: added a using std::endl directive. + + * insetcommand.h (getScreenLabel): removed pure virtual function, + as it duplicates that in InsetButton. + + * insetbib.[Ch] (getScreenLabel): + * insetbutton.[Ch] (getScreenLabel): + * insetcite.[Ch] (getScreenLabel): + * insetert.[Ch] (getScreenLabel): + * insetexternal.[Ch] (getScreenLabel): + * insetfloatlist.[Ch] (getScreenLabel): + * insetinclude.[Ch] (getScreenLabel): + * insetindex.[Ch] (getScreenLabel): + * insetlabel.h (getScreenLabel): + * insetparent.[Ch] (getScreenLabel): + * insetref.[Ch] (getScreenLabel): + * insettoc.[Ch] (getScreenLabel): + * inseturl.[Ch] (getScreenLabel): passed a Buffer const * parameter. + + * insetcite.C (getScreenLabel): use this Buffer parameter in creating + the label. + (validate): remove check on "cite" when using natbib. + +2001-07-26 Baruch Even + + * insetgraphics.C (draw): changed casting to be in one place rather than + all over the function. + + * insetgraphics.h: + * insetgraphics.C (read): Added compatibility reads of InsetFig. + + * insetgraphicsParams.h: + * insetgraphicsParams.C: + * insetgraphics.C: Removed inline option and changed rotateAngle to float. + +2001-07-28 Kayvan A. Sylvan + + * insetfoot.C (validate): Added method to ensure that the + right bit of LaTeX is emitted. + + * insetfoot.h: Added validate method to set the correct + LaTeXFeatures bit for the special footnote code. + 2001-07-26 Yves Bastide * insetquotes.C (dispString): display the right ISO8859-{1,9,15} diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 9f4caab3f9..4699700505 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -100,7 +100,7 @@ string const InsetBibKey::getBibLabel() const return tostr(counter); } -string const InsetBibKey::getScreenLabel() const +string const InsetBibKey::getScreenLabel(Buffer const *) const { return getContents() + " [" + getBibLabel() + "]"; } @@ -128,7 +128,7 @@ InsetBibtex::~InsetBibtex() } -string const InsetBibtex::getScreenLabel() const +string const InsetBibtex::getScreenLabel(Buffer const *) const { return _("BibTeX Generated References"); } diff --git a/src/insets/insetbib.h b/src/insets/insetbib.h index 50cf26f368..408d24b161 100644 --- a/src/insets/insetbib.h +++ b/src/insets/insetbib.h @@ -41,7 +41,7 @@ public: /// void read(Buffer const *, LyXLex & lex); /// - virtual string const getScreenLabel() const; + virtual string const getScreenLabel(Buffer const *) const; /// void edit(BufferView *, int x, int y, unsigned int button); /// @@ -87,7 +87,7 @@ public: return new InsetBibtex(params(), same_id); } /// - string const getScreenLabel() const; + string const getScreenLabel(Buffer const *) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// diff --git a/src/insets/insetbutton.C b/src/insets/insetbutton.C index 617b2bf820..c3b8907f6e 100644 --- a/src/insets/insetbutton.C +++ b/src/insets/insetbutton.C @@ -36,7 +36,7 @@ int InsetButton::ascent(BufferView * bv, LyXFont const &) const int width; int ascent; int descent; - string const s = getScreenLabel(); + string const s = getScreenLabel(bv->buffer()); #if 0 if (editable()) { @@ -68,7 +68,7 @@ int InsetButton::descent(BufferView * bv, LyXFont const &) const int width; int ascent; int descent; - string const s = getScreenLabel(); + string const s = getScreenLabel(bv->buffer()); #if 0 if (editable()) { @@ -100,7 +100,7 @@ int InsetButton::width(BufferView * bv, LyXFont const &) const int width; int ascent; int descent; - string const s = getScreenLabel(); + string const s = getScreenLabel(bv->buffer()); #if 0 if (editable()) { @@ -132,7 +132,7 @@ void InsetButton::draw(BufferView * bv, LyXFont const &, LyXFont font(LyXFont::ALL_SANE); font.setColor(LColor::command).decSize(); - string const s = getScreenLabel(); + string const s = getScreenLabel(bv->buffer()); #if 0 int width; diff --git a/src/insets/insetbutton.h b/src/insets/insetbutton.h index 23f4e73f6a..35c85c4f23 100644 --- a/src/insets/insetbutton.h +++ b/src/insets/insetbutton.h @@ -34,7 +34,7 @@ public: protected: /// This should provide the text for the button - virtual string const getScreenLabel() const = 0; + virtual string const getScreenLabel(Buffer const *) const = 0; }; #endif diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index 934e463e60..d89732c80d 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -25,7 +25,7 @@ InsetCitation::InsetCitation(InsetCommandParams const & p, bool) : InsetCommand(p) {} -string const InsetCitation::getScreenLabel() const +string const InsetCitation::getScreenLabel(Buffer const *) const { string keys(getContents()); @@ -98,6 +98,6 @@ int InsetCitation::latex(Buffer const * buffer, std::ostream & os, void InsetCitation::validate(LaTeXFeatures & features) const { - if (getCmdName() != "cite" && features.bufferParams().use_natbib) + if (features.bufferParams().use_natbib) features.natbib = true; } diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index 75db049ea2..efa21fd178 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -28,7 +28,7 @@ public: return new InsetCitation(params(), same_id); } /// - string const getScreenLabel() const; + string const getScreenLabel(Buffer const *) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index 6dd6ad05da..10eee35774 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -101,13 +101,6 @@ public: /// Inset::Code lyxCode() const { return Inset::NO_CODE; } - /** Get the label that appears at screen. - - I thought it was enough to eliminate the argument to avoid - confusion with lyxinset::getLabel(int), but I've seen that - it wasn't. I hope you never confuse again both methods. (ale) - */ - virtual string const getScreenLabel() const = 0; /// string const getCommand() const { return p_.getCommand(); } /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 4f2a75c964..d6df241c66 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -222,8 +222,8 @@ string const InsetERT::get_new_label() const string la; Paragraph::size_type const max_length = 15; - int const p_siz = inset.paragraph()->size(); - int const n = std::min(max_length, p_siz); + Paragraph::size_type const p_siz = inset.paragraph()->size(); + Paragraph::size_type const n = std::min(max_length, p_siz); int i = 0; int j = 0; for(; i < n && j < p_siz; ++j) { diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 51f177de40..47a7afdce1 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -202,7 +202,7 @@ Inset * InsetExternal::clone(Buffer const &, bool same_id) const } -string const InsetExternal::getScreenLabel() const +string const InsetExternal::getScreenLabel(Buffer const *) const { ExternalTemplate const & et = params_.templ; if (et.guiName.empty()) diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index fee519ee71..2dfd03ef87 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -79,7 +79,7 @@ public: virtual Inset * clone(Buffer const &, bool same_id = false) const; /// returns the text of the button - virtual string const getScreenLabel() const; + virtual string const getScreenLabel(Buffer const *) const; // The following public members are used from the frontends code diff --git a/src/insets/insetfloatlist.C b/src/insets/insetfloatlist.C index 3cb79a2c25..5b35f22f56 100644 --- a/src/insets/insetfloatlist.C +++ b/src/insets/insetfloatlist.C @@ -12,7 +12,7 @@ using std::endl; -string const InsetFloatList::getScreenLabel() const +string const InsetFloatList::getScreenLabel(Buffer const *) const { string const guiName = floatList[float_type]->second.name(); if (!guiName.empty()) { @@ -104,7 +104,7 @@ int InsetFloatList::latex(Buffer const *, std::ostream & os, bool, bool) const int InsetFloatList::ascii(Buffer const * buffer, std::ostream & os, int) const { - os << getScreenLabel() << "\n\n"; + os << getScreenLabel(buffer) << "\n\n"; Buffer::Lists const toc_list = buffer->getLists(); Buffer::Lists::const_iterator cit = diff --git a/src/insets/insetfloatlist.h b/src/insets/insetfloatlist.h index bf50f8ea10..a279574a7f 100644 --- a/src/insets/insetfloatlist.h +++ b/src/insets/insetfloatlist.h @@ -32,7 +32,7 @@ public: return new InsetFloatList(*this); } /// - string const getScreenLabel() const; + string const getScreenLabel(Buffer const *) const; /// void edit(BufferView * bv, int, int, unsigned int); /// diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index a9a103db49..1e0ccb8f39 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -62,3 +62,8 @@ int InsetFoot::latex(Buffer const * buf, return i + 2; } + +void InsetFoot::validate(LaTeXFeatures & features) const +{ + features.NeedLyXFootnoteCode = true; +} diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index 5f10835f91..d8e1f8cb4d 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -18,6 +18,7 @@ #pragma interface #endif +#include "LaTeXFeatures.h" #include "insetfootlike.h" /** The footnote inset @@ -37,6 +38,8 @@ public: int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// string const editMessage() const; + /// + void InsetFoot::validate(LaTeXFeatures & features) const; }; #endif diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 6ffb2d4155..530db1b052 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -150,6 +150,7 @@ TODO Extended features: extern string system_tempdir; using std::ostream; +using std::endl; // This function is a utility function inline @@ -337,6 +338,20 @@ void InsetGraphics::write(Buffer const * buf, ostream & os) const void InsetGraphics::read(Buffer const * buf, LyXLex & lex) +{ + string const token = lex.GetString(); + + if (token == "GRAPHICS") + readInsetGraphics(buf, lex); + else if (token == "Figure") // Compatibility reading of FigInset figures. + readFigInset(buf, lex); + else + lyxerr[Debug::INFO] << "Not a GRAPHICS or Figure inset!\n"; + + updateInset(); +} + +void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex) { bool finished = false; @@ -368,8 +383,70 @@ void InsetGraphics::read(Buffer const * buf, LyXLex & lex) << std::endl; } } +} - updateInset(); + +void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex) +{ + bool finished = false; + + while (lex.IsOK() && !finished) { + lex.next(); + + string const token = lex.GetString(); + lyxerr[Debug::INFO] << "Token: " << token << endl; + + if (token.empty()) + continue; + else if (token == "\\end_inset") { + finished = true; + } else if (token == "file") { + if (lex.next()) { + string const name = lex.GetString(); + string const path = OnlyPath(buf->fileName()); + params.filename = MakeAbsPath(name, path); + } + } else if (token == "extra") { + if (lex.next()); + // kept for backwards compability. Delete in 0.13.x + } else if (token == "subcaption") { + if (lex.EatLine()) + params.subcaptionText = lex.GetString(); + } else if (token == "label") { + if (lex.next()); + // kept for backwards compability. Delete in 0.13.x + } else if (token == "angle") { + if (lex.next()) + params.rotateAngle = lex.GetFloat(); + } else if (token == "size") { + // Size of image on screen is ignored in InsetGraphics, just eat + // the input. + if (lex.next()) + lex.GetInteger(); + if (lex.next()) + lex.GetInteger(); + } else if (token == "flags") { + InsetGraphicsParams::DisplayType tmp = InsetGraphicsParams::COLOR; + if (lex.next()) + switch (lex.GetInteger()) { + case 1: tmp = InsetGraphicsParams::MONOCHROME; break; + case 2: tmp = InsetGraphicsParams::GRAYSCALE; break; + } + params.display = tmp; + } else if (token == "subfigure") { + params.subcaption = true; + } else if (token == "width") { + if (lex.next()) + params.widthResize = static_cast(lex.GetInteger()); + if (lex.next()) + params.widthSize = lex.GetFloat(); + } else if (token == "height") { + if (lex.next()) + params.heightResize = static_cast(lex.GetInteger()); + if (lex.next()) + params.heightSize = lex.GetFloat(); + } + } } @@ -415,7 +492,9 @@ InsetGraphics::createLatexOptions() const formatResize(options, "width", params.widthResize, params.widthSize); formatResize(options, "height", params.heightResize, params.heightSize); - if (params.rotateAngle != 0) { + // Make sure it's not very close to zero, a float can be effectively + // zero but not exactly zero. + if (lyx::float_equal(params.rotateAngle, 0, 0.001)) { options << "angle=" << params.rotateAngle << ','; } @@ -511,13 +590,6 @@ int InsetGraphics::latex(Buffer const *buf, ostream & os, string before; string after; - // If it's not an inline image, surround it with the centering paragraph. - if (! params.inlineFigure) { - before += "\n" "\\vspace{0.3cm}\n" "{\\par\\centering "; - after = " \\par}\n" "\\vspace{0.3cm}\n" + after; - newlines += 4; - } - // Do we want subcaptions? if (params.subcaption) { before += "\\subfigure[" + params.subcaptionText + "]{"; diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 045995b764..ab83affc1b 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -98,6 +98,11 @@ public: SigC::Signal0 hideDialog; private: + /// Read the inset native format + void readInsetGraphics(Buffer const * buf, LyXLex & lex); + /// Read the FigInset file format + void readFigInset(Buffer const * buf, LyXLex & lex); + /// Update the inset after parameter change. void updateInset() const; /// Get the status message, depends on the image loading status. diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index 0218ac1ddc..6626aea350 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -18,6 +18,7 @@ #include "support/translator.h" #include "support/filetools.h" +#include "support/lyxlib.h" #include "support/LAssert.h" @@ -109,7 +110,6 @@ void InsetGraphicsParams::init() { subcaptionText = filename = string(); display = MONOCHROME; - inlineFigure = false; subcaption = false; keepAspectRatio = true; widthResize = DEFAULT_SIZE; @@ -117,7 +117,7 @@ void InsetGraphicsParams::init() heightResize = DEFAULT_SIZE; heightSize = 0.0; rotateOrigin = DEFAULT; - rotateAngle = 0; + rotateAngle = 0.0; testInvariant(); } @@ -126,7 +126,6 @@ void InsetGraphicsParams::copy(InsetGraphicsParams const & igp) { filename = igp.filename; display = igp.display; - inlineFigure = igp.inlineFigure; subcaption = igp.subcaption; subcaptionText = igp.subcaptionText; keepAspectRatio = igp.keepAspectRatio; @@ -171,8 +170,8 @@ void InsetGraphicsParams::testInvariant() const // The reason for this is that in latex there is a meaning for the // different angles and they are not necessarliy interchangeable, // it depends on the rotation origin. - lyx::Assert(rotateAngle < 360); - lyx::Assert(rotateAngle > -360); + lyx::Assert(rotateAngle < 360.0); + lyx::Assert(rotateAngle > -360.0); } @@ -181,7 +180,6 @@ bool operator==(InsetGraphicsParams const & left, { if (left.filename == right.filename && left.display == right.display && - left.inlineFigure == right.inlineFigure && left.subcaption == right.subcaption && left.subcaptionText == right.subcaptionText && left.keepAspectRatio == right.keepAspectRatio && @@ -190,7 +188,7 @@ bool operator==(InsetGraphicsParams const & left, left.heightResize == right.heightResize && left.heightSize == right.heightSize && left.rotateOrigin == right.rotateOrigin && - left.rotateAngle == right.rotateAngle + lyx::float_equal(left.rotateAngle, right.rotateAngle, 0.001) ) return true; @@ -237,10 +235,6 @@ void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const // Save the display type os << " display " << displayTranslator.find(display) << '\n'; - // Save the inline status - if (inlineFigure) - os << " inline"; - // Save the subcaption status if (subcaption) os << " subcaption"; @@ -252,7 +246,7 @@ void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const writeResize(os, "height", heightResize, heightSize); writeOrigin(os, rotateOrigin); - if (rotateAngle != 0) + if (lyx::float_equal(rotateAngle, 0.0, 0.001)) os << " rotateAngle " << rotateAngle << '\n'; } @@ -298,8 +292,6 @@ bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex, string const type = lex.GetString(); display = displayTranslator.find(type); - } else if (token == "inline") { - inlineFigure = true; } else if (token == "subcaption") { subcaption = true; } else if (token == "subcaptionText") { @@ -328,7 +320,7 @@ bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex, readOrigin(this, token); } else if (token == "rotateAngle") { lex.next(); - rotateAngle = lex.GetInteger(); + rotateAngle = lex.GetFloat(); } else { // If it's none of the above, its not ours. return false; diff --git a/src/insets/insetgraphicsParams.h b/src/insets/insetgraphicsParams.h index c774df827f..5eb3415ffc 100644 --- a/src/insets/insetgraphicsParams.h +++ b/src/insets/insetgraphicsParams.h @@ -44,9 +44,6 @@ struct InsetGraphicsParams /// How to display the image DisplayType display; - /// Is the figure inlined? (not in a paragraph of its own). - bool inlineFigure; - /// Do we have a subcaption? bool subcaption; @@ -97,7 +94,7 @@ struct InsetGraphicsParams /// Origin point of rotation Origin rotateOrigin; /// Rotation angle. - int rotateAngle; + float rotateAngle; /// InsetGraphicsParams(); /// diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 12315f3cc3..2ff7aa82b0 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -162,7 +162,7 @@ bool InsetInclude::display() const } -string const InsetInclude::getScreenLabel() const +string const InsetInclude::getScreenLabel(Buffer const *) const { string temp; diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 892ed6be20..043f23c273 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -119,7 +119,7 @@ public: SigC::Signal0 hideDialog; private: /// get the text displayed on the button - string const getScreenLabel() const; + string const getScreenLabel(Buffer const *) const; /// is this a verbatim include ? bool isVerbatim() const; /// get the filename of the master buffer diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index 87b3cfaa19..dc91d1f3c8 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -16,7 +16,7 @@ InsetIndex::InsetIndex(InsetCommandParams const & p, bool) {} -string const InsetIndex::getScreenLabel() const +string const InsetIndex::getScreenLabel(Buffer const *) const { return _("Idx"); } @@ -44,7 +44,7 @@ InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p, bool) : InsetCommand(p) {} -string const InsetPrintIndex::getScreenLabel() const +string const InsetPrintIndex::getScreenLabel(Buffer const *) const { return _("Index"); } diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index 051d78cd3f..36707af81d 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -31,7 +31,7 @@ public: return new InsetIndex(params(), same_id); } /// - string const getScreenLabel() const; + string const getScreenLabel(Buffer const *) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// @@ -64,7 +64,7 @@ public: /// Inset::Code lyxCode() const; /// - string const getScreenLabel() const; + string const getScreenLabel(Buffer const *) const; }; #endif diff --git a/src/insets/insetlabel.h b/src/insets/insetlabel.h index 094965e3c7..8fbfeeaa5a 100644 --- a/src/insets/insetlabel.h +++ b/src/insets/insetlabel.h @@ -27,7 +27,7 @@ public: return new InsetLabel(params(), same_id); } /// - string const getScreenLabel() const { return getContents(); } + string const getScreenLabel(Buffer const *) const { return getContents(); } /// EDITABLE editable() const { return IS_EDITABLE; } /// diff --git a/src/insets/insetparent.C b/src/insets/insetparent.C index 26d5cf0cfa..cf495ec7ec 100644 --- a/src/insets/insetparent.C +++ b/src/insets/insetparent.C @@ -37,7 +37,7 @@ InsetParent::InsetParent(InsetCommandParams const & p, Buffer const & bf, bool) } -string const InsetParent::getScreenLabel() const +string const InsetParent::getScreenLabel(Buffer const *) const { return string(_("Parent:")) + getContents(); } diff --git a/src/insets/insetparent.h b/src/insets/insetparent.h index 70e2e2434d..63e61b2e1e 100644 --- a/src/insets/insetparent.h +++ b/src/insets/insetparent.h @@ -33,7 +33,7 @@ public: return new InsetParent(params(), buffer, same_id); } /// - string const getScreenLabel() const; + string const getScreenLabel(Buffer const *) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// diff --git a/src/insets/insetref.C b/src/insets/insetref.C index ef0da4aa72..8910dcb4b8 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -38,7 +38,7 @@ void InsetRef::edit(BufferView *, bool) } -string const InsetRef::getScreenLabel() const +string const InsetRef::getScreenLabel(Buffer const *) const { string temp; for (int i = 0; !types[i].latex_name.empty(); ++ i) diff --git a/src/insets/insetref.h b/src/insets/insetref.h index eec668ea79..31eed6a1e4 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -44,7 +44,7 @@ public: return new InsetRef(params(), buffer, same_id); } /// - string const getScreenLabel() const; + string const getScreenLabel(Buffer const *) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index 32d9560d6b..d78ef8f37b 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -14,7 +14,7 @@ using std::vector; -string const InsetTOC::getScreenLabel() const +string const InsetTOC::getScreenLabel(Buffer const *) const { string const cmdname(getCmdName()); @@ -47,7 +47,7 @@ void InsetTOC::edit(BufferView * bv, bool) int InsetTOC::ascii(Buffer const * buffer, std::ostream & os, int) const { - os << getScreenLabel() << "\n\n"; + os << getScreenLabel(buffer) << "\n\n"; string type; string const cmdname = getCmdName(); diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index 4107d128a0..349cf61171 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -30,7 +30,7 @@ public: return new InsetTOC(params(), same_id); } /// - string const getScreenLabel() const; + string const getScreenLabel(Buffer const *) const; /// void edit(BufferView * bv, int, int, unsigned int); /// diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index 241c69fffe..03531c8db8 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -32,7 +32,7 @@ void InsetUrl::edit(BufferView * bv, bool) } -string const InsetUrl::getScreenLabel() const +string const InsetUrl::getScreenLabel(Buffer const *) const { string temp; if (getCmdName() == "url" ) diff --git a/src/insets/inseturl.h b/src/insets/inseturl.h index 4fffbcae6d..b97913009d 100644 --- a/src/insets/inseturl.h +++ b/src/insets/inseturl.h @@ -35,7 +35,7 @@ public: /// void validate(LaTeXFeatures &) const; /// - string const getScreenLabel() const; + string const getScreenLabel(Buffer const *) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// diff --git a/src/support/ChangeLog b/src/support/ChangeLog index d0d4a5e15a..7c7ec802d0 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,8 @@ +2001-07-26 Baruch Even + + * lyxlib.h (float_equal): Added function to compare floats almost equal + (see function comment). + 2001-07-13 Angus Leeming Consistent use of Lsstream.h: diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index 290043e88d..8554ca0ec8 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -53,5 +53,23 @@ int atoi(string const & nstr); string const tempName(string const & dir = string(), string const & mask = string()); + +/** Returns true if var is approximately equal to number with allowed error + * of 'error'. + * + * Reason: A float can be very close to the number, yet still need not be + * exactly equal, you can have exp(-10) which is very close to zero but not + * zero. If you only need an approximate equality (you usually do), use this + * template. + * + * Usage: if (float_equal(var, number, 0.0001)) { } + * + * This will check if 'var' is approx. equal to 'number' with error of 1/1000 + */ +inline bool float_equal(float var, float number, float error) +{ + return (number - error <= var && var <= number + error); +} + } // namespace lyx #endif /* LYX_LIB_H */ -- 2.39.2