LibreOffice Module sc (master) 1
inscodlg.cxx
Go to the documentation of this file.
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#undef SC_DLLIMPLEMENTATION
21
22#include <inscodlg.hxx>
23#include <officecfg/Office/Common.hxx>
24
29
30//whether the dialog has loaded for the first time
31static bool firstLoad = true;
32
34{
35 //store the flags in the registry
36 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
37
38 //InsertDeleteFlags
39 officecfg::Office::Common::PasteSpecial::Paste::All::set(ScInsertContentsDlg::mxBtnInsAll->get_active(), batch);
40 officecfg::Office::Common::PasteSpecial::Paste::Numbers::set(ScInsertContentsDlg::mxBtnInsNumbers->get_active(), batch);
41 officecfg::Office::Common::PasteSpecial::Paste::Text::set(ScInsertContentsDlg::mxBtnInsStrings->get_active(), batch);
42 officecfg::Office::Common::PasteSpecial::Paste::DateTime::set(ScInsertContentsDlg::mxBtnInsDateTime->get_active(), batch);
43 officecfg::Office::Common::PasteSpecial::Paste::Formats::set(ScInsertContentsDlg::mxBtnInsAttrs->get_active(), batch);
44 officecfg::Office::Common::PasteSpecial::Paste::Comments::set(ScInsertContentsDlg::mxBtnInsNotes->get_active(), batch);
45 officecfg::Office::Common::PasteSpecial::Paste::Objects::set(ScInsertContentsDlg::mxBtnInsObjects->get_active(), batch);
46 officecfg::Office::Common::PasteSpecial::Paste::Formulas::set(ScInsertContentsDlg::mxBtnInsFormulas->get_active(), batch);
47
48 //ScPasteFunc
49 if(ScInsertContentsDlg::mxRbNoOp->get_active())
50 officecfg::Office::Common::PasteSpecial::Operations::set(0, batch);
51 else if(ScInsertContentsDlg::mxRbAdd->get_active())
52 officecfg::Office::Common::PasteSpecial::Operations::set(1, batch);
53 else if(ScInsertContentsDlg::mxRbSub->get_active())
54 officecfg::Office::Common::PasteSpecial::Operations::set(2, batch);
55 else if(ScInsertContentsDlg::mxRbMul->get_active())
56 officecfg::Office::Common::PasteSpecial::Operations::set(3, batch);
57 else if(ScInsertContentsDlg::mxRbDiv->get_active())
58 officecfg::Office::Common::PasteSpecial::Operations::set(4, batch);
59
60 //InsertContentsFlags
61 officecfg::Office::Common::PasteSpecial::Options::AsLink::set(ScInsertContentsDlg::mxBtnLink->get_active(), batch);
62 officecfg::Office::Common::PasteSpecial::Options::Transpose::set(ScInsertContentsDlg::mxBtnTranspose->get_active(), batch);
63 officecfg::Office::Common::PasteSpecial::Options::SkipEmptyCells::set(ScInsertContentsDlg::mxBtnSkipEmptyCells->get_active(), batch);
64
65 //InsCellCmd
66 if(ScInsertContentsDlg::mxRbMoveNone->get_active())
67 officecfg::Office::Common::PasteSpecial::ShiftCells::set(4, batch);
68 else if(ScInsertContentsDlg::mxRbMoveDown->get_active())
69 officecfg::Office::Common::PasteSpecial::ShiftCells::set(0, batch);
70 else if(ScInsertContentsDlg::mxRbMoveRight->get_active())
71 officecfg::Office::Common::PasteSpecial::ShiftCells::set(1, batch);
72
73 batch->commit();
74}
75
77 const OUString* pStrTitle )
78 : GenericDialogController(pParent, "modules/scalc/ui/pastespecial.ui", "PasteSpecial")
79 , bOtherDoc(false)
80 , bFillMode(false)
81 , bChangeTrack(false)
82 , bMoveDownDisabled(false)
83 , bMoveRightDisabled(false)
84 , mxBtnInsAll(m_xBuilder->weld_check_button("paste_all"))
85 , mxBtnInsStrings(m_xBuilder->weld_check_button("text"))
86 , mxBtnInsNumbers(m_xBuilder->weld_check_button("numbers"))
87 , mxBtnInsDateTime(m_xBuilder->weld_check_button("datetime"))
88 , mxBtnInsFormulas(m_xBuilder->weld_check_button("formulas"))
89 , mxBtnInsNotes(m_xBuilder->weld_check_button("comments"))
90 , mxBtnInsAttrs(m_xBuilder->weld_check_button("formats"))
91 , mxBtnInsObjects(m_xBuilder->weld_check_button("objects"))
92 , mxBtnSkipEmptyCells(m_xBuilder->weld_check_button("skip_empty"))
93 , mxBtnTranspose(m_xBuilder->weld_check_button("transpose"))
94 , mxBtnLink(m_xBuilder->weld_check_button("link"))
95 , mxRbNoOp(m_xBuilder->weld_radio_button("none"))
96 , mxRbAdd(m_xBuilder->weld_radio_button("add"))
97 , mxRbSub(m_xBuilder->weld_radio_button("subtract"))
98 , mxRbMul(m_xBuilder->weld_radio_button("multiply"))
99 , mxRbDiv(m_xBuilder->weld_radio_button("divide"))
100 , mxRbMoveNone(m_xBuilder->weld_radio_button("no_shift"))
101 , mxRbMoveDown(m_xBuilder->weld_radio_button("move_down"))
102 , mxRbMoveRight(m_xBuilder->weld_radio_button("move_right"))
103 , mxBtnShortCutPasteValuesOnly(m_xBuilder->weld_button("paste_values_only"))
104 , mxBtnShortCutPasteValuesFormats(m_xBuilder->weld_button("paste_values_formats"))
105 , mxBtnShortCutPasteTranspose(m_xBuilder->weld_button("paste_transpose"))
106 , mxBtnShortCutPasteFormats(m_xBuilder->weld_button("paste_formats"))
107 , mxOKBtn(m_xBuilder->weld_button("ok"))
108 , mxImmediately(m_xBuilder->weld_check_button("cbImmediately"))
109{
110 if (pStrTitle)
111 m_xDialog->set_title(*pStrTitle);
112
113 if (firstLoad)
114 {
115 //unset firstLoad
116 firstLoad = false;
117
118 //set the flags from the registry
119
120 /*
121 * Flags for nPreviousChecks
122 */
123 if(officecfg::Office::Common::PasteSpecial::Paste::All::get())
125 if(officecfg::Office::Common::PasteSpecial::Paste::Numbers::get())
127 if(officecfg::Office::Common::PasteSpecial::Paste::Text::get())
129 if(officecfg::Office::Common::PasteSpecial::Paste::DateTime::get())
131 if(officecfg::Office::Common::PasteSpecial::Paste::Formats::get())
133 if(officecfg::Office::Common::PasteSpecial::Paste::Comments::get())
135 if(officecfg::Office::Common::PasteSpecial::Paste::Objects::get())
137 if(officecfg::Office::Common::PasteSpecial::Paste::Formulas::get())
139
140 /*
141 * Flags for nPreviousFormulaChecks
142 */
143 int optionFlagValue = officecfg::Office::Common::PasteSpecial::Operations::get();
144 switch(optionFlagValue)
145 {
147 break;
148
150 break;
151
153 break;
154
156 break;
157
159 break;
160 }
161
162 /*
163 * Flags for nPreviousChecks2
164 */
165 if(officecfg::Office::Common::PasteSpecial::Options::AsLink::get())
167 if(officecfg::Office::Common::PasteSpecial::Options::Transpose::get())
169 if(officecfg::Office::Common::PasteSpecial::Options::SkipEmptyCells::get())
171
172 /*
173 * Flags for nPreviousMoveMode
174 */
175 int shiftFlagValue = officecfg::Office::Common::PasteSpecial::ShiftCells::get();
176 switch(shiftFlagValue)
177 {
179 break;
180
182 break;
183
185 break;
186 }
187 }
188
193 DisableChecks( mxBtnInsAll->get_active() );
194
195 mxBtnInsAll->connect_toggled( LINK( this, ScInsertContentsDlg, InsAllHdl ) );
196 mxBtnLink->connect_toggled( LINK( this, ScInsertContentsDlg, LinkBtnHdl ) );
197 mxBtnShortCutPasteValuesOnly->connect_clicked( LINK( this, ScInsertContentsDlg, ShortCutHdl ) );
198 mxBtnShortCutPasteValuesFormats->connect_clicked( LINK( this, ScInsertContentsDlg, ShortCutHdl ) );
199 mxBtnShortCutPasteTranspose->connect_clicked( LINK( this, ScInsertContentsDlg, ShortCutHdl ) );
200 mxBtnShortCutPasteFormats->connect_clicked( LINK( this, ScInsertContentsDlg, ShortCutHdl ) );
201 mxOKBtn->connect_clicked( LINK( this, ScInsertContentsDlg, ClickHdl ) );
202}
203
205{
207
208 if ( mxBtnInsStrings->get_active() )
210 if ( mxBtnInsNumbers->get_active() )
212 if ( mxBtnInsDateTime->get_active())
214 if ( mxBtnInsFormulas->get_active())
216 // tdf#139858 - do not delete existing cell contents when pasting notes
217 if ( mxBtnInsNotes->get_active() )
219 if ( mxBtnInsAttrs->get_active() )
221 if ( mxBtnInsObjects->get_active() )
223
224 return ( mxBtnInsAll->get_active()
227}
228
230{
239 DisableChecks( mxBtnInsAll->get_active() );
240}
241
243{
244 switch( eFlags )
245 {
246 case ScPasteFunc::NONE: mxRbNoOp->set_active(true); break;
247 case ScPasteFunc::ADD: mxRbAdd->set_active(true); break;
248 case ScPasteFunc::SUB: mxRbSub->set_active(true); break;
249 case ScPasteFunc::MUL: mxRbMul->set_active(true); break;
250 case ScPasteFunc::DIV: mxRbDiv->set_active(true); break;
251 }
252}
253
255{
256 switch( eFlags )
257 {
258 case INS_NONE: mxRbMoveNone->set_active(true); break;
259 case INS_CELLSDOWN: mxRbMoveDown->set_active(true); break;
260 case INS_CELLSRIGHT: mxRbMoveRight->set_active(true); break;
264 case INS_INSCOLS_AFTER: break;
265 }
266}
267
269{
270 mxBtnSkipEmptyCells->set_active(bool(InsertContentsFlags::NoEmpty & eFlags));
271 mxBtnTranspose->set_active(bool(InsertContentsFlags::Trans & eFlags));
272 mxBtnLink->set_active(bool(InsertContentsFlags::Link & eFlags));
273}
274
276{
277 if ( mxRbMoveDown->get_active() )
278 return INS_CELLSDOWN;
279 if ( mxRbMoveRight->get_active() )
280 return INS_CELLSRIGHT;
281
282 return INS_NONE;
283}
284
286{
287 return mxBtnSkipEmptyCells->get_active();
288}
289
291{
292 return mxBtnTranspose->get_active();
293}
294
296{
297 return mxBtnLink->get_active();
298}
299
300void ScInsertContentsDlg::DisableChecks( bool bInsAllChecked )
301{
302 if ( bInsAllChecked )
303 {
304 mxBtnInsStrings->set_sensitive(false);
305 mxBtnInsNumbers->set_sensitive(false);
306 mxBtnInsDateTime->set_sensitive(false);
307 mxBtnInsFormulas->set_sensitive(false);
308 mxBtnInsNotes->set_sensitive(false);
309 mxBtnInsAttrs->set_sensitive(false);
310 mxBtnInsObjects->set_sensitive(false);
311 }
312 else
313 {
314 mxBtnInsStrings->set_sensitive(true);
315 mxBtnInsNumbers->set_sensitive(true);
316 mxBtnInsDateTime->set_sensitive(true);
317 mxBtnInsFormulas->set_sensitive(true);
318 mxBtnInsNotes->set_sensitive(true);
319 mxBtnInsAttrs->set_sensitive(true);
320
321 // "Objects" is disabled for "Fill Tables"
322 if ( bFillMode )
323 mxBtnInsObjects->set_sensitive(false);
324 else
325 mxBtnInsObjects->set_sensitive(true);
326 }
327}
328
329// Link to other document -> everything else is disabled
330
332{
333 if ( bOtherDoc && mxBtnLink->get_active() )
334 {
335 mxBtnSkipEmptyCells->set_sensitive(false);
336 mxBtnTranspose->set_sensitive(false);
337 mxRbNoOp->set_sensitive(false);
338 mxRbAdd->set_sensitive(false);
339 mxRbSub->set_sensitive(false);
340 mxRbMul->set_sensitive(false);
341 mxRbDiv->set_sensitive(false);
342
343 mxRbMoveNone->set_sensitive(false);
344 mxRbMoveDown->set_sensitive(false);
345 mxRbMoveRight->set_sensitive(false);
346
347 mxBtnInsAll->set_sensitive(false);
348 DisableChecks(true);
349 }
350 else
351 {
352 mxBtnSkipEmptyCells->set_sensitive(true);
353 mxBtnTranspose->set_sensitive(!bFillMode);
354 mxRbNoOp->set_sensitive(true);
355 mxRbAdd->set_sensitive(true);
356 mxRbSub->set_sensitive(true);
357 mxRbMul->set_sensitive(true);
358 mxRbDiv->set_sensitive(true);
359
361 mxRbMoveDown->set_sensitive(!bFillMode && !bChangeTrack && !bMoveDownDisabled);
363
364 mxBtnInsAll->set_sensitive(true);
365 DisableChecks( mxBtnInsAll->get_active() );
366 }
367}
368
370{
371 if ( bSet != bOtherDoc )
372 {
373 bOtherDoc = bSet;
374 TestModes();
375 if ( bSet )
376 mxRbMoveNone->set_active(true);
377 }
378}
379
381{
382 if ( bSet != bFillMode )
383 {
384 bFillMode = bSet;
385 TestModes();
386 if ( bSet )
387 mxRbMoveNone->set_active(true);
388 }
389}
390
392{
393 if ( bSet != bChangeTrack )
394 {
395 bChangeTrack = bSet;
396 TestModes();
397 if ( bSet )
398 mxRbMoveNone->set_active(true);
399 }
400}
401
403{
404 bool bDown(nDisable & CellShiftDisabledFlags::Down);
405 bool bRight(nDisable & CellShiftDisabledFlags::Right);
406 if ( bDown != bMoveDownDisabled || bRight != bMoveRightDisabled )
407 {
408 bMoveDownDisabled = bDown;
409 bMoveRightDisabled = bRight;
410 TestModes();
411 if ( bMoveDownDisabled && mxRbMoveDown->get_active() )
412 mxRbMoveNone->set_active(true);
413 if ( bMoveRightDisabled && mxRbMoveRight->get_active() )
414 mxRbMoveNone->set_active(true);
415 }
416}
417
418IMPL_LINK(ScInsertContentsDlg, ShortCutHdl, weld::Button&, rBtn, void)
419{
420 if (&rBtn == mxBtnShortCutPasteValuesOnly.get())
421 {
423 SetContentsFlags( InsertContentsFlags::NONE );
424 }
425 else if (&rBtn == mxBtnShortCutPasteValuesFormats.get())
426 {
428 SetContentsFlags( InsertContentsFlags::NONE );
429 }
430 else if (&rBtn == mxBtnShortCutPasteTranspose.get())
431 {
432 SetInsContentsCmdBits( InsertDeleteFlags::ALL );
433 SetContentsFlags( InsertContentsFlags::Trans );
434 }
435 else if (&rBtn == mxBtnShortCutPasteFormats.get())
436 {
437 SetInsContentsCmdBits( InsertDeleteFlags::ATTRIB );
438 SetContentsFlags( InsertContentsFlags::NONE );
439 }
440 else
441 return;
442
443 SetCellCmdFlags( InsCellCmd::INS_NONE );
444 SetFormulaCmdBits(ScPasteFunc::NONE);
445
446 if (mxImmediately->get_active())
447 {
448 storeFlagsInRegistry();
449 m_xDialog->response(RET_OK);
450 }
451}
452
454{
455 storeFlagsInRegistry();
456 m_xDialog->response(RET_OK);
457}
458
460{
461 DisableChecks( mxBtnInsAll->get_active() );
462}
463
465{
466 TestModes();
467}
468
470{
472 if(mxBtnSkipEmptyCells->get_active())
474 if( mxBtnTranspose->get_active())
476 if( mxBtnLink->get_active() )
478
479 if (!bFillMode) // in FillMode, None is checked and all three options are disabled
480 {
481 if ( mxRbMoveNone->get_active() )
483 else if ( mxRbMoveDown->get_active() )
485 else if ( mxRbMoveRight->get_active() )
487 }
488}
489
491{
493 if(mxRbAdd->get_active())
495 else if(mxRbSub->get_active())
497 else if(mxRbMul->get_active())
499 else if(mxRbDiv->get_active())
502}
503
504/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
std::unique_ptr< weld::CheckButton > mxBtnInsNotes
Definition: inscodlg.hxx:64
void SetCellShiftDisabled(CellShiftDisabledFlags nDisable)
Definition: inscodlg.cxx:402
static InsertDeleteFlags nPreviousChecks
Definition: inscodlg.hxx:90
std::unique_ptr< weld::RadioButton > mxRbDiv
Definition: inscodlg.hxx:76
void DisableChecks(bool bInsAllChecked)
Definition: inscodlg.cxx:300
ScInsertContentsDlg(weld::Window *pParent, const OUString *pStrTitle)
Definition: inscodlg.cxx:76
void SetInsContentsCmdBits(const InsertDeleteFlags eFlags)
Definition: inscodlg.cxx:229
static ScPasteFunc nPreviousFormulaChecks
Definition: inscodlg.hxx:92
std::unique_ptr< weld::CheckButton > mxBtnInsAll
Definition: inscodlg.hxx:59
bool IsLink() const
Definition: inscodlg.cxx:295
std::unique_ptr< weld::CheckButton > mxBtnLink
Definition: inscodlg.hxx:70
std::unique_ptr< weld::Button > mxBtnShortCutPasteTranspose
Definition: inscodlg.hxx:84
std::unique_ptr< weld::RadioButton > mxRbMul
Definition: inscodlg.hxx:75
std::unique_ptr< weld::CheckButton > mxBtnInsDateTime
Definition: inscodlg.hxx:62
InsCellCmd GetMoveMode() const
Definition: inscodlg.cxx:275
std::unique_ptr< weld::CheckButton > mxBtnInsNumbers
Definition: inscodlg.hxx:61
void SetFormulaCmdBits(const ScPasteFunc eFlags)
Definition: inscodlg.cxx:242
virtual ~ScInsertContentsDlg() override
Definition: inscodlg.cxx:469
std::unique_ptr< weld::Button > mxBtnShortCutPasteFormats
Definition: inscodlg.hxx:85
InsertDeleteFlags GetInsContentsCmdBits() const
Definition: inscodlg.cxx:204
std::unique_ptr< weld::Button > mxBtnShortCutPasteValuesFormats
Definition: inscodlg.hxx:83
std::unique_ptr< weld::RadioButton > mxRbMoveRight
Definition: inscodlg.hxx:80
std::unique_ptr< weld::Button > mxBtnShortCutPasteValuesOnly
Definition: inscodlg.hxx:82
static InsCellCmd nPreviousMoveMode
Definition: inscodlg.hxx:93
void SetCellCmdFlags(const InsCellCmd eFlags)
Definition: inscodlg.cxx:254
bool IsSkipEmptyCells() const
Definition: inscodlg.cxx:285
void SetChangeTrack(bool bSet)
Definition: inscodlg.cxx:391
std::unique_ptr< weld::Button > mxOKBtn
Definition: inscodlg.hxx:86
std::unique_ptr< weld::RadioButton > mxRbAdd
Definition: inscodlg.hxx:73
std::unique_ptr< weld::RadioButton > mxRbMoveDown
Definition: inscodlg.hxx:79
std::unique_ptr< weld::RadioButton > mxRbMoveNone
Definition: inscodlg.hxx:78
std::unique_ptr< weld::RadioButton > mxRbNoOp
Definition: inscodlg.hxx:72
static InsertContentsFlags nPreviousChecks2
Definition: inscodlg.hxx:91
ScPasteFunc GetFormulaCmdBits() const
Definition: inscodlg.cxx:490
void SetContentsFlags(const InsertContentsFlags eFlags)
Definition: inscodlg.cxx:268
std::unique_ptr< weld::RadioButton > mxRbSub
Definition: inscodlg.hxx:74
bool IsTranspose() const
Definition: inscodlg.cxx:290
void SetFillMode(bool bSet)
Definition: inscodlg.cxx:380
void SetOtherDoc(bool bSet)
Definition: inscodlg.cxx:369
std::unique_ptr< weld::CheckButton > mxBtnTranspose
Definition: inscodlg.hxx:69
std::unique_ptr< weld::CheckButton > mxBtnInsFormulas
Definition: inscodlg.hxx:63
std::unique_ptr< weld::CheckButton > mxBtnSkipEmptyCells
Definition: inscodlg.hxx:68
void storeFlagsInRegistry()
Definition: inscodlg.cxx:33
std::unique_ptr< weld::CheckButton > mxBtnInsStrings
Definition: inscodlg.hxx:60
std::unique_ptr< weld::CheckButton > mxBtnInsObjects
Definition: inscodlg.hxx:66
std::unique_ptr< weld::CheckButton > mxBtnInsAttrs
Definition: inscodlg.hxx:65
static std::shared_ptr< ConfigurationChanges > create()
std::shared_ptr< weld::Dialog > m_xDialog
ScPasteFunc
Definition: global.hxx:181
InsCellCmd
Definition: global.hxx:290
@ INS_INSROWS_AFTER
Definition: global.hxx:296
@ INS_NONE
Definition: global.hxx:295
@ INS_INSCOLS_AFTER
Definition: global.hxx:297
@ INS_CELLSDOWN
Definition: global.hxx:291
@ INS_INSCOLS_BEFORE
Definition: global.hxx:294
@ INS_CELLSRIGHT
Definition: global.hxx:292
@ INS_INSROWS_BEFORE
Definition: global.hxx:293
InsertDeleteFlags
Definition: global.hxx:149
@ NOTE
Strings (and string results if InsertDeleteFlags::FORMULA is not set).
@ OBJECTS
Cell styles.
@ STRING
Dates, times, datetime values.
@ ADDNOTES
Internal use only (undo etc.): do not copy/delete caption objects of cell notes.
@ DATETIME
Numeric values (and numeric results if InsertDeleteFlags::FORMULA is not set).
@ ATTRIB
Internal use only (d&d undo): do not delete caption objects of cell notes.
@ FORMULA
Cell notes.
IMPL_LINK_NOARG(ScInsertContentsDlg, ClickHdl, weld::Button &, void)
Definition: inscodlg.cxx:453
IMPL_LINK(ScInsertContentsDlg, ShortCutHdl, weld::Button &, rBtn, void)
Definition: inscodlg.cxx:418
static bool firstLoad
Definition: inscodlg.cxx:31
InsertContentsFlags
Definition: scui_def.hxx:31
CellShiftDisabledFlags
Definition: scui_def.hxx:41
RET_OK