diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-10-13 11:56:25 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-10-13 12:00:29 +0100 |
commit | 96d0aa8ca4f841fd5217b863b976c81959e4aca9 (patch) | |
tree | 26a54e683e0d5d7ed9f3883397e3d9bb5d85076e /vcl | |
parent | 0f613adbfa44fb92e84e73a3fa7ea050c072944c (diff) |
Resolves: tdf#103166 if the menu is empty, add a disabled placeholder
i.e. <No Selection Possible>
otherwise it looks like a bug of some kind.
Change-Id: Ib35146698c31fd3f3d51915ea460eab1dde39d26
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/unx/gtk/gtksalmenu.cxx | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx index 041e9c22f50b..fa52fc9a8097 100644 --- a/vcl/unx/gtk/gtksalmenu.cxx +++ b/vcl/unx/gtk/gtksalmenu.cxx @@ -30,14 +30,20 @@ static bool bUnityMode = false; /* * This function generates a unique command name for each menu item */ -static gchar* GetCommandForItem(GtkSalMenuItem* pSalMenuItem) +static gchar* GetCommandForItem(GtkSalMenu* pParentMenu, sal_uInt16 nItemId) { OString aCommand("window-"); - aCommand = aCommand + OString::number(reinterpret_cast<unsigned long>(pSalMenuItem->mpParentMenu)); - aCommand = aCommand + "-" + OString::number(pSalMenuItem->mnId); + aCommand = aCommand + OString::number(reinterpret_cast<unsigned long>(pParentMenu)); + aCommand = aCommand + "-" + OString::number(nItemId); return g_strdup(aCommand.getStr()); } +static gchar* GetCommandForItem(GtkSalMenuItem* pSalMenuItem) +{ + return GetCommandForItem(pSalMenuItem->mpParentMenu, + pSalMenuItem->mnId); +} + bool GtkSalMenu::PrepUpdate() { #if GTK_CHECK_VERSION(3,0,0) @@ -308,6 +314,27 @@ void GtkSalMenu::ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries) // Delete unused commands. RemoveUnusedCommands( pActionGroup, pOldCommandList, pNewCommandList ); + + // Resolves: tdf#103166 if the menu is empty, add a disabled + // <No Selection Possible> placeholder. + sal_Int32 nSectionsCount = g_menu_model_get_n_items(G_MENU_MODEL(pLOMenu)); + gint nItemsCount = 0; + for (nSection = 0; nSection < nSectionsCount; ++nSection) + { + nItemsCount += g_lo_menu_get_n_items_from_section(pLOMenu, nSection); + if (nItemsCount) + break; + } + if (!nItemsCount) + { + gchar* aNativeCommand = GetCommandForItem(this, 0xFFFF); + OUString aPlaceholderText(VclResId(SV_RESID_STRING_NOSELECTIONPOSSIBLE)); + g_lo_menu_insert_in_section(pLOMenu, nSection-1, 0, + OUStringToOString(aPlaceholderText, RTL_TEXTENCODING_UTF8).getStr()); + NativeSetItemCommand(nSection-1, 0, 0xFFFF, aNativeCommand, MenuItemBits::NONE, false, false); + NativeSetEnableItem(aNativeCommand, false); + g_free(aNativeCommand); + } } void GtkSalMenu::Update() |