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