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