From ff3c4f4c704977b2eec1dba1238b422537e413f3 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Wed, 5 Aug 2015 15:04:28 +0300 Subject: tdf#73691 Implement MSWord's Alt-X: toggle unicode notation -toggles between characters and their unicode notation -sets Alt-X as a global keyboard accelerator -handles all of the unicode planes -intelligently handles combining characters -if text is selected, limits the input to that text -implemented in Writer, Draw, Impress Change-Id: Idcd8e7f0a4f1b81fa7f5f3200c76be19472ffa37 Reviewed-on: https://gerrit.libreoffice.org/17535 Tested-by: Samuel Mehrbrodt Reviewed-by: Miklos Vajna --- sd/sdi/_drvwsh.sdi | 4 ++++ sd/sdi/sdraw.sdi | 23 +++++++++++++++++++++++ sd/source/ui/view/drviewse.cxx | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) (limited to 'sd') diff --git a/sd/sdi/_drvwsh.sdi b/sd/sdi/_drvwsh.sdi index 2a721d8a7038..2f7769be816b 100644 --- a/sd/sdi/_drvwsh.sdi +++ b/sd/sdi/_drvwsh.sdi @@ -96,6 +96,10 @@ interface DrawView ExecMethod = FuSupport ; StateMethod = GetMenuState ; ] + SID_UNICODE_NOTATION_TOGGLE + [ + ExecMethod = FuSupport; + ] SID_PASTE_UNFORMATTED [ ExecMethod = FuSupport ; diff --git a/sd/sdi/sdraw.sdi b/sd/sdi/sdraw.sdi index d91e21bec36f..5fd19ad8bde8 100644 --- a/sd/sdi/sdraw.sdi +++ b/sd/sdi/sdraw.sdi @@ -7208,4 +7208,27 @@ SfxVoidItem MovePageLast SID_MOVE_PAGE_LAST ToolBoxConfig = TRUE, GroupId = GID_MODIFY; ] +SfxVoidItem UnicodeNotationToggle SID_UNICODE_NOTATION_TOGGLE +() +[ + /* flags: */ + AutoUpdate = FALSE, + Cachable = Cachable, + FastCall = FALSE, + HasCoreId = FALSE, + HasDialog = FALSE, + ReadOnlyDoc = FALSE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + Synchron; + + /* config: */ + AccelConfig = TRUE, + MenuConfig = FALSE, + StatusBarConfig = FALSE, + ToolBoxConfig = FALSE, + GroupId = GID_OPTIONS; +] diff --git a/sd/source/ui/view/drviewse.cxx b/sd/source/ui/view/drviewse.cxx index 0eb9f29177c4..093b46d31665 100644 --- a/sd/source/ui/view/drviewse.cxx +++ b/sd/source/ui/view/drviewse.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -837,6 +838,47 @@ void DrawViewShell::FuSupport(SfxRequest& rReq) } break; + case SID_UNICODE_NOTATION_TOGGLE: + { + if ( mpDrawView->IsTextEdit() ) + { + OutlinerView* pOLV = mpDrawView->GetTextEditOutlinerView(); + if (pOLV) + { + OUString sInput = pOLV->GetSurroundingText(); + ESelection aSel( pOLV->GetSelection() ); + if ( aSel.nStartPos > aSel.nEndPos ) + aSel.nEndPos = aSel.nStartPos; + + //calculate a valid end-position by reading logical characters + sal_Int32 nUtf16Pos=0; + while( (nUtf16Pos < sInput.getLength()) && (nUtf16Pos < aSel.nEndPos) ) + { + sInput.iterateCodePoints(&nUtf16Pos); + //The mouse can set the cursor in the middle of a multi-unit character, + // so reset to the proper end of the logical characters + if( nUtf16Pos > aSel.nEndPos ) + aSel.nEndPos = nUtf16Pos; + } + + ToggleUnicodeCodepoint aToggle = ToggleUnicodeCodepoint(); + while( nUtf16Pos && aToggle.AllowMoreInput( sInput[nUtf16Pos-1]) ) + --nUtf16Pos; + OUString sReplacement = aToggle.ReplacementString(); + if( !sReplacement.isEmpty() ) + { + OUString sStringToReplace = aToggle.StringToReplace(); + mpDrawView->BegUndo(sStringToReplace +"->"+ sReplacement); + aSel.nStartPos = aSel.nEndPos - sStringToReplace.getLength(); + pOLV->SetSelection( aSel ); + pOLV->InsertText(sReplacement, true); + mpDrawView->EndUndo(); + } + } + } + } + break; + case SID_PASTE_UNFORMATTED: { WaitObject aWait( GetActiveWindow() ); -- cgit