xref: /aoo41x/main/sw/source/ui/utlui/navipi.cxx (revision efeef26f)
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 
28 
29 #define NAVIPI_CXX
30 
31 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
32 #include <tools/list.hxx>
33 #include <svl/urlbmk.hxx>
34 #include <svl/stritem.hxx>
35 #include <svtools/filter.hxx>
36 #include <svl/urihelper.hxx>
37 #include <sot/formats.hxx>
38 #include <sot/filelist.hxx>
39 #include <sfx2/event.hxx>
40 #include <sfx2/imgmgr.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/dockwin.hxx>
43 #include <vcl/toolbox.hxx>
44 #include <swtypes.hxx>	// fuer Pathfinder
45 #include <errhdl.hxx>
46 #include <swmodule.hxx>
47 #ifndef _VIEW_HXX
48 #include <view.hxx>
49 #endif
50 #include <navicfg.hxx>
51 #include <wrtsh.hxx>
52 #ifndef _DOCSH_HXX
53 #include <docsh.hxx>
54 #endif
55 #include <actctrl.hxx>
56 #include <IMark.hxx>
57 #include <navipi.hxx>
58 #include <content.hxx>
59 #include <workctrl.hxx>
60 #include <section.hxx>
61 #include <edtwin.hxx>
62 #include <sfx2/app.hxx>
63 #ifndef _CMDID_H
64 #include <cmdid.h>
65 #endif
66 #ifndef _HELPID_H
67 #include <helpid.h>
68 #endif
69 #ifndef _RIBBAR_HRC
70 #include <ribbar.hrc>
71 #endif
72 #ifndef _NAVIPI_HRC
73 #include <navipi.hrc>
74 #endif
75 #ifndef _UTLUI_HRC
76 #include <utlui.hrc>
77 #endif
78 
79 #include "access.hrc"
80 
81 #include <unomid.h>
82 
83 
84 #define PAGE_CHANGE_TIMEOUT 1000 //Timeout fuer Seitenwechsel
85 
86 #define JUMP_TYPE_TBL 0
87 #define JUMP_TYPE_FRM 1
88 #define JUMP_TYPE_GRF 2
89 #define JUMP_TYPE_REG 3
90 #define JUMP_TYPE_BKM 4
91 
92 // Version fuer Konfiguration
93 
94 #define NAVI_VERSION0	0
95 #define NAVI_VERSION1   1
96 #define NAVI_VERSION2   2 // bIsGlobalActive
97 
98 #define NAVI_CONFIG_VERSION NAVI_VERSION2
99 
100 using namespace ::com::sun::star::uno;
101 using namespace ::com::sun::star::frame;
102 
103 SFX_IMPL_CHILDWINDOW_CONTEXT( SwNavigationChild, SID_NAVIGATOR, SwView )
104 
105 /*------------------------------------------------------------------------
106 	Bechreibung: Steuerzeichen aus dem Outline-Entry filtern
107 ------------------------------------------------------------------------*/
108 
109 void SwNavigationPI::CleanEntry( String& rEntry )
110 {
111 	sal_uInt16 i = rEntry.Len();
112 	if( i )
113 		for( sal_Unicode* pStr = rEntry.GetBufferAccess(); i; --i, ++pStr )
114 			if( *pStr == 10 || *pStr == 9 )
115 				*pStr = 0x20;
116 }
117 /*------------------------------------------------------------------------
118  Beschreibung:	Ausfuehrung der Drag-Operation
119 				mit und ohne Childs
120 ------------------------------------------------------------------------*/
121 
122 void SwNavigationPI::MoveOutline(sal_uInt16 nSource, sal_uInt16 nTarget,
123 													sal_Bool bWithChilds)
124 {
125     SwView *pView = GetCreateView();
126 	SwWrtShell &rSh = pView->GetWrtShell();
127 	if(nTarget < nSource || nTarget == USHRT_MAX)
128 		nTarget ++;
129 	if ( rSh.IsOutlineMovable( nSource ))
130 	{
131 
132 		short nMove = nTarget-nSource; //( nDir<0 ) ? 1 : 0 ;
133 		rSh.GotoOutline(nSource);
134 		if (bWithChilds)
135 			rSh.MakeOutlineSel(nSource, nSource, sal_True);
136 		// Die selektierten Children zaehlen bei der Bewegung vorwaerts nicht mit
137 		sal_uInt16 nLastOutlinePos = rSh.GetOutlinePos(MAXLEVEL);
138 		if(bWithChilds && nMove > 1 &&
139 				nLastOutlinePos < nTarget)
140 		{
141 			if(!rSh.IsCrsrPtAtEnd())
142 				rSh.SwapPam();
143 			nMove -= nLastOutlinePos - nSource;
144 		}
145 		if(!bWithChilds || nMove < 1 || nLastOutlinePos < nTarget )
146 			rSh.MoveOutlinePara( nMove );
147 		rSh.ClearMark();
148 		rSh.GotoOutline( nSource + nMove);
149 		FillBox();
150 	}
151 
152 }
153 
154 
155 /*------------------------------------------------------------------------
156  Beschreibung:	Nach Goto einen Status Rahmenselektion aufheben
157 ------------------------------------------------------------------------*/
158 
159 
160 void lcl_UnSelectFrm(SwWrtShell *pSh)
161 {
162 	if (pSh->IsFrmSelected())
163 	{
164 		pSh->UnSelectFrm();
165 		pSh->LeaveSelFrmMode();
166 	}
167 }
168 
169 /*------------------------------------------------------------------------
170  Beschreibung:	Select der Documentanzeige
171 ------------------------------------------------------------------------*/
172 
173 
174 IMPL_LINK( SwNavigationPI, DocListBoxSelectHdl, ListBox *, pBox )
175 {
176 	int nEntryIdx = pBox->GetSelectEntryPos();
177 	SwView *pView ;
178 	pView = SwModule::GetFirstView();
179 	while (nEntryIdx-- && pView)
180 	{
181 		pView = SwModule::GetNextView(pView);
182 	}
183 	if(!pView)
184 	{
185 		nEntryIdx == 0 ?
186 			aContentTree.ShowHiddenShell():
187 				aContentTree.ShowActualView();
188 
189 
190 	}
191 	else
192 	{
193 		aContentTree.SetConstantShell(pView->GetWrtShellPtr());
194 	}
195 	return 0;
196 }
197 
198 /*------------------------------------------------------------------------
199  Beschreibung:	Fuellen der ListBox fuer Outline Sicht oder Dokumente
200 				Der PI wird auf volle Groesse gesetzt
201 ------------------------------------------------------------------------*/
202 
203 
204 void SwNavigationPI::FillBox()
205 {
206 	if(pContentWrtShell)
207 	{
208 		aContentTree.SetHiddenShell( pContentWrtShell );
209 		aContentTree.Display(  sal_False );
210 	}
211 	else
212 	{
213         SwView *pView = GetCreateView();
214 		if(!pView)
215 		{
216 			aContentTree.SetActiveShell(0);
217 		}
218 		else if( pView != pActContView)
219 		{
220 			SwWrtShell* pWrtShell = pView->GetWrtShellPtr();
221 			aContentTree.SetActiveShell(pWrtShell);
222 		}
223 		else
224 			aContentTree.Display( sal_True );
225 		pActContView = pView;
226 	}
227 }
228 
229 
230 void SwNavigationPI::UsePage(SwWrtShell *pSh)
231 {
232 	if (!pSh)
233 	{
234         SwView *pView = GetCreateView();
235 		pSh = pView ? &pView->GetWrtShell() : 0;
236 		GetPageEdit().SetValue(1);
237 	}
238 	if (pSh)
239 	{
240 		const sal_uInt16 nPageCnt = pSh->GetPageCnt();
241 		sal_uInt16 nPhyPage, nVirPage;
242 		pSh->GetPageNum(nPhyPage, nVirPage);
243 
244 		GetPageEdit().SetMax(nPageCnt);
245 		GetPageEdit().SetLast(nPageCnt);
246 		GetPageEdit().SetValue(nPhyPage);
247 	}
248 }
249 
250 /*------------------------------------------------------------------------
251  Beschreibung:	SelectHandler der Toolboxen
252 ------------------------------------------------------------------------*/
253 
254 
255 IMPL_LINK( SwNavigationPI, ToolBoxSelectHdl, ToolBox *, pBox )
256 {
257     const sal_uInt16 nCurrItemId = pBox->GetCurItemId();
258     SwView *pView = GetCreateView();
259 	if (!pView)
260 		return 1;
261 	SwWrtShell &rSh = pView->GetWrtShell();
262 	//MouseModifier fuer Outline-Move besorgen
263 
264 	//Standard: Unterebenen werden mitgenommen
265 	// mit Ctrl Unterebenen nicht mitnehmen
266 	sal_Bool bOutlineWithChilds  = ( KEY_MOD1 != pBox->GetModifier());
267 	int nFuncId = 0;
268     sal_Bool bFocusToDoc = sal_False;
269     switch (nCurrItemId)
270 	{
271 		case FN_UP:
272 		case FN_DOWN:
273         {
274             // #i75416# move the execution of the search to an asynchronously called static link
275             bool* pbNext = new bool( FN_DOWN == nCurrItemId );
276             Application::PostUserEvent( STATIC_LINK(pView, SwView, MoveNavigationHdl), pbNext );
277         }
278 		break;
279 		case FN_SHOW_ROOT:
280 		{
281 			aContentTree.ToggleToRoot();
282 		}
283 		break;
284 		case FN_SHOW_CONTENT_BOX:
285 		case FN_SELECT_CONTENT:
286 		if(pContextWin->GetFloatingWindow())
287 		{
288 			if(_IsZoomedIn() )
289 			{
290 				_ZoomOut();
291 			}
292 			else
293 			{
294 				_ZoomIn();
295 			}
296 		}
297 		return sal_True;
298 		//break;
299 		// Funktionen, die eine direkte Aktion ausloesen
300 
301 		case FN_SELECT_FOOTER:
302 		{
303 			rSh.MoveCrsr();
304 			const sal_uInt16 eType = rSh.GetFrmType(0,sal_False);
305 			if (eType & FRMTYPE_FOOTER)
306 			{
307 				if (rSh.EndPg())
308 					nFuncId = FN_END_OF_PAGE;
309 			}
310 			else if (rSh.GotoFooterTxt())
311 				nFuncId = FN_TO_FOOTER;
312             bFocusToDoc = sal_True;
313 		}
314 		break;
315 		case FN_SELECT_HEADER:
316 		{
317 			rSh.MoveCrsr();
318 			const sal_uInt16 eType = rSh.GetFrmType(0,sal_False);
319 			if (eType & FRMTYPE_HEADER)
320 			{
321 				if (rSh.SttPg())
322 					nFuncId = FN_START_OF_PAGE;
323 			}
324 			else if (rSh.GotoHeaderTxt())
325 				nFuncId = FN_TO_HEADER;
326             bFocusToDoc = sal_True;
327         }
328 		break;
329 		case FN_SELECT_FOOTNOTE:
330 		{
331 			rSh.MoveCrsr();
332 			const sal_uInt16 eFrmType = rSh.GetFrmType(0,sal_False);
333 				// aus Fussnote zum Anker springen
334 			if (eFrmType & FRMTYPE_FOOTNOTE)
335 			{
336 				if (rSh.GotoFtnAnchor())
337 					nFuncId = FN_FOOTNOTE_TO_ANCHOR;
338 			}
339 				// andernfalls zuerst zum Fussnotentext springen; geht
340 				// dies nicht, zur naechten Fussnote; geht auch dies
341 				// nicht, zur vorhergehenden Fussnote
342 			else
343 			{
344 				if (rSh.GotoFtnTxt())
345 					nFuncId = FN_FOOTNOTE_TO_ANCHOR;
346 				else if (rSh.GotoNextFtnAnchor())
347 					nFuncId = FN_NEXT_FOOTNOTE;
348 				else if (rSh.GotoPrevFtnAnchor())
349 					nFuncId = FN_PREV_FOOTNOTE;
350 			}
351             bFocusToDoc = sal_True;
352         }
353 		break;
354 
355 		case FN_SELECT_SET_AUTO_BOOKMARK:
356 			MakeMark();
357 		break;
358 		case FN_ITEM_DOWN:
359 		case FN_ITEM_UP:
360 		case FN_ITEM_LEFT:
361 		case FN_ITEM_RIGHT:
362 		case FN_GLOBAL_EDIT:
363 		{
364 			if(IsGlobalMode())
365                 aGlobalTree.ExecCommand(nCurrItemId);
366 			else
367                 aContentTree.ExecCommand(nCurrItemId, bOutlineWithChilds);
368 		}
369 		break;
370 		case FN_GLOBAL_SWITCH:
371 		{
372 			ToggleTree();
373 			pConfig->SetGlobalActive(IsGlobalMode());
374 		}
375 		break;
376 		case FN_GLOBAL_SAVE_CONTENT:
377 		{
378 			sal_Bool bSave = rSh.IsGlblDocSaveLinks();
379 			rSh.SetGlblDocSaveLinks( !bSave );
380 			pBox->CheckItem(FN_GLOBAL_SAVE_CONTENT, !bSave );
381 		}
382 		break;
383 	}
384 
385 	if (nFuncId)
386 	{
387 		lcl_UnSelectFrm(&rSh);
388 	}
389     if(bFocusToDoc)
390         pView->GetEditWin().GrabFocus();
391 	return sal_True;
392 }
393 /*------------------------------------------------------------------------
394  Beschreibung:	ClickHandler der Toolboxen
395 ------------------------------------------------------------------------*/
396 
397 
398 IMPL_LINK( SwNavigationPI, ToolBoxClickHdl, ToolBox *, pBox )
399 {
400     const sal_uInt16 nCurrItemId = pBox->GetCurItemId();
401     switch (nCurrItemId)
402 	{
403 		case FN_GLOBAL_UPDATE:
404 		case FN_GLOBAL_OPEN:
405 		{
406             aGlobalTree.TbxMenuHdl(nCurrItemId, pBox);
407 		}
408 		break;
409 	}
410 
411 	return sal_True;
412 }
413 
414 /*-----------------13.07.04 -------------------
415  ----------------------------------------------*/
416 
417 IMPL_LINK( SwNavigationPI, ToolBoxDropdownClickHdl, ToolBox*, pBox )
418 {
419     const sal_uInt16 nCurrItemId = pBox->GetCurItemId();
420     switch (nCurrItemId)
421     {
422 		case FN_CREATE_NAVIGATION:
423 		{
424             CreateNavigationTool(pBox->GetItemRect(FN_CREATE_NAVIGATION), sal_True);
425         }
426 		break;
427 
428         case FN_DROP_REGION:
429 		{
430             static const char* aHIDs[] =
431             {
432 				HID_NAVI_DRAG_HYP,
433 				HID_NAVI_DRAG_LINK,
434 				HID_NAVI_DRAG_COPY,
435             };
436 			PopupMenu *pMenu = new PopupMenu;
437 			for (sal_uInt16 i = 0; i <= REGION_MODE_EMBEDDED; i++)
438 			{
439 				pMenu->InsertItem( i + 1, aContextArr[i] );
440 				pMenu->SetHelpId(i + 1, aHIDs[i]);
441 			}
442 			pMenu->CheckItem( nRegionMode + 1 );
443 			pMenu->SetSelectHdl(LINK(this, SwNavigationPI, MenuSelectHdl));
444             pBox->SetItemDown( nCurrItemId, sal_True );
445             pMenu->Execute( pBox,
446 					pBox->GetItemRect(FN_DROP_REGION),
447                     POPUPMENU_EXECUTE_DOWN );
448             pBox->SetItemDown( nCurrItemId, sal_False );
449 			pBox->EndSelection();
450 			delete pMenu;
451 			pBox->Invalidate();
452 		}
453 		break;
454 		case FN_OUTLINE_LEVEL:
455 		{
456 			PopupMenu *pMenu = new PopupMenu;
457 			for (sal_uInt16 i = 101; i <= 100 + MAXLEVEL; i++)
458 			{
459 				pMenu->InsertItem( i, String::CreateFromInt32(i - 100) );
460 				pMenu->SetHelpId( i, HID_NAVI_OUTLINES );
461 			}
462 			pMenu->CheckItem( aContentTree.GetOutlineLevel() + 100 );
463 			pMenu->SetSelectHdl(LINK(this, SwNavigationPI, MenuSelectHdl));
464             pBox->SetItemDown( nCurrItemId, sal_True );
465 			pMenu->Execute(	pBox,
466 					pBox->GetItemRect(FN_OUTLINE_LEVEL),
467                     POPUPMENU_EXECUTE_DOWN );
468             pBox->SetItemDown( nCurrItemId, sal_False );
469 			delete pMenu;
470 			pBox->EndSelection();
471 			pBox->Invalidate();
472 		}
473 		break;
474     }
475 	return sal_True;
476 }
477 
478 /*-----------------13.07.04 -------------------
479 --------------------------------------------------*/
480 
481 SwNavHelpToolBox::SwNavHelpToolBox(SwNavigationPI* pParent, const ResId &rResId) :
482 			SwHelpToolBox(pParent, rResId)
483 {}
484 /*-----------------19.06.97 09:09-------------------
485 
486 --------------------------------------------------*/
487 void SwNavHelpToolBox::MouseButtonDown(const MouseEvent &rEvt)
488 {
489 	if(rEvt.GetButtons() == MOUSE_LEFT &&
490 			FN_CREATE_NAVIGATION == GetItemId(rEvt.GetPosPixel()))
491 	{
492         ((SwNavigationPI*)GetParent())->CreateNavigationTool(GetItemRect(FN_CREATE_NAVIGATION), sal_False);
493     }
494 	else
495 		SwHelpToolBox::MouseButtonDown(rEvt);
496 }
497 /* -----------------------------12.03.2002 16:55------------------------------
498 
499  ---------------------------------------------------------------------------*/
500 void SwNavigationPI::CreateNavigationTool(const Rectangle& rRect, sal_Bool bSetFocus)
501 {
502 //    SfxBindings& rBind = GetCreateView()->GetViewFrame()->GetBindings();
503 //    rBind.ENTERREGISTRATIONS();
504     Reference< XFrame > xFrame = GetCreateView()->GetViewFrame()->GetFrame().GetFrameInterface();
505     SwScrollNaviPopup* pPopup = new
506         SwScrollNaviPopup(FN_SCROLL_NAVIGATION,
507                           xFrame );
508 //    rBind.LEAVEREGISTRATIONS();
509 
510     Rectangle aRect(rRect);
511     Point aT1 = aRect.TopLeft();
512     aT1 = pPopup->GetParent()->OutputToScreenPixel(pPopup->GetParent()->AbsoluteScreenToOutputPixel(aContentToolBox.OutputToAbsoluteScreenPixel(aT1)));
513     aRect.SetPos(aT1);
514     pPopup->StartPopupMode(aRect, FLOATWIN_POPUPMODE_RIGHT|FLOATWIN_POPUPMODE_ALLOWTEAROFF);
515     SetPopupWindow( pPopup );
516     if(bSetFocus)
517     {
518         pPopup->EndPopupMode(FLOATWIN_POPUPMODEEND_TEAROFF);
519         pPopup->GrabFocus();
520     }
521 }
522 
523 /*-----------------19.06.97 10:12-------------------
524 
525 --------------------------------------------------*/
526 void  SwNavHelpToolBox::RequestHelp( const HelpEvent& rHEvt )
527 {
528 	sal_uInt16 nItemId = GetItemId(ScreenToOutputPixel(rHEvt.GetMousePosPixel()));
529 	if( FN_UP == nItemId || FN_DOWN == nItemId )
530 	{
531 		SetItemText(nItemId, SwScrollNaviPopup::GetQuickHelpText((FN_DOWN == nItemId)));
532 	}
533 	SwHelpToolBox::RequestHelp(rHEvt);
534 }
535 
536 /*------------------------------------------------------------------------
537  Beschreibung:	Action-Handler Edit; wechselt auf die Seite, wenn
538 				nicht Gliederungssicht angeschaltet ist.
539 ------------------------------------------------------------------------*/
540 
541 
542 IMPL_LINK( SwNavigationPI, EditAction, NumEditAction *, pEdit )
543 {
544     SwView *pView = GetCreateView();
545 	if (pView)
546 	{
547 		if(aPageChgTimer.IsActive())
548 			aPageChgTimer.Stop();
549 		pCreateView->GetWrtShell().GotoPage((sal_uInt16)pEdit->GetValue(), sal_True);
550 		pCreateView->GetEditWin().GrabFocus();
551 		pCreateView->GetViewFrame()->GetBindings().Invalidate(FN_STAT_PAGE);
552 	}
553 	return 0;
554 }
555 
556 /*------------------------------------------------------------------------
557  Beschreibung:	Falls die Seite eingestellt werden kann, wird hier
558 				das Maximum gesetzt.
559 ------------------------------------------------------------------------*/
560 
561 
562 IMPL_LINK( SwNavigationPI, EditGetFocus, NumEditAction *, pEdit )
563 {
564     SwView *pView = GetCreateView();
565 	if (!pView)
566 		return 0;
567 	SwWrtShell &rSh = pView->GetWrtShell();
568 
569 	const sal_uInt16 nPageCnt = rSh.GetPageCnt();
570 	pEdit->SetMax(nPageCnt);
571 	pEdit->SetLast(nPageCnt);
572 	return 0;
573 }
574 
575 /*------------------------------------------------------------------------
576  Beschreibung:
577 ------------------------------------------------------------------------*/
578 
579 sal_Bool SwNavigationPI::Close()
580 {
581 	SfxViewFrame* pVFrame = pCreateView->GetViewFrame();
582 	pVFrame->GetBindings().Invalidate(SID_NAVIGATOR);
583 	pVFrame->GetDispatcher()->Execute(SID_NAVIGATOR);
584 	return sal_True;
585 }
586 
587 /*------------------------------------------------------------------------
588  Beschreibung:	Setzen einer automatischen Marke
589 ------------------------------------------------------------------------*/
590 
591 
592 void SwNavigationPI::MakeMark()
593 {
594     SwView *pView = GetCreateView();
595     if (!pView) return;
596     SwWrtShell &rSh = pView->GetWrtShell();
597     IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
598 
599     // collect and sort navigator reminder names
600     ::std::vector< ::rtl::OUString > vNavMarkNames;
601     for(IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getMarksBegin();
602         ppMark != pMarkAccess->getMarksEnd();
603         ppMark++)
604         if( IDocumentMarkAccess::GetType(**ppMark) == IDocumentMarkAccess::NAVIGATOR_REMINDER )
605             vNavMarkNames.push_back(ppMark->get()->GetName());
606     ::std::sort(vNavMarkNames.begin(), vNavMarkNames.end());
607 
608     // we are maxed out and delete one
609     // nAutoMarkIdx rotates through the available MarkNames
610     // this assumes that IDocumentMarkAccess generates Names in ascending order
611     if(vNavMarkNames.size() == MAX_MARKS)
612         pMarkAccess->deleteMark(pMarkAccess->findMark(vNavMarkNames[nAutoMarkIdx]));
613 
614     rSh.SetBookmark(KeyCode(), ::rtl::OUString(), ::rtl::OUString(), IDocumentMarkAccess::NAVIGATOR_REMINDER);
615     SwView::SetActMark( nAutoMarkIdx );
616 
617     if(++nAutoMarkIdx == MAX_MARKS)
618         nAutoMarkIdx = 0;
619 }
620 
621 /*------------------------------------------------------------------------
622  Beschreibung:
623 ------------------------------------------------------------------------*/
624 
625 void SwNavigationPI::GotoPage()
626 {
627 	if ( pContextWin->GetFloatingWindow() && pContextWin->GetFloatingWindow()->IsRollUp())
628 		_ZoomIn();
629 	if(IsGlobalMode())
630 		ToggleTree();
631 	UsePage(0);
632 	GetPageEdit().GrabFocus();
633 }
634 
635 /*------------------------------------------------------------------------
636  Beschreibung:
637 ------------------------------------------------------------------------*/
638 
639 void SwNavigationPI::_ZoomOut()
640 {
641 	if (_IsZoomedIn())
642 	{
643 		FloatingWindow* pFloat = pContextWin->GetFloatingWindow();
644 		bIsZoomedIn = sal_False;
645 		Size aSz(GetOutputSizePixel());
646 		aSz.Height() = nZoomOut;
647 		Size aMinOutSizePixel = ((SfxDockingWindow*)GetParent())->GetMinOutputSizePixel();
648 		((SfxDockingWindow*)GetParent())->SetMinOutputSizePixel(Size(
649 							aMinOutSizePixel.Width(),nZoomOutInit));
650 		pFloat->SetOutputSizePixel(aSz);
651 		FillBox();
652 		if(IsGlobalMode())
653 		{
654 			aGlobalTree.ShowTree();
655 		}
656 		else
657 		{
658 			aContentTree.ShowTree();
659 			aDocListBox.Show();
660 		}
661 		SvLBoxEntry* pFirst = aContentTree.FirstSelected();
662 		if(pFirst)
663 			aContentTree.Select(pFirst, sal_True); // toolbox enablen
664 		pConfig->SetSmall( sal_False );
665 		aContentToolBox.CheckItem(FN_SHOW_CONTENT_BOX);
666 	}
667 }
668 
669 /*------------------------------------------------------------------------
670  Beschreibung:
671 ------------------------------------------------------------------------*/
672 
673 void SwNavigationPI::_ZoomIn()
674 {
675 	FloatingWindow* pFloat = pContextWin->GetFloatingWindow();
676 	if (pFloat &&
677 		(!_IsZoomedIn() || ( pContextWin->GetFloatingWindow()->IsRollUp())))
678 	{
679 		aContentTree.HideTree();
680 		aDocListBox.Hide();
681 		aGlobalTree.HideTree();
682 		bIsZoomedIn = sal_True;
683 		Size aSz(GetOutputSizePixel());
684 		if( aSz.Height() > nZoomIn )
685 			nZoomOut = ( short ) aSz.Height();
686 
687 		aSz.Height() = nZoomIn;
688 		Size aMinOutSizePixel = ((SfxDockingWindow*)GetParent())->GetMinOutputSizePixel();
689 		((SfxDockingWindow*)GetParent())->SetMinOutputSizePixel(Size(
690 							aMinOutSizePixel.Width(), aSz.Height()));
691 		pFloat->SetOutputSizePixel(aSz);
692 		SvLBoxEntry* pFirst = aContentTree.FirstSelected();
693 		if(pFirst)
694 			aContentTree.Select(pFirst, sal_True); // toolbox enablen
695 		pConfig->SetSmall( sal_True );
696 		aContentToolBox.CheckItem(FN_SHOW_CONTENT_BOX, sal_False);
697 	}
698 }
699 /*------------------------------------------------------------------------
700  Beschreibung:
701 ------------------------------------------------------------------------*/
702 
703 void SwNavigationPI::Resize()
704 {
705 	Window* pParent = GetParent();
706 	FloatingWindow* pFloat =  ((DockingWindow*)pParent)->GetFloatingWindow();
707 	Size aNewSize;
708 	if( !_IsZoomedIn() )
709 	{
710         //change the minimum width depending on the dock status
711         Size aMinOutSizePixel = ((SfxDockingWindow*)pParent)->GetMinOutputSizePixel();
712         if( pFloat)
713 		{
714 			aNewSize = pFloat->GetOutputSizePixel();
715             aMinOutSizePixel.Width() = nWishWidth;
716             aMinOutSizePixel.Height() = _IsZoomedIn() ? nZoomIn : nZoomOutInit;
717         }
718 		else
719 		{
720 			aNewSize = pParent->GetOutputSizePixel();
721             aMinOutSizePixel.Width() = 0;
722             aMinOutSizePixel.Height() = 0;
723         }
724         ((SfxDockingWindow*)GetParent())->SetMinOutputSizePixel(aMinOutSizePixel);
725 
726         const Point aPos = aContentTree.GetPosPixel();
727 		Point aLBPos = aDocListBox.GetPosPixel();
728 		long nDist = aPos.X();
729 		aNewSize.Height() -= (aPos.Y() + aPos.X() + nDocLBIniHeight + nDist);
730 		aNewSize.Width() -= 2 * nDist;
731 		aLBPos.Y() = aPos.Y() + aNewSize.Height() + nDist;
732 		aDocListBox.Show(!aGlobalTree.IsVisible() && aLBPos.Y() > aPos.Y() );
733 
734 		Size aDocLBSz = aDocListBox.GetSizePixel();
735 		aDocLBSz.Width() = aNewSize.Width();
736 		if(aNewSize.Height() < 0)
737 			aDocLBSz.Height() = 0;
738 		else
739 			aDocLBSz.Height() = nDocLBIniHeight;
740 		aContentTree.SetSizePixel(aNewSize);
741 		// GlobalTree faengt weiter oben an und reicht bis ganz unten
742 		aNewSize.Height() += (nDist + nDocLBIniHeight + aPos.Y() - aGlobalTree.GetPosPixel().Y());
743 		aGlobalTree.SetSizePixel(aNewSize);
744 		aDocListBox.SetPosSizePixel( aLBPos.X(), aLBPos.Y(),
745 									 aDocLBSz.Width(), aDocLBSz.Height(),
746 									  WINDOW_POSSIZE_X|WINDOW_POSSIZE_Y|WINDOW_POSSIZE_WIDTH);
747 
748 	}
749 }
750 
751 
752 /*------------------------------------------------------------------------
753  Beschreibung:
754 ------------------------------------------------------------------------*/
755 
756 SwNavigationPI::SwNavigationPI( SfxBindings* _pBindings,
757 								SfxChildWindowContext* pCw,
758 								Window* pParent) :
759 
760 	Window( pParent, SW_RES(DLG_NAVIGATION_PI)),
761     SfxControllerItem( SID_DOCFULLNAME, *_pBindings ),
762 
763     aContentToolBox(this, SW_RES(TB_CONTENT)),
764     aGlobalToolBox(this, SW_RES(TB_GLOBAL)),
765     aContentImageList(SW_RES(IL_CONTENT)),
766     aContentImageListH(SW_RES(ILH_CONTENT)),
767     aContentTree(this, SW_RES(TL_CONTENT)),
768 	aGlobalTree(this, SW_RES(TL_GLOBAL)),
769 	aDocListBox(this, SW_RES(LB_DOCS)),
770 
771     pxObjectShell(0),
772     pContentView(0),
773     pContentWrtShell(0),
774     pActContView(0),
775     pCreateView(0),
776     pPopupWindow(0),
777     pFloatingWindow(0),
778 
779     pContextWin(pCw),
780 
781     pConfig(SW_MOD()->GetNavigationConfig()),
782     rBindings(*_pBindings),
783 
784     nWishWidth(0),
785 	nAutoMarkIdx(1),
786     nRegionMode(REGION_MODE_NONE),
787 
788     bSmallMode(sal_False),
789 	bIsZoomedIn(sal_False),
790 	bPageCtrlsVisible(sal_False),
791     bGlobalMode(sal_False)
792 {
793     GetCreateView();
794     InitImageList();
795 
796 	aContentToolBox.SetHelpId(HID_NAVIGATOR_TOOLBOX );
797 	aGlobalToolBox.SetHelpId(HID_NAVIGATOR_GLOBAL_TOOLBOX);
798 	aDocListBox.SetHelpId(HID_NAVIGATOR_LISTBOX );
799 
800 	nDocLBIniHeight = aDocListBox.GetSizePixel().Height();
801 	nZoomOutInit = nZoomOut = Resource::ReadShortRes();
802 
803 	//NumericField in die Toolbox einfuegen
804 	NumEditAction* pEdit = new NumEditAction(
805 					&aContentToolBox, SW_RES(NF_PAGE ));
806 	pEdit->SetActionHdl(LINK(this, SwNavigationPI, EditAction));
807 	pEdit->SetGetFocusHdl(LINK(this, SwNavigationPI, EditGetFocus));
808 	pEdit->SetAccessibleName(pEdit->GetQuickHelpText());
809 	pEdit->SetUpHdl(LINK(this, SwNavigationPI, PageEditModifyHdl));
810 	pEdit->SetDownHdl(LINK(this, SwNavigationPI, PageEditModifyHdl));
811 
812 	bPageCtrlsVisible = sal_True;
813 
814 //	Rectangle aFirstRect = aContentToolBox.GetItemRect(FN_SHOW_ROOT);
815 //	sal_uInt16 nWidth = 2 * (sal_uInt16)aFirstRect.Left();
816 	//doppelte Separatoren sind nicht erlaubt, also muss
817 	//die passende Groesse anders ermittelt werden
818     Rectangle aFirstRect = aContentToolBox.GetItemRect(FN_SELECT_FOOTNOTE);
819     Rectangle aSecondRect = aContentToolBox.GetItemRect(FN_SELECT_HEADER);
820 	sal_uInt16 nWidth = sal_uInt16(aFirstRect.Left() - aSecondRect.Left());
821 
822     Size aItemWinSize( nWidth , aFirstRect.Bottom() - aFirstRect.Top() );
823 	pEdit->SetSizePixel(aItemWinSize);
824 	aContentToolBox.InsertSeparator(4);
825 	aContentToolBox.InsertWindow( FN_PAGENUMBER, pEdit, 0, 4);
826 	aContentToolBox.InsertSeparator(4);
827 	aContentToolBox.SetHelpId(FN_PAGENUMBER, HID_NAVI_TBX16);
828 	aContentToolBox.ShowItem( FN_PAGENUMBER );
829 
830 	for( sal_uInt16 i = 0; i <= REGION_MODE_EMBEDDED; i++  )
831 	{
832 		aContextArr[i] = SW_RESSTR(ST_HYPERLINK + i);
833 		aStatusArr[i] = SW_RESSTR(ST_STATUS_FIRST + i);
834 	}
835 	aStatusArr[3] = SW_RESSTR(ST_ACTIVE_VIEW);
836 	FreeResource();
837 
838 
839 	const Size& rOutSize =  GetOutputSizePixel();
840 
841 	nZoomIn = (short)rOutSize.Height();
842 
843     // Make sure the toolbox has a size that fits all its contents
844     Size aContentToolboxSize( aContentToolBox.CalcWindowSizePixel() );
845     aContentToolBox.SetOutputSizePixel( aContentToolboxSize );
846 
847     // position listbox below toolbar and add some space
848     long nListboxYPos = aContentToolBox.GetPosPixel().Y() + aContentToolboxSize.Height() + 4;
849 
850 	//Der linke und rechte Rand um die Toolboxen soll gleich sein
851 	nWishWidth = aContentToolboxSize.Width();
852 	nWishWidth += 2 * aContentToolBox.GetPosPixel().X();
853 
854     FloatingWindow* pFloat =  ((DockingWindow*)pParent)->GetFloatingWindow();
855     Size aMinSize(pFloat ? nWishWidth : 0, pFloat ? nZoomOutInit : 0);
856 	((SfxDockingWindow*)pParent)->SetMinOutputSizePixel(aMinSize);
857 	SetOutputSizePixel( Size( nWishWidth, nZoomOutInit));
858 	Size aTmpParentSize(((SfxDockingWindow*)pParent)->GetSizePixel());
859 	if(
860         (
861            aTmpParentSize.Width() < aMinSize.Width() ||
862            aTmpParentSize.Height() < aMinSize.Height()
863         )
864         &&
865         ((SfxDockingWindow*)pParent)->GetFloatingWindow() &&
866         !((SfxDockingWindow*)pParent)->GetFloatingWindow()->IsRollUp()
867       )
868 	    ((SfxDockingWindow*)pParent)->SetOutputSizePixel(aMinSize);
869 
870     aContentTree.SetPosSizePixel( 0, nListboxYPos, 0, 0, WINDOW_POSSIZE_Y );
871 	aContentTree.SetStyle( aContentTree.GetStyle()|WB_HASBUTTONS|WB_HASBUTTONSATROOT|
872 							WB_CLIPCHILDREN|WB_HSCROLL|WB_FORCE_MAKEVISIBLE );
873     aContentTree.SetSpaceBetweenEntries(3);
874 	aContentTree.SetSelectionMode( SINGLE_SELECTION );
875 	aContentTree.SetDragDropMode( 	SV_DRAGDROP_CTRL_MOVE |
876 									SV_DRAGDROP_CTRL_COPY |
877 									SV_DRAGDROP_ENABLE_TOP );
878 	aContentTree.EnableAsyncDrag(sal_True);
879 	aContentTree.ShowTree();
880 	aContentToolBox.CheckItem(FN_SHOW_CONTENT_BOX, sal_True);
881 
882 // 	TreeListBox fuer Globaldokument
883     aGlobalTree.SetPosSizePixel( 0, nListboxYPos, 0, 0, WINDOW_POSSIZE_Y );
884 	aGlobalTree.SetSelectionMode( MULTIPLE_SELECTION );
885 	aGlobalTree.SetStyle( aGlobalTree.GetStyle()|WB_HASBUTTONS|WB_HASBUTTONSATROOT|
886 								WB_CLIPCHILDREN|WB_HSCROLL );
887 	Size aGlblSize(aGlobalToolBox.CalcWindowSizePixel());
888 	aGlobalToolBox.SetSizePixel(aGlblSize);
889 
890 //	Handler
891 
892 	Link aLk = LINK(this, SwNavigationPI, ToolBoxSelectHdl);
893 	aContentToolBox.SetSelectHdl( aLk );
894 	aGlobalToolBox.SetSelectHdl( aLk );
895 	aDocListBox.SetSelectHdl(LINK(this, SwNavigationPI,
896 													DocListBoxSelectHdl));
897 	aContentToolBox.SetClickHdl( LINK(this, SwNavigationPI, ToolBoxClickHdl) );
898 	aContentToolBox.SetDropdownClickHdl( LINK(this, SwNavigationPI, ToolBoxDropdownClickHdl) );
899 	aGlobalToolBox.SetClickHdl( LINK(this, SwNavigationPI, ToolBoxClickHdl) );
900 	aGlobalToolBox.SetDropdownClickHdl( LINK(this, SwNavigationPI, ToolBoxDropdownClickHdl) );
901 	aGlobalToolBox.CheckItem(FN_GLOBAL_SWITCH, sal_True);
902 
903 	Font aFont(GetFont());
904 	aFont.SetWeight(WEIGHT_NORMAL);
905 	GetPageEdit().SetFont(aFont);
906 	aFont = aContentTree.GetFont();
907 	aFont.SetWeight(WEIGHT_NORMAL);
908 	aContentTree.SetFont(aFont);
909 	aGlobalTree.SetFont(aFont);
910 
911 	StartListening(*SFX_APP());
912     if ( pCreateView )
913         StartListening(*pCreateView);
914     SfxImageManager* pImgMan = SfxImageManager::GetImageManager( SW_MOD() );
915 	pImgMan->RegisterToolBox(&aContentToolBox, SFX_TOOLBOX_CHANGEOUTSTYLE);
916 	pImgMan->RegisterToolBox(&aGlobalToolBox, SFX_TOOLBOX_CHANGEOUTSTYLE);
917 
918     aContentToolBox.SetItemBits( FN_CREATE_NAVIGATION, aContentToolBox.GetItemBits( FN_CREATE_NAVIGATION ) | TIB_DROPDOWNONLY );
919     aContentToolBox.SetItemBits( FN_DROP_REGION, aContentToolBox.GetItemBits( FN_DROP_REGION ) | TIB_DROPDOWNONLY );
920     aContentToolBox.SetItemBits( FN_OUTLINE_LEVEL, aContentToolBox.GetItemBits( FN_OUTLINE_LEVEL ) | TIB_DROPDOWNONLY );
921 
922 	if(IsGlobalDoc())
923 	{
924         SwView *pActView = GetCreateView();
925 		aGlobalToolBox.CheckItem(FN_GLOBAL_SAVE_CONTENT,
926 					pActView->GetWrtShellPtr()->IsGlblDocSaveLinks());
927 		if(pConfig->IsGlobalActive())
928 			ToggleTree();
929         aGlobalTree.GrabFocus();
930     }
931     else
932         aContentTree.GrabFocus();
933 	UsePage(0);
934 	aPageChgTimer.SetTimeoutHdl(LINK(this, SwNavigationPI, ChangePageHdl));
935 	aPageChgTimer.SetTimeout(PAGE_CHANGE_TIMEOUT);
936 
937 	aContentTree.SetAccessibleName(SW_RESSTR(STR_ACCESS_TL_CONTENT));
938 	aGlobalTree.SetAccessibleName(SW_RESSTR(STR_ACCESS_TL_GLOBAL));
939 	aDocListBox.SetAccessibleName(aStatusArr[3]);
940 }
941 
942 /*------------------------------------------------------------------------
943  Beschreibung:
944 ------------------------------------------------------------------------*/
945 
946 SwNavigationPI::~SwNavigationPI()
947 {
948 	if(IsGlobalDoc() && !IsGlobalMode())
949 	{
950         SwView *pView = GetCreateView();
951 		SwWrtShell &rSh = pView->GetWrtShell();
952 		if( !rSh.IsAllProtect() )
953 			pView->GetDocShell()->SetReadOnlyUI(sal_False);
954 	}
955 
956 	EndListening(*SFX_APP());
957 
958     SfxImageManager* pImgMan = SfxImageManager::GetImageManager( SW_MOD() );
959 	pImgMan->ReleaseToolBox(&aContentToolBox);
960 	pImgMan->ReleaseToolBox(&aGlobalToolBox);
961     delete aContentToolBox.GetItemWindow(FN_PAGENUMBER);
962     aContentToolBox.Clear();
963     if(pxObjectShell)
964 	{
965 		if(pxObjectShell->Is())
966 			(*pxObjectShell)->DoClose();
967 		delete pxObjectShell;
968 	}
969     delete pPopupWindow;
970     delete pFloatingWindow;
971 
972     if ( IsBound() )
973         rBindings.Release(*this);
974 }
975 
976 /*------------------------------------------------------------------------
977  Beschreibung:
978 ------------------------------------------------------------------------*/
979 
980 void SwNavigationPI::SetPopupWindow( SfxPopupWindow* pWindow )
981 {
982     pPopupWindow = pWindow;
983     pPopupWindow->SetPopupModeEndHdl( LINK( this, SwNavigationPI, PopupModeEndHdl ));
984     pPopupWindow->SetDeleteLink_Impl( LINK( this, SwNavigationPI, ClosePopupWindow ));
985 }
986 
987 /*------------------------------------------------------------------------
988  Beschreibung:
989 ------------------------------------------------------------------------*/
990 
991 IMPL_LINK( SwNavigationPI, PopupModeEndHdl, void *, EMPTYARG )
992 {
993 	if ( pPopupWindow->IsVisible() )
994     {
995         // Replace floating window with popup window and destroy
996         // floating window instance.
997         delete pFloatingWindow;
998         pFloatingWindow = pPopupWindow;
999         pPopupWindow    = 0;
1000     }
1001     else
1002     {
1003         // Popup window has been closed by the user. No replacement, instance
1004         // will destroy itself.
1005         pPopupWindow = 0;
1006     }
1007 
1008     return 1;
1009 }
1010 
1011 /*------------------------------------------------------------------------
1012  Beschreibung:
1013 ------------------------------------------------------------------------*/
1014 
1015 IMPL_LINK( SwNavigationPI, ClosePopupWindow, SfxPopupWindow *, pWindow )
1016 {
1017     if ( pWindow == pFloatingWindow )
1018         pFloatingWindow = 0;
1019     else
1020         pPopupWindow = 0;
1021 
1022     return 1;
1023 }
1024 
1025 /*------------------------------------------------------------------------
1026  Beschreibung:
1027 ------------------------------------------------------------------------*/
1028 
1029 void SwNavigationPI::StateChanged( sal_uInt16 nSID, SfxItemState /*eState*/,
1030                                             const SfxPoolItem* /*pState*/ )
1031 {
1032 	if(nSID == SID_DOCFULLNAME)
1033 	{
1034         SwView *pActView = GetCreateView();
1035 		if(pActView)
1036 		{
1037 			SwWrtShell* pWrtShell = pActView->GetWrtShellPtr();
1038 			aContentTree.SetActiveShell(pWrtShell);
1039 			sal_Bool bGlobal = IsGlobalDoc();
1040 			aContentToolBox.EnableItem(FN_GLOBAL_SWITCH, bGlobal);
1041 			if( (!bGlobal && IsGlobalMode()) ||
1042 					(!IsGlobalMode() && pConfig->IsGlobalActive()) )
1043 			{
1044 				ToggleTree();
1045 			}
1046 			if(bGlobal)
1047 			{
1048 				aGlobalToolBox.CheckItem(FN_GLOBAL_SAVE_CONTENT, pWrtShell->IsGlblDocSaveLinks());
1049 			}
1050 		}
1051 		else
1052 		{
1053 			aContentTree.SetActiveShell(0);
1054 		}
1055 		UpdateListBox();
1056 	}
1057 }
1058 
1059 /*------------------------------------------------------------------------
1060 	Bechreibung: NumericField aus der Toolbox holen
1061 ------------------------------------------------------------------------*/
1062 
1063 NumEditAction& SwNavigationPI::GetPageEdit()
1064 {
1065 	return *(NumEditAction*)aContentToolBox.GetItemWindow(FN_PAGENUMBER);
1066 }
1067 
1068 /*------------------------------------------------------------------------
1069  Beschreibung:
1070 ------------------------------------------------------------------------*/
1071 
1072 SfxChildAlignment SwNavigationPI::CheckAlignment
1073 	(
1074 		SfxChildAlignment eActAlign,
1075 		SfxChildAlignment eAlign
1076 	)
1077 {
1078 SfxChildAlignment eRetAlign;
1079 
1080 	if(_IsZoomedIn())
1081 		eRetAlign = SFX_ALIGN_NOALIGNMENT;
1082 	else
1083 		switch (eAlign)
1084 		{
1085 			case SFX_ALIGN_BOTTOM:
1086 			case SFX_ALIGN_LOWESTBOTTOM:
1087 			case SFX_ALIGN_HIGHESTBOTTOM:
1088 				eRetAlign = eActAlign;
1089 				break;
1090 
1091 			case SFX_ALIGN_TOP:
1092 			case SFX_ALIGN_HIGHESTTOP:
1093 			case SFX_ALIGN_LOWESTTOP:
1094 			case SFX_ALIGN_LEFT:
1095 			case SFX_ALIGN_RIGHT:
1096 			case SFX_ALIGN_FIRSTLEFT:
1097 			case SFX_ALIGN_LASTLEFT:
1098 			case SFX_ALIGN_FIRSTRIGHT:
1099 			case SFX_ALIGN_LASTRIGHT:
1100 				eRetAlign = eAlign;
1101 				break;
1102 
1103 			default:
1104 				eRetAlign = eAlign;
1105 				break;
1106 		}
1107 	return eRetAlign;
1108 
1109 }
1110 
1111 /*--------------------------------------------------------------------
1112 	Beschreibung: 	Benachrichtigung bei geaenderter DocInfo
1113  --------------------------------------------------------------------*/
1114 
1115 void SwNavigationPI::Notify( SfxBroadcaster& rBrdc, const SfxHint& rHint )
1116 {
1117     if(&rBrdc == pCreateView)
1118     {
1119         if(rHint.ISA(SfxSimpleHint) && ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING)
1120         {
1121             pCreateView = 0;
1122         }
1123     }
1124     else
1125     {
1126         if(rHint.ISA(SfxEventHint))
1127         {
1128             if( pxObjectShell &&
1129                         ((SfxEventHint&) rHint).GetEventId() == SFX_EVENT_CLOSEAPP)
1130             {
1131                 DELETEZ(pxObjectShell);
1132             }
1133             else if(((SfxEventHint&) rHint).GetEventId() == SFX_EVENT_OPENDOC)
1134             {
1135 
1136                 SwView *pActView = GetCreateView();
1137                 if(pActView)
1138                 {
1139                     SwWrtShell* pWrtShell = pActView->GetWrtShellPtr();
1140                     aContentTree.SetActiveShell(pWrtShell);
1141                     if(aGlobalTree.IsVisible())
1142                     {
1143                         if(aGlobalTree.Update( sal_False ))
1144                             aGlobalTree.Display();
1145                         else
1146                         // wenn kein Update notwendig, dann zumindest painten
1147                         // wg. der roten Eintraege fuer broken links
1148                             aGlobalTree.Invalidate();
1149                     }
1150                 }
1151             }
1152         }
1153     }
1154 }
1155 
1156 /*--------------------------------------------------------------------
1157 	Beschreibung:
1158  --------------------------------------------------------------------*/
1159 
1160 IMPL_LINK( SwNavigationPI, MenuSelectHdl, Menu *, pMenu )
1161 {
1162 	sal_uInt16 nMenuId = pMenu->GetCurItemId();
1163 	if(nMenuId != USHRT_MAX)
1164 	{
1165 		if(nMenuId < 100)
1166 			SetRegionDropMode( --nMenuId);
1167 		else
1168             aContentTree.SetOutlineLevel( static_cast< sal_uInt8 >(nMenuId - 100) );
1169 	}
1170 	return 0;
1171 }
1172 
1173 
1174 /*--------------------------------------------------------------------
1175 	Beschreibung:
1176  --------------------------------------------------------------------*/
1177 
1178 void SwNavigationPI::UpdateListBox()
1179 {
1180 	aDocListBox.SetUpdateMode(sal_False);
1181 	aDocListBox.Clear();
1182     SwView *pActView = GetCreateView();
1183 	sal_Bool bDisable = pActView == 0;
1184 	SwView *pView = SwModule::GetFirstView();
1185 	sal_uInt16 nCount = 0;
1186 	sal_uInt16 nAct = 0;
1187 	sal_uInt16 nConstPos = 0;
1188 	const SwView* pConstView = aContentTree.IsConstantView() &&
1189 								aContentTree.GetActiveWrtShell() ?
1190 									&aContentTree.GetActiveWrtShell()->GetView():
1191 										0;
1192 	while (pView)
1193 	{
1194         SfxObjectShell* pDoc = pView->GetDocShell();
1195         // pb: #i53333# don't show help pages here
1196         if ( !pDoc->IsHelpDocument() )
1197         {
1198             String sEntry = pDoc->GetTitle();
1199             sEntry += C2S(" (");
1200             if (pView == pActView)
1201             {
1202                 nAct = nCount;
1203                 sEntry += aStatusArr[ST_ACTIVE - ST_STATUS_FIRST];
1204             }
1205             else
1206                 sEntry += aStatusArr[ST_INACTIVE - ST_STATUS_FIRST];
1207             sEntry += ')';
1208             aDocListBox.InsertEntry(sEntry);
1209 
1210 
1211             if (pConstView && pView == pConstView)
1212                 nConstPos = nCount;
1213 
1214             nCount++;
1215         }
1216         pView = SwModule::GetNextView(pView);
1217 	}
1218 	aDocListBox.InsertEntry(aStatusArr[3]); //"Aktives Fenster"
1219 	nCount++;
1220 
1221 	if(aContentTree.GetHiddenWrtShell())
1222 	{
1223 		String sEntry = aContentTree.GetHiddenWrtShell()->GetView().
1224 										GetDocShell()->GetTitle();
1225 		sEntry += C2S(" (");
1226 		sEntry += aStatusArr[ST_HIDDEN - ST_STATUS_FIRST];
1227 		sEntry += ')';
1228 		aDocListBox.InsertEntry(sEntry);
1229 		bDisable = sal_False;
1230 	}
1231 	if(aContentTree.IsActiveView())
1232 	{
1233 		//entweder den Namen des akt. Docs oder "Aktives Dokument"
1234 		sal_uInt16 nTmp = pActView ? nAct : --nCount;
1235 		aDocListBox.SelectEntryPos( nTmp );
1236 	}
1237 	else if(aContentTree.IsHiddenView())
1238 	{
1239 		aDocListBox.SelectEntryPos(nCount);
1240 	}
1241 	else
1242 		aDocListBox.SelectEntryPos(nConstPos);
1243 
1244 	aDocListBox.Enable( !bDisable );
1245 	aDocListBox.SetUpdateMode(sal_True);
1246 }
1247 
1248 /*-----------------16.06.97 15:05-------------------
1249 
1250 --------------------------------------------------*/
1251 
1252 /*------------------------------------------------------------------------
1253 	Beschreibung:
1254 ------------------------------------------------------------------------*/
1255 
1256 IMPL_LINK(SwNavigationPI, DoneLink, SfxPoolItem *, pItem)
1257 {
1258 	const SfxViewFrameItem* pFrameItem = PTR_CAST(SfxViewFrameItem, pItem );
1259 	if( pFrameItem )
1260 	{
1261 		SfxViewFrame* pFrame =  pFrameItem->GetFrame();
1262 		if(pFrame)
1263 		{
1264 			aContentTree.Clear();
1265 			pContentView = PTR_CAST(SwView, pFrame->GetViewShell());
1266 			DBG_ASSERT(pContentView, "keine SwView");
1267 			if(pContentView)
1268 				pContentWrtShell = pContentView->GetWrtShellPtr();
1269 			else
1270 				pContentWrtShell = 0;
1271 			pxObjectShell = new SfxObjectShellLock(pFrame->GetObjectShell());
1272 			FillBox();
1273 			aContentTree.Update();
1274 		}
1275 	}
1276 	return 0;
1277 }
1278 
1279 String SwNavigationPI::CreateDropFileName( TransferableDataHelper& rData )
1280 {
1281 	String sFileName;
1282 	sal_uLong nFmt;
1283 	if( rData.HasFormat( nFmt = FORMAT_FILE_LIST ))
1284 	{
1285 		FileList aFileList;
1286 		rData.GetFileList( nFmt, aFileList );
1287 		sFileName = aFileList.GetFile( 0 );
1288 	}
1289 	else if( rData.HasFormat( nFmt = FORMAT_STRING ) ||
1290 	 		 rData.HasFormat( nFmt = FORMAT_FILE ) ||
1291 			 rData.HasFormat( nFmt = SOT_FORMATSTR_ID_FILENAME ))
1292 		rData.GetString( nFmt, sFileName );
1293 	else if( rData.HasFormat( nFmt = SOT_FORMATSTR_ID_SOLK ) ||
1294  		  	 rData.HasFormat( nFmt = SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK )||
1295  		  	 rData.HasFormat( nFmt = SOT_FORMATSTR_ID_FILECONTENT ) ||
1296  		  	 rData.HasFormat( nFmt = SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) ||
1297  		  	 rData.HasFormat( nFmt = SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ))
1298 	{
1299 		INetBookmark aBkmk( aEmptyStr, aEmptyStr );
1300 		rData.GetINetBookmark( nFmt, aBkmk );
1301 		sFileName = aBkmk.GetURL();
1302 	}
1303 	if( sFileName.Len() )
1304     {
1305         sFileName = INetURLObject( sFileName ).GetMainURL( INetURLObject::NO_DECODE );
1306     }
1307 	return sFileName;
1308 }
1309 
1310 /*------------------------------------------------------------------------
1311 	Beschreibung:
1312 ------------------------------------------------------------------------*/
1313 
1314 sal_Int8 SwNavigationPI::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
1315 {
1316 	return ( !aContentTree.IsInDrag() &&
1317 		( aContentTree.IsDropFormatSupported( FORMAT_FILE ) ||
1318 		  aContentTree.IsDropFormatSupported( FORMAT_STRING ) ||
1319 		  aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_SOLK ) ||
1320  		  aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK )||
1321  		  aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_FILECONTENT ) ||
1322  		  aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR ) ||
1323  		  aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ) ||
1324  		  aContentTree.IsDropFormatSupported( SOT_FORMATSTR_ID_FILENAME )))
1325 		? DND_ACTION_COPY
1326 		: DND_ACTION_NONE;
1327 }
1328 
1329 sal_Int8 SwNavigationPI::ExecuteDrop( const ExecuteDropEvent& rEvt )
1330 {
1331 	TransferableDataHelper aData( rEvt.maDropEvent.Transferable );
1332 	sal_Int8 nRet = DND_ACTION_NONE;
1333 	String sFileName;
1334 	if( !aContentTree.IsInDrag() &&
1335 		0 != (sFileName = SwNavigationPI::CreateDropFileName( aData )).Len() )
1336 	{
1337 		INetURLObject aTemp( sFileName );
1338 		GraphicDescriptor aDesc( aTemp );
1339 		if( !aDesc.Detect() )	// keine Grafiken annehmen
1340 		{
1341 			if( STRING_NOTFOUND == sFileName.Search('#')
1342 				&& (!sContentFileName.Len() || sContentFileName != sFileName ))
1343 			{
1344 				nRet = rEvt.mnAction;
1345 				sFileName.EraseTrailingChars( char(0) );
1346 				sContentFileName = sFileName;
1347 				if(pxObjectShell)
1348 				{
1349 					aContentTree.SetHiddenShell( 0 );
1350 					(*pxObjectShell)->DoClose();
1351 					DELETEZ( pxObjectShell);
1352 				}
1353 				SfxStringItem aFileItem(SID_FILE_NAME, sFileName );
1354 				String sOptions = C2S("HRC");
1355 				SfxStringItem aOptionsItem( SID_OPTIONS, sOptions );
1356 				SfxLinkItem aLink( SID_DONELINK,
1357 									LINK( this, SwNavigationPI, DoneLink ) );
1358 				GetActiveView()->GetViewFrame()->GetDispatcher()->Execute(
1359 							SID_OPENDOC, SFX_CALLMODE_ASYNCHRON,
1360 							&aFileItem, &aOptionsItem, &aLink, 0L );
1361 			}
1362 		}
1363 	}
1364 	return nRet;
1365 }
1366 
1367 /*-----------------27.11.96 13.00-------------------
1368 
1369 --------------------------------------------------*/
1370 
1371 void SwNavigationPI::SetRegionDropMode(sal_uInt16 nNewMode)
1372 {
1373 	nRegionMode = nNewMode;
1374 	pConfig->SetRegionMode( nRegionMode );
1375 
1376     sal_uInt16 nDropId = FN_DROP_REGION;
1377 	if(nRegionMode == REGION_MODE_LINK)
1378         nDropId = FN_DROP_REGION_LINK;
1379 	else if(nRegionMode == REGION_MODE_EMBEDDED)
1380         nDropId = FN_DROP_REGION_COPY;
1381 
1382     ImageList& rImgLst = aContentToolBox.GetSettings().GetStyleSettings().GetHighContrastMode()
1383 				? aContentImageListH : aContentImageList;
1384 
1385     aContentToolBox.SetItemImage( FN_DROP_REGION,
1386                                     rImgLst.GetImage(nDropId));
1387 }
1388 
1389 
1390 /*-----------------12.06.97 09:47-------------------
1391 
1392 --------------------------------------------------*/
1393 
1394 sal_Bool	SwNavigationPI::ToggleTree()
1395 {
1396 	sal_Bool bRet = sal_True;
1397 	sal_Bool bGlobalDoc = IsGlobalDoc();
1398 	if(!IsGlobalMode() && bGlobalDoc)
1399 	{
1400 		SetUpdateMode(sal_False);
1401 		if(_IsZoomedIn())
1402 			_ZoomOut();
1403 		aGlobalTree.ShowTree();
1404 		aGlobalToolBox.Show();
1405 		aContentTree.HideTree();
1406 		aContentToolBox.Hide();
1407 		aDocListBox.Hide();
1408 		SetGlobalMode(sal_True);
1409 		SetUpdateMode(sal_True);
1410 	}
1411 	else
1412 	{
1413 		aGlobalTree.HideTree();
1414 		aGlobalToolBox.Hide();
1415 		if(!_IsZoomedIn())
1416 		{
1417 			aContentTree.ShowTree();
1418 			aContentToolBox.Show();
1419 			aDocListBox.Show();
1420 		}
1421 		bRet = sal_False;
1422 		SetGlobalMode(sal_False);
1423 	}
1424     return bRet;
1425 }
1426 
1427 /*-----------------13.06.97 09:42-------------------
1428 
1429 --------------------------------------------------*/
1430 sal_Bool 	SwNavigationPI::IsGlobalDoc() const
1431 {
1432 	sal_Bool bRet = sal_False;
1433     SwView *pView = GetCreateView();
1434 	if(pView)
1435 	{
1436 		SwWrtShell &rSh = pView->GetWrtShell();
1437 		bRet = rSh.IsGlobalDoc();
1438 	}
1439 	return bRet;
1440 }
1441 /* -----------------26.10.98 08:10-------------------
1442  *
1443  * --------------------------------------------------*/
1444 IMPL_LINK( SwNavigationPI, ChangePageHdl, Timer*, EMPTYARG )
1445 {
1446 	EditAction(&GetPageEdit());
1447 	GetPageEdit().GrabFocus();
1448 	return 0;
1449 }
1450 /* -----------------26.10.98 08:14-------------------
1451  *
1452  * --------------------------------------------------*/
1453 IMPL_LINK( SwNavigationPI, PageEditModifyHdl, Edit*, EMPTYARG )
1454 {
1455 	if(aPageChgTimer.IsActive())
1456 		aPageChgTimer.Stop();
1457 	aPageChgTimer.Start();
1458 	return 0;
1459 }
1460 
1461 /* -----------------------------23.04.01 07:34--------------------------------
1462 
1463  ---------------------------------------------------------------------------*/
1464 SwView*  SwNavigationPI::GetCreateView() const
1465 {
1466     if(!pCreateView)
1467     {
1468         SwView* pView = SwModule::GetFirstView();
1469         while(pView)
1470         {
1471             if(&pView->GetViewFrame()->GetBindings() == &rBindings)
1472             {
1473                 ((SwNavigationPI*)this)->pCreateView = pView;
1474                 ((SwNavigationPI*)this)->StartListening(*pCreateView);
1475                 break;
1476             }
1477             pView = SwModule::GetNextView(pView);
1478         }
1479     }
1480     return pCreateView;
1481 }
1482 
1483 
1484 /*------------------------------------------------------------------------
1485  Beschreibung:
1486 ------------------------------------------------------------------------*/
1487 
1488 SwNavigationChild::SwNavigationChild( Window* pParent,
1489                         sal_uInt16 nId,
1490                         SfxBindings* _pBindings,
1491 						SfxChildWinInfo* pInfo )
1492 	: SfxChildWindowContext( nId )
1493 {
1494     SwNavigationPI* pNavi  = new SwNavigationPI( _pBindings, this, pParent );
1495 	SetWindow( pNavi );
1496     _pBindings->Invalidate(SID_NAVIGATOR);
1497 	String sExtra = pInfo->aExtraString;
1498 
1499 	SwNavigationConfig* pNaviConfig = SW_MOD()->GetNavigationConfig();
1500 
1501     sal_uInt16 nRootType = static_cast< sal_uInt16 >( pNaviConfig->GetRootType() );
1502 	if( nRootType < CONTENT_TYPE_MAX )
1503 	{
1504 		pNavi->aContentTree.SetRootType(nRootType);
1505 		pNavi->aContentToolBox.CheckItem(FN_SHOW_ROOT, sal_True);
1506 	}
1507     pNavi->aContentTree.SetOutlineLevel( static_cast< sal_uInt8 >( pNaviConfig->GetOutlineLevel() ) );
1508     pNavi->SetRegionDropMode( static_cast< sal_uInt16 >( pNaviConfig->GetRegionMode() ) );
1509 
1510 	if(GetFloatingWindow() && pNaviConfig->IsSmall())
1511 	{
1512 		pNavi->_ZoomIn();
1513 	}
1514 }
1515 /* -----------------------------06.05.2002 10:06------------------------------
1516 
1517  ---------------------------------------------------------------------------*/
1518 void SwNavigationPI::DataChanged( const DataChangedEvent& rDCEvt )
1519 {
1520     Window::DataChanged( rDCEvt );
1521     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1522          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1523     {
1524         InitImageList();
1525         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1526         Color aBgColor = rStyleSettings.GetFaceColor();
1527         Wallpaper aBack( aBgColor );
1528         SetBackground( aBack );
1529     }
1530 }
1531 /* -----------------------------06.05.2002 10:07------------------------------
1532 
1533  ---------------------------------------------------------------------------*/
1534 void SwNavigationPI::InitImageList()
1535 {
1536     sal_uInt16 k;
1537 
1538     ImageList& rImgLst = aContentToolBox.GetSettings().GetStyleSettings().GetHighContrastMode() ?
1539                 aContentImageListH : aContentImageList;
1540     for( k = 0; k < aContentToolBox.GetItemCount(); k++)
1541 			aContentToolBox.SetItemImage(aContentToolBox.GetItemId(k),
1542                     rImgLst.GetImage(aContentToolBox.GetItemId(k)));
1543 
1544 	for( k = 0; k < aGlobalToolBox.GetItemCount(); k++)
1545 			aGlobalToolBox.SetItemImage(aGlobalToolBox.GetItemId(k),
1546                     rImgLst.GetImage(aGlobalToolBox.GetItemId(k)));
1547 
1548     sal_uInt16 nDropId = FN_DROP_REGION;
1549 	if(nRegionMode == REGION_MODE_LINK)
1550         nDropId = FN_DROP_REGION_LINK;
1551 	else if(nRegionMode == REGION_MODE_EMBEDDED)
1552         nDropId = FN_DROP_REGION_COPY;
1553     aContentToolBox.SetItemImage( FN_DROP_REGION,
1554                                     rImgLst.GetImage(nDropId));
1555 }
1556 
1557