]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/FormBase.h
First attempt at converting copyright dialog to MVC architecture
[lyx.git] / src / frontends / qt2 / FormBase.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  *
11  * \author Angus Leeming <a.leeming@ic.ac.uk>
12  */
13
14 #ifndef FORMBASE_H
15 #define FORMBASE_H
16
17 #include <boost/smart_ptr.hpp>
18
19 class QDialog;
20
21 #ifdef __GNUG__
22 #pragma interface
23 #endif
24
25 #include "ViewBase.h"
26 #include "LString.h"
27 #include "ButtonPolicies.h"
28
29 class qt2BC;
30
31 /** This class is an Qt2 GUI base class.
32  */
33 class FormBase : public ViewBC<qt2BC>
34 {
35 public:
36         ///
37         FormBase(ControlBase &, string const &);
38         ///
39         virtual ~FormBase() {}
40
41 protected:
42         /// Build the dialog
43         virtual void build() = 0;
44         /// Hide the dialog.
45         void hide();
46         /// Create the dialog if necessary, update it and display it.
47         void show();
48
49 private:
50         /// Pointer to the actual instantiation of xform's form
51         virtual QDialog* form() const = 0;
52 //      /** Filter the inputs on callback from xforms
53 //          Return true if inputs are valid. */
54 //      virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
55
56 private:
57         /// dialog title, displayed by WM.
58         string title_;
59 };
60
61
62 template <class Dialog>
63 class FormDB: public FormBase
64 {
65 protected:
66         ///
67         FormDB(ControlBase &, string const &);
68         /// Pointer to the actual instantiation of the Qt dialog
69         virtual QDialog* form() const;
70         /// Real GUI implementation.
71         boost::scoped_ptr<Dialog> dialog_;
72 };
73
74
75 template <class Dialog>
76 FormDB<Dialog>::FormDB(ControlBase & c, string const & t)
77         : FormBase(c, t)
78 {}
79
80
81 template <class Dialog>
82 QDialog* FormDB<Dialog>::form() const
83 {
84     return dialog_.get();
85 }
86
87
88 template <class Controller, class Base>
89 class FormCB: public Base
90 {
91 protected:
92         ///
93         FormCB(ControlBase &, string const &);
94         /// The parent controller
95         Controller & controller() const;
96 };
97
98
99 template <class Controller, class Base>
100 FormCB<Controller, Base>::FormCB(ControlBase & c, string const & t)
101         : Base(c, t)
102 {}
103
104
105 template <class Controller, class Base>
106 Controller & FormCB<Controller, Base>::controller() const
107 {
108         return static_cast<Controller &>(controller_);
109         //return dynamic_cast<Controller &>(controller_);
110 }
111
112
113 #endif // FORMBASE_H