summaryrefslogtreecommitdiffstats
path: root/sw/source/uibase/shells/txtcrsr.cxx
blob: f8ec0d7a6e273648e14b13a032aebefd66724992 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <sal/config.h>

#include <memory>

#include <sfx2/request.hxx>
#include <svl/eitem.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/bindings.hxx>
#include <osl/diagnose.h>

#include <view.hxx>
#include <wrtsh.hxx>
#include <textsh.hxx>
#include <edtwin.hxx>
#include <doc.hxx>
#include <docsh.hxx>

#include <cmdid.h>
#include <globals.hrc>

#include <svx/svdouno.hxx>
#include <svx/fmshell.hxx>
#include <svx/sdrobjectfilter.hxx>

using namespace ::com::sun::star;

void SwTextShell::ExecBasicMove(SfxRequest &rReq)
{
    SwWrtShell &rSh = GetShell();
    GetView().GetEditWin().FlushInBuffer();
    const SfxItemSet *pArgs = rReq.GetArgs();
    bool bSelect = false;
    sal_Int32 nCount = 1;
    if(pArgs)
    {
        if(const SfxInt32Item* pCountItem = pArgs->GetItemIfSet(FN_PARAM_MOVE_COUNT))
            nCount = pCountItem->GetValue();
        if(const SfxBoolItem* pSelectionItem = pArgs->GetItemIfSet(FN_PARAM_MOVE_SELECTION))
            bSelect = pSelectionItem->GetValue();
    }
    switch(rReq.GetSlot())
    {
        case FN_CHAR_LEFT_SEL:
            rReq.SetSlot( FN_CHAR_LEFT );
            bSelect = true;
            break;
        case FN_CHAR_RIGHT_SEL:
            rReq.SetSlot( FN_CHAR_RIGHT );
            bSelect = true;
            break;
        case FN_LINE_UP_SEL:
            rReq.SetSlot( FN_LINE_UP );
            bSelect = true;
            break;
        case FN_LINE_DOWN_SEL:
            rReq.SetSlot( FN_LINE_DOWN );
            bSelect = true;
            break;
    }

    uno::Reference< frame::XDispatchRecorder > xRecorder =
            GetView().GetViewFrame()->GetBindings().GetRecorder();
    if ( xRecorder.is() )
    {
        rReq.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT, nCount) );
        rReq.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, bSelect) );
    }
    const sal_uInt16 nSlot = rReq.GetSlot();
    rReq.Done();
    // Get EditWin before calling the move functions (shell change may occur!)
    SwEditWin& rTmpEditWin = GetView().GetEditWin();
    for( sal_Int32 i = 0; i < nCount; i++ )
    {
        switch(nSlot)
        {
            case FN_CHAR_LEFT:
                rSh.Left( CRSR_SKIP_CELLS,  bSelect, 1, false, true );
                break;
            case FN_CHAR_RIGHT:
                rSh.Right( CRSR_SKIP_CELLS, bSelect, 1, false, true );
                break;
            case FN_LINE_UP:
                rSh.Up( bSelect );
                break;
            case FN_LINE_DOWN:
                rSh.Down( bSelect );
                break;
            default:
                OSL_FAIL("wrong Dispatcher");
                return;
        }
    }

    //#i42732# - notify the edit window that from now on we do not use the input language
    rTmpEditWin.SetUseInputLanguage( false );
}

void SwTextShell::ExecMove(SfxRequest &rReq)
{
    SwWrtShell &rSh = GetShell();
    rSh.addCurrentPosition();
    SwEditWin& rTmpEditWin = GetView().GetEditWin();
    rTmpEditWin.FlushInBuffer();

    bool bRet = false;
    switch ( rReq.GetSlot() )
    {
        case FN_START_OF_LINE_SEL:
            bRet = rSh.LeftMargin( true, false );
            break;
        case FN_START_OF_LINE:
            bRet = rSh.LeftMargin( false, false );
            break;
        case FN_END_OF_LINE_SEL:
            bRet = rSh.RightMargin( true, false );
            break;
        case FN_END_OF_LINE:
            bRet = rSh.RightMargin( false, false );
            break;
        case FN_START_OF_DOCUMENT_SEL:
            bRet = rSh.StartOfSection( true );
            break;
        case FN_START_OF_DOCUMENT:
            bRet = rSh.StartOfSection();
            break;
        case FN_END_OF_DOCUMENT_SEL:
            bRet = rSh.EndOfSection( true );
            break;
        case FN_END_OF_DOCUMENT:
            bRet = rSh.EndOfSection();
            break;
        case FN_SELECT_WORD:
            bRet = rSh.SelNearestWrd();
            break;
        case FN_SELECT_SENTENCE:
            rSh.SelSentence( nullptr );
            bRet = true;
            break;
        case SID_SELECTALL:
            rSh.SelAll();
            bRet = true;
            break;
        default:
            OSL_FAIL("wrong dispatcher");
            return;
    }

    if ( bRet )
        rReq.Done();
    else
        rReq.Ignore();

    //#i42732# - notify the edit window that from now on we do not use the input language
    rTmpEditWin.SetUseInputLanguage( false );
}

void SwTextShell::ExecMovePage(SfxRequest &rReq)
{
    SwWrtShell &rSh = GetShell();
    rSh.addCurrentPosition();
    GetView().GetEditWin().FlushInBuffer();

    switch( rReq.GetSlot() )
    {
        case FN_START_OF_NEXT_PAGE_SEL :
            rSh.SttNxtPg( true );
            break;
        case FN_START_OF_NEXT_PAGE:
            rSh.SttNxtPg();
            break;
        case FN_END_OF_NEXT_PAGE_SEL:
            rSh.EndNxtPg( true );
            break;
        case FN_END_OF_NEXT_PAGE:
            rSh.EndNxtPg();
            break;
        case FN_START_OF_PREV_PAGE_SEL:
            rSh.SttPrvPg( true );
            break;
        case FN_START_OF_PREV_PAGE:
            rSh.SttPrvPg();
            break;
        case FN_END_OF_PREV_PAGE_SEL:
            rSh.EndPrvPg( true );
            break;
        case FN_END_OF_PREV_PAGE:
            rSh.EndPrvPg();
            break;
        case FN_START_OF_PAGE_SEL:
            rSh.SttPg( true );
            break;
        case FN_START_OF_PAGE:
            rSh.SttPg();
            break;
        case FN_END_OF_PAGE_SEL:
            rSh.EndPg( true );
            break;
        case FN_END_OF_PAGE:
            rSh.EndPg();
            break;
        default:
            OSL_FAIL("wrong dispatcher");
            return;
    }
    rReq.Done();
}

void SwTextShell::ExecMoveCol(SfxRequest &rReq)
{
    SwWrtShell &rSh = GetShell();
    rSh.addCurrentPosition();
    switch ( rReq.GetSlot() )
    {
        case FN_START_OF_COLUMN:
            rSh.StartOfColumn();
            break;
        case FN_END_OF_COLUMN:
            rSh.EndOfColumn();
            break;
        case FN_START_OF_NEXT_COLUMN:
            rSh.StartOfNextColumn() ;
            break;
        case FN_END_OF_NEXT_COLUMN:
            rSh.EndOfNextColumn();
            break;
        case FN_START_OF_PREV_COLUMN:
            rSh.StartOfPrevColumn();
            break;
        case FN_END_OF_PREV_COLUMN:
            rSh.EndOfPrevColumn();
            break;
        default:
            OSL_FAIL("wrong dispatcher");
            return;
    }
    rReq.Done();
}

void SwTextShell::ExecMoveLingu(SfxRequest &rReq)
{
    SwWrtShell &rSh = GetShell();
    rSh.addCurrentPosition();
    GetView().GetEditWin().FlushInBuffer();

    switch ( rReq.GetSlot() )
    {
        case FN_NEXT_WORD_SEL:
            rSh.NxtWrd( true );
            break;
        case FN_NEXT_WORD:
            rSh.NxtWrd();
            break;
        case FN_START_OF_PARA_SEL:
            rSh.SttPara( true );
            break;
        case FN_START_OF_PARA:
            rSh.SttPara();
            break;
        case FN_END_OF_PARA_SEL:
            rSh.EndPara( true );
            break;
        case FN_END_OF_PARA:
            rSh.EndPara();
            break;
        case FN_PREV_WORD_SEL:
            rSh.PrvWrd( true );
            break;
        case FN_PREV_WORD:
            rSh.PrvWrd();
            break;
        case FN_NEXT_SENT_SEL:
            rSh.FwdSentence( true );
            break;
        case FN_NEXT_SENT:
            rSh.FwdSentence();
            break;
        case FN_PREV_SENT_SEL:
            rSh.BwdSentence( true );
            break;
        case FN_PREV_SENT:
            rSh.BwdSentence();
            break;
        case FN_NEXT_PARA:
            rSh.FwdPara();
            break;
        case FN_PREV_PARA:
            rSh.BwdPara();
            break;
        default:
            OSL_FAIL("wrong dispatcher");
            return;
    }
    rReq.Done();
}

void SwTextShell::ExecMoveMisc(SfxRequest &rReq)
{
    SwWrtShell &rSh = GetShell();
    rSh.addCurrentPosition();
    const sal_uInt16 nSlot = rReq.GetSlot();
    bool bSetRetVal = true, bRet = true;
    switch ( nSlot )
    {
        case SID_FM_TOGGLECONTROLFOCUS:
            {
                const SwDoc* pDoc = rSh.GetDoc();
                const SwDocShell* pDocShell = pDoc ? pDoc->GetDocShell() : nullptr;
                const SwView* pView = pDocShell ? pDocShell->GetView() : nullptr;
                const FmFormShell* pFormShell = pView ? pView->GetFormShell() : nullptr;
                SdrView* pDrawView = pView ? pView->GetDrawView() : nullptr;
                vcl::Window* pWindow = pView ? pView->GetWrtShell().GetWin() : nullptr;

                OSL_ENSURE( pFormShell && pDrawView && pWindow, "SwXTextView::ExecMoveMisc: no chance!" );
                if ( !pFormShell || !pDrawView || !pWindow )
                    break;

                std::unique_ptr< svx::ISdrObjectFilter > pFilter( FmFormShell::CreateFocusableControlFilter(
                    *pDrawView, *pWindow->GetOutDev() ) );
                if (!pFilter)
                    break;

                const SdrObject* pNearestControl = rSh.GetBestObject( true, GotoObjFlags::DrawControl, false, pFilter.get() );
                if ( !pNearestControl )
                    break;

                const SdrUnoObj* pUnoObject = dynamic_cast< const SdrUnoObj* >( pNearestControl );
                OSL_ENSURE( pUnoObject, "SwTextShell::ExecMoveMisc: GetBestObject returned nonsense!" );
                if ( !pUnoObject )
                    break;

                pFormShell->ToggleControlFocus( *pUnoObject, *pDrawView, *pWindow->GetOutDev() );
            }
            break;
        case FN_CNTNT_TO_NEXT_FRAME:
            bRet = rSh.GotoObj(true, GotoObjFlags::Any);
            if(bRet)
            {
                rSh.HideCursor();
                rSh.EnterSelFrameMode();
            }
        break;
        case FN_NEXT_FOOTNOTE:
            rSh.MoveCursor();
            bRet = rSh.GotoNextFootnoteAnchor();
            break;
        case FN_PREV_FOOTNOTE:
            rSh.MoveCursor();
            bRet = rSh.GotoPrevFootnoteAnchor();
            break;
        case FN_TO_HEADER:
            rSh.MoveCursor();
            if ( FrameTypeFlags::HEADER & rSh.GetFrameType(nullptr,false) )
                rSh.SttPg();
            else
            {
                bool bMoved = rSh.GotoHeaderText();
                if ( !bMoved )
                    rSh.SttPg();
            }
            bSetRetVal = false;
            break;
        case FN_TO_FOOTER:
            rSh.MoveCursor();
            if ( FrameTypeFlags::FOOTER & rSh.GetFrameType(nullptr,false) )
                rSh.EndPg();
            else
            {
                bool bMoved = rSh.GotoFooterText();
                if ( !bMoved )
                    rSh.EndPg();
            }
            bSetRetVal = false;
            break;
        case FN_FOOTNOTE_TO_ANCHOR:
            rSh.MoveCursor();
            if ( FrameTypeFlags::FOOTNOTE & rSh.GetFrameType(nullptr,false) )
                rSh.GotoFootnoteAnchor();
            else
                rSh.GotoFootnoteText();
            bSetRetVal = false;
            break;
        case FN_TO_FOOTNOTE_AREA :
            rSh.GotoFootnoteText();
            break;
        case FN_PREV_TABLE:
            bRet = rSh.MoveTable( GotoPrevTable, fnTableStart);
            break;
        case FN_NEXT_TABLE:
            bRet = rSh.MoveTable(GotoNextTable, fnTableStart);
            break;
        case FN_GOTO_NEXT_REGION :
            bRet = rSh.MoveRegion(GotoNextRegion, fnRegionStart);
            break;
        case FN_GOTO_PREV_REGION :
            bRet = rSh.MoveRegion(GotoPrevRegion, fnRegionStart);
            break;
        case FN_NEXT_TOXMARK:
            bRet = rSh.GotoNxtPrvTOXMark();
            break;
        case FN_PREV_TOXMARK:
            bRet = rSh.GotoNxtPrvTOXMark( false );
            break;
        case FN_NEXT_TBLFML:
            bRet = rSh.GotoNxtPrvTableFormula();
            break;
        case FN_PREV_TBLFML:
            bRet = rSh.GotoNxtPrvTableFormula( false );
            break;
        case FN_NEXT_TBLFML_ERR:
            bRet = rSh.GotoNxtPrvTableFormula( true, true );
            break;
        case FN_PREV_TBLFML_ERR:
            bRet = rSh.GotoNxtPrvTableFormula( false, true );
            break;
        default:
            OSL_FAIL("wrong dispatcher");
            return;
    }

    if( bSetRetVal )
        rReq.SetReturnValue(SfxBoolItem( nSlot, bRet ));
    rReq.Done();

    bool bInHeader = true;
    if ( rSh.IsInHeaderFooter( &bInHeader ) )
    {
        if ( !bInHeader )
        {
            rSh.SetShowHeaderFooterSeparator( FrameControlType::Footer, true );
            rSh.SetShowHeaderFooterSeparator( FrameControlType::Header, false );
        }
        else
        {
            rSh.SetShowHeaderFooterSeparator( FrameControlType::Header, true );
            rSh.SetShowHeaderFooterSeparator( FrameControlType::Footer, false );
        }

        // Force repaint
        rSh.GetWin()->Invalidate();
    }
    if ( rSh.IsInHeaderFooter() != rSh.IsHeaderFooterEdit() )
        rSh.ToggleHeaderFooterEdit();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */