#include "layout.h"
#include "LaTeXFeatures.h"
#include "Painter.h"
-#include "lyx_gui_misc.h"
+#include "frontends/Alert.h"
#include "lyxtext.h"
#include "lyxcursor.h"
#include "CutAndPaste.h"
using std::min;
using std::max;
using std::make_pair;
+using std::vector;
+
+using lyx::pos_type;
extern unsigned char getCurrentTextClass(Buffer *);
extern bool math_insert_greek(BufferView *, char);
par = tmp;
}
par = new Paragraph;
+ reinitLyXText();
need_update = INIT;
}
int InsetText::ascent(BufferView * bv, LyXFont const &) const
{
- int y_temp = 0;
- Row * row = getLyXText(bv)->getRowNearY(y_temp);
- insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
+ bool clear = false;
+ if (!lt) {
+ lt = getLyXText(bv);
+ clear = true;
+ }
+ insetAscent = lt->firstRow()->ascent_of_text() + TEXT_TO_INSET_OFFSET;
+ if (clear)
+ lt = 0;
return insetAscent;
}
lt = getLyXText(bv);
clear = true;
}
- int y_temp = 0;
- Row * row = lt->getRowNearY(y_temp);
- insetDescent = lt->height - row->ascent_of_text() +
- TEXT_TO_INSET_OFFSET;
+ insetDescent = lt->height - lt->firstRow()->ascent_of_text() +
+ TEXT_TO_INSET_OFFSET;
if (clear)
lt = 0;
return insetDescent;
inset_y = cy(bv) + drawTextYOffset;
}
if (!cleared && (need_update == CURSOR)
- && !getLyXText(bv)->selection.set())
- {
+ && !getLyXText(bv)->selection.set()) {
drawFrame(pain, cleared);
x += last_width; // was width(bv, f);
need_update = NONE;
}
x += TEXT_TO_INSET_OFFSET;
- int y = 0;
- Row * row = lt->getRowNearY(y);
+ Row * row = lt->firstRow();
int y_offset = baseline - row->ascent_of_text();
int ph = pain.paperHeight();
int first = 0;
- y = y_offset;
+ int y = y_offset;
while ((row != 0) && ((y+row->height()) <= 0)) {
y += row->height();
first += row->height();
bv->screen()->update(lt, bv, y_offset, int(x));
} else {
locked = false;
- if (need_update & SELECTION)
+ if (need_update & SELECTION) {
bv->screen()->toggleToggle(lt, bv, y_offset, int(x));
- else if (need_update & CURSOR) {
+ } else if (need_update & CURSOR) {
bv->screen()->toggleSelection(lt, bv, true, y_offset,int(x));
lt->clearSelection();
lt->selection.cursor = lt->cursor;
lt->refresh_y = 0;
lt->status(bv, LyXText::UNCHANGED);
if ((need_update != CURSOR_PAR) &&
- ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
+ ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked))) {
drawFrame(pain, cleared);
- else if (need_update & CLEAR_FRAME)
+ } else if (need_update & CLEAR_FRAME) {
clearFrame(pain, cleared);
+ }
+
x += last_width /* was width(bv, f) */ - TEXT_TO_INSET_OFFSET;
+
if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
need_update |= FULL;
- } else if (need_update != INIT)
+ } else if (need_update != INIT) {
need_update = NONE;
+ }
+
if (clear)
lt = 0;
}
frame_y = top_baseline - insetAscent + ttoD2;
frame_w = last_width - TEXT_TO_INSET_OFFSET;
frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
- pain.rectangle(frame_x, frame_y, frame_w, frame_h,
+ pain.rectangle(frame_x, frame_y,
+ frame_w, frame_h,
frame_color);
frame_is_visible = true;
}
in_update = true;
if (reinit || need_update == INIT) {
need_update = FULL;
+ // we should put this call where we set need_update to INIT!
reinitLyXText();
if (owner())
owner()->update(bv, font, true);
the_locking_inset = 0;
}
if (bv->theLockingInset()) {
- if (inset && inset->editable() == Inset::HIGHLY_EDITABLE) {
+ if (isHighlyEditableInset(inset)) {
UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
inset_x = cx(bv) - top_x + drawTextXOffset;
inset_y = cy(bv) + drawTextYOffset;
inset_boundary = cboundary(bv);
the_locking_inset = uinset;
uinset->insetButtonPress(bv, x - inset_x, y - inset_y,
- button);
+ button);
uinset->edit(bv, x - inset_x, y - inset_y, 0);
if (the_locking_inset)
updateLocal(bv, CURSOR, false);
localDispatch(bv, LFUN_PASTE, "");
else
localDispatch(bv, LFUN_PASTESELECTION,
- "paragraph");
+ "paragraph");
}
if (clear)
lt = 0;
x - inset_x, y - inset_y,
button);
} else {
- if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
+ if (cpar(bv)->isInset(cpos(bv))) {
inset = static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
- if (inset->editable() == Inset::HIGHLY_EDITABLE) {
+ if (isHighlyEditableInset(inset)) {
inset->insetButtonRelease(bv,
x - inset_x,
y - inset_y, button);
else if (result == DISPATCHED) {
updateLocal(bv, CURSOR_PAR, false);
return result;
- } else if (result == FINISHED) {
- bool dispatched = false;
- switch (action) {
- case LFUN_UNKNOWN_ACTION:
- case LFUN_BREAKPARAGRAPH:
- case LFUN_BREAKLINE:
+ } else if (result >= FINISHED) {
+ switch(result) {
+ case FINISHED_RIGHT:
moveRightIntern(bv, false, false);
+ result = DISPATCHED;
break;
- case LFUN_RIGHT:
- if (!getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
- moveRightIntern(bv, false, false);
- dispatched = true;
+ case FINISHED_UP:
+ if ((result = moveUp(bv)) >= FINISHED) {
+ updateLocal(bv, CURSOR, false);
+ bv->unlockInset(this);
+ }
break;
- case LFUN_LEFT:
- if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
- moveRightIntern(bv, false, false);
- dispatched = true;
+ case FINISHED_DOWN:
+ if ((result = moveDown(bv)) >= FINISHED) {
+ updateLocal(bv, CURSOR, false);
+ bv->unlockInset(this);
+ }
break;
default:
+ result = DISPATCHED;
break;
}
the_locking_inset = 0;
- if (dispatched)
- return DISPATCHED;
+#ifdef WITH_WARNINGS
+#warning I changed this to always return Dispatched maybe it is wrong (20011001 Jug)
+#endif
+ return result;
}
}
hideInsetCursor(bv);
if (!autoBreakRows) {
if (CutAndPaste::nrOfParagraphs() > 1) {
- WriteAlert(_("Impossible operation"),
+ Alert::alert(_("Impossible operation"),
_("Cannot include more than one paragraph!"),
_("Sorry."));
break;
}
-int InsetText::docBook(Buffer const * buf, ostream & os) const
+int InsetText::docbook(Buffer const * buf, ostream & os) const
{
Paragraph * p = par;
unsigned int lines = 0;
- int desc = 0;
+
+ vector<string> environment_stack(10);
+ vector<string> environment_inner(10);
- string tmp;
+ int const command_depth = 0;
+ string item_name;
+
+ Paragraph::depth_type depth = 0; // paragraph depth
+
while (p) {
- buf->simpleDocBookOnePar(os, tmp, p, desc, 0);
+ string sgmlparam;
+ int desc_on = 0; // description mode
+
+ LyXLayout const & style =
+ textclasslist.Style(buf->params.textclass,
+ p->layout);
+
+ // environment tag closing
+ for (; depth > p->params().depth(); --depth) {
+ if (environment_inner[depth] != "!-- --") {
+ item_name = "listitem";
+ buf->sgmlCloseTag(os, command_depth + depth,
+ item_name);
+ if (environment_inner[depth] == "varlistentry")
+ buf->sgmlCloseTag(os, depth+command_depth,
+ environment_inner[depth]);
+ }
+ buf->sgmlCloseTag(os, depth + command_depth,
+ environment_stack[depth]);
+ environment_stack[depth].erase();
+ environment_inner[depth].erase();
+ }
+
+ if (depth == p->params().depth()
+ && environment_stack[depth] != style.latexname()
+ && !environment_stack[depth].empty()) {
+ if (environment_inner[depth] != "!-- --") {
+ item_name= "listitem";
+ buf->sgmlCloseTag(os, command_depth+depth,
+ item_name);
+ if (environment_inner[depth] == "varlistentry")
+ buf->sgmlCloseTag(os,
+ depth + command_depth,
+ environment_inner[depth]);
+ }
+
+ buf->sgmlCloseTag(os, depth + command_depth,
+ environment_stack[depth]);
+
+ environment_stack[depth].erase();
+ environment_inner[depth].erase();
+ }
+
+ // Write opening SGML tags.
+ switch (style.latextype) {
+ case LATEX_PARAGRAPH:
+ buf->sgmlOpenTag(os, depth + command_depth,
+ style.latexname());
+ break;
+
+ case LATEX_COMMAND:
+ buf->sgmlError(p, 0,
+ _("Error : LatexType Command not allowed here.\n"));
+ return -1;
+ break;
+
+ case LATEX_ENVIRONMENT:
+ case LATEX_ITEM_ENVIRONMENT:
+ if (depth < p->params().depth()) {
+ depth = p->params().depth();
+ environment_stack[depth].erase();
+ }
+
+ if (environment_stack[depth] != style.latexname()) {
+ if(environment_stack.size() == depth + 1) {
+ environment_stack.push_back("!-- --");
+ environment_inner.push_back("!-- --");
+ }
+ environment_stack[depth] = style.latexname();
+ environment_inner[depth] = "!-- --";
+ buf->sgmlOpenTag(os, depth + command_depth,
+ environment_stack[depth]);
+ } else {
+ if (environment_inner[depth] != "!-- --") {
+ item_name= "listitem";
+ buf->sgmlCloseTag(os,
+ command_depth + depth,
+ item_name);
+ if (environment_inner[depth] == "varlistentry")
+ buf->sgmlCloseTag(os,
+ depth + command_depth,
+ environment_inner[depth]);
+ }
+ }
+
+ if (style.latextype == LATEX_ENVIRONMENT) {
+ if (!style.latexparam().empty()) {
+ if(style.latexparam() == "CDATA")
+ os << "<![CDATA[";
+ else
+ buf->sgmlOpenTag(os, depth + command_depth,
+ style.latexparam());
+ }
+ break;
+ }
+
+ desc_on = (style.labeltype == LABEL_MANUAL);
+
+ if (desc_on)
+ environment_inner[depth]= "varlistentry";
+ else
+ environment_inner[depth]= "listitem";
+
+ buf->sgmlOpenTag(os, depth + 1 + command_depth,
+ environment_inner[depth]);
+
+ if (desc_on) {
+ item_name= "term";
+ buf->sgmlOpenTag(os, depth + 1 + command_depth,
+ item_name);
+ } else {
+ item_name= "para";
+ buf->sgmlOpenTag(os, depth + 1 + command_depth,
+ item_name);
+ }
+ break;
+ default:
+ buf->sgmlOpenTag(os, depth + command_depth,
+ style.latexname());
+ break;
+ }
+
+ buf->simpleDocBookOnePar(os, p, desc_on,
+ depth + 1 + command_depth);
p = p->next();
+
+ string end_tag;
+ // write closing SGML tags
+ switch (style.latextype) {
+ case LATEX_ENVIRONMENT:
+ if (!style.latexparam().empty()) {
+ if(style.latexparam() == "CDATA")
+ os << "]]>";
+ else
+ buf->sgmlCloseTag(os, depth + command_depth,
+ style.latexparam());
+ }
+ break;
+ case LATEX_ITEM_ENVIRONMENT:
+ if (desc_on == 1) break;
+ end_tag= "para";
+ buf->sgmlCloseTag(os, depth + 1 + command_depth, end_tag);
+ break;
+ case LATEX_PARAGRAPH:
+ buf->sgmlCloseTag(os, depth + command_depth, style.latexname());
+ break;
+ default:
+ buf->sgmlCloseTag(os, depth + command_depth, style.latexname());
+ break;
+ }
+ }
+
+ // Close open tags
+ for (int d = depth; d >= 0; --d) {
+ if (!environment_stack[depth].empty()) {
+ if (environment_inner[depth] != "!-- --") {
+ item_name = "listitem";
+ buf->sgmlCloseTag(os, command_depth + depth,
+ item_name);
+ if (environment_inner[depth] == "varlistentry")
+ buf->sgmlCloseTag(os, depth + command_depth,
+ environment_inner[depth]);
+ }
+
+ buf->sgmlCloseTag(os, depth + command_depth,
+ environment_stack[depth]);
+ }
}
return lines;
}
lt->insertInset(bv, inset);
#if 0
- if ((cpar(bv)->getChar(cpos(bv)) != Paragraph::META_INSET) ||
+ if ((!cpar(bv)->isInset(cpos(bv))) ||
(cpar(bv)->getInset(cpos(bv)) != inset))
lt->cursorLeft(bv);
#endif
bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
{
- if (cpar(bv)->getChar(cpos(bv)) == Paragraph::META_INSET) {
+ if (cpar(bv)->isInset(cpos(bv))) {
unsigned int x;
unsigned int y;
Inset * inset =
static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
- if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
+ if (!isHighlyEditableInset(inset))
return false;
LyXFont const font =
getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
np = np->next();
np->setInsetOwner(this);
}
+ reinitLyXText();
need_update = INIT;
}
}
-Paragraph::size_type InsetText::cpos(BufferView * bv) const
+pos_type InsetText::cpos(BufferView * bv) const
{
return getLyXText(bv)->cursor.pos();
}
LyXText * InsetText::getLyXText(BufferView const * lbv,
bool const recursive) const
{
- if (!recursive && (cached_bview == lbv))
+ if (!recursive && (cached_bview == lbv)) {
+ LyXText * lt = cached_text.get();
+ lyx::Assert(lt && lt->firstRow()->par() == par);
return cached_text.get();
+ }
// Super UGLY! (Lgb)
BufferView * bv = const_cast<BufferView *>(lbv);
}
+Paragraph * InsetText::getFirstParagraph(int i) const
+{
+ return (i == 0) ? par : 0;
+}
+
+
LyXCursor const & InsetText::cursor(BufferView * bv) const
{
if (the_locking_inset)
void InsetText::paragraph(Paragraph * p)
{
par = p;
-#if 0
- // we now have to update/redraw all instances
- for (Cache::iterator cit = cache.begin(); cit != cache.end(); ++cit) {
- delete cit->second;
- cit->second = 0;
- }
-#endif
+ reinitLyXText();
// redraw myself when asked for
need_update = INIT;
}
}
-string const InsetText::selectNextWord(BufferView * bv, float & value) const
+string const InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
{
bool clear = false;
string str;
clear = true;
}
if (the_locking_inset) {
- str = the_locking_inset->selectNextWord(bv, value);
+ str = the_locking_inset->selectNextWordToSpellcheck(bv, value);
if (!str.empty()) {
value += cy(bv);
if (clear)
// we have to go on checking so move cusor to the right
lt->cursor.pos(lt->cursor.pos() + 1);
}
- str = lt->selectNextWord(bv, value);
+ str = lt->selectNextWordToSpellcheck(bv, value);
if (str.empty())
bv->unlockInset(const_cast<InsetText *>(this));
else
int x = top_x + TEXT_TO_INSET_OFFSET;
- int y = 0;
- Row * row = lt->getRowNearY(y);
+ Row * row = lt->firstRow();
int y_offset = top_baseline - row->ascent_of_text();
- y = y_offset;
+ int y = y_offset;
while ((row != 0) && ((y+row->height()) <= 0)) {
y += row->height();
row = row->next();
clear = true;
}
Paragraph * lpar = lt->cursor.par();
- Paragraph::size_type pos = lt->cursor.pos();
+ pos_type pos = lt->cursor.pos();
if (pos < lpar->size() - 1)
++pos;
else {
bv->unlockInset(const_cast<InsetText *>(this));
return false;
}
+
+
+bool InsetText::checkInsertChar(LyXFont & font)
+{
+ if (owner())
+ return owner()->checkInsertChar(font);
+ return true;
+}