xref: /aoo41x/main/sd/source/ui/inc/DrawViewShell.hxx (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 #ifndef SD_DRAW_VIEW_SHELL_HXX
29 #define SD_DRAW_VIEW_SHELL_HXX
30 
31 #include "ViewShell.hxx"
32 #include "tools/AsynchronousCall.hxx"
33 #include <sfx2/viewfac.hxx>
34 #include <sfx2/viewsh.hxx>
35 #include "TabControl.hxx"
36 #include "pres.hxx"
37 #include <com/sun/star/lang/XEventListener.hpp>
38 #include <com/sun/star/scanner/XScannerManager.hpp>
39 
40 class SdPage;
41 class DrawDocShell;
42 class SdAnimationWin;
43 class SdRuler;
44 class TabBar;
45 class SdrObject;
46 class SdrPageView;
47 class TransferableDataHelper;
48 class TransferableClipboardListener;
49 class AbstractSvxNameDialog;
50 class SdrLayer;
51 class SvxClipboardFmtItem;
52 
53 namespace sd {
54 
55 class DrawView;
56 class LayerTabBar;
57 class Ruler;
58 class SdUnoDrawView;
59 class AnnotationManager;
60 class ViewOverlayManager;
61 
62 #define CHECK_RANGE(nMin, nValue, nMax) ((nValue >= nMin) && (nValue <= nMax))
63 
64 /** Base class of the stacked shells that provide graphical views to
65     Draw and Impress documents and editing functionality.  In contrast
66     to this other stacked shells are responsible for showing an
67     overview over several slides (SlideViewShell) or a textual
68     overview over the text in an Impress document (OutlineViewShell).
69 */
70 class DrawViewShell
71     : public ViewShell,
72       public SfxListener
73 {
74 public:
75     static const int SLOTARRAY_COUNT = 24;
76 
77     TYPEINFO();
78 
79     SFX_DECL_INTERFACE(SD_IF_SDDRAWVIEWSHELL)
80 
81     /** Create a new stackable shell that may take some information
82         (e.g. the frame view) from the given previous shell.
83         @param ePageKind
84             This parameter gives the initial page kind that the new shell
85             will show.
86         @param pFrameView
87             The frame view that makes it possible to pass information from
88             one view shell to the next.
89     */
90     DrawViewShell (
91         SfxViewFrame* pFrame,
92         ViewShellBase& rViewShellBase,
93         ::Window* pParentWindow,
94         PageKind ePageKind = PK_STANDARD,
95         FrameView* pFrameView = NULL);
96 
97     virtual ~DrawViewShell (void);
98 
99     virtual void Init (bool bIsMainViewShell);
100 
101     virtual void Shutdown (void);
102 
103     void PrePaint();
104     virtual void Paint(const Rectangle& rRect, ::sd::Window* pWin);
105 
106     /** Set the position and size of the area which contains the GUI
107         elements like rulers, sliders, and buttons as well as the document
108         view.  Both size and position are expected to be in pixel
109         coordinates.  The positions and sizes of the mentioned GUI elements
110         are updated as well.
111 
112         <p> This method is implemented by first setting copying the given
113         values to internal variables and then calling the
114         <type>ArrangeGUIElements</type> method which performs the actual
115         work of sizeing and arranging the UI elements accordingly.</p>
116         @param rPos
117             The position of the enclosing window relative to the document
118             window.  This is only interesting if a Draw/Impress document
119             view is embedded as OLE object into another document view.  For
120             normal documents this position is (0,0).
121         @param rSize
122             The new size in pixel.
123     */
124     //	virtual void	AdjustPosSizePixel(const Point &rPos, const Size &rSize);
125 
126     /** Arrange and resize the GUI elements like rulers, sliders, and
127         buttons as well as the actual document view according to the size of
128         the enclosing window and current sizes of buttons, rulers, and
129         sliders.
130     */
131     virtual void ArrangeGUIElements (void);
132 
133     void 	        HidePage();
134 
135 	virtual sal_Bool    KeyInput(const KeyEvent& rKEvt, ::sd::Window* pWin);
136 	virtual void    MouseMove(const MouseEvent& rMEvt, ::sd::Window* pWin);
137 	virtual void    MouseButtonUp(const MouseEvent& rMEvt, ::sd::Window* pWin);
138 	virtual void    MouseButtonDown(const MouseEvent& rMEvt, ::sd::Window* pWin);
139 	virtual void    Command(const CommandEvent& rCEvt, ::sd::Window* pWin);
140 
141 	virtual void Resize (void);
142 
143 	void            ShowMousePosInfo(const Rectangle& rRect, ::sd::Window* pWin);
144 
145 	virtual void    AddWindow(::sd::Window* pWin);
146 	virtual void    RemoveWindow(::sd::Window* pWin);
147 
148 	virtual void ChangeEditMode (EditMode eMode, bool bIsLayerModeActive);
149 
150 	virtual void    SetZoom( long nZoom );
151 	virtual void    SetZoomRect( const Rectangle& rZoomRect );
152 
153 	void	        InsertURLField(const String& rURL, const String& rText, const String& rTarget,
154 			        			   const Point* pPos);
155 	void	        InsertURLButton(const String& rURL, const String& rText, const String& rTarget,
156 			        				const Point* pPos);
157 
158 	virtual void    SetUIUnit(FieldUnit eUnit);
159 
160 	void		    SelectionHasChanged();
161 	void		    ModelHasChanged();
162 	virtual void    Activate(sal_Bool bIsMDIActivate);
163 	virtual void    Deactivate(sal_Bool IsMDIActivate);
164     virtual void    UIActivating( SfxInPlaceClient* );
165     virtual void    UIDeactivated( SfxInPlaceClient* );
166 	virtual String	GetSelectionText( sal_Bool bCompleteWords = sal_False );
167 	virtual sal_Bool    HasSelection( sal_Bool bText = sal_True ) const;
168 
169 	void	        ExecCtrl(SfxRequest& rReq);
170 	void	        GetCtrlState(SfxItemSet& rSet);
171 	void	        GetMenuState(SfxItemSet& rSet);
172 	void	        GetTableMenuState(SfxItemSet& rSet);
173     /** Set the items of the given item set that are related to
174         switching the editing mode to the correct values.
175         <p>This function also sets the states of the mode buttons
176         (those at the upper right corner) accordingly.</p>
177     */
178     void GetModeSwitchingMenuState (SfxItemSet &rSet);
179 	void	        GetAttrState(SfxItemSet& rSet);
180 	void	        GetSnapItemState(SfxItemSet& rSet);
181 
182 	void	        GetState (SfxItemSet& rSet);
183     void            Execute (SfxRequest& rReq);
184 
185 	void	        ExecStatusBar(SfxRequest& rReq);
186 	void	        GetStatusBarState(SfxItemSet& rSet);
187 
188 	void	        ExecOptionsBar(SfxRequest& rReq);
189 	void	        GetOptionsBarState(SfxItemSet& rSet);
190 
191 	void	        ExecRuler(SfxRequest& rReq);
192 	void	        GetRulerState(SfxItemSet& rSet);
193 
194 	void	        ExecFormText(SfxRequest& rReq);
195 	void	        GetFormTextState(SfxItemSet& rSet);
196 
197 	void	        ExecAnimationWin(SfxRequest& rReq);
198 	void	        GetAnimationWinState(SfxItemSet& rSet);
199 
200 	void	        ExecNavigatorWin(SfxRequest& rReq);
201 	void	        GetNavigatorWinState(SfxItemSet& rSet);
202 
203 	void	        ExecEffectWin(SfxRequest& rReq);
204 
205 	void	        Update3DWindow();
206 	void	        AssignFrom3DWindow();
207 
208 	void	        ExecGallery(SfxRequest& rReq);
209 	void	        GetGalleryState(SfxItemSet& rSet);
210 
211 	void	        ExecBmpMask( SfxRequest& rReq );
212 	void	        GetBmpMaskState( SfxItemSet& rSet );
213 
214 	void	        ExecIMap( SfxRequest& rReq );
215 	void	        GetIMapState( SfxItemSet& rSet );
216 
217 	void	        FuTemporary(SfxRequest& rReq);
218 	void	        FuPermanent(SfxRequest& rReq);
219 	void	        FuSupport(SfxRequest& rReq);
220 	void	        FuTable(SfxRequest& rReq);
221 
222 	void	        AttrExec (SfxRequest& rReq);
223 	void	        AttrState (SfxItemSet& rSet);
224 
225     void            ExecuteAnnotation (SfxRequest& rRequest);
226     void            GetAnnotationState (SfxItemSet& rItemSet);
227 
228     void StartRulerDrag (
229         const Ruler& rRuler,
230         const MouseEvent& rMEvt);
231 
232 	virtual sal_uInt16  PrepareClose( sal_Bool bUI = sal_True, sal_Bool bForBrowsing = sal_False );
233 
234 	PageKind	    GetPageKind() { return mePageKind; }
235 
236 	Point		    GetMousePos() { return maMousePos; }
237 	sal_Bool 		    IsMousePosFreezed() { return mbMousePosFreezed; }
238 	void 		    SetMousePosFreezed( sal_Bool bIn ) { mbMousePosFreezed = bIn; }
239 
240 	EditMode	    GetEditMode() const { return meEditMode; }
241 	virtual SdPage*	GetActualPage() { return mpActualPage; }
242 
243 	/// inherited from sd::ViewShell
244 	virtual SdPage* getCurrentPage() const;
245 
246 	void		    ResetActualPage();
247 	void		    ResetActualLayer();
248 	sal_Bool		    SwitchPage(sal_uInt16 nPage);
249 	sal_Bool		    IsSwitchPageAllowed() const;
250 
251 	sal_Bool		    GotoBookmark(const String& rBookmark);
252 	void            MakeVisible(const Rectangle& rRect, ::Window& rWin);
253 
254 	virtual void    ReadFrameViewData(FrameView* pView);
255 	virtual void    WriteFrameViewData();
256 
257 	virtual ErrCode DoVerb(long nVerb);
258 	virtual sal_Bool    ActivateObject(SdrOle2Obj* pObj, long nVerb);
259 
260 	void		    SetZoomOnPage( sal_Bool bZoom = sal_True ) { mbZoomOnPage = bZoom; }
261 	sal_Bool		    IsZoomOnPage() { return mbZoomOnPage; }
262 	void		    CheckLineTo (SfxRequest& rReq);
263 	void		    FuTemp01(SfxRequest& rReq);
264 	void		    FuTemp02(SfxRequest& rReq);
265 	void		    FuTemp03(SfxRequest& rReq);
266 	void		    FuTemp04(SfxRequest& rReq);
267 	void		    SetChildWindowState( SfxItemSet& rSet );
268 
269 	void		    UpdateIMapDlg( SdrObject* pObj );
270 
271 	void		    LockInput();
272 	void		    UnlockInput();
273 	sal_Bool		    IsInputLocked() const { return mnLockCount > 0UL; }
274 
275 	sal_uInt16		    GetCurPageId() { return( maTabControl.GetCurPageId() ); }
276 
277     /** Show controls of the UI or hide them, depending on the given flag.
278         Do not call this method directly.  Call the method at ViewShellBase
279         instead.
280     */
281 	virtual void ShowUIControls (bool bVisible = true);
282 
283 	void		    ScannerEvent( const ::com::sun::star::lang::EventObject& rEventObject );
284 
285 	bool IsLayerModeActive (void) const;
286 
287 	sal_uInt16*	    	GetSlotArray() const { return mpSlotArray; }
288 
289 	virtual sal_Int8    AcceptDrop( const AcceptDropEvent& rEvt, DropTargetHelper& rTargetHelper,
290                                     ::sd::Window* pTargetWindow, sal_uInt16 nPage, sal_uInt16 nLayer );
291 	virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& rEvt, DropTargetHelper& rTargetHelper,
292                                     ::sd::Window* pTargetWindow, sal_uInt16 nPage, sal_uInt16 nLayer );
293 
294     virtual void    WriteUserDataSequence ( ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool bBrowse = sal_False );
295     virtual void    ReadUserDataSequence ( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool bBrowse = sal_False );
296 
297 	virtual void    VisAreaChanged(const Rectangle& rRect);
298 
299     /** Create an accessible object representing the specified window.
300 	    @param pWindow
301 	        The returned object makes the document displayed in this window
302 	        accessible.
303         @return
304 	        Returns an <type>AccessibleDrawDocumentView</type> object.
305    */
306     virtual ::com::sun::star::uno::Reference<
307         ::com::sun::star::accessibility::XAccessible>
308         CreateAccessibleDocumentView (::sd::Window* pWindow);
309 
310     /** Return the number of layers managed by the layer tab control.  This
311         will usually differ from the number of layers managed by the layer
312         administrator.
313         @return
314             The number of layers managed by the layer tab control.  The
315             returned value is independent of whether the layer modus is
316             currently active and the tab control is visible.
317     */
318     virtual int GetTabLayerCount (void) const;
319 
320     /** Return the numerical id of the currently active layer as seen by the
321         layer tab control.
322         @return
323             The returned id is a number between zero (inclusive) and the
324             number of layers as returned by the
325             <member>GetTabLayerCount</member> method (exclusive).
326     */
327     virtual int GetActiveTabLayerIndex (void) const;
328 
329     /** Set the active layer at the layer tab control and update the control
330         accordingly to reflect the change on screen.
331         @param nId
332             The id is expected to be a number between zero (inclusive) and
333             the number of layers as returned by the
334             <member>GetTabLayerCount</member> method (exclusive).  Note that
335             Invalid values are ignored.  No excpetion is thrown in that case.
336     */
337     virtual void SetActiveTabLayerIndex (int nId);
338 
339     /** Return a pointer to the tab control for pages.
340     */
341 	TabControl* GetPageTabControl (void);
342 
343     /** Return a pointer to the tab control for layers.
344     */
345 	LayerTabBar* GetLayerTabControl (void);
346 
347     /** Renames the given slide using an SvxNameDialog
348 
349         @param nPageId the index of the page in the SdTabControl.
350         @param rName the new name of the slide.
351 
352         @return false, if the new name is invalid for some reason.
353 
354         <p>Implemented in <code>drviews8.cxx</code>.</p>
355      */
356     bool RenameSlide( sal_uInt16 nPageId, const String & rName );
357 
358 	/** modifies the given layer with the given values */
359 	void ModifyLayer( SdrLayer* pLayer, const String& rLayerName, const String& rLayerTitle, const String& rLayerDesc, bool bIsVisible, bool bIsLocked, bool bIsPrintable );
360 
361     virtual css::uno::Reference<css::drawing::XDrawSubController> CreateSubController (void);
362 
363 	DrawView*	GetDrawView() const { return mpDrawView; }
364 
365     /** Relocation to a new parent window is not supported for DrawViewShell
366         objects so this method always returns <FALSE/>.
367     */
368     virtual bool RelocateToParentWindow (::Window* pParentWindow);
369 
370 protected:
371 	DrawView*		mpDrawView;
372 	SdPage* 		mpActualPage;
373 	Rectangle		maMarkRect;
374 	Point			maMousePos;
375 	sal_Bool			mbMousePosFreezed;
376 	TabControl		maTabControl;
377 	EditMode		meEditMode;
378 	PageKind		mePageKind;
379 	sal_Bool			mbZoomOnPage;
380 	sal_Bool			mbIsRulerDrag;
381 	sal_uLong			mnLockCount;
382 	Timer			maCloseTimer;
383 	sal_Bool 			mbReadOnly;
384 	sal_uInt16*			mpSlotArray;
385 
386     static sal_Bool 	mbPipette;
387 
388                 	DECL_LINK( ClipboardChanged, TransferableDataHelper* );
389                 	DECL_LINK( CloseHdl, Timer* pTimer );
390 	                DECL_LINK( TabSplitHdl, TabBar * );
391 	                DECL_LINK( NameObjectHdl, AbstractSvxNameDialog* );
392 	                DECL_LINK( RenameSlideHdl, AbstractSvxNameDialog* );
393 
394 	void	        DeleteActualPage();
395 	void	        DeleteActualLayer();
396 
397 	virtual SvxRuler* CreateHRuler(::sd::Window* pWin, sal_Bool bIsFirst);
398 	virtual SvxRuler* CreateVRuler(::sd::Window* pWin);
399 	virtual void    UpdateHRuler();
400 	virtual void    UpdateVRuler();
401 	virtual long    GetHCtrlWidth();
402 	virtual void    SetZoomFactor(const Fraction& rZoomX, const Fraction& rZoomY);
403 	virtual Size    GetOptimalSizePixel() const;
404 
405 	void            SetupPage( Size &rSize, long nLeft, long nRight, long nUpper, long nLower,
406 					           sal_Bool bSize, sal_Bool bMargin, sal_Bool bScaleAll );
407 
408 	sal_uInt16	        GetIdBySubId( sal_uInt16 nSId );
409 	void	        MapSlot( sal_uInt16 nSId );
410 	void	        UpdateToolboxImages( SfxItemSet &rSet, sal_Bool bPermanent = sal_True );
411 	sal_uInt16	        GetMappedSlot( sal_uInt16 nSId );
412 	sal_uInt16	        GetArrayId( sal_uInt16 nSId );
413 
414 	void	        GetMenuStateSel(SfxItemSet& rSet);
415 
416 private:
417     /** This flag controls whether the layer mode is active, i.e. the layer
418         dialog is visible.
419     */
420 	bool mbIsLayerModeActive;
421 
422     /** This item contains the clipboard formats of the current clipboard
423         content that are supported both by that content and by the
424         DrawViewShell.
425     */
426     ::std::auto_ptr<SvxClipboardFmtItem> mpCurrentClipboardFormats;
427 
428     /** On some occasions it is necessary to make SwitchPage calls
429         asynchronously.
430     */
431     tools::AsynchronousCall maAsynchronousSwitchPageCall;
432 
433     /** This flag is used to prevent nested calls to SwitchPage().
434     */
435     bool mbIsInSwitchPage;
436 
437 	void Construct (DrawDocShell* pDocSh, PageKind ePageKind);
438 
439     /** Depending on the given request create a new page or duplicate an
440         existing one.  See ViewShell::CreateOrDuplicatePage() for more
441         information.
442     */
443     virtual SdPage* CreateOrDuplicatePage (
444         SfxRequest& rRequest,
445         PageKind ePageKind,
446         SdPage* pPage,
447         const sal_Int32 nInsertPosition = -1);
448 
449 	::com::sun::star::uno::Reference< ::com::sun::star::scanner::XScannerManager >	mxScannerManager;
450 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >		mxScannerListener;
451 	TransferableClipboardListener*                                                  mpClipEvtLstnr;
452 	sal_Bool			                                                                mbPastePossible;
453 
454 	virtual void Notify (SfxBroadcaster& rBC, const SfxHint& rHint);
455 
456     /** Stop a running slide show.  The frame the show is running in is
457         destroyed if
458         a) it is running in its own frame, i.e. is a full screen show and
459         b) the given flag bCloseFrame is true.
460         @param bCloseFrame
461             Be carefull with this flag when stopping a full screen show.
462             When called from the destructor the flag has to be <FALSE/> or
463             otherwise we run into a loop of calls to destructors of the view
464             and the frame.
465             When called from other places the flag should be <TRUE/> so that
466             not an empty frame remains. When called with <TRUE/> it is the
467             responsibility of the caller to avoid an illegal reentrant
468             call.
469     */
470     void StopSlideShow (bool bCloseFrame);
471 
472     /** Show the context menu for snap lines and points.  Because snap lines
473         can not be selected the index of the snap line/point for which the
474         popup menu is opened has to be passed to the processing slot
475         handlers.  This can be done only by manually showing the popup menu.
476         @param rPageView
477             The page view is used to access the help lines.
478         @param nSnapLineIndex
479             Index of the snap line or snap point for which to show the
480             context menu.
481         @param rMouseLocation
482             The mouse location defines the location at which to display the
483             context menu.
484     */
485     void ShowSnapLineContextMenu (
486         SdrPageView& rPageView,
487         const sal_uInt16 nSnapLineIndex,
488         const Point& rMouseLocation);
489 
490 	using ViewShell::Notify;
491 
492 	::std::auto_ptr< AnnotationManager > mpAnnotationManager;
493 	::std::auto_ptr< ViewOverlayManager > mpViewOverlayManager;
494 };
495 
496 
497 } // end of namespace sd
498 
499 #endif
500