]> git.lyx.org Git - features.git/commitdiff
towards saner frontends (?). Part II: the menubar (now it is possible to switch front...
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 25 Jul 2003 21:34:45 +0000 (21:34 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 25 Jul 2003 21:34:45 +0000 (21:34 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7361 a592a061-630c-0410-9148-cb99ea01b6c8

26 files changed:
config/ChangeLog
config/configure.ac
config/configure.in
po/POTFILES.in
src/frontends/ChangeLog
src/frontends/Makefile.am
src/frontends/Menubar.C [deleted file]
src/frontends/Menubar.h
src/frontends/qt2/ChangeLog
src/frontends/qt2/Makefile.am
src/frontends/qt2/Menubar_pimpl.C [deleted file]
src/frontends/qt2/Menubar_pimpl.h [deleted file]
src/frontends/qt2/QLMenubar.C [new file with mode: 0644]
src/frontends/qt2/QLMenubar.h [new file with mode: 0644]
src/frontends/qt2/QLPopupMenu.C
src/frontends/qt2/QLPopupMenu.h
src/frontends/qt2/QtView.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/Makefile.am
src/frontends/xforms/Menubar_pimpl.C [deleted file]
src/frontends/xforms/Menubar_pimpl.h [deleted file]
src/frontends/xforms/XFormsMenubar.C [new file with mode: 0644]
src/frontends/xforms/XFormsMenubar.h [new file with mode: 0644]
src/frontends/xforms/XFormsToolbar.C
src/frontends/xforms/XFormsToolbar.h
src/frontends/xforms/XFormsView.C

index 978a3bfd03c24f451f305ed58d808997a31714b9..89491f3d389987d7f5fbd2daef31832ba26eecc3 100644 (file)
@@ -1,3 +1,8 @@
+2003-07-25  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * configure.in: 
+       * configure.ac: remove frontend directories from FRONTEND_INCLUDES
+
 2003-07-22  John Levon  <levon@movementarian.org>
 
        * configure.ac:
index 2c134b819e94b6218c1779fd615ab6a6c29ebfd5..a0f114b98feffc0719f8696efc85740b1f450732 100644 (file)
@@ -177,7 +177,6 @@ case "$lyx_use_frontend" in
         RPM_FRONTEND="xforms"
         RPM_FRONTEND_DEPS='libforms >= 1.0'
        FRONTEND_GUILIB="frontends/xforms/libxforms.la"
-       FRONTEND_INCLUDES="-I\$(srcdir)/xforms"
        FRONTEND_INFO="    libXpm version:               ${XPM_VERSION}\n\
     libforms version:             ${XFORMS_VERSION}\n"
        ;;
@@ -192,7 +191,7 @@ dnl     AC_SUBST(GNOME_FRONTEND_LIBS)
 dnl     FRONTEND="xforms gnome"
 dnl     FRONTEND_GUILIB="gnome/*.lo"
 dnl     FRONTEND_LDFLAGS="${GNOME_FRONTEND_LIBS}"
-dnl     FRONTEND_INCLUDES="-I\${srcdir}/gnome -I\${srcdir}/xforms ${GNOME_FRONTEND_CFLAGS} "
+dnl     FRONTEND_INCLUDES="${GNOME_FRONTEND_CFLAGS}"
 dnl     FRONTEND_LIBS="@XPM_LIB@ @XFORMS_LIB@ ${GNOME_FRONTEND_LIBS}"
 dnl    ;;
   qt)
@@ -200,7 +199,7 @@ dnl ;;
     RPM_FRONTEND_DEPS='qt >= 2.2.1'
     FRONTEND="qt2"
     FRONTEND_GUILIB="frontends/qt2/libqt2.la"
-    FRONTEND_INCLUDES="-I\${srcdir}/qt2 \$(QT_INCLUDES)"
+    FRONTEND_INCLUDES="\$(QT_INCLUDES)"
     FRONTEND_INFO="    Qt version:                   ${QT_VERSION}\n"
     ;;
   *)
index 336edfcf714760481394e89cd91a5e1249f53be2..98d0f458a2b512c1d0250bb958eb52d98312da8c 100644 (file)
@@ -174,7 +174,6 @@ case "$lyx_use_frontend" in
         RPM_FRONTEND="xforms"
         RPM_FRONTEND_DEPS='libforms >= 1.0'
        FRONTEND_GUILIB="xforms/*.lo xforms/forms/*.lo"
-       FRONTEND_INCLUDES="-I\$(srcdir)/xforms"
        FRONTEND_LIBS="@XFORMS_IMAGE_LIB@ @XFORMS_LIB@ @XPM_LIB@"
        FRONTEND_INFO="    libXpm version:               ${XPM_VERSION}\n\
     libforms version:             ${XFORMS_VERSION}\n"
@@ -193,7 +192,7 @@ dnl     AC_SUBST(GNOME_FRONTEND_LIBS)
 dnl     FRONTEND="xforms gnome"
 dnl     FRONTEND_GUILIB="gnome/*.lo"
 dnl     FRONTEND_LDFLAGS="${GNOME_FRONTEND_LIBS}"
-dnl     FRONTEND_INCLUDES="-I\${srcdir}/gnome -I\${srcdir}/xforms ${GNOME_FRONTEND_CFLAGS} "
+dnl     FRONTEND_INCLUDES="${GNOME_FRONTEND_CFLAGS} "
 dnl     FRONTEND_LIBS="@XPM_LIB@ @XFORMS_LIB@ ${GNOME_FRONTEND_LIBS}";;
   qt)
     QT_DO_IT_ALL
@@ -201,8 +200,8 @@ dnl     FRONTEND_LIBS="@XPM_LIB@ @XFORMS_LIB@ ${GNOME_FRONTEND_LIBS}";;
     RPM_FRONTEND_DEPS='qt >= 2.2.1'
     FRONTEND="qt2"
     FRONTEND_GUILIB="qt2/*.lo qt2/ui/*.lo qt2/moc/*.lo qt2/ui/moc/*.lo"
-    FRONTEND_LDFLAGS="\$(QT_LDFLAGS)"
-    FRONTEND_INCLUDES="-I\${srcdir}/qt2 \$(QT_INCLUDES)"
+    FRONTEND_LDFLAGS='$(QT_LDFLAGS)'
+    FRONTEND_INCLUDES='$(QT_INCLUDES)'
     FRONTEND_LIBS="\$(QT_LIB)"
     FRONTEND_INFO="    Qt version:                   ${QT_VERSION}\n"
     ;;
index 819b1966a7547feaf227cb36b934675d43c7f339..4fd6289d9a6fb68707a4caf237002f7f93e46ecb 100644 (file)
@@ -130,6 +130,7 @@ src/frontends/xforms/FormUrl.C
 src/frontends/xforms/FormVCLog.C
 src/frontends/xforms/FormWrap.C
 src/frontends/xforms/Menubar_pimpl.C
+src/frontends/xforms/XFormsMenubar.C
 src/frontends/xforms/XMiniBuffer.C
 src/frontends/xforms/xformsBC.h
 src/frontends/xforms/xforms_helpers.C
index 0331a9a882493ccce6f69d5840c5840de21e38a6..76f0356731ab7497f2717863262c3077304b0a3d 100644 (file)
@@ -1,3 +1,13 @@
+2003-07-25  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * Menubar.h: do not use a pimpl, but rather an abstract class
+
+       * Menubar.C: removed
+       
+2003-07-25  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * Toolbar.h: do not use a pimpl, but rather an abstract class
+
 2003-07-21  Angus Leeming  <leeming@lyx.org>
 
        * screen.C (c-tor, greyOut): use namespace lyx::graphics
index f7ba3d4085bda49ee6201a7f51fc2c25507286c5..803e0f7d0fb02b29085a811d946ca2dbd5e35747 100644 (file)
@@ -6,7 +6,7 @@ DIST_SUBDIRS = controllers xforms qt2 gnome
 
 noinst_LTLIBRARIES = libfrontends.la
 
-INCLUDES = $(FRONTEND_INCLUDES) -I$(srcdir)/..  $(BOOST_INCLUDES)
+INCLUDES = -I$(srcdir)/..  $(BOOST_INCLUDES)
 
 libfrontends_la_SOURCES = \
        Alert.C \
@@ -20,7 +20,6 @@ libfrontends_la_SOURCES = \
        LyXScreenFactory.h \
        LyXView.C \
        LyXView.h \
-       Menubar.C \
        Menubar.h \
        Painter.C \
        Painter.h \
diff --git a/src/frontends/Menubar.C b/src/frontends/Menubar.C
deleted file mode 100644 (file)
index d13d73d..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * \file Menubar.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Jean-Marc Lasgouttes
- *
- * Full author contact details are available in file CREDITS
- */
-
-#include <config.h>
-
-
-#include "Menubar.h"
-#include "MenuBackend.h"
-#include "Menubar_pimpl.h"
-
-Menubar::Menubar(LyXView * o, MenuBackend const & md)
-{
-       pimpl_ = new Pimpl(o, md);
-}
-
-
-Menubar::~Menubar()
-{
-       delete pimpl_;
-}
-
-
-void Menubar::openByName(string const & name)
-{
-       pimpl_->openByName(name);
-}
-
-
-void Menubar::update()
-{
-       pimpl_->update();
-}
index 5bef504b2dc97de2ed7337d2ffe06c1ce1265590..10b734ed5aa2d344f98d6b1ad0e57ef4b61e23ae 100644 (file)
@@ -5,6 +5,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
  *
  * Full author contact details are available in file CREDITS
  */
 
 #include "LString.h"
 
-class LyXView;
-class MenuBackend;
-
 /**
  * The LyX GUI independent menubar class
- * The GUI interface is implemented in the corresponding Menubar_pimpl class.
+ * The GUI interface is implemented in the frontends
  */
 class Menubar {
 public:
        ///
-       Menubar(LyXView * o, MenuBackend const &);
-       ///
-       ~Menubar();
+       virtual ~Menubar() {}
        /// Opens a top-level submenu given its name
-       void openByName(string const &);
+       virtual void openByName(string const &) = 0;
        /// update the state of the menuitems
-       void update();
-
-
-       //I disable this temporarily until I find a nice way to make it work
-       //with compaq cxx. (Jean-Marc)
-       // Is this a new comment? (Lgb)
-       struct Pimpl;
-       friend struct Pimpl;
-private:
-       ///
-       Pimpl * pimpl_;
+       virtual void update() = 0;
 };
 #endif // MENUBAR_H
index 52d3a27f163d12630fd75dfe956b2f7fd36b7ee9..3b75a43a45420057e455123daee60184af269df3 100644 (file)
@@ -1,3 +1,13 @@
+2003-07-25  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * QLMenubar.h: 
+       * QLMenubar.C: derives from Menubar (replaces Menubar::Pimpl)
+
+       * Menubar_pimpl.C:
+       * Menubar_pimpl.h: removed
+
+       * QtView.C: modified because of changes above
+
 2003-07-25  Jean-Marc Lasgouttes <lasgouttes@lyx.org>
 
        * QLToolbar.h: 
index d111884f7627d150c1f06086cf64b2eb79d65456..df4aee221be1c8cc010881c1ec38cff1921d0c91 100644 (file)
@@ -25,7 +25,7 @@ libqt2_la_SOURCES = \
        FileDialog.C \
        LyXKeySymFactory.C \
        LyXScreenFactory.C \
-       Menubar_pimpl.C Menubar_pimpl.h \
+       QLMenubar.C QLMenubar.h \
        qtTimeout.C qtTimeout.h \
        QAbout.C QAbout.h \
        QBibitem.C QBibitem.h \
diff --git a/src/frontends/qt2/Menubar_pimpl.C b/src/frontends/qt2/Menubar_pimpl.C
deleted file mode 100644 (file)
index 5a5ee63..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/**
- * \file qt2/Menubar_pimpl.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author  Lars Gullik Bjønnes
- *
- * Full author contact details are available in file CREDITS
- */
-
-#include <config.h>
-
-
-#include "Menubar_pimpl.h"
-#include "MenuBackend.h"
-#include "LyXAction.h"
-#include "kbmap.h"
-#include "buffer.h"
-#include "lyxfunc.h"
-#include "FloatList.h"
-#include "support/lstrings.h"
-#include "support/LAssert.h"
-#include "qt_helpers.h"
-#include "debug.h"
-
-#include "QtView.h"
-#include "QLPopupMenu.h"
-
-#include <qmenubar.h>
-#include <qcursor.h>
-
-#include <algorithm>
-
-using std::endl;
-using std::vector;
-using std::max;
-using std::min;
-using std::for_each;
-using std::pair;
-
-
-Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mbe)
-       : owner_(static_cast<QtView*>(view)), menubackend_(mbe)
-{
-       Menu::const_iterator m = mbe.getMenubar().begin();
-       Menu::const_iterator end = mbe.getMenubar().end();
-       for (; m != end; ++m) {
-               pair<int, QLPopupMenu *> menu =
-                       createMenu(owner_->menuBar(), &(*m), this, true);
-               name_map_[m->submenuname()] = menu.second;
-#ifdef Q_WS_MAC
-               /* The qt/mac menu code has a very silly hack that
-                  moves some menu entries that it recognizes by name
-                  (ex: "Preferences...") to the "LyX" menu. This
-                  feature can only work if the menu entries are
-                  always available. Since we build menus on demand,
-                  we have to have a reasonable default value before
-                  the menus have been explicitely opened. (JMarc)
-               */
-               menu.second->showing();
-#endif
-       }
-}
-
-
-Menubar::Pimpl::~Pimpl()
-{}
-
-
-void Menubar::Pimpl::openByName(string const & name)
-{
-       NameMap::const_iterator const cit = name_map_.find(name);
-       if (cit == name_map_.end())
-               return;
-
-       // this will have to do I'm afraid.
-       cit->second->exec(QCursor::pos());
-}
-
-
-void Menubar::Pimpl::update()
-{}
-
-
-QtView * Menubar::Pimpl::view()
-{
-       return owner_;
-}
-
-
-MenuBackend const & Menubar::Pimpl::backend()
-{
-       return menubackend_;
-}
diff --git a/src/frontends/qt2/Menubar_pimpl.h b/src/frontends/qt2/Menubar_pimpl.h
deleted file mode 100644 (file)
index 20d0fb4..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-// -*- C++ -*-
-/**
- * \file qt2/Menubar_pimpl.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS
- */
-
-
-#ifndef MENUBAR_PIMPL_H
-#define MENUBAR_PIMPL_H
-
-
-#include "frontends/Menubar.h"
-#include "LString.h"
-#include <map>
-
-class LyXView;
-class QtView;
-class MenuBackend;
-class QLPopupMenu;
-
-struct Menubar::Pimpl {
-public:
-       Pimpl(LyXView *, MenuBackend const &);
-
-       ~Pimpl();
-       
-       /// opens a top-level submenu given its name
-       void openByName(string const &);
-
-       /// update the state of the menuitems - not needed
-       void update();
-
-       /// return the owning view
-       QtView * view();
-
-       /// return the menu controller
-       MenuBackend const & backend();
-private:
-       /// owning view
-       QtView * owner_;
-
-       /// menu controller
-       MenuBackend const & menubackend_;
-
-       typedef std::map<string, QLPopupMenu *> NameMap;
-
-       /// name to menu for openByName
-       NameMap name_map_;
-};
-
-#endif // MENUBAR_PIMPL_H
diff --git a/src/frontends/qt2/QLMenubar.C b/src/frontends/qt2/QLMenubar.C
new file mode 100644 (file)
index 0000000..3c60325
--- /dev/null
@@ -0,0 +1,89 @@
+/**
+ * \file qt2/QLMenubar.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
+#include "MenuBackend.h"
+#include "LyXAction.h"
+#include "kbmap.h"
+#include "buffer.h"
+#include "lyxfunc.h"
+#include "FloatList.h"
+#include "support/lstrings.h"
+#include "support/LAssert.h"
+#include "qt_helpers.h"
+#include "debug.h"
+
+#include "QtView.h"
+#include "QLMenubar.h"
+#include "QLPopupMenu.h"
+
+#include <qmenubar.h>
+#include <qcursor.h>
+
+#include <algorithm>
+
+using std::endl;
+using std::vector;
+using std::max;
+using std::min;
+using std::for_each;
+using std::pair;
+
+
+QLMenubar::QLMenubar(LyXView * view, MenuBackend const & mbe)
+       : owner_(static_cast<QtView*>(view)), menubackend_(mbe)
+{
+       Menu::const_iterator m = mbe.getMenubar().begin();
+       Menu::const_iterator end = mbe.getMenubar().end();
+       for (; m != end; ++m) {
+               pair<int, QLPopupMenu *> menu =
+                       createMenu(owner_->menuBar(), &(*m), this, true);
+               name_map_[m->submenuname()] = menu.second;
+#ifdef Q_WS_MAC
+               /* The qt/mac menu code has a very silly hack that
+                  moves some menu entries that it recognizes by name
+                  (ex: "Preferences...") to the "LyX" menu. This
+                  feature can only work if the menu entries are
+                  always available. Since we build menus on demand,
+                  we have to have a reasonable default value before
+                  the menus have been explicitely opened. (JMarc)
+               */
+               menu.second->showing();
+#endif
+       }
+}
+
+
+void QLMenubar::openByName(string const & name)
+{
+       NameMap::const_iterator const cit = name_map_.find(name);
+       if (cit == name_map_.end())
+               return;
+
+       // this will have to do I'm afraid.
+       cit->second->exec(QCursor::pos());
+}
+
+
+void QLMenubar::update()
+{}
+
+
+QtView * QLMenubar::view()
+{
+       return owner_;
+}
+
+
+MenuBackend const & QLMenubar::backend()
+{
+       return menubackend_;
+}
diff --git a/src/frontends/qt2/QLMenubar.h b/src/frontends/qt2/QLMenubar.h
new file mode 100644 (file)
index 0000000..d92f4e6
--- /dev/null
@@ -0,0 +1,54 @@
+// -*- C++ -*-
+/**
+ * \file qt2/QLMenubar.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+
+#ifndef QLMENUBAR_H
+#define QLMENUBAR_H
+
+#include "frontends/Menubar.h"
+#include "LString.h"
+#include <map>
+
+class LyXView;
+class QtView;
+class MenuBackend;
+class QLPopupMenu;
+
+class QLMenubar : public Menubar {
+public:
+       QLMenubar(LyXView *, MenuBackend const &);
+
+       /// opens a top-level submenu given its name
+       void openByName(string const &);
+
+       /// update the state of the menuitems - not needed
+       void update();
+
+       /// return the owning view
+       QtView * view();
+
+       /// return the menu controller
+       MenuBackend const & backend();
+private:
+       /// owning view
+       QtView * owner_;
+
+       /// menu controller
+       MenuBackend const & menubackend_;
+
+       typedef std::map<string, QLPopupMenu *> NameMap;
+
+       /// name to menu for openByName
+       NameMap name_map_;
+};
+
+#endif // QLMENUBAR_H
index 40b24685e1f65460d577824be90fa1c867b480e4..676dd9ffd247982f415d08729f297b69d366fa22 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "QtView.h"
 
+#include "QLMenubar.h"
 #include "QLPopupMenu.h"
 #include "qt_helpers.h"
 
@@ -58,7 +59,7 @@ string const getLabel(MenuItem const & mi)
 
 
 pair<int, QLPopupMenu *>
-createMenu(QMenuData * parent, MenuItem const * item, Menubar::Pimpl * owner,
+createMenu(QMenuData * parent, MenuItem const * item, QLMenubar * owner,
           bool is_toplevel)
 {
        // FIXME: leaks ??
@@ -68,7 +69,7 @@ createMenu(QMenuData * parent, MenuItem const * item, Menubar::Pimpl * owner,
 }
 
 
-QLPopupMenu::QLPopupMenu(Menubar::Pimpl * owner,
+QLPopupMenu::QLPopupMenu(QLMenubar * owner,
                         string const & name, bool toplevel)
        : owner_(owner), name_(name)
 {
index 38fe2984cbf16c4038556e6086ce36ab919ab374..df2368c52eb6031a93be7c717c1723bb7fe9e8ab 100644 (file)
@@ -13,8 +13,6 @@
 #define QLPOPUPMENU_H
 
 
-#include "Menubar_pimpl.h"
-
 #include <qpopupmenu.h>
 
 #include "LString.h"
@@ -23,18 +21,19 @@ class MenuBackend;
 class MenuItem;
 class Menu;
 class QMenuData;
+class QLMenubar;
 class QLPopupMenu;
 
 /// create a sub-menu
 std::pair<int, QLPopupMenu *>
 createMenu(QMenuData * parent, MenuItem const * item,
-          Menubar::Pimpl * owner, bool is_toplevel = false);
+          QLMenubar * owner, bool is_toplevel = false);
 
 /// a submenu
 class QLPopupMenu : public QPopupMenu {
        Q_OBJECT
 public:
-       QLPopupMenu(Menubar::Pimpl * owner,
+       QLPopupMenu(QLMenubar * owner,
                    string const & name, bool toplevel);
 
        /// populate the menu
@@ -44,7 +43,7 @@ public slots:
        void showing();
 private:
        /// our owning menubar
-       Menubar::Pimpl * owner_;
+       QLMenubar * owner_;
 
        /// the name of this menu
        string name_;
index 6e411efc37a3347e3b4af5ebbfadda3e7ae6d6ce..e9162aa5c579176118e1ffb292201b2804f74d6c 100644 (file)
@@ -21,7 +21,6 @@
 #include "lyxfunc.h"
 #include "BufferView.h"
 
-#include "frontends/Menubar.h"
 #include "frontends/Dialogs.h"
 #include "frontends/Timeout.h"
 
@@ -29,6 +28,7 @@
 
 #include "QtView.h"
 #include "QLToolbar.h"
+#include "QLMenubar.h"
 #include "qfont_loader.h"
 #include "QCommandBuffer.h"
 #include "qt_helpers.h"
@@ -61,7 +61,7 @@ QtView::QtView(unsigned int width, unsigned int height)
 
        bufferview_.reset(new BufferView(this, 0, 0, width, height));
 
-       menubar_.reset(new Menubar(this, menubackend));
+       menubar_.reset(new QLMenubar(this, menubackend));
        toolbar_.reset(new QLToolbar(this));
        toolbar_->init();
 
index 5048b25a164cb0d809a9a1c11e0bb0232adaa529..c1cd64ac4d830ab1b4b93e125d9b450296fab759 100644 (file)
@@ -1,10 +1,22 @@
-2003-07-25  Jean-Marc Lasgouttes <lasgouttes@lyx.org>  <lyx@htwm.de>
+2003-07-25  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
-       * 
+       * XFormsMenubar.h: 
+       * XFormsMenubar.C: derives from Menubar (replaces Menubar::Pimpl)
 
-2003-07-25  Jean-Marc Lasgouttes  <lasgoutes@lyx.org>
+       * Menubar_pimpl.C:
+       * Menubar_pimpl.h: removed
+
+       * XFormsView.C: modified because of changes above
+
+2003-07-25  Jean-Marc Lasgouttes <lasgouttes@lyx.org>
 
        * XFormsToolbar.h: 
+       * XFormsToolbar.C: derives from Toolbar (replaces Toolbar::Pimpl)
+
+       * Toolbar_pimpl.C:
+       * Toolbar_pimpl.h: removed
+
+       * XFormsView.C: modified because of changes above
 
 2003-07-23  Angus Leeming  <leeming@lyx.org>
 
index 988c2f59544f12179ca97acae91fe06580c53fed..6b826efce8210134ff71c9de31f1aba60af48e47 100644 (file)
@@ -151,8 +151,8 @@ libxforms_la_SOURCES = \
        FormWrap.h \
        LyXKeySymFactory.C \
        LyXScreenFactory.C \
-       Menubar_pimpl.C \
-       Menubar_pimpl.h \
+       XFormsMenubar.C \
+       XFormsMenubar.h \
        RadioButtonGroup.C \
        RadioButtonGroup.h \
        XFormsToolbar.C \
diff --git a/src/frontends/xforms/Menubar_pimpl.C b/src/frontends/xforms/Menubar_pimpl.C
deleted file mode 100644 (file)
index ea868c8..0000000
+++ /dev/null
@@ -1,400 +0,0 @@
-/**
- * \file xforms/Menubar_pimpl.C
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author  Lars Gullik Bjønnes
- * \author Jean-Marc Lasgouttes
- *
- * Full author contact details are available in file CREDITS
- */
-
-#include <config.h>
-
-#include "Menubar_pimpl.h"
-#include "MenuBackend.h"
-#include "XFormsView.h"
-#include "lyxfunc.h"
-#include "support/lstrings.h"
-#include "support/tostr.h"
-#include "support/LAssert.h"
-#include "gettext.h"
-#include "debug.h"
-#include "lyx_forms.h"
-
-//#include <boost/scoped_ptr.hpp>
-
-#include <algorithm>
-
-using namespace lyx::support;
-
-using std::endl;
-using std::vector;
-using std::max;
-using std::min;
-using std::for_each;
-
-typedef vector<int>::size_type size_type;
-
-namespace {
-
-// Some constants
-int const MENU_LABEL_SIZE = FL_NORMAL_SIZE;
-int const MENU_LABEL_STYLE = FL_NORMAL_STYLE;
-int const mheight = 30;
-int const mbheight= 22;
-// where to place the menubar?
-int const yloc = (mheight - mbheight)/2; //air + bw;
-int const mbadd = 20; // menu button add (to width)
-// Some space between buttons on the menubar
-int const air = 2;
-char const * menu_tabstop = "aa";
-char const * default_tabstop = "aaaaaaaa";
-// We do not want to mix position values in a menu (like the index of
-// a submenu) with the action numbers which convey actual information.
-// Therefore we offset all the action values by an arbitrary large
-// constant.
-int const action_offset = 1000;
-
-// This is used a few times below.
-inline
-int string_width(string const & str)
-{
-       return fl_get_string_widthTAB(MENU_LABEL_STYLE, MENU_LABEL_SIZE,
-                                     str.c_str(),
-                                     static_cast<int>(str.length()));
-}
-
-} // namespace anon
-
-
-extern "C" {
-
-       //Defined later, used in makeMenubar().
-       static
-       void C_Menubar_Pimpl_MenuCallback(FL_OBJECT * ob, long button)
-       {
-               Menubar::Pimpl::MenuCallback(ob, button);
-       }
-
-}
-
-
-Menubar::Pimpl::Pimpl(LyXView * view, MenuBackend const & mb)
-       : owner_(static_cast<XFormsView*>(view)), menubackend_(&mb)
-{
-       makeMenubar(menubackend_->getMenubar());
-}
-
-
-Menubar::Pimpl::~Pimpl()
-{}
-
-
-void Menubar::Pimpl::makeMenubar(Menu const & menu)
-{
-       FL_FORM * form = owner_->getForm();
-       int moffset = 0;
-
-       // Create menu frame if there is non yet.
-       FL_OBJECT * frame = fl_add_frame(FL_UP_FRAME, 0, 0,
-                                        form->w, mheight, "");
-       fl_set_object_resize(frame, FL_RESIZE_ALL);
-       fl_set_object_gravity(frame, NorthWestGravity,
-                             NorthEastGravity);
-
-       Menu::const_iterator i = menu.begin();
-       Menu::const_iterator end = menu.end();
-       for (; i != end; ++i) {
-               FL_OBJECT * obj;
-               if (i->kind() != MenuItem::Submenu) {
-                       lyxerr << "ERROR: Menubar::Pimpl::createMenubar:"
-                               " only submenus can appear in a menubar"
-                              << endl;
-                       continue;
-               }
-               string const label = i->label();
-               string const shortcut = '#' + i->shortcut();
-               int const width = string_width(label);
-               obj = fl_add_button(FL_MENU_BUTTON,
-                                   air + moffset, yloc,
-                                   width + mbadd,
-                                   mbheight,
-                                   label.c_str());
-               fl_set_object_boxtype(obj, FL_FLAT_BOX);
-               fl_set_object_color(obj, FL_MCOL, FL_MCOL);
-               fl_set_object_lsize(obj, MENU_LABEL_SIZE);
-               fl_set_object_lstyle(obj, MENU_LABEL_STYLE);
-               fl_set_object_resize(obj, FL_RESIZE_ALL);
-               fl_set_object_gravity(obj, NorthWestGravity,
-                                     NorthWestGravity);
-               moffset += obj->w + air;
-               fl_set_object_shortcut(obj, shortcut.c_str(), 1);
-               fl_set_object_callback(obj, C_Menubar_Pimpl_MenuCallback, 1);
-
-               boost::shared_ptr<ItemInfo>
-                       iteminfo(new ItemInfo(this, new MenuItem(*i), obj));
-               buttonlist_.push_back(iteminfo);
-               obj->u_vdata = iteminfo.get();
-       }
-
-}
-
-
-void Menubar::Pimpl::update()
-{
-       // nothing yet
-}
-
-
-void Menubar::Pimpl::openByName(string const & name)
-{
-       for (ButtonList::const_iterator cit = buttonlist_.begin();
-            cit != buttonlist_.end(); ++cit) {
-               if ((*cit)->item_->submenuname() == name) {
-                       MenuCallback((*cit)->obj_, 1);
-                       return;
-               }
-       }
-
-       lyxerr << "Menubar::Pimpl::openByName: menu "
-              << name << " not found" << endl;
-}
-
-
-namespace {
-
-Menu::size_type const max_number_of_items = 25;
-
-int get_new_submenu(vector<int> & smn, Window win)
-{
-       static size_type max_number_of_menus = 32;
-       if (smn.size() >= max_number_of_menus)
-               max_number_of_menus =
-                   fl_setpup_maxpup(static_cast<int>(2*smn.size()));
-       int menu = fl_newpup(win);
-       fl_setpup_softedge(menu, true);
-       fl_setpup_bw(menu, -1);
-       smn.push_back(menu);
-       return menu;
-}
-
-
-string const fixlabel(string const & str)
-{
-       return subst(str, "%", "%%");
-}
-
-
-
-} // namespace anon
-
-
-
-int Menubar::Pimpl::create_submenu(Window win, XFormsView * view,
-                                  Menu const & menu, vector<int> & smn)
-{
-       const int menuid = get_new_submenu(smn, win);
-       lyxerr[Debug::GUI] << "Menubar::Pimpl::create_submenu: creating "
-                          << menu.name() << " as menuid=" << menuid << endl;
-
-       // Compute the size of the largest label (because xforms is
-       // not able to support shortcuts correctly...)
-       int max_width = 0;
-       string widest_label;
-       Menu::const_iterator end = menu.end();
-       for (Menu::const_iterator i = menu.begin(); i != end; ++i) {
-               MenuItem const & item = (*i);
-               if (item.kind() == MenuItem::Command) {
-                       string const label = item.label() + '\t';
-                       int const width = string_width(label);
-                       if (width > max_width) {
-                               max_width = width;
-                               widest_label = label;
-                       }
-               }
-       }
-       lyxerr[Debug::GUI] << "max_width=" << max_width
-                          << ", widest_label=\"" << widest_label
-                          << '"' << endl;
-
-       size_type count = 0;
-       int curmenuid = menuid;
-       for (Menu::const_iterator i = menu.begin(); i != end; ++i) {
-               MenuItem const & item = (*i);
-
-               ++count;
-               // add a More... submenu if the menu is too long (but
-               // not just for one extra entry!)
-               if (count > max_number_of_items && (i+1) != end) {
-                       int tmpmenuid = get_new_submenu(smn, win);
-                       lyxerr[Debug::GUI] << "Too many items, creating "
-                                          << "new menu " << tmpmenuid << endl;
-                       string label = _("More");
-                       label += "...%m";
-                       fl_addtopup(curmenuid, label.c_str(), tmpmenuid);
-                       count = 0;
-                       curmenuid = tmpmenuid;
-               }
-
-               switch (item.kind()) {
-               case MenuItem::Command:
-               case MenuItem::Submenu:
-               {
-                       // Build the menu label from all the info
-                       string label = fixlabel(item.label());
-                       FuncStatus const flag = item.status();
-                       int submenuid = 0;
-
-                       // Is there a key binding?
-                       string const binding = item.binding();
-                       if (!binding.empty()) {
-                               // Try to be clever and add  just enough
-                               // tabs to align shortcuts.
-                               do
-                                       label += '\t';
-                               while (string_width(label) < max_width + 5);
-                               label += binding;
-                       }
-
-                       // Is there a separator after the item?
-                       if ((i+1) != end
-                           && (i + 1)->kind() == MenuItem::Separator)
-                               label += "%l";
-
-                       // Modify the entry using the function status
-                       if (flag.onoff(true))
-                               label += "%B";
-                       if (flag.onoff(false))
-                               label += "%b";
-                       if (flag.disabled())
-                               label += "%i";
-
-                       // Add the shortcut
-                       string shortcut = item.shortcut();
-                       if (!shortcut.empty()) {
-                               shortcut += lowercase(shortcut[0]);
-                               label += "%h";
-                       }
-
-                       // Finally add the action/submenu
-                       if (item.kind() == MenuItem::Submenu) {
-                               // create the submenu
-                               submenuid =
-                                       create_submenu(win, view,
-                                                      *item.submenu(), smn);
-                               if (submenuid == -1)
-                                       return -1;
-                               label += "%x" + tostr(smn.size());
-                               lyxerr[Debug::GUI]
-                                       << "Menu: " << submenuid
-                                       << " (at index " << smn.size()
-                                       << "), ";
-                       } else {
-                               // Add the action
-                               label += "%x" + tostr(item.action()
-                                                     + action_offset);
-                               lyxerr[Debug::GUI] << "Action: \""
-                                                  << item.action() << "\", ";
-                       }
-
-                       // Add everything to the menu
-                       fl_addtopup(curmenuid, label.c_str(),
-                                   shortcut.c_str());
-                       if (item.kind() == MenuItem::Submenu)
-                               fl_setpup_submenu(curmenuid, smn.size(),
-                                                 submenuid);
-
-                       lyxerr[Debug::GUI] << "label \"" << label
-                                          << "\", binding \"" << binding
-                                          << "\", shortcut \"" << shortcut
-                                          << "\" (added to menu "
-                                          << curmenuid << ')' << endl;
-                       break;
-               }
-
-               case MenuItem::Separator:
-                       // already done, and if it was the first one,
-                       // we just ignore it.
-                       --count;
-                       break;
-
-
-               default:
-                       lyxerr << "Menubar::Pimpl::create_submenu: "
-                               "this should not happen" << endl;
-                       break;
-               }
-       }
-       return menuid;
-}
-
-
-void Menubar::Pimpl::MenuCallback(FL_OBJECT * ob, long button)
-{
-       ItemInfo * iteminfo = static_cast<ItemInfo *>(ob->u_vdata);
-       XFormsView * view = iteminfo->pimpl_->owner_;
-       MenuItem const * item = iteminfo->item_.get();
-
-       if (button == 1) {
-               // set the pseudo menu-button
-               fl_set_object_boxtype(ob, FL_DOWN_BOX);
-               fl_set_button(ob, 0);
-               fl_redraw_object(ob);
-       }
-
-       // Paranoia check
-       Assert(item->kind() == MenuItem::Submenu);
-
-       // set tabstop length
-       fl_set_tabstop(menu_tabstop);
-
-       MenuBackend const * menubackend_ = iteminfo->pimpl_->menubackend_;
-       Menu tomenu;
-       Menu const frommenu = menubackend_->getMenu(item->submenuname());
-       menubackend_->expand(frommenu, tomenu, view);
-       vector<int> submenus;
-       int menu = iteminfo->pimpl_->create_submenu(FL_ObjWin(ob), view,
-                                                   tomenu, submenus);
-       if (menu != -1) {
-               // place popup
-               fl_setpup_position(view->getForm()->x + ob->x,
-                                  view->getForm()->y + ob->y + ob->h + 10);
-               int choice = fl_dopup(menu);
-
-               if (button == 1) {
-                               // set the pseudo menu-button back
-                       fl_set_object_boxtype(ob, FL_FLAT_BOX);
-                       fl_redraw_object(ob);
-               }
-
-               // If the action value is too low, then it is not a
-               // valid action, but something else.
-               if (choice >= action_offset + 1) {
-                       view->getLyXFunc().dispatch(choice - action_offset, true);
-               } else {
-                       lyxerr[Debug::GUI]
-                               << "MenuCallback: ignoring bogus action "
-                               << choice << endl;
-               }
-       } else {
-               lyxerr << "Error in MenuCallback" << endl;
-       }
-
-       for_each(submenus.begin(), submenus.end(), fl_freepup);
-       // restore tabstop length
-       fl_set_tabstop(default_tabstop);
-
-}
-
-
-Menubar::Pimpl::ItemInfo::ItemInfo
-       (Menubar::Pimpl * p, MenuItem const * i, FL_OBJECT * o)
-       : pimpl_(p), obj_(o)
-{
-       item_.reset(i);
-}
-
-
-Menubar::Pimpl::ItemInfo::~ItemInfo()
-{}
diff --git a/src/frontends/xforms/Menubar_pimpl.h b/src/frontends/xforms/Menubar_pimpl.h
deleted file mode 100644 (file)
index 2e04224..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-// -*- C++ -*-
-/**
- * \file xforms/Menubar_pimpl.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Lars Gullik Bjønnes
- *
- * Full author contact details are available in file CREDITS
- */
-
-#ifndef MENUBAR_PIMPL_H
-#define MENUBAR_PIMPL_H
-
-
-#include "LString.h"
-#include "frontends/Menubar.h"
-
-#include <boost/shared_ptr.hpp>
-
-#include "forms_fwd.h"
-#include <X11/X.h> // Window
-
-#include <vector>
-#include <map>
-
-class LyXView;
-class XFormsView;
-class Menu;
-class MenuItem;
-
-/** The LyX GUI independent menubar class
-  The GUI interface is implemented in the corresponding Menubar_pimpl class.
-  */
-struct Menubar::Pimpl {
-public:
-       ///
-       Pimpl(LyXView *, MenuBackend const &);
-       ///
-       ~Pimpl();
-
-       /// update the state of the menuitems
-       void update();
-
-       /// Opens a top-level submenu given its name
-       void openByName(string const &);
-
-       ///
-       static void MenuCallback(FL_OBJECT *, long);
-
-private:
-       ///
-       void add_toc(int menu, string const & extra_label,
-                    std::vector<int> & smn, Window win);
-       ///
-       void add_references(int menu, string const & extra_label,
-                           std::vector<int> & smn, Window win);
-       ///
-       int create_submenu(Window win, XFormsView * view,
-                          Menu const & menu, std::vector<int> & smn);
-
-       //
-       void makeMenubar(Menu const & menu);
-
-       ///
-       XFormsView * owner_;
-       ///
-       MenuBackend const * menubackend_;
-       ///
-       struct ItemInfo {
-               ///
-               ItemInfo(Menubar::Pimpl * p, MenuItem const * i,
-                        FL_OBJECT * o);
-               ~ItemInfo();
-               ///
-               Menubar::Pimpl * pimpl_;
-               ///
-               boost::shared_ptr<MenuItem const> item_;
-               ///
-               FL_OBJECT * obj_;
-       };
-
-       ///
-       typedef std::vector<boost::shared_ptr<ItemInfo> > ButtonList;
-       ///
-       ButtonList buttonlist_;
-};
-#endif
diff --git a/src/frontends/xforms/XFormsMenubar.C b/src/frontends/xforms/XFormsMenubar.C
new file mode 100644 (file)
index 0000000..c5e2c0f
--- /dev/null
@@ -0,0 +1,400 @@
+/**
+ * \file XFormsMenubar.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author  Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <config.h>
+
+#include "XFormsMenubar.h"
+#include "MenuBackend.h"
+#include "XFormsView.h"
+#include "lyxfunc.h"
+#include "support/lstrings.h"
+#include "support/tostr.h"
+#include "support/LAssert.h"
+#include "gettext.h"
+#include "debug.h"
+#include "lyx_forms.h"
+
+//#include <boost/scoped_ptr.hpp>
+
+#include <algorithm>
+
+using namespace lyx::support;
+
+using std::endl;
+using std::vector;
+using std::max;
+using std::min;
+using std::for_each;
+
+typedef vector<int>::size_type size_type;
+
+namespace {
+
+// Some constants
+int const MENU_LABEL_SIZE = FL_NORMAL_SIZE;
+int const MENU_LABEL_STYLE = FL_NORMAL_STYLE;
+int const mheight = 30;
+int const mbheight= 22;
+// where to place the menubar?
+int const yloc = (mheight - mbheight)/2; //air + bw;
+int const mbadd = 20; // menu button add (to width)
+// Some space between buttons on the menubar
+int const air = 2;
+char const * menu_tabstop = "aa";
+char const * default_tabstop = "aaaaaaaa";
+// We do not want to mix position values in a menu (like the index of
+// a submenu) with the action numbers which convey actual information.
+// Therefore we offset all the action values by an arbitrary large
+// constant.
+int const action_offset = 1000;
+
+// This is used a few times below.
+inline
+int string_width(string const & str)
+{
+       return fl_get_string_widthTAB(MENU_LABEL_STYLE, MENU_LABEL_SIZE,
+                                     str.c_str(),
+                                     static_cast<int>(str.length()));
+}
+
+} // namespace anon
+
+
+extern "C" {
+
+       //Defined later, used in makeMenubar().
+       static
+       void C_XFormsMenubar_MenuCallback(FL_OBJECT * ob, long button)
+       {
+               XFormsMenubar::MenuCallback(ob, button);
+       }
+
+}
+
+
+XFormsMenubar::XFormsMenubar(LyXView * view, MenuBackend const & mb)
+       : owner_(static_cast<XFormsView*>(view)), menubackend_(&mb)
+{
+       makeMenubar(menubackend_->getMenubar());
+}
+
+
+XFormsMenubar::~XFormsMenubar()
+{}
+
+
+void XFormsMenubar::makeMenubar(Menu const & menu)
+{
+       FL_FORM * form = owner_->getForm();
+       int moffset = 0;
+
+       // Create menu frame if there is non yet.
+       FL_OBJECT * frame = fl_add_frame(FL_UP_FRAME, 0, 0,
+                                        form->w, mheight, "");
+       fl_set_object_resize(frame, FL_RESIZE_ALL);
+       fl_set_object_gravity(frame, NorthWestGravity,
+                             NorthEastGravity);
+
+       Menu::const_iterator i = menu.begin();
+       Menu::const_iterator end = menu.end();
+       for (; i != end; ++i) {
+               FL_OBJECT * obj;
+               if (i->kind() != MenuItem::Submenu) {
+                       lyxerr << "ERROR: XFormsMenubar::createMenubar:"
+                               " only submenus can appear in a menubar"
+                              << endl;
+                       continue;
+               }
+               string const label = i->label();
+               string const shortcut = '#' + i->shortcut();
+               int const width = string_width(label);
+               obj = fl_add_button(FL_MENU_BUTTON,
+                                   air + moffset, yloc,
+                                   width + mbadd,
+                                   mbheight,
+                                   label.c_str());
+               fl_set_object_boxtype(obj, FL_FLAT_BOX);
+               fl_set_object_color(obj, FL_MCOL, FL_MCOL);
+               fl_set_object_lsize(obj, MENU_LABEL_SIZE);
+               fl_set_object_lstyle(obj, MENU_LABEL_STYLE);
+               fl_set_object_resize(obj, FL_RESIZE_ALL);
+               fl_set_object_gravity(obj, NorthWestGravity,
+                                     NorthWestGravity);
+               moffset += obj->w + air;
+               fl_set_object_shortcut(obj, shortcut.c_str(), 1);
+               fl_set_object_callback(obj, C_XFormsMenubar_MenuCallback, 1);
+
+               boost::shared_ptr<ItemInfo>
+                       iteminfo(new ItemInfo(this, new MenuItem(*i), obj));
+               buttonlist_.push_back(iteminfo);
+               obj->u_vdata = iteminfo.get();
+       }
+
+}
+
+
+void XFormsMenubar::update()
+{
+       // nothing yet
+}
+
+
+void XFormsMenubar::openByName(string const & name)
+{
+       for (ButtonList::const_iterator cit = buttonlist_.begin();
+            cit != buttonlist_.end(); ++cit) {
+               if ((*cit)->item_->submenuname() == name) {
+                       MenuCallback((*cit)->obj_, 1);
+                       return;
+               }
+       }
+
+       lyxerr << "XFormsMenubar::openByName: menu "
+              << name << " not found" << endl;
+}
+
+
+namespace {
+
+Menu::size_type const max_number_of_items = 25;
+
+int get_new_submenu(vector<int> & smn, Window win)
+{
+       static size_type max_number_of_menus = 32;
+       if (smn.size() >= max_number_of_menus)
+               max_number_of_menus =
+                   fl_setpup_maxpup(static_cast<int>(2*smn.size()));
+       int menu = fl_newpup(win);
+       fl_setpup_softedge(menu, true);
+       fl_setpup_bw(menu, -1);
+       smn.push_back(menu);
+       return menu;
+}
+
+
+string const fixlabel(string const & str)
+{
+       return subst(str, "%", "%%");
+}
+
+
+
+} // namespace anon
+
+
+
+int XFormsMenubar::create_submenu(Window win, XFormsView * view,
+                                  Menu const & menu, vector<int> & smn)
+{
+       const int menuid = get_new_submenu(smn, win);
+       lyxerr[Debug::GUI] << "XFormsMenubar::create_submenu: creating "
+                          << menu.name() << " as menuid=" << menuid << endl;
+
+       // Compute the size of the largest label (because xforms is
+       // not able to support shortcuts correctly...)
+       int max_width = 0;
+       string widest_label;
+       Menu::const_iterator end = menu.end();
+       for (Menu::const_iterator i = menu.begin(); i != end; ++i) {
+               MenuItem const & item = (*i);
+               if (item.kind() == MenuItem::Command) {
+                       string const label = item.label() + '\t';
+                       int const width = string_width(label);
+                       if (width > max_width) {
+                               max_width = width;
+                               widest_label = label;
+                       }
+               }
+       }
+       lyxerr[Debug::GUI] << "max_width=" << max_width
+                          << ", widest_label=\"" << widest_label
+                          << '"' << endl;
+
+       size_type count = 0;
+       int curmenuid = menuid;
+       for (Menu::const_iterator i = menu.begin(); i != end; ++i) {
+               MenuItem const & item = (*i);
+
+               ++count;
+               // add a More... submenu if the menu is too long (but
+               // not just for one extra entry!)
+               if (count > max_number_of_items && (i+1) != end) {
+                       int tmpmenuid = get_new_submenu(smn, win);
+                       lyxerr[Debug::GUI] << "Too many items, creating "
+                                          << "new menu " << tmpmenuid << endl;
+                       string label = _("More");
+                       label += "...%m";
+                       fl_addtopup(curmenuid, label.c_str(), tmpmenuid);
+                       count = 0;
+                       curmenuid = tmpmenuid;
+               }
+
+               switch (item.kind()) {
+               case MenuItem::Command:
+               case MenuItem::Submenu:
+               {
+                       // Build the menu label from all the info
+                       string label = fixlabel(item.label());
+                       FuncStatus const flag = item.status();
+                       int submenuid = 0;
+
+                       // Is there a key binding?
+                       string const binding = item.binding();
+                       if (!binding.empty()) {
+                               // Try to be clever and add  just enough
+                               // tabs to align shortcuts.
+                               do
+                                       label += '\t';
+                               while (string_width(label) < max_width + 5);
+                               label += binding;
+                       }
+
+                       // Is there a separator after the item?
+                       if ((i+1) != end
+                           && (i + 1)->kind() == MenuItem::Separator)
+                               label += "%l";
+
+                       // Modify the entry using the function status
+                       if (flag.onoff(true))
+                               label += "%B";
+                       if (flag.onoff(false))
+                               label += "%b";
+                       if (flag.disabled())
+                               label += "%i";
+
+                       // Add the shortcut
+                       string shortcut = item.shortcut();
+                       if (!shortcut.empty()) {
+                               shortcut += lowercase(shortcut[0]);
+                               label += "%h";
+                       }
+
+                       // Finally add the action/submenu
+                       if (item.kind() == MenuItem::Submenu) {
+                               // create the submenu
+                               submenuid =
+                                       create_submenu(win, view,
+                                                      *item.submenu(), smn);
+                               if (submenuid == -1)
+                                       return -1;
+                               label += "%x" + tostr(smn.size());
+                               lyxerr[Debug::GUI]
+                                       << "Menu: " << submenuid
+                                       << " (at index " << smn.size()
+                                       << "), ";
+                       } else {
+                               // Add the action
+                               label += "%x" + tostr(item.action()
+                                                     + action_offset);
+                               lyxerr[Debug::GUI] << "Action: \""
+                                                  << item.action() << "\", ";
+                       }
+
+                       // Add everything to the menu
+                       fl_addtopup(curmenuid, label.c_str(),
+                                   shortcut.c_str());
+                       if (item.kind() == MenuItem::Submenu)
+                               fl_setpup_submenu(curmenuid, smn.size(),
+                                                 submenuid);
+
+                       lyxerr[Debug::GUI] << "label \"" << label
+                                          << "\", binding \"" << binding
+                                          << "\", shortcut \"" << shortcut
+                                          << "\" (added to menu "
+                                          << curmenuid << ')' << endl;
+                       break;
+               }
+
+               case MenuItem::Separator:
+                       // already done, and if it was the first one,
+                       // we just ignore it.
+                       --count;
+                       break;
+
+
+               default:
+                       lyxerr << "XFormsMenubar::create_submenu: "
+                               "this should not happen" << endl;
+                       break;
+               }
+       }
+       return menuid;
+}
+
+
+void XFormsMenubar::MenuCallback(FL_OBJECT * ob, long button)
+{
+       ItemInfo * iteminfo = static_cast<ItemInfo *>(ob->u_vdata);
+       XFormsView * view = iteminfo->menubar_->owner_;
+       MenuItem const * item = iteminfo->item_.get();
+
+       if (button == 1) {
+               // set the pseudo menu-button
+               fl_set_object_boxtype(ob, FL_DOWN_BOX);
+               fl_set_button(ob, 0);
+               fl_redraw_object(ob);
+       }
+
+       // Paranoia check
+       Assert(item->kind() == MenuItem::Submenu);
+
+       // set tabstop length
+       fl_set_tabstop(menu_tabstop);
+
+       MenuBackend const * menubackend_ = iteminfo->menubar_->menubackend_;
+       Menu tomenu;
+       Menu const frommenu = menubackend_->getMenu(item->submenuname());
+       menubackend_->expand(frommenu, tomenu, view);
+       vector<int> submenus;
+       int menu = iteminfo->menubar_->create_submenu(FL_ObjWin(ob), view,
+                                                   tomenu, submenus);
+       if (menu != -1) {
+               // place popup
+               fl_setpup_position(view->getForm()->x + ob->x,
+                                  view->getForm()->y + ob->y + ob->h + 10);
+               int choice = fl_dopup(menu);
+
+               if (button == 1) {
+                               // set the pseudo menu-button back
+                       fl_set_object_boxtype(ob, FL_FLAT_BOX);
+                       fl_redraw_object(ob);
+               }
+
+               // If the action value is too low, then it is not a
+               // valid action, but something else.
+               if (choice >= action_offset + 1) {
+                       view->getLyXFunc().dispatch(choice - action_offset, true);
+               } else {
+                       lyxerr[Debug::GUI]
+                               << "MenuCallback: ignoring bogus action "
+                               << choice << endl;
+               }
+       } else {
+               lyxerr << "Error in MenuCallback" << endl;
+       }
+
+       for_each(submenus.begin(), submenus.end(), fl_freepup);
+       // restore tabstop length
+       fl_set_tabstop(default_tabstop);
+
+}
+
+
+XFormsMenubar::ItemInfo::ItemInfo
+       (XFormsMenubar * p, MenuItem const * i, FL_OBJECT * o)
+       : menubar_(p), obj_(o)
+{
+       item_.reset(i);
+}
+
+
+XFormsMenubar::ItemInfo::~ItemInfo()
+{}
diff --git a/src/frontends/xforms/XFormsMenubar.h b/src/frontends/xforms/XFormsMenubar.h
new file mode 100644 (file)
index 0000000..552738b
--- /dev/null
@@ -0,0 +1,85 @@
+// -*- C++ -*-
+/**
+ * \file XFormsMenubar.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#ifndef XFORMSMENUBAR_H
+#define XFORMSMENUBAR_H
+
+#include "LString.h"
+#include "frontends/Menubar.h"
+
+#include <boost/shared_ptr.hpp>
+
+#include "forms_fwd.h"
+#include <X11/X.h> // Window
+
+#include <vector>
+#include <map>
+
+class LyXView;
+class XFormsView;
+class Menu;
+class MenuItem;
+class MenuBackend;
+
+class XFormsMenubar : public Menubar {
+public:
+       ///
+       XFormsMenubar(LyXView *, MenuBackend const &);
+       ///
+       ~XFormsMenubar();
+
+       /// update the state of the menuitems
+       void update();
+
+       /// Opens a top-level submenu given its name
+       void openByName(string const &);
+
+       ///
+       static void MenuCallback(FL_OBJECT *, long);
+
+private:
+       ///
+       void add_toc(int menu, string const & extra_label,
+                    std::vector<int> & smn, Window win);
+       ///
+       void add_references(int menu, string const & extra_label,
+                           std::vector<int> & smn, Window win);
+       ///
+       int create_submenu(Window win, XFormsView * view,
+                          Menu const & menu, std::vector<int> & smn);
+
+       //
+       void makeMenubar(Menu const & menu);
+
+       ///
+       XFormsView * owner_;
+       ///
+       MenuBackend const * menubackend_;
+       ///
+       struct ItemInfo {
+               ///
+               ItemInfo(XFormsMenubar * p, MenuItem const * i,
+                        FL_OBJECT * o);
+               ~ItemInfo();
+               ///
+               XFormsMenubar * menubar_;
+               ///
+               boost::shared_ptr<MenuItem const> item_;
+               ///
+               FL_OBJECT * obj_;
+       };
+
+       ///
+       typedef std::vector<boost::shared_ptr<ItemInfo> > ButtonList;
+       ///
+       ButtonList buttonlist_;
+};
+#endif
index 2c08f12071776a27bf1dd68d260476d6b2ec015b..f2e3ebc30afb35a6f7d178b1acf2e083c65453f8 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file xforms/XFormsToolbar.C
+ * \file XFormsToolbar.C
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
index 89559a60b831eb8ababf9e51a8c7838067b16e20..e8a3f621e95f4614b8ee945caa47e8761ba8c461 100644 (file)
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 /**
- * \file xforms/XFormsToolbar.h
+ * \file XFormsToolbar.h
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
index 948f47f44b50c9c0518bb1734b1bc378199908fb..5608ab0ffed85f2a33307198e9fb478b7e8b80f0 100644 (file)
 #include "lyx_forms.h"
 
 #include "XMiniBuffer.h"
+#include "XFormsMenubar.h"
 #include "XFormsToolbar.h"
 #include "debug.h"
 #include "intl.h"
 #include "lyxrc.h"
 #include "support/filetools.h"        // OnlyFilename()
-#include "frontends/Menubar.h"
 #include "frontends/Timeout.h"
 #include "frontends/Dialogs.h"
 #include "MenuBackend.h"
@@ -140,7 +140,7 @@ void XFormsView::create_form_form_main(int width, int height)
        int const air = 2;
        int const bw = abs(fl_get_border_width());
 
-       menubar_.reset(new Menubar(this, menubackend));
+       menubar_.reset(new XFormsMenubar(this, menubackend));
 
        toolbar_.reset(new XFormsToolbar(this, air, 30 + air + bw));
        toolbar_->init();