]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Dialogs.C
Added lyx-func tabular-feature for menu structure.
[lyx.git] / src / frontends / xforms / Dialogs.C
1 #include <config.h>
2 #include FORMS_H_LOCATION
3
4 #include "Dialogs.h"
5 #include "FormCitation.h"
6 #include "FormCopyright.h"
7 #include "FormPreferences.h"
8 #include "FormPrint.h"
9 #include "FormTabular.h"
10 #include "FormUrl.h"
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16
17 Dialogs::Dialogs(LyXView * lv)
18 {
19         dialogs_.push_back(new FormCitation(lv, this));
20         dialogs_.push_back(new FormCopyright(lv, this));
21         dialogs_.push_back(new FormPreferences(lv, this));
22         dialogs_.push_back(new FormPrint(lv, this));
23         dialogs_.push_back(new FormTabular(lv, this));
24         dialogs_.push_back(new FormUrl(lv, this));
25
26         // reduce the number of connections needed in
27         // dialogs by a simple connection here.
28         hideAll.connect(hideBufferDependent.slot());
29 }
30
31 Dialogs::~Dialogs()
32 {
33         for (vector<DialogBase *>::iterator iter = dialogs_.begin();
34              iter != dialogs_.end();
35              ++iter) {
36                 delete *iter;
37         }
38 }
39
40
41 /*****************************************************************************
42
43 Q.  WHY does Dialogs::Dialogs pass `this' to dialog constructors?
44
45 A.  To avoid a segfault.
46     The dialog constructors need to connect to their
47     respective showSomeDialog signal(*) but in order to do
48     that they need to get the address of the Dialogs instance
49     from LyXView::getDialogs().  However, since the Dialogs
50     instance is still being constructed at that time
51     LyXView::getDialogs() will *not* return the correct
52     address because it hasn't finished being constructed.
53     A Catch-22 situation (or is that the chicken and the egg...).
54     So to get around the problem we pass the address of
55     the newly created Dialogs instance using `this'.
56
57 (*) -- I'm using signals exclusively to guarantee that the gui code
58        remains hidden from the rest of the system.  In fact the only 
59        header related to dialogs that anything in the non-gui-specific
60        code gets to see is Dialogs.h!  Even Dialogs.h doesn't know what a 
61        FormCopyright class looks like or that its even going to be used!
62
63        No other gui dialog headers are seen outside of the gui-specific
64        directories!  This ensures that the gui is completely separate from
65        the rest of LyX.  All this through the use of a few simple signals.
66        BUT, the price is that during construction we need to connect the
67        implementations show() method to the showSomeDialog signal and this
68        requires that we have an instance of Dialogs and the problem mentioned
69        above.
70
71        Almost all other dialogs should be able to operate using the same style
72        of signalling used for Copyright.  Exceptions should be handled
73        by adding a specific show or update signal.  For example, spellchecker
74        needs to set the next suspect word and its options/replacements so we
75        need a:
76                  Signal0<void> updateSpellChecker;
77
78        Since we would have to have a
79                  Signal0<void> showSpellChecker;
80
81        in order to just see the spellchecker and let the user push the [Start]
82        button then the updateSpellChecker signal will make the SpellChecker
83        dialog get the new word and replacements list from LyX.  If you really,
84        really wanted to you could define a signal that would pass the new
85        word and replacements:
86                  Signal2<void, string, vector<string> > updateSpellChecker;
87
88        (or something similar) but, why bother when the spellchecker can get
89        it anyway with a LyXFunc call or two.  Besides if someone extends
90        what a dialog does then they also have to change code in the rest of 
91        LyX to pass more parameters or get the extra info via a function 
92        call anyway.  Thus reducing the independence of the two code bases.
93
94        We don't need a separate update signal for each dialog because most of 
95        them will be changed only when the buffer is changed (either by closing
96        the current open buffer or switching to another buffer in the current
97        LyXView -- different BufferView same LyXView or same BufferView same
98        LyXView).
99
100        So we minimise signals but maximise independence and programming 
101        simplicity, understandability and maintainability.  It's also
102        extremely easy to add support for Qt or gtk-- because they use
103        signals already. Guis that use callbacks, like xforms, must have their
104        code wrapped up like that in the form_copyright.[Ch] which is awkward
105        but will at least allow multiple instances of the same dialog.
106
107        Signals will also be a great help in controlling the splashscreen --
108        once signalled to hide it can disconnect from the signal and remove
109        itself from memory.
110
111        LyXFuncs will be used for requesting/setting LyX internal info.  This
112        will ensure that scripts or LyXServer-connected applications can all
113        have access to the same calls as the internal user-interface.
114
115 ******************************************************************************/