]> git.lyx.org Git - lyx.git/blob - src/insets/insetbase.h
Enable the external inset to handle unknown templates gracefully.
[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 <vector>
16
17 class BufferView;
18 class FuncRequest;
19 class MetricsInfo;
20 class Dimension;
21 class PainterInfo;
22 class LaTeXFeatures;
23
24 /** Dispatch result codes
25                 DISPATCHED          = the inset catched the action
26                 DISPATCHED_NOUPDATE = the inset catched the action and no update
27                                 is needed here to redraw the inset
28                 FINISHED            = the inset must be unlocked as a result
29                                 of the action
30                 FINISHED_RIGHT      = FINISHED, but put the cursor to the RIGHT of
31                                 the inset.
32                 FINISHED_UP         = FINISHED, but put the cursor UP of
33                                 the inset.
34                 FINISHED_DOWN       = FINISHED, but put the cursor DOWN of
35                                 the inset.
36                 UNDISPATCHED        = the action was not catched, it should be
37                                 dispatched by lower level insets
38 */
39 enum dispatch_result {
40         UNDISPATCHED = 0,
41         DISPATCHED,
42         DISPATCHED_NOUPDATE,
43         FINISHED,
44         FINISHED_RIGHT,
45         FINISHED_UP,
46         FINISHED_DOWN,
47         DISPATCHED_POP
48 };
49
50
51 /// Common base class to all insets
52 class InsetBase {
53 public:
54         ///
55         typedef int      difference_type;
56         /// short of anything else reasonable
57         typedef size_t   size_type;
58         /// type for cell indices
59         typedef size_t  idx_type;
60         /// type for cursor positions
61         typedef size_t  pos_type;
62         /// type for row numbers
63         typedef size_t  row_type;
64         /// type for column numbers
65         typedef size_t  col_type;
66
67         // the real dispatcher
68         virtual dispatch_result dispatch
69                 (FuncRequest const & cmd, idx_type & idx, pos_type & pos);
70
71         /// small wrapper for the time being
72         virtual dispatch_result localDispatch(FuncRequest const & cmd);
73         /// compute the size of the object returned in dim
74         virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
75         /// draw inset and update (xo, yo)-cache
76         virtual void draw(PainterInfo & pi, int x, int y) const = 0;
77
78         ///
79         virtual ~InsetBase() {}
80
81         /// Methods to cache and retrieve a cached BufferView.
82         virtual void cache(BufferView *) const {}
83         ///
84         virtual BufferView * view() const { return 0; }
85         /// request "external features"
86         virtual void validate(LaTeXFeatures &) const {}
87 };
88
89 #endif