diff --git a/ChangeLog b/ChangeLog index 4a4aa1ffe3..e9be3ff214 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2000-09-14 Lars Gullik Bjønnes + + * src/buffer.C (writeFile): try to fix the locale modified format + number to always be as we want it. + + * src/WorkArea.C (work_area_handler): try to workaround the bugs + in XForms 0.89. C-space is now working again. + + * src/Lsstream.h src/support/sstream.h: new files. + + * also commented out all cases where strstream were used. + + * src/Bullet.h (c_str): remove method. + + * remove all stuff that is irrelevant when NEW_MENUBAR is defined + + * a lot of files: get rid of "char const *" and "char *" is as + many places as possible. We only want to use them in interaction + with system of other libraries, not inside lyx. + + * a lot of files: return const object is not of pod type. This + helps ensure that temporary objects is not modified. And fits well + with "programming by contract". + + * configure.in: check for the locale header too + + * Makefile.am (sourcedoc): new tag for generation of doc++ + documentation + 2000-09-14 Juergen Vigna * src/frontends/xforms/FormDocument.C (ComboInputCB): fixed the diff --git a/Makefile.am b/Makefile.am index 75ade4d09f..41372745b4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,3 +49,8 @@ bindist: @echo "*** distribution and refer to *you* in case of problem." @echo "*** $(bindistfile) has been created." + +sourcedoc: + mkdir sourcedoc + cd sourcedoc + doc++ -p $(srcdir)/src/*.h diff --git a/configure.in b/configure.in index 6a7c25ec51..e46c447543 100644 --- a/configure.in +++ b/configure.in @@ -94,7 +94,7 @@ LYX_CXX_CHEADERS LYX_STD_COUNT dnl we disable rtti for now dnl LYX_CXX_RTTI -AC_CHECK_HEADERS(ostream istream sstream) +AC_CHECK_HEADERS(ostream istream sstream locale) LYX_CXX_STL_MODERN_STREAMS ### We need a regex implementation, so we provide our own if none is found. diff --git a/po/POTFILES.in b/po/POTFILES.in index a70f1b39b2..70efb80a26 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -119,7 +119,6 @@ src/mathed/formulamacro.C src/mathed/math_forms.C src/mathed/math_panel.C src/MenuBackend.C -src/menus.C src/minibuffer.C src/PaperLayout.C src/paragraph.C diff --git a/src/BackStack.h b/src/BackStack.h index ca5a1b5264..4974ce22d5 100644 --- a/src/BackStack.h +++ b/src/BackStack.h @@ -43,7 +43,7 @@ public: stakk.push(bit); } /// - string pop(int * x, int * y) { + string const pop(int * x, int * y) { BackStackItem bit = stakk.top(); *x = bit.x; *y = bit.y; diff --git a/src/BufferView.h b/src/BufferView.h index e1b3bc6218..444fcaed49 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -124,7 +124,7 @@ public: /// void selectLastWord(); /// - char * nextWord(float & value); + string const nextWord(float & value); /// void insertCorrectQuote(); /// diff --git a/src/BufferView2.C b/src/BufferView2.C index e58b0e4ef7..d51763dcf8 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -678,16 +678,14 @@ void BufferView::insertCorrectQuote() /* these functions are for the spellchecker */ -char * BufferView::nextWord(float & value) +string const BufferView::nextWord(float & value) { if (!available()) { value = 1; return 0; } - char * string = text->SelectNextWord(this, value); - - return string; + return text->SelectNextWord(this, value); } diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index affdf76346..17039740e0 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -26,9 +26,6 @@ #include "intl.h" #include "support/LAssert.h" #include "frontends/Dialogs.h" -#ifndef NEW_MENUBAR -# include "menus.h" -#endif #ifdef SIGC_CXX_NAMESPACES using SigC::slot; @@ -162,22 +159,14 @@ void BufferView::Pimpl::buffer(Buffer * b) updateScrollbar(); } bv_->text->first = screen_->TopCursorVisible(bv_->text); -#ifdef NEW_MENUBAR owner_->updateMenubar(); -#else - owner_->getMenus()->showMenus(); -#endif owner_->updateToolbar(); redraw(); owner_->getDialogs()->updateBufferDependent(); bv_->insetWakeup(); } else { lyxerr[Debug::INFO] << " No Buffer!" << endl; -#ifdef NEW_MENUBAR owner_->updateMenubar(); -#else - owner_->getMenus()->hideMenus(); -#endif owner_->updateToolbar(); updateScrollbar(); workarea_->redraw(); diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index e0a33d4aa4..46e9e3df18 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -137,7 +137,9 @@ struct BufferView::Pimpl : public Object { /// BackStack backstack; /// - int last_click_x, last_click_y; + int last_click_x; + /// + int last_click_y; /// WorkArea * workarea_; /// diff --git a/src/Bullet.C b/src/Bullet.C index 70b842608a..b14aea8e91 100644 --- a/src/Bullet.C +++ b/src/Bullet.C @@ -62,7 +62,7 @@ string const & Bullet::getText() const } -bool operator == (const Bullet & b1, const Bullet & b2) +bool operator==(const Bullet & b1, const Bullet & b2) { bool result = false; @@ -109,7 +109,7 @@ void Bullet::generateText() const } -string Bullet::bulletSize(short int s) +string const Bullet::bulletSize(short int s) { // use a parameter rather than hard code `size' in here // in case some future function may want to retrieve @@ -125,7 +125,7 @@ string Bullet::bulletSize(short int s) } -string Bullet::bulletEntry(short int f, short int c) +string const Bullet::bulletEntry(short int f, short int c) { // Despite how this may at first appear the static local variables // are only initialized once.. diff --git a/src/Bullet.h b/src/Bullet.h index f761dd8cf2..b1eb94d516 100644 --- a/src/Bullet.h +++ b/src/Bullet.h @@ -49,15 +49,9 @@ public: /// string const & getText() const; /// - char const * c_str() const; - /// - Bullet & operator = (Bullet const &); + Bullet & operator=(Bullet const &); /// friend bool operator==(Bullet const &, Bullet const &); - /// - friend bool operator!=(Bullet const & b1, Bullet const & b2) { - return !(b1 == b2); - } protected: #ifdef ENABLE_ASSERTIONS /// @@ -107,9 +101,9 @@ private: /// void generateText() const; /// - static string bulletSize(short int); + static string const bulletSize(short int); /// - static string bulletEntry(short int, short int); + static string const bulletEntry(short int, short int); /// short font; @@ -245,16 +239,14 @@ Bullet & Bullet::operator=(Bullet const & b) return *this; } +/*-----------------End Bullet Member Functions-----------------*/ inline -char const * Bullet::c_str() const +bool operator!=(Bullet const & b1, Bullet const & b2) { - return getText().c_str(); + return !(b1 == b2); } - -/*-----------------End Bullet Member Functions-----------------*/ - /// extern Bullet const ITEMIZE_DEFAULTS[]; diff --git a/src/FloatList.C b/src/FloatList.C index fbbfa370a0..0bfabdfb6f 100644 --- a/src/FloatList.C +++ b/src/FloatList.C @@ -47,7 +47,7 @@ void FloatList::newFloat(Floating const & fl) } -string FloatList::defaultPlacement(string const & t) const +string const FloatList::defaultPlacement(string const & t) const { List::const_iterator cit = list.find(t); if (cit != list.end()) diff --git a/src/FloatList.h b/src/FloatList.h index aed0dfa79b..a1bab70dcf 100644 --- a/src/FloatList.h +++ b/src/FloatList.h @@ -31,7 +31,7 @@ public: /// void newFloat(Floating const & fl); /// - string defaultPlacement(string const & t) const; + string const defaultPlacement(string const & t) const; /// bool typeExist(string const & t) const; /// diff --git a/src/FontInfo.C b/src/FontInfo.C index c61d6662bb..1ccb10816f 100644 --- a/src/FontInfo.C +++ b/src/FontInfo.C @@ -27,7 +27,7 @@ using std::endl; /// Load font close to this size -string FontInfo::getFontname(int size) +string const FontInfo::getFontname(int size) { if (!exist()) return string(); @@ -71,7 +71,7 @@ string FontInfo::getFontname(int size) /// Build newly sized font string -string FontInfo::resize(string const & font, int size) const +string const FontInfo::resize(string const & font, int size) const { string ret(font); // Find the position of the size spec diff --git a/src/FontInfo.h b/src/FontInfo.h index d3d2e8b0a0..3bc79d9135 100644 --- a/src/FontInfo.h +++ b/src/FontInfo.h @@ -51,14 +51,14 @@ public: } /// Get existing pattern - string getPattern() const { return pattern; } + string const getPattern() const { return pattern; } /// Set new pattern void setPattern(string const & pat); /** Return full name of font close to this size. If impossible, result is the empty string */ - string getFontname(int size); + string const getFontname(int size); private: /// Font pattern (with wildcard for size) string pattern; @@ -91,6 +91,6 @@ private: void query(); /// Build newly sized font string - string resize(string const &, int size) const; + string const resize(string const &, int size) const; }; #endif diff --git a/src/ImportNoweb.C b/src/ImportNoweb.C index 31c30bdd78..28e6f425cc 100644 --- a/src/ImportNoweb.C +++ b/src/ImportNoweb.C @@ -52,7 +52,7 @@ Buffer * ImportNoweb::run() // Provide the literate documentclass by parsing the file. -string ImportNoweb::documentclass() +string const ImportNoweb::documentclass() { string result = "literate-article"; // Default diff --git a/src/ImportNoweb.h b/src/ImportNoweb.h index c83d148341..5bb967b9f2 100644 --- a/src/ImportNoweb.h +++ b/src/ImportNoweb.h @@ -39,7 +39,7 @@ private: /// string file; /// - string documentclass(); + string const documentclass(); /// enum { /// diff --git a/src/LColor.C b/src/LColor.C index 8ba1e503d7..adf5c73e42 100644 --- a/src/LColor.C +++ b/src/LColor.C @@ -119,7 +119,7 @@ LColor::LColor() } -string LColor::getGUIName(LColor::color c) const +string const LColor::getGUIName(LColor::color c) const { InfoTab::const_iterator ici = infotab.find(c); if (ici != infotab.end()) @@ -129,7 +129,7 @@ string LColor::getGUIName(LColor::color c) const } -string LColor::getX11Name(LColor::color c) const +string const LColor::getX11Name(LColor::color c) const { InfoTab::const_iterator ici = infotab.find(c); if (ici != infotab.end()) @@ -142,7 +142,7 @@ string LColor::getX11Name(LColor::color c) const } -string LColor::getLaTeXName(LColor::color c) const +string const LColor::getLaTeXName(LColor::color c) const { InfoTab::const_iterator ici = infotab.find(c); if (ici != infotab.end()) @@ -151,7 +151,7 @@ string LColor::getLaTeXName(LColor::color c) const } -string LColor::getLyXName(LColor::color c) const +string const LColor::getLyXName(LColor::color c) const { InfoTab::const_iterator ici = infotab.find(c); if (ici != infotab.end()) @@ -196,7 +196,7 @@ LColor::color LColor::getFromGUIName(string const & guiname) const if (!compare_no_case((*ici).second.guiname, guiname)) return (*ici).first; } - return LColor::ignore; + return LColor::inherit; } diff --git a/src/LColor.h b/src/LColor.h index e282761c1b..6f8af995b5 100644 --- a/src/LColor.h +++ b/src/LColor.h @@ -176,16 +176,16 @@ public: /// bool setColor(string const & lyxname, string const & x11name); /// Get GUI name of color - string getGUIName(LColor::color c) const; + string const getGUIName(LColor::color c) const; /// Get X11 name of color - string getX11Name(LColor::color c) const; + string const getX11Name(LColor::color c) const; /// Get LaTeX name of color - string getLaTeXName(LColor::color c) const; + string const getLaTeXName(LColor::color c) const; /// Get LyX name of color - string getLyXName(LColor::color c) const; + string const getLyXName(LColor::color c) const; /// LColor::color getFromGUIName(string const & guiname) const; /// diff --git a/src/LaTeX.h b/src/LaTeX.h index 89325b2a26..e490695442 100644 --- a/src/LaTeX.h +++ b/src/LaTeX.h @@ -23,6 +23,8 @@ #include "DepTable.h" #include +#include "support/utility.hpp" + class MiniBuffer; /// @@ -61,7 +63,7 @@ private: /// -class LaTeX { +class LaTeX : public noncopyable { public: /** Return values from scanLogFile() and run() (to come) @@ -122,11 +124,6 @@ protected: /// The dependency file. string depfile; - /// unavail - LaTeX(LaTeX const &); - /// unavail - LaTeX & operator= (LaTeX const &); - /// void deplog(DepTable & head); diff --git a/src/LaTeXFeatures.C b/src/LaTeXFeatures.C index eeecf32930..6fa3da722b 100644 --- a/src/LaTeXFeatures.C +++ b/src/LaTeXFeatures.C @@ -32,7 +32,7 @@ LaTeXFeatures::LaTeXFeatures(BufferParams const & p, int n) array = false; color = false; graphics = false; // INSET_GRAPHICS: remove this when InsetFig is thrown. - graphicx = false; + graphicx = false; setspace = false; makeidx = false; verbatim = false; @@ -74,7 +74,9 @@ LaTeXFeatures::LaTeXFeatures(BufferParams const & p, int n) NeedLyXMinipageIndent = false; } -void LaTeXFeatures::require(string const & name) { + +void LaTeXFeatures::require(string const & name) +{ if (name == "array") { array = true; } else if (name == "color") { @@ -121,7 +123,8 @@ void LaTeXFeatures::require(string const & name) { } } -string LaTeXFeatures::getPackages() + +string const LaTeXFeatures::getPackages() { string packages; LyXTextClass const & tclass = @@ -158,7 +161,7 @@ string LaTeXFeatures::getPackages() + params.graphicsDriver + "]{graphicx}\n"; } - // INSET_GRAPHICS: remove this when InsetFig is thrown. + // INSET_GRAPHICS: remove this when InsetFig is thrown. // graphics.sty if (graphics && params.graphicsDriver != "none") { if (params.graphicsDriver == "default") @@ -200,22 +203,22 @@ string LaTeXFeatures::getPackages() packages += "\\doublespacing\n"; break; case Spacing::Other: -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream value; -#else - char val[30]; - ostrstream value(val, 30); - -#endif +//#else +// char val[30]; +// ostrstream value(val, 30); +// +//#endif value << params.spacing.getValue(); // setw? -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM packages += string("\\setstretch{") + value.str().c_str() + "}\n"; -#else - value << '\0'; - packages += string("\\setstretch{") - + value.str() + "}\n"; -#endif +//#else +// value << '\0'; +// packages += string("\\setstretch{") +// + value.str() + "}\n"; +//#endif break; } @@ -273,7 +276,7 @@ string LaTeXFeatures::getPackages() } -string LaTeXFeatures::getMacros() +string const LaTeXFeatures::getMacros() { string macros; @@ -330,7 +333,7 @@ string LaTeXFeatures::getMacros() } -string LaTeXFeatures::getTClassPreamble() +string const LaTeXFeatures::getTClassPreamble() { // the text class specific preamble LyXTextClass const & tclass = @@ -347,7 +350,7 @@ string LaTeXFeatures::getTClassPreamble() } -string LaTeXFeatures::getIncludedFiles() +string const LaTeXFeatures::getIncludedFiles() { string sgmlpreamble; FileMap::const_iterator end = IncludedFiles.end(); diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index f8cc2e63ae..5e6ff72c56 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -36,13 +36,13 @@ struct LaTeXFeatures { /// LaTeXFeatures(BufferParams const &, int n) ; /// The packaes needed by the document - string getPackages(); + string const getPackages(); /// The macros definitions needed by the document - string getMacros(); + string const getMacros(); /// The definitions needed by the document's textclass - string getTClassPreamble(); + string const getTClassPreamble(); /// - string getIncludedFiles(); + string const getIncludedFiles(); /// void showStruct(); diff --git a/src/Lsstream.h b/src/Lsstream.h new file mode 100644 index 0000000000..8d171d2156 --- /dev/null +++ b/src/Lsstream.h @@ -0,0 +1,21 @@ +// -*- C++ -*- +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2000 The LyX Team. + * + * ====================================================== */ + +#ifndef LSSTREAM_H +#define LSSTREAM_H + +#ifdef HAVE_SSTREAM +#include +#else +#include "support/sstream.h" +#endif + +#endif diff --git a/src/LyXAction.C b/src/LyXAction.C index 670230d9a4..6df70fef84 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -609,7 +609,7 @@ int LyXAction::getApproxFunc(string const & func) const } -string LyXAction::getApproxFuncName(string const & func) const +string const LyXAction::getApproxFuncName(string const & func) const { int f = getApproxFunc(func); // This will return empty string if f isn't an action. @@ -617,7 +617,7 @@ string LyXAction::getApproxFuncName(string const & func) const } -string LyXAction::getActionName(int action) const +string const LyXAction::getActionName(int action) const { kb_action ac; string arg; @@ -639,7 +639,7 @@ string LyXAction::getActionName(int action) const // Returns one line help associated with a (pseudo)action, i.e. appends // the argument of the action if necessary -string LyXAction::helpText(int pseudoaction) const +string const LyXAction::helpText(int pseudoaction) const { string help, arg; kb_action action; diff --git a/src/LyXAction.h b/src/LyXAction.h index 19790c32e5..cf611e3c35 100644 --- a/src/LyXAction.h +++ b/src/LyXAction.h @@ -74,7 +74,7 @@ public: /** Returns an action name the most similar to a string. Don't include arguments, they would be ignored. */ - string getApproxFuncName(string const & func) const; + string const getApproxFuncName(string const & func) const; /// Returns a pseudo-action given an action and its argument. int getPseudoAction(kb_action action, string const & arg) const; @@ -89,10 +89,10 @@ public: bool isPseudoAction(int) const; /// Return the name associated with command - string getActionName(int action) const; + string const getActionName(int action) const; /// Return one line help text associated with (pseudo)action - string helpText(int action) const; + string const helpText(int action) const; /// True if the command has `flag' set bool funcHasFlag(kb_action action, func_attrib flag) const; diff --git a/src/LyXView.C b/src/LyXView.C index 2e28a73a68..5f0deb8c66 100644 --- a/src/LyXView.C +++ b/src/LyXView.C @@ -32,12 +32,8 @@ #include "buffer.h" #include "frontends/Dialogs.h" #include "frontends/Toolbar.h" -#ifdef NEW_MENUBAR -# include "frontends/Menubar.h" -# include "MenuBackend.h" -#else -# include "menus.h" -#endif +#include "frontends/Menubar.h" +#include "MenuBackend.h" #include "ToolbarDefaults.h" #include "lyx_gui_misc.h" // [update,Close]AllBufferRelatedDialogs #include "bufferview_funcs.h" // CurrentState() @@ -83,11 +79,7 @@ LyXView::LyXView(int width, int height) LyXView::~LyXView() { -#ifdef NEW_MENUBAR delete menubar; -#else - delete menus; -#endif delete toolbar; delete bufferview; delete minibuffer; @@ -155,7 +147,6 @@ MiniBuffer * LyXView::getMiniBuffer() const } -#ifdef NEW_MENUBAR Menubar * LyXView::getMenubar() const { return menubar; @@ -171,13 +162,6 @@ void LyXView::updateMenubar() menubar->set("main"); } -#else -Menus * LyXView::getMenus() const -{ - return menus; -} -#endif - Intl * LyXView::getIntl() const { @@ -224,9 +208,9 @@ void LyXView::setPosition(int x, int y) } -void LyXView::show(int place, int border, char const * title) +void LyXView::show(int place, int border, string const & title) { - fl_show_form(form_, place, border, title); + fl_show_form(form_, place, border, title.c_str()); minibuffer->Init(); InitLyXLookup(fl_display, form_->window); } @@ -254,11 +238,7 @@ void LyXView::create_form_form_main(int width, int height) // // THE MENUBAR // -#ifdef NEW_MENUBAR menubar = new Menubar(this, menubackend); -#else - menus = new Menus(this, air); -#endif // // TOOLBAR @@ -332,9 +312,7 @@ void LyXView::init() invalidateLayoutChoice(); updateLayoutChoice(); UpdateDocumentClassChoice(); -#ifdef NEW_MENUBAR updateMenubar(); -#endif // Start autosave timer if (lyxrc.autosave) { diff --git a/src/LyXView.h b/src/LyXView.h index 85f56b7fd7..af420cad92 100644 --- a/src/LyXView.h +++ b/src/LyXView.h @@ -18,22 +18,17 @@ #include FORMS_H_LOCATION +#include "LString.h" #include "Timeout.h" #include "support/utility.hpp" -// uncomment this line to try out the new menus -#define NEW_MENUBAR 1 class LyXFunc; class Toolbar; class MiniBuffer; class Intl; class Buffer; -#ifdef NEW_MENUBAR class Menubar; -#else -class Menus; -#endif class BufferView; class Dialogs; @@ -60,7 +55,7 @@ public: void setPosition(int, int); /// Show the main form. - void show(int, int, char const * t = "LyX"); + void show(int, int, string const & t = string("LyX")); /// init (should probably be removed later) (Lgb) void init(); @@ -92,16 +87,12 @@ public: /// return a pointer to the minibuffer MiniBuffer * getMiniBuffer() const; -#ifdef NEW_MENUBAR /// Menubar * getMenubar() const; /// void updateMenubar(); -#else - /// - Menus * getMenus() const; -#endif + /// Intl * getIntl() const; @@ -127,13 +118,8 @@ private: Toolbar * toolbar; /// MiniBuffer * minibuffer; -#ifdef NEW_MENUBAR /// Menubar * menubar; -#else - /// - Menus * menus; -#endif /// Intl * intl; /// diff --git a/src/Makefile.am b/src/Makefile.am index 0623dc00f9..83ef229a09 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -56,6 +56,7 @@ lyx_SOURCES = \ LaTeXLog.C \ Literate.C \ Literate.h \ + Lsstream.h \ LyXAction.C \ LyXAction.h \ LyXSendto.C \ @@ -192,8 +193,6 @@ lyx_SOURCES = \ lyxvc.C \ lyxvc.h \ main.C \ - menus.C \ - menus.h \ minibuffer.C \ minibuffer.h \ nt_defines.h \ @@ -208,8 +207,6 @@ lyx_SOURCES = \ spellchecker.C \ spellchecker.h \ stl_string_fwd.h \ - table.C \ - table.h \ tabular.C \ tabular.h \ tex-accent.C \ diff --git a/src/MenuBackend.h b/src/MenuBackend.h index d0a3e1e8dd..7ceb6c6ec5 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -61,9 +61,9 @@ public: string const & command = string(), bool optional = false); /// The label of a given menuitem - string label() const { return token(label_, '|', 0); } + string const label() const { return token(label_, '|', 0); } /// - string shortcut() const { return token(label_, '|', 1); } + string const shortcut() const { return token(label_, '|', 1); } /// The kind of entry Kind kind() const { return kind_; } /// the action (if relevant) diff --git a/src/PainterBase.h b/src/PainterBase.h index 11624821e7..771baec8b9 100644 --- a/src/PainterBase.h +++ b/src/PainterBase.h @@ -153,7 +153,7 @@ public: /// Draw a string at position x, y (y is the baseline) virtual PainterBase & text(int x, int y, - string const &str, LyXFont const & f) = 0; + string const & str, LyXFont const & f) = 0; /** Draw a string at position x, y (y is the baseline) This is just for fast drawing */ diff --git a/src/Spacing.C b/src/Spacing.C index f3ad1f6672..635ef14169 100644 --- a/src/Spacing.C +++ b/src/Spacing.C @@ -14,6 +14,7 @@ #pragma implementation #endif +#if 0 #ifdef HAVE_SSTREAM #include using std::istringstream; @@ -21,6 +22,9 @@ using std::ostringstream; #else #include #endif +#else +#include "Lsstream.h" +#endif #include "Spacing.h" #include "LString.h" @@ -60,14 +64,14 @@ void Spacing::set(Spacing::Space sp, float val) } -void Spacing::set(Spacing::Space sp, char const * val) +void Spacing::set(Spacing::Space sp, string const & val) { float fval; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM istringstream istr(val); -#else - istrstream istr(val); -#endif +//#else +// istrstream istr(val.c_str()); +//#endif istr >> fval; set(sp, fval); } @@ -90,7 +94,7 @@ void Spacing::writeFile(ostream & os, bool para) const } -string Spacing::writeEnvirBegin() const +string const Spacing::writeEnvirBegin() const { switch(space) { case Default: break; // do nothing @@ -101,26 +105,28 @@ string Spacing::writeEnvirBegin() const case Double: return "\\begin{doublespace}"; case Other: -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM + { ostringstream ost; ost << "\\begin{spacing}{" << getValue() << "}"; return ost.str().c_str(); -#else - { - char tmp[512]; - ostrstream ost(tmp, 512); - ost << "\\begin{spacing}{" - << getValue() << "}" << '\0'; - return ost.str(); - } -#endif + } +//#else +// { +// char tmp[512]; +// ostrstream ost(tmp, 512); +// ost << "\\begin{spacing}{" +// << getValue() << "}\0"; +// return ost.str(); +// } +//#endif } return string(); } -string Spacing::writeEnvirEnd() const +string const Spacing::writeEnvirEnd() const { switch(space) { case Default: break; // do nothing diff --git a/src/Spacing.h b/src/Spacing.h index 120b14b97a..98f9463250 100644 --- a/src/Spacing.h +++ b/src/Spacing.h @@ -49,25 +49,33 @@ public: /// void set(Spacing::Space sp, float val = 1.0); /// - void set(Spacing::Space sp, char const * val) ; + void set(Spacing::Space sp, string const & val) ; /// void writeFile(std::ostream &, bool para = false) const; /// - string writeEnvirBegin() const; + string const writeEnvirBegin() const; /// - string writeEnvirEnd() const; - /// - friend bool operator==(Spacing const & a, Spacing const & b) { - return a.space == b.space && a.getValue() == b.getValue(); - } - /// - friend bool operator!=(Spacing const & a, Spacing const & b) { - return !(a == b); - } + string const writeEnvirEnd() const; private: /// Space space; /// float value; }; + + +/// +inline +bool operator==(Spacing const & a, Spacing const & b) +{ + return a.getSpace() == b.getSpace() + && a.getValue() == b.getValue(); +} + +/// +inline +bool operator!=(Spacing const & a, Spacing const & b) +{ + return !(a == b); +} #endif diff --git a/src/Variables.C b/src/Variables.C index 9f4a516e38..c20ed86bdb 100644 --- a/src/Variables.C +++ b/src/Variables.C @@ -27,7 +27,7 @@ void Variables::set(string const & var, string const & val) } -string Variables::get(string const & var) const +string const Variables::get(string const & var) const { Vars::const_iterator cit = vars_.find(var); if (cit != vars_.end()) @@ -44,7 +44,7 @@ bool Variables::isset(string const & var) const } -string Variables::expand(string const & s) const +string const Variables::expand(string const & s) const { string str(s); LRegex reg("\\$\\{\\(.*\\)\\}"); diff --git a/src/Variables.h b/src/Variables.h index 45747927c1..1b71983911 100644 --- a/src/Variables.h +++ b/src/Variables.h @@ -26,11 +26,11 @@ public: /// void set(string const &, string const &); /// - string get(string const &) const; + string const get(string const &) const; /// bool isset(string const & var) const; /// - string expand(string const &) const; + string const expand(string const &) const; private: /// typedef std::map Vars; diff --git a/src/WorkArea.C b/src/WorkArea.C index 02f5e97e70..0bb29e960b 100644 --- a/src/WorkArea.C +++ b/src/WorkArea.C @@ -40,6 +40,7 @@ void waitForX() XSync(fl_get_display(), 0); } + extern "C" { // Just a bunch of C wrappers around static members of WorkArea void C_WorkArea_scroll_cb(FL_OBJECT * ob, long buf) @@ -125,10 +126,9 @@ WorkArea::WorkArea(BufferView * o, int xpos, int ypos, int width, int height) width - 15 - 2 * bw, // scrollbarwidth height - 2 * bw, "", C_WorkArea_work_area_handler); - //obj->wantkey = FL_KEY_TAB; obj->wantkey = FL_KEY_ALL; obj->u_vdata = this; /* This is how we pass the WorkArea - to the work_area_handler. */ + to the work_area_handler. */ fl_set_object_boxtype(obj,FL_DOWN_BOX); fl_set_object_resize(obj, FL_RESIZE_ALL); fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity); @@ -265,6 +265,7 @@ void WorkArea::scroll_cb(FL_OBJECT * ob, long) waitForX(); } + bool Lgb_bug_find_hack = false; int WorkArea::work_area_handler(FL_OBJECT * ob, int event, @@ -355,19 +356,35 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, } KeySym ret_key = keysym; #else - // Ok, this is a bit simplistic...seems that the rules - // need to be a bit more... - if (!key) break; - KeySym ret_key = (keysym ? keysym : key); + // Note that we need this handling because of a bug + // in XForms 0.89, if this bug is resolved in the way I hope + // we can just use the keysym directly with out looking + // at key at all. (Lgb) + KeySym ret_key = 0; + if (!key) { + // We migth have to add more keysyms here also, + // we will do that as the issues arise. (Lgb) + if (keysym == XK_space) + ret_key = keysym; + else + break; + } else { + ret_key = (keysym ? keysym : key); + } + #endif unsigned int ret_state = xke->state; - + + // If you have a better way to handle "wild-output" of + // characters after the key has been released than the one + // below, please contact me. (Lgb) static Time last_time_pressed = 0; static unsigned int last_key_pressed = 0; static unsigned int last_state_pressed = 0; - //lyxerr << "Workarea Diff: " << xke->time - last_time_pressed - // << endl; - if (xke->time - last_time_pressed < 40 // should perhaps be tunable + lyxerr[Debug::KEY] << "Workarea Diff: " + << xke->time - last_time_pressed + << endl; + if (xke->time - last_time_pressed < 35 // should perhaps be tunable && xke->state == last_state_pressed && xke->keycode == last_key_pressed) { lyxerr[Debug::KEY] @@ -449,9 +466,10 @@ int request_clipboard_cb(FL_OBJECT * /*ob*/, long /*type*/, clipboard_read = true; return 0; } -} +} // extern "C" -string WorkArea::getClipboard() const + +string const WorkArea::getClipboard() const { clipboard_read = false; diff --git a/src/WorkArea.h b/src/WorkArea.h index 18b10611c7..503feb5b7b 100644 --- a/src/WorkArea.h +++ b/src/WorkArea.h @@ -86,7 +86,7 @@ public: return fl_get_scrollbar_value(scrollbar); } /// - std::pair getScrollbarBounds() const { + std::pair const getScrollbarBounds() const { std::pair p; fl_get_scrollbar_bounds(scrollbar, &p.first, &p.second); return p; @@ -100,7 +100,7 @@ public: /// xforms callback static void scroll_cb(FL_OBJECT *, long); /// - string getClipboard() const; + string const getClipboard() const; /// void putClipboard(string const &) const; /// diff --git a/src/buffer.C b/src/buffer.C index 82d8255cf6..a363f8e4ce 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -24,6 +24,10 @@ #include +#ifdef HAVE_LOCALE +#include +#endif + #ifdef __GNUG__ #pragma implementation "buffer.h" #endif @@ -100,9 +104,9 @@ using std::pair; using std::vector; using std::max; using std::set; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM using std::istringstream; -#endif +//#endif // all these externs should eventually be removed. extern BufferList bufferlist; @@ -163,7 +167,7 @@ Buffer::~Buffer() } -string Buffer::getLatexName(bool no_path) const +string const Buffer::getLatexName(bool no_path) const { if (no_path) return OnlyFilename(ChangeExtension(MakeLatexName(filename), @@ -461,11 +465,11 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par, old_float += "\n\\end_inset\n"; //lyxerr << "float body: " << old_float << endl; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM istringstream istr(old_float); -#else - istrstream istr(old_float.c_str()); -#endif +//#else +// istrstream istr(old_float.c_str()); +//#endif LyXLex nylex(0, 0); nylex.setStream(istr); @@ -1261,6 +1265,12 @@ bool Buffer::writeFile(string const & fname, bool flag) const fname); return false; } + +#ifdef HAVE_LOCALE + // Use the standard "C" locale for file output. + ofs.imbue(locale::classic()); +#endif + // The top of the file should not be written by params. // write out a comment in the top of the file @@ -1268,8 +1278,13 @@ bool Buffer::writeFile(string const & fname, bool flag) const << " created this file. For more info see http://www.lyx.org/\n"; ofs.setf(ios::showpoint|ios::fixed); ofs.precision(2); +#ifndef HAVE_LOCALE + char dummy_format[512]; + sprintf(dummy_format, "%.2f", LYX_FORMAT); + ofs << "\\lyxformat " << dummy_format << "\n"; +#else ofs << "\\lyxformat " << setw(4) << LYX_FORMAT << "\n"; - +#endif // now write out the buffer paramters. params.writeFile(ofs); @@ -1428,19 +1443,19 @@ void Buffer::writeFileAscii(string const & fname, int linelen) c = par->GetChar(i); if (c == LyXParagraph::META_INSET) { if ((inset = par->GetInset(i))) { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; inset->Ascii(this, ost); h += ost.str().length(); -#else - ostrstream ost; - inset->Ascii(this, ost); - ost << '\0'; - char * tmp = ost.str(); - string tstr(tmp); - h += tstr.length(); - delete [] tmp; -#endif +//#else +// ostrstream ost; +// inset->Ascii(this, ost); +// ost << '\0'; +// char * tmp = ost.str(); +// string tstr(tmp); +// h += tstr.length(); +// delete [] tmp; +//#endif } } else if (c == LyXParagraph::META_NEWLINE) { if (clen[j] < h) @@ -2135,24 +2150,24 @@ void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par, { bool was_title = false; bool already_title = false; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ftnote; -#else - char * tmpholder = 0; -#endif +//#else +// char * tmpholder = 0; +//#endif TexRow ft_texrow; int ftcount = 0; // if only_body while (par != endpar) { -#ifndef HAVE_SSTREAM - ostrstream ftnote; - if (tmpholder) { - ftnote << tmpholder; - delete [] tmpholder; - tmpholder = 0; - } -#endif +//#ifndef HAVE_SSTREAM +// ostrstream ftnote; +// if (tmpholder) { +// ftnote << tmpholder; +// delete [] tmpholder; +// tmpholder = 0; +// } +//#endif #ifndef NEW_INSETS if (par->IsDummy()) lyxerr[Debug::LATEX] << "Error in latexParagraphs." @@ -2204,26 +2219,26 @@ void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par, } ofs << ftnote.str(); texrow += ft_texrow; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM // The extra .c_str() is needed when we use // lyxstring instead of the STL string class. ftnote.str(string().c_str()); -#else - delete [] ftnote.str(); -#endif +//#else +// delete [] ftnote.str(); +//#endif ft_texrow.reset(); ftcount = 0; } -#ifndef HAVE_SSTREAM - else { - // I hate strstreams - tmpholder = ftnote.str(); - } -#endif +//#ifndef HAVE_SSTREAM +// else { +// // I hate strstreams +// tmpholder = ftnote.str(); +// } +//#endif } -#ifndef HAVE_SSTREAM - delete [] tmpholder; -#endif +//#ifndef HAVE_SSTREAM +// delete [] tmpholder; +//#endif // It might be that we only have a title in this document if (was_title && !already_title) { ofs << "\\maketitle\n"; @@ -2597,21 +2612,21 @@ void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par, if (par->layout != textclasslist .NumberOfLayout(params.textclass, "Caption").second) { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; -#else - ostrstream ost; -#endif +//#else +// ostrstream ost; +//#endif SimpleDocBookOnePar(ost, extra_par, par, desc_on, depth + 2); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM tmp_par += ost.str().c_str(); -#else - ost << '\0'; - char * ctmp = ost.str(); - tmp_par += ctmp; - delete [] ctmp; -#endif +//#else +// ost << '\0'; +// char * ctmp = ost.str(); +// tmp_par += ctmp; +// delete [] ctmp; +//#endif } tmp_par = frontStrip(strip(tmp_par)); @@ -2627,15 +2642,16 @@ void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par, // push a tag in a style stack -void Buffer::push_tag(ostream & os, char const * tag, +void Buffer::push_tag(ostream & os, string const & tag, int & pos, char stack[5][3]) { +#warning Use a real stack! (Lgb) // pop all previous tags for (int j = pos; j >= 0; --j) os << ""; // add new tag - sprintf(stack[++pos], "%s", tag); + sprintf(stack[++pos], "%s", tag.c_str()); // push all tags for (int i = 0; i <= pos; ++i) @@ -2643,20 +2659,19 @@ void Buffer::push_tag(ostream & os, char const * tag, } -void Buffer::pop_tag(ostream & os, char const * tag, +void Buffer::pop_tag(ostream & os, string const & tag, int & pos, char stack[5][3]) { - int j; - +#warning Use a real stack! (Lgb) // pop all tags till specified one - for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j) + for (int j = pos; (j >= 0) && (strcmp(stack[j], tag.c_str())); --j) os << ""; // closes the tag os << ""; // push all tags, but the specified one - for (j = j + 1; j <= pos; ++j) { + for (int j = j + 1; j <= pos; ++j) { os << "<" << stack[j] << ">"; strcpy(stack[j-1], stack[j]); } @@ -2879,7 +2894,7 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par, // Print an error message. void Buffer::LinuxDocError(LyXParagraph * par, int pos, - char const * message) + string const & message) { // insert an error marker in text InsetError * new_inset = new InsetError(message); @@ -3242,18 +3257,18 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra, if (c == LyXParagraph::META_INSET) { Inset * inset = par->GetInset(i); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; inset->DocBook(this, ost); string tmp_out = ost.str().c_str(); -#else - ostrstream ost; - inset->DocBook(this, ost); - ost << '\0'; - char * ctmp = ost.str(); - string tmp_out(ctmp); - delete [] ctmp; -#endif +//#else +// ostrstream ost; +// inset->DocBook(this, ost); +// ost << '\0'; +// char * ctmp = ost.str(); +// string tmp_out(ctmp); +// delete [] ctmp; +//#endif // // This code needs some explanation: // Two insets are treated specially @@ -3661,7 +3676,7 @@ void Buffer::setPaperStuff() // This function should be in Buffer because it's a buffer's property (ale) -string Buffer::getIncludeonlyList(char delim) +string const Buffer::getIncludeonlyList(char delim) { string lst; for (inset_iterator it = inset_iterator_begin(); @@ -3682,7 +3697,7 @@ string Buffer::getIncludeonlyList(char delim) } -vector Buffer::getLabelList() +vector const Buffer::getLabelList() { /// if this is a child document and the parent is already loaded /// Use the parent's list instead [ale990407] @@ -3703,7 +3718,7 @@ vector Buffer::getLabelList() } -vector > Buffer::getTocList() +vector > const Buffer::getTocList() { vector > l(4); LyXParagraph * par = paragraph; @@ -3758,8 +3773,9 @@ vector > Buffer::getTocList() return l; } + // This is also a buffer property (ale) -vector > Buffer::getBibkeyList() +vector > const Buffer::getBibkeyList() { /// if this is a child document and the parent is already loaded /// Use the parent's list instead [ale990412] diff --git a/src/buffer.h b/src/buffer.h index 1404bfc90b..9991e5becc 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -181,7 +181,7 @@ public: bool nice, bool only_body = false); /// returns the main language for the buffer (document) - string GetLanguage() const { + string const GetLanguage() const { return params.language; } @@ -247,7 +247,7 @@ public: /** A transformed version of the file name, adequate for LaTeX The path is stripped if no_path is true (default) */ - string getLatexName(bool no_path = true) const; + string const getLatexName(bool no_path = true) const; /// Change name of buffer. Updates "read-only" flag. void fileName(string const & newfile); @@ -288,9 +288,9 @@ public: void validate(LaTeXFeatures &) const; /// - string getIncludeonlyList(char delim = ','); + string const getIncludeonlyList(char delim = ','); /// - std::vector > getBibkeyList(); + std::vector > const getBibkeyList(); /// struct TocItem { /// @@ -312,9 +312,9 @@ public: TOC_LOA }; /// - std::vector > getTocList(); + std::vector > const getTocList(); /// - std::vector getLabelList(); + std::vector const getLabelList(); /** This will clearly have to change later. Later we can have more than one user per buffer. */ @@ -375,7 +375,8 @@ private: void sgmlCloseTag(std::ostream & os, int depth, string const & latexname) const; /// - void LinuxDocError(LyXParagraph * par, int pos, char const * message); + void LinuxDocError(LyXParagraph * par, int pos, + string const & message); /// void SimpleLinuxDocOnePar(std::ostream & os, LyXParagraph * par, int desc_on, int const depth); @@ -385,11 +386,11 @@ private: int const depth); /// LinuxDoc. - void push_tag(std::ostream & os, char const * tag, + void push_tag(std::ostream & os, string const & tag, int & pos, char stack[5][3]); /// LinuxDoc. - void pop_tag(std::ostream & os, char const * tag, + void pop_tag(std::ostream & os, string const & tag, int & pos, char stack[5][3]); /// is save needed @@ -459,10 +460,10 @@ public: friend bool operator==(inset_iterator const & iter1, inset_iterator const & iter2); - /// - friend - bool operator!=(inset_iterator const & iter1, - inset_iterator const & iter2); + // + //friend + //bool operator!=(inset_iterator const & iter1, + // inset_iterator const & iter2); private: /// void SetParagraph(); diff --git a/src/bufferlist.C b/src/bufferlist.C index d05d1deda1..232297862f 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -219,7 +219,7 @@ bool BufferList::close(Buffer * buf) } -vector BufferList::getFileNames() const +vector const BufferList::getFileNames() const { vector nvec; for(BufferStorage::const_iterator cit = bstore.begin(); @@ -456,14 +456,11 @@ Buffer * BufferList::newFile(string const & name, string tname, bool isNamed) // no template, start with empty buffer b->paragraph = new LyXParagraph; } - } - else { // start with empty buffer + } else { // start with empty buffer b->paragraph = new LyXParagraph; } -#warning Why mark a new document dirty? I deactivate this (Jug) if (!lyxrc.new_ask_filename) { -// b->markDirty(); if (!isNamed) b->setUnnamed(); } diff --git a/src/bufferlist.h b/src/bufferlist.h index da970e6fe8..57c59faffb 100644 --- a/src/bufferlist.h +++ b/src/bufferlist.h @@ -108,7 +108,7 @@ public: /// Make a new file (buffer) using a template Buffer * newFile(string const &, string, bool isNamed=false); /// returns a vector with all the buffers filenames - std::vector getFileNames() const; + std::vector const getFileNames() const; /// int unlockInset(UpdatableInset *); diff --git a/src/bufferparams.C b/src/bufferparams.C index 158463fe90..1a8fb3cac0 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -165,7 +165,7 @@ void BufferParams::writeFile(ostream & os) const else { os << "\\bulletLaTeX " << i << "\n\t" - << user_defined_bullets[i].c_str() + << user_defined_bullets[i].getText().c_str() << "\n\\end_bullet\n"; } } diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index 8d68fc7456..66fc4c0a24 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -247,7 +247,7 @@ void FontSize(BufferView * bv, string const & size) // Returns the current font and depth as a message. -string CurrentState(BufferView * bv) +string const CurrentState(BufferView * bv) { string state; if (bv->available()) { diff --git a/src/bufferview_funcs.h b/src/bufferview_funcs.h index e2f689249b..4837f19e46 100644 --- a/src/bufferview_funcs.h +++ b/src/bufferview_funcs.h @@ -68,7 +68,7 @@ extern void Underline(BufferView *); /// extern void FontSize(BufferView *, string const &); /// Returns the current font and depth as a message. -extern string CurrentState(BufferView *); +extern string const CurrentState(BufferView *); /// extern void ToggleAndShow(BufferView *, LyXFont const &); #endif diff --git a/src/bullet_forms_cb.C b/src/bullet_forms_cb.C index a8b37a5bed..0531db3c7d 100644 --- a/src/bullet_forms_cb.C +++ b/src/bullet_forms_cb.C @@ -84,7 +84,7 @@ bool updateBulletForm() fl_set_button(fd_form_bullet->radio_bullet_depth_1, 1); fl_set_input(fd_form_bullet->input_bullet_latex, current_view->buffer() - ->params.user_defined_bullets[0].c_str()); + ->params.user_defined_bullets[0].getText().c_str()); fl_set_choice(fd_form_bullet->choice_bullet_size, current_view->buffer() ->params.user_defined_bullets[0].getSize() + 2); @@ -149,7 +149,7 @@ void ChoiceBulletSizeCB(FL_OBJECT * ob, long /*data*/ ) // convert from 1-6 range to -1-4 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2); fl_set_input(fd_form_bullet->input_bullet_latex, - param.temp_bullets[current_bullet_depth].c_str()); + param.temp_bullets[current_bullet_depth].getText().c_str()); } @@ -172,7 +172,7 @@ void BulletDepthCB(FL_OBJECT * ob, long data) default: current_bullet_depth = data; fl_set_input(fd_form_bullet->input_bullet_latex, - param.temp_bullets[data].c_str()); + param.temp_bullets[data].getText().c_str()); fl_set_choice(fd_form_bullet->choice_bullet_size, param.temp_bullets[data].getSize() + 2); } @@ -242,5 +242,5 @@ void BulletBMTableCB(FL_OBJECT *ob, long /*data*/ ) param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel); param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button); fl_set_input(fd_form_bullet->input_bullet_latex, - param.temp_bullets[current_bullet_depth].c_str()); + param.temp_bullets[current_bullet_depth].getText().c_str()); } diff --git a/src/chset.C b/src/chset.C index cf3a3b1c44..b08adfed4d 100644 --- a/src/chset.C +++ b/src/chset.C @@ -62,7 +62,7 @@ bool CharacterSet::loadFile(string const & fname) } -pair CharacterSet::encodeString(string const & str) const +pair const CharacterSet::encodeString(string const & str) const { lyxerr[Debug::KBMAP] << "Checking if we know [" << str << "]" << endl; bool ret = false; diff --git a/src/chset.h b/src/chset.h index 73d49c8449..90d9affad4 100644 --- a/src/chset.h +++ b/src/chset.h @@ -19,7 +19,7 @@ public: /// string const & getName() const; /// - std::pair encodeString(string const &) const; + std::pair const encodeString(string const &) const; private: /// string name_; diff --git a/src/combox.C b/src/combox.C index 260d781eed..d44545c4f5 100644 --- a/src/combox.C +++ b/src/combox.C @@ -109,28 +109,30 @@ void Combox::remove() } -void Combox::addline(char const* text) +void Combox::addline(string const & text) { if (!browser) return; - fl_add_browser_line(browser, text); + fl_add_browser_line(browser, text.c_str()); // By default the first item is selected if (!sel) { sel = 1; if (type == FL_COMBOX_INPUT) - fl_set_input(label, text); + fl_set_input(label, text.c_str()); else - fl_set_object_label(label, text); + fl_set_object_label(label, text.c_str()); } is_empty = false; } -bool Combox::select_text(char const* t) +bool Combox::select_text(string const & t) { - if (!browser || !t) return false; - for (int i = 1; i <= fl_get_browser_maxline(browser); ++i) { - if (!strcmp(t, fl_get_browser_line(browser, i))) { + if (!browser || t.empty()) return false; + int const maxline = fl_get_browser_maxline(browser); + + for (int i = 1; i <= maxline; ++i) { + if (t == fl_get_browser_line(browser, i)) { select(i); return true; } @@ -142,7 +144,7 @@ bool Combox::select_text(char const* t) void Combox::select(int i) { if (!browser || !button) return; - if (i>0 && i<= fl_get_browser_maxline(browser)) sel = i; + if (i > 0 && i <= fl_get_browser_maxline(browser)) sel = i; fl_deactivate_object(button); if (type == FL_COMBOX_INPUT) @@ -155,7 +157,7 @@ void Combox::select(int i) void Combox::add(int x, int y, int w, int hmin, int hmax) { - FL_OBJECT *obj; + FL_OBJECT * obj; switch(type) { case FL_COMBOX_DROPLIST: @@ -311,7 +313,7 @@ void Combox::deactivate() if (label) fl_deactivate_object(label); } -void Combox::input_cb(FL_OBJECT *ob, long) +void Combox::input_cb(FL_OBJECT * ob, long) { Combox * combo = static_cast(ob->u_vdata); diff --git a/src/combox.h b/src/combox.h index 8dee29f1fc..16c6cd056a 100644 --- a/src/combox.h +++ b/src/combox.h @@ -30,6 +30,7 @@ #include FORMS_H_LOCATION #include +#include "LString.h" /// enum combox_type { @@ -63,20 +64,20 @@ public: void add(int x, int y, int w, int hmin, int hmax); /// Add lines. Same as for fl_browser object - void addline(char const *); + void addline(string const &); /// Add lines. Same as for fl_browser object - void addto(char const *); + void addto(string const &); /// Returns the selected item int get(); /// Returns a pointer to the selected line of text - char const * getline(); + string const getline(); /// Select an arbitrary item void select(int); /// - bool select_text(char const *); + bool select_text(string const &); /// Clear all the list void clear(); @@ -106,7 +107,7 @@ public: /// void deactivate(); /// - void shortcut(char const *, int); + void shortcut(string const &, int); /// void Redraw(); /// @@ -152,10 +153,10 @@ public: //----------------- Inline methods --------------------------- inline -void Combox::addto(char const * text) +void Combox::addto(string const & text) { if (browser) { - fl_addto_browser(browser, text); + fl_addto_browser(browser, text.c_str()); is_empty = false; } } @@ -178,10 +179,10 @@ void Combox::gravity(unsigned g1, unsigned g2) inline -void Combox::shortcut(char const * s, int i) +void Combox::shortcut(string const & s, int i) { if (button) - fl_set_object_shortcut(button, s, i); + fl_set_object_shortcut(button, s.c_str(), i); } @@ -215,7 +216,7 @@ int Combox::get() inline -char const * Combox::getline() +string const Combox::getline() { if (type == FL_COMBOX_INPUT) return fl_get_input(label); diff --git a/src/converter.C b/src/converter.C index 860d6c2ae6..c16f8a083b 100644 --- a/src/converter.C +++ b/src/converter.C @@ -43,7 +43,7 @@ vector Converter::commands; string Converter::latex_command; inline -string add_options(string const & command, string const & options) +string const add_options(string const & command, string const & options) { string head; string tail = split(command, head, ' '); @@ -492,7 +492,7 @@ bool Converter::runLaTeX(Buffer * buffer, string const & command) } -string Converter::dvi_papersize(Buffer * buffer) +string const Converter::dvi_papersize(Buffer const * buffer) { char real_papersize = buffer->params.papersize; if (real_papersize == BufferParams::PAPER_DEFAULT) @@ -518,7 +518,7 @@ string Converter::dvi_papersize(Buffer * buffer) } -string Converter::dvips_options(Buffer * buffer) +string const Converter::dvips_options(Buffer const * buffer) { string result; if (buffer->params.use_geometry diff --git a/src/converter.h b/src/converter.h index 8556952a6c..3b6f01270c 100644 --- a/src/converter.h +++ b/src/converter.h @@ -108,14 +108,15 @@ public: bool Convert(Buffer * buffer, string const & from_file, string const & to_file, string const & using_format, string * view_file = 0); + /// static string const SplitFormat(string const & str, string & format); /// static - string dvi_papersize(Buffer * buffer); + string const dvi_papersize(Buffer const * buffer); /// static - string dvips_options(Buffer * buffer); + string const dvips_options(Buffer const * buffer); private: /// static diff --git a/src/filedlg.C b/src/filedlg.C index 1413a9fffa..ff6b37e1bf 100644 --- a/src/filedlg.C +++ b/src/filedlg.C @@ -18,6 +18,7 @@ #include #include #include + using std::map; using std::sort; @@ -427,7 +428,7 @@ void LyXFileDlg::SetButton(int iIndex, string const & pszName, // GetDirectory: gets last dialog directory -string LyXFileDlg::GetDirectory() const +string const LyXFileDlg::GetDirectory() const { if (!pszDirectory.empty()) return pszDirectory; @@ -666,7 +667,7 @@ void LyXFileDlg::Force(bool cancel) // Select: launches dialog and returns selected file -string LyXFileDlg::Select(string const & title, string const & path, +string const LyXFileDlg::Select(string const & title, string const & path, string const & mask, string const & suggested) { // handles new mask and path diff --git a/src/filedlg.h b/src/filedlg.h index 75ff15f698..e51547fb65 100644 --- a/src/filedlg.h +++ b/src/filedlg.h @@ -45,9 +45,9 @@ public: void SetButton(int iIndex, string const & pszName = string(), string const & pszPath = string()); /// gets last dialog directory - string GetDirectory() const; + string const GetDirectory() const; /// launches dialog and returns selected file - string Select(string const & pszTitle = string(), + string const Select(string const & pszTitle = string(), string const & pszPath = string(), string const & pszMask = string(), string const & pszSuggested = string()); diff --git a/src/font.C b/src/font.C index 462241db96..96cb595f00 100644 --- a/src/font.C +++ b/src/font.C @@ -162,6 +162,7 @@ int lyxfont::signedWidth(string const & s, LyXFont const & f) } +//int lyxfont::width(wstring const & s, int n, LyXFont const & f) int lyxfont::width(XChar2b const * s, int n, LyXFont const & f) { if (!lyxrc.use_gui) @@ -187,13 +188,13 @@ int lyxfont::width(XChar2b const * s, int n, LyXFont const & f) } } -int lyxfont::XTextWidth(LyXFont const & f, char * str, int count) +int lyxfont::XTextWidth(LyXFont const & f, char const * str, int count) { return ::XTextWidth(getXFontstruct(f), str, count); } -int lyxfont::XTextWidth16(LyXFont const & f, XChar2b * str, int count) +int lyxfont::XTextWidth16(LyXFont const & f, XChar2b const * str, int count) { return ::XTextWidth16(getXFontstruct(f), str, count); } diff --git a/src/font.h b/src/font.h index 98f0013f52..d078ea8ba2 100644 --- a/src/font.h +++ b/src/font.h @@ -68,13 +68,13 @@ struct lyxfont { int signedWidth(string const & s, LyXFont const & f); /// static - int XTextWidth(LyXFont const & f, char * str, int count); + int XTextWidth(LyXFont const & f, char const * str, int count); /// static int width(XChar2b const * s, int n, LyXFont const & f); /// static - int XTextWidth16(LyXFont const & f, XChar2b * str, int count); + int XTextWidth16(LyXFont const & f, XChar2b const * str, int count); /// static void XSetFont(Display * display, GC gc, LyXFont const & f); diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index 52d7d02afb..5511d850b2 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -3,7 +3,7 @@ * * LyX, The Document Processor * - * Copyright (C) 2000 The LyX Team. + * Copyright 2000 The LyX Team. * * @author Jürgen Vigna * @@ -63,6 +63,7 @@ C_GENERICCB(FormDocument, BulletDepthCB) C_GENERICCB(FormDocument, InputBulletLaTeXCB) C_GENERICCB(FormDocument, ChoiceBulletSizeCB) + FormDocument::FormDocument(LyXView * lv, Dialogs * d) : dialog_(0), paper_(0), class_(0), language_(0), options_(0), bullets_(0), lv_(lv), d_(d), u_(0), h_(0), @@ -78,12 +79,14 @@ FormDocument::FormDocument(LyXView * lv, Dialogs * d) current_bullet_panel = 0; } + FormDocument::~FormDocument() { free(); delete bc_; } + void FormDocument::build() { int n; @@ -267,6 +270,7 @@ void FormDocument::build() } } + void FormDocument::show() { if (!dialog_) @@ -286,6 +290,7 @@ void FormDocument::show() } } + void FormDocument::hide() { if (dialog_->form->visible) { @@ -295,15 +300,13 @@ void FormDocument::hide() } } + void FormDocument::apply() { if (!lv_->view()->available() || !dialog_) return; - bool - redo; - - redo = class_apply(); + bool redo = class_apply(); paper_apply(); redo = language_apply() || redo; redo = options_apply() || redo; @@ -441,10 +444,10 @@ bool FormDocument::class_apply() return redo; } + void FormDocument::paper_apply() { - BufferParams - ¶ms = lv_->buffer()->params; + BufferParams & params = lv_->buffer()->params; params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1; params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1; @@ -465,12 +468,11 @@ void FormDocument::paper_apply() lv_->buffer()->setPaperStuff(); } + bool FormDocument::language_apply() { - BufferParams - ¶ms = lv_->buffer()->params; - InsetQuotes::quote_language - lga = InsetQuotes::EnglishQ; + BufferParams & params = lv_->buffer()->params; + InsetQuotes::quote_language lga = InsetQuotes::EnglishQ; bool redo = false; switch(fl_get_choice(language_->choice_quotes_language) - 1) { @@ -522,12 +524,11 @@ bool FormDocument::language_apply() return redo; } + bool FormDocument::options_apply() { - BufferParams - ¶ms = lv_->buffer()->params; - bool - redo = false; + BufferParams & params = lv_->buffer()->params; + bool redo = false; params.graphicsDriver = fl_get_choice_text(options_->choice_postscript_driver); @@ -546,6 +547,7 @@ bool FormDocument::options_apply() return redo; } + void FormDocument::bullets_apply() { /* update the bullet settings */ @@ -558,6 +560,7 @@ void FormDocument::bullets_apply() param.user_defined_bullets[3] = param.temp_bullets[3]; } + void FormDocument::cancel() { // this avoids confusion when reopening @@ -568,6 +571,7 @@ void FormDocument::cancel() param.temp_bullets[3] = param.user_defined_bullets[3]; } + void FormDocument::update() { if (!dialog_) @@ -575,8 +579,7 @@ void FormDocument::update() checkReadOnly(); - BufferParams - const & params = lv_->buffer()->params; + BufferParams const & params = lv_->buffer()->params; class_update(params); paper_update(params); @@ -585,12 +588,13 @@ void FormDocument::update() bullets_update(params); } + void FormDocument::class_update(BufferParams const & params) { if (!class_) return; - LyXTextClass - const & tclass = textclasslist.TextClass(params.textclass); + + LyXTextClass const & tclass = textclasslist.TextClass(params.textclass); #ifdef USE_CLASS_COMBO combo_doc_class->select_text( @@ -679,6 +683,7 @@ void FormDocument::class_update(BufferParams const & params) fl_set_input(class_->input_doc_extra, ""); } + void FormDocument::language_update(BufferParams const & params) { if (!language_) @@ -695,6 +700,7 @@ void FormDocument::language_update(BufferParams const & params) fl_set_button(language_->radio_double, 1); } + void FormDocument::options_update(BufferParams const & params) { if (!options_) @@ -712,6 +718,7 @@ void FormDocument::options_update(BufferParams const & params) fl_set_input(options_->input_float_placement, ""); } + void FormDocument::paper_update(BufferParams const & params) { if (!paper_) @@ -738,6 +745,7 @@ void FormDocument::paper_update(BufferParams const & params) fl_set_focus_object(paper_->form, paper_->choice_papersize2); } + void FormDocument::bullets_update(BufferParams const & params) { if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7))) @@ -763,11 +771,12 @@ void FormDocument::bullets_update(BufferParams const & params) fl_set_button(bullets_->radio_bullet_depth_1, 1); fl_set_input(bullets_->input_bullet_latex, - params.user_defined_bullets[0].c_str()); + params.user_defined_bullets[0].getText().c_str()); fl_set_choice(bullets_->choice_bullet_size, params.user_defined_bullets[0].getSize() + 2); } + void FormDocument::free() { if (dialog_) { @@ -807,39 +816,44 @@ void FormDocument::free() } } + int FormDocument::WMHideCB(FL_FORM * form, void *) { // Ensure that the signals (u and h) are disconnected even if the // window manager is used to close the popup. - FormDocument * pre = (FormDocument*)form->u_vdata; + FormDocument * pre = static_cast(form->u_vdata); pre->hide(); pre->bc_->hide(); return FL_CANCEL; } + void FormDocument::OKCB(FL_OBJECT * ob, long) { - FormDocument * pre = (FormDocument*)ob->form->u_vdata; + FormDocument * pre = static_cast(ob->form->u_vdata); pre->apply(); pre->hide(); pre->bc_->ok(); } + void FormDocument::ApplyCB(FL_OBJECT * ob, long) { - FormDocument * pre = (FormDocument*)ob->form->u_vdata; + FormDocument * pre = static_cast(ob->form->u_vdata); pre->apply(); pre->bc_->apply(); } + void FormDocument::CancelCB(FL_OBJECT * ob, long) { - FormDocument * pre = (FormDocument*)ob->form->u_vdata; + FormDocument * pre = static_cast(ob->form->u_vdata); pre->cancel(); pre->hide(); pre->bc_->cancel(); } + void FormDocument::RestoreCB(FL_OBJECT * ob, long) { FormDocument * pre = static_cast(ob->form->u_vdata); @@ -847,12 +861,14 @@ void FormDocument::RestoreCB(FL_OBJECT * ob, long) pre->bc_->undoAll(); } + void FormDocument::InputCB(FL_OBJECT * ob, long) { - FormDocument * pre = (FormDocument*)ob->form->u_vdata; + FormDocument * pre = static_cast(ob->form->u_vdata); pre->bc_->valid(pre->CheckDocumentInput(ob,0)); } + void FormDocument::ComboInputCB(int, void * v, Combox * combox) { FormDocument * pre = static_cast(v); @@ -861,13 +877,15 @@ void FormDocument::ComboInputCB(int, void * v, Combox * combox) pre->bc_->valid(pre->CheckDocumentInput(0,0)); } + void FormDocument::ChoiceClassCB(FL_OBJECT * ob, long) { - FormDocument * pre = (FormDocument*)ob->form->u_vdata; + FormDocument * pre = static_cast(ob->form->u_vdata); pre->CheckChoiceClass(ob,0); pre->bc_->valid(pre->CheckDocumentInput(ob,0)); } + void FormDocument::checkReadOnly() { if (bc_->readOnly(lv_->buffer()->isReadonly())) { @@ -884,11 +902,10 @@ void FormDocument::checkReadOnly() } } + void FormDocument::checkMarginValues() { - int allEmpty; - - allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) && + int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) && !strlen(fl_get_input(paper_->input_bottom_margin)) && !strlen(fl_get_input(paper_->input_left_margin)) && !strlen(fl_get_input(paper_->input_right_margin)) && @@ -990,13 +1007,15 @@ bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long) return ok; } + void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long) { - FormDocument * pre = (FormDocument*)ob->form->u_vdata; + FormDocument * pre = static_cast(ob->form->u_vdata); pre->ChoiceBulletSize(ob,0); pre->bc_->valid(pre->CheckDocumentInput(ob,0)); } + void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ ) { BufferParams & param = lv_->buffer()->params; @@ -1004,16 +1023,18 @@ void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ ) // convert from 1-6 range to -1-4 param.temp_bullets[current_bullet_depth].setSize(fl_get_choice(ob) - 2); fl_set_input(bullets_->input_bullet_latex, - param.temp_bullets[current_bullet_depth].c_str()); + param.temp_bullets[current_bullet_depth].getText().c_str()); } + void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long) { - FormDocument * pre = (FormDocument*)ob->form->u_vdata; + FormDocument * pre = static_cast(ob->form->u_vdata); pre->InputBulletLaTeX(ob,0); pre->bc_->valid(pre->CheckDocumentInput(ob,0)); } + void FormDocument::InputBulletLaTeX(FL_OBJECT *, long) { BufferParams & param = lv_->buffer()->params; @@ -1022,12 +1043,14 @@ void FormDocument::InputBulletLaTeX(FL_OBJECT *, long) setText(fl_get_input(bullets_->input_bullet_latex)); } + void FormDocument::BulletDepthCB(FL_OBJECT * ob, long) { - FormDocument * pre = (FormDocument*)ob->form->u_vdata; + FormDocument * pre = static_cast(ob->form->u_vdata); pre->BulletDepth(ob,0); } + void FormDocument::BulletDepth(FL_OBJECT * ob, long data) { /* Should I do the following: */ @@ -1047,18 +1070,20 @@ void FormDocument::BulletDepth(FL_OBJECT * ob, long data) default: current_bullet_depth = data; fl_set_input(bullets_->input_bullet_latex, - param.temp_bullets[data].c_str()); + param.temp_bullets[data].getText().c_str()); fl_set_choice(bullets_->choice_bullet_size, param.temp_bullets[data].getSize() + 2); } } + void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data) { - FormDocument * pre = (FormDocument*)ob->form->u_vdata; + FormDocument * pre = static_cast(ob->form->u_vdata); pre->BulletPanel(ob,data); } + void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data) { /* Here we have to change the background pixmap to that selected */ @@ -1106,13 +1131,15 @@ void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data) } } + void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long) { - FormDocument * pre = (FormDocument*)ob->form->u_vdata; + FormDocument * pre = static_cast(ob->form->u_vdata); pre->BulletBMTable(ob,0); pre->bc_->valid(pre->CheckDocumentInput(ob,0)); } + void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ ) { /* handle the user input by setting the current bullet depth's pixmap */ @@ -1127,9 +1154,10 @@ void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ ) param.temp_bullets[current_bullet_depth].setFont(current_bullet_panel); param.temp_bullets[current_bullet_depth].setCharacter(bmtable_button); fl_set_input(bullets_->input_bullet_latex, - param.temp_bullets[current_bullet_depth].c_str()); + param.temp_bullets[current_bullet_depth].getText().c_str()); } + void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long) { if (!ob) @@ -1137,7 +1165,7 @@ void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long) ProhibitInput(lv_->view()); int tc; - const char * tct; + string tct; #ifdef USE_CLASS_COMBO tc = combo_doc_class->get(); @@ -1170,6 +1198,7 @@ void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long) AllowInput(lv_->view()); } + void FormDocument::UpdateLayoutDocument(BufferParams const & params) { if (!dialog_) diff --git a/src/frontends/xforms/Toolbar_pimpl.C b/src/frontends/xforms/Toolbar_pimpl.C index 62c362d948..788135c251 100644 --- a/src/frontends/xforms/Toolbar_pimpl.C +++ b/src/frontends/xforms/Toolbar_pimpl.C @@ -63,7 +63,7 @@ void Toolbar::Pimpl::toolbarItem::clean() { Toolbar::Pimpl::toolbarItem & -Toolbar::Pimpl::toolbarItem::operator=(const toolbarItem & ti) { +Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti) { // Are we assigning the object onto itself? if (this == &ti) return *this; diff --git a/src/graphics/EPS_Renderer.C b/src/graphics/EPS_Renderer.C index ee0d1bd061..82a2b12fc5 100644 --- a/src/graphics/EPS_Renderer.C +++ b/src/graphics/EPS_Renderer.C @@ -26,21 +26,21 @@ using std::endl; using std::ios; + EPS_Renderer::EPS_Renderer() : Renderer() {} -EPS_Renderer::~EPS_Renderer() -{} bool EPS_Renderer::renderImage() { return false; } + bool EPS_Renderer::isImageFormatOK(string const & filename) const { - std::ifstream is(filename.c_str(), ios::in); + std::ifstream is(filename.c_str()); // The signature of the file without the spaces. static const char str[] = "%!PS"; diff --git a/src/graphics/EPS_Renderer.h b/src/graphics/EPS_Renderer.h index ed7051c78b..7e36806743 100644 --- a/src/graphics/EPS_Renderer.h +++ b/src/graphics/EPS_Renderer.h @@ -23,12 +23,9 @@ class EPS_Renderer : public Renderer { public: /// c-tor. EPS_Renderer(); - /// d-tor. - virtual ~EPS_Renderer(); /// Load the EPS image and create a pixmap out of it. virtual bool renderImage(); - private: /// Verify that filename is really an EPS file. virtual bool isImageFormatOK(string const & filename) const; diff --git a/src/graphics/GraphicsCache.C b/src/graphics/GraphicsCache.C index b83a78f97a..adb20613d6 100644 --- a/src/graphics/GraphicsCache.C +++ b/src/graphics/GraphicsCache.C @@ -25,12 +25,12 @@ GraphicsCache * GraphicsCache::singleton = 0; GraphicsCache * GraphicsCache::getInstance() { - if (! singleton) { - singleton = new GraphicsCache; + if (!singleton) { + singleton = new GraphicsCache; Assert(singleton != 0); - } + } - return singleton; + return singleton; } @@ -38,34 +38,37 @@ GraphicsCache::~GraphicsCache() { // Free the map. //std::foreach(map.begin(), map.end(), ...); +#warning This is a bogus reason to not clean up after your self. (Lgb) + // Clean up and be done with it. (Lgb) + // This is not really needed, it will only happen on program close and in // any case the OS will release those resources (not doing it may have // a good effect on closing time). - - delete singleton; + + delete singleton; } GraphicsCacheItem * GraphicsCache::addFile(string const & filename) { - CacheType::const_iterator it = cache.find(filename); - - if (it != cache.end()) { - return new GraphicsCacheItem( *((*it).second) ); - } + CacheType::const_iterator it = cache.find(filename); + + if (it != cache.end()) { + return new GraphicsCacheItem( *((*it).second) ); + } GraphicsCacheItem * cacheItem = new GraphicsCacheItem(); if (cacheItem == 0) return 0; - + cacheItem->setFilename(filename); - + cache[filename] = cacheItem; - + // We do not want to return the main cache object, otherwise when the // will destroy their copy they will destroy the main copy. - return new GraphicsCacheItem( *cacheItem ); + return new GraphicsCacheItem( *cacheItem ); } diff --git a/src/graphics/GraphicsCache.h b/src/graphics/GraphicsCache.h index 847eedc789..e9a8c6f88c 100644 --- a/src/graphics/GraphicsCache.h +++ b/src/graphics/GraphicsCache.h @@ -30,32 +30,32 @@ */ class GraphicsCache : public noncopyable { public: - /// Get the instance of the class. - static GraphicsCache * getInstance(); + /// Get the instance of the class. + static GraphicsCache * getInstance(); - /// Add a file to the cache. - GraphicsCacheItem * addFile(string const & filename); + /// Add a file to the cache. + GraphicsCacheItem * addFile(string const & filename); private: - /// Remove a cache item if it's count has gone to zero. - void removeFile(string const & filename); - - /// Private c-tor so we can control how many objects are instantiated. - GraphicsCache() {} - - /// Private d-tor so that no-one will destroy us. - ~GraphicsCache(); - - /// Holder of the single instance of the class. - static GraphicsCache * singleton; - /// - typedef std::map CacheType; - /// - CacheType cache; - - // We need this so that an Item can tell the cache that it should be - // deleted. (to call removeFile). - // It also helps removing a warning gcc emits. + /// Remove a cache item if it's count has gone to zero. + void removeFile(string const & filename); + + /// Private c-tor so we can control how many objects are instantiated. + GraphicsCache() {} + + /// Private d-tor so that no-one will destroy us. + ~GraphicsCache(); + + /// Holder of the single instance of the class. + static GraphicsCache * singleton; + /// + typedef std::map CacheType; + /// + CacheType cache; + + /** We need this so that an Item can tell the cache that it should be + deleted. (to call removeFile). + It also helps removing a warning gcc emits. */ friend class GraphicsCacheItem; }; #endif diff --git a/src/graphics/GraphicsCacheItem.C b/src/graphics/GraphicsCacheItem.C index 2cea9589ad..a92f0812b2 100644 --- a/src/graphics/GraphicsCacheItem.C +++ b/src/graphics/GraphicsCacheItem.C @@ -19,17 +19,20 @@ #include "graphics/GraphicsCacheItem.h" #include "graphics/GraphicsCacheItem_pimpl.h" + GraphicsCacheItem::GraphicsCacheItem() : pimpl(new GraphicsCacheItem_pimpl) { pimpl->refCount = 1; } + GraphicsCacheItem::~GraphicsCacheItem() { destroy(); } + bool GraphicsCacheItem::setFilename(string const & filename) { @@ -37,20 +40,21 @@ GraphicsCacheItem::setFilename(string const & filename) return pimpl->setFilename(filename); } + GraphicsCacheItem::GraphicsCacheItem(GraphicsCacheItem const & gci) { pimpl = 0; copy(gci); } -GraphicsCacheItem const & +GraphicsCacheItem & GraphicsCacheItem::operator=(GraphicsCacheItem const & gci) { // Are we trying to copy the object onto itself. if (this == &gci) return *this; - // Destory old copy + // Destroy old copy destroy(); // And then copy new object. @@ -59,6 +63,7 @@ GraphicsCacheItem::operator=(GraphicsCacheItem const & gci) return *this; } + void GraphicsCacheItem::copy(GraphicsCacheItem const & gci) { @@ -66,6 +71,7 @@ GraphicsCacheItem::copy(GraphicsCacheItem const & gci) ++(pimpl->refCount); } + void GraphicsCacheItem::destroy() { @@ -79,14 +85,18 @@ GraphicsCacheItem::destroy() } } + GraphicsCacheItem::ImageStatus GraphicsCacheItem::getImageStatus() const { return pimpl->imageStatus_; } + int GraphicsCacheItem::getHeight() const { return pimpl->height_; } - + + int GraphicsCacheItem::getWidth() const { return pimpl->width_; } + Pixmap GraphicsCacheItem::getImage() const { return pimpl->pixmap_; } diff --git a/src/graphics/GraphicsCacheItem.h b/src/graphics/GraphicsCacheItem.h index 53dca53c9c..01843f46ce 100644 --- a/src/graphics/GraphicsCacheItem.h +++ b/src/graphics/GraphicsCacheItem.h @@ -47,7 +47,7 @@ public: /// copy c-tor. GraphicsCacheItem(GraphicsCacheItem const &); /// Assignment operator. - GraphicsCacheItem const & operator=(GraphicsCacheItem const &); + GraphicsCacheItem & operator=(GraphicsCacheItem const &); /// Get the height of the image. Returns -1 on error. int getHeight() const; diff --git a/src/graphics/GraphicsCacheItem_pimpl.C b/src/graphics/GraphicsCacheItem_pimpl.C index 3fab0167b0..d13c7d37b5 100644 --- a/src/graphics/GraphicsCacheItem_pimpl.C +++ b/src/graphics/GraphicsCacheItem_pimpl.C @@ -11,6 +11,12 @@ #include +#include + +#include // unlink + +#include FORMS_H_LOCATION + #ifdef __GNUG__ #pragma implementation #endif @@ -23,11 +29,6 @@ #include "support/filetools.h" #include "debug.h" #include "support/LAssert.h" -#include // unlink - -#include - -#include FORMS_H_LOCATION using std::endl; using std::map; @@ -38,6 +39,7 @@ GraphicsCacheItem_pimpl::GraphicsCacheItem_pimpl() pixmap_(0), renderer(0), refCount(0) {} + GraphicsCacheItem_pimpl::~GraphicsCacheItem_pimpl() { if (imageStatus_ == GraphicsCacheItem::Loaded) { @@ -47,6 +49,7 @@ GraphicsCacheItem_pimpl::~GraphicsCacheItem_pimpl() delete renderer; } + bool GraphicsCacheItem_pimpl::setFilename(string const & filename) { @@ -59,15 +62,17 @@ GraphicsCacheItem_pimpl::setFilename(string const & filename) return false; } + /*** Callback method ***/ typedef map CallbackMap; static CallbackMap callbackMap; + void callback(string cmd, int retval) { - lyxerr << "callback, cmd="<data->wid << ' ' << p->data->hgh << " 72 72 0 0 0 0"; -#ifndef HAVE_SSTREAM - t1 << '\0'; -#endif +//#ifndef HAVE_SSTREAM +// t1 << '\0'; +//#endif if (lyxerr.debugging()) { lyxerr << "Will set GHOSTVIEW property to [" @@ -613,7 +613,7 @@ void runqueue() ::sleep(1); XGrabServer(tempdisp); } -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM XChangeProperty(tempdisp, fl_get_canvas_id(figinset_canvas), XInternAtom(tempdisp, "GHOSTVIEW", false), @@ -621,25 +621,25 @@ void runqueue() 8, PropModeAppend, reinterpret_cast(const_cast(t1.str().c_str())), t1.str().size()); -#else - - XChangeProperty(tempdisp, - fl_get_canvas_id(figinset_canvas), - XInternAtom(tempdisp, "GHOSTVIEW", false), - XInternAtom(tempdisp, "STRING", false), - 8, PropModeAppend, - reinterpret_cast(const_cast(t1.str())), - ::strlen(t1.str())); -#endif +//#else +// +// XChangeProperty(tempdisp, +// fl_get_canvas_id(figinset_canvas), +// XInternAtom(tempdisp, "GHOSTVIEW", false), +// XInternAtom(tempdisp, "STRING", false), +// 8, PropModeAppend, +// reinterpret_cast(const_cast(t1.str())), +// ::strlen(t1.str())); +//#endif XUngrabServer(tempdisp); XFlush(tempdisp); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM ostringstream t3; -#else - //char tbuf[384]; - ostrstream t3(tbuf, sizeof(tbuf)); -#endif +//#else +// //char tbuf[384]; +// ostrstream t3(tbuf, sizeof(tbuf)); +//#endif switch (p->data->flags & 3) { case 0: t3 << 'H'; break; // Hidden case 1: t3 << 'M'; break; // Mono @@ -654,12 +654,12 @@ void runqueue() t3 << ' ' << BlackPixelOfScreen(DefaultScreenOfDisplay(tempdisp)) << ' ' << background_pixel; -#ifndef HAVE_SSTREAM - t3 << '\0'; -#endif +//#ifndef HAVE_SSTREAM +// t3 << '\0'; +//#endif XGrabServer(tempdisp); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM XChangeProperty(tempdisp, fl_get_canvas_id(figinset_canvas), XInternAtom(tempdisp, @@ -668,16 +668,16 @@ void runqueue() 8, PropModeReplace, reinterpret_cast(const_cast(t3.str().c_str())), t3.str().size()); -#else - XChangeProperty(tempdisp, - fl_get_canvas_id(figinset_canvas), - XInternAtom(tempdisp, - "GHOSTVIEW_COLORS", false), - XInternAtom(tempdisp, "STRING", false), - 8, PropModeReplace, - reinterpret_cast(const_cast(t3.str())), - ::strlen(t3.str())); -#endif +//#else +// XChangeProperty(tempdisp, +// fl_get_canvas_id(figinset_canvas), +// XInternAtom(tempdisp, +// "GHOSTVIEW_COLORS", false), +// XInternAtom(tempdisp, "STRING", false), +// 8, PropModeReplace, +// reinterpret_cast(const_cast(t3.str())), +// ::strlen(t3.str())); +//#endif XUngrabServer(tempdisp); XFlush(tempdisp); @@ -691,14 +691,14 @@ void runqueue() ++ne; typedef char * char_p; env = new char_p[ne + 2]; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM string tmp = t2.str().c_str(); env[0] = new char[tmp.size() + 1]; std::copy(tmp.begin(), tmp.end(), env[0]); env[0][tmp.size()] = '\0'; -#else - env[0] = tbuf2; -#endif +//#else +// env[0] = tbuf2; +//#endif ::memcpy(&env[1], environ, sizeof(char*) * (ne + 1)); environ = env; @@ -1250,7 +1250,7 @@ bool InsetFig::Deletable() const } -char const * InsetFig::EditMessage() const +string const InsetFig::EditMessage() const { return _("Opened figure"); } @@ -1957,7 +1957,7 @@ void InsetFig::RestoreForm() } -void InsetFig::Preview(char const * p) +void InsetFig::Preview(string const & p) { int pid = fork(); diff --git a/src/insets/figinset.h b/src/insets/figinset.h index b48d9235d2..8c0799cca0 100644 --- a/src/insets/figinset.h +++ b/src/insets/figinset.h @@ -47,7 +47,7 @@ public: void Validate(LaTeXFeatures & features) const; /// what appears in the minibuffer when opening - char const * EditMessage() const; + string const EditMessage() const; /// void Edit(BufferView *, int, int, unsigned int); @@ -62,7 +62,7 @@ public: /// void CallbackFig(long arg); /// - void Preview(char const * p); + void Preview(string const & p); /// browse for file void BrowseFile(); diff --git a/src/insets/inset.C b/src/insets/inset.C index e948979a6b..77b969764d 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -64,13 +64,13 @@ void Inset::Edit(BufferView *, int, int, unsigned int) } -LyXFont Inset::ConvertFont(LyXFont const & font) const +LyXFont const Inset::ConvertFont(LyXFont const & font) const { return LyXFont(font); } -char const * Inset::EditMessage() const +string const Inset::EditMessage() const { return _("Opened inset"); } diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 1f1dcfbf9a..2cf364350d 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -153,7 +153,7 @@ void InsetBibKey::Read(Buffer const *, LyXLex & lex) } -string InsetBibKey::getScreenLabel() const +string const InsetBibKey::getScreenLabel() const { if (! getOptions().empty()) return getOptions(); @@ -214,7 +214,7 @@ InsetBibtex::~InsetBibtex() } -string InsetBibtex::getScreenLabel() const +string const InsetBibtex::getScreenLabel() const { return _("BibTeX Generated References"); } @@ -262,7 +262,7 @@ int InsetBibtex::Latex(Buffer const *, ostream & os, // This method returns a comma separated list of Bibtex entries -vector > InsetBibtex::getKeys() const +vector > const InsetBibtex::getKeys() const { // This hack is copied from InsetBibtex::Latex. // Is it still needed? Probably yes. @@ -397,7 +397,7 @@ int bibitemMaxWidth(BufferView * bv, LyXFont const & font) // ale070405 -string bibitemWidest(BufferView * bv) +string const bibitemWidest(BufferView * bv) { int w = 0; // Does look like a hack? It is! (but will change at 0.13) diff --git a/src/insets/insetbib.h b/src/insets/insetbib.h index 58266516ab..a717f52d30 100644 --- a/src/insets/insetbib.h +++ b/src/insets/insetbib.h @@ -42,7 +42,7 @@ public: /// void Read(Buffer const *, LyXLex & lex); /// - virtual string getScreenLabel() const; + virtual string const getScreenLabel() const; /// void Edit(BufferView *, int x, int y, unsigned int button); /// @@ -84,7 +84,7 @@ public: /// Inset * Clone() const { return new InsetBibtex(params(), owner); } /// - string getScreenLabel() const; + string const getScreenLabel() const; /// EDITABLE Editable() const { return IS_EDITABLE; } /// @@ -95,7 +95,7 @@ public: int Latex(Buffer const *, std::ostream &, bool fragile, bool freespace) const; /// - std::vector > getKeys() const; + std::vector > const getKeys() const; /// bool addDatabase(string const &); /// diff --git a/src/insets/insetbutton.h b/src/insets/insetbutton.h index 7176769d71..c6a6a12ffc 100644 --- a/src/insets/insetbutton.h +++ b/src/insets/insetbutton.h @@ -34,7 +34,7 @@ public: protected: /// This should provide the text for the button - virtual string getScreenLabel() const = 0; + virtual string const getScreenLabel() const = 0; }; #endif diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index f0d33a8021..640c53695b 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -24,7 +24,7 @@ InsetCitation::InsetCitation(InsetCommandParams const & p) : InsetCommand(p) {} -string InsetCitation::getScreenLabel() const +string const InsetCitation::getScreenLabel() const { string keys(getContents()); @@ -56,6 +56,7 @@ string InsetCitation::getScreenLabel() const return '[' + label + ']'; } + void InsetCitation::Edit(BufferView * bv, int, int, unsigned int) { bv->owner()->getDialogs()->showCitation( this ); diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index fc2487c41c..43d3c21a27 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -26,7 +26,7 @@ public: /// Inset * Clone() const { return new InsetCitation(params()); } /// - string getScreenLabel() const; + string const getScreenLabel() const; /// EDITABLE Editable() const { return IS_EDITABLE; } /// diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 5c1e972ed6..0530cc516e 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -33,7 +33,7 @@ InsetCommandParams::InsetCommandParams( string const & n, {} -string InsetCommandParams::getAsString() const +string const InsetCommandParams::getAsString() const { string b(cmdname); b += "|++|" + options + "|++|" + contents; @@ -66,19 +66,14 @@ void InsetCommandParams::setFromString( string const & b ) bool InsetCommandParams::operator==(InsetCommandParams const & o) const { - if( cmdname != o.cmdname ) return false; - if( contents != o.contents ) return false; - if( options != o.options ) return false; - return true; + if (cmdname == o.cmdname && contents == o.contents && options == o.options) return true; + return false; } bool InsetCommandParams::operator!=(InsetCommandParams const & o) const { - if( cmdname != o.cmdname ) return true; - if( contents != o.contents ) return true; - if( options != o.options ) return true; - return false; + return !(*this == o); } @@ -173,7 +168,7 @@ void InsetCommandParams::Write(ostream & os) const } -string InsetCommandParams::getCommand() const +string const InsetCommandParams::getCommand() const { string s; if (!getCmdName().empty()) s += "\\"+getCmdName(); diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index bc040acd22..8a4fdcfcaa 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -50,7 +50,7 @@ public: /// void Write(std::ostream &) const; /// Build the complete LaTeX command - string getCommand() const; + string const getCommand() const; /// string const & getCmdName() const { return cmdname; } /// @@ -64,7 +64,7 @@ public: /// void setContents(string const & c) { contents = c; } /// - string getAsString() const; + string const getAsString() const; /// void setFromString( string const & ); private: @@ -111,9 +111,9 @@ public: confusion with lyxinset::getLabel(int), but I've seen that it wasn't. I hope you never confuse again both methods. (ale) */ - virtual string getScreenLabel() const = 0; + virtual string const getScreenLabel() const = 0; /// - string getCommand() const { return p_.getCommand(); } + string const getCommand() const { return p_.getCommand(); } /// string const & getCmdName() const { return p_.getCmdName(); } /// diff --git a/src/insets/inseterror.C b/src/insets/inseterror.C index 7cfdd4b250..efabf8bf2a 100644 --- a/src/insets/inseterror.C +++ b/src/insets/inseterror.C @@ -162,7 +162,7 @@ void C_InsetError_CloseErrorCB(FL_OBJECT * ob, long data) } -char const * InsetError::EditMessage() const +string const InsetError::EditMessage() const { return _("Opened error"); } diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index d1a19f8491..6f2770bf50 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -61,7 +61,7 @@ public: /// bool AutoDelete() const; /// what appears in the minibuffer when opening - char const * EditMessage() const; + string const EditMessage() const; /// void Edit(BufferView *, int x, int y, unsigned int button); /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 2abd91b8e4..f90eaba32f 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -54,7 +54,7 @@ Inset * InsetERT::Clone() const } -char const * InsetERT::EditMessage() const +string const InsetERT::EditMessage() const { return _("Opened ERT Inset"); } diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 77c63df10a..0ba3405cb3 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -34,7 +34,7 @@ public: /// Inset * Clone() const; /// - char const * EditMessage() const; + string const EditMessage() const; /// bool InsertInset(BufferView *, Inset *) { return false; } /// diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index caaad36f99..6da89c9812 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -245,10 +245,10 @@ void InsetExternal::cancelCB(FL_OBJECT * ob, long) } -char const * InsetExternal::EditMessage() const +string const InsetExternal::EditMessage() const { ExternalTemplate const & et = getTemplate(templatename); - return doSubstitution(0, et.guiName).c_str(); + return doSubstitution(0, et.guiName); } @@ -402,7 +402,7 @@ Inset * InsetExternal::Clone() const } -string InsetExternal::getScreenLabel() const +string const InsetExternal::getScreenLabel() const { if (templatename.empty()) { return _("External"); @@ -469,7 +469,7 @@ void InsetExternal::automaticUpdate(BufferView const * bv) const } -string InsetExternal::doSubstitution(Buffer const * buffer, +string const InsetExternal::doSubstitution(Buffer const * buffer, string const & s) const { string result; @@ -506,13 +506,13 @@ string InsetExternal::doSubstitution(Buffer const * buffer, } -string InsetExternal::getCurrentTemplate() const +string const InsetExternal::getCurrentTemplate() const { return getTemplateName(fl_get_choice(form_external->templatechoice)); } -ExternalTemplate InsetExternal::getTemplate(string const & name) const +ExternalTemplate const InsetExternal::getTemplate(string const & name) const { ExternalTemplateManager::Templates::const_iterator i = ExternalTemplateManager::get().getTemplates().find(name); @@ -543,7 +543,7 @@ int InsetExternal::getTemplateNumber(string const & name) const } -string InsetExternal::getTemplateName(int i) const +string const InsetExternal::getTemplateName(int i) const { ExternalTemplateManager::Templates::const_iterator i1; i1 = ExternalTemplateManager::get().getTemplates().begin(); @@ -554,7 +554,7 @@ string InsetExternal::getTemplateName(int i) const } -string InsetExternal::getTemplateString() const +string const InsetExternal::getTemplateString() const { string result; bool first = true; diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 58f1b6763c..2c02c285d1 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -29,7 +29,7 @@ public: /// virtual ~InsetExternal(); /// what appears in the minibuffer when opening - virtual char const * EditMessage() const; + virtual string const EditMessage() const; /// virtual void Edit(BufferView *, int x, int y, unsigned int button); /// @@ -62,7 +62,7 @@ public: virtual Inset * Clone() const; /// returns the text of the button - virtual string getScreenLabel() const; + virtual string const getScreenLabel() const; /// Callback function for the template drop-down static void templateCB(FL_OBJECT *, long); @@ -106,27 +106,27 @@ private: void doView(BufferView const *) const; /// Substitute meta-variables in this string - string doSubstitution(Buffer const *, string const & s) const; + string const doSubstitution(Buffer const *, string const & s) const; /** Get the LyX name of the currently selected template in the choice list */ - string getCurrentTemplate() const; + string const getCurrentTemplate() const; /// Get a certain template from a LyX name - ExternalTemplate getTemplate(string const & lyxname) const; + ExternalTemplate const getTemplate(string const & lyxname) const; /** - * Get the number starting from 1 of a template with a - * specific LyX name for the choice list + Get the number starting from 1 of a template with a + specific LyX name for the choice list */ int getTemplateNumber(string const & guiname) const; /// Get the LyX name of a template with a given number starting from 1 - string getTemplateName(int n) const; + string const getTemplateName(int n) const; /// Get a string with all the GUI template names separated by | - string getTemplateString() const; + string const getTemplateString() const; /// struct Holder { diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index dd482beefd..0a104ae345 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -146,7 +146,7 @@ Inset * InsetFloat::Clone() const } -char const * InsetFloat::EditMessage() const +string const InsetFloat::EditMessage() const { return _("Opened Float Inset"); } diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index 3fca507bb1..821fd7409f 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -40,7 +40,7 @@ public: /// int Latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// - const char * EditMessage() const; + string const EditMessage() const; /// bool InsertInsetAllowed(Inset * inset) const; /// diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index 732c0441b4..c806568c2e 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -45,7 +45,7 @@ Inset * InsetFoot::Clone() const } -char const * InsetFoot::EditMessage() const +string const InsetFoot::EditMessage() const { return _("Opened Footnote Inset"); } diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index d84e1327c2..8c83d5a65c 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -34,7 +34,7 @@ public: /// int Latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// - const char * EditMessage() const; + string const EditMessage() const; /// bool InsertInsetAllowed(Inset * inset) const; }; diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 806ffebbf6..f260fb1a63 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -368,8 +368,9 @@ void InsetGraphics::Read(Buffer const * buf, LyXLex & lex) updateInset(); } -static void formatResize(ostream & os, char const *key, - InsetGraphicsParams::Resize resizeType, double size) +static +void formatResize(ostream & os, string const & key, + InsetGraphicsParams::Resize resizeType, double size) { switch (resizeType) { case InsetGraphicsParams::DEFAULT_SIZE: @@ -423,11 +424,11 @@ int InsetGraphics::Latex(Buffer const *buf, ostream & os, // Calculate the options part of the command, we must do it to a string // stream since we might have a trailing comma that we would like to remove // before writing it to the output stream. -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream options; -#else - ostrstream options; -#endif +//#else +// ostrstream options; +//#endif formatResize(options, "width", params.widthResize, params.widthSize); formatResize(options, "height", params.heightResize, params.heightSize); @@ -543,14 +544,14 @@ int InsetGraphics::Latex(Buffer const *buf, ostream & os, } #endif -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM string opts(options.str().c_str()); -#else - options << '\0'; - char * tmp = options.str(); - string opts(tmp); - delete [] tmp; -#endif +//#else +// options << '\0'; +// char * tmp = options.str(); +// string opts(tmp); +// delete [] tmp; +//#endif opts = strip(opts, ','); diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index a285b7929a..ec1c1bae11 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -36,11 +36,10 @@ class Dialogs; /// #ifdef SIGC_CXX_NAMESPACES class InsetGraphics : public Inset, public SigC::Object -{ #else class InsetGraphics : public Inset, public Object +#endif { -#endif public: /// InsetGraphics(); @@ -66,8 +65,8 @@ public: void Read(Buffer const *, LyXLex & lex); /** returns the number of rows (\n's) of generated tex code. - fragile == true means, that the inset should take care about - fragile commands by adding a \protect before. + #fragile == true# means, that the inset should take care about + fragile commands by adding a #\protect# before. */ int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const; @@ -79,8 +78,8 @@ public: int DocBook(Buffer const *, std::ostream &) const; /** Tell LyX what the latex features you need i.e. what latex packages - * you need to be included. - */ + you need to be included. + */ void Validate(LaTeXFeatures & features) const; /// returns LyX code associated with the inset. Used for TOC, ...) @@ -89,16 +88,18 @@ public: /// Inset * Clone() const; - /// Set the inset parameters, used by the GUIndependent dialog. - /// Return true of new params are different from what was so far. + /** Set the inset parameters, used by the GUIndependent dialog. + Return true of new params are different from what was so far. + */ bool setParams(InsetGraphicsParams const & params); /// Get the inset parameters, used by the GUIndependent dialog. InsetGraphicsParams getParams() const; - /// This signal is connected by our dialog and called when the inset - /// is deleted. - Signal0 < void > hide; + /** This signal is connected by our dialog and called when the inset + is deleted. + */ + Signal0 hide; private: /// Update the inset after parameter change. void updateInset(); diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index 7c3b0e89b9..8ac312521a 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -94,8 +94,8 @@ InsetGraphicsParams::InsetGraphicsParams(InsetGraphicsParams const & igp) copy(igp); } -InsetGraphicsParams const & -InsetGraphicsParams::operator=(InsetGraphicsParams const ¶ms) +InsetGraphicsParams & +InsetGraphicsParams::operator=(InsetGraphicsParams const & params) { // Are we assigning the object into itself? if (this == ¶ms) @@ -197,7 +197,9 @@ bool operator==(InsetGraphicsParams const & left, return false; } -static void writeResize(ostream & os, char const * key, + +static +void writeResize(ostream & os, string const & key, InsetGraphicsParams::Resize resize, double size) { os << ' ' << key << "Resize "; diff --git a/src/insets/insetgraphicsParams.h b/src/insets/insetgraphicsParams.h index f6bce4aeef..605ddd43f3 100644 --- a/src/insets/insetgraphicsParams.h +++ b/src/insets/insetgraphicsParams.h @@ -71,8 +71,8 @@ struct InsetGraphicsParams REFERENCE_POINT = LEFTBASELINE }; - /// The resize of the image, is it the default size, in cm, inch or - /// percentage of the page/column width/height + /** The resize of the image, is it the default size, in cm, inch or + percentage of the page/column width/height */ enum Resize { DEFAULT_SIZE, CM, @@ -85,24 +85,25 @@ struct InsetGraphicsParams /// Keep the ratio between height and width when resizing. bool keepAspectRatio; - // What width resize to do? + /// What width resize to do? Resize widthResize; - // Value of width resize + /// Value of width resize float widthSize; - // What height resize to do? + /// What height resize to do? Resize heightResize; - // Value of height resize + /// Value of height resize float heightSize; - // Origin point of rotation + /// Origin point of rotation Origin rotateOrigin; - // Rotation angle. + /// Rotation angle. int rotateAngle; - + /// InsetGraphicsParams(); - + /// InsetGraphicsParams(InsetGraphicsParams const &); - InsetGraphicsParams const & operator=(InsetGraphicsParams const &); + /// + InsetGraphicsParams & operator=(InsetGraphicsParams const &); /// Save the parameters in the LyX format stream. void Write(Buffer const * buf, ostream & os) const; @@ -121,6 +122,7 @@ private: void copy(InsetGraphicsParams const & params); }; -bool operator==(InsetGraphicsParams const&, InsetGraphicsParams const &); +/// +bool operator==(InsetGraphicsParams const &, InsetGraphicsParams const &); #endif diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index bb2c28c854..835e1fac42 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -190,23 +190,24 @@ void include_cb(FL_OBJECT *, long arg) } -static string unique_id() { +static inline +string unique_id() { static unsigned int seed=1000; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; ost << "file" << ++seed; // Needed if we use lyxstring. return ost.str().c_str(); -#else - char ctmp[16]; - ostrstream ost(ctmp,16); - ost << "file" << ++seed << '\0'; - - // Needed if we use lyxstring. - return ost.str(); -#endif +//#else +// char ctmp[16]; +// ostrstream ost(ctmp,16); +// ost << "file" << ++seed << '\0'; +// +// // Needed if we use lyxstring. +// return ost.str(); +//#endif } @@ -313,7 +314,7 @@ bool InsetInclude::display() const } -string InsetInclude::getScreenLabel() const +string const InsetInclude::getScreenLabel() const { string temp; if (isInput()) @@ -333,14 +334,14 @@ string InsetInclude::getScreenLabel() const } -string InsetInclude::getFileName() const +string const InsetInclude::getFileName() const { return MakeAbsPath(getContents(), OnlyPath(getMasterFilename())); } -string InsetInclude::getMasterFilename() const +string const InsetInclude::getMasterFilename() const { return master->fileName(); } @@ -535,7 +536,7 @@ void InsetInclude::Validate(LaTeXFeatures & features) const } -vector InsetInclude::getLabelList() const +vector const InsetInclude::getLabelList() const { vector l; string parentname; @@ -551,7 +552,7 @@ vector InsetInclude::getLabelList() const } -vector > InsetInclude::getKeys() const +vector > const InsetInclude::getKeys() const { vector > keys; diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index ff6477c069..954342cd5e 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -35,9 +35,9 @@ public: /// Inset::Code LyxCode() const { return Inset::INCLUDE_CODE; } /// This returns the list of labels on the child buffer - std::vector getLabelList() const; + std::vector const getLabelList() const; /// This returns the list of bibkeys on the child buffer - std::vector< std::pair > getKeys() const; + std::vector< std::pair > const getKeys() const; /// void Edit(BufferView *, int x, int y, unsigned int button); /// @@ -63,11 +63,11 @@ public: */ bool display() const; /// - string getScreenLabel() const; + string const getScreenLabel() const; /// - string getMasterFilename() const; + string const getMasterFilename() const; /// - string getFileName() const; + string const getFileName() const; /// In "input" mode uses \input instead of \include. bool isInput() const { return flag == InsetInclude::INPUT; } diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index c5ebb9b92f..7f8cbe6f00 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -15,7 +15,7 @@ InsetIndex::InsetIndex(InsetCommandParams const & p) {} -string InsetIndex::getScreenLabel() const +string const InsetIndex::getScreenLabel() const { return _("Idx"); } @@ -31,7 +31,7 @@ InsetPrintIndex::InsetPrintIndex(InsetCommandParams const & p) : InsetCommand(p) {} -string InsetPrintIndex::getScreenLabel() const +string const InsetPrintIndex::getScreenLabel() const { return _("Index"); } diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index 92b6f57542..7d0120ab4f 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -29,7 +29,7 @@ public: /// Inset * Clone() const { return new InsetIndex(params());} /// - string getScreenLabel() const; + string const getScreenLabel() const; /// EDITABLE Editable() const { return IS_EDITABLE; } /// @@ -54,7 +54,7 @@ public: /// Inset::Code LyxCode() const; /// - string getScreenLabel() const; + string const getScreenLabel() const; }; #endif diff --git a/src/insets/insetinfo.C b/src/insets/insetinfo.C index 445bb65c0f..55d6cf9111 100644 --- a/src/insets/insetinfo.C +++ b/src/insets/insetinfo.C @@ -193,7 +193,7 @@ void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data) } -char const * InsetInfo::EditMessage() const +string const InsetInfo::EditMessage() const { return _("Opened note"); } diff --git a/src/insets/insetinfo.h b/src/insets/insetinfo.h index 01894676d6..9e9b342e58 100644 --- a/src/insets/insetinfo.h +++ b/src/insets/insetinfo.h @@ -59,7 +59,7 @@ public: /// int DocBook(Buffer const *, std::ostream &) const; /// what appears in the minibuffer when opening - char const * EditMessage() const; + string const EditMessage() const; /// void Edit(BufferView *, int, int, unsigned int); /// diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index 2aa37e0efd..666c41a3be 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -33,7 +33,7 @@ InsetLabel::InsetLabel(InsetCommandParams const & p) {} -vector InsetLabel::getLabelList() const +vector const InsetLabel::getLabelList() const { return vector(1,getContents()); } @@ -96,7 +96,7 @@ int InsetLabel::DocBook(Buffer const *, ostream & os) const // This function escapes 8-bit characters and other problematic characters // It's exactly the same code as in insetref.C. -string InsetLabel::escape(string const & lab) const { +string const InsetLabel::escape(string const & lab) const { char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; string enc; diff --git a/src/insets/insetlabel.h b/src/insets/insetlabel.h index 39cc24e8e0..ccaa4c084b 100644 --- a/src/insets/insetlabel.h +++ b/src/insets/insetlabel.h @@ -25,7 +25,7 @@ public: /// Inset * Clone() const { return new InsetLabel(params()); } /// - string getScreenLabel() const { return getContents(); } + string const getScreenLabel() const { return getContents(); } /// EDITABLE Editable() const { return IS_EDITABLE; } /// @@ -33,7 +33,7 @@ public: /// void Edit(BufferView *, int, int, unsigned int); /// - std::vector getLabelList() const; + std::vector const getLabelList() const; /// int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const; @@ -45,7 +45,7 @@ public: int DocBook(Buffer const *, std::ostream &) const; private: /// This function escapes 8-bit characters - string escape(string const &) const; + string const escape(string const &) const; }; #endif diff --git a/src/insets/insetlist.C b/src/insets/insetlist.C index 0b33ce08f7..a71be8a629 100644 --- a/src/insets/insetlist.C +++ b/src/insets/insetlist.C @@ -67,7 +67,7 @@ Inset * InsetList::Clone() const } -char const * InsetList::EditMessage() const +string const InsetList::EditMessage() const { return _("Opened List Inset"); } diff --git a/src/insets/insetlist.h b/src/insets/insetlist.h index b8a0e1c3f5..bb8c02eb11 100644 --- a/src/insets/insetlist.h +++ b/src/insets/insetlist.h @@ -34,7 +34,7 @@ public: /// int Latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// - const char * EditMessage() const; + string const EditMessage() const; /// bool InsertInsetAllowed(Inset * inset) const; }; diff --git a/src/insets/insetmarginal.C b/src/insets/insetmarginal.C index 017a0e642d..9d078780a9 100644 --- a/src/insets/insetmarginal.C +++ b/src/insets/insetmarginal.C @@ -45,7 +45,7 @@ Inset * InsetMarginal::Clone() const } -char const * InsetMarginal::EditMessage() const +string const InsetMarginal::EditMessage() const { return _("Opened Marginal Note Inset"); } diff --git a/src/insets/insetmarginal.h b/src/insets/insetmarginal.h index cf68c7631f..d8253c6343 100644 --- a/src/insets/insetmarginal.h +++ b/src/insets/insetmarginal.h @@ -32,7 +32,7 @@ public: /// int Latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// - const char * EditMessage() const; + string const EditMessage() const; /// bool InsertInsetAllowed(Inset * inset) const; }; diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 80083833d4..7d34868024 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -85,7 +85,7 @@ Inset * InsetMinipage::Clone() const } -char const * InsetMinipage::EditMessage() const +string const InsetMinipage::EditMessage() const { return _("Opened Minipage Inset"); } diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index a9800d08fd..a85ab503ee 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -34,7 +34,7 @@ public: /// int Latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// - const char * EditMessage() const; + string const EditMessage() const; /// bool InsertInsetAllowed(Inset * inset) const; }; diff --git a/src/insets/insetparent.C b/src/insets/insetparent.C index 3672116110..05b14f1626 100644 --- a/src/insets/insetparent.C +++ b/src/insets/insetparent.C @@ -28,6 +28,7 @@ using std::ostream; + InsetParent::InsetParent(InsetCommandParams const & p, Buffer * bf) : InsetCommand(p) { @@ -39,7 +40,7 @@ InsetParent::InsetParent(InsetCommandParams const & p, Buffer * bf) } -string InsetParent::getScreenLabel() const +string const InsetParent::getScreenLabel() const { return string(_("Parent:")) + getContents(); } diff --git a/src/insets/insetparent.h b/src/insets/insetparent.h index 0a1e982702..548acbaea4 100644 --- a/src/insets/insetparent.h +++ b/src/insets/insetparent.h @@ -31,7 +31,7 @@ public: /// Inset * Clone() const { return new InsetParent(params()); } /// - string getScreenLabel() const; + string const getScreenLabel() const; /// EDITABLE Editable() const { return IS_EDITABLE; } /// diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 8c9bd55521..b03780babe 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -141,7 +141,7 @@ void InsetQuotes::ParseString(string const & s) } -string InsetQuotes::DispString() const +string const InsetQuotes::DispString() const { string disp; disp += quote_char[quote_index[side][language]]; @@ -188,9 +188,7 @@ int InsetQuotes::width(BufferView *, LyXFont const & font) const } -//LyXFont InsetQuotes::ConvertFont(LyXFont font) -// I really belive this should be -LyXFont InsetQuotes::ConvertFont(LyXFont const & f) const +LyXFont const InsetQuotes::ConvertFont(LyXFont const & f) const { LyXFont font(f); // quotes-insets cannot be latex of any kind diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index f19a7b7792..eb4ce51012 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -80,8 +80,7 @@ public: /// void draw(BufferView *, LyXFont const &, int, float &, bool) const; /// - LyXFont ConvertFont(LyXFont const & font) const; - //LyXFont ConvertFont(LyXFont font); + LyXFont const ConvertFont(LyXFont const & font) const; /// void Write(Buffer const *, std::ostream &) const; /// @@ -116,7 +115,7 @@ private: /// void ParseString(string const &); /// - string DispString() const; + string const DispString() const; }; #endif diff --git a/src/insets/insetref.C b/src/insets/insetref.C index 0f50539eff..d40fe4c2c6 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -34,7 +34,7 @@ void InsetRef::Edit(BufferView * bv, int, int, unsigned int button) } -string InsetRef::getScreenLabel() const +string const InsetRef::getScreenLabel() const { string temp; if (getCmdName() == "ref") @@ -97,7 +97,7 @@ int InsetRef::DocBook(Buffer const *, ostream & os) const // This function escapes 8-bit characters and other problematic characters // It's exactly the same code as in insetlabel.C. -string InsetRef::escape(string const & lab) const +string const InsetRef::escape(string const & lab) const { char hexdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; @@ -115,6 +115,7 @@ string InsetRef::escape(string const & lab) const return enc; } + void InsetRef::Validate(LaTeXFeatures & features) const { if (getCmdName() == "vref" || getCmdName() == "vpageref") diff --git a/src/insets/insetref.h b/src/insets/insetref.h index 3b889dda85..655602350d 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -28,7 +28,7 @@ public: /// Inset * Clone() const { return new InsetRef(params()); } /// - string getScreenLabel() const; + string const getScreenLabel() const; /// EDITABLE Editable() const { return IS_EDITABLE; } /// @@ -50,6 +50,6 @@ public: void Validate(LaTeXFeatures & features) const; private: /// This function escapes 8-bit characters - string escape(string const &) const; + string const escape(string const &) const; }; #endif diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 2cbcc3503e..b0906a2509 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -102,7 +102,7 @@ static tabular_features tabularFeatures[] = { LyXTabular::LAST_ACTION, "" } }; -//#define cellstart(p) ((p % 2) == 0) + static inline bool cellstart(LyXParagraph::size_type p) { @@ -398,7 +398,7 @@ void InsetTabular::update(BufferView * bv, LyXFont const & font, bool reinit) } -char const * InsetTabular::EditMessage() const +string const InsetTabular::EditMessage() const { return _("Opened Tabular Inset"); } @@ -1209,8 +1209,7 @@ void InsetTabular::TabularFeatures(BufferView * bv, int feature, string value) setLines = 0, setAlign = LYX_ALIGN_LEFT, lineSet; - bool - what; + bool what; switch (feature) { case LyXTabular::M_ALIGN_LEFT: diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 9c3357f80a..46e0ed4b19 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -4,7 +4,7 @@ * * LyX, The Document Processor * - * Copyright (C) 1995-2000 The LyX Team. + * Copyright 1995-2000 The LyX Team. * *====================================================== */ @@ -95,7 +95,7 @@ public: /// void update(BufferView *, LyXFont const &, bool = false); /// - const char * EditMessage() const; + string const EditMessage() const; /// void Edit(BufferView *, int x, int y, unsigned int); /// @@ -166,13 +166,13 @@ public: void OpenLayoutDialog(BufferView *) const; LyXFunc::func_status getStatus(string argument) const; - /// - /// Public structures and variables + // + // Public structures and variables /// LyXTabular * tabular; private: - + /// bool calculate_dimensions_of_cells(BufferView *, LyXFont const &, bool =false) const; /// @@ -189,14 +189,21 @@ private: void setPos(BufferView *, int x, int y) const; /// UpdatableInset::RESULT moveRight(BufferView *, bool lock = true); + /// UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true); + /// UpdatableInset::RESULT moveUp(BufferView *); + /// UpdatableInset::RESULT moveDown(BufferView *); + /// bool moveNextCell(BufferView *); + /// bool movePrevCell(BufferView *); + /// bool Delete(); /// int getCellXPos(int cell) const; + /// void resetPos(BufferView *) const; /// void RemoveTabularRow(); @@ -214,32 +221,52 @@ private: bool hasPasteBuffer() const { return (paste_tabular != 0); } /// bool copySelection(); + /// bool pasteSelection(BufferView *); + /// bool cutSelection(); - /// - /// Private structures and variables + // + // Private structures and variables /// InsetText * the_locking_inset; + /// Buffer * buffer; - mutable LyXCursor - cursor, - old_cursor; - mutable int - inset_pos, - inset_x, inset_y, - sel_pos_start, - sel_pos_end, - sel_cell_start, - sel_cell_end, - actcell, - oldcell, - actcol, - actrow; + /// + mutable LyXCursor cursor; + /// + mutable LyXCursor old_cursor; + /// + mutable int inset_pos; + /// + mutable int inset_x; + /// + mutable int inset_y; + /// + mutable int sel_pos_start; + /// + mutable int sel_pos_end; + /// + mutable int sel_cell_start; + /// + mutable int sel_cell_end; + /// + mutable int actcell; + /// + mutable int oldcell; + /// + mutable int actcol; + /// + mutable int actrow; + /// bool no_selection; + /// mutable bool locked; + /// mutable UpdateCodes need_update; + /// mutable Dialogs * dialogs_; + /// LyXTabular * paste_tabular; }; #endif diff --git a/src/insets/insettext.C b/src/insets/insettext.C index cf3c5805e3..7cc117d7b6 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -6,8 +6,6 @@ * * Copyright 1998-2000 The LyX Team. * - * @author: Jürgen Vigna - * * ====================================================== */ @@ -80,6 +78,7 @@ InsetText & InsetText::operator=(InsetText const & it) return * this; } + void InsetText::init(InsetText const * ins) { top_y = last_width = last_height = 0; @@ -434,7 +433,7 @@ void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty) } -char const * InsetText::EditMessage() const +string const InsetText::EditMessage() const { return _("Opened Text Inset"); } @@ -926,11 +925,11 @@ InsetText::LocalDispatch(BufferView * bv, cur_value = par->spacing.getValue(); } -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::istringstream istr(arg.c_str()); -#else - istrstream istr(arg.c_str()); -#endif +//#else +// istrstream istr(arg.c_str()); +//#endif string tmp; istr >> tmp; Spacing::Space new_spacing = cur_spacing; @@ -1354,6 +1353,7 @@ void InsetText::deleteLyXText(BufferView * bv, bool recursive) const } } + void InsetText::resizeLyXText(BufferView * bv) const { if (!par->next && !par->size()) // resize not neccessary! @@ -1408,8 +1408,7 @@ void InsetText::resizeLyXText(BufferView * bv) const /// then resize all LyXText in text-insets inset_x = cx(bv) - top_x + drawTextXOffset; inset_y = cy(bv) + drawTextYOffset; - LyXParagraph * p = par; - for(;p;p = p->next) { + for(LyXParagraph * p = par; p; p = p->next) { p->resizeInsetsLyXText(bv); } } @@ -1419,9 +1418,7 @@ void InsetText::resizeLyXText(BufferView * bv) const void InsetText::removeNewlines() { - LyXParagraph * p = par; - - for(;p; p = p->next) { + for(LyXParagraph * p = par; p; p = p->next) { for(int i = 0; i < p->Last(); ++i) { if (p->GetChar(i) == LyXParagraph::META_NEWLINE) p->Erase(i); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 0bceade43c..eb92980d4c 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -6,7 +6,6 @@ * * Copyright 1998 The LyX Team. * - * @author: Jürgen Vigna * *====================================================== */ @@ -34,26 +33,38 @@ class LyXText; class LyXScreen; /** - * A text inset is like a TeX box to write full text - * (including styles and other insets) in a given space. + A text inset is like a TeX box to write full text + (including styles and other insets) in a given space. + @author: Jürgen Vigna */ class InsetText : public UpdatableInset { public: /// enum UpdateCodes { + /// NONE = 0, + /// INIT, + /// FULL, + /// CURSOR_PAR, + /// CURSOR, + /// SELECTION, + /// DRAW_FRAME, + /// CLEAR_FRAME }; /// enum DrawFrame { + /// NEVER = 0, + /// LOCKED, + /// ALWAYS }; /// @@ -66,7 +77,7 @@ public: /// Inset * Clone() const; /// - InsetText & operator= (InsetText const & it); + InsetText & operator=(InsetText const & it); /// void clear(); /// @@ -86,7 +97,7 @@ public: /// void update(BufferView *, LyXFont const &, bool =false); /// - char const * EditMessage() const; + string const EditMessage() const; /// void Edit(BufferView *, int, int, unsigned int); /// @@ -153,8 +164,6 @@ public: /// void SetFrameColor(BufferView *, LColor::color); /// -// LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const; - /// LyXText * getLyXText(BufferView *) const; /// void deleteLyXText(BufferView *, bool recursive=true) const; @@ -201,7 +210,7 @@ private: /// void SetCharFont(Buffer const *, int pos, LyXFont const & font); /// - string getText(int); + string const getText(int); /// bool checkAndActivateInset(BufferView * bv, bool behind); /// diff --git a/src/insets/insettheorem.C b/src/insets/insettheorem.C index 4394b3ac23..11ef790d8b 100644 --- a/src/insets/insettheorem.C +++ b/src/insets/insettheorem.C @@ -63,7 +63,7 @@ Inset * InsetTheorem::Clone() const } -char const * InsetTheorem::EditMessage() const +string const InsetTheorem::EditMessage() const { return _("Opened Theorem Inset"); } diff --git a/src/insets/insettheorem.h b/src/insets/insettheorem.h index 46485caa06..e2a6a8a380 100644 --- a/src/insets/insettheorem.h +++ b/src/insets/insettheorem.h @@ -36,7 +36,7 @@ public: /// int Latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// - const char * EditMessage() const; + string const EditMessage() const; /// bool InsertInsetAllowed(Inset * inset) const; }; diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index f74b85ff8e..6657beb0f6 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -14,7 +14,7 @@ using std::ostream; -string InsetTOC::getScreenLabel() const +string const InsetTOC::getScreenLabel() const { string cmdname( getCmdName() ); if( cmdname == "tableofcontents" ) diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index cf0de54519..9acd77bde8 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -27,7 +27,7 @@ public: /// Inset * Clone() const { return new InsetTOC(params()); } /// - string getScreenLabel() const; + string const getScreenLabel() const; /// void Edit(BufferView * bv, int, int, unsigned int); /// diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index a63a7ef412..161fe59fa9 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -25,7 +25,7 @@ void InsetUrl::Edit(BufferView * bv, int, int, unsigned int) } -string InsetUrl::getScreenLabel() const +string const InsetUrl::getScreenLabel() const { string temp; if( getCmdName() == "url" ) diff --git a/src/insets/inseturl.h b/src/insets/inseturl.h index 30a7b2c49b..1f66ada053 100644 --- a/src/insets/inseturl.h +++ b/src/insets/inseturl.h @@ -33,7 +33,7 @@ public: /// void Validate(LaTeXFeatures &) const; /// - string getScreenLabel() const; + string const getScreenLabel() const; /// EDITABLE Editable() const { return IS_EDITABLE; } /// diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index 05dde1c36f..140e7f3778 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -132,9 +132,9 @@ public: virtual void update(BufferView *, LyXFont const &, bool = false) {} /// - virtual LyXFont ConvertFont(LyXFont const & font) const; + virtual LyXFont const ConvertFont(LyXFont const & font) const; /// what appears in the minibuffer when opening - virtual const char * EditMessage() const; + virtual string const EditMessage() const; /// virtual void Edit(BufferView *, int x, int y, unsigned int button); /// @@ -177,7 +177,7 @@ public: /// returns LyX code associated with the inset. Used for TOC, ...) virtual Inset::Code LyxCode() const { return NO_CODE; } - virtual std::vector getLabelList() const { + virtual std::vector const getLabelList() const { return std::vector(); } diff --git a/src/kbmap.C b/src/kbmap.C index 68cde51c6a..1d76704a91 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -71,7 +71,7 @@ void kb_keymap::printKey(kb_key const & key, string & buf) // This binds a key to an action -int kb_keymap::bind(char const * seq, int action) +int kb_keymap::bind(string const & seq, int action) { kb_sequence k; @@ -238,7 +238,7 @@ kb_keymap::~kb_keymap() } -string kb_keymap::keyname(kb_key const & k) +string const kb_keymap::keyname(kb_key const & k) { string buf; printKeysym(k.code, k.mod, buf); @@ -247,7 +247,7 @@ string kb_keymap::keyname(kb_key const & k) // Finds a key for a keyaction, if possible -string kb_keymap::findbinding(int act) const +string const kb_keymap::findbinding(int act) const { string res; if (table.empty()) return res; diff --git a/src/kbmap.h b/src/kbmap.h index e3805b79c5..015bce9c37 100644 --- a/src/kbmap.h +++ b/src/kbmap.h @@ -28,7 +28,7 @@ public: /** Bind a key-sequence to an action. Returns 0 on success. Otherwise, position in string where error occured. */ - int bind(char const * seq, int action); + int bind(string const & seq, int action); /// void print(string & buf) const; @@ -38,7 +38,7 @@ public: unsigned int mod, kb_sequence * seq) const; /// Given an action, find all keybindings. - string findbinding(int action) const; + string const findbinding(int action) const; private: /// struct kb_key { @@ -59,7 +59,7 @@ private: /// Define a new key sequence int defkey(kb_sequence * seq, int action, int idx = 0); /// - static string keyname(kb_key const & k); + static string const keyname(kb_key const & k); /// static diff --git a/src/kbsequence.C b/src/kbsequence.C index 2be7a9b792..567ff5944e 100644 --- a/src/kbsequence.C +++ b/src/kbsequence.C @@ -96,15 +96,15 @@ int kb_sequence::addkey(unsigned int key, Prefixes are S-, C-, M- for shift, control, meta \* ---F------------------------------------------------------------------- */ -int kb_sequence::parse(char const * s) +int kb_sequence::parse(string const & s) { - if(!s[0]) return 1; + if(s.empty()) return 1; int i = 0; unsigned int mod = 0, nmod = 0; - while(s[i]) { + while (i < s.length()) { if(s[i] && (s[i]) <= ' ') ++i; - if(!s[i]) break; + if(i >= s.length()) break; if(s[i + 1] == '-') { // is implicit that s[i] == true switch(s[i]) { @@ -143,7 +143,7 @@ int kb_sequence::parse(char const * s) } else { string tbuf; int j = i; - for(; s[j] && s[j] > ' '; ++j) + for(; j < s.length() && s[j] > ' '; ++j) tbuf += s[j]; // (!!!check bounds :-) KeySym key = XStringToKeysym(tbuf.c_str()); diff --git a/src/kbsequence.h b/src/kbsequence.h index 9315d43b11..87265b74f9 100644 --- a/src/kbsequence.h +++ b/src/kbsequence.h @@ -62,7 +62,7 @@ public: void reset(); /// - int parse(char const * s); + int parse(string const & s); /// Keymap to use if a new sequence is starting kb_keymap * stdmap; diff --git a/src/lastfiles.h b/src/lastfiles.h index 6e9bd81fab..dee8c5e0f8 100644 --- a/src/lastfiles.h +++ b/src/lastfiles.h @@ -36,31 +36,36 @@ public: typedef Files::const_iterator const_iterator; /** Read the lastfiles file. - @param file The file to read the lastfiles form. - @param dostat Whether to check for file existance. - @param num number of files to remember. + @param file The file to read the lastfiles form. + @param dostat Whether to check for file existance. + @param num number of files to remember. */ explicit LastFiles(string const & file, bool dostat = true, unsigned int num = 4); - /** - This funtion inserts #file# into the last files list. If the file - already exist it is moved to the top of the list, else exist it - is placed on the top of the list. If the list is full the last - file in the list is popped from the end. + /** Insert #file# into the list. + This funtion inserts #file# into the last files list. If the file + already exist it is moved to the top of the list, else exist it + is placed on the top of the list. If the list is full the last + file in the list is popped from the end. + @param file the file to insert in the list. */ void newFile(string const & file); - /** Writes the lastfiles table to disk. One file on each line, this - way we can at least have some special chars (e.g. space), but - newline in filenames are thus not allowed. + /** Writes the lastfiles table to disk. + Writes one file on each line, this way we can at least have + some special chars (e.g. space), but newline in filenames + are thus not allowed. + @param file the file we write the lastfiles list to. */ - void writeFile(string const &) const; - /// - string const operator[](unsigned int) const; - /// + void writeFile(string const & file) const; + /** Return file #n# in the lastfiles list. + @param n number in the list to get + */ + string const operator[](unsigned int n) const; + /// Iterator to the beginning of the list. Files::const_iterator begin() const { return files.begin(); } - /// + /// Iterator to the end of the list. Files::const_iterator end() const { return files.end(); } private: /** Local constants. @@ -88,13 +93,16 @@ private: bool dostat; /** Read the lastfiles file. - Reads the .lyx_lastfiles at the beginning of the LyX session. - This will read the lastfiles file (usually .lyx_lastfiles). It + Reads the #.lyx_lastfiles# at the beginning of the LyX session. + This will read the lastfiles file (usually #.lyx_lastfiles#). It will normally discard files that don't exist anymore, unless - LastFiles has been initialized with dostat = false. + LastFiles has been initialized with #dostat = false#. + @param file the file containing the lastfiles. + */ + void readFile(string const & file); + /** Used by the constructor to set the number of stored last files. + @param num the number of lastfiles to set. */ - void readFile(string const &); - /// used by the constructor to set the number of stored last files. void setNumberOfFiles(unsigned int num); }; #endif diff --git a/src/layout.C b/src/layout.C index 797f2855b1..1cbb0501c2 100644 --- a/src/layout.C +++ b/src/layout.C @@ -1210,7 +1210,7 @@ void LyXTextClass::load() ////////////////////////////////////////// // Gets textclass number from name -pair +pair const LyXTextClassList::NumberOfClass(string const & textclass) const { for (ClassList::const_iterator cit = classlist.begin(); @@ -1236,7 +1236,7 @@ LyXTextClassList::Style(LyXTextClassList::size_type textclass, // Gets layout number from name and textclass number -pair +pair const LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass, string const & name) const { @@ -1450,3 +1450,4 @@ std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p) } return os; } + diff --git a/src/layout.h b/src/layout.h index 2eb47cef59..789f9ca098 100644 --- a/src/layout.h +++ b/src/layout.h @@ -565,7 +565,7 @@ public: LyXTextClass::size_type layout) const; /// Gets layout number from textclass number and layout name - std::pair + std::pair const NumberOfLayout(size_type textclass, string const & name) const; @@ -577,7 +577,7 @@ public: /** Gets textclass number from name. Returns -1 if textclass name does not exist */ - std::pair + std::pair const NumberOfClass(string const & textclass) const; /// diff --git a/src/lyx_cb.C b/src/lyx_cb.C index e6cd7c02a5..ad8921b954 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -14,7 +14,6 @@ #include #include -//#include "LString.h" #include FORMS_H_LOCATION #include "lyx.h" #include "layout_forms.h" @@ -1153,9 +1152,9 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph) } -void MenuInsertLabel(char const * arg) +void MenuInsertLabel(string const & arg) { - string label = arg; + string label(arg); ProhibitInput(current_view); if (label.empty()) { pair @@ -1321,7 +1320,7 @@ void MenuLayoutCharacter() } -inline +static inline void DeactivateParagraphButtons () { fl_deactivate_object (fd_form_paragraph->button_ok); @@ -1331,7 +1330,7 @@ void DeactivateParagraphButtons () } -inline +static inline void ActivateParagraphButtons () { fl_activate_object (fd_form_paragraph->button_ok); @@ -1341,7 +1340,7 @@ void ActivateParagraphButtons () } -inline +static inline void DisableParagraphLayout () { DeactivateParagraphButtons(); @@ -1365,7 +1364,7 @@ void DisableParagraphLayout () } -inline +static inline void EnableParagraphLayout () { ActivateParagraphButtons(); @@ -1576,7 +1575,7 @@ void MenuLayoutParagraph() } #ifdef USE_OLD_DOCUMENT_LAYOUT -inline +static inline void DeactivateDocumentButtons () { fl_deactivate_object (fd_form_document->button_ok); @@ -1586,7 +1585,7 @@ void DeactivateDocumentButtons () } -inline +static inline void ActivateDocumentButtons () { fl_activate_object (fd_form_document->button_ok); @@ -1596,7 +1595,7 @@ void ActivateDocumentButtons () } -inline +static inline void DisableDocumentLayout () { DeactivateDocumentButtons (); @@ -1629,7 +1628,7 @@ void DisableDocumentLayout () } -inline +static inline void EnableDocumentLayout () { ActivateDocumentButtons (); @@ -1779,17 +1778,17 @@ bool UpdateLayoutDocument(BufferParams * params) fl_set_choice(fd_form_document->choice_spacing, 4); //char sval[20]; //sprintf(sval, "%g", params->spacing.getValue()); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream sval; sval << params->spacing.getValue(); // setw? fl_set_input(fd_form_document->input_spacing, sval.str().c_str()); -#else - char tval[20]; - ostrstream sval(tval, 20); - sval << params->spacing.getValue() << '\0'; // setw? - fl_set_input(fd_form_document->input_spacing, sval.str()); -#endif +//#else +// char tval[20]; +// ostrstream sval(tval, 20); +// sval << params->spacing.getValue() << '\0'; // setw? +// fl_set_input(fd_form_document->input_spacing, sval.str()); +//#endif break; } } @@ -1953,7 +1952,7 @@ void MenuLayoutSave() // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger) // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger) -LyXFont UserFreeFont(BufferParams const & params) +LyXFont const UserFreeFont(BufferParams const & params) { LyXFont font(LyXFont::ALL_IGNORE); diff --git a/src/lyx_cb.h b/src/lyx_cb.h index cc9bb3f42b..ce23fb9dbc 100644 --- a/src/lyx_cb.h +++ b/src/lyx_cb.h @@ -16,7 +16,7 @@ extern bool toggleall; /// extern bool BindFileSet; /// -extern LyXFont UserFreeFont(BufferParams const & params); +extern LyXFont const UserFreeFont(BufferParams const & params); /// void ShowMessage(Buffer * buf, string const & msg1, diff --git a/src/lyx_main.C b/src/lyx_main.C index de72dc3678..6051cc406c 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -35,9 +35,7 @@ #include "layout.h" #include "gettext.h" #include "kbmap.h" -#ifdef NEW_MENUBAR -# include "MenuBackend.h" -#endif +#include "MenuBackend.h" #include "ToolbarDefaults.h" #include "lyxlex.h" #if 1 @@ -635,18 +633,8 @@ void LyX::ReadUIFile(string const & name) while (lex.IsOK()) { switch(lex.lex()) { case ui_menuset: -#ifdef NEW_MENUBAR menubackend.read(lex); break; -#else - // Skip any menu definition and fall over to toolbar. - // This is a hack, but it is supposed to go away... - do { - lex.next(); - if (!lex.IsOK()) return; - } - while (lex.lex() != ui_toolbar); -#endif case ui_toolbar: toolbardefaults.read(lex); diff --git a/src/lyxfont.C b/src/lyxfont.C index dd4706d37f..8e6f3ba84e 100644 --- a/src/lyxfont.C +++ b/src/lyxfont.C @@ -381,14 +381,14 @@ bool LyXFont::resolved() const /// Build GUI description of font state -string LyXFont::stateText(BufferParams * params) const +string const LyXFont::stateText(BufferParams * params) const { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; -#else - char str[1024]; - ostrstream ost(str, 1024); -#endif +//#else +// char str[1024]; +// ostrstream ost(str, 1024); +//#endif if (family() != INHERIT_FAMILY) ost << _(GUIFamilyNames[family()]) << ", "; if (series() != INHERIT_SERIES) @@ -414,12 +414,12 @@ string LyXFont::stateText(BufferParams * params) const if (!params || (language() != params->language_info && language()->lang() != "default")) ost << _("Language: ") << _(language()->display().c_str()); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM string buf(ost.str().c_str()); -#else - ost << '\0'; - string buf(ost.str()); -#endif +//#else +// ost << '\0'; +// string buf(ost.str()); +//#endif buf = strip(buf, ' '); buf = strip(buf, ','); return buf; @@ -524,7 +524,7 @@ LyXFont & LyXFont::setGUISize(string const & siz) // Returns size in latex format -string LyXFont::latexSize() const +string const LyXFont::latexSize() const { return LaTeXSizeNames[size()]; } @@ -729,7 +729,7 @@ int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base, count += strlen(LaTeXShapeNames[f.shape()]) + 2; env = true; //We have opened a new environment } - if (f.color() != LColor::inherit) { + if (f.color() != LColor::inherit && f.color() != LColor::ignore) { os << "\\textcolor{" << lcolor.getLaTeXName(f.color()) << "}{"; @@ -804,7 +804,7 @@ int LyXFont::latexWriteEndChanges(ostream & os, LyXFont const & base, ++count; env = true; // Size change need not bother about closing env. } - if (f.color() != LColor::inherit) { + if (f.color() != LColor::inherit && f.color() != LColor::ignore) { os << '}'; ++count; env = true; // Size change need not bother about closing env. diff --git a/src/lyxfont.h b/src/lyxfont.h index 4123fa3513..910782dceb 100644 --- a/src/lyxfont.h +++ b/src/lyxfont.h @@ -262,7 +262,7 @@ public: LyXFont & setGUISize(string const &); /// Returns size of font in LaTeX text notation - string latexSize() const; + string const latexSize() const; /** Updates font settings according to request. If an attribute is IGNORE, the attribute is left as it is. @@ -309,7 +309,7 @@ public: LyXFont const & next) const; /// Build GUI description of font state - string stateText(BufferParams * params) const; + string const stateText(BufferParams * params) const; /// LColor::color realColor() const; diff --git a/src/lyxfr0.C b/src/lyxfr0.C index 24a22dad96..0b14d4c6ba 100644 --- a/src/lyxfr0.C +++ b/src/lyxfr0.C @@ -102,7 +102,7 @@ void SearchForm::StartSearch(LyXFindReplace * lfr) // Returns the value of the replace string in the form -string SearchForm::ReplaceString() const +string const SearchForm::ReplaceString() const { return fl_get_input(search_form->input_replace); } diff --git a/src/lyxfr0.h b/src/lyxfr0.h index bf549062db..09949f2ed1 100644 --- a/src/lyxfr0.h +++ b/src/lyxfr0.h @@ -51,7 +51,7 @@ public: } /// - string SearchString() const { + string const SearchString() const { return fl_get_input(search_form->input_search); } @@ -71,7 +71,7 @@ public: /// void SetSearchString(string const & ls); /// - string ReplaceString() const; + string const ReplaceString() const; /// bool ValidSearchData() const { return !(SearchString().empty()); } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 0d9c79a790..0fddfde276 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -10,12 +10,16 @@ #include +#if 0 #ifdef HAVE_SSTREAM #include using std::istringstream; #else #include #endif +#else +#include "Lsstream.h" +#endif #include #include @@ -86,11 +90,7 @@ using std::istringstream; #include "bufferview_funcs.h" #include "frontends/Dialogs.h" #include "frontends/Toolbar.h" -#ifdef NEW_MENUBAR #include "frontends/Menubar.h" -#else -#include "menus.h" -#endif #include "FloatList.h" #include "exporter.h" #include "FontLoader.h" @@ -102,7 +102,7 @@ using std::endl; extern bool cursor_follows_scrollbar; extern void InsertAsciiFile(BufferView *, string const &, bool); -extern void math_insert_symbol(char const *); +extern void math_insert_symbol(string const &); extern bool math_insert_greek(char); extern BufferList bufferlist; extern LyXServer * lyxserver; @@ -113,9 +113,7 @@ extern kb_keymap * toplevel_keymap; extern bool MenuWrite(Buffer *); extern bool MenuWriteAs(Buffer *); -#ifdef NEW_MENUBAR extern int MenuRunLaTeX(Buffer *); -#endif extern int MenuBuildProg(Buffer *); extern int MenuRunChktex(Buffer *); #ifndef NEW_EXPORT @@ -139,7 +137,7 @@ extern void AutoSave(BufferView *); extern bool PreviewDVI(Buffer *); extern bool PreviewPostscript(Buffer *); #endif -extern void MenuInsertLabel(char const *); +extern void MenuInsertLabel(string const &); extern void MenuLayoutCharacter(); extern void MenuLayoutParagraph(); extern void MenuLayoutDocument(); @@ -658,7 +656,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const } -string LyXFunc::Dispatch(string const & s) +string const LyXFunc::Dispatch(string const & s) { // Split command string into command and argument string cmd, line = frontStrip(s); @@ -668,8 +666,8 @@ string LyXFunc::Dispatch(string const & s) } -string LyXFunc::Dispatch(int ac, - char const * do_not_use_this_arg) +string const LyXFunc::Dispatch(int ac, + string const & do_not_use_this_arg) { string argument; kb_action action; @@ -687,7 +685,7 @@ string LyXFunc::Dispatch(int ac, argument = tmparg; } else { action = static_cast(ac); - if (do_not_use_this_arg) + if (!do_not_use_this_arg.empty()) argument = do_not_use_this_arg; // except here } @@ -1630,11 +1628,7 @@ string LyXFunc::Dispatch(int ac, break; case LFUN_MENU_OPEN_BY_NAME: -#ifdef NEW_MENUBAR owner->getMenubar()->openByName(argument); -#else - owner->getMenus()->openByName(argument); -#endif break; // RVDK_PATCH_5 case LFUN_SPELLCHECK: @@ -2232,11 +2226,11 @@ string LyXFunc::Dispatch(int ac, cur_value = par->spacing.getValue(); } -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM istringstream istr(argument); -#else - istrstream istr(argument.c_str()); -#endif +//#else +// istrstream istr(argument.c_str()); +//#endif string tmp; istr >> tmp; Spacing::Space new_spacing = cur_spacing; @@ -2534,11 +2528,11 @@ string LyXFunc::Dispatch(int ac, case LFUN_GOTO_PARAGRAPH: { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM istringstream istr(argument); -#else - istrstream istr(argument.c_str()); -#endif +//#else +// istrstream istr(argument.c_str()); +//#endif int id; istr >> id; diff --git a/src/lyxfunc.h b/src/lyxfunc.h index 4aa874c670..31c4c7494b 100644 --- a/src/lyxfunc.h +++ b/src/lyxfunc.h @@ -41,10 +41,10 @@ public: LyXFunc(LyXView *); /// LyX dispatcher, executes lyx actions. - string Dispatch(int action, char const * arg = 0); + string const Dispatch(int action, string const & arg = string()); /// The same but uses the name of a lyx command. - string Dispatch(string const & cmd); + string const Dispatch(string const & cmd); /// Same again but for xtl buffers. Still looking for better idea. bool Dispatch(int action, auto_mem_buffer &); @@ -65,13 +65,13 @@ public: // These can't be global because are part of the // internal state (ale970227) /// Get the current keyseq string - string keyseqStr() const; + string const keyseqStr() const; /// Is the key sequence uncomplete? bool keyseqUncomplete() const; /// get options for the current keyseq - string keyseqOptions() const; + string const keyseqOptions() const; /// True if lyxfunc reports an error bool errorStat() const { return errorstat; } @@ -80,7 +80,7 @@ public: /// Buffer to store result messages void setErrorMessage(string const &) const; /// Buffer to store result messages - string getMessage() const { return dispatch_buffer; } + string const getMessage() const { return dispatch_buffer; } /// Get next inset of this class from current cursor position Inset * getInsetByCode(Inset::Code); @@ -151,7 +151,7 @@ bool LyXFunc::wasMetaKey() const inline -string LyXFunc::keyseqStr() const +string const LyXFunc::keyseqStr() const { // Why not just remove this function string text; @@ -161,7 +161,7 @@ string LyXFunc::keyseqStr() const inline -string LyXFunc::keyseqOptions() const +string const LyXFunc::keyseqOptions() const { // Why not just remove this function string text; diff --git a/src/lyxlex.C b/src/lyxlex.C index 8fe4b94be4..7bb8ea59c2 100644 --- a/src/lyxlex.C +++ b/src/lyxlex.C @@ -55,7 +55,7 @@ int LyXLex::GetLineNo() const } -char const * const LyXLex::text() const +string const LyXLex::text() const { return &pimpl_->buff[0]; } diff --git a/src/lyxlex.h b/src/lyxlex.h index 9825fc962e..420396be13 100644 --- a/src/lyxlex.h +++ b/src/lyxlex.h @@ -104,7 +104,7 @@ public: int CheckToken(char const * str[], int print_error); /// - char const * const text() const; + string const text() const; /** Pushes a token list on a stack and replaces it with a new one. */ @@ -132,19 +132,22 @@ private: }; -/** Use to enable multipe exit points. +/** Use to enable multiple exit points. This is needed to ensure that the pop is done upon exit from methods with more than one exit point or that can return as a response to exceptions. @autor Lgb */ struct pushpophelper { + /// pushpophelper(LyXLex & lexrc, keyword_item * i, int s) : lex(lexrc) { lex.pushTable(i, s); } + /// ~pushpophelper() { lex.popTable(); } + /// LyXLex & lex; }; /** Avoid wrong usage of pushpophelper. diff --git a/src/lyxparagraph.h b/src/lyxparagraph.h index b868eb8811..abae1e2cf6 100644 --- a/src/lyxparagraph.h +++ b/src/lyxparagraph.h @@ -150,9 +150,9 @@ public: bool isMultiLingual(BufferParams const &); /// - string String(Buffer const *, bool label); + string const String(Buffer const *, bool label); /// - string String(Buffer const *, size_type beg, size_type end); + string const String(Buffer const *, size_type beg, size_type end); /// void writeFile(Buffer const *, std::ostream &, BufferParams const &, @@ -388,7 +388,7 @@ public: string const & GetLabelstring() const; /// the next two functions are for the manual labels - string GetLabelWidthString() const; + string const GetLabelWidthString() const; /// void SetLabelWidthString(string const & s); /// @@ -418,9 +418,10 @@ public: between the characters font and the layoutfont. This is what is stored in the fonttable */ - LyXFont GetFontSettings(BufferParams const &, size_type pos) const; + LyXFont const + GetFontSettings(BufferParams const &, size_type pos) const; /// - LyXFont GetFirstFontSettings() const; + LyXFont const GetFirstFontSettings() const; /** Get fully instantiated font. If pos == -1, use the layout font attached to this paragraph. @@ -429,7 +430,7 @@ public: attributes with values LyXFont::INHERIT, LyXFont::IGNORE or LyXFont::TOGGLE. */ - LyXFont getFont(BufferParams const &, size_type pos) const; + LyXFont const getFont(BufferParams const &, size_type pos) const; /// value_type GetChar(size_type pos) const; /// The position must already exist. @@ -440,7 +441,7 @@ public: /// void SetFont(size_type pos, LyXFont const & font); /// - string GetWord(size_type &) const; + string const GetWord(size_type &) const; /// Returns the height of the highest font in range LyXFont::FONT_SIZE HighestFontInRange(size_type startpos, size_type endpos) const; @@ -533,8 +534,8 @@ public: /* If I set a PExtra Indent on one paragraph of a ENV_LIST-TYPE I have to set it on each of it's elements */ /// - void SetPExtraType(BufferParams const &, - int type, char const * width, char const * widthp); + void SetPExtraType(BufferParams const &, int type, + string const & width, string const & widthp); /// void UnsetPExtraType(BufferParams const &); /// diff --git a/src/lyxtext.h b/src/lyxtext.h index 1afc30597c..05ffe20fd1 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -73,7 +73,7 @@ public: InsetText * inset_owner; /// - LyXFont GetFont(Buffer const *, LyXParagraph * par, + LyXFont const GetFont(Buffer const *, LyXParagraph * par, LyXParagraph::size_type pos) const; /// void SetCharFont(Buffer const *, LyXParagraph * par, @@ -232,7 +232,7 @@ public: /// void ClearSelection() const; /// - string selectionAsString(Buffer const *) const; + string const selectionAsString(Buffer const *) const; /// just selects the word the cursor is in void SelectWord(BufferView *); @@ -242,7 +242,7 @@ public: to the beginning of this word. With SelectSelectedWord can this be highlighted really */ - char * SelectNextWord(BufferView *, float & value); + string const SelectNextWord(BufferView *, float & value) const; /// void SelectSelectedWord(BufferView *); /// @@ -394,8 +394,8 @@ public: bool noindent); /// void SetParagraphExtraOpt(BufferView *, int type, - char const * width, - char const * widthp, + string const & width, + string const & widthp, int alignment, bool hfill, bool start_minipage); @@ -406,22 +406,22 @@ public: */ bool IsStringInText(LyXParagraph * par, LyXParagraph::size_type pos, - char const * str) const; + string const & str) const; /** sets the selection over the number of characters of string, no check!! */ - void SetSelectionOverString(BufferView *, char const * str); + void SetSelectionOverString(BufferView *, string const & str); /** simple replacing. The font of the first selected character is used */ - void ReplaceSelectionWithString(BufferView *, char const * str); + void ReplaceSelectionWithString(BufferView *, string const & str); /** if the string can be found: return true and set the cursor to the new position */ - bool SearchForward(BufferView *, char const * str) const; + bool SearchForward(BufferView *, string const & str) const; /// - bool SearchBackward(BufferView *, char const * str) const; + bool SearchBackward(BufferView *, string const & str) const; /// needed to insert the selection void InsertStringA(BufferView *, string const & str); diff --git a/src/mathed/array.h b/src/mathed/array.h index 4683fc13ac..1a33d6438c 100644 --- a/src/mathed/array.h +++ b/src/mathed/array.h @@ -46,7 +46,7 @@ public: ~LyxArrayBase(); /// Constructs a new array with dx elements starting at pos - LyxArrayBase & operator= (LyxArrayBase const &); + LyxArrayBase & operator=(LyxArrayBase const &); /// int empty() const { return (last == 0); } @@ -142,7 +142,7 @@ LyxArrayBase::~LyxArrayBase() } inline -LyxArrayBase::LyxArrayBase(const LyxArrayBase& a) +LyxArrayBase::LyxArrayBase(LyxArrayBase const & a) { maxsize = a.maxsize; bf = new byte[maxsize]; @@ -151,7 +151,7 @@ LyxArrayBase::LyxArrayBase(const LyxArrayBase& a) } inline -LyxArrayBase& LyxArrayBase::operator= (const LyxArrayBase& a) +LyxArrayBase & LyxArrayBase::operator=(LyxArrayBase const & a) { if (this != &a) { Resize(a.maxsize); @@ -164,11 +164,11 @@ inline bool LyxArrayBase::Move(int p, int shift) { bool result = false; - if (p<= last) { - if (last+shift>= maxsize) { + if (p <= last) { + if (last + shift >= maxsize) { Resize(last + shift); } - memmove(&bf[p+shift], &bf[p], last-p); + memmove(&bf[p + shift], &bf[p], last - p); last += shift; bf[last] = 0; result = true; @@ -185,32 +185,32 @@ void LyxArrayBase::Fit() inline void LyxArrayBase::Remove(int pos, int dx) { - Move(pos+dx, -dx); + Move(pos + dx, -dx); } inline -void LyxArrayBase::Merge(LyxArrayBase *a, int p, int dx) +void LyxArrayBase::Merge(LyxArrayBase * a, int p, int dx) { Move(p, dx); memcpy(&bf[p], &a->bf[0], dx); } inline -void LyxArrayBase::MergeF(LyxArrayBase *a, int p, int dx) +void LyxArrayBase::MergeF(LyxArrayBase * a, int p, int dx) { memcpy(&bf[p], &a->bf[0], dx); } inline -void LyxArrayBase::Copy(void *a, int p, int dx) +void LyxArrayBase::Copy(void * a, int p, int dx) { memcpy(&bf[p], a, dx); } inline -LyxArrayBase *LyxArrayBase::Extract(int, int dx) +LyxArrayBase * LyxArrayBase::Extract(int, int dx) { - LyxArrayBase *a = new LyxArrayBase(dx); + LyxArrayBase * a = new LyxArrayBase(dx); a->Merge(this, 0, dx); return a; } @@ -225,10 +225,10 @@ byte LyxArrayBase::operator[](const int i) inline void LyxArrayBase::Insert(int pos, byte c) { - if (pos<0) pos = last; - if (pos>= maxsize) - Resize(maxsize+ARRAY_STEP); + if (pos < 0) pos = last; + if (pos >= maxsize) + Resize(maxsize + ARRAY_STEP); bf[pos] = c; - if (pos>= last) - last = pos+1; + if (pos >= last) + last = pos + 1; } diff --git a/src/mathed/formula.C b/src/mathed/formula.C index a90d0db7ab..dc4c80c15f 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -15,12 +15,16 @@ #include +#if 0 #ifdef HAVE_SSTREAM #include using std::istringstream; #else #include #endif +#else +#include "Lsstream.h" +#endif #ifdef __GNUG__ #pragma implementation "formula.h" @@ -216,6 +220,11 @@ int mathed_string_width(short type, int size, byte const * s, int ls) return lyxfont::width(reinterpret_cast(s), ls, f); } +int mathed_string_width(short type, int size, string const & str) +{ + return mathed_string_width(type, size, reinterpret_cast(str.c_str()), str.length()); +} + int mathed_char_width(short type, int size, byte c) { @@ -240,10 +249,18 @@ int mathed_string_height(short type, int size, byte const * s, } +int mathed_string_height(short type, int size, string const & str, + int & asc, int & des) +{ + return mathed_string_height(type, size, + reinterpret_cast(str.c_str()), str.length(), + asc, des); +} + + int mathed_char_height(short type, int size, byte c, int & asc, int & des) { LyXFont font = WhichFont(type, size); - asc = des = 0; des = lyxfont::descent(c, font); asc = lyxfont::ascent(c, font); return asc + des; @@ -262,7 +279,7 @@ void MathedInset::drawStr(Painter & pain, short type, int siz, } else { st = string(reinterpret_cast(s), ls); } - LyXFont mf = mathed_get_font(type, siz); + LyXFont const mf = mathed_get_font(type, siz); pain.text(x, y, st, mf); } @@ -453,7 +470,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & f, y = baseline + crow->getBaseline(); if (crow->isNumbered()) { string str; - if (crow->getLabel()) + if (!crow->getLabel().empty()) str = string("(") + crow->getLabel() + ")"; else str = "(#)"; @@ -467,7 +484,7 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & f, } -char const * InsetFormula::EditMessage() const +string const InsetFormula::EditMessage() const { return _("Math editor mode"); } @@ -503,21 +520,22 @@ void InsetFormula::InsetUnlock(BufferView * bv) // Now a symbol can be inserted only if the inset is locked -void InsetFormula::InsertSymbol(BufferView * bv, char const * s) +void InsetFormula::InsertSymbol(BufferView * bv, string const & s) { - if (!s || !mathcursor) return; + if (s.empty() || !mathcursor) return; mathcursor->Interpret(s); UpdateLocal(bv); } -void InsetFormula::GetCursorPos(BufferView *, int& x, int& y) const +void InsetFormula::GetCursorPos(BufferView *, int & x, int & y) const { mathcursor->GetPos(x, y); x -= par->xo; y -= par->yo; } + void InsetFormula::ToggleInsetCursor(BufferView * bv) { if (!mathcursor) @@ -607,7 +625,7 @@ void InsetFormula::display(bool dspf) } -vector InsetFormula::getLabelList() const +vector const InsetFormula::getLabelList() const { //#warning This is dirty, I know. Ill clean it at 0.11 // Correction, the only way to clean this is with a new kernel: 0.13. @@ -618,7 +636,7 @@ vector InsetFormula::getLabelList() const MathMatrixInset * mt = static_cast(par); MathedRowSt const * crow = mt->getRowSt(); while (crow) { - if (crow->getLabel()) + if (!crow->getLabel().empty()) label_list.push_back(crow->getLabel()); crow = crow->getNext(); } @@ -815,11 +833,11 @@ InsetFormula::LocalDispatch(BufferView * bv, case LFUN_SETXY: { int x, y, x1, y1; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM istringstream ist(arg.c_str()); -#else - istrstream ist(arg.c_str()); -#endif +//#else +// istrstream ist(arg.c_str()); +//#endif ist >> x >> y; par->GetXY(x1, y1); mathcursor->SetPos(x1 + x, y1 + y); @@ -1229,7 +1247,7 @@ InsetFormula::LocalDispatch(BufferView * bv, void MathFuncInset::draw(Painter & pain, int x, int y) { - if (name && name[0] > ' ') { + if (!name.empty() && name[0] > ' ') { LyXFont font = WhichFont(LM_TC_TEXTRM, size); font.setLatex(LyXFont::ON); x += (lyxfont::width('I', font) + 3) / 4; @@ -1240,14 +1258,12 @@ MathFuncInset::draw(Painter & pain, int x, int y) void MathFuncInset::Metrics() { - ln = (name) ? strlen(name): 0; + //ln = (name) ? strlen(name): 0; LyXFont font = WhichFont(LM_TC_TEXTRM, size); font.setLatex(LyXFont::ON); - width = lyxfont::width(name, ln, font) + width = lyxfont::width(name, font) + lyxfont::width('I', font) / 2; - mathed_string_height(LM_TC_TEXTRM, size, - reinterpret_cast(name), - strlen(name), ascent, descent); + mathed_string_height(LM_TC_TEXTRM, size, name, ascent, descent); } @@ -1261,7 +1277,7 @@ void mathedValidate(LaTeXFeatures & features, MathParInset * par) if(it.IsActive()) { MathParInset * p = it.GetActiveInset(); if (!features.binom && p->GetType() == LM_OT_MACRO && - strcmp(p->GetName(), "binom") == 0) { + p->GetName() == "binom") { features.binom = true; } else { for (int i = 0; i <= p->getMaxArgumentIdx(); ++i) { @@ -1271,8 +1287,8 @@ void mathedValidate(LaTeXFeatures & features, MathParInset * par) } } else { MathedInset* p = it.GetInset(); - if (!features.boldsymbol && p->GetName() && - strcmp(p->GetName(), "boldsymbol") == 0) { + if (!features.boldsymbol && + p->GetName() == "boldsymbol") { features.boldsymbol = true; } } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index d8ac350492..926a029f70 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -68,7 +68,7 @@ public: /// Inset::Code LyxCode() const { return Inset::MATH_CODE; } /// - LyXFont ConvertFont(LyXFont const & f) const { + LyXFont const ConvertFont(LyXFont const & f) const { // We have already discussed what was here LyXFont font(f); font.setLatex(LyXFont::OFF); @@ -76,7 +76,7 @@ public: } /// what appears in the minibuffer when opening - char const * EditMessage() const; + string const EditMessage() const; /// void Edit(BufferView *, int x, int y, unsigned int button); /// @@ -108,11 +108,11 @@ public: virtual RESULT LocalDispatch(BufferView *, int, string const &); /// - void InsertSymbol(BufferView *, char const *); + void InsertSymbol(BufferView *, string const &); /// bool SetNumber(bool); /// - std::vector getLabelList() const; + std::vector const getLabelList() const; protected: /// diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index f23c3d2429..53b9b01505 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -175,7 +175,7 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f, } -char const * InsetFormulaMacro::EditMessage() const +string const InsetFormulaMacro::EditMessage() const { return _("Math macro editor mode"); } diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index f77aca9ca8..3a66cfddc9 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -59,7 +59,7 @@ public: Inset * Clone() const; /// what appears in the minibuffer when opening - char const * EditMessage() const; + string const EditMessage() const; /// void Edit(BufferView *, int x, int y, unsigned int button); /// @@ -67,10 +67,6 @@ public: /// RESULT LocalDispatch(BufferView *, int, string const &); -protected: - /// - //void UpdateLocal(); - private: /// bool opened; diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index fe467c3445..1442d98cc8 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -35,14 +35,14 @@ static LyxArrayBase * selarray = 0; using std::endl; -inline +static inline bool IsAlpha(char c) { return ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'); } // This was very smaller, I'll change it later -inline +static inline bool IsMacro(short tok, int id) { return (tok != LM_TK_STACK && tok != LM_TK_FRAC && tok != LM_TK_SQRT @@ -55,7 +55,7 @@ bool IsMacro(short tok, int id) // Yes, mathed isn't using string yet. -inline +static inline char * strnew(char const * s) { char * s1 = new char[strlen(s)+1]; @@ -65,7 +65,8 @@ char * strnew(char const * s) -#define MAX_STACK_ITEMS 32 +static int const MAX_STACK_ITEMS = 32; + struct MathStackXIter { @@ -596,9 +597,9 @@ void MathedCursor::SetSize(short size) } -void MathedCursor::setLabel(char const * label) +void MathedCursor::setLabel(string const & label) { // ugly hack and possible bug - if (!cursor->setLabel(strnew(label))) + if (!cursor->setLabel(label)) lyxerr << "MathErr: Bad place to set labels." << endl; } @@ -611,10 +612,10 @@ void MathedCursor::setNumbered() } -void MathedCursor::Interpret(char const * s) +void MathedCursor::Interpret(string const & s) { MathedInset * p = 0; - latexkeys * l = 0; + latexkeys * l = 0; MathedTextCodes tcode = LM_TC_INSET; if (s[0] == '^' || s[0] == '_') { @@ -643,13 +644,13 @@ void MathedCursor::Interpret(char const * s) Insert(p); return; } else - l = in_word_set (s, strlen(s)); + l = in_word_set(s); if (!l) { p = MathMacroTable::mathMTable.getMacro(s); if (!p) { lyxerr[Debug::MATHED] << "Macro2 " << s << ' ' << tcode << endl; - if (strcmp("root", s) == 0) { + if (s == "root") { p = new MathRootInset(); tcode = LM_TC_ACTIVE_INSET; } else diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 24d9a767a3..8ccd85936c 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -76,12 +76,13 @@ class MathedCursor { /// void SetPar(MathParInset *); /// - void Interpret(char const *); + void Interpret(string const &); /// void SetSize(short); /// void setNumbered(); - void setLabel(char const *); + /// + void setLabel(string const &); /// bool Limits(); /// Set accent: if argument = 0 it's considered consumed diff --git a/src/mathed/math_defs.h b/src/mathed/math_defs.h index bebf604daf..99dbf57038 100644 --- a/src/mathed/math_defs.h +++ b/src/mathed/math_defs.h @@ -221,7 +221,7 @@ class MathParInset; class MathedInset { public: /// A math inset has a name (usually its LaTeX name), type and font-size - MathedInset(char const * nm, short ot, short st); + MathedInset(string const & nm, short ot, short st); /// explicit MathedInset(MathedInset *); @@ -254,7 +254,7 @@ class MathedInset { virtual void SetLimits(bool) {} /// - char const * GetName() const { return name; } + string const & GetName() const { return name; } /// short GetType() const { return objtype; } /// @@ -266,10 +266,10 @@ class MathedInset { /// virtual void SetStyle(short st) { size = st; } // Metrics(); /// - virtual void SetName(char const * n) { name = n; } + virtual void SetName(string const & n) { name = n; } protected: /// - char const * name; + string name; /// short objtype; /// @@ -319,7 +319,7 @@ enum MathedParFlag { class MathParInset: public MathedInset { public: /// - MathParInset(short st = LM_ST_TEXT, char const * nm = 0, + MathParInset(short st = LM_ST_TEXT, string const & nm = string(), short ot = LM_OT_MIN); /// explicit @@ -356,21 +356,13 @@ class MathParInset: public MathedInset { // Tab stuff used by Matrix. /// - virtual void SetAlign(char, char const *) {} -// /// -// virtual int GetTabPos() { return 0; } -// /// -// virtual int GetTab(int) { return 0; } + virtual void SetAlign(char, string const &) {} /// virtual int GetColumns() { return 1; } /// virtual int GetRows() { return 1; } /// virtual bool isMatrix() { return false; } -// /// These functions should report an error -// virtual char const* GetLabel() { return 0; } -// virtual char const* GetLabel(int) { return 0; } - // Vertical switching /// virtual bool setArgumentIdx(int i) { return (i == 0); } @@ -380,8 +372,6 @@ class MathParInset: public MathedInset { virtual int getArgumentIdx() { return 0; } /// virtual int getMaxArgumentIdx() { return 0; } -// /// -// virtual void SetLabel(char const *) {} /// virtual void SetStyle(short); /// @@ -430,20 +420,20 @@ struct MathedRowSt { for (int i = 0 ; i < n + 1 ; ++i) w[i] = 0; next = 0; - label = 0; + //label = 0; numbered = true; } /// ~MathedRowSt() { delete[] w; - delete[] label; + //delete[] label; } /// Should be const but... MathedRowSt * getNext() const { return next; } /// ...we couldn't use this. void setNext(MathedRowSt * n) { next = n; } /// - char const * getLabel() const { return label; } + string const & getLabel() const { return label; } /// bool isNumbered() const { return numbered; } /// @@ -451,7 +441,7 @@ struct MathedRowSt { /// int getTab(int i) { return w[i]; } /// - void setLabel(char * l) { label = l; } + void setLabel(string const & l) { label = l; } /// void setNumbered(bool nf) { numbered = nf; } /// @@ -463,7 +453,7 @@ struct MathedRowSt { /// widths int * w; /// - char * label; + string label; /// bool numbered; /// @@ -506,8 +496,6 @@ class MathMatrixInset: public MathParInset { *vv = v_align; return h_align; } -// /// -// int GetTab(int); /// int GetColumns() { return nc; } /// @@ -528,7 +516,7 @@ class MathMatrixInset: public MathParInset { /// tab sizes int * ws; /// - char v_align; // add approp. signedness + char v_align; // add approp. type /// char * h_align; /// Vertical structure @@ -544,7 +532,7 @@ LyxArrayBase * mathed_parse(unsigned flags, LyxArrayBase * data, MathParInset ** mt); /// void mathed_write(MathParInset *, std::ostream &, int *, bool fragile, - char const * label = 0); + string const & label = string()); /// void mathed_parser_file(std::istream &, int); @@ -626,7 +614,7 @@ bool MathIsSymbol(short x) { inline -MathedInset::MathedInset(char const * nm, short ot, short st): +MathedInset::MathedInset(string const & nm, short ot, short st): name(nm), objtype(ot), size(st) { width = ascent = descent = 0; diff --git a/src/mathed/math_draw.C b/src/mathed/math_draw.C index c3c01b2025..8373db25dc 100644 --- a/src/mathed/math_draw.C +++ b/src/mathed/math_draw.C @@ -25,11 +25,11 @@ using std::endl; -extern LyXFont mathed_get_font(short type, int size); +extern LyXFont const mathed_get_font(short type, int size); extern int mathed_char_width(short type, int style, byte c); -extern int mathed_string_width(short type, int style, byte const* s, int ls); -extern int mathed_string_height(short, int, byte const*, int, int&, int&); -extern int mathed_char_height(short, int, byte, int&, int&); +extern int mathed_string_width(short type, int style, string const &); +extern int mathed_string_height(short, int, string const &, int &, int &); +extern int mathed_char_height(short, int, byte, int &, int &); void MathSpaceInset::draw(Painter & pain, int x, int y) @@ -141,10 +141,14 @@ MathParInset::draw(Painter & pain, int x, int y) void MathParInset::Metrics() { - byte cx, cxp= 0, *s; + byte cx; + byte cxp = 0; + string s; int ls; - int asc= df_asc, des= 0; - int tb = 0, tab= 0; + int asc = df_asc; + int des = 0; + int tb = 0; + int tab = 0; bool limits = false; @@ -160,23 +164,23 @@ MathParInset::Metrics() while (data.OK()) { cx = data.GetChar(); if (cx >= ' ') { - s = data.GetString(ls); - mathed_string_height(data.FCode(), size, s, ls, asc, des); + s = reinterpret_cast(data.GetString(ls)); + mathed_string_height(data.FCode(), size, s, asc, des); if (asc > ascent) ascent = asc; if (des > descent) descent = des; limits = false; mathed_char_height(LM_TC_CONST, size, 'y', asc, des); } else if (MathIsInset(cx)) { - MathedInset *p = data.GetInset(); + MathedInset * p = data.GetInset(); p->SetStyle(size); p->Metrics(); if (cx == LM_TC_UP) { - asc += (limits) ? p->Height()+4: p->Ascent() + - ((p->Descent()>asc) ? p->Descent()-asc+4: 0); + asc += (limits) ? p->Height() + 4: p->Ascent() + + ((p->Descent()>asc) ? p->Descent() - asc + 4: 0); } else if (cx == LM_TC_DOWN) { - des += ((limits) ? p->Height()+4: p->Height()-p->Ascent()/2); + des += ((limits) ? p->Height() + 4: p->Height() - p->Ascent() / 2); } else { asc = p->Ascent(); des = p->Descent(); @@ -201,14 +205,14 @@ MathParInset::Metrics() data.Next(); } else if (cx == LM_TC_CR) { - if (tb>0) { + if (tb > 0) { int x, y; data.GetIncPos(x, y); if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) { if (ascent(s), - ls, ascent, descent); - width = mathed_string_width(t, size, - reinterpret_cast(s), - ls); + mathed_string_height(t, size, s, ascent, descent); + width = mathed_string_width(t, size, s); if (sym == LM_oint) width += 2; } diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index ba5fb5cdcc..66af12bcdb 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -354,45 +354,48 @@ static short lookup[] = 276, }; -struct latexkeys * + +latexkeys * in_word_set (register char const *str, register int len) { - if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) - { - register int key = math_hash (str, len); - - if (key <= MAX_HASH_VALUE && key >= 0) - { - register int idx = lookup[key]; - - if (idx >= 0 && idx < MAX_HASH_VALUE) - { - register char const * s = wordlist[idx].name; - - if (*s == *str && !strcmp (str + 1, s + 1)) - return &wordlist[idx]; - } - else if (idx < 0 && idx >= -MAX_HASH_VALUE) - return 0; - else - { - register int offset = key + idx + (idx > 0 ? -MAX_HASH_VALUE : MAX_HASH_VALUE); - register struct latexkeys *base = &wordlist[-lookup[offset]]; - register struct latexkeys *ptr = base + -lookup[offset + 1]; - - while (--ptr >= base) - if (*str == *ptr->name && !strcmp (str + 1, ptr->name + 1)) - return ptr; - } - } - } - return 0; + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) { + int key = math_hash (str, len); + + if (key <= MAX_HASH_VALUE && key >= 0) { + int idx = lookup[key]; + + if (idx >= 0 && idx < MAX_HASH_VALUE) { + char const * s = wordlist[idx].name; + + if (*s == *str && !strcmp (str + 1, s + 1)) + return &wordlist[idx]; + } else if (idx < 0 && idx >= -MAX_HASH_VALUE) { + return 0; + } else { + int offset = key + idx + (idx > 0 ? -MAX_HASH_VALUE : MAX_HASH_VALUE); + latexkeys * base = &wordlist[-lookup[offset]]; + latexkeys * ptr = base + -lookup[offset + 1]; + + while (--ptr >= base) + if (*str == *ptr->name && !strcmp (str + 1, ptr->name + 1)) + return ptr; + } + } + } + return 0; } + +latexkeys * in_word_set(string const & str) +{ + return in_word_set(str.c_str(), str.length()); +} + + latexkeys *lm_get_key_by_id(int t, short tk) { - latexkeys* l = &wordlist[MIN_HASH_VALUE+TOTAL_KEYWORDS]; - latexkeys* base = &wordlist[MIN_HASH_VALUE]; + latexkeys * l = &wordlist[MIN_HASH_VALUE+TOTAL_KEYWORDS]; + latexkeys * base = &wordlist[MIN_HASH_VALUE]; while (--l >= base) { if (t == l->id && tk == l->token) return l; @@ -400,9 +403,10 @@ latexkeys *lm_get_key_by_id(int t, short tk) return 0; } + latexkeys *lm_get_key_by_index(int i) { - if (i>0 && i 0 && i < TOTAL_KEYWORDS + 2) return &wordlist[i]; else return 0; diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 8b872a0af0..dfcce43cd8 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -26,7 +26,7 @@ #include "symbol_def.h" -inline +static inline char * strnew(char const * s) { char * s1 = new char[strlen(s)+1]; @@ -47,21 +47,21 @@ MathedInset::MathedInset(MathedInset * inset) objtype = LM_OT_UNDEF; size = LM_ST_TEXT; width = ascent = descent = 0; - name = 0; + //name = 0; } } -MathFuncInset::MathFuncInset(char const * nm, short ot, short st) +MathFuncInset::MathFuncInset(string const & nm, short ot, short st) : MathedInset("", ot, st) { ln = 0; lims = (GetType() == LM_OT_FUNCLIM); if (GetType() == LM_OT_UNDEF) { - fname = strnew(nm); + fname = nm; SetName(fname); } else { - fname = 0; + //fname = 0; SetName(nm); } } @@ -84,7 +84,7 @@ MathedInset * MathSpaceInset::Clone() } -MathParInset::MathParInset(short st, char const * nm, short ot) +MathParInset::MathParInset(short st, string const & nm, short ot) : MathedInset(nm, ot, st) { array = 0; @@ -338,8 +338,8 @@ MathMatrixInset::MathMatrixInset(MathMatrixInset * mt) while (mrow) { r = new MathedRowSt(nc + 1); r->numbered = mrow->numbered; - if (mrow->label) - r->label = strnew(mrow->label); + //if (mrow->label) + r->label = mrow->label; if (!ro) row = r; else @@ -534,7 +534,7 @@ MathedInset * MathAccentInset::Clone() } -MathBigopInset::MathBigopInset(char const* nam, int id, short st) +MathBigopInset::MathBigopInset(string const & nam, int id, short st) : MathedInset(nam, LM_OT_BIGOP, st), sym(id) { lims = -1; @@ -547,7 +547,7 @@ MathedInset * MathBigopInset::Clone() } -MathDotsInset::MathDotsInset(char const * nam, int id, short st) +MathDotsInset::MathDotsInset(string const & nam, int id, short st) : MathedInset(nam, LM_OT_DOTS, st), code(id) {} diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 2352284008..1b374a866d 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -37,7 +37,7 @@ class MathFuncInset: public MathedInset { public: /// explicit - MathFuncInset(char const * nm, + MathFuncInset(string const & nm, short ot = LM_OT_FUNC, short st = LM_ST_TEXT); /// ~MathFuncInset(); @@ -57,7 +57,7 @@ protected: /// bool lims; /// - char * fname; + string fname; }; @@ -99,7 +99,7 @@ protected: class MathDotsInset: public MathedInset { public: /// - MathDotsInset(char const *, int, short st = LM_ST_TEXT); + MathDotsInset(string const &, int, short st = LM_ST_TEXT); /// MathedInset * Clone(); /// @@ -141,7 +141,7 @@ protected: class MathBigopInset: public MathedInset { public: /// - MathBigopInset(char const *, int, short st = LM_ST_TEXT); + MathBigopInset(string const &, int, short st = LM_ST_TEXT); /// MathedInset * Clone(); /// @@ -284,9 +284,7 @@ protected: inline MathFuncInset::~MathFuncInset() -{ - if (fname && GetType() == LM_OT_UNDEF) delete[] fname; -} +{} inline diff --git a/src/mathed/math_iter.C b/src/mathed/math_iter.C index 9e077461c4..f1e9886640 100644 --- a/src/mathed/math_iter.C +++ b/src/mathed/math_iter.C @@ -38,7 +38,7 @@ extern int mathed_char_height(short, int, byte, int&, int&); // the builtin memcpy() is broken in egcs and gcc 2.95.x on alpha // stations. We provide a hand-made version instead. -inline +static inline void my_memcpy( void * ps_in, const void * pt_in, size_t n ) { char * ps = static_cast(ps_in); @@ -64,7 +64,7 @@ void MathedIter::Reset() } -byte MathedIter::GetChar() +byte MathedIter::GetChar() const { if (IsFont()) { fcode = array->bf[pos]; @@ -74,25 +74,33 @@ byte MathedIter::GetChar() } -byte* MathedIter::GetString(int& len) +byte * MathedIter::GetString(int& len) const { if (IsFont()) { fcode = array->bf[++pos]; - pos++; + ++pos; } - byte *s = &array->bf[pos]; + byte * s = &array->bf[pos]; len = pos; - while (array->bf[pos]>= ' ' && poslast) pos++; - len = pos-len; + while (array->bf[pos] >= ' ' && pos < array->last) ++pos; + len = pos - len; return s; } -MathedInset* MathedIter::GetInset() +string const MathedIter::GetString() const +{ + int ls = 0; + byte * s = GetString(ls); + return string(reinterpret_cast(s), ls); +} + + +MathedInset * MathedIter::GetInset() const { if (IsInset()) { - MathedInset* p; - my_memcpy(&p, &array->bf[pos+1], sizeof(p)); + MathedInset * p; + my_memcpy(&p, &array->bf[pos + 1], sizeof(p)); return p; } else { lyxerr << "Math Error: This is not an inset[" @@ -103,7 +111,7 @@ MathedInset* MathedIter::GetInset() // An active math inset MUST be derived from MathParInset because it // must have at least one paragraph to edit -MathParInset * MathedIter::GetActiveInset() +MathParInset * MathedIter::GetActiveInset() const { if (IsActive()) { return static_cast(GetInset()); @@ -576,12 +584,14 @@ void MathedXIter::SetData(MathParInset *pp) Reset(); } -byte* MathedXIter::GetString(int& ls) + +byte * MathedXIter::GetString(int & ls) const { static byte s[255]; - byte const *sxs = MathedIter::GetString(ls); - if (ls>0) { - strncpy(reinterpret_cast(s), reinterpret_cast(sxs), ls); + byte const * sxs = MathedIter::GetString(ls); + if (ls > 0) { + strncpy(reinterpret_cast(s), + reinterpret_cast(sxs), ls); x += mathed_string_width(fcode, size, s, ls); return &s[0]; } @@ -589,6 +599,14 @@ byte* MathedXIter::GetString(int& ls) } +string const MathedXIter::GetString() const +{ + int ls; + byte * s = GetString(ls); + return string(reinterpret_cast(s), ls); +} + + bool MathedXIter::Next() { // lyxerr << "Ne[" << pos << "]"; @@ -940,9 +958,9 @@ bool MathedXIter::setNumbered(bool numb) } -bool MathedXIter::setLabel(char* label) +bool MathedXIter::setLabel(string const & label) { - if (label && crow) { + if (!label.empty() && crow) { crow->setLabel(label); return true; } @@ -951,19 +969,19 @@ bool MathedXIter::setLabel(char* label) } -MathedRowSt *MathedXIter::adjustVerticalSt() +MathedRowSt * MathedXIter::adjustVerticalSt() { GoBegin(); if (!crow) { // lyxerr << " CRW" << ncols << " "; - crow = new MathedRowSt(ncols+1); // this leaks + crow = new MathedRowSt(ncols + 1); // this leaks } // lyxerr<< " CRW[" << crow << "] "; - MathedRowSt *mrow = crow; + MathedRowSt * mrow = crow; while (OK()) { if (IsCR()) { - if (col>= ncols) ncols = col+1; - MathedRowSt *r = new MathedRowSt(ncols+1); // this leaks + if (col >= ncols) ncols = col + 1; + MathedRowSt * r = new MathedRowSt(ncols + 1); // this leaks // r->next = crow->next; crow->next = r; crow = r; diff --git a/src/mathed/math_iter.h b/src/mathed/math_iter.h index dd4b1cb982..84f0d76e82 100644 --- a/src/mathed/math_iter.h +++ b/src/mathed/math_iter.h @@ -60,31 +60,33 @@ class MathedIter { /// void goPosAbs(int); /// - int Empty() { return array->Last()<= 1; } + int Empty() const { return array->Last()<= 1; } /// - int OK() { return array && (pos < array->Last()); } + int OK() const { return array && (pos < array->Last()); } /// - int IsFirst() { return (pos == 0); } + int IsFirst() const { return (pos == 0); } /// - byte GetChar(); + byte GetChar() const; /// - byte * GetString(int& len); + byte * GetString(int & len) const; /// - MathedInset * GetInset(); + string const GetString() const; /// - MathParInset * GetActiveInset(); + MathedInset * GetInset() const; /// - bool IsInset(); + MathParInset * GetActiveInset() const; /// - bool IsActive(); + bool IsInset() const; /// - bool IsFont(); + bool IsActive() const; /// - bool IsScript(); + bool IsFont() const; /// - bool IsTab(); + bool IsScript() const; /// - bool IsCR(); + bool IsTab() const; + /// + bool IsCR() const; /// virtual void Reset(); /// @@ -112,10 +114,10 @@ class MathedIter { /// void SetData(LyxArrayBase * a) { array = a; Reset(); } /// - LyxArrayBase * GetData() { return array; } + LyxArrayBase * GetData() const { return array; } /// Copy every object from position p1 to p2 - LyxArrayBase * Copy(int p1= 0, int p2= 10000); + LyxArrayBase * Copy(int p1 = 0, int p2 = 10000); /// Delete every object from position p1 to p2 void Clear(); @@ -128,13 +130,13 @@ class MathedIter { /// int flags; /// - short fcode; + mutable short fcode; /// - int pos; + mutable int pos; /// int row, col, ncols; /// - LyxArrayBase *array; + LyxArrayBase * array; // one element stack struct MIState { /// @@ -174,7 +176,7 @@ class MathedXIter: public MathedIter { /// void SetData(MathParInset *); /// - MathParInset * getPar() { return p; } + MathParInset * getPar() const { return p; } /// bool Next(); /// @@ -193,22 +195,24 @@ class MathedXIter: public MathedIter { void Adjust(); /// inline - void GetPos(int &, int &); + void GetPos(int &, int &) const; /// inline - void GetIncPos(int &, int &); + void GetIncPos(int &, int &) const; /// - byte * GetString(int &); + byte * GetString(int &) const ; /// - int GetX(); + string const GetString() const; /// - int GetY(); + int GetX() const; + /// + int GetY() const; /// void subMetrics(int, int); /// void fitCoord(int, int); /// - void getAD(int & a, int & d); + void getAD(int & a, int & d) const; /// Create a new row and insert #ncols# tabs. void addRow(); @@ -216,29 +220,30 @@ class MathedXIter: public MathedIter { void delRow(); /// - bool setLabel(char* label); + bool setLabel(string const & label); /// bool setNumbered(bool); /// void setTab(int, int); /// Merge the array at current position - void Merge(LyxArrayBase*); + void Merge(LyxArrayBase *); /// Delete every object from current position to pos2 void Clean(int pos2); - MathedRowSt *adjustVerticalSt(); + /// + MathedRowSt * adjustVerticalSt(); private: /// This function is not recursive, as MathPar::Metrics is - void IMetrics(int, int&, int&, int&); + void IMetrics(int, int &, int &, int &); /// Font size (display, text, script, script2) int size; /// current position - int x, y; -// /// max ascent and descent -// int asc, des; - /// - MathParInset *p; + mutable int x; + /// + int y; + /// + MathParInset * p; // Limits auxiliary variables /// Position and max width of a script @@ -254,7 +259,7 @@ private: protected: /// - MathedRowSt *crow; + MathedRowSt * crow; private: /// @@ -266,46 +271,47 @@ private: inline -bool MathedIter::IsInset() +bool MathedIter::IsInset() const { return MathIsInset((*array)[pos]); } inline -bool MathedIter::IsActive() +bool MathedIter::IsActive() const { return MathIsActive((*array)[pos]); } inline -bool MathedIter::IsFont() +bool MathedIter::IsFont() const { return MathIsFont((*array)[pos]); } inline -bool MathedIter::IsScript() +bool MathedIter::IsScript() const { return MathIsScript((*array)[pos]); } inline -bool MathedIter::IsTab() +bool MathedIter::IsTab() const { return ((*array)[pos] == LM_TC_TAB); } inline -bool MathedIter::IsCR() +bool MathedIter::IsCR() const { return ((*array)[pos] == LM_TC_CR); } inline -MathedIter::MathedIter(LyxArrayBase * d): array(d) +MathedIter::MathedIter(LyxArrayBase * d) + : array(d) { pos = 0; row = col = 0; @@ -334,7 +340,7 @@ void MathedIter::ipop() inline -void MathedXIter::GetPos(int&xx, int& yy) +void MathedXIter::GetPos(int & xx, int & yy) const { if (p) p->GetXY(xx, yy); @@ -344,7 +350,7 @@ void MathedXIter::GetPos(int&xx, int& yy) } inline -int MathedXIter::GetX() +int MathedXIter::GetX() const { int xx, yy; GetPos(xx, yy); @@ -352,7 +358,7 @@ int MathedXIter::GetX() } inline -int MathedXIter::GetY() +int MathedXIter::GetY() const { int xx, yy; GetPos(xx, yy); @@ -361,14 +367,14 @@ int MathedXIter::GetY() inline -void MathedXIter::GetIncPos(int& xx, int& yy) +void MathedXIter::GetIncPos(int & xx, int & yy) const { xx = x; yy = y; } inline -void MathedXIter::getAD(int& a, int& d) +void MathedXIter::getAD(int & a, int & d) const { if (crow) { a = crow->asc; diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index 9f1a3a36ee..5f2a77cad6 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -218,18 +218,18 @@ void MathMacroArgument::draw(Painter & pain, int x, int baseline) if (expnd_mode) { MathParInset::draw(pain, x, baseline); } else { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; ost << '#' << number; drawStr(pain, LM_TC_TEX, size, x, baseline, reinterpret_cast(ost.str().c_str()), 2); -#else - char s[3]; - ostrstream ost(s, 3); - ost << '#' << number << '\0'; - drawStr(pain, LM_TC_TEX, size, x, baseline, - reinterpret_cast(ost.str()), 2); -#endif +//#else +// char s[3]; +// ostrstream ost(s, 3); +// ost << '#' << number << '\0'; +// drawStr(pain, LM_TC_TEX, size, x, baseline, +// reinterpret_cast(ost.str()), 2); +//#endif } } @@ -239,7 +239,7 @@ void MathMacroArgument::Metrics() if (expnd_mode) { MathParInset::Metrics(); } else { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; ost << '#' << number; width = mathed_string_width(LM_TC_TEX, size, @@ -247,17 +247,17 @@ void MathMacroArgument::Metrics() mathed_string_height(LM_TC_TEX, size, reinterpret_cast(ost.str().c_str()), 2, ascent, descent); -#else - char s[3]; - ostrstream ost(s, 3); - ost << '#' << number << '\0'; - width = mathed_string_width(LM_TC_TEX, size, - reinterpret_cast - (ost.str()), 2); - mathed_string_height(LM_TC_TEX, size, - reinterpret_cast(ost.str()), - 2, ascent, descent); -#endif +//#else +// char s[3]; +// ostrstream ost(s, 3); +// ost << '#' << number << '\0'; +// width = mathed_string_width(LM_TC_TEX, size, +// reinterpret_cast +// (ost.str()), 2); +// mathed_string_height(LM_TC_TEX, size, +// reinterpret_cast(ost.str()), +// 2, ascent, descent); +//#endif } } @@ -438,10 +438,10 @@ MathMacroTable::~MathMacroTable() // The search is currently linear but will be binary or hash, later. -MathMacroTemplate * MathMacroTable::getTemplate(char const * name) const +MathMacroTemplate * MathMacroTable::getTemplate(string const & name) const { for (int i = 0; i < num_macros; ++i) { - if (strcmp(name, macro_table[i]->GetName()) == 0) + if (name == macro_table[i]->GetName()) return macro_table[i]; } diff --git a/src/mathed/math_macro.h b/src/mathed/math_macro.h index bd87b701af..f57f09098e 100644 --- a/src/mathed/math_macro.h +++ b/src/mathed/math_macro.h @@ -201,9 +201,9 @@ public: /// void addTemplate(MathMacroTemplate *); /// - MathMacro * getMacro(char const *) const; + MathMacro * getMacro(string const &) const; /// - MathMacroTemplate * getTemplate(char const *) const; + MathMacroTemplate * getTemplate(string const &) const; /// void builtinMacros(); /// @@ -262,7 +262,7 @@ void MathMacro::SetData(LyxArrayBase * a) inline -MathMacro * MathMacroTable::getMacro(char const * name) const +MathMacro * MathMacroTable::getMacro(string const & name) const { MathMacroTemplate * mt = getTemplate(name); return (mt) ? new MathMacro(mt): 0; diff --git a/src/mathed/math_panel.C b/src/mathed/math_panel.C index 8ad14ff12c..3a7bb08122 100644 --- a/src/mathed/math_panel.C +++ b/src/mathed/math_panel.C @@ -14,11 +14,15 @@ #include +#if 0 #ifdef HAVE_SSTREAM #include #else #include #endif +#else +#include "Lsstream.h" +#endif #include FORMS_H_LOCATION @@ -152,16 +156,16 @@ void delim_cb(FL_OBJECT *, long data) case MM_APPLY: case MM_OK: { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; ost << delim_code[left] << ' ' << delim_code[right]; lyxfunc->Dispatch(LFUN_MATH_DELIM, ost.str().c_str()); -#else - char s[80]; - ostrstream ost(s, 80); - ost << delim_code[left] << ' ' << delim_code[right] << '\0'; - lyxfunc->Dispatch(LFUN_MATH_DELIM, ost.str()); -#endif +//#else +// char s[80]; +// ostrstream ost(s, 80); +// ost << delim_code[left] << ' ' << delim_code[right] << '\0'; +// lyxfunc->Dispatch(LFUN_MATH_DELIM, ost.str()); +//#endif if (data == MM_APPLY) break; } case MM_CLOSE: fl_hide_form(fd_delim->delim); break; @@ -211,16 +215,16 @@ void matrix_cb(FL_OBJECT *, long data) int nx = int(fl_get_slider_value(fd_matrix->columns)+0.5); int ny = int(fl_get_slider_value(fd_matrix->rows)+0.5); if (data == MM_OK) fl_hide_form(fd_matrix->matrix); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; ost << nx << ' ' << ny << ' ' << c << sh; lyxfunc->Dispatch(LFUN_INSERT_MATRIX, ost.str().c_str()); -#else - char s[80]; - ostrstream ost(s, 80); - ost << nx << ' ' << ny << ' ' << c << sh << '\0'; - lyxfunc->Dispatch(LFUN_INSERT_MATRIX, ost.str()); -#endif +//#else +// char s[80]; +// ostrstream ost(s, 80); +// ost << nx << ' ' << ny << ' ' << c << sh << '\0'; +// lyxfunc->Dispatch(LFUN_INSERT_MATRIX, ost.str()); +//#endif break; } case MM_CLOSE: fl_hide_form(fd_matrix->matrix); break; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 2c8c7053cf..9d08906c89 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -92,7 +92,7 @@ static int yylineno; static istream * yyis; static bool yy_mtextmode= false; -inline +static inline char * strnew(char const * s) { char * s1 = new char[strlen(s) + 1]; // this leaks when not delete[]'ed @@ -102,7 +102,7 @@ char * strnew(char const * s) static -void mathPrintError(char const * msg) +void mathPrintError(string const & msg) { lyxerr << "Line ~" << yylineno << ": Math parse error: " << msg << endl; diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index 3a283b48e7..a999664230 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -23,6 +23,8 @@ #pragma interface #endif +#include "LString.h" + #include "symbol_def.h" /// @@ -113,6 +115,9 @@ struct latexkeys { latexkeys * in_word_set (register char const * str, register int len); +/// +latexkeys * in_word_set(string const & str); + /// latexkeys * lm_get_key(int index); diff --git a/src/mathed/math_symbols.C b/src/mathed/math_symbols.C index 8eaf226a79..34447a4f9d 100644 --- a/src/mathed/math_symbols.C +++ b/src/mathed/math_symbols.C @@ -176,7 +176,8 @@ void BitmapMenu::Show() } FL_OBJECT * -BitmapMenu::AddBitmap(int id, int nx, int ny, int bw, int bh, unsigned char const * data, Bool vert) +BitmapMenu::AddBitmap(int id, int nx, int ny, int bw, int bh, + unsigned char const * data, Bool vert) { if (i >= nb) return 0; @@ -359,7 +360,7 @@ bool math_insert_greek(char c) } -void math_insert_symbol(char const * s) +void math_insert_symbol(string const & s) { if (current_view->available()) { if (!current_view->the_locking_inset) { diff --git a/src/mathed/math_write.C b/src/mathed/math_write.C index 425f015299..f70873edbb 100644 --- a/src/mathed/math_write.C +++ b/src/mathed/math_write.C @@ -252,7 +252,7 @@ void MathParInset::Write(ostream & os, bool fragile) if (!crow->isNumbered()) { os << "\\nonumber "; } - if (crow->getLabel()) { + if (!crow->getLabel().empty()) { os << "\\label{" << crow->getLabel() << "} "; @@ -276,7 +276,7 @@ void MathParInset::Write(ostream & os, bool fragile) if (!crow->isNumbered()) { os << "\\nonumber "; } - if (crow->getLabel()) { + if (!crow->getLabel().empty()) { os << "\\label{" << crow->getLabel() << "} "; @@ -320,7 +320,7 @@ void MathMatrixInset::Write(ostream & os, bool fragile) void mathed_write(MathParInset * p, ostream & os, int * newlines, - bool fragile, char const * label) + bool fragile, string const & label) { number_of_newlines = 0; short mathed_env = p->GetType(); @@ -340,7 +340,7 @@ void mathed_write(MathParInset * p, ostream & os, int * newlines, ++number_of_newlines; } - if (label && label[0] > ' ' && mathed_env == LM_EN_EQUATION){ + if (!label.empty() && label[0] > ' ' && mathed_env == LM_EN_EQUATION){ os << "\\label{" << label << "}\n"; diff --git a/src/minibuffer.h b/src/minibuffer.h index 80cfc15ccb..d040e08f6a 100644 --- a/src/minibuffer.h +++ b/src/minibuffer.h @@ -31,7 +31,7 @@ public: string const & = string(), int delay_secs= 6); /// - string GetText() const { return text; } + string const GetText() const { return text; } /// void Init(); /// @@ -71,11 +71,13 @@ private: /// enum{ MAX_HISTORY = 10 }; /// - string history[MAX_HISTORY]; + mutable string history[MAX_HISTORY]; /// - int history_idx, history_cnt; + mutable int history_idx; + /// + mutable int history_cnt; /// - void addHistory(string const &cmd) { + void addHistory(string const &cmd) const { if (history_cnt == 0 || (history_cnt > 0 && cmd != history[(history_cnt - 1) % MAX_HISTORY])) { @@ -85,6 +87,6 @@ private: history_idx = history_cnt; } /// - string getHistory() { return history[history_idx % MAX_HISTORY]; } + string const getHistory() const { return history[history_idx % MAX_HISTORY]; } }; #endif diff --git a/src/paragraph.C b/src/paragraph.C index d4116332d8..fd5b186606 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -818,7 +818,7 @@ Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const // Gets uninstantiated font setting at position. // Optimized after profiling. (Asger) -LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams, +LyXFont const LyXParagraph::GetFontSettings(BufferParams const & bparams, LyXParagraph::size_type pos) const { #ifdef NEW_INSETS @@ -871,7 +871,7 @@ LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams, } // Gets uninstantiated font setting at position 0 -LyXFont LyXParagraph::GetFirstFontSettings() const +LyXFont const LyXParagraph::GetFirstFontSettings() const { if (size() > 0) { if (!fontlist.empty()) @@ -893,7 +893,7 @@ LyXFont LyXParagraph::GetFirstFontSettings() const // the true picture of the buffer. (Asger) // If position is -1, we get the layout font of the paragraph. // If position is -2, we get the font of the manual label of the paragraph. -LyXFont LyXParagraph::getFont(BufferParams const & bparams, +LyXFont const LyXParagraph::getFont(BufferParams const & bparams, LyXParagraph::size_type pos) const { LyXFont tmpfont; @@ -1034,7 +1034,7 @@ LyXParagraph::GetChar(LyXParagraph::size_type pos) const // return an string of the current word, and the end of the word in lastpos. -string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const +string const LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const { Assert(lastpos >= 0); @@ -1926,7 +1926,7 @@ int LyXParagraph::GetFirstCounter(int i) const // the next two functions are for the manual labels -string LyXParagraph::GetLabelWidthString() const +string const LyXParagraph::GetLabelWidthString() const { #ifndef NEW_INSETS if (!FirstPhysicalPar()->labelwidthstring.empty()) @@ -3219,18 +3219,18 @@ void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer, column = 0; } else if (c == LyXParagraph::META_INSET) { inset = GetInset(i); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; inset->DocBook(buffer, ost); string tmp_out = ost.str().c_str(); -#else - ostrstream ost; - inset->DocBook(buffer, ost); - ost << '\0'; - char * ctmp = ost.str(); - string tmp_out(ctmp); - delete [] ctmp; -#endif +//#else +// ostrstream ost; +// inset->DocBook(buffer, ost); +// ost << '\0'; +// char * ctmp = ost.str(); +// string tmp_out(ctmp); +// delete [] ctmp; +//#endif // // This code needs some explanation: // Two insets are treated specially @@ -3392,18 +3392,18 @@ void LyXParagraph::DocBookContTableRows(Buffer const * buffer, } if (c == LyXParagraph::META_INSET) { inset = GetInset(i); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; inset->DocBook(buffer, ost); string tmp_out = ost.str().c_str(); -#else - ostrstream ost; - inset->DocBook(buffer, ost); - ost << '\0'; - char * ctmp = ost.str(); - string tmp_out(ctmp); - delete [] ctmp; -#endif +//#else +// ostrstream ost; +// inset->DocBook(buffer, ost); +// ost << '\0'; +// char * ctmp = ost.str(); +// string tmp_out(ctmp); +// delete [] ctmp; +//#endif // // This code needs some explanation: // Two insets are treated specially @@ -4297,11 +4297,11 @@ LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf, // process footnotes > depth 0 or in environments separately // NOTE: Currently don't support footnotes within footnotes // even though that is possible using the \footnotemark -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream dummy; -#else - ostrstream dummy; -#endif +//#else +// ostrstream dummy; +//#endif TexRow dummy_texrow; int dummy_count = 0; do { @@ -4342,9 +4342,9 @@ LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf, "Footnote in a Footnote -- not supported" << endl; } -#ifndef HAVE_OSTREAM - delete [] dummy.str(); -#endif +//#ifndef HAVE_OSTREAM +// delete [] dummy.str(); +//#endif } switch (footnotekind) { @@ -4408,8 +4408,8 @@ bool LyXParagraph::IsDummy() const #endif void LyXParagraph::SetPExtraType(BufferParams const & bparams, - int type, char const * width, - char const * widthp) + int type, string const & width, + string const & widthp) { pextra_type = type; pextra_width = width; @@ -4655,7 +4655,7 @@ bool LyXParagraph::isMultiLingual(BufferParams const & bparams) // Convert the paragraph to a string. // Used for building the table of contents -string LyXParagraph::String(Buffer const * buffer, bool label) +string const LyXParagraph::String(Buffer const * buffer, bool label) { BufferParams const & bparams = buffer->params; string s; @@ -4673,14 +4673,14 @@ string LyXParagraph::String(Buffer const * buffer, bool label) s += c; else if (c == META_INSET && GetInset(i)->LyxCode() == Inset::MATH_CODE) { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; GetInset(i)->Ascii(buffer, ost); -#else - ostrstream ost; - GetInset(i)->Ascii(buffer, ost); - ost << '\0'; -#endif +//#else +// ostrstream ost; +// GetInset(i)->Ascii(buffer, ost); +// ost << '\0'; +//#endif s += subst(ost.str(),'\n',' '); } } @@ -4701,7 +4701,7 @@ string LyXParagraph::String(Buffer const * buffer, bool label) } -string LyXParagraph::String(Buffer const * buffer, +string const LyXParagraph::String(Buffer const * buffer, LyXParagraph::size_type beg, LyXParagraph::size_type end) { @@ -4732,14 +4732,14 @@ string LyXParagraph::String(Buffer const * buffer, if (IsPrintable(c)) s += c; else if (c == META_INSET) { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ost; GetInset(i)->Ascii(buffer, ost); -#else - ostrstream ost; - GetInset(i)->Ascii(buffer, ost); - ost << '\0'; -#endif +//#else +// ostrstream ost; +// GetInset(i)->Ascii(buffer, ost); +// ost << '\0'; +//#endif s += ost.str(); } #ifndef NEW_TABULAR diff --git a/src/spellchecker.C b/src/spellchecker.C index 3a36462599..6783f2989e 100644 --- a/src/spellchecker.C +++ b/src/spellchecker.C @@ -491,22 +491,21 @@ void sc_clean_up_after_error() // Send word to ispell and get reply static -isp_result * sc_check_word(char *word) +isp_result * sc_check_word(string const & word) { //Please rewrite to use string. - isp_result *result; - char buf[1024]; - fputs(word, out); + fputs(word.c_str(), out); fputc('\n', out); + char buf[1024]; fgets(buf, 1024, in); /* I think we have to check if ispell is still alive here because the signal-handler could have disabled blocking on the fd */ - if (isp_pid == -1) return 0; + if (!sc_still_alive()) return 0; - result = new isp_result; + isp_result * result = new isp_result; switch (*buf) { case '*': // Word found @@ -562,27 +561,27 @@ void close_spell_checker() static inline -void sc_insert_word(char const *word) +void sc_insert_word(string const & word) { fputc('*', out); // Insert word in personal dictionary - fputs(word, out); + fputs(word.c_str(), out); fputc('\n', out); } static inline -void sc_accept_word(char const *word) +void sc_accept_word(string const & word) { fputc('@', out); // Accept in this session - fputs(word, out); + fputs(word.c_str(), out); fputc('\n', out); } static inline -void sc_store_replacement(char const *mis, string const & cor) { +void sc_store_replacement(string const & mis, string const & cor) { if(actual_spell_checker == ASC_ASPELL) { fputs("$$ra ", out); - fputs(mis, out); + fputs(mis.c_str(), out); fputc(',', out); fputs(cor.c_str(), out); fputc('\n', out); @@ -622,26 +621,23 @@ void sc_clean_up_after_error() // Send word to ispell and get reply static -isp_result * sc_check_word(char *word) +isp_result * sc_check_word(string const & word) { isp_result * result = new isp_result; int word_ok = pspell_manager_check(sc, word); - assert(word_ok != -1); + Assert(word_ok != -1); if (word_ok) { - result->flag = ISP_OK; - } else { - const PspellWordList * sugs = pspell_manager_suggest(sc, word); - assert(sugs != 0); + PspellWordList const * sugs = pspell_manager_suggest(sc, word); + Assert(sugs != 0); result->els = pspell_word_list_elements(sugs); if (pspell_word_list_empty(sugs)) result->flag = ISP_UNKNOWN; else result->flag = ISP_MISSED; - } return result; } @@ -653,22 +649,25 @@ void close_spell_checker() pspell_manager_save_all_word_lists(sc); } + static inline -void sc_insert_word(char const *word) +void sc_insert_word(string const & word) { pspell_manager_add_to_personal(sc, word); } static inline -void sc_accept_word(char const *word) +void sc_accept_word(string const & word) { pspell_manager_add_to_session(sc, word); } + static inline -void sc_store_replacement(char const *mis, string const & cor) { - pspell_manager_store_replacement(sc, mis, cor.c_str()); +void sc_store_replacement(string const & mis, string const & cor) +{ + pspell_manager_store_replacement(sc, mis.c_str(), cor.c_str()); } #endif @@ -814,8 +813,8 @@ bool RunSpellChecker(BufferView * bv) unsigned int word_count = 0; while (true) { - char * word = bv->nextWord(newval); - if (word == 0) break; + string const word = bv->nextWord(newval); + if (word.empty()) break; ++word_count; // Update slider if and only if value has changed @@ -828,12 +827,10 @@ bool RunSpellChecker(BufferView * bv) if (word_count%1000 == 0) { obj = fl_check_forms(); if (obj == fd_form_spell_check->stop) { - delete[] word; close_spell_checker(); return true; } if (obj == fd_form_spell_check->done) { - delete[] word; close_spell_checker(); return false; } @@ -842,7 +839,6 @@ bool RunSpellChecker(BufferView * bv) result = sc_check_word(word); if (!sc_still_alive()) { delete result; - delete[] word; break; } @@ -856,8 +852,8 @@ bool RunSpellChecker(BufferView * bv) reverse(tmp.begin(),tmp.end()); fl_set_object_label(fd_form_spell_check->text, tmp.c_str()); } else - fl_set_object_label(fd_form_spell_check->text, word); - fl_set_input(fd_form_spell_check->input, word); + fl_set_object_label(fd_form_spell_check->text, word.c_str()); + fl_set_input(fd_form_spell_check->input, word.c_str()); fl_clear_browser(fd_form_spell_check->browser); const char * w; while ((w = result->next_miss()) != 0) { @@ -913,14 +909,12 @@ bool RunSpellChecker(BufferView * bv) } if (obj == fd_form_spell_check->stop) { delete result; - delete[] word; close_spell_checker(); return true; } if (obj == fd_form_spell_check->done) { delete result; - delete[] word; close_spell_checker(); return false; } @@ -928,7 +922,6 @@ bool RunSpellChecker(BufferView * bv) } default: delete result; - delete[] word; } } diff --git a/src/support/Makefile.am b/src/support/Makefile.am index cf52922815..5fe7a45640 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -52,6 +52,7 @@ libsupport_la_SOURCES = \ path.h \ putenv.C \ rename.C \ + sstream.h \ $(REGEX) syscall.C \ syscall.h \ syscontr.C \ diff --git a/src/support/copy.C b/src/support/copy.C index ed1fa9ea45..29eb28394b 100644 --- a/src/support/copy.C +++ b/src/support/copy.C @@ -1,15 +1,27 @@ #include -#include +#include + +//#include #include "support/lyxlib.h" #include "LString.h" -#include "support/syscall.h" +//#include "support/syscall.h" #include "support/filetools.h" -bool lyx::copy(char const * from, char const * to) +bool lyx::copy(string const & from, string const & to) { +#if 0 string command = "cp " + QuoteName(from) + " " + QuoteName(to); return Systemcalls().startscript(Systemcalls::System, command) == 0; +#else + ifstream ifs(from.c_str()); + if (!ifs) return false; + ofstream ofs(to.c_str(), ios::out|ios::trunc); + if (!ofs) return false; + ofs << ifs.rdbuf(); + if (ofs.good()) return true; + return false; +#endif } diff --git a/src/support/filetools.C b/src/support/filetools.C index e4c2ee6096..0fb5be8df3 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -21,11 +21,15 @@ #include #include +#if 0 #ifdef HAVE_SSTREAM #include #else #include #endif +#else +#include "Lsstream.h" +#endif #ifdef __GNUG__ #pragma implementation "filetools.h" @@ -739,24 +743,24 @@ string const GetFileContents(string const & fname) FileInfo finfo(fname); if (finfo.exist()) { ifstream ifs(fname.c_str()); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream ofs; -#else -#warning The rumour goes that this might leak, but who really cares? - ostrstream ofs; -#endif +//#else +//#warning The rumour goes that this might leak, but who really cares? +// ostrstream ofs; +//#endif if (ifs && ofs) { ofs << ifs.rdbuf(); ifs.close(); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM return ofs.str().c_str(); -#else - ofs << '\0'; - char const * tmp = ofs.str(); - string ret(tmp); - delete[] tmp; - return ret; -#endif +//#else +// ofs << '\0'; +// char const * tmp = ofs.str(); +// string ret(tmp); +// delete[] tmp; +// return ret; +//#endif } } lyxerr << "LyX was not able to read file '" << fname << "'" << endl; @@ -964,8 +968,9 @@ ChangeExtension(string const & oldname, string const & extension) return CleanupPath(oldname.substr(0, last_dot) + ext); } + /// Return the extension of the file (not including the .) -string GetExtension(string const & name) +string const GetExtension(string const & name) { string::size_type last_slash = name.rfind('/'); string::size_type last_dot = name.rfind('.'); @@ -977,6 +982,7 @@ string GetExtension(string const & name) return string(); } + // Creates a nice compact path for displaying string const MakeDisplayPath (string const & path, unsigned int threshold) @@ -1109,6 +1115,7 @@ findtexfile(string const & fil, string const & /*format*/) return c.first != -1 ? strip(c.second, '\n') : string(); } + void removeAutosaveFile(string const & filename) { string a = OnlyPath(filename); diff --git a/src/support/filetools.h b/src/support/filetools.h index 24dc32bab9..d1329d89e6 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -140,7 +140,7 @@ string const ChangeExtension(string const & oldname, string const & extension); /// Return the extension of the file (not including the .) -string GetExtension(string const & name); +string const GetExtension(string const & name); /// Create absolute path. If impossible, don't do anything string const ExpandPath(string const & path); diff --git a/src/support/getUserName.C b/src/support/getUserName.C index 03ed40d5fe..3fe433f1cb 100644 --- a/src/support/getUserName.C +++ b/src/support/getUserName.C @@ -4,7 +4,7 @@ #include "support/filetools.h" #include "gettext.h" -string lyx::getUserName() +string const lyx::getUserName() { string userName(GetEnv("LOGNAME")); if (userName.empty()) diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 1c90c07598..020a1abf2d 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -16,11 +16,15 @@ #include #include +#if 0 #ifdef HAVE_SSTREAM #include #else #include #endif +#else +#include "Lsstream.h" +#endif #include "LString.h" @@ -74,25 +78,26 @@ template inline string const tostr(T const & t) { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::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. (of course we don't want this later) -#else +//#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 +// char buf[2048]; // a bit too large perhaps? +// ostrstream ostr(buf, sizeof(buf)); +// ostr << t << '\0'; +// return buf; +//#endif } + /// inline string const tostr(bool b) diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index b14fe84dd5..e7fd1c55a7 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -29,13 +29,13 @@ namespace lyx { /// Returns false it it fails bool rename(char const * from, char const * to); /// Returns false it it fails - bool copy(char const * from, char const * to); + bool copy(string const & from, string const & to); /// generates a checksum unsigned long sum(char const * file); /// returns a date string (not used currently) char * date(); /// returns the name of the user (not used currently) - string getUserName(); + string const getUserName(); /// int kill(long int pid, int sig); /// @@ -55,13 +55,13 @@ struct lyx { /// Returns false it it fails static bool rename(char const * from, char const * to); /// Returns false it it fails - static bool copy(char const * from, char const * to); + static bool copy(string const & from, string const & to); /// generates a checksum static unsigned long sum(char const * file); /// returns a date string (not used currently) static char * date(); /// returns the name of the user (not used currently) - static string getUserName(); + static string const getUserName(); /// static int kill(long int pid, int sig); /// diff --git a/src/support/lyxstring.C b/src/support/lyxstring.C index d247be4b7f..1e3b542a6d 100644 --- a/src/support/lyxstring.C +++ b/src/support/lyxstring.C @@ -1317,7 +1317,7 @@ lyxstring & lyxstring::replace(size_type i, size_type n, value_type const * p) lyxstring & lyxstring::replace(size_type i, size_type n, size_type n2, value_type c) { - Assert(i < rep->sz); // OURS! + Assert(i <= rep->sz); // OURS! TestlyxstringInvariant(this); rep = rep->get_own_copy(); diff --git a/src/support/lyxsum.C b/src/support/lyxsum.C index fbf532d34d..a0efb5d1b7 100644 --- a/src/support/lyxsum.C +++ b/src/support/lyxsum.C @@ -17,12 +17,16 @@ #include +#if 0 #ifdef HAVE_SSTREAM #include using std::ostringstream; #else #include #endif +#else +#include "Lsstream.h" +#endif #include "support/lyxlib.h" @@ -116,22 +120,22 @@ unsigned long lyx::sum(char const * file) ifstream ifs(file); if (!ifs) return 0; ifs.unsetf(ios::skipws); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM ostringstream ostr; ostr << ifs.rdbuf(); // The .c_str() is here in case we use our lyxstring class // instead of standard string. string w = ostr.str().c_str(); return do_crc(w.begin(), w.end()); -#else - ostrstream ostr; - ostr << ifs.rdbuf(); - ostr << '\0'; - char * tmp = ostr.str(); - if (!tmp) return 0; // empty file - string w(tmp, ostr.tellp()); - unsigned long crc = do_crc(w.begin(), w.end()); - delete tmp; - return crc; -#endif +//#else +// ostrstream ostr; +// ostr << ifs.rdbuf(); +// ostr << '\0'; +// char * tmp = ostr.str(); +// if (!tmp) return 0; // empty file +// string w(tmp, ostr.tellp()); +// unsigned long crc = do_crc(w.begin(), w.end()); +// delete tmp; +// return crc; +//#endif } diff --git a/src/support/sstream.h b/src/support/sstream.h new file mode 100644 index 0000000000..2d11caad69 --- /dev/null +++ b/src/support/sstream.h @@ -0,0 +1,236 @@ +/* This is part of libio/iostream, providing -*- C++ -*- input/output. +Copyright (C) 2000 Free Software Foundation + +This file is part of the GNU IO Library. This library is free +software; you can redistribute it and/or modify it under the +terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) +any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this library; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +As a special exception, if you link this library with files +compiled with a GNU compiler to produce an executable, this does not cause +the resulting executable to be covered by the GNU General Public License. +This exception does not however invalidate any other reasons why +the executable file might be covered by the GNU General Public License. */ + +/* Written by Magnus Fromreide (magfr@lysator.liu.se). */ + +/* Sligtly modified for use in The LyX Project. + Made to be usable with both std::string (as supplied with Gcc 2.95.2), + and with lyxstring. Dynamic casts have been replaced by static_casts. + One fix to avoid unsigned/signed warnings. + + Some further changes might be needed to avoid use of namespaces. + + Lars Gullik Bjønnes (larsbj@lyx.org) +*/ + +#ifndef SSTREAM_H +#define SSTREAM_H + +#include "LString.h" +#include +#include + +namespace std +{ + class stringbuf : public streambuf + { + public: + typedef char char_type; + typedef int int_type; + typedef streampos pos_type; + typedef streamoff off_type; + + explicit stringbuf(int which=ios::in|ios::out) : + streambuf(which), buf(), mode(static_cast(which)), + rpos(0), bufsize(1) + { } + + explicit stringbuf(const string &s, int which=ios::in|ios::out) : + streambuf(which), buf(s), mode(static_cast(which)), + bufsize(1) + { + if(mode & ios::in) + { + setg(&defbuf, &defbuf + bufsize, &defbuf + bufsize); + } + if(mode & ios::out) + { + setp(&defbuf, &defbuf + bufsize); + } + rpos = (mode & ios::ate ? s.size() : 0); + } + + string str() const + { + const_cast(this)->sync(); // Sigh, really ugly hack + return buf; + }; + + void str(const string& s) + { + buf = s; + if(mode & ios::in) + { + gbump(egptr() - gptr()); + } + if(mode & ios::out) + { + pbump(pbase() - pptr()); + } + rpos = (mode & ios::ate ? s.size() : 0); + } + + protected: + inline virtual int sync(); + inline virtual int overflow(int = EOF); + inline virtual int underflow(); + private: + string buf; + ios::open_mode mode; + string::size_type rpos; + streamsize bufsize; + char defbuf; + }; + + class stringstreambase : virtual public ios { + protected: + stringbuf __my_sb; + public: + string str() const + { + return static_cast(_strbuf)->str(); + } + void str(const string& s) + { + clear(); + static_cast(_strbuf)->str(s); + } + + stringbuf* rdbuf() + { + return &__my_sb; + } + protected: + stringstreambase(int which) : + __my_sb(which) + { + init (&__my_sb); + } + + stringstreambase(const string& s, int which) : + __my_sb(s, which) + { + init (&__my_sb); + } + }; + + class istringstream : public stringstreambase, public istream { + public: + istringstream(int which=ios::in) : + stringstreambase(which) + { } + + istringstream(const string& s, int which=ios::in) : + stringstreambase(s, which) + { } + }; + + class ostringstream : public stringstreambase, public ostream { + public: + ostringstream(int which=ios::out) : + stringstreambase(which) + { } + + ostringstream(const string& s, int which=ios::out) : + stringstreambase(s, which) + { } + }; + + class stringstream : public stringstreambase, public iostream { + public: + stringstream(int which=ios::in|ios::out) : + stringstreambase(which) + { } + + stringstream(const string &s, int which=ios::in|ios::out) : + stringstreambase(s, which) + { } + }; +} + +inline int stringbuf::sync() +{ + if((mode & ios::out) == 0) + return EOF; + + streamsize n = pptr() - pbase(); + if(n) + { + buf.replace(rpos, string::npos, pbase(), n); + //if(buf.size() - rpos != n) + if (buf.size() != n + rpos) + return EOF; + rpos += n; + pbump(-n); + gbump(egptr() - gptr()); + } + return 0; +} + +inline int stringbuf::overflow(int ch) +{ + if((mode & ios::out) == 0) + return EOF; + + streamsize n = pptr() - pbase(); + + if(n && sync()) + return EOF; + + if(ch != EOF) + { + string::size_type oldSize = buf.size(); + + buf.replace(rpos, string::npos, 1, ch); + if(buf.size() - oldSize != 1) + return EOF; + ++rpos; + } + return 0; +} + +inline int stringbuf::underflow() +{ + sync(); + if((mode & ios::in) == 0) + { + return EOF; + } + if(rpos >= buf.size()) + { + return EOF; + } + + string::size_type n = egptr() - eback(); + string::size_type s; + + s = buf.copy(eback(), n, rpos); + pbump(pbase() - pptr()); + gbump(eback() - gptr()); + int res = (0377 & buf[rpos]); + rpos += s; + return res; +} + +#endif /* not __STRSTREAM__ */ diff --git a/src/support/syscall.h b/src/support/syscall.h index 0668dd5351..4aa51cece7 100644 --- a/src/support/syscall.h +++ b/src/support/syscall.h @@ -31,10 +31,14 @@ class Systemcalls { public: /// enum Starttype { - System, // Uses system() which uses /bin/sh - SystemDontWait, // Uses system() which uses /bin/sh - Wait, // Uses fork() and execvp() - DontWait // Uses fork() and execvp() + /// Uses system() which uses /bin/sh + System, + /// Uses system() which uses /bin/sh + SystemDontWait, + /// Uses fork() and execvp() + Wait, + /// Uses fork() and execvp() + DontWait }; /// Callback function gets commandline and return value from child @@ -44,27 +48,29 @@ public: Systemcalls(); /** Generate instance and start child process. - The string "what" contains a commandline with arguments separated - by spaces. - When the requested program finishes, the callback-function is - called with the commandline and the return value from the program. - The instance is automatically added to a timer check if starttype - is DontWait (i.e. background execution). When a background child - finishes, the timer check will automatically call the callback - function. - */ + The string "what" contains a commandline with arguments separated + by spaces. + When the requested program finishes, the callback-function is + called with the commandline and the return value from the program. + The instance is automatically added to a timer check if starttype + is DontWait (i.e. background execution). When a background child + finishes, the timer check will automatically call the callback + function. + */ Systemcalls(Starttype how, string const & what, Callbackfct call = 0); /// ~Systemcalls(); /** Start childprocess. "what" contains a command at system level. - * This is for reuse of the Systemcalls instance. - */ + This is for reuse of the Systemcalls instance. + */ int startscript(Starttype how, string const & what, Callbackfct call = 0); - /** gets PID of childprocess. Used by timer */ + /** gets PID of childprocess. + Used by timer + */ pid_t getpid() { return pid; } /// Start callback @@ -74,10 +80,10 @@ public: void setRetValue(int r) { retval = r; } /** Kill child prematurely. - First, a SIGHUP is sent to the child. - If that does not end the child process within "tolerance" - seconds, the SIGKILL signal is sent to the child. - When the child is dead, the callback is called. + First, a SIGHUP is sent to the child. + If that does not end the child process within "tolerance" + seconds, the SIGKILL signal is sent to the child. + When the child is dead, the callback is called. */ void kill(int tolerance = 5); private: diff --git a/src/support/syscontr.h b/src/support/syscontr.h index 5de04c8e65..07437636c3 100644 --- a/src/support/syscontr.h +++ b/src/support/syscontr.h @@ -9,27 +9,42 @@ class Systemcalls; +/// class SystemcallsSingletoncontroller { public: + /// class Startcontroller { public: + /// Startcontroller(); + /// ~Startcontroller(); + /// static SystemcallsSingletoncontroller * getController(); + /// void reduceRefcount() { --refcount; } private: + /// static SystemcallsSingletoncontroller * contr; + /// static int refcount; }; + /// ~SystemcallsSingletoncontroller(); + /// void addCall(Systemcalls const & newcall); + /// void timer(); - // private: // DEC cxx does not like that (JMarc) + /// private: // DEC cxx does not like that (JMarc) SystemcallsSingletoncontroller(); private: + /// struct ControlledCalls { - Systemcalls *call; - ControlledCalls *next; + /// + Systemcalls * call; + /// + ControlledCalls * next; }; + /// ControlledCalls * sysCalls; }; diff --git a/src/support/textutils.h b/src/support/textutils.h index e54a6aedb1..20dd4d7751 100644 --- a/src/support/textutils.h +++ b/src/support/textutils.h @@ -14,28 +14,28 @@ #include -// +/// inline bool IsNewlineChar(char c) { return (c == LyXParagraph::META_NEWLINE); } -// +/// inline bool IsSeparatorChar(char c) { return (c == ' '); } -// +/// inline bool IsHfillChar(char c) { return (c == LyXParagraph::META_HFILL); } -// +/// inline bool IsInsetChar(char c) { return (c == LyXParagraph::META_INSET); @@ -43,7 +43,7 @@ bool IsInsetChar(char c) { #ifndef NEW_INSETS -// +/// inline bool IsFloatChar(char c) { return (c == LyXParagraph::META_FOOTNOTE @@ -57,14 +57,14 @@ bool IsFloatChar(char c) { #endif -// +/// inline bool IsLineSeparatorChar(char c) { return (c == ' '); } -// +/// inline bool IsKommaChar(char c) { return (c == ',' @@ -95,7 +95,7 @@ bool IsKommaChar(char c) { } -// +/// inline bool IsLetterChar(unsigned char c) { return ((c >= 'A' && c <= 'Z') @@ -104,21 +104,21 @@ bool IsLetterChar(unsigned char c) { } -// +/// inline bool IsPrintable(unsigned char c) { return (c >= ' '); } -// +/// inline bool IsPrintableNonspace(unsigned char c) { return (c > ' '); } -// Word is not IsSeparator or IsKomma or IsHfill or IsFloat or IsInset. +/// Word is not IsSeparator or IsKomma or IsHfill or IsFloat or IsInset. inline bool IsWordChar(unsigned char c) { return !( IsSeparatorChar( c ) @@ -131,7 +131,7 @@ bool IsWordChar(unsigned char c) { } -// +/// inline bool IsLetterCharOrDigit(char ch) { diff --git a/src/support/translator.h b/src/support/translator.h index 9e9fb15449..c138391658 100644 --- a/src/support/translator.h +++ b/src/support/translator.h @@ -20,106 +20,121 @@ #include "support/LAssert.h" // Functors used in the template. + +/// template class equal_1st_in_pair { public: - equal_1st_in_pair(T1 const & value) : value_(value) {} - - typedef std::pair pair_type; - bool operator() (pair_type const & p) const { - return p.first == value_; - } + /// + equal_1st_in_pair(T1 const & value) : value_(value) {} + /// + typedef std::pair pair_type; + /// + bool operator() (pair_type const & p) const { + return p.first == value_; + } private: - T1 const & value_; + /// + T1 const & value_; }; + +/// template class equal_2nd_in_pair { public: - equal_2nd_in_pair(T2 const & value) : value_(value) {} - - typedef std::pair pair_type; - bool operator() (pair_type const & p) const { - return p.second == value_; - } + /// + equal_2nd_in_pair(T2 const & value) : value_(value) {} + /// + typedef std::pair pair_type; + /// + bool operator() (pair_type const & p) const { + return p.second == value_; + } private: - T2 const & value_; + /// + T2 const & value_; }; -/** This class template is used to translate between two elements, specifically - * it was worked out to translate between an enum and strings when reading - * the lyx file. - * - * The two template arguments should be of different types. - */ +/** This class template is used to translate between two elements, specifically + it was worked out to translate between an enum and strings when reading + the lyx file. + + The two template arguments should be of different types. +*/ template class Translator { public: - typedef T1 first_argument_type; - typedef T2 second_argument_type; - typedef std::pair MapPair; - typedef std::vector Map; - - /// c-tor. - Translator(T1 const & t1, T2 const & t2) - : default_t1(t1), default_t2(t2) - {} - - /// Add a mapping to the translator. - void addPair(T1 const & first, T2 const & second) { - map.push_back(MapPair(first, second)); - } - - /// Find the mapping for the first argument - T2 const & find(T1 const & first) const { - Assert( ! map.empty()); - - // For explanation see the next find() function. - Map::const_iterator it = - std::find_if(map.begin(), map.end(), - equal_1st_in_pair(first) - ); - - if (it != map.end()) - return (*it).second; - else { - return default_t2; - } - } - - /// Find the mapping for the second argument - T1 const & find(T2 const & second) const { - Assert( ! map.empty()); - - // The idea is as follows: - // find_if() will try to compare the data in the vector with the value. - // The vector is made of pairs and the value has the type of the - // second part of the pair. - // We thus give find_if() an equal_to functor and assign to its second - // post the value we want to compare. We now compose the equal_to - // functor with the select2nd functor to take only the second value - // of the pair to be compared. - // - // We can depict it as follows: - // equal_to( select2nd(pair) , second) - Map::const_iterator it = - std::find_if(map.begin(), map.end(), - equal_2nd_in_pair(second) - ); - - if (it != map.end()) - return (*it).first; - else { - return default_t1; - } - } - + /// + typedef T1 first_argument_type; + /// + typedef T2 second_argument_type; + /// + typedef std::pair MapPair; + /// + typedef std::vector Map; + + /// + Translator(T1 const & t1, T2 const & t2) + : default_t1(t1), default_t2(t2) + {} + + /// Add a mapping to the translator. + void addPair(T1 const & first, T2 const & second) { + map.push_back(MapPair(first, second)); + } + + /// Find the mapping for the first argument + T2 const & find(T1 const & first) const { + Assert(!map.empty()); + + // For explanation see the next find() function. + Map::const_iterator it = + std::find_if(map.begin(), map.end(), + equal_1st_in_pair(first) + ); + + if (it != map.end()) { + return (*it).second; + } else { + return default_t2; + } + } + + /// Find the mapping for the second argument + T1 const & find(T2 const & second) const { + Assert(!map.empty()); + + // The idea is as follows: + // find_if() will try to compare the data in the vector with + // the value. The vector is made of pairs and the value has + // the type of the second part of the pair. + // We thus give find_if() an equal_to functor and assign to + // its second post the value we want to compare. We now + // compose the equal_to functor with the select2nd functor + // to take only the second value of the pair to be compared. + // + // We can depict it as follows: + // equal_to( select2nd(pair) , second) + Map::const_iterator it = + std::find_if(map.begin(), map.end(), + equal_2nd_in_pair(second) + ); + + if (it != map.end()) + return (*it).first; + else { + return default_t1; + } + } private: - Map map; - - T1 const default_t1; - T2 const default_t2; + /// + Map map; + /// + T1 const default_t1; + /// + T2 const default_t2; }; #endif diff --git a/src/table.C b/src/table.C index e9972a7e7b..2ed7027547 100644 --- a/src/table.C +++ b/src/table.C @@ -85,7 +85,7 @@ LyXTable::rowstruct::~rowstruct() } LyXTable::rowstruct & - LyXTable::rowstruct::operator=(rowstruct const & rs) +LyXTable::rowstruct::operator=(rowstruct const & rs) { top_line = rs.top_line; bottom_line = rs.bottom_line; @@ -109,7 +109,7 @@ LyXTable::columnstruct::~columnstruct() } LyXTable::columnstruct & - LyXTable::columnstruct::operator=(columnstruct const & cs) +LyXTable::columnstruct::operator=(columnstruct const & cs) { left_line = cs.left_line; right_line = cs.right_line; diff --git a/src/table.h b/src/table.h index 68b93307c2..27c9b7c9a3 100644 --- a/src/table.h +++ b/src/table.h @@ -170,9 +170,9 @@ public: /// char GetAlignment(int cell); // add approp. signedness /// - string GetPWidth(int cell); + string const GetPWidth(int cell); /// - string GetAlignSpecial(int cell, int what); + string const GetAlignSpecial(int cell, int what); /// int GetWidthOfCell(int cell); diff --git a/src/tabular.C b/src/tabular.C index 8077204d1c..e29f37b40b 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -94,7 +94,7 @@ LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt) { owner_ = inset; Init(lt.rows_, lt.columns_); - +#warning Jürgen, can you make it the other way round. So that copy assignment depends on the copy constructor and not the other way. (Lgb) operator=(lt); } @@ -142,13 +142,10 @@ LyXTabular & LyXTabular::operator=(LyXTabular const & lt) LyXTabular * LyXTabular::Clone(InsetTabular * inset) { LyXTabular * result = new LyXTabular(inset, *this); - /// // don't know if this is good but I need to Clone also // the text-insets here, this is for the Undo-facility! - /// - int i,j; - for(i=0; i < rows_; ++i) { - for(j=0; j < columns_; ++j) { + for(int i = 0; i < rows_; ++i) { + for(int j = 0; j < columns_; ++j) { result->cell_info[i][j].inset = cell_info[i][j].inset; result->cell_info[i][j].inset.setOwner(inset); } @@ -160,8 +157,6 @@ LyXTabular * LyXTabular::Clone(InsetTabular * inset) /* activates all lines and sets all widths to 0 */ void LyXTabular::Init(int rows_arg, int columns_arg) { - int i, j; - int cellno = 0; rows_ = rows_arg; columns_ = columns_arg; @@ -171,20 +166,22 @@ void LyXTabular::Init(int rows_arg, int columns_arg) (rows_, vector(columns_, cellstruct())); // Jürgen, use iterators. - for (i = 0; i < rows_; ++i) { - for (j = 0; j < columns_; ++j) { + int cellno = 0; + int i = 0; + for (; i < rows_; ++i) { + for (int j = 0; j < columns_; ++j) { cell_info[i][j].inset.setOwner(owner_); cell_info[i][j].inset.SetDrawFrame(0, InsetText::LOCKED); cell_info[i][j].cellno = cellno++; } } - row_info[i-1].bottom_line = true; + row_info[i - 1].bottom_line = true; row_info[0].bottom_line = true; for (i = 0; i < columns_; ++i) { calculate_width_of_column(i); } - column_info[columns_-1].right_line = true; + column_info[columns_ - 1].right_line = true; calculate_width_of_tabular(); @@ -221,7 +218,7 @@ void LyXTabular::AppendRow(int cell ) c_info[i][j] = cell_info[i][j]; } } - for(int i = row+1; i < rows_; ++i) { + for(int i = row + 1; i < rows_; ++i) { for(int j = 0; j < columns_; ++j) { c_info[i][j] = cell_info[i-1][j]; } @@ -254,29 +251,28 @@ void LyXTabular::AppendColumn(int cell) cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_, cellstruct())); int column = column_of_cell(cell); - int i, j; column_vector::iterator cit = column_info.begin() + column + 1; column_info.insert(cit, columnstruct()); - for (i = 0; i < rows_; ++i) { - for (j = 0; j <= column; ++j) { + for (int i = 0; i < rows_; ++i) { + for (int j = 0; j <= column; ++j) { c_info[i][j] = cell_info[i][j]; } - for (j = column+1; j < columns_; ++j) { - c_info[i][j] = cell_info[i][j-1]; + for (int j = column + 1; j < columns_; ++j) { + c_info[i][j] = cell_info[i][j - 1]; } // care about multicolumns - if (cell_info[i][column+1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) { - cell_info[i][column+1].multicolumn = CELL_PART_OF_MULTICOLUMN; + if (cell_info[i][column + 1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) { + cell_info[i][column + 1].multicolumn = CELL_PART_OF_MULTICOLUMN; } - if (((column+1) == columns_) || - (cell_info[i][column+2].multicolumn != CELL_PART_OF_MULTICOLUMN)) { - cell_info[i][column+1].multicolumn = LyXTabular::CELL_NORMAL; + if ((column + 1) == columns_ || + cell_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN) { + cell_info[i][column + 1].multicolumn = LyXTabular::CELL_NORMAL; } } cell_info = c_info; ++column; - for (i = 0; i < rows_; ++i) { + for (int i = 0; i < rows_; ++i) { cell_info[i][column].inset.clear(); } Reinit(); @@ -298,19 +294,15 @@ void LyXTabular::DeleteColumn(int column) void LyXTabular::Reinit() { - int j; - - int i = 0; - // Jürgen, use iterators. - for (; i < rows_; ++i) { - for (j = 0; j < columns_; ++j) { + for (int i = 0; i < rows_; ++i) { + for (int j = 0; j < columns_; ++j) { cell_info[i][j].width_of_cell = 0; cell_info[i][j].inset.setOwner(owner_); } } - for (i = 0; i < columns_; ++i) { + for (int i = 0; i < columns_; ++i) { calculate_width_of_column(i); } calculate_width_of_tabular(); @@ -474,9 +466,8 @@ int LyXTabular::GetAdditionalHeight(int cell) const int top = 1; // bool top = true; ?? int bottom = 1; // bool bottom = true; ?? - int column; - for (column = 0; column < columns_ - 1 && bottom; ++column) { + for (int column = 0; column < columns_ - 1 && bottom; ++column) { switch (cell_info[row - 1][column].multicolumn) { case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN: bottom = cell_info[row - 1][column].bottom_line; @@ -485,7 +476,7 @@ int LyXTabular::GetAdditionalHeight(int cell) const bottom = row_info[row - 1].bottom_line; } } - for (column = 0; column < columns_ - 1 && top; ++column) { + for (int column = 0; column < columns_ - 1 && top; ++column) { switch (cell_info[row][column].multicolumn){ case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN: top = cell_info[row][column].top_line; @@ -516,8 +507,8 @@ int LyXTabular::GetAdditionalWidth(int cell) const // returns the maximum over all rows int LyXTabular::GetWidthOfColumn(int cell) const { - int column1 = column_of_cell(cell); - int column2 = right_column_of_cell(cell); + int const column1 = column_of_cell(cell); + int const column2 = right_column_of_cell(cell); int result = 0; int i = column1; for (; i <= column2; ++i) { @@ -539,9 +530,9 @@ bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width) if (!IsMultiColumn(cell)) return false; - int row = row_of_cell(cell); - int column1 = column_of_cell(cell); - int column2 = right_column_of_cell(cell); + int const row = row_of_cell(cell); + int const column1 = column_of_cell(cell); + int const column2 = right_column_of_cell(cell); // first set columns to 0 so we can calculate the right width int i = column1; @@ -565,9 +556,9 @@ bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width) void LyXTabular::recalculateMulticolCells(int cell, int new_width) { - int row = row_of_cell(cell); - int column1 = column_of_cell(cell); - int column2 = right_column_of_cell(cell); + int const row = row_of_cell(cell); + int const column1 = column_of_cell(cell); + int const column2 = right_column_of_cell(cell); // first set columns to 0 so we can calculate the right width int i = column1; @@ -584,8 +575,8 @@ void LyXTabular::recalculateMulticolCells(int cell, int new_width) /* returns 1 if a complete update is necessary, otherwise 0 */ bool LyXTabular::SetWidthOfCell(int cell, int new_width) { - int row = row_of_cell(cell); - int column1 = column_of_cell(cell); + int const row = row_of_cell(cell); + int const column1 = column_of_cell(cell); bool tmp = false; int width = 0; @@ -602,14 +593,14 @@ bool LyXTabular::SetWidthOfCell(int cell, int new_width) tmp = calculate_width_of_column_NMC(column1); } if (tmp) { - int i; - for(i = 0; iSetAutoBreakRows(flag); } @@ -658,7 +648,7 @@ bool LyXTabular::SetColumnPWidth(int cell, string const & width) bool LyXTabular::SetMColumnPWidth(int cell, string const & width) { - bool flag = !width.empty(); + bool const flag = !width.empty(); cellinfo_of_cell(cell)->p_width = width; if (IsMultiColumn(cell)) { @@ -691,7 +681,7 @@ bool LyXTabular::SetAllLines(int cell, bool line) bool LyXTabular::SetTopLine(int cell, bool line, bool onlycolumn) { - int row = row_of_cell(cell); + int const row = row_of_cell(cell); if (onlycolumn || !IsMultiColumn(cell)) row_info[row].top_line = line; @@ -749,7 +739,7 @@ char LyXTabular::GetVAlignment(int cell, bool onlycolumn) const } -string LyXTabular::GetPWidth(int cell) const +string const LyXTabular::GetPWidth(int cell) const { if (IsMultiColumn(cell)) return cellinfo_of_cell(cell)->p_width; @@ -757,13 +747,13 @@ string LyXTabular::GetPWidth(int cell) const } -string LyXTabular::GetColumnPWidth(int cell) const +string const LyXTabular::GetColumnPWidth(int cell) const { return column_info[column_of_cell(cell)].p_width; } -string LyXTabular::GetMColumnPWidth(int cell) const +string const LyXTabular::GetMColumnPWidth(int cell) const { if (IsMultiColumn(cell)) return cellinfo_of_cell(cell)->p_width; @@ -771,7 +761,7 @@ string LyXTabular::GetMColumnPWidth(int cell) const } -string LyXTabular::GetAlignSpecial(int cell, int what) const +string const LyXTabular::GetAlignSpecial(int cell, int what) const { if (what == SET_SPECIAL_MULTI) return cellinfo_of_cell(cell)->align_special; @@ -781,12 +771,11 @@ string LyXTabular::GetAlignSpecial(int cell, int what) const int LyXTabular::GetWidthOfCell(int cell) const { - int row = row_of_cell(cell); - int column1 = column_of_cell(cell); - int column2 = right_column_of_cell(cell); + int const row = row_of_cell(cell); + int const column1 = column_of_cell(cell); + int const column2 = right_column_of_cell(cell); int result = 0; - int i = column1; - for (; i <= column2; ++i) { + for (int i = column1; i <= column2; ++i) { result += cell_info[row][i].width_of_cell; } return result; @@ -843,7 +832,7 @@ int LyXTabular::GetLastCellInRow(int row) const bool LyXTabular::calculate_width_of_column(int column) { - int old_column_width = column_info[column].width_of_column; + int const old_column_width = column_info[column].width_of_column; int maximum = 0; for (int i = 0; i < rows_; ++i) { @@ -854,13 +843,13 @@ bool LyXTabular::calculate_width_of_column(int column) } -/// -/// calculate the with of the column without regarding REAL MultiColumn -/// cells. This means MultiColumn-cells spanning more than 1 column. -/// +// +// calculate the with of the column without regarding REAL MultiColumn +// cells. This means MultiColumn-cells spanning more than 1 column. +// bool LyXTabular::calculate_width_of_column_NMC(int column) { - int old_column_width = column_info[column].width_of_column; + int const old_column_width = column_info[column].width_of_column; int max = 0; for (int i = 0; i < rows_; ++i) { if (!IsMultiColumn(GetCellNumber(i, column), true) && @@ -904,7 +893,7 @@ int LyXTabular::column_of_cell(int cell) const int LyXTabular::right_column_of_cell(int cell) const { - int row = row_of_cell(cell); + int const row = row_of_cell(cell); int column = column_of_cell(cell); while (column < (columns_ - 1) && cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN) @@ -915,8 +904,6 @@ int LyXTabular::right_column_of_cell(int cell) const void LyXTabular::Write(Buffer const * buf, ostream & os) const { - int i, j; - // header line os << "" << endl; @@ -926,12 +913,12 @@ void LyXTabular::Write(Buffer const * buf, ostream & os) const " endhead=" << endhead << " endfirsthead=" << endfirsthead << " endfoot=" << endfoot << " endlastfoot=" << endlastfoot << ">" << endl << endl; - for (i = 0; i < rows_; ++i) { + for (int i = 0; i < rows_; ++i) { os << "" << endl; - for (j = 0; j < columns_; ++j) { + for (int j = 0; j < columns_; ++j) { if (!i) { os << "align_special.empty()) { - return cellinfo_of_cell(cell)->align_special.c_str(); + return cellinfo_of_cell(cell)->align_special; } else { switch (GetAlignment(cell)) { case LYX_ALIGN_LEFT: @@ -1374,7 +1362,7 @@ char const * LyXTabular::GetDocBookAlign(int cell, bool isColumn) const } } else { if (!column_info[i].align_special.empty()) { - return column_info[i].align_special.c_str(); + return column_info[i].align_special; } #ifdef IGNORE_THIS_FOR_NOW else if (!column_info[i].p_width.empty()) { @@ -1715,8 +1703,8 @@ int LyXTabular::GetUsebox(int cell) const void LyXTabular::SetLTHead(int cell, bool first) { - int row = row_of_cell(cell); - int val = (row+1) * (column_of_cell(cell)? 1:-1); + int const row = row_of_cell(cell); + int const val = (row+1) * (column_of_cell(cell)? 1:-1); if (first) { if (endfirsthead == val) @@ -1752,8 +1740,8 @@ bool LyXTabular::GetRowOfLTFirstHead(int cell, int & row) const void LyXTabular::SetLTFoot(int cell, bool last) { - int row = row_of_cell(cell); - int val = (row + 1) * (column_of_cell(cell)? 1:-1); + int const row = row_of_cell(cell); + int const val = (row + 1) * (column_of_cell(cell)? 1:-1); if (last) { if (endlastfoot == val) @@ -1777,6 +1765,7 @@ bool LyXTabular::GetRowOfLTFoot(int cell, int & row) const return (row_of_cell(cell) == (abs(endfoot)-1)); } + bool LyXTabular::GetRowOfLTLastFoot(int cell, int & row) const { row = endlastfoot; @@ -1885,19 +1874,18 @@ int LyXTabular::TeXTopHLine(ostream & os, int row) const int LyXTabular::TeXBottomHLine(ostream & os, int row) const { - int fcell = GetFirstCellInRow(row); - int n = NumberOfCellsInRow(fcell) + fcell; + int const fcell = GetFirstCellInRow(row); + int const n = NumberOfCellsInRow(fcell) + fcell; int tmp = 0; - int i; - for (i = fcell; i < n; ++i) { + for (int i = fcell; i < n; ++i) { if (BottomLine(i)) ++tmp; } if (tmp == (n-fcell)){ os << "\\hline"; } else { - for (i = fcell; i < n; ++i) { + for (int i = fcell; i < n; ++i) { if (BottomLine(i)) { os << "\\cline{" << column_of_cell(i) + 1 @@ -2020,8 +2008,10 @@ int LyXTabular::TeXCellPostamble(ostream & os, int cell) const } -int LyXTabular::Latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const +int LyXTabular::Latex(Buffer const * buf, + ostream & os, bool fragile, bool fp) const { +#warning Jürgen, this func should be split into more funcs (Lgb) int ret = 0; int i,j; int cell = 0; @@ -2171,6 +2161,7 @@ InsetText * LyXTabular::GetCellInset(int cell) const return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset; } + void LyXTabular::Validate(LaTeXFeatures & features) const { if (IsLongTabular()) diff --git a/src/tabular.h b/src/tabular.h index fb7a56f98e..3035110f62 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -232,13 +232,13 @@ public: /// char GetVAlignment(int cell, bool onlycolumn = false) const; /// - string GetPWidth(int cell) const; + string const GetPWidth(int cell) const; /// - string GetColumnPWidth(int cell) const; + string const GetColumnPWidth(int cell) const; /// - string GetMColumnPWidth(int cell) const; + string const GetMColumnPWidth(int cell) const; /// - string GetAlignSpecial(int cell, int what) const; + string const GetAlignSpecial(int cell, int what) const; /// int GetWidthOfCell(int cell) const; /// @@ -288,7 +288,7 @@ public: int RoffEndOfCell(std::ostream &, int cell); #endif /// - char const * GetDocBookAlign(int cell, bool isColumn = false) const; + string const GetDocBookAlign(int cell, bool isColumn = false) const; /// bool IsMultiColumn(int cell, bool real = false) const; @@ -485,6 +485,7 @@ private: ////////////////////////////////////////////////////////////////// void set_row_column_number_info(); /// Returns true if a complete update is necessary, otherwise false bool SetWidthOfMulticolCell(int cell, int new_width); + /// void recalculateMulticolCells(int cell, int new_width); /// Returns true if change bool calculate_width_of_column(int column); diff --git a/src/tex-accent.h b/src/tex-accent.h index 841829b056..daf4314773 100644 --- a/src/tex-accent.h +++ b/src/tex-accent.h @@ -97,11 +97,11 @@ struct tex_accent_struct { /// tex_accent accent; /// - char const *cmd; + char const * cmd; /// - char const *native; + char const * native; /// - char const *name; + char const * name; /// kb_action action; }; diff --git a/src/tex-strings.h b/src/tex-strings.h index 486f372eab..8d06300fdf 100644 --- a/src/tex-strings.h +++ b/src/tex-strings.h @@ -37,9 +37,6 @@ extern char const * string_align[]; // used all over. As it happens, that meant that these strings were included // 27 times in the object file. (Asger) -// -// extern char const * tex_babel[]; - /// extern char const * tex_graphics[]; diff --git a/src/text.C b/src/text.C index d9bc6e6c98..b20ec72f7a 100644 --- a/src/text.C +++ b/src/text.C @@ -3266,7 +3266,8 @@ bool LyXText::SelectWordWhenUnderCursor(BufferView * bview) // This function is only used by the spellchecker for NextWord(). // It doesn't handle LYX_ACCENTs and probably never will. -char * LyXText::SelectNextWord(BufferView * bview, float & value) +string const LyXText::SelectNextWord(BufferView * bview, + float & value) const { LyXParagraph * tmppar = cursor.par(); @@ -3301,11 +3302,11 @@ char * LyXText::SelectNextWord(BufferView * bview, float & value) // Start the selection from here sel_cursor = cursor; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream latex; -#else - ostrstream latex; -#endif +//#else +// ostrstream latex; +//#endif // and find the end of the word // (optional hyphens are part of a word) while (cursor.pos() < cursor.par()->Last() @@ -3313,29 +3314,26 @@ char * LyXText::SelectNextWord(BufferView * bview, float & value) || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET && cursor.par()->GetInset(cursor.pos()) != 0 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0 -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM && latex.str() == "\\-" -#else - && latex.str() // protect against null pointers - && string(latex.str(), 3) == "\\-" // this is not nice at all -#endif +//#else +// && latex.str() // protect against null pointers +// && string(latex.str(), 3) == "\\-" // this is not nice at all +//#endif )) cursor.pos(cursor.pos() + 1); -#ifndef HAVE_SSTREAM - delete [] latex.str(); -#endif +//#ifndef HAVE_SSTREAM +// delete [] latex.str(); +//#endif // Finally, we copy the word to a string and return it - char * str = 0; - + string str; if (sel_cursor.pos() < cursor.pos()) { - str = new char [cursor.pos() - sel_cursor.pos() + 2]; - LyXParagraph::size_type i, j; - for (i = sel_cursor.pos(), j = 0; i < cursor.pos(); ++i) { + LyXParagraph::size_type i; + for (i = sel_cursor.pos(); i < cursor.pos(); ++i) { if (cursor.par()->GetChar(i) != LyXParagraph::META_INSET) - str[j++] = cursor.par()->GetChar(i); + str += cursor.par()->GetChar(i); } - str[j] = '\0'; } return str; } @@ -3350,11 +3348,11 @@ void LyXText::SelectSelectedWord(BufferView * bview) // set the sel cursor sel_cursor = cursor; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream latex; -#else - ostrstream latex; -#endif +//#else +// ostrstream latex; +//#endif // now find the end of the word while (cursor.pos() < cursor.par()->Last() @@ -3362,17 +3360,17 @@ void LyXText::SelectSelectedWord(BufferView * bview) || (cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET && cursor.par()->GetInset(cursor.pos()) != 0 && cursor.par()->GetInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0 -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM && latex.str() == "\\-" -#else - && string(latex.str(), 3) == "\\-" -#endif +//#else +// && string(latex.str(), 3) == "\\-" +//#endif ))) cursor.pos(cursor.pos() + 1); -#ifndef HAVE_SSTREAM - delete [] latex.str(); -#endif +//#ifndef HAVE_SSTREAM +// delete [] latex.str(); +//#endif SetCursor(bview, cursor.par(), cursor.pos()); // finally set the selection diff --git a/src/text2.C b/src/text2.C index f2d5876271..a1ca4733e3 100644 --- a/src/text2.C +++ b/src/text2.C @@ -172,7 +172,7 @@ LyXText::~LyXText() // smaller. (Asger) // If position is -1, we get the layout font of the paragraph. // If position is -2, we get the font of the manual label of the paragraph. -LyXFont LyXText::GetFont(Buffer const * buf, LyXParagraph * par, +LyXFont const LyXText::GetFont(Buffer const * buf, LyXParagraph * par, LyXParagraph::size_type pos) const { LyXLayout const & layout = @@ -190,11 +190,14 @@ LyXFont LyXText::GetFont(Buffer const * buf, LyXParagraph * par, if (layout.labeltype == LABEL_MANUAL && pos < BeginningOfMainBody(buf, par)) { // 1% goes here - return par->GetFontSettings(buf->params, pos). - realize(layout.reslabelfont); - } else - return par->GetFontSettings(buf->params, pos). - realize(layout.resfont); + LyXFont f = par->GetFontSettings(buf->params, + pos); + return f.realize(layout.reslabelfont); + } else { + LyXFont f = par->GetFontSettings(buf->params, pos); + return f.realize(layout.resfont); + } + } else { // 5% goes here. // process layoutfont for pos == -1 and labelfont for pos < -1 @@ -1161,7 +1164,7 @@ void LyXText::SetSelection() } -string LyXText::selectionAsString(Buffer const * buffer) const +string const LyXText::selectionAsString(Buffer const * buffer) const { if (!selection) return string(); string result; @@ -1542,8 +1545,8 @@ void LyXText::SetParagraph(BufferView * bview, void LyXText::SetParagraphExtraOpt(BufferView * bview, int type, - char const * width, - char const * widthp, + string const & width, + string const & widthp, int alignment, bool hfill, bool start_minipage) { @@ -1661,8 +1664,8 @@ char hebrewCounter(int n) } -static -char const * romanCounter(int n) +static inline +string const romanCounter(int n) { static char const * roman[20] = { "i", "ii", "iii", "iv", "v", @@ -1829,11 +1832,11 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const par->labelstring.erase(); } -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream s; -#else - ostrstream s; -#endif +//#else +// ostrstream s; +//#endif if (!par->appendix) { switch (2 * LABEL_COUNTER_CHAPTER - textclass.maxcounter() + i) { @@ -1956,16 +1959,16 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const break; } } -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM par->labelstring += s.str().c_str(); // We really want to remove the c_str as soon as // possible... -#else - s << '\0'; - char * tmps = s.str(); - par->labelstring += tmps; - delete [] tmps; -#endif +//#else +// s << '\0'; +// char * tmps = s.str(); +// par->labelstring += tmps; +// delete [] tmps; +//#endif for (i++; i < 10; ++i) { // reset the following counters @@ -1980,11 +1983,11 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const par->incCounter(i + par->enumdepth); int number = par->getCounter(i + par->enumdepth); -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream s; -#else - ostrstream s; -#endif +//#else +// ostrstream s; +//#endif switch (par->enumdepth) { case 1: if (par->isRightToLeftPar(buf->params)) @@ -2017,15 +2020,15 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const s << number << '.'; break; } -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM par->labelstring = s.str().c_str(); // we really want to get rid of that c_str() -#else - s << '\0'; - char * tmps = s.str(); - par->labelstring = tmps; - delete [] tmps; -#endif +//#else +// s << '\0'; +// char * tmps = s.str(); +// par->labelstring = tmps; +// delete [] tmps; +//#endif for (i += par->enumdepth + 1; i < 10; ++i) par->setCounter(i, 0); /* reset the following counters */ @@ -2428,15 +2431,15 @@ LyXParagraph * LyXText::FirstParagraph() const // returns true if the specified string is at the specified position bool LyXText::IsStringInText(LyXParagraph * par, LyXParagraph::size_type pos, - char const * str) const + string const & str) const { if (par) { - int i = 0; - while (pos + i < par->Last() && str[i] && + unsigned int i = 0; + while (pos + i < par->Last() && i < str.length()&& str[i] == par->GetChar(pos + i)) { ++i; } - if (!str[i]) + if (str.length() == i) return true; } return false; @@ -2444,17 +2447,18 @@ bool LyXText::IsStringInText(LyXParagraph * par, // sets the selection over the number of characters of string, no check!! -void LyXText::SetSelectionOverString(BufferView * bview, char const * string) +void LyXText::SetSelectionOverString(BufferView * bview, string const & str) { sel_cursor = cursor; - for (int i = 0; string[i]; ++i) + for (int i = 0; str[i]; ++i) CursorRight(bview); SetSelection(); } // simple replacing. The font of the first selected character is used -void LyXText::ReplaceSelectionWithString(BufferView * bview, char const * str) +void LyXText::ReplaceSelectionWithString(BufferView * bview, + string const & str) { SetCursorParUndo(bview->buffer()); FreezeUndo(); @@ -2466,15 +2470,16 @@ void LyXText::ReplaceSelectionWithString(BufferView * bview, char const * str) // Get font setting before we cut LyXParagraph::size_type pos = sel_end_cursor.pos(); - LyXFont font = sel_start_cursor.par()->GetFontSettings(bview->buffer()->params, - sel_start_cursor.pos()); + LyXFont const font = sel_start_cursor.par() + ->GetFontSettings(bview->buffer()->params, + sel_start_cursor.pos()); // Insert the new string - for (int i = 0; str[i]; ++i) { - sel_end_cursor.par()->InsertChar(pos, str[i], font); + for (string::const_iterator cit = str.begin(); cit != str.end(); ++cit) { + sel_end_cursor.par()->InsertChar(pos, (*cit), font); ++pos; } - + // Cut the selection CutSelection(bview); @@ -2484,7 +2489,7 @@ void LyXText::ReplaceSelectionWithString(BufferView * bview, char const * str) // if the string can be found: return true and set the cursor to // the new position -bool LyXText::SearchForward(BufferView * bview, char const * str) const +bool LyXText::SearchForward(BufferView * bview, string const & str) const { LyXParagraph * par = cursor.par(); LyXParagraph::size_type pos = cursor.pos(); @@ -2505,7 +2510,7 @@ bool LyXText::SearchForward(BufferView * bview, char const * str) const } -bool LyXText::SearchBackward(BufferView * bview, char const * string) const +bool LyXText::SearchBackward(BufferView * bview, string const & str) const { LyXParagraph * par = cursor.par(); int pos = cursor.pos(); @@ -2521,7 +2526,7 @@ bool LyXText::SearchBackward(BufferView * bview, char const * string) const pos = par->Last() - 1; } while (par && pos < 0); } - } while (par && !IsStringInText(par, pos, string)); + } while (par && !IsStringInText(par, pos, str)); if (par) { SetCursor(bview, par, pos); diff --git a/src/trans.C b/src/trans.C index 066694fc2b..52d7a26cd4 100644 --- a/src/trans.C +++ b/src/trans.C @@ -35,7 +35,7 @@ DefaultTrans::DefaultTrans() } -string DefaultTrans::process(char c, TransManager & k) +string const DefaultTrans::process(char c, TransManager & k) { char dummy[2] = "?"; dummy[0] = c; @@ -49,9 +49,6 @@ string DefaultTrans::process(char c, TransManager & k) Trans::Trans() { int i = 0; - for(; i < 256; ++i) - keymap_[i] = 0; - for(i = 0; i < TEX_MAX_ACCENT + 1; ++i) kmod_list_[i] = 0; } @@ -91,13 +88,12 @@ void Trans::FreeException(Trans::keyexc & exclist) void Trans::FreeKeymap() { - int i = 0; - for(; i < 256; ++i) - if (keymap_[i]) { - delete keymap_[i]; - keymap_[i] = 0; + for(int i = 0; i < 256; ++i) + if (!keymap_[i].empty()) { + //delete keymap_[i]; + keymap_[i].erase(); } - for(i = 0; i < TEX_MAX_ACCENT + 1; ++i) + for(int i = 0; i < TEX_MAX_ACCENT + 1; ++i) if (kmod_list_[i]) { FreeException(kmod_list_[i]->exception_list); delete kmod_list_[i]; @@ -106,13 +102,13 @@ void Trans::FreeKeymap() } -bool Trans::IsDefined() +bool Trans::IsDefined() const { return !name_.empty(); } -string const & Trans::GetName() +string const & Trans::GetName() const { return name_; } @@ -157,10 +153,9 @@ void Trans::AddDeadkey(tex_accent accent, string const & keys, } for(string::size_type i = 0; i < keys.length(); ++i) { - char * temp = - keymap_[static_cast(keys[i])] = - new char[2]; - temp[0] = 0; temp[1] = accent; + string * temp = + &keymap_[static_cast(keys[i])]; + (*temp)[0] = 0; (*temp)[1] = accent; } kmod_list_[accent]->exception_list = 0; } @@ -210,7 +205,7 @@ int Trans::Load(LyXLex & lex) break; } case KCOMB: { - char const * str; + string str; lyxerr[Debug::KBMAP] << "KCOMB:" << endl; if (lex.next(true)) { @@ -239,7 +234,8 @@ int Trans::Load(LyXLex & lex) // check about accent_1 also int key = 0; for(; key < 256; ++key) { - if (keymap_[key] && keymap_[key][0] == 0 + if (!keymap_[key].empty() + && keymap_[key][0] == 0 && keymap_[key][1] == accent_2) break; } @@ -271,9 +267,9 @@ int Trans::Load(LyXLex & lex) return -1; if (lex.next(true)) { - char const * t = lex.text(); - char * string_to = - strcpy(new char[strlen(t)+1], t); + string string_to = lex.text(); + //char * string_to = + // strcpy(new char[strlen(t)+1], t); keymap_[key_from] = string_to; if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "\t`" << string_to << "'" @@ -286,7 +282,7 @@ int Trans::Load(LyXLex & lex) case KXMOD: { tex_accent accent; char key; - char const * str; + string str; if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "KXMOD:\t" << lex.text() << endl; @@ -331,9 +327,9 @@ int Trans::Load(LyXLex & lex) } -bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) +bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) const { - if (kmod_list_[accent]!= 0) { + if (kmod_list_[accent] != 0) { i = *kmod_list_[accent]; return true; } @@ -341,13 +337,17 @@ bool Trans::isAccentDefined(tex_accent accent, KmodInfo & i) } -string Trans::process(char c, TransManager & k) +string const Trans::process(char c, TransManager & k) { - char dummy[2] = "?"; - char * dt = dummy; - char * t = Match(static_cast(c)); - - if ((t == 0 && (*dt = c)) || (t[0] != 0 && (dt = t)) ){ + string dummy("?"); + string dt = dummy; + string const t = Match(static_cast(c)); + + if (t.empty() && c != 0) { + dt[0] = c; + return k.normalkey(c, dt); + } else if (!t.empty()) { + dt = t; return k.normalkey(c, dt); } else { return k.deadkey(c, diff --git a/src/trans.h b/src/trans.h index 9c9f4e2731..720a6b425d 100644 --- a/src/trans.h +++ b/src/trans.h @@ -22,9 +22,9 @@ class TransManager; class TransInterface { public: /// - virtual string process(char, TransManager &) = 0; + virtual string const process(char, TransManager &) = 0; /// - virtual bool isAccentDefined(tex_accent, KmodInfo &) = 0; + virtual bool isAccentDefined(tex_accent, KmodInfo &) const = 0; }; /** @@ -36,7 +36,7 @@ public: /// DefaultTrans(); /// - virtual string process(char, TransManager &); + virtual string const process(char, TransManager &); private: /// static bool init_; @@ -56,13 +56,13 @@ public: /// int Load(string const & language); /// - bool IsDefined(); + bool IsDefined() const; /// - string const & GetName(); + string const & GetName() const; /// - string process(char, TransManager &); + string const process(char, TransManager &); /// - bool isAccentDefined(tex_accent, KmodInfo &); + bool isAccentDefined(tex_accent, KmodInfo &) const; private: /// @@ -77,7 +77,7 @@ private: /// int Load(LyXLex &); /// - inline char * Match(unsigned char c); + inline string const & Match(unsigned char c); /// void InsertException(keyexc & exclist, char c, string const & data, bool = false, @@ -88,7 +88,7 @@ private: /// string name_; /// - char * keymap_[256]; + string keymap_[256]; /// kmod_list_decl * kmod_list_[TEX_MAX_ACCENT+1]; @@ -96,7 +96,7 @@ private: /// -char * Trans::Match(unsigned char c) +string const & Trans::Match(unsigned char c) { return keymap_[c]; } diff --git a/src/trans_mgr.C b/src/trans_mgr.C index eea9e01464..e6fea7a4f3 100644 --- a/src/trans_mgr.C +++ b/src/trans_mgr.C @@ -19,8 +19,8 @@ using std::endl; using std::pair; -extern string DoAccent(string const &, tex_accent); -extern string DoAccent(char, tex_accent); +extern string const DoAccent(string const &, tex_accent); +extern string const DoAccent(char, tex_accent); extern BufferView * current_view; @@ -44,17 +44,17 @@ TransInitState::TransInitState() } -string TransInitState::normalkey(char c, char * t) +string const TransInitState::normalkey(char c, string const & t) { string res; - if (t) res = t; + if (!t.empty()) res = t; else res = c; return res; } -string TransInitState::deadkey(char c, KmodInfo d) +string const TransInitState::deadkey(char c, KmodInfo d) { deadkey_ = c; deadkey_info_ = d; @@ -70,7 +70,7 @@ TransDeadkeyState::TransDeadkeyState() } -string TransDeadkeyState::normalkey(char c, char * trans) +string const TransDeadkeyState::normalkey(char c, string const & trans) { string res; @@ -100,7 +100,7 @@ string TransDeadkeyState::normalkey(char c, char * trans) } -string TransDeadkeyState::deadkey(char c, KmodInfo d) +string const TransDeadkeyState::deadkey(char c, KmodInfo d) { string res; @@ -153,7 +153,7 @@ TransCombinedState::TransCombinedState() } -string TransCombinedState::normalkey(char c, char * trans) +string const TransCombinedState::normalkey(char c, string const & trans) { string res; @@ -177,7 +177,7 @@ string TransCombinedState::normalkey(char c, char * trans) } -string TransCombinedState::deadkey(char c, KmodInfo d) +string const TransCombinedState::deadkey(char c, KmodInfo d) { // Third key in a row. Output the first one and // reenter with shifted deadkeys @@ -238,9 +238,9 @@ int TransManager::SetSecondary(string const & language) } -bool TransManager::setCharset(char const * set) +bool TransManager::setCharset(string const & str) { - return chset_.loadFile(set); + return chset_.loadFile(str); } diff --git a/src/trans_mgr.h b/src/trans_mgr.h index f3abf31c13..e45bf55ada 100644 --- a/src/trans_mgr.h +++ b/src/trans_mgr.h @@ -20,11 +20,11 @@ public: /// virtual ~TransState() {} /// - virtual string normalkey(char, char *) = 0; + virtual string const normalkey(char, string const &) = 0; /// virtual bool backspace() = 0; /// - virtual string deadkey(char, KmodInfo) = 0; + virtual string const deadkey(char, KmodInfo) = 0; /// static char const TOKEN_SEP; }; @@ -66,11 +66,11 @@ public: /// TransInitState(); /// - virtual string normalkey(char, char *); + virtual string const normalkey(char, string const &); /// virtual bool backspace() { return true; } /// - virtual string deadkey(char, KmodInfo); + virtual string const deadkey(char, KmodInfo); }; @@ -80,14 +80,14 @@ public: /// TransDeadkeyState(); /// - virtual string normalkey(char, char *); + virtual string const normalkey(char, string const &); /// virtual bool backspace() { currentState = init_state_; return false; } /// - virtual string deadkey(char, KmodInfo); + virtual string const deadkey(char, KmodInfo); }; @@ -97,7 +97,7 @@ public: /// TransCombinedState(); /// - virtual string normalkey(char, char *); + virtual string const normalkey(char, string const &); /// virtual bool backspace() { // cancel the second deadkey @@ -108,7 +108,7 @@ public: return false; } /// - virtual string deadkey(char, KmodInfo); + virtual string const deadkey(char, KmodInfo); }; @@ -158,7 +158,7 @@ public: /// void DisableKeymap(); /// - bool setCharset(const char *); + bool setCharset(string const &); /// bool backspace() { return trans_fsm_.currentState->backspace(); @@ -166,21 +166,21 @@ public: /// void TranslateAndInsert(char, LyXText *); /// - inline string deadkey(char, KmodInfo); + inline string const deadkey(char, KmodInfo); /// - inline string normalkey(char, char *); + inline string const normalkey(char, string const &); /// void deadkey(char, tex_accent, LyXText *); }; -string TransManager::normalkey(char c, char * t) +string const TransManager::normalkey(char c, string const & t) { return trans_fsm_.currentState->normalkey(c, t); } -string TransManager::deadkey(char c, KmodInfo t) +string const TransManager::deadkey(char c, KmodInfo t) { return trans_fsm_.currentState->deadkey(c, t); } diff --git a/src/vc-backend.C b/src/vc-backend.C index 3b4ef26a23..48f0d341b9 100644 --- a/src/vc-backend.C +++ b/src/vc-backend.C @@ -37,7 +37,7 @@ RCS::RCS(string const & m) } -string RCS::find_file(string const & file) +string const RCS::find_file(string const & file) { string tmp(file); // Check if *,v exists. @@ -200,7 +200,7 @@ CVS::CVS(string const & m, string const & f) } -string CVS::find_file(string const & file) +string const CVS::find_file(string const & file) { // First we look for the CVS/Entries in the same dir // where we have file. diff --git a/src/vc-backend.h b/src/vc-backend.h index 0e8652763b..bd54e89484 100644 --- a/src/vc-backend.h +++ b/src/vc-backend.h @@ -79,7 +79,7 @@ public: explicit RCS(string const & m); /// - static string find_file(string const & file); + static string const find_file(string const & file); /// static void retrive(string const & file); /// @@ -106,7 +106,7 @@ public: explicit CVS(string const & m, string const & f); /// - static string find_file(string const & file); + static string const find_file(string const & file); /// virtual void scanMaster(); /// diff --git a/src/vspace.C b/src/vspace.C index 312753288b..e82588473e 100644 --- a/src/vspace.C +++ b/src/vspace.C @@ -55,52 +55,48 @@ int number_index, unit_index; static inline -void lyx_advance (string & data, unsigned int n) +void lyx_advance(string & data, unsigned int n) { data.erase(0, n); } static inline -bool isEndOfData (string const & data) +bool isEndOfData(string const & data) { - return frontStrip (data).empty(); + return frontStrip(data).empty(); } static -char nextToken (string & data) +char nextToken(string & data) { data = frontStrip(data); if (data.empty()) return '\0'; else if (data[0] == '+') { - lyx_advance (data, 1); + lyx_advance(data, 1); return '+'; - } - else if (prefixIs(data, "plus")) { - lyx_advance (data, 4); + } else if (prefixIs(data, "plus")) { + lyx_advance(data, 4); return '+'; - } - else if (data[0] == '-') { - lyx_advance (data, 1); + } else if (data[0] == '-') { + lyx_advance(data, 1); return '-'; - } - else if (prefixIs(data, "minus")) { - lyx_advance (data, 5); + } else if (prefixIs(data, "minus")) { + lyx_advance(data, 5); return '-'; - } - else { + } else { string::size_type i; // I really mean assignment ("=") below, not equality! if ((i = data.find_last_of("0123456789.")) != string::npos) { if (number_index > 3) return 'E'; // Error - string buffer = data.substr(0, i + 1).c_str(); + string buffer = data.substr(0, i + 1); double x = strToDbl(buffer); if (x || (buffer[0] == '0')) { number[number_index] = x; - lyx_advance (data, i + 1); + lyx_advance(data, i + 1); ++number_index; return 'n'; } else @@ -109,9 +105,9 @@ char nextToken (string & data) != string::npos) { if (unit_index > 3) return 'E'; // Error string buffer = data.substr(0, i + 1); - unit[unit_index] = unitFromString (buffer); + unit[unit_index] = unitFromString(buffer); if (unit[unit_index] != LyXLength::UNIT_NONE) { - lyx_advance (data, i + 1); + lyx_advance(data, i + 1); ++unit_index; return 'u'; } else @@ -230,7 +226,7 @@ bool isValidLength(string const & data, LyXLength * result) /// glue, but since we already have it, using it is /// easier than writing something from scratch. - string buffer = data; + string buffer(data); int pattern_index = 0; char pattern[3]; @@ -290,18 +286,18 @@ LyXLength::LyXLength(string const & data) } -string LyXLength::asString() const +string const LyXLength::asString() const { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream buffer; buffer << val << unit_name[uni]; // setw? return buffer.str().c_str(); -#else - char tbuf[20]; - ostrstream buffer(tbuf, 20); - buffer << val << unit_name[uni] << '\0'; // setw? - return buffer.str(); -#endif +//#else +// char tbuf[20]; +// ostrstream buffer(tbuf, 20); +// buffer << val << unit_name[uni] << '\0'; // setw? +// return buffer.str(); +//#endif } @@ -325,14 +321,14 @@ LyXGlueLength::LyXGlueLength (string const & data) } -string LyXGlueLength::asString() const +string const LyXGlueLength::asString() const { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream buffer; -#else - char tbuf[20]; - ostrstream buffer(tbuf, 20); -#endif +//#else +// char tbuf[20]; +// ostrstream buffer(tbuf, 20); +//#endif if (plus_val != 0.0) if (minus_val != 0.0) if ((uni == plus_uni) && (uni == minus_uni)) @@ -378,23 +374,23 @@ string LyXGlueLength::asString() const << unit_name[minus_uni]; else buffer << val << unit_name[uni]; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM return buffer.str().c_str(); -#else - buffer << '\0'; - return buffer.str(); -#endif +//#else +// buffer << '\0'; +// return buffer.str(); +//#endif } -string LyXGlueLength::asLatexString() const +string const LyXGlueLength::asLatexString() const { -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM std::ostringstream buffer; -#else - char tbuf[40]; - ostrstream buffer(tbuf, 40); -#endif +//#else +// char tbuf[40]; +// ostrstream buffer(tbuf, 40); +//#endif if (plus_val != 0.0) if (minus_val != 0.0) @@ -414,12 +410,12 @@ string LyXGlueLength::asLatexString() const << minus_val << unit_name[minus_uni]; else buffer << val << unit_name[uni]; -#ifdef HAVE_SSTREAM +//#ifdef HAVE_SSTREAM return buffer.str().c_str(); -#else - buffer << '\0'; - return buffer.str(); -#endif +//#else +// buffer << '\0'; +// return buffer.str(); +//#endif } @@ -474,7 +470,7 @@ bool VSpace::operator==(VSpace const & other) const } -string VSpace::asLyXCommand() const +string const VSpace::asLyXCommand() const { string result; @@ -494,7 +490,7 @@ string VSpace::asLyXCommand() const } -string VSpace::asLatexCommand(BufferParams const & params) const +string const VSpace::asLatexCommand(BufferParams const & params) const { switch (kin) { case NONE: return string(); diff --git a/src/vspace.h b/src/vspace.h index fce31b09fd..11fe28079d 100644 --- a/src/vspace.h +++ b/src/vspace.h @@ -64,20 +64,21 @@ public: LyXLength(string const & data); /// - float value() const { return val; }; + float value() const { return val; } /// - LyXLength::UNIT unit() const { return uni; }; + LyXLength::UNIT unit() const { return uni; } /// conversion - virtual string asString() const; + virtual string const asString() const; /// - virtual string asLatexString() const { return this->asString(); }; - + virtual string const asLatexString() const { + return this->asString(); + } /** If "data" is valid, the length represented by it is stored into "result", if that is not 0. */ friend bool isValidLength(string const & data, - LyXLength * result= 0); + LyXLength * result = 0); protected: /// @@ -123,30 +124,34 @@ public: LyXGlueLength(string const & data); /// - float plusValue() const { return plus_val; }; + float plusValue() const { return plus_val; } /// - LyXLength::UNIT plusUnit() const { return plus_uni; }; + LyXLength::UNIT plusUnit() const { return plus_uni; } /// - float minusValue() const { return minus_val; }; + float minusValue() const { return minus_val; } /// - LyXLength::UNIT minusUnit() const { return minus_uni; }; + LyXLength::UNIT minusUnit() const { return minus_uni; } /// conversion - virtual string asString() const; + virtual string const asString() const; /// - virtual string asLatexString() const; + virtual string const asLatexString() const; /** If "data" is valid, the length represented by it is stored into "result", if that is not 0. */ friend bool isValidGlueLength(string const & data, - LyXGlueLength* result= 0); + LyXGlueLength* result = 0); protected: /// - float plus_val, minus_val; + float plus_val; /// - LyXLength::UNIT plus_uni, minus_uni; + float minus_val; + /// + LyXLength::UNIT plus_uni; + /// + LyXLength::UNIT minus_uni; }; /// @@ -224,22 +229,22 @@ public: /// void setKeep(bool val) { kp = val; } /// - bool operator == (VSpace const &) const; + bool operator==(VSpace const &) const; // conversion /// - string asLyXCommand() const; // how it goes into the LyX file + string const asLyXCommand() const; // how it goes into the LyX file /// - string asLatexCommand(BufferParams const & params) const; + string const asLatexCommand(BufferParams const & params) const; /// int inPixels(BufferView * bv) const; /// int inPixels(int default_height, int default_skip) const; private: /// - vspace_kind kin; + vspace_kind kin; /// - LyXGlueLength len; + LyXGlueLength len; /// bool kp; };