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