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