xref: /aoo41x/main/sd/source/ui/inc/sdtreelb.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 _SDTREELB_HXX
29 #define _SDTREELB_HXX
30 
31 #include <svtools/transfer.hxx>
32 
33 #ifndef _SD_SDRESID_HXX
34 #include "sdresid.hxx"
35 #endif
36 #include "pres.hxx"
37 #include "sddllapi.h"
38 #include <tools/string.hxx>
39 #include <svtools/svtreebx.hxx>
40 #include <svl/urlbmk.hxx>
41 #include <tools/ref.hxx>
42 #include "sdxfer.hxx"
43 #include <boost/scoped_ptr.hpp>
44 #include <boost/function.hpp>
45 
46 class SdDrawDocument;
47 class SfxMedium;
48 class SfxViewFrame;
49 class SdNavigatorWin;
50 class SdrObject;
51 class SdrObjList;
52 class SdPage;
53 class SvLBoxEntry;
54 
55 namespace sd {
56 class ViewShell;
57 
58 class DrawDocShell;
59 #ifndef SV_DECL_DRAW_DOC_SHELL_DEFINED
60 #define SV_DECL_DRAW_DOC_SHELL_DEFINED
61 SV_DECL_REF(DrawDocShell)
62 #endif
63 }
64 
65 /*************************************************************************
66 |*
67 |* Effekte-Tab-Dialog
68 |*
69 \************************************************************************/
70 
71 class SD_DLLPUBLIC SdPageObjsTLB : public SvTreeListBox
72 {
73 private:
74 
75 	static sal_Bool  SD_DLLPRIVATE bIsInDrag;      // static, falls der Navigator im ExecuteDrag geloescht wird
76 
77 public:
78 
79 	// nested class to implement the TransferableHelper
80 	class SdPageObjsTransferable : public SdTransferable
81 	{
82 	public:
83         SdPageObjsTransferable(
84             SdPageObjsTLB& rParent,
85             const INetBookmark& rBookmark,
86             ::sd::DrawDocShell& rDocShell,
87             NavigatorDragType eDragType,
88             const ::com::sun::star::uno::Any& rTreeListBoxData );
89 	    ::sd::DrawDocShell&     GetDocShell() const;
90 	    NavigatorDragType   GetDragType() const;
91 
92     	static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
93         static SdPageObjsTransferable* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData ) throw();
94         /** Return a temporary transferable data flavor that is used
95             internally in the navigator for reordering entries.  Its
96             lifetime ends with the office application.
97         */
98         static sal_uInt32 GetListBoxDropFormatId (void);
99 
100 	private:
101         /** Temporary drop flavor id that is used internally in the
102             navigator.
103         */
104         static sal_uInt32 mnListBoxDropFormatId;
105 
106 		SdPageObjsTLB&		mrParent;
107 		INetBookmark		maBookmark;
108 		::sd::DrawDocShell&     mrDocShell;
109 		NavigatorDragType   meDragType;
110         const ::com::sun::star::uno::Any maTreeListBoxData;
111 		SD_DLLPRIVATE virtual				~SdPageObjsTransferable();
112 
113 		SD_DLLPRIVATE virtual void		AddSupportedFormats();
114 		SD_DLLPRIVATE virtual sal_Bool	GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
115 		SD_DLLPRIVATE virtual void		DragFinished( sal_Int8 nDropAction );
116 
117         SD_DLLPRIVATE virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException );
118 	};
119 
120 	friend class SdPageObjsTLB::SdPageObjsTransferable;
121 
122     /** Determine whether the specified page belongs to the current show
123         which is either the standard show or a custom show.
124         @param pPage
125             Pointer to the page for which to check whether it belongs to the
126             show.
127         @return
128             Returns <FALSE/> if there is no custom show or if the current
129             show does not contain the specified page at least once.
130     */
131     bool PageBelongsToCurrentShow (const SdPage* pPage) const;
132 
133 protected:
134 
135 	Window* 				mpParent;
136 	const SdDrawDocument*	mpDoc;
137 	SdDrawDocument* 		mpBookmarkDoc;
138 	SfxMedium*				mpMedium;
139 	SfxMedium*				mpOwnMedium;
140 	Image					maImgOle;
141 	Image					maImgGraphic;
142 	Image					maImgOleH;
143 	Image					maImgGraphicH;
144 	sal_Bool                    mbLinkableSelected;
145 	sal_Bool					mbDragEnabled;
146 	String					maDocName;
147 	::sd::DrawDocShellRef		mxBookmarkDocShRef;	// Zum Laden von Bookmarks
148 	::sd::DrawDocShell* 		mpDropDocSh;
149 	SdNavigatorWin*			mpDropNavWin;
150 	SfxViewFrame*           mpFrame;
151 
152 	// DragSourceHelper
153 	virtual void			StartDrag( sal_Int8 nAction, const Point& rPosPixel );
154 
155 	// DropTargetHelper
156 	virtual sal_Int8		AcceptDrop( const AcceptDropEvent& rEvt );
157 	virtual	sal_Int8		ExecuteDrop( const ExecuteDropEvent& rEvt );
158 
159 	virtual void			RequestingChilds( SvLBoxEntry* pParent );
160 
161     void                    DoDrag();
162 	void					OnDragFinished( sal_uInt8 nDropAction );
163 
164     /** Return the name of the object.  When the object has no user supplied
165         name and the bCreate flag is <TRUE/> then a name is created
166         automatically.  Additionally the mbShowAllShapes flag is taken into
167         account when there is no user supplied name.  When this flag is
168         <FALSE/> then no name is created.
169         @param pObject
170             When this is NULL then an empty string is returned, regardless
171             of the value of bCreate.
172         @param bCreate
173             This flag controls for objects without user supplied name
174             whether a name is created.  When a name is created then this
175             name is not stored in the object.
176     */
177     String GetObjectName (
178         const SdrObject* pObject,
179         const bool bCreate = true) const;
180     void                    CloseBookmarkDoc();
181 							DECL_STATIC_LINK(SdPageObjsTLB, ExecDragHdl, void*);
182 
183     /** Handle the reordering of entries in the navigator.  This method
184         reorders both the involved shapes in their page as well as the
185         associated list box entries.
186     */
187 	virtual sal_Bool NotifyMoving(
188 		SvLBoxEntry*  pTarget,
189 		SvLBoxEntry*  pEntry,
190 		SvLBoxEntry*& rpNewParent,
191 		sal_uLong&		  rNewChildPos);
192 
193     using Window::GetDropTarget;
194     virtual SvLBoxEntry* GetDropTarget (const Point& rLocation);
195 
196 public:
197 
198 							SdPageObjsTLB( Window* pParent, const SdResId& rSdResId );
199 							~SdPageObjsTLB();
200 
201 	virtual void			SelectHdl();
202 	virtual void			KeyInput( const KeyEvent& rKEvt );
203 
204 	void					SetViewFrame( SfxViewFrame* pViewFrame ) { mpFrame = pViewFrame; }
205 	SfxViewFrame*			GetViewFrame() const { return mpFrame; }
206 
207 	void					Fill( const SdDrawDocument*, sal_Bool bAllPages, const String& rDocName );
208 	void					Fill( const SdDrawDocument*, SfxMedium* pSfxMedium, const String& rDocName );
209     void                    SetShowAllShapes (const bool bShowAllShapes, const bool bFill);
210     bool                    GetShowAllShapes (void) const;
211 	sal_Bool					IsEqualToDoc( const SdDrawDocument* pInDoc = NULL );
212 	sal_Bool					HasSelectedChilds( const String& rName );
213 	sal_Bool					SelectEntry( const String& rName );
214 	String					GetSelectEntry();
215 	List*					GetSelectEntryList( sal_uInt16 nDepth );
216 	SdDrawDocument*			GetBookmarkDoc(SfxMedium* pMedium = NULL);
217 	::sd::DrawDocShell*			GetDropDocSh() { return(mpDropDocSh); }
218 
219 	sal_Bool                    IsLinkableSelected() const { return mbLinkableSelected; }
220 
221 	static sal_Bool				IsInDrag();
222 	using SvLBox::ExecuteDrop;
223 
224     using SvTreeListBox::SelectEntry;
225 
226     /** Return the view shell that is linked to the given doc shell.
227         Call this method when the there is a chance that the doc shell
228         has been disconnected from the view shell (but not the other
229         way round.)
230         @return
231             May return <NULL/> when the link between view shell and
232             doc shell has been severed.
233     */
234     static ::sd::ViewShell* GetViewShellForDocShell (::sd::DrawDocShell &rDocShell);
235 
236 private:
237     /** This flag controls whether all shapes are shown as children of pages
238         and group shapes or only the named shapes.
239     */
240     bool mbShowAllShapes;
241     /** This flag controls whether to show all pages.
242     */
243     bool mbShowAllPages;
244 
245     /** Return <TRUE/> when the current transferable may be dropped at the
246         given list box entry.
247     */
248     bool IsDropAllowed (SvLBoxEntry* pEntry);
249 
250     /** This inner class is defined in sdtreelb.cxx and is basically a
251         container for the icons used in the list box for the entries.
252     */
253     class IconProvider;
254 
255     /** Add one list box entry for the parent of the given shapes and one child entry for
256         each of the given shapes.
257         @param rList
258             The container of shapes that are to be inserted.
259         @param pShape
260             The parent shape or NULL when the parent is a page.
261         @param rsName
262             The name to be displayed for the new parent node.
263         @param bIsExcluded
264             Some pages can be excluded (from the show?).
265         @param pParentEntry
266             The parent entry of the new parent entry.
267         @param rIconProvider
268             Icons used to visualize the different shape and page types.
269     */
270     void AddShapeList (
271         const SdrObjList& rList,
272         SdrObject* pShape,
273         const ::rtl::OUString& rsName,
274         const bool bIsExcluded,
275         SvLBoxEntry* pParentEntry,
276         const IconProvider& rIconProvider);
277 
278     /** Add the given object to a transferable object so that the object can
279         be dragged and dropped without having a name.
280     */
281     void AddShapeToTransferable (
282         SdTransferable& rTransferable,
283         SdrObject& rObject) const;
284 };
285 
286 #endif		// _SDTREELB_HXX
287