diff --git a/src/BufferView.C b/src/BufferView.C index 4d998fbc73..c7da720e5a 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -12,7 +12,6 @@ #include "BufferView.h" #include "BufferView_pimpl.h" -#include "BufferView_pimpl.h" #include "LaTeX.h" #include "ParagraphParameters.h" #include "WordLangTuple.h" diff --git a/src/ChangeLog b/src/ChangeLog index 54f18be7b9..956209ce19 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,4 +1,17 @@ +2003-05-19 André Pönitz + + * dimension.[Ch]: promote from mathed/dimension.[Ch] + + * Makefile.am: + * BufferView.C: + * DepTable.h: + * LaTeXFeatures.C: + * buffer.C: + * lyxfont.C: + * lyxlex.h: + * paragraph_funcs.C: dimensions() instead of ascend/descend/width + 2003-05-19 André Pönitz * buffer.C: diff --git a/src/DepTable.h b/src/DepTable.h index 9efe5c7612..676a2b4561 100644 --- a/src/DepTable.h +++ b/src/DepTable.h @@ -25,8 +25,7 @@ public: /** This one is a little bit harder since we need the absolute filename. Should we insert files with .sty .cls etc as extension? */ - void insert(string const & f, - bool upd = false); + void insert(string const & f, bool upd = false); /// void update(); diff --git a/src/LaTeXFeatures.C b/src/LaTeXFeatures.C index f79a7aa5e7..ae9e23002b 100644 --- a/src/LaTeXFeatures.C +++ b/src/LaTeXFeatures.C @@ -176,12 +176,12 @@ int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *); } + string const LaTeXFeatures::getPackages() const { ostringstream packages; LyXTextClass const & tclass = params.getLyXTextClass(); - // // These are all the 'simple' includes. i.e // packages which we just \usepackage{package} diff --git a/src/Makefile.am b/src/Makefile.am index 5b9d99363a..db9abb5441 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -121,6 +121,8 @@ lyx_SOURCES = \ counters.h \ debug.C \ debug.h \ + dimension.C \ + dimension.h \ encoding.C \ encoding.h \ exporter.C \ diff --git a/src/buffer.C b/src/buffer.C index 8783c6a876..146de3472f 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -161,10 +161,7 @@ Buffer::~Buffer() string const Buffer::getLatexName(bool no_path) const { string const name = ChangeExtension(MakeLatexName(fileName()), ".tex"); - if (no_path) - return OnlyFilename(name); - else - return name; + return no_path ? OnlyFilename(name) : name; } diff --git a/src/mathed/dimension.C b/src/dimension.C similarity index 66% rename from src/mathed/dimension.C rename to src/dimension.C index 5ceeec385a..f7fdd75089 100644 --- a/src/mathed/dimension.C +++ b/src/dimension.C @@ -10,10 +10,9 @@ #include -#include "dimension.h" -#include "math_support.h" -#include +#include "dimension.h" +#include "frontends/font_metrics.h" void Dimension::operator+=(Dimension const & dim) @@ -26,15 +25,9 @@ void Dimension::operator+=(Dimension const & dim) } -std::ostream & operator<<(std::ostream & os, Dimension const & dim) -{ - os << " (" << dim.w << 'x' << dim.a << '-' << dim.d << ") "; - return os; -} - - void Dimension::clear(LyXFont const & font) { - math_font_max_dim(font, a, d); + a = font_metrics::maxAscent(font); + d = font_metrics::maxDescent(font); w = 0; } diff --git a/src/mathed/dimension.h b/src/dimension.h similarity index 79% rename from src/mathed/dimension.h rename to src/dimension.h index 7edfcaf153..7fe34b34d6 100644 --- a/src/mathed/dimension.h +++ b/src/dimension.h @@ -15,12 +15,10 @@ #define DIMENSION_H -#include - class LyXFont; /// Simple wrapper around three ints -class Dimension { +struct Dimension { public: /// constructor Dimension() : w(0), a(0), d(0) {} @@ -43,6 +41,15 @@ public: int width() const { return w; } public: + /// these are intentionally public as things like + /// + /// dim.a += 20; + /// + /// are used all over the place and "hiding" those behind + /// + /// dim.ascent(dim.ascent() + 20); + /// + /// makes the code neither faster nor clearer /// width int w; /// ascent @@ -51,6 +58,4 @@ public: int d; }; -std::ostream & operator<<(std::ostream & os, Dimension const & dim); - #endif diff --git a/src/frontends/controllers/ControlDocument.C b/src/frontends/controllers/ControlDocument.C index 36c92ed93e..295eb9e844 100644 --- a/src/frontends/controllers/ControlDocument.C +++ b/src/frontends/controllers/ControlDocument.C @@ -62,7 +62,6 @@ void ControlDocument::apply() if (!bufferIsAvailable()) return; - classApply(); view().apply(); diff --git a/src/frontends/qt2/Alert_pimpl.C b/src/frontends/qt2/Alert_pimpl.C index 9e4b3a3880..41e0fa8dc6 100644 --- a/src/frontends/qt2/Alert_pimpl.C +++ b/src/frontends/qt2/Alert_pimpl.C @@ -10,7 +10,6 @@ #include - #include #include #include diff --git a/src/frontends/xforms/xformsImage.C b/src/frontends/xforms/xformsImage.C index d32f08270b..5956906cb8 100644 --- a/src/frontends/xforms/xformsImage.C +++ b/src/frontends/xforms/xformsImage.C @@ -10,7 +10,6 @@ #include - #include "xformsImage.h" #include "graphics/GraphicsParams.h" #include "Color.h" diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index bfb9043cf3..1d487f1208 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -21,6 +21,7 @@ #include "support/LAssert.h" #include "support/FileInfo.h" #include "support/filetools.h" +#include "support/tostr.h" #include "support/lstrings.h" // frontStrip, strip #include "lyx_forms.h" @@ -196,9 +197,7 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice, fl_set_input(input, ""); fl_set_choice_text(choice, default_unit.c_str()); } else { - ostringstream buffer; - buffer << len.value(); - fl_set_input(input, buffer.str().c_str()); + fl_set_input(input, tostr(len.value()).c_str()); // Set the choice to the desired unit, if present in the choice. // Else set the choice to the default unit. @@ -220,7 +219,8 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice, string formatted(string const & sin, int w, int size, int style) { string sout; - if (sin.empty()) return sout; + if (sin.empty()) + return sout; string::size_type curpos = 0; string line; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 80b522f599..93aeab8aa1 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,4 +1,22 @@ +2003-05-19 André Pönitz + + * inset.[Ch]: + * insetbutton.[Ch]: + * insetcollapsable.[Ch]: + * inseterror.[Ch]: + * insetert.[Ch]: + * insetfoot.[Ch]: + * insetgraphics.[Ch]: + * insetgraphicsParams.[Ch]: + * insetlatexaccent.[Ch]: + * insetminipage.[Ch]: + * insetnewline.[Ch]: + * insetquotes.[Ch]: + * insetspecialchar.[Ch]: + * insettabular.[Ch]: + * insettext.[Ch]: dimensions() instead of ascend/descend/width + 2003-05-19 André Pönitz * insetenv.[Ch]: diff --git a/src/insets/inset.C b/src/insets/inset.C index 5c89fc89f8..51f655cf47 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -13,14 +13,13 @@ #include - #include "inset.h" - #include "BufferView.h" #include "funcrequest.h" #include "gettext.h" #include "lyxfont.h" #include "lyxtext.h" +#include "dimension.h" #include "frontends/Painter.h" #include "frontends/mouse_state.h" @@ -148,3 +147,27 @@ int Inset::latexTextWidth(BufferView * bv) const return bv->workWidth(); } + +int Inset::ascent(BufferView * bv, LyXFont const & font) const +{ + Dimension dim; + dimension(bv, font, dim); + return dim.ascent(); +} + + +int Inset::descent(BufferView * bv, LyXFont const & font) const +{ + Dimension dim; + dimension(bv, font, dim); + return dim.descent(); +} + + +int Inset::width(BufferView * bv, LyXFont const & font) const +{ + Dimension dim; + dimension(bv, font, dim); + return dim.width(); +} + diff --git a/src/insets/inset.h b/src/insets/inset.h index b306b35f2b..32843b5e30 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -18,12 +18,12 @@ #include "LString.h" #include "LColor.h" #include "insetbase.h" -#include "frontends/mouse_state.h" #include "support/types.h" #include class LyXFont; +class Dimension; class Buffer; class Painter; class LyXText; @@ -157,11 +157,13 @@ public: /// Inset(Inset const & in, bool same_id = false); /// - virtual int ascent(BufferView *, LyXFont const &) const = 0; + virtual void dimension(BufferView *, LyXFont const &, Dimension &) const = 0; /// - virtual int descent(BufferView *, LyXFont const &) const = 0; + int ascent(BufferView *, LyXFont const &) const; /// - virtual int width(BufferView *, LyXFont const &) const = 0; + int descent(BufferView *, LyXFont const &) const; + /// + int width(BufferView *, LyXFont const &) const; /// virtual void draw(BufferView *, LyXFont const &, int baseline, float & x) const = 0; /// update the inset representation diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 58371411a2..5a90fb006e 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -1,4 +1,3 @@ - #include "insetbase.h" diff --git a/src/insets/insetbutton.C b/src/insets/insetbutton.C index 809f49cf77..8f46a75574 100644 --- a/src/insets/insetbutton.C +++ b/src/insets/insetbutton.C @@ -12,9 +12,9 @@ #include - #include "insetbutton.h" #include "debug.h" +#include "dimension.h" #include "BufferView.h" #include "funcrequest.h" #include "frontends/LyXView.h" @@ -27,69 +27,22 @@ using std::ostream; using std::endl; -int InsetButton::ascent(BufferView * bv, LyXFont const &) const +void InsetButton::dimension(BufferView * bv, LyXFont const &, + Dimension & dim) const { lyx::Assert(bv); LyXFont font(LyXFont::ALL_SANE); font.decSize(); - int width; - int ascent; - int descent; string const s = getScreenLabel(bv->buffer()); - if (editable()) { - font_metrics::buttonText(s, font, width, ascent, descent); - } else { - font_metrics::rectText(s, font, width, ascent, descent); - } - - return ascent; -} - - -int InsetButton::descent(BufferView * bv, LyXFont const &) const -{ - lyx::Assert(bv); - - LyXFont font(LyXFont::ALL_SANE); - font.decSize(); - - int width; - int ascent; - int descent; - string const s = getScreenLabel(bv->buffer()); - - if (editable()) { - font_metrics::buttonText(s, font, width, ascent, descent); - } else { - font_metrics::rectText(s, font, width, ascent, descent); - } - - return descent; -} - - -int InsetButton::width(BufferView * bv, LyXFont const &) const -{ - lyx::Assert(bv); - - LyXFont font(LyXFont::ALL_SANE); - font.decSize(); - - int width; - int ascent; - int descent; - string const s = getScreenLabel(bv->buffer()); - - if (editable()) { - font_metrics::buttonText(s, font, width, ascent, descent); - } else { - font_metrics::rectText(s, font, width, ascent, descent); - } - - return width + 4; + if (editable()) + font_metrics::buttonText(s, font, dim.w, dim.a, dim.d); + else + font_metrics::rectText(s, font, dim.w, dim.a, dim.d); + + dim.w += 4; } diff --git a/src/insets/insetbutton.h b/src/insets/insetbutton.h index a27485a17a..9d5deb9266 100644 --- a/src/insets/insetbutton.h +++ b/src/insets/insetbutton.h @@ -24,11 +24,7 @@ class InsetButton: public Inset { public: /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// void draw(BufferView *, LyXFont const &, int, float &) const; /// diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index 1b4feaee44..d5d84fd95c 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -26,33 +26,23 @@ public: /// void read(Buffer const * buf, LyXLex & lex); /// - virtual - bool display() const; + virtual bool display() const; /// - virtual - bool needFullRow() const; + virtual bool needFullRow() const; /// - virtual - Inset::Code lyxCode() const; + virtual Inset::Code lyxCode() const; /// - virtual - string const editMessage() const; + virtual string const editMessage() const; /// - virtual - void draw(BufferView * bv, LyXFont const & f, + virtual void draw(BufferView * bv, LyXFont const & f, int baseline, float & x) const; /// - virtual - int latex(Buffer const * buf, std::ostream & os, + virtual int latex(Buffer const * buf, std::ostream & os, bool fragile, bool free_spc) const; /// - virtual int ascii(Buffer const * buf, std::ostream & os, int linelen) const; /// - virtual int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const; -protected: -private: }; @@ -75,4 +65,5 @@ Inset::Code InsetCaption::lyxCode() const { return CAPTION_CODE; } + #endif diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index ea684568d0..3bb3f46f1d 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -17,6 +17,7 @@ #include "BufferView.h" #include "debug.h" +#include "dimension.h" #include "gettext.h" #include "lyxfont.h" #include "lyxlex.h" @@ -88,7 +89,6 @@ void InsetCollapsable::write(Buffer const * buf, ostream & os) const } - void InsetCollapsable::read(Buffer const * buf, LyXLex & lex) { if (lex.isOK()) { @@ -108,64 +108,31 @@ void InsetCollapsable::read(Buffer const * buf, LyXLex & lex) } -int InsetCollapsable::ascent_collapsed() const +void InsetCollapsable::dimension_collapsed(Dimension & dim) const { - int width = 0; - int ascent = 0; - int descent = 0; - font_metrics::buttonText(label, labelfont, width, ascent, descent); - return ascent; + font_metrics::buttonText(label, labelfont, dim.w, dim.a, dim.d); + dim.w += 2 * TEXT_TO_INSET_OFFSET; } -int InsetCollapsable::descent_collapsed() const +int InsetCollapsable::height_collapsed() const { - int width = 0; - int ascent = 0; - int descent = 0; - font_metrics::buttonText(label, labelfont, width, ascent, descent); - return descent; + Dimension dim; + font_metrics::buttonText(label, labelfont, dim.w, dim.a, dim.d); + return dim.a + dim.d; } -//int InsetCollapsable::width_collapsed(Painter & pain) const -int InsetCollapsable::width_collapsed() const +void InsetCollapsable::dimension(BufferView * bv, LyXFont const & font, + Dimension & dim) const { - int width; - int ascent; - int descent; - font_metrics::buttonText(label, labelfont, width, ascent, descent); - return width + 2 * TEXT_TO_INSET_OFFSET; -} - - -int InsetCollapsable::ascent(BufferView * /*bv*/, LyXFont const &) const -{ - return ascent_collapsed(); -} - - -int InsetCollapsable::descent(BufferView * bv, LyXFont const & font) const -{ - if (collapsed_) - return descent_collapsed(); - - return descent_collapsed() - + inset.descent(bv, font) - + inset.ascent(bv, font) - + TEXT_TO_BOTTOM_OFFSET; -} - - -int InsetCollapsable::width(BufferView * bv, LyXFont const & font) const -{ - if (collapsed_) - return width_collapsed(); - - int const collapsed_width = width_collapsed(); - int const contents_width = inset.width(bv, font); - - return max(collapsed_width, contents_width); + dimension_collapsed(dim); + if (collapsed_) + return; + Dimension insetdim; + inset.dimension(bv, font, insetdim); + dim.d += insetdim.height() + TEXT_TO_BOTTOM_OFFSET; + dim.w = max(dim.w, insetdim.width()); } @@ -174,7 +141,9 @@ void InsetCollapsable::draw_collapsed(Painter & pain, { pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, baseline, label, labelfont); - x += width_collapsed(); + Dimension dim; + dimension_collapsed(dim); + x += dim.w; } @@ -187,12 +156,14 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, if (nodraw()) return; + Dimension dim_collapsed; + dimension_collapsed(dim_collapsed); + Painter & pain = bv->painter(); - button_length = width_collapsed(); - button_top_y = -ascent(bv, f); - button_bottom_y = -ascent(bv, f) + ascent_collapsed() + - descent_collapsed(); + button_length = dim_collapsed.width(); + button_top_y = -ascent(bv, f); + button_bottom_y = -ascent(bv, f) + dim_collapsed.height(); if (!isOpen()) { draw_collapsed(pain, baseline, x); @@ -207,15 +178,16 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, top_x = int(x); top_baseline = baseline; - int const bl = baseline - ascent(bv, f) + ascent_collapsed(); + int const bl = baseline - ascent(bv, f) + dim_collapsed.ascent(); if (inlined) { inset.draw(bv, f, baseline, x); } else { draw_collapsed(pain, bl, old_x); - inset.draw(bv, f, bl + descent_collapsed() + inset.ascent(bv, f), x); + int const yy = bl + dim_collapsed.descent() + inset.ascent(bv, f); + inset.draw(bv, f, yy, x); // contained inset may be shorter than the button - if (x < (top_x + button_length + TEXT_TO_INSET_OFFSET)) + if (x < top_x + button_length + TEXT_TO_INSET_OFFSET) x = top_x + button_length + TEXT_TO_INSET_OFFSET; } } @@ -259,9 +231,7 @@ FuncRequest InsetCollapsable::adjustCommand(FuncRequest const & cmd) LyXFont font(LyXFont::ALL_SANE); FuncRequest cmd1 = cmd; cmd1.y = ascent(cmd.view(), font) + cmd.y - - (ascent_collapsed() + - descent_collapsed() + - inset.ascent(cmd.view(), font)); + (height_collapsed() + inset.ascent(cmd.view(), font)); return cmd1; } @@ -394,9 +364,7 @@ Inset::RESULT InsetCollapsable::localDispatch(FuncRequest const & cmd) } else { LyXFont font(LyXFont::ALL_SANE); cmd1.y = ascent(bv, font) + cmd.y - - (ascent_collapsed() + - descent_collapsed() + - inset.ascent(bv, font)); + (height_collapsed() + inset.ascent(bv, font)); } inset.localDispatch(cmd); } diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 577111f21a..6550987174 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -45,18 +45,14 @@ public: /// void write(Buffer const *, std::ostream &) const; /// - int ascent(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; - /// - void draw(BufferView *, const LyXFont &, int , float &) const; + void draw(BufferView *, const LyXFont &, int, float &) const; /// draw, either inlined (no button) or collapsed/open void draw(BufferView * bv, LyXFont const & f, int baseline, float & x, bool inlined) const; /// - void update(BufferView *, bool =false); + void update(BufferView *, bool = false); /// EDITABLE editable() const; /// @@ -181,13 +177,11 @@ protected: virtual BufferView * view() const; /// - int ascent_collapsed() const; + void dimension_collapsed(Dimension &) const; /// - int descent_collapsed() const; + int height_collapsed() const; /// - int width_collapsed() const; - /// - void draw_collapsed(Painter & pain, int , float &) const; + void draw_collapsed(Painter & pain, int, float &) const; /// int getMaxTextWidth(Painter & pain, UpdatableInset const *) const; diff --git a/src/insets/inseterror.C b/src/insets/inseterror.C index 1470506170..dbca5c1222 100644 --- a/src/insets/inseterror.C +++ b/src/insets/inseterror.C @@ -13,6 +13,7 @@ #include "inseterror.h" #include "BufferView.h" +#include "dimension.h" #include "funcrequest.h" #include "gettext.h" #include "lyxfont.h" @@ -54,27 +55,14 @@ dispatch_result InsetError::localDispatch(FuncRequest const & cmd) } -int InsetError::ascent(BufferView *, LyXFont const & font) const +void InsetError::dimension(BufferView *, LyXFont const & font, + Dimension & dim) const { LyXFont efont; efont.setSize(font.size()).decSize(); - return font_metrics::maxAscent(efont) + 1; -} - - -int InsetError::descent(BufferView *, LyXFont const & font) const -{ - LyXFont efont; - efont.setSize(font.size()).decSize(); - return font_metrics::maxDescent(efont) + 1; -} - - -int InsetError::width(BufferView *, LyXFont const & font) const -{ - LyXFont efont; - efont.setSize(font.size()).decSize(); - return 6 + font_metrics::width(_("Error"), efont); + dim.a = font_metrics::maxAscent(efont) + 1; + dim.d = font_metrics::maxDescent(efont) + 1; + dim.w = 6 + font_metrics::width(_("Error"), efont); } diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index fa23e55fa4..06525a0356 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -30,11 +30,7 @@ public: /// virtual dispatch_result localDispatch(FuncRequest const & cmd); /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// void draw(BufferView *, LyXFont const &, int, float &) const; /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 2c5db8d3ae..24c076ff63 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -306,7 +306,7 @@ bool InsetERT::lfunMouseRelease(FuncRequest const & cmd) if (status_ == Inlined) inset.localDispatch(cmd1); else if (!collapsed_ && (cmd.y > button_bottom_y)) { - cmd1.y -= ascent_collapsed() + descent_collapsed(); + cmd1.y -= height_collapsed(); inset.localDispatch(cmd1); } } @@ -552,30 +552,13 @@ bool InsetERT::checkInsertChar(LyXFont & /* font */) } -int InsetERT::ascent(BufferView * bv, LyXFont const & font) const +void InsetERT::dimension(BufferView * bv, LyXFont const & font, + Dimension & dim) const { - if (!inlined()) - return InsetCollapsable::ascent(bv, font); - - return inset.ascent(bv, font); -} - - -int InsetERT::descent(BufferView * bv, LyXFont const & font) const -{ - if (!inlined()) - return InsetCollapsable::descent(bv, font); - - return inset.descent(bv, font); -} - - -int InsetERT::width(BufferView * bv, LyXFont const & font) const -{ - if (!inlined()) - return InsetCollapsable::width(bv, font); - - return inset.width(bv, font); + if (inlined()) + inset.dimension(bv, font, dim); + else + InsetCollapsable::dimension(bv, font, dim); } diff --git a/src/insets/insetert.h b/src/insets/insetert.h index e6cd89a1b7..75984623f7 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -99,11 +99,7 @@ public: WordLangTuple const selectNextWordToSpellcheck(BufferView *, float &) const; /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// void draw(BufferView *, const LyXFont &, int , float &) const; /// set the status of the inset diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index 345d921f51..e030627886 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -11,7 +11,6 @@ #include - #include "insetfoot.h" #include "gettext.h" #include "lyxfont.h" diff --git a/src/insets/insetfootlike.h b/src/insets/insetfootlike.h index 5248f5a8c8..a7989386b5 100644 --- a/src/insets/insetfootlike.h +++ b/src/insets/insetfootlike.h @@ -12,14 +12,11 @@ #ifndef INSETFOOTLIKE_H #define INSETFOOTLIKE_H - #include "insetcollapsable.h" // To have this class is probably a bit overkill... (Lgb) -/** The footnote inset - -*/ +// The footnote inset class InsetFootlike : public InsetCollapsable { public: /// diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index f423210c58..5a5f25ffc8 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -60,6 +60,7 @@ TODO #include "graphics/GraphicsParams.h" #include "lyxtext.h" +#include "dimension.h" #include "buffer.h" #include "BufferView.h" #include "converter.h" @@ -88,11 +89,11 @@ TODO #include "support/tostr.h" #include "support/systemcall.h" #include "support/os.h" +#include "support/lstrings.h" #include #include #include -#include "support/BoostFormat.h" #include // For the std::max @@ -287,45 +288,36 @@ bool InsetGraphics::imageIsDrawable() const } -int InsetGraphics::ascent(BufferView *, LyXFont const &) const +void InsetGraphics::dimension(BufferView *, LyXFont const & font, + Dimension & dim) const { cache_->old_ascent = 50; if (imageIsDrawable()) cache_->old_ascent = cache_->loader.image()->getHeight(); - return cache_->old_ascent; -} - - -int InsetGraphics::descent(BufferView *, LyXFont const &) const -{ - return 0; -} - - -int InsetGraphics::width(BufferView *, LyXFont const & font) const -{ + dim.a = cache_->old_ascent; + dim.d = 0; if (imageIsDrawable()) - return cache_->loader.image()->getWidth() + 2 * TEXT_TO_INSET_OFFSET; + dim.w = cache_->loader.image()->getWidth() + 2 * TEXT_TO_INSET_OFFSET; + else { + int font_width = 0; - int font_width = 0; + LyXFont msgFont(font); + msgFont.setFamily(LyXFont::SANS_FAMILY); - LyXFont msgFont(font); - msgFont.setFamily(LyXFont::SANS_FAMILY); + string const justname = OnlyFilename(params().filename); + if (!justname.empty()) { + msgFont.setSize(LyXFont::SIZE_FOOTNOTE); + font_width = font_metrics::width(justname, msgFont); + } - string const justname = OnlyFilename (params().filename); - if (!justname.empty()) { - msgFont.setSize(LyXFont::SIZE_FOOTNOTE); - font_width = font_metrics::width(justname, msgFont); + string const msg = statusMessage(); + if (!msg.empty()) { + msgFont.setSize(LyXFont::SIZE_TINY); + font_width = std::max(font_width, font_metrics::width(msg, msgFont)); + } + + dim.w = std::max(50, font_width + 15); } - - string const msg = statusMessage(); - if (!msg.empty()) { - msgFont.setSize(LyXFont::SIZE_TINY); - int const msg_width = font_metrics::width(msg, msgFont); - font_width = std::max(font_width, msg_width); - } - - return std::max(50, font_width + 15); } @@ -633,15 +625,8 @@ string const InsetGraphics::prepareFile(Buffer const * buf) const << temp_file << (success ? " succeeded\n" : " failed\n"); if (!success) { -#if USE_BOOST_FORMAT - boost::format fmt(_("Could not copy the file\n%1$s\ninto the temporary directory.")); - fmt % orig_file_with_path; - string str = fmt.str(); -#else - string str = _("Could not copy the file\n"); - str += orig_file_with_path; - str += _("\ninto the temporary directory."); -#endif + string str = bformat(_("Could not copy the file\n%1$s\n" + "into the temporary directory."), orig_file_with_path); Alert::error(_("Graphics display failed"), str); return orig_file; } @@ -677,16 +662,9 @@ string const InsetGraphics::prepareFile(Buffer const * buf) const Systemcall one; one.startscript(Systemcall::Wait, command); if (!IsFileReadable(ChangeExtension(outfile_base, to))) { -#if USE_BOOST_FORMAT - boost::format fmt(_("No information for converting %1$s format files to %1$s.\n" - "Try defining a convertor in the preferences.")); - fmt % from % to; - string str = fmt.str(); -#else - string str = _("No information for converting "); - str += from + _(" format files to ") + to; - str += _(".\nTry defining a convertor in the preferences."); -#endif + string str = bformat(_("No information for converting %1$s " + "format files to %1$s.\n" + "Try defining a convertor in the preferences."), from, to); Alert::error(_("Could not convert image"), str); } } diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 2acaa173d1..99c1273b83 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -35,11 +35,7 @@ public: /// virtual dispatch_result localDispatch(FuncRequest const & cmd); /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// void draw(BufferView *, LyXFont const &, int, float &) const; /// diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index d8b01f8404..1b8963802b 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -28,11 +28,13 @@ using std::ostream; + InsetGraphicsParams::InsetGraphicsParams() { init(); } + InsetGraphicsParams::InsetGraphicsParams(InsetGraphicsParams const & igp) { // I decided to skip the initialization since the copy will overwrite @@ -41,6 +43,7 @@ InsetGraphicsParams::InsetGraphicsParams(InsetGraphicsParams const & igp) copy(igp); } + InsetGraphicsParams & InsetGraphicsParams::operator=(InsetGraphicsParams const & params) { @@ -51,6 +54,7 @@ InsetGraphicsParams::operator=(InsetGraphicsParams const & params) return *this; } + void InsetGraphicsParams::init() { filename.erase(); @@ -73,6 +77,7 @@ void InsetGraphicsParams::init() special.erase(); // additional userdefined stuff } + void InsetGraphicsParams::copy(InsetGraphicsParams const & igp) { filename = igp.filename; @@ -95,6 +100,7 @@ void InsetGraphicsParams::copy(InsetGraphicsParams const & igp) special = igp.special; } + bool operator==(InsetGraphicsParams const & left, InsetGraphicsParams const & right) { @@ -123,12 +129,14 @@ bool operator==(InsetGraphicsParams const & left, return false; } + bool operator!=(InsetGraphicsParams const & left, InsetGraphicsParams const & right) { return !(left == right); } + void InsetGraphicsParams::Write(ostream & os) const { // Do not write the default values diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index da4bbe4375..d29506dc3f 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -13,6 +13,7 @@ #include "insetlatexaccent.h" #include "debug.h" +#include "dimension.h" #include "lyxrc.h" #include "support/lstrings.h" #include "BufferView.h" @@ -262,48 +263,34 @@ void InsetLatexAccent::checkContents() } -int InsetLatexAccent::ascent(BufferView *, LyXFont const & font) const +void InsetLatexAccent::dimension(BufferView *, LyXFont const & font, + Dimension & dim) const { - // This function is a bit too simplistix and is just a + // This function is a bit too simplistic and is just a // "try to make a fit for all accents" approach, to // make it better we need to know what kind of accent is // used and add to max based on that. - int max; if (candisp) { if (ic == ' ') - max = font_metrics::ascent('a', font); + dim.a = font_metrics::ascent('a', font); else - max = font_metrics::ascent(ic, font); + dim.a = font_metrics::ascent(ic, font); if (plusasc) - max += (font_metrics::maxAscent(font) + 3) / 3; - } else - max = font_metrics::maxAscent(font) + 4; - return max; -} + dim.a += (font_metrics::maxAscent(font) + 3) / 3; - -int InsetLatexAccent::descent(BufferView *, LyXFont const & font) const -{ - int max; - if (candisp) { if (ic == ' ') - max = font_metrics::descent('a', font); + dim.d = font_metrics::descent('a', font); else - max = font_metrics::descent(ic, font); + dim.d = font_metrics::descent(ic, font); if (plusdesc) - max += 3; - } else - max = font_metrics::maxDescent(font) + 4; - return max; -} + dim.d += 3; - -int InsetLatexAccent::width(BufferView *, LyXFont const & font) const -{ - if (candisp) - return font_metrics::width(ic, font); - else - return font_metrics::width(contents, font) + 4; + dim.w = font_metrics::width(ic, font); + } else { + dim.a = font_metrics::maxAscent(font) + 4; + dim.d = font_metrics::maxDescent(font) + 4; + dim.w = font_metrics::width(contents, font) + 4; + } } diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index 06345ef6e7..3c6bcf390b 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -34,11 +34,7 @@ public: explicit InsetLatexAccent(string const & string); /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// void draw(BufferView *, LyXFont const &, int, float &) const; /// diff --git a/src/insets/insetlist.h b/src/insets/insetlist.h index 78bb9a2ecd..6ed5875529 100644 --- a/src/insets/insetlist.h +++ b/src/insets/insetlist.h @@ -9,8 +9,8 @@ * Full author contact details are available in file CREDITS */ -#ifndef InsetList_H -#define InsetList_H +#ifndef INSETLIST_H +#define INSETLIST_H #include "insetcollapsable.h" diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 120b6841b3..90454e3779 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -16,8 +16,10 @@ #include "BufferView.h" #include "debug.h" +#include "dimension.h" #include "funcrequest.h" #include "gettext.h" +#include "Lsstream.h" #include "lyxfont.h" #include "lyxlex.h" #include "lyxtext.h" @@ -27,7 +29,6 @@ #include "frontends/Dialogs.h" #include "support/LOstream.h" -#include "support/lstrings.h" using std::ostream; using std::endl; @@ -217,50 +218,28 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex) } -int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const +void InsetMinipage::dimension(BufferView * bv, LyXFont const & font, + Dimension & dim) const { if (collapsed_) - return ascent_collapsed(); + dimension_collapsed(dim); else { - // Take placement into account. - int i = 0; + Dimension d; + InsetCollapsable::dimension(bv, font, dim); switch (params_.pos) { case top: - i = InsetCollapsable::ascent(bv, font); + dim.a = d.a; + dim.d = d.d; break; case center: - i = (InsetCollapsable::ascent(bv, font) - + InsetCollapsable::descent(bv, font)) / 2; + dim.a = d.height() / 2; + dim.d = dim.a; break; case bottom: - i = InsetCollapsable::descent(bv, font); + dim.a = d.d; + dim.d = d.a; break; } - return i; - } -} - - -int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const -{ - if (collapsed_) - return descent_collapsed(); - else { - // Take placement into account. - int i = 0; - switch (params_.pos) { - case top: - i = InsetCollapsable::descent(bv, font); - break; - case center: - i = (InsetCollapsable::ascent(bv, font) - + InsetCollapsable::descent(bv, font)) / 2; - break; - case bottom: - i = InsetCollapsable::ascent(bv, font); - break; - } - return i; } } diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index e6946a650f..33eb8ff90f 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -68,9 +68,7 @@ public: /// Inset * clone(Buffer const &, bool same_id = false) const; /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// Inset::Code lyxCode() const { return Inset::MINIPAGE_CODE; } /// diff --git a/src/insets/insetnewline.C b/src/insets/insetnewline.C index cdea8f9d5b..1becea0d8e 100644 --- a/src/insets/insetnewline.C +++ b/src/insets/insetnewline.C @@ -10,24 +10,20 @@ #include +#include "insetnewline.h" #include "BufferView.h" +#include "debug.h" +#include "dimension.h" #include "paragraph.h" #include "lyxtext.h" -#include "insetnewline.h" #include "support/LOstream.h" #include "frontends/Painter.h" #include "frontends/font_metrics.h" -#include "debug.h" - using std::ostream; using std::endl; -InsetNewline::InsetNewline() - : Inset() -{} - void InsetNewline::read(Buffer const *, LyXLex &) { @@ -41,21 +37,12 @@ void InsetNewline::write(Buffer const *, ostream & os) const } -int InsetNewline::ascent(BufferView *, LyXFont const & font) const +void InsetNewline::dimension(BufferView *, LyXFont const & font, + Dimension & dim) const { - return font_metrics::maxAscent(font); -} - - -int InsetNewline::descent(BufferView *, LyXFont const & font) const -{ - return font_metrics::maxDescent(font); -} - - -int InsetNewline::width(BufferView *, LyXFont const & font) const -{ - return font_metrics::width('n', font); + dim.a = font_metrics::maxAscent(font); + dim.d = font_metrics::maxDescent(font); + dim.w = font_metrics::width('n', font); } diff --git a/src/insets/insetnewline.h b/src/insets/insetnewline.h index 3a60b12596..84baa12ba2 100644 --- a/src/insets/insetnewline.h +++ b/src/insets/insetnewline.h @@ -18,7 +18,7 @@ class InsetNewline : public Inset { public: - InsetNewline(); + InsetNewline() {} virtual Inset * clone(Buffer const &, bool = false) const { return new InsetNewline; @@ -26,11 +26,7 @@ public: Inset::Code lyxCode() const { return Inset::NEWLINE_CODE; } - virtual int ascent(BufferView *, LyXFont const &) const; - - virtual int descent(BufferView *, LyXFont const &) const; - - virtual int width(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; virtual void draw(BufferView *, LyXFont const &, int baseline, float & x) const; diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index a1d05e0567..53fbebdb40 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -10,29 +10,26 @@ #include - #include "insetquotes.h" -#include "support/LAssert.h" -#include "support/lstrings.h" #include "BufferView.h" #include "LaTeXFeatures.h" #include "frontends/Painter.h" #include "buffer.h" #include "debug.h" +#include "dimension.h" #include "frontends/font_metrics.h" #include "language.h" #include "lyxfont.h" #include "lyxrc.h" #include "paragraph.h" #include "lyxlex.h" +#include "support/LAssert.h" +#include "support/lstrings.h" using std::ostream; using std::endl; -// Quotes. Used for the various quotes. German, English, French, -// Danish, Polish, all either double or single. - namespace { // codes used to read/write quotes to LyX files @@ -73,9 +70,7 @@ InsetQuotes::InsetQuotes(string const & str) } -InsetQuotes::InsetQuotes(quote_language l, - quote_side s, - quote_times t) +InsetQuotes::InsetQuotes(quote_language l, quote_side s, quote_times t) : language_(l), side_(s), times_(t) {} @@ -174,33 +169,22 @@ string const InsetQuotes::dispString(Language const * loclang) const } -int InsetQuotes::ascent(BufferView *, LyXFont const & font) const +void InsetQuotes::dimension(BufferView *, LyXFont const & font, + Dimension & dim) const { - return font_metrics::maxAscent(font); -} + dim.a = font_metrics::maxAscent(font); + dim.d = font_metrics::maxDescent(font); + dim.w = 0; - -int InsetQuotes::descent(BufferView *, LyXFont const & font) const -{ - return font_metrics::maxDescent(font); -} - - -int InsetQuotes::width(BufferView *, LyXFont const & font) const -{ string const text = dispString(font.language()); - int w = 0; - for (string::size_type i = 0; i < text.length(); ++i) { if (text[i] == ' ') - w += font_metrics::width('i', font); + dim.w += font_metrics::width('i', font); else if (i == 0 || text[i] != text[i - 1]) - w += font_metrics::width(text[i], font); + dim.w += font_metrics::width(text[i], font); else - w += font_metrics::width(',', font); + dim.w += font_metrics::width(',', font); } - - return w; } diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index 5d5a10463a..4e9e0bf01f 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -22,7 +22,6 @@ struct LaTeXFeatures; /** Quotes. - Used for the various quotes. German, English, French, all either double or single **/ class InsetQuotes : public Inset { @@ -68,13 +67,11 @@ public: InsetQuotes(string const & str = "eld"); /// Create the right quote inset after character c InsetQuotes(char c, BufferParams const & params); + /// + Inset * clone(Buffer const &, bool same_id = false) const; /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// void draw(BufferView *, LyXFont const &, int, float &) const; #if 0 @@ -97,8 +94,6 @@ public: /// void validate(LaTeXFeatures &) const; /// - virtual Inset * clone(Buffer const &, bool same_id = false) const; - /// Inset::Code lyxCode() const; // should this inset be handled like a normal charater bool isChar() const { return true; } diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index 23a30b53d4..54a6a2e354 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -12,9 +12,10 @@ #include - #include "insetspecialchar.h" + #include "debug.h" +#include "dimension.h" #include "LaTeXFeatures.h" #include "BufferView.h" #include "frontends/Painter.h" @@ -25,6 +26,7 @@ using std::ostream; using std::max; + InsetSpecialChar::InsetSpecialChar(Kind k) : kind_(k) {} @@ -36,51 +38,23 @@ InsetSpecialChar::Kind InsetSpecialChar::kind() const } -int InsetSpecialChar::ascent(BufferView *, LyXFont const & font) const +void InsetSpecialChar::dimension(BufferView *, LyXFont const & font, + Dimension & dim) const { - return font_metrics::maxAscent(font); -} + dim.a = font_metrics::maxAscent(font); + dim.d = font_metrics::maxDescent(font); - -int InsetSpecialChar::descent(BufferView *, LyXFont const & font) const -{ - return font_metrics::maxDescent(font); -} - - -int InsetSpecialChar::width(BufferView *, LyXFont const & font) const -{ + char const * s = 0; switch (kind_) { - case HYPHENATION: - { - int w = font_metrics::width('-', font); - if (w > 5) - w -= 2; // to make it look shorter - return w; + case LIGATURE_BREAK: s = "|"; break; + case END_OF_SENTENCE: s = "."; break; + case LDOTS: s = ". . ."; break; + case MENU_SEPARATOR: s = " x "; break; + case PROTECTED_SEPARATOR: s = "x"; break; } - case LIGATURE_BREAK: - { - return font_metrics::width('|', font); - } - case END_OF_SENTENCE: - { - return font_metrics::width('.', font); - } - case LDOTS: - { - return font_metrics::width(". . .", font); - } - case MENU_SEPARATOR: - { - return font_metrics::width(" x ", font); - } - case PROTECTED_SEPARATOR: - { - return font_metrics::width('x', font); - } - - } - return 1; // To shut up gcc + dim.w = font_metrics::width('x', font); + if (kind_ == HYPHENATION && dim.w > 5) + dim.w -= 2; // to make it look shorter } diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index 09bc4d7d02..e56b713a22 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -48,11 +48,7 @@ public: /// Kind kind() const; /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// void draw(BufferView *, LyXFont const &, int, float &) const; /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index d13ee3a8a5..84cfd4f024 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -17,10 +17,12 @@ #include "BufferView.h" #include "lfuns.h" #include "debug.h" +#include "dimension.h" #include "funcrequest.h" #include "gettext.h" #include "language.h" #include "LaTeXFeatures.h" +#include "Lsstream.h" #include "lyx_cb.h" #include "lyxfunc.h" #include "lyxlength.h" @@ -242,21 +244,12 @@ void InsetTabular::read(Buffer const * buf, LyXLex & lex) } -int InsetTabular::ascent(BufferView *, LyXFont const &) const +void InsetTabular::dimension(BufferView *, LyXFont const &, + Dimension & dim) const { - return tabular->GetAscentOfRow(0); -} - - -int InsetTabular::descent(BufferView *, LyXFont const &) const -{ - return tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1; -} - - -int InsetTabular::width(BufferView *, LyXFont const &) const -{ - return tabular->GetWidthOfTabular() + (2 * ADD_TO_TABULAR_WIDTH); + dim.a = tabular->GetAscentOfRow(0); + dim.d = tabular->GetHeightOfTabular() - tabular->GetAscentOfRow(0) + 1; + dim.w = tabular->GetWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH; } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index b1992c9cca..eeb146a2a9 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -50,6 +50,7 @@ #include "LString.h" #include "lyxcursor.h" #include "FuncStatus.h" +#include "frontends/mouse_state.h" #include #include @@ -85,11 +86,7 @@ public: /// void write(Buffer const *, std::ostream &) const; /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const & f) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// void draw(BufferView *, const LyXFont &, int , float &) const; /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 85845d18f8..f0cc7fb301 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -16,11 +16,13 @@ #include "BufferView.h" #include "CutAndPaste.h" #include "debug.h" +#include "dimension.h" #include "funcrequest.h" #include "gettext.h" #include "intl.h" #include "LaTeXFeatures.h" #include "LColor.h" +#include "Lsstream.h" #include "lyxfont.h" #include "lyxcursor.h" #include "lyxfind.h" @@ -296,47 +298,29 @@ void InsetText::read(Buffer const * buf, LyXLex & lex) } -int InsetText::ascent(BufferView * bv, LyXFont const &) const +void InsetText::dimension(BufferView * bv, LyXFont const &, + Dimension & dim) const { - insetAscent = getLyXText(bv)->rows().begin()->ascent_of_text() + - TEXT_TO_INSET_OFFSET; - return insetAscent; -} - - -int InsetText::descent(BufferView * bv, LyXFont const &) const -{ - LyXText * llt = getLyXText(bv); - insetDescent = llt->height - llt->rows().begin()->ascent_of_text() + - TEXT_TO_INSET_OFFSET; - return insetDescent; -} - - -int InsetText::width(BufferView * bv, LyXFont const &) const -{ - insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) + - (2 * TEXT_TO_INSET_OFFSET); - insetWidth = max(insetWidth, 10); - return insetWidth; + LyXText * text = getLyXText(bv); + dim.a = text->rows().begin()->ascent_of_text() + TEXT_TO_INSET_OFFSET; + dim.d = text->height - dim.a + TEXT_TO_INSET_OFFSET; + dim.w = max(textWidth(bv), int(text->width)) + 2 * TEXT_TO_INSET_OFFSET; + dim.w = max(dim.w, 10); } int InsetText::textWidth(BufferView * bv, bool fordraw) const { - int w; - if (!autoBreakRows) { - w = -1; - } else { - w = getMaxWidth(bv, this); - } - if (fordraw) { - return max(w - (2 * TEXT_TO_INSET_OFFSET), + int w = autoBreakRows ? getMaxWidth(bv, this) : -1; + + if (fordraw) + return max(w - 2 * TEXT_TO_INSET_OFFSET, (int)getLyXText(bv)->width); - } else if (w < 0) { - return -1; - } - return w - (2 * TEXT_TO_INSET_OFFSET); + + if (w < 0) + return -1; + + return w - 2 * TEXT_TO_INSET_OFFSET; } @@ -2626,14 +2610,13 @@ void InsetText::getDrawFont(LyXFont & font) const } -void InsetText::appendParagraphs(Buffer * buffer, - ParagraphList & plist) +void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist) { #warning FIXME Check if Changes stuff needs changing here. (Lgb) // And it probably does. You have to take a look at this John. (Lgb) #warning John, have a look here. (Lgb) - BufferParams const & bparams = buffer->params; #if 0 + BufferParams const & bparams = buffer->params; Paragraph * buf; Paragraph * tmpbuf = newpar; Paragraph * lastbuffer = buf = new Paragraph(*tmpbuf, false); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 422cdf68a1..82d9dbbb64 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -86,11 +86,7 @@ public: /// void write(Buffer const *, std::ostream &) const; /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const & f) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// int textWidth(BufferView *, bool fordraw = false) const; /// diff --git a/src/lyxfont.C b/src/lyxfont.C index 517eb897d8..2b0ffbd34d 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -542,10 +542,11 @@ LyXFont & LyXFont::setLyXFamily(string const & fam) string const s = ascii_lowercase(fam); int i = 0; - while (s != LyXFamilyNames[i] && LyXFamilyNames[i] != "error") ++i; - if (s == LyXFamilyNames[i]) { + while (s != LyXFamilyNames[i] && LyXFamilyNames[i] != "error") + ++i; + if (s == LyXFamilyNames[i]) setFamily(LyXFont::FONT_FAMILY(i)); - } else + else lyxerr << "LyXFont::setLyXFamily: Unknown family `" << s << '\'' << endl; return *this; diff --git a/src/lyxlex.h b/src/lyxlex.h index f78a653c9c..4dda5a3697 100644 --- a/src/lyxlex.h +++ b/src/lyxlex.h @@ -28,7 +28,7 @@ struct keyword_item { class LyXLex : boost::noncopyable { public: /// - LyXLex (keyword_item *, int); + LyXLex(keyword_item *, int); /// ~LyXLex(); diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 7cfd0f5469..1f2daa0992 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,4 +1,14 @@ +2003-05-19 André Pönitz + + * Makefile.am: + * dimension.[Ch]: promote files to src/dimension.[Ch[ + + * formula.[Ch]: + * formulamacro.[Ch]: + * formulamacro.h: + * math_inset.h: replace ascents/descent/witdh with dimension() + 2003-05-14 André Pönitz * math_substack.[Ch]: add markers diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index b5bf583d50..a490bbdc81 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -5,8 +5,6 @@ noinst_LTLIBRARIES = libmathed.la INCLUDES = -I$(srcdir)/../ $(BOOST_INCLUDES) libmathed_la_SOURCES = \ - dimension.C \ - dimension.h \ textpainter.C \ textpainter.h \ formulabase.C \ diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 99adbf7d2f..79efa32e3a 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -34,6 +34,7 @@ #include "debug.h" #include "lyxrc.h" #include "funcrequest.h" +#include "Lsstream.h" #include "support/LOstream.h" #include "support/LAssert.h" @@ -275,29 +276,21 @@ bool InsetFormula::insetAllowed(Inset::Code code) const } -int InsetFormula::ascent(BufferView *, LyXFont const &) const -{ - return preview_->previewReady() ? - preview_->pimage()->ascent() : 1 + par_->ascent(); -} - - -int InsetFormula::descent(BufferView *, LyXFont const &) const -{ - if (!preview_->previewReady()) - return 1 + par_->descent(); - - int const descent = preview_->pimage()->descent(); - return display() ? descent + 12 : descent; -} - - -int InsetFormula::width(BufferView * bv, LyXFont const & font) const +void InsetFormula::dimension(BufferView * bv, LyXFont const & font, + Dimension & dim) const { metrics(bv, font); - return preview_->previewReady() ? - 1 + preview_->pimage()->width() : par_->width(); + if (preview_->previewReady()) { + dim.a = preview_->pimage()->ascent(); + int const descent = preview_->pimage()->descent(); + dim.d = display() ? descent + 12 : descent; // insert a one pixel gap in front of the formula + dim.w = 1 + preview_->pimage()->width(); + } else { + dim = par_->dimensions(); + dim.a += 1; + dim.d += 1; + } } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index cf45606dad..22a93b57cb 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -35,11 +35,7 @@ public: /// ~InsetFormula(); /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// void draw(BufferView *, LyXFont const &, int, float &) const; diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index f2fa252137..e33559d6bc 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -13,9 +13,7 @@ #ifndef INSET_FORMULABASE_H #define INSET_FORMULABASE_H - #include "insets/updatableinset.h" -#include "frontends/mouse_state.h" #include "lyxfont.h" #include @@ -25,17 +23,14 @@ class Buffer; class BufferView; class MathAtom; + /// An abstract base class for all math related LyX insets class InsetFormulaBase : public UpdatableInset { public: /// InsetFormulaBase(); /// - virtual int ascent(BufferView *, LyXFont const &) const = 0; - /// - virtual int descent(BufferView *, LyXFont const &) const = 0; - /// - virtual int width(BufferView *, LyXFont const &) const = 0; + Inset * clone(Buffer const &, bool same_id = false) const = 0; /// virtual void draw(BufferView *,LyXFont const &, int, float &) const = 0; /// lowest x coordinate @@ -53,8 +48,6 @@ public: // user-accessible way to override "false positives" virtual void validate(LaTeXFeatures &) const; /// - virtual Inset * clone(Buffer const &, bool same_id = false) const = 0; - /// virtual Inset::Code lyxCode() const; /// what appears in the minibuffer when opening virtual string const editMessage() const; diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index 5135bdfe61..0159403f40 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -126,29 +126,22 @@ void InsetFormulaMacro::read(std::istream & is) string InsetFormulaMacro::prefix() const { #if USE_BOOST_FORMAT - return boost::io::str(boost::format(_(" Macro: %s: ")) % getInsetName()); + return STRCONV(boost::io::str(boost::format(_(" Macro: %s: ")) % + STRCONV(getInsetName()))); #else return _(" Macro: ") + getInsetName() + ": "; #endif } -int InsetFormulaMacro::ascent(BufferView *, LyXFont const &) const +void InsetFormulaMacro::dimension(BufferView * bv, LyXFont const & font, + Dimension & dim) const { - return par()->ascent() + 5; -} - - -int InsetFormulaMacro::descent(BufferView *, LyXFont const &) const -{ - return par()->descent() + 5; -} - - -int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const -{ - metrics(bv, f); - return 10 + font_metrics::width(prefix(), f) + par()->width(); + metrics(bv, font); + dim = par()->dimensions(); + dim.a += 5; + dim.d += 5; + dim.w += 10 + font_metrics::width(prefix(), font); } diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index 8ad88e4001..4566b86dea 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -33,11 +33,7 @@ public: /// constructs a mocro from its LaTeX definition explicit InsetFormulaMacro(string const & s); /// - int ascent(BufferView *, LyXFont const &) const; - /// - int descent(BufferView *, LyXFont const &) const; - /// - int width(BufferView *, LyXFont const &) const; + void dimension(BufferView *, LyXFont const &, Dimension &) const; /// void draw(BufferView *, LyXFont const &, int, float &) const; diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 85e62e18a4..611d4fd75b 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -22,11 +22,9 @@ #ifndef MATH_INSET_H #define MATH_INSET_H - #include #include "LString.h" -#include "frontends/mouse_state.h" #include "insets/insetbase.h" #include "math_data.h" diff --git a/src/paragraph_funcs.C b/src/paragraph_funcs.C index 9ee4573abe..19cc57f1c9 100644 --- a/src/paragraph_funcs.C +++ b/src/paragraph_funcs.C @@ -41,6 +41,7 @@ using lyx::pos_type; using std::endl; using std::ostream; + void breakParagraph(BufferParams const & bparams, ParagraphList & paragraphs, ParagraphList::iterator par,