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"
28 #include "layout_forms.h"
31 #include "support/filetools.h" // OnlyFilename()
35 #include "frontends/Dialogs.h"
36 #include "frontends/Toolbar.h"
37 #include "frontends/Menubar.h"
38 #include "MenuBackend.h"
39 #include "ToolbarDefaults.h"
40 #include "lyx_gui_misc.h" // [update,Close,Redraw]AllBufferRelatedDialogs
41 #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 *);
54 #ifdef SIGC_CXX_NAMESPACES
55 using SigC::Connection;
59 LyXView::LyXView(int width, int height)
61 create_form_form_main(width, height);
62 fl_set_form_atclose(form_, C_LyXView_atCloseMainFormCB, 0);
63 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
64 lyxfunc = new LyXFunc(this);
67 // Make sure the buttons are disabled if needed.
71 dialogs_ = new Dialogs(this);
72 // temporary until all dialogs moved into Dialogs.
73 dialogs_->updateBufferDependent
74 .connect(slot(&updateAllVisibleBufferRelatedDialogs));
75 dialogs_->hideBufferDependent
76 .connect(slot(&CloseAllBufferRelatedDialogs));
77 Dialogs::redrawGUI.connect(slot(this, &LyXView::redraw));
78 Dialogs::redrawGUI.connect(slot(&RedrawAllBufferRelatedDialogs));
94 /// Redraw the main form.
95 void LyXView::redraw() {
96 lyxerr[Debug::INFO] << "LyXView::redraw()" << endl;
97 fl_redraw_form(form_);
98 minibuffer->Activate();
102 /// returns the buffer currently shown in the main form.
103 Buffer * LyXView::buffer() const
105 return bufferview->buffer();
109 BufferView * LyXView::view() const
115 FL_FORM * LyXView::getForm() const
121 Toolbar * LyXView::getToolbar() const
127 void LyXView::setLayout(LyXTextClass::size_type layout)
129 toolbar->setLayout(layout);
133 void LyXView::updateToolbar()
140 LyXFunc * LyXView::getLyXFunc() const
146 MiniBuffer * LyXView::getMiniBuffer() const
152 Menubar * LyXView::getMenubar() const
158 void LyXView::updateMenubar()
160 if ((!view() || !view()->buffer())
161 && menubackend.hasMenu("main_nobuffer"))
162 menubar->set("main_nobuffer");
164 menubar->set("main");
168 Intl * LyXView::getIntl() const
174 // Callback for autosave timer
175 void LyXView::AutoSave()
177 lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
178 if (view()->available())
183 /// Reset autosave timer
184 void LyXView::resetAutosaveTimer()
187 autosave_timeout.restart();
191 // Callback for close main form from window manager
192 int LyXView::atCloseMainFormCB(FL_FORM *, void *)
199 // Wrapper for the above
201 int C_LyXView_atCloseMainFormCB(FL_FORM * form, void * p)
203 return LyXView::atCloseMainFormCB(form, p);
207 void LyXView::setPosition(int x, int y)
209 fl_set_form_position(form_, x, y);
213 void LyXView::show(int place, int border, string const & title)
215 fl_show_form(form_, place, border, title.c_str());
217 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
218 InitLyXLookup(fl_get_display(), form_->window);
223 void LyXView::create_form_form_main(int width, int height)
224 /* to make this work as it should, .lyxrc should have been
225 * read first; OR maybe this one should be made dynamic.
227 * We will probably not have lyxrc before the main form is
228 * initialized, because error messages from lyxrc parsing
229 * are presented (and rightly so) in GUI popups. Asger.
233 form_ = fl_bgn_form(FL_NO_BOX, width, height);
234 form_->u_vdata = this;
235 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
236 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
238 // Parameters for the appearance of the main form
240 int const bw = abs(fl_get_border_width());
245 menubar = new Menubar(this, menubackend);
251 toolbar = new Toolbar(this, air, 30 + air + bw, toolbardefaults);
260 int const ywork = 60 + 2 * air + bw;
261 int const workheight = height - ywork - (25 + 2 * air);
263 ::current_view = bufferview = new BufferView(this, air, ywork,
271 minibuffer = new MiniBuffer(this, air, height - (25 + air),
272 width - (2 * air), 25);
278 autosave_timeout.timeout.connect(slot(this, &LyXView::AutoSave));
284 // assign an icon to main form
285 string iconname = LibFileSearch("images", "lyx", "xpm");
286 if (!iconname.empty()) {
288 Pixmap lyx_p, lyx_mask;
289 lyx_p = fl_read_pixmapfile(fl_root,
297 fl_set_form_icon(form_, lyx_p, lyx_mask);
301 fl_set_form_minsize(form_, 50, 50);
309 // Set the textclass choice
310 invalidateLayoutChoice();
311 updateLayoutChoice();
314 // Start autosave timer
315 if (lyxrc.autosave) {
316 autosave_timeout.setTimeout(lyxrc.autosave * 1000);
317 autosave_timeout.start();
320 intl->InitKeyMapper(lyxrc.use_kbmap);
324 void LyXView::invalidateLayoutChoice()
330 void LyXView::updateLayoutChoice()
332 // This has a side-effect that the layouts are not showed when no
333 // document is loaded.
334 if (!view() || !view()->buffer()) {
335 toolbar->clearLayoutList();
339 // Update the layout display
340 if (last_textclass != int(buffer()->params.textclass)) {
341 toolbar->updateLayoutList(true);
342 last_textclass = int(buffer()->params.textclass);
345 toolbar->updateLayoutList(false);
349 LyXTextClass::size_type layout =
350 bufferview->text->cursor.par()->GetLayout();
352 if (layout != current_layout){
353 toolbar->setLayout(layout);
354 current_layout = layout;
359 // Updates the title of the window with the filename of the current document
360 void LyXView::updateWindowTitle()
362 static string last_title = "LyX";
363 string title = "LyX";
365 if (view()->available()) {
366 string cur_title = buffer()->fileName();
367 if (!cur_title.empty()){
368 title += ": " + MakeDisplayPath(cur_title, 30);
369 if (!buffer()->isLyxClean())
370 title += _(" (Changed)");
371 if (buffer()->isReadonly())
372 title += _(" (read only)");
375 // Don't update title if it's the same as last time
376 if (title != last_title) {
377 fl_set_form_title(form_, title.c_str());
383 void LyXView::showState()
385 getMiniBuffer()->Set(CurrentState(view()));
386 getToolbar()->update();