]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
I reactivate the code to resize the InsetText on a resize event of the main
[lyx.git] / src / BufferView_pimpl.C
index 6c27f04f58f5926ab243da97070fe2d0704acde1..84152ccb47041b363c2642efe7a77fbe095c7659 100644 (file)
@@ -18,7 +18,6 @@
 #include "bufferview_funcs.h"
 #include "TextCache.h"
 #include "bufferlist.h"
-#include "lyx_gui_misc.h"
 #include "lyxrc.h"
 #include "intl.h"
 // added for Dispatch functions
@@ -74,7 +73,7 @@
 #include <clocale>
 
 
-extern lyx::layout_type current_layout;
+extern string current_layout;
 
 using std::vector;
 using std::find_if;
@@ -86,7 +85,6 @@ using std::min;
 using SigC::slot;
 
 using lyx::pos_type;
-using lyx::layout_type;
 using lyx::textclass_type;
 
 /* the selection possible is needed, that only motion events are 
@@ -216,7 +214,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
                        updateScreen();
                        updateScrollbar();
                }
-               bv_->text->first = screen_->topCursorVisible(bv_->text);
+               bv_->text->first_y = screen_->topCursorVisible(bv_->text);
                owner_->updateMenubar();
                owner_->updateToolbar();
                // Similarly, buffer-dependent dialogs should be updated or
@@ -370,8 +368,10 @@ int BufferView::Pimpl::resizeCurrentBuffer()
                // remake the inset locking
                bv_->theLockingInset(the_locking_inset);
        }
-       bv_->text->first = screen_->topCursorVisible(bv_->text);
-#if 0
+       bv_->text->first_y = screen_->topCursorVisible(bv_->text);
+       // please tell me WHY the heck you deactivated this code, whoever
+       // 'you' are (Jug 20020311)
+#if 1
        buffer_->resizeInsets(bv_);
 #endif
        // this will scroll the screen such that the cursor becomes visible
@@ -410,7 +410,7 @@ void BufferView::Pimpl::updateScrollbar()
 
        if (text_height <= work_height) {
                workarea_.setScrollbarBounds(0.0, 0.0);
-               current_scrollbar_value = bv_->text->first;
+               current_scrollbar_value = bv_->text->first_y;
                workarea_.setScrollbar(current_scrollbar_value, 1.0);
                return;
        }
@@ -432,9 +432,9 @@ void BufferView::Pimpl::updateScrollbar()
                workarea_.setScrollbarIncrements(lineh);
                old_lineh = lineh;
        }
-       if (current_scrollbar_value != bv_->text->first
+       if (current_scrollbar_value != bv_->text->first_y
            || slider_size != old_slider_size) {
-               current_scrollbar_value = bv_->text->first;
+               current_scrollbar_value = bv_->text->first_y;
                workarea_.setScrollbar(current_scrollbar_value, slider_size);
                old_slider_size = slider_size;
        }
@@ -464,8 +464,8 @@ void BufferView::Pimpl::scrollCB(double value)
        LyXText * vbt = bv_->text;
  
        int const height = vbt->defaultHeight();
-       int const first = static_cast<int>((bv_->text->first + height));
-       int const last = static_cast<int>((bv_->text->first + workarea_.height() - height));
+       int const first = static_cast<int>((bv_->text->first_y + height));
+       int const last = static_cast<int>((bv_->text->first_y + workarea_.height() - height));
 
        if (vbt->cursor.y() < first)
                vbt->setCursorFromCoordinates(bv_, 0, first);
@@ -560,7 +560,7 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
                bv_->theLockingInset()->
                        insetMotionNotify(bv_,
                                          x - start_x,
-                                         y - cursor.y() + bv_->text->first,
+                                         y - cursor.y() + bv_->text->first_y,
                                          state);
                return;
        }
@@ -573,7 +573,7 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
  
        screen_->hideCursor();
 
-       bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first);
+       bv_->text->setCursorFromCoordinates(bv_, x, y + bv_->text->first_y);
       
        if (!bv_->text->selection.set())
                update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted
@@ -623,7 +623,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
                selection_possible = true;
        screen_->hideCursor();
 
-       int const screen_first = bv_->text->first;
+       int const screen_first = bv_->text->first_y;
        
        // Middle button press pastes if we have a selection
        bool paste_internally = false;
@@ -758,10 +758,12 @@ void BufferView::Pimpl::selectionRequested()
  
 void BufferView::Pimpl::selectionLost()
 {
-       hideCursor();
-       toggleSelection();
-       bv_->getLyXText()->clearSelection();
-       showCursor(); 
+       if (active() && available()) { 
+               hideCursor();
+               toggleSelection();
+               bv_->getLyXText()->clearSelection();
+               showCursor(); 
+       }
 }
 
  
@@ -871,9 +873,7 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
 
        // Maybe we want to edit a bibitem ale970302
        if (bv_->text->cursor.par()->bibkey && x < 20 + 
-           bibitemMaxWidth(bv_, textclasslist.
-                           TextClass(buffer_->
-                                     params.textclass).defaultfont())) {
+           bibitemMaxWidth(bv_, textclasslist[buffer_->params.textclass].defaultfont())) {
                bv_->text->cursor.par()->bibkey->edit(bv_, 0, 0, 0);
        }
 
@@ -945,7 +945,7 @@ Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y)
        if (!screen_.get())
                return 0;
   
-       int y_tmp = y + text->first;
+       int y_tmp = y + text->first_y;
  
        LyXCursor cursor;
        text->setCursorFromCoordinates(bv_, cursor, x, y_tmp);
@@ -1146,10 +1146,9 @@ void BufferView::Pimpl::cursorPrevious(LyXText * text)
        if (!text->cursor.row()->previous())
                return;
        
-       int y = text->first;
-       if (text->inset_owner)
-               y += bv_->text->first;
+       int y = text->first_y;
        Row * cursorrow = text->cursor.row();
+       
        text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
        finishUndo();
        // This is to allow jumping over large insets
@@ -1172,7 +1171,7 @@ void BufferView::Pimpl::cursorNext(LyXText * text)
        if (!text->cursor.row()->next())
                return;
        
-       int y = text->first + workarea_.height();
+       int y = text->first_y + workarea_.height();
 //     if (text->inset_owner)
 //             y += bv_->text->first;
        text->getRowNearY(y);
@@ -1194,7 +1193,8 @@ void BufferView::Pimpl::cursorNext(LyXText * text)
 
 bool BufferView::Pimpl::available() const
 {
-       if (buffer_ && bv_->text) return true;
+       if (buffer_ && bv_->text)
+               return true;
        return false;
 }
 
@@ -1543,7 +1543,6 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                break;
        }
                
-       case LFUN_TABULAR_FEATURE:
        case LFUN_SCROLL_INSET:
                // this is not handled here as this funktion is only aktive
                // if we have a locking_inset and that one is (or contains)
@@ -1671,34 +1670,34 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                // Derive layout number from given argument (string)
                // and current buffer's textclass (number). */    
                textclass_type tclass = buffer_->params.textclass;
-               pair <bool, layout_type> layout = 
-                       textclasslist.NumberOfLayout(tclass, argument);
+               bool hasLayout =
+                       textclasslist[tclass].hasLayout(argument);
+               string layout = argument;
 
                // If the entry is obsolete, use the new one instead.
-               if (layout.first) {
-                       string obs = textclasslist.Style(tclass, layout.second)
+               if (hasLayout) {
+                       string const & obs = textclasslist[tclass][layout]
                                .obsoleted_by();
                        if (!obs.empty()) 
-                               layout = textclasslist.NumberOfLayout(tclass, obs);
+                               layout = obs;
                }
 
-               // see if we found the layout number:
-               if (!layout.first) {
+               if (!hasLayout) {
                        owner_->getLyXFunc()->setErrorMessage(
                                string(N_("Layout ")) + argument +
                                N_(" not known"));
                        break;
                }
 
-               if (current_layout != layout.second) {
+               if (current_layout != layout) {
                        LyXText * lt = bv_->getLyXText();
                        hideCursor();
-                       current_layout = layout.second;
+                       current_layout = layout;
                        update(lt,
                               BufferView::SELECT
                               | BufferView::FITCUR);
-                       lt->setLayout(bv_, layout.second);
-                       owner_->setLayout(layout.second);
+                       lt->setLayout(bv_, layout);
+                       owner_->setLayout(layout);
                        update(lt,
                               BufferView::SELECT
                               | BufferView::FITCUR
@@ -2343,9 +2342,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        {
                LyXText * lt = bv_->getLyXText();
 
-               LyXLayout const & style = textclasslist
-                       .Style(buffer_->params.textclass,
-                              lt->cursor.par()->getLayout());
+               LyXLayout const & style = textclasslist[buffer_->params.textclass][lt->cursor.par()->layout()];
 
                if (style.free_spacing) {
                        lt->insertChar(bv_, ' ');
@@ -2750,11 +2747,11 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        break;
        
        case LFUN_INSET_TEXT:
-               insertAndEditInset(new InsetText);
+               insertAndEditInset(new InsetText(buffer_->params));
                break;
        
        case LFUN_INSET_ERT:
-               insertAndEditInset(new InsetERT);
+               insertAndEditInset(new InsetERT(buffer_->params));
                break;
        
        case LFUN_INSET_EXTERNAL:
@@ -2762,25 +2759,26 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                break;
        
        case LFUN_INSET_FOOTNOTE:
-               insertAndEditInset(new InsetFoot);
+               insertAndEditInset(new InsetFoot(buffer_->params));
                break;
 
        case LFUN_INSET_MARGINAL:
-               insertAndEditInset(new InsetMarginal);
+               insertAndEditInset(new InsetMarginal(buffer_->params));
                break;
 
        case LFUN_INSET_MINIPAGE:
-               insertAndEditInset(new InsetMinipage);
+               insertAndEditInset(new InsetMinipage(buffer_->params));
                break;
 
        case LFUN_INSERT_NOTE:
-               insertAndEditInset(new InsetNote);
+               insertAndEditInset(new InsetNote(buffer_->params));
                break;
 
        case LFUN_INSET_FLOAT:
                // check if the float type exist
                if (floatList.typeExist(argument)) {
-                       insertAndEditInset(new InsetFloat(argument));
+                       insertAndEditInset(new InsetFloat(buffer_->params,
+                                                         argument));
                } else {
                        lyxerr << "Non-existent float type: "
                               << argument << endl;
@@ -2791,7 +2789,8 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        {
                // check if the float type exist
                if (floatList.typeExist(argument)) {
-                       InsetFloat * new_inset = new InsetFloat(argument);
+                       InsetFloat * new_inset =
+                               new InsetFloat(buffer_->params, argument);
                        new_inset->wide(true);
                        if (insertInset(new_inset))
                                new_inset->edit(bv_);
@@ -2821,7 +2820,8 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                if (bv_->theLockingInset()) {
                        lyxerr << "Locking inset code: "
                               << static_cast<int>(bv_->theLockingInset()->lyxCode());
-                       InsetCaption * new_inset = new InsetCaption;
+                       InsetCaption * new_inset =
+                               new InsetCaption(buffer_->params);
                        new_inset->setOwner(bv_->theLockingInset());
                        new_inset->setAutoBreakRows(true);
                        new_inset->setDrawFrame(0, InsetText::LOCKED);
@@ -2881,7 +2881,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
        break;
        
        case LFUN_GETLAYOUT:
-               owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout));
+               owner_->getLyXFunc()->setMessage(tostr(bv_->getLyXText()->cursor.par()->layout()));
                break;
                        
        case LFUN_GETFONT:
@@ -3310,8 +3310,8 @@ void BufferView::Pimpl::smartQuote()
 
        hideCursor();
 
-       LyXLayout const & style = textclasslist.Style(
-               bv_->buffer()->params.textclass, par->getLayout());
+       LyXLayout const & style =
+               textclasslist[bv_->buffer()->params.textclass][par->layout()];
        
        if (style.pass_thru ||
                (!insertInset(new InsetQuotes(c, bv_->buffer()->params))))
@@ -3371,17 +3371,20 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
                        update(bv_->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                }
 
-               pair<bool, layout_type> lres =
-                       textclasslist.NumberOfLayout(buffer_->params .textclass, lout);
-               layout_type lay = 0;
-               if (lres.first != false) {
+               string lres = lout;
+               LyXTextClass const & tclass =
+                       textclasslist[buffer_->params.textclass];
+               bool hasLayout = tclass.hasLayout(lres);
+               string lay = tclass.defaultLayoutName();
+
+               if (hasLayout != false) {
                        // layout found
-                       lay = lres.second;
+                       lay = lres;
                } else {
-                       // layout not fount using default "Standard" (0)
-                       lay = 0;
+                       // layout not fount using default
+                       lay = tclass.defaultLayoutName();
                }
-                
+
                bv_->text->setLayout(bv_, lay);
                
                bv_->text->setParagraph(bv_, 0, 0,
@@ -3404,7 +3407,7 @@ bool BufferView::Pimpl::insertInset(Inset * inset, string const & lout)
 
 void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
 {
-       if (!inset)
+       if (!inset || !available())
                return;
 
        // first check for locking insets
@@ -3430,9 +3433,14 @@ void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
                }
        }
   
-       // then check the current buffer
-       if (available()) {
-               hideCursor();
+       // then check if the inset is a top_level inset (has no owner)
+       // if yes do the update as always otherwise we have to update the
+       // toplevel inset where this inset is inside
+       Inset * tl_inset = inset;
+       while(tl_inset->owner())
+               tl_inset = tl_inset->owner();
+       hideCursor();
+       if (tl_inset == inset) {
                update(bv_->text, BufferView::UPDATE);
                if (bv_->text->updateInset(bv_, inset)) {
                        if (mark_dirty) {
@@ -3445,6 +3453,13 @@ void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
                        }
                        return;
                }
+       } else if (static_cast<UpdatableInset *>(tl_inset)
+                          ->updateInsetInInset(bv_, inset))
+       {
+                       if (bv_->text->updateInset(bv_,  tl_inset)) {
+                               update();
+                               updateScrollbar();
+                       }
        }
 }