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