1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <strings.hrc>
21 #include <basidesh.hxx>
23 #include "basicbox.hxx"
24 #include <iderdll.hxx>
26 #include <localizationmgr.hxx>
27 #include <managelang.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <svtools/langtab.hxx>
35 using namespace ::com::sun::star
;
36 using namespace ::com::sun::star::lang
;
37 using namespace ::com::sun::star::uno
;
39 SFX_IMPL_TOOLBOX_CONTROL( LibBoxControl
, SfxStringItem
);
41 LibBoxControl::LibBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
)
42 : SfxToolBoxControl( nSlotId
, nId
, rTbx
)
47 void LibBoxControl::StateChanged( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
49 LibBox
* pBox
= static_cast<LibBox
*>(GetToolBox().GetItemWindow(GetId()));
51 DBG_ASSERT( pBox
, "Box not found" );
55 if ( eState
!= SfxItemState::DEFAULT
)
60 pBox
->Update(dynamic_cast<SfxStringItem
const*>(pState
));
65 VclPtr
<vcl::Window
> LibBoxControl::CreateItemWindow( vcl::Window
*pParent
)
67 return VclPtr
<LibBox
>::Create( pParent
);
71 DocListenerBox::DocListenerBox( vcl::Window
* pParent
)
72 :ListBox( pParent
, WinBits( WB_BORDER
| WB_DROPDOWN
) )
77 DocListenerBox::~DocListenerBox()
82 void DocListenerBox::dispose()
84 m_aNotifier
.dispose();
88 void DocListenerBox::onDocumentCreated( const ScriptDocument
& /*_rDocument*/ )
93 void DocListenerBox::onDocumentOpened( const ScriptDocument
& /*_rDocument*/ )
98 void DocListenerBox::onDocumentSave( const ScriptDocument
& /*_rDocument*/ )
103 void DocListenerBox::onDocumentSaveDone( const ScriptDocument
& /*_rDocument*/ )
108 void DocListenerBox::onDocumentSaveAs( const ScriptDocument
& /*_rDocument*/ )
113 void DocListenerBox::onDocumentSaveAsDone( const ScriptDocument
& /*_rDocument*/ )
118 void DocListenerBox::onDocumentClosed( const ScriptDocument
& /*_rDocument*/ )
123 void DocListenerBox::onDocumentTitleChanged( const ScriptDocument
& /*_rDocument*/ )
128 void DocListenerBox::onDocumentModeChanged( const ScriptDocument
& /*_rDocument*/ )
133 LibBox::LibBox( vcl::Window
* pParent
) :
134 DocListenerBox( pParent
)
137 bIgnoreSelect
= true; // do not yet transfer select of 0
140 aCurText
= GetEntry( 0 );
141 SetSizePixel( Size( 250, 200 ) );
142 bIgnoreSelect
= false;
151 void LibBox::dispose()
154 DocListenerBox::dispose();
157 void LibBox::Update( const SfxStringItem
* pItem
)
160 // if ( !pItem || !pItem->GetValue().Len() )
165 aCurText
= pItem
->GetValue();
166 if ( aCurText
.isEmpty() )
167 aCurText
= IDEResId(RID_STR_ALL
);
170 if ( GetSelectedEntry() != aCurText
)
171 SelectEntry( aCurText
);
174 void LibBox::ReleaseFocus()
176 SfxViewShell
* pCurSh
= SfxViewShell::Current();
177 DBG_ASSERT( pCurSh
, "Current ViewShell not found!" );
181 vcl::Window
* pShellWin
= pCurSh
->GetWindow();
183 pShellWin
= Application::GetDefDialogParent();
185 pShellWin
->GrabFocus();
189 void LibBox::FillBox()
191 SetUpdateMode(false);
192 bIgnoreSelect
= true;
194 aCurText
= GetSelectedEntry();
199 // create list box entries
200 sal_Int32 nPos
= InsertEntry(IDEResId(RID_STR_ALL
));
201 SetEntryData( nPos
, new LibEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_UNKNOWN
, OUString() ) );
202 InsertEntries( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER
);
203 InsertEntries( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE
);
205 ScriptDocuments
aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::DocumentsSorted
) );
206 for ( ScriptDocuments::const_iterator doc
= aDocuments
.begin();
207 doc
!= aDocuments
.end();
211 InsertEntries( *doc
, LIBRARY_LOCATION_DOCUMENT
);
216 SelectEntry( aCurText
);
217 if ( !GetSelectedEntryCount() )
219 SelectEntryPos( GetEntryCount() );
220 aCurText
= GetSelectedEntry();
222 bIgnoreSelect
= false;
225 void LibBox::InsertEntries( const ScriptDocument
& rDocument
, LibraryLocation eLocation
)
227 // get a sorted list of library names
228 Sequence
< OUString
> aLibNames
= rDocument
.getLibraryNames();
229 sal_Int32 nLibCount
= aLibNames
.getLength();
230 const OUString
* pLibNames
= aLibNames
.getConstArray();
232 for ( sal_Int32 i
= 0 ; i
< nLibCount
; ++i
)
234 OUString aLibName
= pLibNames
[ i
];
235 if ( eLocation
== rDocument
.getLibraryLocation( aLibName
) )
237 OUString
aName( rDocument
.getTitle( eLocation
) );
238 OUString
aEntryText( CreateMgrAndLibStr( aName
, aLibName
) );
239 sal_Int32 nPos
= InsertEntry( aEntryText
);
240 SetEntryData( nPos
, new LibEntry( rDocument
, eLocation
, aLibName
) );
245 bool LibBox::PreNotify( NotifyEvent
& rNEvt
)
248 if( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
250 KeyEvent aKeyEvt
= *rNEvt
.GetKeyEvent();
251 sal_uInt16 nKeyCode
= aKeyEvt
.GetKeyCode().GetCode();
263 SelectEntry( aCurText
);
270 else if( rNEvt
.GetType() == MouseNotifyEvent::GETFOCUS
)
278 else if( rNEvt
.GetType() == MouseNotifyEvent::LOSEFOCUS
)
280 if ( !HasChildPathFocus(true) )
282 bIgnoreSelect
= true;
287 return bDone
|| ListBox::PreNotify( rNEvt
);
290 void LibBox::Select()
292 if ( !IsTravelSelect() )
294 if ( !bIgnoreSelect
)
297 SelectEntry( aCurText
); // since 306... (Select after Escape)
301 void LibBox::NotifyIDE()
303 sal_Int32 nSelPos
= GetSelectedEntryPos();
304 if (LibEntry
* pEntry
= static_cast<LibEntry
*>(GetEntryData(nSelPos
)))
306 ScriptDocument
aDocument( pEntry
->GetDocument() );
307 SfxUsrAnyItem
aDocumentItem( SID_BASICIDE_ARG_DOCUMENT_MODEL
, uno::Any( aDocument
.getDocumentOrNull() ) );
308 OUString aLibName
= pEntry
->GetLibName();
309 SfxStringItem
aLibNameItem( SID_BASICIDE_ARG_LIBNAME
, aLibName
);
310 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
311 pDispatcher
->ExecuteList(
312 SID_BASICIDE_LIBSELECTED
, SfxCallMode::SYNCHRON
,
313 { &aDocumentItem
, &aLibNameItem
}
319 void LibBox::ClearBox()
321 sal_Int32 nCount
= GetEntryCount();
322 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
324 LibEntry
* pEntry
= static_cast<LibEntry
*>(GetEntryData( i
));
330 // class LanguageBoxControl ----------------------------------------------
332 SFX_IMPL_TOOLBOX_CONTROL( LanguageBoxControl
, SfxStringItem
);
334 LanguageBoxControl::LanguageBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
)
335 : SfxToolBoxControl( nSlotId
, nId
, rTbx
)
339 void LanguageBoxControl::StateChanged( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pItem
)
341 if (LanguageBox
* pBox
= static_cast<LanguageBox
*>(GetToolBox().GetItemWindow(GetId())))
343 if (eState
!= SfxItemState::DEFAULT
)
348 pBox
->Update(dynamic_cast<SfxStringItem
const*>(pItem
));
353 VclPtr
<vcl::Window
> LanguageBoxControl::CreateItemWindow( vcl::Window
*pParent
)
355 return VclPtr
<LanguageBox
>::Create( pParent
);
358 // class basctl::LanguageBox -----------------------------------------------
360 LanguageBox::LanguageBox( vcl::Window
* pParent
) :
362 DocListenerBox( pParent
),
364 m_sNotLocalizedStr( IDEResId( RID_STR_TRANSLATION_NOTLOCALIZED
) ),
365 m_sDefaultLanguageStr( IDEResId( RID_STR_TRANSLATION_DEFAULT
) ),
367 m_bIgnoreSelect( false )
370 SetSizePixel( Size( 210, 200 ) );
375 LanguageBox::~LanguageBox()
380 void LanguageBox::dispose()
383 DocListenerBox::dispose();
386 void LanguageBox::FillBox()
388 SetUpdateMode(false);
389 m_bIgnoreSelect
= true;
390 m_sCurrentText
= GetSelectedEntry();
393 std::shared_ptr
<LocalizationMgr
> pCurMgr(GetShell()->GetCurLocalizationMgr());
394 if ( pCurMgr
->isLibraryLocalized() )
397 Locale aDefaultLocale
= pCurMgr
->getStringResourceManager()->getDefaultLocale();
398 Locale aCurrentLocale
= pCurMgr
->getStringResourceManager()->getCurrentLocale();
399 Sequence
< Locale
> aLocaleSeq
= pCurMgr
->getStringResourceManager()->getLocales();
400 const Locale
* pLocale
= aLocaleSeq
.getConstArray();
401 sal_Int32 i
, nCount
= aLocaleSeq
.getLength();
402 sal_Int32 nSelPos
= LISTBOX_ENTRY_NOTFOUND
;
403 for ( i
= 0; i
< nCount
; ++i
)
405 bool bIsDefault
= localesAreEqual( aDefaultLocale
, pLocale
[i
] );
406 bool bIsCurrent
= localesAreEqual( aCurrentLocale
, pLocale
[i
] );
407 LanguageType eLangType
= LanguageTag::convertToLanguageType( pLocale
[i
] );
408 OUString sLanguage
= SvtLanguageTable::GetLanguageString( eLangType
);
412 sLanguage
+= m_sDefaultLanguageStr
;
414 sal_Int32 nPos
= InsertEntry( sLanguage
);
415 SetEntryData( nPos
, new LanguageEntry( pLocale
[i
], bIsDefault
) );
421 if ( nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
423 SelectEntryPos( nSelPos
);
424 m_sCurrentText
= GetSelectedEntry();
429 InsertEntry( m_sNotLocalizedStr
);
435 m_bIgnoreSelect
= false;
438 void LanguageBox::ClearBox()
440 sal_Int32 nCount
= GetEntryCount();
441 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
443 LanguageEntry
* pEntry
= static_cast<LanguageEntry
*>(GetEntryData(i
));
449 void LanguageBox::SetLanguage()
451 LanguageEntry
* pEntry
= static_cast<LanguageEntry
*>(GetSelectedEntryData());
453 GetShell()->GetCurLocalizationMgr()->handleSetCurrentLocale( pEntry
->m_aLocale
);
456 void LanguageBox::Select()
458 if ( !m_bIgnoreSelect
)
461 SelectEntry( m_sCurrentText
); // Select after Escape
464 bool LanguageBox::PreNotify( NotifyEvent
& rNEvt
)
467 if( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
469 sal_uInt16 nKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode().GetCode();
481 SelectEntry( m_sCurrentText
);
487 else if( rNEvt
.GetType() == MouseNotifyEvent::GETFOCUS
)
490 else if( rNEvt
.GetType() == MouseNotifyEvent::LOSEFOCUS
)
494 return bDone
|| ListBox::PreNotify( rNEvt
);
497 void LanguageBox::Update( const SfxStringItem
* pItem
)
501 if ( pItem
&& !pItem
->GetValue().isEmpty() )
503 m_sCurrentText
= pItem
->GetValue();
504 if ( GetSelectedEntry() != m_sCurrentText
)
505 SelectEntry( m_sCurrentText
);
510 } // namespace basctl
512 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */