]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBase.h
small patch from Dekel, begin introducing the real boost framework, get rid of the...
[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 Dialogs;
23 class LyXView;
24
25 #ifdef __GNUG__
26 #pragma interface
27 #endif
28
29 #ifdef SIGC_CXX_NAMESPACES
30 using SigC::Signal0;
31 #endif
32
33 /** This class is an XForms GUI base class
34     @author Angus Leeming
35  */
36 class FormBase : public DialogBase, public noncopyable {
37 public:
38         ///
39         enum BufferDependency {
40                 ///
41                 BUFFER_DEPENDENT,
42                 ///
43                 BUFFER_INDEPENDENT
44         };
45
46         /** Constructor.
47             #FormBase(lv, d, BUFFER_DEPENDENT, _("DialogName"), new ButtonPolicy)#
48          */
49         FormBase(LyXView *, Dialogs *, BufferDependency, string const &,
50                  ButtonPolicy * bp = new OkApplyCancelReadOnlyPolicy,
51                  char const * close = N_("Close"),
52                  char const * cancel = N_("Cancel"));
53         ///
54         virtual ~FormBase();
55
56         /// Callback functions
57         static  int WMHideCB(FL_FORM *, void *);
58         ///
59         static void ApplyCB(FL_OBJECT *, long);
60         ///
61         static void OKCB(FL_OBJECT *, long);
62         ///
63         static void CancelCB(FL_OBJECT *, long);
64         ///
65         static void InputCB(FL_OBJECT *, long);
66         ///
67         static void RestoreCB(FL_OBJECT *, long);
68
69 protected:
70         /// Create the dialog if necessary, update it and display it.
71         void show();
72         /// Hide the dialog.
73         virtual void hide();
74         /// Connect signals
75         virtual void connect();
76         /// Disconnect signals
77         virtual void disconnect();
78         /// Build the dialog
79         virtual void build() = 0;
80         /** Filter the inputs on callback from xforms
81             Return true if inputs are valid.
82          */
83         virtual bool input( long ) {
84                 return true;
85         }
86         /// Update dialog before showing it
87         virtual void update() {}
88         /// Apply from dialog (modify or create inset)
89         virtual void apply() {}
90         /// OK from dialog
91         virtual void ok() {
92                 apply();
93                 hide();
94         }
95         /// Cancel from dialog
96         virtual void cancel() {
97                 hide();
98         }
99         /// Restore from dialog
100         virtual void restore() {}
101         /// delete derived class variables when hide()ing
102         virtual void clearStore() {}
103         /// Pointer to the actual instantiation of xform's form
104         virtual FL_FORM * const form() const = 0;
105
106         /// block opening of form twice at the same time
107         bool dialogIsOpen;
108         /** Which LyXFunc do we use?
109             We could modify Dialogs to have a visible LyXFunc* instead and
110             save a couple of bytes per dialog.
111         */
112         LyXView * lv_;
113         /// Useable even in derived-class's const functions
114         mutable ButtonController bc_;
115
116 private:
117         /// Hide signal
118         Signal0<void> * hSignal_;
119         /// Update signal
120         Signal0<void> * uSignal_;
121         /// Update connection.
122         Connection u_;
123         /// Hide connection.
124         Connection h_;
125         /// dialog title, displayed by WM.
126         string title;
127         ///
128         ButtonPolicy * bp_;
129 };
130
131 #endif