From 93dda00aac4957bda8590e6cad2716081c8eee7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Thu, 22 Mar 2001 19:36:21 +0000 Subject: [PATCH] minipage placement testing git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1807 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer.C | 40 +++++++++++++++------------- src/insets/insetcollapsable.C | 15 ++++++++++- src/insets/insetminipage.C | 50 +++++++++++++++++++++++++++++++++++ src/insets/insetminipage.h | 10 ++++--- 4 files changed, 92 insertions(+), 23 deletions(-) diff --git a/src/buffer.C b/src/buffer.C index 10cd887bef..b388f2d9e4 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -2809,7 +2809,8 @@ void linux_doc_line_break(ostream & os, string::size_type & colcount, // Handle internal paragraph parsing -- layout already processed. -void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par, int /*depth*/) +void Buffer::SimpleLinuxDocOnePar(ostream & os, + LyXParagraph * par, int /*depth*/) { LyXLayout const & style = textclasslist.Style(params.textclass, par->GetLayout()); @@ -2821,8 +2822,7 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par, int /*depth* if (style.labeltype == LABEL_MANUAL) { font_old = style.labelfont; desc_on = true; - } - else { + } else { font_old = style.font; desc_on = false; } @@ -2843,12 +2843,12 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par, int /*depth* }; char const * tag_name[] = {"tt","sf","bf","it","sl","em"}; - stack tag_state; + stack tag_state; // parsing main loop for (LyXParagraph::size_type i = 0; i < par->size(); ++i) { - bitset < LAST > tag_close; - list tag_open; + bitset tag_close; + list tag_open; LyXFont const font = par->getFont(params, i); @@ -2929,16 +2929,15 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par, int /*depth* if (font.emph() == LyXFont::ON) { tag_open.push_back(EM); is_em = true; - } - else if (is_em) { + } else if (is_em) { tag_close.set(EM); is_em = false; } } - list temp; - while(!tag_state.empty() && tag_close.any()) { - int k=tag_state.top(); + list temp; + while (!tag_state.empty() && tag_close.any()) { + int k = tag_state.top(); tag_state.pop(); os << ""; if (tag_close[k]) @@ -2947,13 +2946,13 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par, int /*depth* temp.push_back(k); } - for(list::const_iterator j = temp.begin(); + for (list::const_iterator j = temp.begin(); j != temp.end(); ++j) { tag_state.push(*j); os << "<" << tag_name[*j] << ">"; } - for(list::const_iterator j = tag_open.begin(); + for (list::const_iterator j = tag_open.begin(); j != tag_open.end(); ++j) { tag_state.push(*j); os << "<" << tag_name[*j] << ">"; @@ -3027,17 +3026,22 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) niceFile = nice; // this will be used by Insetincludes. - string top_element= textclasslist.LatexnameOfClass(params.textclass); + string top_element = textclasslist.LatexnameOfClass(params.textclass); vector environment_stack; vector environment_inner; vector command_stack; - bool command_flag= false; - int command_depth= 0, command_base= 0, cmd_depth= 0; + bool command_flag = false; + int command_depth = 0; + int command_base = 0; + int cmd_depth = 0; - string item_name, command_name; - string c_depth, c_params, tmps; + string item_name; + string command_name; + string c_depth; + string c_params; + string tmps; int depth = 0; // paragraph depth LyXTextClass const & tclass = diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index f5599fb6f2..a359a94972 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -183,7 +183,7 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, if (!cleared && ((inset->need_update == InsetText::FULL) || (inset->need_update == InsetText::INIT) || - (top_x!=int(x)) || (top_baseline!=baseline))) { + (top_x != int(x)) || (top_baseline != baseline))) { int w = owner() ? width(bv, f) : pain.paperWidth(); int h = ascent(bv, f) + descent(bv, f); int tx = (needFullRow() && !owner()) ? 0 : int(x); @@ -203,8 +203,21 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, top_x = int(x); top_baseline = baseline; +#if 0 draw_collapsed(pain, f, baseline, x); inset->draw(bv, f, baseline, x, cleared); +#else +#warning Jürgen, can you have a look at this? (Lgb) + // the intention is quite clear if you set the positon in a minipage you + // want the minipage drawn according to that. but as you can see the + // cursor is wrongly placed. + draw_collapsed(pain, f, + baseline - ascent(bv, f) + ascent_collapsed(pain, f), + x); + inset->draw(bv, f, + baseline - ascent(bv, f) + ascent_collapsed(pain, f), + x, cleared); +#endif need_update = NONE; } diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 255085306b..3424835567 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -177,6 +177,56 @@ Inset * InsetMinipage::Clone(Buffer const &) const } +int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const +{ + lyxerr << "InsetMinipage::ascent" << endl; + + if (collapsed) + return ascent_collapsed(bv->painter(), font); + else { + // Take placement into account. + int i = 0; + switch (pos_) { + case top: + i = InsetCollapsable::ascent(bv, font); + break; + case center: + i = (InsetCollapsable::ascent(bv, font) + + InsetCollapsable::descent(bv, font)) / 2; + break; + case bottom: + i = InsetCollapsable::descent(bv, font); + break; + } + return i; + } +} + + +int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const +{ + if (collapsed) + return descent_collapsed(bv->painter(), font); + else { + // Take placement into account. + int i = 0; + switch (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; + } +} + + string const InsetMinipage::EditMessage() const { return _("Opened Minipage Inset"); diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index dff48efd76..14333f96fa 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -4,9 +4,9 @@ * * LyX, The Document Processor * - * Copyright 1998 The LyX Team. + * Copyright 2001 The LyX Team. * - *====================================================== + * ====================================================== */ #ifndef InsetMinipage_H @@ -49,6 +49,10 @@ public: /// Inset * Clone(Buffer const &) const; /// + int ascent(BufferView *, LyXFont const &) const; + /// + int descent(BufferView *, LyXFont const &) const; + /// Inset::Code LyxCode() const { return Inset::MINIPAGE_CODE; } /// int Latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; @@ -86,8 +90,6 @@ public: int getMaxWidth(Painter &, UpdatableInset const *) const; /// bool needFullRow() const { return false; } - - private: /// Position pos_;