[Libreoffice-commits] core.git: sfx2/inc sfx2/source sfx2/uiconfig

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Oct 5 10:20:55 UTC 2018


 sfx2/inc/srchdlg.hxx             |   42 ++++++--------
 sfx2/source/appl/newhelp.cxx     |   27 ++++-----
 sfx2/source/appl/newhelp.hxx     |    2 
 sfx2/source/dialog/srchdlg.cxx   |  110 ++++++++++++---------------------------
 sfx2/uiconfig/ui/searchdialog.ui |   18 ++++--
 5 files changed, 78 insertions(+), 121 deletions(-)

New commits:
commit faf6b466ab510ccee540953eebb790b6a57386e6
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Oct 4 17:06:50 2018 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Oct 5 12:20:28 2018 +0200

    weld modeless sfx SearchDialog
    
    Change-Id: I90a9b5dcf8878356b6666f8fe911d5dce9391904
    Reviewed-on: https://gerrit.libreoffice.org/61396
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sfx2/inc/srchdlg.hxx b/sfx2/inc/srchdlg.hxx
index 2dfab6612abc..42941356012b 100644
--- a/sfx2/inc/srchdlg.hxx
+++ b/sfx2/inc/srchdlg.hxx
@@ -32,52 +32,44 @@ namespace sfx2 {
 // SearchDialog
 
 
-class SearchDialog : public ModelessDialog
+class SearchDialog : public weld::GenericDialogController
 {
 private:
-    VclPtr<ComboBox>           m_pSearchEdit;
-    VclPtr<CheckBox>           m_pWholeWordsBox;
-    VclPtr<CheckBox>           m_pMatchCaseBox;
-    VclPtr<CheckBox>           m_pWrapAroundBox;
-    VclPtr<CheckBox>           m_pBackwardsBox;
-    VclPtr<PushButton>         m_pFindBtn;
-
     Link<SearchDialog&,void>   m_aFindHdl;
     Link<LinkParamNone*,void>  m_aCloseHdl;
 
     OUString            m_sConfigName;
-    OString             m_sWinState;
 
-    bool                m_bIsConstructed;
+    std::unique_ptr<weld::ComboBox> m_xSearchEdit;
+    std::unique_ptr<weld::CheckButton> m_xWholeWordsBox;
+    std::unique_ptr<weld::CheckButton> m_xMatchCaseBox;
+    std::unique_ptr<weld::CheckButton> m_xWrapAroundBox;
+    std::unique_ptr<weld::CheckButton> m_xBackwardsBox;
+    std::unique_ptr<weld::Button> m_xFindBtn;
 
     void                LoadConfig();
     void                SaveConfig();
 
-    DECL_LINK(FindHdl, Button *, void);
+    DECL_LINK(FindHdl, weld::Button&, void);
 
 public:
-    SearchDialog( vcl::Window* pWindow, const OUString& rConfigName );
+    SearchDialog(weld::Window* pWindow, const OUString& rConfigName);
+    static void runAsync(std::shared_ptr<SearchDialog>& rController);
     virtual ~SearchDialog() override;
-    virtual void dispose() override;
 
     void         SetFindHdl( const Link<SearchDialog&,void>& rLink ) { m_aFindHdl = rLink; }
     void         SetCloseHdl( const Link<LinkParamNone*,void>& rLink ) { m_aCloseHdl = rLink; }
 
-    OUString     GetSearchText() const { return m_pSearchEdit->GetText(); }
-    void         SetSearchText( const OUString& _rText ) { m_pSearchEdit->SetText( _rText ); }
-    bool         IsOnlyWholeWords() const { return m_pWholeWordsBox->IsChecked(); }
-    bool         IsMarchCase() const { return m_pMatchCaseBox->IsChecked(); }
-    bool         IsWrapAround() const { return m_pWrapAroundBox->IsChecked(); }
-    bool         IsSearchBackwards() const { return m_pBackwardsBox->IsChecked(); }
-
-    void            SetFocusOnEdit();
+    OUString     GetSearchText() const { return m_xSearchEdit->get_active_text(); }
+    void         SetSearchText( const OUString& _rText ) { m_xSearchEdit->set_entry_text( _rText ); }
+    bool         IsOnlyWholeWords() const { return m_xWholeWordsBox->get_active(); }
+    bool         IsMarchCase() const { return m_xMatchCaseBox->get_active(); }
+    bool         IsWrapAround() const { return m_xWrapAroundBox->get_active(); }
+    bool         IsSearchBackwards() const { return m_xBackwardsBox->get_active(); }
 
-    virtual bool    Close() override;
-    virtual void    Move() override;
-    virtual void    StateChanged( StateChangedType nStateChange ) override;
+    void         SetFocusOnEdit();
 };
 
-
 } // namespace sfx2
 
 
diff --git a/sfx2/source/appl/newhelp.cxx b/sfx2/source/appl/newhelp.cxx
index f2a28bb418ed..a7c7404cab32 100644
--- a/sfx2/source/appl/newhelp.cxx
+++ b/sfx2/source/appl/newhelp.cxx
@@ -1863,7 +1863,6 @@ SfxHelpTextWindow_Impl::SfxHelpTextWindow_Impl( SfxHelpWindow_Impl* pParent ) :
     aOnStartupText      ( SfxResId( RID_HELP_ONSTARTUP_TEXT ) ),
     pHelpWin            ( pParent ),
     pTextWin            ( VclPtr<TextWin_Impl>::Create( this ) ),
-    pSrchDlg            ( nullptr ),
     nMinPos             ( 0 ),
     bIsDebug            ( false ),
     bIsIndexOn          ( false ),
@@ -1924,7 +1923,7 @@ void SfxHelpTextWindow_Impl::dispose()
 
     bIsInClose = true;
     SvtMiscOptions().RemoveListenerLink( LINK( this, SfxHelpTextWindow_Impl, NotifyHdl ) );
-    pSrchDlg.disposeAndClear();
+    m_xSrchDlg.reset();
     aToolBox.disposeAndClear();
     aOnStartupCB.disposeAndClear();
     pHelpWin.clear();
@@ -2205,7 +2204,7 @@ void SfxHelpTextWindow_Impl::FindHdl(sfx2::SearchDialog* pDlg)
 {
     bool bWrapAround = ( nullptr == pDlg );
     if ( bWrapAround )
-        pDlg = pSrchDlg;
+        pDlg = m_xSrchDlg.get();
     DBG_ASSERT( pDlg, "invalid search dialog" );
     OUString sSearchText = pDlg->GetSearchText();
     try
@@ -2265,11 +2264,11 @@ void SfxHelpTextWindow_Impl::FindHdl(sfx2::SearchDialog* pDlg)
                 }
                 else
                 {
-                    assert(pSrchDlg && "no search dialog");
-                    std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pSrchDlg->GetFrameWeld(),
+                    assert(m_xSrchDlg && "no search dialog");
+                    std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xSrchDlg->getDialog(),
                                                               VclMessageType::Info, VclButtonsType::Ok, SfxResId(STR_INFO_NOSEARCHTEXTFOUND)));
                     xBox->run();
-                    pSrchDlg->SetFocusOnEdit();
+                    m_xSrchDlg->SetFocusOnEdit();
                 }
             }
         }
@@ -2280,13 +2279,11 @@ void SfxHelpTextWindow_Impl::FindHdl(sfx2::SearchDialog* pDlg)
     }
 }
 
-
 IMPL_LINK_NOARG( SfxHelpTextWindow_Impl, CloseHdl, LinkParamNone*, void )
 {
-    pSrchDlg.clear();
+    m_xSrchDlg.reset();
 }
 
-
 IMPL_LINK( SfxHelpTextWindow_Impl, CheckHdl, Button*, pButton, void )
 {
     CheckBox* pBox = static_cast<CheckBox*>(pButton);
@@ -2571,22 +2568,22 @@ void SfxHelpTextWindow_Impl::CloseFrame()
 
 void SfxHelpTextWindow_Impl::DoSearch()
 {
-    if ( !pSrchDlg )
+    if (!m_xSrchDlg)
     {
         // create the search dialog
-        pSrchDlg = VclPtr<sfx2::SearchDialog>::Create( pTextWin, "HelpSearchDialog" );
+        m_xSrchDlg.reset(new sfx2::SearchDialog(pTextWin->GetFrameWeld(), "HelpSearchDialog"));
         // set handler
-        pSrchDlg->SetFindHdl( LINK( this, SfxHelpTextWindow_Impl, FindHdl ) );
-        pSrchDlg->SetCloseHdl( LINK( this, SfxHelpTextWindow_Impl, CloseHdl ) );
+        m_xSrchDlg->SetFindHdl( LINK( this, SfxHelpTextWindow_Impl, FindHdl ) );
+        m_xSrchDlg->SetCloseHdl( LINK( this, SfxHelpTextWindow_Impl, CloseHdl ) );
         // get selected text of the help page to set it as the search text
         Reference< XTextRange > xCursor = getCursor();
         if ( xCursor.is() )
         {
             OUString sText = xCursor->getString();
             if ( !sText.isEmpty() )
-                pSrchDlg->SetSearchText( sText );
+                m_xSrchDlg->SetSearchText( sText );
         }
-        pSrchDlg->Show();
+        sfx2::SearchDialog::runAsync(m_xSrchDlg);
     }
 }
 
diff --git a/sfx2/source/appl/newhelp.hxx b/sfx2/source/appl/newhelp.hxx
index 133502e6fef8..fa660cd5f01c 100644
--- a/sfx2/source/appl/newhelp.hxx
+++ b/sfx2/source/appl/newhelp.hxx
@@ -433,7 +433,7 @@ private:
 
     VclPtr<SfxHelpWindow_Impl>     pHelpWin;
     VclPtr<vcl::Window>            pTextWin;
-    VclPtr<sfx2::SearchDialog>     pSrchDlg;
+    std::shared_ptr<sfx2::SearchDialog> m_xSrchDlg;
     css::uno::Reference < css::frame::XFrame2 >
                             xFrame;
     css::uno::Reference< css::i18n::XBreakIterator >
diff --git a/sfx2/source/dialog/srchdlg.cxx b/sfx2/source/dialog/srchdlg.cxx
index 66c6dbaae171..fe91d230fb47 100644
--- a/sfx2/source/dialog/srchdlg.cxx
+++ b/sfx2/source/dialog/srchdlg.cxx
@@ -36,42 +36,27 @@ namespace sfx2 {
 // SearchDialog
 
 
-SearchDialog::SearchDialog(vcl::Window* pWindow, const OUString& rConfigName)
-    : ModelessDialog(pWindow, "SearchDialog", "sfx/ui/searchdialog.ui")
+SearchDialog::SearchDialog(weld::Window* pWindow, const OUString& rConfigName)
+    : GenericDialogController(pWindow, "sfx/ui/searchdialog.ui", "SearchDialog")
     , m_sConfigName(rConfigName)
-    , m_bIsConstructed(false)
-
+    , m_xSearchEdit(m_xBuilder->weld_combo_box("searchterm"))
+    , m_xWholeWordsBox(m_xBuilder->weld_check_button("wholewords"))
+    , m_xMatchCaseBox(m_xBuilder->weld_check_button("matchcase"))
+    , m_xWrapAroundBox(m_xBuilder->weld_check_button("wrap"))
+    , m_xBackwardsBox(m_xBuilder->weld_check_button("backwards"))
+    , m_xFindBtn(m_xBuilder->weld_button("ok"))
 {
-    get(m_pSearchEdit, "searchterm");
-    get(m_pWholeWordsBox, "wholewords");
-    get(m_pMatchCaseBox, "matchcase");
-    get(m_pWrapAroundBox, "wrap");
-    get(m_pBackwardsBox, "backwards");
-    get(m_pFindBtn, "search");
-
     // set handler
-    m_pFindBtn->SetClickHdl( LINK( this, SearchDialog, FindHdl ) );
+    m_xFindBtn->connect_clicked(LINK(this, SearchDialog, FindHdl));
     // load config: old search strings and the status of the check boxes
     LoadConfig();
     // the search edit should have the focus
-    m_pSearchEdit->GrabFocus();
+    m_xSearchEdit->grab_focus();
 }
 
 SearchDialog::~SearchDialog()
 {
-    disposeOnce();
-}
-
-void SearchDialog::dispose()
-{
     SaveConfig();
-    m_pSearchEdit.clear();
-    m_pWholeWordsBox.clear();
-    m_pMatchCaseBox.clear();
-    m_pWrapAroundBox.clear();
-    m_pBackwardsBox.clear();
-    m_pFindBtn.clear();
-    ModelessDialog::dispose();
 }
 
 void SearchDialog::LoadConfig()
@@ -79,7 +64,6 @@ void SearchDialog::LoadConfig()
     SvtViewOptions aViewOpt( EViewType::Dialog, m_sConfigName );
     if ( aViewOpt.Exists() )
     {
-        m_sWinState = OUStringToOString(aViewOpt.GetWindowState(), RTL_TEXTENCODING_ASCII_US);
         Any aUserItem = aViewOpt.GetUserItem( "UserItem" );
         OUString sUserData;
         if ( aUserItem >>= sUserData )
@@ -87,91 +71,69 @@ void SearchDialog::LoadConfig()
             DBG_ASSERT( comphelper::string::getTokenCount(sUserData, ';') == 5, "invalid config data" );
             sal_Int32 nIdx = 0;
             OUString sSearchText = sUserData.getToken( 0, ';', nIdx );
-            m_pWholeWordsBox->Check( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
-            m_pMatchCaseBox->Check( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
-            m_pWrapAroundBox->Check( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
-            m_pBackwardsBox->Check( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
+            m_xWholeWordsBox->set_active( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
+            m_xMatchCaseBox->set_active( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
+            m_xWrapAroundBox->set_active( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
+            m_xBackwardsBox->set_active( sUserData.getToken( 0, ';', nIdx ).toInt32() == 1 );
 
             nIdx = 0;
             while ( nIdx != -1 )
-                m_pSearchEdit->InsertEntry( sSearchText.getToken( 0, '\t', nIdx ) );
-            m_pSearchEdit->SelectEntryPos(0);
+                m_xSearchEdit->append_text(sSearchText.getToken( 0, '\t', nIdx));
+            m_xSearchEdit->set_active(0);
         }
     }
     else
-        m_pWrapAroundBox->Check();
+        m_xWrapAroundBox->set_active(true);
 }
 
 void SearchDialog::SaveConfig()
 {
     SvtViewOptions aViewOpt( EViewType::Dialog, m_sConfigName );
-    aViewOpt.SetWindowState(OStringToOUString(m_sWinState, RTL_TEXTENCODING_ASCII_US));
     OUString sUserData;
-    sal_Int32 i = 0, nCount = std::min( m_pSearchEdit->GetEntryCount(), static_cast<sal_Int32>(MAX_SAVE_COUNT) );
+    int i = 0, nCount = std::min(m_xSearchEdit->get_count(), static_cast<int>(MAX_SAVE_COUNT));
     for ( ; i < nCount; ++i )
     {
-        sUserData += m_pSearchEdit->GetEntry(i);
+        sUserData += m_xSearchEdit->get_text(i);
         sUserData += "\t";
     }
     sUserData = comphelper::string::stripStart(sUserData, '\t');
     sUserData += ";";
-    sUserData += OUString::number( m_pWholeWordsBox->IsChecked() ? 1 : 0 );
+    sUserData += OUString::number( m_xWholeWordsBox->get_active() ? 1 : 0 );
     sUserData += ";";
-    sUserData += OUString::number( m_pMatchCaseBox->IsChecked() ? 1 : 0 );
+    sUserData += OUString::number( m_xMatchCaseBox->get_active() ? 1 : 0 );
     sUserData += ";";
-    sUserData += OUString::number( m_pWrapAroundBox->IsChecked() ? 1 : 0 );
+    sUserData += OUString::number( m_xWrapAroundBox->get_active() ? 1 : 0 );
     sUserData += ";";
-    sUserData += OUString::number( m_pBackwardsBox->IsChecked() ? 1 : 0 );
+    sUserData += OUString::number( m_xBackwardsBox->get_active() ? 1 : 0 );
 
     Any aUserItem = makeAny( sUserData );
     aViewOpt.SetUserItem( "UserItem", aUserItem );
 }
 
-IMPL_LINK_NOARG(SearchDialog, FindHdl, Button*, void)
+IMPL_LINK_NOARG(SearchDialog, FindHdl, weld::Button&, void)
 {
-    OUString sSrchTxt = m_pSearchEdit->GetText();
-    sal_Int32 nPos = m_pSearchEdit->GetEntryPos( sSrchTxt );
-    if ( nPos > 0 && nPos != COMBOBOX_ENTRY_NOTFOUND )
-        m_pSearchEdit->RemoveEntryAt(nPos);
-    if ( nPos > 0 )
-        m_pSearchEdit->InsertEntry( sSrchTxt, 0 );
+    OUString sSrchTxt = m_xSearchEdit->get_active_text();
+    auto nPos = m_xSearchEdit->find_text(sSrchTxt);
+    if (nPos != 0)
+    {
+        if (nPos != -1)
+            m_xSearchEdit->remove(nPos);
+        m_xSearchEdit->insert_text(0, sSrchTxt);
+    }
     m_aFindHdl.Call( *this );
 }
 
 void SearchDialog::SetFocusOnEdit()
 {
-    Selection aSelection( 0, m_pSearchEdit->GetText().getLength() );
-    m_pSearchEdit->SetSelection( aSelection );
-    m_pSearchEdit->GrabFocus();
+    m_xSearchEdit->select_entry_region(0, -1);
+    m_xSearchEdit->grab_focus();
 }
 
-bool SearchDialog::Close()
+void SearchDialog::runAsync(std::shared_ptr<SearchDialog>& rController)
 {
-    bool bRet = ModelessDialog::Close();
-    m_aCloseHdl.Call( nullptr );
-    return bRet;
+    weld::DialogController::runAsync(rController, [=](sal_Int32 /*nResult*/){ rController->m_aCloseHdl.Call(nullptr); });
 }
 
-void SearchDialog::StateChanged( StateChangedType nStateChange )
-{
-    if ( nStateChange == StateChangedType::InitShow )
-    {
-        if (!m_sWinState.isEmpty())
-            SetWindowState( m_sWinState );
-        m_bIsConstructed = true;
-    }
-
-    ModelessDialog::StateChanged( nStateChange );
-}
-
-void SearchDialog::Move()
-{
-    ModelessDialog::Move();
-    if ( m_bIsConstructed && IsReallyVisible() )
-        m_sWinState = GetWindowState( WindowStateMask::Pos | WindowStateMask::State );
-}
-
-
 } // namespace sfx2
 
 
diff --git a/sfx2/uiconfig/ui/searchdialog.ui b/sfx2/uiconfig/ui/searchdialog.ui
index a8468aa1e54f..8445eabb5bc9 100644
--- a/sfx2/uiconfig/ui/searchdialog.ui
+++ b/sfx2/uiconfig/ui/searchdialog.ui
@@ -1,12 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.18.3 -->
+<!-- Generated with glade 3.22.1 -->
 <interface domain="sfx">
   <requires lib="gtk+" version="3.18"/>
   <object class="GtkDialog" id="SearchDialog">
     <property name="can_focus">False</property>
     <property name="border_width">6</property>
     <property name="title" translatable="yes" context="searchdialog|SearchDialog">Find on this Page</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-vbox3">
         <property name="can_focus">False</property>
@@ -17,7 +22,7 @@
             <property name="can_focus">False</property>
             <property name="layout_style">end</property>
             <child>
-              <object class="GtkButton" id="search">
+              <object class="GtkButton" id="ok">
                 <property name="label" translatable="yes" context="searchdialog|search">_Find</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -68,7 +73,7 @@
                 <property name="can_focus">False</property>
                 <property name="row_spacing">6</property>
                 <child>
-                  <object class="GtkComboBox" id="searchterm">
+                  <object class="GtkComboBoxText" id="searchterm">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="valign">center</property>
@@ -76,7 +81,8 @@
                     <property name="has_entry">True</property>
                     <child internal-child="entry">
                       <object class="GtkEntry" id="combobox-entry1">
-                        <property name="can_focus">False</property>
+                        <property name="can_focus">True</property>
+                        <property name="activates_default">True</property>
                       </object>
                     </child>
                   </object>
@@ -89,10 +95,10 @@
                   <object class="GtkLabel" id="label1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
                     <property name="label" translatable="yes" context="searchdialog|label1">_Search for:</property>
                     <property name="use_underline">True</property>
                     <property name="mnemonic_widget">searchterm</property>
+                    <property name="xalign">0</property>
                   </object>
                   <packing>
                     <property name="left_attach">0</property>
@@ -189,7 +195,7 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="0">search</action-widget>
+      <action-widget response="101">ok</action-widget>
       <action-widget response="-7">close</action-widget>
     </action-widgets>
   </object>


More information about the Libreoffice-commits mailing list