X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fvspace.h;h=30aa427ab43ef66f5a5ac9d0e1860f83afa3c786;hb=dff2911bda426ad439e6475f62183cedd7044801;hp=8e224649899418477c2e5411bfbe07e50b601b8f;hpb=27de1486ca34aaad446adb798d71a77d6f6304da;p=lyx.git diff --git a/src/vspace.h b/src/vspace.h index 8e22464989..30aa427ab4 100644 --- a/src/vspace.h +++ b/src/vspace.h @@ -1,22 +1,25 @@ // -*- C++ -*- /* This file is part of - * ====================================================== + * ====================================================== * * LyX, The Document Processor * - * Copyright (C) 1995 1996 Matthias Ettrich - * and the LyX Team. + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2001 The LyX Team. * - *======================================================*/ + * ====================================================== */ -#ifndef _VSPACE_H_ -#define _VSPACE_H_ +#ifndef VSPACE_H +#define VSPACE_H #ifdef __GNUG__ #pragma interface #endif -#include +#include "LString.h" + +class BufferParams; +class BufferView; /// LyXLength Class class LyXLength { @@ -47,61 +50,76 @@ public: EM, /// Math unit (18mu = 1em) for positioning in math mode MU, + /// Percent of columnwidth both "%" or "%c" + PW, + PE, + /// Percent of pagewidth + PP, + /// Percent of linewidth + PL, /// no unit UNIT_NONE }; - //@Man: constructors - //@{ /// - LyXLength() : val(0), uni(LyXLength::PT) {}; - LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}; + LyXLength() : val(0), uni(LyXLength::PT) {} + /// + LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {} /** "data" must be a decimal number, followed by a unit. */ - LyXLength(LString const & data); - //@} + explicit + LyXLength(string const & data); - //@Man: selectors - //@{ /// - float value() const { return val; }; + float value() const { return val; } /// - LyXLength::UNIT unit() const { return uni; }; - //@} - - /// - bool operator==(LyXLength other); + LyXLength::UNIT unit() const { return uni; } /// conversion - virtual LString asString() const; - virtual LString asLatexString() const { return this->asString(); }; - + virtual string const asString() const; + /// + virtual string const asLatexString() const; /** If "data" is valid, the length represented by it is - stored into "result", if that is not NULL. */ - friend bool isValidLength(LString const & data, - LyXLength* result=NULL); + stored into "result", if that is not 0. */ + friend bool isValidLength(string const & data, + LyXLength * result = 0); protected: + /// float val; + /// LyXLength::UNIT uni; }; -extern LyXLength::UNIT unitFromString (LString const & data); -extern bool isValidLength(LString const &data, LyXLength* result); +/// +inline +bool operator==(LyXLength const & l1, LyXLength const & l2) +{ + return l1.value() == l2.value() + && l1.unit() == l2.unit(); +} + +/// +extern LyXLength::UNIT unitFromString (string const & data); +/// +extern bool isValidLength(string const & data, LyXLength * result); +/// +extern const char * stringFromUnit(int unit); /// LyXGlueLength class class LyXGlueLength : public LyXLength { public: - //@Man: constructors - //@{ /// - LyXGlueLength(float v, LyXLength::UNIT u, - float pv=0.0, LyXLength::UNIT pu=LyXLength::UNIT_NONE, - float mv=0.0, LyXLength::UNIT mu=LyXLength::UNIT_NONE) + LyXGlueLength(float v, + LyXLength::UNIT u, + float pv = 0.0, + LyXLength::UNIT pu = LyXLength::UNIT_NONE, + float mv = 0.0, + LyXLength::UNIT mu = LyXLength::UNIT_NONE) : LyXLength (v, u), plus_val(pv), minus_val(mv), - plus_uni(pu), minus_uni(mu) {}; + plus_uni(pu), minus_uni(mu) {} /** "data" must be a decimal number, followed by a unit, and optional "glue" indicated by "+" and "-". You may abbreviate @@ -109,92 +127,133 @@ public: 1.2 cm // 4mm +2pt // 2cm -4mm +2mm // 4+0.1-0.2cm The traditional Latex format is also accepted, like 4cm plus 10pt minus 10pt */ - LyXGlueLength(LString const & data); - //@} + explicit + LyXGlueLength(string const & data); - //@Man: selectors - //@{ /// - 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; }; - //@} - - /// - bool operator==(LyXGlueLength other); + LyXLength::UNIT minusUnit() const { return minus_uni; } /// conversion - virtual LString asString() const; - virtual LString asLatexString() const; + virtual string const asString() const; + /// + virtual string const asLatexString() const; /** If "data" is valid, the length represented by it is - stored into "result", if that is not NULL. */ - friend bool isValidGlueLength(LString const & data, - LyXGlueLength* result=NULL); + stored into "result", if that is not 0. */ + friend bool isValidGlueLength(string const & data, + LyXGlueLength* result = 0); protected: - float plus_val, minus_val; - LyXLength::UNIT plus_uni, minus_uni; + /// + float plus_val; + /// + float minus_val; + /// + LyXLength::UNIT plus_uni; + /// + LyXLength::UNIT minus_uni; }; -extern bool isValidGlueLength(LString const &data, LyXGlueLength* result); +/// +inline +bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2) +{ + return l1.value() == l2.value() + && l1.unit() == l2.unit() + && l1.plusValue() == l2.plusValue() + && l1.plusUnit() == l2.plusUnit() + && l1.minusValue() == l2.minusValue() + && l1.minusUnit() == l2.minusUnit(); +} + + +/// +extern bool isValidGlueLength(string const & data, LyXGlueLength * result); /// VSpace class class VSpace { public: - /// - enum vspace_kind { NONE, DEFSKIP, - SMALLSKIP, MEDSKIP, BIGSKIP, - VFILL, LENGTH }; - // constructors + /// The different kinds of spaces. + enum vspace_kind { + /// + NONE, + /// + DEFSKIP, + /// + SMALLSKIP, + /// + MEDSKIP, + /// + BIGSKIP, + /// + VFILL, + /// + LENGTH + }; + /// Constructor VSpace() : kin (NONE), len(0.0, LyXLength::PT), - kp (false) {}; - - VSpace(vspace_kind k) : + kp (false) {} + /// Constructor + explicit + VSpace(vspace_kind k) : kin (k), len (0.0, LyXLength::PT), - kp (false) {}; - + kp (false) {} + /// Constructor + explicit VSpace(LyXGlueLength l) : kin (LENGTH), len (l), - kp (false) {}; + kp (false) {} + /// Constructor + explicit VSpace(float v, LyXLength::UNIT u) : kin (LENGTH), len (v, u), - kp (false) {}; + kp (false) {} - /// this constructor is for reading from a .lyx file - VSpace(LString const & data); + /// Constructor for reading from a .lyx file + explicit + VSpace(string const & data); - // access functions - vspace_kind kind() const { return kin; } - LyXLength length() const { return len; } + /// access functions + vspace_kind kind() const { return kin; } + /// + LyXGlueLength length() const { return len; } // a flag that switches between \vspace and \vspace* bool keep() const { return kp; } + /// void setKeep(bool val) { kp = val; } - - bool operator== (VSpace other); + /// + bool operator==(VSpace const &) const; // conversion - LString asLyXCommand() const; // how it goes into the LyX file - LString asLatexCommand() const; - int inPixels() const; + /// + string const asLyXCommand() const; // how it goes into the LyX file + /// + string const asLatexCommand(BufferParams const & params) const; + /// + int inPixels(BufferView * bv) const; + /// + int inPixels(int default_height, int default_skip, int default_width=0) const; private: - vspace_kind kin; - LyXGlueLength len; + /// This VSpace kind + vspace_kind kin; + /// + LyXGlueLength len; + /// bool kp; }; #endif - -