xref: /AOO41X/main/sd/source/ui/inc/DrawViewShell.hxx (revision 9dcd2d78ee6377e8ad1e2e01efd517f26f4562c3)
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         ExecutePropPanelAttr (SfxRequest& rReq);
203     void            GetStatePropPanelAttr(SfxItemSet& rSet);
204 
205     void            ExecEffectWin(SfxRequest& rReq);
206 
207     void            Update3DWindow();
208     void            AssignFrom3DWindow();
209 
210     void            ExecGallery(SfxRequest& rReq);
211     void            GetGalleryState(SfxItemSet& rSet);
212 
213     void            ExecBmpMask( SfxRequest& rReq );
214     void            GetBmpMaskState( SfxItemSet& rSet );
215 
216     void            ExecIMap( SfxRequest& rReq );
217     void            GetIMapState( SfxItemSet& rSet );
218 
219     void            FuTemporary(SfxRequest& rReq);
220     void            FuPermanent(SfxRequest& rReq);
221     void            FuSupport(SfxRequest& rReq);
222     void            FuTable(SfxRequest& rReq);
223 
224     void            AttrExec (SfxRequest& rReq);
225     void            AttrState (SfxItemSet& rSet);
226 
227     void        ExecChar(SfxRequest& rReq);
228 
229     void            ExecuteAnnotation (SfxRequest& rRequest);
230     void            GetAnnotationState (SfxItemSet& rItemSet);
231 
232     void StartRulerDrag (
233         const Ruler& rRuler,
234         const MouseEvent& rMEvt);
235 
236     virtual sal_uInt16  PrepareClose( sal_Bool bUI = sal_True, sal_Bool bForBrowsing = sal_False );
237 
238     PageKind        GetPageKind() { return mePageKind; }
239 
240     Point           GetMousePos() { return maMousePos; }
241     sal_Bool            IsMousePosFreezed() { return mbMousePosFreezed; }
242     void            SetMousePosFreezed( sal_Bool bIn ) { mbMousePosFreezed = bIn; }
243 
244     EditMode        GetEditMode() const { return meEditMode; }
245     virtual SdPage* GetActualPage() { return mpActualPage; }
246 
247     /// inherited from sd::ViewShell
248     virtual SdPage* getCurrentPage() const;
249 
250     void            ResetActualPage();
251     void            ResetActualLayer();
252     sal_Bool            SwitchPage(sal_uInt16 nPage);
253     sal_Bool            IsSwitchPageAllowed() const;
254 
255     sal_Bool            GotoBookmark(const String& rBookmark);
256     void            MakeVisible(const Rectangle& rRect, ::Window& rWin);
257 
258     virtual void    ReadFrameViewData(FrameView* pView);
259     virtual void    WriteFrameViewData();
260 
261     virtual ErrCode DoVerb(long nVerb);
262     virtual sal_Bool    ActivateObject(SdrOle2Obj* pObj, long nVerb);
263 
264     void            SetZoomOnPage( sal_Bool bZoom = sal_True ) { mbZoomOnPage = bZoom; }
265     sal_Bool            IsZoomOnPage() { return mbZoomOnPage; }
266     void            CheckLineTo (SfxRequest& rReq);
267     void            FuTemp01(SfxRequest& rReq);
268     void            FuTemp02(SfxRequest& rReq);
269     void            FuTemp03(SfxRequest& rReq);
270     void            FuTemp04(SfxRequest& rReq);
271     void            SetChildWindowState( SfxItemSet& rSet );
272 
273     void            UpdateIMapDlg( SdrObject* pObj );
274 
275     void            LockInput();
276     void            UnlockInput();
277     sal_Bool            IsInputLocked() const { return mnLockCount > 0UL; }
278 
279     sal_uInt16          GetCurPageId() { return( maTabControl.GetCurPageId() ); }
280 
281     /** Show controls of the UI or hide them, depending on the given flag.
282         Do not call this method directly.  Call the method at ViewShellBase
283         instead.
284     */
285     virtual void ShowUIControls (bool bVisible = true);
286 
287     void            ScannerEvent( const ::com::sun::star::lang::EventObject& rEventObject );
288 
289     bool IsLayerModeActive (void) const;
290 
291     sal_uInt16*         GetSlotArray() const { return mpSlotArray; }
292 
293     virtual sal_Int8    AcceptDrop( const AcceptDropEvent& rEvt, DropTargetHelper& rTargetHelper,
294                                     ::sd::Window* pTargetWindow, sal_uInt16 nPage, sal_uInt16 nLayer );
295     virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& rEvt, DropTargetHelper& rTargetHelper,
296                                     ::sd::Window* pTargetWindow, sal_uInt16 nPage, sal_uInt16 nLayer );
297 
298     virtual void    WriteUserDataSequence ( ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool bBrowse = sal_False );
299     virtual void    ReadUserDataSequence ( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, sal_Bool bBrowse = sal_False );
300 
301     virtual void    VisAreaChanged(const Rectangle& rRect);
302 
303     /** Create an accessible object representing the specified window.
304         @param pWindow
305             The returned object makes the document displayed in this window
306             accessible.
307         @return
308             Returns an <type>AccessibleDrawDocumentView</type> object.
309    */
310     virtual ::com::sun::star::uno::Reference<
311         ::com::sun::star::accessibility::XAccessible>
312         CreateAccessibleDocumentView (::sd::Window* pWindow);
313 
314     /** Return the number of layers managed by the layer tab control.  This
315         will usually differ from the number of layers managed by the layer
316         administrator.
317         @return
318             The number of layers managed by the layer tab control.  The
319             returned value is independent of whether the layer modus is
320             currently active and the tab control is visible.
321     */
322     virtual int GetTabLayerCount (void) const;
323 
324     /** Return the numerical id of the currently active layer as seen by the
325         layer tab control.
326         @return
327             The returned id is a number between zero (inclusive) and the
328             number of layers as returned by the
329             <member>GetTabLayerCount</member> method (exclusive).
330     */
331     virtual int GetActiveTabLayerIndex (void) const;
332 
333     /** Set the active layer at the layer tab control and update the control
334         accordingly to reflect the change on screen.
335         @param nId
336             The id is expected to be a number between zero (inclusive) and
337             the number of layers as returned by the
338             <member>GetTabLayerCount</member> method (exclusive).  Note that
339             Invalid values are ignored.  No excpetion is thrown in that case.
340     */
341     virtual void SetActiveTabLayerIndex (int nId);
342 
343     /** Return a pointer to the tab control for pages.
344     */
345     TabControl* GetPageTabControl (void);
346 
347     /** Return a pointer to the tab control for layers.
348     */
349     LayerTabBar* GetLayerTabControl (void);
350 
351     /** Renames the given slide using an SvxNameDialog
352 
353         @param nPageId the index of the page in the SdTabControl.
354         @param rName the new name of the slide.
355 
356         @return false, if the new name is invalid for some reason.
357 
358         <p>Implemented in <code>drviews8.cxx</code>.</p>
359      */
360     bool RenameSlide( sal_uInt16 nPageId, const String & rName );
361 
362     /** modifies the given layer with the given values */
363     void ModifyLayer( SdrLayer* pLayer, const String& rLayerName, const String& rLayerTitle, const String& rLayerDesc, bool bIsVisible, bool bIsLocked, bool bIsPrintable );
364 
365     virtual css::uno::Reference<css::drawing::XDrawSubController> CreateSubController (void);
366 
367     DrawView*   GetDrawView() const { return mpDrawView; }
368 
369     /** Relocation to a new parent window is not supported for DrawViewShell
370         objects so this method always returns <FALSE/>.
371     */
372     virtual bool RelocateToParentWindow (::Window* pParentWindow);
373 
374 protected:
375     DrawView*       mpDrawView;
376     SdPage*         mpActualPage;
377     Rectangle       maMarkRect;
378     Point           maMousePos;
379     sal_Bool            mbMousePosFreezed;
380     TabControl      maTabControl;
381     EditMode        meEditMode;
382     PageKind        mePageKind;
383     sal_Bool            mbZoomOnPage;
384     sal_Bool            mbIsRulerDrag;
385     sal_uLong           mnLockCount;
386     Timer           maCloseTimer;
387     sal_Bool            mbReadOnly;
388     sal_uInt16*         mpSlotArray;
389 
390     static sal_Bool     mbPipette;
391 
392                     DECL_LINK( ClipboardChanged, TransferableDataHelper* );
393                     DECL_LINK( CloseHdl, Timer* pTimer );
394                     DECL_LINK( TabSplitHdl, TabBar * );
395                     DECL_LINK( NameObjectHdl, AbstractSvxNameDialog* );
396                     DECL_LINK( RenameSlideHdl, AbstractSvxNameDialog* );
397 
398     void            DeleteActualPage();
399     void            DeleteActualLayer();
400 
401     virtual SvxRuler* CreateHRuler(::sd::Window* pWin, sal_Bool bIsFirst);
402     virtual SvxRuler* CreateVRuler(::sd::Window* pWin);
403     virtual void    UpdateHRuler();
404     virtual void    UpdateVRuler();
405     virtual long    GetHCtrlWidth();
406     virtual void    SetZoomFactor(const Fraction& rZoomX, const Fraction& rZoomY);
407     virtual Size    GetOptimalSizePixel() const;
408 
409     void            SetupPage( Size &rSize, long nLeft, long nRight, long nUpper, long nLower,
410                                sal_Bool bSize, sal_Bool bMargin, sal_Bool bScaleAll );
411 
412     sal_uInt16          GetIdBySubId( sal_uInt16 nSId );
413     void            MapSlot( sal_uInt16 nSId );
414     void            UpdateToolboxImages( SfxItemSet &rSet, sal_Bool bPermanent = sal_True );
415     sal_uInt16          GetMappedSlot( sal_uInt16 nSId );
416     sal_uInt16          GetArrayId( sal_uInt16 nSId );
417 
418     void            GetMenuStateSel(SfxItemSet& rSet);
419 
420 private:
421     /** This flag controls whether the layer mode is active, i.e. the layer
422         dialog is visible.
423     */
424     bool mbIsLayerModeActive;
425 
426     /** This item contains the clipboard formats of the current clipboard
427         content that are supported both by that content and by the
428         DrawViewShell.
429     */
430     ::std::auto_ptr<SvxClipboardFmtItem> mpCurrentClipboardFormats;
431 
432     /** On some occasions it is necessary to make SwitchPage calls
433         asynchronously.
434     */
435     tools::AsynchronousCall maAsynchronousSwitchPageCall;
436 
437     /** This flag is used to prevent nested calls to SwitchPage().
438     */
439     bool mbIsInSwitchPage;
440 
441     /** Listen for selection changes and broadcast context changes for the sidebar.
442     */
443     ::rtl::Reference<svx::sidebar::SelectionChangeHandler> mpSelectionChangeHandler;
444 
445     void Construct (DrawDocShell* pDocSh, PageKind ePageKind);
446 
447     /** Depending on the given request create a new page or duplicate an
448         existing one.  See ViewShell::CreateOrDuplicatePage() for more
449         information.
450     */
451     virtual SdPage* CreateOrDuplicatePage (
452         SfxRequest& rRequest,
453         PageKind ePageKind,
454         SdPage* pPage,
455         const sal_Int32 nInsertPosition = -1);
456 
457     ::com::sun::star::uno::Reference< ::com::sun::star::scanner::XScannerManager >  mxScannerManager;
458     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >      mxScannerListener;
459     TransferableClipboardListener*                                                  mpClipEvtLstnr;
460     sal_Bool                                                                            mbPastePossible;
461 
462     virtual void Notify (SfxBroadcaster& rBC, const SfxHint& rHint);
463 
464     /** Stop a running slide show.  The frame the show is running in is
465         destroyed if
466         a) it is running in its own frame, i.e. is a full screen show and
467         b) the given flag bCloseFrame is true.
468         @param bCloseFrame
469             Be carefull with this flag when stopping a full screen show.
470             When called from the destructor the flag has to be <FALSE/> or
471             otherwise we run into a loop of calls to destructors of the view
472             and the frame.
473             When called from other places the flag should be <TRUE/> so that
474             not an empty frame remains. When called with <TRUE/> it is the
475             responsibility of the caller to avoid an illegal reentrant
476             call.
477     */
478     void StopSlideShow (bool bCloseFrame);
479 
480     /** Show the context menu for snap lines and points.  Because snap lines
481         can not be selected the index of the snap line/point for which the
482         popup menu is opened has to be passed to the processing slot
483         handlers.  This can be done only by manually showing the popup menu.
484         @param rPageView
485             The page view is used to access the help lines.
486         @param nSnapLineIndex
487             Index of the snap line or snap point for which to show the
488             context menu.
489         @param rMouseLocation
490             The mouse location defines the location at which to display the
491             context menu.
492     */
493     void ShowSnapLineContextMenu (
494         SdrPageView& rPageView,
495         const sal_uInt16 nSnapLineIndex,
496         const Point& rMouseLocation);
497 
498     ::sfx2::sidebar::EnumContext::Context GetContextForSelection (void) const;
499 
500     using ViewShell::Notify;
501 
502     ::std::auto_ptr< AnnotationManager > mpAnnotationManager;
503     ::std::auto_ptr< ViewOverlayManager > mpViewOverlayManager;
504 };
505 
506 
507 } // end of namespace sd
508 
509 #endif
510