Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / txtcrsr.cxx
blob6dc161cb1e58cea216b178cb8d6d936b0528c0f9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <memory>
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>
30 #include <view.hxx>
31 #include <wrtsh.hxx>
32 #include <textsh.hxx>
33 #include <edtwin.hxx>
34 #include <doc.hxx>
35 #include <docsh.hxx>
37 #include <cmdid.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();
51 bool bSelect = false;
52 sal_Int32 nCount = 1;
53 if(pArgs)
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 );
64 bSelect = true;
65 break;
66 case FN_CHAR_RIGHT_SEL:
67 rReq.SetSlot( FN_CHAR_RIGHT );
68 bSelect = true;
69 break;
70 case FN_LINE_UP_SEL:
71 rReq.SetSlot( FN_LINE_UP );
72 bSelect = true;
73 break;
74 case FN_LINE_DOWN_SEL:
75 rReq.SetSlot( FN_LINE_DOWN );
76 bSelect = true;
77 break;
80 uno::Reference< frame::XDispatchRecorder > xRecorder =
81 GetView().GetViewFrame().GetBindings().GetRecorder();
82 if ( xRecorder.is() )
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();
88 rReq.Done();
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++ )
93 switch(nSlot)
95 case FN_CHAR_LEFT:
96 rSh.Left( SwCursorSkipMode::Cells, bSelect, 1, false, true );
97 break;
98 case FN_CHAR_RIGHT:
99 rSh.Right( SwCursorSkipMode::Cells, bSelect, 1, false, true );
100 break;
101 case FN_LINE_UP:
102 rSh.Up( bSelect );
103 break;
104 case FN_LINE_DOWN:
105 rSh.Down( bSelect );
106 break;
107 default:
108 OSL_FAIL("wrong Dispatcher");
109 return;
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();
124 bool bRet = false;
125 switch ( rReq.GetSlot() )
127 case FN_START_OF_LINE_SEL:
128 bRet = rSh.LeftMargin( true, false );
129 break;
130 case FN_START_OF_LINE:
131 bRet = rSh.LeftMargin( false, false );
132 break;
133 case FN_END_OF_LINE_SEL:
134 bRet = rSh.RightMargin( true, false );
135 break;
136 case FN_END_OF_LINE:
137 bRet = rSh.RightMargin( false, false );
138 break;
139 case FN_START_OF_DOCUMENT_SEL:
140 bRet = rSh.StartOfSection( true );
141 break;
142 case FN_START_OF_DOCUMENT:
143 bRet = rSh.StartOfSection();
144 break;
145 case FN_END_OF_DOCUMENT_SEL:
146 bRet = rSh.EndOfSection( true );
147 break;
148 case FN_END_OF_DOCUMENT:
149 bRet = rSh.EndOfSection();
150 break;
151 case FN_SELECT_WORD:
152 bRet = rSh.SelNearestWrd();
153 break;
154 case FN_SELECT_SENTENCE:
155 rSh.SelSentence( nullptr );
156 bRet = true;
157 break;
158 case SID_SELECTALL:
159 rSh.SelAll();
160 bRet = true;
161 break;
162 default:
163 OSL_FAIL("wrong dispatcher");
164 return;
167 if ( bRet )
168 rReq.Done();
169 else
170 rReq.Ignore();
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 );
186 break;
187 case FN_START_OF_NEXT_PAGE:
188 rSh.SttNxtPg();
189 break;
190 case FN_END_OF_NEXT_PAGE_SEL:
191 rSh.EndNxtPg( true );
192 break;
193 case FN_END_OF_NEXT_PAGE:
194 rSh.EndNxtPg();
195 break;
196 case FN_START_OF_PREV_PAGE_SEL:
197 rSh.SttPrvPg( true );
198 break;
199 case FN_START_OF_PREV_PAGE:
200 rSh.SttPrvPg();
201 break;
202 case FN_END_OF_PREV_PAGE_SEL:
203 rSh.EndPrvPg( true );
204 break;
205 case FN_END_OF_PREV_PAGE:
206 rSh.EndPrvPg();
207 break;
208 case FN_START_OF_PAGE_SEL:
209 rSh.SttPg( true );
210 break;
211 case FN_START_OF_PAGE:
212 rSh.SttPg();
213 break;
214 case FN_END_OF_PAGE_SEL:
215 rSh.EndPg( true );
216 break;
217 case FN_END_OF_PAGE:
218 rSh.EndPg();
219 break;
220 default:
221 OSL_FAIL("wrong dispatcher");
222 return;
224 rReq.Done();
227 void SwTextShell::ExecMoveCol(SfxRequest &rReq)
229 SwWrtShell &rSh = GetShell();
230 rSh.addCurrentPosition();
231 switch ( rReq.GetSlot() )
233 case FN_START_OF_COLUMN:
234 rSh.StartOfColumn();
235 break;
236 case FN_END_OF_COLUMN:
237 rSh.EndOfColumn();
238 break;
239 case FN_START_OF_NEXT_COLUMN:
240 rSh.StartOfNextColumn() ;
241 break;
242 case FN_END_OF_NEXT_COLUMN:
243 rSh.EndOfNextColumn();
244 break;
245 case FN_START_OF_PREV_COLUMN:
246 rSh.StartOfPrevColumn();
247 break;
248 case FN_END_OF_PREV_COLUMN:
249 rSh.EndOfPrevColumn();
250 break;
251 default:
252 OSL_FAIL("wrong dispatcher");
253 return;
255 rReq.Done();
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:
267 rSh.NxtWrd( true );
268 break;
269 case FN_NEXT_WORD:
270 rSh.NxtWrd();
271 break;
272 case FN_START_OF_PARA_SEL:
273 rSh.SttPara( true );
274 break;
275 case FN_START_OF_PARA:
276 rSh.SttPara();
277 break;
278 case FN_END_OF_PARA_SEL:
279 rSh.EndPara( true );
280 break;
281 case FN_END_OF_PARA:
282 rSh.EndPara();
283 break;
284 case FN_PREV_WORD_SEL:
285 rSh.PrvWrd( true );
286 break;
287 case FN_PREV_WORD:
288 rSh.PrvWrd();
289 break;
290 case FN_NEXT_SENT_SEL:
291 rSh.FwdSentence( true );
292 break;
293 case FN_NEXT_SENT:
294 rSh.FwdSentence();
295 break;
296 case FN_PREV_SENT_SEL:
297 rSh.BwdSentence( true );
298 break;
299 case FN_PREV_SENT:
300 rSh.BwdSentence();
301 break;
302 case FN_NEXT_PARA:
303 rSh.FwdPara();
304 break;
305 case FN_PREV_PARA:
306 rSh.BwdPara();
307 break;
308 default:
309 OSL_FAIL("wrong dispatcher");
310 return;
312 rReq.Done();
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;
321 switch ( nSlot )
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 )
334 break;
336 std::unique_ptr< svx::ISdrObjectFilter > pFilter( FmFormShell::CreateFocusableControlFilter(
337 *pDrawView, *pWindow->GetOutDev() ) );
338 if (!pFilter)
339 break;
341 const SdrObject* pNearestControl = rSh.GetBestObject( true, GotoObjFlags::DrawControl, false, pFilter.get() );
342 if ( !pNearestControl )
343 break;
345 const SdrUnoObj* pUnoObject = dynamic_cast< const SdrUnoObj* >( pNearestControl );
346 OSL_ENSURE( pUnoObject, "SwTextShell::ExecMoveMisc: GetBestObject returned nonsense!" );
347 if ( !pUnoObject )
348 break;
350 pFormShell->ToggleControlFocus( *pUnoObject, *pDrawView, *pWindow->GetOutDev() );
352 break;
353 case FN_CNTNT_TO_NEXT_FRAME:
354 bRet = rSh.GotoObj(true, GotoObjFlags::Any);
355 if(bRet)
357 rSh.HideCursor();
358 rSh.EnterSelFrameMode();
360 break;
361 case FN_NEXT_FOOTNOTE:
362 rSh.MoveCursor();
363 bRet = rSh.GotoNextFootnoteAnchor();
364 break;
365 case FN_PREV_FOOTNOTE:
366 rSh.MoveCursor();
367 bRet = rSh.GotoPrevFootnoteAnchor();
368 break;
369 case FN_TO_HEADER:
370 rSh.MoveCursor();
371 if ( FrameTypeFlags::HEADER & rSh.GetFrameType(nullptr,false) )
372 rSh.SttPg();
373 else
375 bool bMoved = rSh.GotoHeaderText();
376 if ( !bMoved )
377 rSh.SttPg();
379 bSetRetVal = false;
380 break;
381 case FN_TO_FOOTER:
382 rSh.MoveCursor();
383 if ( FrameTypeFlags::FOOTER & rSh.GetFrameType(nullptr,false) )
384 rSh.EndPg();
385 else
387 bool bMoved = rSh.GotoFooterText();
388 if ( !bMoved )
389 rSh.EndPg();
391 bSetRetVal = false;
392 break;
393 case FN_FOOTNOTE_TO_ANCHOR:
394 rSh.MoveCursor();
395 if ( FrameTypeFlags::FOOTNOTE & rSh.GetFrameType(nullptr,false) )
396 rSh.GotoFootnoteAnchor();
397 else
398 rSh.GotoFootnoteText();
399 bSetRetVal = false;
400 break;
401 case FN_TO_FOOTNOTE_AREA :
402 rSh.GotoFootnoteText();
403 break;
404 case FN_PREV_TABLE:
405 bRet = rSh.MoveTable( GotoPrevTable, fnTableStart);
406 break;
407 case FN_NEXT_TABLE:
408 bRet = rSh.MoveTable(GotoNextTable, fnTableStart);
409 break;
410 case FN_GOTO_NEXT_REGION :
411 bRet = rSh.MoveRegion(GotoNextRegion, fnRegionStart);
412 break;
413 case FN_GOTO_PREV_REGION :
414 bRet = rSh.MoveRegion(GotoPrevRegion, fnRegionStart);
415 break;
416 case FN_NEXT_TOXMARK:
417 bRet = rSh.GotoNxtPrvTOXMark();
418 break;
419 case FN_PREV_TOXMARK:
420 bRet = rSh.GotoNxtPrvTOXMark( false );
421 break;
422 case FN_NEXT_TBLFML:
423 bRet = rSh.GotoNxtPrvTableFormula();
424 break;
425 case FN_PREV_TBLFML:
426 bRet = rSh.GotoNxtPrvTableFormula( false );
427 break;
428 case FN_NEXT_TBLFML_ERR:
429 bRet = rSh.GotoNxtPrvTableFormula( true, true );
430 break;
431 case FN_PREV_TBLFML_ERR:
432 bRet = rSh.GotoNxtPrvTableFormula( false, true );
433 break;
434 default:
435 OSL_FAIL("wrong dispatcher");
436 return;
439 if( bSetRetVal )
440 rReq.SetReturnValue(SfxBoolItem( nSlot, bRet ));
441 rReq.Done();
443 bool bInHeader = true;
444 if ( rSh.IsInHeaderFooter( &bInHeader ) )
446 if ( !bInHeader )
448 rSh.SetShowHeaderFooterSeparator( FrameControlType::Footer, true );
449 rSh.SetShowHeaderFooterSeparator( FrameControlType::Header, false );
451 else
453 rSh.SetShowHeaderFooterSeparator( FrameControlType::Header, true );
454 rSh.SetShowHeaderFooterSeparator( FrameControlType::Footer, false );
457 // Force repaint
458 rSh.GetWin()->Invalidate();
460 if ( rSh.IsInHeaderFooter() != rSh.IsHeaderFooterEdit() )
461 rSh.ToggleHeaderFooterEdit();
464 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */