1*31598a22SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*31598a22SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*31598a22SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*31598a22SAndrew Rist * distributed with this work for additional information
6*31598a22SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*31598a22SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*31598a22SAndrew Rist * "License"); you may not use this file except in compliance
9*31598a22SAndrew Rist * with the License. You may obtain a copy of the License at
10*31598a22SAndrew Rist *
11*31598a22SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*31598a22SAndrew Rist *
13*31598a22SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*31598a22SAndrew Rist * software distributed under the License is distributed on an
15*31598a22SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*31598a22SAndrew Rist * KIND, either express or implied. See the License for the
17*31598a22SAndrew Rist * specific language governing permissions and limitations
18*31598a22SAndrew Rist * under the License.
19*31598a22SAndrew Rist *
20*31598a22SAndrew Rist *************************************************************/
21*31598a22SAndrew Rist
22*31598a22SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_basctl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <ide_pch.hxx>
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <basidesh.hrc>
31cdf0e10cSrcweir #include <basidesh.hxx>
32cdf0e10cSrcweir #include <basobj.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <basicbox.hxx>
35cdf0e10cSrcweir #include <iderid.hxx>
36cdf0e10cSrcweir #include <iderdll.hxx>
37cdf0e10cSrcweir #include <bastypes.hxx>
38cdf0e10cSrcweir #include "bastype2.hxx"
39cdf0e10cSrcweir #include "basdoc.hxx"
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include "localizationmgr.hxx"
42cdf0e10cSrcweir #include "managelang.hxx"
43cdf0e10cSrcweir #include "dlgresid.hrc"
44cdf0e10cSrcweir #include <editeng/unolingu.hxx>
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include <svtools/langtab.hxx>
47cdf0e10cSrcweir
48cdf0e10cSrcweir
49cdf0e10cSrcweir using namespace ::com::sun::star;
50cdf0e10cSrcweir using namespace ::com::sun::star::lang;
51cdf0e10cSrcweir using namespace ::com::sun::star::uno;
52cdf0e10cSrcweir
53cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL( LibBoxControl, SfxStringItem );
54cdf0e10cSrcweir
LibBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)55cdf0e10cSrcweir LibBoxControl::LibBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
56cdf0e10cSrcweir : SfxToolBoxControl( nSlotId, nId, rTbx )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir
60cdf0e10cSrcweir
61cdf0e10cSrcweir
~LibBoxControl()62cdf0e10cSrcweir LibBoxControl::~LibBoxControl()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
66cdf0e10cSrcweir
67cdf0e10cSrcweir
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)68cdf0e10cSrcweir void LibBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir BasicLibBox* pBox = (BasicLibBox*) GetToolBox().GetItemWindow( GetId() );
71cdf0e10cSrcweir
72cdf0e10cSrcweir DBG_ASSERT( pBox, "Box not found" );
73cdf0e10cSrcweir if ( !pBox )
74cdf0e10cSrcweir return;
75cdf0e10cSrcweir
76cdf0e10cSrcweir if ( eState != SFX_ITEM_AVAILABLE )
77cdf0e10cSrcweir pBox->Disable();
78cdf0e10cSrcweir else
79cdf0e10cSrcweir {
80cdf0e10cSrcweir pBox->Enable();
81cdf0e10cSrcweir
82cdf0e10cSrcweir if ( pState->ISA(SfxStringItem) )
83cdf0e10cSrcweir pBox->Update( (const SfxStringItem*)pState );
84cdf0e10cSrcweir else
85cdf0e10cSrcweir pBox->Update( NULL );
86cdf0e10cSrcweir }
87cdf0e10cSrcweir }
88cdf0e10cSrcweir
89cdf0e10cSrcweir
90cdf0e10cSrcweir
CreateItemWindow(Window * pParent)91cdf0e10cSrcweir Window* LibBoxControl::CreateItemWindow( Window *pParent )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir return new BasicLibBox( pParent, m_xFrame );
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir //=============================================================================
97cdf0e10cSrcweir //= DocListenerBox
98cdf0e10cSrcweir //=============================================================================
99cdf0e10cSrcweir
DocListenerBox(Window * pParent)100cdf0e10cSrcweir DocListenerBox::DocListenerBox( Window* pParent )
101cdf0e10cSrcweir :ListBox( pParent, WinBits( WB_BORDER | WB_DROPDOWN ) )
102cdf0e10cSrcweir ,m_aNotifier( *this )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
~DocListenerBox()106cdf0e10cSrcweir DocListenerBox::~DocListenerBox()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir m_aNotifier.dispose();
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
onDocumentCreated(const ScriptDocument &)111cdf0e10cSrcweir void DocListenerBox::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir FillBox();
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
onDocumentOpened(const ScriptDocument &)116cdf0e10cSrcweir void DocListenerBox::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir FillBox();
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
onDocumentSave(const ScriptDocument &)121cdf0e10cSrcweir void DocListenerBox::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir // not interested in
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
onDocumentSaveDone(const ScriptDocument &)126cdf0e10cSrcweir void DocListenerBox::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir // not interested in
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
onDocumentSaveAs(const ScriptDocument &)131cdf0e10cSrcweir void DocListenerBox::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir // not interested in
134cdf0e10cSrcweir }
135cdf0e10cSrcweir
onDocumentSaveAsDone(const ScriptDocument &)136cdf0e10cSrcweir void DocListenerBox::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir FillBox();
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
onDocumentClosed(const ScriptDocument &)141cdf0e10cSrcweir void DocListenerBox::onDocumentClosed( const ScriptDocument& /*_rDocument*/ )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir FillBox();
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
onDocumentTitleChanged(const ScriptDocument &)146cdf0e10cSrcweir void DocListenerBox::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir // not interested in
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
onDocumentModeChanged(const ScriptDocument &)151cdf0e10cSrcweir void DocListenerBox::onDocumentModeChanged( const ScriptDocument& /*_rDocument*/ )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir // not interested in
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir //=============================================================================
157cdf0e10cSrcweir //= BasicLibBox
158cdf0e10cSrcweir //=============================================================================
BasicLibBox(Window * pParent,const uno::Reference<frame::XFrame> & rFrame)159cdf0e10cSrcweir BasicLibBox::BasicLibBox( Window* pParent, const uno::Reference< frame::XFrame >& rFrame ) :
160cdf0e10cSrcweir DocListenerBox( pParent ),
161cdf0e10cSrcweir m_xFrame( rFrame )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir FillBox();
164cdf0e10cSrcweir bIgnoreSelect = sal_True; // Select von 0 noch nicht weiterleiten
165cdf0e10cSrcweir bFillBox = sal_True;
166cdf0e10cSrcweir SelectEntryPos( 0 );
167cdf0e10cSrcweir aCurText = GetEntry( 0 );
168cdf0e10cSrcweir SetSizePixel( Size( 250, 200 ) );
169cdf0e10cSrcweir bIgnoreSelect = sal_False;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir
173cdf0e10cSrcweir
~BasicLibBox()174cdf0e10cSrcweir __EXPORT BasicLibBox::~BasicLibBox()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir ClearBox();
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
Update(const SfxStringItem * pItem)179cdf0e10cSrcweir void __EXPORT BasicLibBox::Update( const SfxStringItem* pItem )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir // Immer auf dem laufenden sein...
182cdf0e10cSrcweir // if ( !pItem || !pItem->GetValue().Len() )
183cdf0e10cSrcweir FillBox();
184cdf0e10cSrcweir
185cdf0e10cSrcweir if ( pItem )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir aCurText = pItem->GetValue();
188cdf0e10cSrcweir if ( aCurText.Len() == 0 )
189cdf0e10cSrcweir aCurText = String( IDEResId( RID_STR_ALL ) );
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir if ( GetSelectEntry() != aCurText )
193cdf0e10cSrcweir SelectEntry( aCurText );
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
ReleaseFocus()196cdf0e10cSrcweir void __EXPORT BasicLibBox::ReleaseFocus()
197cdf0e10cSrcweir {
198cdf0e10cSrcweir SfxViewShell* pCurSh = SfxViewShell::Current();
199cdf0e10cSrcweir DBG_ASSERT( pCurSh, "Current ViewShell not found!" );
200cdf0e10cSrcweir
201cdf0e10cSrcweir if ( pCurSh )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir Window* pShellWin = pCurSh->GetWindow();
204cdf0e10cSrcweir if ( !pShellWin ) // sonst werde ich ihn nicht los
205cdf0e10cSrcweir pShellWin = Application::GetDefDialogParent();
206cdf0e10cSrcweir
207cdf0e10cSrcweir pShellWin->GrabFocus();
208cdf0e10cSrcweir }
209cdf0e10cSrcweir }
210cdf0e10cSrcweir
FillBox()211cdf0e10cSrcweir void BasicLibBox::FillBox()
212cdf0e10cSrcweir {
213cdf0e10cSrcweir SetUpdateMode( sal_False );
214cdf0e10cSrcweir bIgnoreSelect = sal_True;
215cdf0e10cSrcweir
216cdf0e10cSrcweir aCurText = GetSelectEntry();
217cdf0e10cSrcweir
218cdf0e10cSrcweir SelectEntryPos( 0 );
219cdf0e10cSrcweir ClearBox();
220cdf0e10cSrcweir
221cdf0e10cSrcweir // create list box entries
222cdf0e10cSrcweir sal_uInt16 nPos = InsertEntry( String( IDEResId( RID_STR_ALL ) ), LISTBOX_APPEND );
223cdf0e10cSrcweir SetEntryData( nPos, new BasicLibEntry( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_UNKNOWN, String() ) );
224cdf0e10cSrcweir InsertEntries( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_USER );
225cdf0e10cSrcweir InsertEntries( ScriptDocument::getApplicationScriptDocument(), LIBRARY_LOCATION_SHARE );
226cdf0e10cSrcweir
227cdf0e10cSrcweir ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::DocumentsSorted ) );
228cdf0e10cSrcweir for ( ScriptDocuments::const_iterator doc = aDocuments.begin();
229cdf0e10cSrcweir doc != aDocuments.end();
230cdf0e10cSrcweir ++doc
231cdf0e10cSrcweir )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir InsertEntries( *doc, LIBRARY_LOCATION_DOCUMENT );
234cdf0e10cSrcweir }
235cdf0e10cSrcweir
236cdf0e10cSrcweir SetUpdateMode( sal_True );
237cdf0e10cSrcweir
238cdf0e10cSrcweir SelectEntry( aCurText );
239cdf0e10cSrcweir if ( !GetSelectEntryCount() )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir SelectEntryPos( GetEntryCount() ); // gibst es nicht => leer?
242cdf0e10cSrcweir aCurText = GetSelectEntry();
243cdf0e10cSrcweir }
244cdf0e10cSrcweir bIgnoreSelect = sal_False;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
InsertEntries(const ScriptDocument & rDocument,LibraryLocation eLocation)247cdf0e10cSrcweir void BasicLibBox::InsertEntries( const ScriptDocument& rDocument, LibraryLocation eLocation )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir // get a sorted list of library names
250cdf0e10cSrcweir Sequence< ::rtl::OUString > aLibNames = rDocument.getLibraryNames();
251cdf0e10cSrcweir sal_Int32 nLibCount = aLibNames.getLength();
252cdf0e10cSrcweir const ::rtl::OUString* pLibNames = aLibNames.getConstArray();
253cdf0e10cSrcweir
254cdf0e10cSrcweir for ( sal_Int32 i = 0 ; i < nLibCount ; ++i )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir String aLibName = pLibNames[ i ];
257cdf0e10cSrcweir if ( eLocation == rDocument.getLibraryLocation( aLibName ) )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir String aName( rDocument.getTitle( eLocation ) );
260cdf0e10cSrcweir String aEntryText( CreateMgrAndLibStr( aName, aLibName ) );
261cdf0e10cSrcweir sal_uInt16 nPos = InsertEntry( aEntryText, LISTBOX_APPEND );
262cdf0e10cSrcweir SetEntryData( nPos, new BasicLibEntry( rDocument, eLocation, aLibName ) );
263cdf0e10cSrcweir }
264cdf0e10cSrcweir }
265cdf0e10cSrcweir }
266cdf0e10cSrcweir
PreNotify(NotifyEvent & rNEvt)267cdf0e10cSrcweir long BasicLibBox::PreNotify( NotifyEvent& rNEvt )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir long nDone = 0;
270cdf0e10cSrcweir if( rNEvt.GetType() == EVENT_KEYINPUT )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir KeyEvent aKeyEvt = *rNEvt.GetKeyEvent();
273cdf0e10cSrcweir sal_uInt16 nKeyCode = aKeyEvt.GetKeyCode().GetCode();
274cdf0e10cSrcweir switch( nKeyCode )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir case KEY_RETURN:
277cdf0e10cSrcweir {
278cdf0e10cSrcweir NotifyIDE();
279cdf0e10cSrcweir nDone = 1;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir break;
282cdf0e10cSrcweir
283cdf0e10cSrcweir case KEY_ESCAPE:
284cdf0e10cSrcweir {
285cdf0e10cSrcweir SelectEntry( aCurText );
286cdf0e10cSrcweir ReleaseFocus();
287cdf0e10cSrcweir nDone = 1;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir break;
290cdf0e10cSrcweir }
291cdf0e10cSrcweir }
292cdf0e10cSrcweir else if( rNEvt.GetType() == EVENT_GETFOCUS )
293cdf0e10cSrcweir {
294cdf0e10cSrcweir if ( bFillBox )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir FillBox();
297cdf0e10cSrcweir bFillBox = sal_False;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir }
300cdf0e10cSrcweir else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir if ( !HasChildPathFocus( sal_True ) )
303cdf0e10cSrcweir {
304cdf0e10cSrcweir bIgnoreSelect = sal_True;
305cdf0e10cSrcweir bFillBox = sal_True;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir }
308cdf0e10cSrcweir
309cdf0e10cSrcweir return nDone ? nDone : ListBox::PreNotify( rNEvt );
310cdf0e10cSrcweir }
311cdf0e10cSrcweir
Select()312cdf0e10cSrcweir void __EXPORT BasicLibBox::Select()
313cdf0e10cSrcweir {
314cdf0e10cSrcweir if ( !IsTravelSelect() )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir if ( !bIgnoreSelect )
317cdf0e10cSrcweir NotifyIDE();
318cdf0e10cSrcweir else
319cdf0e10cSrcweir SelectEntry( aCurText ); // Seit 306... (Select nach Escape)
320cdf0e10cSrcweir }
321cdf0e10cSrcweir }
322cdf0e10cSrcweir
NotifyIDE()323cdf0e10cSrcweir void BasicLibBox::NotifyIDE()
324cdf0e10cSrcweir {
325cdf0e10cSrcweir sal_uInt16 nSelPos = GetSelectEntryPos();
326cdf0e10cSrcweir BasicLibEntry* pEntry = (BasicLibEntry*)GetEntryData( nSelPos );
327cdf0e10cSrcweir if ( pEntry )
328cdf0e10cSrcweir {
329cdf0e10cSrcweir ScriptDocument aDocument( pEntry->GetDocument() );
330cdf0e10cSrcweir SfxUsrAnyItem aDocumentItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, uno::makeAny( aDocument.getDocumentOrNull() ) );
331cdf0e10cSrcweir String aLibName = pEntry->GetLibName();
332cdf0e10cSrcweir SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName );
333cdf0e10cSrcweir BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
334cdf0e10cSrcweir SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
335cdf0e10cSrcweir SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
336cdf0e10cSrcweir if ( pDispatcher )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir pDispatcher->Execute( SID_BASICIDE_LIBSELECTED,
339cdf0e10cSrcweir SFX_CALLMODE_SYNCHRON, &aDocumentItem, &aLibNameItem, 0L );
340cdf0e10cSrcweir }
341cdf0e10cSrcweir }
342cdf0e10cSrcweir ReleaseFocus();
343cdf0e10cSrcweir }
344cdf0e10cSrcweir
ClearBox()345cdf0e10cSrcweir void BasicLibBox::ClearBox()
346cdf0e10cSrcweir {
347cdf0e10cSrcweir sal_uInt16 nCount = GetEntryCount();
348cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; ++i )
349cdf0e10cSrcweir {
350cdf0e10cSrcweir BasicLibEntry* pEntry = (BasicLibEntry*)GetEntryData( i );
351cdf0e10cSrcweir delete pEntry;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir ListBox::Clear();
354cdf0e10cSrcweir }
355cdf0e10cSrcweir
356cdf0e10cSrcweir // class LanguageBoxControl ----------------------------------------------
357cdf0e10cSrcweir
358cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL( LanguageBoxControl, SfxStringItem );
359cdf0e10cSrcweir
LanguageBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)360cdf0e10cSrcweir LanguageBoxControl::LanguageBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
361cdf0e10cSrcweir : SfxToolBoxControl( nSlotId, nId, rTbx )
362cdf0e10cSrcweir {
363cdf0e10cSrcweir }
364cdf0e10cSrcweir
~LanguageBoxControl()365cdf0e10cSrcweir LanguageBoxControl::~LanguageBoxControl()
366cdf0e10cSrcweir {
367cdf0e10cSrcweir }
368cdf0e10cSrcweir
StateChanged(sal_uInt16 _nID,SfxItemState _eState,const SfxPoolItem * _pItem)369cdf0e10cSrcweir void LanguageBoxControl::StateChanged( sal_uInt16 _nID, SfxItemState _eState, const SfxPoolItem* _pItem )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir (void)_nID;
372cdf0e10cSrcweir
373cdf0e10cSrcweir BasicLanguageBox* pBox = (BasicLanguageBox*)( GetToolBox().GetItemWindow( GetId() ) );
374cdf0e10cSrcweir
375cdf0e10cSrcweir if ( pBox )
376cdf0e10cSrcweir {
377cdf0e10cSrcweir if ( _eState != SFX_ITEM_AVAILABLE )
378cdf0e10cSrcweir pBox->Disable();
379cdf0e10cSrcweir else
380cdf0e10cSrcweir {
381cdf0e10cSrcweir pBox->Enable();
382cdf0e10cSrcweir if ( _pItem->ISA(SfxStringItem) )
383cdf0e10cSrcweir pBox->Update( (const SfxStringItem*)_pItem );
384cdf0e10cSrcweir else
385cdf0e10cSrcweir pBox->Update( NULL );
386cdf0e10cSrcweir }
387cdf0e10cSrcweir }
388cdf0e10cSrcweir }
389cdf0e10cSrcweir
CreateItemWindow(Window * pParent)390cdf0e10cSrcweir Window* LanguageBoxControl::CreateItemWindow( Window *pParent )
391cdf0e10cSrcweir {
392cdf0e10cSrcweir return new BasicLanguageBox( pParent );
393cdf0e10cSrcweir }
394cdf0e10cSrcweir
395cdf0e10cSrcweir // class BasicLanguageBox ------------------------------------------------
396cdf0e10cSrcweir
BasicLanguageBox(Window * pParent)397cdf0e10cSrcweir BasicLanguageBox::BasicLanguageBox( Window* pParent ) :
398cdf0e10cSrcweir
399cdf0e10cSrcweir DocListenerBox( pParent ),
400cdf0e10cSrcweir
401cdf0e10cSrcweir m_sNotLocalizedStr( IDEResId( RID_STR_TRANSLATION_NOTLOCALIZED ) ),
402cdf0e10cSrcweir m_sDefaultLanguageStr( IDEResId( RID_STR_TRANSLATION_DEFAULT ) ),
403cdf0e10cSrcweir
404cdf0e10cSrcweir m_bIgnoreSelect( false )
405cdf0e10cSrcweir
406cdf0e10cSrcweir {
407cdf0e10cSrcweir SetSizePixel( Size( 210, 200 ) );
408cdf0e10cSrcweir
409cdf0e10cSrcweir FillBox();
410cdf0e10cSrcweir }
411cdf0e10cSrcweir
~BasicLanguageBox()412cdf0e10cSrcweir BasicLanguageBox::~BasicLanguageBox()
413cdf0e10cSrcweir {
414cdf0e10cSrcweir ClearBox();
415cdf0e10cSrcweir }
416cdf0e10cSrcweir
FillBox()417cdf0e10cSrcweir void BasicLanguageBox::FillBox()
418cdf0e10cSrcweir {
419cdf0e10cSrcweir SetUpdateMode( sal_False );
420cdf0e10cSrcweir m_bIgnoreSelect = true;
421cdf0e10cSrcweir m_sCurrentText = GetSelectEntry();
422cdf0e10cSrcweir ClearBox();
423cdf0e10cSrcweir
424cdf0e10cSrcweir LocalizationMgr* pCurMgr = IDE_DLL()->GetShell()->GetCurLocalizationMgr();
425cdf0e10cSrcweir if ( pCurMgr->isLibraryLocalized() )
426cdf0e10cSrcweir {
427cdf0e10cSrcweir Enable();
428cdf0e10cSrcweir SvtLanguageTable aLangTable;
429cdf0e10cSrcweir Locale aDefaultLocale = pCurMgr->getStringResourceManager()->getDefaultLocale();
430cdf0e10cSrcweir Locale aCurrentLocale = pCurMgr->getStringResourceManager()->getCurrentLocale();
431cdf0e10cSrcweir Sequence< Locale > aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales();
432cdf0e10cSrcweir const Locale* pLocale = aLocaleSeq.getConstArray();
433cdf0e10cSrcweir sal_Int32 i, nCount = aLocaleSeq.getLength();
434cdf0e10cSrcweir sal_uInt16 nSelPos = LISTBOX_ENTRY_NOTFOUND;
435cdf0e10cSrcweir for ( i = 0; i < nCount; ++i )
436cdf0e10cSrcweir {
437cdf0e10cSrcweir bool bIsDefault = localesAreEqual( aDefaultLocale, pLocale[i] );
438cdf0e10cSrcweir bool bIsCurrent = localesAreEqual( aCurrentLocale, pLocale[i] );
439cdf0e10cSrcweir LanguageType eLangType = SvxLocaleToLanguage( pLocale[i] );
440cdf0e10cSrcweir String sLanguage = aLangTable.GetString( eLangType );
441cdf0e10cSrcweir if ( bIsDefault )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir sLanguage += ' ';
444cdf0e10cSrcweir sLanguage += m_sDefaultLanguageStr;
445cdf0e10cSrcweir }
446cdf0e10cSrcweir sal_uInt16 nPos = InsertEntry( sLanguage );
447cdf0e10cSrcweir SetEntryData( nPos, new LanguageEntry( sLanguage, pLocale[i], bIsDefault ) );
448cdf0e10cSrcweir
449cdf0e10cSrcweir if ( bIsCurrent )
450cdf0e10cSrcweir nSelPos = nPos;
451cdf0e10cSrcweir }
452cdf0e10cSrcweir
453cdf0e10cSrcweir if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
454cdf0e10cSrcweir {
455cdf0e10cSrcweir SelectEntryPos( nSelPos );
456cdf0e10cSrcweir m_sCurrentText = GetSelectEntry();
457cdf0e10cSrcweir }
458cdf0e10cSrcweir }
459cdf0e10cSrcweir else
460cdf0e10cSrcweir {
461cdf0e10cSrcweir InsertEntry( m_sNotLocalizedStr );
462cdf0e10cSrcweir SelectEntryPos(0);
463cdf0e10cSrcweir Disable();
464cdf0e10cSrcweir }
465cdf0e10cSrcweir
466cdf0e10cSrcweir SetUpdateMode( sal_True );
467cdf0e10cSrcweir m_bIgnoreSelect = false;
468cdf0e10cSrcweir }
469cdf0e10cSrcweir
ClearBox()470cdf0e10cSrcweir void BasicLanguageBox::ClearBox()
471cdf0e10cSrcweir {
472cdf0e10cSrcweir sal_uInt16 nCount = GetEntryCount();
473cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; ++i )
474cdf0e10cSrcweir {
475cdf0e10cSrcweir LanguageEntry* pEntry = (LanguageEntry*)GetEntryData(i);
476cdf0e10cSrcweir delete pEntry;
477cdf0e10cSrcweir }
478cdf0e10cSrcweir ListBox::Clear();
479cdf0e10cSrcweir }
480cdf0e10cSrcweir
SetLanguage()481cdf0e10cSrcweir void BasicLanguageBox::SetLanguage()
482cdf0e10cSrcweir {
483cdf0e10cSrcweir LanguageEntry* pEntry = (LanguageEntry*)GetEntryData( GetSelectEntryPos() );
484cdf0e10cSrcweir if ( pEntry )
485cdf0e10cSrcweir IDE_DLL()->GetShell()->GetCurLocalizationMgr()->handleSetCurrentLocale( pEntry->m_aLocale );
486cdf0e10cSrcweir }
487cdf0e10cSrcweir
Select()488cdf0e10cSrcweir void BasicLanguageBox::Select()
489cdf0e10cSrcweir {
490cdf0e10cSrcweir if ( !m_bIgnoreSelect )
491cdf0e10cSrcweir SetLanguage();
492cdf0e10cSrcweir else
493cdf0e10cSrcweir SelectEntry( m_sCurrentText ); // Select after Escape
494cdf0e10cSrcweir }
495cdf0e10cSrcweir
PreNotify(NotifyEvent & rNEvt)496cdf0e10cSrcweir long BasicLanguageBox::PreNotify( NotifyEvent& rNEvt )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir long nDone = 0;
499cdf0e10cSrcweir if( rNEvt.GetType() == EVENT_KEYINPUT )
500cdf0e10cSrcweir {
501cdf0e10cSrcweir sal_uInt16 nKeyCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
502cdf0e10cSrcweir switch( nKeyCode )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir case KEY_RETURN:
505cdf0e10cSrcweir {
506cdf0e10cSrcweir SetLanguage();
507cdf0e10cSrcweir nDone = 1;
508cdf0e10cSrcweir }
509cdf0e10cSrcweir break;
510cdf0e10cSrcweir
511cdf0e10cSrcweir case KEY_ESCAPE:
512cdf0e10cSrcweir {
513cdf0e10cSrcweir SelectEntry( m_sCurrentText );
514cdf0e10cSrcweir nDone = 1;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir break;
517cdf0e10cSrcweir }
518cdf0e10cSrcweir }
519cdf0e10cSrcweir else if( rNEvt.GetType() == EVENT_GETFOCUS )
520cdf0e10cSrcweir {
521cdf0e10cSrcweir }
522cdf0e10cSrcweir else if( rNEvt.GetType() == EVENT_LOSEFOCUS )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir }
525cdf0e10cSrcweir
526cdf0e10cSrcweir return nDone ? nDone : ListBox::PreNotify( rNEvt );
527cdf0e10cSrcweir }
528cdf0e10cSrcweir
Update(const SfxStringItem * pItem)529cdf0e10cSrcweir void BasicLanguageBox::Update( const SfxStringItem* pItem )
530cdf0e10cSrcweir {
531cdf0e10cSrcweir FillBox();
532cdf0e10cSrcweir
533cdf0e10cSrcweir if ( pItem && pItem->GetValue().Len() > 0 )
534cdf0e10cSrcweir {
535cdf0e10cSrcweir m_sCurrentText = pItem->GetValue();
536cdf0e10cSrcweir if ( GetSelectEntry() != m_sCurrentText )
537cdf0e10cSrcweir SelectEntry( m_sCurrentText );
538cdf0e10cSrcweir }
539cdf0e10cSrcweir }
540cdf0e10cSrcweir
541