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