bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / shells / txtcrsr.cxx
blob2c09feac936aaa593ff6bfc594a6f672bc950de9
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 <sfx2/request.hxx>
21 #include <svl/eitem.hxx>
22 #include <basic/sbxvar.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <sfx2/bindings.hxx>
26 #include <view.hxx>
27 #include <wrtsh.hxx>
28 #include <textsh.hxx>
29 #include <num.hxx>
30 #include <edtwin.hxx>
31 #include <crsskip.hxx>
32 #include <doc.hxx>
33 #include <docsh.hxx>
35 #include <cmdid.h>
36 #include <globals.h>
37 #include <globals.hrc>
39 #include <svx/svdouno.hxx>
40 #include <svx/fmshell.hxx>
41 #include <svx/sdrobjectfilter.hxx>
43 using namespace ::com::sun::star;
45 void SwTextShell::ExecBasicMove(SfxRequest &rReq)
47 SwWrtShell &rSh = GetShell();
48 GetView().GetEditWin().FlushInBuffer();
49 const SfxItemSet *pArgs = rReq.GetArgs();
50 sal_Bool bSelect = sal_False;
51 sal_uInt16 nCount = 1;
52 if(pArgs)
54 const SfxPoolItem *pItem;
55 if(SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_MOVE_COUNT, sal_True, &pItem))
56 nCount = ((const SfxInt16Item *)pItem)->GetValue();
57 if(SFX_ITEM_SET == pArgs->GetItemState(FN_PARAM_MOVE_SELECTION, sal_True, &pItem))
58 bSelect = ((const SfxBoolItem *)pItem)->GetValue();
60 switch(rReq.GetSlot())
62 case FN_CHAR_LEFT_SEL: rReq.SetSlot( FN_CHAR_LEFT ); bSelect = sal_True; break;
63 case FN_CHAR_RIGHT_SEL: rReq.SetSlot( FN_CHAR_RIGHT ); bSelect = sal_True; break;
64 case FN_LINE_UP_SEL: rReq.SetSlot( FN_LINE_UP ); bSelect = sal_True; break;
65 case FN_LINE_DOWN_SEL: rReq.SetSlot( FN_LINE_DOWN ); bSelect = sal_True; break;
68 uno::Reference< frame::XDispatchRecorder > xRecorder =
69 GetView().GetViewFrame()->GetBindings().GetRecorder();
70 if ( xRecorder.is() )
72 rReq.AppendItem( SfxInt16Item(FN_PARAM_MOVE_COUNT, nCount) );
73 rReq.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, bSelect) );
75 sal_uInt16 nSlot = rReq.GetSlot();
76 rReq.Done();
77 // Get EditWin before calling the move functions (shell change may occur!)
78 SwEditWin& rTmpEditWin = GetView().GetEditWin();
79 for( sal_uInt16 i = 0; i < nCount; i++ )
81 switch(nSlot)
83 case FN_CHAR_LEFT: rSh.Left( CRSR_SKIP_CELLS, bSelect, 1, sal_False, sal_True ); break;
84 case FN_CHAR_RIGHT: rSh.Right( CRSR_SKIP_CELLS, bSelect, 1, sal_False, sal_True ); break;
85 case FN_LINE_UP: rSh.Up ( bSelect, 1 ); break;
86 case FN_LINE_DOWN: rSh.Down ( bSelect, 1 ); break;
87 default: OSL_FAIL("wrong Dispatcher"); return;
91 //#i42732# - notify the edit window that from now on we do not use the input language
92 rTmpEditWin.SetUseInputLanguage( sal_False );
95 void SwTextShell::ExecMove(SfxRequest &rReq)
97 SwWrtShell &rSh = GetShell();
98 SwEditWin& rTmpEditWin = GetView().GetEditWin();
99 rTmpEditWin.FlushInBuffer();
101 sal_uInt16 nSlot = rReq.GetSlot();
102 sal_Bool bRet = sal_False;
103 switch ( nSlot )
105 case FN_START_OF_LINE_SEL:
106 case FN_START_OF_LINE: bRet = rSh.LeftMargin ( FN_START_OF_LINE_SEL == nSlot, sal_False );
107 break;
109 case FN_END_OF_LINE_SEL:
110 case FN_END_OF_LINE: bRet = rSh.RightMargin( FN_END_OF_LINE_SEL == nSlot, sal_False );
111 break;
113 case FN_START_OF_DOCUMENT_SEL:
114 case FN_START_OF_DOCUMENT: bRet = rSh.SttDoc ( FN_START_OF_DOCUMENT_SEL == nSlot);
115 break;
117 case FN_END_OF_DOCUMENT_SEL:
118 case FN_END_OF_DOCUMENT: bRet = rSh.EndDoc( FN_END_OF_DOCUMENT_SEL == nSlot );
119 break;
121 case FN_SELECT_WORD: bRet = rSh.SelNearestWrd(); break;
123 case SID_SELECTALL: bRet = 0 != rSh.SelAll(); break;
124 default: OSL_FAIL("wrong dispatcher"); return;
127 if ( bRet )
128 rReq.Done();
129 else
130 rReq.Ignore();
132 //#i42732# - notify the edit window that from now on we do not use the input language
133 rTmpEditWin.SetUseInputLanguage( sal_False );
136 void SwTextShell::ExecMovePage(SfxRequest &rReq)
138 SwWrtShell &rSh = GetShell();
139 GetView().GetEditWin().FlushInBuffer();
141 sal_uInt16 nSlot = rReq.GetSlot();
142 switch( nSlot )
144 case FN_START_OF_NEXT_PAGE_SEL :
145 case FN_START_OF_NEXT_PAGE: rSh.SttNxtPg( FN_START_OF_NEXT_PAGE_SEL == nSlot ); break;
147 case FN_END_OF_NEXT_PAGE_SEL:
148 case FN_END_OF_NEXT_PAGE: rSh.EndNxtPg( FN_END_OF_NEXT_PAGE_SEL == nSlot ); break;
150 case FN_START_OF_PREV_PAGE_SEL:
151 case FN_START_OF_PREV_PAGE: rSh.SttPrvPg( FN_START_OF_PREV_PAGE_SEL == nSlot ); break;
153 case FN_END_OF_PREV_PAGE_SEL:
154 case FN_END_OF_PREV_PAGE: rSh.EndPrvPg( FN_END_OF_PREV_PAGE_SEL == nSlot ); break;
156 case FN_START_OF_PAGE_SEL:
157 case FN_START_OF_PAGE: rSh.SttPg ( FN_START_OF_PAGE_SEL == nSlot ); break;
159 case FN_END_OF_PAGE_SEL:
160 case FN_END_OF_PAGE: rSh.EndPg ( FN_END_OF_PAGE_SEL == nSlot ); break;
161 default: OSL_FAIL("wrong dispatcher"); return;
163 rReq.Done();
166 void SwTextShell::ExecMoveCol(SfxRequest &rReq)
168 SwWrtShell &rSh = GetShell();
169 switch ( rReq.GetSlot() )
171 case FN_START_OF_COLUMN: rSh.StartOfColumn ( sal_False ); break;
172 case FN_END_OF_COLUMN: rSh.EndOfColumn ( sal_False ); break;
173 case FN_START_OF_NEXT_COLUMN: rSh.StartOfNextColumn( sal_False ) ; break;
174 case FN_END_OF_NEXT_COLUMN: rSh.EndOfNextColumn ( sal_False ); break;
175 case FN_START_OF_PREV_COLUMN: rSh.StartOfPrevColumn( sal_False ); break;
176 case FN_END_OF_PREV_COLUMN: rSh.EndOfPrevColumn ( sal_False ); break;
177 default: OSL_FAIL("wrong dispatcher"); return;
179 rReq.Done();
182 void SwTextShell::ExecMoveLingu(SfxRequest &rReq)
184 SwWrtShell &rSh = GetShell();
185 GetView().GetEditWin().FlushInBuffer();
187 sal_uInt16 nSlot = rReq.GetSlot();
188 switch ( nSlot )
190 case FN_NEXT_WORD_SEL:
191 case FN_NEXT_WORD: rSh.NxtWrd( FN_NEXT_WORD_SEL == nSlot );
192 break;
194 case FN_START_OF_PARA_SEL:
195 case FN_START_OF_PARA: rSh.SttPara( FN_START_OF_PARA_SEL == nSlot );
196 break;
198 case FN_END_OF_PARA_SEL:
199 case FN_END_OF_PARA: rSh.EndPara( FN_END_OF_PARA_SEL == nSlot );
200 break;
202 case FN_PREV_WORD_SEL:
203 case FN_PREV_WORD: rSh.PrvWrd( FN_PREV_WORD_SEL == nSlot );
204 break;
206 case FN_NEXT_SENT_SEL:
207 case FN_NEXT_SENT: rSh.FwdSentence( FN_NEXT_SENT_SEL == nSlot );
208 break;
210 case FN_PREV_SENT_SEL:
211 case FN_PREV_SENT: rSh.BwdSentence( FN_PREV_SENT_SEL == nSlot );
212 break;
214 case FN_NEXT_PARA: rSh.FwdPara ( sal_False );
215 break;
217 case FN_PREV_PARA: rSh.BwdPara ( sal_False );
218 break;
219 default: OSL_FAIL("wrong dispatcher"); return;
221 rReq.Done();
224 void SwTextShell::ExecMoveMisc(SfxRequest &rReq)
226 SwWrtShell &rSh = GetShell();
227 sal_uInt16 nSlot = rReq.GetSlot();
228 sal_Bool bSetRetVal = sal_True, bRet = sal_True;
229 switch ( nSlot )
231 case SID_FM_TOGGLECONTROLFOCUS:
233 const SwDoc* pDoc = rSh.GetDoc();
234 const SwDocShell* pDocShell = pDoc ? pDoc->GetDocShell() : NULL;
235 const SwView* pView = pDocShell ? pDocShell->GetView() : NULL;
236 const FmFormShell* pFormShell = pView ? pView->GetFormShell() : NULL;
237 SdrView* pDrawView = pView ? pView->GetDrawView() : NULL;
238 Window* pWindow = pView ? pView->GetWrtShell().GetWin() : NULL;
240 OSL_ENSURE( pFormShell && pDrawView && pWindow, "SwXTextView::ExecMoveMisc: no chance!" );
241 if ( !pFormShell || !pDrawView || !pWindow )
242 break;
244 ::std::auto_ptr< ::svx::ISdrObjectFilter > pFilter( pFormShell->CreateFocusableControlFilter(
245 *pDrawView, *pWindow ) );
246 if ( !pFilter.get() )
247 break;
249 const SdrObject* pNearestControl = rSh.GetBestObject( sal_True, GOTOOBJ_DRAW_CONTROL, sal_False, pFilter.get() );
250 if ( !pNearestControl )
251 break;
253 const SdrUnoObj* pUnoObject = dynamic_cast< const SdrUnoObj* >( pNearestControl );
254 OSL_ENSURE( pUnoObject, "SwTextShell::ExecMoveMisc: GetBestObject returned nonsense!" );
255 if ( !pUnoObject )
256 break;
258 pFormShell->ToggleControlFocus( *pUnoObject, *pDrawView, *pWindow );
260 break;
261 case FN_CNTNT_TO_NEXT_FRAME:
262 bRet = rSh.GotoObj(sal_True, GOTOOBJ_GOTO_ANY);
263 if(bRet)
265 rSh.HideCrsr();
266 rSh.EnterSelFrmMode();
268 break;
269 case FN_NEXT_FOOTNOTE:
270 rSh.MoveCrsr();
271 bRet = rSh.GotoNextFtnAnchor();
272 break;
273 case FN_PREV_FOOTNOTE:
274 rSh.MoveCrsr();
275 bRet = rSh.GotoPrevFtnAnchor();
276 break;
277 case FN_TO_HEADER:
278 rSh.MoveCrsr();
279 if ( FRMTYPE_HEADER & rSh.GetFrmType(0,sal_False) )
280 rSh.SttPg();
281 else
283 bool bMoved = rSh.GotoHeaderTxt();
284 if ( !bMoved )
285 rSh.SttPg();
287 bSetRetVal = sal_False;
288 break;
289 case FN_TO_FOOTER:
290 rSh.MoveCrsr();
291 if ( FRMTYPE_FOOTER & rSh.GetFrmType(0,sal_False) )
292 rSh.EndPg();
293 else
295 bool bMoved = rSh.GotoFooterTxt();
296 if ( !bMoved )
297 rSh.EndPg();
299 bSetRetVal = sal_False;
300 break;
301 case FN_FOOTNOTE_TO_ANCHOR:
302 rSh.MoveCrsr();
303 if ( FRMTYPE_FOOTNOTE & rSh.GetFrmType(0,sal_False) )
304 rSh.GotoFtnAnchor();
305 else
306 rSh.GotoFtnTxt();
307 bSetRetVal = sal_False;
308 break;
309 case FN_TO_FOOTNOTE_AREA :
310 rSh.GotoFtnTxt();
311 break;
312 case FN_PREV_TABLE:
313 bRet = rSh.MoveTable( fnTablePrev, fnTableStart);
314 break;
315 case FN_NEXT_TABLE:
316 bRet = rSh.MoveTable(fnTableNext, fnTableStart);
317 break;
318 case FN_GOTO_NEXT_REGION :
319 bRet = rSh.MoveRegion(fnRegionNext, fnRegionStart);
320 break;
321 case FN_GOTO_PREV_REGION :
322 bRet = rSh.MoveRegion(fnRegionPrev, fnRegionStart);
323 break;
325 case FN_NEXT_TOXMARK:
326 bRet = rSh.GotoNxtPrvTOXMark( sal_True );
327 break;
328 case FN_PREV_TOXMARK:
329 bRet = rSh.GotoNxtPrvTOXMark( sal_False );
330 break;
331 case FN_NEXT_TBLFML:
332 bRet = rSh.GotoNxtPrvTblFormula( sal_True, sal_False );
333 break;
334 case FN_PREV_TBLFML:
335 bRet = rSh.GotoNxtPrvTblFormula( sal_False, sal_False );
336 break;
337 case FN_NEXT_TBLFML_ERR:
338 bRet = rSh.GotoNxtPrvTblFormula( sal_True, sal_True );
339 break;
340 case FN_PREV_TBLFML_ERR:
341 bRet = rSh.GotoNxtPrvTblFormula( sal_False, sal_True );
342 break;
344 default:
345 OSL_FAIL("wrong dispatcher");
346 return;
349 if( bSetRetVal )
350 rReq.SetReturnValue(SfxBoolItem( nSlot, bRet ));
351 rReq.Done();
353 sal_Bool bInHeader = sal_True;
354 if ( rSh.IsInHeaderFooter( &bInHeader ) )
356 if ( !bInHeader )
358 rSh.SetShowHeaderFooterSeparator( Footer, true );
359 rSh.SetShowHeaderFooterSeparator( Header, false );
361 else
363 rSh.SetShowHeaderFooterSeparator( Header, true );
364 rSh.SetShowHeaderFooterSeparator( Footer, false );
367 // Force repaint
368 rSh.GetWin()->Invalidate();
370 if ( rSh.IsInHeaderFooter() != rSh.IsHeaderFooterEdit() )
371 rSh.ToggleHeaderFooterEdit();
374 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */