summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2014-05-22 12:28:02 +0200
committerKohei Yoshida <libreoffice@kohei.us>2014-05-23 06:28:29 -0500
commitaca222ee87826eb99554dba8fcf22e0cf7c718e0 (patch)
tree8a9215caef39481c1bb531da4c5e33b6db9c8e68 /svx
parentd4a19c4098f4556f05666ed92a85c6138b4f769a (diff)
switch the Western language list box to SvxLanguageComboBox
This allows the user to assign an arbitrary (but valid) BCP 47 language tag to a portion of text, so that customized spell-checkers or other language-dependent tools can be used without the need to wait for LibreOffice to add yet another language to the list in the next release. +bool SvtLanguageTable::HasLanguageType() (cherry picked from commit 2a8eff589a53c8dd65e18d7a9d11cdb98a937e68) + SvxLanguageComboBox EditModifyHdl(), SaveEditedAsEntry() (cherry picked from commit 29c024afbe6a46459e37c5ceec510de1cd0ca7c8) handle SvxLanguageComboBox edit (cherry picked from commit 1aad7628dcd7fd14d48814d00c3d04e4ec0c59d5) finally switch the Western language list box to SvxLanguageComboBox (cherry picked from commit dbe8b3b6d4f2d2cc2e8c702b78034e9013f71e8f) advance start of edit selection on a matching entry ... to allow continuous typing. (cherry picked from commit fe2b8ef18b11b226fddd1cf3fc7f9133426a1b1a) Change-Id: Id57eb51b69e50be78f85d19a7b3623c1acdf6509 Reviewed-on: https://gerrit.libreoffice.org/9447 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com> Reviewed-by: Kohei Yoshida <libreoffice@kohei.us> Tested-by: Kohei Yoshida <libreoffice@kohei.us>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/dialog/langbox.cxx90
1 files changed, 90 insertions, 0 deletions
diff --git a/svx/source/dialog/langbox.cxx b/svx/source/dialog/langbox.cxx
index 92f5cb6b0b8d..028e33df15ba 100644
--- a/svx/source/dialog/langbox.cxx
+++ b/svx/source/dialog/langbox.cxx
@@ -33,6 +33,7 @@
#include <svx/dialmgr.hxx>
#include <svx/dialogs.hrc>
#include <vcl/builder.hxx>
+#include <vcl/i18nhelp.hxx>
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::lang;
@@ -507,6 +508,7 @@ SvxLanguageComboBox::SvxLanguageComboBox( Window* pParent, WinBits nBits, bool b
: ComboBox( pParent, nBits )
, SvxLanguageBoxBase( bCheck )
, mnSavedValuePos( COMBOBOX_ENTRY_NOTFOUND )
+ , meEditedAndValid( EDITED_NO )
{
// display entries sorted
SetStyle( GetStyle() | WB_SORT );
@@ -514,6 +516,8 @@ SvxLanguageComboBox::SvxLanguageComboBox( Window* pParent, WinBits nBits, bool b
EnableMultiSelection( false );
ImplLanguageBoxBaseInit();
+
+ SetModifyHdl( LINK( this, SvxLanguageComboBox, EditModifyHdl ) );
}
SvxLanguageComboBox::~SvxLanguageComboBox()
@@ -698,4 +702,90 @@ sal_Int32 SvxLanguageComboBox::ImplGetSavedValue() const
}
+IMPL_LINK( SvxLanguageComboBox, EditModifyHdl, SvxLanguageComboBox*, /*pEd*/ )
+{
+ OUString aStr( vcl::I18nHelper::filterFormattingChars( GetText()));
+ if (aStr.isEmpty())
+ meEditedAndValid = EDITED_INVALID;
+ else
+ {
+ const sal_Int32 nPos = GetEntryPos( aStr);
+ if (nPos != COMBOBOX_ENTRY_NOTFOUND)
+ {
+ // Advance start of full selection by one so the next character
+ // will already continue the string instead of having to type the
+ // same character again to start a new string. The selection
+ // includes formatting characters and is reverse when obtained from
+ // the Edit control.
+ Selection aSel( GetSelection());
+ if (aSel.Max() == 1)
+ {
+ OUString aText( GetText());
+ if (aSel.Min() == aText.getLength())
+ {
+ ++aSel.Max();
+ SetSelection( aSel);
+ }
+ }
+ meEditedAndValid = EDITED_NO;
+ }
+ else
+ {
+ OUString aCanonicalized;
+ bool bValid = LanguageTag::isValidBcp47( aStr, &aCanonicalized);
+ meEditedAndValid = (bValid ? EDITED_VALID : EDITED_INVALID);
+ if (bValid && aCanonicalized != aStr)
+ {
+ SetText( aCanonicalized);
+ SetSelection( Selection( aCanonicalized.getLength()));
+ }
+ }
+ }
+ return 0;
+}
+
+
+SvxLanguageComboBox::EditedAndValid SvxLanguageComboBox::GetEditedAndValid() const
+{
+ return meEditedAndValid;
+}
+
+
+sal_Int32 SvxLanguageComboBox::SaveEditedAsEntry()
+{
+ if (meEditedAndValid != EDITED_VALID)
+ return COMBOBOX_ENTRY_NOTFOUND;
+
+ LanguageTag aLanguageTag( vcl::I18nHelper::filterFormattingChars( GetText()));
+ LanguageType nLang = aLanguageTag.getLanguageType();
+ if (nLang == LANGUAGE_DONTKNOW)
+ {
+ SAL_WARN( "svx.dialog", "SvxLanguageComboBox::SaveEditedAsEntry: unknown tag");
+ return COMBOBOX_ENTRY_NOTFOUND;
+ }
+
+ sal_Int32 nPos = ImplTypeToPos( nLang);
+ if (nPos != COMBOBOX_ENTRY_NOTFOUND)
+ return nPos; // Already present but with a different string.
+
+ if (SvtLanguageTable::HasLanguageType( nLang))
+ {
+ // In SvtLanguageTable but not in SvxLanguageComboBox. On purpose? This
+ // may be an entry with different settings or CTL instead of Western or
+ // ... all things we don't handle yet.
+ SAL_WARN( "svx.dialog", "SvxLanguageComboBox::SaveEditedAsEntry: already in SvtLanguageTable: " <<
+ SvtLanguageTable::GetLanguageString( nLang) << ", " << nLang);
+ }
+ else
+ {
+ // Add to both, SvtLanguageTable and SvxLanguageComboBox.
+ /* TODO: a descriptive user comment would be a nice to have here. */
+ SvtLanguageTable::AddLanguageTag( aLanguageTag, OUString());
+ }
+
+ nPos = InsertLanguage( nLang);
+
+ return nPos;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */