1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 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"
30 #include "support/filetools.h" // OnlyFilename()
34 #include "frontends/Dialogs.h"
35 #include "frontends/Toolbar.h"
36 #include "frontends/Menubar.h"
37 #include "MenuBackend.h"
38 #include "ToolbarDefaults.h"
39 #include "lyx_gui_misc.h" // [update,Close,Redraw]AllBufferRelatedDialogs
40 #include "bufferview_funcs.h" // CurrentState()
44 extern void AutoSave(BufferView *);
45 extern void QuitLyX();
46 LyXTextClass::size_type current_layout = 0;
48 // This is very temporary
49 BufferView * current_view;
51 extern "C" int C_LyXView_atCloseMainFormCB(FL_FORM *, void *);
54 LyXView::LyXView(int width, int height)
56 create_form_form_main(width, height);
57 fl_set_form_atclose(form_, C_LyXView_atCloseMainFormCB, 0);
58 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
59 lyxfunc = new LyXFunc(this);
62 // Make sure the buttons are disabled if needed.
66 dialogs_ = new Dialogs(this);
67 // temporary until all dialogs moved into Dialogs.
68 dialogs_->updateBufferDependent
69 .connect(SigC::slot(&updateAllVisibleBufferRelatedDialogs));
70 dialogs_->hideBufferDependent
71 .connect(SigC::slot(&CloseAllBufferRelatedDialogs));
72 Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
73 Dialogs::redrawGUI.connect(SigC::slot(&RedrawAllBufferRelatedDialogs));
89 /// Redraw the main form.
90 void LyXView::redraw() {
91 lyxerr[Debug::INFO] << "LyXView::redraw()" << endl;
92 fl_redraw_form(form_);
93 minibuffer->Activate();
97 /// returns the buffer currently shown in the main form.
98 Buffer * LyXView::buffer() const
100 return bufferview->buffer();
104 BufferView * LyXView::view() const
110 FL_FORM * LyXView::getForm() const
116 Toolbar * LyXView::getToolbar() const
122 void LyXView::setLayout(LyXTextClass::size_type layout)
124 toolbar->setLayout(layout);
128 void LyXView::updateToolbar()
135 LyXFunc * LyXView::getLyXFunc() const
141 MiniBuffer * LyXView::getMiniBuffer() const
147 Menubar * LyXView::getMenubar() const
153 void LyXView::updateMenubar()
155 if ((!view() || !view()->buffer())
156 && menubackend.hasMenu("main_nobuffer"))
157 menubar->set("main_nobuffer");
159 menubar->set("main");
163 Intl * LyXView::getIntl() const
169 // Callback for autosave timer
170 void LyXView::AutoSave()
172 lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
173 if (view()->available())
178 /// Reset autosave timer
179 void LyXView::resetAutosaveTimer()
182 autosave_timeout.restart();
186 // Callback for close main form from window manager
187 int LyXView::atCloseMainFormCB(FL_FORM *, void *)
194 // Wrapper for the above
196 int C_LyXView_atCloseMainFormCB(FL_FORM * form, void * p)
198 return LyXView::atCloseMainFormCB(form, p);
202 void LyXView::setPosition(int x, int y)
204 fl_set_form_position(form_, x, y);
208 void LyXView::show(int place, int border, string const & title)
210 fl_show_form(form_, place, border, title.c_str());
212 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
213 InitLyXLookup(fl_get_display(), form_->window);
218 void LyXView::create_form_form_main(int width, int height)
219 /* to make this work as it should, .lyxrc should have been
220 * read first; OR maybe this one should be made dynamic.
222 * We will probably not have lyxrc before the main form is
223 * initialized, because error messages from lyxrc parsing
224 * are presented (and rightly so) in GUI popups. Asger.
228 form_ = fl_bgn_form(FL_NO_BOX, width, height);
229 form_->u_vdata = this;
230 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
231 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
233 // Parameters for the appearance of the main form
235 int const bw = abs(fl_get_border_width());
240 menubar = new Menubar(this, menubackend);
246 toolbar = new Toolbar(this, air, 30 + air + bw, toolbardefaults);
255 int const ywork = 60 + 2 * air + bw;
256 int const workheight = height - ywork - (25 + 2 * air);
258 ::current_view = bufferview = new BufferView(this, air, ywork,
266 minibuffer = new MiniBuffer(this, air, height - (25 + air),
267 width - (2 * air), 25);
273 autosave_timeout.timeout.connect(SigC::slot(this, &LyXView::AutoSave));
279 // assign an icon to main form
280 string iconname = LibFileSearch("images", "lyx", "xpm");
281 if (!iconname.empty()) {
283 Pixmap lyx_p, lyx_mask;
284 lyx_p = fl_read_pixmapfile(fl_root,
292 fl_set_form_icon(form_, lyx_p, lyx_mask);
296 fl_set_form_minsize(form_, 50, 50);
304 // Set the textclass choice
305 invalidateLayoutChoice();
306 updateLayoutChoice();
309 // Start autosave timer
310 if (lyxrc.autosave) {
311 autosave_timeout.setTimeout(lyxrc.autosave * 1000);
312 autosave_timeout.start();
315 intl->InitKeyMapper(lyxrc.use_kbmap);
319 void LyXView::invalidateLayoutChoice()
325 void LyXView::updateLayoutChoice()
327 // This has a side-effect that the layouts are not showed when no
328 // document is loaded.
329 if (!view() || !view()->buffer()) {
330 toolbar->clearLayoutList();
334 // Update the layout display
335 if (last_textclass != int(buffer()->params.textclass)) {
336 toolbar->updateLayoutList(true);
337 last_textclass = int(buffer()->params.textclass);
340 toolbar->updateLayoutList(false);
344 LyXTextClass::size_type layout =
345 bufferview->text->cursor.par()->GetLayout();
347 if (layout != current_layout){
348 toolbar->setLayout(layout);
349 current_layout = layout;
354 // Updates the title of the window with the filename of the current document
355 void LyXView::updateWindowTitle()
357 static string last_title = "LyX";
358 string title = "LyX";
360 if (view()->available()) {
361 string cur_title = buffer()->fileName();
362 if (!cur_title.empty()){
363 title += ": " + MakeDisplayPath(cur_title, 30);
364 if (!buffer()->isLyxClean())
365 title += _(" (Changed)");
366 if (buffer()->isReadonly())
367 title += _(" (read only)");
370 // Don't update title if it's the same as last time
371 if (title != last_title) {
372 fl_set_form_title(form_, title.c_str());
378 void LyXView::showState()
380 getMiniBuffer()->Set(CurrentState(view()));
381 getToolbar()->update();