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