xref: /aoo42x/main/sd/source/ui/func/futhes.cxx (revision 79aad27f)
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_sd.hxx"
26 
27 
28 #include "futhes.hxx"
29 
30 #include <tools/pstm.hxx>
31 #include <editeng/outliner.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <svx/svdobj.hxx>
34 #include <svx/svdotext.hxx>
35 #include <editeng/eeitem.hxx>
36 
37 #include <svx/dialogs.hrc>
38 #include <svx/svxerr.hxx>
39 #include <svx/dialmgr.hxx>
40 #include <editeng/unolingu.hxx>
41 #include <comphelper/processfactory.hxx>
42 #include "app.hrc"
43 #include "strings.hrc"
44 #include "drawdoc.hxx"
45 #include "app.hxx"
46 #include "View.hxx"
47 #include "Outliner.hxx"
48 #include "DrawViewShell.hxx"
49 #include "OutlineViewShell.hxx"
50 #ifndef SD_WINDOW_SHELL_HXX
51 #include "Window.hxx"
52 #endif
53 #include "sdresid.hxx"
54 
55 using ::rtl::OUString;
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::linguistic2;
60 
61 class SfxRequest;
62 
63 namespace sd {
64 
65 TYPEINIT1( FuThesaurus, FuPoor );
66 
67 /*************************************************************************
68 |*
69 |* Konstruktor
70 |*
71 \************************************************************************/
72 
FuThesaurus(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)73 FuThesaurus::FuThesaurus( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
74 				  SdDrawDocument* pDoc, SfxRequest& rReq )
75 	   : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
76 {
77 }
78 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)79 FunctionReference FuThesaurus::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
80 {
81 	FunctionReference xFunc( new FuThesaurus( pViewSh, pWin, pView, pDoc, rReq ) );
82 	xFunc->DoExecute(rReq);
83 	return xFunc;
84 }
85 
DoExecute(SfxRequest &)86 void FuThesaurus::DoExecute( SfxRequest& )
87 {
88 	SfxErrorContext aContext(ERRCTX_SVX_LINGU_THESAURUS, String(),
89 							 mpWindow, RID_SVXERRCTX, &DIALOG_MGR() );
90 
91 	if( mpViewShell && mpViewShell->ISA(DrawViewShell) )
92 	{
93 		SdrTextObj* pTextObj = NULL;
94 
95 		if ( mpView->AreObjectsMarked() )
96 		{
97 			const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
98 
99 			if ( rMarkList.GetMarkCount() == 1 )
100 			{
101 				SdrMark* pMark = rMarkList.GetMark(0);
102 				SdrObject* pObj = pMark->GetMarkedSdrObj();
103 
104 				if ( pObj->ISA(SdrTextObj) )
105 				{
106 					pTextObj = (SdrTextObj*) pObj;
107 				}
108 			}
109 		}
110 
111 		::Outliner* pOutliner = mpView->GetTextEditOutliner();
112 		const OutlinerView* pOutlView = mpView->GetTextEditOutlinerView();
113 
114 		if ( pTextObj && pOutliner && pOutlView )
115 		{
116 			if ( !pOutliner->GetSpeller().is() )
117 			{
118 	            Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
119 	            if ( xSpellChecker.is() )
120 		            pOutliner->SetSpeller( xSpellChecker );
121 
122 	            Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
123 	            if( xHyphenator.is() )
124 		            pOutliner->SetHyphenator( xHyphenator );
125 
126 				pOutliner->SetDefaultLanguage( mpDoc->GetLanguage( EE_CHAR_LANGUAGE ) );
127 			}
128 
129 			EESpellState eState = ( (OutlinerView*) pOutlView)->StartThesaurus();
130 			DBG_ASSERT(eState != EE_SPELL_NOSPELLER, "No SpellChecker");
131 
132 			if (eState == EE_SPELL_NOLANGUAGE)
133 			{
134 				ErrorBox(mpWindow, WB_OK, String(SdResId(STR_NOLANGUAGE))).Execute();
135 			}
136 		}
137 	}
138 	else if ( mpViewShell->ISA(OutlineViewShell) )
139 	{
140 		Outliner* pOutliner = mpDoc->GetOutliner();
141 		OutlinerView* pOutlView = pOutliner->GetView(0);
142 
143 		if ( !pOutliner->GetSpeller().is() )
144 		{
145 	        Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
146 	        if ( xSpellChecker.is() )
147 		        pOutliner->SetSpeller( xSpellChecker );
148 
149 	        Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
150 	        if( xHyphenator.is() )
151 		        pOutliner->SetHyphenator( xHyphenator );
152 
153 			pOutliner->SetDefaultLanguage( mpDoc->GetLanguage( EE_CHAR_LANGUAGE ) );
154 		}
155 
156 		EESpellState eState = pOutlView->StartThesaurus();
157 		DBG_ASSERT(eState != EE_SPELL_NOSPELLER, "No SpellChecker");
158 
159 		if (eState == EE_SPELL_NOLANGUAGE)
160 		{
161 			ErrorBox(mpWindow, WB_OK, String(SdResId(STR_NOLANGUAGE))).Execute();
162 		}
163 	}
164 }
165 
166 } // end of namespace sd
167