]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/XFormsView.C
remove defaults stuff, let Qt handle no toolbar
[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
14 #include "XFormsView.h"
15 #include FORMS_H_LOCATION
16
17 #include "XMiniBuffer.h"
18 #include "debug.h"
19 #include "intl.h"
20 #include "lyxrc.h"
21 #include "support/filetools.h"        // OnlyFilename()
22 #include "frontends/Toolbar.h"
23 #include "frontends/Menubar.h"
24 #include "frontends/Timeout.h"
25 #include "frontends/Dialogs.h"
26 #include "MenuBackend.h"
27 #include "ToolbarBackend.h"
28 #include "lyxfunc.h"
29 #include "bufferview_funcs.h"
30 #include "BufferView.h"
31
32 #include <boost/bind.hpp>
33 #include <boost/signals/connection.hpp>
34 using std::abs;
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           icon_pixmap_(0), icon_mask_(0)
57 {
58         create_form_form_main(width, height);
59         fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
60
61         view_state_con = view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this));
62         focus_con = focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get()));
63
64         // Make sure the buttons are disabled if needed.
65         updateToolbar();
66         redraw_con = getDialogs().redrawGUI().connect(boost::bind(&XFormsView::redraw, this));
67 }
68
69
70 XFormsView::~XFormsView()
71 {
72         if (icon_pixmap_)
73                 XFreePixmap(fl_get_display(), icon_pixmap_);
74
75         minibuffer_->freeze();
76         fl_hide_form(form_);
77         fl_free_form(form_);
78 }
79
80
81 /// Redraw the main form.
82 void XFormsView::redraw()
83 {
84         lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
85         fl_redraw_form(getForm());
86         minibuffer_->redraw();
87 }
88
89
90 FL_FORM * XFormsView::getForm() const
91 {
92         return form_;
93 }
94
95
96 // Callback for close main form from window manager
97 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
98 {
99         QuitLyX();
100         return FL_IGNORE;
101 }
102
103
104 void XFormsView::show(int x, int y, string const & title)
105 {
106         FL_FORM * form = getForm();
107
108         fl_set_form_minsize(form, form->w, form->h);
109
110         int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
111
112         // Did we get a valid geometry position ?
113         if (x >= 0 && y >= 0) {
114                 fl_set_form_position(form, x, y);
115                 placement = FL_PLACE_POSITION;
116         }
117
118         fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
119
120         show_view_state();
121 }
122
123
124 void XFormsView::create_form_form_main(int width, int height)
125         /* to make this work as it should, .lyxrc should have been
126          * read first; OR maybe this one should be made dynamic.
127          * Hmmmm. Lgb.
128          * We will probably not have lyxrc before the main form is
129          * initialized, because error messages from lyxrc parsing
130          * are presented (and rightly so) in GUI popups. Asger.
131          */
132 {
133         // the main form
134         form_ = fl_bgn_form(FL_NO_BOX, width, height);
135         getForm()->u_vdata = this;
136         FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
137         fl_set_object_color(obj, FL_MCOL, FL_MCOL);
138
139         // Parameters for the appearance of the main form
140         int const air = 2;
141         int const bw = abs(fl_get_border_width());
142
143         menubar_.reset(new Menubar(this, menubackend));
144
145         toolbar_.reset(new Toolbar(this, air, 30 + air + bw, toolbarbackend));
146
147         int const ywork = 60 + 2 * air + bw;
148         int const workheight = height - ywork - (25 + 2 * air);
149
150         bufferview_.reset(new BufferView(this, air, ywork,
151                 width - 3 * air, workheight));
152         ::current_view = bufferview_.get();
153
154         minibuffer_.reset(new XMiniBuffer(*controlcommand_,
155                 air, height - (25 + air), width - (2 * air), 25));
156
157         //  assign an icon to main form
158         string const iconname = LibFileSearch("images", "lyx", "xpm");
159         if (!iconname.empty()) {
160                 unsigned int w, h;
161                 icon_pixmap_ = fl_read_pixmapfile(fl_root,
162                                            iconname.c_str(),
163                                            &w,
164                                            &h,
165                                            &icon_mask_,
166                                            0,
167                                            0,
168                                            0);
169                 fl_set_form_icon(getForm(), icon_pixmap_, icon_mask_);
170         }
171
172         // set min size
173         fl_set_form_minsize(getForm(), 50, 50);
174
175         fl_end_form();
176 }
177
178
179 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
180 {
181         fl_set_form_title(getForm(), title.c_str());
182         fl_winicontitle(form_->window, icon_title.c_str());
183 }
184
185
186 void XFormsView::message(string const & str)
187 {
188         minibuffer_->message(str);
189 }
190
191
192 void XFormsView::show_view_state()
193 {
194         message(getLyXFunc().view_status_message());
195 }
196
197
198 void XFormsView::busy(bool yes) const
199 {
200         if (yes) {
201                 view()->hideCursor();
202
203                 static Cursor cursor;
204                 static bool cursor_undefined = true;
205
206                 if (cursor_undefined) {
207                         cursor = XCreateFontCursor(fl_get_display(), XC_watch);
208                         XFlush(fl_get_display());
209                         cursor_undefined = false;
210                 }
211
212                 /// set the cursor to the watch for all forms and the canvas
213                 XDefineCursor(fl_get_display(), getForm()->window, cursor);
214
215                 XFlush(fl_get_display());
216
217                 /// we only need to deactivate to prevent resetting the cursor
218                 /// to I-beam over the workarea
219                 fl_deactivate_all_forms();
220         } else {
221                 /// reset the cursor from the watch for all forms and the canvas
222
223                 XUndefineCursor(fl_get_display(), getForm()->window);
224
225                 XFlush(fl_get_display());
226                 fl_activate_all_forms();
227         }
228 }