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