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