cui/source/dialogs/cuicharmap.cxx |   45 +++++++++-----------------------------
 include/cui/cuicharmap.hxx        |    6 ++---
 2 files changed, 14 insertions(+), 37 deletions(-)

New commits:
commit cb29cd301d6a493870d8efc233965658ae532206
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Apr 1 22:41:27 2023 +0300
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Mon Apr 3 16:59:55 2023 +0200

    tdf#153806 cui: Deduplicate code for special char dialog handlers
    
    Various handlers for `m_xShowSet` and `m_xSearchSet` are
    the same, except that they operate on the different objects.
    
    However, since a pointer to the `SvxShowCharSet`/`SvxSearchCharSet`
    is passed as an argument to the handler, use that
    and reuse the existing handlers instead of duplicating them.
    
    Also extract a `SvxCharacterMap::insertSelectedCharacter` method
    from the `CharDoubleClickHdl`, since that will be reused elsewhere
    in a follow-up commit for tdf#153806.
    
    Change-Id: I14e8e7fd7add33f86fa0246c65927ceb88bb7899
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149919
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/cui/source/dialogs/cuicharmap.cxx 
b/cui/source/dialogs/cuicharmap.cxx
index c6994000e36d..7bcbc463c26f 100644
--- a/cui/source/dialogs/cuicharmap.cxx
+++ b/cui/source/dialogs/cuicharmap.cxx
@@ -514,10 +514,10 @@ void SvxCharacterMap::init()
     m_xShowSet->SetPreSelectHdl( LINK( this, SvxCharacterMap, CharPreSelectHdl 
) );
     m_xShowSet->SetFavClickHdl( LINK( this, SvxCharacterMap, FavClickHdl ) );
 
-    m_xSearchSet->SetDoubleClickHdl( LINK( this, SvxCharacterMap, 
SearchCharDoubleClickHdl ) );
-    m_xSearchSet->SetSelectHdl( LINK( this, SvxCharacterMap, 
SearchCharSelectHdl ) );
+    m_xSearchSet->SetDoubleClickHdl( LINK( this, SvxCharacterMap, 
CharDoubleClickHdl ) );
+    m_xSearchSet->SetSelectHdl( LINK( this, SvxCharacterMap, CharSelectHdl ) );
     m_xSearchSet->SetHighlightHdl( LINK( this, SvxCharacterMap, 
SearchCharHighlightHdl ) );
-    m_xSearchSet->SetPreSelectHdl( LINK( this, SvxCharacterMap, 
SearchCharPreSelectHdl ) );
+    m_xSearchSet->SetPreSelectHdl( LINK( this, SvxCharacterMap, 
CharPreSelectHdl ) );
     m_xSearchSet->SetFavClickHdl( LINK( this, SvxCharacterMap, FavClickHdl ) );
 
     m_xDecimalCodeText->connect_changed( LINK( this, SvxCharacterMap, 
DecimalCodeChangeHdl ) );
@@ -921,22 +921,19 @@ IMPL_LINK(SvxCharacterMap, CharClickHdl, SvxCharView*, 
rView, void)
     m_xOKBtn->set_sensitive(true);
 }
 
-IMPL_LINK_NOARG(SvxCharacterMap, CharDoubleClickHdl, SvxShowCharSet*, void)
+void SvxCharacterMap::insertSelectedCharacter(const SvxShowCharSet* pCharSet)
 {
-    sal_UCS4 cChar = m_xShowSet->GetSelectCharacter();
+    assert(pCharSet);
+    sal_UCS4 cChar = pCharSet->GetSelectCharacter();
     // using the new UCS4 constructor
     OUString aOUStr( &cChar, 1 );
     setFavButtonState(aOUStr, aFont.GetFamilyName());
     insertCharToDoc(aOUStr);
 }
 
-IMPL_LINK_NOARG(SvxCharacterMap, SearchCharDoubleClickHdl, SvxShowCharSet*, 
void)
+IMPL_LINK(SvxCharacterMap, CharDoubleClickHdl, SvxShowCharSet*, pCharSet, void)
 {
-    sal_UCS4 cChar = m_xSearchSet->GetSelectCharacter();
-    // using the new UCS4 constructor
-    OUString aOUStr( &cChar, 1 );
-    setFavButtonState(aOUStr, aFont.GetFamilyName());
-    insertCharToDoc(aOUStr);
+    insertSelectedCharacter(pCharSet);
 }
 
 IMPL_LINK_NOARG(SvxCharacterMap, CharSelectHdl, SvxShowCharSet*, void)
@@ -944,11 +941,6 @@ IMPL_LINK_NOARG(SvxCharacterMap, CharSelectHdl, 
SvxShowCharSet*, void)
     m_xOKBtn->set_sensitive(true);
 }
 
-IMPL_LINK_NOARG(SvxCharacterMap, SearchCharSelectHdl, SvxShowCharSet*, void)
-{
-    m_xOKBtn->set_sensitive(true);
-}
-
 IMPL_LINK_NOARG(SvxCharacterMap, InsertClickHdl, weld::Button&, void)
 {
     OUString sChar = m_aShowChar.GetText();
@@ -1106,28 +1098,13 @@ IMPL_LINK_NOARG(SvxCharacterMap, HexCodeChangeHdl, 
weld::Entry&, void)
     selectCharByCode(Radix::hexadecimal);
 }
 
-IMPL_LINK_NOARG(SvxCharacterMap, CharPreSelectHdl, SvxShowCharSet*, void)
-{
-    // adjust subset selection
-    if( pSubsetMap )
-    {
-        sal_UCS4 cChar = m_xShowSet->GetSelectCharacter();
-
-        setFavButtonState(OUString(&cChar, 1), aFont.GetFamilyName());
-        const Subset* pSubset = pSubsetMap->GetSubsetByUnicode( cChar );
-        if( pSubset )
-            m_xSubsetLB->set_active_text(pSubset->GetName());
-    }
-
-    m_xOKBtn->set_sensitive(true);
-}
-
-IMPL_LINK_NOARG(SvxCharacterMap, SearchCharPreSelectHdl, SvxShowCharSet*, void)
+IMPL_LINK(SvxCharacterMap, CharPreSelectHdl, SvxShowCharSet*, pCharSet, void)
 {
+    assert(pCharSet);
     // adjust subset selection
     if( pSubsetMap )
     {
-        sal_UCS4 cChar = m_xSearchSet->GetSelectCharacter();
+        sal_UCS4 cChar = pCharSet->GetSelectCharacter();
 
         setFavButtonState(OUString(&cChar, 1), aFont.GetFamilyName());
         const Subset* pSubset = pSubsetMap->GetSubsetByUnicode( cChar );
diff --git a/include/cui/cuicharmap.hxx b/include/cui/cuicharmap.hxx
index 688fb570eff0..351382d71f53 100644
--- a/include/cui/cuicharmap.hxx
+++ b/include/cui/cuicharmap.hxx
@@ -120,6 +120,9 @@ private:
         hexadecimal = 16
     };
 
+    // inserts the character that is currently selected in the given 
SvxShowCharSet
+    void insertSelectedCharacter(const SvxShowCharSet* pCharSet);
+
     DECL_DLLPRIVATE_LINK(FontSelectHdl, weld::ComboBox&, void);
     DECL_DLLPRIVATE_LINK(SubsetSelectHdl, weld::ComboBox&, void);
     DECL_DLLPRIVATE_LINK(CharDoubleClickHdl, SvxShowCharSet*, void);
@@ -127,10 +130,7 @@ private:
     DECL_DLLPRIVATE_LINK(CharHighlightHdl, SvxShowCharSet*, void);
     DECL_DLLPRIVATE_LINK(CharPreSelectHdl, SvxShowCharSet*, void);
     DECL_DLLPRIVATE_LINK(FavClickHdl, SvxShowCharSet*, void);
-    DECL_DLLPRIVATE_LINK(SearchCharDoubleClickHdl, SvxShowCharSet*, void);
-    DECL_DLLPRIVATE_LINK(SearchCharSelectHdl, SvxShowCharSet*, void);
     DECL_DLLPRIVATE_LINK(SearchCharHighlightHdl, SvxShowCharSet*, void);
-    DECL_DLLPRIVATE_LINK(SearchCharPreSelectHdl, SvxShowCharSet*, void);
     DECL_DLLPRIVATE_LINK(DecimalCodeChangeHdl, weld::Entry&, void);
     DECL_DLLPRIVATE_LINK(HexCodeChangeHdl, weld::Entry&, void);
     DECL_DLLPRIVATE_LINK(CharClickHdl, SvxCharView*, void);

Reply via email to