diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-09-19 13:47:11 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-09-20 09:56:54 +0200 |
commit | 41db073808566641a3c364e6490f33b7f204d0b0 (patch) | |
tree | 56748a1212bf2f2f049a47d8815d15224aee34d4 /cui/source/dialogs/hyphen.cxx | |
parent | da9a539999fc8ae47a78542ce646005f3a9be868 (diff) |
weld SvxHyphenWordDialog
Change-Id: If92d57c5c807a7fc04fe66a748aa385c558be664
Reviewed-on: https://gerrit.libreoffice.org/60774
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'cui/source/dialogs/hyphen.cxx')
-rw-r--r-- | cui/source/dialogs/hyphen.cxx | 188 |
1 files changed, 80 insertions, 108 deletions
diff --git a/cui/source/dialogs/hyphen.cxx b/cui/source/dialogs/hyphen.cxx index ba55b4c3bc26..c519f755e3d6 100644 --- a/cui/source/dialogs/hyphen.cxx +++ b/cui/source/dialogs/hyphen.cxx @@ -33,49 +33,31 @@ using namespace css; -HyphenEdit::HyphenEdit(vcl::Window* pParent) - : Edit(pParent, WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK|WB_TABSTOP) +IMPL_LINK_NOARG(SvxHyphenWordDialog, CursorChangeHdl_Impl, weld::Entry&, void) { + int nStart, nEnd; + m_xWordEdit->get_selection_bounds(nStart, nEnd); + if (nStart == m_nOldPos && nEnd == m_nOldPos + 1) + return; + bool bReSelect; + if (nStart <= m_nOldPos) + bReSelect = !SelLeft(); + else + bReSelect = !SelRight(); + if (bReSelect) + select_region(m_nOldPos, m_nOldPos + 1); } -VCL_BUILDER_FACTORY(HyphenEdit) - -void HyphenEdit::KeyInput( const KeyEvent& rKEvt ) -{ - sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); - - switch ( nCode ) - { - case KEY_LEFT: - static_cast<SvxHyphenWordDialog*>( GetParentDialog() )->SelLeft(); - break; - - case KEY_RIGHT: - static_cast<SvxHyphenWordDialog*>( GetParentDialog() )->SelRight(); - break; - - case KEY_TAB: - case KEY_ESCAPE: - case KEY_RETURN: - Edit::KeyInput(rKEvt); - break; - default: - Control::KeyInput( rKEvt ); // pass on to the dialog - break; - } -} - - void SvxHyphenWordDialog::EnableLRBtn_Impl() { const sal_Int32 nLen = m_aEditWord.getLength(); - m_pRightBtn->Disable(); + m_xRightBtn->set_sensitive(false); for ( sal_Int32 i = m_nOldPos + 2; i < nLen; ++i ) { if ( m_aEditWord[ i ] == sal_Unicode( HYPH_POS_CHAR ) ) { - m_pRightBtn->Enable(); + m_xRightBtn->set_sensitive(true); break; } } @@ -83,18 +65,17 @@ void SvxHyphenWordDialog::EnableLRBtn_Impl() DBG_ASSERT(m_nOldPos < nLen, "nOldPos out of range"); if (m_nOldPos >= nLen) m_nOldPos = nLen - 1; - m_pLeftBtn->Disable(); + m_xLeftBtn->set_sensitive(false); for ( sal_Int32 i = m_nOldPos; i-- > 0; ) { if ( m_aEditWord[ i ] == sal_Unicode( HYPH_POS_CHAR ) ) { - m_pLeftBtn->Enable(); + m_xLeftBtn->set_sensitive(true); break; } } } - OUString SvxHyphenWordDialog::EraseUnusableHyphens_Impl() { // returns a String showing only those hyphen positions which will result @@ -195,7 +176,6 @@ OUString SvxHyphenWordDialog::EraseUnusableHyphens_Impl() return aTxt; } - void SvxHyphenWordDialog::InitControls_Impl() { m_xPossHyph = nullptr; @@ -207,14 +187,13 @@ void SvxHyphenWordDialog::InitControls_Impl() if (m_xPossHyph.is()) m_aEditWord = EraseUnusableHyphens_Impl(); } - m_pWordEdit->SetText( m_aEditWord ); + m_xWordEdit->set_text(m_aEditWord); m_nOldPos = m_aEditWord.getLength(); SelLeft(); EnableLRBtn_Impl(); } - void SvxHyphenWordDialog::ContinueHyph_Impl( sal_Int32 nInsPos ) { if ( nInsPos >= 0 && m_xPossHyph.is() ) @@ -266,14 +245,14 @@ void SvxHyphenWordDialog::ContinueHyph_Impl( sal_Int32 nInsPos ) } else { - m_pCloseBtn->Disable(); - EndDialog(RET_OK); + m_xCloseBtn->set_sensitive(false); + m_xDialog->response(RET_OK); } } - -void SvxHyphenWordDialog::SelLeft() +bool SvxHyphenWordDialog::SelLeft() { + bool bRet = false; DBG_ASSERT( m_nOldPos > 0, "invalid hyphenation position" ); if (m_nOldPos > 0) { @@ -286,19 +265,21 @@ void SvxHyphenWordDialog::SelLeft() aTxt = aTxt.replaceAt( i, 1, OUString( CUR_HYPH_POS_CHAR ) ); m_nOldPos = i; - m_pWordEdit->SetText( aTxt ); - m_pWordEdit->GrabFocus(); - m_pWordEdit->SetSelection( Selection( i, i + 1 ) ); + m_xWordEdit->set_text(aTxt); + select_region(i, i + 1); + m_xWordEdit->grab_focus(); + bRet = true; break; } } EnableLRBtn_Impl(); } + return bRet; } - -void SvxHyphenWordDialog::SelRight() +bool SvxHyphenWordDialog::SelRight() { + bool bRet = false; OUString aTxt( m_aEditWord ); for ( sal_Int32 i = m_nOldPos + 1; i < aTxt.getLength(); ++i ) { @@ -307,17 +288,18 @@ void SvxHyphenWordDialog::SelRight() aTxt = aTxt.replaceAt( i, 1, OUString( CUR_HYPH_POS_CHAR ) ); m_nOldPos = i; - m_pWordEdit->SetText( aTxt ); - m_pWordEdit->GrabFocus(); - m_pWordEdit->SetSelection( Selection( i, i + 1 ) ); + m_xWordEdit->set_text(aTxt); + select_region(i, i + 1); + m_xWordEdit->grab_focus(); + bRet = true; break; } } EnableLRBtn_Impl(); + return bRet; } - -IMPL_LINK_NOARG(SvxHyphenWordDialog, CutHdl_Impl, Button*, void) +IMPL_LINK_NOARG(SvxHyphenWordDialog, CutHdl_Impl, weld::Button&, void) { if( !m_bBusy ) { @@ -327,8 +309,7 @@ IMPL_LINK_NOARG(SvxHyphenWordDialog, CutHdl_Impl, Button*, void) } } - -IMPL_LINK_NOARG( SvxHyphenWordDialog, HyphenateAllHdl_Impl, Button *, void ) +IMPL_LINK_NOARG(SvxHyphenWordDialog, HyphenateAllHdl_Impl, weld::Button&, void) { if( !m_bBusy ) { @@ -351,8 +332,7 @@ IMPL_LINK_NOARG( SvxHyphenWordDialog, HyphenateAllHdl_Impl, Button *, void ) } } - -IMPL_LINK_NOARG(SvxHyphenWordDialog, DeleteHdl_Impl, Button*, void) +IMPL_LINK_NOARG(SvxHyphenWordDialog, DeleteHdl_Impl, weld::Button&, void) { if( !m_bBusy ) { @@ -362,8 +342,7 @@ IMPL_LINK_NOARG(SvxHyphenWordDialog, DeleteHdl_Impl, Button*, void) } } - -IMPL_LINK_NOARG(SvxHyphenWordDialog, ContinueHdl_Impl, Button*, void) +IMPL_LINK_NOARG(SvxHyphenWordDialog, ContinueHdl_Impl, weld::Button&, void) { if( !m_bBusy ) { @@ -373,19 +352,17 @@ IMPL_LINK_NOARG(SvxHyphenWordDialog, ContinueHdl_Impl, Button*, void) } } - -IMPL_LINK_NOARG(SvxHyphenWordDialog, CancelHdl_Impl, Button*, void) +IMPL_LINK_NOARG(SvxHyphenWordDialog, CancelHdl_Impl, weld::Button&, void) { if( !m_bBusy ) { m_bBusy = true; - EndDialog(); + m_xDialog->response(RET_CANCEL); m_bBusy = false; } } - -IMPL_LINK_NOARG(SvxHyphenWordDialog, Left_Impl, Button*, void) +IMPL_LINK_NOARG(SvxHyphenWordDialog, Left_Impl, weld::Button&, void) { if( !m_bBusy ) { @@ -395,8 +372,7 @@ IMPL_LINK_NOARG(SvxHyphenWordDialog, Left_Impl, Button*, void) } } - -IMPL_LINK_NOARG(SvxHyphenWordDialog, Right_Impl, Button*, void) +IMPL_LINK_NOARG(SvxHyphenWordDialog, Right_Impl, weld::Button&, void) { if( !m_bBusy ) { @@ -406,21 +382,30 @@ IMPL_LINK_NOARG(SvxHyphenWordDialog, Right_Impl, Button*, void) } } - -IMPL_LINK_NOARG(SvxHyphenWordDialog, GetFocusHdl_Impl, Control&, void) +void SvxHyphenWordDialog::select_region(int nStart, int nEnd) { - m_pWordEdit->SetSelection( Selection( m_nOldPos, m_nOldPos + 1 ) ); + int nScrollPos = nStart + m_nWordEditWidth/2; + if (nScrollPos > m_aEditWord.getLength()) + nScrollPos = m_aEditWord.getLength() - m_nWordEditWidth/2; + if (nScrollPos < 0) + nScrollPos = 0; + m_xWordEdit->set_position(nScrollPos); + m_xWordEdit->select_region(nStart, nEnd); } +IMPL_LINK_NOARG(SvxHyphenWordDialog, GetFocusHdl_Impl, weld::Widget&, void) +{ + select_region(m_nOldPos, m_nOldPos + 1); +} // class SvxHyphenWordDialog --------------------------------------------- SvxHyphenWordDialog::SvxHyphenWordDialog( const OUString &rWord, LanguageType nLang, - vcl::Window* pParent, + weld::Window* pParent, uno::Reference< linguistic2::XHyphenator > const &xHyphen, SvxSpellWrapper* pWrapper) - : SfxModalDialog(pParent, "HyphenateDialog", "cui/ui/hyphenate.ui") + : weld::GenericDialogController(pParent, "cui/ui/hyphenate.ui", "HyphenateDialog") , m_pHyphWrapper(pWrapper) , m_aActWord(rWord) , m_nActLanguage(nLang) @@ -428,17 +413,17 @@ SvxHyphenWordDialog::SvxHyphenWordDialog( , m_nOldPos(0) , m_nHyphenationPositionsOffset(0) , m_bBusy(false) + , m_xWordEdit(m_xBuilder->weld_entry("worded")) + , m_xLeftBtn(m_xBuilder->weld_button("left")) + , m_xRightBtn(m_xBuilder->weld_button("right")) + , m_xOkBtn(m_xBuilder->weld_button("ok")) + , m_xContBtn(m_xBuilder->weld_button("continue")) + , m_xDelBtn(m_xBuilder->weld_button("delete")) + , m_xHyphAll(m_xBuilder->weld_button("hyphall")) + , m_xCloseBtn(m_xBuilder->weld_button("close")) { - get(m_pWordEdit, "worded"); - get(m_pLeftBtn, "left"); - get(m_pRightBtn, "right"); - get(m_pOkBtn, "ok"); - get(m_pContBtn, "continue"); - get(m_pDelBtn, "delete"); - get(m_pHyphAll, "hyphall"); - get(m_pCloseBtn, "close"); - - m_aLabel = GetText(); + m_nWordEditWidth = m_xWordEdit->get_width_chars(); + m_aLabel = m_xDialog->get_title(); m_xHyphenator = xHyphen; uno::Reference< linguistic2::XHyphenatedWord > xHyphWord( m_pHyphWrapper ? @@ -452,47 +437,34 @@ SvxHyphenWordDialog::SvxHyphenWordDialog( } InitControls_Impl(); - m_pWordEdit->GrabFocus(); - - m_pLeftBtn->SetClickHdl( LINK( this, SvxHyphenWordDialog, Left_Impl ) ); - m_pRightBtn->SetClickHdl( LINK( this, SvxHyphenWordDialog, Right_Impl ) ); - m_pOkBtn->SetClickHdl( LINK( this, SvxHyphenWordDialog, CutHdl_Impl ) ); - m_pContBtn->SetClickHdl( LINK( this, SvxHyphenWordDialog, ContinueHdl_Impl ) ); - m_pDelBtn->SetClickHdl( LINK( this, SvxHyphenWordDialog, DeleteHdl_Impl ) ); - m_pHyphAll->SetClickHdl( LINK( this, SvxHyphenWordDialog, HyphenateAllHdl_Impl ) ); - m_pCloseBtn->SetClickHdl( LINK( this, SvxHyphenWordDialog, CancelHdl_Impl ) ); - m_pWordEdit->SetGetFocusHdl( LINK( this, SvxHyphenWordDialog, GetFocusHdl_Impl ) ); + m_xWordEdit->grab_focus(); + + m_xLeftBtn->connect_clicked( LINK( this, SvxHyphenWordDialog, Left_Impl ) ); + m_xRightBtn->connect_clicked( LINK( this, SvxHyphenWordDialog, Right_Impl ) ); + m_xOkBtn->connect_clicked( LINK( this, SvxHyphenWordDialog, CutHdl_Impl ) ); + m_xContBtn->connect_clicked( LINK( this, SvxHyphenWordDialog, ContinueHdl_Impl ) ); + m_xDelBtn->connect_clicked( LINK( this, SvxHyphenWordDialog, DeleteHdl_Impl ) ); + m_xHyphAll->connect_clicked( LINK( this, SvxHyphenWordDialog, HyphenateAllHdl_Impl ) ); + m_xCloseBtn->connect_clicked( LINK( this, SvxHyphenWordDialog, CancelHdl_Impl ) ); + m_xWordEdit->connect_focus_in( LINK( this, SvxHyphenWordDialog, GetFocusHdl_Impl ) ); + m_xWordEdit->connect_cursor_position( LINK( this, SvxHyphenWordDialog, CursorChangeHdl_Impl ) ); SetWindowTitle( nLang ); // disable controls if service is not available if (!m_xHyphenator.is()) - Enable( false ); + m_xDialog->set_sensitive(false); } SvxHyphenWordDialog::~SvxHyphenWordDialog() { - disposeOnce(); -} - -void SvxHyphenWordDialog::dispose() -{ - if (m_pCloseBtn->IsEnabled()) + if (m_xCloseBtn->get_sensitive()) m_pHyphWrapper->SpellEnd(); - m_pWordEdit.clear(); - m_pLeftBtn.clear(); - m_pRightBtn.clear(); - m_pOkBtn.clear(); - m_pContBtn.clear(); - m_pDelBtn.clear(); - m_pHyphAll.clear(); - m_pCloseBtn.clear(); - SfxModalDialog::dispose(); } -void SvxHyphenWordDialog::SetWindowTitle( LanguageType nLang ) +void SvxHyphenWordDialog::SetWindowTitle(LanguageType nLang) { - SetText( m_aLabel + " (" + SvtLanguageTable::GetLanguageString( nLang ) + ")" ); + m_xDialog->set_title(m_aLabel + " (" + SvtLanguageTable::GetLanguageString(nLang) + ")"); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |