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