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