From: Lars Gullik Bjønnes Date: Thu, 31 May 2001 02:23:46 +0000 (+0000) Subject: adjust to be able to complile with gcc 3.0, put selection vars into own struct, remov... X-Git-Tag: 1.6.10~21217 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f1d829a18584fe8c787c7ea428f10cc7a82d6083;p=features.git adjust to be able to complile with gcc 3.0, put selection vars into own struct, remove some C string funcs in favour of lstrings ones git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2074 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView2.C b/src/BufferView2.C index 1e6ceef3dc..961b4c5879 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -267,7 +267,7 @@ bool BufferView::gotoLabel(string const & label) != labels.end()) { beforeChange(text); text->SetCursor(this, it.getPar(), it.getPos()); - text->sel_cursor = text->cursor; + text->selection.cursor = text->cursor; update(text, BufferView::SELECT|BufferView::FITCUR); return true; } @@ -418,7 +418,7 @@ void BufferView::gotoInset(std::vector const & codes, } } update(text, BufferView::SELECT|BufferView::FITCUR); - text->sel_cursor = text->cursor; + text->selection.cursor = text->cursor; } diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 66fd7fc535..421bb8b25f 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -291,12 +291,12 @@ int BufferView::Pimpl::resizeCurrentBuffer() if (bv_->text) { par = bv_->text->cursor.par(); pos = bv_->text->cursor.pos(); - selstartpar = bv_->text->sel_start_cursor.par(); - selstartpos = bv_->text->sel_start_cursor.pos(); - selendpar = bv_->text->sel_end_cursor.par(); - selendpos = bv_->text->sel_end_cursor.pos(); - selection = bv_->text->selection; - mark_set = bv_->text->mark_set; + selstartpar = bv_->text->selection.start.par(); + selstartpos = bv_->text->selection.start.pos(); + selendpar = bv_->text->selection.end.par(); + selendpos = bv_->text->selection.end.pos(); + selection = bv_->text->selection.set(); + mark_set = bv_->text->selection.mark(); the_locking_inset = bv_->text->the_locking_inset; delete bv_->text; bv_->text = new LyXText(bv_); @@ -320,20 +320,20 @@ int BufferView::Pimpl::resizeCurrentBuffer() updateScreen(); if (par) { - bv_->text->selection = true; + bv_->text->selection.set(true); /* at this point just to avoid the Delete-Empty-Paragraph * Mechanism when setting the cursor */ - bv_->text->mark_set = mark_set; + bv_->text->selection.mark(mark_set); if (selection) { bv_->text->SetCursor(bv_, selstartpar, selstartpos); - bv_->text->sel_cursor = bv_->text->cursor; + bv_->text->selection.cursor = bv_->text->cursor; bv_->text->SetCursor(bv_, selendpar, selendpos); bv_->text->SetSelection(bv_); bv_->text->SetCursor(bv_, par, pos); } else { bv_->text->SetCursor(bv_, par, pos); - bv_->text->sel_cursor = bv_->text->cursor; - bv_->text->selection = false; + bv_->text->selection.cursor = bv_->text->cursor; + bv_->text->selection.set(false); } // remake the inset locking bv_->text->the_locking_inset = the_locking_inset; @@ -554,7 +554,7 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state) bv_->text->SetCursorFromCoordinates(bv_, x, y + bv_->text->first); - if (!bv_->text->selection) + if (!bv_->text->selection.set()) update(bv_->text, BufferView::UPDATE); // Maybe an empty line was deleted bv_->text->SetSelection(bv_); @@ -612,7 +612,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos, // Middle button press pastes if we have a selection bool paste_internally = false; if (button == 2 - && bv_->text->selection) { + && bv_->text->selection.set()) { owner_->getLyXFunc()->Dispatch(LFUN_COPY); paste_internally = true; } @@ -646,7 +646,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos, if (!inset_hit) // otherwise it was already set in checkInsetHit(...) bv_->text->SetCursorFromCoordinates(bv_, xpos, ypos + screen_first); bv_->text->FinishUndo(); - bv_->text->sel_cursor = bv_->text->cursor; + bv_->text->selection.cursor = bv_->text->cursor; bv_->text->cursor.x_fix(bv_->text->cursor.x()); owner_->updateLayoutChoice(); @@ -711,7 +711,7 @@ void BufferView::Pimpl::tripleClick(int /*x*/, int /*y*/, unsigned int button) screen_->HideCursor(); screen_->ToggleSelection(text, bv_); text->CursorHome(bv_); - text->sel_cursor = text->cursor; + text->selection.cursor = text->cursor; text->CursorEnd(bv_); text->SetSelection(bv_); screen_->ToggleSelection(text, bv_, false); @@ -1008,8 +1008,8 @@ void BufferView::Pimpl::update(LyXText * text, BufferView::UpdateCodes f) { owner_->updateLayoutChoice(); - if (!text->selection && (f & SELECT)) { - text->sel_cursor = text->cursor; + if (!text->selection.set() && (f & SELECT)) { + text->selection.cursor = text->cursor; } text->FullRebreak(bv_); @@ -1333,7 +1333,7 @@ void BufferView::Pimpl::moveCursorUpdate(bool selecting) { LyXText * lt = bv_->getLyXText(); - if (selecting || lt->mark_set) { + if (selecting || lt->selection.mark()) { lt->SetSelection(bv_); if (lt->bv_owner) bv_->toggleToggle(); @@ -1795,7 +1795,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) LyXText * lt = bv_->getLyXText(); bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::SELECT|BufferView::FITCUR); if (is_rtl) @@ -1832,7 +1832,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) // it simpler? (Lgb) LyXText * lt = bv_->getLyXText(); bool is_rtl = lt->cursor.par()->isRightToLeftPar(buffer_->params); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::SELECT|BufferView::FITCUR); LyXCursor const & cur = lt->cursor; @@ -1872,7 +1872,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::UPDATE); lt->CursorUp(bv_); @@ -1886,7 +1886,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::UPDATE); lt->CursorDown(bv_); @@ -1900,7 +1900,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::UPDATE); lt->CursorUpParagraph(bv_); @@ -1914,7 +1914,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::UPDATE); lt->CursorDownParagraph(bv_); @@ -1928,7 +1928,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::UPDATE); cursorPrevious(lt); @@ -1942,7 +1942,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::UPDATE); cursorNext(lt); @@ -1956,7 +1956,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::SELECT|BufferView::FITCUR); lt->CursorHome(bv_); @@ -1970,7 +1970,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::SELECT|BufferView::FITCUR); @@ -1986,7 +1986,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::SELECT|BufferView::FITCUR); @@ -2001,7 +2001,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::SELECT|BufferView::FITCUR); if (lt->cursor.par()->isRightToLeftPar(buffer_->params)) @@ -2018,7 +2018,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::SELECT|BufferView::FITCUR); if (lt->cursor.par()->isRightToLeftPar(buffer_->params)) @@ -2035,7 +2035,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::SELECT|BufferView::FITCUR); @@ -2050,7 +2050,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->mark_set) + if (!lt->selection.mark()) beforeChange(lt); update(lt, BufferView::SELECT|BufferView::FITCUR); @@ -2293,7 +2293,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (lt->mark_set) { + if (lt->selection.mark()) { beforeChange(lt); update(lt, BufferView::SELECT @@ -2301,13 +2301,13 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) owner_->getLyXFunc()->setMessage(N_("Mark removed")); } else { beforeChange(lt); - lt->mark_set = 1; + lt->selection.mark(true); update(lt, BufferView::SELECT | BufferView::FITCUR); owner_->getLyXFunc()->setMessage(N_("Mark set")); } - lt->sel_cursor = lt->cursor; + lt->selection.cursor = lt->cursor; } break; @@ -2315,9 +2315,9 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) { LyXText * lt = bv_->getLyXText(); - if (!lt->selection) { + if (!lt->selection.set()) { lt->Delete(bv_); - lt->sel_cursor = lt->cursor; + lt->selection.cursor = lt->cursor; update(lt, BufferView::SELECT | BufferView::FITCUR @@ -2342,7 +2342,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) LyXCursor cursor = lt->cursor; - if (!lt->selection) { + if (!lt->selection.set()) { if (cursor.pos() == cursor.par()->size()) { lt->CursorRight(bv_); cursor = lt->cursor; @@ -2367,7 +2367,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) } else { lt->CursorLeft(bv_); lt->Delete(bv_); - lt->sel_cursor = lt->cursor; + lt->selection.cursor = lt->cursor; update(lt, BufferView::SELECT | BufferView::FITCUR @@ -2375,7 +2375,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) } } else { lt->Delete(bv_); - lt->sel_cursor = lt->cursor; + lt->selection.cursor = lt->cursor; update(lt, BufferView::SELECT | BufferView::FITCUR @@ -2398,46 +2398,68 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) /* -------> Delete word backward. */ case LFUN_DELETE_WORD_BACKWARD: - update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR); - bv_->getLyXText()->DeleteWordBackward(bv_); - update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + { + LyXText * lt = bv_->getLyXText(); + + update(lt, BufferView::SELECT|BufferView::FITCUR); + lt->DeleteWordBackward(bv_); + update(lt, + BufferView::SELECT + | BufferView::FITCUR + | BufferView::CHANGE); moveCursorUpdate(false); owner_->showState(); - break; + } + break; /* -------> Kill to end of line. */ case LFUN_DELETE_LINE_FORWARD: - update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR); - bv_->getLyXText()->DeleteLineForward(bv_); - update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + { + LyXText * lt = bv_->getLyXText(); + + update(lt, BufferView::SELECT|BufferView::FITCUR); + lt->DeleteLineForward(bv_); + update(lt, + BufferView::SELECT + | BufferView::FITCUR + | BufferView::CHANGE); moveCursorUpdate(false); - break; + } + break; /* -------> Set mark off. */ case LFUN_MARK_OFF: - beforeChange(bv_->getLyXText()); - update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR); - bv_->getLyXText()->sel_cursor = bv_->getLyXText()->cursor; + { + LyXText * lt = bv_->getLyXText(); + + beforeChange(lt); + update(lt, BufferView::SELECT|BufferView::FITCUR); + lt->selection.cursor = lt->cursor; owner_->getLyXFunc()->setMessage(N_("Mark off")); - break; + } + break; /* -------> Set mark on. */ case LFUN_MARK_ON: - beforeChange(bv_->getLyXText()); - bv_->getLyXText()->mark_set = 1; - update(bv_->getLyXText(), BufferView::SELECT|BufferView::FITCUR); - bv_->getLyXText()->sel_cursor = bv_->getLyXText()->cursor; + { + LyXText * lt = bv_->getLyXText(); + + beforeChange(lt); + lt->selection.mark(true); + update(lt, BufferView::SELECT|BufferView::FITCUR); + lt->selection.cursor = lt->cursor; owner_->getLyXFunc()->setMessage(N_("Mark on")); - break; + } + break; case LFUN_BACKSPACE: { LyXText * lt = bv_->getLyXText(); - if (!lt->selection) { + if (!lt->selection.set()) { if (owner_->getIntl()->getTrans().backspace()) { lt->Backspace(bv_); - lt->sel_cursor = lt->cursor; + lt->selection.cursor = lt->cursor; update(lt, BufferView::SELECT | BufferView::FITCUR @@ -2461,7 +2483,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) LyXCursor cursor = lt->cursor; - if (!lt->selection) { + if (!lt->selection.set()) { if (cursor.pos() == 0 && !(cursor.par()->params.spaceTop() == VSpace (VSpace::NONE))) { @@ -2480,7 +2502,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) | BufferView::CHANGE); } else { lt->Backspace(bv_); - lt->sel_cursor = cursor; + lt->selection.cursor = cursor; update(lt, BufferView::SELECT | BufferView::FITCUR @@ -2501,7 +2523,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE); - lt->sel_cursor = lt->cursor; + lt->selection.cursor = lt->cursor; setState(); owner_->showState(); break; @@ -2517,7 +2539,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE); - lt->sel_cursor = lt->cursor; + lt->selection.cursor = lt->cursor; setState(); owner_->showState(); break; @@ -2556,7 +2578,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE); - lt->sel_cursor = cursor; + lt->selection.cursor = cursor; setState(); owner_->showState(); } @@ -3098,7 +3120,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) LyXText * lt = bv_->getLyXText(); if (lyxrc.auto_region_delete) { - if (lt->selection){ + if (lt->selection.set()) { lt->CutSelection(bv_, false); bv_->update(lt, BufferView::SELECT @@ -3125,7 +3147,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) | BufferView::FITCUR | BufferView::CHANGE); - lt->sel_cursor = lt->cursor; + lt->selection.cursor = lt->cursor; moveCursorUpdate(false); // real_current_font.number can change so we need to @@ -3149,13 +3171,18 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) char datetmp[32]; int const datetmp_len = ::strftime(datetmp, 32, arg.c_str(), now_tm); + + LyXText * lt = bv_->getLyXText(); + for (int i = 0; i < datetmp_len; i++) { - bv_->getLyXText()->InsertChar(bv_, datetmp[i]); - update(bv_->getLyXText(), - BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + lt->InsertChar(bv_, datetmp[i]); + update(lt, + BufferView::SELECT + | BufferView::FITCUR + | BufferView::CHANGE); } - bv_->getLyXText()->sel_cursor = bv_->getLyXText()->cursor; + lt->selection.cursor = lt->cursor; moveCursorUpdate(false); } break; diff --git a/src/ChangeLog b/src/ChangeLog index 2efc2e2c12..16f4dee895 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,40 @@ +2001-05-31 Lars Gullik Bjønnes + + * text2.C: adjust + * text.C: adjust + + + * tabular.C (getTokenValue): add std:: + + * tabular-old.C (getTokenValue): add std:: + (getTokenValue): ditto + (getTokenValue): ditto + + * screen.C (ToggleSelection): adjust + + * lyxtext.h: put selection cursors inside a Selection struct. + + * lyxfunc.C (moveCursorUpdate): adjust + + * lyxfont.C (latexWriteStartChanges): add std:: + + * lyxfind.C: adjust + + * font.h: delete with(char const *, LyXFont const &) + + * buffer.C (parseSingleLyXformat2Token): use contains instead of strstr + + * FontInfo.C (getFontname): add std:: + + * BufferView_pimpl.C (resizeCurrentBuffer): adjust + (workAreaButtonPress): adjust + (tripleClick): adjust + (update): adjust + (moveCursorUpdate): adjust + (Dispatch): adjust + + * BufferView2.C (gotoInset): adjust + 2001-05-30 Juergen Vigna * spellchecker.C (USE_ORIGINAL_MANAGER_FUNCS): as it seems only I use diff --git a/src/FontInfo.C b/src/FontInfo.C index a9117e6f94..9f55fa5f05 100644 --- a/src/FontInfo.C +++ b/src/FontInfo.C @@ -41,15 +41,15 @@ string const FontInfo::getFontname(int size) lyxerr[Debug::FONT] << "Exact font match with\n" << strings[i] << endl; return strings[i]; - } else if (fabs(sizes[i] - size - 0.1) < error) { - error = fabs(sizes[i] - size - 0.1); + } else if (std::fabs(sizes[i] - size - 0.1) < error) { + error = std::fabs(sizes[i] - size - 0.1); closestind = i; } } if (scalable && lyxrc.use_scalable_fonts) { // We can use scalable - string font = resize(strings[scaleindex], size); + string const font = resize(strings[scaleindex], size); lyxerr[Debug::FONT] << "Using scalable font to get\n" << font << endl; return font; diff --git a/src/buffer.C b/src/buffer.C index 27cbb6435d..65d46a01ec 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1535,10 +1535,10 @@ string const Buffer::asciiParagraph(LyXParagraph const * par, } else if (tmp == "Enumerate") { ltype = 2; ltype_depth = depth + 1; - } else if (strstr(tmp.c_str(), "ection")) { + } else if (contains(tmp, "ection")) { ltype = 3; ltype_depth = depth + 1; - } else if (strstr(tmp.c_str(), "aragraph")) { + } else if (contains(tmp, "aragraph")) { ltype = 4; ltype_depth = depth + 1; } else if (tmp == "Description") { diff --git a/src/font.h b/src/font.h index ed578aa345..ae164a7d10 100644 --- a/src/font.h +++ b/src/font.h @@ -59,10 +59,10 @@ struct lyxfont { return width(s.c_str(), s.length(), f); } /// - static - int width(char const * s, LyXFont const & f) { - return width(s, strlen(s), f); - } + //static + //int width(char const * s, LyXFont const & f) { + // return width(s, strlen(s), f); + //} /// static int signedWidth(string const & s, LyXFont const & f); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index df53486386..ee75a80f55 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,9 @@ +2001-05-31 Lars Gullik Bjønnes + + * MathsSymbols.C (pixmapFromBitmapData): add std:: + + * FormMathsMatrix.C (AlignFilter): add std:: + 2001-05-22 Adrien Rebollo * FormDocument.C (build): add iso8859-15 support. diff --git a/src/frontends/xforms/FormFiledialog.C b/src/frontends/xforms/FormFiledialog.C index cf650718a0..260f6b7fb2 100644 --- a/src/frontends/xforms/FormFiledialog.C +++ b/src/frontends/xforms/FormFiledialog.C @@ -13,7 +13,7 @@ #include #include #include -#include +//#include #include #include diff --git a/src/frontends/xforms/FormMathsMatrix.C b/src/frontends/xforms/FormMathsMatrix.C index aea5a7188c..0a957c56a1 100644 --- a/src/frontends/xforms/FormMathsMatrix.C +++ b/src/frontends/xforms/FormMathsMatrix.C @@ -105,8 +105,8 @@ bool FormMathsMatrix::input(FL_OBJECT * ob, long) int FormMathsMatrix::AlignFilter(char const * cur, int c) { - int n = int(fl_get_slider_value(dialog_->slider_columns)+0.5) - - int(strlen(cur)); + int const n = int(fl_get_slider_value(dialog_->slider_columns) + 0.5) - + int(std::strlen(cur)); if (n < 0) return FL_INVALID; diff --git a/src/frontends/xforms/MathsSymbols.C b/src/frontends/xforms/MathsSymbols.C index d6c273ecdb..ec5f692910 100644 --- a/src/frontends/xforms/MathsSymbols.C +++ b/src/frontends/xforms/MathsSymbols.C @@ -268,7 +268,7 @@ static char const ** pixmapFromBitmapData(char const * s, int wx, int hx) XpmCreateDataFromImage(fl_get_display(), const_cast(&data), sbima, sbima, 0); // Dirty hack to get blue symbols quickly - char * sx = const_cast(strstr(data[2], "FFFFFFFF")); + char * sx = const_cast(std::strstr(data[2], "FFFFFFFF")); if (sx) { for (int k = 0; k < 8; ++k) sx[k] = '0'; } diff --git a/src/frontends/xforms/combox.C b/src/frontends/xforms/combox.C index f0ea91c1d5..3d5ac155fc 100644 --- a/src/frontends/xforms/combox.C +++ b/src/frontends/xforms/combox.C @@ -36,7 +36,7 @@ #endif #include "combox.h" -#include +//#include #include "debug.h" diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 698715f6a3..642c26840d 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,14 @@ +2001-05-31 Lars Gullik Bjønnes + + * insettext.C: adjust + + * insetgraphics.[Ch] (statusMessage): change to return string + (width): adjust + (draw): adjust + + * figinset.C (runqueue): add std:: + (Recompute): ditto + 2001-05-28 Jean-Marc Lasgouttes * insetcite.C (Ascii): add std:: qualifier diff --git a/src/insets/figinset.C b/src/insets/figinset.C index f1e0ad7779..64f1e288cb 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -632,7 +632,8 @@ void runqueue() env[0] = new char[tmp.size() + 1]; std::copy(tmp.begin(), tmp.end(), env[0]); env[0][tmp.size()] = '\0'; - ::memcpy(&env[1], environ, sizeof(char*) * (ne + 1)); + std::memcpy(&env[1], environ, + sizeof(char*) * (ne + 1)); environ = env; // now make gs command @@ -1003,7 +1004,8 @@ void InsetFig::draw(BufferView * bv, LyXFont const & f, wid + 1, hgh + 1); } else { - char const * msg = 0; + //char const * msg = 0; + string msg; string lfname = fname; if (!fname.empty() && GetExtension(fname).empty()) lfname += ".eps"; @@ -1023,16 +1025,16 @@ void InsetFig::draw(BufferView * bv, LyXFont const & f, else if (lyxrc.ps_command.empty()) msg = _("[no ghostscript]"); - if (!msg) msg = _("[unknown error]"); + if (msg.empty()) msg = _("[unknown error]"); font.setFamily(LyXFont::SANS_FAMILY); font.setSize(LyXFont::SIZE_FOOTNOTE); - string justname = OnlyFilename (fname); + string const justname = OnlyFilename (fname); pain.text(int(x + 8), baseline - lyxfont::maxAscent(font) - 4, justname, font); font.setSize(LyXFont::SIZE_TINY); - pain.text(int(x + 8), baseline - 4, msg, strlen(msg), font); + pain.text(int(x + 8), baseline - 4, msg, font); } x += width(bv, font); // ? } @@ -1435,10 +1437,10 @@ void InsetFig::Recompute() if (changed) GetPSSizes(); - float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */ - float cos_a = cos (angle / DEG2PI); - int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh))); - int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid))); + float sin_a = std::sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */ + float cos_a = std::cos (angle / DEG2PI); + int frame_wid = int(ceil(std::fabs(cos_a * pswid) + std::fabs(sin_a * pshgh))); + int frame_hgh= int(ceil(std::fabs(cos_a * pshgh) + std::fabs(sin_a * pswid))); string lfname = fname; if (GetExtension(fname).empty()) diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 3d7a2d151a..a99ce6cb79 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -172,10 +172,10 @@ InsetGraphics::~InsetGraphics() } -char const * +string const InsetGraphics::statusMessage() const { - char const * msg = 0; + string msg; if (cacheHandle.get()) { switch (cacheHandle->getImageStatus()) { @@ -229,10 +229,10 @@ int InsetGraphics::width(BufferView *, LyXFont const & font) const if (cacheHandle.get() && (pixmap = cacheHandle->getImage())) return pixmap->getWidth(); else { - char const * msg = statusMessage(); + string const msg = statusMessage(); int font_width = 0; - if (msg) + if (!msg.empty()) font_width = lyxfont::width(msg, font); return std::max(50, font_width + 15); @@ -276,13 +276,13 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, return; } - char const * msg = statusMessage(); + string const msg = statusMessage(); paint.rectangle(int(old_x) + 2, baseline - lascent, lwidth - 4, lascent + ldescent); - if (msg) { + if (!msg.empty()) { // Print the message. LyXFont msgFont(font); msgFont.setFamily(LyXFont::SANS_FAMILY); @@ -294,7 +294,7 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, msgFont.setSize(LyXFont::SIZE_TINY); paint.text(int(old_x) + 8, baseline - 4, - msg, strlen(msg), msgFont); + msg, msgFont); } } } diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index dc5ba73adb..4318042606 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -97,7 +97,7 @@ private: /// Update the inset after parameter change. void updateInset() const; /// Get the status message, depends on the image loading status. - char const * statusMessage() const; + string const statusMessage() const; /// Create the options for the latex command. string const createLatexOptions() const; /// Convert the file if needed, and return the location of the file. diff --git a/src/insets/insettext.C b/src/insets/insettext.C index b126a5d5ae..02ab563ae9 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -337,7 +337,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; } - if (!cleared && (need_update == CURSOR) && !TEXT(bv)->selection) { + if (!cleared && (need_update == CURSOR) && !TEXT(bv)->selection.set()) { drawFrame(pain, cleared); x += width(bv, f); need_update = NONE; @@ -379,7 +379,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, if (need_update & CURSOR) { bv->screen()->ToggleSelection(TEXT(bv), bv, true, y_offset,int(x)); TEXT(bv)->ClearSelection(bv); - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + TEXT(bv)->selection.cursor = TEXT(bv)->cursor; } bv->screen()->Update(TEXT(bv), bv, y_offset, int(x)); } else { @@ -389,7 +389,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, else if (need_update & CURSOR) { bv->screen()->ToggleSelection(TEXT(bv), bv, true, y_offset,int(x)); TEXT(bv)->ClearSelection(bv); - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + TEXT(bv)->selection.cursor = TEXT(bv)->cursor; } bv->screen()->Update(TEXT(bv), bv, y_offset, int(x)); locked = true; @@ -499,7 +499,7 @@ void InsetText::UpdateLocal(BufferView * bv, int what, bool mark_dirty) TEXT(bv)->FullRebreak(bv); SetUpdateStatus(bv, what); if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED) || - TEXT(bv)->selection) + TEXT(bv)->selection.set()) bv->updateInset(this, mark_dirty); bv->owner()->showState(); if (old_par != cpar(bv)) { @@ -534,7 +534,7 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button) if (!checkAndActivateInset(bv, x, tmp_y, button)) TEXT(bv)->SetCursorFromCoordinates(bv, x - drawTextXOffset, y + insetAscent); - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + TEXT(bv)->selection.cursor = TEXT(bv)->cursor; bv->text->FinishUndo(); ShowInsetCursor(bv); UpdateLocal(bv, CURSOR, false); @@ -561,7 +561,7 @@ void InsetText::InsetUnlock(BufferView * bv) no_selection = false; locked = false; int code = CURSOR|CLEAR_FRAME; - if (TEXT(bv)->selection) { + if (TEXT(bv)->selection.set()) { TEXT(bv)->ClearSelection(bv); code = FULL; } else if (owner()) @@ -705,13 +705,13 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button) } if (!inset) { // && (button == 2)) { bool paste_internally = false; - if ((button == 2) && TEXT(bv)->selection) { + if ((button == 2) && TEXT(bv)->selection.set()) { LocalDispatch(bv, LFUN_COPY, ""); paste_internally = true; } TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset, y + insetAscent); - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + TEXT(bv)->selection.cursor = TEXT(bv)->cursor; UpdateLocal(bv, CURSOR, false); bv->owner()->setLayout(cpar(bv)->GetLayout()); old_par = cpar(bv); @@ -859,7 +859,7 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->cursor.par()->next()); bv->setState(); if (lyxrc.auto_region_delete) { - if (TEXT(bv)->selection){ + if (TEXT(bv)->selection.set()) { TEXT(bv)->CutSelection(bv, false); } } @@ -876,7 +876,7 @@ InsetText::LocalDispatch(BufferView * bv, } } } - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + TEXT(bv)->selection.cursor = TEXT(bv)->cursor; UpdateLocal(bv, CURSOR_PAR, true); result=DISPATCHED_NOUPDATE; break; @@ -938,7 +938,7 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->SetUndo(bv->buffer(), Undo::DELETE, bv->text->cursor.par()->previous(), bv->text->cursor.par()->next()); - if (TEXT(bv)->selection) + if (TEXT(bv)->selection.set()) TEXT(bv)->CutSelection(bv); else TEXT(bv)->Backspace(bv); @@ -948,7 +948,7 @@ InsetText::LocalDispatch(BufferView * bv, bv->text->SetUndo(bv->buffer(), Undo::DELETE, bv->text->cursor.par()->previous(), bv->text->cursor.par()->next()); - if (TEXT(bv)->selection) + if (TEXT(bv)->selection.set()) TEXT(bv)->CutSelection(bv); else TEXT(bv)->Delete(bv); @@ -1284,7 +1284,7 @@ InsetText::moveRightIntern(BufferView * bv, bool behind, return DISPATCHED; TEXT(bv)->CursorRight(bv); if (!selecting) - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + TEXT(bv)->selection.cursor = TEXT(bv)->cursor; return DISPATCHED_NOUPDATE; } @@ -1297,7 +1297,7 @@ InsetText::moveLeftIntern(BufferView * bv, bool behind, return FINISHED; TEXT(bv)->CursorLeft(bv); if (!selecting) - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + TEXT(bv)->selection.cursor = TEXT(bv)->cursor; if (activate_inset && checkAndActivateInset(bv, behind)) return DISPATCHED; return DISPATCHED_NOUPDATE; @@ -1394,7 +1394,7 @@ std::vector const InsetText::getLabelList() const void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall, bool selectall) { - if (TEXT(bv)->selection) { + if (TEXT(bv)->selection.set()) { bv->text->SetUndo(bv->buffer(), Undo::EDIT, bv->text->cursor.par()->previous(), bv->text->cursor.par()->next()); @@ -1405,7 +1405,7 @@ void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall, if (selectall) TEXT(bv)->ClearSelection(bv); bv->fitCursor(TEXT(bv)); - if (selectall || TEXT(bv)->selection) + if (selectall || TEXT(bv)->selection.set()) UpdateLocal(bv, FULL, true); else UpdateLocal(bv, CURSOR_PAR, true); @@ -1657,8 +1657,8 @@ void InsetText::resizeLyXText(BufferView * bv) const bool boundary = false; bool selstartboundary = false; bool selendboundary = false; - int selection = 0; - int mark_set = 0; + bool selection = false; + bool mark_set = false; // ProhibitInput(bv); @@ -1666,34 +1666,34 @@ void InsetText::resizeLyXText(BufferView * bv) const lpar = TEXT(bv)->cursor.par(); pos = TEXT(bv)->cursor.pos(); boundary = TEXT(bv)->cursor.boundary(); - selstartpar = TEXT(bv)->sel_start_cursor.par(); - selstartpos = TEXT(bv)->sel_start_cursor.pos(); - selstartboundary = TEXT(bv)->sel_start_cursor.boundary(); - selendpar = TEXT(bv)->sel_end_cursor.par(); - selendpos = TEXT(bv)->sel_end_cursor.pos(); - selendboundary = TEXT(bv)->sel_end_cursor.boundary(); - selection = TEXT(bv)->selection; - mark_set = TEXT(bv)->mark_set; + selstartpar = TEXT(bv)->selection.start.par(); + selstartpos = TEXT(bv)->selection.start.pos(); + selstartboundary = TEXT(bv)->selection.start.boundary(); + selendpar = TEXT(bv)->selection.end.par(); + selendpos = TEXT(bv)->selection.end.pos(); + selendboundary = TEXT(bv)->selection.end.boundary(); + selection = TEXT(bv)->selection.set(); + mark_set = TEXT(bv)->selection.mark(); } deleteLyXText(bv, (the_locking_inset == 0)); if (lpar) { - TEXT(bv)->selection = true; + TEXT(bv)->selection.set(true); /* at this point just to avoid the Delete-Empty-Paragraph * Mechanism when setting the cursor */ - TEXT(bv)->mark_set = mark_set; + TEXT(bv)->selection.mark(mark_set); if (selection) { TEXT(bv)->SetCursor(bv, selstartpar, selstartpos, true, selstartboundary); - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + TEXT(bv)->selection.cursor = TEXT(bv)->cursor; TEXT(bv)->SetCursor(bv, selendpar, selendpos, true, selendboundary); TEXT(bv)->SetSelection(bv); TEXT(bv)->SetCursor(bv, lpar, pos); } else { TEXT(bv)->SetCursor(bv, lpar, pos, true, boundary); - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; - TEXT(bv)->selection = false; + TEXT(bv)->selection.cursor = TEXT(bv)->cursor; + TEXT(bv)->selection.set(false); } } if (bv->screen()) @@ -1751,7 +1751,7 @@ bool InsetText::doClearArea() const void InsetText::selectAll(BufferView * bv) { TEXT(bv)->CursorTop(bv); - TEXT(bv)->sel_cursor = TEXT(bv)->cursor; + TEXT(bv)->selection.cursor = TEXT(bv)->cursor; TEXT(bv)->CursorBottom(bv); TEXT(bv)->SetSelection(bv); } diff --git a/src/kbmap.C b/src/kbmap.C index 35bb32ec2f..13ec0039ea 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -10,7 +10,7 @@ #include -#include +//#include #include #ifdef __GNUG__ diff --git a/src/kbsequence.C b/src/kbsequence.C index e7beccc908..5acea1f8af 100644 --- a/src/kbsequence.C +++ b/src/kbsequence.C @@ -9,7 +9,7 @@ * ====================================================== */ #include -#include +//#include #include #include "gettext.h" diff --git a/src/lyxfind.C b/src/lyxfind.C index 21d834eab1..0098c0ff04 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -86,9 +86,9 @@ bool LyXFind(BufferView * bv, bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR); LyXText * ltCur = bv->text; - if (ltCur->selection) - ltCur->cursor = forward ? ltCur->sel_end_cursor - : ltCur->sel_start_cursor; + if (ltCur->selection.set()) + ltCur->cursor = forward ? ltCur->selection.end + : ltCur->selection.start; if (forward ? SearchForward(bv, searchstr, casesens, matchwrd) diff --git a/src/lyxfont.C b/src/lyxfont.C index a4e4a1b27f..8aae34aac2 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -841,21 +841,21 @@ int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base, os << '\\' << LaTeXFamilyNames[f.family()] << '{'; - count += strlen(LaTeXFamilyNames[f.family()]) + 2; + count += std::strlen(LaTeXFamilyNames[f.family()]) + 2; env = true; //We have opened a new environment } if (f.series() != INHERIT_SERIES) { os << '\\' << LaTeXSeriesNames[f.series()] << '{'; - count += strlen(LaTeXSeriesNames[f.series()]) + 2; + count += std::strlen(LaTeXSeriesNames[f.series()]) + 2; env = true; //We have opened a new environment } if (f.shape() != INHERIT_SHAPE) { os << '\\' << LaTeXShapeNames[f.shape()] << '{'; - count += strlen(LaTeXShapeNames[f.shape()]) + 2; + count += std::strlen(LaTeXShapeNames[f.shape()]) + 2; env = true; //We have opened a new environment } if (f.color() != LColor::inherit && f.color() != LColor::ignore) { @@ -890,7 +890,7 @@ int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base, os << '\\' << LaTeXSizeNames[f.size()] << ' '; - count += strlen(LaTeXSizeNames[f.size()]) + 2; + count += std::strlen(LaTeXSizeNames[f.size()]) + 2; } return count; } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index bc045aff3b..cbb0f0ebb8 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -19,7 +19,7 @@ #include #include -#include +//#include #ifdef __GNUG__ #pragma implementation @@ -180,7 +180,7 @@ LyXText * LyXFunc::TEXT(bool flag = true) const inline void LyXFunc::moveCursorUpdate(bool flag, bool selecting) { - if (selecting || TEXT(flag)->mark_set) { + if (selecting || TEXT(flag)->selection.mark()) { TEXT(flag)->SetSelection(owner->view()); if (TEXT(flag)->bv_owner) owner->view()->toggleToggle(); @@ -210,7 +210,7 @@ void LyXFunc::handleKeyFunc(kb_action action) // copied verbatim from do_accent_char owner->view()->update(TEXT(false), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); - TEXT(false)->sel_cursor = TEXT(false)->cursor; + TEXT(false)->selection.cursor = TEXT(false)->cursor; } diff --git a/src/lyxserver.C b/src/lyxserver.C index 4ba5a38f62..82ec2164a8 100644 --- a/src/lyxserver.C +++ b/src/lyxserver.C @@ -37,7 +37,7 @@ #include -#include +//#include #include #include #include diff --git a/src/lyxtext.h b/src/lyxtext.h index 84d266ce20..413ec2a6e1 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -210,7 +210,8 @@ public: it should not be absolutely needed to move the cursor... */ mutable LyXCursor cursor; - + +#if 0 /* the selection cursor */ /// mutable bool selection; @@ -223,6 +224,31 @@ public: mutable LyXCursor sel_start_cursor; /// mutable LyXCursor sel_end_cursor; +#else + /** The structrue that keeps track of the selections set. */ + struct Selection { + bool set() const { + return set_; + } + void set(bool s) { + set_ = s; + } + bool mark() const { + return mark_; + } + void mark(bool m) { + mark_ = m; + } + LyXCursor cursor; + LyXCursor start; + LyXCursor end; + private: + bool set_; // former selection + bool mark_; // former mark_set + + }; + mutable Selection selection; +#endif /// needed for the toggling LyXCursor last_sel_cursor; /// diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index a5fb2aeae9..b99f004de1 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,18 @@ +2001-05-31 Lars Gullik Bjønnes + + * math_parser.C (yylex): use contains instead of strchr + (parse_align): remove last arg, change to take string const & as + first arg. + (mathed_parse): use string for ar2 and ar, adjust + + * math_decorationinset.C (Write): use compare instead of strcmp + + * formula.C (LocalDispatch): change arg2 to string, adjust for this + (LocalDispatch): add std:: + (LocalDispatch): use contains instead of strchr + + * array.C (move): add std:: + 2001-05-02 Jean-Marc Lasgouttes * matriz.C: add using directives when needed for C functions diff --git a/src/mathed/array.C b/src/mathed/array.C index e8f3377043..40ec0bcc8f 100644 --- a/src/mathed/array.C +++ b/src/mathed/array.C @@ -227,7 +227,7 @@ void MathedArray::move(int p, int shift) { if (p <= last_) { need_size(last_ + shift); - memmove(&bf_[p + shift], &bf_[p], last_ - p); + std::memmove(&bf_[p + shift], &bf_[p], last_ - p); last_ += shift; bf_[last_] = 0; } diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 48d0b55581..e594b487ce 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -962,13 +962,16 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action, { bv->lockedInsetStoreUndo(Undo::INSERT); char s[80]; - char arg2[80]; + //char arg2[80]; + // This is just so that too long args won't ooze out of s. - strncpy(arg2, arg.c_str(), 80); - arg2[79]= '\0'; + //strncpy(arg2, arg.c_str(), 80); + //arg2[79]= '\0'; + string arg2(arg, 0, 80); + int m; int n; - int const k = sscanf(arg2, "%d %d %s", &m, &n, s); + int const k = sscanf(arg2.c_str(), "%d %d %s", &m, &n, s); s[79] = '\0'; if (k < 1) { @@ -979,7 +982,7 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action, if (mathcursor) { MathMatrixInset * p = new MathMatrixInset(m, n); - if (k > 2 && int(strlen(s)) > m) + if (k > 2 && int(std::strlen(s)) > m) p->SetAlign(s[0], &s[1]); mathcursor->insertInset(p, LM_TC_ACTIVE_INSET); // Andre: @@ -993,7 +996,7 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action, bv->lockedInsetStoreUndo(Undo::INSERT); char lf[40]; char rg[40]; - char arg2[40]; + //char arg2[40]; int ilf = '('; int irg = '.'; latexkeys const * l; @@ -1001,9 +1004,11 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action, if (arg.empty()) break; - ::strncpy(arg2, arg.c_str(), 40); - arg2[39]= '\0'; - int const n = sscanf(arg2, "%s %s", lf, rg); + //::strncpy(arg2, arg.c_str(), 40); + //arg2[39]= '\0'; + string arg2(arg, 0, 40); + + int const n = sscanf(arg2.c_str(), "%s %s", lf, rg); lf[39] = '\0'; rg[39] = '\0'; @@ -1197,8 +1202,12 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action, if (greek_kb_flag < 2) greek_kb_flag = 0; - +#if 0 } else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) { +#else + } else if (contains("!,:;{}", c) + && (varcode == LM_TC_TEX||was_macro)) { +#endif mathcursor->Insert(c, LM_TC_TEX); if (c == '{') { mathcursor->Insert('}', LM_TC_TEX); @@ -1214,11 +1223,29 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action, mathcursor->MacroModeOpen(); mathcursor->clearLastCode(); mathcursor->Insert(c, LM_TC_MIN); - } else if (('0'<= c && c<= '9') || strchr(";:!|[]().,?", c)) { + } else if (('0'<= c && c<= '9') || +#if 0 + strchr(";:!|[]().,?", c) +#else + contains(";:!|[]().,?", c) +#endif + ) { mathcursor->Insert(c, LM_TC_CONST); - } else if (strchr("+/-*<>=", c)) { + } else if ( +#if 0 + strchr("+/-*<>=", c) +#else + contains("+/-*<>=", c) +#endif + ) { mathcursor->Insert(c, LM_TC_BOP); - } else if (strchr(latex_special_chars, c) && c!= '_') { + } else if ( +#if 0 + strchr(latex_special_chars, c) +#else + contains(latex_special_chars, c) +#endif + && c!= '_') { mathcursor->Insert(c, LM_TC_SPECIAL); } else if (c == '_' || c == '^') { char s[2]; diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index b4f1a0673a..b1a1c4352d 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -9,6 +9,8 @@ #include "mathed/support.h" #include "math_parser.h" #include "support/LOstream.h" +#include "support/lstrings.h" + using std::ostream; @@ -67,10 +69,10 @@ void MathDecorationInset::Write(ostream & os, bool fragile) { latexkeys const * l = lm_get_key_by_id(deco_, LM_TK_WIDE); if (fragile && - (strcmp(l->name, "overbrace") == 0 || - strcmp(l->name, "underbrace") == 0 || - strcmp(l->name, "overleftarrow") == 0 || - strcmp(l->name, "overrightarrow") == 0)) + (compare(l->name, "overbrace") == 0 || + compare(l->name, "underbrace") == 0 || + compare(l->name, "overleftarrow") == 0 || + compare(l->name, "overrightarrow") == 0)) os << "\\protect"; os << '\\' << l->name << '{'; MathParInset::Write(os, fragile); diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index da195e5fc4..c762e8e1aa 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -294,7 +294,13 @@ int yylex(void) yylval.i = LM_OT_PAR; return LM_TK_END; } - if (strchr(latex_special_chars, c)) { + if ( +#if 0 + strchr(latex_special_chars, c) +#else + contains(latex_special_chars, c) +#endif + ) { yylval.i = c; return LM_TK_SPECIAL; } @@ -345,13 +351,24 @@ int yylex(void) } -int parse_align(char * hor, char *) +#if 0 +int parse_align(char const * hor) { int nc = 0; for (char * c = hor; c && *c > ' '; ++c) ++nc; return nc; } - +#else +int parse_align(string const & hor) +{ + int nc = 0; + string::const_iterator cit = hor.begin(); + string::const_iterator end = hor.end(); + for (; cit != end; ++cit) + if (*cit > ' ') ++nc; + return nc; +} +#endif // Accent hacks only for 0.12. Stolen from Cursor. int accent = 0; @@ -837,16 +854,30 @@ void mathed_parse(MathedArray & array, MathParInset * & par, unsigned flags) case LM_TK_BEGIN: if (yylval.i == LM_OT_MATRIX) { //lyxerr << "###### Reading LM_OT_MATRIX \n"; +#if 0 char ar[120]; char ar2[8]; - ar[0] = ar2[0] = '\0'; + ar[0] = ar2[0] = '\0'; +#endif char rg = LexGetArg(0); +#if 1 + string ar2; +#endif if (rg == ']') { +#if 0 strcpy(ar2, yytext.data()); +#else + ar2 = yytext.data(); +#endif rg = LexGetArg('{'); } +#if 0 strcpy(ar, yytext.data()); - int const nc = parse_align(ar, ar2); + int const nc = parse_align(ar); +#else + string ar(yytext.data()); + int const nc = parse_align(ar); +#endif MathParInset * mm = new MathMatrixInset(nc, 0); mm->SetAlign(ar2[0], ar); diff --git a/src/mathed/matriz.C b/src/mathed/matriz.C index 3fe13a03f1..7394abede2 100644 --- a/src/mathed/matriz.C +++ b/src/mathed/matriz.C @@ -1,6 +1,6 @@ #include -#include +#include // memcpy #include "matriz.h" diff --git a/src/screen.C b/src/screen.C index 5ef3ad3aac..11d7412a64 100644 --- a/src/screen.C +++ b/src/screen.C @@ -446,22 +446,22 @@ void LyXScreen::ToggleSelection(LyXText * text, BufferView * bv, int y_offset, int x_offset) { // only if there is a selection - if (!text->selection) return; + if (!text->selection.set()) return; int const bottom = min( - max(static_cast(text->sel_end_cursor.y() - - text->sel_end_cursor.row()->baseline() - + text->sel_end_cursor.row()->height()), + max(static_cast(text->selection.end.y() + - text->selection.end.row()->baseline() + + text->selection.end.row()->height()), text->first), static_cast(text->first + owner.height())); int const top = min( - max(static_cast(text->sel_start_cursor.y() - - text->sel_start_cursor.row()->baseline()), + max(static_cast(text->selection.start.y() - + text->selection.start.row()->baseline()), text->first), static_cast(text->first + owner.height())); if (kill_selection) - text->selection = 0; + text->selection.set(false); DrawFromTo(text, bv, top - text->first, bottom - text->first, y_offset, x_offset); expose(0, top - text->first, diff --git a/src/spellchecker.C b/src/spellchecker.C index 8348455a82..5a019dbb59 100644 --- a/src/spellchecker.C +++ b/src/spellchecker.C @@ -19,7 +19,7 @@ #include #include #include -#include +//#include #include #include #include diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 10a495ef31..021dcb535a 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,17 @@ +2001-05-31 Lars Gullik Bjønnes + + * syscontr.C: add std:: + + * syscall.C: add std:: + + * lstrings.h (compare): add std:: + + * lstrings.C (prefixIs): add std:: + (suffixIs): ditto + (subst): ditto + + * LSubstring.C (LSubstring): add std:: + 2001-05-30 Lars Gullik Bjønnes * lyxsum.C (sum): use istreambuf_iterator when available. diff --git a/src/support/LSubstring.C b/src/support/LSubstring.C index 42ef649dd9..3abf851057 100644 --- a/src/support/LSubstring.C +++ b/src/support/LSubstring.C @@ -35,7 +35,7 @@ LSubstring::LSubstring(string & s, string const & s2) LSubstring::LSubstring(string & s, string::value_type const * p) : ps(&s) { - n = strlen(p); + n = std::strlen(p); pos = s.find(p); } diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 9a5a061865..88327571fb 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -232,7 +232,7 @@ bool prefixIs(string const & a, char const * pre) { lyx::Assert(pre); - size_t const l = strlen(pre); + size_t const l = std::strlen(pre); string::size_type const alen = a.length(); if (l > alen || a.empty()) @@ -280,7 +280,7 @@ bool suffixIs(string const & a, char const * suf) { lyx::Assert(suf); - size_t const suflen = strlen(suf); + size_t const suflen = std::strlen(suf); string::size_type const alen = a.length(); if (suflen > alen) @@ -478,7 +478,7 @@ string const subst(string const & a, string lstr(a); string::size_type i = 0; - string::size_type olen = strlen(oldstr); + string::size_type olen = std::strlen(oldstr); while((i = lstr.find(oldstr, i)) != string::npos) { lstr.replace(i, olen, newstr); i += newstr.length(); // We need to be sure that we dont diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 1878476b2b..73971a78b9 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -16,7 +16,7 @@ #pragma interface #endif -#include +//#include #include #include "Lsstream.h" @@ -34,14 +34,14 @@ int compare_no_case(string const & s, string const & s2, unsigned int len); inline int compare(char const * a, char const * b) { - return strcmp(a, b); + return std::strcmp(a, b); } /// inline int compare(char const * a, char const * b, unsigned int len) { - return strncmp(a, b, len); + return std::strncmp(a, b, len); } /// diff --git a/src/support/syscall.C b/src/support/syscall.C index 6735aad5c2..f308f770f4 100644 --- a/src/support/syscall.C +++ b/src/support/syscall.C @@ -110,7 +110,8 @@ void Systemcalls::waitForChild() { while (wait) { pid_t waitrpid = waitpid(pid, &status, WUNTRACED); if (waitrpid == -1) { - lyxerr << "LyX: Error waiting for child:" << strerror(errno) << endl; + lyxerr << "LyX: Error waiting for child:" + << std::strerror(errno) << endl; wait = false; } else if (WIFEXITED(status)) { // Child exited normally. Update return value. @@ -176,13 +177,15 @@ pid_t Systemcalls::fork() #ifndef __EMX__ execvp(syscmd, argv); // If something goes wrong, we end up here: - lyxerr << "LyX: execvp failed: " << strerror(errno) << endl; + lyxerr << "LyX: execvp failed: " + << std::strerror(errno) << endl; } else if (cpid < 0) { // error #else pid_t cpid = spawnvp(P_SESSION|P_DEFAULT|P_MINIMIZE|P_BACKGROUND, syscmd, argv); if (cpid < 0) { // error #endif - lyxerr << "LyX: Could not fork: " << strerror(errno) << endl; + lyxerr << "LyX: Could not fork: " + << std::strerror(errno) << endl; } else { // parent return cpid; } diff --git a/src/support/syscontr.C b/src/support/syscontr.C index 87a83c9638..56d46b810e 100644 --- a/src/support/syscontr.C +++ b/src/support/syscontr.C @@ -76,7 +76,7 @@ SystemcallsSingletoncontroller::timer() { int waitrpid = waitpid(pid, &stat_loc, WNOHANG); if (waitrpid == -1) { lyxerr << "LyX: Error waiting for child:" - << strerror(errno) << endl; + << std::strerror(errno) << endl; } else if (WIFEXITED(stat_loc) || WIFSIGNALED(stat_loc)) { if (WIFEXITED(stat_loc)) { // Ok, the return value goes into retval. diff --git a/src/tabular-old.C b/src/tabular-old.C index feb698e219..b769acc229 100644 --- a/src/tabular-old.C +++ b/src/tabular-old.C @@ -25,11 +25,11 @@ namespace { bool getTokenValue(string const & str, const char * token, string & ret) { - size_t token_length = strlen(token); + size_t token_length = std::strlen(token); string::size_type pos = str.find(token); - if (pos == string::npos || pos+token_length+1 >= str.length() - || str[pos+token_length] != '=') + if (pos == string::npos || pos + token_length + 1 >= str.length() + || str[pos + token_length] != '=') return false; ret.erase(); pos += token_length + 1; @@ -48,12 +48,12 @@ bool getTokenValue(string const & str, const char * token, string & ret) bool getTokenValue(string const & str, const char * token, int & num) { string::size_type pos = str.find(token); - char ch = str[pos + strlen(token)]; + char ch = str[pos + std::strlen(token)]; if ((pos == string::npos) || (ch != '=')) return false; string ret; - pos += strlen(token) + 1; + pos += std::strlen(token) + 1; ch = str[pos]; if ((ch != '"') && (ch != '\'')) { // only read till next space if (!isdigit(ch)) @@ -101,12 +101,12 @@ bool getTokenValue(string const & str, const char * token, bool getTokenValue(string const & str, const char * token, bool & flag) { string::size_type pos = str.find(token); - char ch = str[pos + strlen(token)]; + char ch = str[pos + std::strlen(token)]; if ((pos == string::npos) || (ch != '=')) return false; string ret; - pos += strlen(token) + 1; + pos += std::strlen(token) + 1; ch = str[pos]; if ((ch != '"') && (ch != '\'')) { // only read till next space if (!isdigit(ch)) diff --git a/src/tabular.C b/src/tabular.C index 5c02d30482..e7f3822031 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -1149,11 +1149,11 @@ bool string2type(string const str, bool & num) bool getTokenValue(string const & str, const char * token, string & ret) { - size_t token_length = strlen(token); + size_t token_length = std::strlen(token); string::size_type pos = str.find(token); - if (pos == string::npos || pos+token_length+1 >= str.length() - || str[pos+token_length] != '=') + if (pos == string::npos || pos + token_length + 1 >= str.length() + || str[pos + token_length] != '=') return false; ret.erase(); pos += token_length + 1; diff --git a/src/text.C b/src/text.C index 2add763aea..7eaca2ece6 100644 --- a/src/text.C +++ b/src/text.C @@ -2164,8 +2164,12 @@ void LyXText::SelectWord(BufferView * bview) CursorLeftOneWord(bview); // set the sel cursor +#if 0 sel_cursor = cursor; - +#else + selection.cursor = cursor; +#endif + while (cursor.pos() < cursor.par()->size() && !cursor.par()->IsSeparator(cursor.pos()) && !cursor.par()->IsKomma(cursor.pos()) ) @@ -2183,7 +2187,11 @@ void LyXText::SelectWord(BufferView * bview) bool LyXText::SelectWordWhenUnderCursor(BufferView * bview) { +#if 0 if (!selection && +#else + if (!selection.set() && +#endif cursor.pos() > 0 && cursor.pos() < cursor.par()->size() && !cursor.par()->IsSeparator(cursor.pos()) && !cursor.par()->IsKomma(cursor.pos()) @@ -2233,8 +2241,12 @@ string const LyXText::SelectNextWord(BufferView * bview, } // Start the selection from here +#if 0 sel_cursor = cursor; - +#else + selection.cursor = cursor; +#endif + std::ostringstream latex; // and find the end of the word @@ -2250,6 +2262,7 @@ string const LyXText::SelectNextWord(BufferView * bview, // Finally, we copy the word to a string and return it string str; +#if 0 if (sel_cursor.pos() < cursor.pos()) { LyXParagraph::size_type i; for (i = sel_cursor.pos(); i < cursor.pos(); ++i) { @@ -2257,6 +2270,15 @@ string const LyXText::SelectNextWord(BufferView * bview, str += cursor.par()->GetChar(i); } } +#else + if (selection.cursor.pos() < cursor.pos()) { + LyXParagraph::size_type i; + for (i = selection.cursor.pos(); i < cursor.pos(); ++i) { + if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET) + str += cursor.par()->GetChar(i); + } + } +#endif return str; } @@ -2264,12 +2286,19 @@ string const LyXText::SelectNextWord(BufferView * bview, // This one is also only for the spellchecker void LyXText::SelectSelectedWord(BufferView * bview) { +#if 0 // move cursor to the beginning SetCursor(bview, sel_cursor.par(), sel_cursor.pos()); // set the sel cursor sel_cursor = cursor; - +#else + // move cursor to the beginning + SetCursor(bview, selection.cursor.par(), selection.cursor.pos()); + + // set the sel cursor + selection.cursor = cursor; +#endif std::ostringstream latex; // now find the end of the word @@ -2297,10 +2326,18 @@ void LyXText::DeleteWordForward(BufferView * bview) else { LyXCursor tmpcursor = cursor; tmpcursor.row(0); // ?? - selection = true; // to avoid deletion +#if 0 + selection = true; // to avoid deletion +#else + selection.set(true); // to avoid deletion +#endif CursorRightOneWord(bview); SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos()); +#if 0 sel_cursor = cursor; +#else + selection.cursor = cursor; +#endif cursor = tmpcursor; SetSelection(bview); @@ -2318,10 +2355,18 @@ void LyXText::DeleteWordBackward(BufferView * bview) else { LyXCursor tmpcursor = cursor; tmpcursor.row(0); // ?? - selection = true; // to avoid deletion +#if 0 + selection = true; // to avoid deletion +#else + selection.set(true); // to avoid deletion +#endif CursorLeftOneWord(bview); SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos()); +#if 0 sel_cursor = cursor; +#else + selection.cursor = cursor; +#endif cursor = tmpcursor; SetSelection(bview); CutSelection(bview); @@ -2340,14 +2385,26 @@ void LyXText::DeleteLineForward(BufferView * bview) // We can't store the row over a regular SetCursor // so we set it to 0 and reset it afterwards. tmpcursor.row(0); // ?? - selection = true; // to avoid deletion +#if 0 + selection = true; // to avoid deletion +#else + selection.set(true); // to avoid deletion +#endif CursorEnd(bview); SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos()); +#if 0 sel_cursor = cursor; +#else + selection.cursor = cursor; +#endif cursor = tmpcursor; SetSelection(bview); // What is this test for ??? (JMarc) +#if 0 if (!selection) { +#else + if (!selection.set()) { +#endif DeleteWordForward(bview); } else { CutSelection(bview); @@ -2868,68 +2925,68 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, pain.fillRectangle(w, y_offset, ww - w, row_ptr->height()); } } - - if (selection) { + + if (selection.set()) { int const w = (inset_owner ? inset_owner->width(bview, font) : ww); // selection code if (bidi_same_direction) { - if (sel_start_cursor.row() == row_ptr && - sel_end_cursor.row() == row_ptr) { - if (sel_start_cursor.x() < sel_end_cursor.x()) - pain.fillRectangle(x_offset + sel_start_cursor.x(), + if (selection.start.row() == row_ptr && + selection.end.row() == row_ptr) { + if (selection.start.x() < selection.end.x()) + pain.fillRectangle(x_offset + selection.start.x(), y_offset, - sel_end_cursor.x() - sel_start_cursor.x(), + selection.end.x() - selection.start.x(), row_ptr->height(), LColor::selection); else - pain.fillRectangle(x_offset + sel_end_cursor.x(), + pain.fillRectangle(x_offset + selection.end.x(), y_offset, - sel_start_cursor.x() - sel_end_cursor.x(), + selection.start.x() - selection.end.x(), row_ptr->height(), LColor::selection); - } else if (sel_start_cursor.row() == row_ptr) { + } else if (selection.start.row() == row_ptr) { if (is_rtl) pain.fillRectangle(x_offset, y_offset, - sel_start_cursor.x(), + selection.start.x(), row_ptr->height(), LColor::selection); else - pain.fillRectangle(x_offset + sel_start_cursor.x(), + pain.fillRectangle(x_offset + selection.start.x(), y_offset, - w - sel_start_cursor.x(), + w - selection.start.x(), row_ptr->height(), LColor::selection); - } else if (sel_end_cursor.row() == row_ptr) { + } else if (selection.end.row() == row_ptr) { if (is_rtl) - pain.fillRectangle(x_offset + sel_end_cursor.x(), + pain.fillRectangle(x_offset + selection.end.x(), y_offset, - w - sel_end_cursor.x(), + w - selection.end.x(), row_ptr->height(), LColor::selection); else pain.fillRectangle(x_offset, y_offset, - sel_end_cursor.x(), + selection.end.x(), row_ptr->height(), LColor::selection); - } else if (y > sel_start_cursor.y() - && y < sel_end_cursor.y()) { + } else if (y > selection.start.y() + && y < selection.end.y()) { pain.fillRectangle(x_offset, y_offset, w, row_ptr->height(), LColor::selection); } - } else if (sel_start_cursor.row() != row_ptr && - sel_end_cursor.row() != row_ptr && - y > sel_start_cursor.y() - && y < sel_end_cursor.y()) { + } else if (selection.start.row() != row_ptr && + selection.end.row() != row_ptr && + y > selection.start.y() + && y < selection.end.y()) { pain.fillRectangle(x_offset, y_offset, w, row_ptr->height(), LColor::selection); - } else if (sel_start_cursor.row() == row_ptr || - sel_end_cursor.row() == row_ptr) { + } else if (selection.start.row() == row_ptr || + selection.end.row() == row_ptr) { float tmpx = x; - if ((sel_start_cursor.row() != row_ptr && !is_rtl) || - (sel_end_cursor.row() != row_ptr && is_rtl)) + if ((selection.start.row() != row_ptr && !is_rtl) || + (selection.end.row() != row_ptr && is_rtl)) pain.fillRectangle(x_offset, y_offset, int(tmpx), row_ptr->height(), @@ -2963,10 +3020,10 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, } else tmpx += SingleWidth(bview, row_ptr->par(), pos); - if ((sel_start_cursor.row() != row_ptr || - sel_start_cursor.pos() <= pos) && - (sel_end_cursor.row() != row_ptr || - pos < sel_end_cursor.pos()) ) + if ((selection.start.row() != row_ptr || + selection.start.pos() <= pos) && + (selection.end.row() != row_ptr || + pos < selection.end.pos()) ) // Here we do not use x_offset as x_offset was // added to x. pain.fillRectangle(int(old_tmpx), @@ -2976,8 +3033,8 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset, LColor::selection); } - if ((sel_start_cursor.row() != row_ptr && is_rtl) || - (sel_end_cursor.row() != row_ptr && !is_rtl) ) + if ((selection.start.row() != row_ptr && is_rtl) || + (selection.end.row() != row_ptr && !is_rtl) ) pain.fillRectangle(x_offset + int(tmpx), y_offset, int(ww - tmpx), diff --git a/src/text2.C b/src/text2.C index 489323069a..3fe279c4c1 100644 --- a/src/text2.C +++ b/src/text2.C @@ -77,11 +77,19 @@ void LyXText::init() width = 0; first = 0; status = LyXText::UNCHANGED; + // set cursor at the very top position +#if 0 selection = true; /* these setting is necessary because of the delete-empty- paragraph mechanism in SetCursor */ +#else + selection.set(true); /* these setting is necessary + because of the delete-empty- + paragraph mechanism in + SetCursor */ +#endif if (bv_owner) { LyXParagraph * par = OwnerParagraph(); current_font = GetFont(bv_owner->buffer(), par, 0); @@ -93,10 +101,16 @@ void LyXText::init() } else current_font = LyXFont(LyXFont::ALL_SANE); +#if 0 sel_cursor = cursor; selection = false; mark_set = false; - +#else + selection.cursor = cursor; + selection.set(false); + selection.mark(false); +#endif + // no rebreak necessary need_break_row = 0; @@ -136,7 +150,11 @@ void LyXText::init(BufferView * bview) par = par->next(); } SetCursorIntern(bview, firstrow->par(), 0); +#if 0 sel_cursor = cursor; +#else + selection.cursor = cursor; +#endif #if 0 printf("TP = %x\n",inset_owner->owner()); // Dump all rowinformation: @@ -526,6 +544,7 @@ LyXParagraph * LyXText::SetLayout(BufferView * bview, // set layout over selection and make a total rebreak of those paragraphs void LyXText::SetLayout(BufferView * bview, LyXTextClass::size_type layout) { +#if 0 LyXCursor tmpcursor = cursor; /* store the current cursor */ // if there is no selection just set the layout @@ -550,9 +569,35 @@ void LyXText::SetLayout(BufferView * bview, LyXTextClass::size_type layout) ClearSelection(bview); SetSelection(bview); SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true); +#else + 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; + } + LyXParagraph * endpar = SetLayout(bview, cursor, selection.start, + selection.end, layout); + RedoParagraphs(bview, selection.start, endpar); + + // we have to reset the selection, because the + // geometry could have changed + SetCursor(bview, selection.start.par(), + selection.start.pos(), false); + selection.cursor = cursor; + SetCursor(bview, selection.end.par(), selection.end.pos(), + false); + UpdateCounters(bview, cursor.row()); + ClearSelection(bview); + SetSelection(bview); + SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true); +#endif } +#if 0 // increment depth over selection and // make a total rebreak of those paragraphs void LyXText::IncDepth(BufferView * bview) @@ -635,6 +680,89 @@ void LyXText::IncDepth(BufferView * bview) SetSelection(bview); SetCursor(bview, tmpcursor.par(), tmpcursor.pos()); } +#else +// increment depth over selection and +// make a total rebreak of those paragraphs +void LyXText::IncDepth(BufferView * bview) +{ + // If there is no selection, just use the current paragraph + if (!selection.set()) { + selection.start = cursor; // dummy selection + selection.end = cursor; + } + + // We end at the next paragraph with depth 0 + LyXParagraph * endpar = selection.end.par()->next(); + + LyXParagraph * undoendpar = endpar; + + if (endpar && endpar->GetDepth()) { + while (endpar && endpar->GetDepth()) { + endpar = endpar->next(); + undoendpar = endpar; + } + } + else if (endpar) { + endpar = endpar->next(); // because of parindents etc. + } + + SetUndo(bview->buffer(), Undo::EDIT, + selection.start.par()->previous(), + undoendpar); + + LyXCursor tmpcursor = cursor; // store the current cursor + + // ok we have a selection. This is always between sel_start_cursor + // and sel_end cursor + cursor = selection.start; + + bool anything_changed = false; + + while (true) { + // NOTE: you can't change the depth of a bibliography entry + if ( + textclasslist.Style(bview->buffer()->params.textclass, + cursor.par()->GetLayout() + ).labeltype != LABEL_BIBLIO) { + LyXParagraph * prev = cursor.par()->previous(); + + if (prev + && (prev->GetDepth() - cursor.par()->GetDepth() > 0 + || (prev->GetDepth() == cursor.par()->GetDepth() + && textclasslist.Style(bview->buffer()->params.textclass, + prev->GetLayout()).isEnvironment()))) { + cursor.par()->params.depth(cursor.par()->params.depth() + 1); + anything_changed = true; + } + } + if (cursor.par() == selection.end.par()) + break; + cursor.par(cursor.par()->next()); + } + + // if nothing changed set all depth to 0 + if (!anything_changed) { + cursor = selection.start; + while (cursor.par() != selection.end.par()) { + cursor.par()->params.depth(0); + cursor.par(cursor.par()->next()); + } + cursor.par()->params.depth(0); + } + + RedoParagraphs(bview, selection.start, endpar); + + // we have to reset the selection, because the + // geometry could have changed + SetCursor(bview, selection.start.par(), selection.start.pos()); + selection.cursor = cursor; + SetCursor(bview, selection.end.par(), selection.end.pos()); + UpdateCounters(bview, cursor.row()); + ClearSelection(bview); + SetSelection(bview); + SetCursor(bview, tmpcursor.par(), tmpcursor.pos()); +} +#endif // decrement depth over selection and @@ -643,11 +771,11 @@ void LyXText::DecDepth(BufferView * bview) { // if there is no selection just set the layout // of the current paragraph - if (!selection) { - sel_start_cursor = cursor; // dummy selection - sel_end_cursor = cursor; + if (!selection.set()) { + selection.start = cursor; // dummy selection + selection.end = cursor; } - LyXParagraph * endpar = sel_end_cursor.par()->next(); + LyXParagraph * endpar = selection.end.par()->next(); LyXParagraph * undoendpar = endpar; if (endpar && endpar->GetDepth()) { @@ -655,37 +783,36 @@ void LyXText::DecDepth(BufferView * bview) endpar = endpar->next(); undoendpar = endpar; } - } - else if (endpar) { + } else if (endpar) { endpar = endpar->next(); // because of parindents etc. } SetUndo(bview->buffer(), Undo::EDIT, - sel_start_cursor.par()->previous(), + selection.start.par()->previous(), undoendpar); LyXCursor tmpcursor = cursor; // store the current cursor // ok we have a selection. This is always between sel_start_cursor // and sel_end cursor - cursor = sel_start_cursor; + cursor = selection.start; while (true) { if (cursor.par()->params.depth()) cursor.par()->params.depth(cursor.par()->params.depth() - 1); - if (cursor.par() == sel_end_cursor.par()) + if (cursor.par() == selection.end.par()) break; cursor.par(cursor.par()->next()); } - RedoParagraphs(bview, sel_start_cursor, endpar); + RedoParagraphs(bview, selection.start, endpar); // we have to reset the selection, because the // geometry could have changed - SetCursor(bview, sel_start_cursor.par(), - sel_start_cursor.pos()); - sel_cursor = cursor; - SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos()); + SetCursor(bview, selection.start.par(), + selection.start.pos()); + selection.cursor = cursor; + SetCursor(bview, selection.end.par(), selection.end.pos()); UpdateCounters(bview, cursor.row()); ClearSelection(bview); SetSelection(bview); @@ -697,7 +824,7 @@ void LyXText::DecDepth(BufferView * bview) void LyXText::SetFont(BufferView * bview, LyXFont const & font, bool toggleall) { // if there is no selection just set the current_font - if (!selection) { + if (!selection.set()) { // Determine basis font LyXFont layoutfont; if (cursor.pos() < BeginningOfMainBody(bview->buffer(), @@ -724,12 +851,12 @@ void LyXText::SetFont(BufferView * bview, LyXFont const & font, bool toggleall) // and sel_end cursor SetUndo(bview->buffer(), Undo::EDIT, - sel_start_cursor.par()->previous(), - sel_end_cursor.par()->next()); + selection.start.par()->previous(), + selection.end.par()->next()); FreezeUndo(); - cursor = sel_start_cursor; - while (cursor.par() != sel_end_cursor.par() || - (cursor.pos() < sel_end_cursor.pos())) { + cursor = selection.start; + while (cursor.par() != selection.end.par() || + (cursor.pos() < selection.end.pos())) { if (cursor.pos() < cursor.par()->size()) { // an open footnote should behave // like a closed one @@ -742,13 +869,13 @@ void LyXText::SetFont(BufferView * bview, LyXFont const & font, bool toggleall) } UnFreezeUndo(); - RedoParagraphs(bview, sel_start_cursor, sel_end_cursor.par()->next()); + RedoParagraphs(bview, selection.start, selection.end.par()->next()); // we have to reset the selection, because the // geometry could have changed - SetCursor(bview, sel_start_cursor.par(), sel_start_cursor.pos()); - sel_cursor = cursor; - SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos()); + SetCursor(bview, selection.start.par(), selection.start.pos()); + selection.cursor = cursor; + SetCursor(bview, selection.end.par(), selection.end.pos()); ClearSelection(bview); SetSelection(bview); SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true, @@ -924,15 +1051,15 @@ bool LyXText::FullRebreak(BufferView * bview) // need the selection cursor: void LyXText::SetSelection(BufferView * bview) { - const bool lsel = selection; + bool const lsel = selection.set(); - if (!selection) { - last_sel_cursor = sel_cursor; - sel_start_cursor = sel_cursor; - sel_end_cursor = sel_cursor; + if (!selection.set()) { + last_sel_cursor = selection.cursor; + selection.start = selection.cursor; + selection.end = selection.cursor; } - selection = true; + selection.set(true); // first the toggling area if (cursor.y() < last_sel_cursor.y() @@ -949,65 +1076,65 @@ void LyXText::SetSelection(BufferView * bview) // and now the whole selection - if (sel_cursor.par() == cursor.par()) - if (sel_cursor.pos() < cursor.pos()) { - sel_end_cursor = cursor; - sel_start_cursor = sel_cursor; + if (selection.cursor.par() == cursor.par()) + if (selection.cursor.pos() < cursor.pos()) { + selection.end = cursor; + selection.start = selection.cursor; } else { - sel_end_cursor = sel_cursor; - sel_start_cursor = cursor; + selection.end = selection.cursor; + selection.start = cursor; } - else if (sel_cursor.y() < cursor.y() || - (sel_cursor.y() == cursor.y() && sel_cursor.x() < cursor.x())) { - sel_end_cursor = cursor; - sel_start_cursor = sel_cursor; + else if (selection.cursor.y() < cursor.y() || + (selection.cursor.y() == cursor.y() && selection.cursor.x() < cursor.x())) { + selection.end = cursor; + selection.start = selection.cursor; } else { - sel_end_cursor = sel_cursor; - sel_start_cursor = cursor; + selection.end = selection.cursor; + selection.start = cursor; } // a selection with no contents is not a selection - if (sel_start_cursor.par() == sel_end_cursor.par() && - sel_start_cursor.pos() == sel_end_cursor.pos()) - selection = false; + if (selection.start.par() == selection.end.par() && + selection.start.pos() == selection.end.pos()) + selection.set(false); - if (inset_owner && (selection || lsel)) + if (inset_owner && (selection.set() || lsel)) inset_owner->SetUpdateStatus(bview, InsetText::SELECTION); } string const LyXText::selectionAsString(Buffer const * buffer) const { - if (!selection) return string(); + if (!selection.set()) return string(); string result; // Special handling if the whole selection is within one paragraph - if (sel_start_cursor.par() == sel_end_cursor.par()) { - result += sel_start_cursor.par()->String(buffer, - sel_start_cursor.pos(), - sel_end_cursor.pos()); + if (selection.start.par() == selection.end.par()) { + result += selection.start.par()->String(buffer, + selection.start.pos(), + selection.end.pos()); return result; } // The selection spans more than one paragraph // First paragraph in selection - result += sel_start_cursor.par()->String(buffer, - sel_start_cursor.pos(), - sel_start_cursor.par()->size()) + result += selection.start.par()->String(buffer, + selection.start.pos(), + selection.start.par()->size()) + "\n\n"; // The paragraphs in between (if any) - LyXCursor tmpcur(sel_start_cursor); + LyXCursor tmpcur(selection.start); tmpcur.par(tmpcur.par()->next()); - while (tmpcur.par() != sel_end_cursor.par()) { + while (tmpcur.par() != selection.end.par()) { result += tmpcur.par()->String(buffer, 0, tmpcur.par()->size()) + "\n\n"; tmpcur.par(tmpcur.par()->next()); // Or NextAfterFootnote?? } // Last paragraph in selection - result += sel_end_cursor.par()->String(buffer, 0, sel_end_cursor.pos()); + result += selection.end.par()->String(buffer, 0, selection.end.pos()); return result; } @@ -1015,9 +1142,9 @@ string const LyXText::selectionAsString(Buffer const * buffer) const void LyXText::ClearSelection(BufferView * /*bview*/) const { - selection = false; - mark_set = false; - sel_end_cursor = sel_start_cursor = cursor; + selection.set(false); + selection.mark(false); + selection.end = selection.start = cursor; } @@ -1085,7 +1212,7 @@ void LyXText::ToggleFree(BufferView * bview, ClearSelection(bview); cursor = resetCursor; SetCursor(bview, cursor.par(), cursor.pos()); - sel_cursor = cursor; + selection.cursor = cursor; } if (inset_owner) inset_owner->SetUpdateStatus(bview, InsetText::CURSOR_PAR); @@ -1120,13 +1247,13 @@ void LyXText::SetParagraph(BufferView * bview, bool noindent) { LyXCursor tmpcursor = cursor; - if (!selection) { - sel_start_cursor = cursor; - sel_end_cursor = cursor; + if (!selection.set()) { + selection.start = cursor; + selection.end = cursor; } // make sure that the depth behind the selection are restored, too - LyXParagraph * endpar = sel_end_cursor.par()->next(); + LyXParagraph * endpar = selection.end.par()->next(); LyXParagraph * undoendpar = endpar; if (endpar && endpar->GetDepth()) { @@ -1140,12 +1267,12 @@ void LyXText::SetParagraph(BufferView * bview, } SetUndo(bview->buffer(), Undo::EDIT, - sel_start_cursor.par()->previous(), + selection.start.par()->previous(), undoendpar); - LyXParagraph * tmppar = sel_end_cursor.par(); - while (tmppar != sel_start_cursor.par()->previous()) { + LyXParagraph * tmppar = selection.end.par(); + while (tmppar != selection.start.par()->previous()) { SetCursor(bview, tmppar, 0); status = LyXText::NEED_MORE_REFRESH; refresh_row = cursor.row(); @@ -1176,12 +1303,12 @@ void LyXText::SetParagraph(BufferView * bview, tmppar = cursor.par()->previous(); } - RedoParagraphs(bview, sel_start_cursor, endpar); + RedoParagraphs(bview, selection.start, endpar); ClearSelection(bview); - SetCursor(bview, sel_start_cursor.par(), sel_start_cursor.pos()); - sel_cursor = cursor; - SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos()); + SetCursor(bview, selection.start.par(), selection.start.pos()); + selection.cursor = cursor; + SetCursor(bview, selection.end.par(), selection.end.pos()); SetSelection(bview); SetCursor(bview, tmpcursor.par(), tmpcursor.pos()); if (inset_owner) @@ -1655,14 +1782,14 @@ void LyXText::CutSelection(BufferView * bview, bool doclear) bview->stuffClipboard(selectionAsString(bview->buffer())); // This doesn't make sense, if there is no selection - if (!selection) + if (!selection.set()) return; - // OK, we have a selection. This is always between sel_start_cursor - // and sel_end_cursor + // OK, we have a selection. This is always between selection.start + // and selection.end // make sure that the depth behind the selection are restored, too - LyXParagraph * endpar = sel_end_cursor.par()->next(); + LyXParagraph * endpar = selection.end.par()->next(); LyXParagraph * undoendpar = endpar; if (endpar && endpar->GetDepth()) { @@ -1675,49 +1802,49 @@ void LyXText::CutSelection(BufferView * bview, bool doclear) } SetUndo(bview->buffer(), Undo::DELETE, - sel_start_cursor.par()->previous(), + selection.start.par()->previous(), undoendpar); CutAndPaste cap; // there are two cases: cut only within one paragraph or // more than one paragraph - if (sel_start_cursor.par() == sel_end_cursor.par()) { + if (selection.start.par() == selection.end.par()) { // only within one paragraph - endpar = sel_end_cursor.par(); - int pos = sel_end_cursor.pos(); - cap.cutSelection(sel_start_cursor.par(), &endpar, - sel_start_cursor.pos(), pos, + endpar = selection.end.par(); + int pos = selection.end.pos(); + cap.cutSelection(selection.start.par(), &endpar, + selection.start.pos(), pos, bview->buffer()->params.textclass, doclear); - sel_end_cursor.pos(pos); + selection.end.pos(pos); } else { - endpar = sel_end_cursor.par(); - int pos = sel_end_cursor.pos(); - cap.cutSelection(sel_start_cursor.par(), &endpar, - sel_start_cursor.pos(), pos, + endpar = selection.end.par(); + int pos = selection.end.pos(); + cap.cutSelection(selection.start.par(), &endpar, + selection.start.pos(), pos, bview->buffer()->params.textclass, doclear); cursor.par(endpar); - sel_end_cursor.par(endpar); - sel_end_cursor.pos(pos); - cursor.pos(sel_end_cursor.pos()); + selection.end.par(endpar); + selection.end.pos(pos); + cursor.pos(selection.end.pos()); } endpar = endpar->next(); // sometimes necessary if (doclear) - sel_start_cursor.par()->StripLeadingSpaces(bview->buffer()->params.textclass); + selection.start.par()->StripLeadingSpaces(bview->buffer()->params.textclass); - RedoParagraphs(bview, sel_start_cursor, endpar); + RedoParagraphs(bview, selection.start, endpar); // cutSelection can invalidate the cursor so we need to set // it anew. (Lgb) - cursor = sel_start_cursor; + cursor = selection.start; // need a valid cursor. (Lgb) ClearSelection(bview); SetCursor(bview, cursor.par(), cursor.pos()); - sel_cursor = cursor; + selection.cursor = cursor; UpdateCounters(bview, cursor.row()); } @@ -1735,23 +1862,23 @@ void LyXText::CopySelection(BufferView * bview) bview->stuffClipboard(selectionAsString(bview->buffer())); // this doesnt make sense, if there is no selection - if (!selection) + if (!selection.set()) return; - // ok we have a selection. This is always between sel_start_cursor + // ok we have a selection. This is always between selection.start // and sel_end cursor // copy behind a space if there is one - while (sel_start_cursor.par()->size() > sel_start_cursor.pos() - && sel_start_cursor.par()->IsLineSeparator(sel_start_cursor.pos()) - && (sel_start_cursor.par() != sel_end_cursor.par() - || sel_start_cursor.pos() < sel_end_cursor.pos())) - sel_start_cursor.pos(sel_start_cursor.pos() + 1); + while (selection.start.par()->size() > selection.start.pos() + && selection.start.par()->IsLineSeparator(selection.start.pos()) + && (selection.start.par() != selection.end.par() + || selection.start.pos() < selection.end.pos())) + selection.start.pos(selection.start.pos() + 1); CutAndPaste cap; - cap.copySelection(sel_start_cursor.par(), sel_end_cursor.par(), - sel_start_cursor.pos(), sel_end_cursor.pos(), + cap.copySelection(selection.start.par(), selection.end.par(), + selection.start.pos(), selection.end.pos(), bview->buffer()->params.textclass); } @@ -1780,7 +1907,7 @@ void LyXText::PasteSelection(BufferView * bview) SetCursor(bview, cursor.par(), cursor.pos()); ClearSelection(bview); - sel_cursor = cursor; + selection.cursor = cursor; SetCursor(bview, actpar, pos); SetSelection(bview); UpdateCounters(bview, cursor.row()); @@ -1797,7 +1924,7 @@ LyXParagraph * LyXText::FirstParagraph() const // sets the selection over the number of characters of string, no check!! void LyXText::SetSelectionOverString(BufferView * bview, string const & str) { - sel_cursor = cursor; + selection.cursor = cursor; for (int i = 0; str[i]; ++i) CursorRight(bview); SetSelection(bview); @@ -1811,20 +1938,20 @@ void LyXText::ReplaceSelectionWithString(BufferView * bview, SetCursorParUndo(bview->buffer()); FreezeUndo(); - if (!selection) { // create a dummy selection - sel_end_cursor = cursor; - sel_start_cursor = cursor; + if (!selection.set()) { // create a dummy selection + selection.end = cursor; + selection.start = cursor; } // Get font setting before we cut - LyXParagraph::size_type pos = sel_end_cursor.pos(); - LyXFont const font = sel_start_cursor.par() + LyXParagraph::size_type pos = selection.end.pos(); + LyXFont const font = selection.start.par() ->GetFontSettings(bview->buffer()->params, - sel_start_cursor.pos()); + selection.start.pos()); // Insert the new string for (string::const_iterator cit = str.begin(); cit != str.end(); ++cit) { - sel_end_cursor.par()->InsertChar(pos, (*cit), font); + selection.end.par()->InsertChar(pos, (*cit), font); ++pos; } @@ -1910,7 +2037,7 @@ void LyXText::InsertStringA(BufferView * bview, string const & str) RedoParagraphs(bview, cursor, endpar); SetCursor(bview, cursor.par(), cursor.pos()); - sel_cursor = cursor; + selection.cursor = cursor; SetCursor(bview, par, pos); SetSelection(bview); } @@ -2007,7 +2134,7 @@ void LyXText::CheckParagraph(BufferView * bview, LyXParagraph * par, // dangling pointers are possible SetCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary()); - sel_cursor = cursor; + selection.cursor = cursor; return; } } @@ -2039,19 +2166,19 @@ void LyXText::CheckParagraph(BufferView * bview, LyXParagraph * par, // set the cursor again. Otherwise dangling pointers are possible // also set the selection - if (selection) { + if (selection.set()) { tmpcursor = cursor; - SetCursorIntern(bview, sel_cursor.par(), sel_cursor.pos(), - false, sel_cursor.boundary()); - sel_cursor = cursor; - SetCursorIntern(bview, sel_start_cursor.par(), - sel_start_cursor.pos(), - false, sel_start_cursor.boundary()); - sel_start_cursor = cursor; - SetCursorIntern(bview, sel_end_cursor.par(), - sel_end_cursor.pos(), - false, sel_end_cursor.boundary()); - sel_end_cursor = cursor; + SetCursorIntern(bview, selection.cursor.par(), selection.cursor.pos(), + false, selection.cursor.boundary()); + selection.cursor = cursor; + SetCursorIntern(bview, selection.start.par(), + selection.start.pos(), + false, selection.start.boundary()); + selection.start = cursor; + SetCursorIntern(bview, selection.end.par(), + selection.end.pos(), + false, selection.end.boundary()); + selection.end = cursor; SetCursorIntern(bview, last_sel_cursor.par(), last_sel_cursor.pos(), false, last_sel_cursor.boundary()); @@ -2338,7 +2465,7 @@ void LyXText::DeleteEmptyParagraphMechanism(BufferView * bview, LyXCursor const & old_cursor) const { // Would be wrong to delete anything if we have a selection. - if (selection) return; + if (selection.set()) return; // We allow all kinds of "mumbo-jumbo" when freespacing. if (textclasslist.Style(bview->buffer()->params.textclass, @@ -2485,10 +2612,10 @@ void LyXText::DeleteEmptyParagraphMechanism(BufferView * bview, SetCursorIntern(bview, cursor.par(), cursor.pos()); - if (sel_cursor.par() == old_cursor.par() - && sel_cursor.pos() == sel_cursor.pos()) { + if (selection.cursor.par() == old_cursor.par() + && selection.cursor.pos() == selection.cursor.pos()) { // correct selection - sel_cursor = cursor; + selection.cursor = cursor; } } if (!deleted) { @@ -2496,7 +2623,7 @@ void LyXText::DeleteEmptyParagraphMechanism(BufferView * bview, RedoParagraphs(bview, old_cursor, old_cursor.par()->next()); // correct cursor y SetCursorIntern(bview, cursor.par(), cursor.pos()); - sel_cursor = cursor; + selection.cursor = cursor; } } }