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