]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormDocument.C
controller-view split of FormLog and FormVCLog.
[lyx.git] / src / frontends / xforms / FormDocument.C
index 6f28e1468506914f497fc573e895e9261b033cd7..0a114121bb0a6d3e7b95cb3bc7396e622b3e34fc 100644 (file)
 
 #include <config.h>
 
+#include FORMS_H_LOCATION
+#include XPM_H_LOCATION
+
 #ifdef __GNUG_
 #pragma implementation
 #endif
 
 #include "lyx_gui_misc.h"
-#include FORMS_H_LOCATION
-#include XPM_H_LOCATION
 
 #include "FormDocument.h"
 #include "form_document.h"
 #include "Liason.h"
 #include "CutAndPaste.h"
 #include "bufferview_funcs.h"
+#include "xforms_helpers.h" 
 
-#ifdef CXX_WORKING_NAMESPACES
 using Liason::setMinibuffer;
-#endif
-
-#define USE_CLASS_COMBO 1
+using SigC::slot;
 
 FormDocument::FormDocument(LyXView * lv, Dialogs * d)
-       : FormBaseBD(lv, d, _("Document Layout"),
-                    new NoRepeatedApplyReadOnlyPolicy),
-         dialog_(0), paper_(0), class_(0), language_(0), options_(0),
-         bullets_(0), current_bullet_panel(0), current_bullet_depth(0),
-         fbullet(0), combo_language(0), combo_doc_class(0)
+       : FormBaseBD(lv, d, _("Document Layout")), fbullet(0)
 {
     // let the popup be shown
     // This is a permanent connection so we won't bother
@@ -58,21 +53,6 @@ FormDocument::FormDocument(LyXView * lv, Dialogs * d)
 }
 
 
-FormDocument::~FormDocument()
-{
-#ifdef USE_CLASS_COMBO
-    delete combo_doc_class;
-#endif
-    delete class_;
-    delete paper_;
-    delete combo_language;
-    delete language_;
-    delete options_;
-    delete bullets_;
-    delete dialog_;
-}
-
-
 void FormDocument::redraw()
 {
        if( form() && form()->visible )
@@ -88,7 +68,7 @@ void FormDocument::redraw()
 
 FL_FORM * FormDocument::form() const
 {
-    if (dialog_) return dialog_->form;
+    if (dialog_.get()) return dialog_->form;
     return 0;
 }
 
@@ -98,21 +78,17 @@ void FormDocument::build()
     int n;
 
     // the tabbed folder
-    dialog_ = build_tabbed_document();
+    dialog_.reset(build_tabbed_document());
 
     // 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_.setUndoAll(dialog_->button_restore);
-    bc_.refresh();
-
-    // Workaround dumb xforms sizing bug
-    minw_ = form()->w;
-    minh_ = form()->h;
+    bc().setOK(dialog_->button_ok);
+    bc().setApply(dialog_->button_apply);
+    bc().setCancel(dialog_->button_cancel);
+    bc().setUndoAll(dialog_->button_restore);
+    bc().refresh();
 
     // 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 "));
@@ -131,31 +107,31 @@ void FormDocument::build()
     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);
+    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.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);
@@ -166,14 +142,7 @@ void FormDocument::build()
     {
        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");
@@ -188,43 +157,39 @@ void FormDocument::build()
     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);
-#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);
+    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"
                    "|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.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.
-#ifdef DO_USE_DEFAULT_LANGUAGE
-    combo_language->addto("default");
-#endif
+
     for (Languages::const_iterator cit = languages.begin();
        cit != languages.end(); ++cit) {
        combo_language->addto((*cit).second.lang());
@@ -234,11 +199,10 @@ void FormDocument::build()
                    _(" ``text'' | ''text'' | ,,text`` | ,,text'' |"
                      " «text» | »text« "));
 
-    bc_.addReadOnly (language_->choice_language);
-    bc_.addReadOnly (language_->choice_inputenc);
+    bc().addReadOnly (language_->choice_inputenc);
 
     // 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);
@@ -250,14 +214,14 @@ void FormDocument::build()
        fl_addto_choice(options_->choice_postscript_driver, tex_graphics[n]);
     }
 
-    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_->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"));
@@ -265,9 +229,9 @@ void FormDocument::build()
     fl_set_input_return(bullets_->input_bullet_latex, FL_RETURN_CHANGED);
     fl_set_input_maxchars(bullets_->input_bullet_latex, 80);
 
-    bc_.addReadOnly (bullets_->bmtable_bullet_panel);
-    bc_.addReadOnly (bullets_->choice_bullet_size);
-    bc_.addReadOnly (bullets_->input_bullet_latex);
+    bc().addReadOnly (bullets_->bmtable_bullet_panel);
+    bc().addReadOnly (bullets_->choice_bullet_size);
+    bc().addReadOnly (bullets_->input_bullet_latex);
 
     fl_addto_tabfolder(dialog_->tabbed_folder,_("Document"),
                       class_->form);
@@ -291,7 +255,7 @@ void FormDocument::build()
 
 void FormDocument::apply()
 {
-    if (!lv_->view()->available() || !dialog_)
+    if (!lv_->view()->available() || !dialog_.get())
        return;
 
     bool redo = class_apply();
@@ -322,7 +286,7 @@ void FormDocument::cancel()
 
 void FormDocument::update()
 {
-    if (!dialog_)
+    if (!dialog_.get())
         return;
 
     checkReadOnly();
@@ -390,9 +354,9 @@ bool FormDocument::input( FL_OBJECT * ob, long data )
 void FormDocument::ComboInputCB(int, void * v, Combox * combox)
 {
     FormDocument * pre = static_cast<FormDocument*>(v);
-    if (combox == pre->combo_doc_class)
+    if (combox == pre->combo_doc_class.get())
        pre->CheckChoiceClass(0, 0);
-    pre->bc_.valid(pre->CheckDocumentInput(0,0));
+    pre->bc().valid(pre->CheckDocumentInput(0,0));
 }
 
 
@@ -411,11 +375,8 @@ 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 const new_class = combo_doc_class->get() - 1;
-#else
-       unsigned int const new_class = fl_get_choice(class_->choice_doc_class) - 1;
-#endif
+       
        if (params.textclass != new_class) {
                // try to load new_class
                if (textclasslist.Load(new_class)) {
@@ -444,12 +405,7 @@ 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(int(params.textclass) + 1);
-#else
-                       fl_set_choice(class_->choice_doc_class,
-                                     params.textclass + 1);
-#endif
                }
        }
        BufferParams::PARSEP tmpsep = params.paragraph_separation;
@@ -637,18 +593,13 @@ void FormDocument::bullets_apply()
 
 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));
-#else  
-    fl_set_choice_text(class_->choice_doc_class, 
-                      textclasslist.DescOfClass(params.textclass).c_str());
-#endif
     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");
@@ -732,7 +683,7 @@ 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->lang());
@@ -749,7 +700,7 @@ 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,
@@ -767,7 +718,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);
@@ -794,17 +745,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);
-    }
+    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,
@@ -816,7 +763,7 @@ void FormDocument::bullets_update(BufferParams const & params)
 
 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,
@@ -833,19 +780,21 @@ 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;
@@ -1079,18 +1028,15 @@ void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
 
     ProhibitInput(lv_->view());
 
-#ifdef USE_CLASS_COMBO
-    int tc = combo_doc_class->get() - 1;
-    string tct = combo_doc_class->getline();
-#else
-    int tc = fl_get_choice(ob) - 1;
-    string 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);
@@ -1100,12 +1046,7 @@ 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(int(lv_->buffer()->params.textclass) + 1);
-#else
-       fl_set_choice(class_->choice_doc_class, 
-                     lv_->buffer()->params.textclass + 1);
-#endif
     }
     AllowInput(lv_->view());
 }
@@ -1113,7 +1054,7 @@ void FormDocument::CheckChoiceClass(FL_OBJECT * ob, long)
 
 void FormDocument::UpdateLayoutDocument(BufferParams const & params)
 {
-    if (!dialog_)
+    if (!dialog_.get())
         return;
 
     checkReadOnly();