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