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