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