Line data Source code
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 "basidesh.hxx"
21 : #include "basobj.hxx"
22 : #include "iderdll.hxx"
23 : #include "iderid.hxx"
24 : #include "localizationmgr.hxx"
25 : #include "managelang.hxx"
26 :
27 : #include "dlgresid.hrc"
28 : #include "helpid.hrc"
29 :
30 : #include <com/sun/star/i18n/Boundary.hpp>
31 : #include <com/sun/star/i18n/WordType.hpp>
32 : #include <com/sun/star/i18n/XBreakIterator.hpp>
33 : #include <editeng/unolingu.hxx>
34 : #include <sfx2/bindings.hxx>
35 : #include <svtools/langtab.hxx>
36 : #include <svx/langbox.hxx>
37 : #include <vcl/unohelp.hxx>
38 : #include <vcl/svapp.hxx>
39 : #include <vcl/layout.hxx>
40 : #include <vcl/settings.hxx>
41 :
42 : namespace basctl
43 : {
44 :
45 : using namespace ::com::sun::star::i18n;
46 : using namespace ::com::sun::star::lang;
47 : using namespace ::com::sun::star::resource;
48 : using namespace ::com::sun::star::uno;
49 :
50 0 : bool localesAreEqual( const Locale& rLocaleLeft, const Locale& rLocaleRight )
51 : {
52 0 : bool bRet = ( rLocaleLeft.Language.equals( rLocaleRight.Language ) &&
53 0 : rLocaleLeft.Country.equals( rLocaleRight.Country ) &&
54 0 : rLocaleLeft.Variant.equals( rLocaleRight.Variant ) );
55 0 : return bRet;
56 : }
57 :
58 0 : ManageLanguageDialog::ManageLanguageDialog(vcl::Window* pParent, boost::shared_ptr<LocalizationMgr> xLMgr)
59 : : ModalDialog(pParent, "ManageLanguagesDialog", "modules/BasicIDE/ui/managelanguages.ui")
60 : , m_xLocalizationMgr(xLMgr)
61 : , m_sDefLangStr(IDE_RESSTR(RID_STR_DEF_LANG))
62 0 : , m_sCreateLangStr(IDE_RESSTR(RID_STR_CREATE_LANG))
63 : {
64 0 : get(m_pLanguageLB, "treeview");
65 0 : m_pLanguageLB->set_height_request(m_pLanguageLB->GetTextHeight() * 10);
66 0 : m_pLanguageLB->set_width_request(m_pLanguageLB->approximate_char_width() * 50);
67 0 : get(m_pAddPB, "add");
68 0 : get(m_pDeletePB, "delete");
69 0 : get(m_pMakeDefPB, "default");
70 :
71 0 : Init();
72 0 : FillLanguageBox();
73 0 : SelectHdl( NULL );
74 0 : }
75 :
76 0 : ManageLanguageDialog::~ManageLanguageDialog()
77 : {
78 0 : disposeOnce();
79 0 : }
80 :
81 0 : void ManageLanguageDialog::dispose()
82 : {
83 0 : ClearLanguageBox();
84 0 : m_pLanguageLB.clear();
85 0 : m_pAddPB.clear();
86 0 : m_pDeletePB.clear();
87 0 : m_pMakeDefPB.clear();
88 0 : ModalDialog::dispose();
89 0 : }
90 :
91 0 : void ManageLanguageDialog::Init()
92 : {
93 : // get current IDE
94 0 : Shell* pShell = GetShell();
95 0 : OUString sLibName = pShell->GetCurLibName();
96 : // set dialog title with library name
97 0 : OUString sText = GetText();
98 0 : sText = sText.replaceAll("$1", sLibName);
99 0 : SetText( sText );
100 : // set handler
101 0 : m_pAddPB->SetClickHdl( LINK( this, ManageLanguageDialog, AddHdl ) );
102 0 : m_pDeletePB->SetClickHdl( LINK( this, ManageLanguageDialog, DeleteHdl ) );
103 0 : m_pMakeDefPB->SetClickHdl( LINK( this, ManageLanguageDialog, MakeDefHdl ) );
104 0 : m_pLanguageLB->SetSelectHdl( LINK( this, ManageLanguageDialog, SelectHdl ) );
105 :
106 0 : m_pLanguageLB->EnableMultiSelection( true );
107 0 : }
108 :
109 0 : void ManageLanguageDialog::FillLanguageBox()
110 : {
111 : DBG_ASSERT( m_xLocalizationMgr, "ManageLanguageDialog::FillLanguageBox(): no localization manager" );
112 :
113 0 : if ( m_xLocalizationMgr->isLibraryLocalized() )
114 : {
115 0 : Locale aDefaultLocale = m_xLocalizationMgr->getStringResourceManager()->getDefaultLocale();
116 0 : Sequence< Locale > aLocaleSeq = m_xLocalizationMgr->getStringResourceManager()->getLocales();
117 0 : const Locale* pLocale = aLocaleSeq.getConstArray();
118 0 : sal_Int32 i, nCount = aLocaleSeq.getLength();
119 0 : for ( i = 0; i < nCount; ++i )
120 : {
121 0 : bool bIsDefault = localesAreEqual( aDefaultLocale, pLocale[i] );
122 0 : LanguageType eLangType = LanguageTag::convertToLanguageType( pLocale[i] );
123 0 : OUString sLanguage = SvtLanguageTable::GetLanguageString( eLangType );
124 0 : if ( bIsDefault )
125 : {
126 0 : sLanguage += " " + m_sDefLangStr;
127 : }
128 0 : sal_uInt16 nPos = m_pLanguageLB->InsertEntry( sLanguage );
129 0 : m_pLanguageLB->SetEntryData( nPos, new LanguageEntry( sLanguage, pLocale[i], bIsDefault ) );
130 0 : }
131 : }
132 : else
133 0 : m_pLanguageLB->InsertEntry( m_sCreateLangStr );
134 0 : }
135 :
136 0 : void ManageLanguageDialog::ClearLanguageBox()
137 : {
138 0 : sal_uInt16 i, nCount = m_pLanguageLB->GetEntryCount();
139 0 : for ( i = 0; i < nCount; ++i )
140 : {
141 0 : LanguageEntry* pEntry = static_cast<LanguageEntry*>(m_pLanguageLB->GetEntryData(i));
142 0 : delete pEntry;
143 : }
144 0 : m_pLanguageLB->Clear();
145 0 : }
146 :
147 0 : IMPL_LINK_NOARG(ManageLanguageDialog, AddHdl)
148 : {
149 0 : ScopedVclPtrInstance< SetDefaultLanguageDialog > aDlg( this, m_xLocalizationMgr );
150 0 : if ( RET_OK == aDlg->Execute() )
151 : {
152 : // add new locales
153 0 : Sequence< Locale > aLocaleSeq = aDlg->GetLocales();
154 0 : m_xLocalizationMgr->handleAddLocales( aLocaleSeq );
155 : // update listbox
156 0 : ClearLanguageBox();
157 0 : FillLanguageBox();
158 :
159 0 : if (SfxBindings* pBindings = GetBindingsPtr())
160 0 : pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG );
161 : }
162 0 : return 1;
163 : }
164 :
165 0 : IMPL_LINK_NOARG(ManageLanguageDialog, DeleteHdl)
166 : {
167 0 : ScopedVclPtrInstance< MessageDialog > aQBox(this, "DeleteLangDialog", "modules/BasicIDE/ui/deletelang.ui");
168 0 : if ( aQBox->Execute() == RET_OK )
169 : {
170 0 : sal_uInt16 i, nCount = m_pLanguageLB->GetSelectEntryCount();
171 0 : sal_uInt16 nPos = m_pLanguageLB->GetSelectEntryPos();
172 : // remove locales
173 0 : Sequence< Locale > aLocaleSeq( nCount );
174 0 : for ( i = 0; i < nCount; ++i )
175 : {
176 0 : sal_uInt16 nSelPos = m_pLanguageLB->GetSelectEntryPos(i);
177 0 : LanguageEntry* pEntry = static_cast<LanguageEntry*>(m_pLanguageLB->GetEntryData( nSelPos ));
178 0 : if ( pEntry )
179 0 : aLocaleSeq[i] = pEntry->m_aLocale;
180 : }
181 0 : m_xLocalizationMgr->handleRemoveLocales( aLocaleSeq );
182 : // update listbox
183 0 : ClearLanguageBox();
184 0 : FillLanguageBox();
185 : // reset selection
186 0 : nCount = m_pLanguageLB->GetEntryCount();
187 0 : if ( nCount <= nPos )
188 0 : nPos = nCount - 1;
189 0 : m_pLanguageLB->SelectEntryPos( nPos );
190 0 : SelectHdl( NULL );
191 : }
192 0 : return 1;
193 : }
194 :
195 0 : IMPL_LINK_NOARG(ManageLanguageDialog, MakeDefHdl)
196 : {
197 0 : sal_uInt16 nPos = m_pLanguageLB->GetSelectEntryPos();
198 0 : LanguageEntry* pSelectEntry = static_cast<LanguageEntry*>(m_pLanguageLB->GetEntryData( nPos ));
199 0 : if ( pSelectEntry && !pSelectEntry->m_bIsDefault )
200 : {
201 : // set new default entry
202 0 : m_xLocalizationMgr->handleSetDefaultLocale( pSelectEntry->m_aLocale );
203 : // update Listbox
204 0 : ClearLanguageBox();
205 0 : FillLanguageBox();
206 : // reset selection
207 0 : m_pLanguageLB->SelectEntryPos( nPos );
208 0 : SelectHdl( NULL );
209 : }
210 :
211 0 : return 1;
212 : }
213 :
214 0 : IMPL_LINK_NOARG(ManageLanguageDialog, SelectHdl)
215 : {
216 0 : sal_uInt16 nCount = m_pLanguageLB->GetEntryCount();
217 0 : bool bEmpty = ( !nCount ||
218 0 : m_pLanguageLB->GetEntryPos( m_sCreateLangStr ) != LISTBOX_ENTRY_NOTFOUND );
219 0 : bool bSelect = ( m_pLanguageLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND );
220 0 : bool bEnable = !bEmpty && bSelect;
221 :
222 0 : m_pDeletePB->Enable(bEnable);
223 0 : m_pMakeDefPB->Enable(bEnable && nCount > 1 && m_pLanguageLB->GetSelectEntryCount() == 1);
224 :
225 0 : return 1;
226 : }
227 :
228 : // class SetDefaultLanguageDialog -----------------------------------------------
229 :
230 0 : SetDefaultLanguageDialog::SetDefaultLanguageDialog(vcl::Window* pParent, boost::shared_ptr<LocalizationMgr> xLMgr)
231 : : ModalDialog(pParent, "DefaultLanguageDialog", "modules/BasicIDE/ui/defaultlanguage.ui")
232 : , m_pCheckLangLB(NULL)
233 0 : , m_xLocalizationMgr(xLMgr)
234 : {
235 0 : get(m_pLanguageLB, "entries");
236 0 : get(m_pCheckLangLB, "checkedentries");
237 0 : get(m_pDefinedFT, "defined");
238 0 : get(m_pAddedFT, "added");
239 0 : get(m_pLanguageFT, "defaultlabel");
240 0 : get(m_pCheckLangFT, "checkedlabel");
241 :
242 0 : m_pLanguageLB->set_height_request(m_pLanguageLB->GetTextHeight() * 10);
243 0 : m_pCheckLangLB->set_height_request(m_pCheckLangLB->GetTextHeight() * 10);
244 :
245 0 : if (m_xLocalizationMgr->isLibraryLocalized())
246 : {
247 : // change to "Add Interface Language" mode
248 0 : m_pLanguageLB->Hide();
249 0 : m_pCheckLangLB->Show();
250 0 : SetText(get<FixedText>("alttitle")->GetText());
251 0 : m_pLanguageFT->Hide();
252 0 : m_pCheckLangFT->Show();
253 0 : m_pDefinedFT->Hide();
254 0 : m_pAddedFT->Show();
255 : }
256 :
257 0 : FillLanguageBox();
258 0 : }
259 :
260 0 : SetDefaultLanguageDialog::~SetDefaultLanguageDialog()
261 : {
262 0 : disposeOnce();
263 0 : }
264 :
265 0 : void SetDefaultLanguageDialog::dispose()
266 : {
267 0 : m_pLanguageFT.clear();
268 0 : m_pLanguageLB.clear();
269 0 : m_pCheckLangFT.clear();
270 0 : m_pCheckLangLB.clear();
271 0 : m_pDefinedFT.clear();
272 0 : m_pAddedFT.clear();
273 0 : ModalDialog::dispose();
274 0 : }
275 :
276 0 : void SetDefaultLanguageDialog::FillLanguageBox()
277 : {
278 : // fill list with all languages
279 0 : m_pLanguageLB->SetLanguageList( SvxLanguageListFlags::ALL, false );
280 : // remove the already localized languages
281 0 : Sequence< Locale > aLocaleSeq = m_xLocalizationMgr->getStringResourceManager()->getLocales();
282 0 : const Locale* pLocale = aLocaleSeq.getConstArray();
283 0 : sal_Int32 i, nCount = aLocaleSeq.getLength();
284 0 : for ( i = 0; i < nCount; ++i )
285 0 : m_pLanguageLB->RemoveLanguage( LanguageTag::convertToLanguageType( pLocale[i] ) );
286 :
287 : // fill checklistbox if not in default mode
288 0 : if ( m_xLocalizationMgr->isLibraryLocalized() )
289 : {
290 0 : sal_uInt16 j, nCount_ = m_pLanguageLB->GetEntryCount();
291 0 : for ( j = 0; j < nCount_; ++j )
292 : {
293 : m_pCheckLangLB->InsertEntry(
294 0 : m_pLanguageLB->GetEntry(j), LISTBOX_APPEND, m_pLanguageLB->GetEntryData(j) );
295 : }
296 0 : m_pLanguageLB = NULL;
297 : }
298 : else
299 : // preselect current UI language
300 0 : m_pLanguageLB->SelectLanguage( Application::GetSettings().GetUILanguageTag().getLanguageType() );
301 0 : }
302 :
303 0 : Sequence< Locale > SetDefaultLanguageDialog::GetLocales() const
304 : {
305 0 : bool bNotLocalized = !m_xLocalizationMgr->isLibraryLocalized();
306 0 : sal_Int32 nSize = bNotLocalized ? 1 : m_pCheckLangLB->GetCheckedEntryCount();
307 0 : Sequence< Locale > aLocaleSeq( nSize );
308 0 : if ( bNotLocalized )
309 : {
310 0 : aLocaleSeq[0] = LanguageTag( m_pLanguageLB->GetSelectLanguage() ).getLocale();
311 : }
312 : else
313 : {
314 0 : sal_uInt16 i, nCount = static_cast< sal_uInt16 >( m_pCheckLangLB->GetEntryCount() );
315 0 : sal_Int32 j = 0;
316 0 : for ( i = 0; i < nCount; ++i )
317 : {
318 0 : if ( m_pCheckLangLB->IsChecked(i) )
319 : {
320 0 : LanguageType eType = LanguageType( reinterpret_cast<sal_uLong>(m_pCheckLangLB->GetEntryData(i)) );
321 0 : aLocaleSeq[j++] = LanguageTag::convertToLocale( eType );
322 : }
323 : }
324 : DBG_ASSERT( nSize == j, "SetDefaultLanguageDialog::GetLocales(): invalid indexes" );
325 : }
326 0 : return aLocaleSeq;
327 : }
328 :
329 0 : } // namespace basctl
330 :
331 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|