/src/libreoffice/sd/source/ui/func/funavig.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <funavig.hxx> |
21 | | #include <sfx2/viewfrm.hxx> |
22 | | |
23 | | #include <app.hrc> |
24 | | #include <sdpage.hxx> |
25 | | #include <sfx2/bindings.hxx> |
26 | | #include <sfx2/request.hxx> |
27 | | #include <drawdoc.hxx> |
28 | | #include <DrawViewShell.hxx> |
29 | | #include <ViewShell.hxx> |
30 | | #include <slideshow.hxx> |
31 | | |
32 | | #include <svx/svxids.hrc> |
33 | | #include <svx/dialog/gotodlg.hxx> |
34 | | #include <strings.hrc> |
35 | | #include <sdresid.hxx> |
36 | | |
37 | | namespace sd { |
38 | | |
39 | | |
40 | | FuNavigation::FuNavigation ( |
41 | | ViewShell& rViewSh, |
42 | | ::sd::Window* pWin, |
43 | | ::sd::View* pView, |
44 | | SdDrawDocument& rDoc, |
45 | | SfxRequest& rReq) |
46 | 0 | : FuPoor(rViewSh, pWin, pView, rDoc, rReq) |
47 | 0 | { |
48 | 0 | } |
49 | | |
50 | | rtl::Reference<FuPoor> FuNavigation::Create( ViewShell& rViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument& rDoc, SfxRequest& rReq ) |
51 | 0 | { |
52 | 0 | rtl::Reference<FuPoor> xFunc( new FuNavigation( rViewSh, pWin, pView, rDoc, rReq ) ); |
53 | 0 | xFunc->DoExecute(rReq); |
54 | 0 | return xFunc; |
55 | 0 | } |
56 | | |
57 | | void FuNavigation::DoExecute( SfxRequest& rReq ) |
58 | 0 | { |
59 | 0 | bool bSlideShow = SlideShow::IsRunning( mrViewShell.GetViewShellBase() ) |
60 | 0 | && !SlideShow::IsInteractiveSlideshow( mrViewShell.GetViewShellBase() ); // IASS |
61 | |
|
62 | 0 | switch ( rReq.GetSlot() ) |
63 | 0 | { |
64 | 0 | case SID_GO_TO_FIRST_PAGE: |
65 | 0 | { |
66 | 0 | if (!mpView->IsTextEdit() |
67 | 0 | && dynamic_cast< const DrawViewShell *>( &mrViewShell ) != nullptr |
68 | 0 | && !bSlideShow) |
69 | 0 | { |
70 | | // jump to first page |
71 | 0 | static_cast<DrawViewShell*>(&mrViewShell)->SwitchPage(0); |
72 | 0 | } |
73 | 0 | } |
74 | 0 | break; |
75 | | |
76 | 0 | case SID_GO_TO_PREVIOUS_PAGE: |
77 | 0 | { |
78 | 0 | if( !bSlideShow) |
79 | 0 | if( auto pDrawViewShell = dynamic_cast<DrawViewShell *>( &mrViewShell ) ) |
80 | 0 | { |
81 | | // With no modifier pressed we move to the previous |
82 | | // slide. |
83 | 0 | mpView->SdrEndTextEdit(); |
84 | | |
85 | | // Previous page. |
86 | 0 | SdPage* pPage = pDrawViewShell->GetActualPage(); |
87 | 0 | sal_uInt16 nSdPage = (pPage->GetPageNum() - 1) / 2; |
88 | |
|
89 | 0 | if (nSdPage > 0) |
90 | 0 | { |
91 | | // Switch the page and send events regarding |
92 | | // deactivation the old page and activating the new |
93 | | // one. |
94 | 0 | TabControl& rPageTabControl = |
95 | 0 | static_cast<DrawViewShell*>(&mrViewShell) |
96 | 0 | ->GetPageTabControl(); |
97 | 0 | if (rPageTabControl.IsReallyShown()) |
98 | 0 | rPageTabControl.SendDeactivatePageEvent (); |
99 | 0 | static_cast<DrawViewShell*>(&mrViewShell)->SwitchPage(nSdPage - 1); |
100 | 0 | if (rPageTabControl.IsReallyShown()) |
101 | 0 | rPageTabControl.SendActivatePageEvent (); |
102 | 0 | } |
103 | 0 | } |
104 | 0 | } |
105 | 0 | break; |
106 | | |
107 | 0 | case SID_GO_TO_NEXT_PAGE: |
108 | 0 | { |
109 | 0 | if( !bSlideShow) |
110 | 0 | if( auto pDrawViewShell = dynamic_cast<DrawViewShell *>( &mrViewShell )) |
111 | 0 | { |
112 | | // With no modifier pressed we move to the next slide. |
113 | 0 | mpView->SdrEndTextEdit(); |
114 | | |
115 | | // Next page. |
116 | 0 | SdPage* pPage = pDrawViewShell->GetActualPage(); |
117 | 0 | sal_uInt16 nSdPage = (pPage->GetPageNum() - 1) / 2; |
118 | |
|
119 | 0 | if (nSdPage < mrDoc.GetSdPageCount(pPage->GetPageKind()) - 1) |
120 | 0 | { |
121 | | // Switch the page and send events regarding |
122 | | // deactivation the old page and activating the new |
123 | | // one. |
124 | 0 | TabControl& rPageTabControl = |
125 | 0 | static_cast<DrawViewShell*>(&mrViewShell)->GetPageTabControl(); |
126 | 0 | if (rPageTabControl.IsReallyShown()) |
127 | 0 | rPageTabControl.SendDeactivatePageEvent (); |
128 | 0 | static_cast<DrawViewShell*>(&mrViewShell)->SwitchPage(nSdPage + 1); |
129 | 0 | if (rPageTabControl.IsReallyShown()) |
130 | 0 | rPageTabControl.SendActivatePageEvent (); |
131 | 0 | } |
132 | 0 | } |
133 | 0 | } |
134 | 0 | break; |
135 | | |
136 | 0 | case SID_GO_TO_LAST_PAGE: |
137 | 0 | { |
138 | 0 | if (!mpView->IsTextEdit() && !bSlideShow) |
139 | 0 | if (auto pDrawViewShell = dynamic_cast<DrawViewShell *>( &mrViewShell )) |
140 | 0 | { |
141 | | // jump to last page |
142 | 0 | SdPage* pPage = pDrawViewShell->GetActualPage(); |
143 | 0 | pDrawViewShell->SwitchPage(mrDoc.GetSdPageCount( |
144 | 0 | pPage->GetPageKind()) - 1); |
145 | 0 | } |
146 | 0 | } |
147 | 0 | break; |
148 | | |
149 | 0 | case SID_GO_TO_PAGE: |
150 | 0 | { |
151 | 0 | if( !bSlideShow) |
152 | 0 | if(auto pDrawViewShell = dynamic_cast<DrawViewShell *>( &mrViewShell )) |
153 | 0 | { |
154 | 0 | OUString sTitle = SdResId(STR_GOTO_PAGE_DLG_TITLE); |
155 | 0 | OUString sLabel = SdResId(STR_PAGE_NAME) + ":"; |
156 | |
|
157 | 0 | if (mrDoc.GetDocumentType() == DocumentType::Impress) |
158 | 0 | { |
159 | 0 | sTitle = SdResId(STR_GOTO_SLIDE_DLG_TITLE); |
160 | 0 | sLabel = SdResId(STR_SLIDE_NAME) + ":"; |
161 | 0 | } |
162 | 0 | std::shared_ptr<SfxRequest> xRequest = std::make_shared<SfxRequest>(rReq); |
163 | 0 | rReq.Ignore(); // the 'old' request is not relevant any more |
164 | |
|
165 | 0 | auto xDialog = std::make_shared<svx::GotoPageDlg>(pDrawViewShell->GetFrameWeld(), sTitle, sLabel, |
166 | 0 | pDrawViewShell->GetCurPagePos() + 1, |
167 | 0 | mrDoc.GetSdPageCount(PageKind::Standard)); |
168 | |
|
169 | 0 | rtl::Reference<FuNavigation> xThis( this ); // avoid destruction within async processing |
170 | 0 | weld::DialogController::runAsync(xDialog, [xDialog, xRequest=std::move(xRequest), xThis](sal_uInt32 nResult) { |
171 | 0 | if (nResult == RET_OK) |
172 | 0 | { |
173 | 0 | DrawViewShell& rDrawViewShell2 = dynamic_cast<DrawViewShell&>(xThis->mrViewShell); |
174 | 0 | rDrawViewShell2.SwitchPage(xDialog->GetPageSelection() - 1); |
175 | 0 | } |
176 | 0 | xThis->Finish(); |
177 | 0 | xRequest->Done(); |
178 | 0 | }); |
179 | |
|
180 | 0 | return; |
181 | 0 | } |
182 | 0 | } |
183 | 0 | break; |
184 | 0 | } |
185 | | |
186 | 0 | Finish(); |
187 | 0 | } |
188 | | |
189 | | void FuNavigation::Finish() |
190 | 0 | { |
191 | | // Refresh toolbar icons |
192 | 0 | SfxBindings& rBindings = mrViewShell.GetViewFrame()->GetBindings(); |
193 | 0 | rBindings.Invalidate(SID_GO_TO_FIRST_PAGE); |
194 | 0 | rBindings.Invalidate(SID_GO_TO_PREVIOUS_PAGE); |
195 | 0 | rBindings.Invalidate(SID_GO_TO_NEXT_PAGE); |
196 | 0 | rBindings.Invalidate(SID_GO_TO_LAST_PAGE); |
197 | 0 | } |
198 | | |
199 | | |
200 | | } // end of namespace sd |
201 | | |
202 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |