]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/XFormsView.C
remove preamble dialog from the qt frontend
[lyx.git] / src / frontends / xforms / XFormsView.C
1 /**
2  * \file XFormsView.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "XFormsView.h"
18 #include FORMS_H_LOCATION
19
20 #include "XMiniBuffer.h"
21 #include "debug.h"
22 #include "intl.h"
23 #include "lyxrc.h"
24 #include "support/filetools.h"        // OnlyFilename()
25 #include "frontends/Toolbar.h"
26 #include "frontends/Menubar.h"
27 #include "frontends/Timeout.h"
28 #include "frontends/Dialogs.h"
29 #include "MenuBackend.h"
30 #include "ToolbarDefaults.h"
31 #include "lyxfunc.h"
32 #include "bufferview_funcs.h"
33 #include "BufferView.h"
34
35 #include <boost/bind.hpp>
36 #include <boost/signals/connection.hpp>
37 using std::abs;
38 using std::endl;
39
40 //extern void AutoSave(BufferView *);
41 extern void QuitLyX();
42
43 // This is very temporary
44 BufferView * current_view;
45
46 extern "C" {
47
48 static
49 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
50 {
51         return XFormsView::atCloseMainFormCB(form, p);
52 }
53
54 }
55
56
57 XFormsView::XFormsView(int width, int height)
58         : LyXView(),
59           icon_pixmap_(0), icon_mask_(0)
60 {
61         create_form_form_main(width, height);
62         fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
63
64         view_state_con = view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this));
65         focus_con = focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get()));
66
67         // Make sure the buttons are disabled if needed.
68         updateToolbar();
69         redraw_con = getDialogs().redrawGUI().connect(boost::bind(&XFormsView::redraw, this));
70 }
71
72
73 XFormsView::~XFormsView()
74 {
75         if (icon_pixmap_)
76                 XFreePixmap(fl_get_display(), icon_pixmap_);
77
78         minibuffer_->freeze();
79         fl_hide_form(form_);
80         fl_free_form(form_);
81 }
82
83
84 /// Redraw the main form.
85 void XFormsView::redraw()
86 {
87         lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
88         fl_redraw_form(getForm());
89         minibuffer_->redraw();
90 }
91
92
93 FL_FORM * XFormsView::getForm() const
94 {
95         return form_;
96 }
97
98
99 // Callback for close main form from window manager
100 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
101 {
102         QuitLyX();
103         return FL_IGNORE;
104 }
105
106
107 void XFormsView::show(int x, int y, string const & title)
108 {
109         FL_FORM * form = getForm();
110
111         fl_set_form_minsize(form, form->w, form->h);
112
113         int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
114
115         // Did we get a valid geometry position ?
116         if (x >= 0 && y >= 0) {
117                 fl_set_form_position(form, x, y);
118                 placement = FL_PLACE_POSITION;
119         }
120
121         fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
122
123         show_view_state();
124 }
125
126
127 void XFormsView::create_form_form_main(int width, int height)
128         /* to make this work as it should, .lyxrc should have been
129          * read first; OR maybe this one should be made dynamic.
130          * Hmmmm. Lgb.
131          * We will probably not have lyxrc before the main form is
132          * initialized, because error messages from lyxrc parsing
133          * are presented (and rightly so) in GUI popups. Asger.
134          */
135 {
136         // the main form
137         form_ = fl_bgn_form(FL_NO_BOX, width, height);
138         getForm()->u_vdata = this;
139         FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
140         fl_set_object_color(obj, FL_MCOL, FL_MCOL);
141
142         // Parameters for the appearance of the main form
143         int const air = 2;
144         int const bw = abs(fl_get_border_width());
145
146         menubar_.reset(new Menubar(this, menubackend));
147
148         toolbar_.reset(new Toolbar(this, air, 30 + air + bw, toolbardefaults));
149
150         int const ywork = 60 + 2 * air + bw;
151         int const workheight = height - ywork - (25 + 2 * air);
152
153         bufferview_.reset(new BufferView(this, air, ywork,
154                 width - 3 * air, workheight));
155         ::current_view = bufferview_.get();
156
157         minibuffer_.reset(new XMiniBuffer(this, *controlcommand_,
158                 air, height - (25 + air), width - (2 * air), 25));
159
160         //  assign an icon to main form
161         string const iconname = LibFileSearch("images", "lyx", "xpm");
162         if (!iconname.empty()) {
163                 unsigned int w, h;
164                 icon_pixmap_ = fl_read_pixmapfile(fl_root,
165                                            iconname.c_str(),
166                                            &w,
167                                            &h,
168                                            &icon_mask_,
169                                            0,
170                                            0,
171                                            0);
172                 fl_set_form_icon(getForm(), icon_pixmap_, icon_mask_);
173         }
174
175         // set min size
176         fl_set_form_minsize(getForm(), 50, 50);
177
178         fl_end_form();
179
180         minibuffer_->dd_init();
181 }
182
183
184 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
185 {
186         fl_set_form_title(getForm(), title.c_str());
187         fl_winicontitle(form_->window, icon_title.c_str());
188 }
189
190
191 void XFormsView::message(string const & str)
192 {
193         minibuffer_->message(str);
194 }
195
196
197 void XFormsView::show_view_state()
198 {
199         message(getLyXFunc().view_status_message());
200 }
201
202
203 // How should this actually work? Should it prohibit input in all BufferViews,
204 // or just in the current one? If "just the current one", then it should be
205 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
206 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
207 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
208 // current LyXView that should be prohibited (Lgb) (This applies to
209 // "allowInput" as well.)
210 void XFormsView::prohibitInput() const
211 {
212         view()->hideCursor();
213
214         static Cursor cursor;
215         static bool cursor_undefined = true;
216
217         if (cursor_undefined) {
218                 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
219                 XFlush(fl_get_display());
220                 cursor_undefined = false;
221         }
222
223         /* set the cursor to the watch for all forms and the canvas */
224         XDefineCursor(fl_get_display(), getForm()->window, cursor);
225
226         XFlush(fl_get_display());
227         fl_deactivate_all_forms();
228 }
229
230
231 void XFormsView::allowInput() const
232 {
233         /* reset the cursor from the watch for all forms and the canvas */
234
235         XUndefineCursor(fl_get_display(), getForm()->window);
236
237         XFlush(fl_get_display());
238         fl_activate_all_forms();
239 }