1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
2002-05-30 03:37:24 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file TexRow.h
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2002-05-30 03:37:24 +00:00
|
|
|
* \author Matthias Ettrich
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author John Levon
|
2015-10-13 23:17:05 +00:00
|
|
|
* \author Guillaume Munch
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-05-30 03:37:24 +00:00
|
|
|
*/
|
|
|
|
|
2015-10-13 22:51:50 +00:00
|
|
|
/* Note about debugging options:
|
|
|
|
*
|
|
|
|
* When compiled in devel mode and run with the option -dbg latex, two ways
|
|
|
|
* of debugging TexRow are available:
|
|
|
|
*
|
|
|
|
* 1. The source view panel prepends the full TexRow information to the LaTeX
|
|
|
|
* output.
|
|
|
|
*
|
|
|
|
* 2. Clicking on any line in the source view moves the buffer to the location
|
|
|
|
* recognised by TexRow.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
#ifndef TEXROW_H
|
|
|
|
#define TEXROW_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2015-10-13 23:17:05 +00:00
|
|
|
#include "support/types.h"
|
2015-09-15 04:56:01 +00:00
|
|
|
#include "support/debug.h"
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
#include <vector>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
class LyXErr;
|
2015-10-13 19:26:21 +00:00
|
|
|
class Cursor;
|
2015-10-13 23:17:05 +00:00
|
|
|
class CursorSlice;
|
2015-09-15 04:56:01 +00:00
|
|
|
class DocIterator;
|
2015-10-13 23:17:05 +00:00
|
|
|
class docstring_list;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2015-10-13 23:17:05 +00:00
|
|
|
/// types for cells and math insets
|
2015-10-13 23:23:12 +00:00
|
|
|
typedef void const * uid_type;
|
2015-10-13 23:17:05 +00:00
|
|
|
typedef size_t idx_type;
|
|
|
|
|
2015-10-13 23:23:12 +00:00
|
|
|
|
2007-08-12 14:54:54 +00:00
|
|
|
/// Represents the correspondence between paragraphs and the generated
|
2008-10-31 14:13:44 +00:00
|
|
|
/// LaTeX file
|
2007-08-12 14:54:54 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
class TexRow {
|
|
|
|
public:
|
2015-10-13 23:17:05 +00:00
|
|
|
/// an individual par id/pos <=> row mapping
|
|
|
|
struct TextEntry { int id; int pos; };
|
|
|
|
|
|
|
|
/// an individual math id/cell <=> row mapping
|
|
|
|
struct MathEntry { uid_type id; idx_type cell; };
|
|
|
|
|
|
|
|
/// a container for passing entries around
|
|
|
|
struct RowEntry {
|
|
|
|
bool is_math;// true iff the union is a math
|
|
|
|
union {
|
|
|
|
struct TextEntry text;
|
|
|
|
struct MathEntry math;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-10-13 22:51:50 +00:00
|
|
|
// For each row we store a list of one special TextEntry and several
|
|
|
|
// RowEntries. (The order is important.) We only want one text entry
|
2015-10-13 23:17:05 +00:00
|
|
|
// because we do not want to store every position in the lyx file. On the
|
2015-10-13 22:51:50 +00:00
|
|
|
// other hand we want to record all math and table cells positions for
|
|
|
|
// enough precision. Usually the count of cells is easier to handle.
|
2015-10-13 23:17:05 +00:00
|
|
|
class RowEntryList : public std::vector<RowEntry> {
|
|
|
|
public:
|
|
|
|
RowEntryList() : std::vector<RowEntry>(), text_entry_(-1) {}
|
|
|
|
|
|
|
|
// returns true if the row entry will appear in the row entry list
|
|
|
|
bool addEntry(RowEntry const &);
|
|
|
|
|
2015-10-13 22:51:50 +00:00
|
|
|
// the row entry will appear in the row entry list, but it never counts
|
|
|
|
// as a proper text entry.
|
|
|
|
void forceAddEntry(RowEntry const &);
|
|
|
|
|
2015-10-13 23:17:05 +00:00
|
|
|
// returns the TextEntry or TexRow::text_none if none
|
|
|
|
TextEntry getTextEntry() const;
|
|
|
|
|
|
|
|
// returns the first entry, or TexRow::row_none if none
|
|
|
|
RowEntry entry() const;
|
|
|
|
|
2015-10-13 22:51:50 +00:00
|
|
|
// appends a row
|
|
|
|
void append(RowEntryList const &);
|
|
|
|
|
2015-10-13 23:17:05 +00:00
|
|
|
private:
|
|
|
|
size_t text_entry_;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Returns true if RowEntry is devoid of information
|
|
|
|
static bool isNone(RowEntry const &);
|
|
|
|
static const TextEntry text_none;
|
|
|
|
static const RowEntry row_none;
|
2015-10-13 22:51:50 +00:00
|
|
|
|
2015-10-13 23:17:05 +00:00
|
|
|
/// Returns true if TextEntry is devoid of information
|
|
|
|
static bool isNone(TextEntry const &);
|
|
|
|
|
|
|
|
/// Converts a CursorSlice into a RowEntry
|
|
|
|
static RowEntry rowEntryFromCursorSlice(CursorSlice const & slice);
|
|
|
|
|
|
|
|
/// Encapsulates the paragraph and position for later use
|
|
|
|
static RowEntry textEntry(int id, int pos);
|
|
|
|
|
|
|
|
/// Encapsulates a cell and position for later use
|
|
|
|
static RowEntry mathEntry(uid_type id, idx_type cell);
|
|
|
|
|
|
|
|
/// true iff same paragraph or math inset
|
|
|
|
static bool sameParOrInsetMath(RowEntry const &, RowEntry const &);
|
|
|
|
|
|
|
|
/// computes the distance in pos or cell index
|
|
|
|
/// assumes it is the sameParOrInsetMath
|
|
|
|
static int comparePos(RowEntry const & entry1, RowEntry const & entry2);
|
|
|
|
|
|
|
|
/// for debugging purposes
|
|
|
|
static docstring asString(RowEntry const &);
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2015-09-15 04:56:01 +00:00
|
|
|
TexRow(bool enable = true)
|
2015-10-13 23:17:05 +00:00
|
|
|
: current_row_(RowEntryList()), enabled_(enable) {}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2015-10-13 23:17:05 +00:00
|
|
|
/// Clears structure. Set enable to false if texrow is not needed, to avoid
|
|
|
|
/// computing TexRow when it is going to be immediately discarded.
|
2015-09-15 04:56:01 +00:00
|
|
|
void reset(bool enable = true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2015-10-13 23:17:05 +00:00
|
|
|
/// Defines the row information for the current line
|
|
|
|
/// returns true if this entry will appear on the current row
|
|
|
|
bool start(RowEntry entry);
|
|
|
|
|
|
|
|
/// Defines the paragraph and position for the current line
|
|
|
|
/// returns true if this entry will appear on the current row
|
|
|
|
bool start(int id, int pos);
|
|
|
|
|
2015-10-13 22:51:50 +00:00
|
|
|
/// Defines a cell and position for the current line. Always appear in the
|
|
|
|
/// current row.
|
|
|
|
void startMath(uid_type id, idx_type cell);
|
|
|
|
|
|
|
|
/// Defines the paragraph for the current cell-like inset. Always appears
|
|
|
|
/// in the current row like a math cell, but is detached from the normal
|
|
|
|
/// text flow. Note: since the cell idx is not recorded it does not work as
|
|
|
|
/// well as for math grids; if we were to do that properly we would need to
|
|
|
|
/// access the id of the parent Tabular inset from the CursorSlice.
|
|
|
|
void forceStart(int id, int pos);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Insert node when line is completed
|
|
|
|
void newline();
|
|
|
|
|
2010-02-08 17:39:55 +00:00
|
|
|
/// Insert multiple nodes when zero or more lines are completed
|
|
|
|
void newlines(int num_lines);
|
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
/// Call when code generation is complete
|
|
|
|
void finalize();
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
/**
|
|
|
|
* getIdFromRow - find pid and position for a given row
|
|
|
|
* @param row row number to find
|
|
|
|
* @param id set to id if found
|
|
|
|
* @param pos set to paragraph position if found
|
|
|
|
* @return true if found, false otherwise
|
|
|
|
*
|
|
|
|
* If the row could not be found, pos is set to zero and
|
|
|
|
* id is set to -1
|
|
|
|
*/
|
2000-08-05 05:17:18 +00:00
|
|
|
bool getIdFromRow(int row, int & id, int & pos) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
/// Finds the best pair of rows for dit
|
|
|
|
/// returns (-1,-1) if not found.
|
|
|
|
std::pair<int,int> rowFromDocIterator(DocIterator const & dit) const;
|
2015-10-13 19:26:21 +00:00
|
|
|
|
|
|
|
/// Finds the best pair of rows for cursor, taking the selection into
|
|
|
|
/// account
|
|
|
|
/// returns (-1,-1) if not found.
|
|
|
|
std::pair<int,int> rowFromCursor(Cursor const & dit) const;
|
2007-08-13 14:04:35 +00:00
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
/// Returns the number of rows contained
|
2015-10-13 23:17:05 +00:00
|
|
|
int rows() const { return rowlist_.size(); }
|
|
|
|
|
2015-10-13 22:51:50 +00:00
|
|
|
/// appends texrow. the final line of this is merged with the first line of
|
|
|
|
/// texrow.
|
|
|
|
void append(TexRow const & texrow);
|
|
|
|
|
2015-10-13 23:17:05 +00:00
|
|
|
/// for debugging purpose
|
|
|
|
void prepend(docstring_list &) const;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
private:
|
2015-10-13 23:17:05 +00:00
|
|
|
typedef std::vector<RowEntryList> RowList;
|
|
|
|
///
|
|
|
|
class RowListIterator;
|
|
|
|
///
|
|
|
|
RowListIterator begin() const;
|
|
|
|
///
|
|
|
|
RowListIterator end() const;
|
2002-05-30 03:37:24 +00:00
|
|
|
/// container of id/pos <=> row mapping
|
2015-10-13 23:17:05 +00:00
|
|
|
RowList rowlist_;
|
|
|
|
/// Entry of current line
|
|
|
|
RowEntryList current_row_;
|
2015-09-15 04:56:01 +00:00
|
|
|
///
|
|
|
|
bool enabled_;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2015-10-13 23:17:05 +00:00
|
|
|
bool operator==(TexRow::RowEntry const &, TexRow::RowEntry const &);
|
|
|
|
|
2015-09-15 04:56:01 +00:00
|
|
|
LyXErr & operator<<(LyXErr &, TexRow &);
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2002-05-30 03:37:24 +00:00
|
|
|
#endif // TEXROW_H
|