diff --git a/CefSharp.Core/Internals/CefMenuModelWrapper.h b/CefSharp.Core/Internals/CefMenuModelWrapper.h index f7c192bb1..71eb6cb3a 100644 --- a/CefSharp.Core/Internals/CefMenuModelWrapper.h +++ b/CefSharp.Core/Internals/CefMenuModelWrapper.h @@ -89,6 +89,352 @@ namespace CefSharp return _menu->AddItem((int)commandId, StringUtils::ToNative(label)); } + + virtual bool AddCheckItem(CefMenuCommand commandId, String^ label) + { + ThrowIfDisposed(); + + return _menu->AddCheckItem((int)commandId, StringUtils::ToNative(label)); + } + + virtual bool AddRadioItem(CefMenuCommand commandId, String^ label, int groupId) + { + ThrowIfDisposed(); + + return _menu->AddRadioItem((int)commandId, StringUtils::ToNative(label), groupId); + } + + virtual IMenuModel^ AddSubMenu(CefMenuCommand commandId, String^ label) + { + ThrowIfDisposed(); + + auto subMenu =_menu->AddSubMenu((int)commandId, StringUtils::ToNative(label)); + + if (subMenu.get()) + { + return gcnew CefMenuModelWrapper(subMenu); + } + + return nullptr; + } + + virtual bool InsertSeparatorAt(int index) + { + ThrowIfDisposed(); + + return _menu->InsertSeparatorAt(index); + } + + virtual bool InsertItemAt(int index, CefMenuCommand commandId, String^ label) + { + ThrowIfDisposed(); + + return _menu->InsertItemAt(index, (int)commandId, StringUtils::ToNative(label)); + } + + virtual bool InsertCheckItemAt(int index, CefMenuCommand commandId, String^ label) + { + ThrowIfDisposed(); + + return _menu->InsertCheckItemAt(index, (int)commandId, StringUtils::ToNative(label)); + } + + virtual bool InsertRadioItemAt(int index, CefMenuCommand commandId, String^ label, int groupId) + { + ThrowIfDisposed(); + + return _menu->InsertRadioItemAt(index, (int)commandId, StringUtils::ToNative(label), groupId); + } + + virtual IMenuModel^ InsertSubMenuAt(int index, CefMenuCommand commandId, String^ label) + { + ThrowIfDisposed(); + + auto subMenu = _menu->InsertSubMenuAt(index, (int)commandId, StringUtils::ToNative(label)); + + if (subMenu.get()) + { + return gcnew CefMenuModelWrapper(subMenu); + } + + return nullptr; + } + + virtual bool RemoveAt(int index) + { + ThrowIfDisposed(); + + return _menu->RemoveAt(index); + } + + virtual int GetIndexOf(CefMenuCommand commandId) + { + ThrowIfDisposed(); + + return _menu->GetIndexOf((int)commandId); + } + + virtual bool SetCommandIdAt(int index, CefMenuCommand commandId) + { + ThrowIfDisposed(); + + return _menu->SetCommandIdAt(index, (int)commandId); + } + + virtual String^ GetLabel(CefMenuCommand commandId) + { + ThrowIfDisposed(); + + return StringUtils::ToClr(_menu->GetLabel((int)commandId)); + } + + virtual bool SetLabel(CefMenuCommand commandId, String^ label) + { + ThrowIfDisposed(); + + return _menu->SetLabel((int)commandId, StringUtils::ToNative(label)); + } + + virtual bool SetLabelAt(int index, String^ label) + { + ThrowIfDisposed(); + + return _menu->SetLabelAt(index, StringUtils::ToNative(label)); + } + + virtual MenuItemType GetType(CefMenuCommand commandId) + { + ThrowIfDisposed(); + + return (CefSharp::MenuItemType)_menu->GetType((int)commandId); + } + + virtual MenuItemType GetTypeAt(int index) + { + ThrowIfDisposed(); + + return (MenuItemType)_menu->GetTypeAt(index); + } + + virtual int GetGroupId(CefMenuCommand commandId) + { + ThrowIfDisposed(); + + return _menu->GetGroupId((int)commandId); + } + + virtual int GetGroupIdAt(int index) + { + ThrowIfDisposed(); + + return _menu->GetGroupIdAt(index); + } + + virtual bool SetGroupId(CefMenuCommand commandId, int groupId) + { + ThrowIfDisposed(); + + return _menu->SetGroupId((int)commandId, groupId); + } + + virtual bool SetGroupIdAt(int index, int groupId) + { + ThrowIfDisposed(); + + return _menu->SetGroupIdAt(index, groupId); + } + + virtual IMenuModel^ GetSubMenu(CefMenuCommand commandId) + { + ThrowIfDisposed(); + + auto subMenu =_menu->GetSubMenu((int)commandId); + + if (subMenu.get()) + { + return gcnew CefMenuModelWrapper(subMenu); + } + + return nullptr; + } + + virtual IMenuModel^ GetSubMenuAt(int index) + { + ThrowIfDisposed(); + + auto subMenu = _menu->GetSubMenuAt(index); + + if (subMenu.get()) + { + return gcnew CefMenuModelWrapper(subMenu); + } + + return nullptr; + } + + virtual bool IsVisible(CefMenuCommand commandId) + { + ThrowIfDisposed(); + + return _menu->IsVisible((int)commandId); + } + + virtual bool IsVisibleAt(int index) + { + ThrowIfDisposed(); + + return _menu->IsVisibleAt(index); + } + + virtual bool SetVisible(CefMenuCommand commandId, bool visible) + { + ThrowIfDisposed(); + + return _menu->SetVisible((int)commandId, visible); + } + + virtual bool SetVisibleAt(int index, bool visible) + { + ThrowIfDisposed(); + + return _menu->SetVisibleAt(index, visible); + } + + virtual bool IsEnabled(CefMenuCommand commandId) + { + ThrowIfDisposed(); + + return _menu->IsEnabled((int)commandId); + } + + virtual bool IsEnabledAt(int index) + { + ThrowIfDisposed(); + + return _menu->IsEnabledAt(index); + } + + virtual bool SetEnabled(CefMenuCommand commandId, bool enabled) + { + ThrowIfDisposed(); + + return _menu->SetEnabled((int)commandId, enabled); + } + + virtual bool SetEnabledAt(int index, bool enabled) + { + ThrowIfDisposed(); + + return _menu->SetEnabledAt(index, enabled); + } + + virtual bool IsChecked(CefMenuCommand commandId) + { + ThrowIfDisposed(); + + return _menu->IsChecked((int)commandId); + } + + virtual bool IsCheckedAt(int index) + { + ThrowIfDisposed(); + + return _menu->IsCheckedAt(index); + } + + virtual bool SetChecked(CefMenuCommand commandId, bool isChecked) + { + ThrowIfDisposed(); + + return _menu->SetChecked((int)commandId, isChecked); + } + + virtual bool SetCheckedAt(int index, bool isChecked) + { + ThrowIfDisposed(); + + return _menu->SetCheckedAt(index, isChecked); + } + + virtual bool HasAccelerator(CefMenuCommand commandId) + { + ThrowIfDisposed(); + + return _menu->HasAccelerator((int)commandId); + } + + virtual bool HasAcceleratorAt(int index) + { + ThrowIfDisposed(); + + return _menu->HasAcceleratorAt(index); + } + + virtual bool SetAccelerator(CefMenuCommand commandId, int keyCode, bool shiftPressed, bool ctrlPressed, bool altPressed) + { + ThrowIfDisposed(); + + return _menu->SetAccelerator((int)commandId, keyCode, shiftPressed, ctrlPressed, altPressed); + } + + virtual bool SetAcceleratorAt(int index, int keyCode, bool shiftPressed, bool ctrlPressed, bool altPressed) + { + ThrowIfDisposed(); + + return _menu->SetAcceleratorAt(index, keyCode, shiftPressed, ctrlPressed, altPressed); + } + + virtual bool RemoveAccelerator(CefMenuCommand commandId) + { + ThrowIfDisposed(); + + return _menu->RemoveAccelerator((int)commandId); + } + + virtual bool RemoveAcceleratorAt(int index) + { + ThrowIfDisposed(); + + return _menu->RemoveAcceleratorAt(index); + } + + virtual bool GetAccelerator(CefMenuCommand commandId, int% keyCode, bool% shiftPressed, bool% ctrlPressed, bool% altPressed) + { + ThrowIfDisposed(); + + int key; + bool shift; + bool ctrl; + bool alt; + + auto result = _menu->GetAccelerator((int)commandId, key, shift, ctrl, alt); + + keyCode = key; + shiftPressed = shift; + ctrlPressed = ctrl; + altPressed = alt; + + return result; + } + + virtual bool GetAcceleratorAt(int index, int% keyCode, bool% shiftPressed, bool% ctrlPressed, bool% altPressed) + { + ThrowIfDisposed(); + + int key; + bool shift; + bool ctrl; + bool alt; + + auto result = _menu->GetAcceleratorAt(index, key, shift, ctrl, alt); + + keyCode = key; + shiftPressed = shift; + ctrlPressed = ctrl; + altPressed = alt; + + return result; + } }; } } \ No newline at end of file diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index 3118029a1..dc08a47f0 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -90,6 +90,7 @@ + diff --git a/CefSharp/IMenuModel.cs b/CefSharp/IMenuModel.cs index 3ba70832d..2082e1ee4 100644 --- a/CefSharp/IMenuModel.cs +++ b/CefSharp/IMenuModel.cs @@ -52,5 +52,339 @@ namespace CefSharp /// /// Returns true on success. bool AddSeparator(); + + /// + /// Add a check item to the menu. + /// + /// the command Id + /// the label of the item + /// Returns true on success. + bool AddCheckItem(CefMenuCommand commandId, string label); + + /// + /// Add a radio item to the menu. Only a single item with the specified groupId can be checked at a time. + /// + /// the command Id + /// the label of the item + /// Returns true on success. + bool AddRadioItem(CefMenuCommand commandId, string label, int groupId); + + /// + /// Add a sub-menu to the menu. The new sub-menu is returned. + /// + /// the command Id + /// the label of the item + /// Returns the newly created . + IMenuModel AddSubMenu(CefMenuCommand commandId, string label); + + /// + /// Insert a separator in the menu at the specified index. + /// + /// index + /// Returns true on success. + bool InsertSeparatorAt(int index); + + /// + /// Insert an item in the menu at the specified index. + /// + /// index + /// the command Id + /// the label of the item + /// Returns true on success. + bool InsertItemAt(int index, CefMenuCommand commandId, string label); + + /// + /// Insert a check item in the menu at the specified index. + /// + /// index + /// the command Id + /// the label of the item + /// Returns true on success. + bool InsertCheckItemAt(int index, CefMenuCommand commandId, string label); + + /// + /// Insert a radio item in the menu at the specified index. + /// Only a single item with the specified groupId can be checked at a time. + /// + /// index + /// the command Id + /// the label of the item + /// the group id + /// Returns true on success. + bool InsertRadioItemAt(int index, CefMenuCommand commandId, string label, int groupId); + + /// + /// Insert a sub-menu in the menu at the specified index. + /// + /// index + /// the command Id + /// the label of the item + /// Returns the newly created . + IMenuModel InsertSubMenuAt(int index, CefMenuCommand commandId, string label); + + /// + /// Removes the item at the specified index. + /// + /// index + /// Returns true on success. + bool RemoveAt(int index); + + /// + /// Returns the index associated with the specified commandId or -1 if not found due to the command id not existing in the menu. + /// + /// the command Id + /// Returns the index associated with the specified commandId or -1 if not found due to the command id not existing in the menu. + int GetIndexOf(CefMenuCommand commandId); + + /// + /// Sets the command id at the specified index. + /// + /// index + /// the command Id + /// Returns true on success. + bool SetCommandIdAt(int index, CefMenuCommand commandId); + + /// + /// Returns the label for the specified commandId or empty if not found. + /// + /// the command Id + /// Returns the label for the specified commandId or empty if not found. + string GetLabel(CefMenuCommand commandId); + + /// + /// Sets the label for the specified commandId. + /// + /// the command Id + /// the label + /// Returns true on success. + bool SetLabel(CefMenuCommand commandId, string label); + + /// + /// Set the label at the specified index. + /// + /// index + /// the label + /// Returns true on success. + bool SetLabelAt(int index, string label); + + /// + /// Returns the item type for the specified commandId. + /// + /// the command Id + /// Returns the item type for the specified commandId. + MenuItemType GetType(CefMenuCommand commandId); + + /// + /// Returns the item type at the specified index. + /// + /// index + /// Returns the item type at the specified index. + MenuItemType GetTypeAt(int index); + + /// + /// Returns the group id for the specified commandId or -1 if invalid. + /// + /// the command Id + /// Returns the group id for the specified commandId or -1 if invalid. + int GetGroupId(CefMenuCommand commandId); + + /// + /// Returns the group id at the specified index or -1 if invalid. + /// + /// index + /// Returns the group id at the specified index or -1 if invalid. + int GetGroupIdAt(int index); + + /// + /// Sets the group id for the specified commandId. + /// + /// the command Id + /// the group id + /// Returns true on success. + bool SetGroupId(CefMenuCommand commandId, int groupId); + + /// + /// Sets the group id at the specified index. + /// + /// index + /// the group id + /// Returns true on success. + bool SetGroupIdAt(int index, int groupId); + + /// + /// Returns the for the specified commandId or null if invalid. + /// + /// the command Id + /// Returns the for the specified commandId or null if invalid. + IMenuModel GetSubMenu(CefMenuCommand commandId); + + /// + /// Returns the at the specified index or empty if invalid. + /// + /// index + /// Returns the for the specified commandId or null if invalid. + IMenuModel GetSubMenuAt(int index); + + /// + /// Returns true if the specified commandId is visible. + /// + /// the command Id + /// Returns true if the specified commandId is visible. + bool IsVisible(CefMenuCommand commandId); + + /// + /// Returns true if the specified index is visible. + /// + /// index + /// Returns true if the specified index is visible. + bool IsVisibleAt(int index); + + /// + /// Change the visibility of the specified commandId. + /// + /// the command Id + /// visible + /// Returns true on success. + bool SetVisible(CefMenuCommand commandId, bool visible); + + /// + /// Change the visibility at the specified index. + /// + /// index + /// visible + /// Returns true on success. + bool SetVisibleAt(int index, bool visible); + + /// + /// Returns true if the specified commandId is enabled. + /// + /// the command Id + /// Returns true if the specified commandId is enabled. + bool IsEnabled(CefMenuCommand commandId); + + /// + /// Returns true if the specified index is enabled. + /// + /// index + /// Returns true if the specified index is enabled. + bool IsEnabledAt(int index); + + /// + /// Change the enabled status of the specified commandId. + /// + /// the command Id + /// is enabled + /// Returns true on success. + bool SetEnabled(CefMenuCommand commandId, bool enabled); + + /// + /// Change the enabled status at the specified index. + /// + /// index + /// is enabled + /// Returns true on success. + bool SetEnabledAt(int index, bool enabled); + + /// + /// Returns true if the specified commandId is checked. Only applies to check and radio items. + /// + /// the command Id + /// Returns true if the specified commandId is checked. Only applies to check and radio items. + bool IsChecked(CefMenuCommand commandId); + + /// + /// Returns true if the specified index is checked. Only applies to check and radio items. + /// + /// index + /// Returns true if the specified index is checked. Only applies to check and radio items. + bool IsCheckedAt(int index); + + /// + /// Check the specified commandId. Only applies to check and radio items. + /// + /// the command Id + /// set checked + /// Returns true on success. + bool SetChecked(CefMenuCommand commandId, bool isChecked); + + /// + /// Check the specified index. Only applies to check and radio items. + /// + /// index + /// set checked + /// Returns true on success. + bool SetCheckedAt(int index, bool isChecked); + + /// + /// Returns true if the specified commandId has a keyboard accelerator assigned. + /// + /// the command Id + /// Returns true if the specified commandId has a keyboard accelerator assigned. + bool HasAccelerator(CefMenuCommand commandId); + + /// + /// Returns true if the specified index has a keyboard accelerator assigned. + /// + /// index + /// Returns true if the specified index has a keyboard accelerator assigned. + bool HasAcceleratorAt(int index); + + /// + /// Set the keyboard accelerator for the specified commandId. + /// + /// the command Id + /// keyCode can be any key or character value. + /// shift key pressed + /// ctrl key pressed + /// alt key pressed + /// Returns true on success. + bool SetAccelerator(CefMenuCommand commandId, int keyCode, bool shiftPressed, bool ctrlPressed, bool altPressed); + + /// + /// Set the keyboard accelerator at the specified index. keyCode can be any key or character value. + /// + /// index + /// keyCode can be any key or character value. + /// shift key pressed + /// ctrl key pressed + /// alt key pressed + /// Returns true on success. + bool SetAcceleratorAt(int index, int keyCode, bool shiftPressed, bool ctrlPressed, bool altPressed); + + /// + /// Remove the keyboard accelerator for the specified commandId. + /// + /// the command Id + /// Returns true on success. + bool RemoveAccelerator(CefMenuCommand commandId); + + /// + /// Remove the keyboard accelerator at the specified index. + /// + /// index + /// Returns true on success. + bool RemoveAcceleratorAt(int index); + + /// + /// Retrieves the keyboard accelerator for the specified commandId. + /// + /// the command Id + /// keyCode can be any key or character value. + /// shift key pressed + /// ctrl key pressed + /// alt key pressed + /// Returns true on success. + bool GetAccelerator(CefMenuCommand commandId, out int keyCode, out bool shiftPressed, out bool ctrlPressed, out bool altPressed); + + /// + /// Retrieves the keyboard accelerator for the specified index. + /// + /// index + /// keyCode can be any key or character value. + /// shift key pressed + /// ctrl key pressed + /// alt key pressed + /// Returns true on success. + bool GetAcceleratorAt(int index, out int keyCode, out bool shiftPressed, out bool ctrlPressed, out bool altPressed); } } diff --git a/CefSharp/MenuItemType.cs b/CefSharp/MenuItemType.cs new file mode 100644 index 000000000..6dc1fd08c --- /dev/null +++ b/CefSharp/MenuItemType.cs @@ -0,0 +1,16 @@ +// Copyright © 2010-2016 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +namespace CefSharp +{ + public enum MenuItemType + { + None = 0, + Command, + Check, + Radio, + Separator, + SubMenu + } +}