1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
17 #include "XFormsView.h"
18 #include FORMS_H_LOCATION
19 #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
20 #include "frontends/xforms/lyxlookup.h"
22 #include "frontends/xforms/XMiniBuffer.h"
26 #include "support/filetools.h" // OnlyFilename()
27 #include "frontends/Toolbar.h"
28 #include "frontends/Menubar.h"
29 #include "frontends/Timeout.h"
30 #include "frontends/Dialogs.h"
31 #include "MenuBackend.h"
32 #include "ToolbarDefaults.h"
34 #include "bufferview_funcs.h"
35 #include "BufferView.h"
37 #include <boost/bind.hpp>
42 //extern void AutoSave(BufferView *);
43 extern void QuitLyX();
45 // This is very temporary
46 BufferView * current_view;
51 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
53 return XFormsView::atCloseMainFormCB(form, p);
59 XFormsView::XFormsView(int width, int height)
62 create_form_form_main(*getDialogs(), width, height);
63 fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
65 view_state_changed.connect(boost::bind(&XFormsView::show_view_state, this));
66 focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get()));
68 // Make sure the buttons are disabled if needed.
70 getDialogs()->redrawGUI.connect(boost::bind(&XFormsView::redraw, this));
74 XFormsView::~XFormsView()
76 minibuffer_->freeze();
82 /// Redraw the main form.
83 void XFormsView::redraw()
85 lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
86 fl_redraw_form(getForm());
87 minibuffer_->redraw();
91 FL_FORM * XFormsView::getForm() const
97 // Callback for close main form from window manager
98 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
105 void XFormsView::show(int x, int y, string const & title)
107 FL_FORM * form = getForm();
109 fl_set_form_minsize(form, form->w, form->h);
111 int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
113 // Did we get a valid geometry position ?
114 if (x >= 0 && y >= 0) {
115 fl_set_form_position(form, x, y);
116 placement = FL_PLACE_POSITION;
119 fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
122 #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
123 InitLyXLookup(fl_get_display(), form_->window);
128 void XFormsView::create_form_form_main(Dialogs & dia, int width, int height)
129 /* to make this work as it should, .lyxrc should have been
130 * read first; OR maybe this one should be made dynamic.
132 * We will probably not have lyxrc before the main form is
133 * initialized, because error messages from lyxrc parsing
134 * are presented (and rightly so) in GUI popups. Asger.
138 form_ = fl_bgn_form(FL_NO_BOX, width, height);
139 getForm()->u_vdata = this;
140 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
141 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
143 // Parameters for the appearance of the main form
145 int const bw = abs(fl_get_border_width());
147 menubar_.reset(new Menubar(this, menubackend));
149 toolbar_.reset(new Toolbar(this, dia,
150 air, 30 + air + bw, toolbardefaults));
152 int const ywork = 60 + 2 * air + bw;
153 int const workheight = height - ywork - (25 + 2 * air);
155 bufferview_.reset(new BufferView(this, air, ywork,
156 width - 3 * air, workheight));
157 ::current_view = bufferview_.get();
159 minibuffer_.reset(new XMiniBuffer(this, *controlcommand_,
160 air, height - (25 + air), width - (2 * air), 25));
162 // assign an icon to main form
163 string iconname = LibFileSearch("images", "lyx", "xpm");
164 if (!iconname.empty()) {
166 Pixmap lyx_p, lyx_mask;
167 lyx_p = fl_read_pixmapfile(fl_root,
175 fl_set_form_icon(getForm(), lyx_p, lyx_mask);
179 fl_set_form_minsize(getForm(), 50, 50);
183 minibuffer_->dd_init();
187 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
189 fl_set_form_title(getForm(), title.c_str());
190 fl_winicontitle(form_->window, icon_title.c_str());
194 void XFormsView::message(string const & str)
196 minibuffer_->message(str);
200 void XFormsView::show_view_state()
202 message(getLyXFunc()->view_status_message());
206 // How should this actually work? Should it prohibit input in all BufferViews,
207 // or just in the current one? If "just the current one", then it should be
208 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
209 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
210 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
211 // current LyxView that should be prohibited (Lgb) (This applies to
212 // "allowInput" as well.)
213 void XFormsView::prohibitInput() const
215 view()->hideCursor();
217 static Cursor cursor;
218 static bool cursor_undefined = true;
220 if (cursor_undefined) {
221 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
222 XFlush(fl_get_display());
223 cursor_undefined = false;
226 /* set the cursor to the watch for all forms and the canvas */
227 XDefineCursor(fl_get_display(), getForm()->window, cursor);
229 XFlush(fl_get_display());
230 fl_deactivate_all_forms();
234 void XFormsView::allowInput() const
236 /* reset the cursor from the watch for all forms and the canvas */
238 XUndefineCursor(fl_get_display(), getForm()->window);
240 XFlush(fl_get_display());
241 fl_activate_all_forms();