]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormBase.C
Yet more dialog tweaking from Rob.
[lyx.git] / src / frontends / xforms / FormBase.C
index ebfd35804f5dbb38d7ab41cf1e551465f0543aba..4486572f8846d55616ad08e1c690dd35232d95e3 100644 (file)
@@ -1,13 +1,11 @@
-/* This file is part of
- * ====================================================== 
+/**
+ * \file FormBase.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Angus Leeming 
  *
- *           Copyright 2000-2001 The LyX Team.
- *
- * ======================================================
- *
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 #pragma implementation
 #endif
 
-#include "Dialogs.h"
 #include "FormBase.h"
+
+#include "ControlButtons.h"
 #include "xformsBC.h"
+#include "xforms_resize.h"
+#include "Tooltips.h"
+
 #include "support/LAssert.h"
+#include "support/filetools.h" //  LibFileSearch
+
+#include FORMS_H_LOCATION
 
 extern "C" {
 
 // Callback function invoked by xforms when the dialog is closed by the
 // window manager
-static int C_FormBaseWMHideCB(FL_FORM * form, void *);
+static int C_WMHideCB(FL_FORM * form, void *);
 
-// Use this to diaplay feedback messages or to trigger an input event on paste
-// with the middle mouse button
-static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
-                               FL_Coord, FL_Coord, int key, void *);
+// Callback function invoked by the xforms pre- and post-handler routines
+static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
 
 } // extern "C"
 
 
-FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
-       : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
-         title_(t), warning_posted_(false)
-
+FormBase::FormBase(string const & t, bool allowResize)
+       : ViewBase(), minw_(0), minh_(0), allow_resize_(allowResize),
+         title_(t), tooltips_(new Tooltips())
 {}
 
 
+FormBase::~FormBase()
+{
+       delete tooltips_;
+}
+
+
+Tooltips & FormBase::tooltips()
+{
+       return *tooltips_;
+}
+
+
 void FormBase::redraw()
 {
        if (form() && form()->visible)
@@ -49,6 +63,13 @@ void FormBase::redraw()
 }
 
 
+xformsBC & FormBase::bc()
+{
+       return static_cast<xformsBC &>(getController().bc());
+       // return dynamic_cast<GUIbc &>(controller_ptr_->bc());
+}
+
+
 void FormBase::show()
 {
        if (!form()) {
@@ -58,13 +79,17 @@ void FormBase::show()
        // 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) {
+               double const scale = scale_to_fit_tabs(form());
+               if (scale > 1.001)
+                       scale_form(form(), scale);
+
                bc().refresh();
 
                // work around dumb xforms sizing bug
                minw_ = form()->w;
                minh_ = form()->h;
 
-               fl_set_form_atclose(form(), C_FormBaseWMHideCB, 0);
+               fl_set_form_atclose(form(), C_WMHideCB, 0);
        }
 
        fl_freeze_form(form());
@@ -89,21 +114,60 @@ void FormBase::show()
                if (!allow_resize_)
                        fl_set_form_maxsize(form(), minw_, minh_);
 
+               string const maximize_title = "LyX: " + title_;
+               int const iconify_policy = getController().IconifyWithMain() ?
+                                               FL_TRANSIENT : 0;
+
                fl_show_form(form(),
-                       FL_PLACE_MOUSE | FL_FREE_SIZE,
-                       (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
-                       title_.c_str());
+                            FL_PLACE_MOUSE | FL_FREE_SIZE,
+                            iconify_policy,
+                            maximize_title.c_str());
+
+               if (iconify_policy == 0) {
+                       // set title for minimized form
+                       string const minimize_title = title_;
+                       fl_winicontitle(form()->window, minimize_title.c_str());
+
+                       //  assign an icon to form
+                       string const iconname = LibFileSearch("images", "lyx", "xpm");
+                       if (!iconname.empty()) {
+                               unsigned int w, h;
+                               Pixmap icon_mask;
+                               Pixmap const icon_p = fl_read_pixmapfile(fl_root,
+                                                       iconname.c_str(),
+                                                       &w,
+                                                       &h,
+                                                       &icon_mask,
+                                                       0, 0, 0); // this leaks
+                               fl_set_form_icon(form(), icon_p, icon_mask);
+                       }
+               }
        }
+
+       tooltips().set();
 }
 
 
 void FormBase::hide()
 {
+       // xforms sometimes tries to process a hint-type MotionNotify, and
+       // use XQueryPointer, without verifying if the window still exists.
+       // So we try to clear out motion events in the queue before the
+       // DestroyNotify
+       XSync(fl_get_display(), false);
+
        if (form() && form()->visible)
                fl_hide_form(form());
 }
 
 
+void FormBase::setPrehandler(FL_OBJECT * ob)
+{
+       lyx::Assert(ob);
+       fl_set_object_prehandler(ob, C_PrehandlerCB);
+}
+
+
 void FormBase::InputCB(FL_OBJECT * ob, long data)
 {
        // It is possible to set the choice to 0 when using the
@@ -122,48 +186,13 @@ ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
 }
 
 
-// preemptive handler for feedback messages
-void FormBase::FeedbackCB(FL_OBJECT * ob, int event)
-{
-       lyx::Assert(ob);
-
-       switch (event) {
-       case FL_ENTER:
-               warning_posted_ = false;
-               feedback(ob);
-               break;
-
-       case FL_LEAVE:
-               if (!warning_posted_)
-                       clear_feedback();
-               break;
-
-       default:
-               break;
-       }
-}
-
-
-void FormBase::setPrehandler(FL_OBJECT * ob)
-{
-       lyx::Assert(ob);
-       fl_set_object_prehandler(ob, C_FormBasePrehandler);
-}
-
-
-void FormBase::setWarningPosted(bool warning)
-{
-       warning_posted_ = warning;
-}
-
-
 namespace {
 
 FormBase * GetForm(FL_OBJECT * ob)
 {
        lyx::Assert(ob && ob->form && ob->form->u_vdata);
-       FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
-       return pre;
+       FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
+       return ptr;
 }
 
 } // namespace anon
@@ -171,38 +200,28 @@ FormBase * GetForm(FL_OBJECT * ob)
 
 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 C_FormBaseApplyCB(FL_OBJECT * ob, long)
 {
-       GetForm(ob)->ApplyButton();
+       GetForm(ob)->getController().ApplyButton();
 }
 
 
 void C_FormBaseOKCB(FL_OBJECT * ob, long)
 {
-       GetForm(ob)->OKButton();
+       GetForm(ob)->getController().OKButton();
 }
 
 
 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
 {
        FormBase * form = GetForm(ob);
-       form->CancelButton();
+       form->getController().CancelButton();
 }
 
 
 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
 {
-       GetForm(ob)->RestoreButton();
+       GetForm(ob)->getController().RestoreButton();
 }
 
 
@@ -212,8 +231,17 @@ void C_FormBaseInputCB(FL_OBJECT * ob, long d)
 }
 
 
-static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
-                               FL_Coord, FL_Coord, int key, void *)
+static int C_WMHideCB(FL_FORM * form, void *)
+{
+       // Close the dialog cleanly, even if the WM is used to do so.
+       lyx::Assert(form && form->u_vdata);
+       FormBase * ptr = static_cast<FormBase *>(form->u_vdata);
+       ptr->getController().CancelButton();
+       return FL_CANCEL;
+}
+
+static int C_PrehandlerCB(FL_OBJECT * ob, int event,
+                         FL_Coord, FL_Coord, int key, void *)
 {
        // Note that the return value is important in the pre-emptive handler.
        // Don't return anything other than 0.
@@ -224,21 +252,12 @@ static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
        //Assert(ob->form);
        if (!ob->form) return 0;
 
-       FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
-       if (!pre) return 0;
+       FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
 
-       if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
-               // Trigger an input event when pasting in an xforms input object
-               // using the middle mouse button.
-               pre->InputCB(ob, 0);
-
-       } else if (event == FL_ENTER || event == FL_LEAVE){
-               // Post feedback as the mouse enters the object,
-               // remove it as the mouse leaves.
-               pre->FeedbackCB(ob, event);
-       }
+       if (ptr)
+               ptr->PrehandlerCB(ob, event, key);
 
        return 0;
 }
-       
+
 } // extern "C"