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 <basidesh.hrc>
21 #include <basidesh.hxx>
23 #include <basicbox.hxx>
24 #include <iderdll.hxx>
26 #include "localizationmgr.hxx"
27 #include "managelang.hxx"
28 #include "dlgresid.hrc"
30 #include <sfx2/dispatch.hxx>
31 #include <svtools/langtab.hxx>
36 using namespace ::com::sun::star
;
37 using namespace ::com::sun::star::lang
;
38 using namespace ::com::sun::star::uno
;
40 SFX_IMPL_TOOLBOX_CONTROL( LibBoxControl
, SfxStringItem
);
42 LibBoxControl::LibBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
)
43 : SfxToolBoxControl( nSlotId
, nId
, rTbx
)
49 void LibBoxControl::StateChanged( sal_uInt16
, SfxItemState eState
, const SfxPoolItem
* pState
)
51 LibBox
* pBox
= static_cast<LibBox
*>(GetToolBox().GetItemWindow(GetId()));
53 DBG_ASSERT( pBox
, "Box not found" );
57 if ( eState
!= SfxItemState::DEFAULT
)
62 pBox
->Update(dynamic_cast<SfxStringItem
const*>(pState
));
68 VclPtr
<vcl::Window
> LibBoxControl::CreateItemWindow( vcl::Window
*pParent
)
70 return VclPtr
<LibBox
>::Create( pParent
, m_xFrame
);
74 DocListenerBox::DocListenerBox( vcl::Window
* pParent
)
75 :ListBox( pParent
, WinBits( WB_BORDER
| WB_DROPDOWN
) )
80 DocListenerBox::~DocListenerBox()
85 void DocListenerBox::dispose()
87 m_aNotifier
.dispose();
91 void DocListenerBox::onDocumentCreated( const ScriptDocument
& /*_rDocument*/ )
96 void DocListenerBox::onDocumentOpened( const ScriptDocument
& /*_rDocument*/ )
101 void DocListenerBox::onDocumentSave( const ScriptDocument
& /*_rDocument*/ )
106 void DocListenerBox::onDocumentSaveDone( const ScriptDocument
& /*_rDocument*/ )
111 void DocListenerBox::onDocumentSaveAs( const ScriptDocument
& /*_rDocument*/ )
116 void DocListenerBox::onDocumentSaveAsDone( const ScriptDocument
& /*_rDocument*/ )
121 void DocListenerBox::onDocumentClosed( const ScriptDocument
& /*_rDocument*/ )
126 void DocListenerBox::onDocumentTitleChanged( const ScriptDocument
& /*_rDocument*/ )
131 void DocListenerBox::onDocumentModeChanged( const ScriptDocument
& /*_rDocument*/ )
136 LibBox::LibBox( vcl::Window
* pParent
, const uno::Reference
< frame::XFrame
>& rFrame
) :
137 DocListenerBox( pParent
),
141 bIgnoreSelect
= true; // do not yet transfer select of 0
144 aCurText
= GetEntry( 0 );
145 SetSizePixel( Size( 250, 200 ) );
146 bIgnoreSelect
= false;
156 void LibBox::dispose()
159 DocListenerBox::dispose();
162 void LibBox::Update( const SfxStringItem
* pItem
)
165 // if ( !pItem || !pItem->GetValue().Len() )
170 aCurText
= pItem
->GetValue();
171 if ( aCurText
.isEmpty() )
172 aCurText
= OUString( IDEResId( RID_STR_ALL
) );
175 if ( GetSelectEntry() != aCurText
)
176 SelectEntry( aCurText
);
179 void LibBox::ReleaseFocus()
181 SfxViewShell
* pCurSh
= SfxViewShell::Current();
182 DBG_ASSERT( pCurSh
, "Current ViewShell not found!" );
186 vcl::Window
* pShellWin
= pCurSh
->GetWindow();
188 pShellWin
= Application::GetDefDialogParent();
190 pShellWin
->GrabFocus();
194 void LibBox::FillBox()
196 SetUpdateMode(false);
197 bIgnoreSelect
= true;
199 aCurText
= GetSelectEntry();
204 // create list box entries
205 sal_Int32 nPos
= InsertEntry( OUString( IDEResId( RID_STR_ALL
) ), LISTBOX_APPEND
);
206 SetEntryData( nPos
, new LibEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_UNKNOWN
, OUString() ) );
207 InsertEntries( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER
);
208 InsertEntries( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE
);
210 ScriptDocuments
aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::DocumentsSorted
) );
211 for ( ScriptDocuments::const_iterator doc
= aDocuments
.begin();
212 doc
!= aDocuments
.end();
216 InsertEntries( *doc
, LIBRARY_LOCATION_DOCUMENT
);
221 SelectEntry( aCurText
);
222 if ( !GetSelectEntryCount() )
224 SelectEntryPos( GetEntryCount() );
225 aCurText
= GetSelectEntry();
227 bIgnoreSelect
= false;
230 void LibBox::InsertEntries( const ScriptDocument
& rDocument
, LibraryLocation eLocation
)
232 // get a sorted list of library names
233 Sequence
< OUString
> aLibNames
= rDocument
.getLibraryNames();
234 sal_Int32 nLibCount
= aLibNames
.getLength();
235 const OUString
* pLibNames
= aLibNames
.getConstArray();
237 for ( sal_Int32 i
= 0 ; i
< nLibCount
; ++i
)
239 OUString aLibName
= pLibNames
[ i
];
240 if ( eLocation
== rDocument
.getLibraryLocation( aLibName
) )
242 OUString
aName( rDocument
.getTitle( eLocation
) );
243 OUString
aEntryText( CreateMgrAndLibStr( aName
, aLibName
) );
244 sal_Int32 nPos
= InsertEntry( aEntryText
, LISTBOX_APPEND
);
245 SetEntryData( nPos
, new LibEntry( rDocument
, eLocation
, aLibName
) );
250 bool LibBox::PreNotify( NotifyEvent
& rNEvt
)
253 if( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
255 KeyEvent aKeyEvt
= *rNEvt
.GetKeyEvent();
256 sal_uInt16 nKeyCode
= aKeyEvt
.GetKeyCode().GetCode();
268 SelectEntry( aCurText
);
275 else if( rNEvt
.GetType() == MouseNotifyEvent::GETFOCUS
)
283 else if( rNEvt
.GetType() == MouseNotifyEvent::LOSEFOCUS
)
285 if ( !HasChildPathFocus(true) )
287 bIgnoreSelect
= true;
292 return nDone
|| ListBox::PreNotify( rNEvt
);
295 void LibBox::Select()
297 if ( !IsTravelSelect() )
299 if ( !bIgnoreSelect
)
302 SelectEntry( aCurText
); // since 306... (Select after Escape)
306 void LibBox::NotifyIDE()
308 sal_Int32 nSelPos
= GetSelectEntryPos();
309 if (LibEntry
* pEntry
= static_cast<LibEntry
*>(GetEntryData(nSelPos
)))
311 ScriptDocument
aDocument( pEntry
->GetDocument() );
312 SfxUsrAnyItem
aDocumentItem( SID_BASICIDE_ARG_DOCUMENT_MODEL
, uno::makeAny( aDocument
.getDocumentOrNull() ) );
313 OUString aLibName
= pEntry
->GetLibName();
314 SfxStringItem
aLibNameItem( SID_BASICIDE_ARG_LIBNAME
, aLibName
);
315 if (SfxDispatcher
* pDispatcher
= GetDispatcher())
316 pDispatcher
->Execute(
317 SID_BASICIDE_LIBSELECTED
,
318 SfxCallMode::SYNCHRON
, &aDocumentItem
, &aLibNameItem
, 0L
324 void LibBox::ClearBox()
326 sal_Int32 nCount
= GetEntryCount();
327 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
329 LibEntry
* pEntry
= static_cast<LibEntry
*>(GetEntryData( i
));
335 // class LanguageBoxControl ----------------------------------------------
337 SFX_IMPL_TOOLBOX_CONTROL( LanguageBoxControl
, SfxStringItem
);
339 LanguageBoxControl::LanguageBoxControl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
)
340 : SfxToolBoxControl( nSlotId
, nId
, rTbx
)
344 void LanguageBoxControl::StateChanged( sal_uInt16 nID
, SfxItemState eState
, const SfxPoolItem
* pItem
)
347 if (LanguageBox
* pBox
= static_cast<LanguageBox
*>(GetToolBox().GetItemWindow(GetId())))
349 if (eState
!= SfxItemState::DEFAULT
)
354 pBox
->Update(dynamic_cast<SfxStringItem
const*>(pItem
));
359 VclPtr
<vcl::Window
> LanguageBoxControl::CreateItemWindow( vcl::Window
*pParent
)
361 return VclPtr
<LanguageBox
>::Create( pParent
);
364 // class basctl::LanguageBox -----------------------------------------------
366 LanguageBox::LanguageBox( vcl::Window
* pParent
) :
368 DocListenerBox( pParent
),
370 m_sNotLocalizedStr( IDEResId( RID_STR_TRANSLATION_NOTLOCALIZED
) ),
371 m_sDefaultLanguageStr( IDEResId( RID_STR_TRANSLATION_DEFAULT
) ),
373 m_bIgnoreSelect( false )
376 SetSizePixel( Size( 210, 200 ) );
381 LanguageBox::~LanguageBox()
386 void LanguageBox::dispose()
389 DocListenerBox::dispose();
392 void LanguageBox::FillBox()
394 SetUpdateMode(false);
395 m_bIgnoreSelect
= true;
396 m_sCurrentText
= GetSelectEntry();
399 boost::shared_ptr
<LocalizationMgr
> pCurMgr(GetShell()->GetCurLocalizationMgr());
400 if ( pCurMgr
->isLibraryLocalized() )
403 Locale aDefaultLocale
= pCurMgr
->getStringResourceManager()->getDefaultLocale();
404 Locale aCurrentLocale
= pCurMgr
->getStringResourceManager()->getCurrentLocale();
405 Sequence
< Locale
> aLocaleSeq
= pCurMgr
->getStringResourceManager()->getLocales();
406 const Locale
* pLocale
= aLocaleSeq
.getConstArray();
407 sal_Int32 i
, nCount
= aLocaleSeq
.getLength();
408 sal_Int32 nSelPos
= LISTBOX_ENTRY_NOTFOUND
;
409 for ( i
= 0; i
< nCount
; ++i
)
411 bool bIsDefault
= localesAreEqual( aDefaultLocale
, pLocale
[i
] );
412 bool bIsCurrent
= localesAreEqual( aCurrentLocale
, pLocale
[i
] );
413 LanguageType eLangType
= LanguageTag::convertToLanguageType( pLocale
[i
] );
414 OUString sLanguage
= SvtLanguageTable::GetLanguageString( eLangType
);
418 sLanguage
+= m_sDefaultLanguageStr
;
420 sal_Int32 nPos
= InsertEntry( sLanguage
);
421 SetEntryData( nPos
, new LanguageEntry( sLanguage
, pLocale
[i
], bIsDefault
) );
427 if ( nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
429 SelectEntryPos( nSelPos
);
430 m_sCurrentText
= GetSelectEntry();
435 InsertEntry( m_sNotLocalizedStr
);
441 m_bIgnoreSelect
= false;
444 void LanguageBox::ClearBox()
446 sal_Int32 nCount
= GetEntryCount();
447 for ( sal_Int32 i
= 0; i
< nCount
; ++i
)
449 LanguageEntry
* pEntry
= static_cast<LanguageEntry
*>(GetEntryData(i
));
455 void LanguageBox::SetLanguage()
457 LanguageEntry
* pEntry
= static_cast<LanguageEntry
*>(GetSelectEntryData());
459 GetShell()->GetCurLocalizationMgr()->handleSetCurrentLocale( pEntry
->m_aLocale
);
462 void LanguageBox::Select()
464 if ( !m_bIgnoreSelect
)
467 SelectEntry( m_sCurrentText
); // Select after Escape
470 bool LanguageBox::PreNotify( NotifyEvent
& rNEvt
)
473 if( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
475 sal_uInt16 nKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode().GetCode();
487 SelectEntry( m_sCurrentText
);
493 else if( rNEvt
.GetType() == MouseNotifyEvent::GETFOCUS
)
496 else if( rNEvt
.GetType() == MouseNotifyEvent::LOSEFOCUS
)
500 return nDone
|| ListBox::PreNotify( rNEvt
);
503 void LanguageBox::Update( const SfxStringItem
* pItem
)
507 if ( pItem
&& !pItem
->GetValue().isEmpty() )
509 m_sCurrentText
= pItem
->GetValue();
510 if ( GetSelectEntry() != m_sCurrentText
)
511 SelectEntry( m_sCurrentText
);
516 } // namespace basctl
518 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */