xref: /aoo42x/main/sw/source/ui/lingu/hyp.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 
29 #include "initui.hxx"
30 #include "view.hxx"
31 #include "edtwin.hxx"
32 #include "wrtsh.hxx"
33 #include "globals.hrc"
34 #include <vcl/msgbox.hxx>
35 #ifndef _WRKWIN_HXX //autogen
36 #include <vcl/wrkwin.hxx>
37 #endif
38 #include <linguistic/lngprops.hxx>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <swwait.hxx>
41 
42 
43 #include "hyp.hxx"
44 #include "mdiexp.hxx"
45 #include "olmenu.hrc"
46 
47 #include <unomid.h>
48 
49 #define HYPHHERE 	'-'
50 #define PSH 		(&pView->GetWrtShell())
51 
52 using namespace ::com::sun::star;
53 using ::rtl::OUString;
54 
55 /*--------------------------------------------------------------------
56 	 Beschreibung: Interaktive Trennung
57  --------------------------------------------------------------------*/
58 
59 SwHyphWrapper::SwHyphWrapper( SwView* pVw,
60 			uno::Reference< linguistic2::XHyphenator >  &rxHyph,
61 			sal_Bool bStart, sal_Bool bOther, sal_Bool bSelect ) :
62 	SvxSpellWrapper( &pVw->GetEditWin(), rxHyph, bStart, bOther ),
63 	pView( pVw ),
64 	xHyph( rxHyph ),
65 	nLangError( 0 ),
66 	nPageCount( 0 ),
67 	nPageStart( 0 ),
68 	bInSelection( bSelect ),
69 	bShowError( sal_False ),
70     bInfoBox( sal_False )
71 {
72 	uno::Reference< beans::XPropertySet >  xProp( GetLinguPropertySet() );
73 	bAutomatic = xProp.is() ?
74 			*(sal_Bool*)xProp->getPropertyValue( C2U(UPN_IS_HYPH_AUTO) ).getValue() : sal_False;
75 	SetHyphen();
76 }
77 
78 // -----------------------------------------------------------------------
79 void SwHyphWrapper::SpellStart( SvxSpellArea eSpell )
80 {
81 	if( SVX_SPELL_OTHER == eSpell && nPageCount )
82 	{
83 		::EndProgress( pView->GetDocShell() );
84 		nPageCount = 0;
85 		nPageStart = 0;
86 	}
87 	pView->HyphStart( eSpell );
88 }
89 
90 // -----------------------------------------------------------------------
91 
92 sal_Bool SwHyphWrapper::SpellContinue()
93 {
94 	// Fuer autom. Trennung Aktionen erst am Ende sichtbar machen
95 	SwWait *pWait = 0;
96 	if( bAutomatic )
97 	{
98 		PSH->StartAllAction();
99 		pWait = new SwWait( *pView->GetDocShell(), sal_True );
100 	}
101 
102 		uno::Reference< uno::XInterface >  xHyphWord = bInSelection ?
103 				PSH->HyphContinue( NULL, NULL ) :
104 				PSH->HyphContinue( &nPageCount, &nPageStart );
105 		SetLast( xHyphWord );
106 
107 	// Fuer autom. Trennung Aktionen erst am Ende sichtbar machen
108 	if( bAutomatic )
109 	{
110 		PSH->EndAllAction();
111 		delete pWait;
112 	}
113 
114 	if( bShowError )
115 	{
116 		bShowError = sal_False;
117 		PSH->Push();
118 		PSH->ClearMark();
119 		pView->SpellError( &nLangError );
120 		PSH->Combine();
121 	}
122 	return GetLast().is();
123 }
124 
125 // -----------------------------------------------------------------------
126 void SwHyphWrapper::SpellEnd()
127 {
128 	PSH->HyphEnd();
129 	SvxSpellWrapper::SpellEnd();
130 }
131 
132 IMPL_LINK( SwHyphWrapper, SpellError, LanguageType *, pLang )
133 {
134 	if (pLang &&  *pLang != nLangError )
135 	{
136 		nLangError = *pLang;
137 		bShowError = sal_True;
138 	}
139 	return 0;
140 }
141 
142 
143 // -----------------------------------------------------------------------
144 sal_Bool SwHyphWrapper::SpellMore()
145 {
146     PSH->Push();
147     bInfoBox = sal_True;
148     PSH->Combine();
149 	return sal_False;
150 }
151 
152 // -----------------------------------------------------------------------
153 
154 void SwHyphWrapper::InsertHyphen( const sal_uInt16 nPos )
155 {
156 	if( nPos)
157 		PSH->InsertSoftHyph( nPos + 1);	// does nPos == 1 really mean
158 										// insert hyphen after first char?
159 										// (instead of nPos == 0)
160 	else
161 		PSH->HyphIgnore();
162 }
163 
164 // -----------------------------------------------------------------------
165 SwHyphWrapper::~SwHyphWrapper()
166 {
167 	if( nPageCount )
168 		::EndProgress( pView->GetDocShell() );
169     if( bInfoBox )
170         InfoBox( &pView->GetEditWin(), SW_RESSTR(STR_HYP_OK) ).Execute();
171 }
172 
173