]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/Dialogs.C
gtkmm-2 upgrade. Still some small bugs to iron out, but mostly functional
[lyx.git] / src / frontends / gnome / Dialogs.C
1 /* This file is part of
2  * ======================================================
3  *
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995-2001 The LyX Team.
7  *
8  * ======================================================
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17
18 #include "Dialogs.h"
19
20 #include "GUI.h"
21 #include "gnomeBC.h"
22
23 #include "frontends/LyXView.h"
24
25 #include "GError.h"
26 #include "GERT.h"
27 #include "GPreamble.h"
28 #include "GTabularCreate.h"
29 #include "GUrl.h"
30
31
32 #include "Tooltips.h"
33
34 bool Dialogs::tooltipsEnabled()
35 {
36         return Tooltips::enabled();
37 }
38 Dialogs::Dialogs(LyXView * lv)
39 {
40
41         add(new GUI<ControlError,GErrorDialog, 
42             OkCancelPolicy, gnomeBC>(*lv, *this));
43         add(new GUI<ControlERT, GERT,
44             NoRepeatedApplyReadOnlyPolicy, gnomeBC>(*lv, *this));
45         add(new GUI<ControlUrl, GUrl,
46             NoRepeatedApplyReadOnlyPolicy, gnomeBC>(*lv,*this));
47         add(new GUI<ControlPreamble, GPreamble,
48             NoRepeatedApplyReadOnlyPolicy, gnomeBC>(*lv, *this));
49         add(new GUI<ControlTabularCreate, GTabularCreate,
50             OkApplyCancelReadOnlyPolicy, gnomeBC>(*lv, *this));
51
52         // reduce the number of connections needed in
53         // dialogs by a simple connection here.
54         hideAll.connect(hideBufferDependent);
55 }
56
57 /*****************************************************************************
58
59 Q.  WHY does Dialogs::Dialogs pass `this' to dialog constructors?
60
61 A.  To avoid a segfault.
62     The dialog constructors need to connect to their
63     respective showSomeDialog signal(*) but in order to do
64     that they need to get the address of the Dialogs instance
65     from LyXView::getDialogs().  However, since the Dialogs
66     instance is still being constructed at that time
67     LyXView::getDialogs() will *not* return the correct
68     address because it hasn't finished being constructed.
69     A Catch-22 situation (or is that the chicken and the egg...).
70     So to get around the problem we pass the address of
71     the newly created Dialogs instance using `this'.
72
73 (*) -- I'm using signals exclusively to guarantee that the gui code
74        remains hidden from the rest of the system.  In fact the only
75        header related to dialogs that anything in the non-gui-specific
76        code gets to see is Dialogs.h!  Even Dialogs.h doesn't know what a
77        FormCopyright class looks like or that its even going to be used!
78
79        No other gui dialog headers are seen outside of the gui-specific
80        directories!  This ensures that the gui is completely separate from
81        the rest of LyX.  All this through the use of a few simple signals.
82        BUT, the price is that during construction we need to connect the
83        implementations show() method to the showSomeDialog signal and this
84        requires that we have an instance of Dialogs and the problem mentioned
85        above.
86
87        Almost all other dialogs should be able to operate using the same style
88        of signalling used for Copyright.  Exceptions should be handled
89        by adding a specific show or update signal.  For example, spellchecker
90        needs to set the next suspect word and its options/replacements so we
91        need a:
92                  Signal0<void> updateSpellChecker;
93
94        Since we would have to have a
95                  Signal0<void> showSpellChecker;
96
97        in order to just see the spellchecker and let the user push the [Start]
98        button then the updateSpellChecker signal will make the SpellChecker
99        dialog get the new word and replacements list from LyX.  If you really,
100        really wanted to you could define a signal that would pass the new
101        word and replacements:
102                  Signal2<void, string, vector<string> > updateSpellChecker;
103
104        (or something similar) but, why bother when the spellchecker can get
105        it anyway with a LyXFunc call or two.  Besides if someone extends
106        what a dialog does then they also have to change code in the rest of
107        LyX to pass more parameters or get the extra info via a function
108        call anyway.  Thus reducing the independence of the two code bases.
109
110        We don't need a separate update signal for each dialog because most of
111        them will be changed only when the buffer is changed (either by closing
112        the current open buffer or switching to another buffer in the current
113        LyXView -- different BufferView same LyXView or same BufferView same
114        LyXView).
115
116        So we minimise signals but maximise independence and programming
117        simplicity, understandability and maintainability.  It's also
118        extremely easy to add support for Qt or gtk-- because they use
119        signals already. Guis that use callbacks, like xforms, must have their
120        code wrapped up like that in the form_copyright.[Ch] which is awkward
121        but will at least allow multiple instances of the same dialog.
122
123        LyXFuncs will be used for requesting/setting LyX internal info.  This
124        will ensure that scripts or LyXServer-connected applications can all
125        have access to the same calls as the internal user-interface.
126
127 ******************************************************************************/