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