Use correct object
[LibreOffice.git] / cui / source / options / optctl.cxx
blobfca642fdbb388c107c9a4c8b50268e43ebb233be
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 "optctl.hxx"
21 #include <svl/ctloptions.hxx>
22 #include <sal/log.hxx>
23 #include <tools/debug.hxx>
25 // class SvxCTLOptionsPage -----------------------------------------------------
27 IMPL_LINK_NOARG(SvxCTLOptionsPage, SequenceCheckingCB_Hdl, weld::Toggleable&, void)
29 bool bIsSequenceChecking = m_xSequenceCheckingCB->get_active();
30 m_xRestrictedCB->set_sensitive( bIsSequenceChecking );
31 m_xTypeReplaceCB->set_sensitive( bIsSequenceChecking );
32 // #i48117#: by default restricted and type&replace have to be switched on
33 if (bIsSequenceChecking)
35 m_xTypeReplaceCB->set_active(true);
36 m_xRestrictedCB->set_active(true);
40 SvxCTLOptionsPage::SvxCTLOptionsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
41 : SfxTabPage(pPage, pController, u"cui/ui/optctlpage.ui"_ustr, u"OptCTLPage"_ustr, &rSet)
42 , m_xSequenceCheckingCB(m_xBuilder->weld_check_button(u"sequencechecking"_ustr))
43 , m_xRestrictedCB(m_xBuilder->weld_check_button(u"restricted"_ustr))
44 , m_xTypeReplaceCB(m_xBuilder->weld_check_button(u"typeandreplace"_ustr))
45 , m_xMovementLogicalRB(m_xBuilder->weld_radio_button(u"movementlogical"_ustr))
46 , m_xMovementVisualRB(m_xBuilder->weld_radio_button(u"movementvisual"_ustr))
47 , m_xNumeralsLB(m_xBuilder->weld_combo_box(u"numerals"_ustr))
49 m_xSequenceCheckingCB->connect_toggled(LINK(this, SvxCTLOptionsPage, SequenceCheckingCB_Hdl));
52 SvxCTLOptionsPage::~SvxCTLOptionsPage()
56 std::unique_ptr<SfxTabPage> SvxCTLOptionsPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
58 return std::make_unique<SvxCTLOptionsPage>( pPage, pController, *rAttrSet );
61 OUString SvxCTLOptionsPage::GetAllStrings()
63 OUString sAllStrings;
64 OUString labels[] = { u"label1"_ustr, u"label2"_ustr, u"label3"_ustr, u"label4"_ustr, u"label5"_ustr };
66 for (const auto& label : labels)
68 if (const auto pString = m_xBuilder->weld_label(label))
69 sAllStrings += pString->get_label() + " ";
72 OUString checkButton[] = { u"sequencechecking"_ustr, u"restricted"_ustr, u"typeandreplace"_ustr };
74 for (const auto& check : checkButton)
76 if (const auto pString = m_xBuilder->weld_check_button(check))
77 sAllStrings += pString->get_label() + " ";
80 OUString radioButton[] = { u"movementlogical"_ustr, u"movementvisual"_ustr };
82 for (const auto& radio : radioButton)
84 if (const auto pString = m_xBuilder->weld_radio_button(radio))
85 sAllStrings += pString->get_label() + " ";
88 return sAllStrings.replaceAll("_", "");
91 bool SvxCTLOptionsPage::FillItemSet( SfxItemSet* )
93 bool bModified = false;
94 SvtCTLOptions aCTLOptions;
96 // Sequence checking
97 bool bChecked = m_xSequenceCheckingCB->get_active();
98 if ( m_xSequenceCheckingCB->get_state_changed_from_saved() )
100 aCTLOptions.SetCTLSequenceChecking( bChecked );
101 bModified = true;
104 bChecked = m_xRestrictedCB->get_active();
105 if( m_xRestrictedCB->get_state_changed_from_saved() )
107 aCTLOptions.SetCTLSequenceCheckingRestricted( bChecked );
108 bModified = true;
110 bChecked = m_xTypeReplaceCB->get_active();
111 if( m_xTypeReplaceCB->get_state_changed_from_saved())
113 aCTLOptions.SetCTLSequenceCheckingTypeAndReplace(bChecked);
114 bModified = true;
117 bool bLogicalChecked = m_xMovementLogicalRB->get_active();
118 if ( m_xMovementLogicalRB->get_state_changed_from_saved() ||
119 m_xMovementVisualRB->get_state_changed_from_saved() )
121 SvtCTLOptions::CursorMovement eMovement =
122 bLogicalChecked ? SvtCTLOptions::MOVEMENT_LOGICAL : SvtCTLOptions::MOVEMENT_VISUAL;
123 aCTLOptions.SetCTLCursorMovement( eMovement );
124 bModified = true;
127 if (m_xNumeralsLB->get_value_changed_from_saved())
129 const sal_Int32 nPos = m_xNumeralsLB->get_active();
130 aCTLOptions.SetCTLTextNumerals( static_cast<SvtCTLOptions::TextNumerals>(nPos) );
131 bModified = true;
134 return bModified;
137 void SvxCTLOptionsPage::Reset( const SfxItemSet* )
139 m_xSequenceCheckingCB->set_active( SvtCTLOptions::IsCTLSequenceChecking() );
140 m_xRestrictedCB->set_active( SvtCTLOptions::IsCTLSequenceCheckingRestricted() );
141 m_xTypeReplaceCB->set_active( SvtCTLOptions::IsCTLSequenceCheckingTypeAndReplace() );
143 SvtCTLOptions::CursorMovement eMovement = SvtCTLOptions::GetCTLCursorMovement();
144 switch ( eMovement )
146 case SvtCTLOptions::MOVEMENT_LOGICAL :
147 m_xMovementLogicalRB->set_active(true);
148 break;
150 case SvtCTLOptions::MOVEMENT_VISUAL :
151 m_xMovementVisualRB->set_active(true);
152 break;
154 default:
155 SAL_WARN( "cui.options", "SvxCTLOptionsPage::Reset(): invalid movement enum" );
158 sal_uInt16 nPos = static_cast<sal_uInt16>(SvtCTLOptions::GetCTLTextNumerals());
159 DBG_ASSERT( nPos < m_xNumeralsLB->get_count(), "SvxCTLOptionsPage::Reset(): invalid numerals enum" );
160 m_xNumeralsLB->set_active(nPos);
162 m_xSequenceCheckingCB->save_state();
163 m_xRestrictedCB->save_state();
164 m_xTypeReplaceCB->save_state();
165 m_xMovementLogicalRB->save_state();
166 m_xMovementVisualRB->save_state();
167 m_xNumeralsLB->save_value();
169 bool bIsSequenceChecking = m_xSequenceCheckingCB->get_active();
170 m_xRestrictedCB->set_sensitive( bIsSequenceChecking );
171 m_xTypeReplaceCB->set_sensitive( bIsSequenceChecking );
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */