2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-1999 The LyX Team.
10 * ======================================================*/
15 #pragma implementation
20 #include "lyxlookup.h"
22 #include "minibuffer.h"
26 #include "layout_forms.h"
29 #include "lyxscreen.h"
30 #include "support/filetools.h" // OnlyFilename()
34 extern FD_form_document *fd_form_document;
35 FD_form_main *fd_form_main; /* a pointer to the one in LyXView
36 should be removed as soon as possible */
38 MiniBuffer *minibuffer;/* a pointer to the one in LyXView
39 should be removed as soon as possible */
41 extern void AutoSave();
42 extern char updatetimer;
43 extern void QuitLyX();
44 int current_layout = 0;
46 // This is very temporary
47 BufferView *current_view;
50 LyXView::LyXView(int width, int height)
52 fd_form_main = create_form_form_main(width,height);
53 fl_set_form_atclose(_form, atCloseMainFormCB, 0);
54 lyxerr.debug() << "Initializing LyXFunc" << endl;
55 lyxfunc = new LyXFunc(this);
70 /// Redraw the main form.
71 void LyXView::redraw() {
72 lyxerr.debug() << "LyXView::redraw()" << endl;
73 fl_redraw_form(_form);
74 minibuffer->Activate();
78 // Callback for update timer
79 void LyXView::UpdateTimerCB(FL_OBJECT *ob, long)
81 LyXView *view = (LyXView*) ob->u_vdata;
82 if (!view->currentView()->available())
84 if (!view->currentView()->getScreen() || !updatetimer)
87 view->currentView()->getScreen()->HideCursor();
88 view->currentBuffer()->update(-2);
89 /* This update can happen, even when the work area has lost
90 * the focus. So suppress the cursor in that case */
95 // Callback for autosave timer
96 void LyXView::AutosaveTimerCB(FL_OBJECT *, long)
98 lyxerr.debug() << "Running AutoSave()" << endl;
103 /// Reset autosave timer
104 void LyXView::resetAutosaveTimer()
107 fl_set_timer(_form_main->timer_autosave, lyxrc->autosave);
111 // Callback for close main form from window manager
112 int LyXView::atCloseMainFormCB(FL_FORM *, void *)
119 void LyXView::setPosition(int x, int y)
121 fl_set_form_position(_form, x, y);
125 void LyXView::show(int place, int border, char const* title)
127 fl_show_form(_form, place, border, title);
129 InitLyXLookup(fl_display, _form->window);
133 FD_form_main *LyXView::create_form_form_main(int width, int height)
134 /* to make this work as it should, .lyxrc should have been
135 * read first; OR maybe this one should be made dynamic.
137 * We will probably not have lyxrc before the main form is
138 * initialized, because error messages from lyxrc parsing
139 * are presented (and rightly so) in GUI popups. Asger.
144 FD_form_main *fdui = (FD_form_main *)
145 fl_calloc(1, sizeof(FD_form_main));
150 _form = fdui->form_main = fl_bgn_form(FL_NO_BOX, width, height);
151 fdui->form_main->u_vdata = (void*) this;
152 obj = fl_add_box(FL_FLAT_BOX,0,0,width,height,"");
153 fl_set_object_color(obj,FL_MCOL,FL_MCOL);
155 // Parameters for the appearance of the main form
157 const int bw = abs(fl_get_border_width());
163 menus = new Menus(this, air);
169 toolbar = new Toolbar(lyxrc->toolbar, this, air, 30 + air + bw);
178 const int ywork = 60 + 2*air + bw;
179 const int workheight = height - ywork - (25 + 2*air);
181 ::current_view = bufferview = new BufferView(this, air, ywork,
189 minibuffer = new MiniBuffer(this, air, height-(25+air),
191 ::minibuffer = minibuffer; // to be removed later
199 fdui->timer_autosave = obj = fl_add_timer(FL_HIDDEN_TIMER,
201 fl_set_object_callback(obj,AutosaveTimerCB,0);
204 fdui->timer_update = obj = fl_add_timer(FL_HIDDEN_TIMER,
206 fl_set_object_callback(obj,UpdateTimerCB,0);
207 obj->u_vdata = (void*) this;
213 // assign an icon to main form
215 Pixmap lyx_p, lyx_mask;
216 lyx_p = fl_create_from_pixmapdata(fl_root,
224 fl_set_form_icon(fdui->form_main, lyx_p, lyx_mask);
227 fl_set_form_minsize(fdui->form_main, 50, 50);
237 // Set the textclass choice
238 invalidateLayoutChoice();
239 updateLayoutChoice();
240 UpdateDocumentClassChoice();
242 // Start autosave timer
244 fl_set_timer(_form_main->timer_autosave, lyxrc->autosave);
247 // Install the raw callback for keyboard events
248 fl_register_raw_callback(_form,
250 KeyPressMask_raw_callback);
251 intl->InitKeyMapper(lyxrc->use_kbmap);
255 void LyXView::invalidateLayoutChoice()
261 void LyXView::updateLayoutChoice()
263 /* update the layout display */
264 if (!toolbar->combox) return;
266 // this has a bi-effect that the layouts are not showed when no
267 // document is loaded.
268 if (bufferview==0 || bufferview->currentBuffer()==0) {
269 toolbar->combox->clear();
270 toolbar->combox->Redraw();
274 // If textclass is different, we need to update the list
275 if (toolbar->combox->empty() ||
276 (last_textclass != currentBuffer()->params.textclass)) {
277 toolbar->combox->clear();
279 lyxstyle.NameOfLayout(currentBuffer()->
280 params.textclass, i) !="@@end@@";
282 LyXLayout *layout = lyxstyle.
283 Style(currentBuffer()->params.textclass, i);
284 if (layout->obsoleted_by.empty())
285 toolbar->combox->addline(layout->name.c_str());
287 toolbar->combox->addline(("@N"+layout->name).c_str());
289 last_textclass = currentBuffer()->params.textclass;
292 // we need to do this.
293 toolbar->combox->Redraw();
295 char layout = currentBuffer()->text->cursor.par->GetLayout();
297 if (layout != current_layout){
298 toolbar->combox->select(layout + 1);
299 current_layout = layout;
304 void LyXView::UpdateDocumentClassChoice()
306 /* update the document class display in the document form */
308 if (fd_form_document) {
309 fl_clear_choice(fd_form_document->choice_class);
310 for (i = 0; lyxstyle.DescOfClass (i)!="@@end@@"; i++) {
311 fl_addto_choice(fd_form_document->choice_class,
312 lyxstyle.DescOfClass(i).c_str());
318 // This is necessary, since FL_FREE-Objects doesn't get all keypress events
319 // as FL_KEYBOARD events :-( Matthias 280596
320 int LyXView::KeyPressMask_raw_callback(FL_FORM *fl, void *xev)
322 LyXView *view = (LyXView*) fl->u_vdata;
323 int retval = 0; // 0 means XForms should have a look at this event
325 // funny. Even though the raw_callback is registered with KeyPressMask,
326 // also KeyRelease-events are passed through:-(
327 // [It seems that xforms puts them in pairs... (JMarc)]
328 if (((XEvent*)xev)->type == KeyPress
329 && view->bufferview->getWorkArea()->focus
330 && view->bufferview->getWorkArea()->active)
331 retval = view->getLyXFunc()->processKeyEvent((XEvent*)xev);
337 // Updates the title of the window with the filename of the current document
338 void LyXView::updateWindowTitle() {
339 static string last_title="LyX";
340 string title = "LyX";
342 if (currentView()->available()) {
343 string cur_title = currentBuffer()->getFileName();
344 if (!cur_title.empty()){
345 title += ": " + OnlyFilename(cur_title);
346 if (!currentBuffer()->isLyxClean())
347 title += _(" (Changed)");
348 if (currentBuffer()->isReadonly())
349 title += _(" (read only)");
352 // Don't update title if it's the same as last time
353 if (title != last_title) {
354 fl_set_form_title(_form, title.c_str());