]> git.lyx.org Git - lyx.git/blobdiff - src/LyXView.C
Added html export for LinuxDoc and DocBook. LinuxDoc import now available in file...
[lyx.git] / src / LyXView.C
index 79a5e9a7df59ec935704911045dcb34a0bbbe5c9..86316604667a70e7a74d9ada5f8c7166bf83f22c 100644 (file)
@@ -5,7 +5,7 @@
  *           LyX, The Document Processor
  *        
  *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-1999 The LyX Team.
+ *           Copyright 1995-2000 The LyX Team.
  *
  * ====================================================== */
 
@@ -15,6 +15,9 @@
 #pragma implementation
 #endif
 
+#include <sys/time.h>
+#include <unistd.h>
+
 #include "LyXView.h"
 #include "lyx_main.h"
 #include "lyxlookup.h"
@@ -26,7 +29,6 @@
 #include "layout_forms.h"
 #include "intl.h"
 #include "lyxrc.h"
-#include "lyxscreen.h"
 #include "support/filetools.h"        // OnlyFilename()
 #include "layout.h"
 #include "lyxtext.h"
@@ -36,7 +38,7 @@ extern FD_form_document * fd_form_document;
 extern void AutoSave();
 extern char updatetimer;
 extern void QuitLyX();
-int current_layout = 0;
+LyXTextClass::size_type current_layout = 0;
 
 // This is very temporary
 BufferView * current_view;
@@ -78,10 +80,10 @@ void LyXView::UpdateTimerCB(FL_OBJECT * ob, long)
        LyXView * view = static_cast<LyXView*>(ob->u_vdata);
        if (!view->view()->available()) 
                return;
-       if (!view->view()->getScreen() || !updatetimer)
+       if (!updatetimer)
                return;
 
-       view->view()->getScreen()->HideCursor();
+       view->view()->hideCursor();
        view->view()->update(-2);
 
        /* This update can happen, even when the work area has lost
@@ -115,8 +117,8 @@ extern "C" void C_LyXView_AutosaveTimerCB(FL_OBJECT * ob, long data)
 /// Reset autosave timer
 void LyXView::resetAutosaveTimer()
 {
-       if (lyxrc->autosave)
-               fl_set_timer(_form_main->timer_autosave, lyxrc->autosave);
+       if (lyxrc.autosave)
+               fl_set_timer(_form_main->timer_autosave, lyxrc.autosave);
 }
 
 
@@ -158,22 +160,20 @@ void LyXView::create_form_form_main(int width, int height)
         * are presented (and rightly so) in GUI popups. Asger. 
         */
 {
-       FL_OBJECT * obj;
-       
-       FD_form_main *fdui = (FD_form_main *)
-               fl_calloc(1, sizeof(FD_form_main));
+       FD_form_main * fdui = static_cast<FD_form_main *>
+               (fl_calloc(1, sizeof(FD_form_main)));
 
        _form_main = fdui;
 
        // the main form
        _form = fdui->form_main = fl_bgn_form(FL_NO_BOX, width, height);
        fdui->form_main->u_vdata = this;
-       obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
+       FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
        fl_set_object_color(obj, FL_MCOL, FL_MCOL);
 
        // Parameters for the appearance of the main form
-       const int air = 2;
-       const int bw = abs(fl_get_border_width());
+       int const air = 2;
+       int const bw = abs(fl_get_border_width());
        
        //
        // THE MENUBAR
@@ -185,7 +185,7 @@ void LyXView::create_form_form_main(int width, int height)
        // TOOLBAR
        //
 
-       toolbar = new Toolbar(lyxrc->toolbar, this, air, 30 + air + bw);
+       toolbar = new Toolbar(this, air, 30 + air + bw);
 
        // Setup the toolbar
        toolbar->set(true);
@@ -194,19 +194,19 @@ void LyXView::create_form_form_main(int width, int height)
        // WORKAREA
        //
 
-       const int ywork = 60 + 2*air + bw;
-       const int workheight = height - ywork - (25 + 2*air);
+       int const ywork = 60 + 2 * air + bw;
+       int const workheight = height - ywork - (25 + 2 * air);
 
        ::current_view = bufferview = new BufferView(this, air, ywork,
-                                                    width - 3*air,
+                                                    width - 3 * air,
                                                     workheight);
 
        //
        // MINIBUFFER
        //
 
-       minibuffer = new MiniBuffer(this, air, height-(25+air), 
-                                   width-(2*air), 25);
+       minibuffer = new MiniBuffer(this, air, height - (25 + air), 
+                                   width - (2 * air), 25);
 
        //
        // TIMERS
@@ -257,15 +257,15 @@ void LyXView::init()
        UpdateDocumentClassChoice();
        
        // Start autosave timer
-       if (lyxrc->autosave)
-               fl_set_timer(_form_main->timer_autosave, lyxrc->autosave);
+       if (lyxrc.autosave)
+               fl_set_timer(_form_main->timer_autosave, lyxrc.autosave);
        
        
        // Install the raw callback for keyboard events 
        fl_register_raw_callback(_form,
                                 KeyPressMask,
                                 C_LyXView_KeyPressMask_raw_callback);
-        intl->InitKeyMapper(lyxrc->use_kbmap);
+        intl->InitKeyMapper(lyxrc.use_kbmap);
 }
 
 
@@ -292,16 +292,13 @@ void LyXView::updateLayoutChoice()
        if (toolbar->combox->empty() ||
            (last_textclass != int(buffer()->params.textclass))) {
                toolbar->combox->clear();
-               for (int i = 0;
-                    textclasslist.NameOfLayout(buffer()->
-                        params.textclass, i) != "@@end@@";
-                    i++) {
-                       LyXLayout const & layout = textclasslist.
-                               Style(buffer()->params.textclass, i);
-                       if (layout.obsoleted_by().empty())
-                               toolbar->combox->addline(layout.name().c_str());
+               LyXTextClass const & tc = textclasslist.TextClass(buffer()->params.textclass);
+               for (LyXTextClass::const_iterator cit = tc.begin();
+                    cit != tc.end(); ++cit) {
+                       if ((*cit).obsoleted_by().empty())
+                               toolbar->combox->addline((*cit).name().c_str());
                        else
-                               toolbar->combox->addline(("@N"+layout.name()).c_str());
+                               toolbar->combox->addline(("@N" + (*cit).name()).c_str());
                }
                last_textclass = int(buffer()->params.textclass);
                current_layout = 0;
@@ -309,7 +306,7 @@ void LyXView::updateLayoutChoice()
        // we need to do this.
        toolbar->combox->Redraw();
 
-       char layout = bufferview->text->cursor.par->GetLayout();
+       LyXTextClass::size_type layout = bufferview->text->cursor.par->GetLayout();
 
        if (layout != current_layout){
                toolbar->combox->select(layout + 1);
@@ -323,10 +320,10 @@ void LyXView::UpdateDocumentClassChoice()
        // Update the document class display in the document form
        if (fd_form_document) {
                fl_clear_choice(fd_form_document->choice_class);
-               for (int i = 0;
-                    textclasslist.DescOfClass(i) != "@@end@@"; ++i) {
+               for (LyXTextClassList::const_iterator cit = textclasslist.begin();
+                    cit != textclasslist.end(); ++cit) {
                        fl_addto_choice(fd_form_document->choice_class,
-                                       textclasslist.DescOfClass(i).c_str());
+                                       (*cit).description().c_str());
                }
        }
 }
@@ -339,14 +336,50 @@ int LyXView::KeyPressMask_raw_callback(FL_FORM * fl, void * xev)
        LyXView * view = static_cast<LyXView*>(fl->u_vdata);
        int retval = 0;  // 0 means XForms should have a look at this event
 
+       XKeyEvent * xke = static_cast<XKeyEvent*>(xev);
+       static Time last_time_pressed = 0;
+       static Time last_time_released = 0;
+       static unsigned int last_key_pressed = 0;
+       static unsigned int last_key_released = 0;
+       static unsigned int last_state_pressed = 0;
+       static unsigned int last_state_released = 0;
+
        // funny. Even though the raw_callback is registered with KeyPressMask,
        // also KeyRelease-events are passed through:-(
        // [It seems that XForms puts them in pairs... (JMarc)]
        if (static_cast<XEvent*>(xev)->type == KeyPress
-           && view->bufferview->getWorkArea()->focus
-           && view->bufferview->getWorkArea()->active)
+           && view->bufferview->focus()
+           && view->bufferview->active())
+               {
+               last_time_pressed = xke->time;
+               last_key_pressed = xke->keycode;
+               last_state_pressed = xke->state;
                retval = view->getLyXFunc()
                        ->processKeyEvent(static_cast<XEvent*>(xev));
+       }
+       else if (static_cast<XEvent*>(xev)->type == KeyRelease
+                && view->bufferview->focus()
+                && view->bufferview->active())
+{
+               last_time_released = xke->time;
+               last_key_released = xke->keycode;
+               last_state_released = xke->state;
+       }
+
+       if (last_key_released == last_key_pressed
+           && last_state_released == last_state_pressed
+           && last_time_released == last_time_pressed) {
+               // When the diff between last_time_released and
+               // last_time_pressed is 0, that sinifies an autoreapeat
+               // at least on my system. It like some feedback from
+               // others, especially from user running LyX remote.
+               //lyxerr << "Syncing - purging X events." << endl;
+               XSync(fl_get_display(), 1);
+               // This purge make f.ex. scrolling stop imidiatly when
+               // releaseing the PageDown button. The question is if this
+               // purging of XEvents can cause any harm...after some testing
+               // I can see no problems, but I'd like other reports too.
+       }
        return retval;
 }