summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-10-04 11:19:15 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-10-04 12:49:27 +0100
commitc5850f4b25d2b735ea59bb0ac8c2bc58527ac17e (patch)
tree8cce2ea35512412d95c38e1cba931bce00dfb505
parentd3b7a3acb481ef530094296eb4461dd343270879 (diff)
Use MenuButton for non-editable GtkComboBoxText instead of ComboBox
its more similar for the non-editable list. Requires some love to MenuButton to reflect the selected entry and resize appropiately Change-Id: I4b37931e35a5f326d6fd4e445eb741bece6b55a6
-rw-r--r--sw/uiconfig/swriter/ui/charurlpage.ui34
-rw-r--r--vcl/inc/vcl/menu.hxx1
-rw-r--r--vcl/inc/vcl/menubtn.hxx17
-rw-r--r--vcl/source/control/menubtn.cxx77
-rw-r--r--vcl/source/window/builder.cxx34
5 files changed, 137 insertions, 26 deletions
diff --git a/sw/uiconfig/swriter/ui/charurlpage.ui b/sw/uiconfig/swriter/ui/charurlpage.ui
index 81534e38a636..794212a93bfd 100644
--- a/sw/uiconfig/swriter/ui/charurlpage.ui
+++ b/sw/uiconfig/swriter/ui/charurlpage.ui
@@ -96,20 +96,6 @@
</packing>
</child>
<child>
- <object class="GtkComboBoxText" id="targetfrmlb">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="entry_text_column">0</property>
- <property name="id_column">1</property>
- </object>
- <packing>
- <property name="left_attach">1</property>
- <property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
- </packing>
- </child>
- <child>
<object class="GtkEntry" id="urled">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -183,6 +169,26 @@
<child>
<placeholder/>
</child>
+ <child>
+ <object class="GtkComboBoxText" id="targetfrmlb">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="has_entry">True</property>
+ <property name="entry_text_column">0</property>
+ <property name="id_column">1</property>
+ <child internal-child="entry">
+ <object class="GtkEntry" id="comboboxtext-entry">
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">3</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/vcl/inc/vcl/menu.hxx b/vcl/inc/vcl/menu.hxx
index cd931c74fa61..e908119a96ae 100644
--- a/vcl/inc/vcl/menu.hxx
+++ b/vcl/inc/vcl/menu.hxx
@@ -126,6 +126,7 @@ class VCL_DLLPUBLIC Menu : public Resource
{
friend class MenuBar;
friend class MenuBarWindow;
+ friend class MenuButton;
friend class MenuFloatingWindow;
friend class PopupMenu;
friend class SystemWindow;
diff --git a/vcl/inc/vcl/menubtn.hxx b/vcl/inc/vcl/menubtn.hxx
index c9906c9dd162..02e2f5dd7edd 100644
--- a/vcl/inc/vcl/menubtn.hxx
+++ b/vcl/inc/vcl/menubtn.hxx
@@ -35,6 +35,8 @@
class Timer;
class PopupMenu;
+class VclBuilder;
+class VclSimpleEvent;
// --------------------
// - MenuButton-Types -
@@ -49,12 +51,15 @@ class PopupMenu;
class VCL_DLLPUBLIC MenuButton : public PushButton
{
private:
+ friend class VclBuilder;
+
Rectangle maFocusRect;
Timer* mpMenuTimer;
PopupMenu* mpOwnMenu;
PopupMenu* mpMenu;
- sal_uInt16 mnCurItemId;
- sal_uInt16 mnMenuMode;
+ sal_uInt16 mnCurItemId;
+ sal_uInt16 mnMenuMode;
+ bool mbDisplaySelectedItem;
Link maActivateHdl;
Link maSelectHdl;
@@ -62,10 +67,14 @@ private:
SAL_DLLPRIVATE void ImplExecuteMenu();
DECL_DLLPRIVATE_LINK( ImplMenuTimeoutHdl, void* );
+ SAL_DLLPRIVATE void updateText();
+
// Copy assignment is forbidden and not implemented.
SAL_DLLPRIVATE MenuButton( const MenuButton & );
SAL_DLLPRIVATE MenuButton& operator=( const MenuButton & );
+ DECL_LINK(MenuEventListener, VclSimpleEvent*);
+
protected:
using Window::ImplInit;
SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
@@ -95,6 +104,10 @@ public:
const Link& GetActivateHdl() const { return maActivateHdl; }
void SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; }
const Link& GetSelectHdl() const { return maSelectHdl; }
+
+ void SetShowDisplaySelectedItem(bool bShow);
+
+ virtual Size GetOptimalSize(WindowSizeType eType) const;
};
#endif // _SV_MENUBTN_HXX
diff --git a/vcl/source/control/menubtn.cxx b/vcl/source/control/menubtn.cxx
index acc7e9ad4d2b..2d40192f69e3 100644
--- a/vcl/source/control/menubtn.cxx
+++ b/vcl/source/control/menubtn.cxx
@@ -84,8 +84,9 @@ void MenuButton::ImplExecuteMenu()
// -----------------------------------------------------------------------
-MenuButton::MenuButton( Window* pParent, WinBits nWinBits ) :
- PushButton( WINDOW_MENUBUTTON )
+MenuButton::MenuButton( Window* pParent, WinBits nWinBits )
+ : PushButton( WINDOW_MENUBUTTON )
+ , mbDisplaySelectedItem(false)
{
ImplInitMenuButtonData();
ImplInit( pParent, nWinBits );
@@ -93,8 +94,9 @@ MenuButton::MenuButton( Window* pParent, WinBits nWinBits ) :
// -----------------------------------------------------------------------
-MenuButton::MenuButton( Window* pParent, const ResId& rResId ) :
- PushButton( WINDOW_MENUBUTTON )
+MenuButton::MenuButton( Window* pParent, const ResId& rResId )
+ : PushButton( WINDOW_MENUBUTTON )
+ , mbDisplaySelectedItem(false)
{
ImplInitMenuButtonData();
rResId.SetRT( RSC_MENUBUTTON );
@@ -127,6 +129,8 @@ void MenuButton::ImplLoadRes( const ResId& rResId )
MenuButton::~MenuButton()
{
delete mpMenuTimer;
+ if (mbDisplaySelectedItem && mpMenu)
+ mpMenu->RemoveEventListener(LINK(this, MenuButton, MenuEventListener));
delete mpOwnMenu;
}
@@ -208,9 +212,33 @@ void MenuButton::Activate()
void MenuButton::Select()
{
+ updateText();
maSelectHdl.Call( this );
}
+void MenuButton::updateText()
+{
+ if (mbDisplaySelectedItem)
+ {
+ if (mpMenu)
+ SetText(mpMenu->GetItemText(mpMenu->GetCurItemId()));
+ else
+ SetText(OUString());
+ }
+}
+
+Size MenuButton::GetOptimalSize(WindowSizeType eType) const
+{
+ Size aRet = PushButton::GetOptimalSize(eType);
+ if (mbDisplaySelectedItem && mpMenu)
+ {
+ Size aMenuSize(mpMenu->ImplCalcSize(const_cast<MenuButton*>(this)));
+ if (aMenuSize.Width() > aRet.Width())
+ aRet.Width() = aMenuSize.Width();
+ }
+ return aRet;
+}
+
// -----------------------------------------------------------------------
void MenuButton::SetMenuMode( sal_uInt16 nMode )
@@ -220,13 +248,52 @@ void MenuButton::SetMenuMode( sal_uInt16 nMode )
mnMenuMode = nMode;
}
-// -----------------------------------------------------------------------
+void MenuButton::SetShowDisplaySelectedItem(bool bShow)
+{
+ if (mbDisplaySelectedItem == bShow)
+ return;
+ if (mbDisplaySelectedItem && mpMenu)
+ mpMenu->RemoveEventListener(LINK(this, MenuButton, MenuEventListener));
+ mbDisplaySelectedItem = bShow;
+ if (mbDisplaySelectedItem && mpMenu)
+ mpMenu->AddEventListener(LINK(this, MenuButton, MenuEventListener));
+}
void MenuButton::SetPopupMenu( PopupMenu* pNewMenu )
{
+ if (pNewMenu == mpMenu)
+ return;
+ if (mbDisplaySelectedItem && mpMenu)
+ mpMenu->RemoveEventListener(LINK(this, MenuButton, MenuEventListener));
// Fuer die 5.1-Auslieferung besser noch nicht inline, ansonsten kann
// diese Funktion zur 6.0 inline werden
mpMenu = pNewMenu;
+ updateText();
+ if (mbDisplaySelectedItem && mpMenu)
+ mpMenu->AddEventListener(LINK(this, MenuButton, MenuEventListener));
+}
+
+IMPL_LINK(MenuButton, MenuEventListener, VclSimpleEvent*, pEvent)
+{
+ if (pEvent && pEvent->ISA(VclMenuEvent))
+ {
+ VclMenuEvent* pMenuEvent = (VclMenuEvent*)pEvent;
+ if (pMenuEvent->GetMenu() == mpMenu)
+ {
+ switch (pMenuEvent->GetId())
+ {
+ case VCLEVENT_MENU_INSERTITEM:
+ case VCLEVENT_MENU_REMOVEITEM:
+ case VCLEVENT_MENU_ITEMTEXTCHANGED:
+ queue_resize();
+ break;
+ case VCLEVENT_MENU_SELECT:
+ updateText();
+ break;
+ }
+ }
+ }
+ return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 63fce3934281..3ef828965363 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -17,6 +17,7 @@
#include <vcl/fixed.hxx>
#include <vcl/layout.hxx>
#include <vcl/lstbox.hxx>
+#include <vcl/menubtn.hxx>
#include <vcl/svapp.hxx>
#include <vcl/tabctrl.hxx>
#include <vcl/tabpage.hxx>
@@ -242,7 +243,7 @@ namespace
bool extractResizable(VclBuilder::stringmap &rMap)
{
bool bResizable = true;
- VclBuilder::stringmap::iterator aFind = rMap.find(OString(RTL_CONSTASCII_STRINGPARAM("resizable")));
+ VclBuilder::stringmap::iterator aFind = rMap.find(OString("resizable"));
if (aFind != rMap.end())
{
bResizable = toBool(aFind->second);
@@ -251,10 +252,22 @@ namespace
return bResizable;
}
+ bool extractEntry(VclBuilder::stringmap &rMap)
+ {
+ bool bHasEntry = false;
+ VclBuilder::stringmap::iterator aFind = rMap.find(OString("has-entry"));
+ if (aFind != rMap.end())
+ {
+ bHasEntry = toBool(aFind->second);
+ rMap.erase(aFind);
+ }
+ return bHasEntry;
+ }
+
bool extractOrientation(VclBuilder::stringmap &rMap)
{
bool bVertical = false;
- VclBuilder::stringmap::iterator aFind = rMap.find(OString(RTL_CONSTASCII_STRINGPARAM("orientation")));
+ VclBuilder::stringmap::iterator aFind = rMap.find(OString("orientation"));
if (aFind != rMap.end())
{
bVertical = aFind->second.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("vertical"));
@@ -597,9 +610,20 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri
else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkComboBoxText")))
{
extractModel(id, rMap);
- ComboBox* pComboBox = new ComboBox(pParent, WB_LEFT|WB_DROPDOWN|WB_VCENTER|WB_3DLOOK);
- pComboBox->SetBestDropDownLineCount();
- pWindow = pComboBox;
+ if (extractEntry(rMap))
+ {
+ ComboBox* pComboBox = new ComboBox(pParent, WB_LEFT|WB_DROPDOWN|WB_VCENTER|WB_3DLOOK);
+ pComboBox->SetBestDropDownLineCount();
+ pWindow = pComboBox;
+ }
+ else
+ {
+ MenuButton *pMenuButton = new MenuButton(pParent, WB_LEFT|WB_VCENTER|WB_3DLOOK);
+ pMenuButton->mpOwnMenu = new PopupMenu; //this now belongs to the menubutton
+ pMenuButton->SetPopupMenu(pMenuButton->mpOwnMenu);
+ pMenuButton->SetShowDisplaySelectedItem(true);
+ pWindow = pMenuButton;
+ }
}
else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkTreeView")))
{