#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
#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
extern BufferList bufferlist;
extern char ascii_type;
-extern void sigchldchecker(pid_t pid, int * status);
extern int bibitemMaxWidth(BufferView *, LyXFont const &);
{
static Cursor cursor;
static bool cursor_undefined = true;
- if (cursor_undefined){
+ if (cursor_undefined) {
cursor = XCreateFontCursor(fl_get_display(), XC_xterm);
XFlush(fl_get_display());
cursor_undefined = false;
.connect(slot(this, &BufferView::Pimpl::workAreaKeyPress));
workarea_.selectionRequested
.connect(slot(this, &BufferView::Pimpl::selectionRequested));
+ workarea_.selectionLost
+ .connect(slot(this, &BufferView::Pimpl::selectionLost));
cursor_timeout.timeout.connect(slot(this,
&BufferView::Pimpl::cursorToggle));
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
// 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
}
long const text_height = bv_->text->height;
+ long const work_height = workarea_.height();
+ if (text_height <= work_height) {
+ workarea_.setScrollbarBounds(0.0, 0.0);
+ current_scrollbar_value = bv_->text->first_y;
+ workarea_.setScrollbar(current_scrollbar_value, 1.0);
+ return;
+ }
+
double const lineh = bv_->text->defaultHeight();
double const slider_size =
(text_height == 0) ? 1.0 : 1.0 / double(text_height);
-
- static long old_text_height = 0;
- static double old_lineh = 0;
- static double old_slider_size = 0;
+
+ static long old_text_height;
+ static double old_lineh;
+ static double old_slider_size;
if (text_height != old_text_height) {
- workarea_.setScrollbarBounds(0, text_height - workarea_.height());
+ workarea_.setScrollbarBounds(0.0,
+ text_height - work_height);
old_text_height = text_height;
}
if (lineh != old_lineh) {
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;
}
if (!buffer_) return;
current_scrollbar_value = long(value);
+
if (current_scrollbar_value < 0)
current_scrollbar_value = 0;
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
bv_->text->setSelection(bv_);
screen_->toggleToggle(bv_->text, bv_);
fitCursor();
-#if 0
- screen_->showCursor(bv_->text, bv_);
-#else
showCursor();
-#endif
}
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;
screen_->toggleSelection(bv_->text, bv_);
bv_->text->clearSelection();
bv_->text->fullRebreak(bv_);
-#if 0
- screen_->update(bv_->text, bv_);
-#else
update();
-#endif
updateScrollbar();
// Single left click in math inset?
selection_possible = false;
owner_->updateLayoutChoice();
owner_->message(inset->editMessage());
+ // IMO the inset has to be first in edit-mode and then we send the
+ // button press. (Jug 20020222)
+ inset->edit(bv_); //, xpos, ypos, button);
inset->insetButtonPress(bv_, xpos, ypos, button);
- inset->edit(bv_, xpos, ypos, button);
return;
}
void BufferView::Pimpl::selectionRequested()
{
- string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(), false));
+ if (!available())
+ return;
+
+ string const sel(bv_->getLyXText()->selectionAsString(bv_->buffer(),
+ false));
if (!sel.empty()) {
workarea_.putClipboard(sel);
}
}
+void BufferView::Pimpl::selectionLost()
+{
+ if (active() && available()) {
+ hideCursor();
+ toggleSelection();
+ bv_->getLyXText()->clearSelection();
+ showCursor();
+ }
+}
+
+
void BufferView::Pimpl::enterView()
{
if (active() && available()) {
// Did we hit an editable inset?
if (inset_hit) {
- // Inset like error, notes and figures
selection_possible = false;
// if we reach this point with a selection, it
// 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);
}
}
-Box BufferView::Pimpl::insetDimensions(LyXText const & text, LyXCursor const & cursor) const
+Box BufferView::Pimpl::insetDimensions(LyXText const & text,
+ LyXCursor const & cursor) const
{
Paragraph /*const*/ & par = *cursor.par();
pos_type const pos = cursor.pos();
}
-Inset * BufferView::Pimpl::checkInset(LyXText const & text, LyXCursor const & cursor, int & x, int & y) const
+Inset * BufferView::Pimpl::checkInset(LyXText const & text,
+ LyXCursor const & cursor,
+ int & x, int & y) const
{
pos_type const pos(cursor.pos());
Paragraph /*const*/ & par(*cursor.par());
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);
// Callback for cursor timer
void BufferView::Pimpl::cursorToggle()
{
- // Quite a nice place for asyncron Inset updating, isn't it?
- // Actually no! This is run even if no buffer exist... so (Lgb)
if (!buffer_) {
cursor_timeout.restart();
return;
}
- int status = 1;
- int const pid = waitpid(static_cast<pid_t>(0), &status, WNOHANG);
- if (pid == -1) // error find out what is wrong
- ; // ignore it for now.
- else if (pid > 0)
- sigchldchecker(pid, &status);
-
- updatelist.update(bv_);
-
if (!screen_.get()) {
cursor_timeout.restart();
return;
}
+ /* FIXME */
+ extern void reapSpellchecker(void);
+ reapSpellchecker();
+
if (!bv_->theLockingInset()) {
screen_->cursorToggle(bv_);
} else {
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
text->cursor.y()
- text->cursor.row()->baseline()
+ text->cursor.row()->height()
- - workarea_.height() + 1 );
+ - workarea_.height() + 1);
updateScrollbar();
}
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;
}
Buffer * b = bufferlist.exists(fname) ?
bufferlist.getBuffer(fname) :
bufferlist.loadLyXFile(fname); // don't ask, just load it
- if (b != 0 ) buffer(b);
+ if (b != 0) buffer(b);
}
Paragraph * par = buffer_->getParFromID(saved_positions[i].par_id);
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)
// 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
{
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_, ' ');
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:
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:
case LFUN_CITATION_INSERT:
{
InsetCommandParams p;
- p.setFromString( argument );
+ p.setFromString(argument);
- InsetCitation * inset = new InsetCitation( p );
+ InsetCitation * inset = new InsetCitation(p);
if (!insertInset(inset))
delete inset;
else
- updateInset( inset, true );
+ updateInset(inset, true);
}
break;
string const db = token(argument, ' ', 0);
string const bibstyle = token(argument, ' ', 1);
- InsetCommandParams p( "BibTeX", db, bibstyle );
+ InsetCommandParams p("BibTeX", db, bibstyle);
InsetBibtex * inset = new InsetBibtex(p);
if (insertInset(inset)) {
case LFUN_PARENTINSERT:
{
lyxerr << "arg " << argument << endl;
- InsetCommandParams p( "lyxparent", argument );
+ InsetCommandParams p("lyxparent", argument);
Inset * inset = new InsetParent(p, *buffer_);
if (!insertInset(inset, "Standard"))
delete inset;
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))))
- Dispatch(LFUN_SELFINSERT, "\"");
+ bv_->owner()->getLyXFunc()->dispatch(LFUN_SELFINSERT, "\"");
}
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
} else if (bv_->theLockingInset()->updateInsetInInset(bv_, inset)) {
if (bv_->text->updateInset(bv_, bv_->theLockingInset())) {
update();
- if (mark_dirty){
+ if (mark_dirty) {
buffer_->markDirty();
}
updateScrollbar();
}
}
- // 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();
+ }
}
}