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