1 // -*- C++ -*-
2 /**
3  * \file InsetMathSideset.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author André Pönitz
8  * \author Georg Baum
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12 
13 #ifndef MATH_SIDESETINSET_H
14 #define MATH_SIDESETINSET_H
15 
16 #include "InsetMathNest.h"
17 
18 
19 namespace lyx {
20 
21 
22 /// An inset for amsmath \sideset. The 'nucleus' is always cell 0.
23 /// cell(1) is the bottom left index, cell(2) is the top left index,
24 /// cell(3) is the bottom right index, and cell(4) is top right index.
25 class InsetMathSideset : public InsetMathNest {
26 public:
27 	///
28 	InsetMathSideset(Buffer * buf, bool scriptl, bool scriptr);
29 	/// create inset with given nucleus
30 	InsetMathSideset(Buffer * buf, bool scriptl, bool scriptr,
31 	                 MathAtom const & at);
32 	///
currentMode()33 	mode_type currentMode() const { return MATH_MODE; }
34 	///
35 	void metrics(MetricsInfo & mi, Dimension & dim) const;
36 	///
37 	void draw(PainterInfo & pi, int x, int y) const;
38 	///
39 	void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
40 	///
41 	void drawT(TextPainter & pi, int x, int y) const;
42 
43 	/// move cursor backwards
44 	bool idxBackward(Cursor & cur) const;
45 	/// move cursor forward
46 	bool idxForward(Cursor & cur) const;
47 	/// move cursor up or down
48 	bool idxUpDown(Cursor & cur, bool up) const;
49 	/// Target pos when we enter the inset while moving forward
50 	bool idxFirst(Cursor & cur) const;
51 	/// Target pos when we enter the inset while moving backwards
52 	bool idxLast(Cursor & cur) const;
53 
54 	/// write LaTeX and Lyx code
55 	void write(WriteStream & os) const;
56 	/// write normalized content
57 	void normalize(NormalStream &) const;
58 	/// write content as MathML
59 	void mathmlize(MathStream &) const;
60 	/// write content as HTML
61 	void htmlize(HtmlStream &) const;
62 
63 	/// returns nucleus
nuc()64 	MathData const & nuc() const { return cell(0); }
65 	/// returns nucleus
nuc()66 	MathData & nuc()             { return cell(0); }
67 	/// bottom left index or single left cell
bl()68 	MathData const & bl() const  { return cell(1); }
69 	/// bottom left index or single left cell
bl()70 	MathData & bl()              { return cell(1); }
71 	/// top left index or single left cell
tl()72 	MathData const & tl() const  { return cell(1 + scriptl_); }
73 	/// top left index or single left cell
tl()74 	MathData & tl()              { return cell(1 + scriptl_); }
75 	/// bottom right index or single right cell
br()76 	MathData const & br() const  { return cell(2 + scriptl_); }
77 	/// bottom right index or single right cell
br()78 	MathData & br()              { return cell(2 + scriptl_); }
79 	/// top right index or single right cell
tr()80 	MathData const & tr() const  { return cell(2 + scriptl_ + scriptr_); }
81 	/// top right index or single right cell
tr()82 	MathData & tr()              { return cell(2 + scriptl_ + scriptr_); }
83 	/// say that we have scripts
84 	void infoize(odocstream & os) const;
85 	///
lyxCode()86 	InsetCode lyxCode() const { return MATH_SCRIPT_CODE; }
87 	///
88 	void validate(LaTeXFeatures &features) const;
89 private:
90 	virtual Inset * clone() const;
91 	/// returns x offset of nucleus
92 	int dxn(BufferView const & bv) const;
93 	/// returns width of nucleus if any
94 	int nwid(BufferView const &) const;
95 	/// returns y offset for either superscript or subscript
96 	int dybt(BufferView const &, int asc, int des, bool top) const;
97 	/// returns y offset for superscript
98 	int dyt(BufferView const &) const;
99 	/// returns y offset for subscript
100 	int dyb(BufferView const &) const;
101 	/// returns x offset for right subscript and superscript
102 	int dxr(BufferView const & bv) const;
103 	/// returns ascent of nucleus if any
104 	int nasc(BufferView const &) const;
105 	/// returns descent of nucleus if any
106 	int ndes(BufferView const &) const;
107 	/// Italic correction as described in InsetMathScript.h
108 	int nker(BufferView const * bv) const;
109 	/// Whether there are two left scripts or one single cell
110 	bool scriptl_;
111 	/// Whether there are two right scripts or one single cell
112 	bool scriptr_;
113 };
114 
115 
116 } // namespace lyx
117 
118 #endif
119