#include "insets/insetref.h"
#include "insets/insetparent.h"
#include "insets/insetindex.h"
-#include "insets/insetinfo.h"
+#include "insets/insetnote.h"
#include "insets/insetinclude.h"
#include "insets/insetcite.h"
#include "insets/insetert.h"
#include "insets/insetmarginal.h"
#include "insets/insetminipage.h"
#include "insets/insetfloat.h"
-#include "insets/insetlist.h"
#include "insets/insettabular.h"
+#if 0
#include "insets/insettheorem.h"
+#include "insets/insetlist.h"
+#endif
#include "insets/insetcaption.h"
#include "insets/insetfloatlist.h"
#include "insets/insetspecialchar.h"
{
lyx::Assert(screen_.get());
- bv_->owner()->getDialogs()->updateParagraph();
+ bool ret;
+
+ if (bv_->theLockingInset()) {
+ bv_->theLockingInset()->fitInsetCursor(bv_);
+ ret = true;
+ } else {
+ ret = screen_->fitCursor(text, bv_);
+ }
- bool const ret = screen_->fitCursor(text, bv_);
+ bv_->owner()->getDialogs()->updateParagraph();
if (ret)
updateScrollbar();
return ret;
/* If the text is smaller than the working area, the scrollbar
* maximum must be the working area height. No scrolling will
* be possible */
-
if (!bv_->text) {
workarea_.setScrollbar(0, 1.0);
return;
long const text_height = bv_->text->height;
double const lineh = bv_->text->defaultHeight();
- double const slider_size = 1.0 / double(text_height);
+ double const slider_size =
+ (text_height == 0) ? 1.0 : 1.0 / double(text_height);
- static long old_text_height;
- static double old_lineh;
- static double old_slider_size;
+ static long old_text_height = 0;
+ static double old_lineh = 0;
+ static double old_slider_size = 0;
if (text_height != old_text_height) {
workarea_.setScrollbarBounds(0, text_height - workarea_.height());
text->fullRebreak(bv_);
if (text->inset_owner) {
- text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
+ text->inset_owner->setUpdateStatus(bv_, InsetText::NONE);
updateInset(text->inset_owner, true);
- } else
+ } else {
update();
-
+ }
+
if ((f & FITCUR)) {
fitCursor(text);
- }
+ }
if ((f & CHANGE)) {
buffer_->markDirty();
void BufferView::Pimpl::showCursor()
{
- if (screen_.get())
- screen_->showCursor(bv_->text, bv_);
+ if (screen_.get()) {
+ if (bv_->theLockingInset())
+ bv_->theLockingInset()->showInsetCursor(bv_);
+ else
+ screen_->showCursor(bv_->text, bv_);
+ }
}
void BufferView::Pimpl::hideCursor()
{
- if (screen_.get())
- screen_->hideCursor();
+ if (screen_.get()) {
+ if (!bv_->theLockingInset())
+// bv_->theLockingInset()->hideInsetCursor(bv_);
+// else
+ screen_->hideCursor();
+ }
}
} else {
// this is need because you don't use a inset->Edit()
updateInset(new_inset, true);
- new_inset->edit(bv_, 0, 0, 0);
+ new_inset->edit(bv_);
}
break;
}
}
case LFUN_HYPHENATION:
- hyphenationPoint();
+ specialChar(InsetSpecialChar::HYPHENATION);
+ break;
+
+ case LFUN_LIGATURE_BREAK:
+ specialChar(InsetSpecialChar::LIGATURE_BREAK);
break;
case LFUN_LDOTS:
- ldots();
+ specialChar(InsetSpecialChar::LDOTS);
break;
case LFUN_END_OF_SENTENCE:
- endOfSentenceDot();
+ specialChar(InsetSpecialChar::END_OF_SENTENCE);
break;
case LFUN_MENU_SEPARATOR:
- menuSeparator();
+ specialChar(InsetSpecialChar::MENU_SEPARATOR);
break;
case LFUN_HFILL:
&& lt->cursor.par()->getInset(lt->cursor.pos())->editable() == Inset::HIGHLY_EDITABLE){
Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
- int y = 0;
- if (is_rtl) {
- LyXFont const font =
- lt->getFont(buffer_,
- lt->cursor.par(),
- lt->cursor.pos());
- y = tmpinset->descent(bv_,font);
- }
- tmpinset->edit(bv_, 0, y, 0);
+ if (is_rtl)
+ tmpinset->edit(bv_, false);
+ else
+ tmpinset->edit(bv_);
break;
}
if (!is_rtl)
{
Inset * tmpinset = lt->cursor.par()->getInset(lt->cursor.pos());
owner_->getLyXFunc()->setMessage(tmpinset->editMessage());
- LyXFont const font = lt->getFont(buffer_,
- lt->cursor.par(),
- lt->cursor.pos());
- int y = is_rtl ? 0
- : tmpinset->descent(bv_,font);
- tmpinset->edit(bv_,
- tmpinset->x() +
- tmpinset->width(bv_,font),
- y, 0);
+ if (is_rtl)
+ tmpinset->edit(bv_);
+ else
+ tmpinset->edit(bv_, false);
break;
}
if (is_rtl)
break;
case LFUN_QUOTE:
- bv_->insertCorrectQuote();
+ smartQuote();
break;
case LFUN_HTMLURL:
p.setCmdName("htmlurl");
else
p.setCmdName("url");
- owner_->getDialogs()->createUrl( p.getAsString() );
+ owner_->getDialogs()->createUrl(p.getAsString());
}
break;
case LFUN_INSERT_URL:
{
InsetCommandParams p;
- p.setFromString( argument );
+ p.setFromString(argument);
- InsetUrl * inset = new InsetUrl( p );
+ InsetUrl * inset = new InsetUrl(p);
if (!insertInset(inset))
delete inset;
else
- updateInset( inset, true );
+ updateInset(inset, true);
}
break;
case LFUN_INSET_TEXT:
- {
- InsetText * new_inset = new InsetText;
- if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
- else
- delete new_inset;
- }
- break;
+ insertAndEditInset(new InsetText);
+ break;
case LFUN_INSET_ERT:
- {
- InsetERT * new_inset = new InsetERT;
- if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
- else
- delete new_inset;
- }
- break;
+ insertAndEditInset(new InsetERT);
+ break;
case LFUN_INSET_EXTERNAL:
- {
- InsetExternal * new_inset = new InsetExternal;
- if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
- else
- delete new_inset;
- }
- break;
+ insertAndEditInset(new InsetExternal);
+ break;
case LFUN_INSET_FOOTNOTE:
- {
- InsetFoot * new_inset = new InsetFoot;
- if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
- else
- delete new_inset;
- }
- break;
+ insertAndEditInset(new InsetFoot);
+ break;
case LFUN_INSET_MARGINAL:
- {
- InsetMarginal * new_inset = new InsetMarginal;
- if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
- else
- delete new_inset;
- }
- break;
+ insertAndEditInset(new InsetMarginal);
+ break;
case LFUN_INSET_MINIPAGE:
- {
- InsetMinipage * new_inset = new InsetMinipage;
- if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
- else
- delete new_inset;
- }
- break;
+ insertAndEditInset(new InsetMinipage);
+ break;
+
+ case LFUN_INSERT_NOTE:
+ insertAndEditInset(new InsetNote);
+ break;
case LFUN_INSET_FLOAT:
- {
// check if the float type exist
if (floatList.typeExist(argument)) {
- InsetFloat * new_inset = new InsetFloat(argument);
- if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
- else
- delete new_inset;
+ insertAndEditInset(new InsetFloat(argument));
} else {
lyxerr << "Non-existant float type: "
<< argument << endl;
}
-
- }
- break;
+ break;
case LFUN_INSET_WIDE_FLOAT:
{
InsetFloat * new_inset = new InsetFloat(argument);
new_inset->wide(true);
if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
+ new_inset->edit(bv_);
else
delete new_inset;
} else {
}
break;
+#if 0
case LFUN_INSET_LIST:
- {
- InsetList * new_inset = new InsetList;
- if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
- else
- delete new_inset;
- }
- break;
+ insertAndEditInset(new InsetList);
+ break;
case LFUN_INSET_THEOREM:
- {
- InsetTheorem * new_inset = new InsetTheorem;
- if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
- else
- delete new_inset;
- }
- break;
-
+ insertAndEditInset(new InsetTheorem);
+ break;
+#endif
+
case LFUN_INSET_CAPTION:
{
// Do we have a locking inset...
new_inset->setDrawFrame(0, InsetText::LOCKED);
new_inset->setFrameColor(0, LColor::captionframe);
if (insertInset(new_inset))
- new_inset->edit(bv_, 0, 0, 0);
+ new_inset->edit(bv_);
else
delete new_inset;
}
if (insertInset(inset)) {
if (argument.empty())
- inset->edit(bv_, 0, 0, 0);
+ inset->edit(bv_);
} else
delete inset;
}
case LFUN_INDEX_CREATE:
{
- InsetCommandParams p( "index" );
+ InsetCommandParams p("index");
if (argument.empty()) {
- // Get the word immediately preceding the cursor
- Paragraph::size_type curpos =
- bv_->getLyXText()->cursor.pos() - 1;
-
- string curstring;
- if (curpos >= 0 )
- curstring = bv_->getLyXText()
- ->cursor.par()->getWord(curpos);
+ // Get word or selection
+ bv_->getLyXText()->selectWordWhenUnderCursor(bv_);
+
+ string const curstring =
+ bv_->getLyXText()->selectionAsString(buffer_);
- p.setContents( curstring );
+ p.setContents(curstring);
} else {
- p.setContents( argument );
+ p.setContents(argument);
}
- owner_->getDialogs()->createIndex( p.getAsString() );
+ owner_->getDialogs()->createIndex(p.getAsString());
}
break;
case LFUN_INDEX_INSERT_LAST:
{
- // Get word immediately preceding the cursor
- Paragraph::size_type curpos =
- bv_->getLyXText()->cursor.pos() - 1;
- // Can't do that at the beginning of a paragraph
- if (curpos < 0) break;
+ // Get word or selection
+ bv_->getLyXText()->selectWordWhenUnderCursor(bv_);
- string const curstring(bv_->getLyXText()
- ->cursor.par()->getWord(curpos));
+ string const curstring =
+ bv_->getLyXText()->selectionAsString(buffer_);
InsetCommandParams p("index", curstring);
InsetIndex * inset = new InsetIndex(p);
}
break;
- case LFUN_INSERT_NOTE:
- insertNote();
- break;
-
case LFUN_SELFINSERT:
{
if (argument.empty()) break;
}
}
- bv_->beforeChange(lt);
+ beforeChange(lt);
LyXFont const old_font(lt->real_current_font);
string::const_iterator cit = argument.begin();
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
}
-void BufferView::Pimpl::menuSeparator()
+void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
{
if (available()) {
LyXText * lt = bv_->getLyXText();
hideCursor();
update(lt, BufferView::SELECT|BufferView::FITCUR);
InsetSpecialChar * new_inset =
- new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
+ new InsetSpecialChar(kind);
insertInset(new_inset);
}
}
-void BufferView::Pimpl::endOfSentenceDot()
+void BufferView::Pimpl::smartQuote()
{
- if (available()) {
- hideCursor();
- update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
- InsetSpecialChar * new_inset =
- new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
- insertInset(new_inset);
- }
-}
-
-
-void BufferView::Pimpl::ldots()
-{
- if (available()) {
- hideCursor();
- update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
- InsetSpecialChar * new_inset =
- new InsetSpecialChar(InsetSpecialChar::LDOTS);
- insertInset(new_inset);
- }
-}
+ char c;
+ LyXText * lt = bv_->getLyXText();
+ if (lt->cursor.pos())
+ c = lt->cursor.par()->getChar(lt->cursor.pos() - 1);
+ else
+ c = ' ';
-void BufferView::Pimpl::hyphenationPoint()
-{
- if (available()) {
- hideCursor();
- update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
- InsetSpecialChar * new_inset =
- new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
- insertInset(new_inset);
- }
+ hideCursor();
+ if (!insertInset(new InsetQuotes(c, bv_->buffer()->params)))
+ Dispatch(LFUN_SELFINSERT, "\"");
}
-void BufferView::Pimpl::insertNote()
+void BufferView::Pimpl::insertAndEditInset(Inset * inset)
{
- InsetInfo * new_inset = new InsetInfo();
- insertInset(new_inset);
- new_inset->edit(bv_, 0, 0, 0);
+ if (insertInset(inset))
+ inset->edit(bv_);
+ else
+ delete inset;
}
-
+
// Open and lock an updatable inset
bool BufferView::Pimpl::open_new_inset(UpdatableInset * new_inset, bool behind)
{
delete new_inset;
return false;
}
- if (behind) {
- LyXFont & font = lt->real_current_font;
- new_inset->edit(bv_, new_inset->width(bv_, font), 0, 0);
- } else
- new_inset->edit(bv_, 0, 0, 0);
+ new_inset->edit(bv_, !behind);
return true;
}