// -*- C++ -*-
-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
+/**
+ * \file insettabular.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * Copyright 1995-2000 The LyX Team.
+ * \author Jürgen Vigna
*
- *======================================================
+ * Full author contact details are available in file CREDITS.
*/
-// This is the rewrite of the tabular (table) support.
-// It will probably be a lot of work.
-// One first goal could be to make the inset read the old table format
-// and just output it again... no viewing at all.
+// This is Juergen's rewrite of the tabular (table) support.
-// When making the internal structure of tabular support I really think
-// that STL containers should be used. This will separate the container from
-// the rest of the code, which is a good thing.
-
-// Ideally the tabular support should do as the mathed and use
-// LaTeX in the .lyx file too.
-
-// Things to think of when desingning the new tabular support:
+// Things to think of when designing the new tabular support:
// - color support (colortbl, color)
// - decimal alignment (dcloumn)
// - custom lines (hhline)
// This is what I have written about tabular support in the LyX3-Tasks file:
//
// o rewrite of table code. Should probably be written as some
-// kind of an inset. At least get the code out of the kernel.
-// - colortbl -multirow
-// - hhline -multicolumn
-// - dcolumn
+// kind of an inset. [Done]
// o enhance longtable support
// Lgb
#ifndef INSETTABULAR_H
#define INSETTABULAR_H
-#include <sigc++/signal_system.h>
-#include <boost/smart_ptr.hpp>
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include "lyxinset.h"
+#include "inset.h"
#include "tabular.h"
-#include "LString.h"
-#include "lyxcursor.h"
-#include "lyxfunc.h"
+#include "mailinset.h"
+namespace lyx {
+
+class FuncStatus;
class LyXLex;
-class Painter;
class BufferView;
class Buffer;
+class BufferParams;
+class Paragraph;
+class CursorSlice;
+
+namespace frontend { class Painter; }
-class InsetTabular : public UpdatableInset {
+class InsetTabular : public InsetOld {
public:
///
- enum UpdateCodes {
- NONE = 0,
- CURSOR = 1,
- CELL = 2,
- SELECTION = 3,
- FULL = 4,
- INIT = 5
- };
- ///
- InsetTabular(Buffer const &, int rows = 1, int columns = 1);
- ///
- InsetTabular(InsetTabular const &, Buffer const &);
+ InsetTabular(Buffer const &, row_type rows = 1,
+ col_type columns = 1);
///
~InsetTabular();
///
- Inset * Clone(Buffer const &) const;
- ///
- void Read(Buffer const *, LyXLex &);
- ///
- void Write(Buffer const *, std::ostream &) const;
- ///
- int ascent(BufferView *, LyXFont const &) const;
- ///
- int descent(BufferView *, LyXFont const &) const;
- ///
- int width(BufferView *, LyXFont const & f) const;
- ///
- void draw(BufferView *, const LyXFont &, int , float &, bool) const;
- ///
- void update(BufferView *, LyXFont const &, bool = false);
- ///
- string const EditMessage() const;
+ void read(Buffer const &, LyXLex &);
///
- void Edit(BufferView *, int x, int y, unsigned int);
+ void write(Buffer const &, std::ostream &) const;
///
- bool doClearArea() const { return !locked; };
+ bool metrics(MetricsInfo &, Dimension &) const;
///
- void InsetUnlock(BufferView *);
+ void draw(PainterInfo & pi, int x, int y) const;
///
- void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty) const;
+ void drawSelection(PainterInfo & pi, int x, int y) const;
///
- bool LockInsetInInset(BufferView *, UpdatableInset *);
+ virtual docstring const editMessage() const;
///
- bool UnlockInsetInInset(BufferView *, UpdatableInset *,
- bool lr = false);
+ EDITABLE editable() const { return HIGHLY_EDITABLE; }
///
- bool UpdateInsetInInset(BufferView *, Inset *);
+ bool insetAllowed(InsetBase::Code) const { return true; }
///
- unsigned int InsetInInsetY();
+ bool allowSpellCheck() const { return true; }
///
- UpdatableInset * GetLockingInset();
+ bool canTrackChanges() const { return true; }
+ /** returns true if, when outputing LaTeX, font changes should
+ be closed before generating this inset. This is needed for
+ insets that may contain several paragraphs */
+ bool noFontChange() const { return true; }
///
- UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
+ bool display() const { return tabular.isLongTabular(); }
///
- bool InsertInset(BufferView *, Inset *);
+ int latex(Buffer const &, odocstream &,
+ OutputParams const &) const;
///
- bool IsTextInset() const { return true; }
+ int plaintext(Buffer const &, odocstream &,
+ OutputParams const &) const;
///
- bool display() const { return tabular->IsLongTabular(); }
+ int docbook(Buffer const &, odocstream &,
+ OutputParams const &) const;
///
- void InsetButtonRelease(BufferView *, int, int, int);
+ void validate(LaTeXFeatures & features) const;
///
- void InsetButtonPress(BufferView *, int, int, int);
+ Code lyxCode() const { return InsetBase::TABULAR_CODE; }
+ /// get offset of this cursor slice relative to our upper left corner
+ void cursorPos(BufferView const & bv, CursorSlice const & sl,
+ bool boundary, int & x, int & y) const;
///
- void InsetMotionNotify(BufferView *, int, int, int);
+ bool tabularFeatures(LCursor & cur, std::string const & what);
///
- void InsetKeyPress(XKeyEvent *);
+ void tabularFeatures(LCursor & cur, LyXTabular::Feature feature,
+ std::string const & val = std::string());
///
- UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action,
- string const &);
+ void openLayoutDialog(BufferView *) const;
///
- int Latex(Buffer const *, std::ostream &, bool, bool) const;
+ bool showInsetDialog(BufferView *) const;
+ /// number of cells
+ size_t nargs() const { return tabular.getNumberOfCells(); }
///
- int Ascii(Buffer const *, std::ostream &, int linelen) const;
+ boost::shared_ptr<InsetText const> cell(idx_type) const;
///
- int Linuxdoc(Buffer const *, std::ostream &) const;
+ boost::shared_ptr<InsetText> cell(idx_type);
///
- int DocBook(Buffer const *, std::ostream &) const;
- ///
- void Validate(LaTeXFeatures & features) const;
- ///
- Inset::Code LyxCode() const { return Inset::TABULAR_CODE; }
- ///
- void GetCursorPos(BufferView *, int & x, int & y) const;
- ///
- void ToggleInsetCursor(BufferView *);
- ///
- bool TabularFeatures(BufferView * bv, string const & what);
- ///
- void TabularFeatures(BufferView * bv, LyXTabular::Feature feature,
- string const & val = string());
- ///
- int GetActCell() const { return actcell; }
- ///
- void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
- ///
- int getMaxWidth(BufferView *, UpdatableInset const *) const;
- ///
- Buffer * BufferOwner() const { return const_cast<Buffer *>(buffer); }
- ///
- LyXText * getLyXText(BufferView const *,
- bool const recursive = false) const;
- ///
- void resizeLyXText(BufferView *) const;
+ LyXText * getText(int) const;
+
+ /// set the change for the entire inset
+ void setChange(Change const & change);
+ /// accept the changes within the inset
+ void acceptChanges();
+ /// reject the changes within the inset
+ void rejectChanges();
+
+ // this should return true if we have a "normal" cell, otherwise false.
+ // "normal" means without width set!
+ /// should all paragraphs be output with "Standard" layout?
+ bool forceDefaultParagraphs(idx_type cell = 0) const;
+
///
- void OpenLayoutDialog(BufferView *) const;
+ void addPreview(graphics::PreviewLoader &) const;
+
///
- bool ShowInsetDialog(BufferView *) const;
+ Buffer const & buffer() const;
+
+ /// set the owning buffer
+ void buffer(Buffer const * buf);
+ /// lock cell with given index
+ void edit(LCursor & cur, bool left);
///
- LyXFunc::func_status getStatus(string const & argument) const;
+ InsetBase * editXY(LCursor & cur, int x, int y);
+ /// can we go further down on mouse click?
+ bool descendable() const { return true; }
//
// Public structures and variables
///
- //LyXTabular * tabular;
- boost::scoped_ptr<LyXTabular> tabular;
- ///
- SigC::Signal0<void> hideDialog;
+ mutable LyXTabular tabular;
-private:
- ///
- bool calculate_dimensions_of_cells(BufferView *, LyXFont const &,
- bool = false) const;
- ///
- void DrawCellLines(Painter &, int x, int baseline,
- int row, int cell) const;
- ///
- void DrawCellSelection(Painter &, int x, int baseline,
- int row, int column, int cell) const;
- ///
- void ShowInsetCursor(BufferView *, bool show=true);
- ///
- void HideInsetCursor(BufferView *);
- ///
- void setPos(BufferView *, int x, int y) const;
+protected:
///
- UpdatableInset::RESULT moveRight(BufferView *, bool lock = true);
+ InsetTabular(InsetTabular const &);
///
- UpdatableInset::RESULT moveLeft(BufferView *, bool lock = true);
+ virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
///
- UpdatableInset::RESULT moveUp(BufferView *, bool lock = true);
+ bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
///
- UpdatableInset::RESULT moveDown(BufferView *, bool lock = true);
- ///
- bool moveNextCell(BufferView *, bool lock = false);
- ///
- bool movePrevCell(BufferView *, bool lock = false);
- ///
- bool Delete();
- ///
- int getCellXPos(int cell) const;
+ int scroll() const { return scx_; }
+
+private:
+ virtual std::auto_ptr<InsetBase> doClone() const;
+
///
- void resetPos(BufferView *) const;
+ void drawCellLines(frontend::Painter &, int x, int y, row_type row,
+ idx_type cell, bool erased) const;
///
- void RemoveTabularRow();
+ void setCursorFromCoordinates(LCursor & cur, int x, int y) const;
+
///
- bool hasSelection() const {
- return sel_cell_start != sel_cell_end;
- }
+ void moveNextCell(LCursor & cur);
///
- void clearSelection() const {
- sel_cell_start = sel_cell_end = 0;
- }
+ void movePrevCell(LCursor & cur);
///
- bool ActivateCellInset(BufferView *, int x = 0, int y = 0, int button = 0,
- bool behind = false);
+ int getCellXPos(idx_type cell) const;
///
- bool ActivateCellInsetAbs(BufferView *, int x = 0, int y=0, int button=0);
+ void resetPos(LCursor & cur) const;
///
- bool InsetHit(BufferView * bv, int x, int y) const;
+ void removeTabularRow();
///
- int GetMaxWidthOfCell(BufferView * bv, int cell) const;
+ bool copySelection(LCursor & cur);
///
- bool hasPasteBuffer() const;
+ bool pasteSelection(LCursor & cur);
///
- bool copySelection(BufferView *);
+ void cutSelection(LCursor & cur);
///
- bool pasteSelection(BufferView *);
+ bool isRightToLeft(LCursor & cur) const;
///
- bool cutSelection();
+ void getSelection(LCursor & cur, row_type & rs, row_type & re,
+ col_type & cs, col_type & ce) const;
///
- bool isRightToLeft(BufferView *);
+ bool insertPlaintextString(BufferView &, docstring const & buf, bool usePaste);
+ /// are we operating on several cells?
+ bool tablemode(LCursor & cur) const;
+
+ /// return the "Manhattan distance" to nearest corner
+ int dist(BufferView &, idx_type cell, int x, int y) const;
+ /// return the cell nearest to x, y
+ idx_type getNearestCell(BufferView &, int x, int y) const;
- //
- // Private structures and variables
- ///
- InsetText * the_locking_inset;
- ///
- InsetText * old_locking_inset;
- ///
- Buffer const * buffer;
- ///
- mutable LyXCursor cursor;
- ///
- mutable unsigned int inset_x;
- ///
- mutable unsigned int inset_y;
///
- mutable int sel_cell_start;
+ Buffer const * buffer_;
///
- mutable int sel_cell_end;
+ mutable idx_type first_visible_cell;
///
- mutable int actcell;
+ mutable int scx_;
+};
+
+
+class InsetTabularMailer : public MailInset {
+public:
///
- mutable int oldcell;
+ InsetTabularMailer(InsetTabular const & inset);
///
- mutable int actcol;
+ virtual InsetBase & inset() const { return inset_; }
///
- mutable int actrow;
+ virtual std::string const & name() const { return name_; }
///
- mutable int first_visible_cell;
+ virtual std::string const inset2string(Buffer const &) const;
///
- bool no_selection;
+ static void string2params(std::string const &, InsetTabular &);
///
- bool no_draw;
+ static std::string const params2string(InsetTabular const &);
+private:
///
- mutable bool locked;
+ static std::string const name_;
///
- mutable UpdateCodes need_update;
+ InsetTabular & inset_;
};
+
+std::string const featureAsString(LyXTabular::Feature feature);
+
+} // namespace lyx
+
#endif