From 1bc4b735755ab8addc9e7bca305889e4784e7ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Fri, 21 Jan 2000 17:41:57 +0000 Subject: [PATCH] fix some of the bugs reported, should hopefully be a bit better now. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@436 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 28 +++++++++++ src/bmtable.c | 2 +- src/insets/figinset.C | 49 +++++++++---------- src/insets/insetlatexaccent.C | 9 ++++ src/kbmap.C | 12 +++-- src/kbmap.h | 8 ++- src/lyxfont.C | 12 ++--- src/mathed/math_forms.C | 2 +- src/mathed/math_panel.C | 4 +- src/paragraph.C | 11 ++--- src/support/lstrings.C | 88 --------------------------------- src/support/lstrings.h | 91 ++++++++++++++--------------------- src/text.C | 30 ++++++++---- 13 files changed, 140 insertions(+), 206 deletions(-) diff --git a/ChangeLog b/ChangeLog index f258bea99c..692aea7a97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2000-01-21 Lars Gullik Bjønnes + + * src/bmtable.c (fl_set_bmtable_file): have arguments in the X r5 + version also. + + * src/paragraph.C (FirstPhysicalPar): remove assert and comment + that obviously was wrong... + + * src/lyxfont.C (textWidth): have c as char c[2] instead of char + c, this avoids warnings with purify and islower. + + * src/insets/figinset.C: rename struct queue to struct + queue_element and rewrite to use a std::queue. gsqueue is now a + std::queue + (runqueue): reflect move to std::queue + (addwait): ditto + + * src/support/lstrings.h (tostr): specialize for bool, otherwise + we would get "1" "0" instead of "true" "false. Also make the tostr + functions inline. + 2000-01-21 Juergen Vigna * src/buffer.C (writeFileAscii): Disabled code for special groff @@ -11,6 +32,13 @@ 2000-01-20 Lars Gullik Bjønnes + * src/insets/insetlatexaccent.C (Draw): make accents on top of 'i' + and 'j' look better. This might fix the "macron" bug that has been + observed. + + * src/support/lstrings.[Ch] (tostr): reimplement all the tostr + functions as one template function. Delete the old versions. + * src/support/lyxsum.C: move using std::ifstream inside MODERN_STL_STREAMS diff --git a/src/bmtable.c b/src/bmtable.c index f1e5288710..9d97965ddb 100644 --- a/src/bmtable.c +++ b/src/bmtable.c @@ -308,7 +308,7 @@ void fl_set_bmtable_file(FL_OBJECT * ob, int nx, int ny, char const * filename) #else -void fl_set_bmtable_file(FL_OBJECT *, int, int, char const *) +void fl_set_bmtable_file(FL_OBJECT * ob, int nx, int ny, char const * filename) { fprintf(stderr, "Set bmtable file: Sorry, I need X11 release 6 to do " "work!\n"); diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 891ddbee8b..1e69c675eb 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -40,8 +40,10 @@ extern long int background_pixels; #include #include #include +#include using std::ofstream; using std::ifstream; +using std::queue; #include "figinset.h" #include "lyx.h" @@ -87,11 +89,10 @@ static int figarrsize = 0; /* current max number of figures */ static int bmpinsref = 0; /* number of bitmaps */ static int bmparrsize = 0; /* current max number of bitmaps */ -struct queue { - float rx, ry; /* resolution x and y */ - int ofsx, ofsy; /* x and y translation */ - figdata * data; /* we are doing it for this data */ - queue * next; /* next item in queue */ +struct queue_element { + float rx, ry; // resolution x and y + int ofsx, ofsy; // x and y translation + figdata * data; // we are doing it for this data }; struct pidwait { @@ -103,7 +104,9 @@ static int const MAXGS = 3; /* maximum 3 gs's at a time */ static Figref ** figures; /* all the figures */ static figdata ** bitmaps; /* all the bitmaps */ -static queue * gsqueue = 0; /* queue for ghostscripting */ + +static queue gsqueue; // queue for ghostscripting + static int gsrunning = 0; /* currently so many gs's are running */ static bool bitmap_waiting = false; /* bitmaps are waiting finished */ static char bittable[256]; /* bit reversion table */ @@ -509,7 +512,7 @@ static void runqueue() Atom * prop; int nprop, i; - if (!gsqueue) { + if (gsqueue.empty()) { if (!gsrunning && gs_xcolor) { // de-allocate rest of colors // ***** @@ -517,10 +520,9 @@ static void runqueue() } return; } - queue * p = gsqueue; - + queue_element * p = &gsqueue.front(); if (!p->data) { - delete p; + gsqueue.pop(); continue; } @@ -720,10 +722,10 @@ static void runqueue() if (lyxerr.debugging()) { lyxerr << "GS [" << pid << "] started" << endl; } - gsqueue = gsqueue->next; - gsrunning++; + p->data->gspid = pid; - delete p; + ++gsrunning; + gsqueue.pop(); } } @@ -731,22 +733,15 @@ static void runqueue() static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data) { // recompute the stuff and put in the queue - queue * p = new queue; - p->ofsx = psx; - p->ofsy = psy; - p->rx = (float(data->raw_wid) * 72.0) / pswid; - p->ry = (float(data->raw_hgh) * 72.0) / pshgh; + queue_element p; + p.ofsx = psx; + p.ofsy = psy; + p.rx = (float(data->raw_wid) * 72.0) / pswid; + p.ry = (float(data->raw_hgh) * 72.0) / pshgh; - p->data = data; - p->next = 0; + p.data = data; - // now put into queue - queue * p2 = gsqueue; - if (!gsqueue) gsqueue = p; - else { - while (p2->next) p2 = p2->next; - p2->next = p; - } + gsqueue.push(p); // if possible, run the queue runqueue(); diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index 53df124be1..780da5c0e5 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -418,6 +418,15 @@ void InsetLatexAccent::Draw(LyXFont font, tmpvar, wid, font.ascent('i') - font.ascent('x') - 1); + // the five lines below is a simple hack to + // make the display of accent 'i' and 'j' + // better. It makes the accent be written + // closer to the top of the dot-less 'i' or 'j'. + char tmpic = ic; // store the ic when we + ic = 'x'; // calculates the ascent of + asc = Ascent(font); // the dot-less version (here: 'x') + ic = tmpic; // set the orig ic back + y = baseline - asc; // update to new y coord. } // now the rest - draw within (x, y, x+wid, y+hg) switch (modtype) { diff --git a/src/kbmap.C b/src/kbmap.C index b1a8ae6387..858edad8b0 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -10,6 +10,8 @@ #include #include +#include + #include "support/lstrings.h" #include "gettext.h" @@ -39,7 +41,7 @@ enum { ModsMask = ShiftMask | ControlMask | Mod1Mask}; Returns : length of printed string if ok, 0 otherwise. \* ---F------------------------------------------------------------------- */ static -void printKeysym(KeySym key, unsigned int mod, string & buf) +void printKeysym(unsigned long key, unsigned int mod, string & buf) { mod &= ModsMask; @@ -90,7 +92,7 @@ void printKeyTab(kb_key * tabPt, string & buf) Returns : action or -1 if error (no map defined or key not found) \* ---F------------------------------------------------------------------- */ -int kb_sequence::addkey(KeySym key, +int kb_sequence::addkey(unsigned long key, unsigned int mod, unsigned int nmod /*= 0*/) { if(length < 0) length = 0; @@ -343,7 +345,7 @@ int kb_keymap::bind(char const * seq, int action) Returns : user defined action; 0 for prefix key, -1 if key not found \* ---F------------------------------------------------------------------- */ -int kb_keymap::lookup(KeySym key, unsigned int mod, kb_sequence * seq) +int kb_keymap::lookup(unsigned long key, unsigned int mod, kb_sequence * seq) { unsigned int ksym, msk1, msk0; kb_key * tab; @@ -493,13 +495,13 @@ int kb_keymap::defkey(kb_sequence * seq, int action, int idx /*= 0*/) // --- define rest of sequence -------------------------------------- - if(idx+1 == seq->length) { + if(idx + 1 == seq->length) { newone->action = action; newone->table = 0; return 0; } else { newone->table = new kb_keymap; - int res = newone->table->defkey(seq, action, idx+1); + int res = newone->table->defkey(seq, action, idx + 1); return res; } } diff --git a/src/kbmap.h b/src/kbmap.h index e49d03067d..e2e15f2286 100644 --- a/src/kbmap.h +++ b/src/kbmap.h @@ -13,8 +13,6 @@ #pragma interface #endif -#include - #include "LString.h" #define KB_PREALLOC 16 @@ -58,7 +56,7 @@ public: void print(string & buf) const; /// Look up a key in the keymap - int lookup(KeySym key, unsigned mod, kb_sequence * seq); + int lookup(unsigned long key, unsigned mod, kb_sequence * seq); /// Given an action, find all keybindings. string findbinding(int action) const; @@ -102,7 +100,7 @@ public: /// Add a key to the key sequence and look it up in the curmap /** Add a key to the key sequence and look it up in the curmap if the latter is defined. */ - int addkey(KeySym key, unsigned mod, unsigned nmod = 0); + int addkey(unsigned long key, unsigned mod, unsigned nmod = 0); /// int print(string & buf, bool when_defined = false) const; @@ -117,7 +115,7 @@ public: char getiso(); /// - KeySym getsym(); + unsigned long getsym(); /// void reset(); diff --git a/src/lyxfont.C b/src/lyxfont.C index 0615b6a959..be2be84f2b 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -879,18 +879,18 @@ int LyXFont::textWidth(char const * s, int n) const } else { // emulate smallcaps since X doesn't support this unsigned int result = 0; - char c; + char c[2]; c[1] = '\0'; LyXFont smallfont = *this; smallfont.decSize(); smallfont.decSize(); smallfont.setShape(LyXFont::UP_SHAPE); for (int i = 0; i < n; ++i) { - c = s[i]; - if (islower(c)){ - c = toupper(c); - result += XTextWidth(smallfont.getXFontstruct(), &c, 1); + c[0] = s[i]; + if (islower(c[0])){ + c[0] = toupper(c[0]); + result += XTextWidth(smallfont.getXFontstruct(), c, 1); } else { - result += XTextWidth(getXFontstruct(), &c, 1); + result += XTextWidth(getXFontstruct(), c, 1); } } return result; diff --git a/src/mathed/math_forms.C b/src/mathed/math_forms.C index 3c0ec49ad2..744364efb6 100644 --- a/src/mathed/math_forms.C +++ b/src/mathed/math_forms.C @@ -9,7 +9,7 @@ #include #include "math_panel.h" -FD_panel *create_form_panel(void) +FD_panel * create_form_panel(void) { FL_OBJECT *obj; FD_panel *fdui = (FD_panel *) fl_calloc(1, sizeof(FD_panel)); diff --git a/src/mathed/math_panel.C b/src/mathed/math_panel.C index 250de2aa6a..57f4785bfc 100644 --- a/src/mathed/math_panel.C +++ b/src/mathed/math_panel.C @@ -323,7 +323,7 @@ FD_panel * create_math_panel( ) return fd_panel; } -extern BitmapMenu* sym_menu; +extern BitmapMenu * sym_menu; extern void create_symbol_menues(FD_panel *); @@ -333,7 +333,7 @@ void free_symbols_form() fl_hide_form(fd_panel->panel); fl_free_form(fd_panel->panel); delete sym_menu; - delete fd_panel; + free(fd_panel); fd_panel = 0; } } diff --git a/src/paragraph.C b/src/paragraph.C index d83f3332e0..4b3457be6d 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1577,8 +1577,7 @@ LyXParagraph * LyXParagraph::FirstPhysicalPar() tmppar = tmppar->previous; if (!tmppar) { - Assert(false); // let's get an abort then - return this; // This should never happen! + return this; } else return tmppar; } @@ -1590,13 +1589,13 @@ LyXParagraph const * LyXParagraph::FirstPhysicalPar() const return this; LyXParagraph const * tmppar = this; - while (tmppar && (tmppar->IsDummy() - || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE)) + while (tmppar && + (tmppar->IsDummy() + || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE)) tmppar = tmppar->previous; if (!tmppar) { - Assert(false); // let's get an abort then - return this; // This should never happen! + return this; } else return tmppar; } diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 0b5a616db3..b811d4c9a6 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -9,13 +9,6 @@ #endif #include -#ifdef HAVE_SSTREAM -#include -using std::ostringstream; -#else -#include -#endif - #include "LString.h" #include "lstrings.h" #include "LRegex.h" @@ -134,87 +127,6 @@ string uppercase(string const & a) } -string tostr(long i) -{ -#ifndef HAVE_SSTREAM - // "Hey!", you say. "Why do we need the char str[30]?". - // Since strstream does not handle memory for us we have to do - // that ourselves, if we don't pass str in we have to capture - // oss.str() in a tmp variable and delete that manually. - // Thus we then require more temporary variables and the code - // gets more obfuscated. - char str[30]; - ostrstream oss(str, 30); - oss << i << '\0'; - return oss.str(); -#else - ostringstream oss; - oss << i; - return oss.str().c_str(); -#endif -} - - -string tostr(unsigned long i) -{ -#ifndef HAVE_SSTREAM - char str[30]; - ostrstream oss(str, 30); - oss << i << '\0'; - return oss.str(); -#else - ostringstream oss; - oss << i; - return oss.str().c_str(); -#endif -} - - -string tostr(void * v) -{ - return tostr(long(v)); -} - - -string tostr(int i) -{ - return tostr(long(i)); -} - - -string tostr(unsigned int ui) -{ - return tostr(long(ui)); -} - - -string tostr(char c) -{ - return string(1, c); -} - - -string tostr(bool b) -{ - return b ? "true" : "false"; -} - - -string tostr(double d) -{ -#ifndef HAVE_SSTREAM - char tmp[40]; - ostrstream oss(tmp, 40); - oss << d << '\0'; - return oss.str(); -#else - ostringstream oss; - oss << d; - return oss.str().c_str(); -#endif -} - - bool prefixIs(string const & a, char const * pre) { unsigned int l = strlen(pre); diff --git a/src/support/lstrings.h b/src/support/lstrings.h index c24a4714a1..e962920ff4 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -9,39 +9,15 @@ #define LSTRINGS_H #include - -//#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; -//} - #include + +#ifdef HAVE_SSTREAM +#include +using std::ostringstream; +#else +#include +#endif + #include "LString.h" @@ -77,30 +53,35 @@ string lowercase(string const &); /// string uppercase(string const &); -/// int to string -string tostr(int i); - -/// -string tostr(unsigned int); - -/// long to string -string tostr(long l); - -/// -string tostr(unsigned long l); - -/// -string tostr(char c); - -/// void * to string -string tostr(void * v); - -/// bool to string -string tostr(bool b); - -/// -string tostr(double d); +/// convert T to string +template +inline string tostr(T const & t) +{ +#ifdef HAVE_SSTREAM + ostringstream ostr; + ostr << t; + return ostr.str().c_str(); + // We need to use the .c_str since we sometimes are using + // our own string class and that is not compatible with + // basic_string. +#else + // The buf is probably a bit large, but if we want to be safer + // we should leave it this big. As compiler/libs gets updated + // this part of the code will cease to be used and we loose + // nothing. + char buf[2048]; // a bit too large perhaps? + ostrstream ostr(buf, sizeof(buf)); + ostr << t << '\0'; + return buf; +#endif +} +inline +string tostr(bool b) +{ + return (b ? "true" : "false"); +} + /// Does the string start with this prefix? bool prefixIs(string const &, char const *); diff --git a/src/text.C b/src/text.C index 4aa3d1e65b..b475f7b2d6 100644 --- a/src/text.C +++ b/src/text.C @@ -281,9 +281,6 @@ void LyXText::Draw(Row const * row, LyXParagraph::size_type & pos, // exactly the label-width. int LyXText::LeftMargin(Row const * row) const { - LyXFont labelfont; - LyXParagraph * newpar; - Row dummyrow; LyXLayout const & layout = textclasslist.Style(parameters->textclass, row->par->GetLayout()); @@ -315,7 +312,7 @@ int LyXText::LeftMargin(Row const * row) const if (!row->par->GetLayout()) { // find the previous same level paragraph if (row->par->FirstPhysicalPar()->Previous()) { - newpar = row->par + LyXParagraph * newpar = row->par ->DepthHook(row->par->GetDepth()); if (newpar && textclasslist.Style(parameters->textclass, @@ -327,7 +324,7 @@ int LyXText::LeftMargin(Row const * row) const } else { // find the next level paragraph - newpar = row->par->DepthHook(row->par->GetDepth()-1); + LyXParagraph * newpar = row->par->DepthHook(row->par->GetDepth()-1); // make a corresponding row. Needed to call LeftMargin() @@ -336,6 +333,7 @@ int LyXText::LeftMargin(Row const * row) const && textclasslist .Style(parameters->textclass, newpar->GetLayout()).isEnvironment()) { + Row dummyrow; dummyrow.par = newpar; dummyrow.pos = newpar->Last(); x = LeftMargin(&dummyrow); @@ -358,7 +356,7 @@ int LyXText::LeftMargin(Row const * row) const } - labelfont = GetFont(row->par, -2); + LyXFont labelfont = GetFont(row->par, -2); switch (layout.margintype) { case MARGIN_DYNAMIC: if (!layout.leftmargin.empty()) { @@ -427,7 +425,7 @@ int LyXText::LeftMargin(Row const * row) const tmprow = tmprow->previous; int minfill = tmprow->fill; - while (tmprow-> next && tmprow->next->par == row->par) { + while (tmprow->next && tmprow->next->par == row->par) { tmprow = tmprow->next; if (tmprow->fill < minfill) minfill = tmprow->fill; @@ -2932,14 +2930,26 @@ void LyXText::Delete() // this is a very easy implementation LyXCursor old_cursor = cursor; + int old_cur_par_id = old_cursor.par->id(); + int old_cur_par_prev_id = old_cursor.par->previous->id(); // just move to the right CursorRightIntern(); - + + // This check is not very good... + // The CursorRightIntern calls DeleteEmptyParagrapgMechanism + // and that can very well delete the par or par->previous in + // old_cursor. Will a solution where we compare paragraph id's + //work better? +#if 1 + if (cursor.par->previous->id() == old_cur_par_prev_id + && cursor.par->id() != old_cur_par_id) + return; // delete-empty-paragraph-mechanism has done it +#else if (cursor.par->previous == old_cursor.par->previous && cursor.par != old_cursor.par) - return; // delete-emty-paragraph-mechanism has done it - + return; // delete-empty-paragraph-mechanism has done it +#endif // if you had success make a backspace if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) { LyXCursor tmpcursor = cursor;