]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormBase.h
Angus's xforms patch -- I don't like some of it but overall we need it...
[features.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     @author Angus Leeming
32  */
33 class FormBase : public DialogBase, public noncopyable {
34 public:
35         ///
36         enum BufferDependency {
37                 ///
38                 BUFFER_DEPENDENT,
39                 ///
40                 BUFFER_INDEPENDENT
41         };
42         ///
43         enum ChangedBufferAction {
44                 ///
45                 UPDATE,
46                 ///
47                 HIDE
48         };
49
50         /** Constructor.
51             #FormBase(lv, d, _("DialogName"), BUFFER_DEPENDENT, new ButtonPolicy)#
52          */
53         FormBase(LyXView *, Dialogs *, string const &,
54                  BufferDependency, ChangedBufferAction,
55                  ButtonPolicy * bp = new OkApplyCancelReadOnlyPolicy,
56                  char const * close = N_("Close"),
57                  char const * cancel = N_("Cancel"));
58         ///
59         virtual ~FormBase();
60
61         /// Callback functions
62         static  int WMHideCB(FL_FORM *, void *);
63         ///
64         static void ApplyCB(FL_OBJECT *, long);
65         ///
66         static void OKCB(FL_OBJECT *, long);
67         ///
68         static void CancelCB(FL_OBJECT *, long);
69         ///
70         static void InputCB(FL_OBJECT *, long);
71         ///
72         static void RestoreCB(FL_OBJECT *, long);
73
74 protected: // methods
75         /// Create the dialog if necessary, update it and display it.
76         void show();
77         /// Hide the dialog.
78         virtual void hide();
79         /// Connect signals
80         virtual void connect();
81         /// Disconnect signals
82         virtual void disconnect();
83         /// Build the dialog
84         virtual void build() = 0;
85         /** Filter the inputs on callback from xforms
86             Return true if inputs are valid.
87          */
88         virtual bool input( FL_OBJECT *, long ) {
89                 return true;
90         }
91         /// Update dialog before showing it
92         virtual void update() {}
93         /// Apply from dialog (modify or create inset)
94         virtual void apply() {}
95         /// OK from dialog
96         virtual void ok() {
97                 apply();
98                 hide();
99         }
100         /// Cancel from dialog
101         virtual void cancel() {
102                 hide();
103         }
104         /// Restore from dialog
105         virtual void restore() {
106                 update();
107         }
108         /// delete derived class variables when hide()ing
109         virtual void clearStore() {}
110         /// Pointer to the actual instantiation of xform's form
111         virtual FL_FORM * form() const = 0;
112
113 private: // methods
114         /// method connected to updateBufferDependent signal.
115         void updateOrHide();
116
117 protected: // data
118         /// block opening of form twice at the same time.
119         bool dialogIsOpen;
120         /** Which LyXFunc do we use?
121             We could modify Dialogs to have a visible LyXFunc* instead and
122             save a couple of bytes per dialog.
123         */
124         LyXView * lv_;
125         /// Useable even in derived-class's const functions.
126         mutable ButtonController bc_;
127
128 private: // data
129         /// Used so we can get at the signals we have to connect to.
130         Dialogs * d_;
131         /// flag whether dialog is buffer dependent or not.
132         BufferDependency const bd_;
133         /// flag whether to hide or update on updateBufferDependent signal.
134         ChangedBufferAction const cba_;
135         /// stores parent buffer when popup was launched.
136         Buffer * parent_;
137         /// Update connection.
138         Connection u_;
139         /// Hide connection.
140         Connection h_;
141         /// dialog title, displayed by WM.
142         string title;
143         ///
144         ButtonPolicy * bp_;
145 };
146
147 #endif