-// -*- C++ -*-
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
- * Copyright 2000 The LyX Team.
+ * Copyright 2000-2001 The LyX Team.
*
* ======================================================
+ *
+ * \author Angus Leeming <a.leeming@ic.ac.uk>
*/
#include <config.h>
-#include FORMS_H_LOCATION
-
#ifdef __GNUG__
#pragma implementation
#endif
#include "Dialogs.h"
#include "FormBase.h"
-#include "xform_macros.h"
+#include "xformsBC.h"
+#include "support/LAssert.h"
+
+extern "C" {
+ // Callback function invoked by xforms when the dialog is closed by the
+ // window manager
+ static int C_FormBaseWMHideCB(FL_FORM * form, void *);
+
+}
-C_RETURNCB (FormBase, WMHideCB)
-C_GENERICCB(FormBase, ApplyCB)
-C_GENERICCB(FormBase, ApplyHideCB)
-C_GENERICCB(FormBase, HideCB)
-C_GENERICCB(FormBase, InputCB)
+FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
+ : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
+ title_(t)
+{}
-FormBase::FormBase(LyXView * lv, Dialogs * d, BufferDependency bd, string const & t)
- : dialogIsOpen(false), lv_(lv), u_(0), h_(0), title(t)
+
+void FormBase::redraw()
{
- switch( bd ) {
- case BUFFER_DEPENDENT:
- hSignal_ = &d->hideBufferDependent;
- uSignal_ = &d->updateBufferDependent;
- break;
- case BUFFER_INDEPENDENT:
- hSignal_ = &d->hideAll;
- uSignal_ = 0;
- break;
- }
+ if (form() && form()->visible)
+ fl_redraw_form(form());
}
-
+
void FormBase::show()
{
if (!form()) {
build();
- fl_set_form_atclose(form(),
- C_FormBaseWMHideCB, 0);
}
-
- fl_freeze_form( form() );
+
+ // use minw_ to flag whether the dialog has ever been shown
+ // (Needed now that build() is/should be called from the controller)
+ if (minw_ == 0) {
+ bc().refresh();
+
+ // work around dumb xforms sizing bug
+ minw_ = form()->w;
+ minh_ = form()->h;
+
+ fl_set_form_atclose(form(), C_FormBaseWMHideCB, 0);
+ }
+
+ fl_freeze_form(form());
update(); // make sure its up-to-date
- fl_unfreeze_form( form() );
+ fl_unfreeze_form(form());
- dialogIsOpen = true;
if (form()->visible) {
fl_raise_form(form());
+ /* This XMapWindow() will hopefully ensure that
+ * iconified dialogs are de-iconified. Mad props
+ * out to those crazy Xlib guys for forgetting a
+ * XDeiconifyWindow(). At least WindowMaker, when
+ * being notified of the redirected MapRequest will
+ * specifically de-iconify. From source, fvwm2 seems
+ * to do the same.
+ */
+ XMapWindow(fl_get_display(), form()->window);
} else {
+ // calls to fl_set_form_minsize/maxsize apply only to the next
+ // fl_show_form(), so this comes first.
+ fl_set_form_minsize(form(), minw_, minh_);
+ if (!allow_resize_)
+ fl_set_form_maxsize(form(), minw_, minh_);
+
fl_show_form(form(),
- FL_PLACE_MOUSE | FL_FREE_SIZE,
- FL_TRANSIENT,
- title.c_str());
- if( uSignal_ )
- u_ = uSignal_->connect(slot(this, &FormBase::update));
- h_ = hSignal_->connect(slot(this, &FormBase::hide));
+ FL_PLACE_MOUSE | FL_FREE_SIZE,
+ (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
+ title_.c_str());
}
}
void FormBase::hide()
{
- if (form() && form()->visible) {
+ if (form() && form()->visible)
fl_hide_form(form());
- u_.disconnect();
- h_.disconnect();
- }
-
- // free up the dialog for another inset
- dialogIsOpen = false;
- clearStore();
}
-int FormBase::WMHideCB(FL_FORM * form, void *)
+void FormBase::InputCB(FL_OBJECT * ob, long data)
{
- // Ensure that the signals (u and h) are disconnected even if the
- // window manager is used to close the dialog.
- FormBase * pre = static_cast<FormBase*>(form->u_vdata);
- pre->hide();
- return FL_CANCEL;
+ // It is possible to set the choice to 0 when using the
+ // keyboard shortcuts. This work-around deals with the problem.
+ if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
+ fl_set_choice(ob, 1);
+ }
+
+ bc().input(input(ob, data));
}
-void FormBase::ApplyCB(FL_OBJECT * ob, long)
+ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
{
- FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
- pre->apply();
+ return ButtonPolicy::SMI_VALID;
}
-void FormBase::ApplyHideCB(FL_OBJECT * ob, long)
+namespace {
+
+FormBase * GetForm(FL_OBJECT * ob)
{
- FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
- pre->apply();
- pre->hide();
+ lyx::Assert(ob && ob->form && ob->form->u_vdata);
+ FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
+ return pre;
}
+} // namespace anon
-void FormBase::HideCB(FL_OBJECT * ob, long)
-{
- FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
- pre->hide();
-}
+
+extern "C" {
+
+ static
+ int C_FormBaseWMHideCB(FL_FORM * form, void *)
+ {
+ // Close the dialog cleanly, even if the WM is used to do so.
+ lyx::Assert(form && form->u_vdata);
+ FormBase * pre = static_cast<FormBase *>(form->u_vdata);
+ pre->CancelButton();
+ return FL_CANCEL;
+ }
-void FormBase::InputCB(FL_OBJECT * ob, long data )
-{
- FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
- pre->input( data );
+ void C_FormBaseApplyCB(FL_OBJECT * ob, long)
+ {
+ GetForm(ob)->ApplyButton();
+ }
+
+
+ void C_FormBaseOKCB(FL_OBJECT * ob, long)
+ {
+ GetForm(ob)->OKButton();
+ }
+
+
+ void C_FormBaseCancelCB(FL_OBJECT * ob, long)
+ {
+ FormBase * form = GetForm(ob);
+ form->CancelButton();
+ }
+
+
+ void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
+ {
+ GetForm(ob)->RestoreButton();
+ }
+
+
+ void C_FormBaseInputCB(FL_OBJECT * ob, long d)
+ {
+ GetForm(ob)->InputCB(ob, d);
+ }
+
+
+ // To trigger an input event when pasting in an xforms input object
+ // using the middle mouse button.
+ int C_CutandPastePH(FL_OBJECT * ob, int event,
+ FL_Coord, FL_Coord, int key, void *)
+ {
+ if ((event == FL_PUSH) && (key == 2)
+ && (ob->objclass == FL_INPUT)) {
+ C_FormBaseInputCB(ob, 0);
+ }
+ return 0;
+ }
+
}