From: Lars Gullik Bjønnes Date: Tue, 21 Dec 1999 06:10:21 +0000 (+0000) Subject: fixes because of SUN CC warnings, bmtable now compiled with C compilator, countChar... X-Git-Tag: 1.6.10~22458 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=5f3f9ad231bc0c24d34c00e3936e226d9834589a;p=lyx.git fixes because of SUN CC warnings, bmtable now compiled with C compilator, countChar should also work on CC now, read ChangeLog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@390 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index cee84cde30..1386aaeeb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,58 @@ +1999-12-21 Lars Gullik Bjønnes + + * src/text2.C (RedoHeightOfParagraph): rename arg cursor -> cur + (RedoDrawingOfParagraph): ditto + (RedoParagraphs): ditto + (RemoveTableRow): ditto + + * src/text.C (Fill): rename arg paperwidth -> paper_width + + * src/buffer.C (insertLyXFile): rename var filename -> fname + (writeFile): rename arg filename -> fname + (writeFileAscii): ditto + (makeLaTeXFile): ditto + (makeLinuxDocFile): ditto + (makeDocBookFile): ditto + + * src/LaTeX.C (runMakeIndex): change arg name from file -> f + (runBibTeX): ditto + + * src/Makefile.am (lyx_SOURCES): add bmtable.c and remove bmtable.C + + * src/bmtable.h: add extern "C" on this file when __cplusplus is + defined. + + * src/bmtable.c: new file, a C'ified copy of bmtable.C, this is + compiled by a C compilator not C++. + + * src/layout.h (LyXTextClass): added typedef for const_iterator + (LyXTextClassList): added typedef for const_iterator + member + functions begin and end. + + * src/LyXView.C (UpdateDocumentClassChoice): rewritten to use + iterators to fill the choice_class. + (updateLayoutChoice): rewritten to use iterators to fill the + layoutlist in the toolbar. + + * src/BufferView.h (BufferView::work_area_width): removed unused + variable. + + * src/lyx_gui_misc.C (WarnReadonly): added string parameter 'file' + + * src/buffer.C (sgmlOpenTag): drop the use of the static space array + (sgmlCloseTag): ditto + + * src/support/lstrings.h: return type of countChar changed to + unsigned char. + + * src/support/lstrings.C (countChar): use HAVE_STD_COUNT to choose + what version of this func to use. Also made to return unsigned int. + + * configure.in: call LYX_STD_COUNT + + * acinclude.m4 (LYX_STD_COUNT): new function checks for a standard + conforming std::count. + 1999-12-20 Jean-Marc Lasgouttes * src/mathed/math_draw.C (Draw, Metrics): fix a bug where a prime diff --git a/acinclude.m4 b/acinclude.m4 index c919e6c3df..3362b4c385 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -286,6 +286,30 @@ if test $lyx_cv_broken_stack = yes ; then fi]) +dnl Usage: LYX_STD_COUNT : checks wherer the C++ library have a conforming +dnl count template, if not the old HP version is assumed. +AC_DEFUN(LYX_STD_COUNT,[ +AC_CACHE_CHECK(for conforming std::count,lyx_cv_std_count, + [AC_TRY_COMPILE([ +#include +#include +using std::string; +using std::count; +int countChar(string const & a, char const c) +{ + return count(a.begin(), a.end(), c); +} +],[ + string a("hello"); + int i = countChar(a, 'l'); +],lyx_cv_std_count=yes,lyx_cv_std_count=no) +]) +if test $lyx_cv_std_count = yes ; then + AC_DEFINE(HAVE_STD_COUNT, 1, + [Define if you have a conforming std::count template, otherwise HP version of count template is assumed.]) +fi]) + + dnl Usage: LYX_CXX_STL_MODERN_STREAMS : checks whether the C++ compiler dnl supports modern STL streams AC_DEFUN(LYX_CXX_STL_MODERN_STREAMS,[ diff --git a/configure.in b/configure.in index 80ff6a10d8..2c3ff8beae 100644 --- a/configure.in +++ b/configure.in @@ -70,6 +70,7 @@ dnl LYX_CXX_STL_STACK LYX_CXX_STL_STRING LYX_CXX_NAMESPACES LYX_CXX_CHEADERS +LYX_STD_COUNT dnl we disable rtti for now dnl LYX_CXX_RTTI AC_CHECK_HEADERS(ostream istream) diff --git a/src/BufferView.C b/src/BufferView.C index 48dc183a91..c6ab81144b 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -402,7 +402,7 @@ extern "C" { void BufferView::create_view(int xpos, int ypos, int width, int height) { FL_OBJECT * obj; - const int bw = abs(fl_get_border_width()); + int const bw = abs(fl_get_border_width()); // a hack for the figinsets (Matthias) // This one first, then it will probably be invisible. (Lgb) @@ -423,9 +423,9 @@ void BufferView::create_view(int xpos, int ypos, int width, int height) // the free object work_area = obj = fl_add_free(FL_INPUT_FREE, - xpos +bw, ypos+bw, - width-15-2*bw /* scrollbarwidth */, - height-2*bw, "", + xpos + bw, ypos + bw, + width - 15 - 2 * bw /* scrollbarwidth */, + height - 2 * bw, "", C_BufferView_work_area_handler); obj->wantkey = FL_KEY_TAB; obj->u_vdata = this; /* This is how we pass the BufferView @@ -445,7 +445,7 @@ void BufferView::create_view(int xpos, int ypos, int width, int height) fl_set_border_width(-2); // to get visible feedback #endif button_up = obj = fl_add_pixmapbutton(FL_TOUCH_BUTTON, - width-15+4*bw, + width - 15 + 4 * bw, ypos, 15, 15, ""); fl_set_object_boxtype(obj, FL_UP_BOX); @@ -464,9 +464,9 @@ void BufferView::create_view(int xpos, int ypos, int width, int height) // the scrollbar slider fl_set_border_width(-bw); scrollbar = obj = fl_add_slider(FL_VERT_SLIDER, - width-15+4*bw, + width - 15 + 4 * bw, ypos + 15, - 15, height-30, ""); + 15, height - 30, ""); fl_set_object_color(obj, FL_COL1, FL_MCOL); fl_set_object_boxtype(obj, FL_UP_BOX); fl_set_object_resize(obj, FL_RESIZE_ALL); @@ -824,11 +824,10 @@ int BufferView::work_area_handler(FL_OBJECT * ob, int event, return 1; } -int BufferView::WorkAreaMotionNotify(FL_OBJECT *ob, Window, +int BufferView::WorkAreaMotionNotify(FL_OBJECT * ob, Window, int /*w*/, int /*h*/, - XEvent * ev, void */*d*/) + XEvent * ev, void * /*d*/) { - if (buffer_ == 0) return 0; if (!screen) return 0; @@ -1350,7 +1349,7 @@ void BufferView::CursorToggleCB(FL_OBJECT * ob, long) } if (view->lyx_focus && view->work_area_focus) { - if (!view->buffer_->the_locking_inset){ + if (!view->buffer_->the_locking_inset) { view->screen->CursorToggle(); } else { view->buffer_->the_locking_inset-> @@ -1359,7 +1358,7 @@ void BufferView::CursorToggleCB(FL_OBJECT * ob, long) goto set_timer_and_return; } else { // Make sure that the cursor is visible. - if (!view->buffer_->the_locking_inset){ + if (!view->buffer_->the_locking_inset) { view->screen->ShowCursor(); } else { if (!view->buffer_->the_locking_inset->isCursorVisible()) @@ -1433,7 +1432,7 @@ int BufferView::WorkAreaSelectionNotify(FL_OBJECT *, Window win, } XFlush(fl_display); - if (uc){ + if (uc) { free(uc); uc = 0; } diff --git a/src/BufferView.h b/src/BufferView.h index 45e4cce06b..2ec4f88575 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -30,7 +30,7 @@ class Inset; class BufferView { public: /// - BufferView(LyXView *owner, int , int , int, int); + BufferView(LyXView * owner, int , int , int, int); /// ~BufferView(); /// @@ -66,11 +66,10 @@ public: /// LyXView * owner() const { return owner_; } /// - LyXScreen * getScreen() - { - fl_set_timer(timer_cursor, 0.4); - return screen; - } + LyXScreen * getScreen() { + fl_set_timer(timer_cursor, 0.4); + return screen; + } /// void savePosition(); /// @@ -142,8 +141,6 @@ private: /// long current_scrollbar_value; /// - int work_area_width; - /// bool lyx_focus; /// bool work_area_focus; diff --git a/src/LaTeX.C b/src/LaTeX.C index f2a3c12f33..82813fa1cb 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -296,18 +296,18 @@ int LaTeX::operator()() } -bool LaTeX::runMakeIndex(string const &file) +bool LaTeX::runMakeIndex(string const & f) { lyxerr[Debug::LATEX] << "idx file has been made," " running makeindex on file " - << file << endl; + << f << endl; // It should be possible to set the switches for makeindex // sorting style and such. It would also be very convenient // to be able to make style files from within LyX. This has // to come for a later time. (0.13 perhaps?) string tmp = "makeindex -c -q "; - tmp += file; + tmp += f; Systemcalls one; one.startscript(Systemcalls::System, tmp); return true; @@ -369,14 +369,14 @@ bool LaTeX::scanAux(DepTable & dep) } -bool LaTeX::runBibTeX(string const & file, DepTable & dep) +bool LaTeX::runBibTeX(string const & f, DepTable & dep) { // Since a run of Bibtex mandates more latex runs it is ok to // remove all ".bib" and ".bst" files, it is also required to // discover style and database changes. dep.remove_files_with_extension(".bib"); dep.remove_files_with_extension(".bst"); - ifstream ifs(file.c_str()); + ifstream ifs(f.c_str()); string token; bool using_bibtex = false; LRegex reg1("\\\\bibdata{([^}]+)}"); diff --git a/src/LyXView.C b/src/LyXView.C index 79a5e9a7df..129aec0e00 100644 --- a/src/LyXView.C +++ b/src/LyXView.C @@ -158,22 +158,20 @@ void LyXView::create_form_form_main(int width, int height) * are presented (and rightly so) in GUI popups. Asger. */ { - FL_OBJECT * obj; - - FD_form_main *fdui = (FD_form_main *) - fl_calloc(1, sizeof(FD_form_main)); + FD_form_main * fdui = static_cast + (fl_calloc(1, sizeof(FD_form_main))); _form_main = fdui; // the main form _form = fdui->form_main = fl_bgn_form(FL_NO_BOX, width, height); fdui->form_main->u_vdata = this; - obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, ""); + FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, ""); fl_set_object_color(obj, FL_MCOL, FL_MCOL); // Parameters for the appearance of the main form - const int air = 2; - const int bw = abs(fl_get_border_width()); + int const air = 2; + int const bw = abs(fl_get_border_width()); // // THE MENUBAR @@ -194,19 +192,19 @@ void LyXView::create_form_form_main(int width, int height) // WORKAREA // - const int ywork = 60 + 2*air + bw; - const int workheight = height - ywork - (25 + 2*air); + int const ywork = 60 + 2 * air + bw; + int const workheight = height - ywork - (25 + 2 * air); ::current_view = bufferview = new BufferView(this, air, ywork, - width - 3*air, + width - 3 * air, workheight); // // MINIBUFFER // - minibuffer = new MiniBuffer(this, air, height-(25+air), - width-(2*air), 25); + minibuffer = new MiniBuffer(this, air, height - (25 + air), + width - (2 * air), 25); // // TIMERS @@ -292,16 +290,13 @@ void LyXView::updateLayoutChoice() if (toolbar->combox->empty() || (last_textclass != int(buffer()->params.textclass))) { toolbar->combox->clear(); - for (int i = 0; - textclasslist.NameOfLayout(buffer()-> - params.textclass, i) != "@@end@@"; - i++) { - LyXLayout const & layout = textclasslist. - Style(buffer()->params.textclass, i); - if (layout.obsoleted_by().empty()) - toolbar->combox->addline(layout.name().c_str()); + LyXTextClass const & tc = textclasslist.TextClass(buffer()->params.textclass); + for (LyXTextClass::const_iterator cit = tc.begin(); + cit != tc.end(); ++cit) { + if ((*cit).obsoleted_by().empty()) + toolbar->combox->addline((*cit).name().c_str()); else - toolbar->combox->addline(("@N"+layout.name()).c_str()); + toolbar->combox->addline(("@N" + (*cit).name()).c_str()); } last_textclass = int(buffer()->params.textclass); current_layout = 0; @@ -323,10 +318,10 @@ void LyXView::UpdateDocumentClassChoice() // Update the document class display in the document form if (fd_form_document) { fl_clear_choice(fd_form_document->choice_class); - for (int i = 0; - textclasslist.DescOfClass(i) != "@@end@@"; ++i) { + for (LyXTextClassList::const_iterator cit = textclasslist.begin(); + cit != textclasslist.end(); ++cit) { fl_addto_choice(fd_form_document->choice_class, - textclasslist.DescOfClass(i).c_str()); + (*cit).description().c_str()); } } } diff --git a/src/Makefile.am b/src/Makefile.am index 58c6fd83a7..efb3142a71 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,7 +48,7 @@ lyx_SOURCES = \ Spacing.h \ TableLayout.C \ bibforms.h \ - bmtable.C \ + bmtable.c \ bmtable.h \ broken_headers.h \ buffer.C \ diff --git a/src/bmtable.C b/src/bmtable.C index 3491478962..c2773abd7c 100644 --- a/src/bmtable.C +++ b/src/bmtable.C @@ -15,10 +15,15 @@ #include -#include +#include #include "bmtable.h" #include XPM_H_LOCATION +#if defined(__cplusplus) +extern "C" +{ +#endif + typedef struct { int nx, ny; /* Dimensions of the table */ int dx, dy; /* Size of each item */ @@ -484,4 +489,6 @@ void fl_free_bmtable_pixmap(FL_OBJECT *ob) } } - +#if defined(__cplusplus) +} +#endif diff --git a/src/bmtable.c b/src/bmtable.c new file mode 100644 index 0000000000..f1e5288710 --- /dev/null +++ b/src/bmtable.c @@ -0,0 +1,494 @@ +/* + * File: bmtable.c + * Purpose: Implementation of the XForms object bmtable. + * Author: Alejandro Aguilar Sierra + * Created: November 1995 + * Description: A bitmap table uses a single bitmap to simulate a 2d array + * of bitmap buttons. It can be used to build bitmap menus. + * + * Copyright 1995, 1996 Alejandro Aguilar Sierra + * + * You are free to use and modify this code under the terms of + * the GNU General Public Licence version 2 or later. + * + */ + +#include + +#include +#include "bmtable.h" +#include XPM_H_LOCATION + +#if defined(__cplusplus) +extern "C" +{ +#endif + +typedef struct { + int nx, ny; /* Dimensions of the table */ + int dx, dy; /* Size of each item */ + int bx, by; /* Bitmap's position */ + int bw, bh; /* Bitmap dimensions */ + unsigned char const * bdata; /* Bitmap data */ + int maxi; /* Number of items */ + int i; /* Current position */ + int mousebut; /* mouse button pushed */ + Pixmap pix; /* Pixmap from data (temporal) */ +} BMTABLE_SPEC; + + +int handle_bitmaptable(FL_OBJECT * ob, int event, FL_Coord mx, + FL_Coord my, int key, void * xev); + + +FL_OBJECT * fl_create_bmtable(int type, FL_Coord x, FL_Coord y, + FL_Coord w, FL_Coord h, char const * label) +{ + FL_OBJECT * ob; + + ob = fl_make_object(FL_BMTABLE, type, x, y, w, h, label, handle_bitmaptable); + ob->boxtype = FL_BMTABLE_BOXTYPE; + ob->spec = fl_calloc(1, sizeof(BMTABLE_SPEC)); + ((BMTABLE_SPEC *)ob->spec)->pix = 0; + ((BMTABLE_SPEC *)ob->spec)->bdata= 0; + ((BMTABLE_SPEC *)ob->spec)->mousebut= -1; + return ob; +} + + +FL_OBJECT *fl_add_bmtable(int type, FL_Coord x, FL_Coord y, + FL_Coord w, FL_Coord h, char const *label) +{ + FL_OBJECT *ob; + + ob = fl_create_bmtable(type, x, y, w, h, label); + fl_add_object(fl_current_form, ob); + + return ob; +} + + +static void draw_bitmaptable(FL_OBJECT *ob) +{ + int i, j, lx; + FL_Coord mx, my; + FL_Coord xx, yy, ww, hh; + BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec; + GC gc = fl_state[fl_get_vclass()].gc[0]; + if (!sp) return; + + /* draw the bounding box first */ + lx = sp->maxi % sp->nx; + fl_drw_box(ob->boxtype, ob->x, ob->y, ob->w, ob->h, ob->col1, ob->bw); + if (lx) { + i = FL_abs(ob->bw); + xx = ob->x+ sp->dx*lx + i; + yy = ob->y+ (sp->ny-1)*sp->dy+i; + ww = ob->x+ob->w - xx - i; + hh = ob->y+ob->h-yy-i; + fl_drw_frame(FL_DOWN_FRAME, xx, yy, ww, hh, ob->col1, ob->bw); + fl_rectf(xx, yy, ww+i, hh+i, ob->col1); + } + + /* draw the background bitmap */ + if (sp->bdata) { + if (!sp->pix) { + sp->pix = XCreatePixmapFromBitmapData(fl_display, fl_winget(), + (char*)sp->bdata, + sp->bw, sp->bh, + fl_get_flcolor(ob->lcol), fl_get_flcolor(ob->col1), + /*DefaultDepth(fl_display, DefaultScreen(fl_display))*/ fl_state[fl_get_vclass()].depth); + XFlush(fl_display); + } + } + if (sp->pix) { + /* Adjust position */ + if (sp->bx < FL_abs(ob->bw) + 1) { + xx = FL_abs(ob->bw) - sp->bx + 1; + mx = ob->x + FL_abs(ob->bw) + 1; + } else { + xx = 0; + mx = ob->x + sp->bx; + } + if (sp->by < FL_abs(ob->bw) + 1) { + yy = FL_abs(ob->bw) - sp->by + 1; + my = ob->y + FL_abs(ob->bw) + 1; + } else { + yy = 0; + my = ob->y + sp->by; + } + ww = (mx + sp->bw < ob->x + ob->w - FL_abs(ob->bw)) ? + sp->bw: ob->x + ob->w - FL_abs(ob->bw) - mx; + hh = (my + sp->bh < ob->y + ob->h - FL_abs(ob->bw)) ? + sp->bh: ob->y + ob->h - FL_abs(ob->bw) - my; + + i = FL_abs(ob->bw); + j = hh - ((lx) ? sp->dy+2*i: 0); + XCopyArea(fl_display, sp->pix, fl_winget(), gc, xx, yy, ww, j, mx, my); + XFlush(fl_display); + if (lx) { + XCopyArea(fl_display, sp->pix, fl_winget(), gc, xx, + yy+j, lx*sp->dx-2*i, hh-j, mx, my+j); + XFlush(fl_display); + } + } + + + /* draw the grid if type > FLAT */ + if (ob->type > FL_BMTABLE_FLAT) { + mx = ob->x + ob->w; + my = ob->y + ob->h; + ww = ob->w; + for (yy= ob->y; yy<= my; yy+= sp->dy) { + if (ob->boxtype!= FL_FLAT_BOX && (yy == ob->y || yy>my-sp->dy)) + continue; + if (lx>0 && yy>= my-sp->dy - sp->dy/2) + ww = lx*sp->dx; + fl_diagline(ob->x, yy, ww, 1, FL_BOTTOM_BCOL); + fl_diagline(ob->x, yy+1, ww-2, 1, FL_TOP_BCOL); + } + hh = ob->h; + for (xx= ob->x; xx<= mx; xx+= sp->dx) { + if (ob->boxtype!= FL_FLAT_BOX && (xx == ob->x || xx>mx-sp->dx)) + continue; + if (lx>0 && xx>= ob->x+lx*sp->dx) + hh = (sp->ny-1)*sp->dy; + fl_diagline(xx, ob->y, 1, hh, FL_RIGHT_BCOL); + fl_diagline(xx+1, ob->y+1, 1, hh-2, FL_LEFT_BCOL); + } + } + + /* Simulate a pushed button */ + if (ob->pushed && 0 <= sp->i && sp->i < sp->maxi) { + i = sp->i % sp->nx; + j = sp->i/sp->nx; + ww = sp->dx-2*FL_abs(ob->bw); + hh = sp->dy-2*FL_abs(ob->bw); + xx = ob->x + sp->dx*i + FL_abs(ob->bw); + yy = ob->y + sp->dy*j + FL_abs(ob->bw); + fl_drw_frame(FL_DOWN_FRAME, xx, yy, ww, hh, ob->col1, ob->bw); + } +} + + +int handle_bitmaptable(FL_OBJECT * ob, int event, FL_Coord mx, + FL_Coord my, int key, void * xev) +{ + int i, j; + BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec; + + switch (event) { + case FL_DRAW: + draw_bitmaptable(ob); + break; + case FL_MOUSE: + if (!ob->belowmouse) { /* This never happens. Why? */ + sp->i = -1; + fl_redraw_object(ob); + break; + } + i = (mx - ob->x)/sp->dx; j = (my - ob->y)/sp->dy; + if (i>= 0 && i< sp->nx && j>= 0 && j< sp->ny) { + i += j*sp->nx; + if (i >= sp->maxi) i = -1; + if (sp->i != i) { + sp->i = i; + fl_redraw_object(ob); + } + } + break; + case FL_PUSH: + sp->mousebut = key; + i = (mx - ob->x)/sp->dx + ((my - ob->y)/sp->dy)*sp->nx; + if (0 <= i && i < sp->maxi) { + sp->i = i; + fl_redraw_object(ob); + } else + sp->i = -1; + break; + case FL_RELEASE: + fl_redraw_object(ob); + return 1; + case FL_FREEMEM: + if (sp->pix) { + XFreePixmap(fl_display, sp->pix); + XFlush(fl_display); + } + fl_free(((BMTABLE_SPEC*)ob->spec)); + break; + } + return 0; +} + + +/* + * The table has nx columns of dx width each and ny rows of dy height each. + * Initially the position of the firts item is supposed to be the same that + * the object position (x, y), and the number of items is supposed to be + * exactly nx*ny. + * + * The user could change these later. See below. + */ +void fl_set_bmtable_data(FL_OBJECT * ob, int nx, int ny, int bw, int bh, + unsigned char const * bdata) +{ + BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec; + if (sp) { + sp->nx = nx; + sp->ny = ny; + sp->bx = FL_abs(ob->bw); + sp->by = FL_abs(ob->bw); + sp->dx = ob->w/nx; + sp->dy = ob->h/ny; + sp->i = -1; + sp->maxi = sp->nx * sp->ny; + sp->bw = bw; + sp->bh = bh; + sp->bdata = bdata; + } +} + + +void fl_set_bmtable_pixmap_data(FL_OBJECT * ob, int nx, int ny, + char ** pdata) +{ + BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec; + extern Colormap color_map; + if (sp) { + Pixmap dummy_shapemask = 0; +#if 0 + // I can't see why this initalization is needed. (Lgb) + XpmAttributes dumb_attributes = {0}; +#else + XpmAttributes dumb_attributes; +#endif + sp->nx = nx; + sp->ny = ny; + sp->bx = FL_abs(ob->bw); + sp->by = FL_abs(ob->bw); + sp->dx = ob->w/nx; + sp->dy = ob->h/ny; + sp->i = -1; + sp->maxi = sp->nx * sp->ny; + sp->bdata = 0; + dumb_attributes.colormap = color_map; + dumb_attributes.closeness = 30000; + dumb_attributes.valuemask = XpmColormap | XpmCloseness; + if (XCreatePixmapFromData(fl_display, fl_winget(), pdata, + &(sp->pix), &dummy_shapemask, + &dumb_attributes) == XpmSuccess) { + sp->bw = dumb_attributes.width; + sp->bh = dumb_attributes.height; + XpmFreeAttributes(&dumb_attributes); + if (dummy_shapemask) { + XFreePixmap(fl_display, dummy_shapemask); + } + } + XFlush(fl_display); + } +} + + +/* + * This function works only for X11R6 or later + */ +#if XlibSpecificationRelease > 5 + +void fl_set_bmtable_file(FL_OBJECT * ob, int nx, int ny, char const * filename) +{ + int xh, yh; + unsigned int bw, bh; + unsigned char * bdata; + + if(XReadBitmapFileData(filename, &bw, &bh, + &bdata, &xh, &yh) == BitmapSuccess) + fl_set_bmtable_data(ob, nx, ny, bw, bh, bdata); + XFlush(fl_display); +} + +#else + +void fl_set_bmtable_file(FL_OBJECT *, int, int, char const *) +{ + fprintf(stderr, "Set bmtable file: Sorry, I need X11 release 6 to do " + "work!\n"); +} + +#endif + + + +void fl_set_bmtable_pixmap_file(FL_OBJECT *ob, int nx, int ny, char const *filename) +{ + extern Colormap color_map; + BMTABLE_SPEC *sp = (BMTABLE_SPEC *)ob->spec; + if (sp) { + Pixmap dummy_shapemask = 0; +#if 0 + XpmAttributes dumb_attributes = {0}; +#else + XpmAttributes dumb_attributes; +#endif + sp->nx = nx; + sp->ny = ny; + sp->bx = FL_abs(ob->bw); + sp->by = FL_abs(ob->bw); + sp->dx = ob->w/nx; + sp->dy = ob->h/ny; + sp->i = -1; + sp->maxi = sp->nx * sp->ny; + sp->bdata = 0; + + dumb_attributes.colormap = color_map; + dumb_attributes.closeness = 30000; + dumb_attributes.valuemask = XpmColormap | XpmCloseness; + + if (XReadPixmapFile(fl_display, fl_winget(), (char *)filename, + &(sp->pix), &dummy_shapemask, + &dumb_attributes) == XpmSuccess) { + sp->bw = dumb_attributes.width; + sp->bh = dumb_attributes.height; + XpmFreeAttributes(&dumb_attributes); + if (dummy_shapemask) { + XFreePixmap(fl_display, dummy_shapemask); + } + } + XFlush(fl_display); + } +} + + +/* + * This function allows to adjust the position of the first item and its + * size (dx, dy). The input values are incremental, not absolute. + */ +void fl_set_bmtable_adjust(FL_OBJECT *ob, int px, int py, int dx, int dy) +{ + BMTABLE_SPEC *sp = (BMTABLE_SPEC *)ob->spec; + if (sp) { + sp->bx += px; + sp->by += py; + sp->dx += dx; + sp->dy += dy; + } +} + +/* + * This function returns the table's selected position. + */ +int fl_get_bmtable(FL_OBJECT *ob) +{ + if ((BMTABLE_SPEC *)ob->spec) + return ((BMTABLE_SPEC *)ob->spec)->i; + else + return 0; +} + + +/* + * You can change the max number of items if you want. + */ +void fl_set_bmtable_maxitems(FL_OBJECT * ob, int i) +{ + if (i > 0 && (BMTABLE_SPEC *)ob->spec) + ((BMTABLE_SPEC *)ob->spec)->maxi = i; +} + + +int fl_get_bmtable_maxitems(FL_OBJECT * ob) +{ + if ((BMTABLE_SPEC *)ob->spec) + return ((BMTABLE_SPEC *)ob->spec)->maxi; + else + return 0; +} + + +void fl_replace_bmtable_item(FL_OBJECT * ob, int id, int cw, int ch, char * data) +{ + fprintf(stderr, "Replace bmtable item: Sorry, not yet implemented!\n"); +} + + +void fl_get_bmtable_item(FL_OBJECT * ob, int id, int * cw, int * ch, char * data) +{ + fprintf(stderr, "Get bmtable item: Sorry, not yet implemented!\n"); +} + +void fl_set_bmtable(FL_OBJECT * ob, int pushed, int pos) +{ + if ((BMTABLE_SPEC *)ob->spec) + ((BMTABLE_SPEC *)ob->spec)->i = (pushed) ? pos: -1; +} + + +int fl_get_bmtable_numb(FL_OBJECT *ob) +{ + if ((BMTABLE_SPEC *)ob->spec) + return ((BMTABLE_SPEC *)ob->spec)->mousebut; + else + return 0; +} + + +Pixmap fl_get_bmtable_pixmap(FL_OBJECT * ob) +{ + if ((BMTABLE_SPEC *)ob->spec) + return ((BMTABLE_SPEC *)ob->spec)->pix; + else + return 0; +} + + +void fl_draw_bmtable_item(FL_OBJECT * ob, int i, Drawable d, int xx, int yy) +{ + int x, y, w, h; + GC gc = fl_state[fl_get_vclass()].gc[0]; + BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec; + + if (sp && sp->pix) { + x = (i % sp->nx)*sp->dx + FL_abs(ob->bw); + y = (i/sp->nx)*sp->dy + FL_abs(ob->bw); + w = sp->dx-2*FL_abs(ob->bw); + h = sp->dy-2*FL_abs(ob->bw); + XCopyArea(fl_display, sp->pix, d, gc, x, y, w, h, xx, yy); + XFlush(fl_display); + } +} + +/* Free the current bitmap and pixmap in preparation for installing a new one */ +void fl_free_bmtable_bitmap(FL_OBJECT * ob) +{ + BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec; + + /* dump the temporary pixmap */ + if (sp && sp->pix) { + XFreePixmap(fl_display, sp->pix); + XFlush(fl_display); + sp->pix = 0; + } + + /* and free the space taken by bdata etc. */ + if (sp && sp->bdata) { + fl_free((void*)sp->bdata); + sp->bdata = 0; + } +} + +/* Free the current pixmap in preparation for installing a new one */ +/* This is needed when using data instead of files to set bitmaps */ +void fl_free_bmtable_pixmap(FL_OBJECT *ob) +{ + BMTABLE_SPEC * sp = (BMTABLE_SPEC *)ob->spec; + + /* dump the temporary pixmap */ + if (sp && sp->pix) { + XFreePixmap(fl_display, sp->pix); + XFlush(fl_display); + sp->pix = 0; + } +} + +#if defined(__cplusplus) +} +#endif diff --git a/src/bmtable.h b/src/bmtable.h index 937b8c112b..4d5a7864e9 100644 --- a/src/bmtable.h +++ b/src/bmtable.h @@ -18,6 +18,11 @@ #include FORMS_H_LOCATION +#if defined(__cplusplus) +extern "C" +{ +#endif + /// #define FL_BMTABLE 1500 /// A flat bitmap table @@ -34,6 +39,7 @@ */ #define FL_BMTABLE_BOXTYPE FL_UP_BOX + /// FL_OBJECT *fl_create_bmtable(int, FL_Coord, FL_Coord, FL_Coord, FL_Coord, char const *); @@ -84,5 +90,9 @@ void fl_free_bmtable_bitmap(FL_OBJECT *ob); /** Free the current pixmap in preparation for installing a new one */ void fl_free_bmtable_pixmap(FL_OBJECT *ob); +#if defined(__cplusplus) +} +#endif + #endif /* BMTABLE_H */ diff --git a/src/buffer.C b/src/buffer.C index 7f0986cf43..db7befb4fc 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -230,25 +230,25 @@ bool Buffer::insertLyXFile(string const & filen) { if (filen.empty()) return false; - string filename = MakeAbsPath(filen); + string fname = MakeAbsPath(filen); // check if file exist - FileInfo fi(filename); + FileInfo fi(fname); if (!fi.readable()) { WriteAlert(_("Error!"), _("Specified file is unreadable: "), - MakeDisplayPath(filename, 50)); + MakeDisplayPath(fname, 50)); return false; } BeforeChange(); - FilePtr myfile(filename, FilePtr::read); + FilePtr myfile(fname, FilePtr::read); if (!myfile()) { WriteAlert(_("Error!"), _("Cannot open specified file: "), - MakeDisplayPath(filename, 50)); + MakeDisplayPath(fname, 50)); return false; } LyXLex lex(0, 0); @@ -1174,45 +1174,45 @@ bool Buffer::readFile(LyXLex & lex, LyXParagraph * par) // Returns false if unsuccesful -bool Buffer::writeFile(string const & filename, bool flag) +bool Buffer::writeFile(string const & fname, bool flag) { // if flag is false writeFile will not create any GUI // warnings, only cerr. // Needed for autosave in background or panic save (Matthias 120496) - if (read_only && (filename == this->filename)) { + if (read_only && (fname == filename)) { // Here we should come with a question if we should // perform the write anyway. if (flag) lyxerr << _("Error! Document is read-only: ") - << filename << endl; + << fname << endl; else WriteAlert(_("Error! Document is read-only: "), - filename); + fname); return false; } - FileInfo finfo(filename); + FileInfo finfo(fname); if (finfo.exist() && !finfo.writable()) { // Here we should come with a question if we should // try to do the save anyway. (i.e. do a chmod first) if (flag) lyxerr << _("Error! Cannot write file: ") - << filename << endl; + << fname << endl; else WriteFSAlert(_("Error! Cannot write file: "), - filename); + fname); return false; } - ofstream ofs(filename.c_str()); + ofstream ofs(fname.c_str()); if (!ofs) { if (flag) lyxerr << _("Error! Cannot open file: ") - << filename << endl; + << fname << endl; else WriteFSAlert(_("Error! Cannot open file: "), - filename); + fname); return false; } // The top of the file should not be written by params. @@ -1242,7 +1242,7 @@ bool Buffer::writeFile(string const & filename, bool flag) } -void Buffer::writeFileAscii(string const & filename, int linelen) +void Buffer::writeFileAscii(string const & fname, int linelen) { LyXFont font1, font2; Inset * inset; @@ -1255,9 +1255,9 @@ void Buffer::writeFileAscii(string const & filename, int linelen) long fpos = 0; bool ref_printed = false; - ofstream ofs(filename.c_str()); + ofstream ofs(fname.c_str()); if (!ofs) { - WriteFSAlert(_("Error: Cannot write file:"), filename); + WriteFSAlert(_("Error: Cannot write file:"), fname); return; } @@ -1565,7 +1565,7 @@ void Buffer::writeFileAscii(string const & filename, int linelen) } -void Buffer::makeLaTeXFile(string const & filename, +void Buffer::makeLaTeXFile(string const & fname, string const & original_path, bool nice, bool only_body) { @@ -1578,9 +1578,9 @@ void Buffer::makeLaTeXFile(string const & filename, LyXTextClass const & tclass = textclasslist.TextClass(params.textclass); - ofstream ofs(filename.c_str()); + ofstream ofs(fname.c_str()); if (!ofs) { - WriteFSAlert(_("Error: Cannot open file: "), filename); + WriteFSAlert(_("Error: Cannot open file: "), fname); return; } @@ -2120,27 +2120,33 @@ bool Buffer::isSGML() const void Buffer::sgmlOpenTag(ostream & os, int depth, string const & latexname) const { - static char * space[] = {" "," ", " ", " ", " ", " ", - " ", - " ", " ", " ", - " "}; - +#if 0 + static char const * space[] = { + " "," ", " ", " ", " ", " ", + " ", + " ", " ", " ", + " "}; os << space[depth] << "<" << latexname << ">\n"; +#endif + os << string(depth, ' ') << "<" << latexname << ">\n"; } void Buffer::sgmlCloseTag(ostream & os, int depth, string const & latexname) const { +#if 0 static char * space[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "}; os << space[depth] << "\n"; +#endif + os << string(depth, ' ') << "\n"; } -void Buffer::makeLinuxDocFile(string const & filename, int column) +void Buffer::makeLinuxDocFile(string const & fname, int column) { LyXParagraph * par = paragraph; @@ -2150,10 +2156,10 @@ void Buffer::makeLinuxDocFile(string const & filename, int column) int depth = 0; /* paragraph depth */ - ofstream ofs(filename.c_str()); + ofstream ofs(fname.c_str()); if (!ofs) { - WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename); + WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname); return; } @@ -2723,7 +2729,7 @@ void Buffer::LinuxDocError(LyXParagraph * par, int pos, enum { MAX_NEST_LEVEL = 25}; -void Buffer::makeDocBookFile(string const & filename, int column) +void Buffer::makeDocBookFile(string const & fname, int column) { LyXParagraph * par = paragraph; @@ -2741,9 +2747,9 @@ void Buffer::makeDocBookFile(string const & filename, int column) tex_code_break_column = column; - ofstream ofs(filename.c_str()); + ofstream ofs(fname.c_str()); if (!ofs) { - WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename); + WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname); return; } diff --git a/src/buffer.h b/src/buffer.h index db9af3a238..f1e6895917 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -33,6 +33,7 @@ #include "texrow.h" #include "lyxtext.h" #include "support/filetools.h" +#include "lyx_gui_misc.h" class LyXRC; @@ -40,7 +41,6 @@ class TeXErrors; class LaTeXFeatures; extern void updateAllVisibleBufferRelatedPopups(); -extern void WarnReadonly(); /// struct DEPCLEAN { @@ -252,17 +252,16 @@ public: bool isReadonly() { return read_only; } /// Set buffer read-only flag - void setReadonly(bool flag = true) - { - if (read_only != flag) { - read_only = flag; - updateTitles(); - updateAllVisibleBufferRelatedPopups(); - } - if (read_only) { - WarnReadonly(); - } + void setReadonly(bool flag = true) { + if (read_only != flag) { + read_only = flag; + updateTitles(); + updateAllVisibleBufferRelatedPopups(); + } + if (read_only) { + WarnReadonly(filename); } + } /// returns true if the buffer contains a LaTeX document bool isLatex() const; diff --git a/src/definitions.h b/src/definitions.h deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 475c8a4ac4..d84a457ea6 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -1285,7 +1285,7 @@ void InsetFig::Edit(int, int) // The actual prevention of altering a readonly doc // is done in CallbackFig() if(current_view->buffer()->isReadonly()) - WarnReadonly(); + WarnReadonly(current_view->buffer()->fileName()); if (!form) { form = create_form_Figure(); diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 19f9100170..4103ef3835 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -152,7 +152,7 @@ InsetCitation::~InsetCitation() void InsetCitation::Edit(int, int) { if(current_view->buffer()->isReadonly()) - WarnReadonly(); + WarnReadonly(current_view->buffer()->fileName()); if (!citation_form) { citation_form = create_form_citation_form(); @@ -257,7 +257,7 @@ string InsetBibKey::getScreenLabel() const void InsetBibKey::Edit(int, int) { if(current_view->buffer()->isReadonly()) - WarnReadonly(); + WarnReadonly(current_view->buffer()->fileName()); if (!bibitem_form) { bibitem_form = create_form_bibitem_form(); diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index ebde3c0049..540552af24 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -230,7 +230,7 @@ Inset * InsetInclude::Clone() const void InsetInclude::Edit(int, int) { if(current_view->buffer()->isReadonly()) - WarnReadonly(); + WarnReadonly(current_view->buffer()->fileName()); if (!form) { form = create_form_include(); diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index 1156066e6d..e393abc4fb 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -13,7 +13,7 @@ #include "LaTeXFeatures.h" #include "gettext.h" #include "LString.h" -#include "lyx_gui_misc.h" // WarnReadonly() +#include "lyx_gui_misc.h" // WarnReadonly extern BufferView * current_view; extern void UpdateInset(Inset * inset, bool mark_dirty = true); @@ -89,7 +89,7 @@ InsetIndex::~InsetIndex() void InsetIndex::Edit(int, int) { if(current_view->buffer()->isReadonly()) - WarnReadonly(); + WarnReadonly(current_view->buffer()->fileName()); if (!index_form) index_form = create_form_index_form(); diff --git a/src/insets/insetinfo.C b/src/insets/insetinfo.C index 8ccb50e0ba..24cc383658 100644 --- a/src/insets/insetinfo.C +++ b/src/insets/insetinfo.C @@ -183,7 +183,7 @@ void InsetInfo::Edit(int, int) static int ow = -1, oh; if(current_view->buffer()->isReadonly()) - WarnReadonly(); + WarnReadonly(current_view->buffer()->fileName()); if (!form) { FL_OBJECT *obj; diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index d6e8cbabe7..2b6b414848 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -112,7 +112,7 @@ void InsetUrl::Edit(int, int) static int ow = -1, oh; if(current_view->buffer()->isReadonly()) - WarnReadonly(); + WarnReadonly(current_view->buffer()->fileName()); if (!fd_form_url) { fd_form_url = create_form_form_url(); diff --git a/src/intl.C b/src/intl.C index eebc879f39..c98f6b260f 100644 --- a/src/intl.C +++ b/src/intl.C @@ -66,9 +66,9 @@ int Intl::SetSecondary(string const & lang) void Intl::update() { - int off, prim, sec; - - off = prim = sec = 0; + int off = 0; + int prim = 0; + int sec = 0; if (!keymapon) { off = 1; @@ -219,11 +219,13 @@ void Intl::DispatchCallback(FL_OBJECT * ob, long code) if (itl!= 0) itl->Keymap(code); } + extern "C" void C_Intl_DispatchCallback(FL_OBJECT * ob, long code) { Intl::DispatchCallback(ob, code); } + void Intl::InitKeyMapper(bool on) /* initialize key mapper */ { @@ -291,7 +293,7 @@ void Intl::InitKeyMapper(bool on) Language->addto(_("other...")); Language2->addto(_("other...")); - otherkeymap = n+1; + otherkeymap = n + 1; if (!Language->select_text(prim_lang.c_str())) { Language->select(n+1); fl_set_input(fd_form_keymap->OtherKeymap, prim_lang.c_str()); @@ -300,7 +302,7 @@ void Intl::InitKeyMapper(bool on) trans->SetPrimary(prim_lang); if (!Language2->select_text(sec_lang.c_str())) { - Language2->select(n+1); + Language2->select(n + 1); fl_set_input(fd_form_keymap->OtherKeymap2, sec_lang.c_str()); } else @@ -319,6 +321,9 @@ void Intl::Keymap(long code) if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "KeyMap callback: " << code << endl; + // Did you wonder if it is possible to write spagetti code with + // other constructs thatn goto's? Well here we have a nice small + // spagetti example using a switch... (Lgb) switch (code) { case 0: /* cancel/hide */ diff --git a/src/kbmap.C b/src/kbmap.C index ca24e92654..3a491f334d 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -40,7 +40,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(KeySym key, unsigned int mod, string & buf) { mod &= ModsMask; @@ -64,7 +64,7 @@ void printKeysym( KeySym key, unsigned int mod, string & buf) \* ---F------------------------------------------------------------------- */ static -void printKeyTab( kb_key * tabPt, string & buf) +void printKeyTab(kb_key * tabPt, string & buf) { unsigned int ksym, mod; @@ -131,59 +131,55 @@ int kb_sequence::addkey(KeySym key, int kb_sequence::parse(char const * s) { + if(!s[0]) return 1; + int i = 0; unsigned int mod = 0, nmod = 0; - KeySym key = 0; - char tbuf[100]; - - if(!s[0]) return 1; - while(s[i]) { if(s[i] && (s[i]) <= ' ') ++i; if(!s[i]) break; - if(s[i+1] == '-') { // is implicit that s[i] == true + if(s[i + 1] == '-') { // is implicit that s[i] == true switch(s[i]) { case 's': case 'S': mod |= ShiftMask; - i+= 2; + i += 2; continue; case 'c': case 'C': mod |= ControlMask; - i+= 2; + i += 2; continue; case 'm': case 'M': mod |= Mod1Mask; - i+= 2; + i += 2; continue; default: - return i+1; + return i + 1; } - } else if(s[i] == '~' && s[i+1] && s[i+2] == '-') { - switch(s[i+1]) { + } else if(s[i] == '~' && s[i + 1] && s[i + 2] == '-') { + switch(s[i + 1]) { case 's': case 'S': nmod |= ShiftMask; - i+= 3; + i += 3; continue; case 'c': case 'C': nmod |= ControlMask; - i+= 3; + i += 3; continue; case 'm': case 'M': nmod |= Mod1Mask; - i+= 3; + i += 3; continue; default: - return i+2; + return i + 2; } } else { - int j = 0; - for(j = i; s[j] && s[j] > ' '; ++j) - tbuf[j-i] = s[j]; // (!!!check bounds :-) + string tbuf; + int j = i; + for(; s[j] && s[j] > ' '; ++j) + tbuf += s[j]; // (!!!check bounds :-) - tbuf[j-i] = '\0'; - - key = XStringToKeysym(tbuf); + KeySym key = XStringToKeysym(tbuf.c_str()); if(key == NoSymbol) { lyxerr[Debug::KBMAP] << "kbmap.C: No such keysym: " @@ -282,7 +278,7 @@ KeySym kb_sequence::getsym() int l = length; if(l == 0) return NoSymbol; if(l < 0) l = -l; - return sequence[l-1]; + return sequence[l - 1]; } @@ -316,7 +312,7 @@ void kb_sequence::reset() { delseq(); curmap = stdmap; - if ( length > 0 ) length = -length; + if (length > 0) length = -length; } @@ -368,7 +364,7 @@ int kb_keymap::lookup(KeySym key, unsigned int mod, kb_sequence * seq) #ifndef NO_HASH if(size < 0) { // --- if hash table --- - hashval = ((key&0xff) ^ ((key>>8)&0xff)) % KB_HASHSIZE; + hashval = ((key & 0xff) ^ ((key >> 8) & 0xff)) % KB_HASHSIZE; tab = htable[hashval]; if(!tab) { seq->curmap = seq->stdmap; @@ -381,7 +377,7 @@ int kb_keymap::lookup(KeySym key, unsigned int mod, kb_sequence * seq) // --- now search the list of keys --- - for( ; (tab->code & 0xffff) != NoSymbol; ++tab) { + for(; (tab->code & 0xffff) != NoSymbol; ++tab) { ksym = tab->code; msk1 = tab->mod & 0xffff; msk0 = (tab->mod >> 16) & 0xffff; @@ -485,7 +481,7 @@ int kb_keymap::defkey(kb_sequence * seq, int action, int idx /*= 0*/) int tsize; for(t = tab, tsize = 1; t->code != NoSymbol; ++t, ++tsize) { if(code == t->code && modmsk == t->mod) { // -- overwrite binding --- - if(idx+1 == seq->length) { + if(idx + 1 == seq->length) { string buf; seq->print(buf, true); lyxerr[Debug::KEY] diff --git a/src/layout.h b/src/layout.h index ad4c598b4c..3926f99bbe 100644 --- a/src/layout.h +++ b/src/layout.h @@ -338,6 +338,8 @@ class LyXTextClass { public: /// typedef vector LayoutList; + /// + typedef LayoutList::const_iterator const_iterator; /// LyXTextClass (string const & = string(), @@ -345,9 +347,9 @@ public: string const & = string()); /// - LayoutList::const_iterator begin() const { return layoutlist.begin(); } + const_iterator begin() const { return layoutlist.begin(); } /// - LayoutList::const_iterator end() const { return layoutlist.end(); } + const_iterator end() const { return layoutlist.end(); } /// bool Read(string const & filename, bool merge = false); @@ -507,6 +509,13 @@ class LyXTextClassList { public: /// typedef vector ClassList; + /// + typedef ClassList::const_iterator const_iterator; + /// + const_iterator begin() const { return classlist.begin(); } + /// + const_iterator end() const { return classlist.end(); } + /// Gets layout structure from layout number and textclass number LyXLayout const & Style(ClassList::size_type textclass, LyXTextClass::LayoutList::size_type layout) const; diff --git a/src/lyx_gui.C b/src/lyx_gui.C index 1cd33780bf..9305d9afce 100644 --- a/src/lyx_gui.C +++ b/src/lyx_gui.C @@ -45,29 +45,29 @@ #include "banner.xpm" #endif -FD_form_title *fd_form_title; -FD_form_paragraph *fd_form_paragraph; -FD_form_paragraph_extra *fd_form_paragraph_extra; -FD_form_search *fd_form_search; -FD_form_character *fd_form_character; -FD_form_document *fd_form_document; -FD_form_paper *fd_form_paper; -FD_form_table_options *fd_form_table_options; -FD_form_table_extra *fd_form_table_extra; -FD_form_quotes *fd_form_quotes; -FD_form_preamble *fd_form_preamble; -FD_form_table *fd_form_table; -FD_form_print *fd_form_print; -FD_form_sendto *fd_form_sendto; -FD_form_figure *fd_form_figure; -FD_form_screen *fd_form_screen; -FD_form_toc *fd_form_toc; -FD_form_ref *fd_form_ref; -FD_LaTeXOptions *fd_latex_options; // from latexoptions.h -FD_LaTeXLog *fd_latex_log; // from latexoptions.h -Combox *combo_language; - -extern LyXServer *lyxserver; +FD_form_title * fd_form_title; +FD_form_paragraph * fd_form_paragraph; +FD_form_paragraph_extra * fd_form_paragraph_extra; +FD_form_search * fd_form_search; +FD_form_character * fd_form_character; +FD_form_document * fd_form_document; +FD_form_paper * fd_form_paper; +FD_form_table_options * fd_form_table_options; +FD_form_table_extra * fd_form_table_extra; +FD_form_quotes * fd_form_quotes; +FD_form_preamble * fd_form_preamble; +FD_form_table * fd_form_table; +FD_form_print * fd_form_print; +FD_form_sendto * fd_form_sendto; +FD_form_figure * fd_form_figure; +FD_form_screen * fd_form_screen; +FD_form_toc * fd_form_toc; +FD_form_ref * fd_form_ref; +FD_LaTeXOptions * fd_latex_options; // from latexoptions.h +FD_LaTeXLog * fd_latex_log; // from latexoptions.h +Combox * combo_language; + +extern LyXServer * lyxserver; extern bool finished; // flag, that we are quitting the program extern BufferList bufferlist; @@ -161,8 +161,8 @@ extern "C" int LyX_XErrHandler(Display * display, XErrorEvent * xeev) } -LyXGUI::LyXGUI(LyX *owner, int *argc, char *argv[], bool GUI) - :_owner(owner) +LyXGUI::LyXGUI(LyX * owner, int * argc, char * argv[], bool GUI) + : _owner(owner) { gui = GUI; if (!gui) @@ -197,7 +197,8 @@ LyXGUI::LyXGUI(LyX *owner, int *argc, char *argv[], bool GUI) // A destructor is always necessary (asierra-970604) -LyXGUI::~LyXGUI() { +LyXGUI::~LyXGUI() +{ // Lyxserver was created in this class so should be destroyed // here. asierra-970604 if (lyxserver) { @@ -441,20 +442,20 @@ void LyXGUI::create_forms() fl_set_counter_precision(fd_form_document->slider_tocdepth, 0); fl_addto_form(fd_form_document->form_document); combo_language = new Combox(FL_COMBOX_DROPLIST); - FL_OBJECT *ob = fd_form_document->choice_language; + FL_OBJECT * ob = fd_form_document->choice_language; combo_language->add(ob->x, ob->y, ob->w, ob->h, 200); combo_language->shortcut("#G", 1); fl_end_form(); int n; // declared here because DEC cxx does not like multiple // declarations of variables in for() loops (JMarc) - for (n = 0; tex_babel[n][0]; n++) { + for (n = 0; tex_babel[n][0]; ++n) { combo_language->addto(tex_babel[n]); } // not really necessary, but we can do it anyway. fl_addto_choice(fd_form_document->choice_fontsize, "default|10|11|12"); - for (n = 0; tex_fonts[n][0]; n++) { + for (n = 0; tex_fonts[n][0]; ++n) { fl_addto_choice(fd_form_document->choice_fonts, tex_fonts[n]); } @@ -462,7 +463,7 @@ void LyXGUI::create_forms() "default|latin1|latin2|latin5" "|koi8-r|koi8-u|cp866|cp1251"); - for (n = 0; tex_graphics[n][0]; n++) { + for (n = 0; tex_graphics[n][0]; ++n) { fl_addto_choice(fd_form_document->choice_postscript_driver, tex_graphics[n]); } @@ -639,7 +640,7 @@ void LyXGUI::runTime() } -void LyXGUI::regBuf(Buffer *b) +void LyXGUI::regBuf(Buffer * b) { lyxViews->view()->buffer(b); } diff --git a/src/lyx_gui_misc.C b/src/lyx_gui_misc.C index 70bfeb83b2..1084810b02 100644 --- a/src/lyx_gui_misc.C +++ b/src/lyx_gui_misc.C @@ -32,7 +32,7 @@ #include "insets/insetindex.h" #include "LyXView.h" -extern BufferView *current_view; +extern BufferView * current_view; extern FD_form_paragraph * fd_form_paragraph; extern FD_form_paragraph_extra * fd_form_paragraph_extra; @@ -305,39 +305,41 @@ void updateAllVisibleBufferRelatedPopups() } // Extract shortcut from | string -const char* flyx_shortcut_extract(const char*sc) +char const * flyx_shortcut_extract(char const * sc) { // Find '|' in the sc and return the string after that. - register char const *sd = sc; - while(sd[0]!= 0 && sd[0] != '|') sd++; + register char const * sd = sc; + while(sd[0]!= 0 && sd[0] != '|') ++sd; if (sd[0] == '|') { - sd++; + ++sd; //lyxerr << sd << endl; return sd; } return ""; } + // Extract identifier from | string -const char* flyx_ident_extract(char const *sc) +char const * flyx_ident_extract(char const * sc) { - register char const *se = sc; - while(se[0]!= 0 && se[0] != '|') se++; + register char const * se = sc; + while(se[0]!= 0 && se[0] != '|') ++se; if (se[0] == 0) return sc; - char * sb = new char[se-sc + 1]; + char * sb = new char[se - sc + 1]; int index = 0; - register char const *sd = sc; + register char const * sd = sc; while (sd != se) { sb[index] = sd[0]; - index++; sd++; + ++index; ++sd; } sb[index] = 0; return sb; } + // void WriteAlert(string const & s1, string const & s2, string const & s3) { @@ -375,6 +377,7 @@ bool AskQuestion(string const & s1, string const & s2, string const & s3) #endif } + // Returns 1 for yes, 2 for no, 3 for cancel. int AskConfirmation(string const & s1, string const & s2, string const & s3) { @@ -399,7 +402,7 @@ int AskConfirmation(string const & s1, string const & s2, string const & s3) // Asks for a text string askForText(string const & msg, string const & dflt) { - const char * tmp; + char const * tmp; fl_set_resource("flInput.cancel.label", idex(_("Cancel|^["))); fl_set_resource("flInput.ok.label", idex(_("OK|#O"))); fl_set_resource("flInput.clear.label", idex(_("Clear|#e"))); @@ -410,12 +413,12 @@ string askForText(string const & msg, string const & dflt) return string(); } + // Inform the user that the buffer is read-only, and that changes in the // dialog box that is to appear will be ignored. -void WarnReadonly() +void WarnReadonly(string const & file) { WriteAlert(_("Any changes will be ignored"), _("The document is read-only:"), - current_view->buffer()->fileName()); + file); } - diff --git a/src/lyx_gui_misc.h b/src/lyx_gui_misc.h index c7291eb142..a8d3eb203d 100644 --- a/src/lyx_gui_misc.h +++ b/src/lyx_gui_misc.h @@ -1,13 +1,13 @@ // -*- C++ -*- /* This file is part of -* ====================================================== -* -* LyX, The Document Processor -* -* Copyright (C) 1995 1996 Matthias Ettrich -* and the LyX Team. -* -* ====================================================== */ + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 1996 Matthias Ettrich + * Copyright 1995-1999 The LyX Team + * + * ====================================================== */ // Misc. GUI specific routines @@ -29,12 +29,12 @@ void CloseAllBufferRelatedPopups(); void updateAllVisibleBufferRelatedPopups(); /// Extract shortcut from | string -const char* flyx_shortcut_extract(const char*sc); +char const * flyx_shortcut_extract(char const * sc); /// Make a shortnamed version of the above func #define scex flyx_shortcut_extract /// Extract shortcut from | string -const char* flyx_ident_extract(char const *sc); +char const * flyx_ident_extract(char const * sc); /// Make a shortnamed versjon of the above func #define idex flyx_ident_extract @@ -57,7 +57,7 @@ int AskConfirmation(string const & s1, string const & s2 = string(), string askForText(string const & msg, string const & dflt = string()); /// Informs the user that changes in the coming form will be ignored -void WarnReadonly(); +void WarnReadonly(string const & file); // inlined functions /// rings the audio bell. diff --git a/src/support/LAssert.h b/src/support/LAssert.h index 2614603acb..20be3713c5 100644 --- a/src/support/LAssert.h +++ b/src/support/LAssert.h @@ -32,7 +32,7 @@ template inline void Assert(A * ptr) #else -template inline void Assert(A /*assertion*/) {;} +template inline void Assert(A /*assertion*/) {} #endif /* ENABLE_ASSERTIONS */ diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 573c6a0a36..06875d2159 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -89,14 +89,6 @@ int strToInt(string const & str) string lowercase(string const & a) { -#if 0 - string tmp; - string::const_iterator cit = a.begin(); - for(; cit != a.end(); ++cit) { - tmp += static_cast(tolower(*cit)); - } - return tmp; -#endif string tmp(a); transform(tmp.begin(), tmp.end(), tmp.begin(), tolower); return tmp; @@ -159,14 +151,6 @@ string tostr(bool b) } -#if 0 -string tostr(float f) -{ - return tostr(double(f)); -} -#endif - - string tostr(double d) { // should use string stream @@ -234,9 +218,15 @@ bool contains(char const * a, char const * b) } -int countChar(string const & a, char const c) +unsigned int countChar(string const & a, char const c) { +#ifdef HAVE_STD_COUNT return count(a.begin(), a.end(), c); +#else + unsigned int n = 0; + count(a.begin(), a.end(), c, n); + return n; +#endif } diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 0769ba2618..f111031658 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -119,7 +119,7 @@ bool contains(string const & a, string const & b); bool contains(char const * a, char const * b); /// Counts how many of character c there is in a -int countChar(string const & a, char const c); +unsigned int countChar(string const & a, char const c); /** Extracts a token from this string at the nth delim. Doesn't modify the original string. Similar to strtok. diff --git a/src/support/lyxstring.h b/src/support/lyxstring.h index d348deedb2..4d3339e95e 100644 --- a/src/support/lyxstring.h +++ b/src/support/lyxstring.h @@ -4,8 +4,8 @@ * * LyX, The Document Processor * - * Copyright (C) 1995 Matthias Ettrich - * Copyright (C) 1995-1999 The LyX Team. + * Copyright 1995 Matthias Ettrich + * Copyright 1995-1999 The LyX Team. * * ====================================================== */ diff --git a/src/text.C b/src/text.C index 5fcfce8539..18fb9d0b51 100644 --- a/src/text.C +++ b/src/text.C @@ -1,12 +1,12 @@ /* This file is part of -* ====================================================== -* -* LyX, The Document Processor -* -* Copyright (C) 1995 Matthias Ettrich -* Copyright (C) 1995-1998 The LyX Team. -* -* ====================================================== */ + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-1999 The LyX Team. + * + * ====================================================== */ #include #include @@ -702,7 +702,7 @@ LyXText::NextBreakPoint(Row * row, int width) /* returns the minimum space a row needs on the screen in pixel */ -int LyXText::Fill(Row * row, int paperwidth) +int LyXText::Fill(Row * row, int paper_width) { int w, fill; /* get the pure distance */ @@ -767,7 +767,7 @@ int LyXText::Fill(Row * row, int paperwidth) } } - fill = paperwidth - w - RightMargin(row); + fill = paper_width - w - RightMargin(row); return fill; } diff --git a/src/text2.C b/src/text2.C index 70580c4a00..c012715c5f 100644 --- a/src/text2.C +++ b/src/text2.C @@ -744,10 +744,10 @@ void LyXText::SetFont(LyXFont font, bool toggleall) } -void LyXText::RedoHeightOfParagraph(LyXCursor cursor) +void LyXText::RedoHeightOfParagraph(LyXCursor cur) { - Row * tmprow = cursor.row; - long y = cursor.y - tmprow->baseline; + Row * tmprow = cur.row; + long y = cur.y - tmprow->baseline; SetHeightOfRow(tmprow); LyXParagraph * first_phys_par = tmprow->par->FirstPhysicalPar(); @@ -768,15 +768,15 @@ void LyXText::RedoHeightOfParagraph(LyXCursor cursor) status = LyXText::NEED_MORE_REFRESH; refresh_y = y; refresh_row = tmprow; - SetCursor(cursor.par, cursor.pos); + SetCursor(cur.par, cur.pos); } -void LyXText::RedoDrawingOfParagraph(LyXCursor cursor) +void LyXText::RedoDrawingOfParagraph(LyXCursor cur) { - Row * tmprow = cursor.row; + Row * tmprow = cur.row; - long y = cursor.y - tmprow->baseline; + long y = cur.y - tmprow->baseline; SetHeightOfRow(tmprow); LyXParagraph * first_phys_par = tmprow->par->FirstPhysicalPar(); /* find the first row of the paragraph */ @@ -797,21 +797,21 @@ void LyXText::RedoDrawingOfParagraph(LyXCursor cursor) refresh_row = tmprow; } status = LyXText::NEED_MORE_REFRESH; - SetCursor(cursor.par, cursor.pos); + SetCursor(cur.par, cur.pos); } /* deletes and inserts again all paragaphs between the cursor * and the specified par * This function is needed after SetLayout and SetFont etc. */ -void LyXText::RedoParagraphs(LyXCursor cursor, LyXParagraph * endpar) +void LyXText::RedoParagraphs(LyXCursor cur, LyXParagraph * endpar) { Row * tmprow2; LyXParagraph * tmppar, * first_phys_par; - Row * tmprow = cursor.row; + Row * tmprow = cur.row; - long y = cursor.y - tmprow->baseline; + long y = cur.y - tmprow->baseline; if (!tmprow->previous){ first_phys_par = FirstParagraph(); // a trick/hack for UNDO @@ -3482,27 +3482,25 @@ void LyXText::SetCursorParUndo() cursor.par->ParFromPos(cursor.pos)->next); } -void LyXText::RemoveTableRow(LyXCursor * cursor) +void LyXText::RemoveTableRow(LyXCursor * cur) { - int - cell_act, - cell = -1, - cell_org = 0, - ocell = 0; + int cell = -1; + int cell_org = 0; + int ocell = 0; /* move to the previous row */ - cell_act = NumberOfCell(cursor->par, cursor->pos); + int cell_act = NumberOfCell(cur->par, cur->pos); if (cell < 0) cell = cell_act; - while (cursor->pos && !cursor->par->IsNewline(cursor->pos-1)) - cursor->pos--; - while (cursor->pos && - !cursor->par->table->IsFirstCell(cell_act)){ - cursor->pos--; - while (cursor->pos && !cursor->par->IsNewline(cursor->pos-1)) - cursor->pos--; - cell--; - cell_act--; + while (cur->pos && !cur->par->IsNewline(cur->pos - 1)) + cur->pos--; + while (cur->pos && + !cur->par->table->IsFirstCell(cell_act)) { + cur->pos--; + while (cur->pos && !cur->par->IsNewline(cur->pos - 1)) + cur->pos--; + --cell; + --cell_act; } /* now we have to pay attention if the actual table is the main row of TableContRows and if yes to delete all of them */ @@ -3511,25 +3509,25 @@ void LyXText::RemoveTableRow(LyXCursor * cursor) do { ocell = cell; /* delete up to the next row */ - while (cursor->pos < cursor->par->Last() && + while (cur->pos < cur->par->Last() && (cell_act == ocell - || !cursor->par->table->IsFirstCell(cell_act))){ - while (cursor->pos < cursor->par->Last() && - !cursor->par->IsNewline(cursor->pos)) - cursor->par->Erase(cursor->pos); - cell++; - cell_act++; - if (cursor->pos < cursor->par->Last()) - cursor->par-> Erase(cursor->pos); + || !cur->par->table->IsFirstCell(cell_act))) { + while (cur->pos < cur->par->Last() && + !cur->par->IsNewline(cur->pos)) + cur->par->Erase(cur->pos); + ++cell; + ++cell_act; + if (cur->pos < cur->par->Last()) + cur->par->Erase(cur->pos); } - if (cursor->pos && cursor->pos == cursor->par->Last()){ - cursor->pos--; - cursor->par->Erase(cursor->pos); // no newline at the very end! + if (cur->pos && cur->pos == cur->par->Last()) { + cur->pos--; + cur->par->Erase(cur->pos); // no newline at the very end! } - } while (((cell+1) < cursor->par->table->GetNumberOfCells()) && - !cursor->par->table->IsContRow(cell_org) && - cursor->par->table->IsContRow(cell)); - cursor->par->table->DeleteRow(cell_org); + } while (((cell + 1) < cur->par->table->GetNumberOfCells()) && + !cur->par->table->IsContRow(cell_org) && + cur->par->table->IsContRow(cell)); + cur->par->table->DeleteRow(cell_org); return; } diff --git a/src/trans.C b/src/trans.C index ee3b985ff8..c35a99530f 100644 --- a/src/trans.C +++ b/src/trans.C @@ -64,9 +64,7 @@ Trans::~Trans() void Trans::InsertException(Trans::keyexc & exclist, char c, string const & data, bool flag, tex_accent accent) { - keyexc p; - - p = new Keyexc; + keyexc p = new Keyexc; p->next = exclist; p->c = c; @@ -259,12 +257,11 @@ int Trans::Load(LyXLex & lex) break; case KMAP: { unsigned char key_from; - char * string_to; if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "KMAP:\t" << lex.text() << endl; if (lex.next(true)) { - key_from= lex.text()[0]; + key_from = lex.text()[0]; if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "\t`" << lex.text() << "'" << endl; @@ -273,7 +270,8 @@ int Trans::Load(LyXLex & lex) if (lex.next(true)) { char const * t = lex.text(); - string_to = strcpy(new char[strlen(t)+1], t); + char * string_to = + strcpy(new char[strlen(t)+1], t); keymap_[key_from] = string_to; if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "\t`" << string_to << "'" diff --git a/src/trans_decl.h b/src/trans_decl.h index 1b2937f16a..e4052f975a 100644 --- a/src/trans_decl.h +++ b/src/trans_decl.h @@ -25,12 +25,7 @@ struct KmodInfo { tex_accent accent; string allowed; KmodException exception_list; - - - //KmodInfo(const KmodInfo&); KmodInfo(); - - //KmodInfo& operator= (const KmodInfo&); }; #endif diff --git a/src/trans_mgr.C b/src/trans_mgr.C index 02b5719193..26beac92ef 100644 --- a/src/trans_mgr.C +++ b/src/trans_mgr.C @@ -26,9 +26,9 @@ extern BufferView * current_view; // TransFSMData TransFSMData::TransFSMData() { - deadkey_ = deadkey2_ = 0; - deadkey_info_.accent = deadkey2_info_.accent = TEX_NOACCENT; - comb_info_ = 0; + deadkey_ = deadkey2_ = 0; + deadkey_info_.accent = deadkey2_info_.accent = TEX_NOACCENT; + comb_info_ = 0; } @@ -39,175 +39,172 @@ char const TransState::TOKEN_SEP = 4; // TransInitState TransInitState::TransInitState() { - init_state_ = this; + init_state_ = this; } string TransInitState::normalkey(char c, char * t) { - string res; - if (t != 0) - res = t; - else - res = c; + string res; + if (t) res = t; + else res = c; - return res; + return res; } string TransInitState::deadkey(char c, KmodInfo d) { - deadkey_ = c; - deadkey_info_ = d; - currentState = deadkey_state_; - return string(); + deadkey_ = c; + deadkey_info_ = d; + currentState = deadkey_state_; + return string(); } // TransDeadkeyState TransDeadkeyState::TransDeadkeyState() { - deadkey_state_ = this; + deadkey_state_ = this; } string TransDeadkeyState::normalkey(char c, char * trans) { - string res; - - // Check if it is an exception - KmodException l = deadkey_info_.exception_list; - while(l != 0) { - if (l->c == c) { - res = l->data; - break; + string res; + + // Check if it is an exception + KmodException l = deadkey_info_.exception_list; + while(l != 0) { + if (l->c == c) { + res = l->data; + break; + } + l = l->next; } - l = l->next; - } - if (l == 0) { - // Not an exception. Check if it allowed - if (current_view->buffer()->params.allowAccents == true || - countChar(deadkey_info_.allowed, c) > 0) { - res = DoAccent(c, deadkey_info_.accent); - } else { - // Not allowed - if (deadkey_!= 0) - res = deadkey_; - res+= TOKEN_SEP; - res+= trans; + if (l == 0) { + // Not an exception. Check if it allowed + if (current_view->buffer()->params.allowAccents == true || + countChar(deadkey_info_.allowed, c) > 0) { + res = DoAccent(c, deadkey_info_.accent); + } else { + // Not allowed + if (deadkey_!= 0) + res = deadkey_; + res+= TOKEN_SEP; + res+= trans; + } } - } - currentState = init_state_; - return res; + currentState = init_state_; + return res; } string TransDeadkeyState::deadkey(char c, KmodInfo d) { - string res; - - // Check if the same deadkey was typed twice - if (deadkey_ == c) { - res = deadkey_; - deadkey_ = 0; - deadkey_info_.accent = TEX_NOACCENT; - currentState = init_state_; - return res; - } - - // Check if it is a combination or an exception - KmodException l; - l = deadkey_info_.exception_list; - - while(l) { - if (l->combined == true && l->accent == d.accent) { - deadkey2_ = c; - deadkey2_info_ = d; - comb_info_ = l; - currentState = combined_state_; - return string(); + string res; + + // Check if the same deadkey was typed twice + if (deadkey_ == c) { + res = deadkey_; + deadkey_ = 0; + deadkey_info_.accent = TEX_NOACCENT; + currentState = init_state_; + return res; } - if (l->c == c) { - res = l->data; - deadkey_ = 0; - deadkey_info_.accent = TEX_NOACCENT; - currentState = init_state_; - return res; + + // Check if it is a combination or an exception + KmodException l; + l = deadkey_info_.exception_list; + + while(l) { + if (l->combined == true && l->accent == d.accent) { + deadkey2_ = c; + deadkey2_info_ = d; + comb_info_ = l; + currentState = combined_state_; + return string(); + } + if (l->c == c) { + res = l->data; + deadkey_ = 0; + deadkey_info_.accent = TEX_NOACCENT; + currentState = init_state_; + return res; + } + l = l->next; } - l = l->next; - } - - // Not a combination or an exception. - // Output deadkey1 and keep deadkey2 - - if (deadkey_!= 0) - res = deadkey_; - deadkey_ = c; - deadkey_info_ = d; - currentState = deadkey_state_; - return res; + // Not a combination or an exception. + // Output deadkey1 and keep deadkey2 + + if (deadkey_!= 0) + res = deadkey_; + deadkey_ = c; + deadkey_info_ = d; + currentState = deadkey_state_; + return res; } TransCombinedState::TransCombinedState() { - combined_state_ = this; + combined_state_ = this; } -string TransCombinedState::normalkey(char c, char *trans) +string TransCombinedState::normalkey(char c, char * trans) { - string res; - - // Check if the key is allowed on the combination - if (countChar(comb_info_->data, c) > 0) { - string temp; - temp = DoAccent(c, deadkey2_info_.accent); - res = DoAccent(temp, deadkey_info_.accent); - currentState = init_state_; - } else { - // Not allowed. Output deadkey1 and check deadkey2 + c - if (deadkey_!= 0) - res+= deadkey_; - res+= TOKEN_SEP; - deadkey_ = deadkey2_; - deadkey_info_ = deadkey2_info_; - // Call deadkey state and leave it to setup the FSM - res+= deadkey_state_->normalkey(c, trans); - } - return res; + string res; + + // Check if the key is allowed on the combination + if (countChar(comb_info_->data, c) > 0) { + string temp; + temp = DoAccent(c, deadkey2_info_.accent); + res = DoAccent(temp, deadkey_info_.accent); + currentState = init_state_; + } else { + // Not allowed. Output deadkey1 and check deadkey2 + c + if (deadkey_ != 0) + res += deadkey_; + res += TOKEN_SEP; + deadkey_ = deadkey2_; + deadkey_info_ = deadkey2_info_; + // Call deadkey state and leave it to setup the FSM + res += deadkey_state_->normalkey(c, trans); + } + return res; } string TransCombinedState::deadkey(char c, KmodInfo d) { - // Third key in a row. Output the first one and - // reenter with shifted deadkeys - string res; - if (deadkey_ != 0) - res = deadkey_; - res += TOKEN_SEP; - deadkey_ = deadkey2_; - deadkey_info_ = deadkey2_info_; - res += deadkey_state_->deadkey(c, d); - return res; + // Third key in a row. Output the first one and + // reenter with shifted deadkeys + string res; + if (deadkey_ != 0) + res = deadkey_; + res += TOKEN_SEP; + deadkey_ = deadkey2_; + deadkey_info_ = deadkey2_info_; + res += deadkey_state_->deadkey(c, d); + return res; } // TransFSM TransFSM::TransFSM(): - TransFSMData(), - TransInitState(), - TransDeadkeyState(), - TransCombinedState() + TransFSMData(), + TransInitState(), + TransDeadkeyState(), + TransCombinedState() { - currentState = init_state_; + currentState = init_state_; } // TransManager - + TransManager::TransManager() : active_(0), t1_(new Trans), t2_(new Trans) {} @@ -218,85 +215,85 @@ Trans * TransManager::default_ = new Trans; TransManager::~TransManager() { - delete t1_; - delete t2_; + delete t1_; + delete t2_; } int TransManager::SetPrimary(string const & language) { - if (t1_->GetName() == language) - return 0; + if (t1_->GetName() == language) + return 0; - return t1_->Load(language); + return t1_->Load(language); } int TransManager::SetSecondary(string const & language) { - if (t2_->GetName() == language) - return 0; + if (t2_->GetName() == language) + return 0; - return t2_->Load(language); + return t2_->Load(language); } bool TransManager::setCharset(char const * set) { - return chset_.loadFile(set); + return chset_.loadFile(set); } void TransManager::EnablePrimary() { - if (t1_->IsDefined()) - active_ = t1_; - - lyxerr[Debug::KBMAP] << "Enabling primary keymap" << endl; + if (t1_->IsDefined()) + active_ = t1_; + + lyxerr[Debug::KBMAP] << "Enabling primary keymap" << endl; } void TransManager::EnableSecondary() { - if (t2_->IsDefined( )) - active_ = t2_; - lyxerr[Debug::KBMAP] << "Enabling secondary keymap" << endl; + if (t2_->IsDefined()) + active_ = t2_; + lyxerr[Debug::KBMAP] << "Enabling secondary keymap" << endl; } void TransManager::DisableKeymap() { - active_ = default_; - lyxerr[Debug::KBMAP] << "Disabling keymap" << endl; + active_ = default_; + lyxerr[Debug::KBMAP] << "Disabling keymap" << endl; } void TransManager::TranslateAndInsert(char c, LyXText * text) { - string res = active_->process(c, *this); - - // Process with tokens - string temp; + string res = active_->process(c, *this); + + // Process with tokens + string temp; - while(res.length() > 0) { - res = split(res, temp, TransState::TOKEN_SEP); - insert(temp, text); - } + while(res.length() > 0) { + res = split(res, temp, TransState::TOKEN_SEP); + insert(temp, text); + } } void TransManager::insertVerbatim(string const & str, LyXText * text) { - int l = str.length(); + int l = str.length(); - for (int i = 0; i < l; ++i){ - if (str[i] == '\"' - && text->GetFont(text->cursor.par, - text->cursor.pos).latex() == LyXFont::OFF) - InsertCorrectQuote(); - else - text->InsertChar(str[i]); - } + for (int i = 0; i < l; ++i){ + if (str[i] == '\"' + && text->GetFont(text->cursor.par, + text->cursor.pos).latex() == LyXFont::OFF) + InsertCorrectQuote(); + else + text->InsertChar(str[i]); + } } @@ -305,7 +302,7 @@ void TransManager::insert(string str, LyXText * text) // Go through the character encoding only if the current // encoding (chset_->name()) matches the current font_norm // (lyrxc->font_norm - + // Is false to speak about "only if" the current encoding will // almost always be equal to font_norm. pair enc = chset_.encodeString(str); @@ -327,30 +324,28 @@ void TransManager::insert(string str, LyXText * text) void TransManager::deadkey(char c, tex_accent accent, LyXText * t) { - KmodInfo i; - string res; - - if (c == 0 && active_ != default_) { - // A deadkey was pressed that cannot be printed - // or a accent command was typed in the minibuffer - - if (active_->isAccentDefined(accent, i) == true) { - res = trans_fsm_.currentState->deadkey(c, i); - insert(res, t); - return; + if (c == 0 && active_ != default_) { + // A deadkey was pressed that cannot be printed + // or a accent command was typed in the minibuffer + KmodInfo i; + if (active_->isAccentDefined(accent, i) == true) { + string res = trans_fsm_.currentState->deadkey(c, i); + insert(res, t); + return; + } } - } - - if (active_ == default_ || c == 0) { - i.accent = accent; - i.allowed = lyx_accent_table[accent].native; - i.data.clear(); - i.exception_list = 0; - string res = trans_fsm_.currentState->deadkey(c, i); - insert(res, t); - } else { - // Go through the translation - TranslateAndInsert(c, t); - } + if (active_ == default_ || c == 0) { + KmodInfo i; + i.accent = accent; + i.allowed = lyx_accent_table[accent].native; + i.data.clear(); + i.exception_list = 0; + + string res = trans_fsm_.currentState->deadkey(c, i); + insert(res, t); + } else { + // Go through the translation + TranslateAndInsert(c, t); + } } diff --git a/src/trans_mgr.h b/src/trans_mgr.h index 7e23cc46dd..93cc95adfe 100644 --- a/src/trans_mgr.h +++ b/src/trans_mgr.h @@ -61,38 +61,37 @@ public: /// Init State -class TransInitState: +class TransInitState : virtual public TransFSMData, public TransState { public: - /// - TransInitState(); - /// - virtual string normalkey(char, char *); - /// - virtual bool backspace() { return true; } - /// - virtual string deadkey(char, KmodInfo); + /// + TransInitState(); + /// + virtual string normalkey(char, char *); + /// + virtual bool backspace() { return true; } + /// + virtual string deadkey(char, KmodInfo); }; /// Deadkey State -class TransDeadkeyState: +class TransDeadkeyState : virtual public TransFSMData, public TransState { public: - /// - TransDeadkeyState(); - /// - virtual string normalkey(char, char *); - /// - virtual bool backspace() - { + /// + TransDeadkeyState(); + /// + virtual string normalkey(char, char *); + /// + virtual bool backspace() { currentState = init_state_; return false; } - /// - virtual string deadkey(char, KmodInfo); + /// + virtual string deadkey(char, KmodInfo); }; @@ -101,13 +100,12 @@ class TransCombinedState: virtual public TransFSMData, public TransState { public: - /// - TransCombinedState(); - /// - virtual string normalkey(char, char *); - /// - virtual bool backspace() - { + /// + TransCombinedState(); + /// + virtual string normalkey(char, char *); + /// + virtual bool backspace() { // cancel the second deadkey deadkey2_ = 0; deadkey2_info_.accent = TEX_NOACCENT; @@ -115,13 +113,13 @@ public: return false; } - /// - virtual string deadkey(char, KmodInfo); + /// + virtual string deadkey(char, KmodInfo); }; /// -class TransFSM: +class TransFSM : virtual public TransFSMData, public TransInitState, public TransDeadkeyState, @@ -132,9 +130,9 @@ public: TransFSM(); }; + /// -class TransManager -{ +class TransManager { private: /// TransFSM trans_fsm_; @@ -170,8 +168,7 @@ public: /// bool setCharset(const char *); /// - bool backspace() - { + bool backspace() { return trans_fsm_.currentState->backspace(); } ///