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