Attached is a small patch to Wt::WMenu that lets you change the horizontal separator between menu items.

  Wt::WStackedWidget *stack_ = new Wt::WStackedWidget(parent);

  Wt::WMenu *menu = new Wt::WMenu(stack_, Wt::Horizontal, parent);
  menu->setItemHSeparator(" - ");
  menu->addItem("item1", new WText("item1 page", content));
  menu->addItem("item2", new WText("item2 page", content), false);

This will output: item1 - item2

That said, I'm not very happy about adding the 4th argument to addItem:

  WMenuItem *addItem(const WString& name, WWidget *contents,
WMenuItem::LoadPolicy policy = WMenuItem::LazyLoading,
                     bool includeSeparator = true);
  WMenuItem *addItem(WMenuItem *item, bool includeSeparator = true);

But felt it was the best way to handle the rendering of the WMenu since its rendering isn't handled at a later point. -sc


diff --git a/src/Wt/WMenu b/src/Wt/WMenu
index 5e3c8f1..785f919 100644
--- a/src/Wt/WMenu
+++ b/src/Wt/WMenu
@@ -135,16 +135,18 @@ public:
    * \sa addItem(WMenuItem *)
    */
   WMenuItem *addItem(const WString& name, WWidget *contents,
-                    WMenuItem::LoadPolicy policy = WMenuItem::LazyLoading);
+                    WMenuItem::LoadPolicy policy = WMenuItem::LazyLoading,
+                    bool includeSeparator = true);
 
   /*! \brief Add an item.
    *
    * Adds a menu item. Use this form to add specialized WMenuItem
-   * implementations.
+   * implementations.  If lastItem is true and this menu is
+   * horizontal, a separator will not be appended to the menu item.
    *
    * \sa addItem(const WString&, WWidget *, WMenuItem::LoadPolicy)
    */
-  WMenuItem *addItem(WMenuItem *item);
+  WMenuItem *addItem(WMenuItem *item, bool includeSeparator = true);
 
   /*! \brief Remove an item.
    *
@@ -197,6 +199,20 @@ public:
    */
   Signal<WMenuItem *>& itemSelectRendered() { return itemSelectRendered_; }
 
+  /*! \brief Returns the Horizontal separator for menu items in this menu
+   *
+   * The default separator is " ".
+   *
+   * \sa setItemHSeparator
+   */
+  const std::string& itemHSeparator() const { return itemHSeparator_; }
+
+  /*! \brief Set the horizontal separator for menu items in this menu
+   *
+   * \sa itemHSeparator
+   */
+  void setItemHSeparator(const std::string& itemHSep) { itemHSeparator_ = 
itemHSep; }
+
   /*! \brief Returns the items.
    *
    * Returns the list of menu items in this menu.
@@ -297,7 +313,7 @@ private:
   Orientation       orientation_;
   bool              renderAsList_;
   bool              internalPathEnabled_;
-  std::string       basePath_, previousInternalPath_;
+  std::string       basePath_, previousInternalPath_, itemHSeparator_;
 
   Signal<WMenuItem *> itemSelected_, itemSelectRendered_;
 
diff --git a/src/Wt/WMenu.C b/src/Wt/WMenu.C
index 8222775..7eecaf4 100644
--- a/src/Wt/WMenu.C
+++ b/src/Wt/WMenu.C
@@ -26,6 +26,7 @@ WMenu::WMenu(WStackedWidget *contentsStack, Orientation 
orientation,
     contentsStack_(contentsStack),
     orientation_(orientation),
     internalPathEnabled_(false),
+    itemHSeparator_(" "),
     itemSelected_(this),
     itemSelectRendered_(this),
     current_(-1)
@@ -91,12 +92,13 @@ void WMenu::updateItems()
 }
 
 WMenuItem *WMenu::addItem(const WString& name, WWidget *contents,
-                         WMenuItem::LoadPolicy policy)
+                         WMenuItem::LoadPolicy policy,
+                         bool includeSeparator)
 {
   return addItem(new WMenuItem(name, contents, policy));
 }
 
-WMenuItem *WMenu::addItem(WMenuItem *item)
+  WMenuItem *WMenu::addItem(WMenuItem *item, bool includeSeparator)
 {
   item->setMenu(this);
   items_.push_back(item);
@@ -116,7 +118,8 @@ WMenuItem *WMenu::addItem(WMenuItem *item)
     // separate horizontal items so wrapping will occur inbetween items.
     if (orientation_ == Horizontal) {
       w->setInline(true);
-      new WText(" ", parent);
+      if (!includeSeparator)
+       new WText(itemHSeparator_, parent);
     }
   }
 


--
Sean Chittenden
[email protected]



------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to