[Libreoffice-commits] core.git: include/svx sc/inc sc/source sc/uiconfig svx/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Feb 15 14:55:06 UTC 2019


 include/svx/txencbox.hxx            |  103 ++++++++++++--
 sc/inc/scabstdlg.hxx                |   10 -
 sc/source/ui/attrdlg/scdlgfact.cxx  |   24 +--
 sc/source/ui/attrdlg/scdlgfact.hxx  |   20 +-
 sc/source/ui/dbgui/scuiimoptdlg.cxx |  255 ++++++++++++++++--------------------
 sc/source/ui/inc/scuiimoptdlg.hxx   |   59 ++++----
 sc/source/ui/unoobj/filtuno.cxx     |    2 
 sc/uiconfig/scalc/ui/imoptdialog.ui |   73 ++++++++--
 svx/source/dialog/txencbox.cxx      |  232 ++++++++++++++++++++++++--------
 9 files changed, 503 insertions(+), 275 deletions(-)

New commits:
commit 36af12e74f4fa20712a3671c1be2a3a4b5a54e7d
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Fri Feb 15 12:58:05 2019 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Feb 15 15:54:39 2019 +0100

    weld ScImportOptionsDlg
    
    Change-Id: Ib8ea4726d20f0bd7f40283983fec2d5890fac382
    Reviewed-on: https://gerrit.libreoffice.org/67869
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/svx/txencbox.hxx b/include/svx/txencbox.hxx
index 4cf66c7c1641..f2edcb83f6d5 100644
--- a/include/svx/txencbox.hxx
+++ b/include/svx/txencbox.hxx
@@ -54,6 +54,50 @@ public:
                             sal_uInt32 nButIncludeInfoFlags = 0
                             );
 
+    /** Fill with all known MIME encodings and select the best according to
+        <method>GetBestMimeEncoding</method>
+     */
+    void                FillWithMimeAndSelectBest();
+
+    void                InsertTextEncoding( const rtl_TextEncoding nEnc );
+
+    void                InsertTextEncoding( const rtl_TextEncoding nEnc,
+                            const OUString& rEntry );
+
+    void                SelectTextEncoding( const rtl_TextEncoding nEnc );
+
+    rtl_TextEncoding    GetSelectTextEncoding() const;
+};
+
+class SVX_DLLPUBLIC TextEncodingBox
+{
+private:
+    std::unique_ptr<weld::ComboBox> m_xControl;
+
+public:
+    TextEncodingBox(std::unique_ptr<weld::ComboBox> pControl);
+
+    ~TextEncodingBox();
+
+    /** Fill with all known encodings but exclude those matching one or more
+        given flags as defined in rtl/tencinfo.h
+
+         <p> If nButIncludeInfoFlags is given, encodings are included even if they
+         match nExcludeInfoFlags. Thus it is possible to exclude 16/32-bit
+         Unicode with RTL_TEXTENCODING_INFO_UNICODE but to include UTF7 and UTF8
+         with RTL_TEXTENCODING_INFO_MIME </p>
+
+        @param bExcludeImportSubsets
+            If <TRUE/>, some specific encodings are not listed, as they are a
+            subset of another encoding. This is the case for
+            RTL_TEXTENCODING_GB_2312, RTL_TEXTENCODING_GBK,
+            RTL_TEXTENCODING_MS_936, which are covered by
+            RTL_TEXTENCODING_GB_18030. Normally, this flag should be set to
+            <TRUE/> whenever the box is used in import dialogs. */
+    void                FillFromTextEncodingTable(
+                            bool bExcludeImportSubsets,
+                            sal_uInt32 nExcludeInfoFlags = 0);
+
     /** Fill with all encodings known to the dbtools::OCharsetMap but exclude
         those matching one or more given flags as defined in rtl/tencinfo.h
 
@@ -71,13 +115,7 @@ public:
             <TRUE/> whenever the box is used in import dialogs. */
     void                FillFromDbTextEncodingMap(
                             bool bExcludeImportSubsets,
-                            sal_uInt32 nExcludeInfoFlags = 0
-                            );
-
-    /** Fill with all known MIME encodings and select the best according to
-        <method>GetBestMimeEncoding</method>
-     */
-    void                FillWithMimeAndSelectBest();
+                            sal_uInt32 nExcludeInfoFlags = 0);
 
     void                InsertTextEncoding( const rtl_TextEncoding nEnc );
 
@@ -87,17 +125,21 @@ public:
     void                SelectTextEncoding( const rtl_TextEncoding nEnc );
 
     rtl_TextEncoding    GetSelectTextEncoding() const;
+
+    void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_xControl->connect_changed(rLink); }
+    void grab_focus() { m_xControl->grab_focus(); }
+    void show() { m_xControl->show(); }
 };
 
-class SVX_DLLPUBLIC TextEncodingBox
+class SVX_DLLPUBLIC TextEncodingTreeView
 {
 private:
-    std::unique_ptr<weld::ComboBox> m_xControl;
+    std::unique_ptr<weld::TreeView> m_xControl;
 
 public:
-    TextEncodingBox(std::unique_ptr<weld::ComboBox> pControl);
+    TextEncodingTreeView(std::unique_ptr<weld::TreeView> pControl);
 
-    ~TextEncodingBox();
+    ~TextEncodingTreeView();
 
     /** Fill with all known encodings but exclude those matching one or more
         given flags as defined in rtl/tencinfo.h
@@ -115,8 +157,29 @@ public:
             RTL_TEXTENCODING_GB_18030. Normally, this flag should be set to
             <TRUE/> whenever the box is used in import dialogs. */
     void                FillFromTextEncodingTable(
-                            bool bExcludeImportSubsets
-                            );
+                            bool bExcludeImportSubsets,
+                            sal_uInt32 nExcludeInfoFlags = 0);
+
+    /** Fill with all encodings known to the dbtools::OCharsetMap but exclude
+        those matching one or more given flags as defined in rtl/tencinfo.h
+
+         <p> If nButIncludeInfoFlags is given, encodings are included even if they
+         match nExcludeInfoFlags. Thus it is possible to exclude 16/32-bit
+         Unicode with RTL_TEXTENCODING_INFO_UNICODE but to include UTF7 and UTF8
+         with RTL_TEXTENCODING_INFO_MIME </p>
+
+        @param bExcludeImportSubsets
+            If <TRUE/>, some specific encodings are not listed, as they are a
+            subset of another encoding. This is the case for
+            RTL_TEXTENCODING_GB_2312, RTL_TEXTENCODING_GBK,
+            RTL_TEXTENCODING_MS_936, which are covered by
+            RTL_TEXTENCODING_GB_18030. Normally, this flag should be set to
+            <TRUE/> whenever the box is used in import dialogs. */
+    void                FillFromDbTextEncodingMap(
+                            bool bExcludeImportSubsets,
+                            sal_uInt32 nExcludeInfoFlags = 0);
+
+    void                InsertTextEncoding( const rtl_TextEncoding nEnc );
 
     void                InsertTextEncoding( const rtl_TextEncoding nEnc,
                             const OUString& rEntry );
@@ -125,10 +188,20 @@ public:
 
     rtl_TextEncoding    GetSelectTextEncoding() const;
 
-    void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_xControl->connect_changed(rLink); }
+    void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xControl->connect_changed(rLink); }
+    void connect_row_activated(const Link<weld::TreeView&, void>& rLink) { m_xControl->connect_row_activated(rLink); }
+    void grab_focus() { m_xControl->grab_focus(); }
+    void show() { m_xControl->show(); }
+    int get_height_rows(int nRows) const
+    {
+        return m_xControl->get_height_rows(nRows);
+    }
+    void set_size_request(int nWidth, int nHeight)
+    {
+        m_xControl->set_size_request(nWidth, nHeight);
+    }
 };
 
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx
index 495d8061751b..9b16e1a26af5 100644
--- a/sc/inc/scabstdlg.hxx
+++ b/sc/inc/scabstdlg.hxx
@@ -510,11 +510,11 @@ public:
                                                                   const OUString& rTabBgColorNoColorText, //Label for no tab color
                                                                   const Color& rDefaultColor) = 0; //Currently selected Color
 
-    virtual VclPtr<AbstractScImportOptionsDlg> CreateScImportOptionsDlg ( bool                    bAscii,
-                                                                    const ScImportOptions*  pOptions,
-                                                                    const OUString*         pStrTitle,
-                                                                    bool                    bOnlyDbtoolsEncodings,
-                                                                    bool                    bImport = true ) = 0;
+    virtual VclPtr<AbstractScImportOptionsDlg> CreateScImportOptionsDlg(weld::Window* pParent, bool bAscii,
+                                                                        const ScImportOptions*  pOptions,
+                                                                        const OUString*         pStrTitle,
+                                                                        bool                    bOnlyDbtoolsEncodings,
+                                                                        bool                    bImport = true ) = 0;
 
     virtual VclPtr<SfxAbstractTabDialog> CreateScAttrDlg(weld::Window* pParent,
                                                     const SfxItemSet* pCellAttrs) = 0;
diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx
index 14d40c76febf..bd39b1bb7be3 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -209,7 +209,10 @@ short AbstractScTabBgColorDlg_Impl::Execute()
     return m_xDlg->run();
 }
 
-IMPL_ABSTDLG_BASE(AbstractScImportOptionsDlg_Impl);
+short AbstractScImportOptionsDlg_Impl::Execute()
+{
+    return m_xDlg->run();
+}
 
 short AbstractScTextImportOptionsDlg_Impl::Execute()
 {
@@ -691,12 +694,12 @@ void AbstractScTabBgColorDlg_Impl::GetSelectedColor( Color& rColor ) const
 
 void AbstractScImportOptionsDlg_Impl::GetImportOptions( ScImportOptions& rOptions ) const
 {
-    pDlg->GetImportOptions(rOptions);
+    m_xDlg->GetImportOptions(rOptions);
 }
 
 void AbstractScImportOptionsDlg_Impl::SaveImportOptions() const
 {
-    pDlg->SaveImportOptions();
+    m_xDlg->SaveImportOptions();
 }
 
 LanguageType AbstractScTextImportOptionsDlg_Impl::GetLanguageType() const
@@ -967,15 +970,14 @@ VclPtr<AbstractScTabBgColorDlg> ScAbstractDialogFactory_Impl::CreateScTabBgColor
     return VclPtr<AbstractScTabBgColorDlg_Impl>::Create(std::make_unique<ScTabBgColorDlg>(pParent, rTitle, rTabBgColorNoColorText, rDefaultColor));
 }
 
-VclPtr<AbstractScImportOptionsDlg> ScAbstractDialogFactory_Impl::CreateScImportOptionsDlg (
-                                                                    bool                    bAscii,
-                                                                    const ScImportOptions*  pOptions,
-                                                                    const OUString*         pStrTitle,
-                                                                    bool                    bOnlyDbtoolsEncodings,
-                                                                    bool                    bImport )
+VclPtr<AbstractScImportOptionsDlg> ScAbstractDialogFactory_Impl::CreateScImportOptionsDlg(weld::Window* pParent,
+                                                                                          bool bAscii,
+                                                                                          const ScImportOptions* pOptions,
+                                                                                          const OUString* pStrTitle,
+                                                                                          bool bOnlyDbtoolsEncodings,
+                                                                                          bool bImport)
 {
-    VclPtr<ScImportOptionsDlg> pDlg = VclPtr<ScImportOptionsDlg>::Create( nullptr, bAscii, pOptions,pStrTitle, true/*bMultiByte*/,bOnlyDbtoolsEncodings, bImport );
-    return VclPtr<AbstractScImportOptionsDlg_Impl>::Create( pDlg );
+    return VclPtr<AbstractScImportOptionsDlg_Impl>::Create(std::make_unique<ScImportOptionsDlg>(pParent, bAscii, pOptions, pStrTitle, true/*bMultiByte*/, bOnlyDbtoolsEncodings, bImport));
 }
 
 VclPtr<SfxAbstractTabDialog> ScAbstractDialogFactory_Impl::CreateScAttrDlg(weld::Window* pParent, const SfxItemSet* pCellAttrs)
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx
index f134f9a1d294..e1eb091553d6 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -518,7 +518,14 @@ public:
 
 class AbstractScImportOptionsDlg_Impl : public AbstractScImportOptionsDlg
 {
-    DECL_ABSTDLG_BASE( AbstractScImportOptionsDlg_Impl, ScImportOptionsDlg)
+protected:
+    std::unique_ptr<ScImportOptionsDlg> m_xDlg;
+public:
+    explicit AbstractScImportOptionsDlg_Impl(std::unique_ptr<ScImportOptionsDlg> p)
+        : m_xDlg(std::move(p))
+    {
+    }
+    virtual short Execute() override;
     virtual void GetImportOptions( ScImportOptions& rOptions ) const override;
     virtual void SaveImportOptions() const override;
 };
@@ -691,11 +698,12 @@ public:
                                                                   const OUString& rTabBgColorNoColorText, //Label for no tab color
                                                                   const Color& rDefaultColor) override; //Currently selected Color
 
-    virtual VclPtr<AbstractScImportOptionsDlg> CreateScImportOptionsDlg ( bool                    bAscii,
-                                                                    const ScImportOptions*  pOptions,
-                                                                    const OUString*         pStrTitle,
-                                                                    bool                    bOnlyDbtoolsEncodings,
-                                                                    bool                    bImport = true ) override;
+    virtual VclPtr<AbstractScImportOptionsDlg> CreateScImportOptionsDlg(weld::Window* pParent, bool bAscii,
+                                                                        const ScImportOptions* pOptions,
+                                                                        const OUString* pStrTitle,
+                                                                        bool bOnlyDbtoolsEncodings,
+                                                                        bool bImport = true) override;
+
     virtual VclPtr<SfxAbstractTabDialog> CreateScAttrDlg(weld::Window* pParent,
                                                          const SfxItemSet* pCellAttrs) override;
 
diff --git a/sc/source/ui/dbgui/scuiimoptdlg.cxx b/sc/source/ui/dbgui/scuiimoptdlg.cxx
index c0db5f64ef63..9eba630d4298 100644
--- a/sc/source/ui/dbgui/scuiimoptdlg.cxx
+++ b/sc/source/ui/dbgui/scuiimoptdlg.cxx
@@ -88,42 +88,56 @@ OUString ScDelimiterTable::GetDelimiter( sal_Unicode nCode ) const
     return OUString();
 }
 
-// ScImportOptionsDlg
+void ScImportOptionsDlg::FillFromTextEncodingTable(bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags)
+{
+    if (m_bIsAsciiImport)
+        m_xLbCharset->FillFromTextEncodingTable(bExcludeImportSubsets, nExcludeInfoFlags);
+    else
+        m_xTvCharset->FillFromTextEncodingTable(bExcludeImportSubsets, nExcludeInfoFlags);
+}
 
-ScImportOptionsDlg::ScImportOptionsDlg(
-        vcl::Window*                 pParent,
-        bool                    bAscii,
-        const ScImportOptions*  pOptions,
-        const OUString*         pStrTitle,
-        bool                    bMultiByte,
-        bool                    bOnlyDbtoolsEncodings,
-        bool                    bImport )
-    :   ModalDialog ( pParent, "ImOptDialog",
-            "modules/scalc/ui/imoptdialog.ui" ),
-        m_bIsAsciiImport( bAscii )
+void ScImportOptionsDlg::FillFromDbTextEncodingMap(bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags)
+{
+    if (m_bIsAsciiImport)
+        m_xLbCharset->FillFromDbTextEncodingMap(bExcludeImportSubsets, nExcludeInfoFlags);
+    else
+        m_xTvCharset->FillFromDbTextEncodingMap(bExcludeImportSubsets, nExcludeInfoFlags);
+}
+
+// ScImportOptionsDlg
+ScImportOptionsDlg::ScImportOptionsDlg(weld::Window* pParent, bool bAscii,
+                                       const ScImportOptions*  pOptions,
+                                       const OUString* pStrTitle,
+                                       bool bMultiByte, bool bOnlyDbtoolsEncodings,
+                                       bool bImport)
+    : GenericDialogController(pParent, "modules/scalc/ui/imoptdialog.ui", "ImOptDialog")
+    , m_bIsAsciiImport(bAscii)
+    , m_xFieldFrame(m_xBuilder->weld_frame("fieldframe"))
+    , m_xFtCharset(m_xBuilder->weld_label("charsetft"))
+    , m_xEncGrid(m_xBuilder->weld_widget("grid2"))
+    , m_xFtFieldSep(m_xBuilder->weld_label("fieldft"))
+    , m_xEdFieldSep(m_xBuilder->weld_combo_box("field"))
+    , m_xFtTextSep(m_xBuilder->weld_label("textft"))
+    , m_xEdTextSep(m_xBuilder->weld_combo_box("text"))
+    , m_xCbShown(m_xBuilder->weld_check_button("asshown"))
+    , m_xCbFormulas(m_xBuilder->weld_check_button("formulas"))
+    , m_xCbQuoteAll(m_xBuilder->weld_check_button("quoteall"))
+    , m_xCbFixed(m_xBuilder->weld_check_button("fixedwidth"))
+    , m_xBtnOk(m_xBuilder->weld_button("ok"))
+    , m_xLbCharset(new TextEncodingBox(m_xBuilder->weld_combo_box("charsetdropdown")))
+    , m_xTvCharset(new TextEncodingTreeView(m_xBuilder->weld_tree_view("charsetlist")))
 {
-    get(m_pFieldFrame, "fieldframe");
-    get(m_pFtCharset, "charsetft");
     if (bAscii)
-        get(m_pLbCharset, "charsetdropdown");
+    {
+        m_xDialog->set_help_id(m_xDialog->get_help_id() + "?config=NonTextImport");
+        m_xLbCharset->show();
+    }
     else
     {
-        get(m_pLbCharset, "charsetlist");
-        m_pLbCharset->set_height_request(6 * m_pLbCharset->GetTextHeight());
-        get(m_pEncGrid, "grid2");
-        m_pEncGrid->set_vexpand(true);
+        m_xTvCharset->set_size_request(-1, m_xTvCharset->get_height_rows(6));
+        m_xEncGrid->set_vexpand(true);
+        m_xTvCharset->show();
     }
-    m_pLbCharset->SetStyle(m_pLbCharset->GetStyle() | WB_SORT);
-    m_pLbCharset->Show();
-    get(m_pFtFieldSep, "fieldft");
-    get(m_pEdFieldSep, "field");
-    get(m_pFtTextSep, "textft");
-    get(m_pEdTextSep, "text");
-    get(m_pCbShown, "asshown");
-    get(m_pCbFormulas, "formulas");
-    get(m_pCbQuoteAll, "quoteall");
-    get(m_pCbFixed, "fixedwidth");
-    get(m_pBtnOk, "ok");
 
     OUString sFieldSep(SCSTR_FIELDSEP);
     sFieldSep = sFieldSep.replaceFirst( "%TAB",   ScResId(SCSTR_FIELDSEP_TAB) );
@@ -136,37 +150,37 @@ ScImportOptionsDlg::ScImportOptionsDlg(
     OUString aStr = pFieldSepTab->FirstDel();
     sal_Unicode nCode;
 
-    while ( !aStr.isEmpty() )
+    while (!aStr.isEmpty())
     {
-        m_pEdFieldSep->InsertEntry( aStr );
+        m_xEdFieldSep->append_text(aStr);
         aStr = pFieldSepTab->NextDel();
     }
 
     aStr = pTextSepTab->FirstDel();
 
-    while ( !aStr.isEmpty() )
+    while (!aStr.isEmpty())
     {
-        m_pEdTextSep->InsertEntry( aStr );
+        m_xEdTextSep->append_text(aStr);
         aStr = pTextSepTab->NextDel();
     }
 
-    m_pEdFieldSep->SetText( m_pEdFieldSep->GetEntry(0) );
-    m_pEdTextSep->SetText( m_pEdTextSep->GetEntry(0) );
+    m_xEdFieldSep->set_active(0);
+    m_xEdTextSep->set_active(0);
 
     if ( bOnlyDbtoolsEncodings )
     {
         // Even dBase export allows multibyte now
         if ( bMultiByte )
-            m_pLbCharset->FillFromDbTextEncodingMap( bImport );
+            FillFromDbTextEncodingMap( bImport );
         else
-            m_pLbCharset->FillFromDbTextEncodingMap( bImport, RTL_TEXTENCODING_INFO_MULTIBYTE );
+            FillFromDbTextEncodingMap( bImport, RTL_TEXTENCODING_INFO_MULTIBYTE );
     }
     else if ( !bAscii )
     {   //!TODO: Unicode would need work in each filter
         if ( bMultiByte )
-            m_pLbCharset->FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE );
+            FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE );
         else
-            m_pLbCharset->FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE |
+            FillFromTextEncodingTable( bImport, RTL_TEXTENCODING_INFO_UNICODE |
                 RTL_TEXTENCODING_INFO_MULTIBYTE );
     }
     else
@@ -177,20 +191,20 @@ ScImportOptionsDlg::ScImportOptionsDlg(
             aStr  = pFieldSepTab->GetDelimiter( nCode );
 
             if ( aStr.isEmpty() )
-                m_pEdFieldSep->SetText( OUString(nCode) );
+                m_xEdFieldSep->set_entry_text(OUString(nCode));
             else
-                m_pEdFieldSep->SetText( aStr );
+                m_xEdFieldSep->set_entry_text(aStr);
 
             nCode = pOptions->nTextSepCode;
             aStr  = pTextSepTab->GetDelimiter( nCode );
 
             if ( aStr.isEmpty() )
-                m_pEdTextSep->SetText( OUString(nCode) );
+                m_xEdTextSep->set_entry_text(OUString(nCode));
             else
-                m_pEdTextSep->SetText( aStr );
+                m_xEdTextSep->set_entry_text(aStr);
         }
         // all encodings allowed, even Unicode
-        m_pLbCharset->FillFromTextEncodingTable( bImport );
+        FillFromTextEncodingTable( bImport );
     }
 
     if( bAscii )
@@ -203,99 +217,76 @@ ScImportOptionsDlg::ScImportOptionsDlg(
         bool bQuoteAllTextCells = officecfg::Office::Calc::Dialogs::CSVExport::QuoteAllTextCells::get();
         bool bFixedWidth = officecfg::Office::Calc::Dialogs::CSVExport::FixedWidth::get();
 
-        m_pCbFixed->Show();
-        m_pCbFixed->SetClickHdl( LINK( this, ScImportOptionsDlg, FixedWidthHdl ) );
-        m_pCbFixed->Check( bFixedWidth );
-        FixedWidthHdl(m_pCbFixed);
-        m_pCbShown->Show();
-        m_pCbShown->Check( bSaveTrueCellContent );
-        m_pCbQuoteAll->Show();
-        m_pCbQuoteAll->Check( bQuoteAllTextCells );
-        m_pCbFormulas->Show();
+        m_xCbFixed->show();
+        m_xCbFixed->connect_toggled(LINK(this, ScImportOptionsDlg, FixedWidthHdl));
+        m_xCbFixed->set_active( bFixedWidth );
+        FixedWidthHdl(*m_xCbFixed);
+        m_xCbShown->show();
+        m_xCbShown->set_active( bSaveTrueCellContent );
+        m_xCbQuoteAll->show();
+        m_xCbQuoteAll->set_active( bQuoteAllTextCells );
+        m_xCbFormulas->show();
         // default option for "save formulas" no longer taken from view shell but from persisted dialog settings
-        m_pCbFormulas->Check( bSaveCellFormulas );
+        m_xCbFormulas->set_active( bSaveCellFormulas );
         // if no charset, text separator or field separator exist, keep the values from dialog initialization
         if (strFieldSeparator.getLength() > 0)
-            m_pEdFieldSep->SetText( strFieldSeparator );
+            m_xEdFieldSep->set_entry_text(strFieldSeparator);
         if (strTextSeparator.getLength() > 0)
-            m_pEdTextSep->SetText( strTextSeparator );
+            m_xEdTextSep->set_entry_text(strTextSeparator);
         if (nCharSet < 0 || nCharSet == RTL_TEXTENCODING_DONTKNOW )
-            m_pLbCharset->SelectTextEncoding(pOptions ? pOptions->eCharSet : osl_getThreadTextEncoding());
+            m_xLbCharset->SelectTextEncoding(pOptions ? pOptions->eCharSet : osl_getThreadTextEncoding());
         else
-            m_pLbCharset->SelectTextEncoding(nCharSet);
+            m_xLbCharset->SelectTextEncoding(nCharSet);
     }
     else
     {
-        m_pFieldFrame->set_label(m_pFtCharset->GetText());
-        m_pFtFieldSep->Hide();
-        m_pFtTextSep->Hide();
-        m_pFtCharset->Hide();
-        m_pEdFieldSep->Hide();
-        m_pEdTextSep->Hide();
-        m_pCbFixed->Hide();
-        m_pCbShown->Hide();
-        m_pCbQuoteAll->Hide();
-        m_pCbFormulas->Hide();
-        m_pLbCharset->GrabFocus();
-        m_pLbCharset->SetDoubleClickHdl( LINK( this, ScImportOptionsDlg, DoubleClickHdl ) );
-
-        m_pLbCharset->SelectTextEncoding(pOptions ? pOptions->eCharSet :
-            osl_getThreadTextEncoding());
+        m_xFieldFrame->set_label(m_xFtCharset->get_label());
+        m_xFtFieldSep->hide();
+        m_xFtTextSep->hide();
+        m_xFtCharset->hide();
+        m_xEdFieldSep->hide();
+        m_xEdTextSep->hide();
+        m_xCbFixed->hide();
+        m_xCbShown->hide();
+        m_xCbQuoteAll->hide();
+        m_xCbFormulas->hide();
+        m_xTvCharset->grab_focus();
+        m_xTvCharset->connect_row_activated(LINK(this, ScImportOptionsDlg, DoubleClickHdl));
+        m_xTvCharset->SelectTextEncoding(pOptions ? pOptions->eCharSet : osl_getThreadTextEncoding());
     }
 
-
     // optional title:
-    if ( pStrTitle )
-        SetText( *pStrTitle );
+    if (pStrTitle)
+        m_xDialog->set_title(*pStrTitle);
 }
 
 ScImportOptionsDlg::~ScImportOptionsDlg()
 {
-    disposeOnce();
-}
-
-void ScImportOptionsDlg::dispose()
-{
-    pFieldSepTab.reset();
-    pTextSepTab.reset();
-    m_pEncGrid.clear();
-    m_pFieldFrame.clear();
-    m_pFtCharset.clear();
-    m_pLbCharset.clear();
-    m_pFtFieldSep.clear();
-    m_pEdFieldSep.clear();
-    m_pFtTextSep.clear();
-    m_pEdTextSep.clear();
-    m_pCbShown.clear();
-    m_pCbFormulas.clear();
-    m_pCbQuoteAll.clear();
-    m_pCbFixed.clear();
-    m_pBtnOk.clear();
-    ModalDialog::dispose();
 }
 
 void ScImportOptionsDlg::GetImportOptions( ScImportOptions& rOptions ) const
 {
-    rOptions.SetTextEncoding( m_pLbCharset->GetSelectTextEncoding() );
+    auto nEncoding = m_bIsAsciiImport ? m_xLbCharset->GetSelectTextEncoding() : m_xTvCharset->GetSelectTextEncoding();
+    rOptions.SetTextEncoding(nEncoding);
 
-    if ( m_pCbFixed->IsVisible() )
+    if (m_xCbFixed->get_visible())
     {
-        rOptions.nFieldSepCode = GetCodeFromCombo( *m_pEdFieldSep );
-        rOptions.nTextSepCode  = GetCodeFromCombo( *m_pEdTextSep );
-        rOptions.bFixedWidth = m_pCbFixed->IsChecked();
-        rOptions.bSaveAsShown = m_pCbShown->IsChecked();
-        rOptions.bQuoteAllText = m_pCbQuoteAll->IsChecked();
-        rOptions.bSaveFormulas = m_pCbFormulas->IsChecked();
+        rOptions.nFieldSepCode = GetCodeFromCombo( *m_xEdFieldSep );
+        rOptions.nTextSepCode  = GetCodeFromCombo( *m_xEdTextSep );
+        rOptions.bFixedWidth = m_xCbFixed->get_active();
+        rOptions.bSaveAsShown = m_xCbShown->get_active();
+        rOptions.bQuoteAllText = m_xCbQuoteAll->get_active();
+        rOptions.bSaveFormulas = m_xCbFormulas->get_active();
     }
 }
 
-sal_uInt16 ScImportOptionsDlg::GetCodeFromCombo( const ComboBox& rEd ) const
+sal_uInt16 ScImportOptionsDlg::GetCodeFromCombo(const weld::ComboBox& rEd) const
 {
     ScDelimiterTable* pTab;
-    OUString  aStr( rEd.GetText() );
+    OUString  aStr( rEd.get_active_text() );
     sal_uInt16  nCode;
 
-    if ( &rEd == m_pEdTextSep )
+    if (&rEd == m_xEdTextSep.get())
         pTab = pTextSepTab.get();
     else
         pTab = pFieldSepTab.get();
@@ -315,43 +306,33 @@ sal_uInt16 ScImportOptionsDlg::GetCodeFromCombo( const ComboBox& rEd ) const
     return nCode;
 }
 
-OString ScImportOptionsDlg::GetScreenshotId() const
+IMPL_LINK_NOARG(ScImportOptionsDlg, FixedWidthHdl, weld::ToggleButton&, void)
 {
-    return (m_bIsAsciiImport) ? GetHelpId() : GetHelpId() + "?config=NonTextImport";
+    bool bEnable = !m_xCbFixed->get_active();
+    m_xFtFieldSep->set_sensitive( bEnable );
+    m_xEdFieldSep->set_sensitive( bEnable );
+    m_xFtTextSep->set_sensitive( bEnable );
+    m_xEdTextSep->set_sensitive( bEnable );
+    m_xCbShown->set_sensitive( bEnable );
+    m_xCbQuoteAll->set_sensitive( bEnable );
 }
 
-IMPL_LINK( ScImportOptionsDlg, FixedWidthHdl, Button*, pCheckBox, void )
+IMPL_LINK_NOARG(ScImportOptionsDlg, DoubleClickHdl, weld::TreeView&, void)
 {
-    if (pCheckBox == m_pCbFixed)
-    {
-        bool bEnable = !m_pCbFixed->IsChecked();
-        m_pFtFieldSep->Enable( bEnable );
-        m_pEdFieldSep->Enable( bEnable );
-        m_pFtTextSep->Enable( bEnable );
-        m_pEdTextSep->Enable( bEnable );
-        m_pCbShown->Enable( bEnable );
-        m_pCbQuoteAll->Enable( bEnable );
-    }
-}
-
-IMPL_LINK( ScImportOptionsDlg, DoubleClickHdl, ListBox&, rLb, void )
-{
-    if (&rLb == m_pLbCharset)
-    {
-        m_pBtnOk->Click();
-    }
+    m_xDialog->response(RET_OK);
 }
 
 void ScImportOptionsDlg::SaveImportOptions() const
 {
     std::shared_ptr < comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create());
-    officecfg::Office::Calc::Dialogs::CSVExport::CharSet::set(m_pLbCharset->GetSelectTextEncoding(), batch);
-    officecfg::Office::Calc::Dialogs::CSVExport::FieldSeparator::set(m_pEdFieldSep->GetText(), batch);
-    officecfg::Office::Calc::Dialogs::CSVExport::TextSeparator::set(m_pEdTextSep->GetText(), batch);
-    officecfg::Office::Calc::Dialogs::CSVExport::FixedWidth::set(m_pCbFixed->IsChecked(), batch);
-    officecfg::Office::Calc::Dialogs::CSVExport::SaveCellFormulas::set(m_pCbFormulas->IsChecked(), batch);
-    officecfg::Office::Calc::Dialogs::CSVExport::SaveTrueCellContent::set(m_pCbShown->IsChecked(), batch);
-    officecfg::Office::Calc::Dialogs::CSVExport::QuoteAllTextCells::set(m_pCbQuoteAll->IsChecked(), batch);
+    auto nEncoding = m_bIsAsciiImport ? m_xLbCharset->GetSelectTextEncoding() : m_xTvCharset->GetSelectTextEncoding();
+    officecfg::Office::Calc::Dialogs::CSVExport::CharSet::set(nEncoding, batch);
+    officecfg::Office::Calc::Dialogs::CSVExport::FieldSeparator::set(m_xEdFieldSep->get_active_text(), batch);
+    officecfg::Office::Calc::Dialogs::CSVExport::TextSeparator::set(m_xEdTextSep->get_active_text(), batch);
+    officecfg::Office::Calc::Dialogs::CSVExport::FixedWidth::set(m_xCbFixed->get_active(), batch);
+    officecfg::Office::Calc::Dialogs::CSVExport::SaveCellFormulas::set(m_xCbFormulas->get_active(), batch);
+    officecfg::Office::Calc::Dialogs::CSVExport::SaveTrueCellContent::set(m_xCbShown->get_active(), batch);
+    officecfg::Office::Calc::Dialogs::CSVExport::QuoteAllTextCells::set(m_xCbQuoteAll->get_active(), batch);
     batch->commit();
 }
 
diff --git a/sc/source/ui/inc/scuiimoptdlg.hxx b/sc/source/ui/inc/scuiimoptdlg.hxx
index d97524a6dec6..8d9699c20375 100644
--- a/sc/source/ui/inc/scuiimoptdlg.hxx
+++ b/sc/source/ui/inc/scuiimoptdlg.hxx
@@ -20,57 +20,56 @@
 #ifndef INCLUDED_SC_SOURCE_UI_INC_SCUIIMOPTDLG_HXX
 #define INCLUDED_SC_SOURCE_UI_INC_SCUIIMOPTDLG_HXX
 
-#include <vcl/layout.hxx>
-#include <vcl/dialog.hxx>
+#include <vcl/weld.hxx>
 #include <svx/txencbox.hxx>
 
 class ScDelimiterTable;
 class ScImportOptions;
 
-class ScImportOptionsDlg : public ModalDialog
+class ScImportOptionsDlg : public weld::GenericDialogController
 {
 public:
-    ScImportOptionsDlg( vcl::Window*            pParent,
-                        bool                    bAscii,
-                        const ScImportOptions*  pOptions,
-                        const OUString*         pStrTitle,
-                        bool                    bMultiByte,
-                        bool                    bOnlyDbtoolsEncodings,
-                        bool                    bImport );
+    ScImportOptionsDlg(weld::Window*           pParent,
+                       bool                    bAscii,
+                       const ScImportOptions*  pOptions,
+                       const OUString*         pStrTitle,
+                       bool                    bMultiByte,
+                       bool                    bOnlyDbtoolsEncodings,
+                       bool                    bImport);
 
     virtual ~ScImportOptionsDlg() override;
-    virtual void dispose() override;
 
     void GetImportOptions( ScImportOptions& rOptions ) const;
     void SaveImportOptions() const;
-    virtual OString GetScreenshotId() const override;
 
 private:
-    VclPtr<VclFrame>           m_pFieldFrame;
-    VclPtr<FixedText>          m_pFtCharset;
-    VclPtr<VclContainer>       m_pEncGrid;
-    VclPtr<SvxTextEncodingBox> m_pLbCharset;
-    VclPtr<FixedText>          m_pFtFieldSep;
-    VclPtr<ComboBox>           m_pEdFieldSep;
-    VclPtr<FixedText>          m_pFtTextSep;
-    VclPtr<ComboBox>           m_pEdTextSep;
-    VclPtr<CheckBox>           m_pCbShown;
-    VclPtr<CheckBox>           m_pCbFormulas;
-    VclPtr<CheckBox>           m_pCbQuoteAll;
-    VclPtr<CheckBox>           m_pCbFixed;
-    VclPtr<OKButton>           m_pBtnOk;
-
-
     std::unique_ptr<ScDelimiterTable> pFieldSepTab;
     std::unique_ptr<ScDelimiterTable> pTextSepTab;
 
     bool const m_bIsAsciiImport;
 
+    std::unique_ptr<weld::Frame> m_xFieldFrame;
+    std::unique_ptr<weld::Label> m_xFtCharset;
+    std::unique_ptr<weld::Widget> m_xEncGrid;
+    std::unique_ptr<weld::Label> m_xFtFieldSep;
+    std::unique_ptr<weld::ComboBox> m_xEdFieldSep;
+    std::unique_ptr<weld::Label> m_xFtTextSep;
+    std::unique_ptr<weld::ComboBox> m_xEdTextSep;
+    std::unique_ptr<weld::CheckButton> m_xCbShown;
+    std::unique_ptr<weld::CheckButton> m_xCbFormulas;
+    std::unique_ptr<weld::CheckButton> m_xCbQuoteAll;
+    std::unique_ptr<weld::CheckButton> m_xCbFixed;
+    std::unique_ptr<weld::Button> m_xBtnOk;
+    std::unique_ptr<TextEncodingBox> m_xLbCharset;
+    std::unique_ptr<TextEncodingTreeView> m_xTvCharset;
+
 private:
-    sal_uInt16 GetCodeFromCombo( const ComboBox& rEd ) const;
+    sal_uInt16 GetCodeFromCombo( const weld::ComboBox& rEd ) const;
+    void FillFromTextEncodingTable(bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags = 0);
+    void FillFromDbTextEncodingMap(bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags = 0);
 
-    DECL_LINK( FixedWidthHdl, Button*, void );
-    DECL_LINK( DoubleClickHdl, ListBox&, void );
+    DECL_LINK(FixedWidthHdl, weld::ToggleButton&, void);
+    DECL_LINK(DoubleClickHdl, weld::TreeView&, void);
 };
 
 #endif
diff --git a/sc/source/ui/unoobj/filtuno.cxx b/sc/source/ui/unoobj/filtuno.cxx
index 947f59869903..2de9e1d5b190 100644
--- a/sc/source/ui/unoobj/filtuno.cxx
+++ b/sc/source/ui/unoobj/filtuno.cxx
@@ -316,7 +316,7 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute()
         }
         else
         {
-            ScopedVclPtr<AbstractScImportOptionsDlg> pDlg(pFact->CreateScImportOptionsDlg(
+            ScopedVclPtr<AbstractScImportOptionsDlg> pDlg(pFact->CreateScImportOptionsDlg(Application::GetFrameWeld(xDialogParent),
                                                                             bAscii, &aOptions, &aTitle,
                                                                             bDBEnc, !bExport));
             if ( pDlg->Execute() == RET_OK )
diff --git a/sc/uiconfig/scalc/ui/imoptdialog.ui b/sc/uiconfig/scalc/ui/imoptdialog.ui
index 2d065cc3bd8f..fe4526d65f32 100644
--- a/sc/uiconfig/scalc/ui/imoptdialog.ui
+++ b/sc/uiconfig/scalc/ui/imoptdialog.ui
@@ -1,13 +1,26 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.22.1 -->
 <interface domain="sc">
   <requires lib="gtk+" version="3.18"/>
-  <requires lib="LibreOffice" version="1.0"/>
+  <object class="GtkTreeStore" id="liststore1">
+    <columns>
+      <!-- column-name text -->
+      <column type="gchararray"/>
+      <!-- column-name id -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkDialog" id="ImOptDialog">
     <property name="can_focus">False</property>
     <property name="border_width">6</property>
     <property name="title" translatable="yes" context="imoptdialog|ImOptDialog">Import File</property>
+    <property name="modal">True</property>
+    <property name="default_width">0</property>
+    <property name="default_height">0</property>
     <property name="type_hint">dialog</property>
+    <child>
+      <placeholder/>
+    </child>
     <child internal-child="vbox">
       <object class="GtkBox" id="dialog-vbox1">
         <property name="can_focus">False</property>
@@ -22,6 +35,7 @@
                 <property name="label">gtk-ok</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="can_default">True</property>
                 <property name="has_default">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_stock">True</property>
@@ -37,6 +51,7 @@
                 <property name="label">gtk-cancel</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="can_default">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_stock">True</property>
               </object>
@@ -73,10 +88,10 @@
           <object class="GtkFrame" id="fieldframe">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="label_xalign">0</property>
-            <property name="shadow_type">none</property>
             <property name="hexpand">True</property>
             <property name="vexpand">True</property>
+            <property name="label_xalign">0</property>
+            <property name="shadow_type">none</property>
             <child>
               <object class="GtkAlignment" id="alignment1">
                 <property name="visible">True</property>
@@ -93,9 +108,9 @@
                       <object class="GtkLabel" id="charsetft">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
                         <property name="label" translatable="yes" context="imoptdialog|charsetft">_Character set:</property>
                         <property name="use_underline">True</property>
+                        <property name="xalign">0</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -106,10 +121,10 @@
                       <object class="GtkLabel" id="fieldft">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
                         <property name="label" translatable="yes" context="imoptdialog|fieldft">_Field delimiter:</property>
                         <property name="use_underline">True</property>
                         <property name="mnemonic_widget">field</property>
+                        <property name="xalign">0</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -120,10 +135,10 @@
                       <object class="GtkLabel" id="textft">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">0</property>
                         <property name="label" translatable="yes" context="imoptdialog|textft">Strin_g delimiter:</property>
                         <property name="use_underline">True</property>
                         <property name="mnemonic_widget">text</property>
+                        <property name="xalign">0</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -202,6 +217,7 @@
                         <child internal-child="entry">
                           <object class="GtkEntry" id="comboboxtext-entry">
                             <property name="can_focus">False</property>
+                            <property name="activates_default">True</property>
                           </object>
                         </child>
                       </object>
@@ -218,6 +234,7 @@
                         <child internal-child="entry">
                           <object class="GtkEntry" id="comboboxtext-entry2">
                             <property name="can_focus">True</property>
+                            <property name="activates_default">True</property>
                           </object>
                         </child>
                       </object>
@@ -232,23 +249,52 @@
                         <property name="can_focus">False</property>
                         <property name="hexpand">True</property>
                         <child>
-                          <object class="svxlo-SvxTextEncodingBox" id="charsetdropdown">
+                          <object class="GtkComboBoxText" id="charsetdropdown">
                             <property name="can_focus">False</property>
                             <property name="no_show_all">True</property>
                             <property name="hexpand">True</property>
-                           </object>
+                          </object>
                           <packing>
                             <property name="left_attach">0</property>
                             <property name="top_attach">0</property>
                           </packing>
                         </child>
                         <child>
-                          <object class="svxlo-SvxTextEncodingBox" id="charsetlist:border">
-                            <property name="dropdown">False</property>
-                            <property name="can_focus">False</property>
-                            <property name="no_show_all">True</property>
+                          <object class="GtkScrolledWindow">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
                             <property name="hexpand">True</property>
                             <property name="vexpand">True</property>
+                            <property name="hscrollbar_policy">never</property>
+                            <property name="shadow_type">in</property>
+                            <child>
+                              <object class="GtkTreeView" id="charsetlist">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="hexpand">True</property>
+                                <property name="vexpand">True</property>
+                                <property name="model">liststore1</property>
+                                <property name="headers_visible">False</property>
+                                <property name="search_column">0</property>
+                                <property name="show_expanders">False</property>
+                                <child internal-child="selection">
+                                  <object class="GtkTreeSelection" id="Macro Library List-selection2"/>
+                                </child>
+                                <child>
+                                  <object class="GtkTreeViewColumn" id="treeviewcolumn5">
+                                    <property name="resizable">True</property>
+                                    <property name="spacing">6</property>
+                                    <child>
+                                      <object class="GtkCellRendererText" id="cellrenderer4"/>
+                                      <attributes>
+                                        <attribute name="text">0</attribute>
+                                      </attributes>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
                           </object>
                           <packing>
                             <property name="left_attach">1</property>
@@ -270,6 +316,7 @@
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
                 <property name="label" translatable="yes" context="imoptdialog|label">Field Options</property>
+                <property name="use_underline">True</property>
                 <attributes>
                   <attribute name="weight" value="bold"/>
                 </attributes>
diff --git a/svx/source/dialog/txencbox.cxx b/svx/source/dialog/txencbox.cxx
index 16b2c1d33c1d..44899b9011b1 100644
--- a/svx/source/dialog/txencbox.cxx
+++ b/svx/source/dialog/txencbox.cxx
@@ -121,63 +121,85 @@ void SvxTextEncodingBox::FillFromTextEncodingTable(
     }
 }
 
-
-void SvxTextEncodingBox::FillFromDbTextEncodingMap(
-        bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags )
+namespace
 {
+    std::vector<rtl_TextEncoding> FillFromDbTextEncodingMap(bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags)
+    {
+        std::vector<rtl_TextEncoding> aRet;
 #if !HAVE_FEATURE_DBCONNECTIVITY
-    (void)bExcludeImportSubsets;
-    (void)nExcludeInfoFlags;
+        (void)bExcludeImportSubsets;
+        (void)nExcludeInfoFlags;
 #else
-    rtl_TextEncodingInfo aInfo;
-    aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
-    ::std::vector< rtl_TextEncoding > aEncs;
-    sal_Int32 nCount = svxform::charset_helper::getSupportedTextEncodings( aEncs );
-    for ( sal_Int32 j=0; j<nCount; j++ )
-    {
-        bool bInsert = true;
-        rtl_TextEncoding nEnc = rtl_TextEncoding( aEncs[j] );
-        if ( nExcludeInfoFlags )
+        rtl_TextEncodingInfo aInfo;
+        aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
+        ::std::vector< rtl_TextEncoding > aEncs;
+        sal_Int32 nCount = svxform::charset_helper::getSupportedTextEncodings( aEncs );
+        for ( sal_Int32 j=0; j<nCount; j++ )
         {
-            if ( !rtl_getTextEncodingInfo( nEnc, &aInfo ) )
-                bInsert = false;
-            else
+            bool bInsert = true;
+            rtl_TextEncoding nEnc = rtl_TextEncoding( aEncs[j] );
+            if ( nExcludeInfoFlags )
             {
-                if ( (aInfo.Flags & nExcludeInfoFlags) == 0 )
+                if ( !rtl_getTextEncodingInfo( nEnc, &aInfo ) )
+                    bInsert = false;
+                else
                 {
-                    if ( (nExcludeInfoFlags & RTL_TEXTENCODING_INFO_UNICODE) &&
-                            ((nEnc == RTL_TEXTENCODING_UCS2) ||
-                            nEnc == RTL_TEXTENCODING_UCS4) )
-                        bInsert = false;    // InfoFlags don't work for Unicode :-(
+                    if ( (aInfo.Flags & nExcludeInfoFlags) == 0 )
+                    {
+                        if ( (nExcludeInfoFlags & RTL_TEXTENCODING_INFO_UNICODE) &&
+                                ((nEnc == RTL_TEXTENCODING_UCS2) ||
+                                nEnc == RTL_TEXTENCODING_UCS4) )
+                            bInsert = false;    // InfoFlags don't work for Unicode :-(
+                    }
+                    else
+                        bInsert = false;
                 }
-                else
-                    bInsert = false;
             }
-        }
-        if ( bInsert )
-        {
-            if ( bExcludeImportSubsets )
+            if ( bInsert )
             {
-                switch ( nEnc )
+                if ( bExcludeImportSubsets )
                 {
-                    // subsets of RTL_TEXTENCODING_GB_18030
-                    case RTL_TEXTENCODING_GB_2312 :
-                    case RTL_TEXTENCODING_GBK :
-                    case RTL_TEXTENCODING_MS_936 :
-                        bInsert = false;
-                    break;
+                    switch ( nEnc )
+                    {
+                        // subsets of RTL_TEXTENCODING_GB_18030
+                        case RTL_TEXTENCODING_GB_2312 :
+                        case RTL_TEXTENCODING_GBK :
+                        case RTL_TEXTENCODING_MS_936 :
+                            bInsert = false;
+                        break;
+                    }
                 }
+                // CharsetMap offers a RTL_TEXTENCODING_DONTKNOW for internal use,
+                // makes no sense here and would result in an empty string as list
+                // entry.
+                if ( bInsert && nEnc != RTL_TEXTENCODING_DONTKNOW )
+                    aRet.push_back(nEnc);
             }
-            // CharsetMap offers a RTL_TEXTENCODING_DONTKNOW for internal use,
-            // makes no sense here and would result in an empty string as list
-            // entry.
-            if ( bInsert && nEnc != RTL_TEXTENCODING_DONTKNOW )
-                InsertTextEncoding( nEnc );
         }
-    }
 #endif
+        return aRet;
+    }
 }
 
+void TextEncodingBox::FillFromDbTextEncodingMap(
+        bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags )
+{
+    m_xControl->freeze();
+    auto aEncs = ::FillFromDbTextEncodingMap(bExcludeImportSubsets, nExcludeInfoFlags);
+    for (auto nEnc : aEncs)
+        InsertTextEncoding(nEnc);
+    m_xControl->thaw();
+}
+
+void TextEncodingTreeView::FillFromDbTextEncodingMap(
+        bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags )
+{
+    m_xControl->freeze();
+    auto aEncs = ::FillFromDbTextEncodingMap(bExcludeImportSubsets, nExcludeInfoFlags);
+    for (auto nEnc : aEncs)
+        InsertTextEncoding(nEnc);
+    m_xControl->thaw();
+}
 
 void SvxTextEncodingBox::FillWithMimeAndSelectBest()
 {
@@ -230,33 +252,91 @@ TextEncodingBox::TextEncodingBox(std::unique_ptr<weld::ComboBox> pControl)
     m_xControl->make_sorted();
 }
 
+TextEncodingTreeView::TextEncodingTreeView(std::unique_ptr<weld::TreeView> pControl)
+    : m_xControl(std::move(pControl))
+{
+    m_xControl->make_sorted();
+}
+
 TextEncodingBox::~TextEncodingBox()
 {
 }
 
-void TextEncodingBox::FillFromTextEncodingTable(
-        bool bExcludeImportSubsets )
+TextEncodingTreeView::~TextEncodingTreeView()
 {
-    m_xControl->freeze();
-    const sal_uInt32 nCount = SAL_N_ELEMENTS(RID_SVXSTR_TEXTENCODING_TABLE);
-    for (sal_uInt32 j = 0; j < nCount; ++j)
+}
+
+namespace
+{
+    std::vector<int> FillFromTextEncodingTable(bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags)
     {
-        bool bInsert = true;
-        rtl_TextEncoding nEnc = RID_SVXSTR_TEXTENCODING_TABLE[j].second;
-        if ( bExcludeImportSubsets )
+        std::vector<int> aRet;
+
+        rtl_TextEncodingInfo aInfo;
+        aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
+        const sal_uInt32 nCount = SAL_N_ELEMENTS(RID_SVXSTR_TEXTENCODING_TABLE);
+        for (sal_uInt32 j = 0; j < nCount; ++j)
         {
-            switch ( nEnc )
+            bool bInsert = true;
+            rtl_TextEncoding nEnc = RID_SVXSTR_TEXTENCODING_TABLE[j].second;
+            if ( nExcludeInfoFlags )
             {
-                // subsets of RTL_TEXTENCODING_GB_18030
-                case RTL_TEXTENCODING_GB_2312 :
-                case RTL_TEXTENCODING_GBK :
-                case RTL_TEXTENCODING_MS_936 :
+                if ( !rtl_getTextEncodingInfo( nEnc, &aInfo ) )
                     bInsert = false;
-                break;
+                else
+                {
+                    if ( (aInfo.Flags & nExcludeInfoFlags) == 0 )
+                    {
+                        if ( (nExcludeInfoFlags & RTL_TEXTENCODING_INFO_UNICODE) &&
+                                ((nEnc == RTL_TEXTENCODING_UCS2) ||
+                                nEnc == RTL_TEXTENCODING_UCS4) )
+                            bInsert = false;    // InfoFlags don't work for Unicode :-(
+                    }
+                    else
+                        bInsert = false;
+                }
+            }
+            if ( bExcludeImportSubsets )
+            {
+                switch ( nEnc )
+                {
+                    // subsets of RTL_TEXTENCODING_GB_18030
+                    case RTL_TEXTENCODING_GB_2312 :
+                    case RTL_TEXTENCODING_GBK :
+                    case RTL_TEXTENCODING_MS_936 :
+                        bInsert = false;
+                    break;
+                }
             }
+            if ( bInsert )
+                aRet.push_back(j);
         }
-        if ( bInsert )
-            InsertTextEncoding(nEnc, SvxResId(RID_SVXSTR_TEXTENCODING_TABLE[j].first));
+        return aRet;
+    }
+}
+
+void TextEncodingBox::FillFromTextEncodingTable(
+        bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags)
+{
+    std::vector<int> aRet(::FillFromTextEncodingTable(bExcludeImportSubsets, nExcludeInfoFlags));
+    m_xControl->freeze();
+    for (auto j : aRet)
+    {
+        rtl_TextEncoding nEnc = RID_SVXSTR_TEXTENCODING_TABLE[j].second;
+        InsertTextEncoding(nEnc, SvxResId(RID_SVXSTR_TEXTENCODING_TABLE[j].first));
+    }
+    m_xControl->thaw();
+}
+
+void TextEncodingTreeView::FillFromTextEncodingTable(
+        bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags)
+{
+    std::vector<int> aRet(::FillFromTextEncodingTable(bExcludeImportSubsets, nExcludeInfoFlags));
+    m_xControl->freeze();
+    for (auto j : aRet)
+    {
+        rtl_TextEncoding nEnc = RID_SVXSTR_TEXTENCODING_TABLE[j].second;
+        InsertTextEncoding(nEnc, SvxResId(RID_SVXSTR_TEXTENCODING_TABLE[j].first));
     }
     m_xControl->thaw();
 }
@@ -267,6 +347,30 @@ void TextEncodingBox::InsertTextEncoding( const rtl_TextEncoding nEnc,
     m_xControl->append(OUString::number(nEnc), rEntry);
 }
 
+void TextEncodingTreeView::InsertTextEncoding( const rtl_TextEncoding nEnc,
+            const OUString& rEntry )
+{
+    m_xControl->append(OUString::number(nEnc), rEntry);
+}
+
+void TextEncodingBox::InsertTextEncoding( const rtl_TextEncoding nEnc )
+{
+    const OUString& rEntry = SvxTextEncodingTable::GetTextString(nEnc);
+    if (!rEntry.isEmpty())
+        InsertTextEncoding( nEnc, rEntry );
+    else
+        SAL_WARN( "svx.dialog", "TextEncodingBox::InsertTextEncoding: no resource string for text encoding: " << static_cast<sal_Int32>( nEnc ) );
+}
+
+void TextEncodingTreeView::InsertTextEncoding( const rtl_TextEncoding nEnc )
+{
+    const OUString& rEntry = SvxTextEncodingTable::GetTextString(nEnc);
+    if (!rEntry.isEmpty())
+        InsertTextEncoding( nEnc, rEntry );
+    else
+        SAL_WARN( "svx.dialog", "TextEncodingTreeView::InsertTextEncoding: no resource string for text encoding: " << static_cast<sal_Int32>( nEnc ) );
+}
+
 rtl_TextEncoding TextEncodingBox::GetSelectTextEncoding() const
 {
     OUString sId(m_xControl->get_active_id());
@@ -276,9 +380,23 @@ rtl_TextEncoding TextEncodingBox::GetSelectTextEncoding() const
         return RTL_TEXTENCODING_DONTKNOW;
 }
 
+rtl_TextEncoding TextEncodingTreeView::GetSelectTextEncoding() const
+{
+    OUString sId(m_xControl->get_selected_id());
+    if (!sId.isEmpty())
+        return rtl_TextEncoding(sId.toInt32());
+    else
+        return RTL_TEXTENCODING_DONTKNOW;
+}
+
 void TextEncodingBox::SelectTextEncoding( const rtl_TextEncoding nEnc )
 {
     m_xControl->set_active_id(OUString::number(nEnc));
 }
 
+void TextEncodingTreeView::SelectTextEncoding( const rtl_TextEncoding nEnc )
+{
+    m_xControl->select_id(OUString::number(nEnc));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list