]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/Kernel.h
fix scrolling bug: 3320 and 3652, maybe not perfect
[lyx.git] / src / frontends / controllers / Kernel.h
1 // -*- C++ -*-
2 /**
3  * \file Kernel.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef KERNEL_H
13 #define KERNEL_H
14
15 #include <string>
16
17 namespace lyx {
18
19 class Buffer;
20 class BufferView;
21 class FuncRequest;
22 class LyXView;
23
24 namespace frontend {
25
26 /** \c Kernel is a wrapper making the LyX kernel available to the dialog.
27  * (Ie, it provides an interface to the Model part of the Model-Controller-
28  *  View split.
29  *  In an ideal world, it will shrink as more info is passed to the
30  *  Dialog::show() and Dialog::update() methods.
31  */
32 class Kernel {
33 public:
34         /// \param lv is the access point for the dialog to the LyX kernel.
35         Kernel(LyXView & lv);
36
37         /** This method is the primary purpose of the class. It provides
38          *  the "gateway" by which the dialog can send a request (of a
39          *  change in the data, for more information) to the kernel.
40          *  \param fr is the encoding of the request.
41          */
42         void dispatch(FuncRequest const & fr) const;
43
44         /** The dialog has received a request from the user
45          *  (who pressed the "Restore" button) to update contents.
46          *  It must, therefore, ask the kernel to provide this information.
47          *  \param name is used to identify the dialog to the kernel.
48          */
49         void updateDialog(std::string const & name) const;
50
51         /** A request from the Controller that future changes to the data
52          *  stored by the dialog are not applied to the inset currently
53          *  connected to the dialog. Instead, they will be used to generate
54          *  a new inset at the cursor position.
55          *  \param name is used to identify the dialog to the kernel.
56          */
57         void disconnect(std::string const & name) const;
58
59         /** \name Kernel Wrappers
60          *  Simple wrapper functions to Buffer methods.
61          */
62         //@{
63         bool isBufferAvailable() const;
64         bool isBufferReadonly() const;
65         std::string const bufferFilepath() const;
66         //@}
67
68         /** \enum DocType used to flag the different kinds of buffer
69          *  without making the kernel header files available to the
70          *  dialog's Controller or View.
71          */
72         enum DocType {
73                 LATEX,
74                 LITERATE,
75                 DOCBOOK
76         };
77         /// The type of the current buffer.
78         DocType docType() const;
79
80         /** \name Kernel Nasties
81          *  Unpleasantly public internals of the LyX kernel.
82          *  We should aim to reduce/remove these from the interface.
83          */
84         //@{
85         LyXView & lyxview() { return lyxview_; }
86         LyXView const & lyxview() const { return lyxview_; }
87
88         Buffer & buffer();
89         Buffer const & buffer() const;
90
91         BufferView * bufferview();
92         BufferView const * bufferview() const;
93         //@}
94
95 private:
96         LyXView & lyxview_;
97 };
98
99
100 /** \c KernelDocType is a wrapper for Kernel::DocType.
101  *  It can be forward-declared and passed as a function argument without
102  *  having to expose Kernel.h.
103  */
104 class KernelDocType {
105 public:
106         KernelDocType(Kernel::DocType val) : val_(val) {}
107         operator Kernel::DocType() const { return val_; }
108 private:
109         Kernel::DocType val_;
110 };
111
112 } // namespace frontend
113 } // namespace lyx
114
115 #endif // KERNEL_H