]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
Angus's FormInset work; Dekel's languages patch; my reworking of Angus's stuff +...
[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         /** Constructor.
37             #FormBase(lv, d, _("DialogName"), BUFFER_DEPENDENT, new ButtonPolicy)#
38          */
39         FormBase(LyXView *, Dialogs *, string const &,
40                  ButtonPolicy *, char const *, char const *);
41         ///
42         virtual ~FormBase();
43
44         /// Callback functions
45         static  int WMHideCB(FL_FORM *, void *);
46         ///
47         static void ApplyCB(FL_OBJECT *, long);
48         ///
49         static void OKCB(FL_OBJECT *, long);
50         ///
51         static void CancelCB(FL_OBJECT *, long);
52         ///
53         static void InputCB(FL_OBJECT *, long);
54         ///
55         static void RestoreCB(FL_OBJECT *, long);
56
57 protected: // methods
58         /// Create the dialog if necessary, update it and display it.
59         void show();
60         /// Hide the dialog.
61         virtual void hide();
62         /// bool indicates if a buffer switch took place
63         virtual void update(bool = false) {}
64         /// Connect signals. Also perform any necessary initialisation.
65         virtual void connect() = 0;
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 protected: // data
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 };
111
112
113 /** This class is an XForms GUI base class for Buffer Independent dialogs.
114     Such dialogs do not require an update Connection although they may use
115     an update() function which is also supported by restore().
116  */
117 class FormBaseBI : public FormBase {
118 public:
119         /// Constructor
120         FormBaseBI(LyXView *, Dialogs *, string const &,
121                    ButtonPolicy * bp = new OkApplyCancelPolicy,
122                    char const * close = N_("Close"),
123                    char const * cancel = N_("Cancel"));
124
125 protected:
126         /// Connect signals
127         virtual void connect();
128         /// Disconnect signals
129         virtual void disconnect();
130 };
131
132
133 /** This class is an XForms GUI base class for Buffer Dependent dialogs
134  */
135 class FormBaseBD : public FormBase {
136 public:
137         /// Constructor
138         FormBaseBD(LyXView *, Dialogs *, string const &,
139                    ButtonPolicy * bp = new OkApplyCancelReadOnlyPolicy,
140                    char const * close = N_("Close"),
141                    char const * cancel = N_("Cancel"));
142
143 protected:
144         /// Connect signals
145         virtual void connect();
146         /// Disconnect signals
147         virtual void disconnect();
148
149         /// Update connection.
150         Connection u_;
151 };
152
153
154 #endif