]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormBase.C
Introduce LFUN_PRINT.
[lyx.git] / src / frontends / xforms / FormBase.C
index f8f896a6eea2d4257c87f210e6d4bfd1ab33f6d1..31836c0e681c47ecc67ce6fcfe61697689b39dfb 100644 (file)
@@ -3,42 +3,40 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Angus Leeming 
+ * \author Angus Leeming
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "FormBase.h"
 
-#include "ControlButtons.h"
-#include "xformsBC.h"
-#include "xforms_resize.h"
 #include "Tooltips.h"
 #include "xforms_helpers.h" // formatted
+#include "xforms_resize.h"
+#include "xformsBC.h"
 
-#include "gettext.h"        // _()
-#include "BoostFormat.h"
+#include "controllers/ButtonController.h"
+#include "controllers/ControlButtons.h"
 
-#include "support/LAssert.h"
 #include "support/filetools.h" //  LibFileSearch
+#include "support/lstrings.h"
 
-#include FORMS_H_LOCATION
+#include "lyx_forms.h"
 
-extern "C" {
+using lyx::support::bformat;
+using lyx::support::LibFileSearch;
 
-#if FL_VERSION > 0 || FL_REVISION >= 89
+using std::string;
 
+
+extern "C" {
+
+#if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
 // These should be in forms.h but aren't
 void fl_show_tooltip(const char *, int, int);
-
 void fl_hide_tooltip();
-
 #endif
 
 // Callback function invoked by xforms when the dialog is closed by the
@@ -52,11 +50,11 @@ static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
 
 
 FormBase::FormBase(string const & t, bool allowResize)
-       : ViewBase(),
+       : ViewBase(t),
          warning_posted_(false), message_widget_(0),
          minw_(0), minh_(0), allow_resize_(allowResize),
-         title_(t), icon_pixmap_(0), icon_mask_(0),
-         tooltips_(new Tooltips())
+         icon_pixmap_(0), icon_mask_(0),
+         tooltips_(new Tooltips)
 {}
 
 
@@ -69,6 +67,12 @@ FormBase::~FormBase()
 }
 
 
+bool FormBase::isVisible() const
+{
+       return form() && form()->visible;
+}
+
+
 Tooltips & FormBase::tooltips()
 {
        return *tooltips_;
@@ -82,10 +86,9 @@ void FormBase::redraw()
 }
 
 
-xformsBC & FormBase::bc()
+xformsBC & FormBase::bcview()
 {
-       return static_cast<xformsBC &>(getController().bc());
-       // return dynamic_cast<GUIbc &>(controller_ptr_->bc());
+       return static_cast<xformsBC &>(bc().view());
 }
 
 
@@ -103,7 +106,7 @@ void FormBase::prepare_to_show()
 
        // set the title for the minimized form
        if (!getController().IconifyWithMain())
-               fl_winicontitle(form()->window, title_.c_str());
+               fl_winicontitle(form()->window, getTitle().c_str());
 
        //  assign an icon to the form
        string const iconname = LibFileSearch("images", "lyx", "xpm");
@@ -124,7 +127,7 @@ void FormBase::show()
 {
        // build() is/should be called from the controller, so form() should
        // always exist.
-       lyx::Assert(form());
+       BOOST_ASSERT(form());
 
        // we use minw_ to flag whether the dialog has ever been shown.
        // In turn, prepare_to_show() initialises various bits 'n' pieces
@@ -156,7 +159,7 @@ void FormBase::show()
                if (!allow_resize_)
                        fl_set_form_maxsize(form(), minw_, minh_);
 
-               string const maximize_title = "LyX: " + title_;
+               string const maximize_title = "LyX: " + getTitle();
                int const iconify_policy =
                        getController().IconifyWithMain() ? FL_TRANSIENT : 0;
 
@@ -170,12 +173,6 @@ void FormBase::show()
 
 void FormBase::hide()
 {
-#if FL_VERSION > 0 || FL_REVISION >= 89
-       // Does no harm if none is visible and ensures that the tooltip form
-       // is hidden should the dialog be closed from the keyboard.
-       fl_hide_tooltip();
-#endif
-
        // 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
@@ -189,14 +186,14 @@ void FormBase::hide()
 
 void FormBase::setPrehandler(FL_OBJECT * ob)
 {
-       lyx::Assert(ob);
+       BOOST_ASSERT(ob);
        fl_set_object_prehandler(ob, C_PrehandlerCB);
 }
 
 
 void FormBase::setMessageWidget(FL_OBJECT * ob)
 {
-       lyx::Assert(ob && ob->objclass == FL_TEXT);
+       BOOST_ASSERT(ob && ob->objclass == FL_TEXT);
        message_widget_ = ob;
        fl_set_object_lsize(message_widget_, FL_NORMAL_SIZE);
 }
@@ -223,7 +220,7 @@ ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
 // preemptive handler for feedback messages
 void FormBase::MessageCB(FL_OBJECT * ob, int event)
 {
-       lyx::Assert(ob);
+       BOOST_ASSERT(ob);
 
        switch (event) {
        case FL_ENTER:
@@ -250,7 +247,7 @@ void FormBase::MessageCB(FL_OBJECT * ob, int event)
 
 void FormBase::PrehandlerCB(FL_OBJECT * ob, int event, int key)
 {
-       lyx::Assert(ob);
+       BOOST_ASSERT(ob);
 
        if (ob->objclass == FL_INPUT && event == FL_PUSH && key == 2) {
                // Trigger an input event when pasting in an xforms input object
@@ -259,43 +256,34 @@ void FormBase::PrehandlerCB(FL_OBJECT * ob, int event, int key)
                return;
        }
 
-
-       if (event != FL_ENTER && event != FL_LEAVE)
-               return;
-
-       if (ob->objclass == FL_TABFOLDER) {
-               // This prehandler is used to work-around an xforms bug and
-               // ensures that the form->x, form->y coords of the active
-               // tabfolder are up to date.
-
-               // The tabfolder itself can be very narrow, being just
-               // the visible border to the tabs.
-               // We thus use both FL_ENTER and FL_LEAVE as flags,
-               // in case the FL_ENTER event is not caught.
-
-               FL_FORM * const folder = fl_get_active_folder(ob);
-               if (folder && folder->window) {
-                       fl_get_winorigin(folder->window,
-                                        &(folder->x), &(folder->y));
-               }
-
-       }
-
        if (message_widget_) {
-               // Post feedback as the mouse enters the object,
-               // remove it as the mouse leaves.
-               MessageCB(ob, event);
+               switch (event) {
+               case FL_ENTER:
+               case FL_LEAVE:
+                       // Post feedback as the mouse enters the object,
+                       // remove it as the mouse leaves.
+                       MessageCB(ob, event);
+                       break;
+               }
        }
 
-#if FL_VERSION > 0 || FL_REVISION >= 89
+#if FL_VERSION == 0 || (FL_REVISION == 0 && FL_FIXLEVEL == 0)
        // Tooltips are not displayed on browser widgets due to an xforms' bug.
        // This is a work-around:
        if (ob->objclass == FL_BROWSER) {
-               if (event == FL_ENTER && ob->tooltip && *(ob->tooltip)) {
-                       fl_show_tooltip(ob->tooltip, ob->form->x + ob->x,
-                                       ob->form->y + ob->y + ob->h + 1);
-               } else if (event == FL_LEAVE) {
+               switch (event) {
+               case FL_ENTER:
+                       if (ob->tooltip && *(ob->tooltip)) {
+                               int const x = ob->form->x + ob->x;
+                               int const y = ob->form->y + ob->y + ob->h + 1;
+                               fl_show_tooltip(ob->tooltip, x, y);
+                       }
+                       break;
+               case FL_LEAVE:
+               case FL_PUSH:
+               case FL_KEYPRESS:
                        fl_hide_tooltip();
+                       break;
                }
        }
 #endif
@@ -311,7 +299,7 @@ void FormBase::postWarning(string const & warning)
 
 void FormBase::clearMessage()
 {
-       lyx::Assert(message_widget_);
+       BOOST_ASSERT(message_widget_);
 
        warning_posted_ = false;
 
@@ -328,23 +316,14 @@ void FormBase::clearMessage()
 
 void FormBase::postMessage(string const & message)
 {
-       lyx::Assert(message_widget_);
-
-#if USE_BOOST_FORMAT
-       boost::format fmter = warning_posted_ ?
-               boost::format(_("WARNING! %1$s")) :
-               boost::format("%1$s");
+       BOOST_ASSERT(message_widget_);
 
        int const width = message_widget_->w - 10;
-       string const str = formatted(boost::io::str(fmter % message),
-                                    width, FL_NORMAL_SIZE);
-#else
        string const tmp = warning_posted_ ?
-               _("WARNING!") + string(" ") + message :
+               bformat(_("WARNING! %1$s"), message) :
                message;
 
        string const str = formatted(tmp, width, FL_NORMAL_SIZE);
-#endif
 
        fl_set_object_label(message_widget_, str.c_str());
        FL_COLOR const label_color = warning_posted_ ? FL_RED : FL_LCOL;
@@ -359,7 +338,7 @@ namespace {
 
 FormBase * GetForm(FL_OBJECT * ob)
 {
-       lyx::Assert(ob && ob->form && ob->form->u_vdata);
+       BOOST_ASSERT(ob && ob->form && ob->form->u_vdata);
        FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
        return ptr;
 }
@@ -403,7 +382,7 @@ void C_FormBaseInputCB(FL_OBJECT * ob, long d)
 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);
+       BOOST_ASSERT(form && form->u_vdata);
        FormBase * ptr = static_cast<FormBase *>(form->u_vdata);
        ptr->getController().CancelButton();
        return FL_CANCEL;
@@ -414,11 +393,11 @@ static int C_PrehandlerCB(FL_OBJECT * ob, int event,
 {
        // Note that the return value is important in the pre-emptive handler.
        // Don't return anything other than 0.
-       lyx::Assert(ob);
+       BOOST_ASSERT(ob);
 
        // Don't Assert this one, as it can happen quite naturally when things
        // are being deleted in the d-tor.
-       //Assert(ob->form);
+       //BOOST_ASSERT(ob->form);
        if (!ob->form) return 0;
 
        FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);