-// -*- 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
*
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "Bullet.h"
+#include "support/LAssert.h"
+
+using namespace lyx::support;
/** 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\\)"
+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}
}
-string Bullet::getText()
+
+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
+}
+
+
+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();
}
-bool operator == (const Bullet & b1, const Bullet & b2)
+bool operator==(const Bullet & b1, const Bullet & b2)
{
bool result = false;
/*--------------------Private Member Functions-------------------*/
-void Bullet::generateText()
+void Bullet::generateText() const
{
// Assumption:
// user hasn't defined their own text and/or I haven't generated
}
-string Bullet::bulletSize(short int 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
// See additional comments in bulletEntry() below.
static char const * BulletSize[SIZEMAX] = {
- "\\tiny", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize",
+ "\\tiny", "\\scriptsize", "\\footnotesize", "\\small", "\\normalsize",
"\\large", "\\Large", "\\LARGE", "\\huge", "\\Huge"
};
}
-string Bullet::bulletEntry(short int f, short int c)
+string const Bullet::bulletEntry(int f, int c)
{
// Despite how this may at first appear the static local variables
// are only initialized once..
// to get around a compiler bug in an earler version of gcc (< 2.7.2.1)
// static string const BulletPanels[FONTMAX][CHARMAX] = {
static char const * BulletPanel0[CHARMAX] = {
- /* standard */
+ /* standard */
"\\normalfont\\bfseries{--}", "\\(\\vdash\\)",
"\\(\\dashv\\)", "\\(\\flat\\)", "\\(\\natural\\)",
- "\\(\\sharp\\)", "\\(\\ast\\)", "\\(\\star\\)",
+ "\\(\\sharp\\)", "\\(\\ast\\)", "\\(\\star\\)",
"\\(\\bullet\\)", "\\(\\circ\\)", "\\(\\cdot\\)",
"\\(\\dagger\\)", "\\(\\bigtriangleup\\)",
"\\(\\bigtriangledown\\)", "\\(\\triangleleft\\)",
"\\(\\oplus\\)", "\\(\\ominus\\)", "\\(\\otimes\\)",
"\\(\\oslash\\)", "\\(\\odot\\)", "\\(\\spadesuit\\)",
"\\(\\diamond\\)", "\\(\\Diamond\\)", "\\(\\Box\\)",
- "\\(\\diamondsuit\\)", "\\(\\heartsuit\\)",
+ "\\(\\diamondsuit\\)", "\\(\\heartsuit\\)",
"\\(\\clubsuit\\)", "\\(\\rightarrow\\)", "\\(\\leadsto\\)",
- "\\(\\rightharpoonup\\)", "\\(\\rightharpoondown\\)",
+ "\\(\\rightharpoonup\\)", "\\(\\rightharpoondown\\)",
"\\(\\Rightarrow\\)", "\\(\\succ\\)"
};
static char const * BulletPanel1[CHARMAX] = {
return BulletPanels[f][c];
}
+
+#ifdef ENABLE_ASSERTIONS
+void Bullet::testInvariant() const {
+ Assert(font >= MIN);
+ Assert(font < FONTMAX);
+ Assert(character >= MIN);
+ Assert(character < CHARMAX);
+ Assert(size >= MIN);
+ Assert(size < SIZEMAX);
+ Assert(user_text >= -1);
+ Assert(user_text <= 1);
+ // now some relational/operational tests
+ if (user_text == 1) {
+ 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