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 *);
53 #ifdef SIGC_CXX_NAMESPACES
54 using SigC::Connection;
58 LyXView::LyXView(int width, int height)
60 create_form_form_main(width, height);
61 fl_set_form_atclose(form_, C_LyXView_atCloseMainFormCB, 0);
62 lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
63 lyxfunc = new LyXFunc(this);
66 // Make sure the buttons are disabled if needed.
70 dialogs_ = new Dialogs(this);
71 // temporary until all dialogs moved into Dialogs.
72 dialogs_->updateBufferDependent
73 .connect(slot(&updateAllVisibleBufferRelatedDialogs));
74 dialogs_->hideBufferDependent
75 .connect(slot(&CloseAllBufferRelatedDialogs));
76 Dialogs::redrawGUI.connect(slot(this, &LyXView::redraw));
77 Dialogs::redrawGUI.connect(slot(&RedrawAllBufferRelatedDialogs));
93 /// Redraw the main form.
94 void LyXView::redraw() {
95 lyxerr[Debug::INFO] << "LyXView::redraw()" << endl;
96 fl_redraw_form(form_);
97 minibuffer->Activate();
101 /// returns the buffer currently shown in the main form.
102 Buffer * LyXView::buffer() const
104 return bufferview->buffer();
108 BufferView * LyXView::view() const
114 FL_FORM * LyXView::getForm() const
120 Toolbar * LyXView::getToolbar() const
126 void LyXView::setLayout(LyXTextClass::size_type layout)
128 toolbar->setLayout(layout);
132 void LyXView::updateToolbar()
139 LyXFunc * LyXView::getLyXFunc() const
145 MiniBuffer * LyXView::getMiniBuffer() const
151 Menubar * LyXView::getMenubar() const
157 void LyXView::updateMenubar()
159 if ((!view() || !view()->buffer())
160 && menubackend.hasMenu("main_nobuffer"))
161 menubar->set("main_nobuffer");
163 menubar->set("main");
167 Intl * LyXView::getIntl() const
173 // Callback for autosave timer
174 void LyXView::AutoSave()
176 lyxerr[Debug::INFO] << "Running AutoSave()" << endl;
177 if (view()->available())
182 /// Reset autosave timer
183 void LyXView::resetAutosaveTimer()
186 autosave_timeout.restart();
190 // Callback for close main form from window manager
191 int LyXView::atCloseMainFormCB(FL_FORM *, void *)
198 // Wrapper for the above
200 int C_LyXView_atCloseMainFormCB(FL_FORM * form, void * p)
202 return LyXView::atCloseMainFormCB(form, p);
206 void LyXView::setPosition(int x, int y)
208 fl_set_form_position(form_, x, y);
212 void LyXView::show(int place, int border, string const & title)
214 fl_show_form(form_, place, border, title.c_str());
216 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
217 InitLyXLookup(fl_get_display(), form_->window);
222 void LyXView::create_form_form_main(int width, int height)
223 /* to make this work as it should, .lyxrc should have been
224 * read first; OR maybe this one should be made dynamic.
226 * We will probably not have lyxrc before the main form is
227 * initialized, because error messages from lyxrc parsing
228 * are presented (and rightly so) in GUI popups. Asger.
232 form_ = fl_bgn_form(FL_NO_BOX, width, height);
233 form_->u_vdata = this;
234 FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
235 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
237 // Parameters for the appearance of the main form
239 int const bw = abs(fl_get_border_width());
244 menubar = new Menubar(this, menubackend);
250 toolbar = new Toolbar(this, air, 30 + air + bw, toolbardefaults);
259 int const ywork = 60 + 2 * air + bw;
260 int const workheight = height - ywork - (25 + 2 * air);
262 ::current_view = bufferview = new BufferView(this, air, ywork,
270 minibuffer = new MiniBuffer(this, air, height - (25 + air),
271 width - (2 * air), 25);
277 autosave_timeout.timeout.connect(slot(this, &LyXView::AutoSave));
283 // assign an icon to main form
284 string iconname = LibFileSearch("images", "lyx", "xpm");
285 if (!iconname.empty()) {
287 Pixmap lyx_p, lyx_mask;
288 lyx_p = fl_read_pixmapfile(fl_root,
296 fl_set_form_icon(form_, lyx_p, lyx_mask);
300 fl_set_form_minsize(form_, 50, 50);
308 // Set the textclass choice
309 invalidateLayoutChoice();
310 updateLayoutChoice();
313 // Start autosave timer
314 if (lyxrc.autosave) {
315 autosave_timeout.setTimeout(lyxrc.autosave * 1000);
316 autosave_timeout.start();
319 intl->InitKeyMapper(lyxrc.use_kbmap);
323 void LyXView::invalidateLayoutChoice()
329 void LyXView::updateLayoutChoice()
331 // This has a side-effect that the layouts are not showed when no
332 // document is loaded.
333 if (!view() || !view()->buffer()) {
334 toolbar->clearLayoutList();
338 // Update the layout display
339 if (last_textclass != int(buffer()->params.textclass)) {
340 toolbar->updateLayoutList(true);
341 last_textclass = int(buffer()->params.textclass);
344 toolbar->updateLayoutList(false);
348 LyXTextClass::size_type layout =
349 bufferview->text->cursor.par()->GetLayout();
351 if (layout != current_layout){
352 toolbar->setLayout(layout);
353 current_layout = layout;
358 // Updates the title of the window with the filename of the current document
359 void LyXView::updateWindowTitle()
361 static string last_title = "LyX";
362 string title = "LyX";
364 if (view()->available()) {
365 string cur_title = buffer()->fileName();
366 if (!cur_title.empty()){
367 title += ": " + MakeDisplayPath(cur_title, 30);
368 if (!buffer()->isLyxClean())
369 title += _(" (Changed)");
370 if (buffer()->isReadonly())
371 title += _(" (read only)");
374 // Don't update title if it's the same as last time
375 if (title != last_title) {
376 fl_set_form_title(form_, title.c_str());
382 void LyXView::showState()
384 getMiniBuffer()->Set(CurrentState(view()));
385 getToolbar()->update();