xref: /aoo42x/main/sw/source/ui/wrtsh/wrtsh3.cxx (revision cdf0e10c)
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_sw.hxx"
30 
31 
32 #ifndef _SVX_SVXIDS_HRC //autogen
33 #include <svx/svxids.hrc>
34 #endif
35 #include <sfx2/app.hxx>
36 #include <sfx2/childwin.hxx>
37 #include <sfx2/bindings.hxx>
38 #include <svx/svdmark.hxx>
39 #include <svx/svdview.hxx>
40 #include <svx/fmglob.hxx>
41 #include <svx/svdouno.hxx>
42 #include <com/sun/star/form/FormButtonType.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <svx/htmlmode.hxx>
45 #include <tools/urlobj.hxx>
46 #include "wrtsh.hxx"
47 #include "view.hxx"
48 #include "IMark.hxx"
49 #include "doc.hxx"
50 #include "wrtsh.hrc"
51 
52 #include <unomid.h>
53 
54 
55 using namespace ::com::sun::star;
56 using ::rtl::OUString;
57 
58 extern sal_Bool bNoInterrupt;       // in mainwn.cxx
59 
60 sal_Bool SwWrtShell::MoveBookMark( BookMarkMove eFuncId, const ::sw::mark::IMark* const pMark)
61 {
62 //JP 08.03.96: die Wizards brauchen die Selektion !!
63 //  EndSelect();
64     (this->*fnKillSel)( 0, sal_False );
65 
66     sal_Bool bRet = sal_True;
67     switch(eFuncId)
68     {
69         case BOOKMARK_INDEX:bRet = SwCrsrShell::GotoMark( pMark );break;
70         case BOOKMARK_NEXT: bRet = SwCrsrShell::GoNextBookmark();break;
71         case BOOKMARK_PREV: bRet = SwCrsrShell::GoPrevBookmark();break;
72         default:;//prevent warning
73     }
74 
75     if( bRet && IsSelFrmMode() )
76     {
77         UnSelectFrm();
78         LeaveSelFrmMode();
79     }
80     if( IsSelection() )
81     {
82         fnKillSel = &SwWrtShell::ResetSelect;
83         fnSetCrsr = &SwWrtShell::SetCrsrKillSel;
84     }
85     return bRet;
86 }
87 
88 sal_Bool SwWrtShell::GotoField( const SwFmtFld& rFld )
89 {
90     (this->*fnKillSel)( 0, sal_False );
91 
92     sal_Bool bRet = SwCrsrShell::GotoFld( rFld );
93     if( bRet && IsSelFrmMode() )
94     {
95         UnSelectFrm();
96         LeaveSelFrmMode();
97     }
98 
99 	if( IsSelection() )
100     {
101         fnKillSel = &SwWrtShell::ResetSelect;
102         fnSetCrsr = &SwWrtShell::SetCrsrKillSel;
103     }
104 
105 	return bRet;
106 }
107 
108 bool SwWrtShell::GotoFieldmark(::sw::mark::IFieldmark const * const pMark)
109 {
110     (this->*fnKillSel)( 0, sal_False );
111     bool bRet = SwCrsrShell::GotoFieldmark(pMark);
112     if( bRet && IsSelFrmMode() )
113     {
114         UnSelectFrm();
115         LeaveSelFrmMode();
116     }
117     if( IsSelection() )
118     {
119         fnKillSel = &SwWrtShell::ResetSelect;
120         fnSetCrsr = &SwWrtShell::SetCrsrKillSel;
121     }
122     return bRet;
123 }
124 
125 /*--------------------------------------------------------------------
126     Beschreibung: FontWork-Slots invalidieren
127  --------------------------------------------------------------------*/
128 
129 
130 void SwWrtShell::DrawSelChanged( )
131 {
132     static sal_uInt16 __READONLY_DATA aInval[] =
133     {
134         SID_ATTR_FILL_STYLE, SID_ATTR_FILL_COLOR, SID_ATTR_LINE_STYLE,
135         SID_ATTR_LINE_WIDTH, SID_ATTR_LINE_COLOR, 0
136     };
137 
138     GetView().GetViewFrame()->GetBindings().Invalidate(aInval);
139 
140     sal_Bool bOldVal = bNoInterrupt;
141     bNoInterrupt = sal_True;    // Trick, um AttrChangedNotify ueber Timer auszufuehren
142     GetView().AttrChangedNotify(this);
143     bNoInterrupt = bOldVal;
144 }
145 
146 sal_Bool SwWrtShell::GotoMark( const ::rtl::OUString& rName )
147 {
148     IDocumentMarkAccess::const_iterator_t ppMark = getIDocumentMarkAccess()->findMark( rName );
149     if(ppMark == getIDocumentMarkAccess()->getMarksEnd()) return false;
150     return MoveBookMark( BOOKMARK_INDEX, ppMark->get() );
151 }
152 
153 
154 sal_Bool SwWrtShell::GotoMark( const ::sw::mark::IMark* const pMark )
155 {
156     return MoveBookMark( BOOKMARK_INDEX, pMark );
157 }
158 
159 
160 sal_Bool SwWrtShell::GoNextBookmark()
161 {
162     return MoveBookMark( BOOKMARK_NEXT );
163 }
164 
165 
166 sal_Bool SwWrtShell::GoPrevBookmark()
167 {
168     return MoveBookMark( BOOKMARK_PREV );
169 }
170 
171 
172 void SwWrtShell::ExecMacro( const SvxMacro& rMacro, String* pRet, SbxArray* pArgs )
173 {
174     // OD 11.02.2003 #100556# - execute macro, if it is allowed.
175     if ( IsMacroExecAllowed() )
176     {
177         GetDoc()->ExecMacro( rMacro, pRet, pArgs );
178     }
179 }
180 
181 
182 sal_uInt16 SwWrtShell::CallEvent( sal_uInt16 nEvent, const SwCallMouseEvent& rCallEvent,
183                                 sal_Bool bChkPtr, SbxArray* pArgs,
184                                 const Link* pCallBack )
185 {
186     return GetDoc()->CallEvent( nEvent, rCallEvent, bChkPtr, pArgs, pCallBack );
187 }
188 
189 
190     // fall ein util::URL-Button selektiert ist, dessen util::URL returnen, ansonsten
191     // einen LeerString
192 sal_Bool SwWrtShell::GetURLFromButton( String& rURL, String& rDescr ) const
193 {
194     sal_Bool bRet = sal_False;
195     const SdrView *pDView = GetDrawView();
196     if( pDView )
197     {
198         // Ein Fly ist genau dann erreichbar, wenn er selektiert ist.
199         const SdrMarkList &rMarkList = pDView->GetMarkedObjectList();
200 
201         if (rMarkList.GetMark(0))
202         {
203             SdrUnoObj* pUnoCtrl = PTR_CAST(SdrUnoObj, rMarkList.GetMark(0)->GetMarkedSdrObj());
204             if (pUnoCtrl && FmFormInventor == pUnoCtrl->GetObjInventor())
205             {
206                 uno::Reference< awt::XControlModel >  xControlModel = pUnoCtrl->GetUnoControlModel();
207 
208                 ASSERT( xControlModel.is(), "UNO-Control ohne Model" );
209                 if( !xControlModel.is() )
210                     return bRet;
211 
212                 uno::Reference< beans::XPropertySet >  xPropSet(xControlModel, uno::UNO_QUERY);
213 
214                 uno::Any aTmp;
215 
216                 form::FormButtonType eButtonType = form::FormButtonType_URL;
217                 uno::Reference< beans::XPropertySetInfo >   xInfo = xPropSet->getPropertySetInfo();
218                 if(xInfo->hasPropertyByName( C2U("ButtonType") ))
219                 {
220                     aTmp = xPropSet->getPropertyValue( C2U("ButtonType") );
221                     form::FormButtonType eTmpButtonType;
222                     aTmp >>= eTmpButtonType;
223                     if( eButtonType == eTmpButtonType)
224                     {
225                         // Label
226                         aTmp = xPropSet->getPropertyValue( C2U("Label") );
227                         OUString uTmp;
228                         if( (aTmp >>= uTmp) && uTmp.getLength())
229                         {
230                             rDescr = String(uTmp);
231                         }
232 
233                         // util::URL
234                         aTmp = xPropSet->getPropertyValue( C2U("TargetURL") );
235                         if( (aTmp >>= uTmp) && uTmp.getLength())
236                         {
237                             rURL = String(uTmp);
238                         }
239                         bRet = sal_True;
240                     }
241                 }
242             }
243         }
244     }
245 
246     return bRet;
247 }
248