xref: /trunk/main/sd/source/ui/view/drviewsd.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "DrawViewShell.hxx"
32 
33 #ifndef _SVXIDS_HRC
34 #include <svx/svxids.hrc>
35 #endif
36 #include <svl/aeitem.hxx>
37 #include <svl/stritem.hxx>
38 #include <sfx2/docfile.hxx>
39 #include <svl/intitem.hxx>
40 #include <sfx2/bindings.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/request.hxx>
43 
44 #include <sfx2/viewfrm.hxx>
45 
46 
47 #include "app.hrc"
48 
49 #include "sdpage.hxx"
50 #include "drawdoc.hxx"
51 #include "DrawDocShell.hxx"
52 #include "slideshow.hxx"
53 #include "pgjump.hxx"
54 #include "NavigatorChildWindow.hxx"
55 #ifndef SD_NAVIGATION_HXX
56 #include "navigatr.hxx"
57 #endif
58 #include "drawview.hxx"
59 #include "slideshow.hxx"
60 
61 namespace sd {
62 
63 /*************************************************************************
64 |*
65 |* SfxRequests fuer Navigator bearbeiten
66 |*
67 \************************************************************************/
68 
69 void DrawViewShell::ExecNavigatorWin( SfxRequest& rReq )
70 {
71 	CheckLineTo (rReq);
72 
73 	sal_uInt16 nSId = rReq.GetSlot();
74 
75 	switch( nSId )
76 	{
77 		case SID_NAVIGATOR_INIT:
78 		{
79 			sal_uInt16 nId = SID_NAVIGATOR;
80 			SfxChildWindow* pWindow = GetViewFrame()->GetChildWindow( nId );
81 			if( pWindow )
82 			{
83 				SdNavigatorWin* pNavWin = (SdNavigatorWin*)( pWindow->GetContextWindow( SD_MOD() ) );
84 				if( pNavWin )
85 					pNavWin->InitTreeLB( GetDoc() );
86 			}
87 		}
88 		break;
89 
90 		case SID_NAVIGATOR_PEN:
91 		case SID_NAVIGATOR_PAGE:
92 		case SID_NAVIGATOR_OBJECT:
93 		{
94 			rtl::Reference< SlideShow > xSlideshow( SlideShow::GetSlideShow( GetViewShellBase() ) );
95 			if (xSlideshow.is() && xSlideshow->isRunning() )
96 			{
97 				xSlideshow->receiveRequest( rReq );
98 			}
99 			else if (nSId == SID_NAVIGATOR_PAGE)
100 			{
101 				if ( mpDrawView->IsTextEdit() )
102 					mpDrawView->SdrEndTextEdit();
103 
104 				const SfxItemSet* pArgs = rReq.GetArgs();
105 				PageJump eJump = (PageJump)((SfxAllEnumItem&) pArgs->
106 								  Get(SID_NAVIGATOR_PAGE)).GetValue();
107 
108 				switch (eJump)
109 				{
110 					case PAGE_FIRST:
111 					{
112 						// Sprung zu erster Seite
113 						SwitchPage(0);
114 					}
115 					break;
116 
117 					case PAGE_LAST:
118 					{
119 						// Sprung zu letzter Seite
120 						SwitchPage(GetDoc()->GetSdPageCount(mpActualPage->GetPageKind()) - 1);
121 					}
122 					break;
123 
124 					case PAGE_NEXT:
125 					{
126 						// Sprung zu naechster Seite
127 						sal_uInt16 nSdPage = (mpActualPage->GetPageNum() - 1) / 2;
128 
129 						if (nSdPage < GetDoc()->GetSdPageCount(mpActualPage->GetPageKind()) - 1)
130 						{
131 							SwitchPage(nSdPage + 1);
132 						}
133 					}
134 					break;
135 
136 					case PAGE_PREVIOUS:
137 					{
138 						// Sprung zu vorheriger Seite
139 						sal_uInt16 nSdPage = (mpActualPage->GetPageNum() - 1) / 2;
140 
141 						if (nSdPage > 0)
142 						{
143 							SwitchPage(nSdPage - 1);
144 						}
145 					}
146 					break;
147 
148 					case PAGE_NONE:
149 						break;
150 				}
151 			}
152 			else if (nSId == SID_NAVIGATOR_OBJECT)
153 			{
154 				String aBookmarkStr;
155 				aBookmarkStr += sal_Unicode( '#' );
156 				const SfxItemSet* pArgs = rReq.GetArgs();
157 				String aTarget = ((SfxStringItem&) pArgs->
158 								 Get(SID_NAVIGATOR_OBJECT)).GetValue();
159 				aBookmarkStr += aTarget;
160 				SfxStringItem aStrItem(SID_FILE_NAME, aBookmarkStr);
161 				SfxStringItem aReferer(SID_REFERER, GetDocSh()->GetMedium()->GetName());
162 				SfxViewFrame* pFrame = GetViewFrame();
163 				SfxFrameItem aFrameItem(SID_DOCFRAME, pFrame);
164 				SfxBoolItem aBrowseItem(SID_BROWSE, sal_True);
165 				pFrame->GetDispatcher()->
166 				Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
167 							&aStrItem, &aFrameItem, &aBrowseItem, &aReferer, 0L);
168 			}
169 
170 			SfxBindings& rBindings = GetViewFrame()->GetBindings();
171 			rBindings.Invalidate( SID_NAVIGATOR_STATE );
172 			rBindings.Invalidate( SID_NAVIGATOR_PAGENAME );
173 		}
174 		break;
175 
176 		default:
177 		break;
178 	}
179 }
180 
181 /*************************************************************************
182 |*
183 |* Statuswerte fuer Navigator zurueckgeben
184 |*
185 \************************************************************************/
186 
187 void DrawViewShell::GetNavigatorWinState( SfxItemSet& rSet )
188 {
189 	sal_uInt32 nState = NAVSTATE_NONE;
190 	sal_uInt16 nCurrentPage = 0;
191 	sal_uInt16 nFirstPage = 0;
192 	sal_uInt16 nLastPage;
193 	sal_Bool   bEndless = sal_False;
194 	String aPageName;
195 
196 	rtl::Reference< SlideShow > xSlideshow( SlideShow::GetSlideShow( GetViewShellBase() ) );
197 	if( xSlideshow.is() && xSlideshow->isRunning() )
198 	{
199 		// pen activated?
200 		nState |= xSlideshow->isDrawingPossible() ? NAVBTN_PEN_CHECKED : NAVBTN_PEN_UNCHECKED;
201 
202 		nCurrentPage = (sal_uInt16)xSlideshow->getCurrentPageNumber();
203 		nFirstPage = (sal_uInt16)xSlideshow->getFirstPageNumber();
204 		nLastPage = (sal_uInt16)xSlideshow->getLastPageNumber();
205 		bEndless = xSlideshow->isEndless();
206 
207         // Get the page for the current page number.
208 		SdPage* pPage = 0;
209 		if( nCurrentPage < GetDoc()->GetSdPageCount( PK_STANDARD ) )
210 			pPage = GetDoc()->GetSdPage (nCurrentPage, PK_STANDARD);
211 
212 		if(pPage)
213 			aPageName = pPage->GetName();
214 	}
215 	else
216 	{
217 		nState |= NAVBTN_PEN_DISABLED | NAVTLB_UPDATE;
218 
219         if (mpActualPage != NULL)
220         {
221             nCurrentPage = ( mpActualPage->GetPageNum() - 1 ) / 2;
222             aPageName = mpActualPage->GetName();
223         }
224 		nLastPage = GetDoc()->GetSdPageCount( mePageKind ) - 1;
225 	}
226 
227 	// erste Seite / vorherige Seite
228 	if( nCurrentPage == nFirstPage )
229 	{
230 		nState |= NAVBTN_FIRST_DISABLED;
231 		if( !bEndless )
232 			nState |= NAVBTN_PREV_DISABLED;
233 		else
234 			nState |= NAVBTN_PREV_ENABLED;
235 	}
236 	else
237 	{
238 		nState |= NAVBTN_FIRST_ENABLED | NAVBTN_PREV_ENABLED;
239 	}
240 
241 	// letzte Seite / naechste Seite
242 	if( nCurrentPage == nLastPage )
243 	{
244 		nState |= NAVBTN_LAST_DISABLED;
245 		if( !bEndless )
246 			nState |= NAVBTN_NEXT_DISABLED;
247 		else
248 			nState |= NAVBTN_NEXT_ENABLED;
249 	}
250 	else
251 	{
252 		nState |= NAVBTN_LAST_ENABLED | NAVBTN_NEXT_ENABLED;
253 	}
254 
255 	rSet.Put( SfxUInt32Item( SID_NAVIGATOR_STATE, nState ) );
256 	rSet.Put( SfxStringItem( SID_NAVIGATOR_PAGENAME, aPageName ) );
257 }
258 
259 } // end of namespace sd
260