#include <clocale>
-extern lyx::layout_type current_layout;
+extern string current_layout;
using std::vector;
using std::find_if;
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
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
pos_type selendpos = 0;
bool selection = false;
bool mark_set = false;
-
+
owner_->prohibitInput();
owner_->message(_("Formatting document..."));
delete bv_->text;
bv_->text = new LyXText(bv_);
bv_->text->init(bv_);
+ buffer_->resizeInsets(bv_);
} else {
// See if we have a text in TextCache that fits
// the new buffer_ with the correct width.
} else {
bv_->text = new LyXText(bv_);
bv_->text->init(bv_);
+ //buffer_->resizeInsets(bv_);
}
}
+
updateScreen();
if (par) {
bv_->text->selection.set(true);
- /* at this point just to avoid the Delete-Empty-Paragraph
- * Mechanism when setting the cursor */
+ // At this point just to avoid the Delete-Empty-Paragraph-
+ // Mechanism when setting the cursor.
bv_->text->selection.mark(mark_set);
if (selection) {
bv_->text->setCursor(bv_, selstartpar, selstartpos);
// remake the inset locking
bv_->theLockingInset(the_locking_inset);
}
- bv_->text->first = screen_->topCursorVisible(bv_->text);
-#if 0
- buffer_->resizeInsets(bv_);
-#endif
+
+ bv_->text->first_y = screen_->topCursorVisible(bv_->text);
+
// this will scroll the screen such that the cursor becomes visible
updateScrollbar();
redraw();
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;
}
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;
}
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);
bv_->theLockingInset()->
insetMotionNotify(bv_,
x - start_x,
- y - cursor.y() + bv_->text->first,
+ y - cursor.y() + bv_->text->first_y,
state);
return;
}
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
void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
unsigned int button)
{
- if (!buffer_ || !screen_.get()) return;
+ if (!buffer_ || !screen_.get())
+ return;
Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos);
}
}
+ // Middle button press pastes if we have a selection
+ // We do this here as if the selection was inside an inset
+ // it could get cleared on the unlocking of the inset so
+ // we have to check this first
+ bool paste_internally = false;
+ if (button == 2 && bv_->getLyXText()->selection.set()) {
+ owner_->getLyXFunc()->dispatch(LFUN_COPY);
+ paste_internally = true;
+ }
+
if (bv_->theLockingInset()) {
// We are in inset locking mode
selection_possible = true;
screen_->hideCursor();
- int const screen_first = bv_->text->first;
-
- // Middle button press pastes if we have a selection
- bool paste_internally = false;
- if (button == 2
- && bv_->text->selection.set()) {
- owner_->getLyXFunc()->dispatch(LFUN_COPY);
- paste_internally = true;
- }
+ int const screen_first = bv_->text->first_y;
// Clear the selection
screen_->toggleSelection(bv_->text, bv_);
owner_->getLyXFunc()->dispatch(LFUN_PASTE);
else
owner_->getLyXFunc()->dispatch(LFUN_PASTESELECTION,
- "paragraph");
+ "paragraph");
selection_possible = false;
return;
}
void BufferView::Pimpl::selectionLost()
{
- hideCursor();
- toggleSelection();
- bv_->getLyXText()->clearSelection();
- showCursor();
+ if (active() && available()) {
+ hideCursor();
+ toggleSelection();
+ bv_->getLyXText()->clearSelection();
+ showCursor();
+ }
}
// 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);
}
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);
if (lyxerr.debugging())
textcache.show(lyxerr, "Expose delete all");
textcache.clear();
+ buffer_->resizeInsets(bv_);
} else if (heightChange) {
// Rebuild image of current screen
updateScreen();
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
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);
bool BufferView::Pimpl::available() const
{
- if (buffer_ && bv_->text) return true;
+ if (buffer_ && bv_->text)
+ return true;
return false;
}
void BufferView::Pimpl::pasteClipboard(bool asPara)
{
- if (!buffer_) return;
+ if (!buffer_)
+ return;
screen_->hideCursor();
beforeChange(bv_->text);
string const clip(workarea_.getClipboard());
- if (clip.empty()) return;
+ if (clip.empty())
+ return;
if (asPara) {
bv_->getLyXText()->insertStringAsParagraphs(bv_, clip);
lt->setSelection(bv_);
if (lt->bv_owner)
toggleToggle();
+ else
+ updateInset(lt->inset_owner, false);
+ }
+ if (lt->bv_owner) {
+ update(lt, BufferView::SELECT|BufferView::FITCUR);
+ showCursor();
}
- update(lt, BufferView::SELECT|BufferView::FITCUR);
- showCursor();
/* ---> Everytime the cursor is moved, show the current font state. */
// should this too me moved out of this func?
case LFUN_PASTESELECTION:
{
- bool asPara = false;
+ bool asPara = false;
if (argument == "paragraph")
asPara = true;
pasteClipboard(asPara);
hfill();
break;
- case LFUN_DEPTH:
- changeDepth(bv_, bv_->getLyXText(), 0);
- break;
-
case LFUN_DEPTH_MIN:
changeDepth(bv_, bv_->getLyXText(), -1);
break;
// 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
case LFUN_ENDSEL:
{
LyXText * lt = bv_->getLyXText();
-
+
update(lt, BufferView::SELECT|BufferView::FITCUR);
lt->cursorEnd(bv_);
finishUndo();
{
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_, ' ');
| BufferView::FITCUR
| BufferView::CHANGE);
} else {
- protectedBlank(lt);
+ specialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
}
moveCursorUpdate(false);
}
}
break;
- case LFUN_INSET_TEXT:
- insertAndEditInset(new InsetText);
- break;
-
case LFUN_INSET_ERT:
- insertAndEditInset(new InsetERT);
+ insertAndEditInset(new InsetERT(buffer_->params));
break;
case LFUN_INSET_EXTERNAL:
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;
{
// 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_);
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);
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:
}
-void BufferView::Pimpl::protectedBlank(LyXText * lt)
-{
- if (available()) {
- hideCursor();
- update(lt, BufferView::SELECT|BufferView::FITCUR);
- InsetSpecialChar * new_inset =
- new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
-#ifdef WITH_WARNINGS
-#warning Why is this code different from specialChar() below? (JMarc)
-// the code in specialChar is a generic version of what used to exist
-// for other special chars. I did not merge this case because of the
-// call to updateInset(), but what does it do?
-#endif
- if (!insertInset(new_inset))
- delete new_inset;
- else
- updateInset(new_inset, true);
- }
-}
-
-
void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
{
if (available()) {
new InsetSpecialChar(kind);
if (!insertInset(new_inset))
delete new_inset;
+ else
+ updateInset(new_inset, true);
}
}
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))))
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,
void BufferView::Pimpl::updateInset(Inset * inset, bool mark_dirty)
{
- if (!inset)
+ if (!inset || !available())
return;
// first check for locking insets
}
}
- // 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) {
}
return;
}
+ } else if (static_cast<UpdatableInset *>(tl_inset)
+ ->updateInsetInInset(bv_, inset))
+ {
+ if (bv_->text->updateInset(bv_, tl_inset)) {
+ update();
+ updateScrollbar();
+ }
}
}