]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
More pref work from Angus
[lyx.git] / src / frontends / xforms / 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
12 #ifndef FORMBASE_H
13 #define FORMBASE_H
14
15 #include "DialogBase.h"
16 #include "LString.h"
17 #include <boost/utility.hpp>
18 #include FORMS_H_LOCATION
19 #include "ButtonController.h"
20 #include "gettext.h"
21
22 class Buffer;
23 class Dialogs;
24 class LyXView;
25
26 #ifdef __GNUG__
27 #pragma interface
28 #endif
29
30 /** This class is an XForms GUI base class.
31     It is meant to be used solely as the parent class to FormBaseBI and FormBaseBD
32     @author Angus Leeming
33  */
34 class FormBase : public DialogBase, public noncopyable {
35 public:
36         /// Callback functions
37         static  int WMHideCB(FL_FORM *, void *);
38         ///
39         static void ApplyCB(FL_OBJECT *, long);
40         ///
41         static void OKCB(FL_OBJECT *, long);
42         ///
43         static void CancelCB(FL_OBJECT *, long);
44         ///
45         static void InputCB(FL_OBJECT *, long);
46         ///
47         static void RestoreCB(FL_OBJECT *, long);
48
49 protected: // methods
50         /** Constructor.
51             #FormBase(lv, d, _("DialogName"), BUFFER_DEPENDENT, new ButtonPolicy)#
52          */
53         FormBase(LyXView *, Dialogs *, string const &,
54                  ButtonPolicy *, char const *, char const *);
55         ///
56         virtual ~FormBase();
57
58         /// Create the dialog if necessary, update it and display it.
59         void show();
60         /// Hide the dialog.
61         virtual void hide();
62         /// Update the dialog.
63         virtual void update() {}
64         /// Connect signals. Also perform any necessary initialisation.
65         virtual void connect();
66         /// Disconnect signals. Also perform any necessary housekeeping.
67         virtual void disconnect() = 0;
68         /// Build the dialog
69         virtual void build() = 0;
70         /** Filter the inputs on callback from xforms
71             Return true if inputs are valid.
72          */
73         virtual bool input( FL_OBJECT *, long ) {
74                 return true;
75         }
76         /// Apply from dialog (modify or create inset)
77         virtual void apply() {}
78         /// OK from dialog
79         virtual void ok() {
80                 apply();
81                 hide();
82         }
83         /// Cancel from dialog
84         virtual void cancel() {
85                 hide();
86         }
87         /// Restore from dialog
88         virtual void restore() {
89                 update();
90         }
91         /// Pointer to the actual instantiation of xform's form
92         virtual FL_FORM * form() const = 0;
93
94         /** Which LyXFunc do we use?
95             We could modify Dialogs to have a visible LyXFunc* instead and
96             save a couple of bytes per dialog.
97         */
98         LyXView * lv_;
99         /// Useable even in derived-class's const functions.
100         mutable ButtonController bc_;
101         /// Used so we can get at the signals we have to connect to.
102         Dialogs * d_;
103         /// Hide connection.
104         Connection h_;
105         /// dialog title, displayed by WM.
106         string title;
107         ///
108         ButtonPolicy * bp_;
109         /// Overcome a dumb xforms sizing bug
110         mutable int minw_;
111         ///
112         mutable int minh_;
113 };
114
115
116 /** This class is an XForms GUI base class for Buffer Independent dialogs.
117     Such dialogs do not require an update Connection although they may use
118     an update() function which is also supported by restore().
119  */
120 class FormBaseBI : public FormBase {
121 protected:
122         /// Constructor
123         FormBaseBI(LyXView *, Dialogs *, string const &,
124                    ButtonPolicy * bp = new OkApplyCancelPolicy,
125                    char const * close = N_("Close"),
126                    char const * cancel = N_("Cancel"));
127
128         /// Connect signals
129         virtual void connect();
130         /// Disconnect signals
131         virtual void disconnect();
132 };
133
134
135 /** This class is an XForms GUI base class for Buffer Dependent dialogs
136  */
137 class FormBaseBD : public FormBase {
138 protected:
139         /// Constructor
140         FormBaseBD(LyXView *, Dialogs *, string const &,
141                    ButtonPolicy * bp = new OkApplyCancelReadOnlyPolicy,
142                    char const * close = N_("Close"),
143                    char const * cancel = N_("Cancel"));
144
145         /// Connect signals
146         virtual void connect();
147         /// Disconnect signals
148         virtual void disconnect();
149         /// bool indicates if a buffer switch took place
150         virtual void updateSlot(bool) { update(); }
151
152         /// Update connection.
153         Connection u_;
154 };
155
156
157 #endif