X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBullet.C;h=8bc3d874ebb95627423e9d1424f337b7e802b9e9;hb=98c966c64594611e469313314abd1e59524adb4a;hp=82c49e9955bf172aaf0fe3742aa36103d6983337;hpb=27de1486ca34aaad446adb798d71a77d6f6304da;p=lyx.git diff --git a/src/Bullet.C b/src/Bullet.C index 82c49e9955..8bc3d874eb 100644 --- a/src/Bullet.C +++ b/src/Bullet.C @@ -1,17 +1,16 @@ -// -*- C++ -*- /* Completes the implementation of the Bullet class * It defines the various LaTeX commands etc. required to * generate the bullets in the bullet-panel's. * * This file is part of - *====================================================== + * ====================================================== * * LyX, The Document Processor * - * Copyright (C) 1997-1998 Allan Rae + * Copyright 1997-1998 Allan Rae * and the LyX Team * - *======================================================*/ + * ====================================================== */ #include @@ -20,13 +19,22 @@ #endif #include "Bullet.h" +#include "support/LAssert.h" + +/** The four LaTeX itemize environment default bullets + */ +extern +Bullet const ITEMIZE_DEFAULTS[4] = { Bullet(0, 8),//"\\(\\bullet\\)" + Bullet(0, 0),//"\\normalfont\\bfseries{--}" + Bullet(0, 6),//"\\(\\ast\\)" + Bullet(0, 10) };//"\\(\\cdot\\)" // will need these later if still using full text as below // \usepackage{latexsym,pifont,amssymb} // and wasysym when that panel is created -Bullet::Bullet(const int f, const int c, const int s) +Bullet::Bullet(int f, int c, int s) : font(f), character(c), size(s), user_text(0) { if (f < MIN || f >= FONTMAX) { @@ -39,13 +47,111 @@ Bullet::Bullet(const int f, const int c, const int s) size = MIN; } generateText(); -#ifdef DEBUG_AS_DEFAULT +#ifdef ENABLE_ASSERTIONS + testInvariant(); +#endif +} + + + +Bullet::Bullet(string const & t) + : font(MIN), character(MIN), size(MIN), user_text(1), text(t) +{ +#ifdef ENABLE_ASSERTIONS + testInvariant(); +#endif +} + + +void Bullet::setCharacter(int c) +{ + if (c < MIN || c >= CHARMAX) { + character = MIN; + } else { + character = c; + } + user_text = 0; +#ifdef ENABLE_ASSERTIONS + testInvariant(); +#endif +} + + +void Bullet::setFont(int f) +{ + if (f < MIN || f >= FONTMAX) { + font = MIN; + } else { + font = f; + } + user_text = 0; +#ifdef ENABLE_ASSERTIONS testInvariant(); #endif } -LString Bullet::getText() +void Bullet::setSize(int s) +{ + if (s < MIN || s >= SIZEMAX) { + size = MIN; + } else { + size = s; + } + user_text = 0; +#ifdef ENABLE_ASSERTIONS + testInvariant(); +#endif +} + + +void Bullet::setText(string const & t) +{ + font = character = size = MIN; + user_text = 1; + text = t; +#ifdef ENABLE_ASSERTIONS + testInvariant(); +#endif +} + + +int Bullet::getCharacter() const +{ + return character; +} + + +int Bullet::getFont() const +{ + return font; +} + + +int Bullet::getSize() const +{ + return size; +} + + +Bullet & Bullet::operator=(Bullet const & b) +{ +#ifdef ENABLE_ASSERTIONS + b.testInvariant(); +#endif + font = b.font; + character = b.character; + size = b.size; + user_text = b.user_text; + text = b.text; +#ifdef ENABLE_ASSERTIONS + this->testInvariant(); +#endif + return *this; +} + + +string const & Bullet::getText() const { if (user_text == 0) { generateText(); @@ -54,7 +160,7 @@ LString Bullet::getText() } -bool operator == (const Bullet & b1, const Bullet & b2) +bool operator==(const Bullet & b1, const Bullet & b2) { bool result = false; @@ -75,7 +181,7 @@ bool operator == (const Bullet & b1, const Bullet & b2) /*--------------------Private Member Functions-------------------*/ -void Bullet::generateText() +void Bullet::generateText() const { // Assumption: // user hasn't defined their own text and/or I haven't generated @@ -101,15 +207,15 @@ void Bullet::generateText() } -const LString & Bullet::bulletSize(const short & s) +string const Bullet::bulletSize(int s) { // use a parameter rather than hard code `size' in here // in case some future function may want to retrieve // an arbitrary entry. // See additional comments in bulletEntry() below. - static LString const BulletSize[SIZEMAX] = { - "\\tiny", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize", + static char const * BulletSize[SIZEMAX] = { + "\\tiny", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize", "\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge" }; @@ -117,7 +223,7 @@ const LString & Bullet::bulletSize(const short & s) } -const LString & Bullet::bulletEntry(const short & f, const short & c) +string const Bullet::bulletEntry(int f, int c) { // Despite how this may at first appear the static local variables // are only initialized once.. @@ -130,12 +236,12 @@ const LString & Bullet::bulletEntry(const short & f, const short & c) // The single 2-dim array had to be changed to multiple 1-dim arrays // to get around a compiler bug in an earler version of gcc (< 2.7.2.1) - // static LString const BulletPanels[FONTMAX][CHARMAX] = { - static LString const BulletPanel0[CHARMAX] = { - /* standard */ + // static string const BulletPanels[FONTMAX][CHARMAX] = { + static char const * BulletPanel0[CHARMAX] = { + /* standard */ "\\normalfont\\bfseries{--}", "\\(\\vdash\\)", "\\(\\dashv\\)", "\\(\\flat\\)", "\\(\\natural\\)", - "\\(\\sharp\\)", "\\(\\ast\\)", "\\(\\star\\)", + "\\(\\sharp\\)", "\\(\\ast\\)", "\\(\\star\\)", "\\(\\bullet\\)", "\\(\\circ\\)", "\\(\\cdot\\)", "\\(\\dagger\\)", "\\(\\bigtriangleup\\)", "\\(\\bigtriangledown\\)", "\\(\\triangleleft\\)", @@ -143,12 +249,12 @@ const LString & Bullet::bulletEntry(const short & f, const short & c) "\\(\\oplus\\)", "\\(\\ominus\\)", "\\(\\otimes\\)", "\\(\\oslash\\)", "\\(\\odot\\)", "\\(\\spadesuit\\)", "\\(\\diamond\\)", "\\(\\Diamond\\)", "\\(\\Box\\)", - "\\(\\diamondsuit\\)", "\\(\\heartsuit\\)", + "\\(\\diamondsuit\\)", "\\(\\heartsuit\\)", "\\(\\clubsuit\\)", "\\(\\rightarrow\\)", "\\(\\leadsto\\)", - "\\(\\rightharpoonup\\)", "\\(\\rightharpoondown\\)", + "\\(\\rightharpoonup\\)", "\\(\\rightharpoondown\\)", "\\(\\Rightarrow\\)", "\\(\\succ\\)" }; - static LString const BulletPanel1[CHARMAX] = { + static char const * BulletPanel1[CHARMAX] = { /* amssymb */ "\\(\\Rrightarrow\\)", "\\(\\rightarrowtail\\)", "\\(\\twoheadrightarrow\\)", "\\(\\rightsquigarrow\\)", @@ -167,7 +273,7 @@ const LString & Bullet::bulletEntry(const short & f, const short & c) "\\(\\blacktriangledown\\)", "\\(\\blacklozenge\\)", "\\(\\blacksquare\\)" }; - static LString const BulletPanel2[CHARMAX] = { + static char const * BulletPanel2[CHARMAX] = { /* psnfss1 */ "\\ding{108}", "\\ding{109}", "\\ding{119}", "\\Pisymbol{psy}{197}", @@ -188,7 +294,7 @@ const LString & Bullet::bulletEntry(const short & f, const short & c) "\\ding{166}", "\\ding{167}", "\\ding{226}", "\\ding{227}" }; - static LString const BulletPanel3[CHARMAX] = { + static char const * BulletPanel3[CHARMAX] = { /* psnfss2 */ "\\ding{37}", "\\ding{38}", "\\ding{34}", "\\ding{36}", @@ -209,7 +315,7 @@ const LString & Bullet::bulletEntry(const short & f, const short & c) "\\ding{171}", "\\ding{168}", "\\ding{169}", "\\ding{170}" }; - static LString const BulletPanel4[CHARMAX] = { + static char const * BulletPanel4[CHARMAX] = { /* psnfss3 */ "\\ding{65}", "\\ding{76}", "\\ding{75}", "\\ding{72}", @@ -230,7 +336,7 @@ const LString & Bullet::bulletEntry(const short & f, const short & c) "\\ding{102}", "\\ding{96}", "\\ding{95}", "\\ding{97}" }; - static LString const BulletPanel5[CHARMAX] = { + static char const * BulletPanel5[CHARMAX] = { /* psnfss4 */ "\\ding{223}", "\\ding{224}", "\\ding{225}", "\\ding{232}", @@ -250,9 +356,9 @@ const LString & Bullet::bulletEntry(const short & f, const short & c) "\\Pisymbol{psy}{174}", "\\Pisymbol{psy}{222}", "\\ding{254}", "\\ding{242}", "\\ding{231}", "\\Pisymbol{psy}{45}" - }; /* LString const BulletPanels[][] */ + }; /* string const BulletPanels[][] */ - static LString const * BulletPanels[FONTMAX] = { + static char const ** BulletPanels[FONTMAX] = { BulletPanel0, BulletPanel1, BulletPanel2, BulletPanel3, BulletPanel4, BulletPanel5 @@ -260,3 +366,28 @@ const LString & Bullet::bulletEntry(const short & f, const short & c) return BulletPanels[f][c]; } + +#ifdef ENABLE_ASSERTIONS +void Bullet::testInvariant() const { + lyx::Assert(font >= MIN); + lyx::Assert(font < FONTMAX); + lyx::Assert(character >= MIN); + lyx::Assert(character < CHARMAX); + lyx::Assert(size >= MIN); + lyx::Assert(size < SIZEMAX); + lyx::Assert(user_text >= -1); + lyx::Assert(user_text <= 1); + // now some relational/operational tests + if (user_text == 1) { + lyx::Assert(font == -1 && (character == -1 && size == -1)); + // Assert(!text.empty()); // this isn't necessarily an error + } + // else if (user_text == -1) { + // Assert(!text.empty()); // this also isn't necessarily an error + // } + // else { + // // user_text == 0 + // Assert(text.empty()); // not usually true + // } +} +#endif