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