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