2000-02-25 12:06:15 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
2000-02-25 13:35:38 +00:00
|
|
|
* Copyright 1998 The LyX Team.
|
2000-02-25 12:06:15 +00:00
|
|
|
*
|
|
|
|
*======================================================
|
|
|
|
*/
|
|
|
|
// The pristine updatable inset: Text
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef INSETTEXT_H
|
|
|
|
#define INSETTEXT_H
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "lyxinset.h"
|
|
|
|
#include "LString.h"
|
2000-04-19 14:42:19 +00:00
|
|
|
#include "lyxparagraph.h"
|
|
|
|
#include "lyxcursor.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
class Painter;
|
|
|
|
class BufferView;
|
2000-03-08 13:52:57 +00:00
|
|
|
class Buffer;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
/** A text inset is like a TeX box
|
|
|
|
|
|
|
|
To write full text (including styles and other insets) in a given
|
|
|
|
space.
|
|
|
|
*/
|
|
|
|
class InsetText : public UpdatableInset {
|
|
|
|
public:
|
|
|
|
///
|
2000-05-04 08:14:34 +00:00
|
|
|
enum { TEXT_TO_INSET_OFFSET = 1 };
|
|
|
|
///
|
|
|
|
explicit
|
2000-02-25 12:06:15 +00:00
|
|
|
InsetText(Buffer *);
|
|
|
|
///
|
|
|
|
InsetText(InsetText const &, Buffer *);
|
|
|
|
///
|
|
|
|
~InsetText();
|
|
|
|
///
|
2000-02-25 16:42:21 +00:00
|
|
|
Inset * Clone() const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
void clear() const { par->clearContents(); }
|
|
|
|
///
|
2000-02-25 12:06:15 +00:00
|
|
|
void Read(LyXLex &);
|
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
void Write(std::ostream &) const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
int ascent(Painter &, LyXFont const &) const;
|
|
|
|
///
|
|
|
|
int descent(Painter &, LyXFont const &) const;
|
|
|
|
///
|
|
|
|
int width(Painter &, LyXFont const & f) const;
|
|
|
|
///
|
2000-02-25 13:35:38 +00:00
|
|
|
void draw(Painter & pain, LyXFont const &, int , float &) const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-02-25 13:35:38 +00:00
|
|
|
char const * EditMessage() const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
void Edit(BufferView *, int, int, unsigned int);
|
|
|
|
///
|
|
|
|
void InsetUnlock(BufferView *);
|
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
bool LockInsetInInset(BufferView *, UpdatableInset *);
|
|
|
|
///
|
|
|
|
bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
bool UpdateInsetInInset(BufferView *, Inset *);
|
|
|
|
///
|
|
|
|
void InsetButtonRelease(BufferView *, int, int, int);
|
|
|
|
///
|
|
|
|
void InsetButtonPress(BufferView *, int, int, int);
|
|
|
|
///
|
|
|
|
void InsetMotionNotify(BufferView *, int, int, int);
|
|
|
|
///
|
|
|
|
void InsetKeyPress(XKeyEvent *);
|
|
|
|
///
|
2000-02-25 13:35:38 +00:00
|
|
|
UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-04-19 01:42:55 +00:00
|
|
|
int Latex(std::ostream &, bool fragile, bool free_spc) const;
|
2000-03-06 02:42:40 +00:00
|
|
|
///
|
2000-04-24 20:58:23 +00:00
|
|
|
int Ascii(std::ostream &) const { return 0; }
|
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
int Linuxdoc(std::ostream &) const { return 0; }
|
2000-03-06 02:42:40 +00:00
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
int DocBook(std::ostream &) const { return 0; }
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
void Validate(LaTeXFeatures & features) const;
|
|
|
|
///
|
|
|
|
Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
|
|
|
|
///
|
2000-02-25 16:42:21 +00:00
|
|
|
void GetCursorPos(int & x, int & y) const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
int InsetInInsetY();
|
|
|
|
///
|
|
|
|
void ToggleInsetCursor(BufferView *);
|
|
|
|
///
|
|
|
|
bool InsertInset(BufferView *, Inset *);
|
|
|
|
///
|
|
|
|
UpdatableInset * GetLockingInset();
|
|
|
|
///
|
|
|
|
void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
|
2000-03-28 16:18:02 +00:00
|
|
|
///
|
2000-04-10 14:29:05 +00:00
|
|
|
void init(Buffer *, InsetText const * ins = 0);
|
2000-05-04 08:14:34 +00:00
|
|
|
///
|
|
|
|
void SetParagraphData(LyXParagraph *);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
LyXParagraph * par;
|
|
|
|
|
|
|
|
protected:
|
2000-03-08 13:52:57 +00:00
|
|
|
///
|
|
|
|
void UpdateLocal(BufferView *, bool);
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
void WriteParagraphData(std::ostream &) const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
void resetPos(Painter &) const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-02-25 16:05:26 +00:00
|
|
|
void drawSelection(Painter &, int pos, int baseline, float x);
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-02-25 16:05:26 +00:00
|
|
|
void SingleHeight(Painter &, LyXParagraph * par,int pos,
|
|
|
|
int & asc, int & desc) const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-02-25 16:05:26 +00:00
|
|
|
int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
LyXFont GetFont(LyXParagraph * par, int pos) const;
|
2000-04-10 14:29:05 +00:00
|
|
|
///
|
|
|
|
virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
|
2000-04-19 14:42:19 +00:00
|
|
|
///
|
|
|
|
virtual int getMaxTextWidth(Painter &, UpdatableInset const *,
|
|
|
|
int x=0) const;
|
2000-03-08 13:52:57 +00:00
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
Buffer * buffer;
|
|
|
|
///
|
|
|
|
LyXFont current_font;
|
2000-02-25 16:05:26 +00:00
|
|
|
///
|
|
|
|
LyXFont real_current_font;
|
|
|
|
///
|
|
|
|
mutable int maxAscent;
|
|
|
|
///
|
|
|
|
mutable int maxDescent;
|
|
|
|
///
|
|
|
|
mutable int insetWidth;
|
2000-03-02 18:30:01 +00:00
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
mutable int drawTextXOffset;
|
|
|
|
mutable int drawTextYOffset;
|
2000-03-08 13:52:57 +00:00
|
|
|
///
|
2000-03-02 18:30:01 +00:00
|
|
|
bool autoBreakRows;
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
void drawRowSelection(Painter &, int startpos, int endpos, int row,
|
|
|
|
int baseline, float x) const;
|
|
|
|
///
|
|
|
|
void drawRowText(Painter &, int startpos, int endpos, int baseline,
|
|
|
|
float x) const;
|
|
|
|
///
|
2000-03-06 02:42:40 +00:00
|
|
|
void computeTextRows(Painter &, float x = 0.0) const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
void computeBaselines(int) const;
|
|
|
|
///
|
|
|
|
int BeginningOfMainBody(LyXParagraph * par) const;
|
|
|
|
///
|
|
|
|
void ShowInsetCursor(BufferView *);
|
|
|
|
///
|
|
|
|
void HideInsetCursor(BufferView *);
|
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
void setPos(Painter &, int x, int y) const;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
|
|
|
|
UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
|
|
|
|
UpdatableInset::RESULT moveUp(BufferView *);
|
|
|
|
UpdatableInset::RESULT moveDown(BufferView *);
|
2000-02-25 12:06:15 +00:00
|
|
|
bool Delete();
|
2000-03-27 15:13:47 +00:00
|
|
|
bool cutSelection();
|
|
|
|
bool copySelection();
|
|
|
|
bool pasteSelection();
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-05-04 08:14:34 +00:00
|
|
|
bool hasSelection() const
|
|
|
|
{ return (selection_start_cursor != selection_end_cursor); }
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-02-25 13:35:38 +00:00
|
|
|
void SetCharFont(int pos, LyXFont const & font);
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
string getText(int);
|
2000-04-19 14:42:19 +00:00
|
|
|
///
|
|
|
|
bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
|
|
|
|
int button = 0);
|
2000-02-25 12:06:15 +00:00
|
|
|
|
|
|
|
/* Private structures and variables */
|
|
|
|
///
|
|
|
|
int inset_pos;
|
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
mutable int inset_x;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
mutable int inset_y;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
int interline_space;
|
|
|
|
///
|
2000-05-04 08:14:34 +00:00
|
|
|
LyXCursor selection_start_cursor;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-05-04 08:14:34 +00:00
|
|
|
LyXCursor selection_end_cursor;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
mutable LyXCursor cursor;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
mutable LyXCursor old_cursor;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
mutable int actrow;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
bool no_selection;
|
|
|
|
///
|
2000-03-08 13:52:57 +00:00
|
|
|
mutable float xpos;
|
|
|
|
///
|
2000-02-25 16:05:26 +00:00
|
|
|
mutable bool init_inset;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
UpdatableInset * the_locking_inset;
|
|
|
|
///
|
|
|
|
struct row_struct {
|
|
|
|
///
|
|
|
|
int asc;
|
|
|
|
///
|
|
|
|
int desc;
|
|
|
|
///
|
|
|
|
int pos;
|
|
|
|
///
|
|
|
|
int baseline;
|
|
|
|
};
|
|
|
|
///
|
2000-04-04 00:19:15 +00:00
|
|
|
typedef std::vector<row_struct> RowList;
|
2000-02-25 12:06:15 +00:00
|
|
|
///
|
|
|
|
mutable RowList rows;
|
|
|
|
InsetText & operator = (InsetText const & it) {
|
|
|
|
par = it.par;
|
|
|
|
buffer = it.buffer; // suspect
|
|
|
|
current_font = it.current_font;
|
|
|
|
real_current_font = it.real_current_font;
|
|
|
|
maxAscent = it.maxAscent;
|
|
|
|
maxDescent = it.maxDescent;
|
|
|
|
insetWidth = it.insetWidth;
|
|
|
|
inset_pos = it.inset_pos;
|
|
|
|
inset_x = it.inset_x;
|
|
|
|
inset_y = it.inset_y;
|
|
|
|
interline_space = it.interline_space;
|
2000-05-04 08:14:34 +00:00
|
|
|
selection_start_cursor = selection_end_cursor = cursor = it.cursor;
|
2000-02-25 12:06:15 +00:00
|
|
|
actrow = it.actrow;
|
|
|
|
no_selection = it.no_selection;
|
|
|
|
the_locking_inset = it.the_locking_inset; // suspect
|
|
|
|
rows = it.rows;
|
|
|
|
return * this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|