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