]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormDocument.C
Disable various buttons when buffer is read only
[lyx.git] / src / frontends / xforms / FormDocument.C
index 1cd89f50c2b958938063fdfe5b8ae6ddadc3a313..b88a029bcd595b2a92c06c4c030935156abb0dc0 100644 (file)
@@ -3,7 +3,7 @@
  * 
  *           LyX, The Document Processor
  *      
- *           Copyright 2000 The LyX Team.
+ *           Copyright 2000-2001 The LyX Team.
  *
  *           @author Jürgen Vigna
  *
 
 #include <config.h>
 
+#include FORMS_H_LOCATION
+#include XPM_H_LOCATION
+
 #ifdef __GNUG_
 #pragma implementation
 #endif
 
 #include "lyx_gui_misc.h"
-#include "gettext.h"
-#include FORMS_H_LOCATION
-#include XPM_H_LOCATION
 
 #include "FormDocument.h"
 #include "form_document.h"
-#include "xform_macros.h"
 #include "Dialogs.h"
 #include "layout.h"
 #include "combox.h"
@@ -32,6 +31,7 @@
 #include "vspace.h"
 #include "bmtable.h"
 #include "support/filetools.h"
+#include "support/lstrings.h"
 #include "language.h"
 #include "LyXView.h"
 #include "BufferView.h"
 #include "Liason.h"
 #include "CutAndPaste.h"
 #include "bufferview_funcs.h"
-#include "ButtonController.h"
+#include "xforms_helpers.h" 
+#include "debug.h"
 
-#ifdef SIGC_CXX_NAMESPACES
-using SigC::slot;
-#endif
-
-#ifdef CXX_WORKING_NAMESPACES
 using Liason::setMinibuffer;
-#endif
-
-#define USE_CLASS_COMBO 1
-
-C_RETURNCB(FormDocument,  WMHideCB)
-C_GENERICCB(FormDocument, InputCB)
-C_GENERICCB(FormDocument, OKCB)
-C_GENERICCB(FormDocument, ApplyCB)
-C_GENERICCB(FormDocument, CancelCB)
-C_GENERICCB(FormDocument, RestoreCB)
-C_GENERICCB(FormDocument, ChoiceClassCB)
-C_GENERICCB(FormDocument, BulletPanelCB)
-C_GENERICCB(FormDocument, BulletDepthCB)
-C_GENERICCB(FormDocument, InputBulletLaTeXCB)
-C_GENERICCB(FormDocument, ChoiceBulletSizeCB)
+using SigC::slot;
 
-       
 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
-       : dialog_(0), paper_(0), class_(0), language_(0), options_(0),
-         bullets_(0), lv_(lv), d_(d), u_(0), h_(0),
-         status(POPUP_UNMODIFIED) ,
-         bc_(new ButtonController<NoRepeatedApplyReadOnlyPolicy>(_("Cancel"),
-                                                                 _("Close")))
+       : FormBaseBD(lv, d, _("Document Layout")), fbullet(0)
 {
-    // let the popup be shown
+    // let the dialog be shown
     // This is a permanent connection so we won't bother
     // storing a copy because we won't be disconnecting.
-    d->showLayoutDocument.connect(slot(this, &FormDocument::show));
-    current_bullet_depth = 0;
-    current_bullet_panel = 0;
+    d->showDocument.connect(slot(this, &FormDocument::show));
 }
 
 
-FormDocument::~FormDocument()
+void FormDocument::redraw()
 {
-    free();
-    delete bc_;
+       if( form() && form()->visible )
+               fl_redraw_form( form() );
+       else
+               return;
+
+       FL_FORM * outer_form = fl_get_active_folder(dialog_->tabbed_folder);
+       if (outer_form && outer_form->visible)
+               fl_redraw_form( outer_form );
+}
+
+
+FL_FORM * FormDocument::form() const
+{
+    if (dialog_.get()) return dialog_->form;
+    return 0;
 }
 
 
@@ -92,17 +80,16 @@ void FormDocument::build()
     int n;
 
     // the tabbed folder
-    dialog_ = build_tabbed_document();
+    dialog_.reset(build_tabbed_document());
 
-    // manage the restore, ok, apply and cancel/close buttons
-    bc_->setOK(dialog_->button_ok);
-    bc_->setApply(dialog_->button_apply);
-    bc_->setCancel(dialog_->button_cancel);
-    bc_->setUndoAll(dialog_->button_restore);
-    bc_->refresh();
+    // Manage the restore, ok, apply, restore and cancel/close buttons
+    bc().setOK(dialog_->button_ok);
+    bc().setApply(dialog_->button_apply);
+    bc().setCancel(dialog_->button_cancel);
+    bc().setRestore(dialog_->button_restore);
 
     // the document paper form
-    paper_ = build_doc_paper();
+    paper_.reset(build_doc_paper());
     fl_addto_choice(paper_->choice_papersize2,
                    _(" Default | Custom | USletter | USlegal "
                      "| USexecutive | A3 | A4 | A5 | B3 | B4 | B5 "));
@@ -111,58 +98,52 @@ void FormDocument::build()
                      "| A4 small Margins (only portrait) "
                      "| A4 very small Margins (only portrait) "
                      "| A4 very wide margins (only portrait) "));
-    fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS);
-    fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS);
-    fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS);
-    fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS);
-    fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS);
-    fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS);
-    fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS);
-    fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS);
-    fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS);
-
-    bc_->addReadOnly (paper_->choice_paperpackage);
-    bc_->addReadOnly (paper_->greoup_radio_orientation);
-    bc_->addReadOnly (paper_->radio_portrait);
-    bc_->addReadOnly (paper_->radio_landscape);
-    bc_->addReadOnly (paper_->choice_papersize2);
-    bc_->addReadOnly (paper_->push_use_geometry);
-    bc_->addReadOnly (paper_->input_custom_width);
-    bc_->addReadOnly (paper_->input_custom_height);
-    bc_->addReadOnly (paper_->input_top_margin);
-    bc_->addReadOnly (paper_->input_bottom_margin);
-    bc_->addReadOnly (paper_->input_left_margin);
-    bc_->addReadOnly (paper_->input_right_margin);
-    bc_->addReadOnly (paper_->input_head_height);
-    bc_->addReadOnly (paper_->input_head_sep);
-    bc_->addReadOnly (paper_->input_foot_skip);
+    fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED);
+    fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED);
+    fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED);
+    fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED);
+    fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED);
+    fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED);
+    fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED);
+    fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED);
+    fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED);
+
+    bc().addReadOnly (paper_->choice_paperpackage);
+    bc().addReadOnly (paper_->greoup_radio_orientation);
+    bc().addReadOnly (paper_->radio_portrait);
+    bc().addReadOnly (paper_->radio_landscape);
+    bc().addReadOnly (paper_->choice_papersize2);
+    bc().addReadOnly (paper_->push_use_geometry);
+    bc().addReadOnly (paper_->input_custom_width);
+    bc().addReadOnly (paper_->input_custom_height);
+    bc().addReadOnly (paper_->input_top_margin);
+    bc().addReadOnly (paper_->input_bottom_margin);
+    bc().addReadOnly (paper_->input_left_margin);
+    bc().addReadOnly (paper_->input_right_margin);
+    bc().addReadOnly (paper_->input_head_height);
+    bc().addReadOnly (paper_->input_head_sep);
+    bc().addReadOnly (paper_->input_foot_skip);
 
     // the document class form
-    class_ = build_doc_class();
+    class_.reset(build_doc_class());
 
     FL_OBJECT * obj;
-#ifdef USE_CLASS_COMBO
     // The language is a combo-box and has to be inserted manually
     obj = class_->choice_doc_class;
+    fl_deactivate_object(obj);
     fl_addto_form(class_->form);
-    combo_doc_class = new Combox(FL_COMBOX_DROPLIST);
-    combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 200);
+    combo_doc_class.reset(new Combox(FL_COMBOX_DROPLIST));
+    combo_doc_class->add(obj->x, obj->y, obj->w, obj->h, 400,
+                        dialog_->tabbed_folder);
     combo_doc_class->shortcut("#C",1);
     combo_doc_class->setcallback(ComboInputCB, this);
     fl_end_form();
     for (LyXTextClassList::const_iterator cit = textclasslist.begin();
         cit != textclasslist.end(); ++cit)
     {
-       combo_doc_class->addto((*cit).description().c_str());
+       combo_doc_class->addto(cit->description());
     }
-#else
-    fl_clear_choice(class_->choice_doc_class);
-    for (LyXTextClassList::const_iterator cit = textclasslist.begin();
-        cit != textclasslist.end(); ++cit)
-    {
-       fl_addto_choice(class_->choice_doc_class,(*cit).description().c_str());
-    }
-#endif
+
     fl_addto_choice(class_->choice_doc_spacing,
                    _(" Single | OneHalf | Double | Other "));
     fl_addto_choice(class_->choice_doc_fontsize, "default|10|11|12");
@@ -173,57 +154,60 @@ void FormDocument::build()
                    "default|empty|plain|headings|fancy");
     fl_addto_choice(class_->choice_doc_skip,
                    _(" Smallskip | Medskip | Bigskip | Length "));
-    fl_set_input_return(class_->input_doc_skip, FL_RETURN_ALWAYS);
-    fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS);
-
-    bc_->addReadOnly (class_->radio_doc_indent);
-    bc_->addReadOnly (class_->radio_doc_skip);
-#ifndef USE_CLASS_COMBO
-    bc_->addReadOnly (class_->choice_doc_class);
-#endif
-    bc_->addReadOnly (class_->choice_doc_pagestyle);
-    bc_->addReadOnly (class_->choice_doc_fonts);
-    bc_->addReadOnly (class_->choice_doc_fontsize);
-    bc_->addReadOnly (class_->radio_doc_sides_one);
-    bc_->addReadOnly (class_->radio_doc_sides_two);
-    bc_->addReadOnly (class_->radio_doc_columns_one);
-    bc_->addReadOnly (class_->radio_doc_columns_two);
-    bc_->addReadOnly (class_->input_doc_extra);
-    bc_->addReadOnly (class_->input_doc_skip);
-    bc_->addReadOnly (class_->choice_doc_skip);
-    bc_->addReadOnly (class_->choice_doc_spacing);
-    bc_->addReadOnly (class_->input_doc_spacing);
+    fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED);
+    fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED);
+    fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED);
+
+    bc().addReadOnly (class_->radio_doc_indent);
+    bc().addReadOnly (class_->radio_doc_skip);
+
+    bc().addReadOnly (class_->choice_doc_pagestyle);
+    bc().addReadOnly (class_->choice_doc_fonts);
+    bc().addReadOnly (class_->choice_doc_fontsize);
+    bc().addReadOnly (class_->radio_doc_sides_one);
+    bc().addReadOnly (class_->radio_doc_sides_two);
+    bc().addReadOnly (class_->radio_doc_columns_one);
+    bc().addReadOnly (class_->radio_doc_columns_two);
+    bc().addReadOnly (class_->input_doc_extra);
+    bc().addReadOnly (class_->input_doc_skip);
+    bc().addReadOnly (class_->choice_doc_skip);
+    bc().addReadOnly (class_->choice_doc_spacing);
+    bc().addReadOnly (class_->input_doc_spacing);
 
     // the document language form
-    language_ = build_doc_language();
+    language_.reset(build_doc_language());
     fl_addto_choice(language_->choice_inputenc,
-                   "default|auto|latin1|latin2|latin5"
+                   "default|auto|latin1|latin2|latin5|latin9"
                    "|koi8-r|koi8-u|cp866|cp1251|iso88595");
 
     // The language is a combo-box and has to be inserted manually
     obj = language_->choice_language;
+    fl_deactivate_object(obj);
     fl_addto_form(language_->form);
-    combo_language = new Combox(FL_COMBOX_DROPLIST);
-    combo_language->add(obj->x, obj->y, obj->w, obj->h, 200);
+    combo_language.reset(new Combox(FL_COMBOX_DROPLIST));
+    combo_language->add(obj->x, obj->y, obj->w, obj->h, 400,
+                       dialog_->tabbed_folder);
     combo_language->shortcut("#L",1);
     combo_language->setcallback(ComboInputCB, this);
     fl_end_form();
-    // "default" is not part of the languages array any more.
-    combo_language->addto("default");
-    for(Languages::iterator cit = languages.begin();
+
+    for (Languages::const_iterator cit = languages.begin();
        cit != languages.end(); ++cit) {
-       combo_language->addto((*cit).second.lang().c_str());
+       combo_language->addto(cit->second.lang());
     }
 
     fl_addto_choice(language_->choice_quotes_language,
                    _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
                      " «text» | »text« "));
 
-    bc_->addReadOnly (language_->choice_language);
-    bc_->addReadOnly (language_->choice_inputenc);
+    bc().addReadOnly (language_->choice_inputenc);
+    bc().addReadOnly (language_->choice_quotes_language);
+    bc().addReadOnly (language_->radio_single);
+    bc().addReadOnly (language_->radio_double);
 
     // the document options form
-    options_ = build_doc_options();
+    options_.reset(build_doc_options());
+    fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED);
     fl_set_counter_bounds(options_->slider_secnumdepth,-2,5);
     fl_set_counter_bounds(options_->slider_tocdepth,-1,5);
     fl_set_counter_step(options_->slider_secnumdepth,1,1);
@@ -233,15 +217,19 @@ void FormDocument::build()
     for (n=0; tex_graphics[n][0]; ++n) {
        fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
     }
+    fl_addto_choice(options_->choice_citation_format,
+                   _(" Author-year | Numerical "));
 
-    bc_->addReadOnly (options_->slider_secnumdepth);
-    bc_->addReadOnly (options_->slider_tocdepth);
-    bc_->addReadOnly (options_->check_use_amsmath);
-    bc_->addReadOnly (options_->input_float_placement);
-    bc_->addReadOnly (options_->choice_postscript_driver);
+    bc_.addReadOnly (options_->slider_secnumdepth);
+    bc_.addReadOnly (options_->slider_tocdepth);
+    bc_.addReadOnly (options_->check_use_amsmath);
+    bc_.addReadOnly (options_->check_use_natbib);
+    bc_.addReadOnly (options_->choice_citation_format);
+    bc_.addReadOnly (options_->input_float_placement);
+    bc_.addReadOnly (options_->choice_postscript_driver);
 
     // the document bullets form
-    bullets_ = build_doc_bullet();
+    bullets_.reset(build_doc_bullet());
     fl_addto_choice(bullets_->choice_bullet_size,
                    _(" default | tiny | script | footnote | small |"
                      " normal | large | Large | LARGE | huge | Huge"));
@@ -249,8 +237,12 @@ void FormDocument::build()
     fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
     fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
 
-    fl_set_form_atclose(dialog_->form,
-                       C_FormDocumentWMHideCB, 0);
+    bc().addReadOnly (bullets_->bmtable_bullet_panel);
+    bc().addReadOnly (bullets_->choice_bullet_size);
+    bc().addReadOnly (bullets_->input_bullet_latex);
+    bc().addReadOnly (bullets_->radio_bullet_depth);
+    bc().addReadOnly (bullets_->radio_bullet_panel);
+
     fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
                       class_->form);
     fl_addto_tabfolder(dialog_->tabbed_folder,_("Paper"),
@@ -263,7 +255,7 @@ void FormDocument::build()
                                 bullets_->form);
     if ((XpmVersion < 4) || (XpmVersion == 4 && XpmRevision < 7)) {
            lyxerr << _("Your version of libXpm is older than 4.7.\n"
-                       "The `bullet' tab of the document popup "
+                       "The `bullet' tab of the document dialog "
                        "has been disabled") << '\n';
        fl_deactivate_object(fbullet);
        fl_set_object_lcol(fbullet, FL_INACTIVE);
@@ -271,39 +263,9 @@ void FormDocument::build()
 }
 
 
-void FormDocument::show()
-{
-    if (!dialog_)
-       build();
-
-    update();  // make sure its up-to-date
-    if (dialog_->form->visible) {
-        fl_raise_form(dialog_->form);
-    } else {
-        fl_show_form(dialog_->form,
-                     FL_PLACE_MOUSE | FL_FREE_SIZE,
-                     FL_TRANSIENT, _("Document Layout"));
-       u_ = d_->updateBufferDependent.connect(
-           slot(this, &FormDocument::update));
-       h_ = d_->hideBufferDependent.connect(
-           slot(this, &FormDocument::hide));
-    }
-}
-
-
-void FormDocument::hide()
-{
-    if (dialog_->form->visible) {
-        fl_hide_form(dialog_->form);
-        u_.disconnect();
-        h_.disconnect();
-    }
-}
-
-
 void FormDocument::apply()
 {
-    if (!lv_->view()->available() || !dialog_)
+    if (!lv_->view()->available() || !dialog_.get())
        return;
 
     bool redo = class_apply();
@@ -320,6 +282,94 @@ void FormDocument::apply()
 }
 
 
+void FormDocument::cancel()
+{
+    // this avoids confusion when reopening
+    BufferParams & param = lv_->buffer()->params;
+    param.temp_bullets[0] = param.user_defined_bullets[0];
+    param.temp_bullets[1] = param.user_defined_bullets[1];
+    param.temp_bullets[2] = param.user_defined_bullets[2];
+    param.temp_bullets[3] = param.user_defined_bullets[3];
+    hide();
+}
+
+
+void FormDocument::update()
+{
+    if (!dialog_.get())
+        return;
+
+    checkReadOnly();
+
+    BufferParams const & params = lv_->buffer()->params;
+
+    class_update(params);
+    paper_update(params);
+    language_update(params);
+    options_update(params);
+    bullets_update(params);
+}
+
+
+bool FormDocument::input( FL_OBJECT * ob, long data )
+{
+       State cb = static_cast<State>( data );
+
+       switch (cb) {
+       case CHECKCHOICECLASS:
+               CheckChoiceClass(ob, 0);
+               break;
+       case CHOICEBULLETSIZE:
+               ChoiceBulletSize(ob, 0);
+               break;
+       case INPUTBULLETLATEX:
+               InputBulletLaTeX(ob, 0);
+               break;
+       case BULLETDEPTH1:
+       case BULLETDEPTH2:
+       case BULLETDEPTH3:
+       case BULLETDEPTH4:
+               BulletDepth(ob, cb);
+               break;
+       case BULLETPANEL1:
+       case BULLETPANEL2:
+       case BULLETPANEL3:
+       case BULLETPANEL4:
+       case BULLETPANEL5:
+       case BULLETPANEL6:
+               BulletPanel(ob, cb);
+               break;
+       case BULLETBMTABLE:
+               BulletBMTable(ob, 0);
+               break;
+       default:
+               break;
+       }
+       
+       switch (data) {
+       case INPUT:
+       case CHECKCHOICECLASS:
+       case CHOICEBULLETSIZE:
+       case INPUTBULLETLATEX:
+       case BULLETBMTABLE:
+               return CheckDocumentInput(ob, 0);
+       default:
+               break;
+       }
+
+       return true;
+}
+
+
+void FormDocument::ComboInputCB(int, void * v, Combox * combox)
+{
+    FormDocument * pre = static_cast<FormDocument*>(v);
+    if (combox == pre->combo_doc_class.get())
+       pre->CheckChoiceClass(0, 0);
+    pre->bc().valid(pre->CheckDocumentInput(0,0));
+}
+
+
 bool FormDocument::class_apply()
 {
        bool redo = false;
@@ -335,19 +385,15 @@ bool FormDocument::class_apply()
        params.fontsize = fl_get_choice_text(class_->choice_doc_fontsize);
        params.pagestyle = fl_get_choice_text(class_->choice_doc_pagestyle);
 
-#ifdef USE_CLASS_COMBO   
-       unsigned int new_class = combo_doc_class->get() - 1;
-#else
-       unsigned int new_class = fl_get_choice(class_->choice_doc_class) - 1;
-#endif
+       unsigned int const new_class = combo_doc_class->get() - 1;
+       
        if (params.textclass != new_class) {
                // try to load new_class
                if (textclasslist.Load(new_class)) {
                        // successfully loaded
                        redo = true;
                        setMinibuffer(lv_, _("Converting document to new document class..."));
-                       CutAndPaste cap;
-                       int ret = cap.SwitchLayoutsBetweenClasses(
+                       int ret = CutAndPaste::SwitchLayoutsBetweenClasses(
                            params.textclass, new_class,
                            lv_->buffer()->paragraph);
                        if (ret) {
@@ -368,15 +414,10 @@ bool FormDocument::class_apply()
                        WriteAlert(_("Conversion Errors!"),
                                   _("Errors loading new document class."),
                                   _("Reverting to original document class."));
-#ifdef USE_CLASS_COMBO
-                       combo_doc_class->select(params.textclass + 1);
-#else
-                       fl_set_choice(class_->choice_doc_class,
-                                     params.textclass + 1);
-#endif
+                       combo_doc_class->select(int(params.textclass) + 1);
                }
        }
-       char tmpsep = params.paragraph_separation;
+       BufferParams::PARSEP tmpsep = params.paragraph_separation;
        if (fl_get_button(class_->radio_doc_indent))
                params.paragraph_separation = BufferParams::PARSEP_INDENT;
        else
@@ -417,7 +458,7 @@ bool FormDocument::class_apply()
                params.sides = LyXTextClass::OneSide;
        
        Spacing tmpSpacing = params.spacing;
-       switch(fl_get_choice(class_->choice_doc_spacing)) {
+       switch (fl_get_choice(class_->choice_doc_spacing)) {
        case 1:
                lyxerr[Debug::INFO] << "Spacing: SINGLE\n";
                params.spacing.set(Spacing::Single);
@@ -449,8 +490,10 @@ void FormDocument::paper_apply()
 {
     BufferParams & params = lv_->buffer()->params;
     
-    params.papersize2 = fl_get_choice(paper_->choice_papersize2)-1;
-    params.paperpackage = fl_get_choice(paper_->choice_paperpackage)-1;
+    params.papersize2 =
+           static_cast<char>(fl_get_choice(paper_->choice_papersize2)-1);
+    params.paperpackage =
+           static_cast<char>(fl_get_choice(paper_->choice_paperpackage)-1);
     params.use_geometry = fl_get_button(paper_->push_use_geometry);
     if (fl_get_button(paper_->radio_landscape))
        params.orientation = BufferParams::ORIENTATION_LANDSCAPE;
@@ -475,7 +518,7 @@ bool FormDocument::language_apply()
     InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
     bool redo = false;
 
-    switch(fl_get_choice(language_->choice_quotes_language) - 1) {
+    switch (fl_get_choice(language_->choice_quotes_language) - 1) {
     case 0:
        lga = InsetQuotes::EnglishQ;
        break;
@@ -501,24 +544,20 @@ bool FormDocument::language_apply()
     else
        params.quotes_times = InsetQuotes::DoubleQ;
 
-    Language const * old_language = params.language_info;
-    params.language = combo_language->getline();
-    Languages::iterator lit = languages.find(params.language);
-
-    Language const * new_language;
-    if (lit != languages.end()) 
-       new_language = &(*lit).second;
-    else
+    Language const * old_language = params.language;
+    Language const * new_language = 
+           languages.getLanguage(combo_language->getline());
+    if (!new_language)
        new_language = default_language;
 
     if (old_language != new_language
        && old_language->RightToLeft() == new_language->RightToLeft()
        && !lv_->buffer()->isMultiLingual())
-       lv_->buffer()->ChangeLanguage(old_language, new_language);
+       lv_->buffer()->changeLanguage(old_language, new_language);
     if (old_language != new_language) {
        redo = true;
     }
-    params.language_info = new_language;
+    params.language = new_language;
     params.inputenc = fl_get_choice_text(language_->choice_inputenc);
 
     return redo;
@@ -533,6 +572,9 @@ bool FormDocument::options_apply()
     params.graphicsDriver =
        fl_get_choice_text(options_->choice_postscript_driver);
     params.use_amsmath = fl_get_button(options_->check_use_amsmath);
+    params.use_natbib  = fl_get_button(options_->check_use_natbib);
+    params.use_numerical_citations  =
+           fl_get_choice(options_->choice_citation_format)-1;
 
     int tmpchar = int(fl_get_counter_value(options_->slider_secnumdepth));
     if (params.secnumdepth != tmpchar)
@@ -561,48 +603,15 @@ void FormDocument::bullets_apply()
 }
 
 
-void FormDocument::cancel()
-{
-    // this avoids confusion when reopening
-    BufferParams & param = lv_->buffer()->params;
-    param.temp_bullets[0] = param.user_defined_bullets[0];
-    param.temp_bullets[1] = param.user_defined_bullets[1];
-    param.temp_bullets[2] = param.user_defined_bullets[2];
-    param.temp_bullets[3] = param.user_defined_bullets[3];
-}
-
-
-void FormDocument::update()
-{
-    if (!dialog_)
-        return;
-
-    checkReadOnly();
-
-    BufferParams const & params = lv_->buffer()->params;
-
-    class_update(params);
-    paper_update(params);
-    language_update(params);
-    options_update(params);
-    bullets_update(params);
-}
-
-
 void FormDocument::class_update(BufferParams const & params)
 {
-    if (!class_)
+    if (!class_.get())
         return;
 
     LyXTextClass const & tclass = textclasslist.TextClass(params.textclass);
 
-#ifdef USE_CLASS_COMBO
     combo_doc_class->select_text(
-       textclasslist.DescOfClass(params.textclass).c_str());
-#else  
-    fl_set_choice_text(class_->choice_doc_class, 
-                      textclasslist.DescOfClass(params.textclass).c_str());
-#endif
+       textclasslist.DescOfClass(params.textclass));
     fl_set_choice_text(class_->choice_doc_fonts, params.fonts.c_str());
     fl_clear_choice(class_->choice_doc_fontsize);
     fl_addto_choice(class_->choice_doc_fontsize, "default");
@@ -643,7 +652,7 @@ void FormDocument::class_update(BufferParams const & params)
     }
     fl_set_button(class_->radio_doc_sides_one, 0);
     fl_set_button(class_->radio_doc_sides_two, 0);
-    if (params.sides == 2)
+    if (params.sides == LyXTextClass::TwoSides)
        fl_set_button(class_->radio_doc_sides_two, 1);
     else
        fl_set_button(class_->radio_doc_sides_one, 1);
@@ -686,10 +695,10 @@ void FormDocument::class_update(BufferParams const & params)
 
 void FormDocument::language_update(BufferParams const & params)
 {
-    if (!language_)
+    if (!language_.get())
         return;
 
-    combo_language->select_text(params.language.c_str());
+    combo_language->select_text(params.language->lang());
     fl_set_choice_text(language_->choice_inputenc, params.inputenc.c_str());
     fl_set_choice(language_->choice_quotes_language, params.quotes_language + 1);
     fl_set_button(language_->radio_single, 0);
@@ -703,12 +712,15 @@ void FormDocument::language_update(BufferParams const & params)
 
 void FormDocument::options_update(BufferParams const & params)
 {
-    if (!options_)
+    if (!options_.get())
         return;
 
     fl_set_choice_text(options_->choice_postscript_driver,
                       params.graphicsDriver.c_str());
     fl_set_button(options_->check_use_amsmath, params.use_amsmath);
+    fl_set_button(options_->check_use_natbib,  params.use_natbib);
+    fl_set_choice(options_->choice_citation_format,
+                 int(params.use_numerical_citations)+1);
     fl_set_counter_value(options_->slider_secnumdepth, params.secnumdepth);
     fl_set_counter_value(options_->slider_tocdepth, params.tocdepth);
     if (!params.float_placement.empty())
@@ -721,7 +733,7 @@ void FormDocument::options_update(BufferParams const & params)
 
 void FormDocument::paper_update(BufferParams const & params)
 {
-    if (!paper_)
+    if (!paper_.get())
         return;
 
     fl_set_choice(paper_->choice_papersize2, params.papersize2 + 1);
@@ -748,26 +760,13 @@ void FormDocument::paper_update(BufferParams const & params)
 
 void FormDocument::bullets_update(BufferParams const & params)
 {
-    if (!bullets_ || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
+    if (!bullets_.get() || ((XpmVersion<4) || (XpmVersion==4 && XpmRevision<7)))
         return;
 
-    if (lv_->buffer()->isLinuxDoc()) {
-       fl_deactivate_object(fbullet);
-       fl_set_object_lcol(fbullet, FL_INACTIVE);
-       return;
-    } else {
-       fl_activate_object(fbullet);
-       fl_set_object_lcol(fbullet, FL_BLACK);
-    }
-    if (lv_->buffer()->isReadonly()) {
-       fl_deactivate_object (bullets_->bmtable_bullet_panel);
-       fl_deactivate_object (bullets_->choice_bullet_size);
-       fl_deactivate_object (bullets_->input_bullet_latex);
-    } else {
-       fl_activate_object (bullets_->bmtable_bullet_panel);
-       fl_activate_object (bullets_->choice_bullet_size);
-       fl_activate_object (bullets_->input_bullet_latex);
-    }
+    bool const isLinuxDoc = lv_->buffer()->isLinuxDoc();
+    setEnabled(fbullet, !isLinuxDoc);
+
+    if (isLinuxDoc) return;
 
     fl_set_button(bullets_->radio_bullet_depth_1, 1);
     fl_set_input(bullets_->input_bullet_latex,
@@ -777,118 +776,9 @@ void FormDocument::bullets_update(BufferParams const & params)
 }
 
 
-void FormDocument::free()
-{
-    if (dialog_) {
-        hide();
-        if (class_) {
-#ifdef USE_CLASS_COMBO
-           delete combo_doc_class;
-#endif
-            fl_free_form(class_->form);
-            delete class_;
-            class_ = 0;
-        }
-        if (paper_) {
-            fl_free_form(paper_->form);
-            delete paper_;
-            paper_ = 0;
-        }
-        if (language_) {
-           delete combo_language;
-            fl_free_form(language_->form);
-            delete language_;
-            language_ = 0;
-        }
-        if (options_) {
-            fl_free_form(options_->form);
-            delete options_;
-            options_ = 0;
-        }
-        if (bullets_) {
-            fl_free_form(bullets_->form);
-            delete bullets_;
-            bullets_ = 0;
-        }
-        fl_free_form(dialog_->form);
-        delete dialog_;
-        dialog_ = 0;
-    }
-}
-
-
-int FormDocument::WMHideCB(FL_FORM * form, void *)
-{
-    // Ensure that the signals (u and h) are disconnected even if the
-    // window manager is used to close the popup.
-    FormDocument * pre = static_cast<FormDocument*>(form->u_vdata);
-    pre->hide();
-    pre->bc_->hide();
-    return FL_CANCEL;
-}
-
-
-void FormDocument::OKCB(FL_OBJECT * ob, long)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->apply();
-    pre->hide();
-    pre->bc_->ok();
-}
-
-
-void FormDocument::ApplyCB(FL_OBJECT * ob, long)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->apply();
-    pre->bc_->apply();
-}
-
-
-void FormDocument::CancelCB(FL_OBJECT * ob, long)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->cancel();
-    pre->hide();
-    pre->bc_->cancel();
-}
-
-
-void FormDocument::RestoreCB(FL_OBJECT * ob, long)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->update();
-    pre->bc_->undoAll();
-}
-
-
-void FormDocument::InputCB(FL_OBJECT * ob, long)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->bc_->valid(pre->CheckDocumentInput(ob,0));
-}
-
-
-void FormDocument::ComboInputCB(int, void * v, Combox * combox)
-{
-    FormDocument * pre = static_cast<FormDocument*>(v);
-    if (combox == pre->combo_doc_class)
-       pre->CheckChoiceClass(0, 0);
-    pre->bc_->valid(pre->CheckDocumentInput(0,0));
-}
-
-
-void FormDocument::ChoiceClassCB(FL_OBJECT * ob, long)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->CheckChoiceClass(ob,0);
-    pre->bc_->valid(pre->CheckDocumentInput(ob,0));
-}
-
-
 void FormDocument::checkReadOnly()
 {
-    if (bc_->readOnly(lv_->buffer()->isReadonly())) {
+    if (bc().readOnly(lv_->buffer()->isReadonly())) {
        combo_doc_class->deactivate();
        combo_language->deactivate();
        fl_set_object_label(dialog_->text_warning,
@@ -905,23 +795,25 @@ void FormDocument::checkReadOnly()
 
 void FormDocument::checkMarginValues()
 {
-    int const allEmpty = (!strlen(fl_get_input(paper_->input_top_margin)) &&
-               !strlen(fl_get_input(paper_->input_bottom_margin)) &&
-               !strlen(fl_get_input(paper_->input_left_margin)) &&
-               !strlen(fl_get_input(paper_->input_right_margin)) &&
-               !strlen(fl_get_input(paper_->input_head_height)) &&
-               !strlen(fl_get_input(paper_->input_head_sep)) &&
-               !strlen(fl_get_input(paper_->input_foot_skip)) &&
-               !strlen(fl_get_input(paper_->input_custom_width)) &&
-               !strlen(fl_get_input(paper_->input_custom_height)));
-    if (!allEmpty)
-       fl_set_button(paper_->push_use_geometry, 1);
+       bool const not_empty =
+               strlen(fl_get_input(paper_->input_top_margin)) ||
+               strlen(fl_get_input(paper_->input_bottom_margin)) ||
+               strlen(fl_get_input(paper_->input_left_margin)) ||
+               strlen(fl_get_input(paper_->input_right_margin)) ||
+               strlen(fl_get_input(paper_->input_head_height)) ||
+               strlen(fl_get_input(paper_->input_head_sep)) ||
+               strlen(fl_get_input(paper_->input_foot_skip)) ||
+               strlen(fl_get_input(paper_->input_custom_width)) ||
+               strlen(fl_get_input(paper_->input_custom_height));
+       if (not_empty)
+               fl_set_button(paper_->push_use_geometry, 1);
 }
 
+
 bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
 {
     string str;
-    char val;
+    int val;
     bool ok = true;
     char const * input;
     
@@ -1008,14 +900,6 @@ bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
 }
 
 
-void FormDocument::ChoiceBulletSizeCB(FL_OBJECT * ob, long)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->ChoiceBulletSize(ob,0);
-    pre->bc_->valid(pre->CheckDocumentInput(ob,0));
-}
-
-
 void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
 {
     BufferParams & param = lv_->buffer()->params;
@@ -1027,14 +911,6 @@ void FormDocument::ChoiceBulletSize(FL_OBJECT * ob, long /*data*/ )
 }
 
 
-void FormDocument::InputBulletLaTeXCB(FL_OBJECT * ob, long)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->InputBulletLaTeX(ob,0);
-    pre->bc_->valid(pre->CheckDocumentInput(ob,0));
-}
-
-
 void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
 {
     BufferParams & param = lv_->buffer()->params;
@@ -1044,14 +920,7 @@ void FormDocument::InputBulletLaTeX(FL_OBJECT *, long)
 }
 
 
-void FormDocument::BulletDepthCB(FL_OBJECT * ob, long)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->BulletDepth(ob,0);
-}
-
-
-void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
+void FormDocument::BulletDepth(FL_OBJECT * ob, State cb)
 {
     /* Should I do the following:                                 */
     /*  1. change to the panel that the current bullet belongs in */
@@ -1063,9 +932,19 @@ void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
     /* maybe try to support the others later                      */
     BufferParams & param = lv_->buffer()->params;
 
+    int data = 0;
+    if (cb == BULLETDEPTH1 )
+           data = 0;
+    else if (cb == BULLETDEPTH2 )
+           data = 1;
+    else if (cb == BULLETDEPTH3 )
+           data = 2;
+    else if (cb == BULLETDEPTH4 )
+           data = 3;
+
     switch (fl_get_button_numb(ob)) {
     case 3:
-       // right mouse button resets to default
+           // right mouse button resets to default
        param.temp_bullets[data] = ITEMIZE_DEFAULTS[data];
     default:
        current_bullet_depth = data;
@@ -1077,18 +956,25 @@ void FormDocument::BulletDepth(FL_OBJECT * ob, long data)
 }
 
 
-void FormDocument::BulletPanelCB(FL_OBJECT * ob, long data)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->BulletPanel(ob,data);
-}
-
-
-void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
+void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, State cb)
 {
     /* Here we have to change the background pixmap to that selected */
     /* by the user. (eg. standard.xpm, psnfss1.xpm etc...)           */
     
+    int data = 0;
+    if (cb == BULLETPANEL1 )
+           data = 0;
+    else if (cb == BULLETPANEL2 )
+           data = 1;
+    else if (cb == BULLETPANEL3 )
+           data = 2;
+    else if (cb == BULLETPANEL4 )
+           data = 3;
+    else if (cb == BULLETPANEL5 )
+           data = 4;
+    else if (cb == BULLETPANEL6 )
+           data = 5;
+
     if (data != current_bullet_panel) {
        fl_freeze_form(bullets_->form);
        current_bullet_panel = data;
@@ -1096,24 +982,24 @@ void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
        /* free the current pixmap */
        fl_free_bmtable_pixmap(bullets_->bmtable_bullet_panel);
        string new_panel;
-       switch (data) {
+       switch (cb) {
            /* display the new one */
-       case 0 :
+       case BULLETPANEL1 :
            new_panel = "standard";
            break;
-       case 1 :
+       case BULLETPANEL2 :
            new_panel = "amssymb";
            break;
-       case 2 :
+       case BULLETPANEL3 :
            new_panel = "psnfss1";
            break;
-       case 3 :
+       case BULLETPANEL4 :
            new_panel = "psnfss2";
            break;
-       case 4 :
+       case BULLETPANEL5 :
            new_panel = "psnfss3";
            break;
-       case 5 :
+       case BULLETPANEL6 :
            new_panel = "psnfss4";
            break;
        default :
@@ -1125,21 +1011,13 @@ void FormDocument::BulletPanel(FL_OBJECT * /*ob*/, long data)
        }
        new_panel += ".xpm";
        fl_set_bmtable_pixmap_file(bullets_->bmtable_bullet_panel, 6, 6,
-                                  LibFileSearch("images", new_panel.c_str()).c_str());
+                                  LibFileSearch("images", new_panel).c_str());
        fl_redraw_object(bullets_->bmtable_bullet_panel);
        fl_unfreeze_form(bullets_->form);
     }
 }
 
 
-void FormDocument::BulletBMTableCB(FL_OBJECT * ob, long)
-{
-    FormDocument * pre = static_cast<FormDocument*>(ob->form->u_vdata);
-    pre->BulletBMTable(ob,0);
-    pre->bc_->valid(pre->CheckDocumentInput(ob,0));
-}
-
-
 void FormDocument::BulletBMTable(FL_OBJECT * ob, long /*data*/ )
 {
     /* handle the user input by setting the current bullet depth's pixmap */
@@ -1163,22 +1041,17 @@ void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
     if (!ob)
        ob = class_->choice_doc_class;
 
-    ProhibitInput(lv_->view());
-    int tc;
-    string tct;
+    lv_->prohibitInput();
 
-#ifdef USE_CLASS_COMBO
-    tc = combo_doc_class->get() - 1;
-    tct = combo_doc_class->getline();
-#else
-    tc = fl_get_choice(ob) - 1;
-    tct = fl_get_choice_text(ob);
-#endif
+    unsigned int tc = combo_doc_class->get() - 1;
     if (textclasslist.Load(tc)) {
-       if (AskQuestion(_("Should I set some parameters to"), tct,
-                       _("the defaults of this document class?"))) {
-           BufferParams params = lv_->buffer()->params;
+           // we use a copy of the bufferparams because we do not
+           // want to modify them yet. 
+           BufferParams params = lv_->buffer()->params;
 
+           if (params.textclass != tc
+               && AskQuestion(_("Should I set some parameters to"), 
+                              _("the defaults of this document class?"))) {
            params.textclass = tc;
            params.useClassDefaults();
            UpdateLayoutDocument(params);
@@ -1188,20 +1061,15 @@ void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
        WriteAlert(_("Conversion Errors!"),
                   _("Unable to switch to new document class."),
                   _("Reverting to original document class."));
-#ifdef USE_CLASS_COMBO
-       combo_doc_class->select(lv_->buffer()->params.textclass + 1);
-#else
-       fl_set_choice(class_->choice_doc_class, 
-                     lv_->buffer()->params.textclass + 1);
-#endif
+       combo_doc_class->select(int(lv_->buffer()->params.textclass) + 1);
     }
-    AllowInput(lv_->view());
+    lv_->allowInput();
 }
 
 
 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
 {
-    if (!dialog_)
+    if (!dialog_.get())
         return;
 
     checkReadOnly();