diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-10-04 11:19:15 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-10-04 12:49:27 +0100 |
commit | c5850f4b25d2b735ea59bb0ac8c2bc58527ac17e (patch) | |
tree | 8cce2ea35512412d95c38e1cba931bce00dfb505 /vcl/source | |
parent | d3b7a3acb481ef530094296eb4461dd343270879 (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
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/control/menubtn.cxx | 77 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 34 |
2 files changed, 101 insertions, 10 deletions
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"))) { |