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
22 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
23 #include "lyxlookup.h"
25 #include "minibuffer.h"
29 #include "support/filetools.h" // OnlyFilename()
33 #include "frontends/Dialogs.h"
34 #include "frontends/Toolbar.h"
35 #include "frontends/Menubar.h"
36 #include "MenuBackend.h"
37 #include "ToolbarDefaults.h"
38 #include "lyx_gui_misc.h" // [update,Close,Redraw]AllBufferRelatedDialogs
39 #include "bufferview_funcs.h" // CurrentState()
45 extern void AutoSave(BufferView *);
46 extern void QuitLyX();
47 LyXTextClass::size_type current_layout = 0;
49 // This is very temporary
50 BufferView * current_view;
52 extern "C" int C_LyXView_atCloseMainFormCB(FL_FORM *, void *);
55 LyXView::LyXView(int width, int height)
57 create_form_form_main(width, height);
58 fl_set_form_atclose(form_, C_LyXView_atCloseMainFormCB, 0);
59 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
60 lyxfunc = new LyXFunc(this);
62 // Connect the minibuffer signals
63 minibuffer->stringReady.connect(SigC::slot(lyxfunc,
64 &LyXFunc::miniDispatch));
65 minibuffer->timeout.connect(SigC::slot(lyxfunc,
66 &LyXFunc::initMiniBuffer));
70 // Make sure the buttons are disabled if needed.
74 dialogs_ = new Dialogs(this);
75 // temporary until all dialogs moved into Dialogs.
76 dialogs_->updateBufferDependent
77 .connect(SigC::slot(&updateAllVisibleBufferRelatedDialogs));
78 dialogs_->hideBufferDependent
79 .connect(SigC::slot(&CloseAllBufferRelatedDialogs));
80 Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
81 Dialogs::redrawGUI.connect(SigC::slot(&RedrawAllBufferRelatedDialogs));
97 /// Redraw the main form.
98 void LyXView::redraw() {
99 lyxerr[Debug::INFO] << "LyXView::redraw()" << endl;
100 fl_redraw_form(form_);
101 minibuffer->redraw();
105 /// returns the buffer currently shown in the main form.
106 Buffer * LyXView::buffer() const
108 return bufferview->buffer();
112 BufferView * LyXView::view() const
118 FL_FORM * LyXView::getForm() const
124 Toolbar * LyXView::getToolbar() const
130 void LyXView::setLayout(LyXTextClass::size_type layout)
132 toolbar->setLayout(layout);
136 void LyXView::updateToolbar()
143 LyXFunc * LyXView::getLyXFunc() const
149 MiniBuffer * LyXView::getMiniBuffer() const
155 void LyXView::message(string const & str)
157 minibuffer->message(str);
161 void LyXView::messagePush(string const & str)
163 minibuffer->messagePush(str);
167 void LyXView::messagePop()
169 minibuffer->messagePop();
173 Menubar * LyXView::getMenubar() const
179 void LyXView::updateMenubar()
181 if ((!view() || !view()->buffer())
182 && menubackend.hasMenu("main_nobuffer"))
183 menubar->set("main_nobuffer");
185 menubar->set("main");
189 Intl * LyXView::getIntl() const
195 // Callback for autosave timer
196 void LyXView::AutoSave()
198 lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
199 if (view()->available())
204 /// Reset autosave timer
205 void LyXView::resetAutosaveTimer()
208 autosave_timeout.restart();
212 // Callback for close main form from window manager
213 int LyXView::atCloseMainFormCB(FL_FORM *, void *)
220 // Wrapper for the above
222 int C_LyXView_atCloseMainFormCB(FL_FORM * form, void * p)
224 return LyXView::atCloseMainFormCB(form, p);
228 void LyXView::setPosition(int x, int y)
230 fl_set_form_position(form_, x, y);
234 void LyXView::show(int place, int border, string const & title)
236 fl_show_form(form_, place, border, title.c_str());
237 lyxfunc->initMiniBuffer();
238 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
239 InitLyXLookup(fl_get_display(), form_->window);
244 void LyXView::create_form_form_main(int width, int height)
245 /* to make this work as it should, .lyxrc should have been
246 * read first; OR maybe this one should be made dynamic.
248 * We will probably not have lyxrc before the main form is
249 * initialized, because error messages from lyxrc parsing
250 * are presented (and rightly so) in GUI popups. Asger.
254 form_ = fl_bgn_form(FL_NO_BOX, width, height);
255 form_->u_vdata = this;
256 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
257 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
259 // Parameters for the appearance of the main form
261 int const bw = abs(fl_get_border_width());
266 menubar = new Menubar(this, menubackend);
272 toolbar = new Toolbar(this, air, 30 + air + bw, toolbardefaults);
281 int const ywork = 60 + 2 * air + bw;
282 int const workheight = height - ywork - (25 + 2 * air);
284 ::current_view = bufferview = new BufferView(this, air, ywork,
292 minibuffer = new MiniBuffer(this, air, height - (25 + air),
293 width - (2 * air), 25);
299 autosave_timeout.timeout.connect(SigC::slot(this, &LyXView::AutoSave));
305 // assign an icon to main form
306 string iconname = LibFileSearch("images", "lyx", "xpm");
307 if (!iconname.empty()) {
309 Pixmap lyx_p, lyx_mask;
310 lyx_p = fl_read_pixmapfile(fl_root,
318 fl_set_form_icon(form_, lyx_p, lyx_mask);
322 fl_set_form_minsize(form_, 50, 50);
330 // Set the textclass choice
331 invalidateLayoutChoice();
332 updateLayoutChoice();
335 // Start autosave timer
336 if (lyxrc.autosave) {
337 autosave_timeout.setTimeout(lyxrc.autosave * 1000);
338 autosave_timeout.start();
341 intl->InitKeyMapper(lyxrc.use_kbmap);
345 void LyXView::invalidateLayoutChoice()
351 void LyXView::updateLayoutChoice()
353 // This has a side-effect that the layouts are not showed when no
354 // document is loaded.
355 if (!view() || !view()->buffer()) {
356 toolbar->clearLayoutList();
360 // Update the layout display
361 if (last_textclass != int(buffer()->params.textclass)) {
362 toolbar->updateLayoutList(true);
363 last_textclass = int(buffer()->params.textclass);
366 toolbar->updateLayoutList(false);
370 LyXTextClass::size_type layout =
371 bufferview->text->cursor.par()->GetLayout();
373 if (layout != current_layout){
374 toolbar->setLayout(layout);
375 current_layout = layout;
380 // Updates the title of the window with the filename of the current document
381 void LyXView::updateWindowTitle()
383 static string last_title = "LyX";
384 string title = "LyX";
386 if (view()->available()) {
387 string const cur_title = buffer()->fileName();
388 if (!cur_title.empty()){
389 title += ": " + MakeDisplayPath(cur_title, 30);
390 if (!buffer()->isLyxClean())
391 title += _(" (Changed)");
392 if (buffer()->isReadonly())
393 title += _(" (read only)");
396 // Don't update title if it's the same as last time
397 if (title != last_title) {
398 fl_set_form_title(form_, title.c_str());
404 void LyXView::showState()
406 message(CurrentState(view()));
407 getToolbar()->update();