xref: /aoo41x/main/sd/source/ui/func/fuoltext.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_sd.hxx"
30 
31 
32 #include "fuoltext.hxx"
33 
34 #include <sfx2/viewfrm.hxx>
35 #include <editeng/outliner.hxx>
36 #include <editeng/eeitem.hxx>
37 #include <editeng/flditem.hxx>
38 #include <sfx2/bindings.hxx>
39 #include <sfx2/docfile.hxx>
40 #include <sfx2/dispatch.hxx>
41 
42 #include <svx/svxids.hrc>
43 #include "app.hrc"
44 #include "OutlineView.hxx"
45 #ifndef SD_WINDOW_SHELL_HXX
46 #include "Window.hxx"
47 #endif
48 #include "DrawDocShell.hxx"
49 #include "ViewShell.hxx"
50 #include "OutlineViewShell.hxx"
51 
52 #include <stdio.h>          // Fuer SlotFilter-Listing
53 
54 namespace sd {
55 
56 static sal_uInt16 SidArray[] = {
57 				SID_STYLE_FAMILY2,
58 				SID_STYLE_FAMILY3,
59 				SID_STYLE_FAMILY5,
60 				SID_STYLE_UPDATE_BY_EXAMPLE,
61 				SID_CUT,
62 				SID_COPY,
63 				SID_PASTE,
64 				SID_SELECTALL,
65 				SID_ATTR_CHAR_FONT,
66 				SID_ATTR_CHAR_POSTURE,
67 				SID_ATTR_CHAR_WEIGHT,
68 				SID_ATTR_CHAR_UNDERLINE,
69 				SID_ATTR_CHAR_FONTHEIGHT,
70 				SID_ATTR_CHAR_COLOR,
71 				SID_OUTLINE_UP,
72 				SID_OUTLINE_DOWN,
73 				SID_OUTLINE_LEFT,
74 				SID_OUTLINE_RIGHT,
75 				//SID_OUTLINE_FORMAT,
76 				SID_OUTLINE_COLLAPSE_ALL,
77 				//SID_OUTLINE_BULLET,
78 				SID_OUTLINE_COLLAPSE,
79 				SID_OUTLINE_EXPAND_ALL,
80 				SID_OUTLINE_EXPAND,
81 				SID_SET_SUPER_SCRIPT,
82 				SID_SET_SUB_SCRIPT,
83 				SID_HYPERLINK_GETLINK,
84 				SID_PRESENTATION_TEMPLATES,
85 				SID_STATUS_PAGE,
86 				SID_STATUS_LAYOUT,
87 				SID_EXPAND_PAGE,
88 				SID_SUMMARY_PAGE,
89 				SID_PARASPACE_INCREASE,
90 				SID_PARASPACE_DECREASE,
91 				0 };
92 
93 TYPEINIT1( FuOutlineText, FuOutline );
94 
95 /*************************************************************************
96 |*
97 |* Konstruktor
98 |*
99 \************************************************************************/
100 
101 FuOutlineText::FuOutlineText(ViewShell* pViewShell, ::sd::Window* pWindow,
102 							 ::sd::View* pView, SdDrawDocument* pDoc,
103 							 SfxRequest& rReq)
104 	   : FuOutline(pViewShell, pWindow, pView, pDoc, rReq)
105 {
106 }
107 
108 FunctionReference FuOutlineText::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
109 {
110 	FunctionReference xFunc( new FuOutlineText( pViewSh, pWin, pView, pDoc, rReq ) );
111 	xFunc->DoExecute( rReq );
112 	return xFunc;
113 }
114 
115 /*************************************************************************
116 |*
117 |* MouseButtonDown-event
118 |*
119 \************************************************************************/
120 
121 sal_Bool FuOutlineText::MouseButtonDown(const MouseEvent& rMEvt)
122 {
123 	sal_Bool bReturn = sal_False;
124 
125 	mpWindow->GrabFocus();
126 
127 	bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseButtonDown(rMEvt);
128 
129 	if (bReturn)
130 	{
131 		// Attributierung der akt. Textstelle kann jetzt anders sein
132 		mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
133 	}
134 	else
135 	{
136 		bReturn = FuOutline::MouseButtonDown(rMEvt);
137 	}
138 
139 	return (bReturn);
140 }
141 
142 /*************************************************************************
143 |*
144 |* MouseMove-event
145 |*
146 \************************************************************************/
147 
148 sal_Bool FuOutlineText::MouseMove(const MouseEvent& rMEvt)
149 {
150 	sal_Bool bReturn = sal_False;
151 
152 	bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseMove(rMEvt);
153 
154 	if (!bReturn)
155 	{
156 		bReturn = FuOutline::MouseMove(rMEvt);
157 	}
158 
159     // MT 07/2002: Done in OutlinerView::MouseMove
160     /*
161 	const SvxFieldItem* pFieldItem = pOutlineView->GetViewByWindow( mpWindow )->
162 										GetFieldUnderMousePointer();
163 	const SvxFieldData* pField = NULL;
164 	if( pFieldItem )
165 		pField = pFieldItem->GetField();
166 
167 	if( pField && pField->ISA( SvxURLField ) )
168 	{
169 	   mpWindow->SetPointer( Pointer( POINTER_REFHAND ) );
170 	}
171 	else
172 	   mpWindow->SetPointer( Pointer( POINTER_TEXT ) );
173     */
174 
175 	return (bReturn);
176 }
177 
178 /*************************************************************************
179 |*
180 |* MouseButtonUp-event
181 |*
182 \************************************************************************/
183 
184 sal_Bool FuOutlineText::MouseButtonUp(const MouseEvent& rMEvt)
185 {
186 	sal_Bool bReturn = sal_False;
187 
188 	bReturn = pOutlineView->GetViewByWindow(mpWindow)->MouseButtonUp(rMEvt);
189 
190 	if (bReturn)
191 	{
192 		// Attributierung der akt. Textstelle kann jetzt anders sein
193 		mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
194 	}
195 	else
196 	{
197 		const SvxFieldItem* pFieldItem = pOutlineView->GetViewByWindow( mpWindow )->GetFieldUnderMousePointer();
198 		if( pFieldItem )
199 		{
200 			const SvxFieldData* pField = pFieldItem->GetField();
201 
202 			if( pField && pField->ISA( SvxURLField ) )
203 			{
204 				bReturn = sal_True;
205 	            mpWindow->ReleaseMouse();
206                 SfxStringItem aStrItem( SID_FILE_NAME, ( (SvxURLField*) pField)->GetURL() );
207                 SfxStringItem aReferer( SID_REFERER, mpDocSh->GetMedium()->GetName() );
208                 SfxBoolItem aBrowseItem( SID_BROWSE, sal_True );
209                 SfxViewFrame* pFrame = mpViewShell->GetViewFrame();
210 
211 				if ( rMEvt.IsMod1() )
212 				{
213 					// Im neuen Frame oeffnen
214                 	pFrame->GetDispatcher()->Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
215                     		    &aStrItem, &aBrowseItem, &aReferer, 0L);
216 				}
217 				else
218 				{
219 					// Im aktuellen Frame oeffnen
220 					SfxFrameItem aFrameItem( SID_DOCFRAME, pFrame );
221                 	pFrame->GetDispatcher()->Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
222                     		    &aStrItem, &aFrameItem, &aBrowseItem, &aReferer, 0L);
223 				}
224 			}
225 		}
226 	}
227 
228 	if( !bReturn )
229 		bReturn = FuOutline::MouseButtonUp(rMEvt);
230 
231 	return (bReturn);
232 }
233 
234 /*************************************************************************
235 |*
236 |* Tastaturereignisse bearbeiten
237 |*
238 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
239 |* sal_False.
240 |*
241 \************************************************************************/
242 
243 sal_Bool FuOutlineText::KeyInput(const KeyEvent& rKEvt)
244 {
245 	sal_Bool bReturn = sal_False;
246 
247 	sal_uInt16 nKeyGroup = rKEvt.GetKeyCode().GetGroup();
248 	if( !mpDocSh->IsReadOnly() || nKeyGroup == KEYGROUP_CURSOR )
249 	{
250 		mpWindow->GrabFocus();
251 
252 		std::auto_ptr< OutlineViewModelChangeGuard > aGuard;
253 
254 		if( (nKeyGroup != KEYGROUP_CURSOR) && (nKeyGroup != KEYGROUP_FKEYS) )
255 			aGuard.reset( new OutlineViewModelChangeGuard( *pOutlineView ) );
256 
257 		bReturn = pOutlineView->GetViewByWindow(mpWindow)->PostKeyEvent(rKEvt);
258 
259 		if (bReturn)
260 		{
261             UpdateForKeyPress (rKEvt);
262 		}
263 		else
264 		{
265 			bReturn = FuOutline::KeyInput(rKEvt);
266 		}
267 	}
268 
269 	return (bReturn);
270 }
271 
272 void FuOutlineText::UpdateForKeyPress (const KeyEvent& rEvent)
273 {
274     // Attributes at the current text position may have changed.
275     mpViewShell->GetViewFrame()->GetBindings().Invalidate(SidArray);
276 
277     bool bUpdatePreview = true;
278     switch (rEvent.GetKeyCode().GetCode())
279     {
280         // When just the cursor has been moved the preview only changes when
281         // it moved to entries of another page.  To prevent unnecessary
282         // updates we check this here.  This is an early rejection test, so
283         // missing a key is not a problem.
284         case KEY_UP:
285         case KEY_DOWN:
286         case KEY_LEFT:
287         case KEY_RIGHT:
288         case KEY_HOME:
289         case KEY_END:
290         case KEY_PAGEUP:
291         case KEY_PAGEDOWN:
292         {
293             SdPage* pCurrentPage = pOutlineViewShell->GetActualPage();
294             bUpdatePreview = (pCurrentPage != pOutlineViewShell->GetActualPage());
295         }
296         break;
297     }
298     if (bUpdatePreview)
299         pOutlineViewShell->UpdatePreview (pOutlineViewShell->GetActualPage());
300 }
301 
302 
303 
304 
305 /*************************************************************************
306 |*
307 |* Function aktivieren
308 |*
309 \************************************************************************/
310 
311 void FuOutlineText::Activate()
312 {
313 	FuOutline::Activate();
314 }
315 
316 /*************************************************************************
317 |*
318 |* Function deaktivieren
319 |*
320 \************************************************************************/
321 
322 void FuOutlineText::Deactivate()
323 {
324 	FuOutline::Deactivate();
325 }
326 
327 /*************************************************************************
328 |*
329 |* Cut object to clipboard
330 |*
331 \************************************************************************/
332 
333 void FuOutlineText::DoCut()
334 {
335 	pOutlineView->GetViewByWindow(mpWindow)->Cut();
336 }
337 
338 /*************************************************************************
339 |*
340 |* Copy object to clipboard
341 |*
342 \************************************************************************/
343 
344 void FuOutlineText::DoCopy()
345 {
346 	pOutlineView->GetViewByWindow(mpWindow)->Copy();
347 }
348 
349 /*************************************************************************
350 |*
351 |* Paste object from clipboard
352 |*
353 \************************************************************************/
354 
355 void FuOutlineText::DoPaste()
356 {
357 	pOutlineView->GetViewByWindow(mpWindow)->PasteSpecial();
358 }
359 
360 
361 } // end of namespace sd
362