]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormPrint.C
Swap two printer related help messages.
[lyx.git] / src / frontends / xforms / FormPrint.C
index 500963f067dca1a87da99f269446a3e290db28c1..29f5126949444b9f429e09079be3a23149f47757 100644 (file)
@@ -12,7 +12,6 @@
 
 #include "FormPrint.h"
 #include "form_print.h"
-#include "xform_macros.h"
 #include "input_validators.h"
 #include "LyXView.h"
 #include "Dialogs.h"
@@ -22,9 +21,7 @@
 #include "Liason.h"
 #include "debug.h"
 #include "BufferView.h"
-#include "lyx_gui_misc.h"
-#include "gettext.h"
-
+#include "lyx_gui_misc.h"      // WriteAlert
 
 #ifdef SIGC_CXX_NAMESPACES
 using SigC::slot;
@@ -35,15 +32,10 @@ using Liason::printBuffer;
 using Liason::getPrinterParams;
 #endif
 
-C_RETURNCB(FormPrint,  WMHideCB)
-C_GENERICCB(FormPrint, OKCB)
-C_GENERICCB(FormPrint, ApplyCB)
-C_GENERICCB(FormPrint, CancelCB)
-C_GENERICCB(FormPrint, InputCB)
-
 
 FormPrint::FormPrint(LyXView * lv, Dialogs * d)
-       : dialog_(0), lv_(lv), d_(d), u_(0), h_(0)
+       : FormBaseBD(lv, d, _("Print"), new OkApplyCancelPolicy),
+         dialog_(0), target_(2), order_(2), which_(3)
 {
        // let the dialog be shown
        // This is a permanent connection so we won't bother
@@ -62,6 +54,16 @@ void FormPrint::build()
 {
        dialog_ = build_print();
 
+       // Workaround dumb xforms sizing bug
+       minw_ = form()->w;
+       minh_ = form()->h;
+
+       // Manage the ok, apply and cancel/close buttons
+       bc_.setOK(dialog_->button_ok);
+       bc_.setApply(dialog_->button_apply);
+       bc_.setCancel(dialog_->button_cancel);
+       bc_.refresh();
+
        // allow controlling of input and ok/apply (de)activation
        fl_set_input_return(dialog_->input_printer,
                            FL_RETURN_CHANGED);
@@ -89,46 +91,30 @@ void FormPrint::build()
        fl_set_input_maxchars(dialog_->input_to_page, 4);   // 9999
        fl_set_input_maxchars(dialog_->input_count, 4);     // 9999
 
-       fl_set_form_atclose(dialog_->form,
-                           C_FormPrintWMHideCB, 0);
+       target_.reset();
+       target_.registerRadioButton(dialog_->radio_printer,
+                                   PrinterParams::PRINTER);
+       target_.registerRadioButton(dialog_->radio_file,
+                                   PrinterParams::FILE);
+       order_.reset();
+       order_.registerRadioButton(dialog_->radio_order_reverse,
+                                  true);
+       order_.registerRadioButton(dialog_->radio_order_normal,
+                                  false);
+       which_.reset();
+       which_.registerRadioButton(dialog_->radio_odd_pages,
+                                  PrinterParams::ODD);
+       which_.registerRadioButton(dialog_->radio_even_pages,
+                                  PrinterParams::EVEN);
+       which_.registerRadioButton(dialog_->radio_all_pages,
+                                  PrinterParams::ALL);
 }
 
 
-void FormPrint::show()
+FL_FORM * FormPrint::form() const
 {
-       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,
-                            _("Print"));
-               fl_set_form_minsize(dialog_->form,
-                                   dialog_->form->w,
-                                   dialog_->form->h);
-               u_ = d_->updateBufferDependent.connect(slot(this,
-                                                           &FormPrint::update));
-               h_ = d_->hideBufferDependent.connect(slot(this,
-                                                         &FormPrint::hide));
-       }
-}
-
-
-void FormPrint::hide()
-{
-       if (dialog_
-           && dialog_->form
-           && dialog_->form->visible) {
-               fl_hide_form(dialog_->form);
-               u_.disconnect();
-               h_.disconnect();
-       }
+       if (dialog_) return dialog_->form;
+       return 0;
 }
 
 
@@ -138,12 +124,8 @@ void FormPrint::apply()
                return;
        }
 
-       PrinterParams::WhichPages wp(PrinterParams::ALL);
-       if (fl_get_button(dialog_->radio_even_pages)) {
-               wp = PrinterParams::EVEN;
-       } else if (fl_get_button(dialog_->radio_odd_pages)) {
-               wp = PrinterParams::ODD;
-       }
+       PrinterParams::WhichPages
+               wp(static_cast<PrinterParams::WhichPages>(which_.getButton()));
 
        string from;
        int to(0);
@@ -156,10 +138,8 @@ void FormPrint::apply()
                } // else we only print one page.
        }
 
-       PrinterParams::Target t(PrinterParams::PRINTER);
-       if (fl_get_button(dialog_->radio_file)) {
-               t = PrinterParams::FILE;
-       }
+       PrinterParams::Target
+               t(static_cast<PrinterParams::Target>(target_.getButton()));
 
        // we really should use the return value here I think.
        if (!printBuffer(lv_->buffer(),
@@ -167,10 +147,9 @@ void FormPrint::apply()
                                       string(fl_get_input(dialog_->input_printer)),
                                       string(fl_get_input(dialog_->input_file)),
                                       wp, from, to,
-                                      static_cast<bool>(fl_get_button(dialog_->
-                                                                      radio_order_reverse)),
-                                      static_cast<bool>(fl_get_button(dialog_->
-                                                                      radio_unsorted)),
+                                      static_cast<bool>(order_.getButton()),
+                                      !static_cast<bool>(fl_get_button(dialog_->
+                                                                       radio_collated)),
                                       strToInt(fl_get_input(dialog_->input_count))))) {
                WriteAlert(_("Error:"),
                           _("Unable to print"),
@@ -188,50 +167,9 @@ void FormPrint::update()
                fl_set_input(dialog_->input_printer, pp.printer_name.c_str());
                fl_set_input(dialog_->input_file, pp.file_name.c_str());
 
-               switch (pp.target) {
-               case PrinterParams::FILE:
-                       fl_set_button(dialog_->radio_printer, 0);
-                       fl_set_button(dialog_->radio_file, 1);
-                       break;
-
-               case PrinterParams::PRINTER:
-               default:
-                       fl_set_button(dialog_->radio_printer, 1);
-                       fl_set_button(dialog_->radio_file, 0);
-                       break;
-               }
-
-               switch (pp.reverse_order) {
-               case true:
-                       fl_set_button(dialog_->radio_order_normal, 0);
-                       fl_set_button(dialog_->radio_order_reverse, 1);
-                       break;
-
-               case false:
-               default:
-                       fl_set_button(dialog_->radio_order_normal, 1);
-                       fl_set_button(dialog_->radio_order_reverse, 0);
-                       break;
-               }
-// should be able to remove the various set_button 0 and rely on radio button
-// action.  Provided xforms is smart enough :D
-               fl_set_button(dialog_->radio_all_pages, 0);
-               fl_set_button(dialog_->radio_odd_pages, 0);
-               fl_set_button(dialog_->radio_even_pages, 0);
-               switch (pp.which_pages) {
-               case PrinterParams::ODD:
-                       fl_set_button(dialog_->radio_odd_pages, 1);
-                       break;
-
-               case PrinterParams::EVEN:
-                       fl_set_button(dialog_->radio_even_pages, 1);
-                       break;
-
-               case PrinterParams::ALL:
-               default:
-                       fl_set_button(dialog_->radio_all_pages, 1);
-                       break;
-               }
+               target_.setButton(pp.target);
+               order_.setButton(pp.reverse_order);
+               which_.setButton(pp.which_pages);
 
                // hmmm... maybe a bit weird but maybe not
                // we might just be remembering the last
@@ -256,18 +194,7 @@ void FormPrint::update()
 
                fl_set_input(dialog_->input_count,
                             tostr(pp.count_copies).c_str());
-
-               // Even readonly docs can be printed
-               // these 4 activations are probably superfluous but I'm
-               // being explicit for a reason.
-               // They can probably be removed soon along with a few more
-               // of the de/activations above once input() is a bit smarter.
-               fl_activate_object(dialog_->input_count);
-               fl_activate_object(dialog_->input_file);
-               fl_activate_object(dialog_->input_from_page);
-               fl_activate_object(dialog_->input_printer);
-               // and we should always be in a working state upon exit
-               input();
+               bc_.valid();
        }
 }
 
@@ -275,7 +202,7 @@ void FormPrint::update()
 // It would be nice if we checked for cases like:
 // Print only-odd-pages and from_page == an even number
 //
-void FormPrint::input()
+bool FormPrint::input(FL_OBJECT *, long)
 {
        bool activate = true;
 
@@ -316,55 +243,5 @@ void FormPrint::input()
 //         && !strlen(fl_get_input(dialog_->input_printer))) {
 //             activate = false;
 //     }
-
-       if (activate) {
-               fl_activate_object(dialog_->button_ok);
-               fl_activate_object(dialog_->button_apply);
-               fl_set_object_lcol(dialog_->button_ok, FL_BLACK);
-               fl_set_object_lcol(dialog_->button_apply, FL_BLACK);
-       } else {
-               fl_deactivate_object(dialog_->button_ok);
-               fl_deactivate_object(dialog_->button_apply);
-               fl_set_object_lcol(dialog_->button_ok, FL_INACTIVE);
-               fl_set_object_lcol(dialog_->button_apply, FL_INACTIVE);
-       }
-}
-
-
-int FormPrint::WMHideCB(FL_FORM * form, void *)
-{
-       // Ensure that the signals (u and h) are disconnected even if the
-       // window manager is used to close the dialog.
-       FormPrint * pre = static_cast<FormPrint*>(form->u_vdata);
-       pre->hide();
-       return FL_CANCEL;
-}
-
-
-void FormPrint::OKCB(FL_OBJECT * ob, long)
-{
-       FormPrint * pre = static_cast<FormPrint*>(ob->form->u_vdata);
-       pre->apply();
-       pre->hide();
-}
-
-
-void FormPrint::ApplyCB(FL_OBJECT * ob, long)
-{
-       FormPrint * pre = static_cast<FormPrint*>(ob->form->u_vdata);
-       pre->apply();
-}
-
-
-void FormPrint::CancelCB(FL_OBJECT * ob, long)
-{
-       FormPrint * pre = static_cast<FormPrint*>(ob->form->u_vdata);
-       pre->hide();
-}
-
-
-void FormPrint::InputCB(FL_OBJECT * ob, long)
-{
-       FormPrint * pre = static_cast<FormPrint*>(ob->form->u_vdata);
-       pre->input();
+       return activate;
 }