#include "Dialogs.h"
#include "FormBase.h"
+#include "LyXView.h"
#include "xform_macros.h"
C_RETURNCB (FormBase, WMHideCB)
C_GENERICCB(FormBase, ApplyCB)
-C_GENERICCB(FormBase, ApplyHideCB)
-C_GENERICCB(FormBase, HideCB)
+C_GENERICCB(FormBase, OKCB)
+C_GENERICCB(FormBase, CancelCB)
C_GENERICCB(FormBase, InputCB)
+C_GENERICCB(FormBase, RestoreCB)
-FormBase::FormBase(LyXView * lv, Dialogs * d, BufferDependency bd, string const & t)
- : dialogIsOpen(false), lv_(lv), u_(0), h_(0), title(t)
+FormBase::FormBase(LyXView * lv, Dialogs * d, string const & t,
+ ButtonPolicy * bp, char const * close, char const * cancel)
+ : lv_(lv), bc_(bp, cancel, close), d_(d), h_(0), title(t), bp_(bp),
+ minw_(0), minh_(0)
+{}
+
+
+FormBase::~FormBase()
{
- switch( bd ) {
- case BUFFER_DEPENDENT:
- hSignal_ = &d->hideBufferDependent;
- uSignal_ = &d->updateBufferDependent;
- break;
- case BUFFER_INDEPENDENT:
- hSignal_ = &d->hideAll;
- uSignal_ = 0;
- break;
- }
+ delete bp_;
+}
+
+
+void FormBase::connect()
+{
+ fl_set_form_minsize( form(), minw_, minh_ );
}
-
+
void FormBase::show()
{
if (!form()) {
update(); // make sure its up-to-date
fl_unfreeze_form( form() );
- dialogIsOpen = true;
if (form()->visible) {
fl_raise_form(form());
} else {
+ // calls to fl_set_form_minsize/maxsize apply only to the next
+ // fl_show_form(), so connect() comes first.
+ connect();
fl_show_form(form(),
FL_PLACE_MOUSE | FL_FREE_SIZE,
FL_TRANSIENT,
title.c_str());
- connect();
}
}
void FormBase::hide()
{
if (form() && form()->visible) {
- fl_hide_form(form());
+ // some dialogs might do things to the form first
+ // such as the nested tabfolder problem in Preferences
disconnect();
+ fl_hide_form(form());
}
-
- // free up the dialog for another inset
- dialogIsOpen = false;
- clearStore();
-}
-
-
-void FormBase::connect()
-{
- if ( uSignal_ ) {
- u_ = uSignal_->connect(slot(this, &FormBase::update));
- }
- h_ = hSignal_->connect(slot(this, &FormBase::hide));
-}
-
-
-void FormBase::disconnect()
-{
- u_.disconnect();
- h_.disconnect();
}
// window manager is used to close the dialog.
FormBase * pre = static_cast<FormBase*>(form->u_vdata);
pre->hide();
+ pre->bc_.hide();
return FL_CANCEL;
}
{
FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
pre->apply();
+ pre->bc_.apply();
}
-void FormBase::ApplyHideCB(FL_OBJECT * ob, long)
+void FormBase::OKCB(FL_OBJECT * ob, long)
{
FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
- pre->apply();
- pre->hide();
+ pre->ok();
+ pre->bc_.ok();
}
-void FormBase::HideCB(FL_OBJECT * ob, long)
+void FormBase::CancelCB(FL_OBJECT * ob, long)
{
FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
- pre->hide();
+ pre->cancel();
+ pre->bc_.cancel();
}
-void FormBase::InputCB(FL_OBJECT * ob, long data)
+void FormBase::InputCB(FL_OBJECT * ob, long data )
{
FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
- pre->input( data );
+ pre->bc_.valid( pre->input( ob, data ) );
+}
+
+
+void FormBase::RestoreCB(FL_OBJECT * ob, long)
+{
+ FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
+ pre->restore();
+ pre->bc_.undoAll();
+}
+
+
+FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
+ ButtonPolicy * bp,
+ char const * close, char const * cancel)
+ : FormBase( lv, d, t, bp, close, cancel )
+{}
+
+
+void FormBaseBI::connect()
+{
+ h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
+ FormBase::connect();
+}
+
+
+void FormBaseBI::disconnect()
+{
+ h_.disconnect();
+}
+
+
+FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
+ ButtonPolicy * bp,
+ char const * close, char const * cancel)
+ : FormBase( lv, d, t, bp, close, cancel ),
+ u_(0)
+{}
+
+
+void FormBaseBD::connect()
+{
+ u_ = d_->updateBufferDependent.
+ connect(slot(this, &FormBaseBD::updateSlot));
+ h_ = d_->hideBufferDependent.
+ connect(slot(this, &FormBaseBD::hide));
+ FormBase::connect();
+}
+
+
+void FormBaseBD::disconnect()
+{
+ u_.disconnect();
+ h_.disconnect();
}