1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: basicbox.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
34 #include <ide_pch.hxx>
37 #include <basidesh.hrc>
38 #include <basidesh.hxx>
41 #include <basicbox.hxx>
43 #include <iderdll.hxx>
44 #include <bastypes.hxx>
45 #include "bastype2.hxx"
48 #include "localizationmgr.hxx"
49 #include "managelang.hxx"
50 #include "dlgresid.hrc"
51 #include <svx/unolingu.hxx>
53 #include <svtools/langtab.hxx>
56 using namespace ::com::sun::star
;
57 using namespace ::com::sun::star::lang
;
58 using namespace ::com::sun::star::uno
;
60 SFX_IMPL_TOOLBOX_CONTROL( LibBoxControl
, SfxStringItem
);
62 LibBoxControl::LibBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
)
63 : SfxToolBoxControl( nSlotId
, nId
, rTbx
)
69 LibBoxControl::~LibBoxControl()
75 void LibBoxControl::StateChanged( USHORT
, SfxItemState eState
, const SfxPoolItem
* pState
)
77 BasicLibBox
* pBox
= (BasicLibBox
*) GetToolBox().GetItemWindow( GetId() );
79 DBG_ASSERT( pBox
, "Box not found" );
83 if ( eState
!= SFX_ITEM_AVAILABLE
)
89 if ( pState
->ISA(SfxStringItem
) )
90 pBox
->Update( (const SfxStringItem
*)pState
);
98 Window
* LibBoxControl::CreateItemWindow( Window
*pParent
)
100 return new BasicLibBox( pParent
, m_xFrame
);
103 //=============================================================================
105 //=============================================================================
107 DocListenerBox::DocListenerBox( Window
* pParent
)
108 :ListBox( pParent
, WinBits( WB_BORDER
| WB_DROPDOWN
) )
109 ,m_aNotifier( *this )
113 DocListenerBox::~DocListenerBox()
115 m_aNotifier
.dispose();
118 void DocListenerBox::onDocumentCreated( const ScriptDocument
& /*_rDocument*/ )
123 void DocListenerBox::onDocumentOpened( const ScriptDocument
& /*_rDocument*/ )
128 void DocListenerBox::onDocumentSave( const ScriptDocument
& /*_rDocument*/ )
133 void DocListenerBox::onDocumentSaveDone( const ScriptDocument
& /*_rDocument*/ )
138 void DocListenerBox::onDocumentSaveAs( const ScriptDocument
& /*_rDocument*/ )
143 void DocListenerBox::onDocumentSaveAsDone( const ScriptDocument
& /*_rDocument*/ )
148 void DocListenerBox::onDocumentClosed( const ScriptDocument
& /*_rDocument*/ )
150 if ( SFX_APP()->IsInBasicCall() )
151 // Nicht wenn Office beendet
155 void DocListenerBox::onDocumentTitleChanged( const ScriptDocument
& /*_rDocument*/ )
160 void DocListenerBox::onDocumentModeChanged( const ScriptDocument
& /*_rDocument*/ )
165 //=============================================================================
167 //=============================================================================
168 BasicLibBox::BasicLibBox( Window
* pParent
, const uno::Reference
< frame::XFrame
>& rFrame
) :
169 DocListenerBox( pParent
),
173 bIgnoreSelect
= TRUE
; // Select von 0 noch nicht weiterleiten
176 aCurText
= GetEntry( 0 );
177 SetSizePixel( Size( 250, 200 ) );
178 bIgnoreSelect
= FALSE
;
183 __EXPORT
BasicLibBox::~BasicLibBox()
188 void __EXPORT
BasicLibBox::Update( const SfxStringItem
* pItem
)
190 // Immer auf dem laufenden sein...
191 // if ( !pItem || !pItem->GetValue().Len() )
196 aCurText
= pItem
->GetValue();
197 if ( aCurText
.Len() == 0 )
198 aCurText
= String( IDEResId( RID_STR_ALL
) );
201 if ( GetSelectEntry() != aCurText
)
202 SelectEntry( aCurText
);
205 void __EXPORT
BasicLibBox::ReleaseFocus()
207 SfxViewShell
* pCurSh
= SfxViewShell::Current();
208 DBG_ASSERT( pCurSh
, "Current ViewShell not found!" );
212 Window
* pShellWin
= pCurSh
->GetWindow();
213 if ( !pShellWin
) // sonst werde ich ihn nicht los
214 pShellWin
= Application::GetDefDialogParent();
216 pShellWin
->GrabFocus();
220 void BasicLibBox::FillBox()
222 SetUpdateMode( FALSE
);
223 bIgnoreSelect
= TRUE
;
225 aCurText
= GetSelectEntry();
230 // create list box entries
231 USHORT nPos
= InsertEntry( String( IDEResId( RID_STR_ALL
) ), LISTBOX_APPEND
);
232 SetEntryData( nPos
, new BasicLibEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_UNKNOWN
, String() ) );
233 InsertEntries( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER
);
234 InsertEntries( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE
);
236 ScriptDocuments
aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::DocumentsSorted
) );
237 for ( ScriptDocuments::const_iterator doc
= aDocuments
.begin();
238 doc
!= aDocuments
.end();
242 InsertEntries( *doc
, LIBRARY_LOCATION_DOCUMENT
);
245 SetUpdateMode( TRUE
);
247 SelectEntry( aCurText
);
248 if ( !GetSelectEntryCount() )
250 SelectEntryPos( GetEntryCount() ); // gibst es nicht => leer?
251 aCurText
= GetSelectEntry();
253 bIgnoreSelect
= FALSE
;
256 void BasicLibBox::InsertEntries( const ScriptDocument
& rDocument
, LibraryLocation eLocation
)
258 // get a sorted list of library names
259 Sequence
< ::rtl::OUString
> aLibNames
= rDocument
.getLibraryNames();
260 sal_Int32 nLibCount
= aLibNames
.getLength();
261 const ::rtl::OUString
* pLibNames
= aLibNames
.getConstArray();
263 for ( sal_Int32 i
= 0 ; i
< nLibCount
; ++i
)
265 String aLibName
= pLibNames
[ i
];
266 if ( eLocation
== rDocument
.getLibraryLocation( aLibName
) )
268 String
aName( rDocument
.getTitle( eLocation
) );
269 String
aEntryText( CreateMgrAndLibStr( aName
, aLibName
) );
270 USHORT nPos
= InsertEntry( aEntryText
, LISTBOX_APPEND
);
271 SetEntryData( nPos
, new BasicLibEntry( rDocument
, eLocation
, aLibName
) );
276 long BasicLibBox::PreNotify( NotifyEvent
& rNEvt
)
279 if( rNEvt
.GetType() == EVENT_KEYINPUT
)
281 KeyEvent aKeyEvt
= *rNEvt
.GetKeyEvent();
282 USHORT nKeyCode
= aKeyEvt
.GetKeyCode().GetCode();
294 SelectEntry( aCurText
);
301 else if( rNEvt
.GetType() == EVENT_GETFOCUS
)
309 else if( rNEvt
.GetType() == EVENT_LOSEFOCUS
)
311 if ( !HasChildPathFocus( TRUE
) )
313 bIgnoreSelect
= TRUE
;
318 return nDone
? nDone
: ListBox::PreNotify( rNEvt
);
321 void __EXPORT
BasicLibBox::Select()
323 if ( !IsTravelSelect() )
325 if ( !bIgnoreSelect
)
328 SelectEntry( aCurText
); // Seit 306... (Select nach Escape)
332 void BasicLibBox::NotifyIDE()
334 USHORT nSelPos
= GetSelectEntryPos();
335 BasicLibEntry
* pEntry
= (BasicLibEntry
*)GetEntryData( nSelPos
);
338 ScriptDocument
aDocument( pEntry
->GetDocument() );
339 SfxUsrAnyItem
aDocumentItem( SID_BASICIDE_ARG_DOCUMENT_MODEL
, uno::makeAny( aDocument
.getDocumentOrNull() ) );
340 String aLibName
= pEntry
->GetLibName();
341 SfxStringItem
aLibNameItem( SID_BASICIDE_ARG_LIBNAME
, aLibName
);
342 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
343 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
344 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
347 pDispatcher
->Execute( SID_BASICIDE_LIBSELECTED
,
348 SFX_CALLMODE_SYNCHRON
, &aDocumentItem
, &aLibNameItem
, 0L );
354 void BasicLibBox::ClearBox()
356 USHORT nCount
= GetEntryCount();
357 for ( USHORT i
= 0; i
< nCount
; ++i
)
359 BasicLibEntry
* pEntry
= (BasicLibEntry
*)GetEntryData( i
);
365 // class LanguageBoxControl ----------------------------------------------
367 SFX_IMPL_TOOLBOX_CONTROL( LanguageBoxControl
, SfxStringItem
);
369 LanguageBoxControl::LanguageBoxControl( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
)
370 : SfxToolBoxControl( nSlotId
, nId
, rTbx
)
374 LanguageBoxControl::~LanguageBoxControl()
378 void LanguageBoxControl::StateChanged( USHORT _nID
, SfxItemState _eState
, const SfxPoolItem
* _pItem
)
382 BasicLanguageBox
* pBox
= (BasicLanguageBox
*)( GetToolBox().GetItemWindow( GetId() ) );
386 if ( _eState
!= SFX_ITEM_AVAILABLE
)
391 if ( _pItem
->ISA(SfxStringItem
) )
392 pBox
->Update( (const SfxStringItem
*)_pItem
);
394 pBox
->Update( NULL
);
399 Window
* LanguageBoxControl::CreateItemWindow( Window
*pParent
)
401 return new BasicLanguageBox( pParent
);
404 // class BasicLanguageBox ------------------------------------------------
406 BasicLanguageBox::BasicLanguageBox( Window
* pParent
) :
408 DocListenerBox( pParent
),
410 m_sNotLocalizedStr( IDEResId( RID_STR_TRANSLATION_NOTLOCALIZED
) ),
411 m_sDefaultLanguageStr( IDEResId( RID_STR_TRANSLATION_DEFAULT
) ),
413 m_bIgnoreSelect( false )
416 SetSizePixel( Size( 210, 200 ) );
421 BasicLanguageBox::~BasicLanguageBox()
426 void BasicLanguageBox::FillBox()
428 SetUpdateMode( FALSE
);
429 m_bIgnoreSelect
= true;
430 m_sCurrentText
= GetSelectEntry();
433 LocalizationMgr
* pCurMgr
= IDE_DLL()->GetShell()->GetCurLocalizationMgr();
434 if ( pCurMgr
->isLibraryLocalized() )
437 SvtLanguageTable aLangTable
;
438 Locale aDefaultLocale
= pCurMgr
->getStringResourceManager()->getDefaultLocale();
439 Locale aCurrentLocale
= pCurMgr
->getStringResourceManager()->getCurrentLocale();
440 Sequence
< Locale
> aLocaleSeq
= pCurMgr
->getStringResourceManager()->getLocales();
441 const Locale
* pLocale
= aLocaleSeq
.getConstArray();
442 INT32 i
, nCount
= aLocaleSeq
.getLength();
443 USHORT nSelPos
= LISTBOX_ENTRY_NOTFOUND
;
444 for ( i
= 0; i
< nCount
; ++i
)
446 bool bIsDefault
= localesAreEqual( aDefaultLocale
, pLocale
[i
] );
447 bool bIsCurrent
= localesAreEqual( aCurrentLocale
, pLocale
[i
] );
448 LanguageType eLangType
= SvxLocaleToLanguage( pLocale
[i
] );
449 String sLanguage
= aLangTable
.GetString( eLangType
);
453 sLanguage
+= m_sDefaultLanguageStr
;
455 USHORT nPos
= InsertEntry( sLanguage
);
456 SetEntryData( nPos
, new LanguageEntry( sLanguage
, pLocale
[i
], bIsDefault
) );
462 if ( nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
464 SelectEntryPos( nSelPos
);
465 m_sCurrentText
= GetSelectEntry();
470 InsertEntry( m_sNotLocalizedStr
);
475 SetUpdateMode( TRUE
);
476 m_bIgnoreSelect
= false;
479 void BasicLanguageBox::ClearBox()
481 USHORT nCount
= GetEntryCount();
482 for ( USHORT i
= 0; i
< nCount
; ++i
)
484 LanguageEntry
* pEntry
= (LanguageEntry
*)GetEntryData(i
);
490 void BasicLanguageBox::SetLanguage()
492 LanguageEntry
* pEntry
= (LanguageEntry
*)GetEntryData( GetSelectEntryPos() );
494 IDE_DLL()->GetShell()->GetCurLocalizationMgr()->handleSetCurrentLocale( pEntry
->m_aLocale
);
497 void BasicLanguageBox::Select()
499 if ( !m_bIgnoreSelect
)
502 SelectEntry( m_sCurrentText
); // Select after Escape
505 long BasicLanguageBox::PreNotify( NotifyEvent
& rNEvt
)
508 if( rNEvt
.GetType() == EVENT_KEYINPUT
)
510 USHORT nKeyCode
= rNEvt
.GetKeyEvent()->GetKeyCode().GetCode();
522 SelectEntry( m_sCurrentText
);
528 else if( rNEvt
.GetType() == EVENT_GETFOCUS
)
531 else if( rNEvt
.GetType() == EVENT_LOSEFOCUS
)
535 return nDone
? nDone
: ListBox::PreNotify( rNEvt
);
538 void BasicLanguageBox::Update( const SfxStringItem
* pItem
)
542 if ( pItem
&& pItem
->GetValue().Len() > 0 )
544 m_sCurrentText
= pItem
->GetValue();
545 if ( GetSelectEntry() != m_sCurrentText
)
546 SelectEntry( m_sCurrentText
);