]> git.lyx.org Git - lyx.git/blob - src/insets/insetbase.h
771ff610fa74110866f610ecb4154a4f6a8557c9
[lyx.git] / src / insets / insetbase.h
1 // -*- C++ -*-
2 /**
3  * \file insetbase.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author none
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSETBASE_H
13 #define INSETBASE_H
14
15 #include <string>
16 #include <vector>
17 #include <memory>
18
19 class Buffer;
20 class BufferView;
21 class DispatchResult;
22 class FuncRequest;
23 class LaTeXFeatures;
24 class MathInset;
25 class MetricsInfo;
26 class Dimension;
27 class PainterInfo;
28 class UpdatableInset;
29
30 /// Common base class to all insets
31 class InsetBase {
32 public:
33         ///
34         typedef ptrdiff_t  difference_type;
35         /// short of anything else reasonable
36         typedef size_t     size_type;
37         /// type for cell indices
38         typedef size_t     idx_type;
39         /// type for cursor positions
40         typedef ptrdiff_t  pos_type;
41         /// type for row numbers
42         typedef size_t     row_type;
43         /// type for column numbers
44         typedef size_t     col_type;
45
46         /// virtual base class destructor
47         virtual ~InsetBase() {}
48         /// replicate ourselves
49         virtual std::auto_ptr<InsetBase> clone() const = 0;
50
51         /// identification as math inset
52         virtual MathInset * asMathInset() { return 0; }
53         /// identification as non-math inset
54         virtual UpdatableInset * asUpdatableInset() { return 0; }
55
56         // the real dispatcher
57         DispatchResult dispatch(BufferView & bv, FuncRequest const & cmd);
58
59         /// cursor enters
60         virtual void edit(BufferView * bv, bool left);
61         /// cursor enters
62         virtual void edit(BufferView * bv, int x, int y);
63
64         /// compute the size of the object returned in dim
65         virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
66         /// draw inset and update (xo, yo)-cache
67         virtual void draw(PainterInfo & pi, int x, int y) const = 0;
68
69         /// request "external features"
70         virtual void validate(LaTeXFeatures &) const {}
71         /// Appends \c list with all labels found within this inset.
72         virtual void getLabelList(Buffer const &,
73                                   std::vector<std::string> & /* list */) const {}
74         /// last drawn position for 'important' insets
75         virtual int x() const { return 0; }
76         /// last drawn position for 'important' insets
77         virtual int y() const { return 0; }
78  
79         /// number of embedded cells
80         virtual size_t nargs() const { return 0; }
81         /// number of rows in gridlike structures
82         virtual size_t nrows() const { return 0; }
83         /// number of columns in gridlike structures
84         virtual size_t ncols() const { return 0; }
85 protected:
86         // the real dispatcher
87         virtual
88         DispatchResult priv_dispatch(BufferView & bv, FuncRequest const & cmd);
89 };
90
91 #endif