2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2001 The LyX Team.
10 * ====================================================== */
15 #pragma implementation
23 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
24 #include "lyxlookup.h"
26 #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()
43 #include "BufferView.h"
47 extern void AutoSave(BufferView *);
48 extern void QuitLyX();
49 LyXTextClass::size_type current_layout = 0;
51 // This is very temporary
52 BufferView * current_view;
54 extern "C" int C_LyXView_atCloseMainFormCB(FL_FORM *, void *);
57 LyXView::LyXView(int width, int height)
59 create_form_form_main(width, height);
60 fl_set_form_atclose(form_, C_LyXView_atCloseMainFormCB, 0);
61 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
62 lyxfunc = new LyXFunc(this);
64 // Connect the minibuffer signals
65 minibuffer->stringReady.connect(SigC::slot(lyxfunc,
66 &LyXFunc::miniDispatch));
67 minibuffer->timeout.connect(SigC::slot(lyxfunc,
68 &LyXFunc::initMiniBuffer));
72 // Make sure the buttons are disabled if needed.
76 dialogs_ = new Dialogs(this);
77 // temporary until all dialogs moved into Dialogs.
78 dialogs_->updateBufferDependent
79 .connect(SigC::slot(&updateAllVisibleBufferRelatedDialogs));
80 dialogs_->hideBufferDependent
81 .connect(SigC::slot(&CloseAllBufferRelatedDialogs));
82 Dialogs::redrawGUI.connect(SigC::slot(this, &LyXView::redraw));
83 Dialogs::redrawGUI.connect(SigC::slot(&RedrawAllBufferRelatedDialogs));
99 /// Redraw the main form.
100 void LyXView::redraw() {
101 lyxerr[Debug::INFO] << "LyXView::redraw()" << endl;
102 fl_redraw_form(form_);
103 minibuffer->redraw();
107 void LyXView::resize()
113 /// returns the buffer currently shown in the main form.
114 Buffer * LyXView::buffer() const
116 return bufferview->buffer();
120 BufferView * LyXView::view() const
126 FL_FORM * LyXView::getForm() const
132 Toolbar * LyXView::getToolbar() const
138 void LyXView::setLayout(LyXTextClass::size_type layout)
140 toolbar->setLayout(layout);
144 void LyXView::updateToolbar()
151 LyXFunc * LyXView::getLyXFunc() const
157 MiniBuffer * LyXView::getMiniBuffer() const
163 void LyXView::message(string const & str)
165 minibuffer->message(str);
169 void LyXView::messagePush(string const & str)
171 minibuffer->messagePush(str);
175 void LyXView::messagePop()
177 minibuffer->messagePop();
181 Menubar * LyXView::getMenubar() const
187 void LyXView::updateMenubar()
189 if ((!view() || !view()->buffer())
190 && menubackend.hasMenu("main_nobuffer"))
191 menubar->set("main_nobuffer");
193 menubar->set("main");
197 Intl * LyXView::getIntl() const
203 // Callback for autosave timer
204 void LyXView::AutoSave()
206 lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
207 if (view()->available())
212 /// Reset autosave timer
213 void LyXView::resetAutosaveTimer()
216 autosave_timeout.restart();
220 // Callback for close main form from window manager
221 int LyXView::atCloseMainFormCB(FL_FORM *, void *)
228 // Wrapper for the above
230 int C_LyXView_atCloseMainFormCB(FL_FORM * form, void * p)
232 return LyXView::atCloseMainFormCB(form, p);
236 void LyXView::setPosition(int x, int y)
238 fl_set_form_position(form_, x, y);
242 void LyXView::show(int place, int border, string const & title)
244 fl_show_form(form_, place, border, title.c_str());
245 lyxfunc->initMiniBuffer();
246 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
247 InitLyXLookup(fl_get_display(), form_->window);
252 void LyXView::create_form_form_main(int width, int height)
253 /* to make this work as it should, .lyxrc should have been
254 * read first; OR maybe this one should be made dynamic.
256 * We will probably not have lyxrc before the main form is
257 * initialized, because error messages from lyxrc parsing
258 * are presented (and rightly so) in GUI popups. Asger.
262 form_ = fl_bgn_form(FL_NO_BOX, width, height);
263 form_->u_vdata = this;
264 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
265 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
267 // Parameters for the appearance of the main form
269 int const bw = abs(fl_get_border_width());
274 menubar = new Menubar(this, menubackend);
280 toolbar = new Toolbar(this, air, 30 + air + bw, toolbardefaults);
289 int const ywork = 60 + 2 * air + bw;
290 int const workheight = height - ywork - (25 + 2 * air);
292 ::current_view = bufferview = new BufferView(this, air, ywork,
300 minibuffer = new MiniBuffer(this, air, height - (25 + air),
301 width - (2 * air), 25);
307 autosave_timeout.timeout.connect(SigC::slot(this, &LyXView::AutoSave));
313 // assign an icon to main form
314 string iconname = LibFileSearch("images", "lyx", "xpm");
315 if (!iconname.empty()) {
317 Pixmap lyx_p, lyx_mask;
318 lyx_p = fl_read_pixmapfile(fl_root,
326 fl_set_form_icon(form_, lyx_p, lyx_mask);
330 fl_set_form_minsize(form_, 50, 50);
338 // Set the textclass choice
339 invalidateLayoutChoice();
340 updateLayoutChoice();
343 // Start autosave timer
344 if (lyxrc.autosave) {
345 autosave_timeout.setTimeout(lyxrc.autosave * 1000);
346 autosave_timeout.start();
349 intl->InitKeyMapper(lyxrc.use_kbmap);
353 void LyXView::invalidateLayoutChoice()
359 void LyXView::updateLayoutChoice()
361 // This has a side-effect that the layouts are not showed when no
362 // document is loaded.
363 if (!view() || !view()->buffer()) {
364 toolbar->clearLayoutList();
368 // Update the layout display
369 if (last_textclass != int(buffer()->params.textclass)) {
370 toolbar->updateLayoutList(true);
371 last_textclass = int(buffer()->params.textclass);
374 toolbar->updateLayoutList(false);
378 LyXTextClass::size_type layout =
379 bufferview->text->cursor.par()->getLayout();
381 if (layout != current_layout){
382 toolbar->setLayout(layout);
383 current_layout = layout;
388 // Updates the title of the window with the filename of the current document
389 void LyXView::updateWindowTitle()
391 static string last_title = "LyX";
392 string title = "LyX";
394 if (view()->available()) {
395 string const cur_title = buffer()->fileName();
396 if (!cur_title.empty()){
397 title += ": " + MakeDisplayPath(cur_title, 30);
398 if (!buffer()->isLyxClean())
399 title += _(" (Changed)");
400 if (buffer()->isReadonly())
401 title += _(" (read only)");
404 // Don't update title if it's the same as last time
405 if (title != last_title) {
406 fl_set_form_title(form_, title.c_str());
412 void LyXView::showState()
414 message(CurrentState(view()));
415 getToolbar()->update();