/src/libreoffice/sw/source/uibase/shells/txtcrsr.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 <sal/config.h> |
21 | | |
22 | | #include <memory> |
23 | | |
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> |
29 | | |
30 | | #include <view.hxx> |
31 | | #include <wrtsh.hxx> |
32 | | #include <textsh.hxx> |
33 | | #include <edtwin.hxx> |
34 | | #include <doc.hxx> |
35 | | #include <docsh.hxx> |
36 | | |
37 | | #include <cmdid.h> |
38 | | #include <globals.hrc> |
39 | | |
40 | | #include <svx/svdouno.hxx> |
41 | | #include <svx/fmshell.hxx> |
42 | | #include <svx/sdrobjectfilter.hxx> |
43 | | |
44 | | using namespace ::com::sun::star; |
45 | | |
46 | | void SwTextShell::ExecBasicMove(SfxRequest &rReq) |
47 | 0 | { |
48 | 0 | SwWrtShell &rSh = GetShell(); |
49 | 0 | GetView().GetEditWin().FlushInBuffer(); |
50 | 0 | const SfxItemSet *pArgs = rReq.GetArgs(); |
51 | 0 | bool bSelect = false; |
52 | 0 | sal_Int32 nCount = 1; |
53 | 0 | if(pArgs) |
54 | 0 | { |
55 | 0 | if(const SfxInt32Item* pCountItem = pArgs->GetItemIfSet(FN_PARAM_MOVE_COUNT)) |
56 | 0 | nCount = pCountItem->GetValue(); |
57 | 0 | if(const SfxBoolItem* pSelectionItem = pArgs->GetItemIfSet(FN_PARAM_MOVE_SELECTION)) |
58 | 0 | bSelect = pSelectionItem->GetValue(); |
59 | 0 | } |
60 | 0 | switch(rReq.GetSlot()) |
61 | 0 | { |
62 | 0 | case FN_CHAR_LEFT_SEL: |
63 | 0 | rReq.SetSlot( FN_CHAR_LEFT ); |
64 | 0 | bSelect = true; |
65 | 0 | break; |
66 | 0 | case FN_CHAR_RIGHT_SEL: |
67 | 0 | rReq.SetSlot( FN_CHAR_RIGHT ); |
68 | 0 | bSelect = true; |
69 | 0 | break; |
70 | 0 | case FN_LINE_UP_SEL: |
71 | 0 | rReq.SetSlot( FN_LINE_UP ); |
72 | 0 | bSelect = true; |
73 | 0 | break; |
74 | 0 | case FN_LINE_DOWN_SEL: |
75 | 0 | rReq.SetSlot( FN_LINE_DOWN ); |
76 | 0 | bSelect = true; |
77 | 0 | break; |
78 | 0 | } |
79 | | |
80 | 0 | uno::Reference< frame::XDispatchRecorder > xRecorder = |
81 | 0 | GetView().GetViewFrame().GetBindings().GetRecorder(); |
82 | 0 | if ( xRecorder.is() ) |
83 | 0 | { |
84 | 0 | rReq.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT, nCount) ); |
85 | 0 | rReq.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, bSelect) ); |
86 | 0 | } |
87 | 0 | const sal_uInt16 nSlot = rReq.GetSlot(); |
88 | 0 | rReq.Done(); |
89 | | // Get EditWin before calling the move functions (shell change may occur!) |
90 | 0 | SwEditWin& rTmpEditWin = GetView().GetEditWin(); |
91 | 0 | for( sal_Int32 i = 0; i < nCount; i++ ) |
92 | 0 | { |
93 | 0 | switch(nSlot) |
94 | 0 | { |
95 | 0 | case FN_CHAR_LEFT: |
96 | 0 | rSh.Left( SwCursorSkipMode::Cells, bSelect, 1, false, true ); |
97 | 0 | break; |
98 | 0 | case FN_CHAR_RIGHT: |
99 | 0 | rSh.Right( SwCursorSkipMode::Cells, bSelect, 1, false, true ); |
100 | 0 | break; |
101 | 0 | case FN_LINE_UP: |
102 | 0 | rSh.Up( bSelect ); |
103 | 0 | break; |
104 | 0 | case FN_LINE_DOWN: |
105 | 0 | rSh.Down( bSelect ); |
106 | 0 | break; |
107 | 0 | default: |
108 | 0 | OSL_FAIL("wrong Dispatcher"); |
109 | 0 | return; |
110 | 0 | } |
111 | 0 | } |
112 | | |
113 | | //#i42732# - notify the edit window that from now on we do not use the input language |
114 | 0 | rTmpEditWin.SetUseInputLanguage( false ); |
115 | 0 | } |
116 | | |
117 | | void SwTextShell::ExecMove(SfxRequest &rReq) |
118 | 0 | { |
119 | 0 | SwWrtShell &rSh = GetShell(); |
120 | 0 | rSh.addCurrentPosition(); |
121 | 0 | SwEditWin& rTmpEditWin = GetView().GetEditWin(); |
122 | 0 | rTmpEditWin.FlushInBuffer(); |
123 | |
|
124 | 0 | bool bRet = false; |
125 | 0 | switch ( rReq.GetSlot() ) |
126 | 0 | { |
127 | 0 | case FN_START_OF_LINE_SEL: |
128 | 0 | bRet = rSh.LeftMargin( true, false ); |
129 | 0 | break; |
130 | 0 | case FN_START_OF_LINE: |
131 | 0 | bRet = rSh.LeftMargin( false, false ); |
132 | 0 | break; |
133 | 0 | case FN_END_OF_LINE_SEL: |
134 | 0 | bRet = rSh.RightMargin( true, false ); |
135 | 0 | break; |
136 | 0 | case FN_END_OF_LINE: |
137 | 0 | bRet = rSh.RightMargin( false, false ); |
138 | 0 | break; |
139 | 0 | case FN_START_OF_DOCUMENT_SEL: |
140 | 0 | bRet = rSh.StartOfSection( true ); |
141 | 0 | break; |
142 | 0 | case FN_START_OF_DOCUMENT: |
143 | 0 | bRet = rSh.StartOfSection(); |
144 | 0 | break; |
145 | 0 | case FN_END_OF_DOCUMENT_SEL: |
146 | 0 | bRet = rSh.EndOfSection( true ); |
147 | 0 | break; |
148 | 0 | case FN_END_OF_DOCUMENT: |
149 | 0 | bRet = rSh.EndOfSection(); |
150 | 0 | break; |
151 | 0 | case FN_SELECT_WORD: |
152 | 0 | bRet = rSh.SelNearestWrd(); |
153 | 0 | break; |
154 | 0 | case FN_SELECT_SENTENCE: |
155 | 0 | rSh.SelSentence( nullptr ); |
156 | 0 | bRet = true; |
157 | 0 | break; |
158 | 0 | case SID_SELECTALL: |
159 | 0 | rSh.SelAll(); |
160 | 0 | bRet = true; |
161 | 0 | break; |
162 | 0 | default: |
163 | 0 | OSL_FAIL("wrong dispatcher"); |
164 | 0 | return; |
165 | 0 | } |
166 | | |
167 | 0 | if ( bRet ) |
168 | 0 | rReq.Done(); |
169 | 0 | else |
170 | 0 | rReq.Ignore(); |
171 | | |
172 | | //#i42732# - notify the edit window that from now on we do not use the input language |
173 | 0 | rTmpEditWin.SetUseInputLanguage( false ); |
174 | 0 | } |
175 | | |
176 | | void SwTextShell::ExecMovePage(SfxRequest &rReq) |
177 | 0 | { |
178 | 0 | SwWrtShell &rSh = GetShell(); |
179 | 0 | rSh.addCurrentPosition(); |
180 | 0 | GetView().GetEditWin().FlushInBuffer(); |
181 | |
|
182 | 0 | switch( rReq.GetSlot() ) |
183 | 0 | { |
184 | 0 | case FN_START_OF_NEXT_PAGE_SEL : |
185 | 0 | rSh.SttNxtPg( true ); |
186 | 0 | break; |
187 | 0 | case FN_START_OF_NEXT_PAGE: |
188 | 0 | rSh.SttNxtPg(); |
189 | 0 | break; |
190 | 0 | case FN_END_OF_NEXT_PAGE_SEL: |
191 | 0 | rSh.EndNxtPg( true ); |
192 | 0 | break; |
193 | 0 | case FN_END_OF_NEXT_PAGE: |
194 | 0 | rSh.EndNxtPg(); |
195 | 0 | break; |
196 | 0 | case FN_START_OF_PREV_PAGE_SEL: |
197 | 0 | rSh.SttPrvPg( true ); |
198 | 0 | break; |
199 | 0 | case FN_START_OF_PREV_PAGE: |
200 | 0 | rSh.SttPrvPg(); |
201 | 0 | break; |
202 | 0 | case FN_END_OF_PREV_PAGE_SEL: |
203 | 0 | rSh.EndPrvPg( true ); |
204 | 0 | break; |
205 | 0 | case FN_END_OF_PREV_PAGE: |
206 | 0 | rSh.EndPrvPg(); |
207 | 0 | break; |
208 | 0 | case FN_START_OF_PAGE_SEL: |
209 | 0 | rSh.SttPg( true ); |
210 | 0 | break; |
211 | 0 | case FN_START_OF_PAGE: |
212 | 0 | rSh.SttPg(); |
213 | 0 | break; |
214 | 0 | case FN_END_OF_PAGE_SEL: |
215 | 0 | rSh.EndPg( true ); |
216 | 0 | break; |
217 | 0 | case FN_END_OF_PAGE: |
218 | 0 | rSh.EndPg(); |
219 | 0 | break; |
220 | 0 | default: |
221 | 0 | OSL_FAIL("wrong dispatcher"); |
222 | 0 | return; |
223 | 0 | } |
224 | 0 | rReq.Done(); |
225 | 0 | } |
226 | | |
227 | | void SwTextShell::ExecMoveCol(SfxRequest &rReq) |
228 | 0 | { |
229 | 0 | SwWrtShell &rSh = GetShell(); |
230 | 0 | rSh.addCurrentPosition(); |
231 | 0 | switch ( rReq.GetSlot() ) |
232 | 0 | { |
233 | 0 | case FN_START_OF_COLUMN: |
234 | 0 | rSh.StartOfColumn(); |
235 | 0 | break; |
236 | 0 | case FN_END_OF_COLUMN: |
237 | 0 | rSh.EndOfColumn(); |
238 | 0 | break; |
239 | 0 | case FN_START_OF_NEXT_COLUMN: |
240 | 0 | rSh.StartOfNextColumn() ; |
241 | 0 | break; |
242 | 0 | case FN_END_OF_NEXT_COLUMN: |
243 | 0 | rSh.EndOfNextColumn(); |
244 | 0 | break; |
245 | 0 | case FN_START_OF_PREV_COLUMN: |
246 | 0 | rSh.StartOfPrevColumn(); |
247 | 0 | break; |
248 | 0 | case FN_END_OF_PREV_COLUMN: |
249 | 0 | rSh.EndOfPrevColumn(); |
250 | 0 | break; |
251 | 0 | default: |
252 | 0 | OSL_FAIL("wrong dispatcher"); |
253 | 0 | return; |
254 | 0 | } |
255 | 0 | rReq.Done(); |
256 | 0 | } |
257 | | |
258 | | void SwTextShell::ExecMoveLingu(SfxRequest &rReq) |
259 | 0 | { |
260 | 0 | SwWrtShell &rSh = GetShell(); |
261 | 0 | rSh.addCurrentPosition(); |
262 | 0 | GetView().GetEditWin().FlushInBuffer(); |
263 | |
|
264 | 0 | switch ( rReq.GetSlot() ) |
265 | 0 | { |
266 | 0 | case FN_NEXT_WORD_SEL: |
267 | 0 | rSh.NxtWrd( true ); |
268 | 0 | break; |
269 | 0 | case FN_NEXT_WORD: |
270 | 0 | rSh.NxtWrd(); |
271 | 0 | break; |
272 | 0 | case FN_START_OF_PARA_SEL: |
273 | 0 | rSh.SttPara( true ); |
274 | 0 | break; |
275 | 0 | case FN_START_OF_PARA: |
276 | 0 | rSh.SttPara(); |
277 | 0 | break; |
278 | 0 | case FN_END_OF_PARA_SEL: |
279 | 0 | rSh.EndPara( true ); |
280 | 0 | break; |
281 | 0 | case FN_END_OF_PARA: |
282 | 0 | rSh.EndPara(); |
283 | 0 | break; |
284 | 0 | case FN_PREV_WORD_SEL: |
285 | 0 | rSh.PrvWrd( true ); |
286 | 0 | break; |
287 | 0 | case FN_PREV_WORD: |
288 | 0 | rSh.PrvWrd(); |
289 | 0 | break; |
290 | 0 | case FN_NEXT_SENT_SEL: |
291 | 0 | rSh.FwdSentence( true ); |
292 | 0 | break; |
293 | 0 | case FN_NEXT_SENT: |
294 | 0 | rSh.FwdSentence(); |
295 | 0 | break; |
296 | 0 | case FN_PREV_SENT_SEL: |
297 | 0 | rSh.BwdSentence( true ); |
298 | 0 | break; |
299 | 0 | case FN_PREV_SENT: |
300 | 0 | rSh.BwdSentence(); |
301 | 0 | break; |
302 | 0 | case FN_NEXT_PARA: |
303 | 0 | rSh.FwdPara(); |
304 | 0 | break; |
305 | 0 | case FN_PREV_PARA: |
306 | 0 | rSh.BwdPara(); |
307 | 0 | break; |
308 | 0 | default: |
309 | 0 | OSL_FAIL("wrong dispatcher"); |
310 | 0 | return; |
311 | 0 | } |
312 | 0 | rReq.Done(); |
313 | 0 | } |
314 | | |
315 | | void SwTextShell::ExecMoveMisc(SfxRequest &rReq) |
316 | 0 | { |
317 | 0 | SwWrtShell &rSh = GetShell(); |
318 | 0 | rSh.addCurrentPosition(); |
319 | 0 | const sal_uInt16 nSlot = rReq.GetSlot(); |
320 | 0 | bool bSetRetVal = true, bRet = true; |
321 | 0 | switch ( nSlot ) |
322 | 0 | { |
323 | 0 | case SID_FM_TOGGLECONTROLFOCUS: |
324 | 0 | { |
325 | 0 | const SwDoc* pDoc = rSh.GetDoc(); |
326 | 0 | const SwDocShell* pDocShell = pDoc ? pDoc->GetDocShell() : nullptr; |
327 | 0 | const SwView* pView = pDocShell ? pDocShell->GetView() : nullptr; |
328 | 0 | const FmFormShell* pFormShell = pView ? pView->GetFormShell() : nullptr; |
329 | 0 | SdrView* pDrawView = pView ? pView->GetDrawView() : nullptr; |
330 | 0 | vcl::Window* pWindow = pView ? pView->GetWrtShell().GetWin() : nullptr; |
331 | |
|
332 | 0 | OSL_ENSURE( pFormShell && pDrawView && pWindow, "SwXTextView::ExecMoveMisc: no chance!" ); |
333 | 0 | if ( !pFormShell || !pDrawView || !pWindow ) |
334 | 0 | break; |
335 | | |
336 | 0 | std::unique_ptr< svx::ISdrObjectFilter > pFilter( FmFormShell::CreateFocusableControlFilter( |
337 | 0 | *pDrawView, *pWindow->GetOutDev() ) ); |
338 | 0 | if (!pFilter) |
339 | 0 | break; |
340 | | |
341 | 0 | const SdrObject* pNearestControl = rSh.GetBestObject( true, GotoObjFlags::DrawControl, false, pFilter.get() ); |
342 | 0 | if ( !pNearestControl ) |
343 | 0 | break; |
344 | | |
345 | 0 | const SdrUnoObj* pUnoObject = dynamic_cast< const SdrUnoObj* >( pNearestControl ); |
346 | 0 | OSL_ENSURE( pUnoObject, "SwTextShell::ExecMoveMisc: GetBestObject returned nonsense!" ); |
347 | 0 | if ( !pUnoObject ) |
348 | 0 | break; |
349 | | |
350 | 0 | pFormShell->ToggleControlFocus( *pUnoObject, *pDrawView, *pWindow->GetOutDev() ); |
351 | 0 | } |
352 | 0 | break; |
353 | 0 | case FN_CNTNT_TO_NEXT_FRAME: |
354 | 0 | bRet = rSh.GotoObj(true, GotoObjFlags::Any); |
355 | 0 | if(bRet) |
356 | 0 | { |
357 | 0 | rSh.HideCursor(); |
358 | 0 | rSh.EnterSelFrameMode(); |
359 | 0 | } |
360 | 0 | break; |
361 | 0 | case FN_NEXT_FOOTNOTE: |
362 | 0 | rSh.MoveCursor(); |
363 | 0 | bRet = rSh.GotoNextFootnoteAnchor(); |
364 | 0 | break; |
365 | 0 | case FN_PREV_FOOTNOTE: |
366 | 0 | rSh.MoveCursor(); |
367 | 0 | bRet = rSh.GotoPrevFootnoteAnchor(); |
368 | 0 | break; |
369 | 0 | case FN_TO_HEADER: |
370 | 0 | rSh.MoveCursor(); |
371 | 0 | if ( FrameTypeFlags::HEADER & rSh.GetFrameType(nullptr,false) ) |
372 | 0 | rSh.SttPg(); |
373 | 0 | else |
374 | 0 | { |
375 | 0 | bool bMoved = rSh.GotoHeaderText(); |
376 | 0 | if ( !bMoved ) |
377 | 0 | rSh.SttPg(); |
378 | 0 | } |
379 | 0 | bSetRetVal = false; |
380 | 0 | break; |
381 | 0 | case FN_TO_FOOTER: |
382 | 0 | rSh.MoveCursor(); |
383 | 0 | if ( FrameTypeFlags::FOOTER & rSh.GetFrameType(nullptr,false) ) |
384 | 0 | rSh.EndPg(); |
385 | 0 | else |
386 | 0 | { |
387 | 0 | bool bMoved = rSh.GotoFooterText(); |
388 | 0 | if ( !bMoved ) |
389 | 0 | rSh.EndPg(); |
390 | 0 | } |
391 | 0 | bSetRetVal = false; |
392 | 0 | break; |
393 | 0 | case FN_FOOTNOTE_TO_ANCHOR: |
394 | 0 | rSh.MoveCursor(); |
395 | 0 | if ( FrameTypeFlags::FOOTNOTE & rSh.GetFrameType(nullptr,false) ) |
396 | 0 | rSh.GotoFootnoteAnchor(); |
397 | 0 | else |
398 | 0 | rSh.GotoFootnoteText(); |
399 | 0 | bSetRetVal = false; |
400 | 0 | break; |
401 | 0 | case FN_TO_FOOTNOTE_AREA : |
402 | 0 | rSh.GotoFootnoteText(); |
403 | 0 | break; |
404 | 0 | case FN_PREV_TABLE: |
405 | 0 | bRet = rSh.MoveTable( GotoPrevTable, fnTableStart); |
406 | 0 | break; |
407 | 0 | case FN_NEXT_TABLE: |
408 | 0 | bRet = rSh.MoveTable(GotoNextTable, fnTableStart); |
409 | 0 | break; |
410 | 0 | case FN_GOTO_NEXT_REGION : |
411 | 0 | bRet = rSh.MoveRegion(GotoNextRegion, fnRegionStart); |
412 | 0 | break; |
413 | 0 | case FN_GOTO_PREV_REGION : |
414 | 0 | bRet = rSh.MoveRegion(GotoPrevRegion, fnRegionStart); |
415 | 0 | break; |
416 | 0 | case FN_NEXT_TOXMARK: |
417 | 0 | bRet = rSh.GotoNxtPrvTOXMark(); |
418 | 0 | break; |
419 | 0 | case FN_PREV_TOXMARK: |
420 | 0 | bRet = rSh.GotoNxtPrvTOXMark( false ); |
421 | 0 | break; |
422 | 0 | case FN_NEXT_TBLFML: |
423 | 0 | bRet = rSh.GotoNxtPrvTableFormula(); |
424 | 0 | break; |
425 | 0 | case FN_PREV_TBLFML: |
426 | 0 | bRet = rSh.GotoNxtPrvTableFormula( false ); |
427 | 0 | break; |
428 | 0 | case FN_NEXT_TBLFML_ERR: |
429 | 0 | bRet = rSh.GotoNxtPrvTableFormula( true, true ); |
430 | 0 | break; |
431 | 0 | case FN_PREV_TBLFML_ERR: |
432 | 0 | bRet = rSh.GotoNxtPrvTableFormula( false, true ); |
433 | 0 | break; |
434 | 0 | default: |
435 | 0 | OSL_FAIL("wrong dispatcher"); |
436 | 0 | return; |
437 | 0 | } |
438 | | |
439 | 0 | if( bSetRetVal ) |
440 | 0 | rReq.SetReturnValue(SfxBoolItem( nSlot, bRet )); |
441 | 0 | rReq.Done(); |
442 | |
|
443 | 0 | bool bInHeader = true; |
444 | 0 | if ( rSh.IsInHeaderFooter( &bInHeader ) ) |
445 | 0 | { |
446 | 0 | if ( !bInHeader ) |
447 | 0 | { |
448 | 0 | rSh.SetShowHeaderFooterSeparator( FrameControlType::Footer, true ); |
449 | 0 | rSh.SetShowHeaderFooterSeparator( FrameControlType::Header, false ); |
450 | 0 | } |
451 | 0 | else |
452 | 0 | { |
453 | 0 | rSh.SetShowHeaderFooterSeparator( FrameControlType::Header, true ); |
454 | 0 | rSh.SetShowHeaderFooterSeparator( FrameControlType::Footer, false ); |
455 | 0 | } |
456 | | |
457 | | // Force repaint |
458 | 0 | rSh.GetWin()->Invalidate(); |
459 | 0 | } |
460 | 0 | if ( rSh.IsInHeaderFooter() != rSh.IsHeaderFooterEdit() ) |
461 | 0 | rSh.ToggleHeaderFooterEdit(); |
462 | 0 | } |
463 | | |
464 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |