2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright (C) 1995 Matthias Ettrich
8 * Copyright (C) 1995-1998 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 "filetools.h" // OnlyFilename()
34 // $Id: LyXView.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $
36 #if !defined(lint) && !defined(WITH_WARNINGS)
37 static char vcid[] = "$Id: LyXView.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $";
40 extern FD_form_document *fd_form_document;
41 FD_form_main *fd_form_main; /* a pointer to the one in LyXView
42 should be removed as soon as possible */
44 MiniBuffer *minibuffer;/* a pointer to the one in LyXView
45 should be removed as soon as possible */
47 extern void AutoSave();
48 extern char updatetimer;
49 extern void QuitLyX();
50 int current_layout = 0;
52 // This is very temporary
53 BufferView *current_view;
56 LyXView::LyXView(int width, int height)
58 fd_form_main = create_form_form_main(width,height);
59 fl_set_form_atclose(_form, atCloseMainFormCB, NULL);
60 lyxerr.debug("Initializing LyXFunc");
61 lyxfunc = new LyXFunc(this);
76 /// Redraw the main form.
77 void LyXView::redraw() {
78 lyxerr.debug("LyXView::redraw()");
79 fl_redraw_form(_form);
80 minibuffer->Activate();
84 // Callback for update timer
85 void LyXView::UpdateTimerCB(FL_OBJECT *ob, long)
87 LyXView *view = (LyXView*) ob->u_vdata;
88 if (!view->currentView()->available())
90 if (!view->currentView()->getScreen() || !updatetimer)
93 view->currentView()->getScreen()->HideCursor();
94 view->currentBuffer()->update(-2);
95 /* This update can happen, even when the work area has lost
96 * the focus. So suppress the cursor in that case */
101 // Callback for autosave timer
102 void LyXView::AutosaveTimerCB(FL_OBJECT *, long)
104 lyxerr.debug("Running AutoSave()");
109 /// Reset autosave timer
110 void LyXView::resetAutosaveTimer()
113 fl_set_timer(_form_main->timer_autosave, lyxrc->autosave);
117 // Callback for close main form from window manager
118 int LyXView::atCloseMainFormCB(FL_FORM *, void *)
125 void LyXView::setPosition(int x, int y)
127 fl_set_form_position(_form, x, y);
131 void LyXView::show(int place, int border, char const* title)
133 fl_show_form(_form, place, border, title);
135 InitLyXLookup(fl_display, _form->window);
139 FD_form_main *LyXView::create_form_form_main(int width, int height)
140 /* to make this work as it should, .lyxrc should have been
141 * read first; OR maybe this one should be made dynamic.
143 * We will probably not have lyxrc before the main form is
144 * initialized, because error messages from lyxrc parsing
145 * are presented (and rightly so) in GUI popups. Asger.
150 FD_form_main *fdui = (FD_form_main *)
151 fl_calloc(1, sizeof(FD_form_main));
156 _form = fdui->form_main = fl_bgn_form(FL_NO_BOX, width, height);
157 fdui->form_main->u_vdata = (void*) this;
158 obj = fl_add_box(FL_FLAT_BOX,0,0,width,height,"");
159 fl_set_object_color(obj,FL_MCOL,FL_MCOL);
161 // Parameters for the appearance of the main form
163 const int bw = abs(fl_get_border_width());
169 menus = new Menus(this, air);
175 toolbar = new Toolbar(lyxrc->toolbar, this, air, 30 + air + bw);
184 const int ywork = 60 + 2*air + bw;
185 const int workheight = height - ywork - (25 + 2*air);
187 ::current_view = bufferview = new BufferView(this, air, ywork,
195 minibuffer = new MiniBuffer(this, air, height-(25+air),
197 ::minibuffer = minibuffer; // to be removed later
205 fdui->timer_autosave = obj = fl_add_timer(FL_HIDDEN_TIMER,
207 fl_set_object_callback(obj,AutosaveTimerCB,0);
210 fdui->timer_update = obj = fl_add_timer(FL_HIDDEN_TIMER,
212 fl_set_object_callback(obj,UpdateTimerCB,0);
213 obj->u_vdata = (void*) this;
219 // assign an icon to main form
221 Pixmap lyx_p, lyx_mask;
222 lyx_p = fl_create_from_pixmapdata(fl_root,
230 fl_set_form_icon(fdui->form_main, lyx_p, lyx_mask);
233 fl_set_form_minsize(fdui->form_main, 50, 50);
243 // Set the textclass choice
244 invalidateLayoutChoice();
245 updateLayoutChoice();
246 UpdateDocumentClassChoice();
248 // Start autosave timer
250 fl_set_timer(_form_main->timer_autosave, lyxrc->autosave);
253 // Install the raw callback for keyboard events
254 fl_register_raw_callback(_form,
256 KeyPressMask_raw_callback);
257 intl->InitKeyMapper(lyxrc->use_kbmap);
261 void LyXView::invalidateLayoutChoice()
267 void LyXView::updateLayoutChoice()
269 /* update the layout display */
270 if (!toolbar->combox) return;
272 // this has a bi-effect that the layouts are not showed when no
273 // document is loaded.
274 if (bufferview==0 || bufferview->currentBuffer()==0) {
275 toolbar->combox->clear();
276 toolbar->combox->Redraw();
280 // If textclass is different, we need to update the list
281 if (toolbar->combox->empty() ||
282 (last_textclass != currentBuffer()->params.textclass)) {
283 toolbar->combox->clear();
285 lyxstyle.NameOfLayout(currentBuffer()->
286 params.textclass, i) !="@@end@@";
288 LyXLayout *layout = lyxstyle.
289 Style(currentBuffer()->params.textclass, i);
290 if (layout->obsoleted_by.empty())
291 toolbar->combox->addline(layout->name.c_str());
293 toolbar->combox->addline(("@N"+layout->name).c_str());
295 last_textclass = currentBuffer()->params.textclass;
298 // we need to do this.
299 toolbar->combox->Redraw();
301 char layout = currentBuffer()->text->cursor.par->GetLayout();
303 if (layout != current_layout){
304 toolbar->combox->select(layout + 1);
305 current_layout = layout;
310 void LyXView::UpdateDocumentClassChoice()
312 /* update the document class display in the document form */
314 if (fd_form_document) {
315 fl_clear_choice(fd_form_document->choice_class);
316 for (i = 0; lyxstyle.DescOfClass (i)!="@@end@@"; i++) {
317 fl_addto_choice(fd_form_document->choice_class,
318 lyxstyle.DescOfClass(i).c_str());
324 // This is necessary, since FL_FREE-Objects doesn't get all keypress events
325 // as FL_KEYBOARD events :-( Matthias 280596
326 int LyXView::KeyPressMask_raw_callback(FL_FORM *fl, void *xev)
328 LyXView *view = (LyXView*) fl->u_vdata;
329 int retval = 0; // 0 means XForms should have a look at this event
331 // funny. Even though the raw_callback is registered with KeyPressMask,
332 // also KeyRelease-events are passed through:-(
333 // [It seems that xforms puts them in pairs... (JMarc)]
334 if (((XEvent*)xev)->type == KeyPress
335 && view->bufferview->getWorkArea()->focus
336 && view->bufferview->getWorkArea()->active)
337 retval = view->getLyXFunc()->processKeyEvent((XEvent*)xev);
343 // Updates the title of the window with the filename of the current document
344 void LyXView::updateWindowTitle() {
345 static LString last_title="LyX";
346 LString title = "LyX";
348 if (currentView()->available()) {
349 LString cur_title = currentBuffer()->getFileName();
350 if (!cur_title.empty()){
351 title += ": " + OnlyFilename(cur_title);
352 if (!currentBuffer()->isLyxClean())
353 title += _(" (Changed)");
354 if (currentBuffer()->isReadonly())
355 title += _(" (read only)");
358 // Don't update title if it's the same as last time
359 if (title != last_title) {
360 fl_set_form_title(_form, title.c_str());