]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/XFormsView.C
introduce namespace lyx::support
[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 "lyx_forms.h"
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
35 using namespace lyx::support;
36
37 using std::abs;
38 using std::endl;
39
40 //extern void AutoSave(BufferView *);
41 extern void QuitLyX();
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));
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
153         minibuffer_.reset(new XMiniBuffer(*controlcommand_,
154                 air, height - (25 + air), width - (2 * air), 25));
155
156         //  assign an icon to main form
157         string const iconname = LibFileSearch("images", "lyx", "xpm");
158         if (!iconname.empty()) {
159                 unsigned int w, h;
160                 icon_pixmap_ = fl_read_pixmapfile(fl_root,
161                                            iconname.c_str(),
162                                            &w,
163                                            &h,
164                                            &icon_mask_,
165                                            0,
166                                            0,
167                                            0);
168                 fl_set_form_icon(getForm(), icon_pixmap_, icon_mask_);
169         }
170
171         // set min size
172         fl_set_form_minsize(getForm(), 50, 50);
173
174         fl_end_form();
175 }
176
177
178 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
179 {
180         fl_set_form_title(getForm(), title.c_str());
181         fl_winicontitle(form_->window, icon_title.c_str());
182 }
183
184
185 void XFormsView::message(string const & str)
186 {
187         minibuffer_->message(str);
188 }
189
190
191 void XFormsView::clearMessage()
192 {
193         message(getLyXFunc().view_status_message());
194 }
195
196
197 void XFormsView::show_view_state()
198 {
199         message(getLyXFunc().view_status_message());
200 }
201
202
203 void XFormsView::busy(bool yes) const
204 {
205         if (yes) {
206                 view()->hideCursor();
207
208                 static Cursor cursor;
209                 static bool cursor_undefined = true;
210
211                 if (cursor_undefined) {
212                         cursor = XCreateFontCursor(fl_get_display(), XC_watch);
213                         XFlush(fl_get_display());
214                         cursor_undefined = false;
215                 }
216
217                 /// set the cursor to the watch for all forms and the canvas
218                 XDefineCursor(fl_get_display(), getForm()->window, cursor);
219
220                 XFlush(fl_get_display());
221
222                 /// we only need to deactivate to prevent resetting the cursor
223                 /// to I-beam over the workarea
224                 fl_deactivate_all_forms();
225         } else {
226                 /// reset the cursor from the watch for all forms and the canvas
227
228                 XUndefineCursor(fl_get_display(), getForm()->window);
229
230                 XFlush(fl_get_display());
231                 fl_activate_all_forms();
232         }
233 }