]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormBase.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormBase.C
index c1f17f9a4bf70c5560951f56631f3c76fd518724..ecd0cfbc42582c6e58fd218288c2ccab670092dc 100644 (file)
@@ -1,67 +1,38 @@
-// -*- 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 "LyXView.h"
+#include "xformsBC.h"
 #include "support/LAssert.h"
-//#include "debug.h"
-
-extern "C" int C_FormBaseWMHideCB(FL_FORM * ob, void * d)
-{
-       return FormBase::WMHideCB(ob, d);
-}
-extern "C" void C_FormBaseApplyCB(FL_OBJECT * ob, long d)
-{
-       FormBase::ApplyCB(ob, d);
-}
-extern "C" void C_FormBaseOKCB(FL_OBJECT * ob, long d)
-{
-       FormBase::OKCB(ob, d);
-}
-extern "C" void C_FormBaseCancelCB(FL_OBJECT * ob, long d)
-{
-       FormBase::CancelCB(ob, d);
-}
-extern "C" void C_FormBaseInputCB(FL_OBJECT * ob, long d)
-{
-       FormBase::InputCB(ob, d);
-}
-extern "C" void C_FormBaseRestoreCB(FL_OBJECT * ob, long d)
-{
-       FormBase::RestoreCB(ob, d);
-}
 
+extern "C" {
+       // Callback function invoked by xforms when the dialog is closed by the
+       // window manager
+       static int C_FormBaseWMHideCB(FL_FORM * form, void *);
 
-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), r_(0), title(t),
-         bp_(bp), minw_(0), minh_(0)
-{
-       Assert(lv && d && bp);
 }
 
 
-FormBase::~FormBase()
-{
-       delete bp_;
-}
+FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
+       : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
+         title_(t)
+{}
 
 
 void FormBase::redraw()
@@ -71,153 +42,145 @@ void FormBase::redraw()
 }
 
 
-void FormBase::connect()
-{
-       fl_set_form_minsize(form(), minw_, minh_);
-       r_ = Dialogs::redrawGUI.connect(slot(this, &FormBase::redraw));
-}
-
-
-void FormBase::disconnect()
-{
-       h_.disconnect();
-       r_.disconnect();
-}
-
-
 void FormBase::show()
 {
        if (!form()) {
                build();
-               fl_set_form_atclose(form(),
-                                   C_FormBaseWMHideCB, 0);
        }
-
+       
+       // 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());
 
        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 connect() comes first.
-               connect();
+               // 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());
+                       FL_PLACE_MOUSE | FL_FREE_SIZE,
+                       (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
+                       title_.c_str());
        }
 }
 
 
 void FormBase::hide()
 {
-       if (form() && form()->visible) {
-               // some dialogs might do things to the form first
-               // such as the nested tabfolder problem in Preferences
-               disconnect();
+       if (form() && form()->visible)
                fl_hide_form(form());
-       }
 }
 
 
-int FormBase::WMHideCB(FL_FORM * form, void *)
+void FormBase::InputCB(FL_OBJECT * ob, long data)
 {
-       Assert(form);
-       // 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);
-       Assert(pre);
-       pre->hide();
-       pre->bc_.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)
 {
-       Assert(ob && ob->form);
-       FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
-       Assert(pre);
-       pre->apply();
-       pre->bc_.apply();
+       return ButtonPolicy::SMI_VALID;
 }
 
 
-void FormBase::OKCB(FL_OBJECT * ob, long)
+namespace {
+
+FormBase * GetForm(FL_OBJECT * ob)
 {
-       Assert(ob && ob->form);
-       FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
-       Assert(pre);
-       pre->ok();
-       pre->bc_.ok();
+       lyx::Assert(ob && ob->form && ob->form->u_vdata);
+       FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
+       return pre;
 }
 
+} // namespace anon
 
-void FormBase::CancelCB(FL_OBJECT * ob, long)
-{
-       Assert(ob && ob->form);
-       FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
-       Assert(pre);
-       pre->cancel();
-       pre->bc_.cancel();
-}
 
+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)
-{
-       Assert(ob && ob->form);
-       FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
-       Assert(ob);
-       pre->bc_.valid(pre->input(ob, data));
-}
 
+       void C_FormBaseApplyCB(FL_OBJECT * ob, long)
+       {
+               GetForm(ob)->ApplyButton();
+       }
 
-void FormBase::RestoreCB(FL_OBJECT * ob, long)
-{
-       Assert(ob && ob->form);
-       FormBase * pre = static_cast<FormBase*>(ob->form->u_vdata);
-       Assert(ob);
-       pre->restore();
-       pre->bc_.undoAll();
-}
 
+       void C_FormBaseOKCB(FL_OBJECT * ob, long)
+       {
+               GetForm(ob)->OKButton();
+       }
 
-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 C_FormBaseCancelCB(FL_OBJECT * ob, long)
+       {
+               FormBase * form = GetForm(ob);
+               form->CancelButton();
+       }
 
-void FormBaseBI::connect()
-{
-       h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
-       FormBase::connect();
-}
 
+       void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
+       {
+               GetForm(ob)->RestoreButton();
+       }
 
-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 C_FormBaseInputCB(FL_OBJECT * ob, long d)
+       {
+               GetForm(ob)->InputCB(ob, d);
+       }
 
-void FormBaseBD::connect()
-{
-       u_ = d_->updateBufferDependent.
-                connect(slot(this, &FormBaseBD::updateSlot));
-       h_ = d_->hideBufferDependent.
-                connect(slot(this, &FormBaseBD::hide));
-       FormBase::connect();
-}
 
+       // 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;
+       }
 
-void FormBaseBD::disconnect()
-{
-       u_.disconnect();
-       FormBase::disconnect();
 }