1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
24 #include <sfx2/request.hxx>
25 #include <svl/eitem.hxx>
26 #include <sfx2/viewfrm.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <osl/diagnose.h>
38 #include <globals.hrc>
40 #include <svx/svdouno.hxx>
41 #include <svx/fmshell.hxx>
42 #include <svx/sdrobjectfilter.hxx>
44 using namespace ::com::sun::star
;
46 void SwTextShell::ExecBasicMove(SfxRequest
&rReq
)
48 SwWrtShell
&rSh
= GetShell();
49 GetView().GetEditWin().FlushInBuffer();
50 const SfxItemSet
*pArgs
= rReq
.GetArgs();
55 if(const SfxInt32Item
* pCountItem
= pArgs
->GetItemIfSet(FN_PARAM_MOVE_COUNT
))
56 nCount
= pCountItem
->GetValue();
57 if(const SfxBoolItem
* pSelectionItem
= pArgs
->GetItemIfSet(FN_PARAM_MOVE_SELECTION
))
58 bSelect
= pSelectionItem
->GetValue();
60 switch(rReq
.GetSlot())
62 case FN_CHAR_LEFT_SEL
:
63 rReq
.SetSlot( FN_CHAR_LEFT
);
66 case FN_CHAR_RIGHT_SEL
:
67 rReq
.SetSlot( FN_CHAR_RIGHT
);
71 rReq
.SetSlot( FN_LINE_UP
);
74 case FN_LINE_DOWN_SEL
:
75 rReq
.SetSlot( FN_LINE_DOWN
);
80 uno::Reference
< frame::XDispatchRecorder
> xRecorder
=
81 GetView().GetViewFrame().GetBindings().GetRecorder();
84 rReq
.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT
, nCount
) );
85 rReq
.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION
, bSelect
) );
87 const sal_uInt16 nSlot
= rReq
.GetSlot();
89 // Get EditWin before calling the move functions (shell change may occur!)
90 SwEditWin
& rTmpEditWin
= GetView().GetEditWin();
91 for( sal_Int32 i
= 0; i
< nCount
; i
++ )
96 rSh
.Left( SwCursorSkipMode::Cells
, bSelect
, 1, false, true );
99 rSh
.Right( SwCursorSkipMode::Cells
, bSelect
, 1, false, true );
108 OSL_FAIL("wrong Dispatcher");
113 //#i42732# - notify the edit window that from now on we do not use the input language
114 rTmpEditWin
.SetUseInputLanguage( false );
117 void SwTextShell::ExecMove(SfxRequest
&rReq
)
119 SwWrtShell
&rSh
= GetShell();
120 rSh
.addCurrentPosition();
121 SwEditWin
& rTmpEditWin
= GetView().GetEditWin();
122 rTmpEditWin
.FlushInBuffer();
125 switch ( rReq
.GetSlot() )
127 case FN_START_OF_LINE_SEL
:
128 bRet
= rSh
.LeftMargin( true, false );
130 case FN_START_OF_LINE
:
131 bRet
= rSh
.LeftMargin( false, false );
133 case FN_END_OF_LINE_SEL
:
134 bRet
= rSh
.RightMargin( true, false );
137 bRet
= rSh
.RightMargin( false, false );
139 case FN_START_OF_DOCUMENT_SEL
:
140 bRet
= rSh
.StartOfSection( true );
142 case FN_START_OF_DOCUMENT
:
143 bRet
= rSh
.StartOfSection();
145 case FN_END_OF_DOCUMENT_SEL
:
146 bRet
= rSh
.EndOfSection( true );
148 case FN_END_OF_DOCUMENT
:
149 bRet
= rSh
.EndOfSection();
152 bRet
= rSh
.SelNearestWrd();
154 case FN_SELECT_SENTENCE
:
155 rSh
.SelSentence( nullptr );
163 OSL_FAIL("wrong dispatcher");
172 //#i42732# - notify the edit window that from now on we do not use the input language
173 rTmpEditWin
.SetUseInputLanguage( false );
176 void SwTextShell::ExecMovePage(SfxRequest
&rReq
)
178 SwWrtShell
&rSh
= GetShell();
179 rSh
.addCurrentPosition();
180 GetView().GetEditWin().FlushInBuffer();
182 switch( rReq
.GetSlot() )
184 case FN_START_OF_NEXT_PAGE_SEL
:
185 rSh
.SttNxtPg( true );
187 case FN_START_OF_NEXT_PAGE
:
190 case FN_END_OF_NEXT_PAGE_SEL
:
191 rSh
.EndNxtPg( true );
193 case FN_END_OF_NEXT_PAGE
:
196 case FN_START_OF_PREV_PAGE_SEL
:
197 rSh
.SttPrvPg( true );
199 case FN_START_OF_PREV_PAGE
:
202 case FN_END_OF_PREV_PAGE_SEL
:
203 rSh
.EndPrvPg( true );
205 case FN_END_OF_PREV_PAGE
:
208 case FN_START_OF_PAGE_SEL
:
211 case FN_START_OF_PAGE
:
214 case FN_END_OF_PAGE_SEL
:
221 OSL_FAIL("wrong dispatcher");
227 void SwTextShell::ExecMoveCol(SfxRequest
&rReq
)
229 SwWrtShell
&rSh
= GetShell();
230 rSh
.addCurrentPosition();
231 switch ( rReq
.GetSlot() )
233 case FN_START_OF_COLUMN
:
236 case FN_END_OF_COLUMN
:
239 case FN_START_OF_NEXT_COLUMN
:
240 rSh
.StartOfNextColumn() ;
242 case FN_END_OF_NEXT_COLUMN
:
243 rSh
.EndOfNextColumn();
245 case FN_START_OF_PREV_COLUMN
:
246 rSh
.StartOfPrevColumn();
248 case FN_END_OF_PREV_COLUMN
:
249 rSh
.EndOfPrevColumn();
252 OSL_FAIL("wrong dispatcher");
258 void SwTextShell::ExecMoveLingu(SfxRequest
&rReq
)
260 SwWrtShell
&rSh
= GetShell();
261 rSh
.addCurrentPosition();
262 GetView().GetEditWin().FlushInBuffer();
264 switch ( rReq
.GetSlot() )
266 case FN_NEXT_WORD_SEL
:
272 case FN_START_OF_PARA_SEL
:
275 case FN_START_OF_PARA
:
278 case FN_END_OF_PARA_SEL
:
284 case FN_PREV_WORD_SEL
:
290 case FN_NEXT_SENT_SEL
:
291 rSh
.FwdSentence( true );
296 case FN_PREV_SENT_SEL
:
297 rSh
.BwdSentence( true );
309 OSL_FAIL("wrong dispatcher");
315 void SwTextShell::ExecMoveMisc(SfxRequest
&rReq
)
317 SwWrtShell
&rSh
= GetShell();
318 rSh
.addCurrentPosition();
319 const sal_uInt16 nSlot
= rReq
.GetSlot();
320 bool bSetRetVal
= true, bRet
= true;
323 case SID_FM_TOGGLECONTROLFOCUS
:
325 const SwDoc
* pDoc
= rSh
.GetDoc();
326 const SwDocShell
* pDocShell
= pDoc
? pDoc
->GetDocShell() : nullptr;
327 const SwView
* pView
= pDocShell
? pDocShell
->GetView() : nullptr;
328 const FmFormShell
* pFormShell
= pView
? pView
->GetFormShell() : nullptr;
329 SdrView
* pDrawView
= pView
? pView
->GetDrawView() : nullptr;
330 vcl::Window
* pWindow
= pView
? pView
->GetWrtShell().GetWin() : nullptr;
332 OSL_ENSURE( pFormShell
&& pDrawView
&& pWindow
, "SwXTextView::ExecMoveMisc: no chance!" );
333 if ( !pFormShell
|| !pDrawView
|| !pWindow
)
336 std::unique_ptr
< svx::ISdrObjectFilter
> pFilter( FmFormShell::CreateFocusableControlFilter(
337 *pDrawView
, *pWindow
->GetOutDev() ) );
341 const SdrObject
* pNearestControl
= rSh
.GetBestObject( true, GotoObjFlags::DrawControl
, false, pFilter
.get() );
342 if ( !pNearestControl
)
345 const SdrUnoObj
* pUnoObject
= dynamic_cast< const SdrUnoObj
* >( pNearestControl
);
346 OSL_ENSURE( pUnoObject
, "SwTextShell::ExecMoveMisc: GetBestObject returned nonsense!" );
350 pFormShell
->ToggleControlFocus( *pUnoObject
, *pDrawView
, *pWindow
->GetOutDev() );
353 case FN_CNTNT_TO_NEXT_FRAME
:
354 bRet
= rSh
.GotoObj(true, GotoObjFlags::Any
);
358 rSh
.EnterSelFrameMode();
361 case FN_NEXT_FOOTNOTE
:
363 bRet
= rSh
.GotoNextFootnoteAnchor();
365 case FN_PREV_FOOTNOTE
:
367 bRet
= rSh
.GotoPrevFootnoteAnchor();
371 if ( FrameTypeFlags::HEADER
& rSh
.GetFrameType(nullptr,false) )
375 bool bMoved
= rSh
.GotoHeaderText();
383 if ( FrameTypeFlags::FOOTER
& rSh
.GetFrameType(nullptr,false) )
387 bool bMoved
= rSh
.GotoFooterText();
393 case FN_FOOTNOTE_TO_ANCHOR
:
395 if ( FrameTypeFlags::FOOTNOTE
& rSh
.GetFrameType(nullptr,false) )
396 rSh
.GotoFootnoteAnchor();
398 rSh
.GotoFootnoteText();
401 case FN_TO_FOOTNOTE_AREA
:
402 rSh
.GotoFootnoteText();
405 bRet
= rSh
.MoveTable( GotoPrevTable
, fnTableStart
);
408 bRet
= rSh
.MoveTable(GotoNextTable
, fnTableStart
);
410 case FN_GOTO_NEXT_REGION
:
411 bRet
= rSh
.MoveRegion(GotoNextRegion
, fnRegionStart
);
413 case FN_GOTO_PREV_REGION
:
414 bRet
= rSh
.MoveRegion(GotoPrevRegion
, fnRegionStart
);
416 case FN_NEXT_TOXMARK
:
417 bRet
= rSh
.GotoNxtPrvTOXMark();
419 case FN_PREV_TOXMARK
:
420 bRet
= rSh
.GotoNxtPrvTOXMark( false );
423 bRet
= rSh
.GotoNxtPrvTableFormula();
426 bRet
= rSh
.GotoNxtPrvTableFormula( false );
428 case FN_NEXT_TBLFML_ERR
:
429 bRet
= rSh
.GotoNxtPrvTableFormula( true, true );
431 case FN_PREV_TBLFML_ERR
:
432 bRet
= rSh
.GotoNxtPrvTableFormula( false, true );
435 OSL_FAIL("wrong dispatcher");
440 rReq
.SetReturnValue(SfxBoolItem( nSlot
, bRet
));
443 bool bInHeader
= true;
444 if ( rSh
.IsInHeaderFooter( &bInHeader
) )
448 rSh
.SetShowHeaderFooterSeparator( FrameControlType::Footer
, true );
449 rSh
.SetShowHeaderFooterSeparator( FrameControlType::Header
, false );
453 rSh
.SetShowHeaderFooterSeparator( FrameControlType::Header
, true );
454 rSh
.SetShowHeaderFooterSeparator( FrameControlType::Footer
, false );
458 rSh
.GetWin()->Invalidate();
460 if ( rSh
.IsInHeaderFooter() != rSh
.IsHeaderFooterEdit() )
461 rSh
.ToggleHeaderFooterEdit();
464 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */