xref: /trunk/main/sd/source/ui/func/futhes.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 
32 #include "futhes.hxx"
33 
34 #include <tools/pstm.hxx>
35 #include <editeng/outliner.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <svx/svdobj.hxx>
38 #include <svx/svdotext.hxx>
39 #include <editeng/eeitem.hxx>
40 
41 #include <svx/dialogs.hrc>
42 #include <svx/svxerr.hxx>
43 #include <svx/dialmgr.hxx>
44 #include <editeng/unolingu.hxx>
45 #include <comphelper/processfactory.hxx>
46 #include "app.hrc"
47 #include "strings.hrc"
48 #include "drawdoc.hxx"
49 #include "app.hxx"
50 #include "View.hxx"
51 #include "Outliner.hxx"
52 #include "DrawViewShell.hxx"
53 #include "OutlineViewShell.hxx"
54 #ifndef SD_WINDOW_SHELL_HXX
55 #include "Window.hxx"
56 #endif
57 #include "sdresid.hxx"
58 
59 using ::rtl::OUString;
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::lang;
63 using namespace ::com::sun::star::linguistic2;
64 
65 class SfxRequest;
66 
67 namespace sd {
68 
69 TYPEINIT1( FuThesaurus, FuPoor );
70 
71 /*************************************************************************
72 |*
73 |* Konstruktor
74 |*
75 \************************************************************************/
76 
77 FuThesaurus::FuThesaurus( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView,
78                   SdDrawDocument* pDoc, SfxRequest& rReq )
79        : FuPoor(pViewSh, pWin, pView, pDoc, rReq)
80 {
81 }
82 
83 FunctionReference FuThesaurus::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
84 {
85     FunctionReference xFunc( new FuThesaurus( pViewSh, pWin, pView, pDoc, rReq ) );
86     xFunc->DoExecute(rReq);
87     return xFunc;
88 }
89 
90 void FuThesaurus::DoExecute( SfxRequest& )
91 {
92     SfxErrorContext aContext(ERRCTX_SVX_LINGU_THESAURUS, String(),
93                              mpWindow, RID_SVXERRCTX, &DIALOG_MGR() );
94 
95     if( mpViewShell && mpViewShell->ISA(DrawViewShell) )
96     {
97         SdrTextObj* pTextObj = NULL;
98 
99         if ( mpView->AreObjectsMarked() )
100         {
101             const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
102 
103             if ( rMarkList.GetMarkCount() == 1 )
104             {
105                 SdrMark* pMark = rMarkList.GetMark(0);
106                 SdrObject* pObj = pMark->GetMarkedSdrObj();
107 
108                 if ( pObj->ISA(SdrTextObj) )
109                 {
110                     pTextObj = (SdrTextObj*) pObj;
111                 }
112             }
113         }
114 
115         ::Outliner* pOutliner = mpView->GetTextEditOutliner();
116         const OutlinerView* pOutlView = mpView->GetTextEditOutlinerView();
117 
118         if ( pTextObj && pOutliner && pOutlView )
119         {
120             if ( !pOutliner->GetSpeller().is() )
121             {
122                 Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
123                 if ( xSpellChecker.is() )
124                     pOutliner->SetSpeller( xSpellChecker );
125 
126                 Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
127                 if( xHyphenator.is() )
128                     pOutliner->SetHyphenator( xHyphenator );
129 
130                 pOutliner->SetDefaultLanguage( mpDoc->GetLanguage( EE_CHAR_LANGUAGE ) );
131             }
132 
133             EESpellState eState = ( (OutlinerView*) pOutlView)->StartThesaurus();
134             DBG_ASSERT(eState != EE_SPELL_NOSPELLER, "No SpellChecker");
135 
136             if (eState == EE_SPELL_NOLANGUAGE)
137             {
138                 ErrorBox(mpWindow, WB_OK, String(SdResId(STR_NOLANGUAGE))).Execute();
139             }
140         }
141     }
142     else if ( mpViewShell->ISA(OutlineViewShell) )
143     {
144         Outliner* pOutliner = mpDoc->GetOutliner();
145         OutlinerView* pOutlView = pOutliner->GetView(0);
146 
147         if ( !pOutliner->GetSpeller().is() )
148         {
149             Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
150             if ( xSpellChecker.is() )
151                 pOutliner->SetSpeller( xSpellChecker );
152 
153             Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
154             if( xHyphenator.is() )
155                 pOutliner->SetHyphenator( xHyphenator );
156 
157             pOutliner->SetDefaultLanguage( mpDoc->GetLanguage( EE_CHAR_LANGUAGE ) );
158         }
159 
160         EESpellState eState = pOutlView->StartThesaurus();
161         DBG_ASSERT(eState != EE_SPELL_NOSPELLER, "No SpellChecker");
162 
163         if (eState == EE_SPELL_NOLANGUAGE)
164         {
165             ErrorBox(mpWindow, WB_OK, String(SdResId(STR_NOLANGUAGE))).Execute();
166         }
167     }
168 }
169 
170 } // end of namespace sd
171