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
|
2000-02-04 09:38:32 +00:00
|
|
|
* Copyright 1995-2000 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:
|
|
|
|
///
|
2000-02-08 15:13:01 +00:00
|
|
|
Bullet(const int f = -1, const int c = -1, const int s = -1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
1999-11-15 12:01:38 +00:00
|
|
|
Bullet(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
void setCharacter(int);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
void setFont(int);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
void setSize(int);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
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();
|
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
Bullet & operator = (Bullet const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
friend bool operator==(Bullet const &, Bullet const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
friend bool operator!=(Bullet const & b1, Bullet const & b2) {
|
|
|
|
return !(b1 == b2);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
protected:
|
1999-12-16 14:16:42 +00:00
|
|
|
#ifdef ENABLE_ASSERTIONS
|
2000-02-04 09:38:32 +00:00
|
|
|
void 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
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-02-04 09:38:32 +00:00
|
|
|
// 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
|
|
|
|
// }
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
private:
|
|
|
|
/**
|
2000-02-04 09:38:32 +00:00
|
|
|
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)
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
enum {
|
|
|
|
///
|
|
|
|
MIN = -1,
|
|
|
|
///
|
|
|
|
FONTMAX = 6,
|
|
|
|
///
|
|
|
|
CHARMAX = 36,
|
|
|
|
///
|
|
|
|
SIZEMAX = 10
|
|
|
|
};
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void generateText();
|
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
static string bulletSize(short int);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
static string bulletEntry(short int, short int);
|
|
|
|
|
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.
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/** flag indicates if user has control of text (1)
|
2000-02-04 09:38:32 +00:00
|
|
|
or if I can use it to generate strings (0)
|
|
|
|
or have already (-1)
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
short user_text;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
//NOTE: Arranging these four shorts above to be together
|
|
|
|
// like this should ensure they are in a single cache line
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/** text may contain a user-defined LaTeX symbol command
|
2000-02-04 09:38:32 +00:00
|
|
|
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)
|
2000-02-04 09:38:32 +00:00
|
|
|
: font(MIN), character(MIN), size(MIN), user_text(1), text(t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-16 14:16:42 +00:00
|
|
|
#ifdef ENABLE_ASSERTIONS
|
1999-09-27 18:44:28 +00:00
|
|
|
testInvariant();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
inline void Bullet::setCharacter(int c)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (c < MIN || c >= CHARMAX) {
|
|
|
|
character = MIN;
|
2000-02-04 09:38:32 +00:00
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
inline void Bullet::setFont(int f)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (f < MIN || f >= FONTMAX) {
|
|
|
|
font = MIN;
|
2000-02-04 09:38:32 +00:00
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
inline void Bullet::setSize(int s)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (s < MIN || s >= SIZEMAX) {
|
|
|
|
size = MIN;
|
2000-02-04 09:38:32 +00:00
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
inline Bullet & Bullet::operator=(Bullet const & b)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
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
|
2000-02-04 09:38:32 +00:00
|
|
|
this->testInvariant();
|
1999-09-27 18:44:28 +00:00
|
|
|
#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-----------------*/
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
extern
|
|
|
|
Bullet const ITEMIZE_DEFAULTS[];
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif /* BULLET_H_ */
|