]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
Color patch from Angus, KDE patch from Johnm menu patch from Rob, and the usual unint...
[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() = 0;
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         /// dialog title, displayed by WM.
114         string title;
115         ///
116         ButtonPolicy * bp_;
117         /// Overcome a dumb xforms sizing bug
118         mutable int minw_;
119         ///
120         mutable int minh_;
121 };
122
123
124 /** This class is an XForms GUI base class for Buffer Independent dialogs.
125     Such dialogs do not require an update Connection although they may use
126     an update() function which is also supported by restore().
127  */
128 class FormBaseBI : public FormBase {
129 protected:
130         /// Constructor
131         FormBaseBI(LyXView *, Dialogs *, string const &,
132                    ButtonPolicy * bp = new OkApplyCancelPolicy,
133                    char const * close = N_("Close"),
134                    char const * cancel = N_("Cancel"));
135
136         /// Connect signals
137         virtual void connect();
138         /// Disconnect signals
139         virtual void disconnect();
140 };
141
142
143 /** This class is an XForms GUI base class for Buffer Dependent dialogs
144  */
145 class FormBaseBD : public FormBase {
146 protected:
147         /// Constructor
148         FormBaseBD(LyXView *, Dialogs *, string const &,
149                    ButtonPolicy * bp = new OkApplyCancelReadOnlyPolicy,
150                    char const * close = N_("Close"),
151                    char const * cancel = N_("Cancel"));
152
153         /// Connect signals
154         virtual void connect();
155         /// Disconnect signals
156         virtual void disconnect();
157         /// bool indicates if a buffer switch took place
158         virtual void updateSlot(bool) { update(); }
159
160         /// Update connection.
161         Connection u_;
162 };
163
164
165 #endif