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 : ClearLanguageBox();
79 0 : }
80 :
81 0 : void ManageLanguageDialog::Init()
82 : {
83 : // get current IDE
84 0 : Shell* pShell = GetShell();
85 0 : OUString sLibName = pShell->GetCurLibName();
86 : // set dialog title with library name
87 0 : OUString sText = GetText();
88 0 : sText = sText.replaceAll("$1", sLibName);
89 0 : SetText( sText );
90 : // set handler
91 0 : m_pAddPB->SetClickHdl( LINK( this, ManageLanguageDialog, AddHdl ) );
92 0 : m_pDeletePB->SetClickHdl( LINK( this, ManageLanguageDialog, DeleteHdl ) );
93 0 : m_pMakeDefPB->SetClickHdl( LINK( this, ManageLanguageDialog, MakeDefHdl ) );
94 0 : m_pLanguageLB->SetSelectHdl( LINK( this, ManageLanguageDialog, SelectHdl ) );
95 :
96 0 : m_pLanguageLB->EnableMultiSelection( true );
97 0 : }
98 :
99 0 : void ManageLanguageDialog::FillLanguageBox()
100 : {
101 : DBG_ASSERT( m_xLocalizationMgr, "ManageLanguageDialog::FillLanguageBox(): no localization manager" );
102 :
103 0 : if ( m_xLocalizationMgr->isLibraryLocalized() )
104 : {
105 0 : Locale aDefaultLocale = m_xLocalizationMgr->getStringResourceManager()->getDefaultLocale();
106 0 : Sequence< Locale > aLocaleSeq = m_xLocalizationMgr->getStringResourceManager()->getLocales();
107 0 : const Locale* pLocale = aLocaleSeq.getConstArray();
108 0 : sal_Int32 i, nCount = aLocaleSeq.getLength();
109 0 : for ( i = 0; i < nCount; ++i )
110 : {
111 0 : bool bIsDefault = localesAreEqual( aDefaultLocale, pLocale[i] );
112 0 : LanguageType eLangType = LanguageTag::convertToLanguageType( pLocale[i] );
113 0 : OUString sLanguage = SvtLanguageTable::GetLanguageString( eLangType );
114 0 : if ( bIsDefault )
115 : {
116 0 : sLanguage += " " + m_sDefLangStr;
117 : }
118 0 : sal_uInt16 nPos = m_pLanguageLB->InsertEntry( sLanguage );
119 0 : m_pLanguageLB->SetEntryData( nPos, new LanguageEntry( sLanguage, pLocale[i], bIsDefault ) );
120 0 : }
121 : }
122 : else
123 0 : m_pLanguageLB->InsertEntry( m_sCreateLangStr );
124 0 : }
125 :
126 0 : void ManageLanguageDialog::ClearLanguageBox()
127 : {
128 0 : sal_uInt16 i, nCount = m_pLanguageLB->GetEntryCount();
129 0 : for ( i = 0; i < nCount; ++i )
130 : {
131 0 : LanguageEntry* pEntry = (LanguageEntry*)( m_pLanguageLB->GetEntryData(i) );
132 0 : delete pEntry;
133 : }
134 0 : m_pLanguageLB->Clear();
135 0 : }
136 :
137 0 : IMPL_LINK_NOARG(ManageLanguageDialog, AddHdl)
138 : {
139 0 : SetDefaultLanguageDialog aDlg( this, m_xLocalizationMgr );
140 0 : if ( RET_OK == aDlg.Execute() )
141 : {
142 : // add new locales
143 0 : Sequence< Locale > aLocaleSeq = aDlg.GetLocales();
144 0 : m_xLocalizationMgr->handleAddLocales( aLocaleSeq );
145 : // update listbox
146 0 : ClearLanguageBox();
147 0 : FillLanguageBox();
148 :
149 0 : if (SfxBindings* pBindings = GetBindingsPtr())
150 0 : pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG );
151 : }
152 0 : return 1;
153 : }
154 :
155 0 : IMPL_LINK_NOARG(ManageLanguageDialog, DeleteHdl)
156 : {
157 0 : MessageDialog aQBox(this, "DeleteLangDialog", "modules/BasicIDE/ui/deletelang.ui");
158 0 : if ( aQBox.Execute() == RET_OK )
159 : {
160 0 : sal_uInt16 i, nCount = m_pLanguageLB->GetSelectEntryCount();
161 0 : sal_uInt16 nPos = m_pLanguageLB->GetSelectEntryPos();
162 : // remove locales
163 0 : Sequence< Locale > aLocaleSeq( nCount );
164 0 : for ( i = 0; i < nCount; ++i )
165 : {
166 0 : sal_uInt16 nSelPos = m_pLanguageLB->GetSelectEntryPos(i);
167 0 : LanguageEntry* pEntry = (LanguageEntry*)( m_pLanguageLB->GetEntryData( nSelPos ) );
168 0 : if ( pEntry )
169 0 : aLocaleSeq[i] = pEntry->m_aLocale;
170 : }
171 0 : m_xLocalizationMgr->handleRemoveLocales( aLocaleSeq );
172 : // update listbox
173 0 : ClearLanguageBox();
174 0 : FillLanguageBox();
175 : // reset selection
176 0 : nCount = m_pLanguageLB->GetEntryCount();
177 0 : if ( nCount <= nPos )
178 0 : nPos = nCount - 1;
179 0 : m_pLanguageLB->SelectEntryPos( nPos );
180 0 : SelectHdl( NULL );
181 : }
182 0 : return 1;
183 : }
184 :
185 0 : IMPL_LINK_NOARG(ManageLanguageDialog, MakeDefHdl)
186 : {
187 0 : sal_uInt16 nPos = m_pLanguageLB->GetSelectEntryPos();
188 0 : LanguageEntry* pSelectEntry = (LanguageEntry*)( m_pLanguageLB->GetEntryData( nPos ) );
189 0 : if ( pSelectEntry && !pSelectEntry->m_bIsDefault )
190 : {
191 : // set new default entry
192 0 : m_xLocalizationMgr->handleSetDefaultLocale( pSelectEntry->m_aLocale );
193 : // update Listbox
194 0 : ClearLanguageBox();
195 0 : FillLanguageBox();
196 : // reset selection
197 0 : m_pLanguageLB->SelectEntryPos( nPos );
198 0 : SelectHdl( NULL );
199 : }
200 :
201 0 : return 1;
202 : }
203 :
204 0 : IMPL_LINK_NOARG(ManageLanguageDialog, SelectHdl)
205 : {
206 0 : sal_uInt16 nCount = m_pLanguageLB->GetEntryCount();
207 0 : bool bEmpty = ( !nCount ||
208 0 : m_pLanguageLB->GetEntryPos( m_sCreateLangStr ) != LISTBOX_ENTRY_NOTFOUND );
209 0 : bool bSelect = ( m_pLanguageLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND );
210 0 : bool bEnable = !bEmpty && bSelect;
211 :
212 0 : m_pDeletePB->Enable(bEnable);
213 0 : m_pMakeDefPB->Enable(bEnable && nCount > 1 && m_pLanguageLB->GetSelectEntryCount() == 1);
214 :
215 0 : return 1;
216 : }
217 :
218 : // class SetDefaultLanguageDialog -----------------------------------------------
219 :
220 0 : SetDefaultLanguageDialog::SetDefaultLanguageDialog(vcl::Window* pParent, boost::shared_ptr<LocalizationMgr> xLMgr)
221 : : ModalDialog(pParent, "DefaultLanguageDialog", "modules/BasicIDE/ui/defaultlanguage.ui")
222 : , m_pCheckLangLB(NULL)
223 0 : , m_xLocalizationMgr(xLMgr)
224 : {
225 0 : get(m_pLanguageLB, "entries");
226 0 : get(m_pCheckLangLB, "checkedentries");
227 0 : get(m_pDefinedFT, "defined");
228 0 : get(m_pAddedFT, "added");
229 0 : get(m_pLanguageFT, "defaultlabel");
230 0 : get(m_pCheckLangFT, "checkedlabel");
231 :
232 0 : m_pLanguageLB->set_height_request(m_pLanguageLB->GetTextHeight() * 10);
233 0 : m_pCheckLangLB->set_height_request(m_pCheckLangLB->GetTextHeight() * 10);
234 :
235 0 : if (m_xLocalizationMgr->isLibraryLocalized())
236 : {
237 : // change to "Add Interface Language" mode
238 0 : m_pLanguageLB->Hide();
239 0 : m_pCheckLangLB->Show();
240 0 : SetText(get<FixedText>("alttitle")->GetText());
241 0 : m_pLanguageFT->Hide();
242 0 : m_pCheckLangFT->Show();
243 0 : m_pDefinedFT->Hide();
244 0 : m_pAddedFT->Show();
245 : }
246 :
247 0 : FillLanguageBox();
248 0 : }
249 :
250 0 : void SetDefaultLanguageDialog::FillLanguageBox()
251 : {
252 : // fill list with all languages
253 0 : m_pLanguageLB->SetLanguageList( LANG_LIST_ALL, false );
254 : // remove the already localized languages
255 0 : Sequence< Locale > aLocaleSeq = m_xLocalizationMgr->getStringResourceManager()->getLocales();
256 0 : const Locale* pLocale = aLocaleSeq.getConstArray();
257 0 : sal_Int32 i, nCount = aLocaleSeq.getLength();
258 0 : for ( i = 0; i < nCount; ++i )
259 0 : m_pLanguageLB->RemoveLanguage( LanguageTag::convertToLanguageType( pLocale[i] ) );
260 :
261 : // fill checklistbox if not in default mode
262 0 : if ( m_xLocalizationMgr->isLibraryLocalized() )
263 : {
264 0 : sal_uInt16 j, nCount_ = m_pLanguageLB->GetEntryCount();
265 0 : for ( j = 0; j < nCount_; ++j )
266 : {
267 : m_pCheckLangLB->InsertEntry(
268 0 : m_pLanguageLB->GetEntry(j), LISTBOX_APPEND, m_pLanguageLB->GetEntryData(j) );
269 : }
270 0 : m_pLanguageLB = NULL;
271 : }
272 : else
273 : // preselect current UI language
274 0 : m_pLanguageLB->SelectLanguage( Application::GetSettings().GetUILanguageTag().getLanguageType() );
275 0 : }
276 :
277 0 : Sequence< Locale > SetDefaultLanguageDialog::GetLocales() const
278 : {
279 0 : bool bNotLocalized = !m_xLocalizationMgr->isLibraryLocalized();
280 0 : sal_Int32 nSize = bNotLocalized ? 1 : m_pCheckLangLB->GetCheckedEntryCount();
281 0 : Sequence< Locale > aLocaleSeq( nSize );
282 0 : if ( bNotLocalized )
283 : {
284 0 : aLocaleSeq[0] = LanguageTag( m_pLanguageLB->GetSelectLanguage() ).getLocale();
285 : }
286 : else
287 : {
288 0 : sal_uInt16 i, nCount = static_cast< sal_uInt16 >( m_pCheckLangLB->GetEntryCount() );
289 0 : sal_Int32 j = 0;
290 0 : for ( i = 0; i < nCount; ++i )
291 : {
292 0 : if ( m_pCheckLangLB->IsChecked(i) )
293 : {
294 0 : LanguageType eType = LanguageType( reinterpret_cast<sal_uLong>(m_pCheckLangLB->GetEntryData(i)) );
295 0 : aLocaleSeq[j++] = LanguageTag::convertToLocale( eType );
296 : }
297 : }
298 : DBG_ASSERT( nSize == j, "SetDefaultLanguageDialog::GetLocales(): invalid indexes" );
299 : }
300 0 : return aLocaleSeq;
301 : }
302 :
303 0 : } // namespace basctl
304 :
305 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|