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