1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This is the bullet class definition file.
|
|
|
|
* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* This file Copyright 1997-1999
|
|
|
|
* Allan Rae
|
1999-11-15 12:01:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
#ifndef BULLET_H
|
|
|
|
#define BULLET_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "LString.h"
|
|
|
|
|
1999-12-16 14:16:42 +00:00
|
|
|
#include "support/LAssert.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
class Bullet {
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
Bullet(const int f = -1, const int c = -1, const int s = -1);
|
|
|
|
|
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
Bullet(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
void setCharacter(const int);
|
|
|
|
///
|
|
|
|
void setFont(const int);
|
|
|
|
///
|
|
|
|
void setSize(const int);
|
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
void setText(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
int getCharacter() const;
|
|
|
|
///
|
|
|
|
int getFont() const;
|
|
|
|
///
|
|
|
|
int getSize() const;
|
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
string getText() const;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
string getText();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
char const * c_str();
|
|
|
|
///
|
|
|
|
Bullet & operator = (const Bullet &);
|
|
|
|
///
|
|
|
|
friend bool operator == (const Bullet &, const Bullet &);
|
|
|
|
///
|
|
|
|
friend bool operator != (const Bullet & b1, const Bullet & b2)
|
|
|
|
{
|
|
|
|
return !(b1 == b2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
1999-12-16 14:16:42 +00:00
|
|
|
#ifdef ENABLE_ASSERTIONS
|
1999-09-27 18:44:28 +00:00
|
|
|
void testInvariant() const
|
|
|
|
{
|
1999-12-16 14:16:42 +00:00
|
|
|
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);
|
1999-09-27 18:44:28 +00:00
|
|
|
// now some relational/operational tests
|
|
|
|
if (user_text == 1) {
|
1999-12-16 14:16:42 +00:00
|
|
|
Assert(font == -1 && (character == -1 && size == -1));
|
|
|
|
// Assert(!text.empty()); // this isn't necessarily an error
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
// else if (user_text == -1) {
|
1999-12-16 14:16:42 +00:00
|
|
|
// Assert(!text.empty()); // this also isn't necessarily an error
|
1999-09-27 18:44:28 +00:00
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// // user_text == 0
|
1999-12-16 14:16:42 +00:00
|
|
|
// Assert(text.empty()); // not usually true
|
1999-09-27 18:44:28 +00:00
|
|
|
// }
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
This enum makes adding additional panels or changing panel sizes
|
|
|
|
easier. Since you only need change these values for all tests to
|
|
|
|
be correct for the new values.
|
|
|
|
|
|
|
|
Note: MAX means the size of the array so to test you need:
|
|
|
|
(x < MAX) *not* (x <= MAX)
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
///
|
|
|
|
MIN = -1,
|
|
|
|
///
|
|
|
|
FONTMAX = 6,
|
|
|
|
///
|
|
|
|
CHARMAX = 36,
|
|
|
|
///
|
|
|
|
SIZEMAX = 10
|
|
|
|
};
|
|
|
|
|
|
|
|
///
|
|
|
|
void generateText();
|
|
|
|
///
|
2000-01-07 03:42:16 +00:00
|
|
|
static string bulletSize(const short &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-01-07 03:42:16 +00:00
|
|
|
static string bulletEntry(const short &, const short &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
short font;
|
|
|
|
///
|
|
|
|
short character;
|
|
|
|
///
|
|
|
|
short size;
|
|
|
|
|
|
|
|
// size, character and font are array indices to access
|
|
|
|
// the predefined arrays of LaTeX equivalent strings.
|
|
|
|
|
|
|
|
/** flag indicates if user has control of text (1)
|
1999-10-02 16:21:10 +00:00
|
|
|
or if I can use it to generate strings (0)
|
1999-09-27 18:44:28 +00:00
|
|
|
or have already (-1)
|
|
|
|
*/
|
|
|
|
short user_text;
|
|
|
|
|
|
|
|
//NOTE: Arranging these four shorts above to be together
|
|
|
|
// like this should ensure they are in a single cache line
|
|
|
|
|
|
|
|
/** text may contain a user-defined LaTeX symbol command
|
|
|
|
or one generated internally from the font, character
|
|
|
|
and size settings.
|
|
|
|
*/
|
1999-10-02 16:21:10 +00:00
|
|
|
string text;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------Inline Bullet Member Functions------------------*/
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
inline Bullet::Bullet(string const & t)
|
1999-09-27 18:44:28 +00:00
|
|
|
: font(MIN), character(MIN), size(MIN), user_text(1), text(t)
|
|
|
|
{
|
1999-12-16 14:16:42 +00:00
|
|
|
#ifdef ENABLE_ASSERTIONS
|
1999-09-27 18:44:28 +00:00
|
|
|
testInvariant();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Bullet::setCharacter(const int c)
|
|
|
|
{
|
|
|
|
if (c < MIN || c >= CHARMAX) {
|
|
|
|
character = MIN;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
character = c;
|
|
|
|
}
|
|
|
|
user_text = 0;
|
1999-12-16 14:16:42 +00:00
|
|
|
#ifdef ENABLE_ASSERTIONS
|
1999-09-27 18:44:28 +00:00
|
|
|
testInvariant();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Bullet::setFont(const int f)
|
|
|
|
{
|
|
|
|
if (f < MIN || f >= FONTMAX) {
|
|
|
|
font = MIN;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
font = f;
|
|
|
|
}
|
|
|
|
user_text = 0;
|
1999-12-16 14:16:42 +00:00
|
|
|
#ifdef ENABLE_ASSERTIONS
|
1999-09-27 18:44:28 +00:00
|
|
|
testInvariant();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline void Bullet::setSize(const int s)
|
|
|
|
{
|
|
|
|
if (s < MIN || s >= SIZEMAX) {
|
|
|
|
size = MIN;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
size = s;
|
|
|
|
}
|
|
|
|
user_text = 0;
|
1999-12-16 14:16:42 +00:00
|
|
|
#ifdef ENABLE_ASSERTIONS
|
1999-09-27 18:44:28 +00:00
|
|
|
testInvariant();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
inline void Bullet::setText(string const & t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
font = character = size = MIN;
|
|
|
|
user_text = 1;
|
|
|
|
text = t;
|
1999-12-16 14:16:42 +00:00
|
|
|
#ifdef ENABLE_ASSERTIONS
|
1999-09-27 18:44:28 +00:00
|
|
|
testInvariant();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline int Bullet::getCharacter() const
|
|
|
|
{
|
|
|
|
return character;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline int Bullet::getFont() const
|
|
|
|
{
|
|
|
|
return font;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline int Bullet::getSize() const
|
|
|
|
{
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
inline string Bullet::getText() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline Bullet & Bullet::operator = (const Bullet & b)
|
|
|
|
{
|
1999-12-16 14:16:42 +00:00
|
|
|
#ifdef ENABLE_ASSERTIONS
|
1999-09-27 18:44:28 +00:00
|
|
|
b.testInvariant();
|
|
|
|
#endif
|
|
|
|
font = b.font;
|
|
|
|
character = b.character;
|
|
|
|
size = b.size;
|
|
|
|
user_text = b.user_text;
|
|
|
|
text = b.text;
|
1999-12-16 14:16:42 +00:00
|
|
|
#ifdef ENABLE_ASSERTIONS
|
1999-09-27 18:44:28 +00:00
|
|
|
this->testInvariant();
|
|
|
|
#endif
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
inline char const * Bullet::c_str()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return this->getText().c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------End Bullet Member Functions-----------------*/
|
|
|
|
|
|
|
|
/** The four LaTeX itemize environment default bullets
|
|
|
|
*/
|
|
|
|
static Bullet const ITEMIZE_DEFAULTS[4] = { Bullet( 0, 8 ),//"\\(\\bullet\\)"
|
|
|
|
Bullet( 0, 0 ),//"\\normalfont\\bfseries{--}"
|
|
|
|
Bullet( 0, 6 ),//"\\(\\ast\\)"
|
1999-11-15 12:01:38 +00:00
|
|
|
Bullet( 0, 10 ) };//"\\(\\cdot\\)"
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif /* BULLET_H_ */
|