]> git.lyx.org Git - features.git/commitdiff
fix some of the bugs reported, should hopefully be a bit better now.
authorLars Gullik Bjønnes <larsbj@gullik.org>
Fri, 21 Jan 2000 17:41:57 +0000 (17:41 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Fri, 21 Jan 2000 17:41:57 +0000 (17:41 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@436 a592a061-630c-0410-9148-cb99ea01b6c8

13 files changed:
ChangeLog
src/bmtable.c
src/insets/figinset.C
src/insets/insetlatexaccent.C
src/kbmap.C
src/kbmap.h
src/lyxfont.C
src/mathed/math_forms.C
src/mathed/math_panel.C
src/paragraph.C
src/support/lstrings.C
src/support/lstrings.h
src/text.C

index f258bea99c99aecee68578bcd4c3bcb6055eb07e..692aea7a97f9874c3b8dd36d898654f90ff3687b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2000-01-21  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * 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<queue_element>
+       (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  <jug@sad.it>
 
        * src/buffer.C (writeFileAscii): Disabled code for special groff
 
 2000-01-20  Lars Gullik Bjønnes  <larsbj@lyx.org>
 
+       * 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
 
index f1e52887105b54772f285782c2100bad3eaf7a7e..9d97965ddb5b445870e930f58ac84bdcb17a0aeb 100644 (file)
@@ -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");
index 891ddbee8b03375b8e79dfa1afb9a25bcdfc467e..1e69c675ebf5868197ae057eedbe32256bb311bc 100644 (file)
@@ -40,8 +40,10 @@ extern long int background_pixels;
 #include <cctype>
 #include <cmath>
 #include <fstream>
+#include <queue>
 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<queue_element> 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;
-
-       p->data = data;
-       p->next = 0;
-
-       // now put into queue
-       queue * p2 = gsqueue;
-       if (!gsqueue) gsqueue = p;
-       else {
-               while (p2->next) p2 = p2->next;
-               p2->next = p;
-       }
+       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;
+
+       gsqueue.push(p);
 
        // if possible, run the queue
        runqueue();
index 53df124be154231dec531760ec1b2188e8fc6323..780da5c0e5c2c3348a8924fcf5ab9d911f981423 100644 (file)
@@ -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) {
index b1a8ae63876de1bff635f75127644164455093f8..858edad8b0b55268d5fbc4326668bb8cfb09da56 100644 (file)
@@ -10,6 +10,8 @@
 
 #include <config.h>
 #include <cstring>
+#include <X11/Xlib.h>
+
 #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;
        }
 }
index e49d03067d02f949e15e146b5a41a940862c75a2..e2e15f228608cf9f9c8443457c8ad5dd93588dab 100644 (file)
@@ -13,8 +13,6 @@
 #pragma interface
 #endif
 
-#include <X11/Xlib.h>
-
 #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();
index 0615b6a9591e72fdccd6631fc3074abc698e0910..be2be84f2b47023817797bc1b0a755b205ae3312 100644 (file)
@@ -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;
index 3c0ec49ad24572aa20085afc147709f19b4c8930..744364efb6938381c2794129dc15d2a8a45946a2 100644 (file)
@@ -9,7 +9,7 @@
 #include <cstdlib>
 #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));
index 250de2aa6a5fc5079bb1cc768a10ff137efa5457..57f4785bfc42b286e9845fb4ec4b0b9b2624d6a0 100644 (file)
@@ -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;  
    }
 }
index d83f3332e023de2daa01f2ae13129e8f87436f4d..4b3457be6dc0ebda7b0ee54734d1207201a5c8bd 100644 (file)
@@ -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;
 }
index 0b5a616db359f6fe40cb9cb2ca55de3a7857b029..b811d4c9a61a3e793cdfc6f401875a14510fae22 100644 (file)
@@ -9,13 +9,6 @@
 #endif
 #include <cstdlib>
 
-#ifdef HAVE_SSTREAM
-#include <sstream>
-using std::ostringstream;
-#else
-#include <strstream>
-#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);
index c24a4714a18e0411205ea7e334ea23378a03b309..e962920ff481f065a7ab4c1115d9016d2d6f702d 100644 (file)
@@ -9,39 +9,15 @@
 #define LSTRINGS_H
 
 #include <cstring>
+#include <cctype>
 
-//#include "LAssert.h"
-
-//#warning verify this please. Lgb
-///
-//template<class T>
-//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<class T>
-//T * lstrchr(T const * t, int c)
-//{
-//  Assert(t); // we don't want null pointers
-//  T * r = const_cast<T*>(t);
-//  while(*r != 0) { 
-//    if (*r == c) 
-//      return r; 
-//    else 
-//      ++r;
-//  }
-//  return 0;
-//}
+#ifdef HAVE_SSTREAM
+#include <sstream>
+using std::ostringstream;
+#else
+#include <strstream>
+#endif
 
-#include <cctype>
 #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<typename T>
+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<char>.
+#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 *);
 
index 4aa3d1e65bbf76be7b242e1921d86b826498ec5b..b475f7b2d672343c23fc35f70d657fab1c183be4 100644 (file)
@@ -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;