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