]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormBaseDeprecated.C
Bugfixes: checkboxes to radiobuttons (from J�rgen S) and remove a little
[lyx.git] / src / frontends / xforms / FormBaseDeprecated.C
index 39f794694802f1f616009c6a37bdc4e8df34820b..c020a59cb1e79f41919af04b64f00a8e677ded6a 100644 (file)
@@ -1,10 +1,9 @@
-// -*- C++ -*-
 /* This file is part of
  * ====================================================== 
  *
  *           LyX, The Document Processor
  *
- *           Copyright 2000 The LyX Team.
+ *           Copyright 2000-2001 The LyX Team.
  *
  * ======================================================
  */
 #include "LyXView.h"
 #include "support/LAssert.h"
 #include "xformsBC.h"
+#include "lyxrc.h"
 //#include "debug.h"
 
 using SigC::slot;
 
-extern "C" int C_FormBaseDeprecatedWMHideCB(FL_FORM * ob, void * d)
-{
-       return FormBaseDeprecated::WMHideCB(ob, d);
-}
-extern "C" void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long d)
-{
-       FormBaseDeprecated::ApplyCB(ob, d);
-}
-extern "C" void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long d)
-{
-       FormBaseDeprecated::OKCB(ob, d);
-}
-extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long d)
-{
-       FormBaseDeprecated::CancelCB(ob, d);
-}
-extern "C" void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
-{
-       FormBaseDeprecated::InputCB(ob, d);
-}
-extern "C" void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long d)
-{
-       FormBaseDeprecated::RestoreCB(ob, d);
+extern "C" {
+       
+       static
+       int C_FormBaseDeprecatedWMHideCB(FL_FORM * ob, void * d)
+       {
+               return FormBaseDeprecated::WMHideCB(ob, d);
+       }
+
+       void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long d)
+       {
+               FormBaseDeprecated::ApplyCB(ob, d);
+       }
+
+       void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long d)
+       {
+               FormBaseDeprecated::OKCB(ob, d);
+       }
+
+       void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long d)
+       {
+               FormBaseDeprecated::CancelCB(ob, d);
+       }
+
+       void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
+       {
+               FormBaseDeprecated::InputCB(ob, d);
+       }
+
+       void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long d)
+       {
+               FormBaseDeprecated::RestoreCB(ob, d);
+       }
 }
 
 
 FormBaseDeprecated::FormBaseDeprecated(LyXView * lv, Dialogs * d,
-                                      string const & t)
-       : lv_(lv), d_(d), h_(0), r_(0), title(t), minw_(0), minh_(0)
+                                      string const & t, bool allowResize)
+       : lv_(lv), d_(d), h_(0), r_(0), title_(t),
+         minw_(0), minh_(0), allow_resize_(allowResize)
 {
-       Assert(lv && d);
+       lyx::Assert(lv && d);
 }
 
 
@@ -85,6 +95,13 @@ void FormBaseDeprecated::show()
 {
        if (!form()) {
                build();
+
+               bc().refresh();
+               // work around dumb xforms sizing bug
+               minw_ = form()->w;
+               minh_ = form()->h;
+
                fl_set_form_atclose(form(),
                                    C_FormBaseDeprecatedWMHideCB, 0);
        }
@@ -95,14 +112,28 @@ void FormBaseDeprecated::show()
 
        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();
+
+               // 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());
+                       FL_PLACE_MOUSE | FL_FREE_SIZE,
+                       (lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0),
+                       title_.c_str());
        }
 }
 
@@ -120,12 +151,12 @@ void FormBaseDeprecated::hide()
 
 int FormBaseDeprecated::WMHideCB(FL_FORM * form, void *)
 {
-       Assert(form);
+       lyx::Assert(form);
        // Ensure that the signals (u and h) are disconnected even if the
        // window manager is used to close the dialog.
        FormBaseDeprecated * pre =
                static_cast<FormBaseDeprecated*>(form->u_vdata);
-       Assert(pre);
+       lyx::Assert(pre);
        pre->hide();
        pre->bc().hide();
        return FL_CANCEL;
@@ -134,10 +165,10 @@ int FormBaseDeprecated::WMHideCB(FL_FORM * form, void *)
 
 void FormBaseDeprecated::ApplyCB(FL_OBJECT * ob, long)
 {
-       Assert(ob && ob->form);
+       lyx::Assert(ob && ob->form);
        FormBaseDeprecated * pre =
                static_cast<FormBaseDeprecated*>(ob->form->u_vdata);
-       Assert(pre);
+       lyx::Assert(pre);
        pre->apply();
        pre->bc().apply();
 }
@@ -145,10 +176,10 @@ void FormBaseDeprecated::ApplyCB(FL_OBJECT * ob, long)
 
 void FormBaseDeprecated::OKCB(FL_OBJECT * ob, long)
 {
-       Assert(ob && ob->form);
+       lyx::Assert(ob && ob->form);
        FormBaseDeprecated * pre =
                static_cast<FormBaseDeprecated*>(ob->form->u_vdata);
-       Assert(pre);
+       lyx::Assert(pre);
        pre->ok();
        pre->bc().ok();
 }
@@ -156,10 +187,10 @@ void FormBaseDeprecated::OKCB(FL_OBJECT * ob, long)
 
 void FormBaseDeprecated::CancelCB(FL_OBJECT * ob, long)
 {
-       Assert(ob && ob->form);
+       lyx::Assert(ob && ob->form);
        FormBaseDeprecated * pre =
                static_cast<FormBaseDeprecated*>(ob->form->u_vdata);
-       Assert(pre);
+       lyx::Assert(pre);
        pre->cancel();
        pre->bc().cancel();
 }
@@ -167,27 +198,35 @@ void FormBaseDeprecated::CancelCB(FL_OBJECT * ob, long)
 
 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
 {
-       Assert(ob && ob->form);
+       lyx::Assert(ob && ob->form);
        FormBaseDeprecated * pre =
                static_cast<FormBaseDeprecated*>(ob->form->u_vdata);
-       Assert(ob);
+       lyx::Assert(pre);
+
+       // 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);
+       }
+
        pre->bc().valid(pre->input(ob, data));
 }
 
 
 void FormBaseDeprecated::RestoreCB(FL_OBJECT * ob, long)
 {
-       Assert(ob && ob->form);
+       lyx::Assert(ob && ob->form);
        FormBaseDeprecated * pre =
                static_cast<FormBaseDeprecated*>(ob->form->u_vdata);
-       Assert(ob);
-       pre->bc().undoAll();
+       lyx::Assert(pre);
+       pre->bc().restore();
        pre->restore();
 }
 
 
-FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t)
-       : FormBaseDeprecated(lv, d, t)
+FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
+                      bool allowResize)
+       : FormBaseDeprecated(lv, d, t, allowResize)
 {}
 
 
@@ -198,8 +237,9 @@ void FormBaseBI::connect()
 }
 
 
-FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t)
-       : FormBaseDeprecated(lv, d, t),
+FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
+                      bool allowResize)
+       : FormBaseDeprecated(lv, d, t, allowResize),
          u_(0)
 {}