diff options
-rw-r--r-- | include/vcl/edit.hxx | 3 | ||||
-rw-r--r-- | vcl/UIConfig_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/inc/svids.hrc | 8 | ||||
-rw-r--r-- | vcl/source/control/edit.cxx | 141 | ||||
-rw-r--r-- | vcl/source/edit/vclmedit.cxx | 127 | ||||
-rw-r--r-- | vcl/source/src/menu.src | 46 | ||||
-rw-r--r-- | vcl/uiconfig/ui/editmenu.ui | 79 |
7 files changed, 228 insertions, 177 deletions
diff --git a/include/vcl/edit.hxx b/include/vcl/edit.hxx index e0a0c91ee2a2..c29fe97ecbb9 100644 --- a/include/vcl/edit.hxx +++ b/include/vcl/edit.hxx @@ -94,6 +94,7 @@ private: Link<Edit&,void> maModifyHdl; Link<Edit&,void> maUpdateDataHdl; Link<Edit&,void> maAutocompleteHdl; + std::unique_ptr<VclBuilder> mpUIBuilder; css::uno::Reference<css::i18n::XExtendedInputSequenceChecker> mxISC; @@ -253,7 +254,7 @@ public: static void SetGetSpecialCharsFunction( FncGetSpecialChars fn ); static FncGetSpecialChars GetGetSpecialCharsFunction(); - static VclPtr<PopupMenu> CreatePopupMenu(); + VclPtr<PopupMenu> CreatePopupMenu(); virtual OUString GetSurroundingText() const override; virtual Selection GetSurroundingTextSelection() const override; diff --git a/vcl/UIConfig_vcl.mk b/vcl/UIConfig_vcl.mk index a81b30ed497a..85dbe823d5cc 100644 --- a/vcl/UIConfig_vcl.mk +++ b/vcl/UIConfig_vcl.mk @@ -11,6 +11,7 @@ $(eval $(call gb_UIConfig_UIConfig,vcl)) $(eval $(call gb_UIConfig_add_uifiles,vcl,\ vcl/uiconfig/ui/cupspassworddialog \ + vcl/uiconfig/ui/editmenu \ vcl/uiconfig/ui/errornocontentdialog \ vcl/uiconfig/ui/errornoprinterdialog \ vcl/uiconfig/ui/printdialog \ diff --git a/vcl/inc/svids.hrc b/vcl/inc/svids.hrc index 47fb0675938a..734f0385875e 100644 --- a/vcl/inc/svids.hrc +++ b/vcl/inc/svids.hrc @@ -73,14 +73,6 @@ #define RID_STR_PAPERNAMES 1080 -#define SV_RESID_MENU_EDIT 2000 -#define SV_MENU_EDIT_UNDO 1 -#define SV_MENU_EDIT_CUT 2 -#define SV_MENU_EDIT_COPY 3 -#define SV_MENU_EDIT_PASTE 4 -#define SV_MENU_EDIT_DELETE 5 -#define SV_MENU_EDIT_SELECTALL 6 -#define SV_MENU_EDIT_INSERTSYMBOL 7 #define SV_RESID_STRING_NOSELECTIONPOSSIBLE 2001 #define SV_MENU_MAC_SERVICES 2002 diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx index c6fe57110c7a..64046ecf87c1 100644 --- a/vcl/source/control/edit.cxx +++ b/vcl/source/control/edit.cxx @@ -226,6 +226,8 @@ Edit::~Edit() void Edit::dispose() { + mpUIBuilder.reset(); + delete mpDDInfo; mpDDInfo = nullptr; @@ -1931,19 +1933,25 @@ void Edit::Command( const CommandEvent& rCEvt ) { VclPtr<PopupMenu> pPopup = Edit::CreatePopupMenu(); + bool bEnableCut = true; + bool bEnableCopy = true; + bool bEnableDelete = true; + bool bEnablePaste = true; + bool bEnableSpecialChar = true; + if ( !maSelection.Len() ) { - pPopup->EnableItem( SV_MENU_EDIT_CUT, false ); - pPopup->EnableItem( SV_MENU_EDIT_COPY, false ); - pPopup->EnableItem( SV_MENU_EDIT_DELETE, false ); + bEnableCut = false; + bEnableCopy = false; + bEnableDelete = false; } if ( IsReadOnly() ) { - pPopup->EnableItem( SV_MENU_EDIT_CUT, false ); - pPopup->EnableItem( SV_MENU_EDIT_PASTE, false ); - pPopup->EnableItem( SV_MENU_EDIT_DELETE, false ); - pPopup->EnableItem( SV_MENU_EDIT_INSERTSYMBOL, false ); + bEnableCut = false; + bEnablePaste = false; + bEnableDelete = false; + bEnableSpecialChar = false; } else { @@ -1965,19 +1973,19 @@ void Edit::Command( const CommandEvent& rCEvt ) bData = xDataObj->isDataFlavorSupported( aFlavor ); } } - pPopup->EnableItem( SV_MENU_EDIT_PASTE, bData ); + bEnablePaste = bData; } - if ( maUndoText == maText.getStr() ) - pPopup->EnableItem( SV_MENU_EDIT_UNDO, false ); - if ( ( maSelection.Min() == 0 ) && ( maSelection.Max() == maText.getLength() ) ) - pPopup->EnableItem( SV_MENU_EDIT_SELECTALL, false ); - if ( !pImplFncGetSpecialChars ) - { - sal_uInt16 nPos = pPopup->GetItemPos( SV_MENU_EDIT_INSERTSYMBOL ); - pPopup->RemoveItem( nPos ); - pPopup->RemoveItem( nPos-1 ); - } + pPopup->EnableItem(pPopup->GetItemId("cut"), bEnableCut); + pPopup->EnableItem(pPopup->GetItemId("copy"), bEnableCopy); + pPopup->EnableItem(pPopup->GetItemId("delete"), bEnableDelete); + pPopup->EnableItem(pPopup->GetItemId("paste"), bEnablePaste); + pPopup->EnableItem(pPopup->GetItemId("specialchar"), bEnableSpecialChar); + pPopup->EnableItem(pPopup->GetItemId("undo"), maUndoText != maText.getStr()); + bool bAllSelected = maSelection.Min() == 0 && maSelection.Max() == maText.getLength(); + pPopup->EnableItem(pPopup->GetItemId("selectall"), !bAllSelected); + pPopup->ShowItem(pPopup->GetItemId("specialchar"), pImplFncGetSpecialChars); + pPopup->ShowItem(pPopup->GetItemId("selectall"), pImplFncGetSpecialChars); mbActivePopup = true; Selection aSaveSel = GetSelection(); // if someone changes selection in Get/LoseFocus, e.g. URL bar @@ -1989,44 +1997,47 @@ void Edit::Command( const CommandEvent& rCEvt ) aPos = Point( aSize.Width()/2, aSize.Height()/2 ); } sal_uInt16 n = pPopup->Execute( this, aPos ); - pPopup.disposeAndClear(); SetSelection( aSaveSel ); - switch ( n ) + OString sCommand = pPopup->GetItemIdent(n); + if (sCommand == "undo") { - case SV_MENU_EDIT_UNDO: - Undo(); - ImplModified(); - break; - case SV_MENU_EDIT_CUT: - Cut(); - ImplModified(); - break; - case SV_MENU_EDIT_COPY: - Copy(); - break; - case SV_MENU_EDIT_PASTE: - Paste(); - ImplModified(); - break; - case SV_MENU_EDIT_DELETE: - DeleteSelected(); + Undo(); + ImplModified(); + } + else if (sCommand == "cut") + { + Cut(); + ImplModified(); + } + else if (sCommand == "copy") + { + Copy(); + } + else if (sCommand == "paste") + { + Paste(); + ImplModified(); + } + else if (sCommand == "delete") + { + DeleteSelected(); + ImplModified(); + } + else if (sCommand == "selectall") + { + ImplSetSelection( Selection( 0, maText.getLength() ) ); + } + else if (sCommand == "specialchar") + { + OUString aChars = pImplFncGetSpecialChars( this, GetFont() ); + SetSelection( aSaveSel ); + if (!aChars.isEmpty()) + { + ImplInsertText( aChars ); ImplModified(); - break; - case SV_MENU_EDIT_SELECTALL: - ImplSetSelection( Selection( 0, maText.getLength() ) ); - break; - case SV_MENU_EDIT_INSERTSYMBOL: - { - OUString aChars = pImplFncGetSpecialChars( this, GetFont() ); - SetSelection( aSaveSel ); - if ( !aChars.isEmpty() ) - { - ImplInsertText( aChars ); - ImplModified(); - } - } - break; + } } + pPopup.clear(); mbActivePopup = false; } else if ( rCEvt.GetCommand() == CommandEventId::StartExtTextInput ) @@ -2787,25 +2798,21 @@ FncGetSpecialChars Edit::GetGetSpecialCharsFunction() VclPtr<PopupMenu> Edit::CreatePopupMenu() { - ResMgr* pResMgr = ImplGetResMgr(); - if( ! pResMgr ) - return VclPtr<PopupMenu>::Create(); - - VclPtrInstance<PopupMenu> pPopup( ResId( SV_RESID_MENU_EDIT, *pResMgr ) ); + if (!mpUIBuilder) + mpUIBuilder.reset(new VclBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "vcl/ui/editmenu.ui", "")); + VclPtr<PopupMenu> pPopup = mpUIBuilder->get_menu("menu"); const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); - if ( rStyleSettings.GetHideDisabledMenuItems() ) + if (rStyleSettings.GetHideDisabledMenuItems()) pPopup->SetMenuFlags( MenuFlags::HideDisabledEntries ); else pPopup->SetMenuFlags ( MenuFlags::AlwaysShowDisabledEntries ); - if ( rStyleSettings.GetContextMenuShortcuts() ) - { - pPopup->SetAccelKey( SV_MENU_EDIT_UNDO, vcl::KeyCode( KeyFuncType::UNDO ) ); - pPopup->SetAccelKey( SV_MENU_EDIT_CUT, vcl::KeyCode( KeyFuncType::CUT ) ); - pPopup->SetAccelKey( SV_MENU_EDIT_COPY, vcl::KeyCode( KeyFuncType::COPY ) ); - pPopup->SetAccelKey( SV_MENU_EDIT_PASTE, vcl::KeyCode( KeyFuncType::PASTE ) ); - pPopup->SetAccelKey( SV_MENU_EDIT_DELETE, vcl::KeyCode( KeyFuncType::DELETE ) ); - pPopup->SetAccelKey( SV_MENU_EDIT_SELECTALL, vcl::KeyCode( KEY_A, false, true, false, false ) ); - pPopup->SetAccelKey( SV_MENU_EDIT_INSERTSYMBOL, vcl::KeyCode( KEY_S, true, true, false, false ) ); + if (rStyleSettings.GetContextMenuShortcuts()) + { + pPopup->SetAccelKey(pPopup->GetItemId("undo"), vcl::KeyCode( KeyFuncType::UNDO)); + pPopup->SetAccelKey(pPopup->GetItemId("cut"), vcl::KeyCode( KeyFuncType::CUT)); + pPopup->SetAccelKey(pPopup->GetItemId("copy"), vcl::KeyCode( KeyFuncType::COPY)); + pPopup->SetAccelKey(pPopup->GetItemId("paste"), vcl::KeyCode( KeyFuncType::PASTE)); + pPopup->SetAccelKey(pPopup->GetItemId("delete"), vcl::KeyCode( KeyFuncType::DELETE)); } return pPopup; } diff --git a/vcl/source/edit/vclmedit.cxx b/vcl/source/edit/vclmedit.cxx index ce778f293277..9cc1a9063d26 100644 --- a/vcl/source/edit/vclmedit.cxx +++ b/vcl/source/edit/vclmedit.cxx @@ -34,6 +34,7 @@ class TextWindow : public vcl::Window { private: + VclPtr<Edit> mxParent; ExtTextEngine* mpExtTextEngine; TextView* mpExtTextView; @@ -44,7 +45,7 @@ private: bool mbSelectOnTab; public: - explicit TextWindow( vcl::Window* pParent ); + explicit TextWindow(Edit* pParent); virtual ~TextWindow() override; virtual void dispose() override; @@ -702,7 +703,9 @@ bool ImpVclMEdit::HandleCommand( const CommandEvent& rCEvt ) return bDone; } -TextWindow::TextWindow( vcl::Window* pParent ) : Window( pParent ) +TextWindow::TextWindow(Edit* pParent) + : Window(pParent) + , mxParent(pParent) { mbInMBDown = false; mbFocusSelectionHide = false; @@ -734,6 +737,7 @@ TextWindow::~TextWindow() void TextWindow::dispose() { + mxParent.clear(); delete mpExtTextView; mpExtTextView = nullptr; delete mpExtTextEngine; @@ -814,34 +818,39 @@ void TextWindow::Command( const CommandEvent& rCEvt ) { if ( rCEvt.GetCommand() == CommandEventId::ContextMenu ) { - VclPtr<PopupMenu> pPopup = Edit::CreatePopupMenu(); + VclPtr<PopupMenu> pPopup = mxParent->CreatePopupMenu(); + bool bEnableCut = true; + bool bEnableCopy = true; + bool bEnableDelete = true; + bool bEnablePaste = true; + bool bEnableSpecialChar = true; + bool bEnableUndo = true; + if ( !mpExtTextView->HasSelection() ) { - pPopup->EnableItem( SV_MENU_EDIT_CUT, false ); - pPopup->EnableItem( SV_MENU_EDIT_COPY, false ); - pPopup->EnableItem( SV_MENU_EDIT_DELETE, false ); + bEnableCut = false; + bEnableCopy = false; + bEnableDelete = false; } if ( mpExtTextView->IsReadOnly() ) { - pPopup->EnableItem( SV_MENU_EDIT_CUT, false ); - pPopup->EnableItem( SV_MENU_EDIT_PASTE, false ); - pPopup->EnableItem( SV_MENU_EDIT_DELETE, false ); - pPopup->EnableItem( SV_MENU_EDIT_INSERTSYMBOL, false ); + bEnableCut = false; + bEnablePaste = false; + bEnableDelete = false; + bEnableSpecialChar = false; } if ( !mpExtTextView->GetTextEngine()->HasUndoManager() || !mpExtTextView->GetTextEngine()->GetUndoManager().GetUndoActionCount() ) { - pPopup->EnableItem( SV_MENU_EDIT_UNDO, false ); - } -// if ( ( maSelection.Min() == 0 ) && ( maSelection.Max() == maText.Len() ) ) -// { -// pPopup->EnableItem( SV_MENU_EDIT_SELECTALL, false ); -// } - if ( !Edit::GetGetSpecialCharsFunction() ) - { - sal_uInt16 nPos = pPopup->GetItemPos( SV_MENU_EDIT_INSERTSYMBOL ); - pPopup->RemoveItem( nPos ); - pPopup->RemoveItem( nPos-1 ); + bEnableUndo = false; } + pPopup->EnableItem(pPopup->GetItemId("cut"), bEnableCut); + pPopup->EnableItem(pPopup->GetItemId("copy"), bEnableCopy); + pPopup->EnableItem(pPopup->GetItemId("delete"), bEnableDelete); + pPopup->EnableItem(pPopup->GetItemId("paste"), bEnablePaste); + pPopup->EnableItem(pPopup->GetItemId("specialchar"), bEnableSpecialChar); + pPopup->EnableItem(pPopup->GetItemId("undo"), bEnableUndo); + pPopup->ShowItem(pPopup->GetItemId("specialchar"), !Edit::GetGetSpecialCharsFunction()); + pPopup->ShowItem(pPopup->GetItemId("selectall"), !Edit::GetGetSpecialCharsFunction()); mbActivePopup = true; Point aPos = rCEvt.GetMousePosPixel(); @@ -851,43 +860,51 @@ void TextWindow::Command( const CommandEvent& rCEvt ) Size aSize = GetOutputSizePixel(); aPos = Point( aSize.Width()/2, aSize.Height()/2 ); } -// pPopup->RemoveDisabledEntries(); sal_uInt16 n = pPopup->Execute( this, aPos ); - pPopup.disposeAndClear(); - switch ( n ) + OString sCommand = pPopup->GetItemIdent(n); + if (sCommand == "undo") { - case SV_MENU_EDIT_UNDO: mpExtTextView->Undo(); - mpExtTextEngine->SetModified( true ); - mpExtTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) ); - break; - case SV_MENU_EDIT_CUT: mpExtTextView->Cut(); - mpExtTextEngine->SetModified( true ); - mpExtTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) ); - break; - case SV_MENU_EDIT_COPY: mpExtTextView->Copy(); - break; - case SV_MENU_EDIT_PASTE: mpExtTextView->Paste(); - mpExtTextEngine->SetModified( true ); - mpExtTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) ); - break; - case SV_MENU_EDIT_DELETE: mpExtTextView->DeleteSelected(); - mpExtTextEngine->SetModified( true ); - mpExtTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) ); - break; - case SV_MENU_EDIT_SELECTALL: mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( TEXT_PARA_ALL, TEXT_INDEX_ALL ) ) ); - break; - case SV_MENU_EDIT_INSERTSYMBOL: - { - OUString aChars = Edit::GetGetSpecialCharsFunction()( this, GetFont() ); - if (!aChars.isEmpty()) - { - mpExtTextView->InsertText( aChars ); - mpExtTextEngine->SetModified( true ); - mpExtTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) ); - } - } - break; + mpExtTextView->Undo(); + mpExtTextEngine->SetModified( true ); + mpExtTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) ); + } + else if (sCommand == "cut") + { + mpExtTextView->Cut(); + mpExtTextEngine->SetModified( true ); + mpExtTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) ); + } + else if (sCommand == "copy") + { + mpExtTextView->Copy(); + } + else if (sCommand == "paste") + { + mpExtTextView->Paste(); + mpExtTextEngine->SetModified( true ); + mpExtTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) ); + } + else if (sCommand == "delete") + { + mpExtTextView->DeleteSelected(); + mpExtTextEngine->SetModified( true ); + mpExtTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) ); + } + else if (sCommand == "selectall") + { + mpExtTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( TEXT_PARA_ALL, TEXT_INDEX_ALL ) ) ); + } + else if (sCommand == "specialchar") + { + OUString aChars = Edit::GetGetSpecialCharsFunction()( this, GetFont() ); + if (!aChars.isEmpty()) + { + mpExtTextView->InsertText( aChars ); + mpExtTextEngine->SetModified( true ); + mpExtTextEngine->Broadcast( TextHint( SfxHintId::TextModified ) ); + } } + pPopup.clear(); mbActivePopup = false; } else diff --git a/vcl/source/src/menu.src b/vcl/source/src/menu.src index 7e489e6a48d6..dd97a69590ed 100644 --- a/vcl/source/src/menu.src +++ b/vcl/source/src/menu.src @@ -24,52 +24,6 @@ String SV_RESID_STRING_NOSELECTIONPOSSIBLE Text [ en-US ] = "<No selection possible>"; }; -Menu SV_RESID_MENU_EDIT -{ - ItemList = - { - MenuItem - { - Identifier = SV_MENU_EDIT_UNDO ; - Text [ en-US ] = "~Undo" ; - }; - MenuItem { Separator = TRUE ; }; - MenuItem - { - Identifier = SV_MENU_EDIT_CUT ; - Text [ en-US ] = "Cu~t" ; - }; - MenuItem - { - Identifier = SV_MENU_EDIT_COPY ; - Text [ en-US ] = "~Copy" ; - }; - MenuItem - { - Identifier = SV_MENU_EDIT_PASTE ; - Text [ en-US ] = "~Paste" ; - }; - MenuItem - { - Identifier = SV_MENU_EDIT_DELETE ; - Text [ en-US ] = "~Delete" ; - }; - MenuItem { Separator = TRUE ; }; - MenuItem - { - Identifier = SV_MENU_EDIT_SELECTALL ; - Text [ en-US ] = "Select ~All" ; - }; - MenuItem { Separator = TRUE ; }; - MenuItem - { - Identifier = SV_MENU_EDIT_INSERTSYMBOL; - Text [ en-US ] = "~Special Character..."; - - }; - }; -}; - String SV_MENU_MAC_SERVICES { Text [ en-US ] = "Services"; diff --git a/vcl/uiconfig/ui/editmenu.ui b/vcl/uiconfig/ui/editmenu.ui new file mode 100644 index 000000000000..9798605c8491 --- /dev/null +++ b/vcl/uiconfig/ui/editmenu.ui @@ -0,0 +1,79 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.20.0 --> +<interface> + <requires lib="gtk+" version="3.10"/> + <object class="GtkMenu" id="menu"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkMenuItem" id="undo"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">_Undo</property> + <property name="use_underline">True</property> + </object> + </child> + <child> + <object class="GtkSeparatorMenuItem" id="menuitem6"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + </child> + <child> + <object class="GtkMenuItem" id="cut"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Cu_t</property> + <property name="use_underline">True</property> + </object> + </child> + <child> + <object class="GtkMenuItem" id="copy"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">_Copy</property> + <property name="use_underline">True</property> + </object> + </child> + <child> + <object class="GtkMenuItem" id="paste"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">_Paste</property> + <property name="use_underline">True</property> + </object> + </child> + <child> + <object class="GtkMenuItem" id="delete"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">_Delete</property> + <property name="use_underline">True</property> + </object> + </child> + <child> + <object class="GtkSeparatorMenuItem" id="menuitem1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + </child> + <child> + <object class="GtkMenuItem" id="selectall"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Select _All</property> + <property name="use_underline">True</property> + <accelerator key="a" signal="activate" modifiers="GDK_CONTROL_MASK"/> + </object> + </child> + <child> + <object class="GtkMenuItem" id="specialchar"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">_Special Character...</property> + <property name="use_underline">True</property> + <accelerator key="s" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/> + </object> + </child> + </object> +</interface> |