/src/libreoffice/sw/source/uibase/uiview/viewmdi.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 <sfx2/dispatch.hxx> |
21 | | #include <sfx2/viewfrm.hxx> |
22 | | #include <svx/ruler.hxx> |
23 | | #include <editeng/lrspitem.hxx> |
24 | | #include <o3tl/safeint.hxx> |
25 | | #include <svl/srchitem.hxx> |
26 | | #include <svl/stritem.hxx> |
27 | | #include <sfx2/request.hxx> |
28 | | #include <vcl/vclevent.hxx> |
29 | | #include <swmodule.hxx> |
30 | | #include <view.hxx> |
31 | | #include <wrtsh.hxx> |
32 | | #include <viewopt.hxx> |
33 | | #include <frmatr.hxx> |
34 | | #include <edtwin.hxx> |
35 | | #include <pagedesc.hxx> |
36 | | #include <IMark.hxx> |
37 | | #include <fldbas.hxx> |
38 | | #include <workctrl.hxx> |
39 | | #include <usrpref.hxx> |
40 | | #include <scroll.hxx> |
41 | | #include <wview.hxx> |
42 | | |
43 | | #include <cmdid.h> |
44 | | |
45 | | #include <PostItMgr.hxx> |
46 | | #include <AnnotationWin.hxx> |
47 | | |
48 | | #include <svx/srchdlg.hxx> |
49 | | #include <svx/svdview.hxx> |
50 | | |
51 | | #include <vcl/uitest/logger.hxx> |
52 | | #include <vcl/uitest/eventdescription.hxx> |
53 | | |
54 | | sal_uInt16 SwView::s_nMoveType = NID_PGE; |
55 | | sal_Int32 SwView::s_nActMark = 0; |
56 | | |
57 | | namespace { |
58 | | |
59 | | void collectUIInformation(const OUString& aFactor) |
60 | 322 | { |
61 | 322 | EventDescription aDescription; |
62 | 322 | aDescription.aID = "writer_edit"; |
63 | 322 | aDescription.aParameters = {{"ZOOM", aFactor}}; |
64 | 322 | aDescription.aAction = "SET"; |
65 | 322 | aDescription.aKeyWord = "SwEditWinUIObject"; |
66 | 322 | aDescription.aParent = "MainWindow"; |
67 | 322 | UITestLogger::getInstance().logEvent(aDescription); |
68 | 322 | } |
69 | | |
70 | | } |
71 | | |
72 | | void SwView::SetZoom( SvxZoomType eZoomType, short nFactor, bool bViewOnly ) |
73 | 322 | { |
74 | 322 | bool const bCursorIsVisible(m_pWrtShell->IsCursorVisible()); |
75 | 322 | SetZoom_( GetEditWin().GetOutputSizePixel(), eZoomType, nFactor, bViewOnly ); |
76 | | // fdo#40465 force the cursor to stay in view whilst zooming |
77 | 322 | if (bCursorIsVisible) |
78 | 0 | m_pWrtShell->ShowCursor(); |
79 | | |
80 | 322 | Invalidate(SID_ZOOM_IN); |
81 | 322 | Invalidate(SID_ZOOM_OUT); |
82 | | |
83 | 322 | collectUIInformation(OUString::number(nFactor)); |
84 | 322 | } |
85 | | |
86 | | void SwView::SetZoom_( const Size &rEditSize, SvxZoomType eZoomType, |
87 | | short nFactor, bool bViewOnly ) |
88 | 322 | { |
89 | 322 | bool bUnLockView = !m_pWrtShell->IsViewLocked(); |
90 | 322 | m_pWrtShell->LockView( true ); |
91 | 322 | m_pWrtShell->LockPaint(LockPaintReason::SetZoom); |
92 | | |
93 | 322 | { // start of SwActContext scope |
94 | 322 | SwActContext aActContext(m_pWrtShell.get()); |
95 | | |
96 | 322 | tools::Long nFac = nFactor; |
97 | | |
98 | 322 | const bool bWeb = dynamic_cast< const SwWebView *>( this ) != nullptr; |
99 | 322 | SwModule* mod = SwModule::get(); |
100 | 322 | SwMasterUsrPref *pUsrPref = const_cast<SwMasterUsrPref*>(mod->GetUsrPref(bWeb)); |
101 | | |
102 | 322 | const SwPageDesc &rDesc = m_pWrtShell->GetPageDesc( m_pWrtShell->GetCurPageDesc() ); |
103 | 322 | const SvxLRSpaceItem &rLRSpace = rDesc.GetMaster().GetLRSpace(); |
104 | 322 | const SwViewOption *pOpt = m_pWrtShell->GetViewOptions(); |
105 | 322 | tools::Long lLeftMargin = 0; |
106 | | |
107 | 322 | if( eZoomType != SvxZoomType::PERCENT ) |
108 | 84 | { |
109 | 84 | const bool bAutomaticViewLayout = 0 == pOpt->GetViewLayoutColumns(); |
110 | | |
111 | 84 | const SwRect aPageRect( m_pWrtShell->GetAnyCurRect( CurRectType::PageCalc ) ); |
112 | 84 | const SwRect aRootRect( m_pWrtShell->GetAnyCurRect( CurRectType::PagesArea ) ); |
113 | 84 | Size aPageSize( aPageRect.SSize() ); |
114 | 84 | Size aRootSize( aRootRect.SSize() ); |
115 | | |
116 | | //mod #i6193# added sidebar width |
117 | 84 | SwPostItMgr* pPostItMgr = GetPostItMgr(); |
118 | 84 | if (pPostItMgr->HasNotes() && pPostItMgr->ShowNotes()) |
119 | 0 | aPageSize.AdjustWidth(pPostItMgr->GetSidebarWidth() + pPostItMgr->GetSidebarBorderWidth() ); |
120 | | |
121 | 84 | const MapMode aTmpMap( MapUnit::MapTwip ); |
122 | 84 | const Size aWindowSize( GetEditWin().PixelToLogic( rEditSize, aTmpMap ) ); |
123 | | |
124 | 84 | if( SvxZoomType::OPTIMAL == eZoomType ) |
125 | 0 | { |
126 | | // unclear if this is useful for OPTIMAL, or completely useless? |
127 | 0 | if( UseOnPage::Mirror == rDesc.GetUseOn() ) // mirrored pages |
128 | 0 | { |
129 | 0 | const SvxLRSpaceItem &rLeftLRSpace = rDesc.GetLeft().GetLRSpace(); |
130 | 0 | aPageSize.AdjustWidth( |
131 | 0 | std::abs(rLeftLRSpace.ResolveLeft() - rLRSpace.ResolveLeft())); |
132 | 0 | } |
133 | |
|
134 | 0 | if (!pPostItMgr->HasNotes() || !pPostItMgr->ShowNotes()) |
135 | 0 | aPageSize.AdjustWidth( |
136 | 0 | -(rLRSpace.ResolveLeft() + rLRSpace.ResolveRight({}) + nLeftOfst * 2)); |
137 | 0 | lLeftMargin = rLRSpace.ResolveLeft() + DOCUMENTBORDER + nLeftOfst; |
138 | 0 | nFac = aWindowSize.Width() * 100 / aPageSize.Width(); |
139 | 0 | } |
140 | 84 | else if(SvxZoomType::WHOLEPAGE == eZoomType || SvxZoomType::PAGEWIDTH == eZoomType ) |
141 | 19 | { |
142 | 19 | const tools::Long nOf = DOCUMENTBORDER * 2; |
143 | 19 | tools::Long nTmpWidth = bAutomaticViewLayout ? aPageSize.Width() : aRootSize.Width(); |
144 | 19 | nTmpWidth += nOf; |
145 | 19 | aPageSize.AdjustHeight(nOf ); |
146 | 19 | nFac = aWindowSize.Width() * 100 / nTmpWidth; |
147 | | |
148 | 19 | if ( SvxZoomType::WHOLEPAGE == eZoomType ) |
149 | 0 | { |
150 | 0 | tools::Long nVisPercent = aWindowSize.Height() * 100 / aPageSize.Height(); |
151 | 0 | nFac = std::min( nFac, nVisPercent ); |
152 | 0 | } |
153 | 19 | } |
154 | 65 | else |
155 | 65 | { |
156 | 65 | const tools::Long nTmpWidth = bAutomaticViewLayout ? aPageSize.Width() : aRootSize.Width(); |
157 | 65 | nFac = aWindowSize.Width() * 100 / nTmpWidth; |
158 | 65 | } |
159 | 84 | } |
160 | | |
161 | 322 | nFac = std::max( tools::Long( MINZOOM ), nFac ); |
162 | 322 | const sal_uInt16 nZoomFac = o3tl::narrowing<sal_uInt16>(nFac); |
163 | | |
164 | 322 | SwViewOption aOpt( *pOpt ); |
165 | 322 | if ( !GetViewFrame().GetFrame().IsInPlace() ) |
166 | 322 | { |
167 | | //Update MasterUsrPrefs and after that update the ViewOptions of the current View. |
168 | 322 | if ( !bViewOnly && |
169 | 0 | (nZoomFac != pUsrPref->GetZoom() || |
170 | 0 | eZoomType != pUsrPref->GetZoomType()) ) |
171 | 0 | { |
172 | 0 | pUsrPref->SetZoom(nZoomFac); |
173 | 0 | pUsrPref->SetZoomType(eZoomType); |
174 | 0 | mod->ApplyUsrPref(*pUsrPref, nullptr); |
175 | 0 | pUsrPref->SetModified(); |
176 | 0 | } |
177 | 322 | if ( pOpt->GetZoom() != nZoomFac ) |
178 | 234 | { |
179 | 234 | aOpt.SetZoom(nZoomFac); |
180 | 234 | aOpt.SetReadonly(pOpt->IsReadonly()); |
181 | 234 | m_pWrtShell->ApplyViewOptions( aOpt ); |
182 | 234 | } |
183 | 322 | if ( eZoomType != SvxZoomType::PERCENT ) |
184 | 84 | { |
185 | 84 | Point aPos; |
186 | | |
187 | 84 | if ( eZoomType == SvxZoomType::WHOLEPAGE ) |
188 | 0 | aPos.setY( m_pWrtShell->GetAnyCurRect(CurRectType::Page).Top() - DOCUMENTBORDER ); |
189 | 84 | else |
190 | 84 | { |
191 | | // Make sure that the cursor is in the visible range, so that |
192 | | // the scrolling will be performed only once. |
193 | 84 | aPos.setX( lLeftMargin ); |
194 | 84 | const SwRect &rCharRect = m_pWrtShell->GetCharRect(); |
195 | 84 | if ( rCharRect.Top() > GetVisArea().Bottom() || |
196 | 0 | rCharRect.Bottom() < aPos.Y() ) |
197 | 84 | aPos.setY( rCharRect.Top() - rCharRect.Height() ); |
198 | 0 | else |
199 | 0 | aPos.setY( GetVisArea().Top() ); |
200 | 84 | } |
201 | 84 | SetVisArea( aPos ); |
202 | 84 | } |
203 | | // Compromise solution - Under certain circumstances SetZoom is called |
204 | | // in CalcVisAreas again and thus be set wrong values. |
205 | 322 | const_cast<SwViewOption*>(m_pWrtShell->GetViewOptions())->SetZoomType( eZoomType ); |
206 | 322 | CalcVisArea( rEditSize ); // for the recalculation of the viewable area |
207 | 322 | } |
208 | 0 | else if ( nZoomFac != pOpt->GetZoom() ) |
209 | 0 | { |
210 | 0 | aOpt.SetZoom( nZoomFac ); |
211 | 0 | m_pWrtShell->ApplyViewOptions( aOpt ); |
212 | 0 | } |
213 | | |
214 | 322 | const double aFrac = double(nFac) / 100; |
215 | 322 | m_pVRuler->SetZoom( aFrac ); |
216 | 322 | m_pVRuler->ForceUpdate(); |
217 | 322 | m_pHRuler->SetZoom( aFrac ); |
218 | 322 | m_pHRuler->ForceUpdate(); |
219 | 322 | const_cast<SwViewOption*>(m_pWrtShell->GetViewOptions())->SetZoomType( eZoomType ); |
220 | 322 | } // end of SwActContext scope |
221 | | |
222 | 322 | m_pWrtShell->UnlockPaint(); |
223 | 322 | if( bUnLockView ) |
224 | 322 | m_pWrtShell->LockView( false ); |
225 | 322 | } |
226 | | |
227 | | void SwView::SetViewLayout( sal_uInt16 nColumns, bool bBookMode, bool bViewOnly ) |
228 | 17 | { |
229 | 17 | SwActContext aActContext(m_pWrtShell.get()); |
230 | | |
231 | 17 | if ( !GetViewFrame().GetFrame().IsInPlace() && !bViewOnly ) |
232 | 0 | { |
233 | 0 | const bool bWeb = dynamic_cast< const SwWebView *>( this ) != nullptr; |
234 | 0 | SwModule* mod = SwModule::get(); |
235 | 0 | SwMasterUsrPref *pUsrPref = const_cast<SwMasterUsrPref*>(mod->GetUsrPref(bWeb)); |
236 | | |
237 | | // Update MasterUsrPrefs and after that update the ViewOptions of the current View. |
238 | 0 | if ( nColumns != pUsrPref->GetViewLayoutColumns() || |
239 | 0 | bBookMode != pUsrPref->IsViewLayoutBookMode() ) |
240 | 0 | { |
241 | 0 | pUsrPref->SetViewLayoutColumns(nColumns); |
242 | 0 | pUsrPref->SetViewLayoutBookMode(bBookMode); |
243 | 0 | mod->ApplyUsrPref(*pUsrPref, nullptr); |
244 | 0 | pUsrPref->SetModified(); |
245 | 0 | } |
246 | 0 | } |
247 | | |
248 | 17 | const SwViewOption *pOpt = m_pWrtShell->GetViewOptions(); |
249 | | |
250 | 17 | if ( nColumns != pOpt->GetViewLayoutColumns() || |
251 | 0 | bBookMode != pOpt->IsViewLayoutBookMode() ) |
252 | 17 | { |
253 | 17 | SwViewOption aOpt( *pOpt ); |
254 | 17 | aOpt.SetViewLayoutColumns( nColumns ); |
255 | 17 | aOpt.SetViewLayoutBookMode( bBookMode ); |
256 | | // tdf#98446 - hiding whitespace is only possible in single-page view |
257 | 17 | if (!aOpt.CanHideWhitespace()) |
258 | 0 | aOpt.SetHideWhitespaceMode(false); |
259 | 17 | m_pWrtShell->ApplyViewOptions( aOpt ); |
260 | 17 | } |
261 | | |
262 | 17 | m_pVRuler->ForceUpdate(); |
263 | 17 | m_pHRuler->ForceUpdate(); |
264 | | |
265 | 17 | SfxBindings& rBnd = GetViewFrame().GetBindings(); |
266 | 17 | rBnd.Invalidate( SID_ATTR_VIEWLAYOUT ); |
267 | 17 | rBnd.Invalidate( SID_ATTR_ZOOMSLIDER); |
268 | 17 | } |
269 | | |
270 | | // Scrollbar - Handler |
271 | | |
272 | | IMPL_LINK( SwView, WindowChildEventListener, VclWindowEvent&, rEvent, void ) |
273 | 0 | { |
274 | 0 | OSL_ENSURE( rEvent.GetWindow(), "Window???" ); |
275 | 0 | vcl::Window* pChildWin = static_cast< vcl::Window* >( rEvent.GetData() ); |
276 | |
|
277 | 0 | switch ( rEvent.GetId() ) |
278 | 0 | { |
279 | 0 | case VclEventId::WindowHide: |
280 | 0 | if( pChildWin == m_pHScrollbar ) |
281 | 0 | ShowHScrollbar( false ); |
282 | 0 | else if( pChildWin == m_pVScrollbar ) |
283 | 0 | ShowVScrollbar( false ); |
284 | 0 | break; |
285 | 0 | case VclEventId::WindowShow: |
286 | 0 | if( pChildWin == m_pHScrollbar ) |
287 | 0 | ShowHScrollbar( true ); |
288 | 0 | else if( pChildWin == m_pVScrollbar ) |
289 | 0 | ShowVScrollbar( true ); |
290 | 0 | break; |
291 | 0 | default: break; |
292 | 0 | } |
293 | 0 | } |
294 | | |
295 | | void SwView::CreateScrollbar( bool bHori ) |
296 | 0 | { |
297 | 0 | vcl::Window *pMDI = &GetViewFrame().GetWindow(); |
298 | 0 | VclPtr<SwScrollbar>& ppScrollbar = bHori ? m_pHScrollbar : m_pVScrollbar; |
299 | |
|
300 | 0 | assert(!ppScrollbar); //check beforehand! |
301 | |
|
302 | 0 | ppScrollbar = VclPtr<SwScrollbar>::Create( pMDI, bHori ); |
303 | 0 | UpdateScrollbars(); |
304 | 0 | if(bHori) |
305 | 0 | ppScrollbar->SetScrollHdl( LINK( this, SwView, HoriScrollHdl )); |
306 | 0 | else |
307 | 0 | ppScrollbar->SetScrollHdl( LINK( this, SwView, VertScrollHdl )); |
308 | |
|
309 | 0 | if(GetWindow()) |
310 | 0 | InvalidateBorder(); |
311 | |
|
312 | 0 | if (!m_bShowAtResize) |
313 | 0 | ppScrollbar->ExtendedShow(); |
314 | 0 | } |
315 | | |
316 | | void SwView::MoveNavigation(bool bNext) |
317 | 0 | { |
318 | 0 | SwWrtShell& rSh = GetWrtShell(); |
319 | 0 | if ( NID_SRCH_REP != s_nMoveType) |
320 | 0 | { |
321 | 0 | if ( rSh.GetDrawView()->IsTextEdit() ) |
322 | 0 | rSh.EndTextEdit(); |
323 | 0 | if ( IsDrawMode() ) |
324 | 0 | LeaveDrawCreate(); |
325 | 0 | } |
326 | 0 | if ( NID_POSTIT != s_nMoveType && m_pPostItMgr ) |
327 | 0 | { |
328 | 0 | sw::annotation::SwAnnotationWin* pActiveSidebarWin = m_pPostItMgr->GetActiveSidebarWin(); |
329 | 0 | if (pActiveSidebarWin) |
330 | 0 | pActiveSidebarWin->SwitchToFieldPos(); |
331 | 0 | } |
332 | 0 | if (NID_RECENCY != s_nMoveType && NID_PGE != s_nMoveType && NID_SRCH_REP != s_nMoveType) |
333 | 0 | rSh.addCurrentPosition(); |
334 | 0 | switch( s_nMoveType ) |
335 | 0 | { |
336 | 0 | case NID_PGE: |
337 | 0 | { |
338 | 0 | tools::Long nYPos; |
339 | 0 | SwVisiblePageNumbers aVisiblePageNumbers; |
340 | 0 | rSh.GetFirstLastVisPageNumbers(aVisiblePageNumbers, rSh.GetView()); |
341 | 0 | if ((bNext && aVisiblePageNumbers.nLastPhy + 1 > rSh.GetPageCnt()) || |
342 | 0 | (!bNext && aVisiblePageNumbers.nFirstPhy == 1)) |
343 | 0 | { |
344 | 0 | nYPos = rSh.GetPagePos(bNext ? 1 : rSh.GetPageCnt()).Y(); |
345 | 0 | SvxSearchDialogWrapper::SetSearchLabel(bNext ? SearchLabel::EndWrapped : |
346 | 0 | SearchLabel::StartWrapped); |
347 | 0 | } |
348 | 0 | else |
349 | 0 | { |
350 | 0 | auto nPage = bNext ? aVisiblePageNumbers.nLastPhy + 1 : |
351 | 0 | aVisiblePageNumbers.nFirstPhy - 1; |
352 | 0 | nYPos = rSh.GetPagePos(nPage).Y(); |
353 | 0 | SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::Empty); |
354 | 0 | } |
355 | 0 | const Point aPt(GetVisArea().Left(), nYPos); |
356 | 0 | Point aAlPt(AlignToPixel(aPt)); |
357 | | // If there is a difference, has been truncated --> then add one pixel, |
358 | | // so that no residue of the previous page is visible. |
359 | 0 | if(aPt.Y() != aAlPt.Y()) |
360 | 0 | aAlPt.AdjustY(3 * GetEditWin().PixelToLogic(Size(0, 1)).Height()); |
361 | 0 | SetVisArea(aAlPt); |
362 | 0 | } |
363 | 0 | break; |
364 | 0 | case NID_TBL : |
365 | 0 | rSh.EnterStdMode(); |
366 | 0 | if(bNext) |
367 | 0 | rSh.MoveTable(GotoNextTable, fnTableStart); |
368 | 0 | else |
369 | 0 | rSh.MoveTable(GotoPrevTable, fnTableStart); |
370 | 0 | break; |
371 | 0 | case NID_FRM : |
372 | 0 | case NID_GRF: |
373 | 0 | case NID_OLE: |
374 | 0 | { |
375 | 0 | GotoObjFlags eType = GotoObjFlags::FlyFrame; |
376 | 0 | if(s_nMoveType == NID_GRF) |
377 | 0 | eType = GotoObjFlags::FlyGrf; |
378 | 0 | else if(s_nMoveType == NID_OLE) |
379 | 0 | eType = GotoObjFlags::FlyOLE; |
380 | 0 | bool bSuccess = bNext ? |
381 | 0 | rSh.GotoNextFly(eType) : |
382 | 0 | rSh.GotoPrevFly(eType); |
383 | 0 | if(bSuccess) |
384 | 0 | { |
385 | 0 | rSh.HideCursor(); |
386 | 0 | rSh.EnterSelFrameMode(); |
387 | 0 | } |
388 | 0 | } |
389 | 0 | break; |
390 | 0 | case NID_CTRL: |
391 | 0 | if (!rSh.GetView().IsDesignMode()) |
392 | 0 | rSh.GetView().GetFormShell()->SetDesignMode(true); |
393 | 0 | [[fallthrough]]; |
394 | 0 | case NID_DRW: |
395 | 0 | { |
396 | 0 | bool bSuccess = rSh.GotoObj(bNext, |
397 | 0 | s_nMoveType == NID_DRW ? |
398 | 0 | GotoObjFlags::DrawSimple : |
399 | 0 | GotoObjFlags::DrawControl); |
400 | 0 | if(bSuccess) |
401 | 0 | { |
402 | 0 | rSh.HideCursor(); |
403 | 0 | rSh.EnterSelFrameMode(); |
404 | 0 | } |
405 | 0 | } |
406 | 0 | break; |
407 | 0 | case NID_REG : |
408 | 0 | rSh.EnterStdMode(); |
409 | 0 | if(bNext) |
410 | 0 | rSh.MoveRegion(GotoNextRegion, fnRegionStart); |
411 | 0 | else |
412 | 0 | rSh.MoveRegion(GotoPrevRegion, fnRegionStart); |
413 | |
|
414 | 0 | break; |
415 | 0 | case NID_BKM : |
416 | 0 | rSh.EnterStdMode(); |
417 | 0 | GetViewFrame().GetDispatcher()->Execute(bNext ? |
418 | 0 | FN_NEXT_BOOKMARK : |
419 | 0 | FN_PREV_BOOKMARK); |
420 | 0 | break; |
421 | 0 | case NID_FIELD: |
422 | 0 | { |
423 | 0 | rSh.EnterStdMode(); |
424 | 0 | rSh.StartAction(); |
425 | 0 | SearchLabel eSearchLabel = SearchLabel::Empty; |
426 | 0 | if (!rSh.MoveFieldType(nullptr, bNext, SwFieldIds::Unknown)) |
427 | 0 | { |
428 | | // no field found in the move direction |
429 | | // wrap and try again |
430 | 0 | SwShellCursor* pCursor = rSh.GetCursor_(); |
431 | 0 | SwCursorSaveState aSaveState(*pCursor); |
432 | 0 | rSh.SttEndDoc(bNext); |
433 | | // document might have a field at the start of the document |
434 | 0 | SwField* pField = rSh.GetCurField(); |
435 | 0 | if ((bNext && pField && pField->GetTypeId() != SwFieldTypesEnum::Postit) || |
436 | 0 | rSh.MoveFieldType(nullptr, bNext, SwFieldIds::Unknown)) |
437 | 0 | { |
438 | 0 | eSearchLabel = bNext ? SearchLabel::EndWrapped : SearchLabel::StartWrapped; |
439 | 0 | } |
440 | 0 | else |
441 | 0 | { |
442 | | // no visible fields found |
443 | 0 | pCursor->RestoreSavePos(); |
444 | 0 | eSearchLabel = SearchLabel::NavElementNotFound; |
445 | 0 | } |
446 | 0 | } |
447 | 0 | SvxSearchDialogWrapper::SetSearchLabel(eSearchLabel); |
448 | 0 | rSh.EndAction(); |
449 | 0 | } |
450 | 0 | break; |
451 | 0 | case NID_FIELD_BYTYPE: |
452 | 0 | { |
453 | | // see: SwFieldMgr::GoNextPrev |
454 | 0 | SwField* pCurField = rSh.GetCurField(true); |
455 | 0 | if (!pCurField) |
456 | 0 | break; |
457 | 0 | rSh.EnterStdMode(); |
458 | 0 | SwFieldType* pTyp = nullptr; |
459 | 0 | const SwFieldTypesEnum nTypeId = pCurField->GetTypeId(); |
460 | 0 | if (SwFieldTypesEnum::SetInput == nTypeId || SwFieldTypesEnum::UserInput == nTypeId) |
461 | 0 | pTyp = rSh.GetFieldType(0, SwFieldIds::Input); |
462 | 0 | else |
463 | 0 | pTyp = pCurField->GetTyp(); |
464 | 0 | if (pTyp) |
465 | 0 | { |
466 | 0 | if (pTyp->Which() == SwFieldIds::Database) |
467 | 0 | rSh.MoveFieldType(nullptr, bNext, SwFieldIds::Database); |
468 | 0 | else |
469 | 0 | rSh.MoveFieldType(pTyp, bNext); |
470 | 0 | } |
471 | 0 | } |
472 | 0 | break; |
473 | 0 | case NID_OUTL: |
474 | 0 | rSh.EnterStdMode(); |
475 | 0 | bNext ? rSh.GotoNextOutline() : rSh.GotoPrevOutline(); |
476 | 0 | break; |
477 | 0 | case NID_SEL : |
478 | 0 | rSh.GoNextPrevCursorSetSearchLabel(bNext); |
479 | 0 | break; |
480 | 0 | case NID_FTN: |
481 | 0 | { |
482 | 0 | bool bFrameTypeFootnote(rSh.GetFrameType(nullptr, false) & FrameTypeFlags::FOOTNOTE); |
483 | |
|
484 | 0 | if (bFrameTypeFootnote) |
485 | 0 | { |
486 | 0 | rSh.LockView(true); |
487 | 0 | rSh.GotoFootnoteAnchor(); |
488 | 0 | } |
489 | |
|
490 | 0 | rSh.EnterStdMode(); |
491 | 0 | bNext ? |
492 | 0 | rSh.GotoNextFootnoteAnchor() : |
493 | 0 | rSh.GotoPrevFootnoteAnchor(); |
494 | |
|
495 | 0 | if (bFrameTypeFootnote) |
496 | 0 | { |
497 | 0 | rSh.LockView(false); |
498 | 0 | rSh.GotoFootnoteText(); |
499 | 0 | } |
500 | 0 | } |
501 | 0 | break; |
502 | 0 | case NID_MARK: |
503 | 0 | { |
504 | | // unselect |
505 | 0 | rSh.MoveCursor(); |
506 | 0 | rSh.EnterStdMode(); |
507 | | |
508 | | // collect and sort navigator reminder names |
509 | 0 | IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess(); |
510 | 0 | std::vector< SwMarkName > vNavMarkNames; |
511 | 0 | for(auto ppMark = pMarkAccess->getAllMarksBegin(); |
512 | 0 | ppMark != pMarkAccess->getAllMarksEnd(); |
513 | 0 | ++ppMark) |
514 | 0 | { |
515 | 0 | if( IDocumentMarkAccess::GetType(**ppMark) == IDocumentMarkAccess::MarkType::NAVIGATOR_REMINDER ) |
516 | 0 | vNavMarkNames.push_back((*ppMark)->GetName()); |
517 | 0 | } |
518 | 0 | std::sort(vNavMarkNames.begin(), vNavMarkNames.end()); |
519 | | |
520 | | // move |
521 | 0 | if(!vNavMarkNames.empty()) |
522 | 0 | { |
523 | 0 | SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty ); |
524 | |
|
525 | 0 | if(bNext) |
526 | 0 | { |
527 | 0 | s_nActMark++; |
528 | 0 | if (s_nActMark >= MAX_MARKS || s_nActMark >= static_cast<sal_Int32>(vNavMarkNames.size())) |
529 | 0 | { |
530 | 0 | s_nActMark = 0; |
531 | 0 | SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::ReminderEndWrapped ); |
532 | 0 | } |
533 | 0 | } |
534 | 0 | else |
535 | 0 | { |
536 | 0 | s_nActMark--; |
537 | 0 | if (s_nActMark < 0 || o3tl::make_unsigned(s_nActMark) >= vNavMarkNames.size()) |
538 | 0 | { |
539 | 0 | s_nActMark = vNavMarkNames.size()-1; |
540 | 0 | SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::ReminderStartWrapped ); |
541 | 0 | } |
542 | 0 | } |
543 | 0 | rSh.GotoMark(vNavMarkNames[s_nActMark]); |
544 | 0 | } |
545 | 0 | else |
546 | 0 | SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound ); |
547 | 0 | } |
548 | 0 | break; |
549 | | |
550 | 0 | case NID_POSTIT: |
551 | 0 | { |
552 | 0 | if (m_pPostItMgr->HasNotes()) |
553 | 0 | { |
554 | 0 | rSh.EnterStdMode(); |
555 | 0 | m_pPostItMgr->AssureStdModeAtShell(); |
556 | 0 | m_pPostItMgr->SetActiveSidebarWin(nullptr); |
557 | 0 | GetEditWin().GrabFocus(); |
558 | 0 | SwShellCursor* pCursor = rSh.GetCursor_(); |
559 | 0 | SwCursorSaveState aSaveState(*pCursor); |
560 | 0 | SwFieldType* pFieldType = rSh.GetFieldType(0, SwFieldIds::Postit); |
561 | 0 | bool bWrapped = false; |
562 | 0 | bool bFound = false; |
563 | 0 | rSh.StartAction(); |
564 | 0 | while (!bFound) |
565 | 0 | { |
566 | 0 | if (!rSh.MoveFieldType(pFieldType, bNext)) |
567 | 0 | { |
568 | 0 | if (bWrapped) |
569 | 0 | break; |
570 | 0 | bWrapped = true; |
571 | 0 | rSh.SttEndDoc(bNext); |
572 | 0 | continue; |
573 | 0 | } |
574 | 0 | do |
575 | 0 | { |
576 | 0 | auto pAnnotationWin = m_pPostItMgr->GetAnnotationWin( |
577 | 0 | rSh.GetPostItFieldAtCursor()); |
578 | 0 | if (pAnnotationWin && pAnnotationWin->IsVisible()) |
579 | 0 | bFound = true; |
580 | 0 | } while (!bFound && rSh.MoveFieldType(pFieldType, bNext)); |
581 | 0 | } |
582 | 0 | if (!bFound) |
583 | 0 | { |
584 | 0 | pCursor->RestoreSavePos(); |
585 | 0 | SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::NavElementNotFound); |
586 | 0 | } |
587 | 0 | rSh.EndAction(); |
588 | 0 | if (bFound) |
589 | 0 | { |
590 | 0 | GetViewFrame().GetDispatcher()->Execute(FN_POSTIT); |
591 | 0 | if (bWrapped) |
592 | 0 | SvxSearchDialogWrapper::SetSearchLabel(bNext ? SearchLabel::EndWrapped : |
593 | 0 | SearchLabel::StartWrapped); |
594 | 0 | else |
595 | 0 | SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::Empty); |
596 | 0 | } |
597 | 0 | } |
598 | 0 | else |
599 | 0 | SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::NavElementNotFound); |
600 | 0 | } |
601 | 0 | break; |
602 | | |
603 | 0 | case NID_SRCH_REP: |
604 | 0 | if(s_pSrchItem) |
605 | 0 | { |
606 | 0 | bool bBackward = s_pSrchItem->GetBackward(); |
607 | 0 | if (rSh.HasSelection() && bNext != rSh.IsCursorPtAtEnd()) |
608 | 0 | rSh.SwapPam(); |
609 | 0 | s_pSrchItem->SetBackward(!bNext); |
610 | 0 | SfxRequest aReq(FN_REPEAT_SEARCH, SfxCallMode::SLOT, GetPool()); |
611 | 0 | ExecSearch(aReq); |
612 | 0 | s_pSrchItem->SetBackward(bBackward); |
613 | 0 | } |
614 | 0 | break; |
615 | 0 | case NID_INDEX_ENTRY: |
616 | 0 | rSh.GotoNxtPrvTOXMark(bNext); |
617 | 0 | break; |
618 | | |
619 | 0 | case NID_TABLE_FORMULA: |
620 | 0 | rSh.GotoNxtPrvTableFormula( bNext ); |
621 | 0 | break; |
622 | | |
623 | 0 | case NID_TABLE_FORMULA_ERROR: |
624 | 0 | rSh.GotoNxtPrvTableFormula( bNext, true ); |
625 | 0 | break; |
626 | | |
627 | 0 | case NID_RECENCY: |
628 | 0 | if (bNext) |
629 | 0 | { |
630 | 0 | rSh.EnterStdMode(); |
631 | 0 | rSh.GetNavigationMgr().goForward(); |
632 | 0 | } |
633 | 0 | else |
634 | 0 | { |
635 | 0 | if (rSh.IsCursorVisible()) |
636 | 0 | { |
637 | 0 | rSh.EnterStdMode(); |
638 | 0 | rSh.GetNavigationMgr().goBack(); |
639 | 0 | } |
640 | 0 | else |
641 | 0 | rSh.UpdateCursor(SwCursorShell::SCROLLWIN); |
642 | 0 | } |
643 | 0 | break; |
644 | 0 | } |
645 | 0 | if (NID_POSTIT != s_nMoveType) |
646 | 0 | m_pEditWin->GrabFocus(); |
647 | 0 | } |
648 | | |
649 | | void SwView::CreateTab() |
650 | 0 | { |
651 | 0 | m_pHRuler->SetActive(GetFrame() && IsActive()); |
652 | |
|
653 | 0 | m_pHRuler->Show(); |
654 | 0 | InvalidateBorder(); |
655 | 0 | } |
656 | | |
657 | | void SwView::KillTab() |
658 | 122 | { |
659 | 122 | m_pHRuler->Hide(); |
660 | 122 | InvalidateBorder(); |
661 | 122 | } |
662 | | |
663 | | void SwView::ChangeTabMetric( FieldUnit eUnit ) |
664 | 0 | { |
665 | 0 | if(m_pHRuler->GetUnit() != eUnit ) |
666 | 0 | { |
667 | 0 | m_pHRuler->SetUnit( eUnit ); |
668 | 0 | m_pHRuler->Invalidate(); |
669 | 0 | } |
670 | 0 | } |
671 | | |
672 | | void SwView::ChangeVRulerMetric( FieldUnit eUnit ) |
673 | 0 | { |
674 | 0 | if(m_pVRuler->GetUnit() != eUnit) |
675 | 0 | { |
676 | 0 | m_pVRuler->SetUnit( eUnit ); |
677 | 0 | m_pVRuler->Invalidate(); |
678 | 0 | } |
679 | 0 | } |
680 | | |
681 | | void SwView::GetVRulerMetric(FieldUnit& eToFill) const |
682 | 0 | { |
683 | 0 | eToFill = m_pVRuler->GetUnit(); |
684 | 0 | } |
685 | | |
686 | | void SwView::GetHRulerMetric(FieldUnit& eToFill) const |
687 | 0 | { |
688 | 0 | eToFill = m_pHRuler->GetUnit(); |
689 | 0 | } |
690 | | |
691 | | void SwView::CreateVRuler() |
692 | 0 | { |
693 | 0 | m_pHRuler->SetBorderPos( m_pVRuler->GetSizePixel().Width()-1 ); |
694 | |
|
695 | 0 | m_pVRuler->SetActive(GetFrame() && IsActive()); |
696 | 0 | m_pVRuler->Show(); |
697 | 0 | InvalidateBorder(); |
698 | 0 | } |
699 | | |
700 | | void SwView::KillVRuler() |
701 | 122 | { |
702 | 122 | m_pVRuler->Hide(); |
703 | 122 | m_pHRuler->SetBorderPos(); |
704 | 122 | InvalidateBorder(); |
705 | 122 | } |
706 | | |
707 | | IMPL_LINK( SwView, ExecRulerClick, Ruler *, pRuler, void ) |
708 | 0 | { |
709 | 0 | OUString sDefPage; |
710 | 0 | TypedWhichId<SfxStringItem> nDefDlg = SID_PARA_DLG; |
711 | 0 | switch( pRuler->GetClickType() ) |
712 | 0 | { |
713 | 0 | case RulerType::DontKnow: |
714 | 0 | case RulerType::Outside: |
715 | 0 | sDefPage="borders"; |
716 | 0 | break; |
717 | 0 | case RulerType::Indent: |
718 | 0 | sDefPage="indents"; |
719 | 0 | break; |
720 | 0 | case RulerType::Margin1: |
721 | 0 | case RulerType::Margin2: |
722 | 0 | nDefDlg= FN_FORMAT_PAGE_DLG; |
723 | 0 | sDefPage = "page"; |
724 | 0 | break; |
725 | 0 | default: |
726 | 0 | sDefPage = "tabs"; |
727 | |
|
728 | 0 | } |
729 | | |
730 | 0 | SfxStringItem aDefPage(nDefDlg, sDefPage); |
731 | 0 | GetViewFrame().GetDispatcher()->ExecuteList(nDefDlg, |
732 | 0 | SfxCallMode::SYNCHRON|SfxCallMode::RECORD, |
733 | 0 | { &aDefPage }); |
734 | 0 | } |
735 | | |
736 | | sal_uInt16 SwView::GetMoveType() |
737 | 0 | { |
738 | 0 | return s_nMoveType; |
739 | 0 | } |
740 | | |
741 | | void SwView::SetMoveType(sal_uInt16 nSet) |
742 | 0 | { |
743 | 0 | s_nMoveType = nSet; |
744 | 0 | } |
745 | | |
746 | | void SwView::SetActMark(sal_Int32 nSet) |
747 | 0 | { |
748 | 0 | s_nActMark = nSet; |
749 | 0 | } |
750 | | |
751 | | void SwView::ShowHScrollbar(bool bShow) |
752 | 0 | { |
753 | 0 | assert(m_pHScrollbar && "Scrollbar invalid"); |
754 | 0 | m_pHScrollbar->ExtendedShow(bShow); |
755 | 0 | } |
756 | | |
757 | | bool SwView::IsHScrollbarVisible()const |
758 | 0 | { |
759 | 0 | assert(m_pHScrollbar && "Scrollbar invalid"); |
760 | 0 | return m_pHScrollbar->IsScrollbarVisible(false) || m_pHScrollbar->IsAuto(); |
761 | 0 | } |
762 | | |
763 | | void SwView::ShowVScrollbar(bool bShow) |
764 | 0 | { |
765 | 0 | assert(m_pVScrollbar && "Scrollbar invalid"); |
766 | 0 | m_pVScrollbar->ExtendedShow(bShow); |
767 | 0 | } |
768 | | |
769 | | bool SwView::IsVScrollbarVisible()const |
770 | 0 | { |
771 | 0 | assert(m_pVScrollbar && "Scrollbar invalid"); |
772 | 0 | return m_pVScrollbar->IsScrollbarVisible(false); |
773 | 0 | } |
774 | | |
775 | | void SwView::EnableHScrollbar(bool bEnable) |
776 | 0 | { |
777 | 0 | if (m_bHScrollbarEnabled != bEnable) |
778 | 0 | { |
779 | 0 | m_bHScrollbarEnabled = bEnable; |
780 | 0 | InvalidateBorder(); |
781 | 0 | } |
782 | 0 | } |
783 | | |
784 | | void SwView::EnableVScrollbar(bool bEnable) |
785 | 0 | { |
786 | 0 | if (m_bVScrollbarEnabled != bEnable) |
787 | 0 | { |
788 | 0 | m_bVScrollbarEnabled = bEnable; |
789 | 0 | InvalidateBorder(); |
790 | 0 | } |
791 | 0 | } |
792 | | |
793 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |