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