]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlInset.h
The reducing file dependencies in the frontends patch.
[lyx.git] / src / frontends / controllers / ControlInset.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2001 The LyX Team.
8  *
9  * ======================================================
10  *
11  * \file ControlInsets.h
12  * \author Angus Leeming <a.leeming@ic.ac.uk>
13  *
14  * ControlInset is to be used as a parent class for dialogs that display and
15  * can perhaps modify the contents of an individual inset. An example being the
16  * ubiquitous Citation dialog.
17  */
18
19 #ifndef CONTROLINSET_H
20 #define CONTROLINSET_H
21
22 #include "ControlConnections.h"
23
24 class Inset;
25
26 template <class Inset, class Params>
27 class ControlInset : public ControlConnectBD
28 {
29 public:
30         ///
31         ControlInset(LyXView &, Dialogs &);
32         /// Allow the View access to the local copy.
33         Params & params();
34         ///
35         Params const & params() const;
36
37 protected:
38         /// Slots connected in the daughter classes c-tor.
39         /// Slot launching dialog to (possibly) create a new inset.
40         void createInset(string const &);
41         /// Slot launching dialog to an existing inset.
42         void showInset(Inset *);
43         /// Allow the daughter methods to access the inset.
44         Inset * inset() const;
45
46 private:
47         /** These 7 methods are all that the individual daughter classes
48             should need to instantiate. */
49
50         /// if the inset exists then do this...
51         virtual void applyParamsToInset() = 0;
52         /// else this...
53         virtual void applyParamsNoInset() = 0;
54
55         /// get the parameters from the string passed to createInset.
56         virtual Params const getParams(string const &) = 0;
57         /// get the parameters from the inset passed to showInset.
58         virtual Params const getParams(Inset const &) = 0;
59
60         /** Most derived classes won't need these two, so they default to empty.
61          */
62
63         /// set any daughter class-particular data on show().
64         virtual void setDaughterParams() {}
65         /// clean-up any daughter class-particular data on hide().
66         virtual void clearDaughterParams() {}
67
68         /** Some dialogs may find it beneficial to disconnect from the inset
69          when the Apply button is pressed. E.g., doing this with the citation
70          dialog allows multiple citiations to be inserted easily. */
71         virtual bool disconnectOnApply() { return false; }
72
73
74         
75         /// Instantiation of ControlButtons virtual methods.
76
77         /// Get changed parameters and Dispatch them to the kernel.
78         virtual void apply();
79         /// Disconnect signals and hide View.
80         virtual void hide();
81         /// Update the dialog.
82         virtual void update();
83
84         /** Instantiation of ControlConnectBD private virtual method.
85             Slot connected to update signal. */
86         virtual void updateSlot(bool);
87
88         /// Show the dialog.
89         void show(Params const &);
90         /// Connect signals
91         void connectInset(Inset * = 0);
92
93         /// pointer to the inset passed through connectInset
94         Inset * inset_; 
95         /// inset::hide connection.
96         SigC::Connection ih_;
97         /** A local copy of the inset's params.
98             Memory is allocated only whilst the dialog is visible.
99         */
100         Params * params_;
101
102         /// is the dialog built ?
103         bool dialog_built_;
104  
105 };
106
107
108 #endif // CONTROLINSET_H