xref: /trunk/main/sw/source/ui/inc/conttree.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 #ifndef _CONTTREE_HXX
28 #define _CONTTREE_HXX
29 
30 #include <svtools/svtreebx.hxx>
31 #include "swcont.hxx"
32 
33 class SwWrtShell;
34 class SwContentType;
35 class SwNavigationPI;
36 class SwNavigationConfig;
37 class Menu;
38 class ToolBox;
39 class SwGlblDocContents;
40 class SwGlblDocContent;
41 class SfxObjectShell;
42 
43 
44 #define EDIT_MODE_EDIT          0
45 #define EDIT_MODE_UPD_IDX       1
46 #define EDIT_MODE_RMV_IDX       2
47 #define EDIT_UNPROTECT_TABLE    3
48 #define EDIT_MODE_DELETE        4
49 #define EDIT_MODE_RENAME        5
50 
51 //----------------------------------------------------------------------------
52 //----------------------------------------------------------------------------
53 
54 class SwContentTree : public SvTreeListBox
55 {
56     ImageList           aEntryImages;
57     String              sSpace;
58     AutoTimer           aUpdTimer;
59 
60     SwContentType*      aActiveContentArr[CONTENT_TYPE_MAX];
61     SwContentType*      aHiddenContentArr[CONTENT_TYPE_MAX];
62     String              aContextStrings[CONTEXT_COUNT + 1];
63     String              sRemoveIdx;
64     String              sUpdateIdx;
65     String              sUnprotTbl;
66     String              sRename;
67     String              sReadonlyIdx;
68     String              sInvisible;
69     String              sPostItShow;
70     String              sPostItHide;
71     String              sPostItDelete;
72 
73     SwWrtShell*         pHiddenShell;   // gedropptes Doc
74     SwWrtShell*         pActiveShell;   // die aktive oder eine konst. offene View
75     SwNavigationConfig* pConfig;
76 
77     sal_Int32           nActiveBlock;
78     sal_uInt16              nHiddenBlock;
79     sal_uInt16              nRootType;
80     sal_uInt16              nLastSelType;
81     sal_uInt8               nOutlineLevel;
82 
83     sal_Bool                bIsActive           :1;
84     sal_Bool                bIsConstant         :1;
85     sal_Bool                bIsHidden           :1;
86     sal_Bool                bDocChgdInDragging  :1;
87     sal_Bool                bIsInternalDrag     :1;
88     sal_Bool                bIsRoot             :1;
89     sal_Bool                bIsIdleClear        :1;
90     sal_Bool                bIsLastReadOnly     :1;
91     sal_Bool                bIsOutlineMoveable  :1;
92     sal_Bool                bViewHasChanged     :1;
93     sal_Bool                bIsImageListInitialized : 1;
94 
95     static sal_Bool         bIsInDrag;
96 
97     void                FindActiveTypeAndRemoveUserData();
98 
99     using SvLBox::ExecuteDrop;
100     using SvTreeListBox::EditEntry;
101     using SvListView::Expand;
102     using SvListView::Collapse;
103     using SvListView::Select;
104 
105 protected:
106 //  virtual void    Command( const CommandEvent& rCEvt );
107     virtual void    RequestHelp( const HelpEvent& rHEvt );
108     virtual void    InitEntry(SvLBoxEntry*,const XubString&,const Image&,const Image&,SvLBoxButtonKind);
109     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
110 
111     SwNavigationPI* GetParentWindow(){return
112                         (SwNavigationPI*)Window::GetParent();}
113 
114     virtual void    StartDrag( sal_Int8 nAction, const Point& rPosPixel );
115     virtual void    DragFinished( sal_Int8 );
116     virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
117 
118     virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );
119 
120     sal_Bool        FillTransferData( TransferDataContainer& rTransfer,
121                                             sal_Int8& rDragMode );
122     sal_Bool            HasContentChanged();
123 
124     virtual DragDropMode NotifyStartDrag( TransferDataContainer& rData,
125                                         SvLBoxEntry* );
126     virtual sal_Bool    NotifyAcceptDrop( SvLBoxEntry* );
127 
128     virtual sal_Bool    NotifyMoving(   SvLBoxEntry*  pTarget,
129                                     SvLBoxEntry*  pEntry,
130                                     SvLBoxEntry*& rpNewParent,
131                                     sal_uLong&        rNewChildPos
132                                 );
133     virtual sal_Bool    NotifyCopying(  SvLBoxEntry*  pTarget,
134                                     SvLBoxEntry*  pEntry,
135                                     SvLBoxEntry*& rpNewParent,
136                                     sal_uLong&        rNewChildPos
137                                 );
138     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
139 
140     void            EditEntry( SvLBoxEntry* pEntry, sal_uInt8 nMode );
141 
142     void            GotoContent(SwContent* pCnt);
143     static void     SetInDrag(sal_Bool bSet) {bIsInDrag = bSet;}
144 
145     virtual PopupMenu* CreateContextMenu( void );
146     virtual void    ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry );
147 
148 public:
149     SwContentTree(Window* pParent, const ResId& rResId);
150     ~SwContentTree();
151 
152     sal_Bool            ToggleToRoot();
153     sal_Bool            IsRoot() const {return bIsRoot;}
154     sal_uInt16          GetRootType() const {return nRootType;}
155     void            SetRootType(sal_uInt16 nType);
156     void            Display( sal_Bool bActiveView );
157     void            Clear();
158     void            SetHiddenShell(SwWrtShell* pSh);
159     void            ShowHiddenShell();
160     void            ShowActualView();
161     void            SetActiveShell(SwWrtShell* pSh);
162     void            SetConstantShell(SwWrtShell* pSh);
163 
164     SwWrtShell*     GetWrtShell()
165                         {return bIsActive||bIsConstant ?
166                                     pActiveShell :
167                                         pHiddenShell;}
168 
169     static sal_Bool     IsInDrag() {return bIsInDrag;}
170     sal_Bool            IsInternalDrag() const {return bIsInternalDrag != 0;}
171 
172     sal_Int32       GetActiveBlock() const {return nActiveBlock;}
173 
174     sal_uInt8           GetOutlineLevel()const {return nOutlineLevel;}
175     void            SetOutlineLevel(sal_uInt8 nSet);
176 
177     sal_Bool            Expand( SvLBoxEntry* pParent );
178 
179     sal_Bool            Collapse( SvLBoxEntry* pParent );
180 
181     void            ExecCommand(sal_uInt16 nCmd, sal_Bool bModifier);
182 
183     void            ShowTree();
184     void            HideTree();
185 
186     sal_Bool            IsConstantView() {return bIsConstant;}
187     sal_Bool            IsActiveView()   {return bIsActive;}
188     sal_Bool            IsHiddenView()   {return bIsHidden;}
189 
190     const SwWrtShell*   GetActiveWrtShell() {return pActiveShell;}
191     SwWrtShell*         GetHiddenWrtShell() {return pHiddenShell;}
192 
193     DECL_LINK( ContentDoubleClickHdl, SwContentTree * );
194 //  DECL_LINK( PopupHdl, Menu* );
195     DECL_LINK( TimerUpdate, Timer * );
196 
197     virtual long    GetTabPos( SvLBoxEntry*, SvLBoxTab* );
198     virtual void    RequestingChilds( SvLBoxEntry* pParent );
199     virtual void    GetFocus();
200     virtual void    KeyInput(const KeyEvent& rKEvt);
201 
202     virtual sal_Bool    Select( SvLBoxEntry* pEntry, sal_Bool bSelect=sal_True );
203 };
204 
205 
206 //----------------------------------------------------------------------------
207 // TreeListBox fuer Globaldokumente
208 //----------------------------------------------------------------------------
209 
210 class SwLBoxString : public SvLBoxString
211 {
212 public:
213 
214     SwLBoxString( SvLBoxEntry* pEntry, sal_uInt16 nFlags,
215         const String& rStr ) : SvLBoxString(pEntry,nFlags,rStr)
216     {
217     }
218 
219     virtual void Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags,
220         SvLBoxEntry* pEntry);
221 };
222 
223 namespace sfx2 { class DocumentInserter; }
224 namespace sfx2 { class FileDialogHelper; }
225 
226 class SwGlobalTree : public SvTreeListBox
227 {
228 private:
229     AutoTimer           aUpdateTimer;
230     String              aContextStrings[GLOBAL_CONTEXT_COUNT];
231 
232     ImageList           aEntryImages;
233 
234     SwWrtShell*             pActiveShell;   //
235     SvLBoxEntry*            pEmphasisEntry; // Drag'n Drop-Emphasis
236     SvLBoxEntry*            pDDSource;      // Quelle beim DnD
237     SwGlblDocContents*      pSwGlblDocContents; // Array mit sortierten Inhalten
238 
239     Window*                 pDefParentWin;
240     SwGlblDocContent*       pDocContent;
241     sfx2::DocumentInserter* pDocInserter;
242 
243     sal_Bool                bIsInternalDrag     :1;
244     sal_Bool                bLastEntryEmphasis  :1; // Drag'n Drop
245     sal_Bool                bIsImageListInitialized : 1;
246 
247     static const SfxObjectShell* pShowShell;
248 
249     void        InsertRegion( const SwGlblDocContent* _pContent,
250                               const com::sun::star::uno::Sequence< ::rtl::OUString >& _rFiles );
251 
252     DECL_LINK(  DialogClosedHdl, sfx2::FileDialogHelper* );
253 
254     using SvLBox::DoubleClickHdl;
255     using SvLBox::ExecuteDrop;
256     using Window::Update;
257 
258 protected:
259 
260     virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
261 
262     virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );
263 
264     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
265 
266     virtual void    RequestHelp( const HelpEvent& rHEvt );
267 
268     virtual long    GetTabPos( SvLBoxEntry*, SvLBoxTab* );
269     virtual sal_Bool    NotifyMoving(   SvLBoxEntry*  pTarget,
270                                     SvLBoxEntry*  pEntry,
271                                     SvLBoxEntry*& rpNewParent,
272                                     sal_uLong&        rNewChildPos
273                                 );
274     virtual sal_Bool    NotifyCopying(  SvLBoxEntry*  pTarget,
275                                     SvLBoxEntry*  pEntry,
276                                     SvLBoxEntry*& rpNewParent,
277                                     sal_uLong&        rNewChildPos
278                                 );
279 
280     virtual void    StartDrag( sal_Int8 nAction, const Point& rPosPixel );
281     virtual void    DragFinished( sal_Int8 );
282     virtual DragDropMode NotifyStartDrag( TransferDataContainer& rData,
283                                         SvLBoxEntry* );
284     virtual sal_Bool    NotifyAcceptDrop( SvLBoxEntry* );
285 
286     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
287     virtual void    KeyInput(const KeyEvent& rKEvt);
288     virtual void    GetFocus();
289     virtual void    SelectHdl();
290     virtual void    DeselectHdl();
291     virtual void InitEntry(SvLBoxEntry*,const XubString&,const Image&,const Image&,SvLBoxButtonKind);
292 
293     void            Clear();
294 
295     DECL_LINK(      PopupHdl, Menu* );
296     DECL_LINK(      Timeout, Timer* );
297     DECL_LINK(      DoubleClickHdl, SwGlobalTree * );
298 
299     sal_Bool            IsInternalDrag() const {return bIsInternalDrag != 0;}
300     SwNavigationPI* GetParentWindow()
301                         { return (SwNavigationPI*)Window::GetParent(); }
302 
303     void            OpenDoc(const SwGlblDocContent*);
304     void            GotoContent(const SwGlblDocContent*);
305     sal_uInt16          GetEnableFlags() const;
306 
307     static const SfxObjectShell*    GetShowShell() {return pShowShell;}
308     static void     SetShowShell(const SfxObjectShell*pSet) {pShowShell = pSet;}
309     DECL_STATIC_LINK(SwGlobalTree, ShowFrameHdl, SwGlobalTree*);
310 
311     virtual PopupMenu* CreateContextMenu( void );
312     virtual void    ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry );
313 
314 public:
315     SwGlobalTree(Window* pParent, const ResId& rResId);
316     virtual ~SwGlobalTree();
317 
318     void                TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox);
319     void                InsertRegion( const SwGlblDocContent* pCont,
320                                         const String* pFileName = 0 );
321     void                EditContent(const SwGlblDocContent* pCont );
322 
323     void                ShowTree();
324     void                HideTree();
325 
326     void                ExecCommand(sal_uInt16 nCmd);
327 
328     void                Display(sal_Bool bOnlyUpdateUserData = sal_False);
329 
330     sal_Bool                Update(sal_Bool bHard);
331 };
332 
333 #endif
334 
335