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