22 #include <com/sun/star/linguistic2/XLinguProperties.hpp>
31 #define HYPH_POS_CHAR '='
33 #define CUR_HYPH_POS_CHAR '-'
40 m_xWordEdit->get_selection_bounds(nStart, nEnd);
41 if (nStart == m_nOldPos && nEnd == m_nOldPos + 1)
44 if (nStart <= m_nOldPos)
45 bReSelect = !SelLeft();
47 bReSelect = !SelRight();
49 select_region(m_nOldPos, m_nOldPos + 1);
54 const sal_Int32 nLen = m_aEditWord.getLength();
56 m_xRightBtn->set_sensitive(
false);
57 for ( sal_Int32
i = m_nOldPos + 2;
i < nLen; ++
i )
61 m_xRightBtn->set_sensitive(
true);
66 DBG_ASSERT(m_nOldPos < nLen,
"nOldPos out of range");
67 if (m_nOldPos >= nLen)
69 m_xLeftBtn->set_sensitive(
false);
70 for ( sal_Int32
i = m_nOldPos;
i-- > 0; )
74 m_xLeftBtn->set_sensitive(
true);
110 DBG_ASSERT(m_xPossHyph.is(),
"missing possible hyphens");
111 if (m_xPossHyph.is())
113 DBG_ASSERT( m_aActWord == m_xPossHyph->getWord(),
"word mismatch" );
115 aTxt = m_xPossHyph->getPossibleHyphens();
117 m_nHyphenationPositionsOffset = 0;
118 uno::Sequence< sal_Int16 > aHyphenationPositions(
119 m_xPossHyph->getHyphenationPositions() );
120 sal_Int32 nLen = aHyphenationPositions.getLength();
121 const sal_Int16 *pHyphenationPos = aHyphenationPositions.getConstArray();
125 sal_Int32
nPos = 0, nPos1 = 0;
128 sal_Int32 nStart = 0;
129 for (sal_Int32
i = 0;
i < nLen; ++
i)
131 if (pHyphenationPos[
i] > m_nMaxHyphenationPos)
148 DBG_ASSERT(nIdx != -1,
"no usable hyphenation position");
151 nPos = nIdx == -1 ? 0 : nIdx + 1;
157 aTxt = aTxt.replaceFirst( aTmp,
"", &nPos);
161 const OUString aSearchRange( aTxt.copy( 0, nPos1 ) );
162 sal_Int32 nPos2 = aSearchRange.lastIndexOf(
'-' );
165 OUString aLeft( aSearchRange.copy( 0, nPos2 ) );
170 aLeft = aLeft.replaceFirst( aTmp,
"", &nPos );
172 ++m_nHyphenationPositionsOffset;
174 aTxt = aTxt.replaceAt( 0, nPos2, aLeft );
182 m_xPossHyph =
nullptr;
183 if (m_xHyphenator.is())
186 m_xPossHyph = m_xHyphenator->createPossibleHyphens( m_aActWord, aLocale,
187 uno::Sequence< beans::PropertyValue >() );
188 if (m_xPossHyph.is())
189 m_aEditWord = EraseUnusableHyphens_Impl();
191 m_xWordEdit->set_text(m_aEditWord);
193 m_nOldPos = m_aEditWord.getLength();
200 if ( nInsPos >= 0 && m_xPossHyph.is() )
204 DBG_ASSERT(nInsPos <= m_aEditWord.getLength() - 2,
"wrong hyphen position");
206 sal_Int32 nIdxPos = -1;
207 for (sal_Int32
i = 0;
i <= nInsPos; ++
i)
214 nIdxPos += m_nHyphenationPositionsOffset;
216 uno::Sequence< sal_Int16 >
aSeq = m_xPossHyph->getHyphenationPositions();
217 sal_Int32 nLen = aSeq.getLength();
219 DBG_ASSERT(0 <= nIdxPos && nIdxPos < nLen,
"index out of range");
220 if (nLen && 0 <= nIdxPos && nIdxPos < nLen)
222 nInsPos = aSeq.getConstArray()[ nIdxPos ];
223 m_pHyphWrapper->InsertHyphen( nInsPos );
229 m_pHyphWrapper->InsertHyphen( nInsPos );
233 if ( m_pHyphWrapper->FindSpellError() )
235 uno::Reference< linguistic2::XHyphenatedWord > xHyphWord( m_pHyphWrapper->GetLast(), uno::UNO_QUERY );
240 m_aActWord = xHyphWord->getWord();
241 m_nActLanguage =
LanguageTag( xHyphWord->getLocale() ).getLanguageType();
242 m_nMaxHyphenationPos = xHyphWord->getHyphenationPos();
244 SetWindowTitle( m_nActLanguage );
249 m_xCloseBtn->set_sensitive(
false);
257 DBG_ASSERT( m_nOldPos > 0,
"invalid hyphenation position" );
260 OUString aTxt( m_aEditWord );
261 for( sal_Int32
i = m_nOldPos - 1;
i > 0; --
i )
263 DBG_ASSERT(
i <= aTxt.getLength(),
"index out of range");
269 m_xWordEdit->set_text(aTxt);
270 select_region(
i,
i + 1);
271 m_xWordEdit->grab_focus();
284 OUString aTxt( m_aEditWord );
285 for ( sal_Int32
i = m_nOldPos + 1;
i < aTxt.getLength(); ++
i )
292 m_xWordEdit->set_text(aTxt);
293 select_region(
i,
i + 1);
294 m_xWordEdit->grab_focus();
308 ContinueHyph_Impl( m_nOldPos );
321 xProp->setIsHyphAuto(
true );
324 ContinueHyph_Impl( m_nOldPos );
327 xProp->setIsHyphAuto(
false );
329 catch (uno::Exception &)
331 SAL_WARN(
"cui.dialogs",
"Hyphenate All failed" );
341 ContinueHyph_Impl( 0 );
388 int nScrollPos = nStart + m_nWordEditWidth/2;
389 if (nScrollPos > m_aEditWord.getLength())
390 nScrollPos = m_aEditWord.getLength() - m_nWordEditWidth/2;
393 m_xWordEdit->set_position(nScrollPos);
394 m_xWordEdit->select_region(nStart, nEnd);
399 select_region(m_nOldPos, m_nOldPos + 1);
407 uno::Reference< linguistic2::XHyphenator >
const &xHyphen,
410 , m_pHyphWrapper(pWrapper)
412 , m_nActLanguage(nLang)
413 , m_nMaxHyphenationPos(0)
415 , m_nHyphenationPositionsOffset(0)
417 , m_xWordEdit(m_xBuilder->weld_entry(
"worded"))
418 , m_xLeftBtn(m_xBuilder->weld_button(
"left"))
419 , m_xRightBtn(m_xBuilder->weld_button(
"right"))
420 , m_xOkBtn(m_xBuilder->weld_button(
"ok"))
421 , m_xContBtn(m_xBuilder->weld_button(
"continue"))
422 , m_xDelBtn(m_xBuilder->weld_button(
"delete"))
423 , m_xHyphAll(m_xBuilder->weld_button(
"hyphall"))
424 , m_xCloseBtn(m_xBuilder->weld_button(
"close"))
430 uno::Reference< linguistic2::XHyphenatedWord > xHyphWord(
m_pHyphWrapper ?
432 DBG_ASSERT( xHyphWord.is(),
"hyphenation result missing" );
#define LINK(Instance, Class, Member)
LanguageType m_nActLanguage
std::unique_ptr< weld::Button > m_xCloseBtn
std::unique_ptr< weld::Button > m_xLeftBtn
static css::uno::Reference< css::linguistic2::XLinguProperties > GetLinguPropertySet()
void select_region(int nStart, int nEnd)
void ContinueHyph_Impl(sal_Int32 nInsPos=-1)
void SetWindowTitle(LanguageType nLang)
#define DBG_ASSERT(sCon, aError)
#define CUR_HYPH_POS_CHAR
std::unique_ptr< weld::Button > m_xHyphAll
std::unique_ptr< weld::Button > m_xContBtn
sal_Int16 m_nMaxHyphenationPos
const css::uno::Reference< css::uno::XInterface > & GetLast() const
IMPL_LINK_NOARG(SvxHyphenWordDialog, CursorChangeHdl_Impl, weld::Entry &, void)
SvxSpellWrapper *const m_pHyphWrapper
std::unique_ptr< weld::Entry > m_xWordEdit
Reference< XExecutableDialog > m_xDialog
Sequence< sal_Int8 > aSeq
std::unique_ptr< weld::Button > m_xDelBtn
static OUString GetLanguageString(const LanguageType eType)
virtual ~SvxHyphenWordDialog() override
#define SAL_WARN(area, stream)
OUString EraseUnusableHyphens_Impl()
css::uno::Reference< css::linguistic2::XHyphenator > m_xHyphenator
std::unique_ptr< weld::Button > m_xRightBtn
SvxHyphenWordDialog(const OUString &rWord, LanguageType nLang, weld::Window *pParent, css::uno::Reference< css::linguistic2::XHyphenator > const &xHyphen, SvxSpellWrapper *pWrapper)
std::unique_ptr< weld::Button > m_xOkBtn
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)