]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/Dialogs.C
776df33c40d852b711c4a38bce145d3c2ba81f33
[lyx.git] / src / frontends / xforms / Dialogs.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2000 The LyX Team.
8  *
9  * ======================================================
10  */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "Dialogs.h"
19
20 #include "ControlBibitem.h"
21 #include "ControlBibtex.h"
22 #include "ControlCitation.h"
23 #include "ControlLog.h"
24 #include "ControlVCLog.h"
25 #include "xformsBC.h"
26
27 #include "form_bibitem.h" // needed for clean destructtion of boost::scoped ptr
28 #include "form_bibtex.h"
29 #include "form_browser.h"
30 #include "form_citation.h"
31
32 #include "FormBibitem.h"
33 #include "FormBibtex.h"
34 #include "FormCitation.h"
35 #include "FormLog.h"
36 #include "FormVCLog.h"
37
38 #include "FormCharacter.h"
39 #include "FormCopyright.h"
40 #include "FormCredits.h"
41 #include "FormDocument.h"
42 #include "FormError.h"
43 #include "FormExternal.h" 
44 #include "FormGraphics.h"
45 #include "FormInclude.h"
46 #include "FormIndex.h"
47 #include "FormMathsPanel.h"
48 #include "FormParagraph.h"
49 #include "FormPreamble.h"
50 #include "FormPreferences.h"
51 #include "FormPrint.h"
52 #include "FormRef.h"
53 #include "FormSearch.h"
54 #include "FormSplash.h"
55 #include "FormTabular.h"
56 #include "FormTabularCreate.h"
57 #include "FormToc.h"
58 #include "FormUrl.h"
59 #include "FormMinipage.h"
60
61 // Signal enabling all visible popups to be redrawn if so desired.
62 // E.g., when the GUI colours have been remapped.
63 SigC::Signal0<void> Dialogs::redrawGUI;
64
65 Dialogs::Dialogs(LyXView * lv)
66 {
67         splash_.reset(new FormSplash(lv, this));
68
69         add(new GUICitation<FormCitation, xformsBC>(*lv, *this));
70         add(new GUIBibitem<FormBibitem, xformsBC>(*lv, *this));
71         add(new GUIBibtex<FormBibtex, xformsBC>(*lv, *this));
72         add(new GUILog<FormLog, xformsBC>(*lv, *this));
73         add(new GUIVCLog<FormVCLog, xformsBC>(*lv, *this));
74
75         add(new FormCharacter(lv, this));
76         add(new FormCopyright(lv, this));
77         add(new FormCredits(lv, this));
78         add(new FormDocument(lv, this));
79         add(new FormError(lv, this));
80         add(new FormExternal(lv, this));
81         add(new FormGraphics(lv, this));
82         add(new FormInclude(lv, this));
83         add(new FormIndex(lv, this));
84         add(new FormMathsPanel(lv, this));
85         add(new FormParagraph(lv, this));
86         add(new FormPreamble(lv, this));
87         add(new FormPreferences(lv, this));
88         add(new FormPrint(lv, this));
89         add(new FormRef(lv, this));
90         add(new FormSearch(lv, this));
91         add(new FormSplash(lv, this));
92         add(new FormTabular(lv, this));
93         add(new FormTabularCreate(lv, this));
94         add(new FormToc(lv, this));
95         add(new FormUrl(lv, this));
96         add(new FormMinipage(lv, this));
97         
98         // reduce the number of connections needed in
99         // dialogs by a simple connection here.
100         hideAll.connect(hideBufferDependent.slot());
101 }
102
103 /*****************************************************************************
104
105 Q.  WHY does Dialogs::Dialogs pass `this' to dialog constructors?
106
107 A.  To avoid a segfault.
108     The dialog constructors need to connect to their
109     respective showSomeDialog signal(*) but in order to do
110     that they need to get the address of the Dialogs instance
111     from LyXView::getDialogs().  However, since the Dialogs
112     instance is still being constructed at that time
113     LyXView::getDialogs() will *not* return the correct
114     address because it hasn't finished being constructed.
115     A Catch-22 situation (or is that the chicken and the egg...).
116     So to get around the problem we pass the address of
117     the newly created Dialogs instance using `this'.
118
119 (*) -- I'm using signals exclusively to guarantee that the gui code
120        remains hidden from the rest of the system.  In fact the only 
121        header related to dialogs that anything in the non-gui-specific
122        code gets to see is Dialogs.h!  Even Dialogs.h doesn't know what a 
123        FormCopyright class looks like or that its even going to be used!
124
125        No other gui dialog headers are seen outside of the gui-specific
126        directories!  This ensures that the gui is completely separate from
127        the rest of LyX.  All this through the use of a few simple signals.
128        BUT, the price is that during construction we need to connect the
129        implementations show() method to the showSomeDialog signal and this
130        requires that we have an instance of Dialogs and the problem mentioned
131        above.
132
133        Almost all other dialogs should be able to operate using the same style
134        of signalling used for Copyright.  Exceptions should be handled
135        by adding a specific show or update signal.  For example, spellchecker
136        needs to set the next suspect word and its options/replacements so we
137        need a:
138                  Signal0<void> updateSpellChecker;
139
140        Since we would have to have a
141                  Signal0<void> showSpellChecker;
142
143        in order to just see the spellchecker and let the user push the [Start]
144        button then the updateSpellChecker signal will make the SpellChecker
145        dialog get the new word and replacements list from LyX.  If you really,
146        really wanted to you could define a signal that would pass the new
147        word and replacements:
148                  Signal2<void, string, vector<string> > updateSpellChecker;
149
150        (or something similar) but, why bother when the spellchecker can get
151        it anyway with a LyXFunc call or two.  Besides if someone extends
152        what a dialog does then they also have to change code in the rest of 
153        LyX to pass more parameters or get the extra info via a function 
154        call anyway.  Thus reducing the independence of the two code bases.
155
156        We don't need a separate update signal for each dialog because most of 
157        them will be changed only when the buffer is changed (either by closing
158        the current open buffer or switching to another buffer in the current
159        LyXView -- different BufferView same LyXView or same BufferView same
160        LyXView).
161
162        So we minimise signals but maximise independence and programming 
163        simplicity, understandability and maintainability.  It's also
164        extremely easy to add support for Qt or gtk-- because they use
165        signals already. Guis that use callbacks, like xforms, must have their
166        code wrapped up like that in the form_copyright.[Ch] which is awkward
167        but will at least allow multiple instances of the same dialog.
168
169        Signals will also be a great help in controlling the splashscreen --
170        once signalled to hide it can disconnect from the signal and remove
171        itself from memory.
172
173        LyXFuncs will be used for requesting/setting LyX internal info.  This
174        will ensure that scripts or LyXServer-connected applications can all
175        have access to the same calls as the internal user-interface.
176
177 ******************************************************************************/