]> git.lyx.org Git - lyx.git/blob - src/XFormsView.C
text2 chane, XFormsView
[lyx.git] / src / XFormsView.C
1
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 //#include <sys/time.h>
19 //#include <unistd.h>
20
21 #include "XFormsView.h"
22 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
23 #include "lyxlookup.h"
24 #endif
25 #include "minibuffer.h"
26 #include "debug.h"
27 #include "intl.h"
28 #include "lyxrc.h"
29 #include "support/filetools.h"        // OnlyFilename()
30 #include "frontends/Toolbar.h"
31 #include "frontends/Menubar.h"
32 #include "MenuBackend.h"
33 #include "ToolbarDefaults.h"
34 #include "lyxfunc.h"
35 #include "BufferView.h"
36
37 using std::endl;
38
39 //extern void AutoSave(BufferView *);
40 extern void QuitLyX();
41
42 // This is very temporary
43 BufferView * current_view;
44
45 extern "C" int C_XFormsView_atCloseMainFormCB(FL_FORM *, void *);
46
47
48 XFormsView::XFormsView(int width, int height)
49         : LyXView()
50 {
51         create_form_form_main(width, height);
52         fl_set_form_atclose(form_, C_XFormsView_atCloseMainFormCB, 0);
53
54         // Connect the minibuffer signals
55         minibuffer->stringReady.connect(SigC::slot(getLyXFunc(),
56                                                    &LyXFunc::miniDispatch));
57         minibuffer->timeout.connect(SigC::slot(getLyXFunc(),
58                                                &LyXFunc::initMiniBuffer));
59         
60         // Make sure the buttons are disabled if needed.
61         updateToolbar();
62 }
63
64
65 XFormsView::~XFormsView() {}
66
67
68 /// Redraw the main form.
69 void XFormsView::redraw() {
70         lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
71         fl_redraw_form(form_);
72         getMiniBuffer()->redraw();
73 }
74
75
76 FL_FORM * XFormsView::getForm() const
77 {
78         return form_;
79 }
80
81
82 // Callback for close main form from window manager
83 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
84 {
85         QuitLyX();
86         return FL_IGNORE;
87 }
88
89
90 // Wrapper for the above
91 extern "C"
92 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
93 {
94         return XFormsView::atCloseMainFormCB(form, p);
95 }
96
97
98 void XFormsView::setPosition(int x, int y)
99 {
100         fl_set_form_position(form_, x, y);
101 }
102
103
104 void XFormsView::show(int place, int border, string const & title)
105 {
106         fl_show_form(form_, place, border, title.c_str());
107         getLyXFunc()->initMiniBuffer();
108 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
109         InitLyXLookup(fl_get_display(), form_->window);
110 #endif
111 }
112
113
114 void XFormsView::create_form_form_main(int width, int height)
115         /* to make this work as it should, .lyxrc should have been
116          * read first; OR maybe this one should be made dynamic.
117          * Hmmmm. Lgb. 
118          * We will probably not have lyxrc before the main form is
119          * initialized, because error messages from lyxrc parsing 
120          * are presented (and rightly so) in GUI popups. Asger. 
121          */
122 {
123         // the main form
124         form_ = fl_bgn_form(FL_NO_BOX, width, height);
125         form_->u_vdata = this;
126         FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
127         fl_set_object_color(obj, FL_MCOL, FL_MCOL);
128
129         // Parameters for the appearance of the main form
130         int const air = 2;
131         int const bw = abs(fl_get_border_width());
132         
133         //
134         // THE MENUBAR
135         //
136         menubar = new Menubar(this, menubackend);
137
138         //
139         // TOOLBAR
140         //
141
142         toolbar = new Toolbar(this, air, 30 + air + bw, toolbardefaults);
143
144         // Setup the toolbar
145         toolbar->set(true);
146
147         //
148         // WORKAREA
149         //
150
151         int const ywork = 60 + 2 * air + bw;
152         int const workheight = height - ywork - (25 + 2 * air);
153
154         ::current_view = bufferview = new BufferView(this, air, ywork,
155                                                      width - 3 * air,
156                                                      workheight);
157
158         //
159         // MINIBUFFER
160         //
161
162         minibuffer = new MiniBuffer(this, air, height - (25 + air), 
163                                     width - (2 * air), 25);
164
165         //
166         // TIMERS
167         //
168
169         autosave_timeout.timeout.connect(SigC::slot(this, &XFormsView::AutoSave));
170         
171         //
172         // Misc
173         //
174
175         //  assign an icon to main form
176         string iconname = LibFileSearch("images", "lyx", "xpm");
177         if (!iconname.empty()) {
178                 unsigned int w, h;
179                 Pixmap lyx_p, lyx_mask;
180                 lyx_p = fl_read_pixmapfile(fl_root,
181                                            iconname.c_str(),
182                                            &w,
183                                            &h,
184                                            &lyx_mask,
185                                            0,
186                                            0,
187                                            0); // this leaks
188                 fl_set_form_icon(form_, lyx_p, lyx_mask);
189         }
190
191         // set min size
192         fl_set_form_minsize(form_, 50, 50);
193         
194         fl_end_form();
195 }
196
197
198 void XFormsView::init()
199 {
200         // Set the textclass choice
201         invalidateLayoutChoice();
202         updateLayoutChoice();
203         updateMenubar();
204         
205         // Start autosave timer
206         if (lyxrc.autosave) {
207                 autosave_timeout.setTimeout(lyxrc.autosave * 1000);
208                 autosave_timeout.start();
209         }
210
211         intl->InitKeyMapper(lyxrc.use_kbmap);
212 }
213
214
215 void XFormsView::setWindowTitle(string const & title)
216 {
217         fl_set_form_title(form_, title.c_str());
218 }
219
220
221 // How should this actually work? Should it prohibit input in all BufferViews,
222 // or just in the current one? If "just the current one", then it should be
223 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
224 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
225 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
226 // current LyxView that should be prohibited (Lgb) (This applies to
227 // "allowInput" as well.)
228 void XFormsView::prohibitInput() const
229 {
230         view()->hideCursor();
231
232         static Cursor cursor;
233         static bool cursor_undefined = true;
234    
235         if (cursor_undefined){
236                 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
237                 XFlush(fl_get_display());
238                 cursor_undefined = false;
239         }
240    
241         /* set the cursor to the watch for all forms and the canvas */ 
242         XDefineCursor(fl_get_display(), getForm()->window, cursor);
243
244         XFlush(fl_get_display());
245         fl_deactivate_all_forms();
246 }
247
248
249 void XFormsView::allowInput() const
250 {
251         /* reset the cursor from the watch for all forms and the canvas */
252    
253         XUndefineCursor(fl_get_display(), getForm()->window);
254
255         XFlush(fl_get_display());
256         fl_activate_all_forms();
257 }