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