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