summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2013-01-07 12:04:04 +0000
committerCaolán McNamara <caolanm@redhat.com>2013-01-07 16:17:52 +0000
commit6773db03a657413a24b87e9ef3a6c68020936e0e (patch)
tree9944195abaf8ce6b344a172edae69d14bf1b0ffb /vcl
parentb2a106249f1624a61a9453bf50f1a17d75ea1825 (diff)
allow menu items to be referred to by a name
Change-Id: I8bb1c082e3948f919232b81e0f1f869b88fcd852
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/vcl/menu.hxx9
-rw-r--r--vcl/source/window/builder.cxx4
-rw-r--r--vcl/source/window/menu.cxx74
3 files changed, 55 insertions, 32 deletions
diff --git a/vcl/inc/vcl/menu.hxx b/vcl/inc/vcl/menu.hxx
index 9bd5c0b37388..ebf8e49ff747 100644
--- a/vcl/inc/vcl/menu.hxx
+++ b/vcl/inc/vcl/menu.hxx
@@ -212,16 +212,20 @@ public:
void InsertItem( sal_uInt16 nItemId, const XubString& rStr,
MenuItemBits nItemBits = 0,
+ const OString &rIdent = OString(),
sal_uInt16 nPos = MENU_APPEND );
void InsertItem( sal_uInt16 nItemId, const Image& rImage,
MenuItemBits nItemBits = 0,
+ const OString &rIdent = OString(),
sal_uInt16 nPos = MENU_APPEND );
void InsertItem( sal_uInt16 nItemId,
const XubString& rString, const Image& rImage,
MenuItemBits nItemBits = 0,
+ const OString &rIdent = OString(),
sal_uInt16 nPos = MENU_APPEND );
void InsertItem( const ResId& rResId, sal_uInt16 nPos = MENU_APPEND );
- void InsertSeparator( sal_uInt16 nPos = MENU_APPEND );
+ void InsertSeparator( const OString &rIdent = OString(),
+ sal_uInt16 nPos = MENU_APPEND );
void RemoveItem( sal_uInt16 nPos );
void CopyItem( const Menu& rMenu, sal_uInt16 nPos,
sal_uInt16 nNewPos = MENU_APPEND );
@@ -233,7 +237,8 @@ public:
sal_uInt16 GetMenuFlags() const { return nMenuFlags; }
sal_uInt16 GetItemCount() const;
- sal_uInt16 GetItemId( sal_uInt16 nPos ) const;
+ sal_uInt16 GetItemId(sal_uInt16 nPos) const;
+ sal_uInt16 GetItemId(const OString &rIdent) const;
sal_uInt16 GetItemPos( sal_uInt16 nItemId ) const;
MenuItemType GetItemType( sal_uInt16 nPos ) const;
sal_uInt16 GetCurItemId() const;
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index b18062583cad..d9defdfc932f 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -1690,11 +1690,11 @@ void VclBuilder::insertMenuObject(PopupMenu *pParent, const OString &rClass, con
if (rClass == "GtkMenuItem")
{
OUString sLabel(OStringToOUString(convertMnemonicMarkup(extractLabel(rProps)), RTL_TEXTENCODING_UTF8));
- pParent->InsertItem(nNewId, sLabel, MIB_TEXT);
+ pParent->InsertItem(nNewId, sLabel, MIB_TEXT, rID);
}
else if (rClass == "GtkSeparatorMenuItem")
{
- pParent->InsertSeparator();
+ pParent->InsertSeparator(rID);
}
SAL_WARN_IF(nOldCount == pParent->GetItemCount(), "vcl.layout", "probably need to implement " << rClass.getStr());
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 5fe08d186b06..d2d6adf89b20 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -109,7 +109,7 @@ static sal_Bool ImplAccelDisabled()
struct MenuItemData
{
- sal_uInt16 nId; // SV Id
+ sal_uInt16 nId; // SV Id
MenuItemType eType; // MenuItem-Type
MenuItemBits nBits; // MenuItem-Bits
Menu* pSubMenu; // Pointer to SubMenu
@@ -119,7 +119,8 @@ struct MenuItemData
XubString aTipHelpText; // TipHelp-String (eg, expanded filenames)
XubString aCommandStr; // CommandString
XubString aHelpCommandStr; // Help command string (to reference external help)
- rtl::OString aHelpId; // Help-Id
+ OString sIdent;
+ OString aHelpId; // Help-Id
sal_uLong nUserValue; // User value
Image aImage; // Image
KeyCode aAccelKey; // Accelerator-Key
@@ -181,9 +182,10 @@ public:
const XubString& rStr,
const Image& rImage,
Menu* pMenu,
- size_t nPos
+ size_t nPos,
+ const OString &rIdent
);
- void InsertSeparator( size_t nPos );
+ void InsertSeparator(const OString &rIdent, size_t nPos);
void Remove( size_t nPos );
@@ -228,11 +230,13 @@ MenuItemData* MenuItemList::Insert(
const XubString& rStr,
const Image& rImage,
Menu* pMenu,
- size_t nPos
+ size_t nPos,
+ const OString &rIdent
)
{
MenuItemData* pData = new MenuItemData( rStr, rImage );
pData->nId = nId;
+ pData->sIdent = rIdent;
pData->eType = eType;
pData->nBits = nBits;
pData->pSubMenu = NULL;
@@ -264,10 +268,11 @@ MenuItemData* MenuItemList::Insert(
return pData;
}
-void MenuItemList::InsertSeparator( size_t nPos )
+void MenuItemList::InsertSeparator(const OString &rIdent, size_t nPos)
{
MenuItemData* pData = new MenuItemData;
pData->nId = 0;
+ pData->sIdent = rIdent;
pData->eType = MENUITEM_SEPARATOR;
pData->nBits = 0;
pData->pSubMenu = NULL;
@@ -1194,7 +1199,8 @@ void Menu::RemoveEventListener( const Link& rEventListener )
maEventListeners.removeListener( rEventListener );
}
-void Menu::InsertItem( sal_uInt16 nItemId, const XubString& rStr, MenuItemBits nItemBits, sal_uInt16 nPos )
+void Menu::InsertItem(sal_uInt16 nItemId, const XubString& rStr, MenuItemBits nItemBits,
+ const OString &rIdent, sal_uInt16 nPos)
{
DBG_ASSERT( nItemId, "Menu::InsertItem(): ItemId == 0" );
DBG_ASSERT( GetItemPos( nItemId ) == MENU_ITEM_NOTFOUND,
@@ -1205,8 +1211,8 @@ void Menu::InsertItem( sal_uInt16 nItemId, const XubString& rStr, MenuItemBits n
nPos = MENU_APPEND;
// put Item in MenuItemList
- MenuItemData* pData = pItemList->Insert( nItemId, MENUITEM_STRING,
- nItemBits, rStr, Image(), this, nPos );
+ MenuItemData* pData = pItemList->Insert(nItemId, MENUITEM_STRING,
+ nItemBits, rStr, Image(), this, nPos, rIdent);
// update native menu
if( ImplGetSalMenu() && pData->pSalMenuItem )
@@ -1223,18 +1229,18 @@ void Menu::InsertItem( sal_uInt16 nItemId, const XubString& rStr, MenuItemBits n
ImplCallEventListeners( VCLEVENT_MENU_INSERTITEM, nPos );
}
-void Menu::InsertItem( sal_uInt16 nItemId, const Image& rImage,
- MenuItemBits nItemBits, sal_uInt16 nPos )
+void Menu::InsertItem(sal_uInt16 nItemId, const Image& rImage,
+ MenuItemBits nItemBits, const OString &rIdent, sal_uInt16 nPos)
{
- InsertItem( nItemId, ImplGetSVEmptyStr(), nItemBits, nPos );
+ InsertItem(nItemId, ImplGetSVEmptyStr(), nItemBits, rIdent, nPos);
SetItemImage( nItemId, rImage );
}
-void Menu::InsertItem( sal_uInt16 nItemId,
- const XubString& rStr, const Image& rImage,
- MenuItemBits nItemBits, sal_uInt16 nPos )
+void Menu::InsertItem(sal_uInt16 nItemId, const XubString& rStr,
+ const Image& rImage, MenuItemBits nItemBits,
+ const OString &rIdent, sal_uInt16 nPos)
{
- InsertItem( nItemId, rStr, nItemBits, nPos );
+ InsertItem(nItemId, rStr, nItemBits, rIdent, nPos);
SetItemImage( nItemId, rImage );
}
@@ -1272,16 +1278,16 @@ void Menu::InsertItem( const ResId& rResId, sal_uInt16 nPos )
{
Bitmap aBmp( ResId( (RSHEADER_TYPE*)GetClassRes(), *pMgr ) );
if ( aText.Len() )
- InsertItem( nItemId, aText, aBmp, nStatus, nPos );
+ InsertItem( nItemId, aText, aBmp, nStatus, OString(), nPos );
else
- InsertItem( nItemId, aBmp, nStatus, nPos );
+ InsertItem( nItemId, aBmp, nStatus, OString(), nPos );
}
IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
}
else if ( !bSep )
- InsertItem( nItemId, aText, nStatus, nPos );
+ InsertItem(nItemId, aText, nStatus, OString(), nPos);
if ( bSep )
- InsertSeparator( nPos );
+ InsertSeparator(OString(), nPos);
String aHelpText;
if ( nObjMask & RSC_MENUITEM_HELPTEXT )
@@ -1342,7 +1348,7 @@ void Menu::InsertItem( const ResId& rResId, sal_uInt16 nPos )
delete mpLayoutData, mpLayoutData = NULL;
}
-void Menu::InsertSeparator( sal_uInt16 nPos )
+void Menu::InsertSeparator(const OString &rIdent, sal_uInt16 nPos)
{
// do nothing if its a menu bar
if ( bIsMenuBar )
@@ -1353,7 +1359,7 @@ void Menu::InsertSeparator( sal_uInt16 nPos )
nPos = MENU_APPEND;
// put separator in item list
- pItemList->InsertSeparator( nPos );
+ pItemList->InsertSeparator(rIdent, nPos);
// update native menu
size_t itemPos = ( nPos != MENU_APPEND ) ? nPos : pItemList->size() - 1;
@@ -1402,7 +1408,7 @@ void ImplCopyItem( Menu* pThis, const Menu& rMenu, sal_uInt16 nPos, sal_uInt16 n
return;
if ( eType == MENUITEM_SEPARATOR )
- pThis->InsertSeparator( nNewPos );
+ pThis->InsertSeparator( OString(), nNewPos );
else
{
sal_uInt16 nId = rMenu.GetItemId( nPos );
@@ -1413,11 +1419,11 @@ void ImplCopyItem( Menu* pThis, const Menu& rMenu, sal_uInt16 nPos, sal_uInt16 n
MenuItemData* pData = rMenu.GetItemList()->GetData( nId );
if ( eType == MENUITEM_STRINGIMAGE )
- pThis->InsertItem( nId, pData->aText, pData->aImage, pData->nBits, nNewPos );
+ pThis->InsertItem( nId, pData->aText, pData->aImage, pData->nBits, pData->sIdent, nNewPos );
else if ( eType == MENUITEM_STRING )
- pThis->InsertItem( nId, pData->aText, pData->nBits, nNewPos );
+ pThis->InsertItem( nId, pData->aText, pData->nBits, pData->sIdent, nNewPos );
else
- pThis->InsertItem( nId, pData->aImage, pData->nBits, nNewPos );
+ pThis->InsertItem( nId, pData->aImage, pData->nBits, pData->sIdent, nNewPos );
if ( rMenu.IsItemChecked( nId ) )
pThis->CheckItem( nId, sal_True );
@@ -1501,7 +1507,7 @@ sal_uInt16 Menu::ImplGetNextVisible( sal_uInt16 nPos ) const
return ITEMPOS_INVALID;
}
-sal_uInt16 Menu::GetItemId( sal_uInt16 nPos ) const
+sal_uInt16 Menu::GetItemId(sal_uInt16 nPos) const
{
MenuItemData* pData = pItemList->GetDataFromPos( nPos );
@@ -1511,6 +1517,18 @@ sal_uInt16 Menu::GetItemId( sal_uInt16 nPos ) const
return 0;
}
+sal_uInt16 Menu::GetItemId(const OString &rIdent) const
+{
+ for (size_t n = 0; n < pItemList->size(); ++n)
+ {
+ MenuItemData* pData = pItemList->GetDataFromPos(n);
+ if (pData && pData->sIdent == rIdent)
+ return pData->nId;
+ }
+ return MENU_ITEM_NOTFOUND;
+}
+
+
sal_uInt16 Menu::GetItemPos( sal_uInt16 nItemId ) const
{
size_t nPos;
@@ -3647,7 +3665,7 @@ sal_uInt16 PopupMenu::ImplExecute( Window* pW, const Rectangle& rRect, sal_uLong
{
rtl::OUString aTmpEntryText( ResId( SV_RESID_STRING_NOSELECTIONPOSSIBLE, *pResMgr ) );
MenuItemData* pData = pItemList->Insert(
- 0xFFFF, MENUITEM_STRING, 0, aTmpEntryText, Image(), NULL, 0xFFFF );
+ 0xFFFF, MENUITEM_STRING, 0, aTmpEntryText, Image(), NULL, 0xFFFF, OString() );
pData->bIsTemporary = sal_True;
}
}