From c36aa67f7bbf964a624be7ced9b3bf03148ab1db Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Mon, 17 Jan 2000 21:01:30 +0000 Subject: [PATCH] some important changes to FIX_DOUBLE_SPCE still not completely correct (please help out.) Some external functions called from wrappers. use MODERN_STL_STREAMS in lyxsum.C git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@423 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 23 ++++++ src/DepTable.C | 4 +- src/buffer.C | 6 +- src/insets/figinset.C | 7 +- src/lyx_gui.C | 2 +- src/lyx_main.C | 2 +- src/support/LAssert.h | 6 +- src/support/Makefile.am | 6 ++ src/support/abort.C | 10 +++ src/support/chdir.C | 14 ++++ src/support/date.C | 14 ++++ src/support/getUserName.C | 15 ++++ src/support/getcwd.C | 14 ++++ src/support/kill.C | 11 +++ src/support/lstrings.h | 54 ++++++------- src/support/lyxlib.h | 57 ++++---------- src/support/lyxsum.C | 11 +-- src/support/syscall.C | 5 +- src/texrow.C | 2 +- src/texrow.h | 2 +- src/text2.C | 161 ++++++++++++++++++++++++++------------ 21 files changed, 286 insertions(+), 140 deletions(-) create mode 100644 src/support/abort.C create mode 100644 src/support/chdir.C create mode 100644 src/support/date.C create mode 100644 src/support/getUserName.C create mode 100644 src/support/getcwd.C create mode 100644 src/support/kill.C diff --git a/ChangeLog b/ChangeLog index a7bc67466d..54d2887f83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2000-01-14 Lars Gullik Bjønnes + + * src/support/date.C: new file + + * src/support/chdir.C: new file + + * src/support/getUserName.C: new file + + * src/support/getcwd.C: new file + + * src/support/abort.C: new file + + * src/support/kill.C: new file + + * src/support/lyxlib.h: moved all the functions in this file + insede struct lyx. Added also kill and abort to this struct. This + is a way to avoid the "kill is not defined in ", we make + C++ wrappers for functions that are not ANSI C or ANSI C++. + + * src/support/lyxsum.C (sum): use #ifdef MODERN_STL_STREAMS + instead of #if __GLIBCPP__. Since lyxsum is now put inside struct + lyx it has been renamed to sum. + 2000-01-14 Jean-Marc Lasgouttes * src/text.C: add using directives for std::min and std::max. diff --git a/src/DepTable.C b/src/DepTable.C index 856a07ef42..9597831351 100644 --- a/src/DepTable.C +++ b/src/DepTable.C @@ -35,7 +35,7 @@ void DepTable::insert(string const & fi, if (deplist.find(f) == deplist.end()) { if (upd) { one = two; - two = lyxsum(f.c_str()); + two = lyx::sum(f.c_str()); } deplist[f] = make_pair(one, two); } @@ -48,7 +48,7 @@ void DepTable::update() itr != deplist.end(); ++itr) { unsigned long one = (*itr).second.second; - unsigned long two = lyxsum((*itr).first.c_str()); + unsigned long two = lyx::sum((*itr).first.c_str()); (*itr).second = make_pair(one, two); if (lyxerr.debugging()) { lyxerr << "update: " << (*itr).first << " " diff --git a/src/buffer.C b/src/buffer.C index 649dc2e291..e7cb2acdb2 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1588,7 +1588,7 @@ void Buffer::makeLaTeXFile(string const & fname, // first paragraph of the document. (Asger) texrow.start(paragraph, 0); - string userName(getUserName()); + string userName(lyx::getUserName()); string LFile; if (!only_body && nice) { @@ -2146,9 +2146,9 @@ void Buffer::makeLinuxDocFile(string const & fname, int column) << params.preamble << " \n]>\n\n"; } - string userName(getUserName()); + string userName(lyx::getUserName()); ofs << "\n"; + << "by <" << userName << "> " << lyx::date() << " -->\n"; if(params.options.empty()) sgmlOpenTag(ofs, 0, top_element); diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 41f482b301..b3d3cbf3fb 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -57,6 +57,7 @@ using std::ifstream; #include "gettext.h" #include "lyx_gui_misc.h" // CancelCloseBoxCB #include "support/FileInfo.h" +#include "support/lyxlib.h" extern BufferView * current_view; #if 0 @@ -260,7 +261,7 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int, lyxerr << "Killing gs " << p->gspid << endl; } - kill(p->gspid, SIGHUP); + lyx::kill(p->gspid, SIGHUP); sprintf(tmp, "%s/~lyxgs%d.ps", system_tempdir.c_str(), @@ -275,7 +276,7 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int, lyxerr << "Killing gs " << p->gspid << endl; } - kill(p->gspid, SIGHUP); + lyx::kill(p->gspid, SIGHUP); sprintf(tmp, "%s/~lyxgs%d.ps", system_tempdir.c_str(), @@ -472,7 +473,7 @@ static void freefigdata(figdata * tmpdata) chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh); // kill ghostscript and unlink it's files tmpdata->gspid = -1; - kill(pid, SIGKILL); + lyx::kill(pid, SIGKILL); sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid); unlink(buf); } diff --git a/src/lyx_gui.C b/src/lyx_gui.C index 9305d9afce..6919c7285a 100644 --- a/src/lyx_gui.C +++ b/src/lyx_gui.C @@ -156,7 +156,7 @@ extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev) XGetErrorText(display, xeev->error_code, etxt, 512); lyxerr << etxt << endl; // By doing an abort we get a nice backtrace. (hopefully) - abort(); + lyx::abort(); return 0; // Solaris CC wants us to return something } diff --git a/src/lyx_main.C b/src/lyx_main.C index 18329f8de2..98a0ebbaf4 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -615,6 +615,6 @@ void error_handler(int err_sig) lyxerr << "Bye." << endl; if(err_sig!= SIGHUP && (!GetEnv("LYXDEBUG").empty() || err_sig == SIGSEGV)) - abort(); + lyx::abort(); exit(0); } diff --git a/src/support/LAssert.h b/src/support/LAssert.h index e429df8c11..cbcb53df64 100644 --- a/src/support/LAssert.h +++ b/src/support/LAssert.h @@ -2,6 +2,8 @@ #ifndef LASSERT_H #define LASSERT_H +#include "support/lyxlib.h" + //namespace LyX { #ifdef ENABLE_ASSERTIONS @@ -11,7 +13,7 @@ template inline void Assert(A assertion) { //if (!assertion) throw X(); if (!assertion) { - abort(); + lyx::abort(); } } @@ -24,7 +26,7 @@ template inline void Assert(A * ptr) template<> inline void Assert(void const * ptr) { if (!ptr) { - abort(); + lyx::abort(); } } #endif /* HAVE_PARTIAL_SPECIALIZATION */ diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 959ba0281a..35560ee7e3 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -23,9 +23,15 @@ libsupport_la_SOURCES = \ LRegex.h \ LSubstring.C \ LSubstring.h \ + abort.C \ block.h \ + chdir.C \ + date.C \ filetools.C \ filetools.h \ + getUserName.C \ + getcwd.C \ + kill.C \ lstrings.C \ lstrings.h \ lyxlib.h \ diff --git a/src/support/abort.C b/src/support/abort.C new file mode 100644 index 0000000000..46f57ce2a9 --- /dev/null +++ b/src/support/abort.C @@ -0,0 +1,10 @@ +#include + +#include + +#include "support/lyxlib.h" + +void lyx::abort() +{ + ::abort(); +} diff --git a/src/support/chdir.C b/src/support/chdir.C new file mode 100644 index 0000000000..0ce2df4942 --- /dev/null +++ b/src/support/chdir.C @@ -0,0 +1,14 @@ +#include + +#include + +#include "support/lyxlib.h" + +int lyx::chdir(char const * name) +{ +#ifndef __EMX__ + return ::chdir(name); +#else + return ::_chdir2(name); +#endif +} diff --git a/src/support/date.C b/src/support/date.C new file mode 100644 index 0000000000..eb1660b888 --- /dev/null +++ b/src/support/date.C @@ -0,0 +1,14 @@ +#include + +#include + +#include "support/lyxlib.h" + +char * lyx::date() +{ + time_t tid; + if ((tid = ::time(0)) == static_cast(-1)) + return 0; + else + return ::ctime(&tid); +} diff --git a/src/support/getUserName.C b/src/support/getUserName.C new file mode 100644 index 0000000000..03ed40d5fe --- /dev/null +++ b/src/support/getUserName.C @@ -0,0 +1,15 @@ +#include + +#include "support/lyxlib.h" +#include "support/filetools.h" +#include "gettext.h" + +string lyx::getUserName() +{ + string userName(GetEnv("LOGNAME")); + if (userName.empty()) + userName = GetEnv("USER"); + if (userName.empty()) + userName = _("unknown"); + return userName; +} diff --git a/src/support/getcwd.C b/src/support/getcwd.C new file mode 100644 index 0000000000..f8e096bba1 --- /dev/null +++ b/src/support/getcwd.C @@ -0,0 +1,14 @@ +#include + +#include + +#include "support/lyxlib.h" + +char * lyx::getcwd(char * buffer, size_t size) +{ +#ifndef __EMX__ + return ::getcwd(buffer, size); +#else + return ::_getcwd2(buffer, size); +#endif +} diff --git a/src/support/kill.C b/src/support/kill.C new file mode 100644 index 0000000000..ba788b9479 --- /dev/null +++ b/src/support/kill.C @@ -0,0 +1,11 @@ +#include + +#include +#include + +#include "lyxlib.h" + +int lyx::kill(pid_t pid, int sig) +{ + return ::kill(pid, sig); +} diff --git a/src/support/lstrings.h b/src/support/lstrings.h index b419798e11..c24a4714a1 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -10,36 +10,36 @@ #include -#include "LAssert.h" +//#include "LAssert.h" //#warning verify this please. Lgb /// -template -size_t lstrlen(T const * t) -{ - Assert(t); // we don't want null pointers - size_t count = 0; - T const * r = t; - while(*r != 0) ++r, ++count; - return count; -} - - -//#warning verify this please. Lgb -/// -template -T * lstrchr(T const * t, int c) -{ - Assert(t); // we don't want null pointers - T * r = const_cast(t); - while(*r != 0) { - if (*r == c) - return r; - else - ++r; - } - return 0; -} +//template +//size_t lstrlen(T const * t) +//{ +// Assert(t); // we don't want null pointers +// size_t count = 0; +// T const * r = t; +// while(*r != 0) ++r, ++count; +// return count; +//} + + +//#Warning verify this please. Lgb +/// +//template +//T * lstrchr(T const * t, int c) +//{ +// Assert(t); // we don't want null pointers +// T * r = const_cast(t); +// while(*r != 0) { +// if (*r == c) +// return r; +// else +// ++r; +// } +// return 0; +//} #include #include "LString.h" diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index da5a4858f9..f7512a7c72 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -12,56 +12,27 @@ #ifndef LYX_LIB_H #define LYX_LIB_H -#include -#include - #include "LString.h" -#include "gettext.h" -#include "support/filetools.h" - -/// generates an checksum -unsigned long lyxsum(char const * file); - -/// returns a date string -inline char * date() -{ - time_t tid; - if ((tid= time(0)) == static_cast(-1)) - return 0; - else - return ctime(&tid); -} - // Where can I put this? I found the occurence of the same code // three/four times. Don't you think it better to use a macro definition // (an inlined member of some class)? -/// -inline string getUserName() -{ - string userName(GetEnv("LOGNAME")); - if (userName.empty()) - userName = GetEnv("USER"); - if (userName.empty()) - userName = _("unknown"); - return userName; -} // This should have been a namespace struct lyx { - static char * getcwd(char * buffer, size_t size) { -#ifndef __EMX__ - return ::getcwd(buffer, size); -#else - return ::_getcwd2(buffer, size); -#endif - }; - static int chdir(char const * name) { -#ifndef __EMX__ - return ::chdir(name); -#else - return ::_chdir2(name); -#endif - }; + /// + static char * getcwd(char * buffer, size_t size); + /// + static int chdir(char const * name); + /// generates an checksum + static unsigned long sum(char const * file); + /// returns a date string + static char * date(); + /// + static string getUserName(); + /// + static int kill(int pid, int sig); + /// + static void abort(); }; #endif diff --git a/src/support/lyxsum.C b/src/support/lyxsum.C index 04f1bdc154..36b512e497 100644 --- a/src/support/lyxsum.C +++ b/src/support/lyxsum.C @@ -3,7 +3,7 @@ * * LyX, The Document Processor * - * The function lyxsum is taken from GNU textutill-1.22 + * The function lyx::sum is taken from GNU textutill-1.22 * and is there part of the program chsum. The chsum program * is written by Q. Frank Xia, qx@math.columbia.edu. * @@ -14,12 +14,14 @@ #include -#ifdef __GLIBCPP__ +#ifdef MODERN_STL_STREAMS #include #else #include #endif +#include "support/lyxlib.h" + /* Number of bytes to read at once. */ #define BUFLEN (1 << 16) @@ -84,12 +86,12 @@ static unsigned long const crctab[256] = Return crc if successful, 0 if an error occurs. */ unsigned long -lyxsum (char const * file) +lyx::sum (char const * file) { unsigned long crc = 0; long length = 0; long bytes_read; -#if __GLIBCPP__ +#ifdef MODERN_STL_STREAMS char buf[BUFLEN]; ifstream ifs(file); if (!ifs) { @@ -98,7 +100,6 @@ lyxsum (char const * file) while ((bytes_read = ifs.readsome(buf, BUFLEN)) > 0) { unsigned char * cp = reinterpret_cast(buf); - length += bytes_read; while (bytes_read--) crc = (crc << 8) ^ crctab[((crc >> 24) ^ *(cp++)) & 0xFF]; diff --git a/src/support/syscall.C b/src/support/syscall.C index c12e755aa5..bd78d81cb0 100644 --- a/src/support/syscall.C +++ b/src/support/syscall.C @@ -14,6 +14,7 @@ #include "syscall.h" #include "syscontr.h" #include "support/lstrings.h" +#include "support/lyxlib.h" Systemcalls::Systemcalls() { pid = 0; // No child yet @@ -33,7 +34,7 @@ Systemcalls::~Systemcalls() { #if 0 // If the child is alive, we have to brutally kill it if (getpid() != 0) { - ::kill(getpid(), SIGKILL); + lyx::kill(getpid(), SIGKILL); } #endif } @@ -77,7 +78,7 @@ void Systemcalls::kill(int /*tolerance*/) { lyxerr << "LyX: Can't kill non-existing process." << endl; return; } - int ret = ::kill(getpid(), SIGHUP); + int ret = lyx::kill(getpid(), SIGHUP); bool wait_for_death = true; if (ret != 0) { if (errno == ESRCH) { diff --git a/src/texrow.C b/src/texrow.C index 5c41cd90d6..702f68b8c0 100644 --- a/src/texrow.C +++ b/src/texrow.C @@ -4,7 +4,7 @@ * LyX, The Document Processor * * Copyright (C) 1995 Matthias Ettrich - * Copyright (C) 1995-1999 The LyX Team. + * Copyright (C) 1995-2000 The LyX Team. * * ====================================================== */ diff --git a/src/texrow.h b/src/texrow.h index 8d4017e9d3..6de80a927b 100644 --- a/src/texrow.h +++ b/src/texrow.h @@ -5,7 +5,7 @@ * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich - * Copyright 1995-1998 The LyX Team + * Copyright 1995-2000 The LyX Team * * ====================================================== */ diff --git a/src/text2.C b/src/text2.C index 1e1d0761b8..441ea8275e 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1746,7 +1746,7 @@ void LyXText::InsertInset(Inset *inset) } -/* this is for the simple cut and paste mechanism */ +// this is for the simple cut and paste mechanism static LyXParagraph * simple_cut_buffer = 0; static char simple_cut_buffer_textclass = 0; @@ -1754,7 +1754,7 @@ void DeleteSimpleCutBuffer() { if (!simple_cut_buffer) return; - LyXParagraph *tmppar; + LyXParagraph * tmppar; while (simple_cut_buffer) { tmppar = simple_cut_buffer; @@ -1789,7 +1789,7 @@ void LyXText::CutSelection(bool doclear) // Check whether there are half footnotes in the selection if (sel_start_cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE - || sel_end_cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE){ + || sel_end_cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) { tmppar = sel_start_cursor.par; while (tmppar != sel_end_cursor.par){ if (tmppar->footnoteflag != sel_end_cursor.par->footnoteflag) { @@ -1832,7 +1832,7 @@ void LyXText::CutSelection(bool doclear) .par->ParFromPos(sel_start_cursor.pos)->previous, undoendpar); - // delete the simple_cut_buffer + // clear the simple_cut_buffer DeleteSimpleCutBuffer(); // set the textclass @@ -1867,7 +1867,18 @@ void LyXText::CutSelection(bool doclear) - cut across footnotes and paragraph My simplistic tests show that the idea are basically sound but there are some items to fix up...we only need to find them - first. (Lgb) + first. + + As do redo Asger's example above (with | beeing the cursor in the + result after cutting.): + + Example: "This is our text." + Using " our " as selection, cutting will give "This is|text.". + Using "our" as selection, cutting will give "This is | text.". + Using " our" as selection, cutting will give "This is| text.". + Using "our " as selection, cutting will give "This is |text.". + + (Lgb) */ #ifndef FIX_DOUBLE_SPACE @@ -1898,7 +1909,7 @@ void LyXText::CutSelection(bool doclear) for (; i < sel_end_cursor.pos; ++i) { /* table stuff -- begin */ if (sel_start_cursor.par->table - && sel_start_cursor.par->IsNewline(sel_start_cursor.pos)){ + && sel_start_cursor.par->IsNewline(sel_start_cursor.pos)) { sel_start_cursor.par->CopyIntoMinibuffer(sel_start_cursor.pos); sel_start_cursor.pos++; } else { @@ -1908,27 +1919,31 @@ void LyXText::CutSelection(bool doclear) } simple_cut_buffer->InsertFromMinibuffer(simple_cut_buffer->Last()); } -#ifdef FIX_DOUBLE_SPACES +#ifndef FIX_DOUBLE_SPACE // check for double spaces if (sel_start_cursor.pos && - sel_start_cursor.par->Last() > sel_start_cursor.pos && - sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1) && - sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) { + sel_start_cursor.par->Last() > sel_start_cursor.pos + && sel_start_cursor.par + ->IsLineSeparator(sel_start_cursor.pos - 1) + && sel_start_cursor.par + ->IsLineSeparator(sel_start_cursor.pos)) { sel_start_cursor.par->Erase(sel_start_cursor.pos); } if (space_wrapped) - simple_cut_buffer->InsertChar(i - sel_start_cursor.pos, ' '); + simple_cut_buffer->InsertChar(i - sel_start_cursor.pos, + ' '); #endif endpar = sel_end_cursor.par->Next(); - } - else { + } else { // cut more than one paragraph - sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos); + sel_end_cursor.par + ->BreakParagraphConservative(sel_end_cursor.pos); #ifndef FIX_DOUBLE_SPACE // insert a space at the end if there was one if (space_wrapped) - sel_end_cursor.par->InsertChar(sel_end_cursor.par->Last(), ' '); + sel_end_cursor.par + ->InsertChar(sel_end_cursor.par->Last(), ' '); #endif sel_end_cursor.par = sel_end_cursor.par->Next(); sel_end_cursor.pos = 0; @@ -1938,22 +1953,26 @@ void LyXText::CutSelection(bool doclear) #ifndef FIX_DOUBLE_SPACE // please break behind a space, if there is one. // The space should be copied too - if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) + if (sel_start_cursor.par + ->IsLineSeparator(sel_start_cursor.pos)) sel_start_cursor.pos++; - +#endif sel_start_cursor.par ->BreakParagraphConservative(sel_start_cursor.pos); +#ifndef FIX_DOUBLE_SPACE if (!sel_start_cursor.pos - || sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1) - || sel_start_cursor.par->IsNewline(sel_start_cursor.pos - 1)) { + || sel_start_cursor.par + ->IsLineSeparator(sel_start_cursor.pos - 1) + || sel_start_cursor.par + ->IsNewline(sel_start_cursor.pos - 1)) { sel_start_cursor.par->Next()->InsertChar(0, ' '); } #endif // store the endparagraph for redoing later - endpar = sel_end_cursor.par->Next(); /* needed because - the sel_end_ - cursor.par - will be pasted! */ + endpar = sel_end_cursor.par->Next(); /* needed because + the sel_end_ + cursor.par + will be pasted! */ // store the selection simple_cut_buffer = sel_start_cursor.par @@ -1970,7 +1989,7 @@ void LyXText::CutSelection(bool doclear) // care about footnotes if (simple_cut_buffer->footnoteflag) { - LyXParagraph *tmppar = simple_cut_buffer; + LyXParagraph * tmppar = simple_cut_buffer; while (tmppar){ tmppar->footnoteflag = LyXParagraph::NO_FOOTNOTE; tmppar = tmppar->next; @@ -1988,15 +2007,17 @@ void LyXText::CutSelection(bool doclear) !sel_start_cursor.par->Next()->Last()) sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->PasteParagraph(); -#ifdef FIX_DOUBLE_SPACE +#ifndef FIX_DOUBLE_SPACE // maybe a forgotten blank if (sel_start_cursor.pos - && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos) - && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1)) { + && sel_start_cursor.par + ->IsLineSeparator(sel_start_cursor.pos) + && sel_start_cursor.par + ->IsLineSeparator(sel_start_cursor.pos - 1)) { sel_start_cursor.par->Erase(sel_start_cursor.pos); } #endif - } + } // sometimes necessary if (doclear) @@ -2024,12 +2045,14 @@ void LyXText::CopySelection() /* check wether there are half footnotes in the selection */ if (sel_start_cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE - || sel_end_cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE){ + || sel_end_cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) { tmppar = sel_start_cursor.par; - while (tmppar != sel_end_cursor.par){ - if (tmppar->footnoteflag != sel_end_cursor.par->footnoteflag){ + while (tmppar != sel_end_cursor.par) { + if (tmppar->footnoteflag != + sel_end_cursor.par->footnoteflag) { WriteAlert(_("Impossible operation"), - _("Don't know what to do with half floats."), + _("Don't know what to do" + " with half floats."), _("sorry.")); return; } @@ -2099,13 +2122,13 @@ void LyXText::CopySelection() tmppar = tmppar->next; } } - + // the simple_cut_buffer paragraph is too big LyXParagraph::size_type tmpi2 = sel_start_cursor.par->PositionInParFromPos(sel_start_cursor.pos); for (; tmpi2; --tmpi2) simple_cut_buffer->Erase(0); - + // now tmppar 2 is too big, delete all after sel_end_cursor.pos tmpi2 = sel_end_cursor.par->PositionInParFromPos(sel_end_cursor.pos); @@ -2145,8 +2168,8 @@ void LyXText::PasteSelection() } /* table stuff -- begin */ - if (cursor.par->table){ - if (simple_cut_buffer->next){ + if (cursor.par->table) { + if (simple_cut_buffer->next) { WriteAlert(_("Impossible operation"), _("Table cell cannot include more than one paragraph!"), _("Sorry.")); @@ -2186,24 +2209,55 @@ void LyXText::PasteSelection() else table_too_small = true; } else { +#ifdef FIX_DOUBLE_SPACE + // This is an attempt to fix the + // "never insert a space at the + // beginning of a paragraph" problem. + if (tmpcursor.pos == 0 + && simple_cut_buffer->IsLineSeparator(0)) { + simple_cut_buffer->Erase(0); + } else { + simple_cut_buffer->CutIntoMinibuffer(0); + simple_cut_buffer->Erase(0); + tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos); + tmpcursor.pos++; + } +#else simple_cut_buffer->CutIntoMinibuffer(0); simple_cut_buffer->Erase(0); tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos); tmpcursor.pos++; +#endif } } } else { /* table stuff -- end */ - // Some provisions should be done here for checking if we - // are inserting at the beginning of a paragraph. If there - // are a space at the beginning of the text to insert and we are - // inserting at the beginning of the paragraph the space should + // Some provisions should be done here for checking + // if we are inserting at the beginning of a + // paragraph. If there are a space at the beginning + // of the text to insert and we are inserting at + // the beginning of the paragraph the space should // be removed. while (simple_cut_buffer->text.size()) { +#ifdef FIX_DOUBLE_SPACE + // This is an attempt to fix the + // "never insert a space at the + // beginning of a paragraph" problem. + if (tmpcursor.pos == 0 + && simple_cut_buffer->IsLineSeparator(0)) { + simple_cut_buffer->Erase(0); + } else { + simple_cut_buffer->CutIntoMinibuffer(0); + simple_cut_buffer->Erase(0); + tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos); + tmpcursor.pos++; + } +#else simple_cut_buffer->CutIntoMinibuffer(0); simple_cut_buffer->Erase(0); tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos); tmpcursor.pos++; +#endif } } delete simple_cut_buffer; @@ -2241,16 +2295,22 @@ void LyXText::PasteSelection() simple_cut_buffer->MakeSameLayout(cursor.par); // find the end of the buffer - LyXParagraph *lastbuffer = simple_cut_buffer; + LyXParagraph * lastbuffer = simple_cut_buffer; while (lastbuffer->Next()) lastbuffer = lastbuffer->Next(); // find the physical end of the buffer +#ifdef WITH_WARNINGS +#warning Explain this please. +#endif +#if 0 + // Can someone explain to be why this is done a second time? + // (Lgb) lastbuffer = simple_cut_buffer; while (lastbuffer->Next()) lastbuffer = lastbuffer->Next(); - -#ifndef FIX_DOUBLE_SPACE +#endif +#ifndef FIX_DOUBLE_SPACE // Please break behind a space, if there is one. The space // should be copied too. if (cursor.par->Last() > cursor.pos @@ -2279,11 +2339,14 @@ void LyXText::PasteSelection() endpar = cursor.par->ParFromPos(cursor.pos)->next->Next(); // paste it! - lastbuffer->ParFromPos(lastbuffer->Last())->next = cursor.par->ParFromPos(cursor.pos)->next; - cursor.par->ParFromPos(cursor.pos)->next->previous = lastbuffer->ParFromPos(lastbuffer->Last()); + lastbuffer->ParFromPos(lastbuffer->Last())->next = + cursor.par->ParFromPos(cursor.pos)->next; + cursor.par->ParFromPos(cursor.pos)->next->previous = + lastbuffer->ParFromPos(lastbuffer->Last()); cursor.par->ParFromPos(cursor.pos)->next = simple_cut_buffer; - simple_cut_buffer->previous = cursor.par->ParFromPos(cursor.pos); + simple_cut_buffer->previous = + cursor.par->ParFromPos(cursor.pos); if (cursor.par->ParFromPos(cursor.pos)->Next() == lastbuffer) lastbuffer = cursor.par; @@ -2310,7 +2373,7 @@ void LyXText::PasteSelection() } else if (!lastbuffer->Next()->Last()) { lastbuffer->Next()->MakeSameLayout(lastbuffer); -#ifndef FIX_DOUBLE_SPACE +#ifndef FIX_DOUBLE_SPACE // be careful witth double spaces if ((!lastbuffer->Last() || lastbuffer->IsLineSeparator(lastbuffer->Last() - 1) @@ -2334,8 +2397,8 @@ void LyXText::PasteSelection() #endif lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(); - } - else lastbuffer->Next()->ClearParagraph(); + } else + lastbuffer->Next()->ClearParagraph(); } // restore the simple cut buffer -- 2.39.2