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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27 #ifndef _SVSTDARR_HXX
28 #define _SVSTDARR_STRINGSDTOR
29 #include <svl/svstdarr.hxx>
30 #endif
31 #include <vcl/msgbox.hxx>
32 #include <svl/stritem.hxx>
33 #include <sfx2/fcontnr.hxx>
34 #include <sfx2/linkmgr.hxx>
35 #include <sfx2/dispatch.hxx>
36 #include <svl/urihelper.hxx>
37 #include <sfx2/docfile.hxx>
38 #include <vcl/help.hxx>
39 #include <sot/filelist.hxx>
40 #include <svl/eitem.hxx>
41 #include <svl/urlbmk.hxx>
42 #include <svtools/filter.hxx>
43 #include <sfx2/docinsert.hxx>
44 #include <sfx2/filedlghelper.hxx>
45
46 #include <sfx2/app.hxx>
47 #include <swmodule.hxx>
48 #include <wrtsh.hxx>
49 #include <view.hxx>
50 #include <errhdl.hxx>
51 #include <docsh.hxx>
52 #include <content.hxx>
53 #include <edglbldc.hxx>
54 #include <section.hxx>
55 #include <tox.hxx>
56 #include <cnttab.hxx>
57 #define NAVIPI_CXX
58 #include <navipi.hxx>
59 #include <navicont.hxx>
60 #include <edtwin.hxx>
61 #include <uitool.hxx>
62
63 #include <cmdid.h>
64 #include <helpid.h>
65 #ifndef _NAVIPI_HRC
66 #include <navipi.hrc>
67 #endif
68 #ifndef _UTLUI_HRC
69 #include <utlui.hrc>
70 #endif
71 #ifndef _COMCORE_HRC
72 #include <comcore.hrc>
73 #endif
74 #include <globals.hrc>
75 #include "swabstdlg.hxx"
76
77 using namespace ::com::sun::star::uno;
78 using ::rtl::OUString;
79
80
81 // Kontextmenue fuer GlobalTree
82 #define CTX_INSERT_ANY_INDEX 10
83 //#define CTX_INSERT_CNTIDX 11
84 //#define CTX_INSERT_USRIDX 12
85 #define CTX_INSERT_FILE 11
86 #define CTX_INSERT_NEW_FILE 12
87 #define CTX_INSERT_TEXT 13
88
89 #define CTX_UPDATE_SEL 20
90 #define CTX_UPDATE_INDEX 21
91 #define CTX_UPDATE_LINK 22
92 #define CTX_UPDATE_ALL 23
93
94 #define CTX_UPDATE 1
95 #define CTX_INSERT 2
96 #define CTX_EDIT 3
97 #define CTX_DELETE 4
98 #define CTX_EDIT_LINK 5
99
100 #define GLOBAL_UPDATE_TIMEOUT 2000
101
102 // Flags fuer PopupMenu-enable/disable
103 #define ENABLE_INSERT_IDX 0x0001
104 #define ENABLE_INSERT_FILE 0x0002
105 #define ENABLE_INSERT_TEXT 0x0004
106 #define ENABLE_EDIT 0x0008
107 #define ENABLE_DELETE 0x0010
108 #define ENABLE_UPDATE 0x0020
109 #define ENABLE_UPDATE_SEL 0x0040
110 #define ENABLE_EDIT_LINK 0x0080
111
112 // TabPos nach links schieben
113 #define GLBL_TABPOS_SUB 5
114
115 const SfxObjectShell* SwGlobalTree::pShowShell = 0;
116 static const char* __FAR_DATA aHelpForMenu[] =
117 {
118 0, //
119 HID_GLBLTREE_UPDATE, //CTX_UPDATE
120 HID_GLBLTREE_INSERT, //CTX_INSERT
121 HID_GLBLTREE_EDIT, //CTX_EDIT
122 HID_GLBLTREE_DEL, //CTX_DELETE
123 HID_GLBLTREE_EDIT_LINK, //CTX_EDIT_LINK
124 0, //
125 0, //
126 0, //
127 0, //
128 HID_GLBLTREE_INS_IDX, //CTX_INSERT_ANY_INDEX
129 HID_GLBLTREE_INS_FILE, //CTX_INSERT_FILE
130 HID_GLBLTREE_INS_NEW_FILE, //CTX_INSERT_NEW_FILE
131 HID_GLBLTREE_INS_TEXT, //CTX_INSERT_TEXT
132 0, //
133 0, //
134 0, //
135 0, //
136 0, //
137 0, //
138 HID_GLBLTREE_UPD_SEL, //CTX_UPDATE_SEL
139 HID_GLBLTREE_UPD_IDX, //CTX_UPDATE_INDEX
140 HID_GLBLTREE_UPD_LINK, //CTX_UPDATE_LINK
141 HID_GLBLTREEUPD_ALL //CTX_UPDATE_ALL
142 };
143
144 /************************************************************************/
145 /* */
146 /************************************************************************/
147 /* -----------------------------24.08.00 12:04--------------------------------
148
149 ---------------------------------------------------------------------------*/
150 class SwGlobalFrameListener_Impl : public SfxListener
151 {
152 sal_Bool bValid;
153 public:
SwGlobalFrameListener_Impl(SfxViewFrame & rFrame)154 SwGlobalFrameListener_Impl(SfxViewFrame& rFrame) :
155 bValid(sal_True)
156 {
157 StartListening(rFrame);
158 }
159
160 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
161
IsValid() const162 sal_Bool IsValid() const {return bValid;}
163 };
164 /* -----------------------------24.08.00 12:05--------------------------------
165
166 ---------------------------------------------------------------------------*/
Notify(SfxBroadcaster &,const SfxHint & rHint)167 void SwGlobalFrameListener_Impl::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
168 {
169 if( rHint.ISA(SfxSimpleHint) &&
170 (((SfxSimpleHint&) rHint).GetId() == SFX_HINT_DYING))
171 bValid = sal_False;
172 }
173
174 /*-----------------12.06.97 09:38-------------------
175
176 --------------------------------------------------*/
SwGlobalTree(Window * pParent,const ResId & rResId)177 SwGlobalTree::SwGlobalTree(Window* pParent, const ResId& rResId) :
178
179 SvTreeListBox(pParent, rResId),
180
181 pActiveShell ( NULL ),
182 pEmphasisEntry ( NULL ),
183 pDDSource ( NULL ),
184 pSwGlblDocContents ( NULL ),
185 pDefParentWin ( NULL ),
186 pDocContent ( NULL ),
187 pDocInserter ( NULL ),
188
189 bIsInternalDrag ( sal_False ),
190 bLastEntryEmphasis ( sal_False ),
191 bIsImageListInitialized ( sal_False )
192
193 {
194 SetDragDropMode(SV_DRAGDROP_APP_COPY |
195 SV_DRAGDROP_CTRL_MOVE |
196 SV_DRAGDROP_ENABLE_TOP );
197
198 aUpdateTimer.SetTimeout(GLOBAL_UPDATE_TIMEOUT);
199 aUpdateTimer.SetTimeoutHdl(LINK(this, SwGlobalTree, Timeout));
200 aUpdateTimer.Start();
201 for(sal_uInt16 i = 0; i < GLOBAL_CONTEXT_COUNT; i++)
202 {
203 aContextStrings[i] = SW_RESSTR(i+ ST_GLOBAL_CONTEXT_FIRST);
204 }
205 SetHelpId(HID_NAVIGATOR_GLOB_TREELIST);
206 SelectHdl();
207 SetDoubleClickHdl(LINK(this, SwGlobalTree, DoubleClickHdl));
208 EnableContextMenuHandling();
209 }
210
211 /*-----------------12.06.97 09:38-------------------
212
213 --------------------------------------------------*/
~SwGlobalTree()214 SwGlobalTree::~SwGlobalTree()
215 {
216 delete pSwGlblDocContents;
217 delete pDocInserter;
218 }
219
220 /*-----------------12.06.97 09:38-------------------
221
222 --------------------------------------------------*/
ExecuteDrop(const ExecuteDropEvent & rEvt)223 sal_Int8 SwGlobalTree::ExecuteDrop( const ExecuteDropEvent& rEvt )
224 {
225 sal_Int8 nRet = DND_ACTION_NONE;
226 SvLBoxEntry* pLast = (SvLBoxEntry*)LastVisible();
227 if(pEmphasisEntry)
228 {
229 ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
230 pEmphasisEntry = 0;
231 }
232 else if(bLastEntryEmphasis && pLast)
233 {
234 ImplShowTargetEmphasis( pLast, sal_False);
235 }
236
237 SvLBoxEntry* pDropEntry = bLastEntryEmphasis ? 0 : GetEntry(rEvt.maPosPixel);
238 if( bIsInternalDrag )
239 {
240 SvLBoxEntry* pDummy = 0;
241 sal_uLong nInsertionPos = LIST_APPEND;
242 NotifyMoving( pDropEntry, pDDSource, pDummy, nInsertionPos );
243 }
244 else
245 {
246 TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
247
248 String sFileName;
249 const SwGlblDocContent* pCnt = pDropEntry ?
250 (const SwGlblDocContent*)pDropEntry->GetUserData() :
251 0;
252 if( aData.HasFormat( FORMAT_FILE_LIST ))
253 {
254 nRet = rEvt.mnAction;
255 SwGlblDocContents* pTempContents = new SwGlblDocContents;
256 int nAbsContPos = pDropEntry ?
257 (int) GetModel()->GetAbsPos(pDropEntry):
258 - 1;
259 sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
260
261 // Daten holen
262 FileList aFileList;
263 aData.GetFileList( FORMAT_FILE_LIST, aFileList );
264 for ( sal_uInt16 n = (sal_uInt16)aFileList.Count(); n--; )
265 {
266 sFileName = aFileList.GetFile(n);
267 InsertRegion(pCnt, &sFileName);
268 // nach dem Einfuegen muss die Liste der Contents neu
269 // geholt werden, um nicht auf einem alten Content zu
270 // arbeiten
271 if(n)
272 {
273 pActiveShell->GetGlobalDocContent(*pTempContents);
274 // wenn das file erfolgreich eingefuegt wurde,
275 // dann muss auch der naechste Content geholt werden
276 if(nEntryCount < pTempContents->Count())
277 {
278 nEntryCount++;
279 nAbsContPos++;
280 pCnt = pTempContents->GetObject( static_cast< sal_uInt16 >(nAbsContPos) );
281 }
282 }
283 }
284 delete pTempContents;
285 }
286 else if( 0 != (sFileName =
287 SwNavigationPI::CreateDropFileName( aData )).Len())
288 {
289 INetURLObject aTemp(sFileName);
290 GraphicDescriptor aDesc(aTemp);
291 if( !aDesc.Detect() ) // keine Grafiken annehmen
292 {
293 nRet = rEvt.mnAction;
294 InsertRegion(pCnt, &sFileName);
295 }
296 }
297 }
298 bLastEntryEmphasis = sal_False;
299 return nRet;
300
301 }
302 /*-----------------12.06.97 09:38-------------------
303
304 --------------------------------------------------*/
AcceptDrop(const AcceptDropEvent & rEvt)305 sal_Int8 SwGlobalTree::AcceptDrop( const AcceptDropEvent& rEvt )
306 {
307 sal_Int8 nRet = rEvt.mnAction;
308
309 //initiate scrolling
310 GetDropTarget( rEvt.maPosPixel );
311 SvLBoxEntry* pLast = (SvLBoxEntry*)LastVisible();
312 if( rEvt.mbLeaving )
313 {
314 if( pEmphasisEntry )
315 {
316 ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
317 pEmphasisEntry = 0;
318 }
319 else if(bLastEntryEmphasis && pLast)
320 {
321 ImplShowTargetEmphasis( pLast, sal_False);
322 }
323 bLastEntryEmphasis = sal_False;
324 }
325 else
326 {
327 SvLBoxEntry* pDropEntry = GetEntry( rEvt.maPosPixel );
328 if(bIsInternalDrag)
329 {
330 if( pDDSource != pDropEntry )
331 nRet = rEvt.mnAction;
332 }
333 else if( IsDropFormatSupported( FORMAT_FILE ) ||
334 IsDropFormatSupported( FORMAT_STRING ) ||
335 IsDropFormatSupported( FORMAT_FILE_LIST ) ||
336 IsDropFormatSupported( SOT_FORMATSTR_ID_SOLK ) ||
337 IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK )||
338 IsDropFormatSupported( SOT_FORMATSTR_ID_FILECONTENT ) ||
339 IsDropFormatSupported( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) ||
340 IsDropFormatSupported( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) ||
341 IsDropFormatSupported( SOT_FORMATSTR_ID_FILENAME ))
342 nRet = DND_ACTION_LINK;
343
344 if(pEmphasisEntry && pEmphasisEntry != pDropEntry)
345 ImplShowTargetEmphasis( Prev(pEmphasisEntry), sal_False );
346 else if(pLast && bLastEntryEmphasis && pDropEntry)
347 {
348 ImplShowTargetEmphasis( pLast, sal_False);
349 bLastEntryEmphasis = sal_False;
350 }
351
352 if(pDropEntry)
353 ImplShowTargetEmphasis( Prev(pDropEntry), DND_ACTION_NONE != nRet );
354 else if(pLast)
355 {
356 ImplShowTargetEmphasis( pLast, DND_ACTION_NONE != nRet );
357 bLastEntryEmphasis = sal_True;
358 }
359 pEmphasisEntry = pDropEntry;
360 }
361 return nRet;
362 }
363 /*-----------------12.06.97 09:38-------------------
364
365 --------------------------------------------------*/
CreateContextMenu()366 PopupMenu* SwGlobalTree::CreateContextMenu()
367 {
368 PopupMenu* pPop = 0;
369 if(pActiveShell &&
370 !pActiveShell->GetView().GetDocShell()->IsReadOnly())
371 {
372 sal_uInt16 nEnableFlags = GetEnableFlags();
373 pPop = new PopupMenu;
374 PopupMenu* pSubPop1 = new PopupMenu;
375 PopupMenu* pSubPop2 = new PopupMenu;
376
377 for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
378 {
379 pSubPop2->InsertItem( i, aContextStrings[ST_UPDATE_SEL - ST_GLOBAL_CONTEXT_FIRST - CTX_UPDATE_SEL+ i] );
380 pSubPop2->SetHelpId(i, aHelpForMenu[i]);
381 }
382 pSubPop2->EnableItem(CTX_UPDATE_SEL, 0 != (nEnableFlags & ENABLE_UPDATE_SEL));
383
384 pSubPop1->InsertItem(CTX_INSERT_ANY_INDEX, aContextStrings[ST_INDEX - ST_GLOBAL_CONTEXT_FIRST]);
385 pSubPop1->SetHelpId(CTX_INSERT_ANY_INDEX, aHelpForMenu[CTX_INSERT_ANY_INDEX]);
386 pSubPop1->InsertItem(CTX_INSERT_FILE, aContextStrings[ST_FILE - ST_GLOBAL_CONTEXT_FIRST]);
387 pSubPop1->SetHelpId(CTX_INSERT_FILE, aHelpForMenu[CTX_INSERT_FILE]);
388 pSubPop1->InsertItem(CTX_INSERT_NEW_FILE, aContextStrings[ST_NEW_FILE - ST_GLOBAL_CONTEXT_FIRST]);
389 pSubPop1->SetHelpId(CTX_INSERT_NEW_FILE, aHelpForMenu[CTX_INSERT_NEW_FILE]);
390 pSubPop1->InsertItem(CTX_INSERT_TEXT, aContextStrings[ST_TEXT - ST_GLOBAL_CONTEXT_FIRST]);
391 pSubPop1->SetHelpId(CTX_INSERT_TEXT, aHelpForMenu[CTX_INSERT_TEXT]);
392
393
394 pPop->InsertItem(CTX_UPDATE, aContextStrings[ST_UPDATE - ST_GLOBAL_CONTEXT_FIRST]);
395 pPop->SetHelpId(CTX_UPDATE, aHelpForMenu[CTX_UPDATE]);
396 pPop->InsertItem(CTX_EDIT, aContextStrings[ST_EDIT_CONTENT - ST_GLOBAL_CONTEXT_FIRST]);
397 pPop->SetHelpId(CTX_EDIT, aHelpForMenu[CTX_EDIT]);
398 if(nEnableFlags&ENABLE_EDIT_LINK)
399 {
400 pPop->InsertItem(CTX_EDIT_LINK, aContextStrings[ST_EDIT_LINK - ST_GLOBAL_CONTEXT_FIRST]);
401 pPop->SetHelpId(CTX_EDIT_LINK, aHelpForMenu[CTX_EDIT_LINK]);
402 }
403 pPop->InsertItem(CTX_INSERT, aContextStrings[ST_INSERT - ST_GLOBAL_CONTEXT_FIRST]);
404 pPop->SetHelpId(CTX_INSERT, aHelpForMenu[CTX_INSERT]);
405 pPop->InsertSeparator() ;
406 pPop->InsertItem(CTX_DELETE, aContextStrings[ST_DELETE - ST_GLOBAL_CONTEXT_FIRST]);
407 pPop->SetHelpId(CTX_DELETE, aHelpForMenu[CTX_DELETE]);
408
409 //evtl. disablen
410 pSubPop1->EnableItem(CTX_INSERT_ANY_INDEX, 0 != (nEnableFlags & ENABLE_INSERT_IDX ));
411 pSubPop1->EnableItem(CTX_INSERT_TEXT, 0 != (nEnableFlags & ENABLE_INSERT_TEXT));
412 pSubPop1->EnableItem(CTX_INSERT_FILE, 0 != (nEnableFlags & ENABLE_INSERT_FILE));
413 pSubPop1->EnableItem(CTX_INSERT_NEW_FILE, 0 != (nEnableFlags & ENABLE_INSERT_FILE));
414
415 pPop->EnableItem(CTX_UPDATE, 0 != (nEnableFlags & ENABLE_UPDATE));
416 pPop->EnableItem(CTX_INSERT, 0 != (nEnableFlags & ENABLE_INSERT_IDX));
417 pPop->EnableItem(CTX_EDIT, 0 != (nEnableFlags & ENABLE_EDIT));
418 pPop->EnableItem(CTX_DELETE, 0 != (nEnableFlags & ENABLE_DELETE));
419
420
421 pPop->SetPopupMenu( CTX_INSERT, pSubPop1 );
422 pPop->SetPopupMenu( CTX_UPDATE, pSubPop2 );
423 }
424 return pPop;
425 }
426 /*-----------------16.06.97 10:41-------------------
427
428 --------------------------------------------------*/
TbxMenuHdl(sal_uInt16 nTbxId,ToolBox * pBox)429 void SwGlobalTree::TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox)
430 {
431 sal_uInt16 nEnableFlags = GetEnableFlags();
432 if(FN_GLOBAL_OPEN == nTbxId)
433 {
434 PopupMenu *pMenu = new PopupMenu;
435 for (sal_uInt16 i = CTX_INSERT_ANY_INDEX; i <= CTX_INSERT_TEXT; i++)
436 {
437 pMenu->InsertItem( i, aContextStrings[ST_INDEX - ST_GLOBAL_CONTEXT_FIRST - CTX_INSERT_ANY_INDEX + i] );
438 pMenu->SetHelpId(i, aHelpForMenu[i] );
439 }
440 pMenu->EnableItem(CTX_INSERT_ANY_INDEX, 0 != (nEnableFlags & ENABLE_INSERT_IDX ));
441 // pMenu->EnableItem(CTX_INSERT_CNTIDX, 0 != (nEnableFlags & ENABLE_INSERT_IDX ));
442 // pMenu->EnableItem(CTX_INSERT_USRIDX, 0 != (nEnableFlags & ENABLE_INSERT_IDX ));
443 pMenu->EnableItem(CTX_INSERT_TEXT, 0 != (nEnableFlags & ENABLE_INSERT_TEXT));
444 pMenu->EnableItem(CTX_INSERT_FILE, 0 != (nEnableFlags & ENABLE_INSERT_FILE));
445 pMenu->EnableItem(CTX_INSERT_NEW_FILE, 0 != (nEnableFlags & ENABLE_INSERT_FILE));
446 pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
447 pMenu->Execute( pBox, pBox->GetItemRect(nTbxId).BottomLeft());
448 delete pMenu;
449 pBox->EndSelection();
450 pBox->Invalidate();
451 }
452 else if(FN_GLOBAL_UPDATE == nTbxId)
453 {
454 PopupMenu *pMenu = new PopupMenu;
455 for (sal_uInt16 i = CTX_UPDATE_SEL; i <= CTX_UPDATE_ALL; i++)
456 {
457 pMenu->InsertItem( i, aContextStrings[ST_UPDATE_SEL - ST_GLOBAL_CONTEXT_FIRST - CTX_UPDATE_SEL+ i] );
458 pMenu->SetHelpId(i, aHelpForMenu[i] );
459 }
460 pMenu->EnableItem(CTX_UPDATE_SEL, 0 != (nEnableFlags & ENABLE_UPDATE_SEL));
461 pMenu->SetSelectHdl(LINK(this, SwGlobalTree, PopupHdl));
462 pMenu->Execute( pBox, pBox->GetItemRect(nTbxId).BottomLeft());
463 delete pMenu;
464 pBox->EndSelection();
465 pBox->Invalidate();
466 }
467 }
468 /*-----------------16.06.97 11:02-------------------
469
470 --------------------------------------------------*/
GetEnableFlags() const471 sal_uInt16 SwGlobalTree::GetEnableFlags() const
472 {
473 SvLBoxEntry* pEntry = FirstSelected();
474 sal_uInt16 nSelCount = (sal_uInt16)GetSelectionCount();
475 sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
476 SvLBoxEntry* pPrevEntry = pEntry ? Prev(pEntry) : 0;
477
478 sal_uInt16 nRet = 0;
479 if(nSelCount == 1 || !nEntryCount)
480 nRet |= ENABLE_INSERT_IDX|ENABLE_INSERT_FILE;
481 if(nSelCount == 1)
482 {
483 nRet |= ENABLE_EDIT;
484 if( ((SwGlblDocContent*)pEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN &&
485 (!pPrevEntry || ((SwGlblDocContent*)pPrevEntry->GetUserData())->GetType() != GLBLDOC_UNKNOWN))
486 nRet |= ENABLE_INSERT_TEXT;
487 if( GLBLDOC_SECTION == ((SwGlblDocContent*)pEntry->GetUserData())->GetType() )
488 nRet |= ENABLE_EDIT_LINK;
489 }
490 else if(!nEntryCount)
491 {
492 nRet |= ENABLE_INSERT_TEXT;
493 }
494 if(nEntryCount)
495 nRet |= ENABLE_UPDATE|ENABLE_DELETE;
496 if(nSelCount)
497 nRet |= ENABLE_UPDATE_SEL;
498 return nRet;
499 }
500
501 /*-----------------12.06.97 09:38-------------------
502
503 --------------------------------------------------*/
RequestHelp(const HelpEvent & rHEvt)504 void SwGlobalTree::RequestHelp( const HelpEvent& rHEvt )
505 {
506 sal_Bool bParent = sal_True;
507 Update(sal_True);
508 Display(sal_True);
509 if( rHEvt.GetMode() & HELPMODE_QUICK )
510 {
511 Point aPos( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ));
512 SvLBoxEntry* pEntry = GetEntry( aPos );
513 const SwGlblDocContent* pCont = pEntry ?
514 (const SwGlblDocContent*)pEntry->GetUserData() : 0;
515 if( pCont && GLBLDOC_SECTION == pCont->GetType())
516 {
517 bParent = sal_False;
518 SvLBoxTab* pTab;
519 SvLBoxItem* pItem = GetItem( pEntry, aPos.X(), &pTab );
520 if(pItem && SV_ITEM_ID_LBOXSTRING == pItem->IsA())
521 {
522 const SwSection* pSect = pCont->GetSection();
523 String sEntry = pSect->GetLinkFileName().GetToken(0, sfx2::cTokenSeperator);
524 if(!pSect->IsConnectFlag())
525 sEntry.Insert(aContextStrings[ST_BROKEN_LINK - ST_GLOBAL_CONTEXT_FIRST], 0 );
526 Point aEntryPos = GetEntryPosition( pEntry );
527
528 aEntryPos.X() = GetTabPos( pEntry, pTab );
529 Size aSize( pItem->GetSize( this, pEntry ) );
530
531 if((aEntryPos.X() + aSize.Width()) > GetSizePixel().Width())
532 aSize.Width() = GetSizePixel().Width() - aEntryPos.X();
533
534 aEntryPos = OutputToScreenPixel(aEntryPos);
535 Rectangle aItemRect( aEntryPos, aSize );
536 if(Help::IsBalloonHelpEnabled())
537 {
538 aEntryPos.X() += aSize.Width();
539 Help::ShowBalloon( this, aEntryPos, aItemRect, sEntry );
540 }
541 else
542 Help::ShowQuickHelp( this, aItemRect, sEntry,
543 QUICKHELP_LEFT|QUICKHELP_VCENTER );
544 }
545 }
546 }
547
548 if(bParent)
549 SvTreeListBox::RequestHelp(rHEvt);
550 }
551 /*-----------------16.06.97 16:15-------------------
552
553 --------------------------------------------------*/
SelectHdl()554 void SwGlobalTree::SelectHdl()
555 {
556
557 sal_uInt16 nSelCount = (sal_uInt16)GetSelectionCount();
558 SvLBoxEntry* pSel = FirstSelected();
559 sal_uInt16 nAbsPos = pSel ? (sal_uInt16)GetModel()->GetAbsPos(pSel) : 0;
560 SwNavigationPI* pNavi = GetParentWindow();
561 sal_Bool bReadonly = !pActiveShell ||
562 pActiveShell->GetView().GetDocShell()->IsReadOnly();
563 pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_EDIT, nSelCount == 1 && !bReadonly);
564 pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_OPEN, nSelCount <= 1 && !bReadonly);
565 pNavi->aGlobalToolBox.EnableItem(FN_GLOBAL_UPDATE, GetEntryCount() > 0 && !bReadonly);
566 pNavi->aGlobalToolBox.EnableItem(FN_ITEM_UP,
567 nSelCount == 1 && nAbsPos && !bReadonly);
568 pNavi->aGlobalToolBox.EnableItem(FN_ITEM_DOWN,
569 nSelCount == 1 && nAbsPos < ((sal_uInt16)GetEntryCount()) - 1 && !bReadonly);
570
571 }
572 /*-----------------16.06.97 16:15-------------------
573
574 --------------------------------------------------*/
DeselectHdl()575 void SwGlobalTree::DeselectHdl()
576 {
577 SelectHdl();
578 }
579
580 /*-----------------17.06.97 13:11-------------------
581
582 --------------------------------------------------*/
NotifyStartDrag(TransferDataContainer &,SvLBoxEntry * pEntry)583 DragDropMode SwGlobalTree::NotifyStartDrag( TransferDataContainer& ,
584 SvLBoxEntry* pEntry )
585 {
586 bIsInternalDrag = sal_True;
587 pDDSource = pEntry;
588 return SV_DRAGDROP_CTRL_MOVE;
589 }
590
591 /*-----------------21.06.97 12:44-------------------
592
593 --------------------------------------------------*/
GetTabPos(SvLBoxEntry *,SvLBoxTab * pTab)594 long SwGlobalTree::GetTabPos( SvLBoxEntry*, SvLBoxTab* pTab)
595 {
596 return pTab->GetPos() - GLBL_TABPOS_SUB;
597 }
598
599 /*-----------------12.06.97 09:38-------------------
600
601 --------------------------------------------------*/
NotifyMoving(SvLBoxEntry * pTarget,SvLBoxEntry * pSource,SvLBoxEntry * &,sal_uLong &)602 sal_Bool SwGlobalTree::NotifyMoving( SvLBoxEntry* pTarget,
603 SvLBoxEntry* pSource,
604 SvLBoxEntry*&,
605 sal_uLong&
606 )
607 {
608 SvTreeList* _pModel = GetModel();
609 sal_uInt16 nSource = (sal_uInt16) _pModel->GetAbsPos(pSource);
610 sal_uInt16 nDest = pTarget ? (sal_uInt16) _pModel->GetAbsPos(pTarget) : pSwGlblDocContents->Count();
611
612 if( pActiveShell->MoveGlobalDocContent(
613 *pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
614 Update( sal_False ))
615 Display();
616 return sal_False;
617 }
618 /*-----------------12.06.97 09:39-------------------
619
620 --------------------------------------------------*/
NotifyCopying(SvLBoxEntry *,SvLBoxEntry *,SvLBoxEntry * &,sal_uLong &)621 sal_Bool SwGlobalTree::NotifyCopying( SvLBoxEntry* /*pTarget*/,
622 SvLBoxEntry* /*pEntry*/,
623 SvLBoxEntry*& /*rpNewParent*/,
624 sal_uLong& /*rNewChildPos*/
625 )
626 {
627 return sal_False;
628 }
629 /*-----------------12.06.97 09:39-------------------
630
631 --------------------------------------------------*/
NotifyAcceptDrop(SvLBoxEntry * pEntry)632 sal_Bool SwGlobalTree::NotifyAcceptDrop( SvLBoxEntry* pEntry)
633 {
634 return pEntry != 0;
635 }
636 /*-----------------12.06.97 09:39-------------------
637
638 --------------------------------------------------*/
StartDrag(sal_Int8 nAction,const Point & rPt)639 void SwGlobalTree::StartDrag( sal_Int8 nAction, const Point& rPt )
640 {
641 if( 1 == GetSelectionCount() )
642 SvTreeListBox::StartDrag( nAction, rPt );
643 }
644 /*-----------------12.06.97 09:39-------------------
645
646 --------------------------------------------------*/
DragFinished(sal_Int8 nAction)647 void SwGlobalTree::DragFinished( sal_Int8 nAction )
648 {
649 SvTreeListBox::DragFinished( nAction );
650 bIsInternalDrag = sal_False;
651 }
652
653 /***************************************************************************
654 Beschreibung: Wird ein Ctrl+DoubleClick in einen freien Bereich ausgefuehrt,
655 * dann soll die Basisfunktion des Controls gerufen werden
656 ***************************************************************************/
MouseButtonDown(const MouseEvent & rMEvt)657 void SwGlobalTree::MouseButtonDown( const MouseEvent& rMEvt )
658 {
659 Point aPos( rMEvt.GetPosPixel());
660 SvLBoxEntry* pEntry = GetEntry( aPos, sal_True );
661 if( !pEntry && rMEvt.IsLeft() && rMEvt.IsMod1() && (rMEvt.GetClicks() % 2) == 0)
662 Control::MouseButtonDown( rMEvt );
663 else
664 SvTreeListBox::MouseButtonDown( rMEvt );
665 }
666
667 /*-----------------12.06.97 13:08-------------------
668
669 --------------------------------------------------*/
GetFocus()670 void SwGlobalTree::GetFocus()
671 {
672 if(Update( sal_False ))
673 Display();
674 SvTreeListBox::GetFocus();
675 }
676
677 /*-----------------12.06.97 12:34-------------------
678
679 --------------------------------------------------*/
KeyInput(const KeyEvent & rKEvt)680 void SwGlobalTree::KeyInput(const KeyEvent& rKEvt)
681 {
682 const KeyCode aCode = rKEvt.GetKeyCode();
683 if(aCode.GetCode() == KEY_RETURN)
684 {
685 switch(aCode.GetModifier())
686 {
687 case KEY_MOD2:
688 // Boxen umschalten
689 GetParentWindow()->ToggleTree();
690 break;
691 }
692 }
693 else
694 SvTreeListBox::KeyInput(rKEvt);
695 }
696
697 /*-----------------17.06.97 11:59-------------------
698
699 --------------------------------------------------*/
Clear()700 void SwGlobalTree::Clear()
701 {
702 pEmphasisEntry = 0;
703 SvTreeListBox::Clear();
704 }
705 /*-----------------12.06.97 12:38-------------------
706
707 --------------------------------------------------*/
Display(sal_Bool bOnlyUpdateUserData)708 void SwGlobalTree::Display(sal_Bool bOnlyUpdateUserData)
709 {
710 if(!bIsImageListInitialized)
711 {
712 sal_uInt16 nResId = GetSettings().GetStyleSettings().GetHighContrastMode() ? IMG_NAVI_ENTRYBMPH : IMG_NAVI_ENTRYBMP;
713 aEntryImages = ImageList(SW_RES(nResId));
714 bIsImageListInitialized = sal_True;
715 }
716 sal_uInt16 nCount = pSwGlblDocContents->Count();
717 if(bOnlyUpdateUserData && GetEntryCount() == pSwGlblDocContents->Count())
718 {
719 SvLBoxEntry* pEntry = First();
720 for( sal_uInt16 i = 0; i < nCount; i++)
721 {
722 SwGlblDocContentPtr pCont = pSwGlblDocContents->GetObject(i);
723 pEntry->SetUserData(pCont);
724 pEntry = Next(pEntry);
725 }
726 }
727 else
728 {
729 SetUpdateMode( sal_False );
730 SvLBoxEntry* pOldSelEntry = FirstSelected();
731 String sEntryName; // Name des Eintrags
732 sal_uInt16 nSelPos = USHRT_MAX;
733 if(pOldSelEntry)
734 {
735 sEntryName = GetEntryText(pOldSelEntry);
736 nSelPos = (sal_uInt16)GetModel()->GetAbsPos(pOldSelEntry);
737 }
738 Clear();
739 if(!pSwGlblDocContents)
740 Update( sal_False );
741
742 SvLBoxEntry* pSelEntry = 0;
743 for( sal_uInt16 i = 0; i < nCount; i++)
744 {
745 SwGlblDocContentPtr pCont = pSwGlblDocContents->GetObject(i);
746 String sEntry;
747 Image aImage;
748 switch( pCont->GetType() )
749 {
750 case GLBLDOC_UNKNOWN:
751 {
752 sEntry = aContextStrings[ST_TEXT - ST_GLOBAL_CONTEXT_FIRST];
753 aImage = aEntryImages.GetImage(SID_SW_START + GLOBAL_CONTENT_TEXT);
754 }
755 break;
756 case GLBLDOC_TOXBASE:
757 {
758 const SwTOXBase* pBase = pCont->GetTOX();
759 sEntry = pBase->GetTitle();
760 aImage = aEntryImages.GetImage(SID_SW_START + CONTENT_TYPE_INDEX);
761 }
762 break;
763 case GLBLDOC_SECTION:
764 {
765 const SwSection* pSect = pCont->GetSection();
766 sEntry = pSect->GetSectionName();
767 aImage = aEntryImages.GetImage(SID_SW_START + CONTENT_TYPE_REGION);
768 }
769 break;
770 }
771 SvLBoxEntry* pEntry = InsertEntry(sEntry, aImage, aImage,
772 0, sal_False, LIST_APPEND, pCont);
773 if(sEntry == sEntryName)
774 {
775 pSelEntry = pEntry;
776 }
777 }
778 if(pSelEntry)
779 {
780 Select(pSelEntry);
781 }
782 else if(nSelPos != USHRT_MAX && nSelPos < nCount)
783 {
784 Select(GetEntry(nSelPos));
785 }
786 else if(nCount)
787 Select(First());
788 else
789 SelectHdl();
790 SetUpdateMode( sal_True );
791 }
792 }
793
794 /*-----------------13.06.97 10:32-------------------
795
796 --------------------------------------------------*/
InsertRegion(const SwGlblDocContent * pCont,const String * pFileName)797 void SwGlobalTree::InsertRegion( const SwGlblDocContent* pCont, const String* pFileName )
798 {
799 Sequence< OUString > aFileNames;
800 if ( !pFileName )
801 {
802 pDefParentWin = Application::GetDefDialogParent();
803 Application::SetDefDialogParent( this );
804 if ( pDocInserter )
805 delete pDocInserter;
806 pDocInserter = new ::sfx2::DocumentInserter( 0, String::CreateFromAscii("swriter"), true );
807 pDocInserter->StartExecuteModal( LINK( this, SwGlobalTree, DialogClosedHdl ) );
808 }
809 else if ( pFileName->Len() )
810 {
811 aFileNames.realloc(1);
812 INetURLObject aFileName;
813 aFileName.SetSmartURL( *pFileName );
814 aFileNames.getArray()[0] = aFileName.GetMainURL( INetURLObject::NO_DECODE );
815 InsertRegion( pCont, aFileNames );
816 }
817 }
818
819 /*-----------------18.06.97 12:42-------------------
820
821 --------------------------------------------------*/
EditContent(const SwGlblDocContent * pCont)822 void SwGlobalTree::EditContent(const SwGlblDocContent* pCont )
823 {
824 sal_uInt16 nSlot = 0;
825 switch( pCont->GetType() )
826 {
827 case GLBLDOC_UNKNOWN:
828 pActiveShell->GetView().GetEditWin().GrabFocus();
829 break;
830 case GLBLDOC_TOXBASE:
831 {
832 const SwTOXBase* pBase = pCont->GetTOX();
833 if(pBase)
834 nSlot = FN_INSERT_MULTI_TOX;
835 }
836 break;
837 case GLBLDOC_SECTION:
838 {
839 OpenDoc(pCont);
840
841 nSlot = 0;
842 pCont = 0;
843 }
844 break;
845 }
846 if(pCont)
847 GotoContent(pCont);
848 if(nSlot)
849 {
850 pActiveShell->GetView().GetViewFrame()->GetDispatcher()->Execute(nSlot);
851 if(Update( sal_False ))
852 Display();
853 }
854 }
855
856 /*-----------------13.06.97 14:22-------------------
857
858 --------------------------------------------------*/
IMPL_LINK(SwGlobalTree,PopupHdl,Menu *,pMenu)859 IMPL_LINK( SwGlobalTree, PopupHdl, Menu* , pMenu)
860 {
861 ExcecuteContextMenuAction( pMenu->GetCurItemId());
862 return sal_True;
863 }
864 /* -----------------26.08.2003 11:57-----------------
865
866 --------------------------------------------------*/
ExcecuteContextMenuAction(sal_uInt16 nSelectedPopupEntry)867 void SwGlobalTree::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
868 //IMPL_LINK( SwGlobalTree, PopupHdl, Menu* , pMenu)
869 {
870 // sal_uInt16 nId = pMenu->GetCurItemId();
871 SvLBoxEntry* pEntry = FirstSelected();
872 SwGlblDocContent* pCont = pEntry ? (SwGlblDocContent*)pEntry->GetUserData() : 0;
873 // wird waehrend des Dialogs ein RequestHelp gerufen,
874 // dann geht der Content verloren. Deshalb wird hier eine
875 // Kopie angelegt, in der nur die DocPos richtig gesetzt ist.
876 SwGlblDocContent* pContCopy = 0;
877 if(pCont)
878 pContCopy = new SwGlblDocContent(pCont->GetDocPos());
879 SfxDispatcher& rDispatch = *pActiveShell->GetView().GetViewFrame()->GetDispatcher();
880 sal_uInt16 nSlot = 0;
881 bool bDeleteContentCopy = true;
882 switch( nSelectedPopupEntry )
883 {
884 case CTX_UPDATE_SEL:
885 {
886 // zwei Durchlaeufe: zuerst die Bereiche, dann die Verzeichnisse
887 // aktualisieren
888 SvLBoxEntry* pSelEntry = FirstSelected();
889 while( pSelEntry )
890 {
891 SwGlblDocContent* pContent = (SwGlblDocContent*)pSelEntry->GetUserData();
892 if(GLBLDOC_SECTION == pContent->GetType() &&
893 pContent->GetSection()->IsConnected())
894 {
895 ((SwSection*)pContent->GetSection())->UpdateNow();
896 }
897
898 pSelEntry = NextSelected(pSelEntry);
899 }
900 pSelEntry = FirstSelected();
901 while( pSelEntry )
902 {
903 SwGlblDocContent* pContent = (SwGlblDocContent*)pSelEntry->GetUserData();
904 if(GLBLDOC_TOXBASE == pContent->GetType())
905 pActiveShell->UpdateTableOf(*pContent->GetTOX());
906 pSelEntry = NextSelected(pSelEntry);
907 }
908
909 }
910 break;
911 case CTX_UPDATE_INDEX:
912 {
913 nSlot = FN_UPDATE_TOX;
914 }
915 break;
916 case CTX_UPDATE_LINK:
917 case CTX_UPDATE_ALL:
918 {
919 pActiveShell->GetLinkManager().UpdateAllLinks(sal_True);
920 if(CTX_UPDATE_ALL == nSelectedPopupEntry)
921 nSlot = FN_UPDATE_TOX;
922 pCont = 0;
923 }
924 break;
925 case CTX_EDIT:
926 {
927 DBG_ASSERT(pCont, "Edit ohne Entry ? " );
928 EditContent(pCont);
929 }
930 break;
931 case CTX_EDIT_LINK:
932 {
933 DBG_ASSERT(pCont, "Edit ohne Entry ? " );
934 SfxStringItem aName(FN_EDIT_REGION,
935 pCont->GetSection()->GetSectionName());
936 rDispatch.Execute(FN_EDIT_REGION, SFX_CALLMODE_ASYNCHRON, &aName, 0L);
937 }
938 break;
939 case CTX_DELETE:
940 {
941 // sind mehrere Eintraege selektiert, dann muss nach jedem delete
942 // das Array neu gefuellt werden. Damit man sich nichts merken muss,
943 // beginnt das Loeschen am Ende
944 SvLBoxEntry* pSelEntry = LastSelected();
945 SwGlblDocContents* pTempContents = 0;
946 pActiveShell->StartAction();
947 while(pSelEntry)
948 {
949 pActiveShell->DeleteGlobalDocContent(
950 pTempContents ? *pTempContents : *pSwGlblDocContents,
951 (sal_uInt16)GetModel()->GetAbsPos(pSelEntry));
952 pSelEntry = PrevSelected(pSelEntry);
953 if(pSelEntry)
954 {
955 delete pTempContents;
956 pTempContents = new SwGlblDocContents;
957 pActiveShell->GetGlobalDocContent(*pTempContents);
958 }
959 }
960 delete pTempContents;
961 pActiveShell->EndAction();
962 pCont = 0;
963 }
964 break;
965 case CTX_INSERT_ANY_INDEX:
966 // case CTX_INSERT_CNTIDX:
967 // case CTX_INSERT_USRIDX:
968 {
969 if(pContCopy)
970 {
971 SfxItemSet aSet(pActiveShell->GetView().GetPool(),
972 RES_COL, RES_COL,
973 RES_BACKGROUND, RES_BACKGROUND,
974 RES_FRM_SIZE, RES_FRM_SIZE,
975 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
976 RES_LR_SPACE, RES_LR_SPACE,
977 FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE,
978 0);
979
980 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
981 DBG_ASSERT(pFact, "Dialogdiet fail!");
982 AbstractMultiTOXTabDialog* pDlg = pFact->CreateMultiTOXTabDialog( DLG_MULTI_TOX,
983 this, aSet,
984 *pActiveShell,
985 0,
986 USHRT_MAX,
987 sal_True);
988 DBG_ASSERT(pDlg, "Dialogdiet fail!");
989 if(RET_OK == pDlg->Execute())
990 {
991 SwTOXDescription& rDesc = pDlg->GetTOXDescription(
992 pDlg->GetCurrentTOXType());
993 SwTOXMgr aMgr(pActiveShell);
994 SwTOXBase* pToInsert = 0;
995 if(aMgr.UpdateOrInsertTOX(rDesc, &pToInsert, pDlg->GetOutputItemSet()))
996 pActiveShell->InsertGlobalDocContent( *pContCopy, *pToInsert );
997 }
998 pCont = 0;
999 delete pDlg;
1000 }
1001 }
1002 break;
1003 case CTX_INSERT_FILE:
1004 {
1005 bDeleteContentCopy = false;
1006 pDocContent = pContCopy;
1007 InsertRegion( pContCopy );
1008 pCont = NULL;
1009 }
1010 break;
1011 case CTX_INSERT_NEW_FILE:
1012 {
1013 SfxViewFrame* pGlobFrm = pActiveShell->GetView().GetViewFrame();
1014 SwGlobalFrameListener_Impl aFrmListener(*pGlobFrm);
1015
1016 sal_uLong nEntryPos = pEntry ? GetModel()->GetAbsPos(pEntry) : (sal_uLong)-1;
1017 // neues Dok anlegen
1018 SfxStringItem aFactory(SID_NEWDOCDIRECT,
1019 SwDocShell::Factory().GetFilterContainer()->GetName());
1020
1021 const SfxFrameItem* pItem = (SfxFrameItem*)
1022 rDispatch.Execute(SID_NEWDOCDIRECT,
1023 SFX_CALLMODE_SYNCHRON, &aFactory, 0L);
1024
1025 // sichern unter
1026 SfxFrame* pFrm = pItem ? pItem->GetFrame() : 0;
1027 SfxViewFrame* pFrame = pFrm ? pFrm->GetCurrentViewFrame() : 0;
1028 if( pFrame )
1029 {
1030 const SfxBoolItem* pBool = (const SfxBoolItem*)
1031 pFrame->GetDispatcher()->Execute(
1032 SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON );
1033 SfxObjectShell& rObj = *pFrame->GetObjectShell();
1034 const SfxMedium* pMedium = rObj.GetMedium();
1035 String sNewFile(pMedium->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI));
1036 // Bereich mit dem Dok-Namen einfuegen
1037 // eigenes Dok in den Vordergrund
1038
1039 if(aFrmListener.IsValid() && sNewFile.Len())
1040 {
1041 pGlobFrm->ToTop();
1042 // durch das Update sind die Eintraege invalid
1043 if(nEntryPos != (sal_uLong)-1)
1044 {
1045 Update( sal_False );
1046 Display();
1047 Select(GetModel()->GetEntryAtAbsPos(nEntryPos));
1048 pEntry = FirstSelected();
1049 pCont = pEntry ? (SwGlblDocContent*)pEntry->GetUserData() : 0;
1050 }
1051 else
1052 {
1053 pEntry = 0;
1054 pCont = 0;
1055 }
1056 if(pBool->GetValue())
1057 {
1058 InsertRegion(pCont, &sNewFile);
1059 pFrame->ToTop();
1060 }
1061 else
1062 pFrame->GetDispatcher()->Execute(SID_CLOSEWIN,
1063 SFX_CALLMODE_SYNCHRON);
1064 }
1065 else
1066 {
1067 pFrame->ToTop();
1068 return;
1069 }
1070 }
1071 }
1072 break;
1073 case CTX_INSERT_TEXT:
1074 {
1075 if(pCont)
1076 pActiveShell->InsertGlobalDocContent(*pCont);
1077 else
1078 {
1079 pActiveShell->SplitNode(); // leeres Dokument
1080 pActiveShell->Up( sal_False, 1 );
1081 }
1082 pActiveShell->GetView().GetEditWin().GrabFocus();
1083 }
1084 break;
1085 case CTX_UPDATE:
1086 pCont = 0;
1087 break;
1088 default:;
1089 // hier passiert nichts
1090 }
1091 if(pCont)
1092 GotoContent(pCont);
1093 if(nSlot)
1094 rDispatch.Execute(nSlot);
1095 if(Update( sal_False ))
1096 Display();
1097 if ( bDeleteContentCopy )
1098 delete pContCopy;
1099 else
1100 bDeleteContentCopy = true;
1101 // return sal_True;
1102 }
1103
1104 /*-----------------16.06.97 07:57-------------------
1105
1106 --------------------------------------------------*/
IMPL_LINK(SwGlobalTree,Timeout,Timer *,EMPTYARG)1107 IMPL_LINK( SwGlobalTree, Timeout, Timer*, EMPTYARG )
1108 {
1109 if(!HasFocus() && Update( sal_False ))
1110 Display();
1111 return 0;
1112 }
1113
1114 /*-----------------13.06.97 16:56-------------------
1115
1116 --------------------------------------------------*/
GotoContent(const SwGlblDocContent * pCont)1117 void SwGlobalTree::GotoContent(const SwGlblDocContent* pCont)
1118 {
1119 pActiveShell->EnterStdMode();
1120
1121 switch( pCont->GetType() )
1122 {
1123 case GLBLDOC_UNKNOWN:
1124 pActiveShell->GotoGlobalDocContent(*pCont);
1125 break;
1126 case GLBLDOC_TOXBASE:
1127 {
1128 String sName = pCont->GetTOX()->GetTOXName();
1129 if (!pActiveShell->GotoNextTOXBase(&sName))
1130 pActiveShell->GotoPrevTOXBase(&sName);
1131 }
1132 break;
1133 case GLBLDOC_SECTION:
1134 break;
1135 }
1136
1137 }
1138 /*-----------------16.06.97 07:42-------------------
1139
1140 --------------------------------------------------*/
ShowTree()1141 void SwGlobalTree::ShowTree()
1142 {
1143 aUpdateTimer.Start();
1144 SvTreeListBox::Show();
1145 }
1146 /*-----------------16.06.97 07:42-------------------
1147
1148 --------------------------------------------------*/
HideTree()1149 void SwGlobalTree::HideTree()
1150 {
1151 aUpdateTimer.Stop();
1152 SvTreeListBox::Hide();
1153 }
1154 /*-----------------18.06.97 10:02-------------------
1155
1156 --------------------------------------------------*/
ExecCommand(sal_uInt16 nCmd)1157 void SwGlobalTree::ExecCommand(sal_uInt16 nCmd)
1158 {
1159 SvLBoxEntry* pEntry = FirstSelected();
1160 DBG_ASSERT(pEntry, "gleich knallt's");
1161 if(FN_GLOBAL_EDIT == nCmd)
1162 {
1163 const SwGlblDocContent* pCont = (const SwGlblDocContent*)
1164 pEntry->GetUserData();
1165 EditContent(pCont);
1166 }
1167 else
1168 {
1169 if(GetSelectionCount() == 1)
1170 {
1171 sal_Bool bMove = sal_False;
1172 sal_uInt16 nSource = (sal_uInt16)GetModel()->GetAbsPos(pEntry);
1173 sal_uInt16 nDest = nSource;
1174 switch(nCmd)
1175 {
1176 case FN_ITEM_DOWN:
1177 {
1178 sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
1179 bMove = nEntryCount > nSource + 1;
1180 nDest+= 2;
1181 }
1182 break;
1183 case FN_ITEM_UP:
1184 {
1185 if(nSource)
1186 bMove = 0 != nSource;
1187 nDest--;
1188 }
1189 break;
1190 }
1191 if( bMove && pActiveShell->MoveGlobalDocContent(
1192 *pSwGlblDocContents, nSource, nSource + 1, nDest ) &&
1193 Update( sal_False ))
1194 Display();
1195 }
1196 }
1197 }
1198
1199 /*-----------------16.06.97 07:43-------------------
1200
1201 --------------------------------------------------*/
Update(sal_Bool bHard)1202 sal_Bool SwGlobalTree::Update(sal_Bool bHard)
1203 {
1204 SwView* pActView = GetParentWindow()->GetCreateView();
1205 sal_Bool bRet = sal_False;
1206 if(pActView && pActView->GetWrtShellPtr())
1207 {
1208 const SwWrtShell* pOldShell = pActiveShell;
1209 pActiveShell = pActView->GetWrtShellPtr();
1210 if(pActiveShell != pOldShell)
1211 {
1212 delete pSwGlblDocContents;
1213 pSwGlblDocContents = 0;
1214 }
1215 if(!pSwGlblDocContents)
1216 {
1217 pSwGlblDocContents = new SwGlblDocContents;
1218 bRet = sal_True;
1219 pActiveShell->GetGlobalDocContent(*pSwGlblDocContents);
1220 }
1221 else
1222 {
1223 sal_Bool bCopy = sal_False;
1224 SwGlblDocContents* pTempContents = new SwGlblDocContents;
1225 pActiveShell->GetGlobalDocContent(*pTempContents);
1226 if(pTempContents->Count() != pSwGlblDocContents->Count() ||
1227 pTempContents->Count() != GetEntryCount())
1228 {
1229 bRet = sal_True;
1230 bCopy = sal_True;
1231 }
1232 else
1233 {
1234 for(sal_uInt16 i = 0; i < pTempContents->Count() && !bCopy; i++)
1235 {
1236 SwGlblDocContent* pLeft = pTempContents->GetObject(i);
1237 SwGlblDocContent* pRight = pSwGlblDocContents->GetObject(i);
1238 GlobalDocContentType eType = pLeft->GetType();
1239 SvLBoxEntry* pEntry = GetEntry(i);
1240 String sTemp = GetEntryText(pEntry);
1241 if (
1242 eType != pRight->GetType() ||
1243 (
1244 eType == GLBLDOC_SECTION &&
1245 pLeft->GetSection()->GetSectionName() != sTemp
1246 ) ||
1247 (
1248 eType == GLBLDOC_TOXBASE &&
1249 pLeft->GetTOX()->GetTitle() != sTemp
1250 )
1251 )
1252 {
1253 bCopy = bRet = sal_True;
1254 }
1255 }
1256 }
1257 if(bCopy || bHard)
1258 {
1259 sal_uInt16 i;
1260
1261 pSwGlblDocContents->DeleteAndDestroy(0, pSwGlblDocContents->Count());
1262 for( i = 0; i < pTempContents->Count(); i++)
1263 {
1264 pSwGlblDocContents->Insert(pTempContents->GetObject(i));
1265 }
1266 for( i = pTempContents->Count(); i; i--)
1267 pTempContents->Remove(i - 1);
1268
1269 }
1270 delete pTempContents;
1271 }
1272
1273 }
1274 else
1275 {
1276 Clear();
1277 if(pSwGlblDocContents)
1278 pSwGlblDocContents->DeleteAndDestroy(0, pSwGlblDocContents->Count());
1279 }
1280 // hier muss noch eine Veraenderungspruefung rein!
1281 return bRet;
1282 }
1283
1284 /*-----------------25.06.97 16:20-------------------
1285
1286 --------------------------------------------------*/
OpenDoc(const SwGlblDocContent * pCont)1287 void SwGlobalTree::OpenDoc(const SwGlblDocContent* pCont)
1288 {
1289 String sFileName(pCont->GetSection()->GetLinkFileName().GetToken(0,
1290 sfx2::cTokenSeperator));
1291 sal_Bool bFound = sal_False;
1292 const SfxObjectShell* pCurr = SfxObjectShell::GetFirst();
1293 while( !bFound && pCurr )
1294 {
1295 if(pCurr->GetMedium() &&
1296 String(pCurr->GetMedium()->GetURLObject().GetMainURL(INetURLObject::DECODE_TO_IURI)) == sFileName)
1297 {
1298 bFound = sal_True;
1299 SwGlobalTree::SetShowShell(pCurr);
1300 Application::PostUserEvent( STATIC_LINK(
1301 this, SwGlobalTree, ShowFrameHdl ) );
1302 pCurr = 0;
1303 }
1304 else
1305 pCurr = SfxObjectShell::GetNext(*pCurr);
1306 }
1307 if(!bFound)
1308 {
1309 SfxStringItem aURL(SID_FILE_NAME,
1310 sFileName);
1311 SfxBoolItem aReadOnly(SID_DOC_READONLY, sal_False);
1312 SfxStringItem aTargetFrameName( SID_TARGETNAME, String::CreateFromAscii("_blank") );
1313 SfxStringItem aReferer(SID_REFERER, pActiveShell->GetView().GetDocShell()->GetTitle());
1314 pActiveShell->GetView().GetViewFrame()->GetDispatcher()->
1315 Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON,
1316 &aURL, &aReadOnly, &aReferer, &aTargetFrameName, 0L);
1317 }
1318 }
1319
1320 /*-----------------25.06.97 16:08-------------------
1321
1322 --------------------------------------------------*/
IMPL_LINK(SwGlobalTree,DoubleClickHdl,SwGlobalTree *,EMPTYARG)1323 IMPL_LINK( SwGlobalTree, DoubleClickHdl, SwGlobalTree *, EMPTYARG )
1324 {
1325 SvLBoxEntry* pEntry = GetCurEntry();
1326 SwGlblDocContent* pCont = (SwGlblDocContent*)pEntry->GetUserData();
1327 if(pCont->GetType() == GLBLDOC_SECTION)
1328 OpenDoc(pCont);
1329 else
1330 {
1331 GotoContent(pCont);
1332 pActiveShell->GetView().GetEditWin().GrabFocus();
1333 }
1334 return 0;
1335 }
1336
1337 /*-----------------07.10.97 08:09-------------------
1338
1339 --------------------------------------------------*/
IMPL_STATIC_LINK_NOINSTANCE(SwGlobalTree,ShowFrameHdl,SwGlobalTree *,EMPTYARG)1340 IMPL_STATIC_LINK_NOINSTANCE(SwGlobalTree, ShowFrameHdl, SwGlobalTree*, EMPTYARG)
1341 {
1342 if(SwGlobalTree::GetShowShell())
1343 SfxViewFrame::GetFirst(SwGlobalTree::GetShowShell())->ToTop();
1344 SwGlobalTree::SetShowShell(0);
1345 return 0;
1346 }
1347 /* -----------------04.11.98 10:43-------------------
1348 *
1349 * --------------------------------------------------*/
InitEntry(SvLBoxEntry * pEntry,const XubString & rStr,const Image & rImg1,const Image & rImg2,SvLBoxButtonKind eButtonKind)1350 void SwGlobalTree::InitEntry(SvLBoxEntry* pEntry,
1351 const XubString& rStr ,const Image& rImg1,const Image& rImg2,
1352 SvLBoxButtonKind eButtonKind)
1353 {
1354 sal_uInt16 nColToHilite = 1; //0==Bitmap;1=="Spalte1";2=="Spalte2"
1355 SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
1356 SvLBoxString* pCol = (SvLBoxString*)pEntry->GetItem( nColToHilite );
1357 SwLBoxString* pStr = new SwLBoxString( pEntry, 0, pCol->GetText() );
1358 pEntry->ReplaceItem( pStr, nColToHilite );
1359 }
1360 /* -----------------04.11.98 10:39-------------------
1361 *
1362 * --------------------------------------------------*/
1363
Paint(const Point & rPos,SvLBox & rDev,sal_uInt16 nFlags,SvLBoxEntry * pEntry)1364 void SwLBoxString::Paint( const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags,
1365 SvLBoxEntry* pEntry )
1366 {
1367 SwGlblDocContent* pCont = (SwGlblDocContent*)pEntry->GetUserData();
1368 const SwSection* pSect;
1369 if(pCont->GetType() == GLBLDOC_SECTION &&
1370 !(pSect = pCont->GetSection())->IsConnectFlag() )
1371 {
1372 Font aOldFont( rDev.GetFont());
1373 Font aFont(aOldFont);
1374 Color aCol( COL_LIGHTRED );
1375 aFont.SetColor( aCol );
1376 rDev.SetFont( aFont );
1377 rDev.DrawText( rPos, GetText() );
1378 rDev.SetFont( aOldFont );
1379 }
1380 else
1381 SvLBoxString::Paint( rPos, rDev, nFlags, pEntry);
1382 }
1383 /* -----------------------------06.05.2002 10:20------------------------------
1384
1385 ---------------------------------------------------------------------------*/
DataChanged(const DataChangedEvent & rDCEvt)1386 void SwGlobalTree::DataChanged( const DataChangedEvent& rDCEvt )
1387 {
1388 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1389 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1390 {
1391 sal_uInt16 nResId = GetSettings().GetStyleSettings().GetHighContrastMode() ? IMG_NAVI_ENTRYBMPH : IMG_NAVI_ENTRYBMP;
1392 aEntryImages = ImageList(SW_RES(nResId));
1393 Update(sal_True);
1394 }
1395 SvTreeListBox::DataChanged( rDCEvt );
1396 }
1397
InsertRegion(const SwGlblDocContent * _pContent,const Sequence<OUString> & _rFiles)1398 void SwGlobalTree::InsertRegion( const SwGlblDocContent* _pContent, const Sequence< OUString >& _rFiles )
1399 {
1400 sal_Int32 nFiles = _rFiles.getLength();
1401 if ( nFiles )
1402 {
1403 sal_Bool bMove = sal_False;
1404 if ( !_pContent )
1405 {
1406 SvLBoxEntry* pLast = (SvLBoxEntry*)LastVisible();
1407 _pContent = (SwGlblDocContent*)pLast->GetUserData();
1408 bMove = sal_True;
1409 }
1410 String sFilePassword;
1411 sal_uInt16 nEntryCount = (sal_uInt16)GetEntryCount();
1412 const OUString* pFileNames = _rFiles.getConstArray();
1413 SwWrtShell& rSh = GetParentWindow()->GetCreateView()->GetWrtShell();
1414 rSh.StartAction();
1415 // after insertion of the first new content the 'pCont' parameter becomes invalid
1416 // find the index of the 'anchor' content to always use a current anchor content
1417 sal_uInt16 nAnchorContent = pSwGlblDocContents->Count() - 1;
1418 if ( !bMove )
1419 {
1420 for( sal_uInt16 nContent = 0; nContent < pSwGlblDocContents->Count(); ++nContent )
1421 {
1422 if( *_pContent == *pSwGlblDocContents->GetObject( nContent ) )
1423 {
1424 nAnchorContent = nContent;
1425 break;
1426 }
1427 }
1428 }
1429 SwGlblDocContents aTempContents;
1430 for ( sal_Int32 nFile = 0; nFile < nFiles; ++nFile )
1431 {
1432 //update the global document content after each inserted document
1433 rSh.GetGlobalDocContent(aTempContents);
1434 SwGlblDocContent* pAnchorContent = 0;
1435 DBG_ASSERT(aTempContents.Count() > (nAnchorContent + nFile), "invalid anchor content -> last insertion failed");
1436 if ( aTempContents.Count() > (nAnchorContent + nFile) )
1437 pAnchorContent = aTempContents.GetObject(nAnchorContent + (sal_uInt16)nFile);
1438 else
1439 pAnchorContent = aTempContents.GetObject(aTempContents.Count() - 1);
1440 String sFileName(pFileNames[nFile]);
1441 INetURLObject aFileUrl;
1442 aFileUrl.SetSmartURL( sFileName );
1443 String sSectionName(String(aFileUrl.GetLastName(
1444 INetURLObject::DECODE_UNAMBIGUOUS)).GetToken(0,
1445 sfx2::cTokenSeperator));
1446 sal_uInt16 nSectCount = rSh.GetSectionFmtCount();
1447 String sTempSectionName(sSectionName);
1448 sal_uInt16 nAddNumber = 0;
1449 sal_uInt16 nCount = 0;
1450 // evtl : und Index anhaengen, wenn der Bereichsname schon vergeben ist
1451 while ( nCount < nSectCount )
1452 {
1453 const SwSectionFmt& rFmt = rSh.GetSectionFmt(nCount);
1454 if ((rFmt.GetSection()->GetSectionName() == sTempSectionName)
1455 && rFmt.IsInNodesArr())
1456 {
1457 nCount = 0;
1458 nAddNumber++;
1459 sTempSectionName = sSectionName;
1460 sTempSectionName += ':';
1461 sTempSectionName += String::CreateFromInt32( nAddNumber );
1462 }
1463 else
1464 nCount++;
1465 }
1466
1467 if ( nAddNumber )
1468 sSectionName = sTempSectionName;
1469
1470 SwSectionData aSectionData(CONTENT_SECTION, sSectionName);
1471 aSectionData.SetProtectFlag(true);
1472 aSectionData.SetHidden(false);
1473
1474 aSectionData.SetLinkFileName(sFileName);
1475 aSectionData.SetType(FILE_LINK_SECTION);
1476 aSectionData.SetLinkFilePassword( sFilePassword );
1477
1478 rSh.InsertGlobalDocContent( *pAnchorContent, aSectionData );
1479 }
1480 if ( bMove )
1481 {
1482 Update( sal_False );
1483 rSh.MoveGlobalDocContent(
1484 *pSwGlblDocContents, nEntryCount, nEntryCount + (sal_uInt16)nFiles, nEntryCount - (sal_uInt16)nFiles );
1485 }
1486 rSh.EndAction();
1487 Update( sal_False );
1488 Display();
1489 }
1490 }
1491
IMPL_LINK(SwGlobalTree,DialogClosedHdl,sfx2::FileDialogHelper *,_pFileDlg)1492 IMPL_LINK( SwGlobalTree, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
1493 {
1494 Application::SetDefDialogParent( pDefParentWin );
1495 if ( ERRCODE_NONE == _pFileDlg->GetError() )
1496 {
1497 SfxMediumList* pMedList = pDocInserter->CreateMediumList();
1498 if ( pMedList )
1499 {
1500 Sequence< OUString >aFileNames( pMedList->Count() );
1501 OUString* pFileNames = aFileNames.getArray();
1502 SfxMedium* pMed = pMedList->First();
1503 sal_Int32 nPos = 0;
1504 while ( pMed )
1505 {
1506 String sFileName = pMed->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
1507 sFileName += sfx2::cTokenSeperator;
1508 sFileName += pMed->GetFilter()->GetFilterName();
1509 sFileName += sfx2::cTokenSeperator;
1510 pFileNames[nPos++] = sFileName;
1511 pMed = pMedList->Next();
1512 }
1513 delete pMedList;
1514 InsertRegion( pDocContent, aFileNames );
1515 DELETEZ( pDocContent );
1516 }
1517 }
1518 return 0;
1519 }
1520
1521