setFont rework + some code simplification

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8140 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Alfredo Braunstein 2003-11-27 09:22:41 +00:00
parent 328760c223
commit 0ca871014a
13 changed files with 45 additions and 183 deletions

View File

@ -1,3 +1,12 @@
2003-11-27 Alfredo Braunstein <abraunst@lyx.org>
* text2.C (setFont): rework using PosIterator (no more recursive)
(setCharFont): no more needed
(setLayout): no more selection cursors fiddling (done by redoCursor)
* text.C: cursorRight(bv)->cursorRight(true) (TODO: find and
destroy remaining ones)
2003-11-26 Alfredo Braunstein <abraunst@lyx.org>
* bufferview_funcs.[Ch]: split changeDepthAllowed from changeDepth

View File

@ -1,3 +1,11 @@
2003-11-27 Alfredo Braunstein <abraunst@lyx.org>
* insettext.[Ch]:
* inset.[Ch]:
* insetcollapsable.[Ch]:
* insetert.[Ch]:
* insettabular.[Ch]: remove setFont
2003-11-25 Alfredo Braunstein <abraunst@lyx.org>
* render_graphic.[Ch]: adjust comments

View File

@ -92,10 +92,6 @@ LColor_color InsetOld::backgroundColor() const
}
void InsetOld::setFont(BufferView *, LyXFont const &, bool, bool)
{}
bool InsetOld::forceDefaultParagraphs(InsetOld const * inset) const
{
if (owner())

View File

@ -239,10 +239,6 @@ public:
/// check if the font of the char we want inserting is correct
/// and modify it if it is not.
virtual bool checkInsertChar(LyXFont &);
/// we need this here because collapsed insets are only EDITABLE
virtual void setFont(BufferView *, LyXFont const &,
bool toggleall = false, bool selectall = false);
// should this inset be handled like a normal charater
virtual bool isChar() const { return false; }
// is this equivalent to a letter?

View File

@ -337,13 +337,6 @@ void InsetCollapsable::getCursorPos(int & x, int & y) const
}
void InsetCollapsable::setFont(BufferView * bv, LyXFont const & font,
bool toggleall, bool selectall)
{
inset.setFont(bv, font, toggleall, selectall);
}
void InsetCollapsable::getLabelList(Buffer const & buffer,
std::vector<string> & list) const
{

View File

@ -79,9 +79,6 @@ public:
/// get the screen x,y of the cursor
void getCursorPos(int & x, int & y) const;
///
void setFont(BufferView *, LyXFont const &, bool toggleall = false,
bool selectall = false);
///
void setLabel(std::string const & l) const;
///
void setLabelFont(LyXFont & f);

View File

@ -224,19 +224,6 @@ bool InsetERT::insertInset(BufferView *, InsetOld *)
}
void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall)
{
#ifdef WITH_WARNINGS
#warning FIXME. More UI stupidity...
#endif
// if selectall is activated then the fontchange was an outside general
// fontchange and this messages is not needed
if (!selectall)
Alert::error(_("Cannot change font"),
_("You cannot change font settings inside TeX code."));
}
void InsetERT::updateStatus(bool swap) const
{
if (status_ != Inlined) {

View File

@ -61,9 +61,6 @@ public:
return code == InsetOld::NEWLINE_CODE;
}
///
void setFont(BufferView *, LyXFont const &,
bool toggleall = false, bool selectall = false);
///
EDITABLE editable() const;
///
int latex(Buffer const &, std::ostream &,

View File

@ -1212,38 +1212,6 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
}
void InsetTabular::setFont(BufferView * bv, LyXFont const & font, bool tall,
bool selectall)
{
if (selectall) {
setSelection(0, tabular.getNumberOfCells() - 1);
}
if (hasSelection()) {
recordUndo(bv, Undo::ATOMIC);
bool const frozen = undo_frozen;
if (!frozen)
freezeUndo();
// apply the fontchange on the whole selection
int sel_row_start;
int sel_row_end;
int sel_col_start;
int sel_col_end;
getSelection(sel_row_start, sel_row_end, sel_col_start, sel_col_end);
for (int i = sel_row_start; i <= sel_row_end; ++i)
for (int j = sel_col_start; j <= sel_col_end; ++j)
tabular.getCellInset(i, j).setFont(bv, font, tall, true);
if (!frozen)
unFreezeUndo();
if (selectall)
clearSelection();
updateLocal(bv);
}
if (the_locking_inset)
the_locking_inset->setFont(bv, font, tall);
}
bool InsetTabular::tabularFeatures(BufferView * bv, string const & what)
{
LyXTabular::Feature action = LyXTabular::LAST_ACTION;

View File

@ -119,9 +119,6 @@ public:
///
int getActCell() const { return actcell; }
///
void setFont(BufferView *, LyXFont const &, bool toggleall = false,
bool selectall = false);
///
void openLayoutDialog(BufferView *) const;
///
bool showInsetDialog(BufferView *) const;

View File

@ -305,7 +305,7 @@ void InsetText::sanitizeEmptyText(BufferView * bv)
&& bv->getParentLanguage(this) != text_.current_font.language()) {
LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(bv->getParentLanguage(this));
setFont(bv, font, false);
text_.setFont(font, false);
}
}
@ -376,7 +376,7 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd,
paragraphs.size() == 1) {
LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(bv->getParentLanguage(this));
setFont(bv, font, false);
text_.setFont(font, false);
}
lyxerr << "InsetText::priv_dispatch (end)" << endl;
@ -489,34 +489,6 @@ void InsetText::getLabelList(Buffer const & buffer,
}
void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
bool selectall)
{
if ((paragraphs.size() == 1 && paragraphs.begin()->empty())
|| cpar()->empty()) {
text_.setFont(font, toggleall);
return;
}
if (text_.selection.set())
text_.recUndo(text_.cursor.par());
if (selectall) {
text_.cursorTop();
text_.selection.cursor = text_.cursor;
text_.cursorBottom();
text_.setSelection();
}
text_.toggleFree(font, toggleall);
if (selectall)
text_.clearSelection();
updateLocal(bv, true);
}
void InsetText::markNew(bool track_changes)
{
ParagraphList::iterator pit = paragraphs.begin();

View File

@ -1281,7 +1281,7 @@ void LyXText::Delete()
LyXCursor old_cursor = cursor;
// just move to the right
cursorRight(bv());
cursorRight(true);
// if you had success make a backspace
if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {

View File

@ -43,6 +43,7 @@
#include "paragraph.h"
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
#include "PosIterator.h"
#include "undo.h"
#include "vspace.h"
@ -178,27 +179,6 @@ LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const
}
void LyXText::setCharFont(ParagraphList::iterator pit,
pos_type pos, LyXFont const & fnt,
bool toggleall)
{
BufferParams const & params = bv()->buffer()->params();
LyXFont font = getFont(pit, pos);
font.update(fnt, params.language, toggleall);
// Let the insets convert their font
if (pit->isInset(pos)) {
InsetOld * inset = pit->getInset(pos);
if (isEditableInset(inset)) {
static_cast<UpdatableInset *>(inset)
->setFont(bv(), fnt, toggleall, true);
}
}
// Plug through to version below:
setCharFont(pit, pos, font);
}
void LyXText::setCharFont(
ParagraphList::iterator pit, pos_type pos, LyXFont const & fnt)
{
@ -349,14 +329,7 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur,
// set layout over selection and make a total rebreak of those paragraphs
void LyXText::setLayout(string const & layout)
{
LyXCursor tmpcursor = cursor; // store the current cursor
// if there is no selection just set the layout
// of the current paragraph
if (!selection.set()) {
selection.start = cursor; // dummy selection
selection.end = cursor;
}
setSelection();
// special handling of new environment insets
BufferParams const & params = bv()->buffer()->params();
@ -371,8 +344,7 @@ void LyXText::setLayout(string const & layout)
if (bv()->insertInset(inset)) {
//inset->edit(bv());
//bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
}
else
} else
delete inset;
return;
}
@ -380,16 +352,8 @@ void LyXText::setLayout(string const & layout)
ParagraphList::iterator endpit = setLayout(cursor, selection.start,
selection.end, layout);
redoParagraphs(getPar(selection.start), endpit);
// we have to reset the selection, because the
// geometry could have changed
setCursor(selection.start.par(), selection.start.pos(), false);
selection.cursor = cursor;
setCursor(selection.end.par(), selection.end.pos(), false);
updateCounters();
clearSelection();
setSelection();
setCursor(tmpcursor.par(), tmpcursor.pos(), true);
redoCursor();
}
@ -499,39 +463,28 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
return;
}
LyXCursor tmpcursor = cursor; // store the current cursor
// ok we have a selection. This is always between sel_start_cursor
// and sel_end cursor
// ok we have a selection.
recUndo(selection.start.par(), selection.end.par());
freezeUndo();
cursor = selection.start;
while (cursor.par() != selection.end.par() ||
cursor.pos() < selection.end.pos())
{
if (cursor.pos() < cursorPar()->size()) {
// an open footnote should behave like a closed one
setCharFont(cursorPar(), cursor.pos(), font, toggleall);
cursor.pos(cursor.pos() + 1);
} else {
cursor.pos(0);
cursor.par(cursor.par() + 1);
}
ParagraphList::iterator beg = getPar(selection.start.par());
ParagraphList::iterator end = getPar(selection.end.par());
PosIterator pos(&ownerParagraphs(), beg, selection.start.pos());
PosIterator posend(&ownerParagraphs(), end, selection.end.pos());
BufferParams const & params = bv()->buffer()->params();
for (; pos != posend; ++pos) {
LyXFont f = getFont(pos.pit(), pos.pos());
f.update(font, params.language, toggleall);
setCharFont(pos.pit(), pos.pos(), f);
}
unFreezeUndo();
redoParagraph(getPar(selection.start));
// we have to reset the selection, because the
// geometry could have changed, but we keep
// it for user convenience
setCursor(selection.start.par(), selection.start.pos());
selection.cursor = cursor;
setCursor(selection.end.par(), selection.end.pos());
setSelection();
setCursor(tmpcursor.par(), tmpcursor.pos(), true,
tmpcursor.boundary());
redoParagraphs(beg, ++end);
redoCursor();
}
@ -665,12 +618,7 @@ void LyXText::setParagraph(VSpace const & space_top,
string const & labelwidthstring,
bool noindent)
{
LyXCursor tmpcursor = cursor;
if (!selection.set()) {
selection.start = cursor;
selection.end = cursor;
}
setSelection();
// make sure that the depth behind the selection are restored, too
ParagraphList::iterator endpit = boost::next(getPar(selection.end));
ParagraphList::iterator undoendpit = endpit;
@ -716,13 +664,7 @@ void LyXText::setParagraph(VSpace const & space_top,
}
redoParagraphs(getPar(selection.start), endpit);
clearSelection();
setCursor(selection.start.par(), selection.start.pos());
selection.cursor = cursor;
setCursor(selection.end.par(), selection.end.pos());
setSelection();
setCursor(tmpcursor.par(), tmpcursor.pos());
redoCursor();
}